use crate::err::Error; use crate::fnc::util::math::vector::{ Add, Angle, CrossProduct, Divide, DotProduct, Magnitude, Multiply, Normalize, Project, Subtract, }; use crate::sql::{Number, Value}; pub fn add((a, b): (Vec, Vec)) -> Result { Ok(a.add(&b)?.into()) } pub fn angle((a, b): (Vec, Vec)) -> Result { Ok(a.angle(&b)?.into()) } pub fn divide((a, b): (Vec, Vec)) -> Result { Ok(a.divide(&b)?.into()) } pub fn cross((a, b): (Vec, Vec)) -> Result { Ok(a.cross(&b)?.into()) } pub fn dot((a, b): (Vec, Vec)) -> Result { Ok(a.dot(&b)?.into()) } pub fn magnitude((a,): (Vec,)) -> Result { Ok(a.magnitude().into()) } pub fn multiply((a, b): (Vec, Vec)) -> Result { Ok(a.multiply(&b)?.into()) } pub fn normalize((a,): (Vec,)) -> Result { Ok(a.normalize().into()) } pub fn project((a, b): (Vec, Vec)) -> Result { Ok(a.project(&b)?.into()) } pub fn subtract((a, b): (Vec, Vec)) -> Result { Ok(a.subtract(&b)?.into()) } pub mod distance { use crate::err::Error; use crate::fnc::util::math::vector::{ ChebyshevDistance, EuclideanDistance, HammingDistance, ManhattanDistance, MinkowskiDistance, }; use crate::sql::{Number, Value}; pub fn chebyshev((a, b): (Vec, Vec)) -> Result { Ok(a.chebyshev_distance(&b)?.into()) } pub fn euclidean((a, b): (Vec, Vec)) -> Result { Ok(a.euclidean_distance(&b)?.into()) } pub fn hamming((a, b): (Vec, Vec)) -> Result { Ok(a.hamming_distance(&b)?.into()) } pub fn mahalanobis((_, _): (Vec, Vec)) -> Result { Err(Error::FeatureNotYetImplemented { feature: "vector::distance::mahalanobis() function", }) } pub fn manhattan((a, b): (Vec, Vec)) -> Result { Ok(a.manhattan_distance(&b)?.into()) } pub fn minkowski((a, b, o): (Vec, Vec, Number)) -> Result { Ok(a.minkowski_distance(&b, o)?.into()) } } pub mod similarity { use crate::err::Error; use crate::fnc::util::math::vector::{CosineSimilarity, JaccardSimilarity, PearsonSimilarity}; use crate::sql::{Number, Value}; pub fn cosine((a, b): (Vec, Vec)) -> Result { Ok(a.cosine_similarity(&b)?.into()) } pub fn jaccard((a, b): (Vec, Vec)) -> Result { Ok(a.jaccard_similarity(&b)?.into()) } pub fn pearson((a, b): (Vec, Vec)) -> Result { Ok(a.pearson_similarity(&b)?.into()) } pub fn spearman((_, _): (Vec, Vec)) -> Result { Err(Error::FeatureNotYetImplemented { feature: "vector::similarity::spearman() function", }) } }