MCPcopy Create free account
hub / github.com/alibaba/zvec / encode

Method encode

src/ailego/algorithm/binary_quantizer.cc:39–56  ·  view source on GitHub ↗

Quantize data: encode the float input to uint32_t output

Source from the content-addressed store, hash-verified

37
38//! Quantize data: encode the float input to uint32_t output
39void BinaryQuantizer::encode(const float *in, size_t dim, uint32_t *out) const {
40 for (size_t i = 0; i < dim; i += 32) {
41 size_t remain = i + 32 <= dim ? 32 : dim - i;
42 uint32_t data = 0;
43 uint32_t mask = 1;
44
45 for (size_t j = 0; j < remain; j++) {
46 if (in[i + j] >= threshold_) {
47 data |= mask;
48 }
49
50 mask <<= 1;
51 }
52
53 *out = data;
54 out++;
55 }
56}
57
58//! De-quantize data: decode the input uint32_t to float output
59//! bit value 1 will be mapped to 1.0

Callers 6

embedMethod · 0.45
embedMethod · 0.45
SerializeToJsonObjectFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45

Calls

no outgoing calls

Tested by 2

TESTFunction · 0.36
TESTFunction · 0.36