Skip to content

Commit

Permalink
Merge pull request scipy#15821 from j-bowhay/dep_sym_pos_kwarg
Browse files Browse the repository at this point in the history
DEP:linalg: add DeprecationWarning for "sym_pos" keyword of solve
  • Loading branch information
ilayn authored Mar 20, 2022
2 parents 6660830 + acfeded commit c7d74d1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
15 changes: 11 additions & 4 deletions scipy/linalg/_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ def solve(a, b, sym_pos=False, lower=False, overwrite_a=False,
Square input data
b : (N, NRHS) array_like
Input data for the right hand side.
sym_pos : bool, optional
Assume `a` is symmetric and positive definite. This key is deprecated
and assume_a = 'pos' keyword is recommended instead. The functionality
is the same. It will be removed in the future.
sym_pos : bool, optional, deprecated
Assume `a` is symmetric and positive definite.
.. deprecated:: 0.19.0
This keyword is deprecated and should be replaced by using
``assume_a = 'pos'``. `sym_pos` will be removed in SciPy 1.11.0.
lower : bool, optional
If True, only the data contained in the lower triangle of `a`. Default
is to use upper triangle. (ignored for ``'gen'``)
Expand Down Expand Up @@ -164,6 +167,10 @@ def solve(a, b, sym_pos=False, lower=False, overwrite_a=False,

# Backwards compatibility - old keyword.
if sym_pos:
message = ("The 'sym_pos' keyword is deprecated and should be "
"replaced by using 'assume_a = \"pos\"'. 'sym_pos' will be"
" removed in SciPy 1.11.0.")
warn(message, DeprecationWarning, stacklevel=2)
assume_a = 'pos'

if assume_a not in ('gen', 'sym', 'her', 'pos'):
Expand Down
11 changes: 9 additions & 2 deletions scipy/linalg/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ def test_random_complex(self):
x = solve(a, b)
assert_array_almost_equal(dot(a, x), b)

def test_sym_pos_dep(self):
with pytest.warns(
DeprecationWarning,
match="The 'sym_pos' keyword is deprecated",
):
solve([[1.]], [1], sym_pos=True)

def test_random_sym(self):
n = 20
a = random([n, n])
Expand All @@ -628,7 +635,7 @@ def test_random_sym(self):
a[i, j] = a[j, i]
for i in range(4):
b = random([n])
x = solve(a, b, sym_pos=1)
x = solve(a, b, assume_a="pos")
assert_array_almost_equal(dot(a, x), b)

def test_random_sym_complex(self):
Expand All @@ -641,7 +648,7 @@ def test_random_sym_complex(self):
a[i, j] = conjugate(a[j, i])
b = random([n])+2j*random([n])
for i in range(2):
x = solve(a, b, sym_pos=1)
x = solve(a, b, assume_a="pos")
assert_array_almost_equal(dot(a, x), b)

def test_check_finite(self):
Expand Down
5 changes: 4 additions & 1 deletion scipy/optimize/_linprog_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ def solve(r):
# this seems to cache the matrix factorization, so solving
# with multiple right hand sides is much faster
def solve(r, sym_pos=sym_pos):
return sp.linalg.solve(M, r, sym_pos=sym_pos)
if sym_pos:
return sp.linalg.solve(M, r, assume_a="pos")
else:
return sp.linalg.solve(M, r)
# There are many things that can go wrong here, and it's hard to say
# what all of them are. It doesn't really matter: if the matrix can't be
# factorized, return None. get_solver will be called again with different
Expand Down
2 changes: 1 addition & 1 deletion scipy/signal/_fir_filter_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ def firls(numtaps, bands, desired, weight=None, nyq=None, fs=None):
try: # try the fast way
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
a = solve(Q, b, sym_pos=True, check_finite=False)
a = solve(Q, b, assume_a="pos", check_finite=False)
for ww in w:
if (ww.category == LinAlgWarning and
str(ww.message).startswith('Ill-conditioned matrix')):
Expand Down

0 comments on commit c7d74d1

Please sign in to comment.