Skip to content

Commit

Permalink
TST:linalg: Tweaks to tests for the new expm()
Browse files Browse the repository at this point in the history
  • Loading branch information
ilayn committed Mar 15, 2022
1 parent a0cd10b commit d40fa4f
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions scipy/linalg/tests/test_matfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@

import numpy as np
from numpy import array, identity, dot, sqrt
from numpy.testing import (
assert_array_equal, assert_array_less, assert_equal,
assert_array_almost_equal,
assert_allclose, assert_, assert_warns)
from numpy.testing import (assert_array_almost_equal, assert_allclose, assert_,
assert_array_less, assert_array_equal, assert_warns)
import pytest

import scipy.linalg
Expand Down Expand Up @@ -108,7 +106,7 @@ def test_al_mohy_higham_2012_experiment_1_logm(self):
A = _get_al_mohy_higham_2012_experiment_1()
A_logm, info = logm(A, disp=False)
A_round_trip = expm(A_logm)
assert_allclose(A_round_trip, A, rtol=1e-5, atol=1e-14)
assert_allclose(A_round_trip, A, rtol=5e-5, atol=1e-14)

def test_al_mohy_higham_2012_experiment_1_funm_log(self):
# The raw funm with np.log does not complete the round trip.
Expand Down Expand Up @@ -604,25 +602,8 @@ def test_zero(self):
assert_array_almost_equal(expm(a),[[1,0],[0,1]])

def test_single_elt(self):
# See gh-5853
from scipy.sparse import csc_matrix

vOne = -2.02683397006j
vTwo = -2.12817566856j

mOne = csc_matrix([[vOne]], dtype='complex')
mTwo = csc_matrix([[vTwo]], dtype='complex')

outOne = expm(mOne)
outTwo = expm(mTwo)

assert_equal(type(outOne), type(mOne))
assert_equal(type(outTwo), type(mTwo))

assert_allclose(outOne[0, 0], complex(-0.44039415155949196,
-0.8978045395698304))
assert_allclose(outTwo[0, 0], complex(-0.52896401032626006,
-0.84864425749518878))
elt = expm(1)
assert_allclose(elt, np.array([[np.e]]))

def test_empty_matrix_input(self):
# handle gh-11082
Expand Down Expand Up @@ -713,8 +694,8 @@ def test_fuzz(self):
expected_expm = scipy.linalg.expm(A)
expected_frechet = scipy.linalg.expm(M)[:n, n:]
observed_expm, observed_frechet = expm_frechet(A, E)
assert_allclose(expected_expm, observed_expm)
assert_allclose(expected_frechet, observed_frechet)
assert_allclose(expected_expm, observed_expm, atol=5e-8)
assert_allclose(expected_frechet, observed_frechet, atol=1e-7)

def test_problematic_matrix(self):
# this test case uncovered a bug which has since been fixed
Expand Down

0 comments on commit d40fa4f

Please sign in to comment.