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 BSD+Patents 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 void Index::add_with_ids(
31 idx_t /*n*/,
32 const float* /*x*/,
33 const long* /*xids*/) {
34 FAISS_THROW_MSG ("add_with_ids not implemented for this type of index");
35 }
36
37 long Index::remove_ids(const IDSelector& /*sel*/) {
38 FAISS_THROW_MSG ("remove_ids not implemented for this type of index");
39 return -1;
40 }
41
42
43 void Index::reconstruct (idx_t, float * ) const {
44 FAISS_THROW_MSG ("Can not compute reconstruct without "
45 "knowing how to do so");
46 }
47
48
49 void Index::reconstruct_n (idx_t i0, idx_t ni, float *recons) const {
50 for (idx_t i = 0; i < ni; i++) {
51 reconstruct (i0 + i, recons + i * d);
52 }
53 }
54
55
56
57 void Index::compute_residual (const float * x,
58 float * residual, idx_t key) const {
59 reconstruct (key, residual);
60 for (size_t i = 0; i < d; i++)
61 residual[i] = x[i] - residual[i];
62 }
63
64
65 void Index::display () const {
66 printf ("Index: %s -> %ld elements\n", typeid (*this).name(), ntotal);
67 }
68
69 }
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:52
faiss::Index::add_with_ids
virtual void add_with_ids(idx_t n, const float *x, const long *xids)
Definition: Index.cpp:30
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:49
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:29
faiss::Index::display
void display() const
Definition: Index.cpp:65
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:57
faiss::Index::reconstruct
virtual void reconstruct(idx_t key, float *recons) const
Definition: Index.cpp:43