fix: return 0-D array for full reductions per Array API standard#932
Open
Abineshabee wants to merge 2 commits intopydata:mainfrom
Open
fix: return 0-D array for full reductions per Array API standard#932Abineshabee wants to merge 2 commits intopydata:mainfrom
Abineshabee wants to merge 2 commits intopydata:mainfrom
Conversation
Fixes pydata#921 - Remove if out.ndim == 0: return out[()] in SparseArray.reduce() which was converting 0-D COO arrays into NumPy scalars - Fix mean() to handle 0-D result uniformly without scalar branch - Fix _einsum_single() two scalar escape hatches to return 0-D COO - Update est_einsum.py scalar branches to use .todense() - Add TestArrayAPIReductions with 16 regression tests
for more information, see https://pre-commit.ci
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.
Fixes #921
Problem
sparse.sum()and all other full reductions (max,min,prod,mean,any,all,einsum) were returning a NumPy scalar instead of a 0-D array, violating the Array API standard.Root Cause
SparseArray.reduce()hadif out.ndim == 0: return out[()]which unwrapped the 0-D COO into a scalar._einsum_single()also had two explicit scalar return paths.Changes
_sparse_array.py— remove scalar unwrap inreduce(), unifymean()path_common.py— fix both scalar paths in_einsum_single()test_einsum.py— update scalar-output branches to use.todense()test_array_function.py— addTestArrayAPIReductionswith 16 regression testsTesting
6079 passed, 0 failed