Function russell_lab::check::array_approx_eq

source ·
pub fn array_approx_eq<T>(u: &[T], v: &[T], tol: f64)
where T: Num + NumCast + Copy,
Expand description

Panics if two arrays (vectors) are not approximately equal to each other

§Panics

  1. Will panic if the dimensions are different
  2. Will panic if NAN, INFINITY, or NEG_INFINITY is found
  3. Will panic if the absolute difference of components is greater than the tolerance

§Examples

§Accepts small error

use russell_lab::array_approx_eq;

fn main() {
    let u = vec![3.0000001, 2.0];
    let v = vec![3.0,       2.0];
    array_approx_eq(&u, &v, 1e-6);
}

§Panics on different value

use russell_lab::array_approx_eq;

fn main() {
    let u = vec![3.0000001, 2.0];
    let v = vec![4.0,       2.0];
    array_approx_eq(&u, &v, 1e-6);
}