1
2 import Numeric
3
7
9 """ solves a*x = b."""
10 b = Numeric.asarray(b0, Numeric.Float)
11 if len(b.shape) == 1:
12 b = Numeric.array((b,), Numeric.Float)
13
14 assert a.n == b.shape[1]
15 import lapack_dpb
16
17
18
19
20 result = lapack_dpb.dpbsv('L', a.n, a.kd, b.shape[0], a.d,
21 a.ldab, b, max(1, a.n), 0)
22
23 if result['info'] != 0:
24 raise NoSolutionError, 'Linear system has no solution. Lapack_dpb.dpbsv info code=%d' % result['info']
25
26 return b
27
28
30 x = sbd(100, 10)
31 x[0,0] = 1
32 assert x[0,0] == 1
33 x[99,99] = 2
34 assert x[99,99] == 2
35 x[10,0] = 10
36 assert x[10,0] == 10
37 assert x[0,10] == 10
38 try:
39 x[12,1] = 2
40 except IndexError:
41 pass
42 else:
43 assert None
44
45
48
50 x = sbd(6,2)
51 b = Numeric.zeros((6,), Numeric.Float) + 10
52 for i in range(6):
53 x[i,i] = 2
54 x[2,1] = 0.5
55
56 y = solve(x, b)
57 y_t = Numeric.array(([5, 4, 4, 5, 5, 5],))
58
59
60 assert err(y_t, y) < 1e-9
61
62
64 x = sbd(6, 2)
65 x[4,3] = 1
66 x[4,4] = 2
67 x[5,3] = 3
68 x[5,5] = -1
69
70 y = x[:]
71
72 assert y[4,3]==1
73 assert y[4,4]==2
74 assert y[5,3]==3
75 assert y[4,5]==0
76 assert y[3,4]==1
77 assert y[3,3]==0
78 assert y[4,5]==0
79 assert y[5,5] == -1
80 y = x[5:6]
81
82 assert y[0,5] == -1
83 assert y[0,3] == 3
84 assert y[0,4] == 0
85
87 x = sbd(6,2)
88 y = Numeric.array([[1, 2], [2, 3]])
89 x.bd_increment(1, y)
90 assert x[1,1]==1
91 assert x[2,2]==3
92 assert x[2,1]==2
93 assert x[1,2]==2
94 assert x[0,0]==0
95 assert x[3,3]==0
96 assert x[3,2]==0
97 z = Numeric.array([[-1, 0, 1], [0, 0, 0], [0, 0, 0]])
98 x.bd_increment(0, z)
99 assert x[0,0]==-1
100 assert x[0, 2]==1
101 assert x[1,1]==1
102 assert x[1, 2]==2
103
104 if __name__ == '__main__':
105 test1()
106 test2()
107 testa()
108 testbdi()
109