Skip to content

Reject NaN in scalar sign assertions - #471

Open
dhairyajangir wants to merge 1 commit into
google-deepmind:mainfrom
dhairyajangir:fix/scalar-sign-nan
Open

dhairyajangir wants to merge 1 commit into
google-deepmind:mainfrom
dhairyajangir:fix/scalar-sign-nan

Conversation

@dhairyajangir

Copy link
Copy Markdown

NaN currently passes assert_scalar_positive, assert_scalar_non_negative, and assert_scalar_negative: each helper rejects the opposite relation, and every ordered comparison with NaN is false. This lets an invalid scalar satisfy mutually exclusive sign assertions.

Check each required relation directly and negate its result, consistent with assert_scalar_in. Existing error messages, scalar type checks, signed-zero behavior and permitted infinities remain unchanged.

Validation on Linux, Python 3.12.14, JAX/JAXlib 0.11.2:

  • The three new NaN regression cases fail on the original implementation with AssertionError not raised and pass with the fix.
  • Full chex/_src/asserts_test.py: 313 passed, 48 skipped, 85 subtests passed. The baseline has the same 48 skips.
  • Assertion-module coverage: 90% with branch measurement enabled.
  • Eighteen manual boundary controls for signed zeros, infinities and booleans passed.
  • Repository Flake8 error/spacing checks on both changed files and source/wheel builds passed.
  • Targeted Pylint using the repository configuration reports the same existing refactor diagnostics as the base; no new diagnostics.

The complete multi-version test.sh workflow and documentation build were not run locally.

Developed, tested, and independently reviewed with Codex assistance.

Check the required ordering relation so unordered NaN values fail positive, non-negative, and negative scalar assertions. Add a regression for each assertion.

Validation: 3 regressions fail before and pass after; full assertions suite 313 passed, 48 existing skips; boundary controls, targeted lint and sdist/wheel builds pass.

Developed with Codex assistance.
@google-cla

google-cla Bot commented Oct 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

1 participant