MCPcopy Create free account
hub / github.com/Rustixir/darkbird / vector_addition

Method vector_addition

src/darkbird/storage_vector.rs:289–298  ·  view source on GitHub ↗

Performs element-wise addition of two vectors stored in the darkbird storage. The vectors are identified by their keys (IDs). The function returns the result of the addition as a new vector. The vectors must have the same number of dimensions. # Arguments `key1` - The key (ID) of the first vector to be added. `key2` - The key (ID) of the second vector to be added. # Returns An `Option` contai

(&self, vec_id1: &str, vec_id2: &str)

Source from the content-addressed store, hash-verified

287 /// assert_eq!(result, Some(vec![5.0, 7.0, 9.0]));
288 /// ```
289 pub fn vector_addition(&self, vec_id1: &str, vec_id2: &str) -> Option<Vector> {
290 let v1 = self.vcache.get(vec_id1)?;
291 let v2 = self.vcache.get(vec_id2)?;
292 if v1.0.len() != v2.0.len() {
293 return None;
294 }
295
296 let v = v1.0.iter().zip(v2.0.iter()).map(|(x, y)| x + y).collect::<Vec<f32>>();
297 return Some(Vector(v))
298 }
299
300
301 /// Performs element-wise subtraction of two vectors stored in the storage.

Callers 1

vec_additionMethod · 0.80

Calls 4

VectorClass · 0.85
lenMethod · 0.80
getMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected