MCPcopy Create free account
hub / github.com/VectorDB-NTU/RaBitQ-Library / main

Function main

sample/cpp/quantizer.cpp:4–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "rabitqlib/utils/rotator.hpp"
3
4int main() {
5 // generate random data
6 size_t dim = 128;
7 size_t bit = 4;
8
9 float* data = new float[dim];
10 for (size_t i = 0; i < dim; i++) {
11 data[i] = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
12 }
13
14 // choose rotator
15 rabitqlib::Rotator<float>* rotator = rabitqlib::choose_rotator<float>(dim);
16
17 size_t padded_dim = rotator->size();
18 float* rotated_data = new float[padded_dim];
19 rotator->rotate(data, rotated_data);
20
21 // print rotated_data
22 for (size_t i = 0; i < padded_dim; i++) {
23 std::cout << rotated_data[i] << " ";
24 }
25 std::cout << '\n';
26
27 // quantize
28 uint8_t* code = new uint8_t[padded_dim];
29 float delta = 0;
30 float vl = 0;
31 rabitqlib::quant::quantize_scalar(rotated_data, padded_dim, bit, code, delta, vl);
32
33 // [Note: we don't need to store vl as vl = - delta * (2^bit - 1) / 2]
34
35 // reconstruct
36 float* reconstructed_data = new float[padded_dim];
37 rabitqlib::quant::reconstruct_vec(code, delta, vl, padded_dim, reconstructed_data);
38
39 // print reconstructed_data
40 for (size_t i = 0; i < padded_dim; i++) {
41 std::cout << reconstructed_data[i] << " ";
42 }
43 std::cout << '\n';
44
45 delete rotator;
46 delete[] data;
47 delete[] rotated_data;
48 delete[] code;
49 delete[] reconstructed_data;
50}

Callers

nothing calls this directly

Calls 4

quantize_scalarFunction · 0.85
reconstruct_vecFunction · 0.85
sizeMethod · 0.45
rotateMethod · 0.45

Tested by

no test coverage detected