Skip to content

Handle scalar bfloat16 leaves in ULP assertions - #476

Open
sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/scalar-bfloat16-ulp-comparisons-20261006
Open

sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/scalar-bfloat16-ulp-comparisons-20261006

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Fixes #475.

Convert host scalar operands to at least one dimension before reinterpreting their storage in the bfloat16 ULP helper. NumPy rejects the existing item-size-changing view for 0D arrays, so identical scalar leaves currently raise a ValueError. Values, tolerances and the existing ULP arithmetic are unchanged.

Validation

python -m pytest -q chex/_src/asserts_test.py chex/_src/asserts_scalar_ulp_test.py -k 'ulp or ScalarBfloat'

32 selected tests passed; 349 unrelated tests were deselected. This includes all existing ULP tests and 23 new cases. On unchanged source, 22 new scalar cases fail and the array/other-dtype control passes.

Tests cover host and JAX scalars, nested leaves, zero and signed values, exact/one/two-ULP boundaries, and host assertions on a jitted reduction's scalar output. The full Chex suite and multi-device execution were not run. No new support for assertions inside JIT or changed mixed-dtype policy is claimed.

Tested on macOS CPU. New test formatting, scoped static checks, syntax checks and git diff --check pass. No dependency or workflow changes.

Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ULP assertions raise a dtype-view error on scalar bfloat16 values

1 participant