SciRuby / nmatrix

Dense and sparse linear algebra library for Ruby via SciRuby
Other
469 stars 133 forks source link

Check equality with tolerance #613

Closed v0dro closed 6 years ago

v0dro commented 6 years ago

If you're approximating a matrix and check element-wise accuracy with the original matrix, you frequently need to use equality with some tolerance. Having a function like be_within similar to rspec would be helpful.

For example:

n = NMatrix.random(8)
u,s,d = n.gesvd
assert n.be_within(0.0001, u.dot(s.dot(d)))
translunar commented 6 years ago

(n - u.dot(s.dot(d))) <= 0.0001