Repository navigation
Add bits and smallest_normal to finfo - #3679
Merged
Merged
Conversation
The array API finfo object requires `bits` (the number of bits of the type) and `smallest_normal` (the smallest positive normal number), in addition to the existing min/max/eps/dtype. These are also needed by hypothesis' array API strategy (hypothesis.extra.array_api), which reads `finfo(dtype).bits` and `finfo(dtype).smallest_normal` and currently raises AttributeError against mlx.core. Adds both fields to mlx::finfo and the Python binding. Also adds a `min()` (smallest normal) to the float16/bfloat16 numeric_limits specializations, which previously only defined lowest/max/epsilon.
1 task done
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.
Proposed changes
The array API
finfoobject requiresbits(number of bits of the type) andsmallest_normal(smallest positive normal number), in addition to themin/max/eps/dtypethatmlx.core.finfoalready exposes. This adds both.It is also a practical prerequisite for running the conformance suite against MLX:
hypothesis.extra.array_apireadsfinfo(dtype).bitsandfinfo(dtype).smallest_normalwhen generating float arrays, and currently raisesAttributeError: 'mlx.core.finfo' object has no attribute 'bits', which aborts data generation for every float test.Changes:
bitsandsmallest_normaltomlx::finfo(mlx/utils.h,mlx/utils.cpp) and to the Python binding (python/src/array.cpp).min()(smallest positive normal) to thefloat16_t/bfloat16_tnumeric_limitsspecializations inmlx/types/limits.h, which previously defined onlylowest()/max()/epsilon().float/doublealready inherit it fromstd::numeric_limits.test_finfoto coverbitsandsmallest_normal(vs NumPy for float32/float16, vs known IEEE values for bfloat16, and the real-component remap for complex64).Resulting values:
Checklist
clang-formatandblack(the formatters configured in.pre-commit-config.yaml) report no changes on the modified filestest_finfo)test_array.TestDtypespasses. Verified againstdata-apis/array-api-tests(ARRAY_API_TESTS_MODULE=mlx.core) that the previousfinfoAttributeErrorno longer occurs and real-float elementwise tests (e.g.test_ceil,test_floor) now run and pass where they previously aborted during data generation