scipy: BUG: scipy.linalg.blas.dnrm2 may return error result when incx < 0

Describe your issue.

scipy.linalg.blas.dnrm2 may returns error result when incx<0 : input array:[10, 10, 10, 10, 10, 10, 10, 10, 10] n:5 offx:3 incx:-1 the scipy.linalg.blas.dnrm2 function returns result 20.0

If we calculate the result follow the document in netlib:
https://netlib.org/lapack/explore-html/df/d28/group__single__blas__level1_gab5393665c8f0e7d5de9bd1dd2ff0d9d0.html

we will get result sqrt(500) -> 22.36

Reproducing Code Example

import os
import time
import numpy as np
from scipy import linalg

x = [10,10,10,10,10,10,10,10,10]
n = 5
offx = 3
incx = -1
print(f"x:{x}")
print(f"n:{n}")
print(f"offx:{offx}")
print(f"incx:{incx}") 
res = linalg.blas.dnrm2(x, n, offx, incx)
print(f"res:{res}")

Error message

x:[10, 10, 10, 10, 10, 10, 10, 10, 10]
n:5
offx:3
incx:-1
res:20.0

SciPy/NumPy/Python version information

1.7.3 1.21.5 sys.version_info(major=3, minor=7, micro=5, releaselevel=‘final’, serial=0)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (20 by maintainers)

Commits related to this issue

Most upvoted comments

True, my emphasis is on the fact that while we are defensive about LAPACK version, which perfectly fine, we should be careful about indirect consequences of bumping other things up.

Otherwise I don’t think we have urgency or good reasons to bump up all the way (though 3.10 included Anderson’s safety scaling paradigm which are really good but they can wait).

working on it, given that the “new way” in https://github.com/scipy/scipy/pull/20074 may need a bit more time

what is the lowest version for SciPy wheel

looks like 0.3.21.dev if I’m looking in the right place: https://github.com/scipy/scipy/blob/2aee5efcbe3720f41fe55f336f492ae0acbecdee/tools/openblas_support.py#L16-L17