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)
| 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. |
no test coverage detected