[Numpy-svn] r4654 - in trunk/numpy: core/tests doc/swig/test f2py fft/tests numarray
numpy-svn at scipy.org
numpy-svn at scipy.org
Fri Dec 28 20:32:42 EST 2007
Author: jarrod.millman
Date: 2007-12-28 19:32:27 -0600 (Fri, 28 Dec 2007)
New Revision: 4654
Modified:
trunk/numpy/core/tests/test_multiarray.py
trunk/numpy/core/tests/test_regression.py
trunk/numpy/doc/swig/test/testArray.py
trunk/numpy/f2py/f90mod_rules.py
trunk/numpy/fft/tests/test_fftpack.py
trunk/numpy/numarray/functions.py
Log:
janitorial work
Modified: trunk/numpy/core/tests/test_multiarray.py
===================================================================
--- trunk/numpy/core/tests/test_multiarray.py 2007-12-29 00:30:47 UTC (rev 4653)
+++ trunk/numpy/core/tests/test_multiarray.py 2007-12-29 01:32:27 UTC (rev 4654)
@@ -1,10 +1,9 @@
+import tempfile
+
+import numpy as np
from numpy.testing import *
from numpy.core import *
-from numpy import random
-import numpy as N
-import tempfile
-
class TestFlags(NumpyTestCase):
def setUp(self):
self.a = arange(10)
@@ -357,7 +356,7 @@
class TestArgmax(NumpyTestCase):
def check_all(self):
- a = random.normal(0,1,(4,5,6,7,8))
+ a = np.random.normal(0,1,(4,5,6,7,8))
for i in xrange(a.ndim):
amax = a.max(i)
aargmax = a.argmax(i)
@@ -373,8 +372,8 @@
class TestClip(NumpyTestCase):
def _check_range(self,x,cmin,cmax):
- assert N.all(x >= cmin)
- assert N.all(x <= cmax)
+ assert np.all(x >= cmin)
+ assert np.all(x <= cmax)
def _clip_type(self,type_group,array_max,
clip_min,clip_max,inplace=False,
@@ -384,16 +383,16 @@
if expected_max is None:
expected_max = clip_max
- for T in N.sctypes[type_group]:
+ for T in np.sctypes[type_group]:
if sys.byteorder == 'little':
byte_orders = ['=','>']
else:
byte_orders = ['<','=']
for byteorder in byte_orders:
- dtype = N.dtype(T).newbyteorder(byteorder)
+ dtype = np.dtype(T).newbyteorder(byteorder)
- x = (N.random.random(1000) * array_max).astype(dtype)
+ x = (np.random.random(1000) * array_max).astype(dtype)
if inplace:
x.clip(clip_min,clip_max,x)
else:
@@ -417,46 +416,46 @@
x = self._clip_type('uint',1024,0,0, inplace=inplace)
def check_record_array(self):
- rec = N.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)],
+ rec = np.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)],
dtype=[('x', '<f8'), ('y', '<f8'), ('z', '<f8')])
y = rec['x'].clip(-0.3,0.5)
self._check_range(y,-0.3,0.5)
def check_max_or_min(self):
- val = N.array([0,1,2,3,4,5,6,7])
+ val = np.array([0,1,2,3,4,5,6,7])
x = val.clip(3)
- assert N.all(x >= 3)
+ assert np.all(x >= 3)
x = val.clip(min=3)
- assert N.all(x >= 3)
+ assert np.all(x >= 3)
x = val.clip(max=4)
- assert N.all(x <= 4)
+ assert np.all(x <= 4)
class TestPutmask(ParametricTestCase):
def tst_basic(self,x,T,mask,val):
- N.putmask(x,mask,val)
- assert N.all(x[mask] == T(val))
+ np.putmask(x,mask,val)
+ assert np.all(x[mask] == T(val))
assert x.dtype == T
def testip_types(self):
- unchecked_types = [str,unicode,N.void,object]
+ unchecked_types = [str, unicode, np.void, object]
- x = N.random.random(1000)*100
+ x = np.random.random(1000)*100
mask = x < 40
tests = []
for val in [-100,0,15]:
- for types in N.sctypes.itervalues():
+ for types in np.sctypes.itervalues():
tests.extend([(self.tst_basic,x.copy().astype(T),T,mask,val)
for T in types if T not in unchecked_types])
return tests
def test_mask_size(self):
- self.failUnlessRaises(ValueError,N.putmask,
- N.array([1,2,3]),[True],5)
+ self.failUnlessRaises(ValueError, np.putmask,
+ np.array([1,2,3]), [True], 5)
def tst_byteorder(self,dtype):
- x = N.array([1,2,3],dtype)
- N.putmask(x,[True,False,True],-1)
+ x = np.array([1,2,3],dtype)
+ np.putmask(x,[True,False,True],-1)
assert_array_equal(x,[-1,2,-1])
def testip_byteorder(self):
@@ -464,46 +463,46 @@
def test_record_array(self):
# Note mixed byteorder.
- rec = N.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)],
+ rec = np.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)],
dtype=[('x', '<f8'), ('y', '>f8'), ('z', '<f8')])
- N.putmask(rec['x'],[True,False],10)
+ np.putmask(rec['x'],[True,False],10)
assert_array_equal(rec['x'],[10,5])
- N.putmask(rec['y'],[True,False],10)
+ np.putmask(rec['y'],[True,False],10)
assert_array_equal(rec['y'],[10,4])
def test_masked_array(self):
- ## x = N.array([1,2,3])
- ## z = N.ma.array(x,mask=[True,False,False])
- ## N.putmask(z,[True,True,True],3)
+ ## x = np.array([1,2,3])
+ ## z = np.ma.array(x,mask=[True,False,False])
+ ## np.putmask(z,[True,True,True],3)
pass
class TestLexsort(NumpyTestCase):
def test_basic(self):
a = [1,2,1,3,1,5]
b = [0,4,5,6,2,3]
- idx = N.lexsort((b,a))
- expected_idx = N.array([0,4,2,1,3,5])
+ idx = np.lexsort((b,a))
+ expected_idx = np.array([0,4,2,1,3,5])
assert_array_equal(idx,expected_idx)
- x = N.vstack((b,a))
- idx = N.lexsort(x)
+ x = np.vstack((b,a))
+ idx = np.lexsort(x)
assert_array_equal(idx,expected_idx)
- assert_array_equal(x[1][idx],N.sort(x[1]))
+ assert_array_equal(x[1][idx],np.sort(x[1]))
class TestFromToFile(NumpyTestCase):
def setUp(self):
shape = (4,7)
- rand = N.random.random
+ rand = np.random.random
- self.x = rand(shape) + rand(shape).astype(N.complex)*1j
- self.dtype = N.complex
+ self.x = rand(shape) + rand(shape).astype(np.complex)*1j
+ self.dtype = np.complex
def test_file(self):
f = tempfile.TemporaryFile()
self.x.tofile(f)
f.seek(0)
- y = N.fromfile(f,dtype=self.dtype)
+ y = np.fromfile(f,dtype=self.dtype)
assert_array_equal(y,self.x.flat)
def test_filename(self):
@@ -511,7 +510,7 @@
f = open(filename,'wb')
self.x.tofile(f)
f.close()
- y = N.fromfile(filename,dtype=self.dtype)
+ y = np.fromfile(filename,dtype=self.dtype)
assert_array_equal(y,self.x.flat)
class TestFromBuffer(ParametricTestCase):
@@ -522,21 +521,21 @@
tests = []
for byteorder in ['<','>']:
for dtype in [float,int,N.complex]:
- dt = N.dtype(dtype).newbyteorder(byteorder)
- x = (N.random.random((4,7))*5).astype(dt)
+ dt = np.dtype(dtype).newbyteorder(byteorder)
+ x = (np.random.random((4,7))*5).astype(dt)
buf = x.tostring()
tests.append((self.tst_basic,buf,x.flat,{'dtype':dt}))
return tests
class TestResize(NumpyTestCase):
def test_basic(self):
- x = N.eye(3)
+ x = np.eye(3)
x.resize((5,5))
assert_array_equal(x.flat[:9],N.eye(3).flat)
assert_array_equal(x[9:].flat,0)
def test_check_reference(self):
- x = N.eye(3)
+ x = np.eye(3)
y = x
self.failUnlessRaises(ValueError,x.resize,(5,1))
Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py 2007-12-29 00:30:47 UTC (rev 4653)
+++ trunk/numpy/core/tests/test_regression.py 2007-12-29 01:32:27 UTC (rev 4654)
@@ -4,7 +4,7 @@
import sys
set_local_path()
-import numpy as N
+import numpy as np
restore_path()
rlevel = 1
@@ -30,11 +30,11 @@
def check_mem_empty(self,level=rlevel):
"""Ticket #7"""
- N.empty((1,),dtype=[('x',N.int64)])
+ np.empty((1,),dtype=[('x',N.int64)])
def check_pickle_transposed(self,level=rlevel):
"""Ticket #16"""
- a = N.transpose(N.array([[2,9],[7,0],[3,8]]))
+ a = np.transpose(N.array([[2,9],[7,0],[3,8]]))
f = StringIO()
pickle.dump(a,f)
f.seek(0)
@@ -44,45 +44,46 @@
def check_masked_array_create(self,level=rlevel):
"""Ticket #17"""
- x = N.ma.masked_array([0,1,2,3,0,4,5,6],mask=[0,0,0,1,1,1,0,0])
+ x = np.ma.masked_array([0,1,2,3,0,4,5,6],mask=[0,0,0,1,1,1,0,0])
+from data_store import load, save, create_module, create_shelf
assert_array_equal(N.ma.nonzero(x),[[1,2,6,7]])
def check_poly1d(self,level=rlevel):
"""Ticket #28"""
- assert_equal(N.poly1d([1]) - N.poly1d([1,0]),
- N.poly1d([-1,1]))
+ assert_equal(np.poly1d([1]) - np.poly1d([1,0]),
+ np.poly1d([-1,1]))
def check_typeNA(self,level=rlevel):
"""Ticket #31"""
- assert_equal(N.typeNA[N.int64],'Int64')
- assert_equal(N.typeNA[N.uint64],'UInt64')
+ assert_equal(np.typeNA[np.int64],'Int64')
+ assert_equal(np.typeNA[np.uint64],'UInt64')
def check_dtype_names(self,level=rlevel):
"""Ticket #35"""
- dt = N.dtype([(('name','label'),N.int32,3)])
+ dt = np.dtype([(('name','label'),np.int32,3)])
def check_reduce(self,level=rlevel):
"""Ticket #40"""
- assert_almost_equal(N.add.reduce([1.,.5],dtype=None), 1.5)
+ assert_almost_equal(np.add.reduce([1.,.5],dtype=None), 1.5)
def check_zeros_order(self,level=rlevel):
"""Ticket #43"""
- N.zeros([3], int, 'C')
- N.zeros([3], order='C')
- N.zeros([3], int, order='C')
+ np.zeros([3], int, 'C')
+ np.zeros([3], order='C')
+ np.zeros([3], int, order='C')
def check_sort_bigendian(self,level=rlevel):
"""Ticket #47"""
- a = N.linspace(0, 10, 11)
+ a = np.linspace(0, 10, 11)
c = a.astype(N.dtype('<f8'))
c.sort()
assert_array_almost_equal(c, a)
def check_negative_nd_indexing(self,level=rlevel):
"""Ticket #49"""
- c = N.arange(125).reshape((5,5,5))
- origidx = N.array([-1, 0, 1])
- idx = N.array(origidx)
+ c = np.arange(125).reshape((5,5,5))
+ origidx = np.array([-1, 0, 1])
+ idx = np.array(origidx)
c[idx]
assert_array_equal(idx, origidx)
@@ -90,15 +91,15 @@
"""Ticket #50"""
import tempfile
f = StringIO()
- ca = N.char.array(N.arange(1000,1010),itemsize=4)
+ ca = np.char.array(N.arange(1000,1010),itemsize=4)
ca.dump(f)
f.seek(0)
- ca = N.load(f)
+ ca = np.load(f)
f.close()
def check_noncontiguous_fill(self,level=rlevel):
"""Ticket #58."""
- a = N.zeros((5,3))
+ a = np.zeros((5,3))
b = a[:,:2,]
def rs():
b.shape = (10,)
@@ -106,17 +107,17 @@
def check_bool(self,level=rlevel):
"""Ticket #60"""
- x = N.bool_(1)
+ x = np.bool_(1)
def check_masked_array(self,level=rlevel):
"""Ticket #61"""
- x = N.core.ma.array(1,mask=[1])
+ x = np.core.ma.array(1,mask=[1])
def check_mem_masked_where(self,level=rlevel):
"""Ticket #62"""
from numpy.core.ma import masked_where, MaskType
- a = N.zeros((1,1))
- b = N.zeros(a.shape, MaskType)
+ a = np.zeros((1,1))
+ b = np.zeros(a.shape, MaskType)
c = masked_where(b,a)
a-c
@@ -124,33 +125,33 @@
"""Ticket #64"""
descr = [('x', [('y', [('z', 'c16', (2,)),]),]),]
buffer = ((([6j,4j],),),)
- h = N.array(buffer, dtype=descr)
+ h = np.array(buffer, dtype=descr)
h['x']['y']['z']
def check_indexing2(self,level=rlevel):
"""Ticket #65"""
descr = [('x', 'i4', (2,))]
buffer = ([3,2],)
- h = N.array(buffer, dtype=descr)
+ h = np.array(buffer, dtype=descr)
h['x']
def check_round(self,level=rlevel):
"""Ticket #67"""
- x = N.array([1+2j])
+ x = np.array([1+2j])
assert_almost_equal(x**(-1), [1/(1+2j)])
def check_kron_matrix(self,level=rlevel):
"""Ticket #71"""
- x = N.matrix('[1 0; 1 0]')
+ x = np.matrix('[1 0; 1 0]')
assert_equal(type(N.kron(x,x)),type(x))
def check_scalar_compare(self,level=rlevel):
"""Ticket #72"""
- a = N.array(['test', 'auto'])
- assert_array_equal(a == 'auto', N.array([False,True]))
+ a = np.array(['test', 'auto'])
+ assert_array_equal(a == 'auto', np.array([False,True]))
self.assert_(a[1] == 'auto')
self.assert_(a[0] != 'auto')
- b = N.linspace(0, 10, 11)
+ b = np.linspace(0, 10, 11)
self.assert_(b != 'auto')
self.assert_(b[0] != 'auto')
@@ -158,26 +159,26 @@
"""Ticket #79"""
ulen = 1
ucs_value = u'\U0010FFFF'
- ua = N.array([[[ucs_value*ulen]*2]*3]*4, dtype='U%s' % ulen)
+ ua = np.array([[[ucs_value*ulen]*2]*3]*4, dtype='U%s' % ulen)
ua2 = ua.newbyteorder()
def check_matrix_std_argmax(self,level=rlevel):
"""Ticket #83"""
- x = N.asmatrix(N.random.uniform(0,1,(3,3)))
+ x = np.asmatrix(N.random.uniform(0,1,(3,3)))
self.assertEqual(x.std().shape, ())
self.assertEqual(x.argmax().shape, ())
def check_object_array_fill(self,level=rlevel):
"""Ticket #86"""
- x = N.zeros(1, 'O')
+ x = np.zeros(1, 'O')
x.fill([])
def check_cov_parameters(self,level=rlevel):
"""Ticket #91"""
- x = N.random.random((3,3))
+ x = np.random.random((3,3))
y = x.copy()
- N.cov(x,rowvar=1)
- N.cov(y,rowvar=0)
+ np.cov(x,rowvar=1)
+ np.cov(y,rowvar=0)
assert_array_equal(x,y)
def check_mem_dtype_align(self,level=rlevel):
@@ -188,13 +189,13 @@
def check_mem_digitize(self,level=rlevel):
"""Ticket #95"""
for i in range(100):
- N.digitize([1,2,3,4],[1,3])
- N.digitize([0,1,2,3,4],[1,3])
+ np.digitize([1,2,3,4],[1,3])
+ np.digitize([0,1,2,3,4],[1,3])
def check_intp(self,level=rlevel):
"""Ticket #99"""
- i_width = N.int_(0).nbytes*2 - 1
- N.intp('0x' + 'f'*i_width,16)
+ i_width = np.int_(0).nbytes*2 - 1
+ np.intp('0x' + 'f'*i_width,16)
self.failUnlessRaises(OverflowError,N.intp,'0x' + 'f'*(i_width+1),16)
self.failUnlessRaises(ValueError,N.intp,'0x1',32)
assert_equal(255,N.intp('0xFF',16))
@@ -202,10 +203,10 @@
def check_endian_bool_indexing(self,level=rlevel):
"""Ticket #105"""
- a = N.arange(10.,dtype='>f8')
- b = N.arange(10.,dtype='<f8')
- xa = N.where((a>2) & (a<6))
- xb = N.where((b>2) & (b<6))
+ a = np.arange(10.,dtype='>f8')
+ b = np.arange(10.,dtype='<f8')
+ xa = np.where((a>2) & (a<6))
+ xb = np.where((b>2) & (b<6))
ya = ((a>2) & (a<6))
yb = ((b>2) & (b<6))
assert_array_almost_equal(xa,ya.nonzero())
@@ -215,35 +216,35 @@
def check_mem_dot(self,level=rlevel):
"""Ticket #106"""
- x = N.random.randn(0,1)
- y = N.random.randn(10,1)
- z = N.dot(x, N.transpose(y))
+ x = np.random.randn(0,1)
+ y = np.random.randn(10,1)
+ z = np.dot(x, np.transpose(y))
def check_arange_endian(self,level=rlevel):
"""Ticket #111"""
- ref = N.arange(10)
- x = N.arange(10,dtype='<f8')
+ ref = np.arange(10)
+ x = np.arange(10,dtype='<f8')
assert_array_equal(ref,x)
- x = N.arange(10,dtype='>f8')
+ x = np.arange(10,dtype='>f8')
assert_array_equal(ref,x)
# Longfloat support is not consistent enough across
# platforms for this test to be meaningful.
# def check_longfloat_repr(self,level=rlevel):
# """Ticket #112"""
-# if N.longfloat(0).itemsize > 8:
-# a = N.exp(N.array([1000],dtype=N.longfloat))
+# if np.longfloat(0).itemsize > 8:
+# a = np.exp(N.array([1000],dtype=N.longfloat))
# assert(str(a)[1:9] == str(a[0])[:8])
def check_argmax(self,level=rlevel):
"""Ticket #119"""
- a = N.random.normal(0,1,(4,5,6,7,8))
+ a = np.random.normal(0,1,(4,5,6,7,8))
for i in xrange(a.ndim):
aargmax = a.argmax(i)
def check_matrix_properties(self,level=rlevel):
"""Ticket #125"""
- a = N.matrix([1.0],dtype=float)
+ a = np.matrix([1.0],dtype=float)
assert(type(a.real) is N.matrix)
assert(type(a.imag) is N.matrix)
c,d = N.matrix([0.0]).nonzero()
Modified: trunk/numpy/doc/swig/test/testArray.py
===================================================================
--- trunk/numpy/doc/swig/test/testArray.py 2007-12-29 00:30:47 UTC (rev 4653)
+++ trunk/numpy/doc/swig/test/testArray.py 2007-12-29 01:32:27 UTC (rev 4654)
@@ -7,10 +7,12 @@
import unittest
# Import NumPy
-import numpy as N
-major, minor = [ int(d) for d in N.__version__.split(".")[:2] ]
-if major == 0: BadListError = TypeError
-else: BadListError = ValueError
+import numpy as np
+major, minor = [ int(d) for d in np.__version__.split(".")[:2] ]
+if major == 0:
+ BadListError = TypeError
+else:
+ BadListError = ValueError
# Add the distutils-generated build directory to the python search path and then
# import the extension module
@@ -38,7 +40,7 @@
def testConstructor2(self):
"Test Array1 array constructor"
- na = N.arange(self.length)
+ na = np.arange(self.length)
aa = Array.Array1(na)
self.failUnless(isinstance(aa, Array.Array1))
@@ -68,7 +70,7 @@
def testResize1(self):
"Test Array1 resize method, array"
- a = N.zeros((2*self.length,), dtype='l')
+ a = np.zeros((2*self.length,), dtype='l')
self.array1.resize(a)
self.failUnless(len(self.array1) == len(a))
@@ -114,7 +116,7 @@
"Test Array1 view method"
for i in range(self.array1.length()): self.array1[i] = i+1
a = self.array1.view()
- self.failUnless(isinstance(a, N.ndarray))
+ self.failUnless(isinstance(a, np.ndarray))
self.failUnless(len(a) == self.length)
self.failUnless((a == [1,2,3,4,5]).all())
@@ -139,7 +141,7 @@
def testConstructor2(self):
"Test Array2 array constructor"
- na = N.zeros((3,4), dtype="l")
+ na = np.zeros((3,4), dtype="l")
aa = Array.Array2(na)
self.failUnless(isinstance(aa, Array.Array2))
@@ -180,7 +182,7 @@
#def testResize1(self):
# "Test Array2 resize method, array"
- # a = N.zeros((2*self.nrows, 2*self.ncols), dtype='l')
+ # a = np.zeros((2*self.nrows, 2*self.ncols), dtype='l')
# self.array2.resize(a)
# self.failUnless(len(self.array2) == len(a))
@@ -197,7 +199,7 @@
m = self.nrows
n = self.ncols
array1 = [ ]
- a = N.arange(n, dtype="l")
+ a = np.arange(n, dtype="l")
for i in range(m):
array1.append(Array.Array1(i*a))
for i in range(m):
@@ -265,7 +267,7 @@
def testView(self):
"Test Array2 view method"
a = self.array2.view()
- self.failUnless(isinstance(a, N.ndarray))
+ self.failUnless(isinstance(a, np.ndarray))
self.failUnless(len(a) == self.nrows)
######################################################################
@@ -279,7 +281,7 @@
# Execute the test suite
print "Testing Classes of Module Array"
- print "NumPy version", N.__version__
+ print "NumPy version", np.__version__
print
result = unittest.TextTestRunner(verbosity=2).run(suite)
sys.exit(len(result.errors) + len(result.failures))
Modified: trunk/numpy/f2py/f90mod_rules.py
===================================================================
--- trunk/numpy/f2py/f90mod_rules.py 2007-12-29 00:30:47 UTC (rev 4653)
+++ trunk/numpy/f2py/f90mod_rules.py 2007-12-29 01:32:27 UTC (rev 4654)
@@ -17,17 +17,15 @@
f2py_version='See `f2py -v`'
-import pprint
-import sys
+import pprint.pprint as show
+import sys.stderr.write as errmess
+import sys.stdout.write as outmess
import time
import types
import copy
-errmess=sys.stderr.write
-outmess=sys.stdout.write
-show=pprint.pprint
from auxfuncs import *
-import numpy as N
+import numpy as np
import capi_maps
import cfuncs
import rules
@@ -61,7 +59,7 @@
deallocate(d)
end if
end if
- if ((.not.allocated(d)).and.(s(1).ge.1)) then""" % N.intp().itemsize
+ if ((.not.allocated(d)).and.(s(1).ge.1)) then""" % np.intp().itemsize
fgetdims2="""\
end if
Modified: trunk/numpy/fft/tests/test_fftpack.py
===================================================================
--- trunk/numpy/fft/tests/test_fftpack.py 2007-12-29 00:30:47 UTC (rev 4653)
+++ trunk/numpy/fft/tests/test_fftpack.py 2007-12-29 01:32:27 UTC (rev 4654)
@@ -1,24 +1,24 @@
import sys
from numpy.testing import *
set_package_path()
-import numpy as N
+import numpy as np
restore_path()
def fft1(x):
L = len(x)
- phase = -2j*N.pi*(N.arange(L)/float(L))
- phase = N.arange(L).reshape(-1,1) * phase
- return N.sum(x*N.exp(phase),axis=1)
+ phase = -2j*np.pi*(np.arange(L)/float(L))
+ phase = np.arange(L).reshape(-1,1) * phase
+ return np.sum(x*np.exp(phase),axis=1)
class TestFFTShift(NumpyTestCase):
def check_fft_n(self):
- self.failUnlessRaises(ValueError,N.fft.fft,[1,2,3],0)
+ self.failUnlessRaises(ValueError,np.fft.fft,[1,2,3],0)
class TestFFT1D(NumpyTestCase):
def check_basic(self):
- rand = N.random.random
+ rand = np.random.random
x = rand(30) + 1j*rand(30)
- assert_array_almost_equal(fft1(x), N.fft.fft(x))
+ assert_array_almost_equal(fft1(x), np.fft.fft(x))
if __name__ == "__main__":
NumpyTest().run()
Modified: trunk/numpy/numarray/functions.py
===================================================================
--- trunk/numpy/numarray/functions.py 2007-12-29 00:30:47 UTC (rev 4653)
+++ trunk/numpy/numarray/functions.py 2007-12-29 01:32:27 UTC (rev 4654)
@@ -36,8 +36,13 @@
'togglebyteorder'
]
-import copy, copy_reg, types
-import os, sys, math, operator
+import copy,
+import copy_reg
+import types
+import os
+import sys
+import math
+import operator
from numpy import dot as matrixmultiply, dot, vdot, ravel, concatenate, all,\
allclose, any, around, argsort, array_equal, array_equiv,\
@@ -45,7 +50,7 @@
diagonal, e, pi, indices, inner as innerproduct, nonzero, \
outer as outerproduct, kron as kroneckerproduct, lexsort, putmask, rank, \
resize, searchsorted, shape, size, sort, swapaxes, trace, transpose
-import numpy as N
+import numpy as np
from numerictypes import typefrom
@@ -62,46 +67,46 @@
if dtype is None:
if type is None:
if use_default or typecode is not None:
- dtype = N.dtype(typecode)
+ dtype = np.dtype(typecode)
else:
- dtype = N.dtype(type)
+ dtype = np.dtype(type)
if use_default and dtype is None:
- dtype = N.dtype('int')
+ dtype = np.dtype('int')
return dtype
def fromfunction(shape, dimensions, type=None, typecode=None, dtype=None):
dtype = type2dtype(typecode, type, dtype, 1)
- return N.fromfunction(shape, dimensions, dtype=dtype)
+ return np.fromfunction(shape, dimensions, dtype=dtype)
def ones(shape, type=None, typecode=None, dtype=None):
dtype = type2dtype(typecode, type, dtype, 1)
- return N.ones(shape, dtype)
+ return np.ones(shape, dtype)
def zeros(shape, type=None, typecode=None, dtype=None):
dtype = type2dtype(typecode, type, dtype, 1)
- return N.zeros(shape, dtype)
+ return np.zeros(shape, dtype)
def where(condition, x=None, y=None, out=None):
if x is None and y is None:
- arr = N.where(condition)
+ arr = np.where(condition)
else:
- arr = N.where(condition, x, y)
+ arr = np.where(condition, x, y)
if out is not None:
out[...] = arr
return out
return arr
def indices(shape, type=None):
- return N.indices(shape, type)
+ return np.indices(shape, type)
def arange(a1, a2=None, stride=1, type=None, shape=None,
typecode=None, dtype=None):
dtype = type2dtype(typecode, type, dtype, 0)
- return N.arange(a1, a2, stride, dtype)
+ return np.arange(a1, a2, stride, dtype)
arrayrange = arange
def alltrue(x, axis=0):
- return N.alltrue(x, axis)
+ return np.alltrue(x, axis)
def and_(a, b):
"""Same as a & b
@@ -113,7 +118,7 @@
return (a/b,a%b)
def around(array, digits=0, output=None):
- ret = N.around(array, digits, output)
+ ret = np.around(array, digits, output)
if output is None:
return ret
return
@@ -123,14 +128,14 @@
def choose(selector, population, outarr=None, clipmode=RAISE):
- a = N.asarray(selector)
+ a = np.asarray(selector)
ret = a.choose(population, out=outarr, mode=clipmode)
if outarr is None:
return ret
return
def compress(condition, a, axis=0):
- return N.compress(condition, a, axis)
+ return np.compress(condition, a, axis)
# only returns a view
def explicit_type(a):
@@ -180,7 +185,7 @@
if -1 not in shape:
if sizing != STRICT:
raise ValueError("sizing must be STRICT if size complete")
- arr = N.empty(shape, dtype)
+ arr = np.empty(shape, dtype)
bytesleft=arr.nbytes
bytesread=0
while(bytesleft > _BLOCKSIZE):
@@ -208,7 +213,7 @@
##file whose size may be determined before allocation, should be
##quick -- only one allocation will be needed.
- recsize = dtype.itemsize * N.product([i for i in shape if i != -1])
+ recsize = dtype.itemsize * np.product([i for i in shape if i != -1])
blocksize = max(_BLOCKSIZE/recsize, 1)*recsize
##try to estimate file size
@@ -222,7 +227,7 @@
else:
initsize=max(1,(endpos-curpos)/recsize)*recsize
- buf = N.newbuffer(initsize)
+ buf = np.newbuffer(initsize)
bytesread=0
while 1:
@@ -260,9 +265,9 @@
uidx = shape.index(-1)
shape[uidx]=len(buf) / recsize
- a = N.ndarray(shape=shape, dtype=type, buffer=buf)
+ a = np.ndarray(shape=shape, dtype=type, buffer=buf)
if a.dtype.char == '?':
- N.not_equal(a, 0, a)
+ np.not_equal(a, 0, a)
return a
def fromstring(datastring, type=None, shape=None, typecode=None, dtype=None):
@@ -270,8 +275,8 @@
if shape is None:
count = -1
else:
- count = N.product(shape)
- res = N.fromstring(datastring, dtype=dtype, count=count)
+ count = np.product(shape)
+ res = np.fromstring(datastring, dtype=dtype, count=count)
if shape is not None:
res.shape = shape
return res
@@ -280,7 +285,7 @@
# check_overflow is ignored
def fromlist(seq, type=None, shape=None, check_overflow=0, typecode=None, dtype=None):
dtype = type2dtype(typecode, type, dtype, False)
- return N.array(seq, dtype)
+ return np.array(seq, dtype)
def array(sequence=None, typecode=None, copy=1, savespace=0,
type=None, shape=None, dtype=None):
@@ -290,21 +295,21 @@
return None
if dtype is None:
dtype = 'l'
- return N.empty(shape, dtype)
+ return np.empty(shape, dtype)
if isinstance(sequence, file):
return fromfile(sequence, dtype=dtype, shape=shape)
if isinstance(sequence, str):
return fromstring(sequence, dtype=dtype, shape=shape)
if isinstance(sequence, buffer):
- arr = N.frombuffer(sequence, dtype=dtype)
+ arr = np.frombuffer(sequence, dtype=dtype)
else:
- arr = N.array(sequence, dtype, copy=copy)
+ arr = np.array(sequence, dtype, copy=copy)
if shape is not None:
arr.shape = shape
return arr
def asarray(seq, type=None, typecode=None, dtype=None):
- if isinstance(seq, N.ndarray) and type is None and \
+ if isinstance(seq, np.ndarray) and type is None and \
typecode is None and dtype is None:
return seq
return array(seq, type=type, typecode=typecode, copy=0, dtype=dtype)
@@ -328,10 +333,10 @@
shape = (shape, ) + args
else:
shape = tuple(shape)
- dummy = N.array(shape)
- if not issubclass(dummy.dtype.type, N.integer):
+ dummy = np.array(shape)
+ if not issubclass(dummy.dtype.type, np.integer):
raise TypeError
- if len(dummy) > N.MAXDIMS:
+ if len(dummy) > np.MAXDIMS:
raise TypeError
except:
raise TypeError("Shape must be a sequence of integers")
@@ -340,7 +345,7 @@
def identity(n, type=None, typecode=None, dtype=None):
dtype = type2dtype(typecode, type, dtype, True)
- return N.identity(n, dtype)
+ return np.identity(n, dtype)
def info(obj, output=sys.stdout, numpy=0):
if numpy:
@@ -396,7 +401,7 @@
#clipmode is ignored if axis is not 0 and array is not 1d
def put(array, indices, values, axis=0, clipmode=RAISE):
- if not isinstance(array, N.ndarray):
+ if not isinstance(array, np.ndarray):
raise TypeError("put only works on subclass of ndarray")
work = asarray(array)
if axis == 0:
@@ -404,7 +409,7 @@
work.put(indices, values, clipmode)
else:
work[indices] = values
- elif isinstance(axis, (int, long, N.integer)):
+ elif isinstance(axis, (int, long, np.integer)):
work = work.swapaxes(0, axis)
work[indices] = values
work = work.swapaxes(0, axis)
@@ -418,13 +423,13 @@
work = work.transpose(axis)
def repeat(array, repeats, axis=0):
- return N.repeat(array, repeats, axis)
+ return np.repeat(array, repeats, axis)
def reshape(array, shape, *args):
if len(args) > 0:
shape = (shape,) + args
- return N.reshape(array, shape)
+ return np.reshape(array, shape)
import warnings as _warnings
@@ -434,12 +439,12 @@
return around(*args, **keys)
def sometrue(array, axis=0):
- return N.sometrue(array, axis)
+ return np.sometrue(array, axis)
#clipmode is ignored if axis is not an integer
def take(array, indices, axis=0, outarr=None, clipmode=RAISE):
- array = N.asarray(array)
- if isinstance(axis, (int, long, N.integer)):
+ array = np.asarray(array)
+ if isinstance(axis, (int, long, np.integer)):
res = array.take(indices, axis, outarr, clipmode)
if outarr is None:
return res
@@ -457,34 +462,34 @@
return
def tensormultiply(a1, a2):
- a1, a2 = N.asarray(a1), N.asarray(a2)
+ a1, a2 = np.asarray(a1), np.asarray(a2)
if (a1.shape[-1] != a2.shape[0]):
raise ValueError("Unmatched dimensions")
shape = a1.shape[:-1] + a2.shape[1:]
- return N.reshape(dot(N.reshape(a1, (-1, a1.shape[-1])),
- N.reshape(a2, (a2.shape[0],-1))),
+ return np.reshape(dot(N.reshape(a1, (-1, a1.shape[-1])),
+ np.reshape(a2, (a2.shape[0],-1))),
shape)
def cumsum(a1, axis=0, out=None, type=None, dim=0):
- return N.asarray(a1).cumsum(axis,dtype=type,out=out)
+ return np.asarray(a1).cumsum(axis,dtype=type,out=out)
def cumproduct(a1, axis=0, out=None, type=None, dim=0):
- return N.asarray(a1).cumprod(axis,dtype=type,out=out)
+ return np.asarray(a1).cumprod(axis,dtype=type,out=out)
def argmax(x, axis=-1):
- return N.argmax(x, axis)
+ return np.argmax(x, axis)
def argmin(x, axis=-1):
- return N.argmin(x, axis)
+ return np.argmin(x, axis)
def newobj(self, type):
if type is None:
- return N.empty_like(self)
+ return np.empty_like(self)
else:
- return N.empty(self.shape, type)
+ return np.empty(self.shape, type)
def togglebyteorder(self):
self.dtype=self.dtype.newbyteorder()
def average(a, axis=0, weights=None, returned=0):
- return N.average(a, axis, weights, returned)
+ return = np.average(a, axis, weights, returned)
More information about the Numpy-svn
mailing list