mathru/algebra/linear/matrix/general/
relative_eq.rs

1use crate::algebra::abstr::AbsDiffEq;
2use crate::algebra::abstr::Field;
3use crate::algebra::abstr::RelativeEq;
4use crate::algebra::abstr::Scalar;
5use crate::algebra::linear::matrix::General;
6
7impl<T> RelativeEq for General<T>
8where
9    T: Field + Scalar + AbsDiffEq<Epsilon = T> + RelativeEq,
10{
11    fn default_max_relative() -> T {
12        T::default_max_relative()
13    }
14
15    /// A test for equality that uses a relative comparison if the values are far apart.
16    fn relative_eq(
17        &self,
18        other: &General<T>,
19        epsilon: Self::Epsilon,
20        max_relative: Self::Epsilon,
21    ) -> bool {
22        if self.dim() != other.dim() {
23            return false;
24        }
25
26        if self.data.len() != other.data.len() {
27            return false;
28        }
29
30        for (a, b) in self.iter().zip(other.iter()) {
31            if a.relative_ne(b, epsilon, max_relative) {
32                return false;
33            }
34        }
35        true
36    }
37}