forked from facebookresearch/faiss
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request facebookresearch#2 from justinaustin/remove_ids
Adding remove_ids method to Index trait
- Loading branch information
Showing
6 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! Abstract Faiss ID selector | ||
use error::Result; | ||
use faiss_sys::*; | ||
use index::Idx; | ||
use std::os::raw::c_long; | ||
use std::ptr; | ||
|
||
/// Abstraction over IDSelectorRange and IDSelectorBatch | ||
#[derive(Debug)] | ||
pub struct IdSelector { | ||
inner: *mut FaissIDSelector, | ||
} | ||
|
||
impl IdSelector { | ||
/// Create new range selector | ||
pub fn range(min: Idx, max: Idx) -> Result<Self> { | ||
let mut p_sel = ptr::null_mut(); | ||
unsafe { | ||
faiss_try!(faiss_IDSelectorRange_new(&mut p_sel, min, max)); | ||
}; | ||
Ok(IdSelector { inner: p_sel as *mut _}) | ||
} | ||
|
||
/// Create new batch selector | ||
pub fn batch(indices: &[Idx]) -> Result<Self> { | ||
let n = indices.len() as c_long; | ||
let mut p_sel = ptr::null_mut(); | ||
unsafe { | ||
faiss_try!(faiss_IDSelectorBatch_new(&mut p_sel, n, indices.as_ptr())); | ||
}; | ||
Ok(IdSelector { inner: p_sel as *mut _}) | ||
} | ||
|
||
/// Return the inner pointer | ||
pub fn inner_ptr(&self) -> *mut FaissIDSelector { | ||
self.inner | ||
} | ||
|
||
} | ||
|
||
impl Drop for IdSelector { | ||
fn drop(&mut self) { | ||
unsafe { | ||
faiss_IDSelector_free(self.inner); | ||
} | ||
} | ||
} | ||
|
||
unsafe impl Send for IdSelector {} | ||
unsafe impl Sync for IdSelector {} |