summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/f2py/f2py.12
-rw-r--r--doc/numpybook/capi.lyx2
-rw-r--r--doc/source/f2py/usage.rst2
-rw-r--r--doc/source/reference/c-api.array.rst14
-rw-r--r--numpy/core/fromnumeric.py1
-rw-r--r--numpy/core/memmap.py5
-rw-r--r--numpy/core/src/multiarray/mapping.c2
-rw-r--r--numpy/core/src/umath/loops.c.src11
-rw-r--r--numpy/core/tests/test_indexing.py19
-rw-r--r--numpy/core/tests/test_memmap.py35
-rw-r--r--numpy/core/tests/test_multiarray.py7
-rw-r--r--numpy/core/tests/test_ufunc.py8
-rw-r--r--numpy/f2py/cfuncs.py2
-rw-r--r--numpy/lib/twodim_base.py11
14 files changed, 82 insertions, 39 deletions
diff --git a/doc/f2py/f2py.1 b/doc/f2py/f2py.1
index 279647424..7f51ea29d 100644
--- a/doc/f2py/f2py.1
+++ b/doc/f2py/f2py.1
@@ -53,7 +53,7 @@ Do [not] lower the cases in <fortran files>. By default, \-\-lower is
assumed with \-h key, and \-\-no\-lower without \-h key.
.TP
.B \-\-build\-dir <dirname>
-All f2py generated files are created in <dirname>. Default is tempfile.mktemp().
+All f2py generated files are created in <dirname>. Default is tempfile.mkdtemp().
.TP
.B \-\-overwrite\-signature
Overwrite existing signature file.
diff --git a/doc/numpybook/capi.lyx b/doc/numpybook/capi.lyx
index a5c835523..b14d5c4f5 100644
--- a/doc/numpybook/capi.lyx
+++ b/doc/numpybook/capi.lyx
@@ -13529,7 +13529,7 @@ PyArray_Descr*
\end_layout
\begin_layout Description
-PyArrayDescr_Check (
+PyArray_DescrCheck (
\family typewriter
int
\family default
diff --git a/doc/source/f2py/usage.rst b/doc/source/f2py/usage.rst
index 2f9017faa..a6f093154 100644
--- a/doc/source/f2py/usage.rst
+++ b/doc/source/f2py/usage.rst
@@ -183,7 +183,7 @@ Other options:
without the ``-h`` switch.
``--build-dir <dirname>``
All F2PY generated files are created in ``<dirname>``. Default is
- ``tempfile.mktemp()``.
+ ``tempfile.mkdtemp()``.
``--quiet``
Run quietly.
``--verbose``
diff --git a/doc/source/reference/c-api.array.rst b/doc/source/reference/c-api.array.rst
index 323ca0655..351b4238e 100644
--- a/doc/source/reference/c-api.array.rst
+++ b/doc/source/reference/c-api.array.rst
@@ -1877,6 +1877,18 @@ Calculation
Equivalent to :meth:`ndarray.argmin` (*self*, *axis*). Return the index of
the smallest element of *self* along *axis*.
+
+
+
+.. note::
+
+ The out argument specifies where to place the result. If out is
+ NULL, then the output array is created, otherwise the output is
+ placed in out which must be the correct size and type. A new
+ reference to the ouput array is always returned even when out
+ is not NULL. The caller of the routine has the responsability
+ to ``DECREF`` out if not NULL or a memory-leak will occur.
+
.. cfunction:: PyObject* PyArray_Max(PyArrayObject* self, int axis, PyArrayObject* out)
Equivalent to :meth:`ndarray.max` (*self*, *axis*). Return the largest
@@ -2583,7 +2595,7 @@ Data-type descriptors
unless otherwise noted. Therefore, you must own a reference to any
data-type object used as input to such a function.
-.. cfunction:: int PyArrayDescr_Check(PyObject* obj)
+.. cfunction:: int PyArray_DescrCheck(PyObject* obj)
Evaluates as true if *obj* is a data-type object ( :ctype:`PyArray_Descr *` ).
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])