Faiss
 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 
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 ("reconstruct not implemented for this type of index");
45 }
46 
47 
48 void Index::reconstruct_n (idx_t i0, idx_t ni, float *recons) const {
49  for (idx_t i = 0; i < ni; i++) {
50  reconstruct (i0 + i, recons + i * d);
51  }
52 }
53 
54 
55 
56 void Index::compute_residual (const float * x,
57  float * residual, idx_t key) const {
58  reconstruct (key, residual);
59  for (size_t i = 0; i < d; i++)
60  residual[i] = x[i] - residual[i];
61 }
62 
63 
64 void Index::display () const {
65  printf ("Index: %s -> %ld elements\n", typeid (*this).name(), ntotal);
66 }
67 
68 }
void assign(idx_t n, const float *x, idx_t *labels, idx_t k=1)
Definition: Index.cpp:23
virtual void add_with_ids(idx_t n, const float *x, const long *xids)
Definition: Index.cpp:30
int d
vector dimension
Definition: Index.h:64
virtual void reconstruct_n(idx_t i0, idx_t ni, float *recons) const
Definition: Index.cpp:48
long idx_t
all indices are this type
Definition: Index.h:62
idx_t ntotal
total nb of indexed vectors
Definition: Index.h:65
virtual long remove_ids(const IDSelector &sel)
Definition: Index.cpp:37
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const =0
void display() const
Definition: Index.cpp:64
virtual void range_search(idx_t n, const float *x, float radius, RangeSearchResult *result) const
Definition: Index.cpp:17
void compute_residual(const float *x, float *residual, idx_t key) const
Definition: Index.cpp:56
virtual void reconstruct(idx_t key, float *recons) const
Definition: Index.cpp:43