11 #include "IndexFlat.h"
12 #include "FaissAssert.h"
32 FAISS_THROW_MSG (
"range search not implemented");
37 float * distances =
new float[n * k];
39 search (n, x, k, distances, labels);
46 FAISS_THROW_MSG (
"add_with_ids not implemented for this type of index");
50 FAISS_THROW_MSG (
"remove_ids not implemented for this type of index");
56 FAISS_THROW_MSG (
"reconstruct not implemented for this type of index");
61 for (
idx_t i = 0; i < ni; i++) {
68 float *distances,
idx_t *labels,
69 float *recons)
const {
70 search (n, x, k, distances, labels);
71 for (
idx_t i = 0; i < n; ++i) {
72 for (
idx_t j = 0; j < k; ++j) {
74 idx_t key = labels[ij];
75 float* reconstructed = recons + ij *
d;
78 memset(reconstructed, -1,
sizeof(*reconstructed) * d);
88 float * residual,
idx_t key)
const {
90 for (
size_t i = 0; i <
d; i++)
91 residual[i] = x[i] - residual[i];
96 printf (
"Index: %s -> %ld elements\n",
typeid (*this).name(),
ntotal);
virtual void search_and_reconstruct(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels, float *recons) const
void assign(idx_t n, const float *x, idx_t *labels, idx_t k=1)
virtual void train(idx_t n, const float *x)
virtual void add_with_ids(idx_t n, const float *x, const long *xids)
virtual void reconstruct_n(idx_t i0, idx_t ni, float *recons) const
long idx_t
all indices are this type
idx_t ntotal
total nb of indexed vectors
virtual long remove_ids(const IDSelector &sel)
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const =0
virtual void range_search(idx_t n, const float *x, float radius, RangeSearchResult *result) const
void compute_residual(const float *x, float *residual, idx_t key) const
virtual void reconstruct(idx_t key, float *recons) const