Imported Upstream version 1.21.5 upstream/1.21.5
authorDongHun Kwak <dh0128.kwak@samsung.com>
Fri, 15 Jul 2022 02:14:51 +0000 (11:14 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Fri, 15 Jul 2022 02:14:51 +0000 (11:14 +0900)
72 files changed:
PKG-INFO
_configtest.o
doc/changelog/1.21.5-changelog.rst [new file with mode: 0644]
doc/source/release.rst
doc/source/release/1.21.5-notes.rst [new file with mode: 0644]
numpy/_version.py
numpy/compat/py3k.py
numpy/core/include/numpy/npy_common.h
numpy/core/setup.py
numpy/core/src/multiarray/_multiarray_tests.c.src
numpy/core/src/multiarray/descriptor.c
numpy/core/src/multiarray/einsum_sumprod.c.src
numpy/core/src/multiarray/multiarraymodule.c
numpy/core/src/npymath/npy_math_internal.h.src
numpy/core/src/umath/svml/linux/avx512/svml_z0_acos_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_acos_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_acosh_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_acosh_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_asin_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_asin_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_asinh_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_asinh_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_atan2_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_atan2_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_atan_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_atan_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_atanh_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_atanh_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_cbrt_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_cbrt_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_cos_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_cos_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_cosh_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_cosh_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_exp2_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_exp2_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_exp_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_exp_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_expm1_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_expm1_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_log10_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_log10_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_log1p_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_log1p_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_log2_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_log2_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_log_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_log_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_pow_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_pow_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_sin_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_sin_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_sinh_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_sinh_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_tan_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_tan_s_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_tanh_d_la.s
numpy/core/src/umath/svml/linux/avx512/svml_z0_tanh_s_la.s
numpy/core/tests/test_dtype.py
numpy/core/tests/test_einsum.py
numpy/distutils/ccompiler.py
numpy/distutils/ccompiler_opt.py
numpy/distutils/misc_util.py
numpy/f2py/cfuncs.py
numpy/random/tests/test_extending.py
numpy/testing/_private/utils.py
numpy/typing/_generic_alias.py
numpy/typing/tests/test_generic_alias.py
pavement.py
pyproject.toml
pytest.ini
test_requirements.txt

index 5e02e4ca5c735ad29cb372df83fa9360f4f264a3..9932e45e02cf29decdad7a3a2a01080ce23e1fb9 100644 (file)
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
-Metadata-Version: 1.2
+Metadata-Version: 2.1
 Name: numpy
-Version: 1.21.4
+Version: 1.21.5
 Summary:  NumPy is the fundamental package for array computing with Python.
 Home-page: https://www.numpy.org
 Author: Travis E. Oliphant et al.
@@ -11,22 +11,6 @@ Download-URL: https://pypi.python.org/pypi/numpy
 Project-URL: Bug Tracker, https://github.com/numpy/numpy/issues
 Project-URL: Documentation, https://numpy.org/doc/1.21
 Project-URL: Source Code, https://github.com/numpy/numpy
-Description: It provides:
-        
-        - a powerful N-dimensional array object
-        - sophisticated (broadcasting) functions
-        - tools for integrating C/C++ and Fortran code
-        - useful linear algebra, Fourier transform, and random number capabilities
-        - and much more
-        
-        Besides its obvious scientific uses, NumPy can also be used as an efficient
-        multi-dimensional container of generic data. Arbitrary data-types can be
-        defined. This allows NumPy to seamlessly and speedily integrate with a wide
-        variety of databases.
-        
-        All NumPy wheels distributed on PyPI are BSD licensed.
-        
-        
 Platform: Windows
 Platform: Linux
 Platform: Solaris
@@ -53,3 +37,23 @@ Classifier: Operating System :: POSIX
 Classifier: Operating System :: Unix
 Classifier: Operating System :: MacOS
 Requires-Python: >=3.7,<3.11
+License-File: LICENSE.txt
+License-File: LICENSES_bundled.txt
+
+It provides:
+
+- a powerful N-dimensional array object
+- sophisticated (broadcasting) functions
+- tools for integrating C/C++ and Fortran code
+- useful linear algebra, Fourier transform, and random number capabilities
+- and much more
+
+Besides its obvious scientific uses, NumPy can also be used as an efficient
+multi-dimensional container of generic data. Arbitrary data-types can be
+defined. This allows NumPy to seamlessly and speedily integrate with a wide
+variety of databases.
+
+All NumPy wheels distributed on PyPI are BSD licensed.
+
+
+
index 4d632006d5e4754b83b4d9e4e54f312b60d829a5..95a4e91c4442cc7c1622f11e34c02bb5ee3be5da 100644 (file)
Binary files a/_configtest.o and b/_configtest.o differ
diff --git a/doc/changelog/1.21.5-changelog.rst b/doc/changelog/1.21.5-changelog.rst
new file mode 100644 (file)
index 0000000..acd3599
--- /dev/null
@@ -0,0 +1,31 @@
+
+Contributors
+============
+
+A total of 7 people contributed to this release.  People with a "+" by their
+names contributed a patch for the first time.
+
+* Bas van Beek
+* Charles Harris
+* Matti Picus
+* Rohit Goswami +
+* Ross Barnowski
+* Sayed Adel
+* Sebastian Berg
+
+Pull requests merged
+====================
+
+A total of 11 pull requests were merged for this release.
+
+* `#20357 <https://github.com/numpy/numpy/pull/20357>`__: MAINT: Do not forward `__(deep)copy__` calls of `_GenericAlias`...
+* `#20462 <https://github.com/numpy/numpy/pull/20462>`__: BUG: Fix float16 einsum fastpaths using wrong tempvar
+* `#20463 <https://github.com/numpy/numpy/pull/20463>`__: BUG, DIST: Print os error message when the executable not exist
+* `#20464 <https://github.com/numpy/numpy/pull/20464>`__: BLD: Verify the ability to compile C++ sources before initiating...
+* `#20465 <https://github.com/numpy/numpy/pull/20465>`__: BUG: Force ``npymath` ` to respect ``npy_longdouble``
+* `#20466 <https://github.com/numpy/numpy/pull/20466>`__: BUG: Fix failure to create aligned, empty structured dtype
+* `#20467 <https://github.com/numpy/numpy/pull/20467>`__: ENH: provide a convenience function to replace npy_load_module
+* `#20495 <https://github.com/numpy/numpy/pull/20495>`__: MAINT: update wheel to version that supports python3.10
+* `#20497 <https://github.com/numpy/numpy/pull/20497>`__: BUG: Clear errors correctly in F2PY conversions
+* `#20613 <https://github.com/numpy/numpy/pull/20613>`__: DEV: add a warningfilter to fix pytest workflow.
+* `#20618 <https://github.com/numpy/numpy/pull/20618>`__: MAINT: Help boost::python libraries at least not crash
index 2a13b25f2a3bd76ee28857aaded5b638f1ef8397..2a053e46b4efd52422d49c06480b41e75f841ab8 100644 (file)
@@ -5,6 +5,7 @@ Release Notes
 .. toctree::
     :maxdepth: 3
 
+    1.21.5 <release/1.21.5-notes>
     1.21.4 <release/1.21.4-notes>
     1.21.3 <release/1.21.3-notes>
     1.21.2 <release/1.21.2-notes>
diff --git a/doc/source/release/1.21.5-notes.rst b/doc/source/release/1.21.5-notes.rst
new file mode 100644 (file)
index 0000000..c69d267
--- /dev/null
@@ -0,0 +1,42 @@
+.. currentmodule:: numpy
+
+==========================
+NumPy 1.21.5 Release Notes
+==========================
+
+NumPy 1.21.5 is a maintenance release that fixes a few bugs discovered after
+the 1.21.4 release and does some maintenance to extend the 1.21.x lifetime.
+The Python versions supported in this release are 3.7-3.10. If you want to
+compile your own version using gcc-11, you will need to use gcc-11.2+ to avoid
+problems.
+
+Contributors
+============
+
+A total of 7 people contributed to this release.  People with a "+" by their
+names contributed a patch for the first time.
+
+* Bas van Beek
+* Charles Harris
+* Matti Picus
+* Rohit Goswami
+* Ross Barnowski
+* Sayed Adel
+* Sebastian Berg
+
+Pull requests merged
+====================
+
+A total of 11 pull requests were merged for this release.
+
+* `#20357 <https://github.com/numpy/numpy/pull/20357>`__: MAINT: Do not forward ``__(deep)copy__`` calls of ``_GenericAlias``...
+* `#20462 <https://github.com/numpy/numpy/pull/20462>`__: BUG: Fix float16 einsum fastpaths using wrong tempvar
+* `#20463 <https://github.com/numpy/numpy/pull/20463>`__: BUG, DIST: Print os error message when the executable not exist
+* `#20464 <https://github.com/numpy/numpy/pull/20464>`__: BLD: Verify the ability to compile C++ sources before initiating...
+* `#20465 <https://github.com/numpy/numpy/pull/20465>`__: BUG: Force ``npymath` ` to respect ``npy_longdouble``
+* `#20466 <https://github.com/numpy/numpy/pull/20466>`__: BUG: Fix failure to create aligned, empty structured dtype
+* `#20467 <https://github.com/numpy/numpy/pull/20467>`__: ENH: provide a convenience function to replace npy_load_module
+* `#20495 <https://github.com/numpy/numpy/pull/20495>`__: MAINT: update wheel to version that supports python3.10
+* `#20497 <https://github.com/numpy/numpy/pull/20497>`__: BUG: Clear errors correctly in F2PY conversions
+* `#20613 <https://github.com/numpy/numpy/pull/20613>`__: DEV: add a warningfilter to fix pytest workflow.
+* `#20618 <https://github.com/numpy/numpy/pull/20618>`__: MAINT: Help boost::python libraries at least not crash
index 3ffbf4d61e7b30bc9aea24f817054b6d8d2e4fb3..a10ba551856423dc8997443110684f45a09f8f11 100644 (file)
@@ -8,11 +8,11 @@ import json
 
 version_json = '''
 {
- "date": "2021-11-04T15:06:03-0600",
+ "date": "2021-12-19T13:38:14-0700",
  "dirty": false,
  "error": null,
- "full-revisionid": "c0b003e9c787ccab27f6fe57c154d7b881da5795",
- "version": "1.21.4"
+ "full-revisionid": "c3d0a09342c08c466984654bc4738af595fba896",
+ "version": "1.21.5"
 }
 '''  # END VERSION_JSON
 
index e1e236d92306273ef6e8a187542694b1b834ef83..5704610711fd07af4c39200e14f49fac5d462792 100644 (file)
@@ -111,7 +111,9 @@ class contextlib_nullcontext:
 
 def npy_load_module(name, fn, info=None):
     """
-    Load a module.
+    Load a module. Uses ``load_module`` which will be deprecated in python
+    3.12. An alternative that uses ``exec_module`` is in
+    numpy.distutils.misc_util.exec_mod_from_location
 
     .. versionadded:: 1.11.2
 
index d5f329b667544f8e198b327ec66a52583dbc9a2a..23b70edd72b07f479d582ba476623f2d001e2d01 100644 (file)
@@ -356,14 +356,31 @@ typedef unsigned long npy_ulonglong;
 typedef unsigned char npy_bool;
 #define NPY_FALSE 0
 #define NPY_TRUE 1
-
-
+/*
+ * `NPY_SIZEOF_LONGDOUBLE` isn't usually equal to sizeof(long double).
+ * In some certain cases, it may forced to be equal to sizeof(double)
+ * even against the compiler implementation and the same goes for
+ * `complex long double`.
+ *
+ * Therefore, avoid `long double`, use `npy_longdouble` instead,
+ * and when it comes to standard math functions make sure of using
+ * the double version when `NPY_SIZEOF_LONGDOUBLE` == `NPY_SIZEOF_DOUBLE`.
+ * For example:
+ *   npy_longdouble *ptr, x;
+ *   #if NPY_SIZEOF_LONGDOUBLE == NPY_SIZEOF_DOUBLE
+ *       npy_longdouble r = modf(x, ptr);
+ *   #else
+ *       npy_longdouble r = modfl(x, ptr);
+ *   #endif
+ *
+ * See https://github.com/numpy/numpy/issues/20348
+ */
 #if NPY_SIZEOF_LONGDOUBLE == NPY_SIZEOF_DOUBLE
-        typedef double npy_longdouble;
-        #define NPY_LONGDOUBLE_FMT "g"
+    #define NPY_LONGDOUBLE_FMT "g"
+    typedef double npy_longdouble;
 #else
-        typedef long double npy_longdouble;
-        #define NPY_LONGDOUBLE_FMT "Lg"
+    #define NPY_LONGDOUBLE_FMT "Lg"
+    typedef long double npy_longdouble;
 #endif
 
 #ifndef Py_USING_UNICODE
index b03e9f99005ebff02f65c69be30d96ffa28a0cb1..ae8081d1b92ba530cb6a8eb2fcff3448a62d334e 100644 (file)
@@ -654,16 +654,38 @@ def configuration(parent_package='',top_path=None):
         # but we cannot use add_installed_pkg_config here either, so we only
         # update the substitution dictionary during npymath build
         config_cmd = config.get_config_cmd()
-
         # Check that the toolchain works, to fail early if it doesn't
         # (avoid late errors with MATHLIB which are confusing if the
         # compiler does not work).
-        st = config_cmd.try_link('int main(void) { return 0;}')
-        if not st:
-            # rerun the failing command in verbose mode
-            config_cmd.compiler.verbose = True
-            config_cmd.try_link('int main(void) { return 0;}')
-            raise RuntimeError("Broken toolchain: cannot link a simple C program")
+        for lang, test_code, note in (
+            ('c', 'int main(void) { return 0;}', ''),
+            ('c++', (
+                    'int main(void)'
+                    '{ auto x = 0.0; return static_cast<int>(x); }'
+                ), (
+                    'note: A compiler with support for C++11 language '
+                    'features is required.'
+                )
+             ),
+        ):
+            is_cpp = lang == 'c++'
+            if is_cpp:
+                # this a workround to get rid of invalid c++ flags
+                # without doing big changes to config.
+                # c tested first, compiler should be here
+                bk_c = config_cmd.compiler
+                config_cmd.compiler = bk_c.cxx_compiler()
+            st = config_cmd.try_link(test_code, lang=lang)
+            if not st:
+                # rerun the failing command in verbose mode
+                config_cmd.compiler.verbose = True
+                config_cmd.try_link(test_code, lang=lang)
+                raise RuntimeError(
+                    f"Broken toolchain: cannot link a simple {lang.upper()} "
+                    f"program. {note}"
+                )
+            if is_cpp:
+                config_cmd.compiler = bk_c
         mlibs = check_mathlib(config_cmd)
 
         posix_mlib = ' '.join(['-l%s' % l for l in mlibs])
index bfdeae07932e292310e43cc30fc1f5b6293ef202..0cb295957126177e09d9919468cf156e8e5d2291 100644 (file)
@@ -2093,7 +2093,7 @@ PrintFloat_Printf_g(PyObject *obj, int precision)
     }
     else if (PyArray_IsScalar(obj, LongDouble)) {
         npy_longdouble x = PyArrayScalar_VAL(obj, LongDouble);
-        PyOS_snprintf(str, sizeof(str), "%.*Lg", precision, x);
+        PyOS_snprintf(str, sizeof(str), "%.*" NPY_LONGDOUBLE_FMT, precision, x);
     }
     else{
         double val = PyFloat_AsDouble(obj);
index b8b477e5d70f8ffc40a14551f470ebc757f3f7b6..fa24f1a87dbf1693c5cd71ea34afa45d827d7aa5 100644 (file)
@@ -1325,7 +1325,7 @@ _convert_from_dict(PyObject *obj, int align)
             goto fail;
         }
         /* If align is set, make sure the alignment divides into the size */
-        if (align && itemsize % new->alignment != 0) {
+        if (align && new->alignment > 0 && itemsize % new->alignment != 0) {
             PyErr_Format(PyExc_ValueError,
                     "NumPy dtype descriptor requires alignment of %d bytes, "
                     "which is not divisible into the specified itemsize %d",
index 333b8e188355773a7c6e29272d340cd62fb658f5..4a3a460e40ff1f2529430749bffbcc8d2a5c1ab5 100644 (file)
@@ -337,13 +337,13 @@ static NPY_GCC_OPT_3 void
         /**begin repeat2
          * #i = 0, 1, 2, 3#
          */
-        const @type@ b@i@ = @from@(data[@i@]);
-        const @type@ c@i@ = @from@(data_out[@i@]);
+        const @temptype@ b@i@ = @from@(data[@i@]);
+        const @temptype@ c@i@ = @from@(data_out[@i@]);
         /**end repeat2**/
         /**begin repeat2
          * #i = 0, 1, 2, 3#
          */
-        const @type@ abc@i@ = scalar * b@i@ + c@i@;
+        const @temptype@ abc@i@ = scalar * b@i@ + c@i@;
         /**end repeat2**/
         /**begin repeat2
          * #i = 0, 1, 2, 3#
@@ -353,8 +353,8 @@ static NPY_GCC_OPT_3 void
     }
 #endif // !NPY_DISABLE_OPTIMIZATION
     for (; count > 0; --count, ++data, ++data_out) {
-        const @type@ b = @from@(*data);
-        const @type@ c = @from@(*data_out);
+        const @temptype@ b = @from@(*data);
+        const @temptype@ c = @from@(*data_out);
         *data_out = @to@(scalar * b + c);
     }
 #endif // NPYV check for @type@
@@ -417,14 +417,14 @@ static void
         /**begin repeat2
          * #i = 0, 1, 2, 3#
          */
-        const @type@ a@i@ = @from@(data0[@i@]);
-        const @type@ b@i@ = @from@(data1[@i@]);
-        const @type@ c@i@ = @from@(data_out[@i@]);
+        const @temptype@ a@i@ = @from@(data0[@i@]);
+        const @temptype@ b@i@ = @from@(data1[@i@]);
+        const @temptype@ c@i@ = @from@(data_out[@i@]);
         /**end repeat2**/
         /**begin repeat2
          * #i = 0, 1, 2, 3#
          */
-        const @type@ abc@i@ = a@i@ * b@i@ + c@i@;
+        const @temptype@ abc@i@ = a@i@ * b@i@ + c@i@;
         /**end repeat2**/
         /**begin repeat2
          * #i = 0, 1, 2, 3#
@@ -434,9 +434,9 @@ static void
     }
 #endif // !NPY_DISABLE_OPTIMIZATION
     for (; count > 0; --count, ++data0, ++data1, ++data_out) {
-        const @type@ a = @from@(*data0);
-        const @type@ b = @from@(*data1);
-        const @type@ c = @from@(*data_out);
+        const @temptype@ a = @from@(*data0);
+        const @temptype@ b = @from@(*data1);
+        const @temptype@ c = @from@(*data_out);
         *data_out = @to@(a * b + c);
     }
 #endif // NPYV check for @type@
@@ -521,14 +521,14 @@ static NPY_GCC_OPT_3 void
         /**begin repeat2
          * #i = 0, 1, 2, 3#
          */
-        const @type@ ab@i@ = @from@(data0[@i@]) * @from@(data1[@i@]);
+        const @temptype@ ab@i@ = @from@(data0[@i@]) * @from@(data1[@i@]);
         /**end repeat2**/
         accum += ab0 + ab1 + ab2 + ab3;
     }
 #endif // !NPY_DISABLE_OPTIMIZATION
     for (; count > 0; --count, ++data0, ++data1) {
-        const @type@ a = @from@(*data0);
-        const @type@ b = @from@(*data1);
+        const @temptype@ a = @from@(*data0);
+        const @temptype@ b = @from@(*data1);
         accum += a * b;
     }
 #endif // NPYV check for @type@
index f7c3ea093a2951d088a67b2900c5d1f1004c3d2b..bc5194483c06a7efc7729708cbb2f85da7be7561 100644 (file)
@@ -1473,6 +1473,24 @@ PyArray_EquivTypes(PyArray_Descr *type1, PyArray_Descr *type2)
     if (type1 == type2) {
         return 1;
     }
+
+    if (Py_TYPE(Py_TYPE(type1)) == &PyType_Type) {
+        /*
+         * 2021-12-17: This case is nonsense and should be removed eventually!
+         *
+         * boost::python has/had a bug effectively using EquivTypes with
+         * `type(arbitrary_obj)`.  That is clearly wrong as that cannot be a
+         * `PyArray_Descr *`.  We assume that `type(type(type(arbitrary_obj))`
+         * is always in practice `type` (this is the type of the metaclass),
+         * but for our descriptors, `type(type(descr))` is DTypeMeta.
+         *
+         * In that case, we just return False.  There is a possibility that
+         * this actually _worked_ effectively (returning 1 sometimes).
+         * We ignore that possibility for simplicity; it really is not our bug.
+         */
+        return 0;
+    }
+
     /*
      * Do not use PyArray_CanCastTypeTo because it supports legacy flexible
      * dtypes as input.
index d692aa7953e99bddcd7050a025123884e6dd3e49..a18f2dc6dbc9805467c0f3fe761cacb04cdf7823 100644 (file)
@@ -480,10 +480,16 @@ NPY_INPLACE @type@ npy_frexp@c@(@type@ x, int* exp)
 
 /**begin repeat
  * #type = npy_longdouble, npy_double, npy_float#
+ * #TYPE = LONGDOUBLE, DOUBLE, FLOAT#
  * #c = l,,f#
  * #C = L,,F#
  */
-
+#undef NPY__FP_SFX
+#if NPY_SIZEOF_@TYPE@ == NPY_SIZEOF_DOUBLE
+    #define NPY__FP_SFX(X) X
+#else
+    #define NPY__FP_SFX(X) NPY_CAT(X, @c@)
+#endif
 /*
  * On arm64 macOS, there's a bug with sin, cos, and tan where they don't
  * raise "invalid" when given INFINITY as input.
@@ -509,7 +515,7 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
         return (x - x);
     }
 #endif
-    return @kind@@c@(x);
+    return NPY__FP_SFX(@kind@)(x);
 }
 #endif
 
@@ -524,7 +530,7 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
 #ifdef HAVE_@KIND@@C@
 NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
 {
-    return @kind@@c@(x, y);
+    return NPY__FP_SFX(@kind@)(x, y);
 }
 #endif
 /**end repeat1**/
@@ -555,21 +561,21 @@ npy_@kind@@c@(@type@ x, @type@ y)
 #ifdef HAVE_MODF@C@
 NPY_INPLACE @type@ npy_modf@c@(@type@ x, @type@ *iptr)
 {
-    return modf@c@(x, iptr);
+    return NPY__FP_SFX(modf)(x, iptr);
 }
 #endif
 
 #ifdef HAVE_LDEXP@C@
 NPY_INPLACE @type@ npy_ldexp@c@(@type@ x, int exp)
 {
-    return ldexp@c@(x, exp);
+    return NPY__FP_SFX(ldexp)(x, exp);
 }
 #endif
 
 #ifdef HAVE_FREXP@C@
 NPY_INPLACE @type@ npy_frexp@c@(@type@ x, int* exp)
 {
-    return frexp@c@(x, exp);
+    return NPY__FP_SFX(frexp)(x, exp);
 }
 #endif
 
@@ -592,10 +598,10 @@ NPY_INPLACE @type@ npy_cbrt@c@(@type@ x)
 #else
 NPY_INPLACE @type@ npy_cbrt@c@(@type@ x)
 {
-    return cbrt@c@(x);
+    return NPY__FP_SFX(cbrt)(x);
 }
 #endif
-
+#undef NPY__FP_SFX
 /**end repeat**/
 
 
@@ -605,10 +611,16 @@ NPY_INPLACE @type@ npy_cbrt@c@(@type@ x)
 
 /**begin repeat
  * #type = npy_float, npy_double, npy_longdouble#
+ * #TYPE = FLOAT, DOUBLE, LONGDOUBLE#
  * #c = f, ,l#
  * #C = F, ,L#
  */
-
+#undef NPY__FP_SFX
+#if NPY_SIZEOF_@TYPE@ == NPY_SIZEOF_DOUBLE
+    #define NPY__FP_SFX(X) X
+#else
+    #define NPY__FP_SFX(X) NPY_CAT(X, @c@)
+#endif
 @type@ npy_heaviside@c@(@type@ x, @type@ h0)
 {
     if (npy_isnan(x)) {
@@ -625,10 +637,10 @@ NPY_INPLACE @type@ npy_cbrt@c@(@type@ x)
     }
 }
 
-#define LOGE2    NPY_LOGE2@c@
-#define LOG2E    NPY_LOG2E@c@
-#define RAD2DEG  (180.0@c@/NPY_PI@c@)
-#define DEG2RAD  (NPY_PI@c@/180.0@c@)
+#define LOGE2    NPY__FP_SFX(NPY_LOGE2)
+#define LOG2E    NPY__FP_SFX(NPY_LOG2E)
+#define RAD2DEG  (NPY__FP_SFX(180.0)/NPY__FP_SFX(NPY_PI))
+#define DEG2RAD  (NPY__FP_SFX(NPY_PI)/NPY__FP_SFX(180.0))
 
 NPY_INPLACE @type@ npy_rad2deg@c@(@type@ x)
 {
@@ -783,7 +795,7 @@ npy_divmod@c@(@type@ a, @type@ b, @type@ *modulus)
 #undef LOG2E
 #undef RAD2DEG
 #undef DEG2RAD
-
+#undef NPY__FP_SFX
 /**end repeat**/
 
 /**begin repeat
index 779b9105fd8db2e45f27e5f3a54f8165dce2f716..993c91f507d2a416b3751c628d7b47c730233410 100644 (file)
@@ -2640,3 +2640,5 @@ _vmldACosHATab:
        .long   0x00000000,0x80000000,0x00000000,0x00000000
        .type   .L_2il0floatpacket.197,@object
        .size   .L_2il0floatpacket.197,16
+
+      .section        .note.GNU-stack,"",@progbits
index b6ecb7e5acca441ebadc2ccfad205e1389e0c176..0212411cb893472b2587ac5ea27bcc0cbda505f0 100644 (file)
@@ -2290,3 +2290,5 @@ _vmldACosHATab:
        .long   0x00000000,0x80000000,0x00000000,0x00000000
        .type   .L_2il0floatpacket.199,@object
        .size   .L_2il0floatpacket.199,16
+
+      .section        .note.GNU-stack,"",@progbits
index bbcd5e5acb3559f3753278d349e744a575552cf9..348ad7e16e90f51f88b601b6668f47126f3cefeb 100644 (file)
@@ -889,3 +889,5 @@ __dacosh_la_CoutTab:
        .long   4293918720
        .type   __dacosh_la_CoutTab,@object
        .size   __dacosh_la_CoutTab,32
+
+      .section        .note.GNU-stack,"",@progbits
index 73c58bd49bf05b40a623b65a6f92f56b2b4dbb29..68f7a495f877bc0e163ea41a0111ee8baa830fc6 100644 (file)
@@ -683,3 +683,5 @@ __sacosh_la__iml_sacosh_cout_tab:
        .long   2139095040
        .type   __sacosh_la__iml_sacosh_cout_tab,@object
        .size   __sacosh_la__iml_sacosh_cout_tab,12
+
+      .section        .note.GNU-stack,"",@progbits
index 1098dfc5bae228021ea34fa83e759e2d3309092f..09b6ce3859caf1032d5fb3e187bec086d2a38f87 100644 (file)
@@ -2549,3 +2549,5 @@ _vmldASinHATab:
        .long   3217739776
        .type   _vmldASinHATab,@object
        .size   _vmldASinHATab,4504
+
+      .section        .note.GNU-stack,"",@progbits
index 74603c65aa7065321ef532770eca249105c9620d..9d92dfbfe7ccc3ef1316757ce8f9ddbaf8447ac9 100644 (file)
@@ -2197,3 +2197,5 @@ _vmldASinHATab:
        .long   3217739776
        .type   _vmldASinHATab,@object
        .size   _vmldASinHATab,4504
+
+      .section        .note.GNU-stack,"",@progbits
index 2c8a32ded30dc1ab9e4441107483da29401c606c..ff70160762e524e272f06cace4b35ee06bbbe69a 100644 (file)
@@ -872,3 +872,5 @@ __svml_dasinh_data_internal_avx512:
        .long   1031600026
        .type   __svml_dasinh_data_internal_avx512,@object
        .size   __svml_dasinh_data_internal_avx512,2048
+
+      .section        .note.GNU-stack,"",@progbits
index f9f7f8100aece790c49eb7d9a424f9c50112633b..8aacb0bfb02e201f648f80a43e8f2bf9c4a50897 100644 (file)
@@ -671,3 +671,5 @@ __svml_sasinh_data_internal_avx512:
        .long   939916788
        .type   __svml_sasinh_data_internal_avx512,@object
        .size   __svml_sasinh_data_internal_avx512,1344
+
+      .section        .note.GNU-stack,"",@progbits
index 75b0935bfcab6f7cb2aa97357092636635c2a264..1f3c838a3ebfd271c9d72e2ab61e76f03cdb9879 100644 (file)
@@ -2391,3 +2391,5 @@ __datan2_la_CoutTab:
        .long   0xffffffff,0xffffffff
        .type   .L_2il0floatpacket.31,@object
        .size   .L_2il0floatpacket.31,8
+
+      .section        .note.GNU-stack,"",@progbits
index 25f12f36c9a9a42945b37881c23db0c8c816016c..6a1fe9cc3bbb5ca34d59bbd86ea48c629d21fb20 100644 (file)
@@ -2072,3 +2072,5 @@ __satan2_la_CoutTab:
        .long   1101004800
        .type   __satan2_la_CoutTab,@object
        .size   __satan2_la_CoutTab,2008
+
+      .section        .note.GNU-stack,"",@progbits
index 01564372eaaf056b5be204cef7e4bcb9743b2eb7..d77f0cf09abf168e81c38562e99f12306eda36b8 100644 (file)
@@ -1350,3 +1350,5 @@ __datan_la_CoutTab:
        .long   0x00000000,0x3ff00000
        .type   .L_2il0floatpacket.14,@object
        .size   .L_2il0floatpacket.14,8
+
+      .section        .note.GNU-stack,"",@progbits
index c1386beb56f006cefd5921cd4104bb620ca274c6..743ebf4917b0e9485f3185c3f2446d5fa5500f48 100644 (file)
@@ -353,3 +353,5 @@ __svml_satan_data_internal_avx512:
        .long   3198855850
        .type   __svml_satan_data_internal_avx512,@object
        .size   __svml_satan_data_internal_avx512,1024
+
+      .section        .note.GNU-stack,"",@progbits
index fbcd15015115f259e1363b8066a671d684e96916..a6a21bc5ab7d72e479026a4831bf15e819dc0a18 100644 (file)
@@ -654,3 +654,5 @@ __datanh_la_CoutTab:
        .long   4293918720
        .type   __datanh_la_CoutTab,@object
        .size   __datanh_la_CoutTab,32
+
+      .section        .note.GNU-stack,"",@progbits
index 9177c0d955c42acc7d349e6cb79a5b4a53194da3..2ae97c492774ec59affda975c7dfb3986389b831 100644 (file)
@@ -556,3 +556,5 @@ __satanh_la__imlsAtanhTab:
        .long   2139095040
        .type   __satanh_la__imlsAtanhTab,@object
        .size   __satanh_la__imlsAtanhTab,12
+
+      .section        .note.GNU-stack,"",@progbits
index e9aa25590ed0cd3d9c3bbd38d1332f208288016b..32dbfcc951e28dc58583e276f2ad4195ccf32a4e 100644 (file)
@@ -909,3 +909,5 @@ __dcbrt_la__vmldCbrtTab:
        .long   0x00000000,0x80000000,0x00000000,0x00000000
        .type   .L_2il0floatpacket.81,@object
        .size   .L_2il0floatpacket.81,16
+
+      .section        .note.GNU-stack,"",@progbits
index b257437ef346bb63c51ab60e1671335979fedd35..ba09907266585e301951c9a9c8b5f7012212cc2e 100644 (file)
@@ -1010,3 +1010,5 @@ __scbrt_la_vscbrt_ha_cout_data:
        .long   0xbd288f47
        .type   .L_2il0floatpacket.35,@object
        .size   .L_2il0floatpacket.35,4
+
+      .section        .note.GNU-stack,"",@progbits
index 51d72fe1d3af580103544b4ab3f6c9adb30ae179..d5db3a28e1be688d8c531e3f6e980c406da09375 100644 (file)
@@ -17672,3 +17672,5 @@ __dcos_la_CoutTab:
        .long   2146435072
        .type   __dcos_la_CoutTab,@object
        .size   __dcos_la_CoutTab,16
+
+      .section        .note.GNU-stack,"",@progbits
index 54e3f47f4f115c89199f159ffaa310e71e13dcfe..4581bf6de8c6cfad1732be739e4a54889bbd1566 100644 (file)
@@ -2852,3 +2852,5 @@ __scos_la__vmlsCosCoutTab:
        .long   2139095040
        .type   __scos_la__vmlsCosCoutTab,@object
        .size   __scos_la__vmlsCosCoutTab,8
+
+      .section        .note.GNU-stack,"",@progbits
index 0c8dc5ebfa439e634fee735edb5e9860a4eef244..5e70a7dc0bc5b1a19fbc6049dbb099535bb64090 100644 (file)
@@ -1713,3 +1713,5 @@ __dcosh_la_CoutTab:
        .long   1077247184
        .type   __dcosh_la_CoutTab,@object
        .size   __dcosh_la_CoutTab,1152
+
+      .section        .note.GNU-stack,"",@progbits
index a7be097fc6905f0861302d3b159150f2df09fd53..6713ad8efd5b8a68c7a34a6d3b710ad574c34f65 100644 (file)
@@ -1209,3 +1209,5 @@ __scosh_la_CoutTab:
        .long   1077247184
        .type   __scosh_la_CoutTab,@object
        .size   __scosh_la_CoutTab,1152
+
+      .section        .note.GNU-stack,"",@progbits
index 7c61b33e5c9df03144cb0d90b6314def55bb3936..af4f281e3c770b897781be3f2fc3951ee4995338 100644 (file)
@@ -828,3 +828,5 @@ __dexp2_la__imldExp2HATab:
        .long   0
        .type   __dexp2_la__imldExp2HATab,@object
        .size   __dexp2_la__imldExp2HATab,1152
+
+      .section        .note.GNU-stack,"",@progbits
index 5ddd79383d450853231da4e866764e8b3ebfaf47..3affa77dc8838282a8b477a44ed811a7f33edc35 100644 (file)
@@ -492,3 +492,5 @@ __svml_sexp2_data_internal_avx512:
        .long   0xc2fc0000
        .type   .L_2il0floatpacket.56,@object
        .size   .L_2il0floatpacket.56,4
+
+      .section        .note.GNU-stack,"",@progbits
index 87aee92c6a7151cef5db76212859af06d8c74f74..dd5f03a44590c5e59e87d0dfb17756f3f902344f 100644 (file)
@@ -1072,3 +1072,5 @@ _imldExpHATab:
        .long   1106771968
        .type   _imldExpHATab,@object
        .size   _imldExpHATab,1176
+
+      .section        .note.GNU-stack,"",@progbits
index 4c0e972ef28396f1957b8b683825461f1b85eb77..7bb40a33d660221e04c9c1237e07115c43f5d585 100644 (file)
@@ -770,3 +770,5 @@ __svml_sexp_data_internal_avx512:
        .long   0x40000000
        .type   .L_2il0floatpacket.67,@object
        .size   .L_2il0floatpacket.67,4
+
+      .section        .note.GNU-stack,"",@progbits
index 6d44b4d17c5d42c68088a06c5df6b53cfb1935cc..0e52bb606bdec59c3270f7fcc7fc55c27f777d2b 100644 (file)
@@ -1087,3 +1087,5 @@ _imldExpHATab:
        .long   0x00000000,0xbff00000
        .type   .L_2il0floatpacket.77,@object
        .size   .L_2il0floatpacket.77,8
+
+      .section        .note.GNU-stack,"",@progbits
index 3ae3336e8abb2d8b6e5b05229ea9d0e423665ef2..9cbefbba56199bbe43f2dc054f7dc65cd76c7304 100644 (file)
@@ -591,3 +591,5 @@ __svml_sexpm1_data_internal_avx512:
        .long   0x3c0950ef
        .type   .L_2il0floatpacket.56,@object
        .size   .L_2il0floatpacket.56,4
+
+      .section        .note.GNU-stack,"",@progbits
index 58313e4cb34823e003c70ab6e7535be0eab90559..86a0bc84cb4afde9ef8eeb1c4966c7a7c7c89b3f 100644 (file)
@@ -1122,3 +1122,5 @@ __dlog10_la_CoutTab:
        .long   0x00000000,0x3ff00000
        .type   .L_2il0floatpacket.89,@object
        .size   .L_2il0floatpacket.89,8
+
+      .section        .note.GNU-stack,"",@progbits
index 4a3dbc96e9b75361f8bbc0bcec5f78ee475f4c0e..1a02ca02f251f2cb6ad84aec9c583e2e6d6fe5e4 100644 (file)
@@ -752,3 +752,5 @@ __slog10_la_CoutTab:
        .long   0x3f800000
        .type   .L_2il0floatpacket.93,@object
        .size   .L_2il0floatpacket.93,4
+
+      .section        .note.GNU-stack,"",@progbits
index 6073965a64416c5868e300a1c66d69dc5bf2faf9..35bd41776012c9faa36ba8e2c0c468e5f870ddfc 100644 (file)
@@ -1130,3 +1130,5 @@ __dlog1p_la_CoutTab:
        .long   0x00000000,0x3ff00000
        .type   .L_2il0floatpacket.81,@object
        .size   .L_2il0floatpacket.81,8
+
+      .section        .note.GNU-stack,"",@progbits
index c6eeec2a4297e5c1b05770a196dfe68385bcb39b..5d1d577177da8fbb0a932ff53f9d7fdc3b98ff06 100644 (file)
@@ -1648,3 +1648,5 @@ __slog1p_la_CoutTab:
        .long   0x3f800000
        .type   .L_2il0floatpacket.90,@object
        .size   .L_2il0floatpacket.90,4
+
+      .section        .note.GNU-stack,"",@progbits
index 89d3bbca9f93a7ef1693091cb8b9148ff246c46a..6ba58fab921a9768df18f6798e8d0dde71199b6d 100644 (file)
@@ -1712,3 +1712,5 @@ __dlog2_la__P:
        .long   1073157447
        .type   __dlog2_la__P,@object
        .size   __dlog2_la__P,56
+
+      .section        .note.GNU-stack,"",@progbits
index 7f26b01b2affc1f227fd09693fd565d2265de255..6ae3389d29202b421b89a231aa21f0cb6647bbe1 100644 (file)
@@ -726,3 +726,5 @@ __slog2_la_CoutTab:
        .long   0x3f800000
        .type   .L_2il0floatpacket.90,@object
        .size   .L_2il0floatpacket.90,4
+
+      .section        .note.GNU-stack,"",@progbits
index 42428c5839bb6c563e16c2939158f0f057fb54f2..86074e6033f838b65aa7db18df63aa88282ca070 100644 (file)
@@ -1094,3 +1094,5 @@ __dlog_la_CoutTab:
        .long   0x00000000,0x3ff00000
        .type   .L_2il0floatpacket.80,@object
        .size   .L_2il0floatpacket.80,8
+
+      .section        .note.GNU-stack,"",@progbits
index d3bcca838d5bbb4b91221e03ae61878b12d37ffd..771d7b725352cce1f86369d537bcc3f2d0e92016 100644 (file)
@@ -928,3 +928,5 @@ _imlsLnHATab:
        .long   0x00000000,0x3ff00000
        .type   .L_2il0floatpacket.73,@object
        .size   .L_2il0floatpacket.73,8
+
+      .section        .note.GNU-stack,"",@progbits
index 3ae18749d184a51b8ca25055214c610cdaf13bf3..a0f51e11225ec7a58ce8fa526e006ed2e703e50b 100644 (file)
@@ -3523,3 +3523,5 @@ __dpow_la_CoutTab:
        .long   862978048
        .type   __dpow_la_CoutTab,@object
        .size   __dpow_la_CoutTab,6880
+
+      .section        .note.GNU-stack,"",@progbits
index 743321c85f4e36c7ebd6b6b91b12071ae1b1209e..cc303bd16a0f0d3fb24425a0de420ca1c590076e 100644 (file)
@@ -2010,3 +2010,5 @@ __spow_la_CoutTab:
        .long   0x3f800000
        .type   .L_2il0floatpacket.136,@object
        .size   .L_2il0floatpacket.136,4
+
+      .section        .note.GNU-stack,"",@progbits
index fcd28895f9c1cec65e10d93c9d57c89fca5beb4f..8641c12cc9864331e3c4009d8828c3cb86ad93bd 100644 (file)
@@ -17542,3 +17542,5 @@ __dsin_la_CoutTab:
        .long   2146435072
        .type   __dsin_la_CoutTab,@object
        .size   __dsin_la_CoutTab,16
+
+      .section        .note.GNU-stack,"",@progbits
index 33ffbfaade4532937c9e8a12c49f00ffc8c1f1ac..cad6a22d83a07f9e0edc6fdb9d067514df7f3e79 100644 (file)
@@ -2749,3 +2749,5 @@ __ssin_la__vmlsSinHATab:
        .long   2139095040
        .type   __ssin_la__vmlsSinHATab,@object
        .size   __ssin_la__vmlsSinHATab,8
+
+      .section        .note.GNU-stack,"",@progbits
index 5b4bcbb6ad9c6da4f62bca79ce21679b82788427..ff0557c0f998456628d247ed56ea431ec0716e6e 100644 (file)
@@ -2050,3 +2050,5 @@ __dsinh_la_CoutTab:
        .long   0x00000000,0x80000000,0x00000000,0x00000000
        .type   .L_2il0floatpacket.97,@object
        .size   .L_2il0floatpacket.97,16
+
+      .section        .note.GNU-stack,"",@progbits
index f2101e52a6337e0008b98196978dc1d0a115c4f8..a5dace2475039370f6b2cd3713f524da562a5e6d 100644 (file)
@@ -1444,3 +1444,5 @@ __ssinh_la_CoutTab:
        .long   0x00000000,0x80000000,0x00000000,0x00000000
        .type   .L_2il0floatpacket.98,@object
        .size   .L_2il0floatpacket.98,16
+
+      .section        .note.GNU-stack,"",@progbits
index 3f5df19d3b3a7596db2e8d3f455ac9e4c4d23a94..377f144e0f34a124690a89d23ea912013dfc1fcb 100644 (file)
@@ -20217,3 +20217,5 @@ __dtan_la_Tab:
        .long   2146435072
        .type   __dtan_la_Tab,@object
        .size   __dtan_la_Tab,16
+
+      .section        .note.GNU-stack,"",@progbits
index befb6edbafdb2e1b751894f3db844cb6a1daefce..478a52a509bd913faf487cede36c447e09b282eb 100644 (file)
@@ -3175,3 +3175,5 @@ __stan_la__vmlsTanTab:
        .long   2139095040
        .type   __stan_la__vmlsTanTab,@object
        .size   __stan_la__vmlsTanTab,8
+
+      .section        .note.GNU-stack,"",@progbits
index e9c3db611fc8fb5b4c360d4a930b4c96df917fa5..34970c6f3a2d06fdf06a172877c1b615a922d735 100644 (file)
@@ -3044,3 +3044,5 @@ __dtanh_la__imldTanhTab:
        .long   3220176896
        .type   __dtanh_la__imldTanhTab,@object
        .size   __dtanh_la__imldTanhTab,16
+
+      .section        .note.GNU-stack,"",@progbits
index 1d5f4582b858f79b0f49145c43b28e7202dab3c2..60c76d9851334b3d996d7af66fd956c0762f0710 100644 (file)
@@ -1789,3 +1789,5 @@ __stanh_la__imlsTanhTab:
        .long   3212836864
        .type   __stanh_la__imlsTanhTab,@object
        .size   __stanh_la__imlsTanhTab,8
+
+      .section        .note.GNU-stack,"",@progbits
index 1dcf1fb8ebd8f55d091c516039ed907b7efdd406..3cb0c2b841c88fc2bb3cda0cb1bf388cb58bff95 100644 (file)
@@ -621,6 +621,12 @@ class TestSubarray:
         t2 = np.dtype('2i4', align=True)
         assert_equal(t1.alignment, t2.alignment)
 
+    def test_aligned_empty(self):
+        # Mainly regression test for gh-19696: construction failed completely
+        dt = np.dtype([], align=True)
+        assert dt == np.dtype([])
+        dt = np.dtype({"names": [], "formats": [], "itemsize": 0}, align=True)
+        assert dt == np.dtype([])
 
 def iter_struct_object_dtypes():
     """
index c697d0c2d6fcd3c7ed6ddc1eb60473a9c45d2a2f..8304a0f92241025803fc08b8d2ce6b7e42154b2e 100644 (file)
@@ -1,5 +1,7 @@
 import itertools
 
+import pytest
+
 import numpy as np
 from numpy.testing import (
     assert_, assert_equal, assert_array_equal, assert_almost_equal,
@@ -744,6 +746,52 @@ class TestEinsum:
         np.einsum('ij,jk->ik', x, x, out=out)
         assert_array_equal(out.base, correct_base)
 
+    @pytest.mark.parametrize("dtype",
+             np.typecodes["AllFloat"] + np.typecodes["AllInteger"])
+    def test_different_paths(self, dtype):
+        # Test originally added to cover broken float16 path: gh-20305
+        # Likely most are covered elsewhere, at least partially.
+        dtype = np.dtype(dtype)
+        # Simple test, designed to excersize most specialized code paths,
+        # note the +0.5 for floats.  This makes sure we use a float value
+        # where the results must be exact.
+        arr = (np.arange(7) + 0.5).astype(dtype)
+        scalar = np.array(2, dtype=dtype)
+
+        # contig -> scalar:
+        res = np.einsum('i->', arr)
+        assert res == arr.sum()
+        # contig, contig -> contig:
+        res = np.einsum('i,i->i', arr, arr)
+        assert_array_equal(res, arr * arr)
+        # noncontig, noncontig -> contig:
+        res = np.einsum('i,i->i', arr.repeat(2)[::2], arr.repeat(2)[::2])
+        assert_array_equal(res, arr * arr)
+        # contig + contig -> scalar
+        assert np.einsum('i,i->', arr, arr) == (arr * arr).sum()
+        # contig + scalar -> contig (with out)
+        out = np.ones(7, dtype=dtype)
+        res = np.einsum('i,->i', arr, dtype.type(2), out=out)
+        assert_array_equal(res, arr * dtype.type(2))
+        # scalar + contig -> contig (with out)
+        res = np.einsum(',i->i', scalar, arr)
+        assert_array_equal(res, arr * dtype.type(2))
+        # scalar + contig -> scalar
+        res = np.einsum(',i->', scalar, arr)
+        # Use einsum to compare to not have difference due to sum round-offs:
+        assert res == np.einsum('i->', scalar * arr)
+        # contig + scalar -> scalar
+        res = np.einsum('i,->', arr, scalar)
+        # Use einsum to compare to not have difference due to sum round-offs:
+        assert res == np.einsum('i->', scalar * arr)
+        # contig + contig + contig -> scalar
+        arr = np.array([0.5, 0.5, 0.25, 4.5, 3.], dtype=dtype)
+        res = np.einsum('i,i,i->', arr, arr, arr)
+        assert_array_equal(res, (arr * arr * arr).sum())
+        # four arrays:
+        res = np.einsum('i,i,i,i->', arr, arr, arr, arr)
+        assert_array_equal(res, (arr * arr * arr * arr).sum())
+
     def test_small_boolean_arrays(self):
         # See gh-5946.
         # Use array of True embedded in False.
index 061f4862dc19d15059dab6618fbc7eedbf2febbe..ffdc4eb4764725e40c76fe90fdb6846e39c99e61 100644 (file)
@@ -21,9 +21,10 @@ from numpy.distutils import log
 from numpy.distutils.exec_command import (
     filepath_from_subprocess_output, forward_bytes_to_stdout
 )
-from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, \
-                                      get_num_build_jobs, \
-                                      _commandline_dep_string
+from numpy.distutils.misc_util import (
+        cyg2win32, is_sequence, mingw32, get_num_build_jobs,
+        _commandline_dep_string, sanitize_cxx_flags
+)
 
 # globals for parallel build management
 import threading
@@ -143,12 +144,18 @@ def CCompiler_spawn(self, cmd, display=None):
     except subprocess.CalledProcessError as exc:
         o = exc.output
         s = exc.returncode
-    except OSError:
+    except OSError as e:
         # OSError doesn't have the same hooks for the exception
         # output, but exec_command() historically would use an
         # empty string for EnvironmentError (base class for
         # OSError)
-        o = b''
+        # o = b''
+        # still that would make the end-user lost in translation!
+        o = f"\n\n{e}\n\n\n"
+        try:
+            o = o.encode(sys.stdout.encoding)
+        except AttributeError:
+            o = o.encode('utf8')
         # status previously used by exec_command() for parent
         # of OSError
         s = 127
@@ -676,7 +683,10 @@ def CCompiler_cxx_compiler(self):
         return self
 
     cxx = copy(self)
-    cxx.compiler_so = [cxx.compiler_cxx[0]] + cxx.compiler_so[1:]
+    cxx.compiler_cxx = cxx.compiler_cxx
+    cxx.compiler_so = [cxx.compiler_cxx[0]] + \
+                      sanitize_cxx_flags(cxx.compiler_so[1:])
+    #cxx.compiler_so = [cxx.compiler_cxx[0]] + cxx.compiler_so[1:]
     if sys.platform.startswith('aix') and 'ld_so_aix' in cxx.linker_so[0]:
         # AIX needs the ld_so_aix script included with Python
         cxx.linker_so = [cxx.linker_so[0], cxx.compiler_cxx[0]] \
index 1942aa06ee27190402c42b0149a6ef6871c6651d..b60f72dc246381c762bc36f63185f44473867f8e 100644 (file)
@@ -645,9 +645,9 @@ class _Distutils:
     @staticmethod
     def dist_load_module(name, path):
         """Load a module from file, required by the abstract class '_Cache'."""
-        from numpy.compat import npy_load_module
+        from .misc_util import exec_mod_from_location
         try:
-            return npy_load_module(name, path)
+            return exec_mod_from_location(name, path)
         except Exception as e:
             _Distutils.dist_log(e, stderr=True)
         return None
@@ -708,8 +708,8 @@ class _Distutils:
         except subprocess.CalledProcessError as exc:
             o = exc.output
             s = exc.returncode
-        except OSError:
-            o = b''
+        except OSError as e:
+            o = e
             s = 127
         else:
             return None
index 60696438f346700167294a39571bc7b8f268f93e..778f1dccc44c4530bd174b0c0c63582538c911f6 100644 (file)
@@ -30,8 +30,6 @@ def clean_up_temporary_directory():
 
 atexit.register(clean_up_temporary_directory)
 
-from numpy.compat import npy_load_module
-
 __all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',
            'dict_append', 'appendpath', 'generate_config_py',
            'get_cmd', 'allpath', 'get_mathlibs',
@@ -43,7 +41,8 @@ __all__ = ['Configuration', 'get_numpy_include_dirs', 'default_config_dict',
            'dot_join', 'get_frame', 'minrelpath', 'njoin',
            'is_sequence', 'is_string', 'as_list', 'gpaths', 'get_language',
            'quote_args', 'get_build_architecture', 'get_info', 'get_pkg_info',
-           'get_num_build_jobs']
+           'get_num_build_jobs', 'sanitize_cxx_flags',
+           'exec_mod_from_location']
 
 class InstallableLib:
     """
@@ -905,9 +904,8 @@ class Configuration:
         try:
             setup_name = os.path.splitext(os.path.basename(setup_py))[0]
             n = dot_join(self.name, subpackage_name, setup_name)
-            setup_module = npy_load_module('_'.join(n.split('.')),
-                                           setup_py,
-                                           ('.py', 'U', 1))
+            setup_module = exec_mod_from_location(
+                                '_'.join(n.split('.')), setup_py)
             if not hasattr(setup_module, 'configuration'):
                 if not self.options['assume_default_configuration']:
                     self.warn('Assuming default configuration '\
@@ -1953,8 +1951,8 @@ class Configuration:
                 name = os.path.splitext(os.path.basename(fn))[0]
                 n = dot_join(self.name, name)
                 try:
-                    version_module = npy_load_module('_'.join(n.split('.')),
-                                                     fn, info)
+                    version_module = exec_mod_from_location(
+                                        '_'.join(n.split('.')), fn)
                 except ImportError as e:
                     self.warn(str(e))
                     version_module = None
@@ -2415,3 +2413,26 @@ def get_build_architecture():
     # systems, so delay the import to here.
     from distutils.msvccompiler import get_build_architecture
     return get_build_architecture()
+
+
+_cxx_ignore_flags = {'-Werror=implicit-function-declaration', '-std=c99'}
+
+
+def sanitize_cxx_flags(cxxflags):
+    '''
+    Some flags are valid for C but not C++. Prune them.
+    '''
+    return [flag for flag in cxxflags if flag not in _cxx_ignore_flags]
+
+
+def exec_mod_from_location(modname, modfile):
+    '''
+    Use importlib machinery to import a module `modname` from the file
+    `modfile`. Depending on the `spec.loader`, the module may not be
+    registered in sys.modules.
+    '''
+    spec = importlib.util.spec_from_file_location(modname, modfile)
+    foo = importlib.util.module_from_spec(spec)
+    spec.loader.exec_module(foo)
+    return foo
+
index f403a66b5d7b4fbe377f177e9d6be5134dcbeec5..4e53344ec74251da6a3b21ede9630920b1bafe68 100644 (file)
@@ -763,20 +763,26 @@ int_from_pyobj(int* v, PyObject *obj, const char *errmess)
         return !(*v == -1 && PyErr_Occurred());
     }
 
-    if (PyComplex_Check(obj))
+    if (PyComplex_Check(obj)) {
+        PyErr_Clear();
         tmp = PyObject_GetAttrString(obj,\"real\");
-    else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
+    }
+    else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
         /*pass*/;
-    else if (PySequence_Check(obj))
+    }
+    else if (PySequence_Check(obj)) {
+        PyErr_Clear();
         tmp = PySequence_GetItem(obj, 0);
+    }
+
     if (tmp) {
-        PyErr_Clear();
         if (int_from_pyobj(v, tmp, errmess)) {
             Py_DECREF(tmp);
             return 1;
         }
         Py_DECREF(tmp);
     }
+
     {
         PyObject* err = PyErr_Occurred();
         if (err == NULL) {
@@ -806,15 +812,19 @@ long_from_pyobj(long* v, PyObject *obj, const char *errmess) {
         return !(*v == -1 && PyErr_Occurred());
     }
 
-    if (PyComplex_Check(obj))
+    if (PyComplex_Check(obj)) {
+        PyErr_Clear();
         tmp = PyObject_GetAttrString(obj,\"real\");
-    else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
+    }
+    else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
         /*pass*/;
-    else if (PySequence_Check(obj))
-        tmp = PySequence_GetItem(obj,0);
+    }
+    else if (PySequence_Check(obj)) {
+        PyErr_Clear();
+        tmp = PySequence_GetItem(obj, 0);
+    }
 
     if (tmp) {
-        PyErr_Clear();
         if (long_from_pyobj(v, tmp, errmess)) {
             Py_DECREF(tmp);
             return 1;
@@ -852,14 +862,19 @@ long_long_from_pyobj(long_long* v, PyObject *obj, const char *errmess)
         return !(*v == -1 && PyErr_Occurred());
     }
 
-    if (PyComplex_Check(obj))
+    if (PyComplex_Check(obj)) {
+        PyErr_Clear();
         tmp = PyObject_GetAttrString(obj,\"real\");
-    else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
+    }
+    else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
         /*pass*/;
-    else if (PySequence_Check(obj))
-        tmp = PySequence_GetItem(obj,0);
-    if (tmp) {
+    }
+    else if (PySequence_Check(obj)) {
         PyErr_Clear();
+        tmp = PySequence_GetItem(obj, 0);
+    }
+
+    if (tmp) {
         if (long_long_from_pyobj(v, tmp, errmess)) {
             Py_DECREF(tmp);
             return 1;
@@ -919,14 +934,20 @@ double_from_pyobj(double* v, PyObject *obj, const char *errmess)
         Py_DECREF(tmp);
         return !(*v == -1.0 && PyErr_Occurred());
     }
-    if (PyComplex_Check(obj))
+
+    if (PyComplex_Check(obj)) {
+        PyErr_Clear();
         tmp = PyObject_GetAttrString(obj,\"real\");
-    else if (PyBytes_Check(obj) || PyUnicode_Check(obj))
+    }
+    else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
         /*pass*/;
-    else if (PySequence_Check(obj))
-        tmp = PySequence_GetItem(obj,0);
-    if (tmp) {
+    }
+    else if (PySequence_Check(obj)) {
         PyErr_Clear();
+        tmp = PySequence_GetItem(obj, 0);
+    }
+
+    if (tmp) {
         if (double_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}
         Py_DECREF(tmp);
     }
index 99a819efb576ceb317945802e831fb7e712061d9..d362092b58857d5061d2aeb2b354fc2fabc474d2 100644 (file)
@@ -5,6 +5,7 @@ import subprocess
 import sys
 import warnings
 import numpy as np
+from numpy.distutils.misc_util import exec_mod_from_location
 
 try:
     import cffi
@@ -75,10 +76,9 @@ def test_cython(tmp_path):
     assert so1 is not None
     assert so2 is not None
     # import the so's without adding the directory to sys.path
-    from importlib.machinery import ExtensionFileLoader 
-    extending = ExtensionFileLoader('extending', so1).load_module()
-    extending_distributions = ExtensionFileLoader('extending_distributions', so2).load_module()
-
+    exec_mod_from_location('extending', so1)
+    extending_distributions = exec_mod_from_location(
+                    'extending_distributions', so2)
     # actually test the cython c-extension
     from numpy.random import PCG64
     values = extending_distributions.uniforms_ex(PCG64(0), 10, 'd')
index 393fedc2705f58d8c22dd45895f444bb9e7a8b4f..917fa157e087319c2be6b56115b6343d7981b9ef 100644 (file)
@@ -1228,13 +1228,13 @@ def rundocs(filename=None, raise_on_error=True):
 
     >>> np.lib.test(doctests=True)  # doctest: +SKIP
     """
-    from numpy.compat import npy_load_module
+    from numpy.distutils.misc_util import exec_mod_from_location
     import doctest
     if filename is None:
         f = sys._getframe(1)
         filename = f.f_globals['__file__']
     name = os.path.splitext(os.path.basename(filename))[0]
-    m = npy_load_module(name, filename)
+    m = exec_mod_from_location(name, filename)
 
     tests = doctest.DocTestFinder().find(m)
     runner = doctest.DocTestRunner(verbose=False)
index 68523827a71aee567382e2dbc7df63bee8e979e4..4195cd93edc920ca8c927017b9ce43ed9e00eddc 100644 (file)
@@ -178,6 +178,8 @@ class _GenericAlias:
         "__mro_entries__",
         "__reduce__",
         "__reduce_ex__",
+        "__copy__",
+        "__deepcopy__",
     })
 
     def __getattribute__(self, name: str) -> Any:
index 5f0ac915352cf21d5999c8ccb952daa5126b57fd..35c0da3490b371f3e8953128537fc19665922362 100644 (file)
@@ -1,6 +1,7 @@
 from __future__ import annotations
 
 import sys
+import copy
 import types
 import pickle
 import weakref
@@ -74,6 +75,21 @@ class TestGenericAlias:
             value_ref = func(NDArray_ref)
             assert value == value_ref
 
+    @pytest.mark.parametrize("name,func", [
+        ("__copy__", lambda n: n == copy.copy(n)),
+        ("__deepcopy__", lambda n: n == copy.deepcopy(n)),
+    ])
+    def test_copy(self, name: str, func: FuncType) -> None:
+        value = func(NDArray)
+
+        # xref bpo-45167
+        GE_398 = (
+            sys.version_info[:2] == (3, 9) and sys.version_info >= (3, 9, 8)
+        )
+        if GE_398 or sys.version_info >= (3, 10, 1):
+            value_ref = func(NDArray_ref)
+            assert value == value_ref
+
     def test_weakref(self) -> None:
         """Test ``__weakref__``."""
         value = weakref.ref(NDArray)()
index 1ef0fe939e3a69c3900f412c32f6e1ea3d47f2bb..f9c67bc832dbe43d4476731e35cfddaee54147d3 100644 (file)
@@ -38,7 +38,7 @@ from paver.easy import Bunch, options, task, sh
 #-----------------------------------
 
 # Path to the release notes
-RELEASE_NOTES = 'doc/source/release/1.21.4-notes.rst'
+RELEASE_NOTES = 'doc/source/release/1.21.5-notes.rst'
 
 
 #-------------------------------------------------------
index 941c8fa8cdcc93a783f9b19b7e58cae8f4be606f..39d6fcd98a2667380f36aa5b810c0327a7248fde 100644 (file)
@@ -2,8 +2,8 @@
 # Minimum requirements for the build system to execute.
 requires = [
     "packaging==20.5; platform_machine=='arm64'",  # macos M1
-    "setuptools<49.2.0",
-    "wheel==0.36.2",
+    "setuptools==59.2.0",
+    "wheel==0.37.0",
     "Cython>=0.29.24,<3.0",  # Note: keep in sync with tools/cythonize.py
 ]
 
index dfad538c2327903de2495919055122d495d4966a..1d84f4c4803b6b86be9180745ac2ec5d4689beda 100644 (file)
@@ -16,3 +16,7 @@ filterwarnings =
     ignore:Importing from numpy.matlib is
 # pytest warning when using PYTHONOPTIMIZE
     ignore:assertions not in test modules or plugins:pytest.PytestConfigWarning
+# TODO: remove below when array_api user warning is removed
+    ignore:The numpy.array_api submodule is still experimental. See NEP 47.
+# Ignore DeprecationWarnings from distutils
+    ignore::DeprecationWarning:.*distutils
index 1ff36ab7255ba5910aa6ba7ab2942d9e7165c7c0..a765692b7416e5631af9f43a3cc59101c853a96e 100644 (file)
@@ -1,15 +1,15 @@
 cython==0.29.24
-wheel<0.36.3
-setuptools<49.2.0
-hypothesis==6.12.0
-pytest==6.2.4
-pytz==2021.1
-pytest-cov==2.12.0
+wheel==0.37.0
+setuptools==59.2.0
+hypothesis==6.24.1
+pytest==6.2.5
+pytz==2021.3
+pytest-cov==3.0.0
 pickle5; python_version == '3.7' and platform_python_implementation != 'PyPy'
 # for numpy.random.test.test_extending
-cffi
+cffi; python_version < '3.10'
 # For testing types. Notes on the restrictions:
 # - Mypy relies on C API features not present in PyPy
 # - There is no point in installing typing_extensions without mypy
-mypy==0.812; platform_python_implementation != "PyPy"
-typing_extensions==3.10.0.0; platform_python_implementation != "PyPy"
+mypy==0.910; platform_python_implementation != "PyPy"
+#typing_extensions==3.10.0.0; platform_python_implementation != "PyPy"