Skip to content

Commit

Permalink
fixed test case, casting pointer to resolve bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin committed Dec 8, 2018
1 parent 9576ce3 commit 415c565
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
19 changes: 9 additions & 10 deletions src/index/id_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,19 +359,18 @@ mod tests {
fn index_remove_ids() {
let mut index = index_factory(4, "Flat", MetricType::L2).unwrap();
let mut id_index = IdMap::new(index).unwrap();
let some_data = &[
7.5_f32, -7.5, 7.5, -7.5, 7.5, 7.5, 7.5, 7.5, -1., 1., 1., 1., 1., 1., 1., -1., 0., 0.,
0., 1., 1., 0., 0., -1.,
];
let some_data = &[2.3_f32, 0.0, -1., 1., 1., 1., 1., 4.5, 2.3, 7.6, 1., 2.2];
println!("{}", some_data.len());

let id = [42];
let ids = &[4, 8, 12];

index.add(some_data).unwrap();
assert_eq!(index.ntotal(), 6);
id_index.add_with_ids(some_data, ids).unwrap();
assert_eq!(id_index.ntotal(), 3);

let id_sel = IdSelector::batch(&[6]).ok().unwrap();
let id_sel = IdSelector::batch(&[4, 12]).ok().unwrap();

index.remove_ids(&id_sel).unwrap();
assert_eq!(index.ntotal(), 0);
id_index.remove_ids(&id_sel).unwrap();
println!("{}", id_index.ntotal());
assert_eq!(id_index.ntotal(), 1);
}
}
12 changes: 8 additions & 4 deletions src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ impl IdSelector {
/// Create new range selector
pub fn range(min: Idx, max: Idx) -> Result<Self> {
let mut p_sel = ptr::null_mut();
faiss_try!(faiss_IDSelectorRange_new(&mut p_sel, min, max));
Ok(IdSelector { inner: p_sel })
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 i64;
let mut p_sel = ptr::null_mut();
faiss_try!(faiss_IDSelectorBatch_new(&mut p_sel, n, &indices[0]));
Ok(IdSelector { inner: p_sel })
unsafe {
faiss_try!(faiss_IDSelectorBatch_new(&mut p_sel, n, &indices[0]));
};
Ok(IdSelector { inner: p_sel as *mut _})
}

/// Return the inner pointer
Expand Down

0 comments on commit 415c565

Please sign in to comment.