Skip to content

Commit 8523a03

Browse files
authored
BUG: linalg: svd avoid segmentation fault (scipy#21850)
1 parent a1dc60a commit 8523a03

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

scipy/linalg/_decomp_svd.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,25 @@ def svd(a, full_matrices=True, compute_uv=True, overwrite_a=False,
134134
message = f'lapack_driver must be "gesdd" or "gesvd", not "{lapack_driver}"'
135135
raise ValueError(message)
136136

137-
if lapack_driver == 'gesdd' and compute_uv:
137+
if compute_uv:
138138
# XXX: revisit int32 when ILP64 lapack becomes a thing
139139
max_mn, min_mn = (m, n) if m > n else (n, m)
140140
if full_matrices:
141141
if max_mn*max_mn > np.iinfo(np.int32).max:
142142
raise ValueError(f"Indexing a matrix size {max_mn} x {max_mn} "
143-
" would incur integer overflow in LAPACK.")
143+
"would incur integer overflow in LAPACK. "
144+
"Try using numpy.linalg.svd instead.")
144145
else:
145146
sz = max(m * min_mn, n * min_mn)
146147
if max(m * min_mn, n * min_mn) > np.iinfo(np.int32).max:
147148
raise ValueError(f"Indexing a matrix of {sz} elements would "
148-
"incur an in integer overflow in LAPACK.")
149+
"incur an in integer overflow in LAPACK. "
150+
"Try using numpy.linalg.svd instead.")
149151

150152
funcs = (lapack_driver, lapack_driver + '_lwork')
151-
gesXd, gesXd_lwork = get_lapack_funcs(funcs, (a1,), ilp64='preferred')
153+
# XXX: As of 1.14.1 it isn't possible to build SciPy with ILP64,
154+
# so the following line always yields a LP64 (32-bit pointer size) variant
155+
gesXd, gesXd_lwork = get_lapack_funcs(funcs, (a1,), ilp64="preferred")
152156

153157
# compute optimal lwork
154158
lwork = _compute_lwork(gesXd_lwork, a1.shape[0], a1.shape[1],

0 commit comments

Comments
 (0)