Repository navigation
fix: Compile non-finite constants in JIT programs - #153
Merged
polvalente merged 1 commit intoOct 23, 2026
Merged
Conversation
georgeguimaraes
force-pushed
the
fix/infinite-constants
branch
from
October 19, 2026 18:16
1b94a98 to
1795a71
Compare
polvalente
approved these changes
Oct 20, 2026
Nx keeps the IEEE 754 special values as atoms: :infinity, :neg_infinity and :nan. In compiled programs, to_native/1 multiplied each constant value by 1.0 to make the NIF wire format, and this raised ArithmeticError for an atom. Erlang floats cannot hold NaN or infinity, so the atoms now go to the NIF as they are. A decoder in compiler.hpp maps them to the C double values infinity, -infinity and quiet NaN. The new tests cover the three atoms in f32, f16 and bf16, and check the values of the results.
georgeguimaraes
force-pushed
the
fix/infinite-constants
branch
from
October 23, 2026 13:06
a2cd182 to
8538d2b
Compare
polvalente
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A compiled function that contains an infinite or NaN constant fails when it compiles:
Nx keeps the special values as atoms:
:infinity,:neg_infinityand:nan.to_native/1multiplied each constant value by1.0to make the NIF wire format, and this raised for an atom.Erlang floats cannot hold NaN or infinity, so the atoms now go to the NIF as they are. A
fine::Decoderforstd::tuple<double, mlx::core::Dtype>incompiler.hppmaps them to the C double values infinity, -infinity and quiet NaN. Other constants do not change.The new tests in
test/emlx/compiler_test.exscover the three atoms in f32, f16 and bf16. They check the values of the results, including NaN propagation. The full suite passes: 2697 tests, 7 excluded.