Changeset 6158


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?.

Location:
anuga_core/source/anuga/utilities
Files:
13 edited

Legend:

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

    r5897 r6158  
    33class ConvergenceError(exceptions.Exception): pass
    44
    5 from Numeric import dot, array, Float, zeros
     5import Numeric as num
    66   
    77import logging, logging.config
     
    2424   
    2525    if x0 is None:
    26         x0 = zeros(b.shape, typecode=Float)
     26        x0 = num.zeros(b.shape, typecode=num.Float)
    2727    else:
    28         x0 = array(x0, typecode=Float)
     28        x0 = num.array(x0, typecode=num.Float)
    2929
    30     b  = array(b, typecode=Float)
     30    b  = num.array(b, typecode=num.Float)
    3131    if len(b.shape) != 1 :
    3232       
     
    5757
    5858
    59    b  = array(b, typecode=Float)
     59   b  = num.array(b, typecode=num.Float)
    6060   if len(b.shape) != 1 :
    6161      raise VectorShapeError, 'input vector should consist of only one column'
    6262
    6363   if x0 is None:
    64       x0 = zeros(b.shape, typecode=Float)
     64      x0 = num.zeros(b.shape, typecode=num.Float)
    6565   else:
    66       x0 = array(x0, typecode=Float)
     66      x0 = num.array(x0, typecode=num.Float)
    6767
    6868
     
    7575   r = b - A*x
    7676   d = r
    77    rTr = dot(r,r)
     77   rTr = num.dot(r,r)
    7878   rTr0 = rTr
    7979
    8080   while (i<imax and rTr>tol**2*rTr0):
    8181       q = A*d
    82        alpha = rTr/dot(d,q)
     82       alpha = rTr/num.dot(d,q)
    8383       x = x + alpha*d
    8484       if i%50 :
     
    8787           r = r - alpha*q
    8888       rTrOld = rTr
    89        rTr = dot(r,r)
     89       rTr = num.dot(r,r)
    9090       bt = rTr/rTrOld
    9191
  • anuga_core/source/anuga/utilities/numerical_tools.py

    r6119 r6158  
    77from warnings import warn
    88
    9 #Establish which Numeric package to use
    10 #(this should move to somewhere central)
    11 #try:
    12 #    from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt,
    13 # searchsorted, sort, concatenate, Float, arange   
    14 #except:
    15 #    #print 'Could not find scipy - using Numeric'
    16 #    from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt,
    17 #searchsorted, sort, concatenate, Float, arange
    18 
    19 from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt,\
    20      searchsorted, sort, concatenate, Float, arange   
    21 
    22 # Getting an infinite number to use when using Numeric
    23 #INF = (array([1])/0.)[0]
    24 
    25 NAN = (array([1])/0.)[0]
    26 # Note, INF is used instead of NAN (Not a number), since Numeric has no NAN
     9import Numeric as num
     10
     11NAN = (num.array([1])/0.)[0]
    2712# if we use a package that has NAN, this should be updated to use NAN.
    2813
     
    8974        v2 = [1.0, 0.0] # Unit vector along the x-axis
    9075       
    91     v1 = ensure_numeric(v1, Float)
    92     v2 = ensure_numeric(v2, Float)   
     76    v1 = ensure_numeric(v1, num.Float)
     77    v2 = ensure_numeric(v2, num.Float)   
    9378   
    9479    # Normalise
    95     v1 = v1/sqrt(sum(v1**2))
    96     v2 = v2/sqrt(sum(v2**2))
     80    v1 = v1/num.sqrt(num.sum(v1**2))
     81    v2 = v2/num.sqrt(num.sum(v2**2))
    9782
    9883    # Compute angle
    99     p = innerproduct(v1, v2)
    100     c = innerproduct(v1, normal_vector(v2)) # Projection onto normal
     84    p = num.innerproduct(v1, v2)
     85    c = num.innerproduct(v1, normal_vector(v2)) # Projection onto normal
    10186                                            # (negative cross product)
    10287       
     
    140125    """
    141126   
    142     return array([-v[1], v[0]], Float)
     127    return num.array([-v[1], v[0]], num.Float)
    143128
    144129   
     
    150135    """Mean value of a vector
    151136    """
    152     return(float(sum(x))/len(x))
     137    return(float(num.sum(x))/len(x))
    153138
    154139
     
    171156    cy = y - mean(y) 
    172157
    173     p = innerproduct(cx,cy)/N
     158    p = num.innerproduct(cx,cy)/N
    174159    return(p)
    175160
     
    220205    """
    221206 
    222     y = ravel(x)
    223     p = sqrt(innerproduct(y,y))
     207    y = num.ravel(x)
     208    p = num.sqrt(num.innerproduct(y,y))
    224209    return p
    225210   
     
    262247
    263248    if typecode is None:
    264         if type(A) == ArrayType:
     249        if type(A) == num.ArrayType:
    265250            return A
    266251        else:
    267             return array(A)
     252            return num.array(A)
    268253    else:
    269         if type(A) == ArrayType:
     254        if type(A) == num.ArrayType:
    270255            if A.typecode == typecode:
    271                 return array(A)  #FIXME: Shouldn't this just return A?
     256                return num.array(A)  #FIXME: Shouldn't this just return A?
    272257            else:
    273                 return array(A,typecode)
     258                return num.array(A,typecode)
    274259        else:
    275             return array(A,typecode)
     260            return num.array(A,typecode)
    276261
    277262
     
    285270    """
    286271
    287     n = searchsorted(sort(a), bins)
    288     n = concatenate( [n, [len(a)]] )
     272    n = num.searchsorted(num.sort(a), bins)
     273    n = num.concatenate( [n, [len(a)]] )
    289274
    290275    hist = n[1:]-n[:-1]
    291276
    292277    if relative is True:
    293         hist = hist/float(sum(hist))
     278        hist = hist/float(num.sum(hist))
    294279       
    295280    return hist
     
    305290
    306291    if mx == mn:
    307         bins = array([mn])
     292        bins = num.array([mn])
    308293    else:
    309294        if number_of_bins is None:
    310295            number_of_bins = 10
    311296           
    312         bins = arange(mn, mx, (mx-mn)/number_of_bins)
     297        bins = num.arange(mn, mx, (mx-mn)/number_of_bins)
    313298
    314299    return bins
  • anuga_core/source/anuga/utilities/polygon.py

    r6119 r6158  
    11#!/usr/bin/env python
    22"""Polygon manipulations
    3 
    43"""
    54
    6 
    7 #try:
    8 #    from scipy import Float, Int, zeros, ones, array, concatenate, reshape, dot
    9 #except:
    10 #    #print 'Could not find scipy - using Numeric'
    11 
    12 from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot, allclose
    13 
     5import Numeric as num
    146
    157from math import sqrt
     
    4941# result functions for possible states
    5042def lines_dont_coincide(p0,p1,p2,p3):               return (3, None)
    51 def lines_0_fully_included_in_1(p0,p1,p2,p3):       return (2, array([p0,p1]))
    52 def lines_1_fully_included_in_0(p0,p1,p2,p3):       return (2, array([p2,p3]))
    53 def lines_overlap_same_direction(p0,p1,p2,p3):      return (2, array([p0,p3]))
    54 def lines_overlap_same_direction2(p0,p1,p2,p3):     return (2, array([p2,p1]))
    55 def lines_overlap_opposite_direction(p0,p1,p2,p3):  return (2, array([p0,p2]))
    56 def lines_overlap_opposite_direction2(p0,p1,p2,p3): return (2, array([p3,p1]))
     43def lines_0_fully_included_in_1(p0,p1,p2,p3):       return (2, num.array([p0,p1]))
     44def lines_1_fully_included_in_0(p0,p1,p2,p3):       return (2, num.array([p2,p3]))
     45def lines_overlap_same_direction(p0,p1,p2,p3):      return (2, num.array([p0,p3]))
     46def lines_overlap_same_direction2(p0,p1,p2,p3):     return (2, num.array([p2,p1]))
     47def lines_overlap_opposite_direction(p0,p1,p2,p3):  return (2, num.array([p0,p2]))
     48def lines_overlap_opposite_direction2(p0,p1,p2,p3): return (2, num.array([p3,p1]))
    5749
    5850# this function called when an impossible state is found
     
    108100    # FIXME (Ole): Write this in C
    109101
    110     line0 = ensure_numeric(line0, Float)
    111     line1 = ensure_numeric(line1, Float)   
     102    line0 = ensure_numeric(line0, num.Float)
     103    line1 = ensure_numeric(line1, num.Float)   
    112104
    113105    x0 = line0[0,0]; y0 = line0[0,1]
     
    121113    u1 = (x2-x0)*(y1-y0) - (y2-y0)*(x1-x0)
    122114       
    123     if allclose(denom, 0.0, rtol=rtol, atol=atol):
     115    if num.allclose(denom, 0.0, rtol=rtol, atol=atol):
    124116        # Lines are parallel - check if they are collinear
    125         if allclose([u0, u1], 0.0, rtol=rtol, atol=atol):
     117        if num.allclose([u0, u1], 0.0, rtol=rtol, atol=atol):
    126118            # We now know that the lines are collinear
    127119            state_tuple = (point_on_line([x0, y0], line1, rtol=rtol, atol=atol),
     
    143135
    144136        # Sanity check - can be removed to speed up if needed
    145         assert allclose(x, x2 + u1*(x3-x2), rtol=rtol, atol=atol)
    146         assert allclose(y, y2 + u1*(y3-y2), rtol=rtol, atol=atol)       
     137        assert num.allclose(x, x2 + u1*(x3-x2), rtol=rtol, atol=atol)
     138        assert num.allclose(y, y2 + u1*(y3-y2), rtol=rtol, atol=atol)       
    147139
    148140        # Check if point found lies within given line segments
    149141        if 0.0 <= u0 <= 1.0 and 0.0 <= u1 <= 1.0:
    150142            # We have intersection
    151             return 1, array([x, y])
     143            return 1, num.array([x, y])
    152144        else:
    153145            # No intersection
     
    184176
    185177
    186     line0 = ensure_numeric(line0, Float)
    187     line1 = ensure_numeric(line1, Float)   
     178    line0 = ensure_numeric(line0, num.Float)
     179    line1 = ensure_numeric(line1, num.Float)   
    188180
    189181    status, value = _intersection(line0[0,0], line0[0,1],
     
    251243    if len(points.shape) == 1:
    252244        # Only one point was passed in. Convert to array of points
    253         points = reshape(points, (1,2))
     245        points = num.reshape(points, (1,2))
    254246
    255247    indices, count = separate_points_by_polygon(points, polygon,
     
    293285    #if verbose: print 'Checking input to outside_polygon'
    294286    try:
    295         points = ensure_numeric(points, Float)
     287        points = ensure_numeric(points, num.Float)
    296288    except NameError, e:
    297289        raise NameError, e
     
    301293
    302294    try:
    303         polygon = ensure_numeric(polygon, Float)
     295        polygon = ensure_numeric(polygon, num.Float)
    304296    except NameError, e:
    305297        raise NameError, e
     
    311303    if len(points.shape) == 1:
    312304        # Only one point was passed in. Convert to array of points
    313         points = reshape(points, (1,2))
     305        points = num.reshape(points, (1,2))
    314306
    315307    indices, count = separate_points_by_polygon(points, polygon,
     
    320312    if count == len(indices):
    321313        # No points are outside
    322         return array([])
     314        return num.array([])
    323315    else:
    324316        return indices[count:][::-1]  #return reversed
     
    335327    #if verbose: print 'Checking input to outside_polygon'
    336328    try:
    337         points = ensure_numeric(points, Float)
     329        points = ensure_numeric(points, num.Float)
    338330    except NameError, e:
    339331        raise NameError, e
     
    343335
    344336    try:
    345         polygon = ensure_numeric(polygon, Float)
     337        polygon = ensure_numeric(polygon, num.Float)
    346338    except NameError, e:
    347339        raise NameError, e
     
    352344    if len(points.shape) == 1:
    353345        # Only one point was passed in. Convert to array of points
    354         points = reshape(points, (1,2))
     346        points = num.reshape(points, (1,2))
    355347
    356348
     
    422414
    423415    try:
    424         points = ensure_numeric(points, Float)
     416        points = ensure_numeric(points, num.Float)
    425417    except NameError, e:
    426418        raise NameError, e
     
    431423    #if verbose: print 'Checking input to separate_points_by_polygon 2'
    432424    try:
    433         polygon = ensure_numeric(polygon, Float)
     425        polygon = ensure_numeric(polygon, num.Float)
    434426    except NameError, e:
    435427        raise NameError, e
     
    453445        # Only one point was passed in.
    454446        # Convert to array of points
    455         points = reshape(points, (1,2))
     447        points = num.reshape(points, (1,2))
    456448
    457449   
     
    472464
    473465
    474     indices = zeros( M, Int )
     466    indices = num.zeros( M, num.Int )
    475467
    476468    count = _separate_points_by_polygon(points, polygon, indices,
     
    607599
    608600    try:
    609         polygon = ensure_numeric(polygon, Float)
     601        polygon = ensure_numeric(polygon, num.Float)
    610602    except NameError, e:
    611603        raise NameError, e
     
    616608    x = polygon[:,0]
    617609    y = polygon[:,1]
    618     x = concatenate((x, [polygon[0,0]]), axis = 0)
    619     y = concatenate((y, [polygon[0,1]]), axis = 0)
     610    x = num.concatenate((x, [polygon[0,0]]), axis = 0)
     611    y = num.concatenate((y, [polygon[0,1]]), axis = 0)
    620612   
    621613    return x, y
     
    716708
    717709    def __call__(self, x, y):
    718         x = array(x).astype(Float)
    719         y = array(y).astype(Float)
     710        x = num.array(x).astype(num.Float)
     711        y = num.array(y).astype(num.Float)
    720712
    721713        N = len(x)
    722714        assert len(y) == N
    723715
    724         points = concatenate( (reshape(x, (N, 1)),
    725                                reshape(y, (N, 1))), axis=1 )
     716        points = num.concatenate( (num.reshape(x, (N, 1)),
     717                                   num.reshape(y, (N, 1))), axis=1 )
    726718
    727719        if callable(self.default):
    728720            z = self.default(x,y)
    729721        else:
    730             z = ones(N, Float) * self.default
     722            z = num.ones(N, num.Float) * self.default
    731723
    732724        for polygon, value in self.regions:
     
    736728            if callable(value):
    737729                for i in indices:
    738                     xx = array([x[i]])
    739                     yy = array([y[i]])
     730                    xx = num.array([x[i]])
     731                    yy = num.array([y[i]])
    740732                    z[i] = value(xx, yy)[0]
    741733            else:
  • anuga_core/source/anuga/utilities/quad.py

    r5897 r6158  
    66from treenode import TreeNode
    77import string, types, sys
     8
    89
    910#FIXME verts are added one at a time.
     
    435436    """
    436437
    437     from Numeric import minimum, maximum
    438 
    439438
    440439    #Make root cell
  • anuga_core/source/anuga/utilities/sparse.py

    r5897 r6158  
    11"""Proof of concept sparse matrix code
    22"""
     3
     4import Numeric as num
    35
    46
     
    1719           
    1820        if len(args) == 1:
    19             from Numeric import array
    2021            try:
    21                 A = array(args[0])
     22                A = num.array(args[0])
    2223            except:
    2324                raise 'Input must be convertable to a Numeric array'
     
    9293
    9394    def todense(self):
    94         from Numeric import zeros, Float
    95 
    96         D = zeros( (self.M, self.N), Float)
     95        D = num.zeros( (self.M, self.N), num.Float)
    9796       
    9897        for i in range(self.M):
     
    109108        """
    110109
    111         from Numeric import array, zeros, Float
    112        
    113110        try:
    114             B = array(other)
     111            B = num.array(other)
    115112        except:
    116113            msg = 'FIXME: Only Numeric types implemented so far'
     
    130127            assert B.shape[0] == self.N, msg
    131128
    132             R = zeros(self.M, Float) #Result
     129            R = num.zeros(self.M, num.Float) #Result
    133130           
    134131            # Multiply nonzero elements
     
    140137       
    141138           
    142             R = zeros((self.M, B.shape[1]), Float) #Result matrix
     139            R = num.zeros((self.M, B.shape[1]), num.Float) #Result matrix
    143140
    144141            # Multiply nonzero elements
     
    162159        """
    163160
    164         from Numeric import array, zeros, Float
    165        
    166161        new = other.copy()
    167162        for key in self.Data.keys():
     
    177172        """
    178173
    179         from Numeric import array, zeros, Float
    180        
    181174        try:
    182175            other = float(other)
     
    200193        """
    201194
    202         from Numeric import array, zeros, Float
    203        
    204195        try:
    205             B = array(other)
     196            B = num.array(other)
    206197        except:
    207198            print 'FIXME: Only Numeric types implemented so far'
     
    214205            assert B.shape[0] == self.M, 'Mismatching dimensions'
    215206
    216             R = zeros((self.N,), Float) #Result
     207            R = num.zeros((self.N,), num.Float) #Result
    217208
    218209            #Multiply nonzero elements
     
    251242        """
    252243
    253         from Numeric import array, Float, Int
    254 
    255244        if isinstance(A,Sparse):
    256245
    257             from Numeric import zeros
    258246            keys = A.Data.keys()
    259247            keys.sort()
    260248            nnz = len(keys)
    261             data    = zeros ( (nnz,), Float)
    262             colind  = zeros ( (nnz,), Int)
    263             row_ptr = zeros ( (A.M+1,), Int)
     249            data    = num.zeros ( (nnz,), num.Float)
     250            colind  = num.zeros ( (nnz,), num.Int)
     251            row_ptr = num.zeros ( (A.M+1,), num.Int)
    264252            current_row = -1
    265253            k = 0
     
    299287
    300288    def todense(self):
    301         from Numeric import zeros, Float
    302 
    303         D = zeros( (self.M, self.N), Float)
     289        D = num.zeros( (self.M, self.N), num.Float)
    304290       
    305291        for i in range(self.M):
     
    314300        """
    315301
    316         from Numeric import array, zeros, Float
    317        
    318302        try:
    319             B = array(other)
     303            B = num.array(other)
    320304        except:
    321305            print 'FIXME: Only Numeric types implemented so far'
     
    334318    # A little selftest
    335319   
    336     from Numeric import allclose, array, Float
    337    
    338320    A = Sparse(3,3)
    339321
     
    366348    u = A*v
    367349    print u
    368     assert allclose(u, [6,14,4])
     350    assert num.allclose(u, [6,14,4])
    369351
    370352    u = A.trans_mult(v)
    371353    print u
    372     assert allclose(u, [6,6,10])
     354    assert num.allclose(u, [6,6,10])
    373355
    374356    #Right hand side column
    375     v = array([[2,4],[3,4],[4,4]])
     357    v = num.array([[2,4],[3,4],[4,4]])
    376358
    377359    u = A*v[:,0]
    378     assert allclose(u, [6,14,4])
     360    assert num.allclose(u, [6,14,4])
    379361
    380362    #u = A*v[:,1]
  • anuga_core/source/anuga/utilities/test_cg_solve.py

    r5897 r6158  
    66
    77
    8 from Numeric import dot, allclose, array, transpose, arange, ones, Float
     8import Numeric as num
    99from anuga.utilities.cg_solve import *
    1010from anuga.utilities.cg_solve import _conjugate_gradient
     
    3030        x = conjugate_gradient(A,b,x,iprint=0)
    3131
    32         assert allclose(x,xe)
     32        assert num.allclose(x,xe)
    3333
    3434    def test_max_iter(self):
     
    6161        A = Sparse(n,n)
    6262
    63         for i in arange(0,n):
     63        for i in num.arange(0,n):
    6464            A[i,i] = 1.0
    6565            if i > 0 :
     
    6868                A[i,i+1] = -0.5
    6969
    70         xe = ones( (n,), Float)
     70        xe = num.ones( (n,), num.Float)
    7171
    7272        b  = A*xe
    7373        x = conjugate_gradient(A,b,b,tol=1.0e-5,iprint=1)
    7474
    75         assert allclose(x,xe)
     75        assert num.allclose(x,xe)
    7676
    7777    def test_solve_large_2d(self):
     
    8383        A = Sparse(m*n, m*n)
    8484
    85         for i in arange(0,n):
    86             for j in arange(0,m):
     85        for i in num.arange(0,n):
     86            for j in num.arange(0,m):
    8787                I = j+m*i
    8888                A[I,I] = 4.0
     
    9696                    A[I,I+1] = -1.0
    9797
    98         xe = ones( (n*m,), Float)
     98        xe = num.ones( (n*m,), num.Float)
    9999
    100100        b  = A*xe
    101101        x = conjugate_gradient(A,b,b,iprint=0)
    102102
    103         assert allclose(x,xe)
     103        assert num.allclose(x,xe)
    104104
    105105    def test_solve_large_2d_csr_matrix(self):
     
    112112        A = Sparse(m*n, m*n)
    113113
    114         for i in arange(0,n):
    115             for j in arange(0,m):
     114        for i in num.arange(0,n):
     115            for j in num.arange(0,m):
    116116                I = j+m*i
    117117                A[I,I] = 4.0
     
    125125                    A[I,I+1] = -1.0
    126126
    127         xe = ones( (n*m,), Float)
     127        xe = num.ones( (n*m,), num.Float)
    128128
    129129        # Convert to csr format
     
    134134        x = conjugate_gradient(A,b,b,iprint=20)
    135135
    136         assert allclose(x,xe)
     136        assert num.allclose(x,xe)
    137137
    138138
     
    145145        A = Sparse(m*n, m*n)
    146146
    147         for i in arange(0,n):
    148             for j in arange(0,m):
     147        for i in num.arange(0,n):
     148            for j in num.arange(0,m):
    149149                I = j+m*i
    150150                A[I,I] = 4.0
     
    158158                    A[I,I+1] = -1.0
    159159
    160         xe = ones( (n*m,), Float)
     160        xe = num.ones( (n*m,), num.Float)
    161161
    162162        b  = A*xe
    163163        x = conjugate_gradient(A,b)
    164164
    165         assert allclose(x,xe)
     165        assert num.allclose(x,xe)
    166166
    167167
     
    202202        x = conjugate_gradient(A,b,x,iprint=0)
    203203
    204         assert allclose(x,xe)
     204        assert num.allclose(x,xe)
    205205
    206206#-------------------------------------------------------------
  • anuga_core/source/anuga/utilities/test_data_audit.py

    r5897 r6158  
    11#!/usr/bin/env python
    22
    3 
    43import unittest
    5 from Numeric import zeros, array, allclose, Float
    64from tempfile import mkstemp
    75import os
    86
    97from data_audit import *
     8
    109
    1110class Test_data_audit(unittest.TestCase):
  • anuga_core/source/anuga/utilities/test_numerical_tools.py

    r5897 r6158  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose
    6 from Numeric import ArrayType, Float, Int, array, alltrue
     5import Numeric as num
    76
    87from math import sqrt, pi
     
    109from numerical_tools import *
    1110
     11
    1212def test_function(x, y):
    1313    return x+y
     
    2323        """Test angles between one vector and the x-axis
    2424        """
    25         assert allclose(angle([1.0, 0.0])/pi*180, 0.0)     
    26         assert allclose(angle([1.0, 1.0])/pi*180, 45.0)
    27         assert allclose(angle([0.0, 1.0])/pi*180, 90.0)         
    28         assert allclose(angle([-1.0, 1.0])/pi*180, 135.0)               
    29         assert allclose(angle([-1.0, 0.0])/pi*180, 180.0)
    30         assert allclose(angle([-1.0, -1.0])/pi*180, 225.0)
    31         assert allclose(angle([0.0, -1.0])/pi*180, 270.0)
    32         assert allclose(angle([1.0, -1.0])/pi*180, 315.0)
     25        assert num.allclose(angle([1.0, 0.0])/pi*180, 0.0)         
     26        assert num.allclose(angle([1.0, 1.0])/pi*180, 45.0)
     27        assert num.allclose(angle([0.0, 1.0])/pi*180, 90.0)             
     28        assert num.allclose(angle([-1.0, 1.0])/pi*180, 135.0)           
     29        assert num.allclose(angle([-1.0, 0.0])/pi*180, 180.0)
     30        assert num.allclose(angle([-1.0, -1.0])/pi*180, 225.0)
     31        assert num.allclose(angle([0.0, -1.0])/pi*180, 270.0)
     32        assert num.allclose(angle([1.0, -1.0])/pi*180, 315.0)
    3333               
    3434                                                         
     
    3737        """   
    3838       
    39         assert allclose(angle([1.0, 0.0], [1.0, 1.0])/pi*180, 315.0)
    40         assert allclose(angle([1.0, 1.0], [1.0, 0.0])/pi*180, 45.0)
     39        assert num.allclose(angle([1.0, 0.0], [1.0, 1.0])/pi*180, 315.0)
     40        assert num.allclose(angle([1.0, 1.0], [1.0, 0.0])/pi*180, 45.0)
    4141               
    42         assert allclose(angle([-1.0, -1.0], [1.0, 1.0])/pi*180, 180)   
    43         assert allclose(angle([-1.0, -1.0], [-1.0, 1.0])/pi*180, 90.0) 
     42        assert num.allclose(angle([-1.0, -1.0], [1.0, 1.0])/pi*180, 180)       
     43        assert num.allclose(angle([-1.0, -1.0], [-1.0, 1.0])/pi*180, 90.0)     
    4444       
    45         assert allclose(angle([-1.0, 0.0], [1.0, 1.0])/pi*180, 135.0)
    46         assert allclose(angle([0.0, -1.0], [1.0, 1.0])/pi*180, 225.0)   
     45        assert num.allclose(angle([-1.0, 0.0], [1.0, 1.0])/pi*180, 135.0)
     46        assert num.allclose(angle([0.0, -1.0], [1.0, 1.0])/pi*180, 225.0)       
    4747       
    48         assert allclose(angle([1.0, -1.0], [1.0, 1.0])/pi*180, 270.0)   
    49         assert allclose(angle([1.0, 0.0], [0.0, 1.0])/pi*180, 270.0)
     48        assert num.allclose(angle([1.0, -1.0], [1.0, 1.0])/pi*180, 270.0)       
     49        assert num.allclose(angle([1.0, 0.0], [0.0, 1.0])/pi*180, 270.0)
    5050
    5151        #From test_get_boundary_polygon_V
    5252        v_prev = [-0.5, -0.5]
    5353        vc = [ 0.0,  -0.5]
    54         assert allclose(angle(vc, v_prev)/pi*180, 45.0)
     54        assert num.allclose(angle(vc, v_prev)/pi*180, 45.0)
    5555
    5656        vc = [ 0.5,  0.0]
    57         assert allclose(angle(vc, v_prev)/pi*180, 135.0)
     57        assert num.allclose(angle(vc, v_prev)/pi*180, 135.0)
    5858
    5959        vc = [ -0.5,  0.5]
    60         assert allclose(angle(vc, v_prev)/pi*180, 270.0)               
     60        assert num.allclose(angle(vc, v_prev)/pi*180, 270.0)               
    6161
    6262
    6363    def test_anglediff(self):
    64         assert allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0)
     64        assert num.allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0)
    6565
    6666       
     
    6868        A = [1,2,3,4]
    6969        B = ensure_numeric(A)
    70         assert type(B) == ArrayType
     70        assert type(B) == num.ArrayType
    7171        assert B.typecode() == 'l'
    7272        assert B[0] == 1 and B[1] == 2 and B[2] == 3 and B[3] == 4
     
    7474        A = [1,2,3.14,4]
    7575        B = ensure_numeric(A)
    76         assert type(B) == ArrayType
     76        assert type(B) == num.ArrayType
    7777        assert B.typecode() == 'd'
    7878        assert B[0] == 1 and B[1] == 2 and B[2] == 3.14 and B[3] == 4
    7979
    8080        A = [1,2,3,4]
    81         B = ensure_numeric(A, Float)
    82         assert type(B) == ArrayType
     81        B = ensure_numeric(A, num.Float)
     82        assert type(B) == num.ArrayType
    8383        assert B.typecode() == 'd'
    8484        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    8585
    8686        A = [1,2,3,4]
    87         B = ensure_numeric(A, Float)
    88         assert type(B) == ArrayType
     87        B = ensure_numeric(A, num.Float)
     88        assert type(B) == num.ArrayType
    8989        assert B.typecode() == 'd'
    9090        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    9191
    92         A = array([1,2,3,4])
     92        A = num.array([1,2,3,4])
    9393        B = ensure_numeric(A)
    94         assert type(B) == ArrayType
     94        assert type(B) == num.ArrayType
    9595        assert B.typecode() == 'l'       
    96         assert alltrue(A == B)   
     96        assert num.alltrue(A == B)   
    9797        assert A is B   #Same object
    9898
    99         A = array([1,2,3,4])
    100         B = ensure_numeric(A, Float)
    101         assert type(B) == ArrayType
     99        A = num.array([1,2,3,4])
     100        B = ensure_numeric(A, num.Float)
     101        assert type(B) == num.ArrayType
    102102        assert B.typecode() == 'd'       
    103         assert alltrue(A == B)   
     103        assert num.alltrue(A == B)   
    104104        assert A is not B   #Not the same object
    105105
    106106        # Check scalars
    107107        A = 1
    108         B = ensure_numeric(A, Float)
     108        B = ensure_numeric(A, num.Float)
    109109        #print A, B[0], len(B), type(B)
    110110        #print B.shape
    111         assert alltrue(A == B)
    112 
    113         B = ensure_numeric(A, Int)       
     111        assert num.alltrue(A == B)
     112
     113        B = ensure_numeric(A, num.Int)       
    114114        #print A, B
    115115        #print B.shape
    116         assert alltrue(A == B)
     116        assert num.alltrue(A == B)
    117117
    118118        # Error situation
    119119
    120         B = ensure_numeric('hello', Int)               
    121         assert allclose(B, [104, 101, 108, 108, 111])
     120        B = ensure_numeric('hello', num.Int)               
     121        assert num.allclose(B, [104, 101, 108, 108, 111])
    122122
    123123
     
    208208        #There are four elements greater than or equal to 3
    209209        bins = [3]
    210         assert allclose(histogram(a, bins), [4])
     210        assert num.allclose(histogram(a, bins), [4])
    211211
    212212        bins = [ min(a) ]
    213         assert allclose(histogram(a, bins), [len(a)])
     213        assert num.allclose(histogram(a, bins), [len(a)])
    214214
    215215        bins = [ max(a)+0.00001 ]
    216         assert allclose(histogram(a, bins), [0])       
     216        assert num.allclose(histogram(a, bins), [0])       
    217217       
    218218        bins = [1,2,3,4]
    219         assert allclose(histogram(a, bins), [8,3,3,1])
     219        assert num.allclose(histogram(a, bins), [8,3,3,1])
    220220
    221221        bins = [1.1,2,3.1,4]
    222222        #print histogram(a, bins)
    223         assert allclose(histogram(a, bins), [0,6,0,1])
     223        assert num.allclose(histogram(a, bins), [0,6,0,1])
    224224
    225225        bins = [0,1.5,2,3]
    226         assert allclose(histogram(a, bins), [8,0,3,4])
    227         assert allclose(histogram(a, [0,3]), histogram(a, [-0.5,3]))
     226        assert num.allclose(histogram(a, bins), [8,0,3,4])
     227        assert num.allclose(histogram(a, [0,3]), histogram(a, [-0.5,3]))
    228228
    229229        # Check situation with #bins >= #datapoints
    230230        a = [1.7]
    231231        bins = [0,1.5,2,3]
    232         assert allclose(histogram(a, bins), [0,1,0,0])
     232        assert num.allclose(histogram(a, bins), [0,1,0,0])
    233233
    234234        a = [1.7]
    235235        bins = [0]
    236         assert allclose(histogram(a, bins), [1])
     236        assert num.allclose(histogram(a, bins), [1])
    237237
    238238        a = [-1.7]
    239239        bins = [0]
    240         assert allclose(histogram(a, bins), [0])
     240        assert num.allclose(histogram(a, bins), [0])
    241241
    242242        a = [-1.7]
    243243        bins = [-1.7]
    244         assert allclose(histogram(a, bins), [1])       
     244        assert num.allclose(histogram(a, bins), [1])       
    245245       
    246246
  • anuga_core/source/anuga/utilities/test_polygon.py

    r6000 r6158  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose
     5import Numeric as num
    66from math import sqrt, pi
    77from anuga.utilities.numerical_tools import ensure_numeric
     
    4545        f = Polygon_function( [(p1, 1.0)] )
    4646        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1
    47         assert allclose(z, [1,1,0,0])
     47        assert num.allclose(z, [1,1,0,0])
    4848
    4949
    5050        f = Polygon_function( [(p2, 2.0)] )
    5151        z = f([5, 5, 27, 35], [5, 9, 8, -5]) # First and last inside p2
    52         assert allclose(z, [2,0,0,2])
     52        assert num.allclose(z, [2,0,0,2])
    5353
    5454
     
    5656        f = Polygon_function( [(p1, 1.0), (p2, 2.0)] )
    5757        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    58         assert allclose(z, [2,1,0,2])
     58        assert num.allclose(z, [2,1,0,2])
    5959
    6060    def test_polygon_function_csvfile(self):
     
    7272        z = f([430000,480000], [490000,7720000]) # first outside, second inside
    7373       
    74         assert allclose(z, [0,10])
     74        assert num.allclose(z, [0,10])
    7575
    7676    def test_polygon_function_georef(self):
     
    9090        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1
    9191
    92         assert allclose(z, [1,1,0,0])
     92        assert num.allclose(z, [1,1,0,0])
    9393
    9494
    9595        f = Polygon_function( [(p2, 2.0)], geo_reference=geo)
    9696        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #First and last inside p2
    97         assert allclose(z, [2,0,0,2])
     97        assert num.allclose(z, [2,0,0,2])
    9898
    9999
     
    101101        f = Polygon_function( [(p1, 1.0), (p2, 2.0)], geo_reference=geo)
    102102        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    103         assert allclose(z, [2,1,0,2])
     103        assert num.allclose(z, [2,1,0,2])
    104104
    105105
     
    107107        f = Polygon_function( [(p1, 1.0), (p2, 2.0)])
    108108        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    109         assert not allclose(z, [2,1,0,2])       
     109        assert not num.allclose(z, [2,1,0,2])       
    110110
    111111
     
    120120        f = Polygon_function( [(p1, test_function)] )
    121121        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1
    122         assert allclose(z, [10,14,0,0])
     122        assert num.allclose(z, [10,14,0,0])
    123123
    124124        # Combined
    125125        f = Polygon_function( [(p1, test_function), (p2, 2.0)] )
    126126        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    127         assert allclose(z, [2,14,0,2])
     127        assert num.allclose(z, [2,14,0,2])
    128128
    129129
     
    131131        f = Polygon_function( [(p1, test_function), (p2, 2.0)], default = 3.14)
    132132        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    133         assert allclose(z, [2,14,3.14,2])
     133        assert num.allclose(z, [2,14,3.14,2])
    134134
    135135
     
    138138                              default = test_function)
    139139        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    140         assert allclose(z, [2,14,35,2])
     140        assert num.allclose(z, [2,14,35,2])
    141141
    142142
     
    210210        res = inside_polygon(points, polygon)
    211211        assert len(res) == 2
    212         assert allclose(res, [0,1])
     212        assert num.allclose(res, [0,1])
    213213
    214214
     
    305305        res = inside_polygon( points, polygon, verbose=False )
    306306
    307         assert allclose( res, [0,1,2] )
     307        assert num.allclose( res, [0,1,2] )
    308308
    309309    def test_outside_polygon(self):
     
    317317       
    318318        indices = outside_polygon( [[0.5, 0.5], [1, -0.5], [0.3, 0.2]], U )
    319         assert allclose( indices, [1] )
     319        assert num.allclose( indices, [1] )
    320320       
    321321        # One more test of vector formulation returning indices
     
    324324        res = outside_polygon( points, polygon )
    325325
    326         assert allclose( res, [3, 4] )
     326        assert num.allclose( res, [3, 4] )
    327327
    328328
     
    332332        res = outside_polygon( points, polygon )
    333333
    334         assert allclose( res, [0, 4, 5] )       
     334        assert num.allclose( res, [0, 4, 5] )       
    335335     
    336336    def test_outside_polygon2(self):
     
    355355        #print indices, count
    356356        assert count == 0 #None inside
    357         assert allclose(indices, [3,2,1,0])
     357        assert num.allclose(indices, [3,2,1,0])
    358358
    359359        indices = outside_polygon(points, U, closed = True)
    360         assert allclose(indices, [0,1,2,3])
     360        assert num.allclose(indices, [0,1,2,3])
    361361
    362362        indices = inside_polygon(points, U, closed = True)
    363         assert allclose(indices, [])               
     363        assert num.allclose(indices, [])               
    364364
    365365
     
    375375        indices, count = separate_points_by_polygon(points, U)
    376376        assert count == 3 #All inside
    377         assert allclose(indices, [0,1,2])
     377        assert num.allclose(indices, [0,1,2])
    378378
    379379        indices = outside_polygon(points, U, closed = True)
    380         assert allclose(indices, [])
     380        assert num.allclose(indices, [])
    381381
    382382        indices = inside_polygon(points, U, closed = True)
    383         assert allclose(indices, [0,1,2])
     383        assert num.allclose(indices, [0,1,2])
    384384       
    385385
     
    388388
    389389        indices, count = separate_points_by_polygon( [[0.5, 0.5], [1, -0.5], [0.3, 0.2]], U )
    390         assert allclose( indices, [0,2,1] )
     390        assert num.allclose( indices, [0,2,1] )
    391391        assert count == 2
    392392       
     
    396396        res, count = separate_points_by_polygon( points, polygon )
    397397
    398         assert allclose( res, [0,1,2,4,3] )
     398        assert num.allclose( res, [0,1,2,4,3] )
    399399        assert count == 3
    400400
     
    404404        res, count = separate_points_by_polygon( points, polygon )
    405405
    406         assert allclose( res, [1,2,3,5,4,0] )       
     406        assert num.allclose( res, [1,2,3,5,4,0] )       
    407407        assert count == 3
    408408       
     
    588588        status, value = intersection(line0, line1)
    589589        assert status == 1
    590         assert allclose(value, [0.0, 0.0])
     590        assert num.allclose(value, [0.0, 0.0])
    591591
    592592    def test_intersection2(self):
     
    596596        status, value = intersection(line0, line1)
    597597        assert status == 1
    598         assert allclose(value, [12.0, 6.0])
     598        assert num.allclose(value, [12.0, 6.0])
    599599
    600600        # Swap direction of one line
     
    603603        status, value = intersection(line0, line1)
    604604        assert status == 1
    605         assert allclose(value, [12.0, 6.0])
     605        assert num.allclose(value, [12.0, 6.0])
    606606
    607607        # Swap order of lines
    608608        status, value = intersection(line1, line0)
    609609        assert status == 1
    610         assert allclose(value, [12.0, 6.0])       
     610        assert num.allclose(value, [12.0, 6.0])       
    611611       
    612612    def test_intersection3(self):
     
    616616        status, value = intersection(line0, line1)
    617617        assert status == 1
    618         assert allclose(value, [14.068965517, 7.0344827586])
     618        assert num.allclose(value, [14.068965517, 7.0344827586])
    619619
    620620        # Swap direction of one line
     
    623623        status, value = intersection(line0, line1)
    624624        assert status == 1
    625         assert allclose(value, [14.068965517, 7.0344827586])       
     625        assert num.allclose(value, [14.068965517, 7.0344827586])       
    626626
    627627        # Swap order of lines
    628628        status, value = intersection(line1, line0)
    629629        assert status == 1       
    630         assert allclose(value, [14.068965517, 7.0344827586])       
     630        assert num.allclose(value, [14.068965517, 7.0344827586])       
    631631
    632632
     
    641641        status, value = intersection(line0, line1)
    642642        assert status == 1
    643         assert allclose(value, [1.0, 1.0])
     643        assert num.allclose(value, [1.0, 1.0])
    644644
    645645
     
    649649        status, value = intersection(line0, line1)
    650650        assert status == 1
    651         assert allclose(value, [1.0, 1.0])       
     651        assert num.allclose(value, [1.0, 1.0])       
    652652
    653653
     
    713713        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    714714                               (str(status), str(value)))
    715         self.failUnless(allclose(value, line0))
     715        self.failUnless(num.allclose(value, line0))
    716716
    717717        # line0 fully within line1, same direction
     
    725725        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    726726                               (str(status), str(value)))
    727         self.failUnless(allclose(value, line0))
     727        self.failUnless(num.allclose(value, line0))
    728728
    729729        # line0 fully within line1, opposite direction
     
    737737        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    738738                               (str(status), str(value)))
    739         self.failUnless(allclose(value, line0))
     739        self.failUnless(num.allclose(value, line0))
    740740
    741741        # line0 fully within line1, opposite direction
     
    749749        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    750750                               (str(status), str(value)))
    751         self.failUnless(allclose(value, line0))
     751        self.failUnless(num.allclose(value, line0))
    752752
    753753        #----------------------------------------------------------------------
     
    763763        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    764764                               (str(status), str(value)))
    765         self.failUnless(allclose(value, line1))
     765        self.failUnless(num.allclose(value, line1))
    766766
    767767        # line1 fully within line0, same direction
     
    775775        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    776776                               (str(status), str(value)))
    777         self.failUnless(allclose(value, line1))
     777        self.failUnless(num.allclose(value, line1))
    778778
    779779        # line1 fully within line0, opposite direction
     
    787787        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    788788                               (str(status), str(value)))
    789         self.failUnless(allclose(value, line1))
     789        self.failUnless(num.allclose(value, line1))
    790790
    791791        # line1 fully within line0, opposite direction
     
    799799        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    800800                               (str(status), str(value)))
    801         self.failUnless(allclose(value, line1))
     801        self.failUnless(num.allclose(value, line1))
    802802
    803803        #----------------------------------------------------------------------
     
    813813        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    814814                               (str(status), str(value)))
    815         self.failUnless(allclose(value, [line1[0],line0[1]]))
     815        self.failUnless(num.allclose(value, [line1[0],line0[1]]))
    816816
    817817        # line in same direction, partial overlap
     
    825825        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    826826                               (str(status), str(value)))
    827         self.failUnless(allclose(value, [line0[0],line1[1]]))
     827        self.failUnless(num.allclose(value, [line0[0],line1[1]]))
    828828
    829829        # line in opposite direction, partial overlap
     
    837837        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    838838                               (str(status), str(value)))
    839         self.failUnless(allclose(value, [line0[0],line1[0]]))
     839        self.failUnless(num.allclose(value, [line0[0],line1[0]]))
    840840
    841841        # line in opposite direction, partial overlap
     
    849849        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    850850                               (str(status), str(value)))
    851         self.failUnless(allclose(value, [line1[1],line0[1]]))
     851        self.failUnless(num.allclose(value, [line1[1],line0[1]]))
    852852
    853853        #----------------------------------------------------------------------
     
    863863        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    864864                               (str(status), str(value)))
    865         self.failUnless(allclose(value, [line0[0],line1[1]]))
     865        self.failUnless(num.allclose(value, [line0[0],line1[1]]))
    866866
    867867        # line in same direction, partial overlap
     
    875875        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    876876                               (str(status), str(value)))
    877         self.failUnless(allclose(value, [line1[0],line0[1]]))
     877        self.failUnless(num.allclose(value, [line1[0],line0[1]]))
    878878
    879879        # line in opposite direction, partial overlap
     
    887887        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    888888                               (str(status), str(value)))
    889         self.failUnless(allclose(value, [line1[1],line0[1]]))
     889        self.failUnless(num.allclose(value, [line1[1],line0[1]]))
    890890
    891891        # line in opposite direction, partial overlap
     
    899899        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    900900                               (str(status), str(value)))
    901         self.failUnless(allclose(value, [line0[0],line1[0]]))
     901        self.failUnless(num.allclose(value, [line0[0],line1[0]]))
    902902
    903903        #----------------------------------------------------------------------
     
    913913        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    914914                               (str(status), str(value)))
    915         self.failUnless(allclose(value, line0))
     915        self.failUnless(num.allclose(value, line0))
    916916
    917917        # line in same direction, same left point, line1 longer
     
    925925        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    926926                               (str(status), str(value)))
    927         self.failUnless(allclose(value, line0))
     927        self.failUnless(num.allclose(value, line0))
    928928
    929929        # line in opposite direction, same left point, line1 longer
     
    937937        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    938938                               (str(status), str(value)))
    939         self.failUnless(allclose(value, line0))
     939        self.failUnless(num.allclose(value, line0))
    940940
    941941        # line in opposite direction, same start point, line1 longer
     
    949949        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    950950                               (str(status), str(value)))
    951         self.failUnless(allclose(value, line0))
     951        self.failUnless(num.allclose(value, line0))
    952952
    953953        #----------------------------------------------------------------------
     
    963963        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    964964                               (str(status), str(value)))
    965         self.failUnless(allclose(value, line0))
     965        self.failUnless(num.allclose(value, line0))
    966966
    967967        # line in same direction, same left point, same right point
     
    975975        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    976976                               (str(status), str(value)))
    977         self.failUnless(allclose(value, line0))
     977        self.failUnless(num.allclose(value, line0))
    978978
    979979        # line in opposite direction, same left point, same right point
     
    987987        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    988988                               (str(status), str(value)))
    989         self.failUnless(allclose(value, line0))
     989        self.failUnless(num.allclose(value, line0))
    990990
    991991        # line in opposite direction, same left point, same right point
     
    999999        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    10001000                               (str(status), str(value)))
    1001         self.failUnless(allclose(value, line0))
     1001        self.failUnless(num.allclose(value, line0))
    10021002
    10031003        #----------------------------------------------------------------------
     
    10131013        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    10141014                               (str(status), str(value)))
    1015         self.failUnless(allclose(value, line0))
     1015        self.failUnless(num.allclose(value, line0))
    10161016
    10171017        # line in same direction, same right point, line1 longer
     
    10251025        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    10261026                               (str(status), str(value)))
    1027         self.failUnless(allclose(value, line0))
     1027        self.failUnless(num.allclose(value, line0))
    10281028
    10291029        # line in opposite direction, same right point, line1 longer
     
    10371037        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    10381038                               (str(status), str(value)))
    1039         self.failUnless(allclose(value, line0))
     1039        self.failUnless(num.allclose(value, line0))
    10401040
    10411041        # line in opposite direction, same right point, line1 longer
     
    10491049        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    10501050                               (str(status), str(value)))
    1051         self.failUnless(allclose(value, line0))
     1051        self.failUnless(num.allclose(value, line0))
    10521052
    10531053        #----------------------------------------------------------------------
     
    10631063        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    10641064                               (str(status), str(value)))
    1065         self.failUnless(allclose(value, line1))
     1065        self.failUnless(num.allclose(value, line1))
    10661066
    10671067        # line in same direction, same left point, line0 longer
     
    10751075        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    10761076                               (str(status), str(value)))
    1077         self.failUnless(allclose(value, line1))
     1077        self.failUnless(num.allclose(value, line1))
    10781078
    10791079        # line in opposite direction, same left point, line0 longer
     
    10871087        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    10881088                               (str(status), str(value)))
    1089         self.failUnless(allclose(value, line1))
     1089        self.failUnless(num.allclose(value, line1))
    10901090
    10911091        # line in opposite direction, same left point, line0 longer
     
    10991099        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    11001100                               (str(status), str(value)))
    1101         self.failUnless(allclose(value, line1))
     1101        self.failUnless(num.allclose(value, line1))
    11021102
    11031103        #----------------------------------------------------------------------
     
    11131113        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    11141114                               (str(status), str(value)))
    1115         self.failUnless(allclose(value, line1))
     1115        self.failUnless(num.allclose(value, line1))
    11161116
    11171117        # line in same direction, same right point, line0 longer
     
    11251125        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    11261126                               (str(status), str(value)))
    1127         self.failUnless(allclose(value, line1))
     1127        self.failUnless(num.allclose(value, line1))
    11281128
    11291129        # line in opposite direction, same right point, line0 longer
     
    11371137        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    11381138                               (str(status), str(value)))
    1139         self.failUnless(allclose(value, line1))
     1139        self.failUnless(num.allclose(value, line1))
    11401140
    11411141        # line in opposite direction, same right point, line0 longer
     
    11491149        self.failIf(status!=2, 'Expected status 2, got status=%s, value=%s' %
    11501150                               (str(status), str(value)))
    1151         self.failUnless(allclose(value, line1))
     1151        self.failUnless(num.allclose(value, line1))
    11521152
    11531153       
     
    13741374                                                          common_end_point[1])
    13751375            msg += ' gave %s, \nbut when reversed we got %s' %(p1, p2)
    1376             assert allclose(p1, p2), msg
     1376            assert num.allclose(p1, p2), msg
    13771377
    13781378            # Swap order of lines
     
    13801380            assert status == 1                       
    13811381            msg = 'Order of lines gave different results'
    1382             assert allclose(p1, p3), msg
     1382            assert num.allclose(p1, p3), msg
    13831383           
    13841384
     
    14201420        status, value = intersection(line0, line1)
    14211421        assert status == 2
    1422         assert allclose(value, [[0,0], [3,0]])
     1422        assert num.allclose(value, [[0,0], [3,0]])
    14231423
    14241424        # Overlap 2
     
    14281428        status, value = intersection(line0, line1)
    14291429        assert status == 2
    1430         assert allclose(value, [[-3, 0], [5,0]])       
     1430        assert num.allclose(value, [[-3, 0], [5,0]])       
    14311431
    14321432        # Inclusion 1
     
    14361436        status, value = intersection(line0, line1)
    14371437        assert status == 2       
    1438         assert allclose(value, line1)
     1438        assert num.allclose(value, line1)
    14391439
    14401440        # Inclusion 2
     
    14441444        status, value = intersection(line0, line1)
    14451445        assert status == 2       
    1446         assert allclose(value, line0)                                       
     1446        assert num.allclose(value, line0)                                       
    14471447
    14481448
     
    14631463        status, value = intersection(line0, line1)
    14641464        assert status == 2               
    1465         assert allclose(value, [[1, 7], [7, 19]])
     1465        assert num.allclose(value, [[1, 7], [7, 19]])
    14661466
    14671467        status, value = intersection(line1, line0)
    14681468        assert status == 2
    1469         assert allclose(value, [[1, 7], [7, 19]])
     1469        assert num.allclose(value, [[1, 7], [7, 19]])
    14701470
    14711471        # Swap direction
     
    14741474        status, value = intersection(line0, line1)
    14751475        assert status == 2
    1476         assert allclose(value, [[7, 19], [1, 7]])
     1476        assert num.allclose(value, [[7, 19], [1, 7]])
    14771477
    14781478        line0 = [[0,5], [7,19]]
     
    14801480        status, value = intersection(line0, line1)
    14811481        assert status == 2
    1482         assert allclose(value, [[1, 7], [7, 19]])       
     1482        assert num.allclose(value, [[1, 7], [7, 19]])       
    14831483       
    14841484
     
    14881488        status, value = intersection(line0, line1)
    14891489        assert status == 2                       
    1490         assert allclose(value, [[1,7], [7, 19]])               
     1490        assert num.allclose(value, [[1,7], [7, 19]])               
    14911491
    14921492        line0 = [[0,5], [10,25]]
     
    14941494        status, value = intersection(line0, line1)
    14951495        assert status == 2                       
    1496         assert allclose(value, [[1,7], [7, 19]])
     1496        assert num.allclose(value, [[1,7], [7, 19]])
    14971497
    14981498
     
    15011501        status, value = intersection(line0, line1)
    15021502        assert status == 2                       
    1503         assert allclose(value, [[7, 19], [1, 7]])                       
     1503        assert num.allclose(value, [[7, 19], [1, 7]])                       
    15041504       
    15051505       
     
    15381538        res = inside_polygon(points, polygon)
    15391539        assert len(res) == 2
    1540         assert allclose(res, [0,1])
     1540        assert num.allclose(res, [0,1])
    15411541
    15421542    def test_polygon_area(self):
  • anuga_core/source/anuga/utilities/test_quad.py

    r5897 r6158  
    11import unittest
    2 from Numeric import array, allclose
     2import Numeric as num
    33
    44from quad import Cell, build_quadtree
     
    236236                     [ 0.,  -1.]]
    237237                     
    238         # assert allclose(array(results),[[[ 2.,  1.],
     238        # assert num.allclose(num.array(results),[[[ 2.,  1.],
    239239        #[ 4.,  1.], [ 4.,  4.]], [[ 4.,  1.],[ 5.,  4.],[ 4.,  4.]]] )
    240240        results = Q.search(5,4.)
  • 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
  • anuga_core/source/anuga/utilities/test_system_tools.py

    r6086 r6158  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose, Float
     5import Numeric as num
    66import zlib
    77from os.path import join, split, sep
     
    8282            pass
    8383        else:
    84             test_array = array([[7.0, 3.14], [-31.333, 0.0]])
     84            test_array = num.array([[7.0, 3.14], [-31.333, 0.0]])
    8585
    8686            # First file
     
    8888            fid = NetCDFFile(filename1, netcdf_mode_w)
    8989            fid.createDimension('two', 2)
    90             fid.createVariable('test_array', Float,
     90            fid.createVariable('test_array', num.Float,
    9191                               ('two', 'two'))
    9292            fid.variables['test_array'][:] = test_array
     
    9797            fid = NetCDFFile(filename2, netcdf_mode_w)
    9898            fid.createDimension('two', 2)
    99             fid.createVariable('test_array', Float,
     99            fid.createVariable('test_array', num.Float,
    100100                               ('two', 'two'))
    101101            fid.variables['test_array'][:] = test_array
  • anuga_core/source/anuga/utilities/test_xml_tools.py

    r5897 r6158  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose, Float
    65from tempfile import mkstemp, mktemp
    76
Note: See TracChangeset for help on using the changeset viewer.