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

Function make_normalized_vectors

nodedb-codec/src/spherical.rs:248–263  ·  view source on GitHub ↗
(n: usize, dims: usize)

Source from the content-addressed store, hash-verified

246 use super::*;
247
248 fn make_normalized_vectors(n: usize, dims: usize) -> Vec<f32> {
249 let mut data = Vec::with_capacity(n * dims);
250 for i in 0..n {
251 let mut vec: Vec<f32> = (0..dims)
252 .map(|d| ((i * dims + d) as f32 * 0.1).sin())
253 .collect();
254 let norm: f32 = vec.iter().map(|x| x * x).sum::<f32>().sqrt();
255 if norm > 0.0 {
256 for v in &mut vec {
257 *v /= norm;
258 }
259 }
260 data.extend_from_slice(&vec);
261 }
262 data
263 }
264
265 #[test]
266 fn empty_roundtrip() {

Callers 3

normalized_roundtripFunction · 0.85
compression_ratioFunction · 0.85
normalization_checkFunction · 0.85

Calls 2

collectMethod · 0.80
iterMethod · 0.45

Tested by 3

normalized_roundtripFunction · 0.68
compression_ratioFunction · 0.68
normalization_checkFunction · 0.68