Changeset 6174


Ignore:
Timestamp:
Jan 15, 2009, 11:03:42 AM (15 years ago)
Author:
rwilson
Message:

Changed .array(A) to .array(A, num.Int) where appropriate. Helps when going to numpy.

Location:
anuga_core/source/anuga
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py

    r6166 r6174  
    185185            #   - Stored as six floats n0x,n0y,n1x,n1y,n2x,n2y per triangle
    186186
    187             n0 = num.array([x2 - x1, y2 - y1])
     187            n0 = num.array([x2 - x1, y2 - y1], num.Float)
    188188            l0 = num.sqrt(num.sum(n0**2))
    189189
    190             n1 = num.array([x0 - x2, y0 - y2])
     190            n1 = num.array([x0 - x2, y0 - y2], num.Float)
    191191            l1 = num.sqrt(num.sum(n1**2))
    192192
    193             n2 = num.array([x1 - x0, y1 - y0])
     193            n2 = num.array([x1 - x0, y1 - y0], num.Float)
    194194            l2 = num.sqrt(num.sum(n2**2))
    195195
     
    273273            if not self.geo_reference.is_absolute():
    274274                return V + num.array([self.geo_reference.get_xllcorner(),
    275                                       self.geo_reference.get_yllcorner()])
     275                                      self.geo_reference.get_yllcorner()], num.Float)
    276276            else:
    277277                return V
     
    315315            if absolute is True and not self.geo_reference.is_absolute():
    316316                offset=num.array([self.geo_reference.get_xllcorner(),
    317                                   self.geo_reference.get_yllcorner()])
     317                                  self.geo_reference.get_yllcorner()], num.Float)
    318318                return num.array([V[i3,:]+offset,
    319319                                  V[i3+1,:]+offset,
    320                                   V[i3+2,:]+offset])
     320                                  V[i3+2,:]+offset], num.Float)
    321321            else:
    322                 return num.array([V[i3,:], V[i3+1,:], V[i3+2,:]])
     322                return num.array([V[i3,:], V[i3+1,:], V[i3+2,:]], num.Float)
    323323               
    324324
  • anuga_core/source/anuga/abstract_2d_finite_volumes/generic_boundary_conditions.py

    r6173 r6174  
    200200           
    201201            # Compute midpoints
    202             if edge_id == 0: m = num.array([(x1 + x2)/2, (y1 + y2)/2])
    203             if edge_id == 1: m = num.array([(x0 + x2)/2, (y0 + y2)/2])
    204             if edge_id == 2: m = num.array([(x1 + x0)/2, (y1 + y0)/2])
     202            if edge_id == 0: m = num.array([(x1 + x2)/2, (y1 + y2)/2], num.Float)
     203            if edge_id == 1: m = num.array([(x0 + x2)/2, (y0 + y2)/2], num.Float)
     204            if edge_id == 2: m = num.array([(x1 + x0)/2, (y1 + y0)/2], num.Float)
    205205
    206206            # Convert to absolute UTM coordinates
  • anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh.py

    r6166 r6174  
    124124
    125125            #Compute centroid
    126             centroid = num.array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3])
     126            centroid = num.array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3], num.Float)
    127127            self.centroid_coordinates[i] = centroid
    128128
     
    133133
    134134                #Midpoints
    135                 m0 = num.array([(x1 + x2)/2, (y1 + y2)/2])
    136                 m1 = num.array([(x0 + x2)/2, (y0 + y2)/2])
    137                 m2 = num.array([(x1 + x0)/2, (y1 + y0)/2])
     135                m0 = num.array([(x1 + x2)/2, (y1 + y2)/2], num.Float)
     136                m1 = num.array([(x0 + x2)/2, (y0 + y2)/2], num.Float)
     137                m2 = num.array([(x1 + x0)/2, (y1 + y0)/2], num.Float)
    138138
    139139                #The radius is the distance from the centroid of
     
    11361136
    11371137            # Distances from line origin to the two intersections
    1138             z0 = num.array([x0 - xi0, y0 - eta0])
    1139             z1 = num.array([x1 - xi0, y1 - eta0])             
     1138            z0 = num.array([x0 - xi0, y0 - eta0], num.Float)
     1139            z1 = num.array([x1 - xi0, y1 - eta0], num.Float)
    11401140            d0 = num.sqrt(num.sum(z0**2))
    11411141            d1 = num.sqrt(num.sum(z1**2))
     
    11521152            # Normal direction:
    11531153            # Right hand side relative to line direction
    1154             vector = num.array([x1 - x0, y1 - y0]) # Segment vector
     1154            vector = num.array([x1 - x0, y1 - y0], num.Float) # Segment vector
    11551155            length = num.sqrt(num.sum(vector**2))      # Segment length
    1156             normal = num.array([vector[1], -vector[0]])/length
     1156            normal = num.array([vector[1], -vector[0]], num.Float)/length
    11571157
    11581158
     
    12341234        assert isinstance(segment, Triangle_intersection), msg
    12351235       
    1236         midpoint = num.sum(num.array(segment.segment))/2
     1236        midpoint = num.sum(num.array(segment.segment, num.Float))/2
    12371237        midpoints.append(midpoint)
    12381238
  • anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py

    r6166 r6174  
    11751175                    sum += self.vertex_values[triangle_id, vertex_id]
    11761176                vert_values.append(sum/len(triangles))
    1177             return num.array(vert_values)
     1177            return num.array(vert_values, num.Float)
    11781178        else:
    11791179            if (indices is None):
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_domain.py

    r6145 r6174  
    345345
    346346
    347         A = num.array([[1,2,3], [5,5,-5], [0,0,9], [-6,3,3]], 'f')
    348         B = num.array([[2,4,4], [3,2,1], [6,-3,4], [4,5,-1]], 'f')
     347        A = num.array([[1,2,3], [5,5,-5], [0,0,9], [-6,3,3]], num.Float)
     348        B = num.array([[2,4,4], [3,2,1], [6,-3,4], [4,5,-1]], num.Float)
    349349       
    350350        #print A
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_general_mesh.py

    r6145 r6174  
    5959       
    6060        #bac, bce, ecf, dbe, daf, dae
    61         triangles = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     61        triangles = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], num.Int)
    6262
    6363        domain = General_mesh(nodes, triangles,
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_neighbour_mesh.py

    r6145 r6174  
    2222
    2323def distance(x, y):
    24     return sqrt( sum( (num.array(x)-num.array(y))**2 ))
     24    return sqrt(num.sum((num.array(x)-num.array(y))**2))
    2525
    2626class Test_Mesh(unittest.TestCase):
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py

    r6145 r6174  
    17661766        quantity = Quantity(self.mesh4)
    17671767
    1768         quantity.vertex_values = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]],num.Float)
     1768        quantity.vertex_values = num.array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]], num.Float)
    17691769
    17701770        quantity.interpolate_from_vertices_to_edges()
     
    17821782                                          [3., 2.5, 1.5],
    17831783                                          [3.5, 4.5, 3.],
    1784                                           [2.5, 3.5, 2]],num.Float)
     1784                                          [2.5, 3.5, 2]], num.Float)
    17851785
    17861786        quantity.interpolate_from_edges_to_vertices()
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r6173 r6174  
    20972097                #add tide to stage if provided
    20982098                if quantity == 'stage':
    2099                      quantity_value[quantity] = num.array(quantity_value[quantity]) \
     2099                     quantity_value[quantity] = num.array(quantity_value[quantity], num.Float) \
    21002100                                                          + directory_add_tide
    21012101
  • anuga_core/source/anuga/alpha_shape/alpha_shape.py

    r6166 r6174  
    242242        ind3 = [self.deltri[j][2] for j in range(len(self.deltri))]
    243243
    244         x1 = num.array([ x[j] for j in ind1 ])
    245         y1 = num.array([ y[j] for j in ind1 ])
    246         x2 = num.array([ x[j] for j in ind2 ])
    247         y2 = num.array([ y[j] for j in ind2 ])
    248         x3 = num.array([ x[j] for j in ind3 ])
    249         y3 = num.array([ y[j] for j in ind3 ])
     244        x1 = num.array([x[j] for j in ind1])
     245        y1 = num.array([y[j] for j in ind1])
     246        x2 = num.array([x[j] for j in ind2])
     247        y2 = num.array([y[j] for j in ind2])
     248        x3 = num.array([x[j] for j in ind3])
     249        y3 = num.array([y[j] for j in ind3])
    250250
    251251        x21 = x2-x1
  • anuga_core/source/anuga/fit_interpolate/search_functions.py

    r6152 r6174  
    2222                        num.array([max_float,max_float]),
    2323                        num.array([max_float,max_float])),
    24                        (num.array([1,1]),num.array([0,0]),num.array([-1.1,-1.1]))]]]
     24                       (num.array([1,1], num.Int),      #array default#
     25                        num.array([0,0], num.Int),      #array default#
     26                        num.array([-1.1,-1.1]))]]]
    2527
    2628def search_tree_of_vertices(root, mesh, x):
  • anuga_core/source/anuga/fit_interpolate/test_fit.py

    r6152 r6174  
    2525
    2626def distance(x, y):
    27     return sqrt( sum( (num.array(x)-num.array(y))**2 ))
     27    return sqrt(num.sum((num.array(x)-num.array(y))**2))
    2828
    2929def linear_function(point):
     
    582582
    583583        #Define f(x,y) = x
    584         f = num.array([0,0,2]) #Value at global vertex 2
     584        f = num.array([0,0,2], num.Int) #Value at global vertex 2      #array default#
    585585
    586586        #Check that int (df/dx)**2 + (df/dy)**2 dx dy =
     
    589589
    590590        #Define f(x,y) = y
    591         f = num.array([0,2,0])  #Value at global vertex 1
     591        f = num.array([0,2,0], num.Int)  #Value at global vertex 1      #array default#
    592592
    593593        #Check that int (df/dx)**2 + (df/dy)**2 dx dy =
     
    596596
    597597        #Define f(x,y) = x+y
    598         f = num.array([0,2,2])  #Values at global vertex 1 and 2
     598        f = num.array([0,2,2], num.Int)  #Values at global vertex 1 and 2      #array default#
    599599
    600600        #Check that int (df/dx)**2 + (df/dy)**2 dx dy =
     
    623623
    624624        #Define f(x,y) = x
    625         f = num.array([0,0,2,0,2,4]) #f evaluated at points a-f
     625        f = num.array([0,0,2,0,2,4], num.Int) #f evaluated at points a-f      #array default#
    626626
    627627        #Check that int (df/dx)**2 + (df/dy)**2 dx dy =
     
    630630
    631631        #Define f(x,y) = y
    632         f = num.array([0,2,0,4,2,0]) #f evaluated at points a-f
     632        f = num.array([0,2,0,4,2,0], num.Int) #f evaluated at points a-f      #array default#
    633633
    634634        #Check that int (df/dx)**2 + (df/dy)**2 dx dy =
     
    637637
    638638        #Define f(x,y) = x+y
    639         f = num.array([0,2,2,4,4,4])  #f evaluated at points a-f
     639        f = num.array([0,2,2,4,4,4], num.Int)  #f evaluated at points a-f     #array default#
    640640
    641641        #Check that int (df/dx)**2 + (df/dy)**2 dx dy =
  • anuga_core/source/anuga/fit_interpolate/test_interpolate.py

    r6170 r6174  
    2929
    3030def distance(x, y):
    31     return sqrt( num.sum( (num.array(x)-num.array(y))**2 ))
     31    return sqrt(num.sum((num.array(x)-num.array(y))**2))
    3232
    3333def linear_function(point):
     
    760760
    761761        interp = Interpolate(vertices, triangles)
    762         f = num.array([linear_function(vertices),2*linear_function(vertices) ])
     762        f = num.array([linear_function(vertices),2*linear_function(vertices)])
    763763        f = num.transpose(f)
    764764        #print "f",f
     
    803803
    804804        interp = Interpolate(vertices, triangles)
    805         f = num.array([linear_function(vertices),2*linear_function(vertices) ])
     805        f = num.array([linear_function(vertices),2*linear_function(vertices)])
    806806        f = num.transpose(f)
    807807        #print "f",f
     
    819819           
    820820        f = num.array([linear_function(vertices),2*linear_function(vertices),
    821                        2*linear_function(vertices) - 100  ])
     821                       2*linear_function(vertices) - 100])
    822822        f = num.transpose(f)
    823823        #print "f",f
     
    829829            answer = num.array([linear_function(point_coords),
    830830                                2*linear_function(point_coords) ,
    831                                 2*linear_function(point_coords)-100 ])
     831                                2*linear_function(point_coords)-100])
    832832            z = num.transpose(z)
    833833            #print "z",z
     
    865865       
    866866        interp = Interpolate(vertices, triangles)
    867         f = num.array([linear_function(vertices),2*linear_function(vertices) ])
     867        f = num.array([linear_function(vertices),2*linear_function(vertices)])
    868868        f = num.transpose(f)
    869869        #print "f",f
     
    883883           
    884884        f = num.array([linear_function(vertices),2*linear_function(vertices),
    885                        2*linear_function(vertices) - 100  ])
     885                       2*linear_function(vertices) - 100])
    886886        f = num.transpose(f)
    887887        #print "f",f
     
    896896                                                              absolute = True)) ,
    897897                                                              2*linear_function(point_coords.get_data_points( \
    898                                                               absolute = True))-100 ])
     898                                                              absolute = True))-100])
    899899            z = num.transpose(z)
    900900            #print "z",z
     
    938938       
    939939        interp = Interpolate(vertices, triangles)
    940         f = num.array([linear_function(vertices),2*linear_function(vertices) ])
     940        f = num.array([linear_function(vertices),2*linear_function(vertices)])
    941941        f = num.transpose(f)
    942942        #print "f",f
     
    984984
    985985        interp = Interpolate(vertices, triangles)
    986         f = num.array([linear_function(vertices),2*linear_function(vertices) ])
     986        f = num.array([linear_function(vertices),2*linear_function(vertices)])
    987987        f = num.transpose(f)
    988988        z = interp.interpolate(f, point_coords,
     
    10471047
    10481048        interp = Interpolate(vertices, triangles)
    1049         f = num.array([linear_function(vertices),2*linear_function(vertices) ])
     1049        f = num.array([linear_function(vertices), 2*linear_function(vertices)])
    10501050        f = num.transpose(f)
    10511051        z = interp.interpolate(f, point_coords)
     
    13631363       
    13641364        interp = Interpolate(points, triangles)
    1365         f = num.array([linear_function(points),2*linear_function(points) ])
     1365        f = num.array([linear_function(points),2*linear_function(points)])
    13661366        f = num.transpose(f)
    13671367        #print "f",f
     
    16531653
    16541654        interp = Interpolate(vertices, triangles)
    1655         f = num.array([linear_function(vertices),2*linear_function(vertices) ])
     1655        f = num.array([linear_function(vertices),2*linear_function(vertices)])
    16561656        f = num.transpose(f)
    16571657        #print "f",f
  • anuga_core/source/anuga/mesh_engine/test_generate_mesh.py

    r6155 r6174  
    4343                              pointattlist,segattlist, mode, points)
    4444
    45         correct = num.array([(1, 0, 2), (2, 3, 1)])
     45        correct = num.array([(1, 0, 2), (2, 3, 1)], num.Int)      #array default#
    4646        self.failUnless(num.alltrue(data['generatedtrianglelist'].flat == \
    4747                                    correct.flat),
    4848                        'trianglelist is wrong!')
    49         correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
     49        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)], num.Int)      #array default#
    5050        self.failUnless(num.alltrue(data['generatedsegmentlist'].flat == \
    5151                                    correct.flat),
     
    7474        data = generate_mesh(points,seglist,holelist,regionlist,
    7575                              pointattlist,segattlist, mode, points)
    76         correct = num.array([(1, 0, 2), (2, 3, 1)])
     76        correct = num.array([(1, 0, 2), (2, 3, 1)], num.Int)      #array default#
    7777        self.failUnless(num.alltrue(data['generatedtrianglelist'].flat == \
    7878                                    correct.flat),
    7979                        'trianglelist is wrong!')
    80         correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
     80        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)], num.Int)      #array default#
    8181        self.failUnless(num.alltrue(data['generatedsegmentlist'].flat == \
    8282                                    correct.flat),
     
    154154                              pointattlist,segattlist, mode, points)
    155155
    156         correct = num.array([(1, 0, 2), (2, 3, 1)])
     156        correct = num.array([(1, 0, 2), (2, 3, 1)], num.Int)      #array default#
    157157        self.failUnless(num.alltrue(data['generatedtrianglelist'].flat == \
    158158                                    correct.flat),
    159159                        'trianglelist is wrong!')
    160         correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
     160        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)], num.Int)      #array default#
    161161        self.failUnless(num.alltrue(data['generatedsegmentlist'].flat == \
    162162                                    correct.flat),
     
    170170       
    171171        self.failUnless(num.alltrue(data['generatedsegmentmarkerlist'] == \
    172                                     num.array([1,2,3,4])),
     172                                    num.array([1,2,3,4], num.Int)),      #array default#
    173173                        'Failed!')
    174174       
     
    388388
    389389     
    390         correct = num.array([(1, 0, 2), (2, 3, 1)])
     390        correct = num.array([(1, 0, 2), (2, 3, 1)], num.Int)      #array default#
    391391        self.failUnless(num.alltrue(data['generatedtrianglelist'].flat == \
    392392                                    correct.flat),
    393393                        'trianglelist is wrong!')
    394         correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
     394        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)], num.Int)      #array default#
    395395        self.failUnless(num.alltrue(data['generatedsegmentlist'].flat == \
    396396                                    correct.flat),
     
    407407                                     correct.flat),
    408408                        'Failed')
    409         correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)])
     409        correct = num.array([(0, 1), (1, 3), (3, 2), (2, 0)], num.Int)      #array default#
    410410        self.failUnless(num.alltrue(data['generatedsegmentlist'].flat == \
    411411                                    correct.flat),
    412412                        'Failed!')
    413413       
    414         correct = num.array(segattlist)
     414        correct = num.array(segattlist, num.Int)      #array default#
    415415        self.failUnless(num.allclose(data['generatedsegmentmarkerlist'].flat,
    416416                                     correct.flat),
     
    418418       
    419419        # I copied these answers from the output, so bad test..
    420         correct = num.array([(-1, 1, -1), (-1, 0, -1)])
     420        correct = num.array([(-1, 1, -1), (-1, 0, -1)], num.Int)      #array default#
    421421        self.failUnless(num.alltrue(data['generatedtriangleneighborlist'].flat == \
    422422                                    correct.flat),
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r6173 r6174  
    49504950
    49514951        ## 7th test
    4952         m2d = num.array([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]])
     4952        m2d = num.array([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]], num.Int)      #array default#
    49534953        kmin, kmax, lmin, lmax = data_manager._get_min_max_indexes(
    49544954            latitudes,longitudes,
     
    50105010        longitudes = [148,149,150,151]
    50115011
    5012         m2d = num.array([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]])
     5012        m2d = num.array([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]], num.Int)      #array default#
    50135013
    50145014        # k - lat
     
    1062610626
    1062710627        # Check runup restricted to a polygon
    10628         p = num.array([[50,1], [99,1], [99,49], [50,49]]) + num.array([E, N])
     10628        p = num.array([[50,1], [99,1], [99,49], [50,49]], num.Int) + num.array([E, N], num.Int)      #array default#
    1062910629
    1063010630        runup = get_maximum_inundation_elevation(swwfile, polygon=p)
  • anuga_core/source/anuga/shallow_water/test_shallow_water_domain.py

    r6157 r6174  
    22
    33import unittest, os
    4 from math import pi
     4from math import pi, sqrt
    55import tempfile
    66
     
    254254        #Check error check
    255255        try:
    256             rotate(r, num.array([1,1,1]) )
     256            rotate(r, num.array([1,1,1], num.Int))      #array default#
    257257        except:
    258258            pass
     
    338338    def test_flux3(self):
    339339        #Use data from previous version of abstract_2d_finite_volumes
    340         normal = num.array([-num.sqrt(2)/2, num.sqrt(2)/2])
     340        normal = num.array([-sqrt(2)/2, sqrt(2)/2])
    341341        ql = num.array([-0.075, 2, 3])
    342342        qr = num.array([-0.075, 2, 3])
     
    347347        max_speed = flux_function(normal, ql, qr, zl, zr, edgeflux, epsilon, g, H0)       
    348348
    349         assert num.allclose(edgeflux, [num.sqrt(2)/2, 4.40221112, 7.3829019])
     349        assert num.allclose(edgeflux, [sqrt(2)/2, 4.40221112, 7.3829019])
    350350        assert num.allclose(max_speed, 4.0716654239)
    351351
    352352    def test_flux4(self):
    353353        #Use data from previous version of abstract_2d_finite_volumes
    354         normal = num.array([-num.sqrt(2)/2, num.sqrt(2)/2])
     354        normal = num.array([-sqrt(2)/2, sqrt(2)/2])
    355355        ql = num.array([-0.34319278, 0.10254161, 0.07273855])
    356356        qr = num.array([-0.30683287, 0.1071986, 0.05930515])
  • anuga_core/source/anuga/utilities/numerical_tools.py

    r6158 r6174  
    254254        if type(A) == num.ArrayType:
    255255            if A.typecode == typecode:
    256                 return num.array(A)  #FIXME: Shouldn't this just return A?
     256#                return num.array(A)  #FIXME: Shouldn't this just return A?
     257                return A
    257258            else:
    258259                return num.array(A,typecode)
  • anuga_core/source/anuga/utilities/test_numerical_tools.py

    r6158 r6174  
    9090        assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0
    9191
    92         A = num.array([1,2,3,4])
     92        A = num.array([1,2,3,4], num.Int)      #array default#
    9393        B = ensure_numeric(A)
    9494        assert type(B) == num.ArrayType
     
    9797        assert A is B   #Same object
    9898
    99         A = num.array([1,2,3,4])
     99        A = num.array([1,2,3,4], num.Int)      #array default#
    100100        B = ensure_numeric(A, num.Float)
    101101        assert type(B) == num.ArrayType
  • anuga_core/source/anuga/utilities/test_sparse.py

    r6158 r6174  
    8686
    8787        #Right hand side column
    88         v = num.array([[2,4],[3,4],[4,4]])
     88        v = num.array([[2,4],[3,4],[4,4]], num.Int)      #array default#
    8989
    9090        u = A*v[:,0]
     
    104104
    105105        #Right hand side matrix
    106         v = num.array([[2,4],[3,4],[4,4]])
     106        v = num.array([[2,4],[3,4],[4,4]], num.Int)      #array default#
    107107
    108108        u = A*v
Note: See TracChangeset for help on using the changeset viewer.