Skip to content

Commit

Permalink
cargo fmt codebase (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
hicder authored Jan 6, 2025
1 parent cf154b6 commit 39b1eda
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion rs/index/src/spann/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ impl SpannWriter {
ivf_quantizer_writer.write(&ivf_quantizer)?;

debug!("Writing IVF index");
let ivf_writer = IvfWriter::<_, PlainEncoder, L2DistanceCalculator>::new(ivf_directory, ivf_quantizer);
let ivf_writer =
IvfWriter::<_, PlainEncoder, L2DistanceCalculator>::new(ivf_directory, ivf_quantizer);
ivf_writer.write(&mut spann_builder.ivf_builder, index_writer_config.reindex)?;
spann_builder.ivf_builder.cleanup()?;
debug!("Finish writing IVF index");
Expand Down
2 changes: 1 addition & 1 deletion rs/utils/src/distance/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl DistanceCalculator for L2DistanceCalculator {
*acc += diff.mul(diff);
});
}

#[inline(always)]
fn outermost_op(x: f32) -> f32 {
x
Expand Down
17 changes: 12 additions & 5 deletions rs/utils/src/distance/lane_conforming.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::marker::PhantomData;
use std::simd::num::SimdFloat;
use std::{marker::PhantomData, simd::{LaneCount, Simd, SupportedLaneCount}};
use std::simd::{LaneCount, Simd, SupportedLaneCount};

use crate::{CalculateSquared, DistanceCalculator};

Expand All @@ -26,15 +27,18 @@ where
}
#[cfg(test)]
mod tests {
use crate::{distance::{dot_product::DotProductDistanceCalculator, l2::L2DistanceCalculator}, test_utils::generate_random_vector};
use super::*;
use crate::distance::dot_product::DotProductDistanceCalculator;
use crate::distance::l2::L2DistanceCalculator;
use crate::test_utils::generate_random_vector;

#[test]
fn test_calculate_l2_distance() {
let a = generate_random_vector(16);
let b = generate_random_vector(16);
let eps = 1e-5;
let conforming_result = LaneConformingDistanceCalculator::<4, L2DistanceCalculator>::calculate_squared(&a, &b);
let conforming_result =
LaneConformingDistanceCalculator::<4, L2DistanceCalculator>::calculate_squared(&a, &b);
let l2_result = L2DistanceCalculator::calculate_squared(&a, &b);
assert!((conforming_result - l2_result).abs() < eps)
}
Expand All @@ -44,8 +48,11 @@ mod tests {
let a = generate_random_vector(16);
let b = generate_random_vector(16);
let eps = 1e-5;
let conforming_result = LaneConformingDistanceCalculator::<4, DotProductDistanceCalculator>::calculate_squared(&a, &b);
let conforming_result =
LaneConformingDistanceCalculator::<4, DotProductDistanceCalculator>::calculate_squared(
&a, &b,
);
let dot_product_result = DotProductDistanceCalculator::calculate_squared(&a, &b);
assert!((conforming_result - dot_product_result).abs() < eps)
assert!((conforming_result - dot_product_result).abs() < eps)
}
}
8 changes: 3 additions & 5 deletions rs/utils/src/kmeans_builder/kmeans_builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::marker::PhantomData;
use std::cmp::min;
use std::marker::PhantomData;
use std::simd::{LaneCount, Simd, SupportedLaneCount};

use anyhow::{anyhow, Ok, Result};
Expand Down Expand Up @@ -290,8 +290,7 @@ impl<D: DistanceCalculator + CalculateSquared + Send + Sync> KMeansBuilder<D> {
.chunks_exact(self.dimension)
.nth(cluster_id)
.unwrap();
let distance =
T::calculate_squared(point, cluster);
let distance = T::calculate_squared(point, cluster);
if distance > max_distance {
max_distance = distance;
chosen_point_id = i;
Expand Down Expand Up @@ -371,9 +370,8 @@ impl<D: DistanceCalculator + CalculateSquared + Send + Sync> KMeansBuilder<D> {
#[cfg(test)]
mod tests {

use crate::distance::l2::L2DistanceCalculator;

use super::*;
use crate::distance::l2::L2DistanceCalculator;

#[test]
fn test_kmeans_lloyd() {
Expand Down
4 changes: 2 additions & 2 deletions rs/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub trait DistanceCalculator {
) where
LaneCount<LANES>: SupportedLaneCount;

/*
* The outermost operator of the distance function,
/*
* The outermost operator of the distance function,
* to be used with accumulate_lanes for lane conforming code.
*/
fn outermost_op(x: f32) -> f32;
Expand Down

0 comments on commit 39b1eda

Please sign in to comment.