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

Function scaled_norm_sq

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

Squared L2 norm of ternary trits scaled by `scale`.

(hot: &[u8], dim: usize, scale: f32)

Source from the content-addressed store, hash-verified

41
42/// Squared L2 norm of ternary trits scaled by `scale`.
43fn scaled_norm_sq(hot: &[u8], dim: usize, scale: f32) -> f32 {
44 let trits = unpack_hot(hot, dim);
45 let count: i32 = trits.iter().map(|&t| (t != 0) as i32).sum();
46 scale * scale * count as f32
47}
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 {

Callers 2

Calls 3

unpack_hotFunction · 0.85
sumMethod · 0.80
iterMethod · 0.45

Tested by

no test coverage detected