Changeset 2545
- Timestamp:
- Mar 14, 2006, 4:37:49 PM (17 years ago)
- Location:
- inundation-numpy-branch/utilities
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation-numpy-branch/utilities/cg_solve.py
r2503 r2545 28 28 """ 29 29 30 from Numericimport dot, array, Float, zeros30 from numpy import dot, array, Float, zeros 31 31 32 b = array(b, typecode=Float)32 b = array(b, dtype=Float) 33 33 if len(b.shape) != 1 : 34 34 raise VectorShapeError, 'input vector should consist of only one column' 35 35 36 36 if x0 is None: 37 x0 = zeros(b.shape, typecode=Float)37 x0 = zeros(b.shape, dtype=Float) 38 38 else: 39 x0 = array(x0, typecode=Float)39 x0 = array(x0, dtype=Float) 40 40 41 41 -
inundation-numpy-branch/utilities/compile.py
r2528 r2545 172 172 package called something like python2.3-dev""" %headerfile 173 173 174 175 # Add location of arrayobject.h 176 177 arraypath = 'Lib' + os.sep + 'site-packages' + os.sep + 'numpy' + os.sep + 'core' + os.sep + 'include' + os.sep + 'numpy' 178 if sys.platform == 'win32': #Windows 179 array_include = os.path.join(sys.exec_prefix, arraypath) 180 else: 181 #FIXME: Not done yet 182 python_include = os.path.join(os.path.join(sys.exec_prefix, 'include'), 183 'python' + version) 184 185 # Check existence of arrayobject.h 186 # 187 array_headerfile = array_include + os.sep + 'arrayobject.h' 188 try: 189 open(array_headerfile, 'r') 190 except: 191 raise """Did not find Numpy header file %s. Make sure files for Python C-extensions are installed. """ %array_headerfile 192 174 193 175 194 … … 221 240 %(compiler, FN, python_include, root) 222 241 else: 223 s = '%s -c %s -I%s -I%s - o %s.o -Wall -O3'\224 %(compiler, FN, python_include, utilities_include_dir, root)242 s = '%s -c %s -I%s -I%s -I%s -o %s.o -Wall -O3'\ 243 %(compiler, FN, python_include, utilities_include_dir, array_include, root) 225 244 226 245 if os.name == 'posix' and os.uname()[4] == 'x86_64': -
inundation-numpy-branch/utilities/numerical_tools.py
r2533 r2545 8 8 #(this should move to somewhere central) 9 9 try: 10 from scipy import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate10 from numpy import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate 11 11 except: 12 print 'Could not find scipy - using Numeric'12 print 'Could not find numpy - using Numeric' 13 13 from Numeric import ArrayType, array, sum, innerproduct, ravel, sqrt, searchsorted, sort, concatenate 14 14 … … 181 181 else: 182 182 if type(A) == ArrayType: 183 if A. typecode== typecode:183 if A.dtype.char == typecode: 184 184 return array(A) #FIXME: Shouldn't this just return A? 185 185 else: … … 242 242 #Initialise module 243 243 244 from utilities import compile 244 #from utilities import compile 245 import compile 245 246 if compile.can_use_C_extension('util_ext.c'): 246 247 from util_ext import gradient, gradient2 -
inundation-numpy-branch/utilities/polygon_ext.c
r2510 r2545 15 15 16 16 #include "Python.h" 17 #include "Numeric/arrayobject.h"17 #include <arrayobject.h> 18 18 #include "math.h" 19 19 -
inundation-numpy-branch/utilities/sparse.py
r2503 r2545 20 20 21 21 if len(args) == 1: 22 from Numericimport array22 from numpy import array 23 23 try: 24 24 A = array(args[0]) 25 25 except: 26 raise 'Input must be convertable to a Numericarray'26 raise 'Input must be convertable to a numpy array' 27 27 28 28 assert len(A.shape) == 2, 'Input must be a 2d matrix' … … 93 93 94 94 def todense(self): 95 from Numericimport zeros, Float95 from numpy import zeros, Float 96 96 97 97 D = zeros( (self.M, self.N), Float) … … 107 107 def __mul__(self, other): 108 108 """Multiply this matrix onto 'other' which can either be 109 a Numeric vector, a Numericmatrix or another sparse matrix.110 """ 111 112 from Numericimport array, zeros, Float109 a numpy vector, a numpy matrix or another sparse matrix. 110 """ 111 112 from numpy import array, zeros, Float 113 113 114 114 try: 115 115 B = array(other) 116 116 except: 117 msg = 'FIXME: Only Numerictypes implemented so far'117 msg = 'FIXME: Only numpy types implemented so far' 118 118 raise msg 119 119 … … 161 161 """ 162 162 163 from Numericimport array, zeros, Float163 from numpy import array, zeros, Float 164 164 165 165 new = other.copy() … … 176 176 """ 177 177 178 from Numericimport array, zeros, Float178 from numpy import array, zeros, Float 179 179 180 180 try: … … 196 196 def trans_mult(self, other): 197 197 """Multiply the transpose of matrix with 'other' which can be 198 a Numericvector.199 """ 200 201 from Numericimport array, zeros, Float198 a numpy vector. 199 """ 200 201 from numpy import array, zeros, Float 202 202 203 203 try: 204 204 B = array(other) 205 205 except: 206 print 'FIXME: Only Numerictypes implemented so far'206 print 'FIXME: Only numpy types implemented so far' 207 207 208 208 … … 250 250 """ 251 251 252 from Numericimport array, Float, Int252 from numpy import array, Float, Int 253 253 254 254 if isinstance(A,Sparse): 255 255 256 from Numericimport zeros256 from numpy import zeros 257 257 keys = A.Data.keys() 258 258 keys.sort() … … 298 298 299 299 def todense(self): 300 from Numericimport zeros, Float300 from numpy import zeros, Float 301 301 302 302 D = zeros( (self.M, self.N), Float) … … 310 310 def __mul__(self, other): 311 311 """Multiply this matrix onto 'other' which can either be 312 a Numeric vector, a Numericmatrix or another sparse matrix.313 """ 314 315 from Numericimport array, zeros, Float312 a numpy vector, a numpy matrix or another sparse matrix. 313 """ 314 315 from numpy import array, zeros, Float 316 316 317 317 try: 318 318 B = array(other) 319 319 except: 320 print 'FIXME: Only Numerictypes implemented so far'320 print 'FIXME: Only numpy types implemented so far' 321 321 322 322 return csr_mv(self,B) … … 328 328 """ 329 329 330 from Numericimport zeros, Float330 from numpy import zeros, Float 331 331 332 332 … … 370 370 371 371 #Setup for C extensions 372 from utilitiesimport compile372 import compile 373 373 if compile.can_use_C_extension('sparse_ext.c'): 374 374 #Replace python version with c implementation … … 377 377 if __name__ == '__main__': 378 378 379 from Numericimport allclose, array, Float379 from numpy import allclose, array, Float 380 380 381 381 A = Sparse(3,3) -
inundation-numpy-branch/utilities/sparse_ext.c
r2503 r2545 11 11 12 12 #include "Python.h" 13 #include " Numeric/arrayobject.h"13 #include "arrayobject.h" 14 14 #include "math.h" 15 15 #include "stdio.h" -
inundation-numpy-branch/utilities/test_cg_solve.py
r2527 r2545 4 4 5 5 6 from Numericimport dot, allclose, array, transpose, arange, ones, Float6 from numpy import dot, allclose, array, transpose, arange, ones, Float 7 7 from cg_solve import * 8 8 from sparse import Sparse, Sparse_CSR -
inundation-numpy-branch/utilities/test_numerical_tools.py
r2534 r2545 3 3 4 4 import unittest 5 from Numericimport zeros, array, allclose5 from numpy import zeros, array, allclose 6 6 from math import sqrt, pi 7 7 from pyvolution.config import epsilon … … 32 32 def test_ensure_numeric(self): 33 33 from numerical_tools import ensure_numeric 34 from Numericimport ArrayType, Float, array34 from numpy import ArrayType, Float, array 35 35 36 36 A = [1,2,3,4] 37 37 B = ensure_numeric(A) 38 38 assert type(B) == ArrayType 39 assert B. typecode()== 'l'39 assert B.dtype.char == 'l' 40 40 assert B[0] == 1 and B[1] == 2 and B[2] == 3 and B[3] == 4 41 41 … … 44 44 B = ensure_numeric(A) 45 45 assert type(B) == ArrayType 46 assert B. typecode()== 'd'46 assert B.dtype.char == 'd' 47 47 assert B[0] == 1 and B[1] == 2 and B[2] == 3.14 and B[3] == 4 48 48 … … 51 51 B = ensure_numeric(A, Float) 52 52 assert type(B) == ArrayType 53 assert B. typecode()== 'd'53 assert B.dtype.char == 'd' 54 54 assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0 55 55 … … 58 58 B = ensure_numeric(A, Float) 59 59 assert type(B) == ArrayType 60 assert B. typecode()== 'd'60 assert B.dtype.char == 'd' 61 61 assert B[0] == 1.0 and B[1] == 2.0 and B[2] == 3.0 and B[3] == 4.0 62 62 … … 65 65 B = ensure_numeric(A) 66 66 assert type(B) == ArrayType 67 assert B. typecode() == 'l'68 assert A == B67 assert B.dtype.char == 'l' 68 assert (A == B).all() 69 69 assert A is B #Same object 70 70 … … 73 73 B = ensure_numeric(A, Float) 74 74 assert type(B) == ArrayType 75 assert B. typecode()== 'd'76 assert A == B75 assert B.dtype.char == 'd' 76 assert (A == B).all() 77 77 assert A is not B #Not the same object 78 78 … … 165 165 166 166 167 bins = [1.1,2,3.1,4] 168 #print histogram(a, bins) 169 assert allclose(histogram(a, bins), [0,6,0,1]) 170 171 172 bins = [0,1.5,2,3] 167 bins = [0.5,1.5,2,3] 173 168 assert allclose(histogram(a, bins), [8,0,3,4]) 174 175 176 assert allclose(histogram(a, [0,3]), histogram(a, [-0.5,3]))177 169 178 170 … … 215 207 from util_ext import gradient as gradient_c 216 208 217 from RandomArray import uniform, seed 218 seed(17, 53) 209 from numpy.random import uniform, seed 210 #seed(17, 53) 211 seed(17) 219 212 220 213 x0, x1, x2, y0, y1, y2 = uniform(0.0,3.0,6) -
inundation-numpy-branch/utilities/test_sparse.py
r2527 r2545 5 5 6 6 from sparse import * 7 from Numericimport allclose, array, transpose, Float7 from numpy import allclose, array, transpose, Float 8 8 9 9 class Test_Sparse(unittest.TestCase): -
inundation-numpy-branch/utilities/util_ext.c
r2510 r2545 15 15 16 16 #include "Python.h" 17 #include " Numeric/arrayobject.h"17 #include "arrayobject.h" 18 18 #include "math.h" 19 19 20 20 //Shared snippets 21 21 #include "util_ext.h" 22 23 22 24 23 -
inundation-numpy-branch/utilities/util_ext.h
r2508 r2545 11 11 12 12 #include "Python.h" 13 #include " Numeric/arrayobject.h"13 #include "arrayobject.h" 14 14 #include "math.h" 15 15
Note: See TracChangeset
for help on using the changeset viewer.