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 Numeric import array, identity
20
from scipy_test.testing import *
23
from scipy_base import dot,sqrt
25
from linalg import signm,logm,funm, sqrtm
30
class test_signm(ScipyTestCase):
33
a = array([[ 29.2, -24.2, 69.5, 49.8, 7. ],
34
[ -9.2, 5.2, -18. , -16.8, -2. ],
35
[-10. , 6. , -20. , -18. , -2. ],
36
[ -9.6, 9.6, -25.5, -15.4, -2. ],
37
[ 9.8, -4.8, 18. , 18.2, 2. ]])
38
cr = array([[ 11.94933333,-2.24533333,15.31733333,21.65333333,-2.24533333],
39
[ -3.84266667,0.49866667,-4.59066667,-7.18666667,0.49866667],
40
[ -4.08,0.56,-4.92,-7.6 ,0.56],
41
[ -4.03466667,1.04266667,-5.59866667,-7.02666667,1.04266667],
42
[4.15733333,-0.50133333,4.90933333,7.81333333,-0.50133333]])
44
assert_array_almost_equal(r,cr)
46
def check_defective1(self):
47
a = array([[0.0,1,0,0],[1,0,1,0],[0,0,0,1],[0,0,1,0]])
49
#XXX: what would be the correct result?
51
def check_defective2(self):
53
[29.2,-24.2,69.5,49.8,7.0],
54
[-9.2,5.2,-18.0,-16.8,-2.0],
55
[-10.0,6.0,-20.0,-18.0,-2.0],
56
[-9.6,9.6,-25.5,-15.4,-2.0],
57
[9.8,-4.8,18.0,18.2,2.0]))
59
#XXX: what would be the correct result?
61
def check_defective3(self):
62
a = array([[ -2., 25., 0., 0., 0., 0., 0.],
63
[ 0., -3., 10., 3., 3., 3., 0.],
64
[ 0., 0., 2., 15., 3., 3., 0.],
65
[ 0., 0., 0., 0., 15., 3., 0.],
66
[ 0., 0., 0., 0., 3., 10., 0.],
67
[ 0., 0., 0., 0., 0., -2., 25.],
68
[ 0., 0., 0., 0., 0., 0., -3.]])
70
#XXX: what would be the correct result?
72
class test_logm(ScipyTestCase):
75
a = array([[ -2., 25., 0., 0., 0., 0., 0.],
76
[ 0., -3., 10., 3., 3., 3., 0.],
77
[ 0., 0., 2., 15., 3., 3., 0.],
78
[ 0., 0., 0., 0., 15., 3., 0.],
79
[ 0., 0., 0., 0., 3., 10., 0.],
80
[ 0., 0., 0., 0., 0., -2., 25.],
81
[ 0., 0., 0., 0., 0., 0., -3.]])
82
logm((identity(7)*3.1+0j)-a)
85
class test_sqrtm(ScipyTestCase):
87
# See http://www.maths.man.ac.uk/~nareports/narep336.ps.gz
90
a = array([[1.0,0,0,1],
94
sa = array([[1,0,0,0.5],
98
assert_array_almost_equal(dot(sa,sa),a)
100
assert_array_almost_equal(dot(esa,esa),a)
103
if __name__ == "__main__":
104
ScipyTest('linalg.matfuncs').run()