| 193 | |
| 194 | template<int Reduction> |
| 195 | void lut(const float* q, int len, int nbytes, |
| 196 | const RowMatrix<float>& centroids, const RowVector<float>& offsets, |
| 197 | float scaleby, ColMatrix<uint8_t>& lut_out) |
| 198 | { |
| 199 | assert(scaleby > 0.); |
| 200 | assert(offsets.data() != nullptr); |
| 201 | |
| 202 | // _naive_lut(q, len, nbytes, centroids, offsets, scaleby, lut_out); |
| 203 | // return; |
| 204 | |
| 205 | // static constexpr int ncentroids = 16; |
| 206 | // int ncodebooks = nbytes * 2; |
| 207 | // ColMatrix<uint8_t>& lut_out(ncentroids, ncodebooks); |
| 208 | auto lut_ptr = lut_out.data(); |
| 209 | |
| 210 | // create lookup table and then scan with it |
| 211 | switch (nbytes) { |
| 212 | case 2: |
| 213 | // TODO uncomment after debug |
| 214 | bolt_lut<2, Reduction>(q, len, centroids.data(), offsets.data(), |
| 215 | scaleby, lut_ptr); |
| 216 | |
| 217 | // bolt_lut<2, Reduction>(q, len, centroids.data(), lut_ptr); |
| 218 | break; |
| 219 | case 8: |
| 220 | bolt_lut<8, Reduction>(q, len, centroids.data(), offsets.data(), |
| 221 | scaleby, lut_ptr); |
| 222 | break; |
| 223 | case 16: |
| 224 | bolt_lut<16, Reduction>(q, len, centroids.data(), offsets.data(), |
| 225 | scaleby, lut_ptr); |
| 226 | break; |
| 227 | case 24: |
| 228 | bolt_lut<24, Reduction>(q, len, centroids.data(), offsets.data(), |
| 229 | scaleby, lut_ptr); |
| 230 | break; |
| 231 | case 32: |
| 232 | bolt_lut<32, Reduction>(q, len, centroids.data(), offsets.data(), |
| 233 | scaleby, lut_ptr); |
| 234 | break; |
| 235 | default: |
| 236 | break; |
| 237 | } |
| 238 | // return lut_out; |
| 239 | } |
| 240 | void BoltEncoder::lut_l2(const float* q, int len) { |
| 241 | lut<Reductions::DistL2>(q, len, _nbytes, _centroids, |
| 242 | _offsets, _scaleby, _lut); |