-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
BUG/ENH?: scipy.linalg.norm: overflow/underflow when axis
is provided
#20136
Comments
Lines 177 to 178 in fdf3b90
|
On top of what @lucascolley mentioned, NumPy does not use the safe norm from LAPACK but does its own unscaled dot product hence bypasses the safety guards. If you don't have too many cols/rows in the axis a for loop is an easy way out without too much of python overhead. |
Should we fix 2-norm working with axis? I can cook up something in C or Cython and Based on what we discussed over kron deprecation, not sure what it entails in terms of array api though since this is a central function and unlike kron we should support it and make it as general as possible, in my opinion. However if I cook something up in C or Cython not sure if it is even possible to support it. |
From what I understand, numpy should be able to use |
that sounds sensible - see data-apis/array-api#213 for the array API perspective. We'd probably rewrite If we can upstream all efficiency gains from the SciPy implementation to those (new) NumPy functions, we'll be able to simplify it to just one codepath (well, there'll be a codepath for if the namespace doesn't implement the |
Oh my, I typed too fast probably: openblas does not support the safe scaling yet apparently: OpenMathLib/OpenBLAS#4313. Until it is available there, probably difficult to use for both numpy and scipy but I would like to be convinced of the opposite by the BLAS gurus. Xref numpy issue numpy/numpy#19097 |
It doesn't have to use the BLAS code as all based on Anderson's work. We can write our own native version of nrm2 in C or Cython. Not sure if NumPy implements it since it is not using nrm2 even now. |
Overall judging by the discussions oat the array api, it seems to me the linalg parts are not well thought out. |
Describe your issue.
I'm working on adding an
axis
argument toscipy.stats.pearsonr
. It usesscipy.linalg.norm
instead of (e.g.)np.linalg.norm
becausescipy.linalg.norm
tends to avoid premature overflow.Unfortunately, that advantage is lost when
axis
is notNone
.Similarly, premature underflow can occur when the argument has small magnitude elements and
axis
is notNone
.I can work around it if need be (e.g. manually scale), but can
linalg.norm
avoid premature under/overflow regardless ofaxis
?Reproducing Code Example
Error message
SciPy/NumPy/Python version and system information
The text was updated successfully, but these errors were encountered: