Changeset 5889


Ignore:
Timestamp:
Nov 5, 2008, 9:15:55 AM (15 years ago)
Author:
rwilson
Message:

NumPy? conversion

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

Legend:

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

    r2841 r5889  
     1
    12import exceptions
    23class VectorShapeError(exceptions.Exception): pass
    34class ConvergenceError(exceptions.Exception): pass
    45
    5 from Numeric import dot, array, Float, zeros
     6##from numpy.oldnumeric import dot, array, Float, zeros
     7from numpy import dot, array, float, zeros
    68   
    79import logging, logging.config
     
    2426   
    2527    if x0 is None:
    26         x0 = zeros(b.shape, typecode=Float)
     28        x0 = zeros(b.shape, dtype=float)
    2729    else:
    28         x0 = array(x0, typecode=Float)
     30        x0 = array(x0, dtype=float)
    2931
    30     b  = array(b, typecode=Float)
     32    b  = array(b, dtype=float)
    3133    if len(b.shape) != 1 :
    3234       
     
    5759
    5860
    59    b  = array(b, typecode=Float)
     61   b  = array(b, dtype=float)
    6062   if len(b.shape) != 1 :
    6163      raise VectorShapeError, 'input vector should consist of only one column'
    6264
    6365   if x0 is None:
    64       x0 = zeros(b.shape, typecode=Float)
     66      x0 = zeros(b.shape, dtype=float)
    6567   else:
    66       x0 = array(x0, typecode=Float)
     68      x0 = array(x0, dtype=float)
    6769
    6870
  • anuga_core/source_numpy_conversion/anuga/utilities/compile.py

    r5138 r5889  
    1010   Ole Nielsen, Duncan Gray Oct 2001     
    1111"""     
     12
     13#NumPy ------------------------------------
     14# these lines recommended in "Converting from NUMARRAY to NUMPY"
     15import numpy
     16import numpy.numarray as nn
     17numpyincludedirs = numpy.get_include()
     18numarrayincludedirs = nn.get_numarray_include_dirs()
     19I_dirs = '-I"%s" ' % numpyincludedirs
     20for d in numarrayincludedirs:
     21    I_dirs += '-I"%s" ' % d
     22#NumPy ------------------------------------
    1223
    1324# FIXME (Ole): Although this script says it works with a range of compilers,
     
    255266    else:
    256267      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)
     268#NumPy        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -O3 -DTRILIBRARY=1 -DNO_TIMER=1'\
     269        s = '%s -c %s %s -I"%s" -I"%s" -o "%s.o" -O3 -DTRILIBRARY=1 -DNO_TIMER=1'\
     270            %(compiler, FN, I_dirs, python_include, utilities_include_dir, root)
    259271      else:
    260         s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
    261             %(compiler, FN, python_include, utilities_include_dir, root)
     272#NumPy        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
     273        s = '%s -c %s %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
     274            %(compiler, FN, I_dirs, python_include, utilities_include_dir, root)
    262275
    263276    if os.name == 'posix' and os.uname()[4] == 'x86_64':
  • anuga_core/source_numpy_conversion/anuga/utilities/interp.py

    r5681 r5889  
     1## Automatically adapted for numpy.oldnumeric Oct 28, 2008 by alter_code1.py
     2
    13#!/usr/bin/python -tt
    24#=======================================================================
     
    111113
    112114    >>> from interp import interp
    113     >>> import Numeric as N
     115    >>> import numpy.oldnumeric as N
    114116    >>> x = N.array([1., 2., 3., 4., 5.])
    115117    >>> y = N.array([3., 6., 2.,-5.,-3.])
     
    138140    """
    139141    import arrayfns
    140     import MA
    141     import Numeric as N
     142##    import numpy.oldnumeric.ma as MA
     143##    import numpy.oldnumeric as N
     144    import numpy.ma as MA
     145    import numpy as N
    142146    from where_close import where_close
    143147
     
    216220
    217221    >>> from interp import interp
    218     >>> import Numeric as N
     222    >>> import numpy.oldnumeric as N
    219223    >>> x = N.array([1.,    2., 3.,  4.,  5.,  6.])
    220224    >>> y = N.array([3., 1e+20, 2., -5., -3., -4.])
     
    284288    >>> ['%.7g' % yint[i] for i in range(len(yint))]
    285289    ['3.4', '2.3']
    286     >>> yint.typecode()
     290    >>> yint.dtype.char
    287291    'd'
    288292    >>> x = N.arange(6)
     
    292296    >>> ['%.7g' % yint[i] for i in range(len(yint))]
    293297    ['3', '2']
    294     >>> yint.typecode()
     298    >>> yint.dtype.char
    295299    'd'
    296300    """}
  • anuga_core/source_numpy_conversion/anuga/utilities/numerical_tools.py

    r5729 r5889  
    1414#except:
    1515#    #print 'Could not find scipy - using Numeric'
    16 #    from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt,
     16#    from numpy.oldnumeric import ArrayType, array, sum, innerproduct, ravel, sqrt,
    1717#searchsorted, sort, concatenate, Float, arange
    1818
    19 from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt,\
    20      searchsorted, sort, concatenate, Float, arange   
     19##from numpy.oldnumeric import ArrayType, array, sum, innerproduct, ravel, sqrt,\
     20##     searchsorted, sort, concatenate, Float, arange   
     21from numpy import ndarray, array, sum, inner, ravel, sqrt, searchsorted, sort, concatenate, float, arange   
    2122
    2223# Getting an infinite number to use when using Numeric
     
    8990        v2 = [1.0, 0.0] # Unit vector along the x-axis
    9091       
    91     v1 = ensure_numeric(v1, Float)
    92     v2 = ensure_numeric(v2, Float)   
     92    v1 = ensure_numeric(v1, float)
     93    v2 = ensure_numeric(v2, float)   
    9394   
    9495    # Normalise
     
    9798
    9899    # Compute angle
    99     p = innerproduct(v1, v2)
    100     c = innerproduct(v1, normal_vector(v2)) # Projection onto normal
     100    p = inner(v1, v2)
     101    c = inner(v1, normal_vector(v2)) # Projection onto normal
    101102                                            # (negative cross product)
    102103       
     
    140141    """
    141142   
    142     return array([-v[1], v[0]], Float)
     143    return array([-v[1], v[0]], float)
    143144
    144145   
     
    171172    cy = y - mean(y) 
    172173
    173     p = innerproduct(cx,cy)/N
     174    p = inner(cx,cy)/N
    174175    return(p)
    175176
     
    221222 
    222223    y = ravel(x)
    223     p = sqrt(innerproduct(y,y))
     224    p = sqrt(inner(y,y))
    224225    return p
    225226   
     
    262263
    263264    if typecode is None:
    264         if type(A) == ArrayType:
     265##NumPy        if isinstance(A, ArrayType):
     266        if type(A) == ndarray:
    265267            return A
    266268        else:
    267269            return array(A)
    268270    else:
    269         if type(A) == ArrayType:
    270             if A.typecode == typecode:
     271##NumPy        if isinstance(A, ArrayType):
     272        if type(A) == ndarray:
     273##NumPy            if A.typecode == typecode:
     274            if A.dtype == typecode:
    271275                return array(A)  #FIXME: Shouldn't this just return A?
    272276            else:
    273                 return array(A,typecode)
     277                return array(A, typecode)
    274278        else:
    275             return array(A,typecode)
    276 
     279            import types                            ##
     280            from numpy import str                   ##
     281            if isinstance(A, types.StringType):     ##
     282                return array(A, dtype=int)          ##
     283            return array(A, typecode)
    277284
    278285
  • anuga_core/source_numpy_conversion/anuga/utilities/polygon.py

    r5658 r5889  
    1010#    #print 'Could not find scipy - using Numeric'
    1111
    12 from Numeric import Float, Int, zeros, ones, array, concatenate, reshape, dot, allclose
     12from numpy import float, int, zeros, ones, array, concatenate, reshape, dot, allclose, newaxis, ascontiguousarray
    1313
    1414
     
    7676    # FIXME (Ole): Write this in C
    7777
    78     line0 = ensure_numeric(line0, Float)
    79     line1 = ensure_numeric(line1, Float)   
     78    line0 = ensure_numeric(line0, float)
     79    line1 = ensure_numeric(line1, float)   
    8080
    8181    x0 = line0[0,0]; y0 = line0[0,1]
     
    203203
    204204
    205     line0 = ensure_numeric(line0, Float)
    206     line1 = ensure_numeric(line1, Float)   
     205    line0 = ensure_numeric(line0, float)
     206    line1 = ensure_numeric(line1, float)   
    207207
    208208    status, value = _intersection(line0[0,0], line0[0,1],
     
    256256        # converted to a numeric array.
    257257        msg = 'Points could not be converted to Numeric array'
    258         raise msg
     258        raise TypeError, msg
    259259
    260260    try:
     
    265265        # If this fails it is going to be because the points can't be
    266266        # converted to a numeric array.
    267         msg = 'Polygon %s could not be converted to Numeric array' %(str(polygon))
    268         raise msg
     267        msg = 'Polygon %s could not be converted to Numeric array' % (str(polygon))
     268        raise TypeError, msg
    269269
    270270    if len(points.shape) == 1:
     
    312312    #if verbose: print 'Checking input to outside_polygon'
    313313    try:
    314         points = ensure_numeric(points, Float)
     314        points = ensure_numeric(points, float)
    315315    except NameError, e:
    316316        raise NameError, e
     
    320320
    321321    try:
    322         polygon = ensure_numeric(polygon, Float)
     322        polygon = ensure_numeric(polygon, float)
    323323    except NameError, e:
    324324        raise NameError, e
     
    354354    #if verbose: print 'Checking input to outside_polygon'
    355355    try:
    356         points = ensure_numeric(points, Float)
     356        points = ensure_numeric(points, float)
    357357    except NameError, e:
    358358        raise NameError, e
     
    362362
    363363    try:
    364         polygon = ensure_numeric(polygon, Float)
     364        polygon = ensure_numeric(polygon, float)
    365365    except NameError, e:
    366366        raise NameError, e
     
    439439    assert isinstance(verbose, bool), 'Keyword argument "verbose" must be boolean'
    440440
    441 
     441##    print 'Before: points=%s, flags=%s' % (type(points), str(points.flags))
    442442    try:
    443         points = ensure_numeric(points, Float)
     443##        points = ascontiguousarray(ensure_numeric(points, float))
     444        points = ensure_numeric(points, float)
    444445    except NameError, e:
    445446        raise NameError, e
    446447    except:
    447448        msg = 'Points could not be converted to Numeric array'
    448         raise msg
     449        raise TypeError, msg
     450##    print 'After: points=%s, flags=%s' % (type(points), str(points.flags))
    449451
    450452    #if verbose: print 'Checking input to separate_points_by_polygon 2'
    451453    try:
    452         polygon = ensure_numeric(polygon, Float)
     454##        polygon = ascontiguousarray(ensure_numeric(polygon, float))
     455        polygon = ensure_numeric(polygon, float)
    453456    except NameError, e:
    454457        raise NameError, e
    455458    except:
    456459        msg = 'Polygon could not be converted to Numeric array'
    457         raise msg
     460        raise TypeError, msg
    458461
    459462    msg = 'Polygon array must be a 2d array of vertices'
     
    476479   
    477480    msg = 'Point array must have two columns (x,y), '
    478     msg += 'I got points.shape[1] == %d' %points.shape[0]
     481    msg += 'I got points.shape[1] == %d' % points.shape[1]
    479482    assert points.shape[1] == 2, msg
    480483
     
    491494
    492495
    493     indices = zeros( M, Int )
     496    indices = zeros( M, int )
    494497
    495498    count = _separate_points_by_polygon(points, polygon, indices,
     
    618621
    619622    try:
    620         polygon = ensure_numeric(polygon, Float)
     623        polygon = ensure_numeric(polygon, float)
    621624    except NameError, e:
    622625        raise NameError, e
     
    680683    """
    681684
    682     def __init__(self, regions, default=0.0, geo_reference=None):
     685    def __init__(self, regions, default=0.0, geo_reference=None, verbose=False):
    683686
    684687        try:
     
    723726            self.regions.append( (P, value) )
    724727
     728        self.verbose = verbose
     729
    725730
    726731
    727732
    728733    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 
     734        x = array(x).astype(float)
     735        y = array(y).astype(float)
     736
     737        assert len(x.shape) == 1 and len(y.shape) == 1
     738       
     739        N = x.shape[0]
     740        assert y.shape[0] == N
     741
     742        points = ascontiguousarray(concatenate( (x[:,newaxis], y[:,newaxis]), axis=1 ))
     743       
    738744        if callable(self.default):
    739             z = self.default(x,y)
     745            z = self.default(x, y)
    740746        else:
    741             z = ones(N, Float) * self.default
     747            z = ones(N, float) * self.default
    742748
    743749        for polygon, value in self.regions:
    744             indices = inside_polygon(points, polygon)
     750            indices = inside_polygon(points, polygon, verbose=self.verbose)
    745751
    746752            # FIXME: This needs to be vectorised
  • anuga_core/source_numpy_conversion/anuga/utilities/polygon_ext.c

    r5570 r5889  
    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_numpy_conversion/anuga/utilities/quad.py

    r4932 r5889  
     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    from numpy import minimum, maximum
    438439
    439440
  • anuga_core/source_numpy_conversion/anuga/utilities/sparse.py

    r5223 r5889  
     1
    12"""Proof of concept sparse matrix code
    23"""
     
    1718           
    1819        if len(args) == 1:
    19             from Numeric import array
     20            from numpy import array
    2021            try:
    2122                A = array(args[0])
     
    9293
    9394    def todense(self):
    94         from Numeric import zeros, Float
    95 
    96         D = zeros( (self.M, self.N), Float)
     95        from numpy import zeros, float
     96
     97        D = zeros( (self.M, self.N), float)
    9798       
    9899        for i in range(self.M):
     
    109110        """
    110111
    111         from Numeric import array, zeros, Float
     112        from numpy import array, zeros, float
    112113       
    113114        try:
     
    130131            assert B.shape[0] == self.N, msg
    131132
    132             R = zeros(self.M, Float) #Result
     133            R = zeros(self.M, float) #Result
    133134           
    134135            # Multiply nonzero elements
     
    140141       
    141142           
    142             R = zeros((self.M, B.shape[1]), Float) #Result matrix
     143            R = zeros((self.M, B.shape[1]), float) #Result matrix
    143144
    144145            # Multiply nonzero elements
     
    162163        """
    163164
    164         from Numeric import array, zeros, Float
    165        
    166165        new = other.copy()
    167166        for key in self.Data.keys():
     
    177176        """
    178177
    179         from Numeric import array, zeros, Float
    180        
    181178        try:
    182179            other = float(other)
     
    200197        """
    201198
    202         from Numeric import array, zeros, Float
     199        from numpy import array, zeros, float
    203200       
    204201        try:
     
    214211            assert B.shape[0] == self.M, 'Mismatching dimensions'
    215212
    216             R = zeros((self.N,), Float) #Result
     213            R = zeros((self.N,), float) #Result
    217214
    218215            #Multiply nonzero elements
     
    251248        """
    252249
    253         from Numeric import array, Float, Int
     250        from numpy import zeros, float, int
    254251
    255252        if isinstance(A,Sparse):
    256253
    257             from Numeric import zeros
    258254            keys = A.Data.keys()
    259255            keys.sort()
    260256            nnz = len(keys)
    261             data    = zeros ( (nnz,), Float)
    262             colind  = zeros ( (nnz,), Int)
    263             row_ptr = zeros ( (A.M+1,), Int)
     257            data    = zeros ( (nnz,), float)
     258            colind  = zeros ( (nnz,), int)
     259            row_ptr = zeros ( (A.M+1,), int)
    264260            current_row = -1
    265261            k = 0
     
    299295
    300296    def todense(self):
    301         from Numeric import zeros, Float
     297        from numpy.oldnumeric import zeros, Float
    302298
    303299        D = zeros( (self.M, self.N), Float)
     
    314310        """
    315311
    316         from Numeric import array, zeros, Float
     312        from numpy.oldnumeric import array, zeros, Float
    317313       
    318314        try:
     
    334330    # A little selftest
    335331   
    336     from Numeric import allclose, array, Float
     332    from numpy.oldnumeric import allclose, array, Float
    337333   
    338334    A = Sparse(3,3)
  • anuga_core/source_numpy_conversion/anuga/utilities/sparse_ext.c

    r3730 r5889  
    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_numpy_conversion/anuga/utilities/test_cg_solve.py

    r3514 r5889  
    66
    77
    8 from Numeric import dot, allclose, array, transpose, arange, ones, Float
     8from numpy import dot, allclose, array, transpose, arange, ones, float
    99from anuga.utilities.cg_solve import *
    1010from anuga.utilities.cg_solve import _conjugate_gradient
     
    6868                A[i,i+1] = -0.5
    6969
    70         xe = ones( (n,), Float)
     70        xe = ones( (n,), float)
    7171
    7272        b  = A*xe
     
    9696                    A[I,I+1] = -1.0
    9797
    98         xe = ones( (n*m,), Float)
     98        xe = ones( (n*m,), float)
    9999
    100100        b  = A*xe
     
    125125                    A[I,I+1] = -1.0
    126126
    127         xe = ones( (n*m,), Float)
     127        xe = ones( (n*m,), float)
    128128
    129129        # Convert to csr format
     
    158158                    A[I,I+1] = -1.0
    159159
    160         xe = ones( (n*m,), Float)
     160        xe = ones( (n*m,), float)
    161161
    162162        b  = A*xe
  • anuga_core/source_numpy_conversion/anuga/utilities/test_data_audit.py

    r5096 r5889  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose, Float
     5from numpy.oldnumeric import zeros, array, allclose
    66from tempfile import mkstemp
    77import os
  • anuga_core/source_numpy_conversion/anuga/utilities/test_numerical_tools.py

    r5870 r5889  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose
    6 from Numeric import ArrayType, Float, Int, array, alltrue
     5from numpy import zeros, array, allclose
     6from numpy import ndarray, float, int, array, alltrue
    77
    88from math import sqrt, pi
     
    6868        A = [1,2,3,4]
    6969        B = ensure_numeric(A)
    70         assert type(B) == ArrayType
    71         assert B.typecode() == 'l'
     70        assert isinstance(B, ndarray)
     71        assert B.dtype.char == 'l'
    7272        assert B[0] == 1 and B[1] == 2 and B[2] == 3 and B[3] == 4
    7373
    7474        A = [1,2,3.14,4]
    7575        B = ensure_numeric(A)
    76         assert type(B) == ArrayType
    77         assert B.typecode() == 'd'
     76        assert isinstance(B, ndarray)
     77        assert B.dtype.char == '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
    83         assert B.typecode() == 'd'
     81        B = ensure_numeric(A, float)
     82        assert isinstance(B, ndarray)
     83        assert B.dtype.char == '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
    89         assert B.typecode() == 'd'
     87        B = ensure_numeric(A, float)
     88        assert isinstance(B, ndarray)
     89        assert B.dtype.char == 'd'
    9090        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    9191
    9292        A = array([1,2,3,4])
    9393        B = ensure_numeric(A)
    94         assert type(B) == ArrayType
    95         assert B.typecode() == 'l'       
     94        assert isinstance(B, ndarray)
     95        assert B.dtype.char == 'l'       
    9696        assert alltrue(A == B)   
    9797        assert A is B   #Same object
    9898
    9999        A = array([1,2,3,4])
    100         B = ensure_numeric(A, Float)
    101         assert type(B) == ArrayType
    102         assert B.typecode() == 'd'       
     100        B = ensure_numeric(A, float)
     101        assert isinstance(B, ndarray)
     102        assert B.dtype.char == 'd'       
    103103        assert alltrue(A == B)   
    104104        assert A is not B   #Not the same object
     
    106106        # Check scalars
    107107        A = 1
    108         B = ensure_numeric(A, Float)
     108        B = ensure_numeric(A, float)
    109109        #print A, B[0], len(B), type(B)
    110110        #print B.shape
    111111        assert alltrue(A == B)
    112112
    113         B = ensure_numeric(A, Int)       
     113        B = ensure_numeric(A, int)       
    114114        #print A, B
    115115        #print B.shape
    116116        assert alltrue(A == B)
    117117
     118    def NO_test_ensure_numeric_char(self):
    118119        # Error situation
    119 
    120         B = ensure_numeric('hello', Int)               
     120        B = ensure_numeric('hello', int)
     121        print 'B=%s %s' % (str(B), type(B))
    121122        assert allclose(B, [104, 101, 108, 108, 111])
    122123
     
    160161        zx, zy = gradient(x0, y0, x1, y1, x2, y2, z0, z1, z2)
    161162        a, b = gradient2(x0, y0, x1, y1, z0, z1)
    162 
     163       
    163164        assert zx == a
    164165        assert zy == b
     
    281282        from util_ext import gradient as gradient_c
    282283
    283         from RandomArray import uniform, seed
    284         seed(17, 53)
     284        from numpy.random import uniform, seed
     285        seed(53)    # numeric was seed(17, 53)
    285286
    286287        x0, x1, x2, y0, y1, y2 = uniform(0.0,3.0,6)
     
    312313        # sqrt(sum_over_x&y((xi - yi)^2))
    313314        err__1 = err(x,y,2,False)
     315       
    314316        assert err__1 == sqrt(20)
    315317        #print "err_", err_
  • anuga_core/source_numpy_conversion/anuga/utilities/test_polygon.py

    r5403 r5889  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose
     5from numpy import zeros, array, allclose, alltrue
    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
    4747        assert allclose(z, [1,1,0,0])
     
    5757        z = f([5, 5, 27, 35], [5, 9, 8, -5])
    5858        assert 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):
     
    210217        res = inside_polygon(points, polygon)
    211218        assert len(res) == 2
    212         assert allclose(res, [0,1])
     219        assert allclose(res, [0,1])     ## alltrue?
    213220
    214221
     
    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_numpy_conversion/anuga/utilities/test_quad.py

    r4741 r5889  
    11import unittest
    2 from Numeric import array, allclose
     2from numpy import array, allclose
    33
    44from quad import Cell, build_quadtree
  • anuga_core/source_numpy_conversion/anuga/utilities/test_sparse.py

    r2527 r5889  
    55
    66from sparse import *
    7 from Numeric import allclose, array, transpose, Float
     7from numpy.oldnumeric import allclose, array, transpose
    88
    99class Test_Sparse(unittest.TestCase):
  • anuga_core/source_numpy_conversion/anuga/utilities/test_system_tools.py

    r5398 r5889  
    33
    44import unittest
    5 from Numeric import zeros, array, allclose, Float
     5from numpy import zeros, array, allclose, float, dtype
    66import zlib
    77from os.path import join, split, sep
     
    8787            fid = NetCDFFile(filename1, 'w')
    8888            fid.createDimension('two', 2)
    89             fid.createVariable('test_array', Float,
    90                                ('two', 'two'))
     89            fid.createVariable('test_array', dtype(float).char, ('two', 'two'))
    9190            fid.variables['test_array'][:] = test_array
    9291            fid.close()
     
    9695            fid = NetCDFFile(filename2, 'w')
    9796            fid.createDimension('two', 2)
    98             fid.createVariable('test_array', Float,
    99                                ('two', 'two'))
     97            fid.createVariable('test_array', dtype(float).char, ('two', 'two'))
    10098            fid.variables['test_array'][:] = test_array
    10199            fid.close()
  • anuga_core/source_numpy_conversion/anuga/utilities/test_xml_tools.py

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

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

    r5743 r5889  
    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.