Changeset 5891


Ignore:
Timestamp:
Nov 5, 2008, 4:19:05 PM (16 years ago)
Author:
rwilson
Message:

Converted to full numpy.

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

Legend:

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

    r2841 r5891  
     1
    12import exceptions
    23class VectorShapeError(exceptions.Exception): pass
    34class ConvergenceError(exceptions.Exception): pass
    45
    5 from Numeric import dot, array, Float, zeros
     6import numpy
    67   
    78import logging, logging.config
     
    2425   
    2526    if x0 is None:
    26         x0 = zeros(b.shape, typecode=Float)
     27        x0 = numpy.zeros(b.shape, dtype=numpy.float)
    2728    else:
    28         x0 = array(x0, typecode=Float)
     29        x0 = numpy.array(x0, dtype=numpy.float)
    2930
    30     b  = array(b, typecode=Float)
     31    b  = numpy.array(b, dtype=numpy.float)
    3132    if len(b.shape) != 1 :
    3233       
     
    5758
    5859
    59    b  = array(b, typecode=Float)
     60   b  = numpy.array(b, dtype=numpy.float)
    6061   if len(b.shape) != 1 :
    6162      raise VectorShapeError, 'input vector should consist of only one column'
    6263
    6364   if x0 is None:
    64       x0 = zeros(b.shape, typecode=Float)
     65      x0 = numpy.zeros(b.shape, dtype=numpy.float)
    6566   else:
    66       x0 = array(x0, typecode=Float)
     67      x0 = numpy.array(x0, dtype=numpy.float)
    6768
    6869
     
    7576   r = b - A*x
    7677   d = r
    77    rTr = dot(r,r)
     78   rTr = numpy.dot(r,r)
    7879   rTr0 = rTr
    7980
    8081   while (i<imax and rTr>tol**2*rTr0):
    8182       q = A*d
    82        alpha = rTr/dot(d,q)
     83       alpha = rTr/numpy.dot(d,q)
    8384       x = x + alpha*d
    8485       if i%50 :
     
    8788           r = r - alpha*q
    8889       rTrOld = rTr
    89        rTr = dot(r,r)
     90       rTr = numpy.dot(r,r)
    9091       bt = rTr/rTrOld
    9192
  • anuga_core/source/anuga/utilities/compile.py

    r5138 r5891  
    1010   Ole Nielsen, Duncan Gray Oct 2001     
    1111"""     
     12
     13#NumPy ------------------------------------
     14# Something like these lines recommended in "Converting from NUMARRAY to NUMPY"
     15import numpy
     16numpyincludedirs = numpy.get_include()
     17I_dirs = '-I"%s" ' % numpyincludedirs
     18#NumPy ------------------------------------
    1219
    1320# FIXME (Ole): Although this script says it works with a range of compilers,
     
    255262    else:
    256263      if FN == "triangle.c" or FN == "mesh_engine_c_layer.c":
    257         s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -O3 -DTRILIBRARY=1 -DNO_TIMER=1'\
    258             %(compiler, FN, python_include, utilities_include_dir, root)
     264#NumPy        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -O3 -DTRILIBRARY=1 -DNO_TIMER=1'\
     265        s = '%s -c %s %s -I"%s" -I"%s" -o "%s.o" -O3 -DTRILIBRARY=1 -DNO_TIMER=1'\
     266            %(compiler, FN, I_dirs, python_include, utilities_include_dir, root)
    259267      else:
    260         s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
    261             %(compiler, FN, python_include, utilities_include_dir, root)
     268#NumPy        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
     269        s = '%s -c %s %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
     270            %(compiler, FN, I_dirs, python_include, utilities_include_dir, root)
    262271
    263272    if os.name == 'posix' and os.uname()[4] == 'x86_64':
  • anuga_core/source/anuga/utilities/interp.py

    r5681 r5891  
    111111
    112112    >>> from interp import interp
    113     >>> import Numeric as N
     113    >>> import numpy.oldnumeric as N
    114114    >>> x = N.array([1., 2., 3., 4., 5.])
    115115    >>> y = N.array([3., 6., 2.,-5.,-3.])
     
    138138    """
    139139    import arrayfns
    140     import MA
    141     import Numeric as N
     140    import numpy.ma as MA
     141    import numpy as N
    142142    from where_close import where_close
    143143
     
    216216
    217217    >>> from interp import interp
    218     >>> import Numeric as N
     218    >>> import numpy.oldnumeric as N
    219219    >>> x = N.array([1.,    2., 3.,  4.,  5.,  6.])
    220220    >>> y = N.array([3., 1e+20, 2., -5., -3., -4.])
     
    284284    >>> ['%.7g' % yint[i] for i in range(len(yint))]
    285285    ['3.4', '2.3']
    286     >>> yint.typecode()
     286    >>> yint.dtype.char
    287287    'd'
    288288    >>> x = N.arange(6)
     
    292292    >>> ['%.7g' % yint[i] for i in range(len(yint))]
    293293    ['3', '2']
    294     >>> yint.typecode()
     294    >>> yint.dtype.char
    295295    'd'
    296296    """}
  • anuga_core/source/anuga/utilities/numerical_tools.py

    r5729 r5891  
    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   
     9##from numpy import ndarray, array, sum, inner, ravel, sqrt, searchsorted, sort, concatenate, float, arange
     10import numpy
    2111
    2212# Getting an infinite number to use when using Numeric
    2313#INF = (array([1])/0.)[0]
    2414
    25 NAN = (array([1])/0.)[0]
     15NAN = (numpy.array([1])/0.)[0]
    2616# Note, INF is used instead of NAN (Not a number), since Numeric has no NAN
    2717# if we use a package that has NAN, this should be updated to use NAN.
     
    8979        v2 = [1.0, 0.0] # Unit vector along the x-axis
    9080       
    91     v1 = ensure_numeric(v1, Float)
    92     v2 = ensure_numeric(v2, Float)   
     81    v1 = ensure_numeric(v1, numpy.float)
     82    v2 = ensure_numeric(v2, numpy.float)   
    9383   
    9484    # Normalise
    95     v1 = v1/sqrt(sum(v1**2))
    96     v2 = v2/sqrt(sum(v2**2))
     85    v1 = v1/numpy.sqrt(numpy.sum(v1**2))
     86    v2 = v2/numpy.sqrt(numpy.sum(v2**2))
    9787
    9888    # Compute angle
    99     p = innerproduct(v1, v2)
    100     c = innerproduct(v1, normal_vector(v2)) # Projection onto normal
     89    p = numpy.inner(v1, v2)
     90    c = numpy.inner(v1, normal_vector(v2)) # Projection onto normal
    10191                                            # (negative cross product)
    10292       
     
    140130    """
    141131   
    142     return array([-v[1], v[0]], Float)
     132    return numpy.array([-v[1], v[0]], numpy.float)
    143133
    144134   
     
    150140    """Mean value of a vector
    151141    """
    152     return(float(sum(x))/len(x))
     142    return(float(numpy.sum(x))/len(x))
    153143
    154144
     
    171161    cy = y - mean(y) 
    172162
    173     p = innerproduct(cx,cy)/N
     163    p = numpy.inner(cx,cy)/N
    174164    return(p)
    175165
     
    220210    """
    221211 
    222     y = ravel(x)
    223     p = sqrt(innerproduct(y,y))
     212    y = numpy.ravel(x)
     213    p = numpy.sqrt(numpy.inner(y,y))
    224214    return p
    225215   
     
    262252
    263253    if typecode is None:
    264         if type(A) == ArrayType:
     254##NumPy        if isinstance(A, ArrayType):
     255        if type(A) == numpy.ndarray:
    265256            return A
    266257        else:
    267             return array(A)
     258            return numpy.array(A)
    268259    else:
    269         if type(A) == ArrayType:
    270             if A.typecode == typecode:
    271                 return array(A)  #FIXME: Shouldn't this just return A?
     260##NumPy        if isinstance(A, ArrayType):
     261        if type(A) == numpy.ndarray:
     262##NumPy            if A.typecode == typecode:
     263            if A.dtype == typecode:
     264                return numpy.array(A)  #FIXME: Shouldn't this just return A?
    272265            else:
    273                 return array(A,typecode)
     266                return numpy.array(A, typecode)
    274267        else:
    275             return array(A,typecode)
    276 
     268            import types                            ##
     269            from numpy import str                   ##
     270            if isinstance(A, types.StringType):     ##
     271                return numpy.array(A, dtype=int)          ##
     272            return numpy.array(A, typecode)
    277273
    278274
     
    285281    """
    286282
    287     n = searchsorted(sort(a), bins)
    288     n = concatenate( [n, [len(a)]] )
     283    n = numpy.searchsorted(numpy.sort(a), bins)
     284    n = numpy.concatenate( [n, [len(a)]] )
    289285
    290286    hist = n[1:]-n[:-1]
    291287
    292288    if relative is True:
    293         hist = hist/float(sum(hist))
     289        hist = hist/float(numpy.sum(hist))
    294290       
    295291    return hist
     
    301297    """
    302298
    303     mx = max(data)
    304     mn = min(data)
     299    mx = numpy.max(data)
     300    mn = numpy.min(data)
    305301
    306302    if mx == mn:
    307         bins = array([mn])
     303        bins = numpy.array([mn])
    308304    else:
    309305        if number_of_bins is None:
    310306            number_of_bins = 10
    311307           
    312         bins = arange(mn, mx, (mx-mn)/number_of_bins)
     308        bins = numpy.arange(mn, mx, (mx-mn)/number_of_bins)
    313309
    314310    return bins
  • anuga_core/source/anuga/utilities/polygon.py

    r5658 r5891  
    1010#    #print 'Could not find scipy - using Numeric'
    1111
    12 from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot, allclose
     12##from numpy import float, int, zeros, ones, array, concatenate, reshape, dot, allclose, newaxis, ascontiguousarray
     13import numpy
    1314
    1415
     
    7677    # FIXME (Ole): Write this in C
    7778
    78     line0 = ensure_numeric(line0, Float)
    79     line1 = ensure_numeric(line1, Float)   
     79    line0 = ensure_numeric(line0, numpy.float)
     80    line1 = ensure_numeric(line1, numpy.float)   
    8081
    8182    x0 = line0[0,0]; y0 = line0[0,1]
     
    8990    u1 = (x2-x0)*(y1-y0) - (y2-y0)*(x1-x0)
    9091       
    91     if allclose(denom, 0.0):
     92    if numpy.allclose(denom, 0.0):
    9293        # Lines are parallel - check if they coincide on a shared a segment
    9394
    94         if allclose( [u0, u1], 0.0 ):
     95        if numpy.allclose( [u0, u1], 0.0 ):
    9596            # We now know that the lines if continued coincide
    9697            # The remaining check will establish if the finite lines share a segment
     
    120121            if line0_starts_on_line1 and line0_ends_on_line1:
    121122                # Shared segment is line0 fully included in line1
    122                 segment = array([[x0, y0], [x1, y1]])               
     123                segment = numpy.array([[x0, y0], [x1, y1]])               
    123124
    124125            if line1_starts_on_line0 and line1_ends_on_line0:
    125126                # Shared segment is line1 fully included in line0
    126                 segment = array([[x2, y2], [x3, y3]])
     127                segment = numpy.array([[x2, y2], [x3, y3]])
    127128           
    128129
     
    130131            if line0_starts_on_line1 and line1_ends_on_line0:
    131132                # Shared segment from line0 start to line 1 end
    132                 segment = array([[x0, y0], [x3, y3]])
     133                segment = numpy.array([[x0, y0], [x3, y3]])
    133134
    134135            if line1_starts_on_line0 and line0_ends_on_line1:
    135136                # Shared segment from line1 start to line 0 end
    136                 segment = array([[x2, y2], [x1, y1]])                               
     137                segment = numpy.array([[x2, y2], [x1, y1]])                               
    137138
    138139
     
    140141            if line0_starts_on_line1 and line1_starts_on_line0:
    141142                # Shared segment from line0 start to line 1 end
    142                 segment = array([[x0, y0], [x2, y2]])
     143                segment = numpy.array([[x0, y0], [x2, y2]])
    143144
    144145            if line0_ends_on_line1 and line1_ends_on_line0:
    145146                # Shared segment from line0 start to line 1 end
    146                 segment = array([[x3, y3], [x1, y1]])               
     147                segment = numpy.array([[x3, y3], [x1, y1]])               
    147148
    148149               
     
    161162
    162163        # Sanity check - can be removed to speed up if needed
    163         assert allclose(x, x2 + u1*(x3-x2))
    164         assert allclose(y, y2 + u1*(y3-y2))       
     164        assert numpy.allclose(x, x2 + u1*(x3-x2))
     165        assert numpy.allclose(y, y2 + u1*(y3-y2))       
    165166
    166167        # Check if point found lies within given line segments
     
    168169            # We have intersection
    169170
    170             return 1, array([x, y])
     171            return 1, numpy.array([x, y])
    171172        else:
    172173            # No intersection
     
    203204
    204205
    205     line0 = ensure_numeric(line0, Float)
    206     line1 = ensure_numeric(line1, Float)   
     206    line0 = ensure_numeric(line0, numpy.float)
     207    line1 = ensure_numeric(line1, numpy.float)   
    207208
    208209    status, value = _intersection(line0[0,0], line0[0,1],
     
    256257        # converted to a numeric array.
    257258        msg = 'Points could not be converted to Numeric array'
    258         raise msg
     259        raise TypeError, msg
    259260
    260261    try:
     
    265266        # If this fails it is going to be because the points can't be
    266267        # converted to a numeric array.
    267         msg = 'Polygon %s could not be converted to Numeric array' %(str(polygon))
    268         raise msg
     268        msg = 'Polygon %s could not be converted to Numeric array' % (str(polygon))
     269        raise TypeError, msg
    269270
    270271    if len(points.shape) == 1:
    271272        # Only one point was passed in. Convert to array of points
    272         points = reshape(points, (1,2))
     273        points = numpy.reshape(points, (1,2))
    273274
    274275    indices, count = separate_points_by_polygon(points, polygon,
     
    312313    #if verbose: print 'Checking input to outside_polygon'
    313314    try:
    314         points = ensure_numeric(points, Float)
     315        points = ensure_numeric(points, numpy.float)
    315316    except NameError, e:
    316317        raise NameError, e
     
    320321
    321322    try:
    322         polygon = ensure_numeric(polygon, Float)
     323        polygon = ensure_numeric(polygon, numpy.float)
    323324    except NameError, e:
    324325        raise NameError, e
     
    330331    if len(points.shape) == 1:
    331332        # Only one point was passed in. Convert to array of points
    332         points = reshape(points, (1,2))
     333        points = numpy.reshape(points, (1,2))
    333334
    334335    indices, count = separate_points_by_polygon(points, polygon,
     
    339340    if count == len(indices):
    340341        # No points are outside
    341         return array([])
     342        return numpy.array([])
    342343    else:
    343344        return indices[count:][::-1]  #return reversed
     
    354355    #if verbose: print 'Checking input to outside_polygon'
    355356    try:
    356         points = ensure_numeric(points, Float)
     357        points = ensure_numeric(points, numpy.float)
    357358    except NameError, e:
    358359        raise NameError, e
     
    362363
    363364    try:
    364         polygon = ensure_numeric(polygon, Float)
     365        polygon = ensure_numeric(polygon, numpy.float)
    365366    except NameError, e:
    366367        raise NameError, e
     
    371372    if len(points.shape) == 1:
    372373        # Only one point was passed in. Convert to array of points
    373         points = reshape(points, (1,2))
     374        points = numpy.reshape(points, (1,2))
    374375
    375376
     
    439440    assert isinstance(verbose, bool), 'Keyword argument "verbose" must be boolean'
    440441
    441 
     442##    print 'Before: points=%s, flags=%s' % (type(points), str(points.flags))
    442443    try:
    443         points = ensure_numeric(points, Float)
     444##        points = numpy.ascontiguousarray(ensure_numeric(points, numpy.float))
     445        points = ensure_numeric(points, numpy.float)
    444446    except NameError, e:
    445447        raise NameError, e
    446448    except:
    447449        msg = 'Points could not be converted to Numeric array'
    448         raise msg
     450        raise TypeError, msg
     451##    print 'After: points=%s, flags=%s' % (type(points), str(points.flags))
    449452
    450453    #if verbose: print 'Checking input to separate_points_by_polygon 2'
    451454    try:
    452         polygon = ensure_numeric(polygon, Float)
     455##        polygon = numpy.ascontiguousarray(ensure_numeric(polygon, numpy.float))
     456        polygon = ensure_numeric(polygon, numpy.float)
    453457    except NameError, e:
    454458        raise NameError, e
    455459    except:
    456460        msg = 'Polygon could not be converted to Numeric array'
    457         raise msg
     461        raise TypeError, msg
    458462
    459463    msg = 'Polygon array must be a 2d array of vertices'
     
    472476        # Only one point was passed in.
    473477        # Convert to array of points
    474         points = reshape(points, (1,2))
     478        points = numpy.reshape(points, (1,2))
    475479
    476480   
    477481    msg = 'Point array must have two columns (x,y), '
    478     msg += 'I got points.shape[1] == %d' %points.shape[0]
     482    msg += 'I got points.shape[1] == %d' % points.shape[1]
    479483    assert points.shape[1] == 2, msg
    480484
     
    491495
    492496
    493     indices = zeros( M, Int )
     497    indices = numpy.zeros( M, numpy.int )
    494498
    495499    count = _separate_points_by_polygon(points, polygon, indices,
     
    618622
    619623    try:
    620         polygon = ensure_numeric(polygon, Float)
     624        polygon = ensure_numeric(polygon, numpy.float)
    621625    except NameError, e:
    622626        raise NameError, e
     
    627631    x = polygon[:,0]
    628632    y = polygon[:,1]
    629     x = concatenate((x, [polygon[0,0]]), axis = 0)
    630     y = concatenate((y, [polygon[0,1]]), axis = 0)
     633    x = numpy.concatenate((x, [polygon[0,0]]), axis = 0)
     634    y = numpy.concatenate((y, [polygon[0,1]]), axis = 0)
    631635   
    632636    return x, y
     
    680684    """
    681685
    682     def __init__(self, regions, default=0.0, geo_reference=None):
     686    def __init__(self, regions, default=0.0, geo_reference=None, verbose=False):
    683687
    684688        try:
     
    723727            self.regions.append( (P, value) )
    724728
     729        self.verbose = verbose
     730
    725731
    726732
    727733
    728734    def __call__(self, x, y):
    729         x = array(x).astype(Float)
    730         y = array(y).astype(Float)
    731 
    732         N = len(x)
    733         assert len(y) == N
    734 
    735         points = concatenate( (reshape(x, (N, 1)),
    736                                reshape(y, (N, 1))), axis=1 )
    737 
     735        x = numpy.array(x).astype(numpy.float)
     736        y = numpy.array(y).astype(numpy.float)
     737
     738        assert len(x.shape) == 1 and len(y.shape) == 1
     739       
     740        N = x.shape[0]
     741        assert y.shape[0] == N
     742
     743        points = numpy.ascontiguousarray(numpy.concatenate( (x[:,numpy.newaxis], y[:,numpy.newaxis]), axis=1 ))
     744       
    738745        if callable(self.default):
    739             z = self.default(x,y)
     746            z = self.default(x, y)
    740747        else:
    741             z = ones(N, Float) * self.default
     748            z = numpy.ones(N, numpy.float) * self.default
    742749
    743750        for polygon, value in self.regions:
    744             indices = inside_polygon(points, polygon)
     751            indices = inside_polygon(points, polygon, verbose=self.verbose)
    745752
    746753            # FIXME: This needs to be vectorised
    747754            if callable(value):
    748755                for i in indices:
    749                     xx = array([x[i]])
    750                     yy = array([y[i]])
     756                    xx = numpy.array([x[i]])
     757                    yy = numpy.array([y[i]])
    751758                    z[i] = value(xx, yy)[0]
    752759            else:
  • anuga_core/source/anuga/utilities/polygon_ext.c

    r5570 r5891  
    1515
    1616#include "Python.h"
    17 #include "Numeric/arrayobject.h"
     17#include "numpy/arrayobject.h"
    1818#include "math.h"
    1919
     
    222222  } 
    223223  for (k=0; k<M; k++) {
     224    x = points[2*k];
     225    y = points[2*k + 1];
     226
    224227    if (verbose){
    225       if (k %((M+10)/10)==0) printf("Doing %d of %d\n", k, M);
     228      if (k %((M+10)/10)==0) printf("Doing %d of %d, x=%f, y=%f\n", k, M, x, y);
    226229    }
    227230   
    228     x = points[2*k];
    229     y = points[2*k + 1];
    230 
    231231    inside = 0;
    232232
     
    376376    *polygon,
    377377    *indices;
     378//  PyObject *xxxx;
    378379
    379380  int closed, verbose; //Flags
     
    393394    return NULL;
    394395  }
     396 
     397//  points = (PyArrayObject *) PyArray_ContiguousFromObject(xxxx, PyArray_DOUBLE, 1, 1);
    395398
    396399  M = points -> dimensions[0];   //Number of points
  • anuga_core/source/anuga/utilities/quad.py

    r4932 r5891  
     1
    12"""quad.py - quad tree data structure for fast indexing of points in the plane
    23
     
    222223            triangles = {}
    223224            verts = self.retrieve_vertices()
    224             # print "verts", verts
     225            print "verts", verts
    225226            for vert in verts:
    226227                triangle_list = self.mesh.get_triangles_and_vertices_per_node(vert)
     228                print 'triangle_list=%s' % str(triangle_list)
    227229                for k, _ in triangle_list:
    228230                    if not triangles.has_key(k):
    229231                        # print 'k',k
    230                         tri = self.mesh.get_vertex_coordinates(k,
    231                                                                absolute=True)
     232                        tri = self.mesh.get_vertex_coordinates(k, absolute=True)
    232233                        n0 = self.mesh.get_normal(k, 0)
    233234                        n1 = self.mesh.get_normal(k, 1)
     
    435436    """
    436437
    437     from Numeric import minimum, maximum
    438 
    439 
    440438    #Make root cell
    441439    #print mesh.coordinates
  • anuga_core/source/anuga/utilities/sparse.py

    r5223 r5891  
     1
    12"""Proof of concept sparse matrix code
    23"""
    34
     5import numpy
    46
    57class Sparse:
     
    1719           
    1820        if len(args) == 1:
    19             from Numeric import array
    2021            try:
    21                 A = array(args[0])
     22                A = numpy.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 = numpy.zeros( (self.M, self.N), numpy.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 = numpy.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 = numpy.zeros(self.M, numpy.float) #Result
    133130           
    134131            # Multiply nonzero elements
     
    140137       
    141138           
    142             R = zeros((self.M, B.shape[1]), Float) #Result matrix
     139            R = numpy.zeros((self.M, B.shape[1]), numpy.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 = numpy.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 = numpy.zeros((self.N,), numpy.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    = numpy.zeros ( (nnz,), numpy.float)
     250            colind  = numpy.zeros ( (nnz,), numpy.int)
     251            row_ptr = numpy.zeros ( (A.M+1,), numpy.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
     290        D = numpy.zeros( (self.M, self.N), numpy.float)
    304291       
    305292        for i in range(self.M):
     
    314301        """
    315302
    316         from Numeric import array, zeros, Float
    317        
    318303        try:
    319             B = array(other)
     304            B = numpy.array(other)
    320305        except:
    321306            print 'FIXME: Only Numeric types implemented so far'
     
    333318if __name__ == '__main__':
    334319    # A little selftest
    335    
    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 numpy.allclose(u, [6,14,4])
    369351
    370352    u = A.trans_mult(v)
    371353    print u
    372     assert allclose(u, [6,6,10])
     354    assert numpy.allclose(u, [6,6,10])
    373355
    374356    #Right hand side column
    375     v = array([[2,4],[3,4],[4,4]])
     357    v = numpy.array([[2,4],[3,4],[4,4]])
    376358
    377359    u = A*v[:,0]
    378     assert allclose(u, [6,14,4])
     360    assert numpy.allclose(u, [6,14,4])
    379361
    380362    #u = A*v[:,1]
  • anuga_core/source/anuga/utilities/sparse_ext.c

    r3730 r5891  
    1111       
    1212#include "Python.h"
    13 #include "Numeric/arrayobject.h"
     13#include "numpy/arrayobject.h"
    1414#include "math.h"
    1515#include "stdio.h"
  • anuga_core/source/anuga/utilities/test_cg_solve.py

    r3514 r5891  
    55import unittest
    66
    7 
    8 from Numeric import dot, allclose, array, transpose, arange, ones, Float
     7import numpy
    98from anuga.utilities.cg_solve import *
    109from anuga.utilities.cg_solve import _conjugate_gradient
     
    3029        x = conjugate_gradient(A,b,x,iprint=0)
    3130
    32         assert allclose(x,xe)
     31        assert numpy.allclose(x,xe)
    3332
    3433    def test_max_iter(self):
     
    6160        A = Sparse(n,n)
    6261
    63         for i in arange(0,n):
     62        for i in numpy.arange(0,n):
    6463            A[i,i] = 1.0
    6564            if i > 0 :
     
    6867                A[i,i+1] = -0.5
    6968
    70         xe = ones( (n,), Float)
     69        xe = numpy.ones( (n,), numpy.float)
    7170
    7271        b  = A*xe
    7372        x = conjugate_gradient(A,b,b,tol=1.0e-5,iprint=1)
    7473
    75         assert allclose(x,xe)
     74        assert numpy.allclose(x,xe)
    7675
    7776    def test_solve_large_2d(self):
     
    8382        A = Sparse(m*n, m*n)
    8483
    85         for i in arange(0,n):
    86             for j in arange(0,m):
     84        for i in numpy.arange(0,n):
     85            for j in numpy.arange(0,m):
    8786                I = j+m*i
    8887                A[I,I] = 4.0
     
    9695                    A[I,I+1] = -1.0
    9796
    98         xe = ones( (n*m,), Float)
     97        xe = numpy.ones( (n*m,), numpy.float)
    9998
    10099        b  = A*xe
    101100        x = conjugate_gradient(A,b,b,iprint=0)
    102101
    103         assert allclose(x,xe)
     102        assert numpy.allclose(x,xe)
    104103
    105104    def test_solve_large_2d_csr_matrix(self):
     
    112111        A = Sparse(m*n, m*n)
    113112
    114         for i in arange(0,n):
    115             for j in arange(0,m):
     113        for i in numpy.arange(0,n):
     114            for j in numpy.arange(0,m):
    116115                I = j+m*i
    117116                A[I,I] = 4.0
     
    125124                    A[I,I+1] = -1.0
    126125
    127         xe = ones( (n*m,), Float)
     126        xe = numpy.ones( (n*m,), numpy.float)
    128127
    129128        # Convert to csr format
     
    134133        x = conjugate_gradient(A,b,b,iprint=20)
    135134
    136         assert allclose(x,xe)
     135        assert numpy.allclose(x,xe)
    137136
    138137
     
    145144        A = Sparse(m*n, m*n)
    146145
    147         for i in arange(0,n):
    148             for j in arange(0,m):
     146        for i in numpy.arange(0,n):
     147            for j in numpy.arange(0,m):
    149148                I = j+m*i
    150149                A[I,I] = 4.0
     
    158157                    A[I,I+1] = -1.0
    159158
    160         xe = ones( (n*m,), Float)
     159        xe = numpy.ones( (n*m,), numpy.float)
    161160
    162161        b  = A*xe
    163162        x = conjugate_gradient(A,b)
    164163
    165         assert allclose(x,xe)
     164        assert numpy.allclose(x,xe)
    166165
    167166
     
    202201        x = conjugate_gradient(A,b,x,iprint=0)
    203202
    204         assert allclose(x,xe)
     203        assert numpy.allclose(x,xe)
    205204
    206205#-------------------------------------------------------------
  • anuga_core/source/anuga/utilities/test_data_audit.py

    r5096 r5891  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose, Float
    65from tempfile import mkstemp
    76import os
  • anuga_core/source/anuga/utilities/test_numerical_tools.py

    r5870 r5891  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose
    6 from Numeric import ArrayType, Float, Int, array, alltrue
     5import numpy
    76
    87from math import sqrt, pi
     
    2322        """Test angles between one vector and the x-axis
    2423        """
    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)
     24        assert numpy.allclose(angle([1.0, 0.0])/pi*180, 0.0)       
     25        assert numpy.allclose(angle([1.0, 1.0])/pi*180, 45.0)
     26        assert numpy.allclose(angle([0.0, 1.0])/pi*180, 90.0)           
     27        assert numpy.allclose(angle([-1.0, 1.0])/pi*180, 135.0)         
     28        assert numpy.allclose(angle([-1.0, 0.0])/pi*180, 180.0)
     29        assert numpy.allclose(angle([-1.0, -1.0])/pi*180, 225.0)
     30        assert numpy.allclose(angle([0.0, -1.0])/pi*180, 270.0)
     31        assert numpy.allclose(angle([1.0, -1.0])/pi*180, 315.0)
    3332               
    3433                                                         
     
    3736        """   
    3837       
    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)
     38        assert numpy.allclose(angle([1.0, 0.0], [1.0, 1.0])/pi*180, 315.0)
     39        assert numpy.allclose(angle([1.0, 1.0], [1.0, 0.0])/pi*180, 45.0)
    4140               
    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) 
     41        assert numpy.allclose(angle([-1.0, -1.0], [1.0, 1.0])/pi*180, 180)     
     42        assert numpy.allclose(angle([-1.0, -1.0], [-1.0, 1.0])/pi*180, 90.0)   
    4443       
    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)   
     44        assert numpy.allclose(angle([-1.0, 0.0], [1.0, 1.0])/pi*180, 135.0)
     45        assert numpy.allclose(angle([0.0, -1.0], [1.0, 1.0])/pi*180, 225.0)     
    4746       
    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)
     47        assert numpy.allclose(angle([1.0, -1.0], [1.0, 1.0])/pi*180, 270.0)     
     48        assert numpy.allclose(angle([1.0, 0.0], [0.0, 1.0])/pi*180, 270.0)
    5049
    5150        #From test_get_boundary_polygon_V
    5251        v_prev = [-0.5, -0.5]
    5352        vc = [ 0.0,  -0.5]
    54         assert allclose(angle(vc, v_prev)/pi*180, 45.0)
     53        assert numpy.allclose(angle(vc, v_prev)/pi*180, 45.0)
    5554
    5655        vc = [ 0.5,  0.0]
    57         assert allclose(angle(vc, v_prev)/pi*180, 135.0)
     56        assert numpy.allclose(angle(vc, v_prev)/pi*180, 135.0)
    5857
    5958        vc = [ -0.5,  0.5]
    60         assert allclose(angle(vc, v_prev)/pi*180, 270.0)               
     59        assert numpy.allclose(angle(vc, v_prev)/pi*180, 270.0)               
    6160
    6261
    6362    def test_anglediff(self):
    64         assert allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0)
     63        assert numpy.allclose(anglediff([0.0, 1.], [1.0, 1.0])/pi*180, 45.0)
    6564
    6665       
     
    6867        A = [1,2,3,4]
    6968        B = ensure_numeric(A)
    70         assert type(B) == ArrayType
    71         assert B.typecode() == 'l'
     69        assert isinstance(B, numpy.ndarray)
     70        assert B.dtype.char == 'l'
    7271        assert B[0] == 1 and B[1] == 2 and B[2] == 3 and B[3] == 4
    7372
    7473        A = [1,2,3.14,4]
    7574        B = ensure_numeric(A)
    76         assert type(B) == ArrayType
    77         assert B.typecode() == 'd'
     75        assert isinstance(B, numpy.ndarray)
     76        assert B.dtype.char == 'd'
    7877        assert B[0] == 1 and B[1] == 2 and B[2] == 3.14 and B[3] == 4
    7978
    8079        A = [1,2,3,4]
    81         B = ensure_numeric(A, Float)
    82         assert type(B) == ArrayType
    83         assert B.typecode() == 'd'
     80        B = ensure_numeric(A, numpy.float)
     81        assert isinstance(B, numpy.ndarray)
     82        assert B.dtype.char == 'd'
    8483        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    8584
    8685        A = [1,2,3,4]
    87         B = ensure_numeric(A, Float)
    88         assert type(B) == ArrayType
    89         assert B.typecode() == 'd'
     86        B = ensure_numeric(A, numpy.float)
     87        assert isinstance(B, numpy.ndarray)
     88        assert B.dtype.char == 'd'
    9089        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    9190
    92         A = array([1,2,3,4])
     91        A = numpy.array([1,2,3,4])
    9392        B = ensure_numeric(A)
    94         assert type(B) == ArrayType
    95         assert B.typecode() == 'l'       
    96         assert alltrue(A == B)   
     93        assert isinstance(B, numpy.ndarray)
     94        assert B.dtype.char == 'l'       
     95        assert numpy.alltrue(A == B)   
    9796        assert A is B   #Same object
    9897
    99         A = array([1,2,3,4])
    100         B = ensure_numeric(A, Float)
    101         assert type(B) == ArrayType
    102         assert B.typecode() == 'd'       
    103         assert alltrue(A == B)   
     98        A = numpy.array([1,2,3,4])
     99        B = ensure_numeric(A, numpy.float)
     100        assert isinstance(B, numpy.ndarray)
     101        assert B.dtype.char == 'd'       
     102        assert numpy.alltrue(A == B)   
    104103        assert A is not B   #Not the same object
    105104
    106105        # Check scalars
    107106        A = 1
    108         B = ensure_numeric(A, Float)
     107        B = ensure_numeric(A, numpy.float)
    109108        #print A, B[0], len(B), type(B)
    110109        #print B.shape
    111         assert alltrue(A == B)
    112 
    113         B = ensure_numeric(A, Int)       
     110        assert numpy.alltrue(A == B)
     111
     112        B = ensure_numeric(A, numpy.int)       
    114113        #print A, B
    115114        #print B.shape
    116         assert alltrue(A == B)
    117 
     115        assert numpy.alltrue(A == B)
     116
     117    def NO_test_ensure_numeric_char(self):
    118118        # Error situation
    119 
    120         B = ensure_numeric('hello', Int)               
    121         assert allclose(B, [104, 101, 108, 108, 111])
     119        B = ensure_numeric('hello', numpy.int)
     120        print 'B=%s %s' % (str(B), type(B))
     121        assert numpy.allclose(B, [104, 101, 108, 108, 111])
    122122
    123123
     
    160160        zx, zy = gradient(x0, y0, x1, y1, x2, y2, z0, z1, z2)
    161161        a, b = gradient2(x0, y0, x1, y1, z0, z1)
    162 
     162       
    163163        assert zx == a
    164164        assert zy == b
     
    208208        #There are four elements greater than or equal to 3
    209209        bins = [3]
    210         assert allclose(histogram(a, bins), [4])
     210        assert numpy.allclose(histogram(a, bins), [4])
    211211
    212212        bins = [ min(a) ]
    213         assert allclose(histogram(a, bins), [len(a)])
     213        assert numpy.allclose(histogram(a, bins), [len(a)])
    214214
    215215        bins = [ max(a)+0.00001 ]
    216         assert allclose(histogram(a, bins), [0])       
     216        assert numpy.allclose(histogram(a, bins), [0])       
    217217       
    218218        bins = [1,2,3,4]
    219         assert allclose(histogram(a, bins), [8,3,3,1])
     219        assert numpy.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 numpy.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 numpy.allclose(histogram(a, bins), [8,0,3,4])
     227        assert numpy.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 numpy.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 numpy.allclose(histogram(a, bins), [1])
    237237
    238238        a = [-1.7]
    239239        bins = [0]
    240         assert allclose(histogram(a, bins), [0])
     240        assert numpy.allclose(histogram(a, bins), [0])
    241241
    242242        a = [-1.7]
    243243        bins = [-1.7]
    244         assert allclose(histogram(a, bins), [1])       
     244        assert numpy.allclose(histogram(a, bins), [1])       
    245245       
    246246
     
    281281        from util_ext import gradient as gradient_c
    282282
    283         from RandomArray import uniform, seed
    284         seed(17, 53)
     283        from numpy.random import uniform, seed
     284        seed(53)    # numeric was seed(17, 53)
    285285
    286286        x0, x1, x2, y0, y1, y2 = uniform(0.0,3.0,6)
     
    312312        # sqrt(sum_over_x&y((xi - yi)^2))
    313313        err__1 = err(x,y,2,False)
     314       
    314315        assert err__1 == sqrt(20)
    315316        #print "err_", err_
  • anuga_core/source/anuga/utilities/test_polygon.py

    r5403 r5891  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose
     5import numpy
    66from math import sqrt, pi
    77from anuga.utilities.numerical_tools import ensure_numeric
     
    4343        p2 = [[0,0], [10,10], [15,5], [20, 10], [25,0], [30,10], [40,-10]]
    4444
    45         f = Polygon_function( [(p1, 1.0)] )
     45        f = Polygon_function( [(p1, 1.0)], verbose=False )
    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 numpy.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 numpy.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 numpy.allclose(z, [2,1,0,2])
     59
     60
     61    def test_polygon_function_constants_tuple(self):
     62        polygon = [[0,0], [10,0], [10,10], [0,10]]
     63        points = ((5, 5), (5, 9), (27, 8), (35, -5))
     64
     65        (indices, count) = separate_points_by_polygon(points, polygon, verbose=False)
    5966
    6067    def test_polygon_function_csvfile(self):
     
    7279        z = f([430000,480000], [490000,7720000]) # first outside, second inside
    7380       
    74         assert allclose(z, [0,10])
     81        assert numpy.allclose(z, [0,10])
    7582
    7683    def test_polygon_function_georef(self):
     
    9097        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1
    9198
    92         assert allclose(z, [1,1,0,0])
     99        assert numpy.allclose(z, [1,1,0,0])
    93100
    94101
    95102        f = Polygon_function( [(p2, 2.0)], geo_reference=geo)
    96103        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #First and last inside p2
    97         assert allclose(z, [2,0,0,2])
     104        assert numpy.allclose(z, [2,0,0,2])
    98105
    99106
     
    101108        f = Polygon_function( [(p1, 1.0), (p2, 2.0)], geo_reference=geo)
    102109        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    103         assert allclose(z, [2,1,0,2])
     110        assert numpy.allclose(z, [2,1,0,2])
    104111
    105112
     
    107114        f = Polygon_function( [(p1, 1.0), (p2, 2.0)])
    108115        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    109         assert not allclose(z, [2,1,0,2])       
     116        assert not numpy.allclose(z, [2,1,0,2])       
    110117
    111118
     
    120127        f = Polygon_function( [(p1, test_function)] )
    121128        z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1
    122         assert allclose(z, [10,14,0,0])
     129        assert numpy.allclose(z, [10,14,0,0])
    123130
    124131        # Combined
    125132        f = Polygon_function( [(p1, test_function), (p2, 2.0)] )
    126133        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    127         assert allclose(z, [2,14,0,2])
     134        assert numpy.allclose(z, [2,14,0,2])
    128135
    129136
     
    131138        f = Polygon_function( [(p1, test_function), (p2, 2.0)], default = 3.14)
    132139        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    133         assert allclose(z, [2,14,3.14,2])
     140        assert numpy.allclose(z, [2,14,3.14,2])
    134141
    135142
     
    138145                              default = test_function)
    139146        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    140         assert allclose(z, [2,14,35,2])
     147        assert numpy.allclose(z, [2,14,35,2])
    141148
    142149
     
    210217        res = inside_polygon(points, polygon)
    211218        assert len(res) == 2
    212         assert allclose(res, [0,1])
     219        assert numpy.allclose(res, [0,1])     ## alltrue?
    213220
    214221
     
    305312        res = inside_polygon( points, polygon, verbose=False )
    306313
    307         assert allclose( res, [0,1,2] )
     314        assert numpy.allclose( res, [0,1,2] )
    308315
    309316    def test_outside_polygon(self):
     
    317324       
    318325        indices = outside_polygon( [[0.5, 0.5], [1, -0.5], [0.3, 0.2]], U )
    319         assert allclose( indices, [1] )
     326        assert numpy.allclose( indices, [1] )
    320327       
    321328        # One more test of vector formulation returning indices
     
    324331        res = outside_polygon( points, polygon )
    325332
    326         assert allclose( res, [3, 4] )
     333        assert numpy.allclose( res, [3, 4] )
    327334
    328335
     
    332339        res = outside_polygon( points, polygon )
    333340
    334         assert allclose( res, [0, 4, 5] )       
     341        assert numpy.allclose( res, [0, 4, 5] )       
    335342     
    336343    def test_outside_polygon2(self):
     
    355362        #print indices, count
    356363        assert count == 0 #None inside
    357         assert allclose(indices, [3,2,1,0])
     364        assert numpy.allclose(indices, [3,2,1,0])
    358365
    359366        indices = outside_polygon(points, U, closed = True)
    360         assert allclose(indices, [0,1,2,3])
     367        assert numpy.allclose(indices, [0,1,2,3])
    361368
    362369        indices = inside_polygon(points, U, closed = True)
    363         assert allclose(indices, [])               
     370        assert numpy.allclose(indices, [])               
    364371
    365372
     
    375382        indices, count = separate_points_by_polygon(points, U)
    376383        assert count == 3 #All inside
    377         assert allclose(indices, [0,1,2])
     384        assert numpy.allclose(indices, [0,1,2])
    378385
    379386        indices = outside_polygon(points, U, closed = True)
    380         assert allclose(indices, [])
     387        assert numpy.allclose(indices, [])
    381388
    382389        indices = inside_polygon(points, U, closed = True)
    383         assert allclose(indices, [0,1,2])
     390        assert numpy.allclose(indices, [0,1,2])
    384391       
    385392
     
    388395
    389396        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] )
     397        assert numpy.allclose( indices, [0,2,1] )
    391398        assert count == 2
    392399       
     
    396403        res, count = separate_points_by_polygon( points, polygon )
    397404
    398         assert allclose( res, [0,1,2,4,3] )
     405        assert numpy.allclose( res, [0,1,2,4,3] )
    399406        assert count == 3
    400407
     
    404411        res, count = separate_points_by_polygon( points, polygon )
    405412
    406         assert allclose( res, [1,2,3,5,4,0] )       
     413        assert numpy.allclose( res, [1,2,3,5,4,0] )       
    407414        assert count == 3
    408415       
     
    588595        status, value = intersection(line0, line1)
    589596        assert status == 1
    590         assert allclose(value, [0.0, 0.0])
     597        assert numpy.allclose(value, [0.0, 0.0])
    591598
    592599    def test_intersection2(self):
     
    596603        status, value = intersection(line0, line1)
    597604        assert status == 1
    598         assert allclose(value, [12.0, 6.0])
     605        assert numpy.allclose(value, [12.0, 6.0])
    599606
    600607        # Swap direction of one line
     
    603610        status, value = intersection(line0, line1)
    604611        assert status == 1
    605         assert allclose(value, [12.0, 6.0])
     612        assert numpy.allclose(value, [12.0, 6.0])
    606613
    607614        # Swap order of lines
    608615        status, value = intersection(line1, line0)
    609616        assert status == 1
    610         assert allclose(value, [12.0, 6.0])       
     617        assert numpy.allclose(value, [12.0, 6.0])       
    611618       
    612619    def test_intersection3(self):
     
    616623        status, value = intersection(line0, line1)
    617624        assert status == 1
    618         assert allclose(value, [14.068965517, 7.0344827586])
     625        assert numpy.allclose(value, [14.068965517, 7.0344827586])
    619626
    620627        # Swap direction of one line
     
    623630        status, value = intersection(line0, line1)
    624631        assert status == 1
    625         assert allclose(value, [14.068965517, 7.0344827586])       
     632        assert numpy.allclose(value, [14.068965517, 7.0344827586])       
    626633
    627634        # Swap order of lines
    628635        status, value = intersection(line1, line0)
    629636        assert status == 1       
    630         assert allclose(value, [14.068965517, 7.0344827586])       
     637        assert numpy.allclose(value, [14.068965517, 7.0344827586])       
    631638
    632639
     
    641648        status, value = intersection(line0, line1)
    642649        assert status == 1
    643         assert allclose(value, [1.0, 1.0])
     650        assert numpy.allclose(value, [1.0, 1.0])
    644651
    645652
     
    649656        status, value = intersection(line0, line1)
    650657        assert status == 1
    651         assert allclose(value, [1.0, 1.0])       
     658        assert numpy.allclose(value, [1.0, 1.0])       
    652659       
    653660
     
    679686                                                          common_end_point[1])
    680687            msg += ' gave %s, \nbut when reversed we got %s' %(p1, p2)
    681             assert allclose(p1, p2), msg
     688            assert numpy.allclose(p1, p2), msg
    682689
    683690            # Swap order of lines
     
    685692            assert status == 1                       
    686693            msg = 'Order of lines gave different results'
    687             assert allclose(p1, p3), msg
     694            assert numpy.allclose(p1, p3), msg
    688695           
    689696
     
    725732        status, value = intersection(line0, line1)
    726733        assert status == 2
    727         assert allclose(value, [[0,0], [3,0]])
     734        assert numpy.allclose(value, [[0,0], [3,0]])
    728735
    729736        # Overlap 2
     
    733740        status, value = intersection(line0, line1)
    734741        assert status == 2
    735         assert allclose(value, [[-3, 0], [5,0]])       
     742        assert numpy.allclose(value, [[-3, 0], [5,0]])       
    736743
    737744        # Inclusion 1
     
    741748        status, value = intersection(line0, line1)
    742749        assert status == 2       
    743         assert allclose(value, line1)
     750        assert numpy.allclose(value, line1)
    744751
    745752        # Inclusion 2
     
    749756        status, value = intersection(line0, line1)
    750757        assert status == 2       
    751         assert allclose(value, line0)                                       
     758        assert numpy.allclose(value, line0)                                       
    752759
    753760
     
    768775        status, value = intersection(line0, line1)
    769776        assert status == 2               
    770         assert allclose(value, [[1, 7], [7, 19]])
     777        assert numpy.allclose(value, [[1, 7], [7, 19]])
    771778
    772779        status, value = intersection(line1, line0)
    773780        assert status == 2
    774         assert allclose(value, [[1, 7], [7, 19]])
     781        assert numpy.allclose(value, [[1, 7], [7, 19]])
    775782
    776783        # Swap direction
     
    779786        status, value = intersection(line0, line1)
    780787        assert status == 2
    781         assert allclose(value, [[7, 19], [1, 7]])
     788        assert numpy.allclose(value, [[7, 19], [1, 7]])
    782789
    783790        line0 = [[0,5], [7,19]]
     
    785792        status, value = intersection(line0, line1)
    786793        assert status == 2
    787         assert allclose(value, [[1, 7], [7, 19]])       
     794        assert numpy.allclose(value, [[1, 7], [7, 19]])       
    788795       
    789796
     
    793800        status, value = intersection(line0, line1)
    794801        assert status == 2                       
    795         assert allclose(value, [[1,7], [7, 19]])               
     802        assert numpy.allclose(value, [[1,7], [7, 19]])               
    796803
    797804        line0 = [[0,5], [10,25]]
     
    799806        status, value = intersection(line0, line1)
    800807        assert status == 2                       
    801         assert allclose(value, [[1,7], [7, 19]])
     808        assert numpy.allclose(value, [[1,7], [7, 19]])
    802809
    803810
     
    806813        status, value = intersection(line0, line1)
    807814        assert status == 2                       
    808         assert allclose(value, [[7, 19], [1, 7]])                       
     815        assert numpy.allclose(value, [[7, 19], [1, 7]])                       
    809816       
    810817       
     
    843850        res = inside_polygon(points, polygon)
    844851        assert len(res) == 2
    845         assert allclose(res, [0,1])
     852        assert numpy.allclose(res, [0,1])
    846853
    847854    def test_polygon_area(self):
     
    990997if __name__ == "__main__":
    991998    suite = unittest.makeSuite(Test_Polygon,'test')
    992     #suite = unittest.makeSuite(Test_Polygon,'test_inside_polygon_geo_ref')
     999##    suite = unittest.makeSuite(Test_Polygon,'test_polygon_function_constantsX')
    9931000    runner = unittest.TextTestRunner()
    9941001    runner.run(suite)
  • anuga_core/source/anuga/utilities/test_quad.py

    r4741 r5891  
    11import unittest
    2 from Numeric import array, allclose
     2##import numpy
    33
    44from quad import Cell, build_quadtree
     
    236236                     [ 0.,  -1.]]
    237237                     
    238         # assert allclose(array(results),[[[ 2.,  1.],
     238        # assert numpy.allclose(numpy.array(results),[[[ 2.,  1.],
    239239        #[ 4.,  1.], [ 4.,  4.]], [[ 4.,  1.],[ 5.,  4.],[ 4.,  4.]]] )
    240240        results = Q.search(5,4.)
     
    253253                     [ 5.,  4.],
    254254                     [ 4.,  4.]]
    255         #assert allclose(array(results),[[[ 2.,  1.],[ 4.,  1.], [ 4.,  4.]]
     255        #assert numpy.allclose(numpy.array(results),[[[ 2.,  1.],[ 4.,  1.], [ 4.,  4.]]
    256256         #                               ,[[ 2.,  1.],[ 4.,  4.], [ 2.,  4.]],
    257257        #[[ 4.,  1.],  [ 5.,  4.], [ 4.,  4.]],
  • anuga_core/source/anuga/utilities/test_sparse.py

    r2527 r5891  
    55
    66from sparse import *
    7 from Numeric import allclose, array, transpose, Float
     7import numpy
    88
    99class Test_Sparse(unittest.TestCase):
     
    4343        C = Sparse(B)
    4444
    45         assert allclose(C.todense(), B)
     45        assert numpy.allclose(C.todense(), B)
    4646
    4747
     
    5050        A[1,1] = 4
    5151
    52         assert allclose(A.todense(), [[0,0,0], [0,4,0], [0,0,0], [0,0,0]])
     52        assert numpy.allclose(A.todense(), [[0,0,0], [0,4,0], [0,0,0], [0,0,0]])
    5353
    5454
     
    6363
    6464        assert len(A) == 0
    65         assert allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])
     65        assert numpy.allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])
    6666
    6767        #Set an existing zero element to zero
    6868        A[1,2] = 0
    6969        assert len(A) == 0
    70         assert allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])
     70        assert numpy.allclose(A.todense(), [[0,0,0], [0,0,0], [0,0,0]])
    7171
    7272    def test_sparse_multiplication_vector(self):
     
    8282
    8383        u = A*v
    84         assert allclose(u, [6,14,4])
     84        assert numpy.allclose(u, [6,14,4])
    8585
    8686        #Right hand side column
    87         v = array([[2,4],[3,4],[4,4]])
     87        v = numpy.array([[2,4],[3,4],[4,4]])
    8888
    8989        u = A*v[:,0]
    90         assert allclose(u, [6,14,4])
     90        assert numpy.allclose(u, [6,14,4])
    9191
    9292        u = A*v[:,1]
    93         assert allclose(u, [12,16,4])
     93        assert numpy.allclose(u, [12,16,4])
    9494
    9595
     
    103103
    104104        #Right hand side matrix
    105         v = array([[2,4],[3,4],[4,4]])
     105        v = numpy.array([[2,4],[3,4],[4,4]])
    106106
    107107        u = A*v
    108         assert allclose(u, [[6,12], [14,16], [4,4]])
     108        assert numpy.allclose(u, [[6,12], [14,16], [4,4]])
    109109
    110110
     
    122122
    123123        u = A.trans_mult(v)
    124         assert allclose(u, [6,6,10])
     124        assert numpy.allclose(u, [6,6,10])
    125125
    126126
     
    137137
    138138        B = 3*A
    139         assert allclose(B.todense(), 3*A.todense())
     139        assert numpy.allclose(B.todense(), 3*A.todense())
    140140
    141141        B = A*3
    142         assert allclose(B.todense(), 3*A.todense())
     142        assert numpy.allclose(B.todense(), 3*A.todense())
    143143
    144144        try:
     
    166166        C = A+B
    167167
    168         assert allclose(C.todense(), [[12,0,0], [2,8,8], [0,0,4]])
     168        assert numpy.allclose(C.todense(), [[12,0,0], [2,8,8], [0,0,4]])
    169169
    170170    def test_sparse_tocsr(self):
     
    190190        C = [1, 2, 3]
    191191
    192         assert allclose(B*C, [15.0, 10.0 ,8.0, 0.0])
     192        assert numpy.allclose(B*C, [15.0, 10.0 ,8.0, 0.0])
    193193
    194194        C2 = [[1,2],[2,4],[3,6]]
     
    196196        #print B*C2
    197197
    198         assert allclose(B*C2, [[15.0, 30.0],[10.0, 20.0],[8.0, 16.0],[0.0, 0.0]])
     198        assert numpy.allclose(B*C2, [[15.0, 30.0],[10.0, 20.0],[8.0, 16.0],[0.0, 0.0]])
    199199
    200200
  • anuga_core/source/anuga/utilities/test_system_tools.py

    r5398 r5891  
    11#!/usr/bin/env python
    22
    3 
    43import unittest
    5 from Numeric import zeros, array, allclose, Float
     4import numpy
    65import zlib
    76from os.path import join, split, sep
     
    8180            pass
    8281        else:
    83             test_array = array([[7.0, 3.14], [-31.333, 0.0]])
     82            test_array = numpy.array([[7.0, 3.14], [-31.333, 0.0]])
    8483
    8584            # First file
     
    8786            fid = NetCDFFile(filename1, 'w')
    8887            fid.createDimension('two', 2)
    89             fid.createVariable('test_array', Float,
    90                                ('two', 'two'))
     88            fid.createVariable('test_array', numpy.dtype(numpy.float).char, ('two', 'two'))
    9189            fid.variables['test_array'][:] = test_array
    9290            fid.close()
     
    9694            fid = NetCDFFile(filename2, 'w')
    9795            fid.createDimension('two', 2)
    98             fid.createVariable('test_array', Float,
    99                                ('two', 'two'))
     96            fid.createVariable('test_array', numpy.dtype(numpy.float).char, ('two', 'two'))
    10097            fid.variables['test_array'][:] = test_array
    10198            fid.close()
  • anuga_core/source/anuga/utilities/test_xml_tools.py

    r5022 r5891  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose, Float
    65from tempfile import mkstemp, mktemp
    76
  • anuga_core/source/anuga/utilities/util_ext.c

    r3730 r5891  
    1616
    1717#include "Python.h"
    18 #include "Numeric/arrayobject.h"
     18#include "numpy/arrayobject.h"
    1919#include "math.h"
    2020
  • anuga_core/source/anuga/utilities/util_ext.h

    r5743 r5891  
    1111       
    1212#include "Python.h"     
    13 #include "Numeric/arrayobject.h"
     13#include "numpy/arrayobject.h"
    1414#include "math.h"
    1515
Note: See TracChangeset for help on using the changeset viewer.