Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/data/users/matthijs/github_faiss/faiss/Index.cpp
1
2 /**
3 * Copyright (c) 2015-present, Facebook, Inc.
4 * All rights reserved.
5 *
6 * This source code is licensed under the CC-by-NC license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10 // Copyright 2004-present Facebook. All Rights Reserved
11
12 #include "IndexFlat.h"
13 #include "FaissAssert.h"
14
15 namespace faiss {
16
17
18 void Index::range_search (idx_t , const float *, float,
19 RangeSearchResult *) const
20 {
21 FAISS_ASSERT (!"range search not implemented");
22 }
23
24 void Index::assign (idx_t n, const float * x, idx_t * labels, idx_t k)
25 {
26 float * distances = new float[n * k];
27 search (n, x, k, distances, labels);
28 delete [] distances;
29 }
30
31
32 void Index::add_with_ids (idx_t n, const float * x, const long *xids)
33 {
34 FAISS_ASSERT (!"add_with_ids not implemented for this type of index");
35 }
36
37
38 long Index::remove_ids (const IDSelector & sel)
39 {
40 FAISS_ASSERT (!"remove_ids not implemented for this type of index");
41 return -1;
42 }
43
44
45 void Index::reconstruct (idx_t, float * ) const {
46 FAISS_ASSERT (! "Can not compute reconstruct without knowing howto\n");
47 }
48
49
50 void Index::reconstruct_n (idx_t i0, idx_t ni, float *recons) const {
51 for (idx_t i = 0; i < ni; i++) {
52 reconstruct (i0 + i, recons + i * d);
53 }
54 }
55
56
57
58 void Index::compute_residual (const float * x,
59 float * residual, idx_t key) const {
60 reconstruct (key, residual);
61 for (size_t i = 0; i < d; i++)
62 residual[i] = x[i] - residual[i];
63 }
64
65
66 void Index::display () const {
67 printf ("Index: %s -> %ld elements\n", typeid (*this).name(), ntotal);
68 }
69
70
71
72
73 }
faiss::Index::assign
void assign(idx_t n, const float *x, idx_t *labels, idx_t k=1)
Definition: Index.cpp:24
faiss::IDSelector
Definition: AuxIndexStructures.h:58
faiss::Index::add_with_ids
virtual void add_with_ids(idx_t n, const float *x, const long *xids)
Definition: Index.cpp:32
faiss::Index::d
int d
vector dimension
Definition: Index.h:66
faiss::Index::reconstruct_n
virtual void reconstruct_n(idx_t i0, idx_t ni, float *recons) const
Definition: Index.cpp:50
faiss::Index::idx_t
long idx_t
all indices are this type
Definition: Index.h:64
faiss::Index::ntotal
idx_t ntotal
total nb of indexed vectors
Definition: Index.h:67
faiss::Index::remove_ids
virtual long remove_ids(const IDSelector &sel)
Definition: Index.cpp:38
faiss::Index::search
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const =0
faiss::RangeSearchResult
Definition: AuxIndexStructures.h:35
faiss::Index::display
void display() const
Definition: Index.cpp:66
faiss::Index::range_search
virtual void range_search(idx_t n, const float *x, float radius, RangeSearchResult *result) const
Definition: Index.cpp:18
faiss::Index::compute_residual
void compute_residual(const float *x, float *residual, idx_t key) const
Definition: Index.cpp:58
faiss::Index::reconstruct
virtual void reconstruct(idx_t key, float *recons) const
Definition: Index.cpp:45