Repository navigation
API: Refactor argmax and argmin - #614
Merged
Merged
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #614 +/- ##
==========================================
- Coverage 91.55% 90.86% -0.69%
==========================================
Files 20 20
Lines 3516 3546 +30
==========================================
+ Hits 3219 3222 +3
- Misses 297 324 +27 |
Collaborator
|
I think the comments from the GitHub bot are valid in this PR and should be addressed. |
mtsokol
force-pushed
the
new-argmax-argmin
branch
from
January 2, 2024 09:21
4f56751 to
cae0fe7
Compare
Collaborator
Author
Hi @hameerabbasi, |
Collaborator
|
Thanks for your awesome work on this @mtsokol. |
hameerabbasi
pushed a commit
that referenced
this pull request
Oct 7, 2026
`_arg_minmax_common` never normalized the axis, and its bounds check only
covered one side (`axis >= x.ndim`), so a negative axis reached the
transpose and reshape logic untouched. The initial `list.pop(axis)`
happens to work for `-1`, but the final un-transpose does
`new_transpose.insert(axis, new_transpose.pop(0))`, which for `-1`
inserts before the last element instead of at the end. The reduced axis
ends up in front.
Measured against numpy on a (2, 3) array:
axis=1 numpy [[1], [0]] (2, 1) sparse [[1], [0]] (2, 1)
axis=-1 numpy [[1], [0]] (2, 1) sparse [[1, 0]] (1, 2)
A 1-D array with `axis=-1` raised `ValueError: shape must be an
non-negative integer...` where numpy returns a value, and `axis=-5` on a
2-D array leaked `IndexError: pop index out of range` instead of a
message naming the bounds.
`normalize_axis` is already imported in this module and every other
axis-taking function in it uses it: `concatenate`, `stack`, `roll`,
`diagonal`, `expand_dims` and `flip`. This was the only one left out,
which also matches the history: the reductions got this treatment in
#118/#119 and `diagonal` in #955, while `argmax`/`argmin` arrived later
in #614 and were never covered. The existing tests parametrize `axis`
over `[None, 0, 1, 2]`, so no negative axis was ever exercised.
The wording of the out-of-bounds `ValueError` is kept so that
`test_argmax_argmin_constraint` still passes, including the 0-D case.
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.
Hi @hameerabbasi,
This PR refactors the current implementation of
argmaxandargmin. It removes "only 0.0 fill value" and "all non-fill values greater/less than the fill value" constraints. It also makes the core of the function jittable.First #613 needs to be merged.