Skip to content

Commit

Permalink
BUG: sparse/linalg: fix expm for np.matrix inputs (scipy#10906)
Browse files Browse the repository at this point in the history
  • Loading branch information
pv authored and tylerjereddy committed Jan 20, 2020
1 parent fd64305 commit 2985d45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scipy/sparse/linalg/matfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def _expm(A, use_exact_onenorm):
# algorithms.

# Avoid indiscriminate asarray() to allow sparse or other strange arrays.
if isinstance(A, (list, tuple)):
if isinstance(A, (list, tuple, np.matrix)):
A = np.asarray(A)
if len(A.shape) != 2 or A.shape[0] != A.shape[1]:
raise ValueError('expected a square matrix')
Expand Down
11 changes: 11 additions & 0 deletions scipy/sparse/linalg/tests/test_matfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,17 @@ def test_pascal(self):
atol = 1e-13 * abs(expected).max()
assert_allclose(got, expected, atol=atol)

def test_matrix_input(self):
# Large np.matrix inputs should work, gh-5546
A = np.zeros((200, 200))
A[-1,0] = 1
B0 = expm(A)
with suppress_warnings() as sup:
sup.filter(DeprecationWarning, "the matrix subclass.*")
sup.filter(PendingDeprecationWarning, "the matrix subclass.*")
B = expm(np.matrix(A))
assert_allclose(B, B0)


class TestOperators(object):

Expand Down

0 comments on commit 2985d45

Please sign in to comment.