From c1d8c088b95ffdee4d1889d1fe85702d99419304 Mon Sep 17 00:00:00 2001 From: Aalekh Patel Date: Sat, 30 Mar 2024 13:38:41 -0500 Subject: [PATCH] Update impl_native_binary_index macro to do proper accounting of the vectors. Signed-off-by: Aalekh Patel --- src/index/mod.rs | 4 ++-- src/macros.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index/mod.rs b/src/index/mod.rs index bf31e3a..0729e5f 100644 --- a/src/index/mod.rs +++ b/src/index/mod.rs @@ -982,7 +982,7 @@ mod tests { } #[test] fn index_binary_clone() { - let mut index = index_binary_factory(16 / 8, "BFlat").unwrap(); + let mut index = index_binary_factory(16, "BFlat").unwrap(); let some_data = &[ 0, 1, 2, 3 @@ -1026,7 +1026,7 @@ mod tests { #[test] fn search_index_binary() { - let mut index = index_binary_factory(256 / 8, "BFlat").unwrap(); + let mut index = index_binary_factory(256, "BFlat").unwrap(); let some_data = &[ 255u8; 32 ]; diff --git a/src/macros.rs b/src/macros.rs index 4e0575a..b8f3af1 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -203,7 +203,7 @@ macro_rules! impl_native_binary_index { fn add(&mut self, x: &[u8]) -> Result<()> { unsafe { - let n = x.len() / self.d() as usize; + let n = (x.len() * 8) / self.d() as usize; faiss_try(faiss_IndexBinary_add( self.inner_ptr(), n as i64, @@ -215,7 +215,7 @@ macro_rules! impl_native_binary_index { fn add_with_ids(&mut self, x: &[u8], xids: &[crate::index::Idx]) -> Result<()> { unsafe { - let n = x.len() / self.d() as usize; + let n = (x.len() * 8) / self.d() as usize; faiss_try(faiss_IndexBinary_add_with_ids( self.inner_ptr(), n as i64, @@ -227,7 +227,7 @@ macro_rules! impl_native_binary_index { } fn train(&mut self, x: &[u8]) -> Result<()> { unsafe { - let n = x.len() / self.d() as usize; + let n = (x.len() * 8) / self.d() as usize; faiss_try(faiss_IndexBinary_train( self.inner_ptr(), n as i64, @@ -242,7 +242,7 @@ macro_rules! impl_native_binary_index { k: usize, ) -> Result { unsafe { - let nq = query.len() / self.d() as usize; + let nq = (query.len() * 8) / self.d() as usize; let mut out_labels = vec![Idx::none(); k * nq]; faiss_try(faiss_IndexBinary_assign( self.inner_ptr(), @@ -260,7 +260,7 @@ macro_rules! impl_native_binary_index { k: usize, ) -> Result { unsafe { - let nq = query.len() / self.d() as usize; + let nq = (query.len() * 8) / self.d() as usize; let mut distances = vec![0_i32; k * nq]; let mut labels = vec![Idx::none(); k * nq]; faiss_try(faiss_IndexBinary_search( @@ -280,7 +280,7 @@ macro_rules! impl_native_binary_index { radius: i32, ) -> Result { unsafe { - let nq = (query.len() / self.d() as usize) as idx_t; + let nq = ((query.len() * 8) / self.d() as usize) as idx_t; let mut p_res: *mut FaissRangeSearchResult = ::std::ptr::null_mut(); faiss_try(faiss_RangeSearchResult_new(&mut p_res, nq))?; faiss_try(faiss_IndexBinary_range_search(