Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does assert_approx_eq exists for ndarray?

I'm referring to the ndarray crate as well as the assert_approx_eq.

My question: Does something like assert_approx_eq exist for ndarray::Array2 etc.?

Currently I'm doing:

for it in mat_a.iter().zip(expect_mat_a.iter()) {
  let (af, bf) = it;
  assert_approx_eq!(af, bf);
}

This is works, but is sub-optimal.

like image 910
B0rk4 Avatar asked Jan 25 '26 17:01

B0rk4


1 Answers

Yes, ndarray has the optional feature approx and with it enabled, it supports the approx crate traits and macros.

use approx::assert_abs_diff_eq;

assert_abs_diff_eq!(af, bf);
like image 53
ramslök Avatar answered Jan 27 '26 10:01

ramslök



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!