11 #include "IndexFlat.h"
12 #include "FaissAssert.h"
31 FAISS_THROW_MSG (
"range search not implemented");
36 float * distances =
new float[n * k];
38 search (n, x, k, distances, labels);
45 FAISS_THROW_MSG (
"add_with_ids not implemented for this type of index");
49 FAISS_THROW_MSG (
"remove_ids not implemented for this type of index");
55 FAISS_THROW_MSG (
"reconstruct not implemented for this type of index");
60 for (
idx_t i = 0; i < ni; i++) {
67 float *distances,
idx_t *labels,
68 float *recons)
const {
69 search (n, x, k, distances, labels);
70 for (
idx_t i = 0; i < n; ++i) {
71 for (
idx_t j = 0; j < k; ++j) {
73 idx_t key = labels[ij];
74 float* reconstructed = recons + ij *
d;
77 memset(reconstructed, -1,
sizeof(*reconstructed) * d);
87 float * residual,
idx_t key)
const {
89 for (
size_t i = 0; i <
d; i++)
90 residual[i] = x[i] - residual[i];
95 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