10 #include "IndexBinaryFromFloat.h"
18 IndexBinaryFromFloat::IndexBinaryFromFloat() {}
20 IndexBinaryFromFloat::IndexBinaryFromFloat(Index *index)
21 : IndexBinary(index->d),
28 IndexBinaryFromFloat::~IndexBinaryFromFloat() {
35 constexpr
idx_t bs = 32768;
36 std::unique_ptr<float[]> xf(
new float[bs *
d]);
38 for (
idx_t b = 0; b < n; b += bs) {
39 idx_t bn = std::min(bs, n - b);
42 index->
add(bn, xf.get());
53 int32_t *distances,
idx_t *labels)
const {
54 constexpr
idx_t bs = 32768;
55 std::unique_ptr<float[]> xf(
new float[bs *
d]);
56 std::unique_ptr<float[]> df(
new float[bs * k]);
58 for (
idx_t b = 0; b < n; b += bs) {
59 idx_t bn = std::min(bs, n - b);
62 index->
search(bn, xf.get(), k, df.get(), labels + b * k);
63 for (
int i = 0; i < bn * k; ++i) {
64 distances[b * k + i] = int32_t(std::round(df[i] / 4.0));
70 std::unique_ptr<float[]> xf(
new float[n *
d]);
73 index->
train(n, xf.get());
void add(idx_t n, const uint8_t *x) override
virtual void reset()=0
removes all elements from the database.
bool own_fields
Whether object owns the index pointer.
virtual void train(idx_t n, const float *x)
bool is_trained
set if the Index does not require training, or if training is done already
int code_size
number of bytes per vector ( = d / 8 )
Index::idx_t idx_t
all indices are this type
void search(idx_t n, const uint8_t *x, idx_t k, int32_t *distances, idx_t *labels) const override
virtual void add(idx_t n, const float *x)=0
idx_t ntotal
total nb of indexed vectors
virtual void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const =0
void reset() override
Removes all elements from the database.
idx_t ntotal
total nb of indexed vectors
void binary_to_real(size_t d, const uint8_t *x_in, float *x_out)
void train(idx_t n, const uint8_t *x) override