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

Function l2_from_dot

nodedb-codec/src/vector_quant/ternary/codec.rs:50–52  ·  view source on GitHub ↗

`‖a·sa - b·sb‖² ≈ sa²·‖a‖² + sb²·‖b‖² - 2·sa·sb·dot(a,b)`

(dot: i32, norm_a: f32, norm_b: f32, sa: f32, sb: f32)

Source from the content-addressed store, hash-verified

48
49/// `‖a·sa - b·sb‖² ≈ sa²·‖a‖² + sb²·‖b‖² - 2·sa·sb·dot(a,b)`
50fn l2_from_dot(dot: i32, norm_a: f32, norm_b: f32, sa: f32, sb: f32) -> f32 {
51 (norm_a + norm_b - 2.0 * sa * sb * dot as f32).max(0.0)
52}
53
54/// Expand cold-packed bits to hot if needed.
55fn ensure_hot(packed: &[u8], quant_mode: u16, dim: usize) -> std::borrow::Cow<'_, [u8]> {

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected