diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-07-09 06:35:23 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-07-09 06:35:23 -0700 |
commit | 6eeb6122cc7126500e0ea7d19cea2e7dc8904e9d (patch) | |
tree | f2e4a11dbd80e801b05cc14fb792da4a6f6dd18c /numpy/core/src | |
parent | 884c403605d5679d4e224bb24263a490f1249b6f (diff) | |
parent | 4441bdd95197ba10651eee8366e67176fb3b5b51 (diff) | |
download | numpy-6eeb6122cc7126500e0ea7d19cea2e7dc8904e9d.tar.gz |
Merge pull request #3501 from inducer/master
Fix "numpy scalar * array-like == performance horror"
Diffstat (limited to 'numpy/core/src')
-rw-r--r-- | numpy/core/src/multiarray/number.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/number.c b/numpy/core/src/multiarray/number.c index 9e13d0f29..392370667 100644 --- a/numpy/core/src/multiarray/number.c +++ b/numpy/core/src/multiarray/number.c @@ -209,6 +209,26 @@ PyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op) Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } + + if (!PyArray_Check(m2)) { + /* + * Catch priority inversion and punt, but only if it's guaranteed + * that we were called through m1 and the other guy is not an array + * at all. Note that some arrays need to pass through here even + * with priorities inverted, for example: float(17) * np.matrix(...) + * + * See also: + * - https://github.com/numpy/numpy/issues/3502 + * - https://github.com/numpy/numpy/issues/3503 + */ + double m1_prio = PyArray_GetPriority(m1, NPY_SCALAR_PRIORITY); + double m2_prio = PyArray_GetPriority(m2, NPY_SCALAR_PRIORITY); + if (m1_prio < m2_prio) { + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } + } + return PyObject_CallFunction(op, "OO", m1, m2); } |