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)
| 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 | /// |