-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
ENH: array comparison utils show calculations and indices of max errors #29395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
danra
wants to merge
13
commits into
numpy:main
Choose a base branch
from
danra:max_errors_indices
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+371
−180
Conversation
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
Recently, numpy#29112 added showing first mismatches indices, but assert_array_almost_equal.compare trips it up by returning a shape different from its input, causing an IndexError: ``` <...> if invalids.ndim != 0: if flagged.ndim > 0: > positions = np.argwhere(np.asarray(~flagged))[invalids] E IndexError: boolean index did not match indexed array along axis 0; size of axis is 3 but size of corresponding boolean axis is 2 ``` (traceback shown using pytest --full-trace)
A nice cleanup (newer, similar inf handling already exists now in assert_array_compare), and resolves the shape mismatch issue. However, the removed logic was handling complex infs while the one isn't, causing the new test and an existing one (TestInterp::test_complex_interp) to now fail with RuntimeWarnings attempting to subtract the complex infs.
assert_array_compare now tests all inf values for matching position and value, including complex infs. Fixes the failing tests.
The behavior for real infs is the same is before. For complex infs, demonstrates that the behavior for mismatching values is now cleaner, showing a concise error message vs. previously displaying nan max errors. For complex infs with matching values, the behavior is the same as before, accepting them as equal (although internally they would now be filtered ahead of being passed to isclose, like real infs already had been).
Not needed since e6b68e5
Noticed the extra dimension while adding the index of the max error to assert_array_XXX_nulp output
Noticed these while attempting to append more content to the expected message, upon which the partial values started causing the regex to stop matching.
Resolves numpy#28827 - Verbose assertion errors raised by testing.assert_allclose and testing.assert_array_XXX now show the calculation and the indices of the maximum absolute and relative differences among the violations. - Assertion errors raised by assert_array_almost_equal_nulp and assert_array_max_ulp, which have no verbose toggle, now show the indices of the maximum ULP difference. The main complexity adding this feature was that one could not 'simply' replace `max` with `argmax` due to masking: the absolute differences is calculated after masking out infs and nans, and the relative differences are additionally calculated after masking out zero denominators.
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.
Resolves #28827
testing.assert_allclose
andtesting.assert_array_XXX
now show the calculation and the indices of the maximum absolute and relative differences among the violations.assert_array_almost_equal_nulp
andassert_array_max_ulp
, which have no verbose toggle, now show the indices of the maximum ULP difference.The main complexity adding this feature was that one could not 'simply' replace
max
withargmax
due to masking: the absolute differences is calculated after masking out infs and nans, and the relative differences are additionally calculated after masking out zero denominators.Notes to reviewer: