Skip to content

Commit

Permalink
Update impl_native_binary_index macro to do proper accounting of the …
Browse files Browse the repository at this point in the history
…vectors.

Signed-off-by: Aalekh Patel <[email protected]>
  • Loading branch information
aalekhpatel07 committed Mar 30, 2024
1 parent 698c65a commit c1d8c08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
];
Expand Down
12 changes: 6 additions & 6 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -242,7 +242,7 @@ macro_rules! impl_native_binary_index {
k: usize,
) -> Result<crate::index::AssignSearchResult> {
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(),
Expand All @@ -260,7 +260,7 @@ macro_rules! impl_native_binary_index {
k: usize,
) -> Result<crate::index::SearchResultBinary> {
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(
Expand All @@ -280,7 +280,7 @@ macro_rules! impl_native_binary_index {
radius: i32,
) -> Result<crate::index::RangeSearchResult> {
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(
Expand Down

0 comments on commit c1d8c08

Please sign in to comment.