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 * Copyright (c) 2015-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the CC-by-NC license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9 // Copyright 2004-present Facebook. All Rights Reserved
10
11 #include "IndexFlat.h"
12 #include "FaissAssert.h"
13
14 namespace faiss {
15
16
17 void Index::range_search (idx_t , const float *, float,
18 RangeSearchResult *) const
19 {
20 FAISS_THROW_MSG ("range search not implemented");
21 }
22
23 void Index::assign (idx_t n, const float * x, idx_t * labels, idx_t k)
24 {
25 float * distances = new float[n * k];
26 ScopeDeleter<float> del(distances);
27 search (n, x, k, distances, labels);
28 }
29
30
31 void Index::add_with_ids (idx_t n, const float * x, const long *xids)
32 {
33 FAISS_THROW_MSG ("add_with_ids not implemented for this type of index");
34 }
35
36
37 long Index::remove_ids (const IDSelector & sel)
38 {
39 FAISS_THROW_MSG ("remove_ids not implemented for this type of index");
40 return -1;
41 }
42
43
44 void Index::reconstruct (idx_t, float * ) const {
45 FAISS_THROW_MSG ("Can not compute reconstruct without "
46 "knowing how to do so");
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 }
faiss::Index::assign
void assign(idx_t n, const float *x, idx_t *labels, idx_t k=1)
Definition: Index.cpp:23
faiss::IDSelector
Definition: AuxIndexStructures.h:57
faiss::Index::add_with_ids
virtual void add_with_ids(idx_t n, const float *x, const long *xids)
Definition: Index.cpp:31
faiss::ScopeDeleter
Definition: FaissException.h:39
faiss::Index::d
int d
vector dimension
Definition: Index.h:64
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:62
faiss::Index::ntotal
idx_t ntotal
total nb of indexed vectors
Definition: Index.h:65
faiss::Index::remove_ids
virtual long remove_ids(const IDSelector &sel)
Definition: Index.cpp:37
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:34
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:17
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:44