Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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)
67 void transfer_thresholds (LinearTransform * vt);
68
69 ~IndexLSH() override {}
70
71 IndexLSH ();
72 };
73
74
75 }
76
77
78 #endif
faiss::RandomRotationMatrix
Randomly rotate a set of vectors.
Definition: VectorTransform.h:116
faiss::IndexLSH::bytes_per_vec
int bytes_per_vec
nb of 8-bits per encoded vector
Definition: IndexLSH.h:27
faiss::IndexLSH::thresholds
std::vector< float > thresholds
thresholds to compare with
Definition: IndexLSH.h:33
faiss::IndexLSH
Definition: IndexLSH.h:23
faiss::IndexLSH::train_thresholds
bool train_thresholds
whether we train thresholds or use 0
Definition: IndexLSH.h:29
faiss::IndexLSH::search
void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override
Definition: IndexLSH.cpp:129
faiss::Index::d
int d
vector dimension
Definition: Index.h:66
faiss::IndexLSH::rrot
RandomRotationMatrix rrot
optional random rotation
Definition: IndexLSH.h:31
faiss::IndexLSH::transfer_thresholds
void transfer_thresholds(LinearTransform *vt)
Definition: IndexLSH.cpp:161
faiss::LinearTransform
Definition: VectorTransform.h:76
faiss::Index::idx_t
long idx_t
all indices are this type
Definition: Index.h:64
faiss::IndexLSH::reset
void reset() override
removes all elements from the database.
Definition: IndexLSH.cpp:174
faiss::IndexLSH::add
void add(idx_t n, const float *x) override
Definition: IndexLSH.cpp:117
faiss::IndexLSH::train
void train(idx_t n, const float *x) override
Definition: IndexLSH.cpp:86
faiss::IndexLSH::nbits
int nbits
nb of bits per vector
Definition: IndexLSH.h:26
faiss::Index
Definition: Index.h:62
faiss::IndexLSH::apply_preprocess
const float * apply_preprocess(idx_t n, const float *x) const
Definition: IndexLSH.cpp:51
faiss::IndexLSH::rotate_data
bool rotate_data
whether to apply a random rotation to input
Definition: IndexLSH.h:28
faiss::IndexLSH::codes
std::vector< uint8_t > codes
encoded dataset
Definition: IndexLSH.h:36