BUG: Allow integer inputs for pow-related functions in array_api
#20807
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.
Backport of 20762.
Updates
xp.pow()
,x.__pow__()
,x.__ipow()__
andx.__rpow()__
to accept integer inputs. Partially resolves #20752. @asmeurer initially wrote these when the Array API spec said only float inputs were allowed, but it has since changed to accept all numeric dtypes.This PR notably only enables integer arrays to work with integer arrays, and not allow the mix of integer arrays with floating arrays, which is out-of-scope for the Array API (i.e. mixing non-promotable dtypes together). This is to keep with the
numpy.array_api
philosophy of not implementing beyond the spec... and conveniently already covered nicely by the internal use ofresult_type()
.This is smoke tested via the
xptests/test_operators_and_elementwise_functions.py::test_pow
test case(s) inarray-api-tests
. Better testing would be ideal, but these pow-related functions are using NumPy proper's pow-related functions anywho.