diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/_pytesttester.py | 8 | ||||
-rw-r--r-- | numpy/conftest.py | 2 | ||||
-rw-r--r-- | numpy/core/function_base.py | 8 | ||||
-rw-r--r-- | numpy/core/src/umath/reduction.c | 45 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 1 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 1 |
6 files changed, 29 insertions, 36 deletions
diff --git a/numpy/_pytesttester.py b/numpy/_pytesttester.py index 0dc38fa59..ca86aeb22 100644 --- a/numpy/_pytesttester.py +++ b/numpy/_pytesttester.py @@ -169,7 +169,13 @@ class PytestTester: pytest_args += ["--cov=" + module_path] if label == "fast": - pytest_args += ["-m", "not slow"] + # not importing at the top level to avoid circular import of module + from numpy.testing import IS_PYPY + if IS_PYPY: + pytest_args += ["-m", "not slow and not slow_pypy"] + else: + pytest_args += ["-m", "not slow"] + elif label != "full": pytest_args += ["-m", label] diff --git a/numpy/conftest.py b/numpy/conftest.py index 1d3e0349f..20c8a449e 100644 --- a/numpy/conftest.py +++ b/numpy/conftest.py @@ -27,6 +27,8 @@ def pytest_configure(config): "leaks_references: Tests that are known to leak references.") config.addinivalue_line("markers", "slow: Tests that are very slow.") + config.addinivalue_line("markers", + "slow_pypy: Tests that are very slow on pypy.") def pytest_addoption(parser): diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py index 6d49b9055..9e46f0ea5 100644 --- a/numpy/core/function_base.py +++ b/numpy/core/function_base.py @@ -110,13 +110,7 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, >>> plt.show() """ - try: - num = operator.index(num) - except TypeError: - raise TypeError( - "object of type {} cannot be safely interpreted as an integer." - .format(type(num))) - + num = operator.index(num) if num < 0: raise ValueError("Number of samples, %s, must be non-negative." % num) div = (num - 1) if endpoint else num diff --git a/numpy/core/src/umath/reduction.c b/numpy/core/src/umath/reduction.c index 79c302755..79adb0051 100644 --- a/numpy/core/src/umath/reduction.c +++ b/numpy/core/src/umath/reduction.c @@ -18,6 +18,7 @@ #include "npy_config.h" #include "npy_pycompat.h" +#include "ctors.h" #include "numpy/ufuncobject.h" #include "lowlevel_strided_loops.h" @@ -88,14 +89,13 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags, PyArrayObject *out, int keepdims, const char *funcname, int need_copy) { - int ndim = PyArray_NDIM(in); - npy_intp *shape_in = PyArray_DIMS(in); - npy_intp strides[NPY_MAXDIMS], shape[NPY_MAXDIMS]; - npy_intp *strides_out = PyArray_STRIDES(out); - npy_intp *shape_out = PyArray_DIMS(out); - int idim, idim_out, ndim_out = PyArray_NDIM(out); - PyArray_Descr *dtype; - PyArrayObject_fields *ret; + /* unpack shape information */ + int const ndim = PyArray_NDIM(in); + npy_intp const *shape_in = PyArray_DIMS(in); + + int const ndim_out = PyArray_NDIM(out); + npy_intp const *strides_out = PyArray_STRIDES(out); + npy_intp const *shape_out = PyArray_DIMS(out); /* * If the 'keepdims' parameter is true, do a simpler validation and @@ -110,7 +110,7 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags, return NULL; } - for (idim = 0; idim < ndim; ++idim) { + for (int idim = 0; idim < ndim; ++idim) { if (axis_flags[idim]) { if (shape_out[idim] != 1) { PyErr_Format(PyExc_ValueError, @@ -137,8 +137,9 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags, } /* Construct the strides and shape */ - idim_out = 0; - for (idim = 0; idim < ndim; ++idim) { + npy_intp strides[NPY_MAXDIMS], shape[NPY_MAXDIMS]; + int idim_out = 0; + for (int idim = 0; idim < ndim; ++idim) { if (axis_flags[idim]) { strides[idim] = 0; shape[idim] = 1; @@ -171,31 +172,20 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags, } /* Allocate the view */ - dtype = PyArray_DESCR(out); + PyArray_Descr *dtype = PyArray_DESCR(out); Py_INCREF(dtype); - /* TODO: use PyArray_NewFromDescrAndBase here once multiarray and umath - * are merged - */ - ret = (PyArrayObject_fields *)PyArray_NewFromDescr( + PyArrayObject_fields *ret = (PyArrayObject_fields *)PyArray_NewFromDescrAndBase( &PyArray_Type, dtype, ndim, shape, strides, PyArray_DATA(out), - PyArray_FLAGS(out), NULL); + PyArray_FLAGS(out), NULL, (PyObject *)out); if (ret == NULL) { return NULL; } - Py_INCREF(out); - if (PyArray_SetBaseObject((PyArrayObject *)ret, (PyObject *)out) < 0) { - Py_DECREF(ret); - return NULL; - } - if (need_copy) { - PyArrayObject *ret_copy; - - ret_copy = (PyArrayObject *)PyArray_NewLikeArray( - (PyArrayObject *)ret, NPY_ANYORDER, NULL, 0); + PyArrayObject *ret_copy = (PyArrayObject *)PyArray_NewLikeArray( + (PyArrayObject *)ret, NPY_ANYORDER, NULL, 0); if (ret_copy == NULL) { Py_DECREF(ret); return NULL; @@ -208,7 +198,6 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags, } if (PyArray_SetWritebackIfCopyBase(ret_copy, (PyArrayObject *)ret) < 0) { - Py_DECREF(ret); Py_DECREF(ret_copy); return NULL; } diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 4d7639e43..fb969e5f8 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -2030,6 +2030,7 @@ class TestRegression: a[...] = [[1, 2]] assert_equal(a, [[1, 2], [1, 2]]) + @pytest.mark.slow_pypy def test_memoryleak(self): # Ticket #1917 - ensure that array data doesn't leak for i in range(1000): diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 8ce20a116..9abde3e11 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -278,6 +278,7 @@ class TestSavezLoad(RoundtripTest): fp.seek(0) assert_(not fp.closed) + @pytest.mark.slow_pypy def test_closing_fid(self): # Test that issue #1517 (too many opened files) remains closed # It might be a "weak" test since failed to get triggered on |