diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/fromnumeric.py | 1 | ||||
-rw-r--r-- | numpy/core/memmap.py | 5 | ||||
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 2 | ||||
-rw-r--r-- | numpy/core/src/umath/loops.c.src | 11 | ||||
-rw-r--r-- | numpy/core/tests/test_indexing.py | 19 | ||||
-rw-r--r-- | numpy/core/tests/test_memmap.py | 35 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 7 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 8 | ||||
-rw-r--r-- | numpy/f2py/cfuncs.py | 2 | ||||
-rw-r--r-- | numpy/lib/twodim_base.py | 11 |
10 files changed, 66 insertions, 35 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 152cceb1b..728c95294 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -90,6 +90,7 @@ def take(a, indices, axis=None, out=None, mode='raise'): See Also -------- + compress : Take elements using a boolean mask ndarray.take : equivalent method Examples diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index 4e0c194f3..b1c96ee29 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -38,6 +38,9 @@ class memmap(ndarray): This class may at some point be turned into a factory function which returns a view into an mmap buffer. + Delete the memmap instance to close. + + Parameters ---------- filename : str or file-like object @@ -91,8 +94,6 @@ class memmap(ndarray): Methods ------- - close - Close the memmap file. flush Flush any changes in memory to file on disk. When you delete a memmap object, flush is called first to write diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 056ca6133..f3ed2bbd0 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -2379,7 +2379,7 @@ PyArray_MapIterCheckIndices(PyArrayMapIterObject *mit) NPY_ITER_BUFFERED | NPY_ITER_NBO | NPY_ITER_ALIGNED | NPY_ITER_EXTERNAL_LOOP | NPY_ITER_GROWINNER | NPY_ITER_READONLY, - NPY_KEEPORDER, NPY_SAFE_CASTING, intp_type); + NPY_KEEPORDER, NPY_SAME_KIND_CASTING, intp_type); if (op_iter == NULL) { Py_DECREF(intp_type); diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src index a0edbc6dc..d6921efee 100644 --- a/numpy/core/src/umath/loops.c.src +++ b/numpy/core/src/umath/loops.c.src @@ -1791,20 +1791,19 @@ NPY_NO_EXPORT void HALF_@kind@(char **args, npy_intp *dimensions, npy_intp *steps, void *NPY_UNUSED(func)) { if (IS_BINARY_REDUCE) { + char *iop1 = args[0]; + float io1 = npy_half_to_float(*(npy_half *)iop1); #if @PW@ - npy_half * iop1 = (npy_half *)args[0]; npy_intp n = dimensions[0]; - *iop1 @OP@= npy_float_to_half(pairwise_sum_HALF((npy_half *)args[1], n, - steps[1] / (npy_intp)sizeof(npy_half))); + io1 @OP@= pairwise_sum_HALF((npy_half *)args[1], n, + steps[1] / (npy_intp)sizeof(npy_half)); #else - char *iop1 = args[0]; - float io1 = npy_half_to_float(*(npy_half *)iop1); BINARY_REDUCE_LOOP_INNER { io1 @OP@= npy_half_to_float(*(npy_half *)ip2); } - *((npy_half *)iop1) = npy_float_to_half(io1); #endif + *((npy_half *)iop1) = npy_float_to_half(io1); } else { BINARY_LOOP { diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py index 20032bc28..736210722 100644 --- a/numpy/core/tests/test_indexing.py +++ b/numpy/core/tests/test_indexing.py @@ -42,6 +42,25 @@ class TestIndexing(TestCase): a = np.array([np.array(1)], dtype=object) assert_(isinstance(a[0.], np.ndarray)) + def test_same_kind_index_casting(self): + # Indexes should be cast with same-kind and not safe, even if + # that is somewhat unsafe. So test various different code paths. + index = np.arange(5) + u_index = index.astype(np.uintp) + arr = np.arange(10) + + assert_array_equal(arr[index], arr[u_index]) + arr[u_index] = np.arange(5) + assert_array_equal(arr, np.arange(10)) + + arr = np.arange(10).reshape(5, 2) + assert_array_equal(arr[index], arr[u_index]) + + arr[u_index] = np.arange(5)[:,None] + assert_array_equal(arr, np.arange(5)[:,None].repeat(2, axis=1)) + + arr = np.arange(25).reshape(5, 5) + assert_array_equal(arr[u_index, u_index], arr[index, index]) def test_empty_fancy_index(self): # Empty list index creates an empty array diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py index 10e7a0817..b364f5eb9 100644 --- a/numpy/core/tests/test_memmap.py +++ b/numpy/core/tests/test_memmap.py @@ -1,8 +1,9 @@ from __future__ import division, absolute_import, print_function import sys -from tempfile import NamedTemporaryFile, TemporaryFile +from tempfile import NamedTemporaryFile, TemporaryFile, mktemp, mkdtemp import os +import shutil from numpy import memmap from numpy import arange, allclose, asarray @@ -11,6 +12,7 @@ from numpy.testing import * class TestMemmap(TestCase): def setUp(self): self.tmpfp = NamedTemporaryFile(prefix='mmap') + self.tempdir = mkdtemp() self.shape = (3, 4) self.dtype = 'float32' self.data = arange(12, dtype=self.dtype) @@ -18,6 +20,7 @@ class TestMemmap(TestCase): def tearDown(self): self.tmpfp.close() + shutil.rmtree(self.tempdir) def test_roundtrip(self): # Write data to file @@ -33,11 +36,11 @@ class TestMemmap(TestCase): assert_array_equal(self.data, newfp) def test_open_with_filename(self): - with NamedTemporaryFile() as tmp: - fp = memmap(tmp.name, dtype=self.dtype, mode='w+', - shape=self.shape) - fp[:] = self.data[:] - del fp + tmpname = mktemp('', 'mmap', dir=self.tempdir) + fp = memmap(tmpname, dtype=self.dtype, mode='w+', + shape=self.shape) + fp[:] = self.data[:] + del fp def test_unnamed_file(self): with TemporaryFile() as f: @@ -54,16 +57,16 @@ class TestMemmap(TestCase): del fp def test_filename(self): - with NamedTemporaryFile() as tmp: - fp = memmap(tmp.name, dtype=self.dtype, mode='w+', - shape=self.shape) - abspath = os.path.abspath(tmp.name) - fp[:] = self.data[:] - self.assertEqual(abspath, fp.filename) - b = fp[:1] - self.assertEqual(abspath, b.filename) - del b - del fp + tmpname = mktemp('', 'mmap', dir=self.tempdir) + fp = memmap(tmpname, dtype=self.dtype, mode='w+', + shape=self.shape) + abspath = os.path.abspath(tmpname) + fp[:] = self.data[:] + self.assertEqual(abspath, fp.filename) + b = fp[:1] + self.assertEqual(abspath, b.filename) + del b + del fp def test_filename_fileobj(self): fp = memmap(self.tmpfp, dtype=self.dtype, mode="w+", diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 40e508549..a73b3350d 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -3,6 +3,7 @@ from __future__ import division, absolute_import, print_function import tempfile import sys import os +import shutil import warnings import operator import io @@ -2373,11 +2374,11 @@ class TestIO(object): self.x = rand(shape) + rand(shape).astype(np.complex)*1j self.x[0,:, 1] = [nan, inf, -inf, nan] self.dtype = self.x.dtype - self.file = tempfile.NamedTemporaryFile() - self.filename = self.file.name + self.tempdir = tempfile.mkdtemp() + self.filename = tempfile.mktemp(dir=self.tempdir) def tearDown(self): - self.file.close() + shutil.rmtree(self.tempdir) def test_bool_fromstring(self): v = np.array([True, False, True, False], dtype=np.bool_) diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index b217936f7..f5a98431c 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -340,6 +340,10 @@ class TestUfunc(TestCase): assert_almost_equal(np.sum(d[-1::-2]), 250.) assert_almost_equal(np.sum(d[::-3]), 167.) assert_almost_equal(np.sum(d[-1::-3]), 167.) + # sum with first reduction entry != 0 + d = np.ones((1,), dtype=dt) + d += d + assert_almost_equal(d, 2.) def test_sum_complex(self): for dt in (np.complex64, np.complex128, np.clongdouble): @@ -361,6 +365,10 @@ class TestUfunc(TestCase): assert_almost_equal(np.sum(d[-1::-2]), 250. + 250j) assert_almost_equal(np.sum(d[::-3]), 167. + 167j) assert_almost_equal(np.sum(d[-1::-3]), 167. + 167j) + # sum with first reduction entry != 0 + d = np.ones((1,), dtype=dt) + 1j + d += d + assert_almost_equal(d, 2. + 2j) def test_inner1d(self): a = np.arange(6).reshape((2, 3)) diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py index aade23db6..7fb630697 100644 --- a/numpy/f2py/cfuncs.py +++ b/numpy/f2py/cfuncs.py @@ -75,7 +75,7 @@ typedef long long long_long; typedef unsigned long long unsigned_long_long; #endif """ -typedefs['insinged_long_long']="""\ +typedefs['unsigned_long_long']="""\ #ifdef _WIN32 typedef __uint64 long_long; #else diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py index 12c0f9bb3..8c99f6804 100644 --- a/numpy/lib/twodim_base.py +++ b/numpy/lib/twodim_base.py @@ -25,7 +25,7 @@ def fliplr(m): Parameters ---------- m : array_like - Input array. + Input array, must be at least 2-D. Returns ------- @@ -40,8 +40,7 @@ def fliplr(m): Notes ----- - Equivalent to A[:,::-1]. Does not require the array to be - two-dimensional. + Equivalent to A[:,::-1]. Requires the array to be at least 2-D. Examples -------- @@ -650,14 +649,14 @@ def histogram2d(x, y, bins=10, range=None, normed=False, weights=None): >>> fig = plt.figure(figsize=(7, 3)) >>> ax = fig.add_subplot(131) - >>> ax.set_title('imshow:\nequidistant') + >>> ax.set_title('imshow: equidistant') >>> im = plt.imshow(H, interpolation='nearest', origin='low', extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]]) pcolormesh can display exact bin edges: >>> ax = fig.add_subplot(132) - >>> ax.set_title('pcolormesh:\nexact bin edges') + >>> ax.set_title('pcolormesh: exact bin edges') >>> X, Y = np.meshgrid(xedges, yedges) >>> ax.pcolormesh(X, Y, H) >>> ax.set_aspect('equal') @@ -665,7 +664,7 @@ def histogram2d(x, y, bins=10, range=None, normed=False, weights=None): NonUniformImage displays exact bin edges with interpolation: >>> ax = fig.add_subplot(133) - >>> ax.set_title('NonUniformImage:\ninterpolated') + >>> ax.set_title('NonUniformImage: interpolated') >>> im = mpl.image.NonUniformImage(ax, interpolation='bilinear') >>> xcenters = xedges[:-1] + 0.5 * (xedges[1:] - xedges[:-1]) >>> ycenters = yedges[:-1] + 0.5 * (yedges[1:] - yedges[:-1]) |