Skip to main content

conspire/math/tensor/norm/
mod.rs

1#[cfg(test)]
2mod test;
3
4use super::{Scalar, Tensor};
5
6/// Different norms for tensors.
7#[derive(Debug, Default)]
8pub enum Norm {
9    Chebyshev,
10    #[default]
11    Euclidean,
12    Manhattan,
13    Minkowski(Scalar),
14}
15
16impl Norm {
17    pub fn apply<T: Tensor>(&self, t: &T) -> Scalar {
18        match self {
19            Self::Chebyshev => t.norm_inf(),
20            Self::Euclidean => t.norm(),
21            Self::Manhattan => t.norm_l1(),
22            Self::Minkowski(p) => t.norm_p(*p),
23        }
24    }
25}