scipy: BUG: linalg.sqrtm results different between version 1.11.1 and 1.11.2/1.11.3
Describe your issue.
There is a difference in the result of scipy.linalg.sqrtm
between version 1.11.1 and the following versions (to date: 1.11.2 and 1.11.3) for specific matrices. In the following code example, the error when calculating the square root of the matrix is infinitesimal in 1.11.1, but gigantic in 1.11.2 and 1.11.3. It seems that sqrtm
either produced a wrong result in earlier versions, or newer versions fail to calculate the square root correctly.
I could not create an example with a random matrix, which is why I made a repository with some data that produces the error: https://github.com/akug/mwe_scipy_sqrtm_bug
Thank you for your time and effort maintaining scipy, it’s a great library!
Reproducing Code Example
# See the repository at https://github.com/akug/mwe_scipy_sqrtm_bug for sample data
import numpy as np
from scipy.linalg import sqrtm
data = np.load("./sample_sqrtm_fails.npz")["array"]
out, error = sqrtm(data, disp=False)
print(error) # error in 1.11.2 and 1.11.3 is about 2.3e+24, but in 1.11.1 is 2.1e-28
Error message
# There is no error message, it just produces different results between versions
SciPy/NumPy/Python version and system information
1.11.3 1.26.0 sys.version_info(major=3, minor=11, micro=5, releaselevel='final', serial=0)
Build Dependencies:
blas:
detection method: pkgconfig
found: true
include directory: /usr/local/include
lib directory: /usr/local/lib
name: openblas
openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= HASWELL MAX_THREADS=2
pc file directory: /usr/local/lib/pkgconfig
version: 0.3.21.dev
lapack:
detection method: pkgconfig
found: true
include directory: /usr/local/include
lib directory: /usr/local/lib
name: openblas
openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= HASWELL MAX_THREADS=2
pc file directory: /usr/local/lib/pkgconfig
version: 0.3.21.dev
pybind11:
detection method: config-tool
include directory: unknown
name: pybind11
version: 2.11.0
Compilers:
c:
commands: cc
linker: ld.bfd
name: gcc
version: 10.2.1
c++:
commands: c++
linker: ld.bfd
name: gcc
version: 10.2.1
cython:
commands: cython
linker: cython
name: cython
version: 0.29.36
fortran:
commands: gfortran
linker: ld.bfd
name: gcc
version: 10.2.1
pythran:
include directory: ../../tmp/pip-build-env-358nkn7q/overlay/lib/python3.11/site-packages/pythran
version: 0.14.0
Machine Information:
build:
cpu: x86_64
endian: little
family: x86_64
system: linux
cross-compiled: false
host:
cpu: x86_64
endian: little
family: x86_64
system: linux
Python Information:
path: /opt/python/cp311-cp311/bin/python
version: '3.11'
About this issue
- Original URL
- State: open
- Created 8 months ago
- Reactions: 1
- Comments: 25 (23 by maintainers)
I believe I was using 1.12 when I first encountered this error, so it’s likely the problem persists.