Rotate the query, then build flat ADC distance table `[M × K]`.
(&self, q: &[f32])
| 303 | |
| 304 | /// Rotate the query, then build flat ADC distance table `[M × K]`. |
| 305 | fn prepare_query(&self, q: &[f32]) -> Self::Query { |
| 306 | let rotated = self.apply_rotation(q); |
| 307 | let mut table = vec![0.0f32; self.m * self.k]; |
| 308 | for s in 0..self.m { |
| 309 | let offset = s * self.sub_dim; |
| 310 | let sub_q = &rotated[offset..offset + self.sub_dim]; |
| 311 | for c in 0..self.k { |
| 312 | table[s * self.k + c] = l2_sq(sub_q, &self.codebooks[s][c]); |
| 313 | } |
| 314 | } |
| 315 | OpqQuery { |
| 316 | distance_table: table, |
| 317 | rotated, |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | fn adc_lut(&self, q: &Self::Query) -> Option<AdcLut> { |
| 322 | let mut lut = AdcLut::new(self.m as u16, self.k as u16); |