use super::Tensor;
impl Tensor {
pub fn sum(&self) -> f32 {
self.data.iter().sum()
}
pub fn distance(&self, other: &Tensor) -> f32 {
f32::sqrt(self.iter().zip(other.iter()).map(|(x,y)| f32::powi(*y-*x, 2)).sum())
}
pub fn manhattan_distance(&self, other: &Tensor) -> f32 {
self.iter().zip(other.iter()).map(|(x,y)| f32::abs(*x-*y)).sum()
}
pub fn minkowsky_distance(&self, other: &Tensor, p: f32) -> f32 {
f32::powf(self.iter().zip(other.iter()).map(|(x,y)| f32::abs(*x-*y)).sum(), 1./p)
}
pub fn hamming_distance(&self, other: &Tensor) -> f32 {
self.iter().zip(other.iter()).map(|(x,y)| if *x!=*y {1.0} else {0.0}).sum()
}
}