Skip to content

Commit

Permalink
MAINT: Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Smit-create committed Jan 17, 2022
1 parent eb2ad0a commit 7b50add
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion scipy/sparse/linalg/_expm_multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

import scipy.linalg
import scipy.sparse
import scipy.sparse.linalg
from scipy.sparse.linalg import aslinearoperator
from scipy.sparse._sputils import is_pydata_spmatrix
Expand Down
24 changes: 12 additions & 12 deletions scipy/sparse/linalg/tests/test_expm_multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
suppress_warnings)
from scipy.sparse import SparseEfficiencyWarning
import scipy.linalg
from scipy.linalg._matfuncs import expm
from scipy.sparse.linalg._expm_multiply import (_theta, _compute_p_max,
_onenormest_matrix_power, expm_multiply, _expm_multiply_simple,
_expm_multiply_interval)
Expand Down Expand Up @@ -63,7 +64,7 @@ def test_expm_multiply(self):
A = scipy.linalg.inv(np.random.randn(n, n))
B = np.random.randn(n, k)
observed = expm_multiply(A, B)
expected = np.dot(scipy.linalg.expm(A), B)
expected = np.dot(expm(A), B)
assert_allclose(observed, expected)

def test_matrix_vector_multiply(self):
Expand All @@ -74,7 +75,7 @@ def test_matrix_vector_multiply(self):
A = scipy.linalg.inv(np.random.randn(n, n))
v = np.random.randn(n)
observed = expm_multiply(A, v)
expected = np.dot(scipy.linalg.expm(A), v)
expected = np.dot(expm(A), v)
assert_allclose(observed, expected)

def test_scaled_expm_multiply(self):
Expand All @@ -88,7 +89,7 @@ def test_scaled_expm_multiply(self):
A = scipy.linalg.inv(np.random.randn(n, n))
B = np.random.randn(n, k)
observed = _expm_multiply_simple(A, B, t=t)
expected = np.dot(scipy.linalg.expm(t*A), B)
expected = np.dot(expm(t*A), B)
assert_allclose(observed, expected)

def test_scaled_expm_multiply_single_timepoint(self):
Expand All @@ -99,7 +100,7 @@ def test_scaled_expm_multiply_single_timepoint(self):
A = np.random.randn(n, n)
B = np.random.randn(n, k)
observed = _expm_multiply_simple(A, B, t=t)
expected = scipy.linalg.expm(t*A).dot(B)
expected = expm(t*A).dot(B)
assert_allclose(observed, expected)

def test_sparse_expm_multiply(self):
Expand All @@ -116,7 +117,7 @@ def test_sparse_expm_multiply(self):
"splu requires CSC matrix format")
sup.filter(SparseEfficiencyWarning,
"spsolve is more efficient when sparse b is in the CSC matrix format")
expected = scipy.linalg.expm(A).dot(B)
expected = expm(A).dot(B)
assert_allclose(observed, expected)

def test_complex(self):
Expand Down Expand Up @@ -156,7 +157,7 @@ def test_sparse_expm_multiply_interval(self):
"spsolve is more efficient when sparse b is in the CSC matrix format")
for solution, t in zip(X, samples):
assert_allclose(solution,
scipy.linalg.expm(t*A).dot(target))
expm(t*A).dot(target))

def test_expm_multiply_interval_vector(self):
np.random.seed(1234)
Expand All @@ -172,7 +173,7 @@ def test_expm_multiply_interval_vector(self):
samples = np.linspace(start=start, stop=stop,
num=num, endpoint=endpoint)
for solution, t in zip(X, samples):
assert_allclose(solution, scipy.linalg.expm(t*A).dot(v))
assert_allclose(solution, expm(t*A).dot(v))

def test_expm_multiply_interval_matrix(self):
np.random.seed(1234)
Expand All @@ -189,21 +190,21 @@ def test_expm_multiply_interval_matrix(self):
samples = np.linspace(start=start, stop=stop,
num=num, endpoint=endpoint)
for solution, t in zip(X, samples):
assert_allclose(solution, scipy.linalg.expm(t*A).dot(B))
assert_allclose(solution, expm(t*A).dot(B))

def test_sparse_expm_multiply_interval_dtypes(self):
# Test A & B int
A = scipy.sparse.diags(np.arange(5),format='csr', dtype=int)
B = np.ones(5, dtype=int)
Aexpm = scipy.sparse.diags(np.exp(np.arange(5)),format='csr')
assert_allclose(expm_multiply(A,B,0,1)[-1], Aexpm.dot(B))

# Test A complex, B int
A = scipy.sparse.diags(-1j*np.arange(5),format='csr', dtype=complex)
B = np.ones(5, dtype=int)
Aexpm = scipy.sparse.diags(np.exp(-1j*np.arange(5)),format='csr')
assert_allclose(expm_multiply(A,B,0,1)[-1], Aexpm.dot(B))

# Test A int, B complex
A = scipy.sparse.diags(np.arange(5),format='csr', dtype=int)
B = np.full(5, 1j, dtype=complex)
Expand Down Expand Up @@ -243,9 +244,8 @@ def _help_test_specific_expm_interval_status(self, target_status):
samples = np.linspace(start=start, stop=stop,
num=num, endpoint=endpoint)
for solution, t in zip(X, samples):
assert_allclose(solution, scipy.linalg.expm(t*A).dot(B))
assert_allclose(solution, expm(t*A).dot(B))
nsuccesses += 1
if not nsuccesses:
msg = 'failed to find a status-' + str(target_status) + ' interval'
raise Exception(msg)

0 comments on commit 7b50add

Please sign in to comment.