All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/data/users/matthijs/github_faiss/faiss/IndexLSH.h
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the CC-by-NC license found in the
* LICENSE file in the root directory of this source tree.
*/
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c++ -*-
#ifndef INDEX_LSH_H
#define INDEX_LSH_H
#include <vector>
#include "Index.h"
#include "VectorTransform.h"
namespace faiss {
/** The sign of each vector component is put in a binary signature */
struct IndexLSH:Index {
typedef unsigned char uint8_t;
int nbits; ///< nb of bits per vector
int bytes_per_vec; ///< nb of 8-bits per encoded vector
bool rotate_data; ///< whether to apply a random rotation to input
bool train_thresholds; ///< whether we train thresholds or use 0
RandomRotationMatrix rrot; ///< optional random rotation
std::vector <float> thresholds; ///< thresholds to compare with
/// encoded dataset
std::vector<uint8_t> codes;
IndexLSH (
idx_t d, int nbits,
bool rotate_data = true,
bool train_thresholds = false);
/** Preprocesses and resizes the input to the size required to
* binarize the data
*
* @param x input vectors, size n * d
* @return output vectors, size n * bits. May be the same pointer
* as x, otherwise it should be deleted by the caller
*/
const float *apply_preprocess (idx_t n, const float *x) const;
virtual void set_typename () override;
virtual void train (idx_t n, const float *x) override;
virtual void add (idx_t n, const float *x) override;
virtual void search (
idx_t n,
const float *x, idx_t k,
float *distances,
idx_t *labels) const override;
virtual void reset() override;
/// transfer the thresholds to a pre-processing stage (and unset
/// train_thresholds)
void transfer_thresholds (LinearTransform * vt);
virtual ~IndexLSH () {}
IndexLSH ();
};
}
#endif
faiss::RandomRotationMatrix
Randomly rotate a set of vectors.
Definition: VectorTransform.h:113
faiss::IndexLSH::bytes_per_vec
int bytes_per_vec
nb of 8-bits per encoded vector
Definition: IndexLSH.h:29
faiss::IndexLSH::thresholds
std::vector< float > thresholds
thresholds to compare with
Definition: IndexLSH.h:35
faiss::IndexLSH
Definition: IndexLSH.h:25
faiss::IndexLSH::train_thresholds
bool train_thresholds
whether we train thresholds or use 0
Definition: IndexLSH.h:31
faiss::IndexLSH::search
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override
Definition: IndexLSH.cpp:137
faiss::Index::d
int d
vector dimension
Definition: Index.h:66
faiss::IndexLSH::rrot
RandomRotationMatrix rrot
optional random rotation
Definition: IndexLSH.h:33
faiss::IndexLSH::transfer_thresholds
void transfer_thresholds(LinearTransform *vt)
Definition: IndexLSH.cpp:169
faiss::LinearTransform
Definition: VectorTransform.h:78
faiss::Index::idx_t
long idx_t
all indices are this type
Definition: Index.h:64
faiss::IndexLSH::reset
virtual void reset() override
removes all elements from the database.
Definition: IndexLSH.cpp:182
faiss::IndexLSH::add
virtual void add(idx_t n, const float *x) override
Definition: IndexLSH.cpp:124
faiss::IndexLSH::train
virtual void train(idx_t n, const float *x) override
Definition: IndexLSH.cpp:94
faiss::IndexLSH::nbits
int nbits
nb of bits per vector
Definition: IndexLSH.h:28
faiss::Index
Definition: Index.h:61
faiss::IndexLSH::apply_preprocess
const float * apply_preprocess(idx_t n, const float *x) const
Definition: IndexLSH.cpp:59
faiss::IndexLSH::rotate_data
bool rotate_data
whether to apply a random rotation to input
Definition: IndexLSH.h:30
faiss::IndexLSH::codes
std::vector< uint8_t > codes
encoded dataset
Definition: IndexLSH.h:38