8 #include "IndexReplicas.h"
9 #include "FaissAssert.h"
13 template <
typename IndexT>
18 template <
typename IndexT>
23 template <
typename IndexT>
28 template <
typename IndexT>
33 if (this->count() > 0 && this->at(0) != index) {
34 auto existing = this->at(0);
36 FAISS_THROW_IF_NOT_FMT(index->ntotal == existing->ntotal,
37 "IndexReplicas: newly added index does "
38 "not have same number of vectors as prior index; "
39 "prior index has %ld vectors, new index has %ld",
40 existing->ntotal, index->ntotal);
42 FAISS_THROW_IF_NOT_MSG(index->is_trained == existing->is_trained,
43 "IndexReplicas: newly added index does "
44 "not have same train status as prior index");
48 this->ntotal = index->ntotal;
49 this->verbose = index->verbose;
50 this->is_trained = index->is_trained;
51 this->metric_type = index->metric_type;
55 template <
typename IndexT>
58 this->runOnIndex([n, x](
int, IndexT* index){ index->train(n, x); });
61 template <
typename IndexT>
64 this->runOnIndex([n, x](
int, IndexT* index){ index->add(n, x); });
68 template <
typename IndexT>
71 FAISS_THROW_IF_NOT_MSG(this->count() > 0,
"no replicas in index");
74 this->at(0)->reconstruct(n, x);
77 template <
typename IndexT>
82 distance_t* distances,
83 idx_t* labels)
const {
84 FAISS_THROW_IF_NOT_MSG(this->count() > 0,
"no replicas in index");
91 size_t componentsPerVec =
92 sizeof(component_t) == 1 ? (dim + 7) / 8 : dim;
98 FAISS_ASSERT(n / queriesPerIndex <= this->count());
101 [queriesPerIndex, componentsPerVec,
102 n, x, k, distances, labels](
int i,
const IndexT* index) {
106 auto numForIndex = std::min(queriesPerIndex, n - base);
108 index->
search(numForIndex,
109 x + base * componentsPerVec,
111 distances + base * k,
116 this->runOnIndex(fn);
void train(idx_t n, const component_t *x) override
IndexReplicasTemplate(bool threaded=true)
long idx_t
all indices are this type
void onAfterAddIndex(IndexT *index) override
Called just after an index is added.
void search(idx_t n, const component_t *x, idx_t k, distance_t *distances, idx_t *labels) const override
void reconstruct(idx_t, component_t *v) const override
reconstructs from the first index
void add(idx_t n, const component_t *x) override
void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override