diff -Nru python-numpy-1.8.1~rc1/debian/changelog python-numpy-1.8.1/debian/changelog --- python-numpy-1.8.1~rc1/debian/changelog 2014-03-23 09:36:20.000000000 +0000 +++ python-numpy-1.8.1/debian/changelog 2014-03-28 11:21:39.000000000 +0000 @@ -1,3 +1,23 @@ +python-numpy (1:1.8.1-1ubuntu1) trusty; urgency=medium + + * Merge with Debian; remaining changes: + - debian/patches/20_disable-plot-extension.patch + Disable plot_directive extension, and catch ImportErrors when + matplotlib cannot be imported, which allows us to remove + python-matplotlib from dependencies. This is required because + python-numpy is in main, while python-matplotlib is in universe. + - debian/patches/ppc64el_cpu_config.patch: Add support for ppc64el. + + -- Matthias Klose Fri, 28 Mar 2014 12:18:54 +0100 + +python-numpy (1:1.8.1-1) unstable; urgency=medium + + * New upstream bugfix release + - remove upstream applied quantities-linspace.patch + - remove upstream applied restore-3kcompat-api.patch + + -- Julian Taylor Thu, 27 Mar 2014 19:29:12 +0100 + python-numpy (1:1.8.1~rc1-2ubuntu1) trusty; urgency=medium * Merge with Debian; remaining changes: diff -Nru python-numpy-1.8.1~rc1/debian/patches/quantities-linspace.patch python-numpy-1.8.1/debian/patches/quantities-linspace.patch --- python-numpy-1.8.1~rc1/debian/patches/quantities-linspace.patch 2014-03-18 18:54:54.000000000 +0000 +++ python-numpy-1.8.1/debian/patches/quantities-linspace.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,18 +0,0 @@ -Description: Fix linspace for use with physical quantities - The fix for issue 3504 led to errors when using linspace with the quantities package. -Origin: ffc0d2c498cb990ca07fe18f3a5b57bb9af48636 -Bug: https://github.com/numpy/numpy/pull/4503 -Applied-Upstream: 1.8.1 ---- a/numpy/core/function_base.py -+++ b/numpy/core/function_base.py -@@ -76,8 +76,8 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False): - num = int(num) - - # Convert float/complex array scalars to float, gh-3504 -- start = start + 0. -- stop = stop + 0. -+ start = start * 1. -+ stop = stop * 1. - - if num <= 0: - return array([], float) diff -Nru python-numpy-1.8.1~rc1/debian/patches/restore-3kcompat-api.patch python-numpy-1.8.1/debian/patches/restore-3kcompat-api.patch --- python-numpy-1.8.1~rc1/debian/patches/restore-3kcompat-api.patch 2014-03-06 19:57:58.000000000 +0000 +++ python-numpy-1.8.1/debian/patches/restore-3kcompat-api.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,147 +0,0 @@ -Author: Julian Taylor -Origin 0bfcb0e36e90f1300a27848ce7d419292d0a53c0 -Applied-Upstream: 1.8.1 -Description: restore api for file npy_PyFile_Dup and npy_PyFile_DupClose - ---- a/doc/release/1.8.1-notes.rst -+++ b/doc/release/1.8.1-notes.rst -@@ -47,3 +47,16 @@ Issues fixed - * gh-4225: fix log1p and exmp1 return for np.inf on windows compiler builds - * gh-4359: Fix infinite recursion in str.format of flex arrays - * gh-4145: Incorrect shape of broadcast result with the exponent operator -+ -+Deprecations -+============ -+ -+C-API -+~~~~~ -+ -+The utility function npy_PyFile_Dup and npy_PyFile_DupClose are broken by the -+internal buffering python 3 applies to its file objects. -+To fix this two new functions npy_PyFile_Dup2 and npy_PyFile_DupClose2 are -+declared in npy_3kcompat.h and the old functions are deprecated. -+Due to the fragile nature of these functions it is recommended to instead use -+the python API when possible. ---- a/numpy/core/include/numpy/npy_3kcompat.h -+++ b/numpy/core/include/numpy/npy_3kcompat.h -@@ -141,12 +141,11 @@ PyUnicode_Concat2(PyObject **left, PyObj - * PyFile_* compatibility - */ - #if defined(NPY_PY3K) -- - /* - * Get a FILE* handle to the file represented by the Python object - */ - static NPY_INLINE FILE* --npy_PyFile_Dup(PyObject *file, char *mode, npy_off_t *orig_pos) -+npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos) - { - int fd, fd2; - PyObject *ret, *os; -@@ -221,7 +220,7 @@ npy_PyFile_Dup(PyObject *file, char *mod - * Close the dup-ed file handle, and seek the Python one to the current position - */ - static NPY_INLINE int --npy_PyFile_DupClose(PyObject *file, FILE* handle, npy_off_t orig_pos) -+npy_PyFile_DupClose2(PyObject *file, FILE* handle, npy_off_t orig_pos) - { - int fd; - PyObject *ret; -@@ -269,10 +268,55 @@ npy_PyFile_Check(PyObject *file) - return 1; - } - -+/* -+ * DEPRECATED DO NOT USE -+ * use npy_PyFile_Dup2 instead -+ * this function will mess ups python3 internal file object buffering -+ * Get a FILE* handle to the file represented by the Python object -+ */ -+static NPY_INLINE FILE* -+npy_PyFile_Dup(PyObject *file, char *mode) -+{ -+ npy_off_t orig; -+ if (DEPRECATE("npy_PyFile_Dup is deprecated, use " -+ "npy_PyFile_Dup2") < 0) { -+ return NULL; -+ } -+ -+ return npy_PyFile_Dup2(file, mode, &orig); -+} -+ -+/* -+ * DEPRECATED DO NOT USE -+ * use npy_PyFile_DupClose2 instead -+ * this function will mess ups python3 internal file object buffering -+ * Close the dup-ed file handle, and seek the Python one to the current position -+ */ -+static NPY_INLINE int -+npy_PyFile_DupClose(PyObject *file, FILE* handle) -+{ -+ PyObject *ret; -+ Py_ssize_t position; -+ position = npy_ftell(handle); -+ fclose(handle); -+ -+ ret = PyObject_CallMethod(file, "seek", NPY_SSIZE_T_PYFMT "i", position, 0); -+ if (ret == NULL) { -+ return -1; -+ } -+ Py_DECREF(ret); -+ return 0; -+} -+ -+ - #else - --#define npy_PyFile_Dup(file, mode, orig_pos_p) PyFile_AsFile(file) --#define npy_PyFile_DupClose(file, handle, orig_pos) (0) -+/* DEPRECATED DO NOT USE */ -+#define npy_PyFile_Dup(file, mode) PyFile_AsFile(file) -+#define npy_PyFile_DupClose(file, handle) (0) -+/* use these */ -+#define npy_PyFile_Dup2(file, mode, orig_pos_p) PyFile_AsFile(file) -+#define npy_PyFile_DupClose2(file, handle, orig_pos) (0) - #define npy_PyFile_Check PyFile_Check - - #endif ---- a/numpy/core/src/multiarray/methods.c -+++ b/numpy/core/src/multiarray/methods.c -@@ -588,7 +588,7 @@ array_tofile(PyArrayObject *self, PyObje - own = 0; - } - -- fd = npy_PyFile_Dup(file, "wb", &orig_pos); -+ fd = npy_PyFile_Dup2(file, "wb", &orig_pos); - if (fd == NULL) { - PyErr_SetString(PyExc_IOError, - "first argument must be a string or open file"); -@@ -597,7 +597,7 @@ array_tofile(PyArrayObject *self, PyObje - if (PyArray_ToFile(self, fd, sep, format) < 0) { - goto fail; - } -- if (npy_PyFile_DupClose(file, fd, orig_pos) < 0) { -+ if (npy_PyFile_DupClose2(file, fd, orig_pos) < 0) { - goto fail; - } - if (own && npy_PyFile_CloseFile(file) < 0) { ---- a/numpy/core/src/multiarray/multiarraymodule.c -+++ b/numpy/core/src/multiarray/multiarraymodule.c -@@ -1995,7 +1995,7 @@ array_fromfile(PyObject *NPY_UNUSED(igno - Py_INCREF(file); - own = 0; - } -- fp = npy_PyFile_Dup(file, "rb", &orig_pos); -+ fp = npy_PyFile_Dup2(file, "rb", &orig_pos); - if (fp == NULL) { - PyErr_SetString(PyExc_IOError, - "first argument must be an open file"); -@@ -2007,7 +2007,7 @@ array_fromfile(PyObject *NPY_UNUSED(igno - } - ret = PyArray_FromFile(fp, type, (npy_intp) nin, sep); - -- if (npy_PyFile_DupClose(file, fp, orig_pos) < 0) { -+ if (npy_PyFile_DupClose2(file, fp, orig_pos) < 0) { - goto fail; - } - if (own && npy_PyFile_CloseFile(file) < 0) { diff -Nru python-numpy-1.8.1~rc1/debian/patches/series python-numpy-1.8.1/debian/patches/series --- python-numpy-1.8.1~rc1/debian/patches/series 2014-03-23 09:23:38.000000000 +0000 +++ python-numpy-1.8.1/debian/patches/series 2014-03-28 11:20:45.000000000 +0000 @@ -4,7 +4,5 @@ #05_fix_endianness_detection.patch 10_use_local_python.org_object.inv_sphinx.diff python3-soabi.patch -restore-3kcompat-api.patch -quantities-linspace.patch 20_disable-plot-extension.patch ppc64el_cpu_config.patch diff -Nru python-numpy-1.8.1~rc1/doc/release/1.8.1-notes.rst python-numpy-1.8.1/doc/release/1.8.1-notes.rst --- python-numpy-1.8.1~rc1/doc/release/1.8.1-notes.rst 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/doc/release/1.8.1-notes.rst 2014-03-25 19:43:24.000000000 +0000 @@ -47,3 +47,49 @@ * gh-4225: fix log1p and exmp1 return for np.inf on windows compiler builds * gh-4359: Fix infinite recursion in str.format of flex arrays * gh-4145: Incorrect shape of broadcast result with the exponent operator +* gh-4483: Fix commutativity of {dot,multiply,inner}(scalar, matrix_of_objs) +* gh-4466: Delay npyiter size check when size may change +* gh-4485: Buffered stride was erroneously marked fixed +* gh-4354: byte_bounds fails with datetime dtypes +* gh-4486: segfault/error converting from/to high-precision datetime64 objects +* gh-4428: einsum(None, None, None, None) causes segfault +* gh-4134: uninitialized use for for size 1 object reductions + +Changes +======= + +NDIter +~~~~~~ +When ``NpyIter_RemoveAxis`` is now called, the iterator range will be reset. + +When a multi index is being tracked and an iterator is not buffered, it is +possible to use ``NpyIter_RemoveAxis``. In this case an iterator can shrink +in size. Because the total size of an iterator is limited, the iterator +may be too large before these calls. In this case its size will be set to ``-1`` +and an error issued not at construction time but when removing the multi +index, setting the iterator range, or getting the next function. + +This has no effect on currently working code, but highlights the necessity +of checking for an error return if these conditions can occur. In most +cases the arrays being iterated are as large as the iterator so that such +a problem cannot occur. + +Optional reduced verbosity for np.distutils +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Set ``numpy.distutils.system_info.system_info.verbosity = 0`` and then +calls to ``numpy.distutils.system_info.get_info('blas_opt')`` will not +print anything on the output. This is mostly for other packages using +numpy.distutils. + +Deprecations +============ + +C-API +~~~~~ + +The utility function npy_PyFile_Dup and npy_PyFile_DupClose are broken by the +internal buffering python 3 applies to its file objects. +To fix this two new functions npy_PyFile_Dup2 and npy_PyFile_DupClose2 are +declared in npy_3kcompat.h and the old functions are deprecated. +Due to the fragile nature of these functions it is recommended to instead use +the python API when possible. diff -Nru python-numpy-1.8.1~rc1/numpy/core/function_base.py python-numpy-1.8.1/numpy/core/function_base.py --- python-numpy-1.8.1~rc1/numpy/core/function_base.py 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/function_base.py 2014-03-25 19:43:24.000000000 +0000 @@ -76,8 +76,8 @@ num = int(num) # Convert float/complex array scalars to float, gh-3504 - start = start + 0. - stop = stop + 0. + start = start * 1. + stop = stop * 1. if num <= 0: return array([], float) diff -Nru python-numpy-1.8.1~rc1/numpy/core/include/numpy/npy_3kcompat.h python-numpy-1.8.1/numpy/core/include/numpy/npy_3kcompat.h --- python-numpy-1.8.1~rc1/numpy/core/include/numpy/npy_3kcompat.h 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/include/numpy/npy_3kcompat.h 2014-03-25 19:43:24.000000000 +0000 @@ -141,12 +141,11 @@ * PyFile_* compatibility */ #if defined(NPY_PY3K) - /* * Get a FILE* handle to the file represented by the Python object */ static NPY_INLINE FILE* -npy_PyFile_Dup(PyObject *file, char *mode, npy_off_t *orig_pos) +npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos) { int fd, fd2; PyObject *ret, *os; @@ -221,7 +220,7 @@ * Close the dup-ed file handle, and seek the Python one to the current position */ static NPY_INLINE int -npy_PyFile_DupClose(PyObject *file, FILE* handle, npy_off_t orig_pos) +npy_PyFile_DupClose2(PyObject *file, FILE* handle, npy_off_t orig_pos) { int fd; PyObject *ret; @@ -269,10 +268,55 @@ return 1; } +/* + * DEPRECATED DO NOT USE + * use npy_PyFile_Dup2 instead + * this function will mess ups python3 internal file object buffering + * Get a FILE* handle to the file represented by the Python object + */ +static NPY_INLINE FILE* +npy_PyFile_Dup(PyObject *file, char *mode) +{ + npy_off_t orig; + if (DEPRECATE("npy_PyFile_Dup is deprecated, use " + "npy_PyFile_Dup2") < 0) { + return NULL; + } + + return npy_PyFile_Dup2(file, mode, &orig); +} + +/* + * DEPRECATED DO NOT USE + * use npy_PyFile_DupClose2 instead + * this function will mess ups python3 internal file object buffering + * Close the dup-ed file handle, and seek the Python one to the current position + */ +static NPY_INLINE int +npy_PyFile_DupClose(PyObject *file, FILE* handle) +{ + PyObject *ret; + Py_ssize_t position; + position = npy_ftell(handle); + fclose(handle); + + ret = PyObject_CallMethod(file, "seek", NPY_SSIZE_T_PYFMT "i", position, 0); + if (ret == NULL) { + return -1; + } + Py_DECREF(ret); + return 0; +} + + #else -#define npy_PyFile_Dup(file, mode, orig_pos_p) PyFile_AsFile(file) -#define npy_PyFile_DupClose(file, handle, orig_pos) (0) +/* DEPRECATED DO NOT USE */ +#define npy_PyFile_Dup(file, mode) PyFile_AsFile(file) +#define npy_PyFile_DupClose(file, handle) (0) +/* use these */ +#define npy_PyFile_Dup2(file, mode, orig_pos_p) PyFile_AsFile(file) +#define npy_PyFile_DupClose2(file, handle, orig_pos) (0) #define npy_PyFile_Check PyFile_Check #endif diff -Nru python-numpy-1.8.1~rc1/numpy/core/setup.py python-numpy-1.8.1/numpy/core/setup.py --- python-numpy-1.8.1~rc1/numpy/core/setup.py 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/setup.py 2014-03-25 19:43:24.000000000 +0000 @@ -530,6 +530,10 @@ def generate_numpyconfig_h(ext, build_dir): """Depends on config.h: generate_config_h has to be called before !""" + # put private include directory in build_dir on search path + # allows using code generation in headers headers + config.add_include_dirs(join(build_dir, "src", "private")) + target = join(build_dir, header_dir, '_numpyconfig.h') d = os.path.dirname(target) if not os.path.exists(d): @@ -683,12 +687,12 @@ subst_dict["posix_mathlib"] = posix_mlib subst_dict["msvc_mathlib"] = msvc_mlib + npymath_sources = [join('src', 'npymath', 'npy_math.c.src'), + join('src', 'npymath', 'ieee754.c.src'), + join('src', 'npymath', 'npy_math_complex.c.src'), + join('src', 'npymath', 'halffloat.c')] config.add_installed_library('npymath', - sources=[join('src', 'npymath', 'npy_math.c.src'), - join('src', 'npymath', 'ieee754.c.src'), - join('src', 'npymath', 'npy_math_complex.c.src'), - join('src', 'npymath', 'halffloat.c'), - get_mathlib_info], + sources=npymath_sources + [get_mathlib_info], install_dir='lib') config.add_npy_pkg_config("npymath.ini.in", "lib/npy-pkg-config", subst_dict) @@ -700,11 +704,15 @@ ####################################################################### # This library is created for the build but it is not installed + npysort_sources=[join('src', 'npysort', 'quicksort.c.src'), + join('src', 'npysort', 'mergesort.c.src'), + join('src', 'npysort', 'heapsort.c.src'), + join('src', 'private', 'npy_partition.h.src'), + join('src', 'npysort', 'selection.c.src'), + ] config.add_library('npysort', - sources = [join('src', 'npysort', 'quicksort.c.src'), - join('src', 'npysort', 'mergesort.c.src'), - join('src', 'npysort', 'heapsort.c.src'), - join('src', 'npysort', 'selection.c.src')]) + sources=npysort_sources, + include_dirs=[]) ####################################################################### @@ -779,7 +787,9 @@ join('include', 'numpy', 'ndarraytypes.h'), join('include', 'numpy', 'npy_1_7_deprecated_api.h'), join('include', 'numpy', '_numpyconfig.h.in'), - ] + # add library sources as distuils does not consider libraries + # dependencies + ] + npysort_sources + npymath_sources multiarray_src = [ join('src', 'multiarray', 'arrayobject.c'), @@ -890,8 +900,9 @@ umath_deps = [ generate_umath_py, + join('src', 'multiarray', 'common.h'), join('src', 'umath', 'simd.inc.src'), - join(codegen_dir, 'generate_ufunc_api.py')] + join(codegen_dir, 'generate_ufunc_api.py'),] + npymath_sources if not ENABLE_SEPARATE_COMPILATION: umath_deps.extend(umath_src) @@ -916,11 +927,12 @@ config.add_extension('scalarmath', sources = [join('src', 'scalarmathmodule.c.src'), + join('src', 'private', 'scalarmathmodule.h.src'), generate_config_h, generate_numpyconfig_h, generate_numpy_api, generate_ufunc_api], - depends = deps, + depends = deps + npymath_sources, libraries = ['npymath'], ) diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/common.c python-numpy-1.8.1/numpy/core/src/multiarray/common.c --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/common.c 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/common.c 2014-03-25 19:43:24.000000000 +0000 @@ -785,3 +785,64 @@ *lower_offset = lower; *upper_offset = upper; } + +/** + * Convert an array shape to a string such as "(1, 2)". + * + * @param Dimensionality of the shape + * @param npy_intp pointer to shape array + * @param String to append after the shape `(1, 2)%s`. + * + * @return Python unicode string + */ +NPY_NO_EXPORT PyObject * +convert_shape_to_string(npy_intp n, npy_intp *vals, char *ending) +{ + npy_intp i; + PyObject *ret, *tmp; + + /* + * Negative dimension indicates "newaxis", which can + * be discarded for printing if it's a leading dimension. + * Find the first non-"newaxis" dimension. + */ + for (i = 0; i < n && vals[i] < 0; i++); + + if (i == n) { + return PyUString_FromFormat("()%s", ending); + } + else { + ret = PyUString_FromFormat("(%" NPY_INTP_FMT, vals[i++]); + if (ret == NULL) { + return NULL; + } + } + + for (; i < n; ++i) { + if (vals[i] < 0) { + tmp = PyUString_FromString(",newaxis"); + } + else { + tmp = PyUString_FromFormat(",%" NPY_INTP_FMT, vals[i]); + } + if (tmp == NULL) { + Py_DECREF(ret); + return NULL; + } + + PyUString_ConcatAndDel(&ret, tmp); + if (ret == NULL) { + return NULL; + } + } + + if (i == 1) { + tmp = PyUString_FromFormat(",)%s", ending); + } + else { + tmp = PyUString_FromFormat(")%s", ending); + } + PyUString_ConcatAndDel(&ret, tmp); + return ret; +} + diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/common.h python-numpy-1.8.1/numpy/core/src/multiarray/common.h --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/common.h 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/common.h 2014-03-25 19:43:24.000000000 +0000 @@ -66,6 +66,9 @@ const npy_intp *dims, const npy_intp *strides, npy_intp *lower_offset, npy_intp *upper_offset); +NPY_NO_EXPORT PyObject * +convert_shape_to_string(npy_intp n, npy_intp *vals, char *ending); + /* * return true if pointer is aligned to 'alignment' */ diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/datetime.c python-numpy-1.8.1/numpy/core/src/multiarray/datetime.c --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/datetime.c 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/datetime.c 2014-03-25 19:43:24.000000000 +0000 @@ -1193,7 +1193,7 @@ } /* If something overflowed, make both num and denom 0 */ - if (denom == 0) { + if (denom == 0 || num == 0) { PyErr_Format(PyExc_OverflowError, "Integer overflow while computing the conversion " "factor between NumPy datetime units %s and %s", diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/methods.c python-numpy-1.8.1/numpy/core/src/multiarray/methods.c --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/methods.c 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/methods.c 2014-03-25 19:43:24.000000000 +0000 @@ -588,7 +588,7 @@ own = 0; } - fd = npy_PyFile_Dup(file, "wb", &orig_pos); + fd = npy_PyFile_Dup2(file, "wb", &orig_pos); if (fd == NULL) { PyErr_SetString(PyExc_IOError, "first argument must be a string or open file"); @@ -597,7 +597,7 @@ if (PyArray_ToFile(self, fd, sep, format) < 0) { goto fail; } - if (npy_PyFile_DupClose(file, fd, orig_pos) < 0) { + if (npy_PyFile_DupClose2(file, fd, orig_pos) < 0) { goto fail; } if (own && npy_PyFile_CloseFile(file) < 0) { diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/multiarraymodule.c python-numpy-1.8.1/numpy/core/src/multiarray/multiarraymodule.c --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/multiarraymodule.c 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/multiarraymodule.c 2014-03-25 19:43:24.000000000 +0000 @@ -1995,7 +1995,7 @@ Py_INCREF(file); own = 0; } - fp = npy_PyFile_Dup(file, "rb", &orig_pos); + fp = npy_PyFile_Dup2(file, "rb", &orig_pos); if (fp == NULL) { PyErr_SetString(PyExc_IOError, "first argument must be an open file"); @@ -2007,7 +2007,7 @@ } ret = PyArray_FromFile(fp, type, (npy_intp) nin, sep); - if (npy_PyFile_DupClose(file, fp, orig_pos) < 0) { + if (npy_PyFile_DupClose2(file, fp, orig_pos) < 0) { goto fail; } if (own && npy_PyFile_CloseFile(file) < 0) { @@ -2273,7 +2273,7 @@ /* Set the operands to NULL */ for (i = 0; i < nop; ++i) { - op[nop] = NULL; + op[i] = NULL; } /* Get the operands and build the subscript string */ diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/multiarray_tests.c.src python-numpy-1.8.1/numpy/core/src/multiarray/multiarray_tests.c.src --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/multiarray_tests.c.src 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/multiarray_tests.c.src 2014-03-25 19:43:23.000000000 +0000 @@ -478,7 +478,8 @@ } if ((it = (PyArrayIterObject *)\ - PyArray_BroadcastToShape(arr, mit->dimensions, mit->nd)) == NULL) { + PyArray_BroadcastToShape((PyObject *)arr, mit->dimensions, + mit->nd)) == NULL) { Py_DECREF(arr); return -1; @@ -689,6 +690,139 @@ #undef GET_PYBUF_FLAG +/* + * Test C-api level item getting. + */ +static PyObject * +array_indexing(PyObject *NPY_UNUSED(self), PyObject *args) +{ + int mode; + Py_ssize_t i; + PyObject *arr, *op = NULL; + + if (!PyArg_ParseTuple(args, "iOn|O", &mode, &arr, &i, &op)) { + return NULL; + } + + if (mode == 0) { + return PySequence_GetItem(arr, i); + } + if (mode == 1) { + if (PySequence_SetItem(arr, i, op) < 0) { + return NULL; + } + Py_RETURN_NONE; + } + + PyErr_SetString(PyExc_ValueError, + "invalid mode. 0: item 1: assign"); + return NULL; +} + + +/* + * Test nditer of too large arrays using remove axis, etc. + */ +static PyObject * +test_nditer_too_large(PyObject *NPY_UNUSED(self), PyObject *args) { + NpyIter *iter; + PyObject *array_tuple, *arr; + PyArrayObject *arrays[NPY_MAXARGS]; + npy_uint32 op_flags[NPY_MAXARGS]; + Py_ssize_t nop; + int i, axis, mode; + + npy_intp index[NPY_MAXARGS] = {0}; + char *msg; + + if (!PyArg_ParseTuple(args, "Oii", &array_tuple, &axis, &mode)) { + return NULL; + } + + if (!PyTuple_CheckExact(array_tuple)) { + PyErr_SetString(PyExc_ValueError, "tuple required as first argument"); + return NULL; + } + nop = PyTuple_Size(array_tuple); + if (nop > NPY_MAXARGS) { + PyErr_SetString(PyExc_ValueError, "tuple must be smaller then maxargs"); + return NULL; + } + + for (i=0; i < nop; i++) { + arr = PyTuple_GET_ITEM(array_tuple, i); + if (!PyArray_CheckExact(arr)) { + PyErr_SetString(PyExc_ValueError, "require base class ndarray"); + return NULL; + } + arrays[i] = (PyArrayObject *)arr; + op_flags[i] = NPY_ITER_READONLY; + } + + iter = NpyIter_MultiNew(nop, arrays, NPY_ITER_MULTI_INDEX | NPY_ITER_RANGED, + NPY_KEEPORDER, NPY_NO_CASTING, op_flags, NULL); + + if (iter == NULL) { + return NULL; + } + + /* Remove an axis (negative, do not remove any) */ + if (axis >= 0) { + if (!NpyIter_RemoveAxis(iter, axis)) { + goto fail; + } + } + + switch (mode) { + /* Test IterNext getting */ + case 0: + if (NpyIter_GetIterNext(iter, NULL) == NULL) { + goto fail; + } + break; + case 1: + if (NpyIter_GetIterNext(iter, &msg) == NULL) { + PyErr_SetString(PyExc_ValueError, msg); + goto fail; + } + break; + /* Test Multi Index removal */ + case 2: + if (!NpyIter_RemoveMultiIndex(iter)) { + goto fail; + } + break; + /* Test GotoMultiIndex (just 0 hardcoded) */ + case 3: + if (!NpyIter_GotoMultiIndex(iter, index)) { + goto fail; + } + break; + /* Test setting iterrange (hardcoded range of 0, 1) */ + case 4: + if (!NpyIter_ResetToIterIndexRange(iter, 0, 1, NULL)) { + goto fail; + } + break; + case 5: + if (!NpyIter_ResetToIterIndexRange(iter, 0, 1, &msg)) { + PyErr_SetString(PyExc_ValueError, msg); + goto fail; + } + break; + /* Do nothing */ + default: + break; + } + + NpyIter_Deallocate(iter); + Py_RETURN_NONE; + fail: + NpyIter_Deallocate(iter); + return NULL; +} + + static PyMethodDef Multiarray_TestsMethods[] = { {"test_neighborhood_iterator", test_neighborhood_iterator, @@ -713,6 +847,12 @@ {"get_buffer_info", get_buffer_info, METH_VARARGS, NULL}, + {"array_indexing", + array_indexing, + METH_VARARGS, NULL}, + {"test_nditer_too_large", + test_nditer_too_large, + METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/nditer_api.c python-numpy-1.8.1/numpy/core/src/multiarray/nditer_api.c --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/nditer_api.c 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/nditer_api.c 2014-03-25 19:43:23.000000000 +0000 @@ -14,6 +14,7 @@ /* Indicate that this .c file is allowed to include the header */ #define NPY_ITERATOR_IMPLEMENTATION_CODE #include "nditer_impl.h" +#include "scalarmathmodule.h" /* Internal helper functions private to this file */ static npy_intp @@ -127,13 +128,23 @@ perm[idim] = p; } - /* Adjust the iteration size */ - NIT_ITERSIZE(iter) /= NAD_SHAPE(axisdata_del); - /* Shift all the axisdata structures by one */ axisdata = NIT_INDEX_AXISDATA(axisdata_del, 1); memmove(axisdata_del, axisdata, (ndim-1-xdim)*sizeof_axisdata); + /* Adjust the iteration size and reset iterend */ + NIT_ITERSIZE(iter) = 1; + axisdata = NIT_AXISDATA(iter); + for (idim = 0; idim < ndim-1; ++idim) { + if (npy_mul_with_overflow_intp(&NIT_ITERSIZE(iter), + NIT_ITERSIZE(iter), NAD_SHAPE(axisdata))) { + NIT_ITERSIZE(iter) = -1; + break; + } + NIT_ADVANCE_AXISDATA(axisdata, 1); + } + NIT_ITEREND(iter) = NIT_ITERSIZE(iter); + /* Shrink the iterator */ NIT_NDIM(iter) = ndim - 1; /* If it is now 0-d fill the singleton dimension */ @@ -166,6 +177,11 @@ itflags = NIT_ITFLAGS(iter); if (itflags&NPY_ITFLAG_HASMULTIINDEX) { + if (NIT_ITERSIZE(iter) < 0) { + PyErr_SetString(PyExc_ValueError, "iterator is too large"); + return NPY_FAIL; + } + NIT_ITFLAGS(iter) = itflags & ~NPY_ITFLAG_HASMULTIINDEX; npyiter_coalesce_axes(iter); } @@ -349,6 +365,15 @@ } if (istart < 0 || iend > NIT_ITERSIZE(iter)) { + if (NIT_ITERSIZE(iter) < 0) { + if (errmsg == NULL) { + PyErr_SetString(PyExc_ValueError, "iterator is too large"); + } + else { + *errmsg = "iterator is too large"; + } + return NPY_FAIL; + } if (errmsg == NULL) { PyErr_Format(PyExc_ValueError, "Out-of-bounds range [%d, %d) passed to " @@ -454,6 +479,10 @@ } if (iterindex < NIT_ITERSTART(iter) || iterindex >= NIT_ITEREND(iter)) { + if (NIT_ITERSIZE(iter) < 0) { + PyErr_SetString(PyExc_ValueError, "iterator is too large"); + return NPY_FAIL; + } PyErr_SetString(PyExc_IndexError, "Iterator GotoMultiIndex called with a multi-index outside the " "restricted iteration range"); @@ -574,6 +603,10 @@ } if (iterindex < NIT_ITERSTART(iter) || iterindex >= NIT_ITEREND(iter)) { + if (NIT_ITERSIZE(iter) < 0) { + PyErr_SetString(PyExc_ValueError, "iterator is too large"); + return NPY_FAIL; + } PyErr_SetString(PyExc_IndexError, "Iterator GotoIterIndex called with an iterindex outside the " "iteration range."); @@ -752,8 +785,8 @@ if (itflags&NPY_ITFLAG_BUFFER) { NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter); /* The outer reduce loop */ - if (NBF_REDUCE_OUTERSTRIDES(bufferdata)[iop] == 0 && - NBF_REDUCE_POS(bufferdata) != 0) { + if (NBF_REDUCE_POS(bufferdata) != 0 && + NBF_REDUCE_OUTERSTRIDES(bufferdata)[iop] == 0) { return 0; } } @@ -1298,21 +1331,20 @@ out_strides[iop] = stride; } /* - * Otherwise it's a fixed stride if the stride is 0 - * for all inner dimensions of the reduction double loop + * Otherwise it's guaranteed to be a fixed stride if the + * stride is 0 for all the dimensions. */ else { NpyIter_AxisData *axisdata = axisdata0; - int idim, - reduce_outerdim = NBF_REDUCE_OUTERDIM(data); - for (idim = 0; idim < reduce_outerdim; ++idim) { + int idim; + for (idim = 0; idim < ndim; ++idim) { if (NAD_STRIDES(axisdata)[iop] != 0) { break; } NIT_ADVANCE_AXISDATA(axisdata, 1); } /* If all the strides were 0, the stride won't change */ - if (idim == reduce_outerdim) { + if (idim == ndim) { out_strides[iop] = stride; } else { @@ -1833,12 +1865,11 @@ *reduce_outeraxisdata = NULL; PyArray_Descr **dtypes = NIT_DTYPES(iter); - npy_intp transfersize = NBF_SIZE(bufferdata), - buffersize = NBF_BUFFERSIZE(bufferdata); + npy_intp transfersize = NBF_SIZE(bufferdata); npy_intp *strides = NBF_STRIDES(bufferdata), *ad_strides = NAD_STRIDES(axisdata); npy_intp sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop); - char **ptrs = NBF_PTRS(bufferdata), **ad_ptrs = NAD_PTRS(axisdata); + char **ad_ptrs = NAD_PTRS(axisdata); char **buffers = NBF_BUFFERS(bufferdata); char *buffer; diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/nditer_constr.c python-numpy-1.8.1/numpy/core/src/multiarray/nditer_constr.c --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/nditer_constr.c 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/nditer_constr.c 2014-03-25 19:43:23.000000000 +0000 @@ -16,6 +16,7 @@ #include "nditer_impl.h" #include "arrayobject.h" +#include "scalarmathmodule.h" /* Internal helper functions private to this file */ static int @@ -193,7 +194,7 @@ /* Allocate memory for the iterator */ iter = (NpyIter*) - PyArray_malloc(NIT_SIZEOF_ITERATOR(itflags, ndim, nop)); + PyObject_Malloc(NIT_SIZEOF_ITERATOR(itflags, ndim, nop)); NPY_IT_TIME_POINT(c_malloc); @@ -216,7 +217,7 @@ flags, op_flags, op_itflags, &NIT_MASKOP(iter))) { - PyArray_free(iter); + PyObject_Free(iter); return NULL; } /* Set resetindex to zero as well (it's just after the resetdataptr) */ @@ -260,6 +261,12 @@ buffersize = NIT_ITERSIZE(iter); } NBF_BUFFERSIZE(bufferdata) = buffersize; + + /* + * Initialize for use in FirstVisit, which may be called before + * the buffers are filled and the reduce pos is updated. + */ + NBF_REDUCE_POS(bufferdata) = 0; } /* @@ -548,7 +555,7 @@ /* Allocate memory for the new iterator */ size = NIT_SIZEOF_ITERATOR(itflags, ndim, nop); - newiter = (NpyIter*)PyArray_malloc(size); + newiter = (NpyIter*)PyObject_Malloc(size); /* Copy the raw values to the new iterator */ memcpy(newiter, iter, size); @@ -639,12 +646,20 @@ NPY_NO_EXPORT int NpyIter_Deallocate(NpyIter *iter) { - npy_uint32 itflags = NIT_ITFLAGS(iter); + npy_uint32 itflags; /*int ndim = NIT_NDIM(iter);*/ - int iop, nop = NIT_NOP(iter); + int iop, nop; + PyArray_Descr **dtype; + PyArrayObject **object; + + if (iter == NULL) { + return NPY_SUCCEED; + } - PyArray_Descr **dtype = NIT_DTYPES(iter); - PyArrayObject **object = NIT_OPERANDS(iter); + itflags = NIT_ITFLAGS(iter); + nop = NIT_NOP(iter); + dtype = NIT_DTYPES(iter); + object = NIT_OPERANDS(iter); /* Deallocate any buffers and buffering data */ if (itflags & NPY_ITFLAG_BUFFER) { @@ -655,9 +670,7 @@ /* buffers */ buffers = NBF_BUFFERS(bufferdata); for(iop = 0; iop < nop; ++iop, ++buffers) { - if (*buffers) { - PyArray_free(*buffers); - } + PyArray_free(*buffers); } /* read bufferdata */ transferdata = NBF_READTRANSFERDATA(bufferdata); @@ -682,7 +695,7 @@ } /* Deallocate the iterator memory */ - PyArray_free(iter); + PyObject_Free(iter); return NPY_SUCCEED; } @@ -1152,11 +1165,7 @@ /* Check the readonly/writeonly flags, and fill in op_itflags */ if (!npyiter_check_per_op_flags(op_flags[iop], &op_itflags[iop])) { - for (i = 0; i <= iop; ++i) { - Py_XDECREF(op[i]); - Py_XDECREF(op_dtype[i]); - } - return 0; + goto fail_iop; } /* Extract the operand which is for masked iteration */ @@ -1165,11 +1174,7 @@ PyErr_SetString(PyExc_ValueError, "Only one iterator operand may receive an " "ARRAYMASK flag"); - for (i = 0; i <= iop; ++i) { - Py_XDECREF(op[i]); - Py_XDECREF(op_dtype[i]); - } - return 0; + goto fail_iop; } maskop = iop; @@ -1190,11 +1195,7 @@ &op_dtype[iop], flags, op_flags[iop], &op_itflags[iop])) { - for (i = 0; i <= iop; ++i) { - Py_XDECREF(op[i]); - Py_XDECREF(op_dtype[i]); - } - return 0; + goto fail_iop; } } @@ -1208,13 +1209,9 @@ } } if (all_null) { - for (i = 0; i < nop; ++i) { - Py_XDECREF(op[i]); - Py_XDECREF(op_dtype[i]); - } PyErr_SetString(PyExc_ValueError, "At least one iterator operand must be non-NULL"); - return 0; + goto fail_nop; } } @@ -1223,17 +1220,26 @@ "An iterator operand was flagged as WRITEMASKED, " "but no ARRAYMASK operand was given to supply " "the mask"); - return 0; + goto fail_nop; } else if (!any_writemasked_ops && maskop >= 0) { PyErr_SetString(PyExc_ValueError, "An iterator operand was flagged as the ARRAYMASK, " "but no WRITEMASKED operands were given to use " "the mask"); - return 0; + goto fail_nop; } return 1; + + fail_nop: + iop = nop; + fail_iop: + for (i = 0; i < iop; ++i) { + Py_XDECREF(op[i]); + Py_XDECREF(op_dtype[i]); + } + return 0; } static const char * @@ -1255,54 +1261,6 @@ } } -static PyObject * -npyiter_shape_string(npy_intp n, npy_intp *vals, char *ending) -{ - npy_intp i; - PyObject *ret, *tmp; - - /* - * Negative dimension indicates "newaxis", which can - * be discarded for printing if it's a leading dimension. - * Find the first non-"newaxis" dimension. - */ - i = 0; - while (i < n && vals[i] < 0) { - ++i; - } - - if (i == n) { - return PyUString_FromFormat("()%s", ending); - } - else { - ret = PyUString_FromFormat("(%" NPY_INTP_FMT, vals[i++]); - if (ret == NULL) { - return NULL; - } - } - - for (; i < n; ++i) { - if (vals[i] < 0) { - tmp = PyUString_FromString(",newaxis"); - } - else { - tmp = PyUString_FromFormat(",%" NPY_INTP_FMT, vals[i]); - } - if (tmp == NULL) { - Py_DECREF(ret); - return NULL; - } - - PyUString_ConcatAndDel(&ret, tmp); - if (ret == NULL) { - return NULL; - } - } - - tmp = PyUString_FromFormat(")%s", ending); - PyUString_ConcatAndDel(&ret, tmp); - return ret; -} static int npyiter_check_casting(int nop, PyArrayObject **op, @@ -1556,6 +1514,7 @@ NAD_SHAPE(axisdata) = 1; NAD_INDEX(axisdata) = 0; memcpy(NAD_PTRS(axisdata), op_dataptr, NPY_SIZEOF_INTP*nop); + memset(NAD_STRIDES(axisdata), 0, NPY_SIZEOF_INTP*nop); } /* Now process the operands, filling in the axisdata */ @@ -1701,7 +1660,24 @@ /* Now fill in the ITERSIZE member */ NIT_ITERSIZE(iter) = 1; for (idim = 0; idim < ndim; ++idim) { - NIT_ITERSIZE(iter) *= broadcast_shape[idim]; + if (npy_mul_with_overflow_intp(&NIT_ITERSIZE(iter), + NIT_ITERSIZE(iter), broadcast_shape[idim])) { + if ((itflags & NPY_ITFLAG_HASMULTIINDEX) && + !(itflags & NPY_ITFLAG_HASINDEX) && + !(itflags & NPY_ITFLAG_BUFFER)) { + /* + * If RemoveAxis may be called, the size check is delayed + * until either the multi index is removed, or GetIterNext + * is called. + */ + NIT_ITERSIZE(iter) = -1; + break; + } + else { + PyErr_SetString(PyExc_ValueError, "iterator is too large"); + return 0; + } + } } /* The range defaults to everything */ NIT_ITERSTART(iter) = 0; @@ -1722,7 +1698,7 @@ } for (iop = 0; iop < nop; ++iop) { if (op[iop] != NULL) { - tmp = npyiter_shape_string(PyArray_NDIM(op[iop]), + tmp = convert_shape_to_string(PyArray_NDIM(op[iop]), PyArray_DIMS(op[iop]), " "); if (tmp == NULL) { @@ -1746,7 +1722,7 @@ return 0; } - tmp = npyiter_shape_string(ndim, itershape, ""); + tmp = convert_shape_to_string(ndim, itershape, ""); if (tmp == NULL) { Py_DECREF(errmsg); return 0; @@ -1769,7 +1745,7 @@ int *axes = op_axes[iop]; tmpstr = (axes == NULL) ? " " : "->"; - tmp = npyiter_shape_string(PyArray_NDIM(op[iop]), + tmp = convert_shape_to_string(PyArray_NDIM(op[iop]), PyArray_DIMS(op[iop]), tmpstr); if (tmp == NULL) { @@ -1791,7 +1767,7 @@ remdims[idim] = -1; } } - tmp = npyiter_shape_string(ndim, remdims, " "); + tmp = convert_shape_to_string(ndim, remdims, " "); if (tmp == NULL) { return 0; } @@ -1813,7 +1789,7 @@ return 0; } - tmp = npyiter_shape_string(ndim, itershape, ""); + tmp = convert_shape_to_string(ndim, itershape, ""); if (tmp == NULL) { Py_DECREF(errmsg); return 0; @@ -1849,7 +1825,7 @@ } /* Operand shape */ - tmp = npyiter_shape_string(PyArray_NDIM(op[iop]), + tmp = convert_shape_to_string(PyArray_NDIM(op[iop]), PyArray_DIMS(op[iop]), ""); if (tmp == NULL) { return 0; @@ -1882,7 +1858,7 @@ return 0; } - tmp = npyiter_shape_string(ndim, remdims, "]"); + tmp = convert_shape_to_string(ndim, remdims, "]"); if (tmp == NULL) { return 0; } @@ -1902,7 +1878,7 @@ } /* Broadcast shape */ - tmp = npyiter_shape_string(ndim, broadcast_shape, ""); + tmp = convert_shape_to_string(ndim, broadcast_shape, ""); if (tmp == NULL) { return 0; } diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/nditer_pywrap.c python-numpy-1.8.1/numpy/core/src/multiarray/nditer_pywrap.c --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/nditer_pywrap.c 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/nditer_pywrap.c 2014-03-25 19:43:23.000000000 +0000 @@ -37,12 +37,16 @@ char writeflags[NPY_MAXARGS]; }; -void npyiter_cache_values(NewNpyArrayIterObject *self) +static int npyiter_cache_values(NewNpyArrayIterObject *self) { NpyIter *iter = self->iter; /* iternext and get_multi_index functions */ self->iternext = NpyIter_GetIterNext(iter, NULL); + if (self->iternext == NULL) { + return -1; + } + if (NpyIter_HasMultiIndex(iter) && !NpyIter_HasDelayedBufAlloc(iter)) { self->get_multi_index = NpyIter_GetGetMultiIndex(iter, NULL); } @@ -67,6 +71,7 @@ /* The read/write settings */ NpyIter_GetReadFlags(iter, self->readflags); NpyIter_GetWriteFlags(iter, self->writeflags); + return 0; } static PyObject * @@ -742,9 +747,7 @@ &op_axes_in, PyArray_IntpConverter, &itershape, &buffersize)) { - if (itershape.ptr != NULL) { - PyDimMem_FREE(itershape.ptr); - } + PyDimMem_FREE(itershape.ptr); return -1; } @@ -805,7 +808,9 @@ } /* Cache some values for the member functions to use */ - npyiter_cache_values(self); + if (npyiter_cache_values(self) < 0) { + goto fail; + } if (NpyIter_GetIterSize(self->iter) == 0) { self->started = 1; @@ -816,9 +821,7 @@ self->finished = 0; } - if (itershape.ptr != NULL) { - PyDimMem_FREE(itershape.ptr); - } + PyDimMem_FREE(itershape.ptr); /* Release the references we got to the ops and dtypes */ for (iop = 0; iop < nop; ++iop) { @@ -829,9 +832,7 @@ return 0; fail: - if (itershape.ptr != NULL) { - PyDimMem_FREE(itershape.ptr); - } + PyDimMem_FREE(itershape.ptr); for (iop = 0; iop < nop; ++iop) { Py_XDECREF(op[iop]); Py_XDECREF(op_request_dtypes[iop]); @@ -1074,7 +1075,10 @@ } /* Cache some values for the member functions to use */ - npyiter_cache_values(iter); + if (npyiter_cache_values(iter) < 0) { + Py_DECREF(ret); + goto fail; + } if (NpyIter_GetIterSize(iter->iter) == 0) { iter->started = 1; @@ -1248,7 +1252,10 @@ } /* Cache some values for the member functions to use */ - npyiter_cache_values(iter); + if (npyiter_cache_values(iter) < 0) { + Py_DECREF(iter); + return NULL; + } iter->started = self->started; iter->finished = self->finished; @@ -1293,7 +1300,9 @@ return NULL; } /* RemoveAxis invalidates cached values */ - npyiter_cache_values(self); + if (npyiter_cache_values(self) < 0) { + return NULL; + } /* RemoveAxis also resets the iterator */ if (NpyIter_GetIterSize(self->iter) == 0) { self->started = 1; diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/multiarray/nditer_templ.c.src python-numpy-1.8.1/numpy/core/src/multiarray/nditer_templ.c.src --- python-numpy-1.8.1~rc1/numpy/core/src/multiarray/nditer_templ.c.src 2014-03-02 14:04:27.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/multiarray/nditer_templ.c.src 2014-03-25 19:43:23.000000000 +0000 @@ -347,6 +347,16 @@ int ndim = NIT_NDIM(iter); int nop = NIT_NOP(iter); + if (NIT_ITERSIZE(iter) < 0) { + if (errmsg == NULL) { + PyErr_SetString(PyExc_ValueError, "iterator is too large"); + } + else { + *errmsg = "iterator is too large"; + } + return NULL; + } + /* * When there is just one iteration and buffering is disabled * the iternext function is very simple. diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/private/npy_partition.h python-numpy-1.8.1/numpy/core/src/private/npy_partition.h --- python-numpy-1.8.1~rc1/numpy/core/src/private/npy_partition.h 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/private/npy_partition.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,558 +0,0 @@ - -/* - ***************************************************************************** - ** This file was autogenerated from a template DO NOT EDIT!!!! ** - ** Changes should be made to the original source (.src) file ** - ***************************************************************************** - */ - -#line 1 -/* - ***************************************************************************** - ** IMPORTANT NOTE for npy_partition.h.src -> npy_partition.h ** - ***************************************************************************** - * The template file loops.h.src is not automatically converted into - * loops.h by the build system. If you edit this file, you must manually - * do the conversion using numpy/distutils/conv_template.py from the - * command line as follows: - * - * $ cd - * $ python numpy/distutils/conv_template.py numpy/core/src/private/npy_partition.h.src - * $ - */ - - -#ifndef __NPY_PARTITION_H__ -#define __NPY_PARTITION_H__ - - -#include "npy_sort.h" - -/* Python include is for future object sorts */ -#include -#include -#include - -#define NPY_MAX_PIVOT_STACK 50 - - -#line 43 - -int introselect_bool(npy_bool *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_bool(npy_bool *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_byte(npy_byte *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_byte(npy_byte *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_ubyte(npy_ubyte *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_ubyte(npy_ubyte *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_short(npy_short *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_short(npy_short *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_ushort(npy_ushort *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_ushort(npy_ushort *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_int(npy_int *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_int(npy_int *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_uint(npy_uint *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_uint(npy_uint *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_long(npy_long *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_long(npy_long *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_ulong(npy_ulong *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_ulong(npy_ulong *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_longlong(npy_longlong *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_longlong(npy_longlong *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_ulonglong(npy_ulonglong *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_ulonglong(npy_ulonglong *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_half(npy_ushort *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_half(npy_ushort *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_float(npy_float *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_float(npy_float *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_double(npy_double *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_double(npy_double *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_longdouble(npy_longdouble *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_longdouble(npy_longdouble *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_cfloat(npy_cfloat *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_cfloat(npy_cfloat *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_cdouble(npy_cdouble *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_cdouble(npy_cdouble *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - -#line 43 - -int introselect_clongdouble(npy_clongdouble *v, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); -int aintroselect_clongdouble(npy_clongdouble *v, npy_intp* tosort, npy_intp num, - npy_intp kth, - npy_intp * pivots, - npy_intp * npiv, - void *NOT_USED); - - - - -int introselect_string(npy_char *vec, npy_intp cnt, npy_intp kth, PyArrayObject *arr); -int aintroselect_string(npy_char *vec, npy_intp *ind, npy_intp cnt, npy_intp kth, void *null); - - -int introselect_unicode(npy_ucs4 *vec, npy_intp cnt, npy_intp kth, PyArrayObject *arr); -int aintroselect_unicode(npy_ucs4 *vec, npy_intp *ind, npy_intp cnt, npy_intp kth, void *null); - -int npy_introselect(void *base, size_t num, size_t size, size_t kth, npy_comparator cmp); - -typedef struct { - enum NPY_TYPES typenum; - PyArray_PartitionFunc * part[NPY_NSELECTS]; - PyArray_ArgPartitionFunc * argpart[NPY_NSELECTS]; -} part_map; - -static part_map _part_map[] = { -#line 87 - { - NPY_BOOL, - { - (PyArray_PartitionFunc *)&introselect_bool, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_bool, - } - }, - -#line 87 - { - NPY_BYTE, - { - (PyArray_PartitionFunc *)&introselect_byte, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_byte, - } - }, - -#line 87 - { - NPY_UBYTE, - { - (PyArray_PartitionFunc *)&introselect_ubyte, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_ubyte, - } - }, - -#line 87 - { - NPY_SHORT, - { - (PyArray_PartitionFunc *)&introselect_short, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_short, - } - }, - -#line 87 - { - NPY_USHORT, - { - (PyArray_PartitionFunc *)&introselect_ushort, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_ushort, - } - }, - -#line 87 - { - NPY_INT, - { - (PyArray_PartitionFunc *)&introselect_int, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_int, - } - }, - -#line 87 - { - NPY_UINT, - { - (PyArray_PartitionFunc *)&introselect_uint, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_uint, - } - }, - -#line 87 - { - NPY_LONG, - { - (PyArray_PartitionFunc *)&introselect_long, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_long, - } - }, - -#line 87 - { - NPY_ULONG, - { - (PyArray_PartitionFunc *)&introselect_ulong, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_ulong, - } - }, - -#line 87 - { - NPY_LONGLONG, - { - (PyArray_PartitionFunc *)&introselect_longlong, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_longlong, - } - }, - -#line 87 - { - NPY_ULONGLONG, - { - (PyArray_PartitionFunc *)&introselect_ulonglong, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_ulonglong, - } - }, - -#line 87 - { - NPY_HALF, - { - (PyArray_PartitionFunc *)&introselect_half, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_half, - } - }, - -#line 87 - { - NPY_FLOAT, - { - (PyArray_PartitionFunc *)&introselect_float, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_float, - } - }, - -#line 87 - { - NPY_DOUBLE, - { - (PyArray_PartitionFunc *)&introselect_double, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_double, - } - }, - -#line 87 - { - NPY_LONGDOUBLE, - { - (PyArray_PartitionFunc *)&introselect_longdouble, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_longdouble, - } - }, - -#line 87 - { - NPY_CFLOAT, - { - (PyArray_PartitionFunc *)&introselect_cfloat, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_cfloat, - } - }, - -#line 87 - { - NPY_CDOUBLE, - { - (PyArray_PartitionFunc *)&introselect_cdouble, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_cdouble, - } - }, - -#line 87 - { - NPY_CLONGDOUBLE, - { - (PyArray_PartitionFunc *)&introselect_clongdouble, - }, - { - (PyArray_ArgPartitionFunc *)&aintroselect_clongdouble, - } - }, - -}; - - -static NPY_INLINE PyArray_PartitionFunc * -get_partition_func(int type, NPY_SELECTKIND which) -{ - npy_intp i; - if (which >= NPY_NSELECTS) { - return NULL; - } - for (i = 0; i < sizeof(_part_map)/sizeof(_part_map[0]); i++) { - if (type == _part_map[i].typenum) { - return _part_map[i].part[which]; - } - } - return NULL; -} - - -static NPY_INLINE PyArray_ArgPartitionFunc * -get_argpartition_func(int type, NPY_SELECTKIND which) -{ - npy_intp i; - if (which >= NPY_NSELECTS) { - return NULL; - } - for (i = 0; i < sizeof(_part_map)/sizeof(_part_map[0]); i++) { - if (type == _part_map[i].typenum) { - return _part_map[i].argpart[which]; - } - } - return NULL; -} - -#endif diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/private/npy_partition.h.src python-numpy-1.8.1/numpy/core/src/private/npy_partition.h.src --- python-numpy-1.8.1~rc1/numpy/core/src/private/npy_partition.h.src 1970-01-01 00:00:00.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/private/npy_partition.h.src 2014-03-25 19:43:24.000000000 +0000 @@ -0,0 +1,131 @@ +/* + ***************************************************************************** + ** IMPORTANT NOTE for npy_partition.h.src -> npy_partition.h ** + ***************************************************************************** + * The template file loops.h.src is not automatically converted into + * loops.h by the build system. If you edit this file, you must manually + * do the conversion using numpy/distutils/conv_template.py from the + * command line as follows: + * + * $ cd + * $ python numpy/distutils/conv_template.py numpy/core/src/private/npy_partition.h.src + * $ + */ + + +#ifndef __NPY_PARTITION_H__ +#define __NPY_PARTITION_H__ + + +#include "npy_sort.h" + +/* Python include is for future object sorts */ +#include +#include +#include + +#define NPY_MAX_PIVOT_STACK 50 + + +/**begin repeat + * + * #TYPE = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, + * LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, + * CFLOAT, CDOUBLE, CLONGDOUBLE# + * #suff = bool, byte, ubyte, short, ushort, int, uint, long, ulong, + * longlong, ulonglong, half, float, double, longdouble, + * cfloat, cdouble, clongdouble# + * #type = npy_bool, npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, + * npy_uint, npy_long, npy_ulong, npy_longlong, npy_ulonglong, + * npy_ushort, npy_float, npy_double, npy_longdouble, npy_cfloat, + * npy_cdouble, npy_clongdouble# + */ + +int introselect_@suff@(@type@ *v, npy_intp num, + npy_intp kth, + npy_intp * pivots, + npy_intp * npiv, + void *NOT_USED); +int aintroselect_@suff@(@type@ *v, npy_intp* tosort, npy_intp num, + npy_intp kth, + npy_intp * pivots, + npy_intp * npiv, + void *NOT_USED); + + +/**end repeat**/ + +int introselect_string(npy_char *vec, npy_intp cnt, npy_intp kth, PyArrayObject *arr); +int aintroselect_string(npy_char *vec, npy_intp *ind, npy_intp cnt, npy_intp kth, void *null); + + +int introselect_unicode(npy_ucs4 *vec, npy_intp cnt, npy_intp kth, PyArrayObject *arr); +int aintroselect_unicode(npy_ucs4 *vec, npy_intp *ind, npy_intp cnt, npy_intp kth, void *null); + +int npy_introselect(void *base, size_t num, size_t size, size_t kth, npy_comparator cmp); + +typedef struct { + enum NPY_TYPES typenum; + PyArray_PartitionFunc * part[NPY_NSELECTS]; + PyArray_ArgPartitionFunc * argpart[NPY_NSELECTS]; +} part_map; + +static part_map _part_map[] = { +/**begin repeat + * + * #TYPE = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, + * LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, + * CFLOAT, CDOUBLE, CLONGDOUBLE# + * #suff = bool, byte, ubyte, short, ushort, int, uint, long, ulong, + * longlong, ulonglong, half, float, double, longdouble, + * cfloat, cdouble, clongdouble# + * #type = npy_bool, npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, + * npy_uint, npy_long, npy_ulong, npy_longlong, npy_ulonglong, + * npy_ushort, npy_float, npy_double, npy_longdouble, npy_cfloat, + * npy_cdouble, npy_clongdouble# + */ + { + NPY_@TYPE@, + { + (PyArray_PartitionFunc *)&introselect_@suff@, + }, + { + (PyArray_ArgPartitionFunc *)&aintroselect_@suff@, + } + }, +/**end repeat**/ +}; + + +static NPY_INLINE PyArray_PartitionFunc * +get_partition_func(int type, NPY_SELECTKIND which) +{ + npy_intp i; + if (which >= NPY_NSELECTS) { + return NULL; + } + for (i = 0; i < sizeof(_part_map)/sizeof(_part_map[0]); i++) { + if (type == _part_map[i].typenum) { + return _part_map[i].part[which]; + } + } + return NULL; +} + + +static NPY_INLINE PyArray_ArgPartitionFunc * +get_argpartition_func(int type, NPY_SELECTKIND which) +{ + npy_intp i; + if (which >= NPY_NSELECTS) { + return NULL; + } + for (i = 0; i < sizeof(_part_map)/sizeof(_part_map[0]); i++) { + if (type == _part_map[i].typenum) { + return _part_map[i].argpart[which]; + } + } + return NULL; +} + +#endif diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/private/scalarmathmodule.h.src python-numpy-1.8.1/numpy/core/src/private/scalarmathmodule.h.src --- python-numpy-1.8.1~rc1/numpy/core/src/private/scalarmathmodule.h.src 1970-01-01 00:00:00.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/private/scalarmathmodule.h.src 2014-03-25 19:43:23.000000000 +0000 @@ -0,0 +1,42 @@ +/* + * some overflow checking integer arithmetic + */ +#include + +#ifndef __NPY_SCALARMATHMODULE_H__ +#define __NPY_SCALARMATHMODULE_H__ + +/**begin repeat + * #name = int, uint, long, ulong, + * longlong, ulonglong, intp# + * #type = npy_int, npy_uint, npy_long, npy_ulong, + * npy_longlong, npy_ulonglong, npy_intp# + * #MAX = NPY_MAX_INT, NPY_MAX_UINT, NPY_MAX_LONG, NPY_MAX_ULONG, + * NPY_MAX_LONGLONG, NPY_MAX_ULONGLONG, NPY_MAX_INTP# + */ + +/* + * writes result of a * b into r + * returns 1 if a * b overflowed else returns 0 + */ +static NPY_INLINE int +npy_mul_with_overflow_@name@(@type@ * r, @type@ a, @type@ b) +{ + const @type@ half_sz = (((@type@)1 << (sizeof(a) * 8 / 2)) - 1); + + *r = a * b; + /* + * avoid expensive division on common no overflow case + * could be improved via compiler intrinsics e.g. via clang + * __builtin_mul_with_overflow, gcc __int128 or cpu overflow flags + */ + if (NPY_UNLIKELY((a | b) >= half_sz) && + a != 0 && b > @MAX@ / a) { + return 1; + } + + return 0; +} +/**end repeat**/ + +#endif diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/scalarmathmodule.c.src python-numpy-1.8.1/numpy/core/src/scalarmathmodule.c.src --- python-numpy-1.8.1~rc1/numpy/core/src/scalarmathmodule.c.src 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/scalarmathmodule.c.src 2014-03-25 19:43:23.000000000 +0000 @@ -16,129 +16,7 @@ #include "npy_pycompat.h" #include "numpy/halffloat.h" - -/** numarray adapted routines.... **/ - -/* - * Note that the C standard requires signed/unsigned integral - * types of the same rank to have the same width. - */ - -#if NPY_SIZEOF_LONGLONG == 64 - -static int -ulonglong_overflow(npy_ulonglong a, npy_ulonglong b) -{ - npy_ulonglong ah, al, bh, bl, w, x, y, z; - unsigned long long mask = 0xFFFFFFFFL; - - ah = (a >> 32); - al = (a & mask); - bh = (b >> 32); - bl = (b & mask); - - /* 128-bit product: z*2**64 + (x+y)*2**32 + w */ - w = al*bl; - x = bh*al; - y = ah*bl; - z = ah*bh; - - /* *c = ((x + y)<<32) + w; */ - return z || (x >> 32) || (y >> 32) || - (((x & mask) + (y & mask) + (w >> 32)) >> 32); -} - -static int -slonglong_overflow(npy_longlong a0, npy_longlong b0) -{ - npy_ulonglong a, b; - npy_ulonglong ah, al, bh, bl, w, x, y, z; - long long mask = 0xFFFFFFFFL; - - a = (a0 < 0) ? -a0 : a0; - b = (b0 < 0) ? -b0 : b0; - - ah = (a >> 32); - al = (a & mask); - bh = (b >> 32); - bl = (b & mask); - - w = al*bl; - x = bh*al; - y = ah*bl; - z = ah*bh; - - return z || (x >> 31) || (y >> 31) || - (((x & mask) + (y & mask) + (w >> 32)) >> 31); -} - -#elif NPY_SIZEOF_LONGLONG == 128 - -static int -ulonglong_overflow(npy_ulonglong a, npy_ulonglong b) -{ - npy_ulonglong ah, al, bh, bl, w, x, y, z; - unsigned long long mask = 0xFFFFFFFFFFFFFFFFL; - - ah = (a >> 64); - al = (a & mask); - bh = (b >> 64); - bl = (b & mask); - - /* 128-bit product: z*2**64 + (x+y)*2**32 + w */ - w = al*bl; - x = bh*al; - y = ah*bl; - z = ah*bh; - - /* *c = ((x + y)<<32) + w; */ - return z || (x >> 64) || (y >> 64) || - (((x & mask) + (y & mask) + (w >> 64)) >> 64); -} - -static int -slonglong_overflow(npy_longlong a0, npy_longlong b0) -{ - npy_ulonglong a, b; - npy_ulonglong ah, al, bh, bl, w, x, y, z; - long long mask = 0xFFFFFFFFFFFFFFFFL; - - a = (a0 < 0) ? -a0 : a0; - b = (b0 < 0) ? -b0 : b0; - - ah = (a >> 64); - al = (a & mask); - bh = (b >> 64); - bl = (b & mask); - - w = al*bl; - x = bh*al; - y = ah*bl; - z = ah*bh; - - return z || (x >> 63) || (y >> 63) || - (((x & mask) + (y & mask) + (w >> 64)) >> 63); -} - -#else - -static int -ulonglong_overflow(npy_ulonglong NPY_UNUSED(a), npy_ulonglong NPY_UNUSED(b)) -{ - return 0; -} - -static int -slonglong_overflow(npy_longlong NPY_UNUSED(a0), npy_longlong NPY_UNUSED(b0)) -{ - return 0; -} - -#endif - - -/** end direct numarray code **/ - +#include "scalarmathmodule.h" /* Basic operations: * @@ -245,13 +123,11 @@ * #type = npy_int, npy_uint, npy_long, npy_ulong, * npy_longlong, npy_ulonglong# * #SIZE = INT*2, LONG*2, LONGLONG*2# - * #char = (s, u)*3# */ #if NPY_SIZEOF_LONGLONG == NPY_SIZEOF_@SIZE@ static void @name@_ctype_multiply(@type@ a, @type@ b, @type@ *out) { - *out = a * b; - if (@char@longlong_overflow(a, b)) { + if (npy_mul_with_overflow_@name@(out, a, b)) { npy_set_floatstatus_overflow(); } return; diff -Nru python-numpy-1.8.1~rc1/numpy/core/src/umath/ufunc_object.c python-numpy-1.8.1/numpy/core/src/umath/ufunc_object.c --- python-numpy-1.8.1~rc1/numpy/core/src/umath/ufunc_object.c 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/src/umath/ufunc_object.c 2014-03-25 19:43:24.000000000 +0000 @@ -2090,6 +2090,11 @@ */ inner_strides = (npy_intp *)PyArray_malloc( NPY_SIZEOF_INTP * (nop+core_dim_ixs_size)); + if (inner_strides == NULL) { + PyErr_NoMemory(); + retval = -1; + goto fail; + } /* Copy the strides after the first nop */ idim = nop; for (i = 0; i < nop; ++i) { @@ -2196,11 +2201,13 @@ PyErr_Format(PyExc_ValueError, "ufunc %s ", ufunc_name); + retval = -1; goto fail; default: PyErr_Format(PyExc_ValueError, "ufunc %s has an invalid identity for reduction", ufunc_name); + retval = -1; goto fail; } } @@ -2379,7 +2386,7 @@ */ if (nin == 2 && nout == 1 && dtypes[1]->type_num == NPY_OBJECT) { PyObject *_obj = PyTuple_GET_ITEM(args, 1); - if (!PyArray_CheckExact(_obj)) { + if (!PyArray_Check(_obj)) { double self_prio, other_prio; self_prio = PyArray_GetPriority(PyTuple_GET_ITEM(args, 0), NPY_SCALAR_PRIORITY); diff -Nru python-numpy-1.8.1~rc1/numpy/core/tests/test_datetime.py python-numpy-1.8.1/numpy/core/tests/test_datetime.py --- python-numpy-1.8.1~rc1/numpy/core/tests/test_datetime.py 2014-03-02 14:04:27.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/tests/test_datetime.py 2014-03-25 21:43:36.000000000 +0000 @@ -592,6 +592,15 @@ assert_raises(OverflowError, np.promote_types, np.dtype('m8[s]'), np.dtype('m8[as]')) + def test_cast_overflow(self): + # gh-4486 + def cast(): + numpy.datetime64("1971-01-01 00:00:00.000000000000000").astype("lpx', A, B) + tp = np.tensordot(A, B, axes=(0, 0)) + assert_equal(es, tp) + # The following is the original test case from the bug report, + # made repeatable by changing random arrays to aranges. + A = np.arange(3*3).reshape(3,3).astype(np.float64) + B = np.arange(3*3*64*64).reshape(3,3,64,64).astype(np.float32) + es = np.einsum ('cl,cpxy->lpxy', A,B) + tp = np.tensordot(A,B, axes=(0,0)) + assert_equal(es, tp) + + if __name__ == "__main__": run_module_suite() diff -Nru python-numpy-1.8.1~rc1/numpy/core/tests/test_function_base.py python-numpy-1.8.1/numpy/core/tests/test_function_base.py --- python-numpy-1.8.1~rc1/numpy/core/tests/test_function_base.py 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/tests/test_function_base.py 2014-03-25 19:43:24.000000000 +0000 @@ -4,20 +4,23 @@ from numpy import logspace, linspace, array class TestLogspace(TestCase): + def test_basic(self): y = logspace(0, 6) - assert_(len(y)==50) + assert_(len(y) == 50) y = logspace(0, 6, num=100) - assert_(y[-1] == 10**6) + assert_(y[-1] == 10 ** 6) y = logspace(0, 6, endpoint=0) - assert_(y[-1] < 10**6) + assert_(y[-1] < 10 ** 6) y = logspace(0, 6, num=7) assert_array_equal(y, [1, 10, 100, 1e3, 1e4, 1e5, 1e6]) + class TestLinspace(TestCase): + def test_basic(self): y = linspace(0, 10) - assert_(len(y)==50) + assert_(len(y) == 50) y = linspace(2, 10, num=100) assert_(y[-1] == 10) y = linspace(2, 10, endpoint=0) @@ -57,3 +60,36 @@ t2 = array([ 0.0+1.j , 2.5+0.75j, 5.0+0.5j , 7.5+0.25j, 10.0+0.j]) assert_equal(lim1, t1) assert_equal(lim2, t2) + + def test_physical_quantities(self): + class PhysicalQuantity(float): + def __new__(cls, value): + return float.__new__(cls, value) + + def __add__(self, x): + assert_(isinstance(x, PhysicalQuantity)) + return PhysicalQuantity(float(x) + float(self)) + __radd__ = __add__ + + def __sub__(self, x): + assert_(isinstance(x, PhysicalQuantity)) + return PhysicalQuantity(float(self) - float(x)) + + def __rsub__(self, x): + assert_(isinstance(x, PhysicalQuantity)) + return PhysicalQuantity(float(x) - float(self)) + + def __mul__(self, x): + return PhysicalQuantity(float(x) * float(self)) + __rmul__ = __mul__ + + def __div__(self, x): + return PhysicalQuantity(float(self) / float(x)) + + def __rdiv__(self, x): + return PhysicalQuantity(float(x) / float(self)) + + + a = PhysicalQuantity(0.0) + b = PhysicalQuantity(1.0) + assert_equal(linspace(a, b), linspace(0.0, 1.0)) diff -Nru python-numpy-1.8.1~rc1/numpy/core/tests/test_multiarray.py python-numpy-1.8.1/numpy/core/tests/test_multiarray.py --- python-numpy-1.8.1~rc1/numpy/core/tests/test_multiarray.py 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/tests/test_multiarray.py 2014-03-25 21:43:36.000000000 +0000 @@ -424,22 +424,29 @@ assert_equal(np.count_nonzero(d), 0) # true for ieee floats assert_equal(d.sum(), 0) - - d = np.zeros((30 * 1024**2,), dtype=dt) - assert_equal(np.count_nonzero(d), 0) - assert_equal(d.sum(), 0) + assert_(not d.any()) d = np.zeros(2, dtype='(2,4)i4') assert_equal(np.count_nonzero(d), 0) assert_equal(d.sum(), 0) + assert_(not d.any()) d = np.zeros(2, dtype='4i4') assert_equal(np.count_nonzero(d), 0) assert_equal(d.sum(), 0) + assert_(not d.any()) d = np.zeros(2, dtype='(2,4)i4, (2,4)i4') assert_equal(np.count_nonzero(d), 0) + @dec.slow + def test_zeros_big(self): + # test big array as they might be allocated different by the sytem + types = np.typecodes['AllInteger'] + np.typecodes['AllFloat'] + for dt in types: + d = np.zeros((30 * 1024**2,), dtype=dt) + assert_(not d.any()) + def test_zeros_obj(self): # test initialization from PyLong(0) d = np.zeros((13,), dtype=object) @@ -2822,6 +2829,23 @@ r = np.empty((1024, 32), dtype=int) assert_raises(ValueError, dot, f, v, r) + def test_dot_scalar_and_matrix_of_objects(self): + # Ticket #2469 + arr = np.matrix([1, 2], dtype=object) + desired = np.matrix([[3, 6]], dtype=object) + assert_equal(np.dot(arr, 3), desired) + assert_equal(np.dot(3, arr), desired) + + +class TestInner(TestCase): + + def test_inner_scalar_and_matrix_of_objects(self): + # Ticket #4482 + arr = np.matrix([1, 2], dtype=object) + desired = np.matrix([[3, 6]], dtype=object) + assert_equal(np.inner(arr, 3), desired) + assert_equal(np.inner(3, arr), desired) + class TestSummarization(TestCase): def test_1d(self): diff -Nru python-numpy-1.8.1~rc1/numpy/core/tests/test_nditer.py python-numpy-1.8.1/numpy/core/tests/test_nditer.py --- python-numpy-1.8.1~rc1/numpy/core/tests/test_nditer.py 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/tests/test_nditer.py 2014-03-25 19:43:23.000000000 +0000 @@ -6,7 +6,7 @@ from numpy import array, arange, nditer, all from numpy.compat import asbytes, sixu from numpy.testing import * - +from numpy.core.multiarray_tests import test_nditer_too_large def iter_multi_index(i): @@ -657,9 +657,9 @@ # The message should contain "shape->remappedshape" for each operand assert_(msg.find('(2,3)->(2,3)') >= 0, 'Message "%s" doesn\'t contain operand shape (2,3)->(2,3)' % msg) - assert_(msg.find('(2)->(2,newaxis)') >= 0, + assert_(msg.find('(2,)->(2,newaxis)') >= 0, ('Message "%s" doesn\'t contain remapped operand shape' + - '(2)->(2,newaxis)') % msg) + '(2,)->(2,newaxis)') % msg) # The message should contain the itershape parameter assert_(msg.find('(4,3)') >= 0, 'Message "%s" doesn\'t contain itershape parameter (4,3)' % msg) @@ -2579,5 +2579,52 @@ assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) +def test_iter_too_large(): + # The total size of the iterator must not exceed the maximum intp due + # to broadcasting. Dividing by 1024 will keep it small enough to + # give a legal array. + size = np.iinfo(np.intp).max // 1024 + arr = np.lib.stride_tricks.as_strided(np.zeros(1), (size,), (0,)) + assert_raises(ValueError, nditer, (arr, arr[:, None])) + # test the same for multiindex. That may get more interesting when + # removing 0 dimensional axis is allowed (since an iterator can grow then) + assert_raises(ValueError, nditer, + (arr, arr[:, None]), flags=['multi_index']) + + +def test_iter_too_large_with_multiindex(): + # When a multi index is being tracked, the error is delayed this + # checks the delayed error messages and getting below that by + # removing an axis. + base_size = 2**10 + num = 1 + while base_size**num < np.iinfo(np.intp).max: + num += 1 + + shape_template = [1, 1] * num + arrays = [] + for i in range(num): + shape = shape_template[:] + shape[i * 2] = 2**10 + arrays.append(np.empty(shape)) + arrays = tuple(arrays) + + # arrays are now too large to be broadcast. The different modes test + # different nditer functionality with or without GIL. + for mode in range(6): + assert_raises(ValueError, test_nditer_too_large, arrays, -1, mode) + # but if we do nothing with the nditer, it can be constructed: + test_nditer_too_large(arrays, -1, 7) + + # When an axis is removed, things should work again (half the time): + for i in range(num): + for mode in range(6): + # an axis with size 1024 is removed: + test_nditer_too_large(arrays, i*2, mode) + # an axis with size 1 is removed: + assert_raises(ValueError, test_nditer_too_large, + arrays, i*2 + 1, mode) + + if __name__ == "__main__": run_module_suite() diff -Nru python-numpy-1.8.1~rc1/numpy/core/tests/test_ufunc.py python-numpy-1.8.1/numpy/core/tests/test_ufunc.py --- python-numpy-1.8.1~rc1/numpy/core/tests/test_ufunc.py 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/core/tests/test_ufunc.py 2014-03-25 19:43:24.000000000 +0000 @@ -534,6 +534,15 @@ assert_equal(np.all(a), False) assert_equal(np.max(a), True) assert_equal(np.min(a), False) + assert_equal(np.array([[1]], dtype=object).sum(), 1) + assert_equal(np.array([[[1, 2]]], dtype=object).sum((0, 1)), [1, 2]) + + def test_object_scalar_multiply(self): + # Tickets #2469 and #4482 + arr = np.matrix([1, 2], dtype=object) + desired = np.matrix([[3, 6]], dtype=object) + assert_equal(np.multiply(arr, 3), desired) + assert_equal(np.multiply(3, arr), desired) def test_zerosize_reduction(self): # Test with default dtype and object dtype diff -Nru python-numpy-1.8.1~rc1/numpy/distutils/command/config.py python-numpy-1.8.1/numpy/distutils/command/config.py --- python-numpy-1.8.1~rc1/numpy/distutils/command/config.py 2014-03-02 14:04:27.000000000 +0000 +++ python-numpy-1.8.1/numpy/distutils/command/config.py 2014-03-25 19:43:23.000000000 +0000 @@ -401,7 +401,7 @@ def get_output(self, body, headers=None, include_dirs=None, libraries=None, library_dirs=None, - lang="c"): + lang="c", use_tee=None): """Try to compile, link to an executable, and run a program built from 'body' and 'headers'. Returns the exit status code of the program and its output. @@ -426,7 +426,8 @@ grabber.restore() raise exe = os.path.join('.', exe) - exitstatus, output = exec_command(exe, execute_in='.') + exitstatus, output = exec_command(exe, execute_in='.', + use_tee=use_tee) if hasattr(os, 'WEXITSTATUS'): exitcode = os.WEXITSTATUS(exitstatus) if os.WIFSIGNALED(exitstatus): diff -Nru python-numpy-1.8.1~rc1/numpy/distutils/exec_command.py python-numpy-1.8.1/numpy/distutils/exec_command.py --- python-numpy-1.8.1~rc1/numpy/distutils/exec_command.py 2014-03-02 14:04:27.000000000 +0000 +++ python-numpy-1.8.1/numpy/distutils/exec_command.py 2014-03-25 19:43:23.000000000 +0000 @@ -120,7 +120,7 @@ if not os.path.islink(f_ext): f_ext = realpath(f_ext) if os.path.isfile(f_ext) and os.access(f_ext, os.X_OK): - log.good('Found executable %s' % f_ext) + log.info('Found executable %s' % f_ext) _cache[key] = f_ext return f_ext diff -Nru python-numpy-1.8.1~rc1/numpy/distutils/system_info.py python-numpy-1.8.1/numpy/distutils/system_info.py --- python-numpy-1.8.1~rc1/numpy/distutils/system_info.py 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/distutils/system_info.py 2014-03-25 19:43:24.000000000 +0000 @@ -756,9 +756,6 @@ 'includes':['fftw.h', 'rfftw.h'], 'macros':[('SCIPY_FFTW_H', None)]}] - def __init__(self): - system_info.__init__(self) - def calc_ver_info(self, ver_param): """Returns True on successful version detection, else False""" lib_dirs = self.get_lib_dirs() @@ -1302,11 +1299,13 @@ info = {} try: s, o = c.get_output(atlas_version_c_text, - libraries=libraries, library_dirs=library_dirs) + libraries=libraries, library_dirs=library_dirs, + use_tee=(system_info.verbosity > 0)) if s and re.search(r'undefined reference to `_gfortran', o, re.M): s, o = c.get_output(atlas_version_c_text, libraries=libraries + ['gfortran'], - library_dirs=library_dirs) + library_dirs=library_dirs, + use_tee=(system_info.verbosity > 0)) if not s: warnings.warn(""" ***************************************************** @@ -1480,7 +1479,7 @@ if not atlas_info: atlas_info = get_info('atlas_blas') - if sys.platform == 'darwin'and not atlas_info: + if sys.platform == 'darwin' and not atlas_info: # Use the system BLAS from Accelerate or vecLib under OSX args = [] link_args = [] diff -Nru python-numpy-1.8.1~rc1/numpy/lib/tests/test_utils.py python-numpy-1.8.1/numpy/lib/tests/test_utils.py --- python-numpy-1.8.1~rc1/numpy/lib/tests/test_utils.py 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/lib/tests/test_utils.py 2014-03-25 19:43:24.000000000 +0000 @@ -1,6 +1,7 @@ from __future__ import division, absolute_import, print_function import sys +from numpy.core import arange from numpy.testing import * import numpy.lib.utils as utils from numpy.lib import deprecate @@ -40,9 +41,17 @@ assert_('old_func3' in new_func3.__doc__) assert_('new_func3' in new_func3.__doc__) + def test_safe_eval_nameconstant(): # Test if safe_eval supports Python 3.4 _ast.NameConstant utils.safe_eval('None') + +def test_byte_bounds(): + a = arange(12).reshape(3, 4) + low, high = utils.byte_bounds(a) + assert_equal(high - low, a.size * a.itemsize) + + if __name__ == "__main__": run_module_suite() diff -Nru python-numpy-1.8.1~rc1/numpy/lib/utils.py python-numpy-1.8.1/numpy/lib/utils.py --- python-numpy-1.8.1~rc1/numpy/lib/utils.py 2014-03-02 14:04:28.000000000 +0000 +++ python-numpy-1.8.1/numpy/lib/utils.py 2014-03-25 19:43:24.000000000 +0000 @@ -6,7 +6,7 @@ import re from numpy.core.numerictypes import issubclass_, issubsctype, issubdtype -from numpy.core import product, ndarray, ufunc +from numpy.core import product, ndarray, ufunc, asarray __all__ = ['issubclass_', 'issubsctype', 'issubdtype', 'deprecate', 'deprecate_with_doc', 'get_numarray_include', @@ -250,8 +250,9 @@ a_data = ai['data'][0] astrides = ai['strides'] ashape = ai['shape'] - bytes_a = int(ai['typestr'][2:]) - + + bytes_a = asarray(a).dtype.itemsize + a_low = a_high = a_data if astrides is None: # contiguous case a_high += a.size * bytes_a diff -Nru python-numpy-1.8.1~rc1/numpy/linalg/tests/test_regression.py python-numpy-1.8.1/numpy/linalg/tests/test_regression.py --- python-numpy-1.8.1~rc1/numpy/linalg/tests/test_regression.py 2014-03-02 14:04:27.000000000 +0000 +++ python-numpy-1.8.1/numpy/linalg/tests/test_regression.py 2014-03-25 19:43:23.000000000 +0000 @@ -69,5 +69,11 @@ bp = linalg.cholesky(b) assert_array_equal(ap, bp) + def test_large_svd_32bit(self): + # See gh-4442, 64bit would require very large/slow matrices. + x = np.eye(1000, 66) + np.linalg.svd(x) + + if __name__ == '__main__': run_module_suite() diff -Nru python-numpy-1.8.1~rc1/numpy/version.py python-numpy-1.8.1/numpy/version.py --- python-numpy-1.8.1~rc1/numpy/version.py 2014-03-02 14:12:36.000000000 +0000 +++ python-numpy-1.8.1/numpy/version.py 2014-03-25 21:44:55.000000000 +0000 @@ -1,9 +1,9 @@ # THIS FILE IS GENERATED FROM NUMPY SETUP.PY -short_version = '1.8.1rc1' -version = '1.8.1rc1' -full_version = '1.8.1rc1' -git_revision = '23f8dcf86cf692fcc9dce48350d5d86c0bc63ada' +short_version = '1.8.1' +version = '1.8.1' +full_version = '1.8.1' +git_revision = '62a7575fd82ddf028517780c01fecf7e0cca27aa' release = True if not release: diff -Nru python-numpy-1.8.1~rc1/PKG-INFO python-numpy-1.8.1/PKG-INFO --- python-numpy-1.8.1~rc1/PKG-INFO 2014-03-02 14:12:38.000000000 +0000 +++ python-numpy-1.8.1/PKG-INFO 2014-03-25 21:44:56.000000000 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: numpy -Version: 1.8.1rc1 +Version: 1.8.1 Summary: NumPy: array processing for numbers, strings, records, and objects. Home-page: http://www.numpy.org Author: NumPy Developers diff -Nru python-numpy-1.8.1~rc1/setup.py python-numpy-1.8.1/setup.py --- python-numpy-1.8.1~rc1/setup.py 2014-03-02 14:09:30.000000000 +0000 +++ python-numpy-1.8.1/setup.py 2014-03-25 21:43:36.000000000 +0000 @@ -51,7 +51,7 @@ MINOR = 8 MICRO = 1 ISRELEASED = True -VERSION = '%d.%d.%drc1' % (MAJOR, MINOR, MICRO) +VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) # Return the git revision as a string