Similarly, premature underflow can occur when the argument has small magnitude elements and axis is not None.
I can work around it if need be (e.g. manually scale), but can linalg.norm avoid premature under/overflow regardless of axis?
import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info); scipy.show_config()
1.13.0.dev0+1376.8360bac 1.26.0 sys.version_info(major=3, minor=11, micro=6, releaselevel='final', serial=0)
Build Dependencies:
blas:
detection method: pkgconfig
found: true
include directory: /Users/matthaberland/miniforge3/envs/scipy-dev/include
lib directory: /Users/matthaberland/miniforge3/envs/scipy-dev/lib
name: openblas
openblas configuration: USE_64BITINT=0 DYNAMIC_ARCH=0 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK=0 NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP=1 VORTEX MAX_THREADS=128
pc file directory: /Users/matthaberland/miniforge3/envs/scipy-dev/lib/pkgconfig
version: 0.3.24
lapack:
detection method: pkgconfig
found: true
include directory: /Users/matthaberland/miniforge3/envs/scipy-dev/include
lib directory: /Users/matthaberland/miniforge3/envs/scipy-dev/lib
name: openblas
openblas configuration: USE_64BITINT=0 DYNAMIC_ARCH=0 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK=0 NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP=1 VORTEX MAX_THREADS=128
pc file directory: /Users/matthaberland/miniforge3/envs/scipy-dev/lib/pkgconfig
version: 0.3.24
pybind11:
detection method: pkgconfig
include directory: /Users/matthaberland/miniforge3/envs/scipy-dev/include
name: pybind11
version: 2.11.1
Compilers:
c:
args: -ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -isystem,
/Users/matthaberland/miniforge3/envs/scipy-dev/include, -D_FORTIFY_SOURCE=2,
-isystem, /Users/matthaberland/miniforge3/envs/scipy-dev/include
commands: arm64-apple-darwin20.0.0-clang
linker: ld64
linker args: -Wl,-pie, -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs,
-Wl,-rpath,/Users/matthaberland/miniforge3/envs/scipy-dev/lib, -L/Users/matthaberland/miniforge3/envs/scipy-dev/lib,
-ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -isystem,
/Users/matthaberland/miniforge3/envs/scipy-dev/include, -D_FORTIFY_SOURCE=2,
-isystem, /Users/matthaberland/miniforge3/envs/scipy-dev/include
name: clang
version: 15.0.7
c++:
args: -ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -stdlib=libc++,
-fvisibility-inlines-hidden, -fmessage-length=0, -isystem, /Users/matthaberland/miniforge3/envs/scipy-dev/include,
-D_FORTIFY_SOURCE=2, -isystem, /Users/matthaberland/miniforge3/envs/scipy-dev/include
commands: arm64-apple-darwin20.0.0-clang++
linker: ld64
linker args: -Wl,-pie, -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs,
-Wl,-rpath,/Users/matthaberland/miniforge3/envs/scipy-dev/lib, -L/Users/matthaberland/miniforge3/envs/scipy-dev/lib,
-ftree-vectorize, -fPIC, -fPIE, -fstack-protector-strong, -O2, -pipe, -stdlib=libc++,
-fvisibility-inlines-hidden, -fmessage-length=0, -isystem, /Users/matthaberland/miniforge3/envs/scipy-dev/include,
-D_FORTIFY_SOURCE=2, -isystem, /Users/matthaberland/miniforge3/envs/scipy-dev/include
name: clang
version: 15.0.7
cython:
commands: cython
linker: cython
name: cython
version: 3.0.4
fortran:
args: -march=armv8.3-a, -ftree-vectorize, -fPIC, -fno-stack-protector, -O2, -pipe,
-isystem, /Users/matthaberland/miniforge3/envs/scipy-dev/include
commands: /Users/matthaberland/miniforge3/envs/scipy-dev/bin/arm64-apple-darwin20.0.0-gfortran
linker: ld64
linker args: -Wl,-pie, -Wl,-headerpad_max_install_names, -Wl,-dead_strip_dylibs,
-Wl,-rpath,/Users/matthaberland/miniforge3/envs/scipy-dev/lib, -L/Users/matthaberland/miniforge3/envs/scipy-dev/lib,
-march=armv8.3-a, -ftree-vectorize, -fPIC, -fno-stack-protector, -O2, -pipe,
-isystem, /Users/matthaberland/miniforge3/envs/scipy-dev/include
name: gcc
version: 12.3.0
pythran:
include directory: ../../../miniforge3/envs/scipy-dev/lib/python3.11/site-packages/pythran
version: 0.14.0
Machine Information:
build:
cpu: aarch64
endian: little
family: aarch64
system: darwin
cross-compiled: false
host:
cpu: aarch64
endian: little
family: aarch64
system: darwin
Python Information:
path: /Users/matthaberland/miniforge3/envs/scipy-dev/bin/python
version: '3.11'
Describe your issue.
I'm working on adding an
axisargument toscipy.stats.pearsonr. It usesscipy.linalg.norminstead of (e.g.)np.linalg.normbecausescipy.linalg.normtends to avoid premature overflow.Unfortunately, that advantage is lost when
axisis notNone.Similarly, premature underflow can occur when the argument has small magnitude elements and
axisis notNone.I can work around it if need be (e.g. manually scale), but can
linalg.normavoid premature under/overflow regardless ofaxis?Reproducing Code Example
Error message
SciPy/NumPy/Python version and system information