Squared L2 norm of ternary trits scaled by `scale`.
(hot: &[u8], dim: usize, scale: f32)
| 41 | |
| 42 | /// Squared L2 norm of ternary trits scaled by `scale`. |
| 43 | fn 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)` |
| 50 | fn l2_from_dot(dot: i32, norm_a: f32, norm_b: f32, sa: f32, sb: f32) -> f32 { |
no test coverage detected