Giter VIP home page Giter VIP logo

Comments (5)

FarnazH avatar FarnazH commented on May 28, 2024

@tovrstra It is safe to say that we use numpy.testing.assert_array_almost_equal for almost all cases and numpy.testing.assert_allclose in rare cases when precision is required?

from iodata.

tovrstra avatar tovrstra commented on May 28, 2024

The Numpy docs recommend using assert_allclose instead of assert_almost_equal. See https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.testing.assert_almost_equal.html

from iodata.

PaulWAyers avatar PaulWAyers commented on May 28, 2024

Or maybe use the Python (not numpy) intrinsic:
math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)

Probably clunkier without the "assert" built in....

from iodata.

FanwangM avatar FanwangM commented on May 28, 2024

The numpy.testing.assert_allclose is asymmetric, which means that a=b might result b not equal a. For example (taken from https://stackoverflow.com/questions/48156460/isclose-function-in-numpy-is-different-from-math)

a = 0.142253
b = 0.142219
rel_tol = 1e-4
abs_tol = 1.9776e-05
# test failed
numpy.testing.assert_allclose(actual=a, desired=b, rtol=rel_tol, atol=abs_tol)
# test passed
np.testing.assert_allclose(actual=b, desired=a, rtol=rel_tol, atol=abs_tol)

But for math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0) , it seems only support scaler instead of numpy array.

a = np.linspace(0., 1., 100).reshape(10, 10)
b = np.arcsin(np.sin(a))
# this will raise an TypeError
math.isclose(a, b, rel_tol=1e-09, abs_tol=0.0)

Once an agreement is reached, I can start working on this.

from iodata.

PaulWAyers avatar PaulWAyers commented on May 28, 2024

It sounds to me like you should use numpy.testing.assert_allclose

The nuance of directionality is unlikely to be important; the example is a rather evil one. To the extent that you can identify one value which is "reference" and one which is "approximate" you should make sure the "desired" is the reference.

from iodata.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.