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

Method encode

src/ailego/algorithm/binary_quantizer.cc:40–57  ·  view source on GitHub ↗

Quantize data: encode the float input to uint32_t output

Source from the content-addressed store, hash-verified

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

Callers 10

embedMethod · 0.45
embedMethod · 0.45
encode_recordMethod · 0.45
transformMethod · 0.45
transformMethod · 0.45
convertMethod · 0.45
encode_recordMethod · 0.45
SerializeToJsonObjectFunction · 0.45
TESTFunction · 0.45
TESTFunction · 0.45

Calls

no outgoing calls

Tested by 2

TESTFunction · 0.36
TESTFunction · 0.36