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

Method vector_subtraction

src/darkbird/storage_vector.rs:341–350  ·  view source on GitHub ↗

Performs element-wise subtraction of two vectors stored in the storage. The vectors are identified by their keys (IDs). The function returns the result of the subtraction as a new vector. The vectors must have the same number of dimensions. # Arguments `key1` - The key (ID) of the minuend vector. `key2` - The key (ID) of the subtrahend vector. # Returns An `Option` containing the result of th

(&self, key1: &str, key2: &str)

Source from the content-addressed store, hash-verified

339 /// assert_eq!(result, Some(vec![-3.0, -3.0, -3.0]));
340 /// ```
341 pub fn vector_subtraction(&self, key1: &str, key2: &str) -> Option<Vector> {
342 let v1 = self.vcache.get(key1)?;
343 let v2 = self.vcache.get(key2)?;
344 if v1.0.len() != v2.0.len() {
345 return None;
346 }
347
348 let v = v1.0.iter().zip(v2.0.iter()).map(|(x, y)| x - y).collect::<Vec<f32>>();
349 return Some(Vector(v))
350 }
351
352 /// Performs scalar multiplication of a vector stored in the storage.
353 ///

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected