Ignore:
Timestamp:
Nov 6, 2008, 12:17:15 PM (15 years ago)
Author:
ole
Message:

Reverted numpy changes to the trunk that should have been made to the branch.
The command was svn merge -r 5895:5890 .

File:
1 edited

Legend:

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

    r5891 r5897  
    77from warnings import warn
    88
    9 ##from numpy import ndarray, array, sum, inner, ravel, sqrt, searchsorted, sort, concatenate, float, arange
    10 import numpy
     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
     19from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt,\
     20     searchsorted, sort, concatenate, Float, arange   
    1121
    1222# Getting an infinite number to use when using Numeric
    1323#INF = (array([1])/0.)[0]
    1424
    15 NAN = (numpy.array([1])/0.)[0]
     25NAN = (array([1])/0.)[0]
    1626# Note, INF is used instead of NAN (Not a number), since Numeric has no NAN
    1727# if we use a package that has NAN, this should be updated to use NAN.
     
    7989        v2 = [1.0, 0.0] # Unit vector along the x-axis
    8090       
    81     v1 = ensure_numeric(v1, numpy.float)
    82     v2 = ensure_numeric(v2, numpy.float)   
     91    v1 = ensure_numeric(v1, Float)
     92    v2 = ensure_numeric(v2, Float)   
    8393   
    8494    # Normalise
    85     v1 = v1/numpy.sqrt(numpy.sum(v1**2))
    86     v2 = v2/numpy.sqrt(numpy.sum(v2**2))
     95    v1 = v1/sqrt(sum(v1**2))
     96    v2 = v2/sqrt(sum(v2**2))
    8797
    8898    # Compute angle
    89     p = numpy.inner(v1, v2)
    90     c = numpy.inner(v1, normal_vector(v2)) # Projection onto normal
     99    p = innerproduct(v1, v2)
     100    c = innerproduct(v1, normal_vector(v2)) # Projection onto normal
    91101                                            # (negative cross product)
    92102       
     
    130140    """
    131141   
    132     return numpy.array([-v[1], v[0]], numpy.float)
     142    return array([-v[1], v[0]], Float)
    133143
    134144   
     
    140150    """Mean value of a vector
    141151    """
    142     return(float(numpy.sum(x))/len(x))
     152    return(float(sum(x))/len(x))
    143153
    144154
     
    161171    cy = y - mean(y) 
    162172
    163     p = numpy.inner(cx,cy)/N
     173    p = innerproduct(cx,cy)/N
    164174    return(p)
    165175
     
    210220    """
    211221 
    212     y = numpy.ravel(x)
    213     p = numpy.sqrt(numpy.inner(y,y))
     222    y = ravel(x)
     223    p = sqrt(innerproduct(y,y))
    214224    return p
    215225   
     
    252262
    253263    if typecode is None:
    254 ##NumPy        if isinstance(A, ArrayType):
    255         if type(A) == numpy.ndarray:
     264        if type(A) == ArrayType:
    256265            return A
    257266        else:
    258             return numpy.array(A)
     267            return array(A)
    259268    else:
    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?
     269        if type(A) == ArrayType:
     270            if A.typecode == typecode:
     271                return array(A)  #FIXME: Shouldn't this just return A?
    265272            else:
    266                 return numpy.array(A, typecode)
     273                return array(A,typecode)
    267274        else:
    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)
     275            return array(A,typecode)
     276
    273277
    274278
     
    281285    """
    282286
    283     n = numpy.searchsorted(numpy.sort(a), bins)
    284     n = numpy.concatenate( [n, [len(a)]] )
     287    n = searchsorted(sort(a), bins)
     288    n = concatenate( [n, [len(a)]] )
    285289
    286290    hist = n[1:]-n[:-1]
    287291
    288292    if relative is True:
    289         hist = hist/float(numpy.sum(hist))
     293        hist = hist/float(sum(hist))
    290294       
    291295    return hist
     
    297301    """
    298302
    299     mx = numpy.max(data)
    300     mn = numpy.min(data)
     303    mx = max(data)
     304    mn = min(data)
    301305
    302306    if mx == mn:
    303         bins = numpy.array([mn])
     307        bins = array([mn])
    304308    else:
    305309        if number_of_bins is None:
    306310            number_of_bins = 10
    307311           
    308         bins = numpy.arange(mn, mx, (mx-mn)/number_of_bins)
     312        bins = arange(mn, mx, (mx-mn)/number_of_bins)
    309313
    310314    return bins
Note: See TracChangeset for help on using the changeset viewer.