From 415c5654e888c511809f181b5de85cb3a5bd3e65 Mon Sep 17 00:00:00 2001 From: Justin Date: Sat, 8 Dec 2018 20:29:41 +0000 Subject: [PATCH] fixed test case, casting pointer to resolve bug --- src/index/id_map.rs | 19 +++++++++---------- src/selector.rs | 12 ++++++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/index/id_map.rs b/src/index/id_map.rs index 5a0ffec8c6..13aa777432 100644 --- a/src/index/id_map.rs +++ b/src/index/id_map.rs @@ -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); } } diff --git a/src/selector.rs b/src/selector.rs index 75a3a5f334..81618a187a 100644 --- a/src/selector.rs +++ b/src/selector.rs @@ -14,16 +14,20 @@ impl IdSelector { /// Create new range selector pub fn range(min: Idx, max: Idx) -> Result { 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 { 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