Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/tmp/faiss/IndexLSH.h
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 // -*- c++ -*-
10 
11 #ifndef INDEX_LSH_H
12 #define INDEX_LSH_H
13 
14 #include <vector>
15 
16 #include "Index.h"
17 #include "VectorTransform.h"
18 
19 namespace faiss {
20 
21 
22 /** The sign of each vector component is put in a binary signature */
23 struct IndexLSH:Index {
24  typedef unsigned char uint8_t;
25 
26  int nbits; ///< nb of bits per vector
27  int bytes_per_vec; ///< nb of 8-bits per encoded vector
28  bool rotate_data; ///< whether to apply a random rotation to input
29  bool train_thresholds; ///< whether we train thresholds or use 0
30 
31  RandomRotationMatrix rrot; ///< optional random rotation
32 
33  std::vector <float> thresholds; ///< thresholds to compare with
34 
35  /// encoded dataset
36  std::vector<uint8_t> codes;
37 
38  IndexLSH (
39  idx_t d, int nbits,
40  bool rotate_data = true,
41  bool train_thresholds = false);
42 
43  /** Preprocesses and resizes the input to the size required to
44  * binarize the data
45  *
46  * @param x input vectors, size n * d
47  * @return output vectors, size n * bits. May be the same pointer
48  * as x, otherwise it should be deleted by the caller
49  */
50  const float *apply_preprocess (idx_t n, const float *x) const;
51 
52  void train(idx_t n, const float* x) override;
53 
54  void add(idx_t n, const float* x) override;
55 
56  void search(
57  idx_t n,
58  const float* x,
59  idx_t k,
60  float* distances,
61  idx_t* labels) const override;
62 
63  void reset() override;
64 
65  /// transfer the thresholds to a pre-processing stage (and unset
66  /// train_thresholds)
68 
69  ~IndexLSH() override {}
70 
71  IndexLSH ();
72 };
73 
74 
75 }
76 
77 
78 #endif
Randomly rotate a set of vectors.
int bytes_per_vec
nb of 8-bits per encoded vector
Definition: IndexLSH.h:27
std::vector< float > thresholds
thresholds to compare with
Definition: IndexLSH.h:33
bool train_thresholds
whether we train thresholds or use 0
Definition: IndexLSH.h:29
void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override
Definition: IndexLSH.cpp:129
int d
vector dimension
Definition: Index.h:66
RandomRotationMatrix rrot
optional random rotation
Definition: IndexLSH.h:31
void transfer_thresholds(LinearTransform *vt)
Definition: IndexLSH.cpp:161
long idx_t
all indices are this type
Definition: Index.h:64
void reset() override
removes all elements from the database.
Definition: IndexLSH.cpp:174
void add(idx_t n, const float *x) override
Definition: IndexLSH.cpp:117
void train(idx_t n, const float *x) override
Definition: IndexLSH.cpp:86
int nbits
nb of bits per vector
Definition: IndexLSH.h:26
const float * apply_preprocess(idx_t n, const float *x) const
Definition: IndexLSH.cpp:51
bool rotate_data
whether to apply a random rotation to input
Definition: IndexLSH.h:28
std::vector< uint8_t > codes
encoded dataset
Definition: IndexLSH.h:36