[Numpy-svn] r4530 - in branches/numpy.scons: . numpy numpy/core/tests numpy/fft/tests numpy/random/mtrand
numpy-svn at scipy.org
numpy-svn at scipy.org
Mon Dec 3 09:48:29 EST 2007
Author: cdavid
Date: 2007-12-03 08:48:18 -0600 (Mon, 03 Dec 2007)
New Revision: 4530
Modified:
branches/numpy.scons/
branches/numpy.scons/numpy/add_newdocs.py
branches/numpy.scons/numpy/core/tests/test_multiarray.py
branches/numpy.scons/numpy/fft/tests/test_fftpack.py
branches/numpy.scons/numpy/random/mtrand/distributions.c
Log:
Merged revisions 4526-4529 via svnmerge from
http://svn.scipy.org/svn/numpy/trunk
........
r4527 | rkern | 2007-12-03 15:39:46 +0900 (Mon, 03 Dec 2007) | 1 line
BUG: fix incorrect ordering of the 'good' and 'bad' objects in the hypergeometric distribution.
........
r4528 | stefan | 2007-12-03 16:15:55 +0900 (Mon, 03 Dec 2007) | 2 lines
Increase test code coverage. Add documentation.
........
Property changes on: branches/numpy.scons
___________________________________________________________________
Name: svnmerge-integrated
- /branches/distutils-revamp:1-2752 /branches/multicore:1-3687 /trunk:1-4525
+ /branches/distutils-revamp:1-2752 /branches/multicore:1-3687 /trunk:1-4529
Modified: branches/numpy.scons/numpy/add_newdocs.py
===================================================================
--- branches/numpy.scons/numpy/add_newdocs.py 2007-12-03 14:44:29 UTC (rev 4529)
+++ branches/numpy.scons/numpy/add_newdocs.py 2007-12-03 14:48:18 UTC (rev 4530)
@@ -379,26 +379,36 @@
sort order, and so on). The keys argument must be a sequence of things
that can be converted to arrays of the same shape.
- Parameters:
+ *Parameters*:
- a : array type
+ keys : (k,N) array or tuple of (N,) sequences
Array containing values that the returned indices should sort.
axis : integer
- Axis to be indirectly sorted. None indicates that the flattened
- array should be used. Default is -1.
+ Axis to be indirectly sorted. Default is -1 (i.e. last axis).
- Returns:
+ *Returns*:
- indices : integer array
- Array of indices that sort the keys along the specified axis. The
- array has the same shape as the keys.
+ indices : (N,) integer array
+ Array of indices that sort the keys along the specified axis.
- SeeAlso:
+ *See Also*:
- argsort : indirect sort
- sort : inplace sort
+ `argsort` : indirect sort
+ `sort` : inplace sort
+ *Examples*
+
+ >>> a = [1,5,1,4,3,6,7]
+ >>> b = [9,4,0,4,0,4,3]
+ >>> ind = lexsort((b,a))
+ >>> print ind
+ [2 0 4 3 1 5 6]
+ >>> print take(a,ind)
+ [1 1 3 4 5 6 7]
+ >>> print take(b,ind)
+ [0 9 0 4 4 4 3]
+
""")
add_newdoc('numpy.core.multiarray','can_cast',
Modified: branches/numpy.scons/numpy/core/tests/test_multiarray.py
===================================================================
--- branches/numpy.scons/numpy/core/tests/test_multiarray.py 2007-12-03 14:44:29 UTC (rev 4529)
+++ branches/numpy.scons/numpy/core/tests/test_multiarray.py 2007-12-03 14:48:18 UTC (rev 4530)
@@ -3,6 +3,8 @@
from numpy import random
import numpy as N
+import tempfile
+
class TestFlags(NumpyTestCase):
def setUp(self):
self.a = arange(10)
@@ -420,7 +422,7 @@
y = rec['x'].clip(-0.3,0.5)
self._check_range(y,-0.3,0.5)
-class test_putmask(ParametricTestCase):
+class TestPutmask(ParametricTestCase):
def tst_basic(self,x,T,mask,val):
N.putmask(x,mask,val)
assert N.all(x[mask] == T(val))
@@ -466,10 +468,74 @@
## N.putmask(z,[True,True,True],3)
pass
-# Import tests from unicode
+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])
+ assert_array_equal(idx,expected_idx)
+
+ x = N.vstack((b,a))
+ idx = N.lexsort(x)
+ assert_array_equal(idx,expected_idx)
+
+ assert_array_equal(x[1][idx],N.sort(x[1]))
+
+class TestFromToFile(NumpyTestCase):
+ def setUp(self):
+ shape = (4,7)
+ rand = N.random.random
+
+ self.x = rand(shape) + rand(shape).astype(N.complex)*1j
+ self.dtype = N.complex
+
+ def test_file(self):
+ f = tempfile.TemporaryFile()
+ self.x.tofile(f)
+ f.seek(0)
+ y = N.fromfile(f,dtype=self.dtype)
+ assert_array_equal(y,self.x.flat)
+
+ def test_filename(self):
+ filename = tempfile.mktemp()
+ f = open(filename,'wb')
+ self.x.tofile(f)
+ f.close()
+ y = N.fromfile(filename,dtype=self.dtype)
+ assert_array_equal(y,self.x.flat)
+
+class TestFromBuffer(ParametricTestCase):
+ def tst_basic(self,buffer,expected,kwargs):
+ assert_array_equal(N.frombuffer(buffer,**kwargs),expected)
+
+ def testip_basic(self):
+ 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)
+ 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.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)
+ y = x
+ self.failUnlessRaises(ValueError,x.resize,(5,1))
+
+# Import tests without matching module names
set_local_path()
from test_unicode import *
from test_regression import *
+from test_ufunc import *
restore_path()
if __name__ == "__main__":
Modified: branches/numpy.scons/numpy/fft/tests/test_fftpack.py
===================================================================
--- branches/numpy.scons/numpy/fft/tests/test_fftpack.py 2007-12-03 14:44:29 UTC (rev 4529)
+++ branches/numpy.scons/numpy/fft/tests/test_fftpack.py 2007-12-03 14:48:18 UTC (rev 4530)
@@ -1,12 +1,24 @@
import sys
from numpy.testing import *
set_package_path()
-from numpy.fft import *
+import numpy as N
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)
+
class TestFFTShift(NumpyTestCase):
def check_fft_n(self):
- self.failUnlessRaises(ValueError,fft,[1,2,3],0)
+ self.failUnlessRaises(ValueError,N.fft.fft,[1,2,3],0)
+class TestFFT1D(NumpyTestCase):
+ def check_basic(self):
+ rand = N.random.random
+ x = rand(30) + 1j*rand(30)
+ assert_array_almost_equal(fft1(x), N.fft.fft(x))
+
if __name__ == "__main__":
NumpyTest().run()
Modified: branches/numpy.scons/numpy/random/mtrand/distributions.c
===================================================================
--- branches/numpy.scons/numpy/random/mtrand/distributions.c 2007-12-03 14:44:29 UTC (rev 4529)
+++ branches/numpy.scons/numpy/random/mtrand/distributions.c 2007-12-03 14:48:18 UTC (rev 4530)
@@ -742,7 +742,7 @@
if (K == 0) break;
}
Z = (long)(d2 - Y);
- if (bad > good) Z = sample - Z;
+ if (good > bad) Z = sample - Z;
return Z;
}
@@ -795,7 +795,7 @@
}
/* this is a correction to HRUA* by Ivan Frohne in rv.py */
- if (bad > good) Z = m - Z;
+ if (good > bad) Z = m - Z;
/* another fix from rv.py to allow sample to exceed popsize/2 */
if (m < sample) Z = bad - Z;
More information about the Numpy-svn
mailing list