summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benchmarks/benchmarks/bench_lib.py61
-rw-r--r--doc/source/reference/maskedarray.generic.rst2
-rw-r--r--doc/source/reference/routines.ctypeslib.rst2
-rw-r--r--doc/source/reference/routines.linalg.rst2
-rw-r--r--doc/source/reference/routines.matlib.rst2
-rw-r--r--doc/source/reference/routines.polynomials.package.rst2
-rw-r--r--doc/source/reference/routines.polynomials.polynomial.rst2
-rw-r--r--doc/source/reference/routines.random.rst2
-rw-r--r--doc/source/reference/routines.testing.rst2
-rw-r--r--numpy/core/src/multiarray/usertypes.c33
-rwxr-xr-xnumpy/f2py/crackfortran.py2
-rw-r--r--numpy/lib/tests/test_recfunctions.py6
12 files changed, 105 insertions, 13 deletions
diff --git a/benchmarks/benchmarks/bench_lib.py b/benchmarks/benchmarks/bench_lib.py
index 7a6b3f01d..f65a96dad 100644
--- a/benchmarks/benchmarks/bench_lib.py
+++ b/benchmarks/benchmarks/bench_lib.py
@@ -54,3 +54,64 @@ class Pad(Benchmark):
def time_pad(self, shape, pad_width, mode):
np.pad(self.array, pad_width, mode)
+
+class Nan(Benchmark):
+ """Benchmarks for nan functions"""
+
+ param_names = ["array_size", "percent_nans"]
+ params = [
+ # sizes of the 1D arrays
+ [200, int(2e5)],
+ # percent of np.nan in arrays
+ [0, 0.1, 2., 50., 90.],
+ ]
+
+ def setup(self, array_size, percent_nans):
+ np.random.seed(123)
+ # produce a randomly shuffled array with the
+ # approximate desired percentage np.nan content
+ base_array = np.random.uniform(size=array_size)
+ base_array[base_array < percent_nans / 100.] = np.nan
+ self.arr = base_array
+
+ def time_nanmin(self, array_size, percent_nans):
+ np.nanmin(self.arr)
+
+ def time_nanmax(self, array_size, percent_nans):
+ np.nanmax(self.arr)
+
+ def time_nanargmin(self, array_size, percent_nans):
+ np.nanargmin(self.arr)
+
+ def time_nanargmax(self, array_size, percent_nans):
+ np.nanargmax(self.arr)
+
+ def time_nansum(self, array_size, percent_nans):
+ np.nansum(self.arr)
+
+ def time_nanprod(self, array_size, percent_nans):
+ np.nanprod(self.arr)
+
+ def time_nancumsum(self, array_size, percent_nans):
+ np.nancumsum(self.arr)
+
+ def time_nancumprod(self, array_size, percent_nans):
+ np.nancumprod(self.arr)
+
+ def time_nanmean(self, array_size, percent_nans):
+ np.nanmean(self.arr)
+
+ def time_nanvar(self, array_size, percent_nans):
+ np.nanvar(self.arr)
+
+ def time_nanstd(self, array_size, percent_nans):
+ np.nanstd(self.arr)
+
+ def time_nanmedian(self, array_size, percent_nans):
+ np.nanmedian(self.arr)
+
+ def time_nanquantile(self, array_size, percent_nans):
+ np.nanquantile(self.arr, q=0.2)
+
+ def time_nanpercentile(self, array_size, percent_nans):
+ np.nanpercentile(self.arr, q=50)
diff --git a/doc/source/reference/maskedarray.generic.rst b/doc/source/reference/maskedarray.generic.rst
index 07ad6c292..7375d60fb 100644
--- a/doc/source/reference/maskedarray.generic.rst
+++ b/doc/source/reference/maskedarray.generic.rst
@@ -2,7 +2,7 @@
.. _maskedarray.generic:
-
+.. module:: numpy.ma
The :mod:`numpy.ma` module
==========================
diff --git a/doc/source/reference/routines.ctypeslib.rst b/doc/source/reference/routines.ctypeslib.rst
index b04713b61..71b944a63 100644
--- a/doc/source/reference/routines.ctypeslib.rst
+++ b/doc/source/reference/routines.ctypeslib.rst
@@ -1,3 +1,5 @@
+.. module:: numpy.ctypeslib
+
***********************************************************
C-Types Foreign Function Interface (:mod:`numpy.ctypeslib`)
***********************************************************
diff --git a/doc/source/reference/routines.linalg.rst b/doc/source/reference/routines.linalg.rst
index 0520df413..c6bffc874 100644
--- a/doc/source/reference/routines.linalg.rst
+++ b/doc/source/reference/routines.linalg.rst
@@ -1,5 +1,7 @@
.. _routines.linalg:
+.. module:: numpy.linalg
+
Linear algebra (:mod:`numpy.linalg`)
************************************
diff --git a/doc/source/reference/routines.matlib.rst b/doc/source/reference/routines.matlib.rst
index a35eaec78..c7f675425 100644
--- a/doc/source/reference/routines.matlib.rst
+++ b/doc/source/reference/routines.matlib.rst
@@ -1,3 +1,5 @@
+.. module:: numpy.matlib
+
Matrix library (:mod:`numpy.matlib`)
************************************
diff --git a/doc/source/reference/routines.polynomials.package.rst b/doc/source/reference/routines.polynomials.package.rst
index 61cb57fbb..7e40d9f00 100644
--- a/doc/source/reference/routines.polynomials.package.rst
+++ b/doc/source/reference/routines.polynomials.package.rst
@@ -1,3 +1,5 @@
+.. module:: numpy.polynomial
+
Polynomial Package
==================
diff --git a/doc/source/reference/routines.polynomials.polynomial.rst b/doc/source/reference/routines.polynomials.polynomial.rst
index 8194ca867..365c8da98 100644
--- a/doc/source/reference/routines.polynomials.polynomial.rst
+++ b/doc/source/reference/routines.polynomials.polynomial.rst
@@ -1,3 +1,5 @@
+.. module:: numpy.polynomial.polynomial
+
Polynomial Module (:mod:`numpy.polynomial.polynomial`)
======================================================
diff --git a/doc/source/reference/routines.random.rst b/doc/source/reference/routines.random.rst
index c8b097d7d..cda4e2b61 100644
--- a/doc/source/reference/routines.random.rst
+++ b/doc/source/reference/routines.random.rst
@@ -1,5 +1,7 @@
.. _routines.random:
+.. module:: numpy.random
+
Random sampling (:mod:`numpy.random`)
*************************************
diff --git a/doc/source/reference/routines.testing.rst b/doc/source/reference/routines.testing.rst
index 5a52a40d6..77c046768 100644
--- a/doc/source/reference/routines.testing.rst
+++ b/doc/source/reference/routines.testing.rst
@@ -1,5 +1,7 @@
.. _numpy-testing:
+.. module:: numpy.testing
+
Test Support (:mod:`numpy.testing`)
===================================
diff --git a/numpy/core/src/multiarray/usertypes.c b/numpy/core/src/multiarray/usertypes.c
index 8e8090002..2e8fb514f 100644
--- a/numpy/core/src/multiarray/usertypes.c
+++ b/numpy/core/src/multiarray/usertypes.c
@@ -40,19 +40,27 @@ maintainer email: oliphant.travis@ieee.org
NPY_NO_EXPORT PyArray_Descr **userdescrs=NULL;
-static int *
-_append_new(int *types, int insert)
+static int
+_append_new(int **p_types, int insert)
{
int n = 0;
int *newtypes;
+ int *types = *p_types;
while (types[n] != NPY_NOTYPE) {
n++;
}
newtypes = (int *)realloc(types, (n + 2)*sizeof(int));
+ if (newtypes == NULL) {
+ PyErr_NoMemory();
+ return -1;
+ }
newtypes[n] = insert;
newtypes[n + 1] = NPY_NOTYPE;
- return newtypes;
+
+ /* Replace the passed-in pointer */
+ *p_types = newtypes;
+ return 0;
}
static npy_bool
@@ -247,10 +255,13 @@ PyArray_RegisterCanCast(PyArray_Descr *descr, int totype,
*/
if (descr->f->cancastto == NULL) {
descr->f->cancastto = (int *)malloc(1*sizeof(int));
+ if (descr->f->cancastto == NULL) {
+ PyErr_NoMemory();
+ return -1;
+ }
descr->f->cancastto[0] = NPY_NOTYPE;
}
- descr->f->cancastto = _append_new(descr->f->cancastto,
- totype);
+ return _append_new(&descr->f->cancastto, totype);
}
else {
/* register with cancastscalarkindto */
@@ -258,6 +269,10 @@ PyArray_RegisterCanCast(PyArray_Descr *descr, int totype,
int i;
descr->f->cancastscalarkindto =
(int **)malloc(NPY_NSCALARKINDS* sizeof(int*));
+ if (descr->f->cancastscalarkindto == NULL) {
+ PyErr_NoMemory();
+ return -1;
+ }
for (i = 0; i < NPY_NSCALARKINDS; i++) {
descr->f->cancastscalarkindto[i] = NULL;
}
@@ -265,11 +280,13 @@ PyArray_RegisterCanCast(PyArray_Descr *descr, int totype,
if (descr->f->cancastscalarkindto[scalar] == NULL) {
descr->f->cancastscalarkindto[scalar] =
(int *)malloc(1*sizeof(int));
+ if (descr->f->cancastscalarkindto[scalar] == NULL) {
+ PyErr_NoMemory();
+ return -1;
+ }
descr->f->cancastscalarkindto[scalar][0] =
NPY_NOTYPE;
}
- descr->f->cancastscalarkindto[scalar] =
- _append_new(descr->f->cancastscalarkindto[scalar], totype);
+ return _append_new(&descr->f->cancastscalarkindto[scalar], totype);
}
- return 0;
}
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index 2620fc9b7..c4a650585 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -2399,7 +2399,7 @@ def _selected_real_kind_func(p, r=0, radix=0):
if p < 16:
return 8
machine = platform.machine().lower()
- if machine.startswith(('aarch64', 'power', 'ppc64', 's390x')):
+ if machine.startswith(('aarch64', 'power', 'ppc64', 's390x', 'sparc')):
if p <= 20:
return 16
else:
diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py
index 11f8a5afa..069693613 100644
--- a/numpy/lib/tests/test_recfunctions.py
+++ b/numpy/lib/tests/test_recfunctions.py
@@ -221,9 +221,9 @@ class TestRecFunctions(object):
( 5, ( 6., 7), [ 8., 9.]),
(10, (11., 12), [13., 14.]),
(15, (16., 17), [18., 19.])],
- dtype=[('a', '<i4'),
- ('b', [('f0', '<f4'), ('f1', '<u2')]),
- ('c', '<f4', (2,))])
+ dtype=[('a', 'i4'),
+ ('b', [('f0', 'f4'), ('f1', 'u2')]),
+ ('c', 'f4', (2,))])
assert_equal(out, want)
d = np.array([(1, 2, 5), (4, 5, 7), (7, 8 ,11), (10, 11, 12)],