Skip to content

Commit

Permalink
Merge pull request #65 from ava57r/main-utils
Browse files Browse the repository at this point in the history
add module utils
  • Loading branch information
Enet4 committed Apr 30, 2023
2 parents 9ce7106 + 9a7e31b commit ce9345f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub mod index;
pub mod metric;
pub mod selector;
pub mod vector_transform;
pub mod utils;

#[cfg(feature = "gpu")]
pub mod gpu;
Expand Down
23 changes: 23 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// L2-renormalize a set of vector. Nothing done if the vector is 0-normed
pub fn fvec_renorm_l2(d: usize, nx: usize, fvec: &mut [f32]) {
unsafe { faiss_sys::faiss_fvec_renorm_L2(d, nx, fvec.as_mut_ptr()) }
}

#[cfg(test)]
mod tests {

use super::*;

const D: u32 = 8;

#[test]
fn check_fvec_renorm_l2_01() {
let mut some_data = vec![
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., 100., 100., 100., 100., -100., 100., 100., 100., 120., 100.,
100., 105., -100., 100., 100., 105.,
];

fvec_renorm_l2(D as usize, 5, &mut some_data);
}
}

0 comments on commit ce9345f

Please sign in to comment.