Code Monkey home page Code Monkey logo

Comments (3)

jakevdp avatar jakevdp commented on August 25, 2024

Hi - thanks for the question! This kind of difference is expected: in general, floating point operations are only accurate to within a particular precision that depends on the width of the float representation. When you compute the "same" result in two ways, the results will not in general be bitwise-equivalent. JIT-compilation replaces your original sequence of operations with a more efficient compiled kernel, and so in general you should not expect bitwise-equivalent outputs.

You can see the approximate expected precision using finfo:

In [1]: import numpy as np

In [2]: np.finfo(np.float64).eps
Out[2]: np.float64(2.220446049250313e-16)

The differences you're seeing are consistent with those expectations.

from jax.

jakevdp avatar jakevdp commented on August 25, 2024

Also, a side note: you might wonder why the compiler doesn't just simplify x + 0 * y to x: the reason for this is that for floating point math, these two expressions may return different results! For example, if you plug-in y = np.inf or y = np.nan, the first and second expression are not equivalent.

from jax.

mattjj avatar mattjj commented on August 25, 2024

I think we should probably close this as working-as-intended, and Jake's answer covers the reasoning well.

from jax.

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.