Method
nearest_centroid
(&self, subspace: usize, sub_vec: &[f32])
Source from the content-addressed store, hash-verified
| 243 | } |
| 244 | |
| 245 | fn nearest_centroid(&self, subspace: usize, sub_vec: &[f32]) -> usize { |
| 246 | let mut best_idx = 0; |
| 247 | let mut best_dist = f32::MAX; |
| 248 | for (i, centroid) in self.codebooks[subspace].iter().enumerate() { |
| 249 | let d = l2_sub(sub_vec, centroid); |
| 250 | if d < best_dist { |
| 251 | best_dist = d; |
| 252 | best_idx = i; |
| 253 | } |
| 254 | } |
| 255 | best_idx |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | /// L2 squared distance for sub-vectors (used in k-means and encoding). |
Tested by
no test coverage detected