Ignore:
Timestamp:
Jan 14, 2009, 9:48:37 AM (16 years ago)
Author:
rwilson
Message:

Change Numeric imports to general form - ready to change to NumPy?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/test_sparse.py

    r5897 r6158  
    55
    66from sparse import *
    7 from Numeric import allclose, array, transpose, Float
     7import Numeric as num
     8
    89
    910class Test_Sparse(unittest.TestCase):
     
    4344        C = Sparse(B)
    4445
    45         assert allclose(C.todense(), B)
     46        assert num.allclose(C.todense(), B)
    4647
    4748
     
    5051        A[1,1] = 4
    5152
    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]])
    5354
    5455
     
    6364
    6465        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]])
    6667
    6768        #Set an existing zero element to zero
    6869        A[1,2] = 0
    6970        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]])
    7172
    7273    def test_sparse_multiplication_vector(self):
     
    8283
    8384        u = A*v
    84         assert allclose(u, [6,14,4])
     85        assert num.allclose(u, [6,14,4])
    8586
    8687        #Right hand side column
    87         v = array([[2,4],[3,4],[4,4]])
     88        v = num.array([[2,4],[3,4],[4,4]])
    8889
    8990        u = A*v[:,0]
    90         assert allclose(u, [6,14,4])
     91        assert num.allclose(u, [6,14,4])
    9192
    9293        u = A*v[:,1]
    93         assert allclose(u, [12,16,4])
     94        assert num.allclose(u, [12,16,4])
    9495
    9596
     
    103104
    104105        #Right hand side matrix
    105         v = array([[2,4],[3,4],[4,4]])
     106        v = num.array([[2,4],[3,4],[4,4]])
    106107
    107108        u = A*v
    108         assert allclose(u, [[6,12], [14,16], [4,4]])
     109        assert num.allclose(u, [[6,12], [14,16], [4,4]])
    109110
    110111
     
    122123
    123124        u = A.trans_mult(v)
    124         assert allclose(u, [6,6,10])
     125        assert num.allclose(u, [6,6,10])
    125126
    126127
     
    137138
    138139        B = 3*A
    139         assert allclose(B.todense(), 3*A.todense())
     140        assert num.allclose(B.todense(), 3*A.todense())
    140141
    141142        B = A*3
    142         assert allclose(B.todense(), 3*A.todense())
     143        assert num.allclose(B.todense(), 3*A.todense())
    143144
    144145        try:
     
    166167        C = A+B
    167168
    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]])
    169170
    170171    def test_sparse_tocsr(self):
     
    190191        C = [1, 2, 3]
    191192
    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])
    193194
    194195        C2 = [[1,2],[2,4],[3,6]]
     
    196197        #print B*C2
    197198
    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]])
    199200
    200201
Note: See TracChangeset for help on using the changeset viewer.