Changeset 6158 for anuga_core/source/anuga/utilities/test_sparse.py
- Timestamp:
- Jan 14, 2009, 9:48:37 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/test_sparse.py
r5897 r6158 5 5 6 6 from sparse import * 7 from Numeric import allclose, array, transpose, Float 7 import Numeric as num 8 8 9 9 10 class Test_Sparse(unittest.TestCase): … … 43 44 C = Sparse(B) 44 45 45 assert allclose(C.todense(), B)46 assert num.allclose(C.todense(), B) 46 47 47 48 … … 50 51 A[1,1] = 4 51 52 52 assert allclose(A.todense(), [[0,0,0], [0,4,0], [0,0,0], [0,0,0]])53 assert num.allclose(A.todense(), [[0,0,0], [0,4,0], [0,0,0], [0,0,0]]) 53 54 54 55 … … 63 64 64 65 assert len(A) == 0 65 assert allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])66 assert num.allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]]) 66 67 67 68 #Set an existing zero element to zero 68 69 A[1,2] = 0 69 70 assert len(A) == 0 70 assert allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])71 assert num.allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]]) 71 72 72 73 def test_sparse_multiplication_vector(self): … … 82 83 83 84 u = A*v 84 assert allclose(u, [6,14,4])85 assert num.allclose(u, [6,14,4]) 85 86 86 87 #Right hand side column 87 v = array([[2,4],[3,4],[4,4]])88 v = num.array([[2,4],[3,4],[4,4]]) 88 89 89 90 u = A*v[:,0] 90 assert allclose(u, [6,14,4])91 assert num.allclose(u, [6,14,4]) 91 92 92 93 u = A*v[:,1] 93 assert allclose(u, [12,16,4])94 assert num.allclose(u, [12,16,4]) 94 95 95 96 … … 103 104 104 105 #Right hand side matrix 105 v = array([[2,4],[3,4],[4,4]])106 v = num.array([[2,4],[3,4],[4,4]]) 106 107 107 108 u = A*v 108 assert allclose(u, [[6,12], [14,16], [4,4]])109 assert num.allclose(u, [[6,12], [14,16], [4,4]]) 109 110 110 111 … … 122 123 123 124 u = A.trans_mult(v) 124 assert allclose(u, [6,6,10])125 assert num.allclose(u, [6,6,10]) 125 126 126 127 … … 137 138 138 139 B = 3*A 139 assert allclose(B.todense(), 3*A.todense())140 assert num.allclose(B.todense(), 3*A.todense()) 140 141 141 142 B = A*3 142 assert allclose(B.todense(), 3*A.todense())143 assert num.allclose(B.todense(), 3*A.todense()) 143 144 144 145 try: … … 166 167 C = A+B 167 168 168 assert allclose(C.todense(), [[12,0,0], [2,8,8], [0,0,4]])169 assert num.allclose(C.todense(), [[12,0,0], [2,8,8], [0,0,4]]) 169 170 170 171 def test_sparse_tocsr(self): … … 190 191 C = [1, 2, 3] 191 192 192 assert allclose(B*C, [15.0, 10.0 ,8.0, 0.0])193 assert num.allclose(B*C, [15.0, 10.0 ,8.0, 0.0]) 193 194 194 195 C2 = [[1,2],[2,4],[3,6]] … … 196 197 #print B*C2 197 198 198 assert allclose(B*C2, [[15.0, 30.0],[10.0, 20.0],[8.0, 16.0],[0.0, 0.0]])199 assert num.allclose(B*C2, [[15.0, 30.0],[10.0, 20.0],[8.0, 16.0],[0.0, 0.0]]) 199 200 200 201
Note: See TracChangeset
for help on using the changeset viewer.