You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The "non-standard" norms in norm(), i.e., ord < 0 or ord > 2 on a 1-d array (so it's a vector norm and not a matrix norm), incorrectly promote the result to float64 regardless of the input dtype. This is because the code just manually implements it with
I have a fix for this, but I'm a little confused about what I should add to the tests. Specifically I'm not clear in the current tests why this isn't being tested already.
asmeurer
added a commit
to asmeurer/numpy
that referenced
this issue
Feb 18, 2022
Previously it would always give float64 because an internal calculation
involved a NumPy scalar and a Python float. The fix is to use a 0-D array
instead of a NumPy scalar so that it type promotes with the float correctly.
Fixesnumpy#21083
I don't have a test for this yet because I'm unclear how exactly to test it.
* Fix computation of numpy.array_api.linalg.vector_norm
Various pieces were incorrect due to a lack of complete coverage of this
function in the array API test suite.
* Fix the output dtype nonstandard vector norm()
Previously it would always give float64 because an internal calculation
involved a NumPy scalar and a Python float. The fix is to use a 0-D array
instead of a NumPy scalar so that it type promotes with the float correctly.
Fixes#21083
I don't have a test for this yet because I'm unclear how exactly to test it.
* Clean up the numpy.array_api.linalg.vector_norm code a little bit
Describe the issue:
The "non-standard" norms in
norm()
, i.e.,ord < 0
orord > 2
on a 1-d array (so it's a vector norm and not a matrix norm), incorrectly promote the result to float64 regardless of the input dtype. This is because the code just manually implements it withat
numpy/numpy/linalg/linalg.py
Line 2559 in 1168868
Specifically, the last line
ret **= (1 / ord)
promotes the result to float64 becauseret
is a scalar and1/ord
is a Python float.Reproduce the code example:
Error message:
No response
NumPy/Python version information:
The text was updated successfully, but these errors were encountered: