Skip to content

Commit fdeb3a6

Browse files
authored
Merge pull request #8 from VectorDB-NTU/rotator-debug
format rotator chocie for qg and ivf
2 parents b76b94e + 907ee66 commit fdeb3a6

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

rabitqlib/index/ivf/ivf.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <immintrin.h>
44
#include <omp.h>
55

6+
#include <algorithm>
67
#include <cassert>
78
#include <cmath>
89
#include <cstddef>
@@ -118,9 +119,7 @@ inline IVF::IVF(size_t n, size_t dim, size_t cluster_num, size_t bits, RotatorTy
118119
std::cerr.flush();
119120
exit(1);
120121
};
121-
rotator_ = choose_rotator<float>(
122-
dim, RotatorType::FhtKacRotator, round_up_to_multiple(dim_, 64)
123-
);
122+
rotator_ = choose_rotator<float>(dim, type, round_up_to_multiple(dim_, 64));
124123
padded_dim_ = rotator_->size();
125124
/* check size */
126125
assert(padded_dim_ % 64 == 0);
@@ -332,9 +331,7 @@ inline void IVF::load(const char* filename) {
332331
input.read(reinterpret_cast<char*>(&this->ex_bits_), sizeof(size_t));
333332
input.read(reinterpret_cast<char*>(&type_), sizeof(type_));
334333

335-
rotator_ = choose_rotator<float>(
336-
dim_, RotatorType::FhtKacRotator, round_up_to_multiple(dim_, 64)
337-
);
334+
rotator_ = choose_rotator<float>(dim_, type_, round_up_to_multiple(dim_, 64));
338335
padded_dim_ = rotator_->size();
339336

340337
/* Load number of vectors of each cluster */
@@ -376,12 +373,12 @@ inline void IVF::search(
376373
PID* __restrict__ results,
377374
bool use_hacc = true
378375
) const {
379-
if (nprobe > num_cluster_) {
380-
nprobe = num_cluster_;
381-
}
376+
nprobe = std::min(nprobe, num_cluster_); // corner case
382377
std::vector<float> rotated_query(padded_dim_);
383378
this->rotator_->rotate(query, rotated_query.data());
384379

380+
std::cout << l2norm_sqr(query, dim_) << '\t' << l2norm_sqr(rotated_query.data(), padded_dim_) << '\n';
381+
385382
// use initer to get closest nprobe centroids
386383
std::vector<AnnCandidate<float>> centroid_dist(nprobe);
387384
this->initer_->centroids_distances(rotated_query.data(), nprobe, centroid_dist);

rabitqlib/index/symqg/qg.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,7 @@ template <typename T>
341341
inline void QuantizedGraph<T>::initialize() {
342342
::delete rotator_;
343343

344-
rotator_ = choose_rotator<float>(
345-
dim_, RotatorType::FhtKacRotator, round_up_to_multiple(dim_, 64)
346-
);
344+
rotator_ = choose_rotator<float>(dim_, type_, round_up_to_multiple(dim_, 64));
347345
padded_dim_ = rotator_->size();
348346

349347
/* check size */

0 commit comments

Comments
 (0)