MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / sign_pack

Function sign_pack

nodedb-codec/src/vector_quant/rabitq.rs:90–99  ·  view source on GitHub ↗

Pack `dim` signs from `rotated` (negative = 1-bit, non-negative = 0-bit) into ceil(dim/8) bytes, LSB-first.

(rotated: &[f32], dim: usize)

Source from the content-addressed store, hash-verified

88/// Pack `dim` signs from `rotated` (negative = 1-bit, non-negative = 0-bit)
89/// into ceil(dim/8) bytes, LSB-first.
90fn sign_pack(rotated: &[f32], dim: usize) -> Vec<u8> {
91 let nbytes = dim.div_ceil(8);
92 let mut out = vec![0u8; nbytes];
93 for (i, &v) in rotated.iter().take(dim).enumerate() {
94 if v < 0.0 {
95 out[i / 8] |= 1 << (i % 8);
96 }
97 }
98 out
99}
100
101/// Dequantize sign-packed bits back to ±1 values (for dot_quantized calc).
102fn sign_unpack(packed: &[u8], dim: usize) -> Vec<f32> {

Callers 2

encode_innerMethod · 0.85
prepare_queryMethod · 0.85

Calls 2

takeMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected