Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

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