Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add module utils #65

Merged
merged 2 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}