File: test_gesv.py

package info (click to toggle)
python-scipy 0.10.1%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 42,232 kB
  • sloc: cpp: 224,773; ansic: 103,496; python: 85,210; fortran: 79,130; makefile: 272; sh: 43
file content (94 lines) | stat: -rw-r--r-- 3,423 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import numpy as np
from numpy.testing import TestCase, assert_array_almost_equal, dec, \
                          assert_equal, assert_

from common import FUNCS_TP, FLAPACK_IS_EMPTY, CLAPACK_IS_EMPTY, FUNCS_FLAPACK, \
                   FUNCS_CLAPACK, PREC

A = np.array([[1,2,3],[2,2,3],[3,3,6]])
B = np.array([[10,-1,1],[-1,8,-2],[1,-2,6]])

class TestSygv(TestCase):
    def _test_base(self, func, lang, itype):
        tp = FUNCS_TP[func]
        a = A.astype(tp)
        b = B.astype(tp)
        if lang == 'C':
            f = FUNCS_CLAPACK[func]
        elif lang == 'F':
            f = FUNCS_FLAPACK[func]
        else:
            raise ValueError("Lang %s ??" % lang)

        w, v, info = f(a, b, itype=itype)

        assert_(not info, msg=repr(info))
        for i in range(3):
            if itype == 1:
                assert_array_almost_equal(np.dot(a,v[:,i]), w[i]*np.dot(b,v[:,i]),
                                          decimal=PREC[tp])
            elif itype == 2:
                assert_array_almost_equal(np.dot(a,np.dot(b,v[:,i])), w[i]*v[:,i],
                                          decimal=PREC[tp])
            elif itype == 3:
                assert_array_almost_equal(np.dot(b,np.dot(a,v[:,i])),
                                          w[i]*v[:,i], decimal=PREC[tp] - 1)
            else:
                raise ValueError(itype)

    @dec.skipif(FLAPACK_IS_EMPTY, "Flapack empty, skip flapack test")
    def test_ssygv_1(self):
        self._test_base('ssygv', 'F', 1)

    @dec.skipif(FLAPACK_IS_EMPTY, "Flapack empty, skip flapack test")
    def test_ssygv_2(self):
        self._test_base('ssygv', 'F', 2)

    @dec.skipif(FLAPACK_IS_EMPTY, "Flapack empty, skip flapack test")
    def test_ssygv_3(self):
        self._test_base('ssygv', 'F', 3)

    @dec.skipif(FLAPACK_IS_EMPTY, "Flapack empty, skip flapack test")
    def test_dsygv_1(self):
        self._test_base('dsygv', 'F', 1)

    @dec.skipif(FLAPACK_IS_EMPTY, "Flapack empty, skip flapack test")
    def test_dsygv_2(self):
        self._test_base('dsygv', 'F', 2)

    @dec.skipif(FLAPACK_IS_EMPTY, "Flapack empty, skip flapack test")
    def test_dsygv_3(self):
        self._test_base('dsygv', 'F', 3)

    @dec.skipif(CLAPACK_IS_EMPTY or not FUNCS_CLAPACK["ssygv"],
                "Clapack empty, skip flapack test")
    def test_clapack_ssygv_1(self):
        self._test_base('ssygv', 'C', 1)

    @dec.skipif(CLAPACK_IS_EMPTY or not FUNCS_CLAPACK["ssygv"],
                "Clapack empty, skip flapack test")
    def test_clapack_ssygv_2(self):
        self._test_base('ssygv', 'C', 2)

    @dec.skipif(CLAPACK_IS_EMPTY or not FUNCS_CLAPACK["ssygv"],
                "Clapack empty, skip flapack test")
    def test_clapack_ssygv_3(self):
        self._test_base('ssygv', 'C', 3)

    @dec.skipif(CLAPACK_IS_EMPTY or not FUNCS_CLAPACK["dsygv"],
                "Clapack empty, skip flapack test")
    def test_clapack_dsygv_1(self):
        self._test_base('dsygv', 'C', 1)

    @dec.skipif(CLAPACK_IS_EMPTY or not FUNCS_CLAPACK["dsygv"],
                "Clapack empty, skip flapack test")
    def test_clapack_dsygv_2(self):
        self._test_base('dsygv', 'C', 2)

    @dec.skipif(CLAPACK_IS_EMPTY or not FUNCS_CLAPACK["dsygv"],
                "Clapack empty, skip flapack test")
    def test_clapack_dsygv_3(self):
        self._test_base('dsygv', 'C', 3)

if __name__=="__main__":
    run_module_suite()