Changeset 5891
- Timestamp:
- Nov 5, 2008, 4:19:05 PM (16 years ago)
- Location:
- anuga_core/source/anuga/utilities
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/cg_solve.py
r2841 r5891 1 1 2 import exceptions 2 3 class VectorShapeError(exceptions.Exception): pass 3 4 class ConvergenceError(exceptions.Exception): pass 4 5 5 from Numeric import dot, array, Float, zeros 6 import numpy 6 7 7 8 import logging, logging.config … … 24 25 25 26 if x0 is None: 26 x0 = zeros(b.shape, typecode=Float)27 x0 = numpy.zeros(b.shape, dtype=numpy.float) 27 28 else: 28 x0 = array(x0, typecode=Float)29 x0 = numpy.array(x0, dtype=numpy.float) 29 30 30 b = array(b, typecode=Float)31 b = numpy.array(b, dtype=numpy.float) 31 32 if len(b.shape) != 1 : 32 33 … … 57 58 58 59 59 b = array(b, typecode=Float)60 b = numpy.array(b, dtype=numpy.float) 60 61 if len(b.shape) != 1 : 61 62 raise VectorShapeError, 'input vector should consist of only one column' 62 63 63 64 if x0 is None: 64 x0 = zeros(b.shape, typecode=Float)65 x0 = numpy.zeros(b.shape, dtype=numpy.float) 65 66 else: 66 x0 = array(x0, typecode=Float)67 x0 = numpy.array(x0, dtype=numpy.float) 67 68 68 69 … … 75 76 r = b - A*x 76 77 d = r 77 rTr = dot(r,r)78 rTr = numpy.dot(r,r) 78 79 rTr0 = rTr 79 80 80 81 while (i<imax and rTr>tol**2*rTr0): 81 82 q = A*d 82 alpha = rTr/ dot(d,q)83 alpha = rTr/numpy.dot(d,q) 83 84 x = x + alpha*d 84 85 if i%50 : … … 87 88 r = r - alpha*q 88 89 rTrOld = rTr 89 rTr = dot(r,r)90 rTr = numpy.dot(r,r) 90 91 bt = rTr/rTrOld 91 92 -
anuga_core/source/anuga/utilities/compile.py
r5138 r5891 10 10 Ole Nielsen, Duncan Gray Oct 2001 11 11 """ 12 13 #NumPy ------------------------------------ 14 # Something like these lines recommended in "Converting from NUMARRAY to NUMPY" 15 import numpy 16 numpyincludedirs = numpy.get_include() 17 I_dirs = '-I"%s" ' % numpyincludedirs 18 #NumPy ------------------------------------ 12 19 13 20 # FIXME (Ole): Although this script says it works with a range of compilers, … … 255 262 else: 256 263 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) 259 267 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) 262 271 263 272 if os.name == 'posix' and os.uname()[4] == 'x86_64': -
anuga_core/source/anuga/utilities/interp.py
r5681 r5891 111 111 112 112 >>> from interp import interp 113 >>> import Numeric as N113 >>> import numpy.oldnumeric as N 114 114 >>> x = N.array([1., 2., 3., 4., 5.]) 115 115 >>> y = N.array([3., 6., 2.,-5.,-3.]) … … 138 138 """ 139 139 import arrayfns 140 import MA141 import Numericas N140 import numpy.ma as MA 141 import numpy as N 142 142 from where_close import where_close 143 143 … … 216 216 217 217 >>> from interp import interp 218 >>> import Numeric as N218 >>> import numpy.oldnumeric as N 219 219 >>> x = N.array([1., 2., 3., 4., 5., 6.]) 220 220 >>> y = N.array([3., 1e+20, 2., -5., -3., -4.]) … … 284 284 >>> ['%.7g' % yint[i] for i in range(len(yint))] 285 285 ['3.4', '2.3'] 286 >>> yint. typecode()286 >>> yint.dtype.char 287 287 'd' 288 288 >>> x = N.arange(6) … … 292 292 >>> ['%.7g' % yint[i] for i in range(len(yint))] 293 293 ['3', '2'] 294 >>> yint. typecode()294 >>> yint.dtype.char 295 295 'd' 296 296 """} -
anuga_core/source/anuga/utilities/numerical_tools.py
r5729 r5891 7 7 from warnings import warn 8 8 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 10 import numpy 21 11 22 12 # Getting an infinite number to use when using Numeric 23 13 #INF = (array([1])/0.)[0] 24 14 25 NAN = ( array([1])/0.)[0]15 NAN = (numpy.array([1])/0.)[0] 26 16 # Note, INF is used instead of NAN (Not a number), since Numeric has no NAN 27 17 # if we use a package that has NAN, this should be updated to use NAN. … … 89 79 v2 = [1.0, 0.0] # Unit vector along the x-axis 90 80 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) 93 83 94 84 # 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)) 97 87 98 88 # Compute angle 99 p = innerproduct(v1, v2)100 c = innerproduct(v1, normal_vector(v2)) # Projection onto normal89 p = numpy.inner(v1, v2) 90 c = numpy.inner(v1, normal_vector(v2)) # Projection onto normal 101 91 # (negative cross product) 102 92 … … 140 130 """ 141 131 142 return array([-v[1], v[0]], Float)132 return numpy.array([-v[1], v[0]], numpy.float) 143 133 144 134 … … 150 140 """Mean value of a vector 151 141 """ 152 return(float( sum(x))/len(x))142 return(float(numpy.sum(x))/len(x)) 153 143 154 144 … … 171 161 cy = y - mean(y) 172 162 173 p = innerproduct(cx,cy)/N163 p = numpy.inner(cx,cy)/N 174 164 return(p) 175 165 … … 220 210 """ 221 211 222 y = ravel(x)223 p = sqrt(innerproduct(y,y))212 y = numpy.ravel(x) 213 p = numpy.sqrt(numpy.inner(y,y)) 224 214 return p 225 215 … … 262 252 263 253 if typecode is None: 264 if type(A) == ArrayType: 254 ##NumPy if isinstance(A, ArrayType): 255 if type(A) == numpy.ndarray: 265 256 return A 266 257 else: 267 return array(A)258 return numpy.array(A) 268 259 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? 272 265 else: 273 return array(A,typecode)266 return numpy.array(A, typecode) 274 267 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) 277 273 278 274 … … 285 281 """ 286 282 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)]] ) 289 285 290 286 hist = n[1:]-n[:-1] 291 287 292 288 if relative is True: 293 hist = hist/float( sum(hist))289 hist = hist/float(numpy.sum(hist)) 294 290 295 291 return hist … … 301 297 """ 302 298 303 mx = max(data)304 mn = min(data)299 mx = numpy.max(data) 300 mn = numpy.min(data) 305 301 306 302 if mx == mn: 307 bins = array([mn])303 bins = numpy.array([mn]) 308 304 else: 309 305 if number_of_bins is None: 310 306 number_of_bins = 10 311 307 312 bins = arange(mn, mx, (mx-mn)/number_of_bins)308 bins = numpy.arange(mn, mx, (mx-mn)/number_of_bins) 313 309 314 310 return bins -
anuga_core/source/anuga/utilities/polygon.py
r5658 r5891 10 10 # #print 'Could not find scipy - using Numeric' 11 11 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 13 import numpy 13 14 14 15 … … 76 77 # FIXME (Ole): Write this in C 77 78 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) 80 81 81 82 x0 = line0[0,0]; y0 = line0[0,1] … … 89 90 u1 = (x2-x0)*(y1-y0) - (y2-y0)*(x1-x0) 90 91 91 if allclose(denom, 0.0):92 if numpy.allclose(denom, 0.0): 92 93 # Lines are parallel - check if they coincide on a shared a segment 93 94 94 if allclose( [u0, u1], 0.0 ):95 if numpy.allclose( [u0, u1], 0.0 ): 95 96 # We now know that the lines if continued coincide 96 97 # The remaining check will establish if the finite lines share a segment … … 120 121 if line0_starts_on_line1 and line0_ends_on_line1: 121 122 # Shared segment is line0 fully included in line1 122 segment = array([[x0, y0], [x1, y1]])123 segment = numpy.array([[x0, y0], [x1, y1]]) 123 124 124 125 if line1_starts_on_line0 and line1_ends_on_line0: 125 126 # Shared segment is line1 fully included in line0 126 segment = array([[x2, y2], [x3, y3]])127 segment = numpy.array([[x2, y2], [x3, y3]]) 127 128 128 129 … … 130 131 if line0_starts_on_line1 and line1_ends_on_line0: 131 132 # Shared segment from line0 start to line 1 end 132 segment = array([[x0, y0], [x3, y3]])133 segment = numpy.array([[x0, y0], [x3, y3]]) 133 134 134 135 if line1_starts_on_line0 and line0_ends_on_line1: 135 136 # Shared segment from line1 start to line 0 end 136 segment = array([[x2, y2], [x1, y1]])137 segment = numpy.array([[x2, y2], [x1, y1]]) 137 138 138 139 … … 140 141 if line0_starts_on_line1 and line1_starts_on_line0: 141 142 # Shared segment from line0 start to line 1 end 142 segment = array([[x0, y0], [x2, y2]])143 segment = numpy.array([[x0, y0], [x2, y2]]) 143 144 144 145 if line0_ends_on_line1 and line1_ends_on_line0: 145 146 # Shared segment from line0 start to line 1 end 146 segment = array([[x3, y3], [x1, y1]])147 segment = numpy.array([[x3, y3], [x1, y1]]) 147 148 148 149 … … 161 162 162 163 # 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)) 165 166 166 167 # Check if point found lies within given line segments … … 168 169 # We have intersection 169 170 170 return 1, array([x, y])171 return 1, numpy.array([x, y]) 171 172 else: 172 173 # No intersection … … 203 204 204 205 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) 207 208 208 209 status, value = _intersection(line0[0,0], line0[0,1], … … 256 257 # converted to a numeric array. 257 258 msg = 'Points could not be converted to Numeric array' 258 raise msg259 raise TypeError, msg 259 260 260 261 try: … … 265 266 # If this fails it is going to be because the points can't be 266 267 # converted to a numeric array. 267 msg = 'Polygon %s could not be converted to Numeric array' % (str(polygon))268 raise msg268 msg = 'Polygon %s could not be converted to Numeric array' % (str(polygon)) 269 raise TypeError, msg 269 270 270 271 if len(points.shape) == 1: 271 272 # Only one point was passed in. Convert to array of points 272 points = reshape(points, (1,2))273 points = numpy.reshape(points, (1,2)) 273 274 274 275 indices, count = separate_points_by_polygon(points, polygon, … … 312 313 #if verbose: print 'Checking input to outside_polygon' 313 314 try: 314 points = ensure_numeric(points, Float)315 points = ensure_numeric(points, numpy.float) 315 316 except NameError, e: 316 317 raise NameError, e … … 320 321 321 322 try: 322 polygon = ensure_numeric(polygon, Float)323 polygon = ensure_numeric(polygon, numpy.float) 323 324 except NameError, e: 324 325 raise NameError, e … … 330 331 if len(points.shape) == 1: 331 332 # Only one point was passed in. Convert to array of points 332 points = reshape(points, (1,2))333 points = numpy.reshape(points, (1,2)) 333 334 334 335 indices, count = separate_points_by_polygon(points, polygon, … … 339 340 if count == len(indices): 340 341 # No points are outside 341 return array([])342 return numpy.array([]) 342 343 else: 343 344 return indices[count:][::-1] #return reversed … … 354 355 #if verbose: print 'Checking input to outside_polygon' 355 356 try: 356 points = ensure_numeric(points, Float)357 points = ensure_numeric(points, numpy.float) 357 358 except NameError, e: 358 359 raise NameError, e … … 362 363 363 364 try: 364 polygon = ensure_numeric(polygon, Float)365 polygon = ensure_numeric(polygon, numpy.float) 365 366 except NameError, e: 366 367 raise NameError, e … … 371 372 if len(points.shape) == 1: 372 373 # Only one point was passed in. Convert to array of points 373 points = reshape(points, (1,2))374 points = numpy.reshape(points, (1,2)) 374 375 375 376 … … 439 440 assert isinstance(verbose, bool), 'Keyword argument "verbose" must be boolean' 440 441 441 442 ## print 'Before: points=%s, flags=%s' % (type(points), str(points.flags)) 442 443 try: 443 points = ensure_numeric(points, Float) 444 ## points = numpy.ascontiguousarray(ensure_numeric(points, numpy.float)) 445 points = ensure_numeric(points, numpy.float) 444 446 except NameError, e: 445 447 raise NameError, e 446 448 except: 447 449 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)) 449 452 450 453 #if verbose: print 'Checking input to separate_points_by_polygon 2' 451 454 try: 452 polygon = ensure_numeric(polygon, Float) 455 ## polygon = numpy.ascontiguousarray(ensure_numeric(polygon, numpy.float)) 456 polygon = ensure_numeric(polygon, numpy.float) 453 457 except NameError, e: 454 458 raise NameError, e 455 459 except: 456 460 msg = 'Polygon could not be converted to Numeric array' 457 raise msg461 raise TypeError, msg 458 462 459 463 msg = 'Polygon array must be a 2d array of vertices' … … 472 476 # Only one point was passed in. 473 477 # Convert to array of points 474 points = reshape(points, (1,2))478 points = numpy.reshape(points, (1,2)) 475 479 476 480 477 481 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] 479 483 assert points.shape[1] == 2, msg 480 484 … … 491 495 492 496 493 indices = zeros( M, Int )497 indices = numpy.zeros( M, numpy.int ) 494 498 495 499 count = _separate_points_by_polygon(points, polygon, indices, … … 618 622 619 623 try: 620 polygon = ensure_numeric(polygon, Float)624 polygon = ensure_numeric(polygon, numpy.float) 621 625 except NameError, e: 622 626 raise NameError, e … … 627 631 x = polygon[:,0] 628 632 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) 631 635 632 636 return x, y … … 680 684 """ 681 685 682 def __init__(self, regions, default=0.0, geo_reference=None ):686 def __init__(self, regions, default=0.0, geo_reference=None, verbose=False): 683 687 684 688 try: … … 723 727 self.regions.append( (P, value) ) 724 728 729 self.verbose = verbose 730 725 731 726 732 727 733 728 734 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 738 745 if callable(self.default): 739 z = self.default(x, y)746 z = self.default(x, y) 740 747 else: 741 z = ones(N, Float) * self.default748 z = numpy.ones(N, numpy.float) * self.default 742 749 743 750 for polygon, value in self.regions: 744 indices = inside_polygon(points, polygon )751 indices = inside_polygon(points, polygon, verbose=self.verbose) 745 752 746 753 # FIXME: This needs to be vectorised 747 754 if callable(value): 748 755 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]]) 751 758 z[i] = value(xx, yy)[0] 752 759 else: -
anuga_core/source/anuga/utilities/polygon_ext.c
r5570 r5891 15 15 16 16 #include "Python.h" 17 #include " Numeric/arrayobject.h"17 #include "numpy/arrayobject.h" 18 18 #include "math.h" 19 19 … … 222 222 } 223 223 for (k=0; k<M; k++) { 224 x = points[2*k]; 225 y = points[2*k + 1]; 226 224 227 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); 226 229 } 227 230 228 x = points[2*k];229 y = points[2*k + 1];230 231 231 inside = 0; 232 232 … … 376 376 *polygon, 377 377 *indices; 378 // PyObject *xxxx; 378 379 379 380 int closed, verbose; //Flags … … 393 394 return NULL; 394 395 } 396 397 // points = (PyArrayObject *) PyArray_ContiguousFromObject(xxxx, PyArray_DOUBLE, 1, 1); 395 398 396 399 M = points -> dimensions[0]; //Number of points -
anuga_core/source/anuga/utilities/quad.py
r4932 r5891 1 1 2 """quad.py - quad tree data structure for fast indexing of points in the plane 2 3 … … 222 223 triangles = {} 223 224 verts = self.retrieve_vertices() 224 #print "verts", verts225 print "verts", verts 225 226 for vert in verts: 226 227 triangle_list = self.mesh.get_triangles_and_vertices_per_node(vert) 228 print 'triangle_list=%s' % str(triangle_list) 227 229 for k, _ in triangle_list: 228 230 if not triangles.has_key(k): 229 231 # print 'k',k 230 tri = self.mesh.get_vertex_coordinates(k, 231 absolute=True) 232 tri = self.mesh.get_vertex_coordinates(k, absolute=True) 232 233 n0 = self.mesh.get_normal(k, 0) 233 234 n1 = self.mesh.get_normal(k, 1) … … 435 436 """ 436 437 437 from Numeric import minimum, maximum438 439 440 438 #Make root cell 441 439 #print mesh.coordinates -
anuga_core/source/anuga/utilities/sparse.py
r5223 r5891 1 1 2 """Proof of concept sparse matrix code 2 3 """ 3 4 5 import numpy 4 6 5 7 class Sparse: … … 17 19 18 20 if len(args) == 1: 19 from Numeric import array20 21 try: 21 A = array(args[0])22 A = numpy.array(args[0]) 22 23 except: 23 24 raise 'Input must be convertable to a Numeric array' … … 92 93 93 94 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) 97 96 98 97 for i in range(self.M): … … 109 108 """ 110 109 111 from Numeric import array, zeros, Float112 113 110 try: 114 B = array(other)111 B = numpy.array(other) 115 112 except: 116 113 msg = 'FIXME: Only Numeric types implemented so far' … … 130 127 assert B.shape[0] == self.N, msg 131 128 132 R = zeros(self.M, Float) #Result129 R = numpy.zeros(self.M, numpy.float) #Result 133 130 134 131 # Multiply nonzero elements … … 140 137 141 138 142 R = zeros((self.M, B.shape[1]), Float) #Result matrix139 R = numpy.zeros((self.M, B.shape[1]), numpy.float) #Result matrix 143 140 144 141 # Multiply nonzero elements … … 162 159 """ 163 160 164 from Numeric import array, zeros, Float165 166 161 new = other.copy() 167 162 for key in self.Data.keys(): … … 177 172 """ 178 173 179 from Numeric import array, zeros, Float180 181 174 try: 182 175 other = float(other) … … 200 193 """ 201 194 202 from Numeric import array, zeros, Float203 204 195 try: 205 B = array(other)196 B = numpy.array(other) 206 197 except: 207 198 print 'FIXME: Only Numeric types implemented so far' … … 214 205 assert B.shape[0] == self.M, 'Mismatching dimensions' 215 206 216 R = zeros((self.N,), Float) #Result207 R = numpy.zeros((self.N,), numpy.float) #Result 217 208 218 209 #Multiply nonzero elements … … 251 242 """ 252 243 253 from Numeric import array, Float, Int254 255 244 if isinstance(A,Sparse): 256 245 257 from Numeric import zeros258 246 keys = A.Data.keys() 259 247 keys.sort() 260 248 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) 264 252 current_row = -1 265 253 k = 0 … … 299 287 300 288 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) 304 291 305 292 for i in range(self.M): … … 314 301 """ 315 302 316 from Numeric import array, zeros, Float317 318 303 try: 319 B = array(other)304 B = numpy.array(other) 320 305 except: 321 306 print 'FIXME: Only Numeric types implemented so far' … … 333 318 if __name__ == '__main__': 334 319 # A little selftest 335 336 from Numeric import allclose, array, Float337 338 320 A = Sparse(3,3) 339 321 … … 366 348 u = A*v 367 349 print u 368 assert allclose(u, [6,14,4])350 assert numpy.allclose(u, [6,14,4]) 369 351 370 352 u = A.trans_mult(v) 371 353 print u 372 assert allclose(u, [6,6,10])354 assert numpy.allclose(u, [6,6,10]) 373 355 374 356 #Right hand side column 375 v = array([[2,4],[3,4],[4,4]])357 v = numpy.array([[2,4],[3,4],[4,4]]) 376 358 377 359 u = A*v[:,0] 378 assert allclose(u, [6,14,4])360 assert numpy.allclose(u, [6,14,4]) 379 361 380 362 #u = A*v[:,1] -
anuga_core/source/anuga/utilities/sparse_ext.c
r3730 r5891 11 11 12 12 #include "Python.h" 13 #include " Numeric/arrayobject.h"13 #include "numpy/arrayobject.h" 14 14 #include "math.h" 15 15 #include "stdio.h" -
anuga_core/source/anuga/utilities/test_cg_solve.py
r3514 r5891 5 5 import unittest 6 6 7 8 from Numeric import dot, allclose, array, transpose, arange, ones, Float 7 import numpy 9 8 from anuga.utilities.cg_solve import * 10 9 from anuga.utilities.cg_solve import _conjugate_gradient … … 30 29 x = conjugate_gradient(A,b,x,iprint=0) 31 30 32 assert allclose(x,xe)31 assert numpy.allclose(x,xe) 33 32 34 33 def test_max_iter(self): … … 61 60 A = Sparse(n,n) 62 61 63 for i in arange(0,n):62 for i in numpy.arange(0,n): 64 63 A[i,i] = 1.0 65 64 if i > 0 : … … 68 67 A[i,i+1] = -0.5 69 68 70 xe = ones( (n,), Float)69 xe = numpy.ones( (n,), numpy.float) 71 70 72 71 b = A*xe 73 72 x = conjugate_gradient(A,b,b,tol=1.0e-5,iprint=1) 74 73 75 assert allclose(x,xe)74 assert numpy.allclose(x,xe) 76 75 77 76 def test_solve_large_2d(self): … … 83 82 A = Sparse(m*n, m*n) 84 83 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): 87 86 I = j+m*i 88 87 A[I,I] = 4.0 … … 96 95 A[I,I+1] = -1.0 97 96 98 xe = ones( (n*m,), Float)97 xe = numpy.ones( (n*m,), numpy.float) 99 98 100 99 b = A*xe 101 100 x = conjugate_gradient(A,b,b,iprint=0) 102 101 103 assert allclose(x,xe)102 assert numpy.allclose(x,xe) 104 103 105 104 def test_solve_large_2d_csr_matrix(self): … … 112 111 A = Sparse(m*n, m*n) 113 112 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): 116 115 I = j+m*i 117 116 A[I,I] = 4.0 … … 125 124 A[I,I+1] = -1.0 126 125 127 xe = ones( (n*m,), Float)126 xe = numpy.ones( (n*m,), numpy.float) 128 127 129 128 # Convert to csr format … … 134 133 x = conjugate_gradient(A,b,b,iprint=20) 135 134 136 assert allclose(x,xe)135 assert numpy.allclose(x,xe) 137 136 138 137 … … 145 144 A = Sparse(m*n, m*n) 146 145 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): 149 148 I = j+m*i 150 149 A[I,I] = 4.0 … … 158 157 A[I,I+1] = -1.0 159 158 160 xe = ones( (n*m,), Float)159 xe = numpy.ones( (n*m,), numpy.float) 161 160 162 161 b = A*xe 163 162 x = conjugate_gradient(A,b) 164 163 165 assert allclose(x,xe)164 assert numpy.allclose(x,xe) 166 165 167 166 … … 202 201 x = conjugate_gradient(A,b,x,iprint=0) 203 202 204 assert allclose(x,xe)203 assert numpy.allclose(x,xe) 205 204 206 205 #------------------------------------------------------------- -
anuga_core/source/anuga/utilities/test_data_audit.py
r5096 r5891 3 3 4 4 import unittest 5 from Numeric import zeros, array, allclose, Float6 5 from tempfile import mkstemp 7 6 import os -
anuga_core/source/anuga/utilities/test_numerical_tools.py
r5870 r5891 3 3 4 4 import unittest 5 from Numeric import zeros, array, allclose 6 from Numeric import ArrayType, Float, Int, array, alltrue 5 import numpy 7 6 8 7 from math import sqrt, pi … … 23 22 """Test angles between one vector and the x-axis 24 23 """ 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) 33 32 34 33 … … 37 36 """ 38 37 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) 41 40 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) 44 43 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) 47 46 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) 50 49 51 50 #From test_get_boundary_polygon_V 52 51 v_prev = [-0.5, -0.5] 53 52 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) 55 54 56 55 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) 58 57 59 58 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) 61 60 62 61 63 62 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) 65 64 66 65 … … 68 67 A = [1,2,3,4] 69 68 B = ensure_numeric(A) 70 assert type(B) == ArrayType71 assert B. typecode()== 'l'69 assert isinstance(B, numpy.ndarray) 70 assert B.dtype.char == 'l' 72 71 assert B[0] == 1 and B[1] == 2 and B[2] == 3 and B[3] == 4 73 72 74 73 A = [1,2,3.14,4] 75 74 B = ensure_numeric(A) 76 assert type(B) == ArrayType77 assert B. typecode()== 'd'75 assert isinstance(B, numpy.ndarray) 76 assert B.dtype.char == 'd' 78 77 assert B[0] == 1 and B[1] == 2 and B[2] == 3.14 and B[3] == 4 79 78 80 79 A = [1,2,3,4] 81 B = ensure_numeric(A, Float)82 assert type(B) == ArrayType83 assert B. typecode()== 'd'80 B = ensure_numeric(A, numpy.float) 81 assert isinstance(B, numpy.ndarray) 82 assert B.dtype.char == 'd' 84 83 assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0 85 84 86 85 A = [1,2,3,4] 87 B = ensure_numeric(A, Float)88 assert type(B) == ArrayType89 assert B. typecode()== 'd'86 B = ensure_numeric(A, numpy.float) 87 assert isinstance(B, numpy.ndarray) 88 assert B.dtype.char == 'd' 90 89 assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0 91 90 92 A = array([1,2,3,4])91 A = numpy.array([1,2,3,4]) 93 92 B = ensure_numeric(A) 94 assert type(B) == ArrayType95 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) 97 96 assert A is B #Same object 98 97 99 A = array([1,2,3,4])100 B = ensure_numeric(A, Float)101 assert type(B) == ArrayType102 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) 104 103 assert A is not B #Not the same object 105 104 106 105 # Check scalars 107 106 A = 1 108 B = ensure_numeric(A, Float)107 B = ensure_numeric(A, numpy.float) 109 108 #print A, B[0], len(B), type(B) 110 109 #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) 114 113 #print A, B 115 114 #print B.shape 116 assert alltrue(A == B) 117 115 assert numpy.alltrue(A == B) 116 117 def NO_test_ensure_numeric_char(self): 118 118 # 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]) 122 122 123 123 … … 160 160 zx, zy = gradient(x0, y0, x1, y1, x2, y2, z0, z1, z2) 161 161 a, b = gradient2(x0, y0, x1, y1, z0, z1) 162 162 163 163 assert zx == a 164 164 assert zy == b … … 208 208 #There are four elements greater than or equal to 3 209 209 bins = [3] 210 assert allclose(histogram(a, bins), [4])210 assert numpy.allclose(histogram(a, bins), [4]) 211 211 212 212 bins = [ min(a) ] 213 assert allclose(histogram(a, bins), [len(a)])213 assert numpy.allclose(histogram(a, bins), [len(a)]) 214 214 215 215 bins = [ max(a)+0.00001 ] 216 assert allclose(histogram(a, bins), [0])216 assert numpy.allclose(histogram(a, bins), [0]) 217 217 218 218 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]) 220 220 221 221 bins = [1.1,2,3.1,4] 222 222 #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]) 224 224 225 225 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])) 228 228 229 229 # Check situation with #bins >= #datapoints 230 230 a = [1.7] 231 231 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]) 233 233 234 234 a = [1.7] 235 235 bins = [0] 236 assert allclose(histogram(a, bins), [1])236 assert numpy.allclose(histogram(a, bins), [1]) 237 237 238 238 a = [-1.7] 239 239 bins = [0] 240 assert allclose(histogram(a, bins), [0])240 assert numpy.allclose(histogram(a, bins), [0]) 241 241 242 242 a = [-1.7] 243 243 bins = [-1.7] 244 assert allclose(histogram(a, bins), [1])244 assert numpy.allclose(histogram(a, bins), [1]) 245 245 246 246 … … 281 281 from util_ext import gradient as gradient_c 282 282 283 from RandomArrayimport uniform, seed284 seed( 17, 53)283 from numpy.random import uniform, seed 284 seed(53) # numeric was seed(17, 53) 285 285 286 286 x0, x1, x2, y0, y1, y2 = uniform(0.0,3.0,6) … … 312 312 # sqrt(sum_over_x&y((xi - yi)^2)) 313 313 err__1 = err(x,y,2,False) 314 314 315 assert err__1 == sqrt(20) 315 316 #print "err_", err_ -
anuga_core/source/anuga/utilities/test_polygon.py
r5403 r5891 3 3 4 4 import unittest 5 from Numeric import zeros, array, allclose 5 import numpy 6 6 from math import sqrt, pi 7 7 from anuga.utilities.numerical_tools import ensure_numeric … … 43 43 p2 = [[0,0], [10,10], [15,5], [20, 10], [25,0], [30,10], [40,-10]] 44 44 45 f = Polygon_function( [(p1, 1.0)] )45 f = Polygon_function( [(p1, 1.0)], verbose=False ) 46 46 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]) 48 48 49 49 50 50 f = Polygon_function( [(p2, 2.0)] ) 51 51 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]) 53 53 54 54 … … 56 56 f = Polygon_function( [(p1, 1.0), (p2, 2.0)] ) 57 57 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) 59 66 60 67 def test_polygon_function_csvfile(self): … … 72 79 z = f([430000,480000], [490000,7720000]) # first outside, second inside 73 80 74 assert allclose(z, [0,10])81 assert numpy.allclose(z, [0,10]) 75 82 76 83 def test_polygon_function_georef(self): … … 90 97 z = f([5, 5, 27, 35], [5, 9, 8, -5]) #Two first inside p1 91 98 92 assert allclose(z, [1,1,0,0])99 assert numpy.allclose(z, [1,1,0,0]) 93 100 94 101 95 102 f = Polygon_function( [(p2, 2.0)], geo_reference=geo) 96 103 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]) 98 105 99 106 … … 101 108 f = Polygon_function( [(p1, 1.0), (p2, 2.0)], geo_reference=geo) 102 109 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]) 104 111 105 112 … … 107 114 f = Polygon_function( [(p1, 1.0), (p2, 2.0)]) 108 115 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]) 110 117 111 118 … … 120 127 f = Polygon_function( [(p1, test_function)] ) 121 128 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]) 123 130 124 131 # Combined 125 132 f = Polygon_function( [(p1, test_function), (p2, 2.0)] ) 126 133 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]) 128 135 129 136 … … 131 138 f = Polygon_function( [(p1, test_function), (p2, 2.0)], default = 3.14) 132 139 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]) 134 141 135 142 … … 138 145 default = test_function) 139 146 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]) 141 148 142 149 … … 210 217 res = inside_polygon(points, polygon) 211 218 assert len(res) == 2 212 assert allclose(res, [0,1])219 assert numpy.allclose(res, [0,1]) ## alltrue? 213 220 214 221 … … 305 312 res = inside_polygon( points, polygon, verbose=False ) 306 313 307 assert allclose( res, [0,1,2] )314 assert numpy.allclose( res, [0,1,2] ) 308 315 309 316 def test_outside_polygon(self): … … 317 324 318 325 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] ) 320 327 321 328 # One more test of vector formulation returning indices … … 324 331 res = outside_polygon( points, polygon ) 325 332 326 assert allclose( res, [3, 4] )333 assert numpy.allclose( res, [3, 4] ) 327 334 328 335 … … 332 339 res = outside_polygon( points, polygon ) 333 340 334 assert allclose( res, [0, 4, 5] )341 assert numpy.allclose( res, [0, 4, 5] ) 335 342 336 343 def test_outside_polygon2(self): … … 355 362 #print indices, count 356 363 assert count == 0 #None inside 357 assert allclose(indices, [3,2,1,0])364 assert numpy.allclose(indices, [3,2,1,0]) 358 365 359 366 indices = outside_polygon(points, U, closed = True) 360 assert allclose(indices, [0,1,2,3])367 assert numpy.allclose(indices, [0,1,2,3]) 361 368 362 369 indices = inside_polygon(points, U, closed = True) 363 assert allclose(indices, [])370 assert numpy.allclose(indices, []) 364 371 365 372 … … 375 382 indices, count = separate_points_by_polygon(points, U) 376 383 assert count == 3 #All inside 377 assert allclose(indices, [0,1,2])384 assert numpy.allclose(indices, [0,1,2]) 378 385 379 386 indices = outside_polygon(points, U, closed = True) 380 assert allclose(indices, [])387 assert numpy.allclose(indices, []) 381 388 382 389 indices = inside_polygon(points, U, closed = True) 383 assert allclose(indices, [0,1,2])390 assert numpy.allclose(indices, [0,1,2]) 384 391 385 392 … … 388 395 389 396 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] ) 391 398 assert count == 2 392 399 … … 396 403 res, count = separate_points_by_polygon( points, polygon ) 397 404 398 assert allclose( res, [0,1,2,4,3] )405 assert numpy.allclose( res, [0,1,2,4,3] ) 399 406 assert count == 3 400 407 … … 404 411 res, count = separate_points_by_polygon( points, polygon ) 405 412 406 assert allclose( res, [1,2,3,5,4,0] )413 assert numpy.allclose( res, [1,2,3,5,4,0] ) 407 414 assert count == 3 408 415 … … 588 595 status, value = intersection(line0, line1) 589 596 assert status == 1 590 assert allclose(value, [0.0, 0.0])597 assert numpy.allclose(value, [0.0, 0.0]) 591 598 592 599 def test_intersection2(self): … … 596 603 status, value = intersection(line0, line1) 597 604 assert status == 1 598 assert allclose(value, [12.0, 6.0])605 assert numpy.allclose(value, [12.0, 6.0]) 599 606 600 607 # Swap direction of one line … … 603 610 status, value = intersection(line0, line1) 604 611 assert status == 1 605 assert allclose(value, [12.0, 6.0])612 assert numpy.allclose(value, [12.0, 6.0]) 606 613 607 614 # Swap order of lines 608 615 status, value = intersection(line1, line0) 609 616 assert status == 1 610 assert allclose(value, [12.0, 6.0])617 assert numpy.allclose(value, [12.0, 6.0]) 611 618 612 619 def test_intersection3(self): … … 616 623 status, value = intersection(line0, line1) 617 624 assert status == 1 618 assert allclose(value, [14.068965517, 7.0344827586])625 assert numpy.allclose(value, [14.068965517, 7.0344827586]) 619 626 620 627 # Swap direction of one line … … 623 630 status, value = intersection(line0, line1) 624 631 assert status == 1 625 assert allclose(value, [14.068965517, 7.0344827586])632 assert numpy.allclose(value, [14.068965517, 7.0344827586]) 626 633 627 634 # Swap order of lines 628 635 status, value = intersection(line1, line0) 629 636 assert status == 1 630 assert allclose(value, [14.068965517, 7.0344827586])637 assert numpy.allclose(value, [14.068965517, 7.0344827586]) 631 638 632 639 … … 641 648 status, value = intersection(line0, line1) 642 649 assert status == 1 643 assert allclose(value, [1.0, 1.0])650 assert numpy.allclose(value, [1.0, 1.0]) 644 651 645 652 … … 649 656 status, value = intersection(line0, line1) 650 657 assert status == 1 651 assert allclose(value, [1.0, 1.0])658 assert numpy.allclose(value, [1.0, 1.0]) 652 659 653 660 … … 679 686 common_end_point[1]) 680 687 msg += ' gave %s, \nbut when reversed we got %s' %(p1, p2) 681 assert allclose(p1, p2), msg688 assert numpy.allclose(p1, p2), msg 682 689 683 690 # Swap order of lines … … 685 692 assert status == 1 686 693 msg = 'Order of lines gave different results' 687 assert allclose(p1, p3), msg694 assert numpy.allclose(p1, p3), msg 688 695 689 696 … … 725 732 status, value = intersection(line0, line1) 726 733 assert status == 2 727 assert allclose(value, [[0,0], [3,0]])734 assert numpy.allclose(value, [[0,0], [3,0]]) 728 735 729 736 # Overlap 2 … … 733 740 status, value = intersection(line0, line1) 734 741 assert status == 2 735 assert allclose(value, [[-3, 0], [5,0]])742 assert numpy.allclose(value, [[-3, 0], [5,0]]) 736 743 737 744 # Inclusion 1 … … 741 748 status, value = intersection(line0, line1) 742 749 assert status == 2 743 assert allclose(value, line1)750 assert numpy.allclose(value, line1) 744 751 745 752 # Inclusion 2 … … 749 756 status, value = intersection(line0, line1) 750 757 assert status == 2 751 assert allclose(value, line0)758 assert numpy.allclose(value, line0) 752 759 753 760 … … 768 775 status, value = intersection(line0, line1) 769 776 assert status == 2 770 assert allclose(value, [[1, 7], [7, 19]])777 assert numpy.allclose(value, [[1, 7], [7, 19]]) 771 778 772 779 status, value = intersection(line1, line0) 773 780 assert status == 2 774 assert allclose(value, [[1, 7], [7, 19]])781 assert numpy.allclose(value, [[1, 7], [7, 19]]) 775 782 776 783 # Swap direction … … 779 786 status, value = intersection(line0, line1) 780 787 assert status == 2 781 assert allclose(value, [[7, 19], [1, 7]])788 assert numpy.allclose(value, [[7, 19], [1, 7]]) 782 789 783 790 line0 = [[0,5], [7,19]] … … 785 792 status, value = intersection(line0, line1) 786 793 assert status == 2 787 assert allclose(value, [[1, 7], [7, 19]])794 assert numpy.allclose(value, [[1, 7], [7, 19]]) 788 795 789 796 … … 793 800 status, value = intersection(line0, line1) 794 801 assert status == 2 795 assert allclose(value, [[1,7], [7, 19]])802 assert numpy.allclose(value, [[1,7], [7, 19]]) 796 803 797 804 line0 = [[0,5], [10,25]] … … 799 806 status, value = intersection(line0, line1) 800 807 assert status == 2 801 assert allclose(value, [[1,7], [7, 19]])808 assert numpy.allclose(value, [[1,7], [7, 19]]) 802 809 803 810 … … 806 813 status, value = intersection(line0, line1) 807 814 assert status == 2 808 assert allclose(value, [[7, 19], [1, 7]])815 assert numpy.allclose(value, [[7, 19], [1, 7]]) 809 816 810 817 … … 843 850 res = inside_polygon(points, polygon) 844 851 assert len(res) == 2 845 assert allclose(res, [0,1])852 assert numpy.allclose(res, [0,1]) 846 853 847 854 def test_polygon_area(self): … … 990 997 if __name__ == "__main__": 991 998 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') 993 1000 runner = unittest.TextTestRunner() 994 1001 runner.run(suite) -
anuga_core/source/anuga/utilities/test_quad.py
r4741 r5891 1 1 import unittest 2 from Numeric import array, allclose 2 ##import numpy 3 3 4 4 from quad import Cell, build_quadtree … … 236 236 [ 0., -1.]] 237 237 238 # assert allclose(array(results),[[[ 2., 1.],238 # assert numpy.allclose(numpy.array(results),[[[ 2., 1.], 239 239 #[ 4., 1.], [ 4., 4.]], [[ 4., 1.],[ 5., 4.],[ 4., 4.]]] ) 240 240 results = Q.search(5,4.) … … 253 253 [ 5., 4.], 254 254 [ 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.]] 256 256 # ,[[ 2., 1.],[ 4., 4.], [ 2., 4.]], 257 257 #[[ 4., 1.], [ 5., 4.], [ 4., 4.]], -
anuga_core/source/anuga/utilities/test_sparse.py
r2527 r5891 5 5 6 6 from sparse import * 7 from Numeric import allclose, array, transpose, Float 7 import numpy 8 8 9 9 class Test_Sparse(unittest.TestCase): … … 43 43 C = Sparse(B) 44 44 45 assert allclose(C.todense(), B)45 assert numpy.allclose(C.todense(), B) 46 46 47 47 … … 50 50 A[1,1] = 4 51 51 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]]) 53 53 54 54 … … 63 63 64 64 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]]) 66 66 67 67 #Set an existing zero element to zero 68 68 A[1,2] = 0 69 69 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]]) 71 71 72 72 def test_sparse_multiplication_vector(self): … … 82 82 83 83 u = A*v 84 assert allclose(u, [6,14,4])84 assert numpy.allclose(u, [6,14,4]) 85 85 86 86 #Right hand side column 87 v = array([[2,4],[3,4],[4,4]])87 v = numpy.array([[2,4],[3,4],[4,4]]) 88 88 89 89 u = A*v[:,0] 90 assert allclose(u, [6,14,4])90 assert numpy.allclose(u, [6,14,4]) 91 91 92 92 u = A*v[:,1] 93 assert allclose(u, [12,16,4])93 assert numpy.allclose(u, [12,16,4]) 94 94 95 95 … … 103 103 104 104 #Right hand side matrix 105 v = array([[2,4],[3,4],[4,4]])105 v = numpy.array([[2,4],[3,4],[4,4]]) 106 106 107 107 u = A*v 108 assert allclose(u, [[6,12], [14,16], [4,4]])108 assert numpy.allclose(u, [[6,12], [14,16], [4,4]]) 109 109 110 110 … … 122 122 123 123 u = A.trans_mult(v) 124 assert allclose(u, [6,6,10])124 assert numpy.allclose(u, [6,6,10]) 125 125 126 126 … … 137 137 138 138 B = 3*A 139 assert allclose(B.todense(), 3*A.todense())139 assert numpy.allclose(B.todense(), 3*A.todense()) 140 140 141 141 B = A*3 142 assert allclose(B.todense(), 3*A.todense())142 assert numpy.allclose(B.todense(), 3*A.todense()) 143 143 144 144 try: … … 166 166 C = A+B 167 167 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]]) 169 169 170 170 def test_sparse_tocsr(self): … … 190 190 C = [1, 2, 3] 191 191 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]) 193 193 194 194 C2 = [[1,2],[2,4],[3,6]] … … 196 196 #print B*C2 197 197 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]]) 199 199 200 200 -
anuga_core/source/anuga/utilities/test_system_tools.py
r5398 r5891 1 1 #!/usr/bin/env python 2 2 3 4 3 import unittest 5 from Numeric import zeros, array, allclose, Float 4 import numpy 6 5 import zlib 7 6 from os.path import join, split, sep … … 81 80 pass 82 81 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]]) 84 83 85 84 # First file … … 87 86 fid = NetCDFFile(filename1, 'w') 88 87 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')) 91 89 fid.variables['test_array'][:] = test_array 92 90 fid.close() … … 96 94 fid = NetCDFFile(filename2, 'w') 97 95 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')) 100 97 fid.variables['test_array'][:] = test_array 101 98 fid.close() -
anuga_core/source/anuga/utilities/test_xml_tools.py
r5022 r5891 3 3 4 4 import unittest 5 from Numeric import zeros, array, allclose, Float6 5 from tempfile import mkstemp, mktemp 7 6 -
anuga_core/source/anuga/utilities/util_ext.c
r3730 r5891 16 16 17 17 #include "Python.h" 18 #include " Numeric/arrayobject.h"18 #include "numpy/arrayobject.h" 19 19 #include "math.h" 20 20 -
anuga_core/source/anuga/utilities/util_ext.h
r5743 r5891 11 11 12 12 #include "Python.h" 13 #include " Numeric/arrayobject.h"13 #include "numpy/arrayobject.h" 14 14 #include "math.h" 15 15
Note: See TracChangeset
for help on using the changeset viewer.