3
# Created by: Pearu Peterson, March 2002
5
""" Test functions for linalg.matfuncs module
10
python setup_linalg.py build
11
Run tests if scipy is installed:
12
python -c 'import scipy;scipy.linalg.test(<level>)'
13
Run tests if linalg is not installed:
14
python tests/test_matfuncs.py [<level>]
17
from numpy import array, identity
20
from numpy.testing import *
23
from numpy import dot,sqrt
25
from linalg import signm,logm,funm, sqrtm, expm, expm2, expm3
28
class test_signm(ScipyTestCase):
31
a = array([[ 29.2, -24.2, 69.5, 49.8, 7. ],
32
[ -9.2, 5.2, -18. , -16.8, -2. ],
33
[-10. , 6. , -20. , -18. , -2. ],
34
[ -9.6, 9.6, -25.5, -15.4, -2. ],
35
[ 9.8, -4.8, 18. , 18.2, 2. ]])
36
cr = array([[ 11.94933333,-2.24533333,15.31733333,21.65333333,-2.24533333],
37
[ -3.84266667,0.49866667,-4.59066667,-7.18666667,0.49866667],
38
[ -4.08,0.56,-4.92,-7.6 ,0.56],
39
[ -4.03466667,1.04266667,-5.59866667,-7.02666667,1.04266667],
40
[4.15733333,-0.50133333,4.90933333,7.81333333,-0.50133333]])
42
assert_array_almost_equal(r,cr)
44
def check_defective1(self):
45
a = array([[0.0,1,0,0],[1,0,1,0],[0,0,0,1],[0,0,1,0]])
47
#XXX: what would be the correct result?
49
def check_defective2(self):
51
[29.2,-24.2,69.5,49.8,7.0],
52
[-9.2,5.2,-18.0,-16.8,-2.0],
53
[-10.0,6.0,-20.0,-18.0,-2.0],
54
[-9.6,9.6,-25.5,-15.4,-2.0],
55
[9.8,-4.8,18.0,18.2,2.0]))
57
#XXX: what would be the correct result?
59
def check_defective3(self):
60
a = array([[ -2., 25., 0., 0., 0., 0., 0.],
61
[ 0., -3., 10., 3., 3., 3., 0.],
62
[ 0., 0., 2., 15., 3., 3., 0.],
63
[ 0., 0., 0., 0., 15., 3., 0.],
64
[ 0., 0., 0., 0., 3., 10., 0.],
65
[ 0., 0., 0., 0., 0., -2., 25.],
66
[ 0., 0., 0., 0., 0., 0., -3.]])
68
#XXX: what would be the correct result?
70
class test_logm(ScipyTestCase):
73
a = array([[ -2., 25., 0., 0., 0., 0., 0.],
74
[ 0., -3., 10., 3., 3., 3., 0.],
75
[ 0., 0., 2., 15., 3., 3., 0.],
76
[ 0., 0., 0., 0., 15., 3., 0.],
77
[ 0., 0., 0., 0., 3., 10., 0.],
78
[ 0., 0., 0., 0., 0., -2., 25.],
79
[ 0., 0., 0., 0., 0., 0., -3.]])
80
m = (identity(7)*3.1+0j)-a
84
class test_sqrtm(ScipyTestCase):
86
# See http://www.maths.man.ac.uk/~nareports/narep336.ps.gz
89
a = array([[1.0,0,0,1],
93
sa = array([[1,0,0,0.5],
97
assert_array_almost_equal(dot(sa,sa),a)
99
assert_array_almost_equal(dot(esa,esa),a)
101
class test_expm(ScipyTestCase):
102
def check_zero(self):
103
a = array([[0.,0],[0,0]])
104
assert_array_almost_equal(expm(a),[[1,0],[0,1]])
105
assert_array_almost_equal(expm2(a),[[1,0],[0,1]])
106
assert_array_almost_equal(expm3(a),[[1,0],[0,1]])
108
if __name__ == "__main__":