diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2015-05-30 11:08:31 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2015-06-04 18:00:50 -0600 |
commit | 1b6193b977c1a411a497ccab4ddf741e3b4849c1 (patch) | |
tree | 484868ffe0a586e12f86895d41ade0001734d412 | |
parent | 721675e19dd3f0c798f9582f69ea153484917e34 (diff) | |
download | numpy-1b6193b977c1a411a497ccab4ddf741e3b4849c1.tar.gz |
ENH: Add support for the '@' operator added in Python 3.5.
-rw-r--r-- | numpy/core/src/multiarray/number.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/number.c b/numpy/core/src/multiarray/number.c index 168799f11..a2160afd8 100644 --- a/numpy/core/src/multiarray/number.c +++ b/numpy/core/src/multiarray/number.c @@ -8,11 +8,10 @@ #include "numpy/arrayobject.h" #include "npy_config.h" - #include "npy_pycompat.h" - -#include "number.h" +#include "npy_import.h" #include "common.h" +#include "number.h" /************************************************************************* **************** Implement Number Protocol **************************** @@ -386,6 +385,24 @@ array_remainder(PyArrayObject *m1, PyObject *m2) return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder); } + +#if PY_VERSION_HEX >= 0x03050000 +/* Need this to be version dependent on account of the slot check */ +static PyObject * +array_matrix_multiply(PyArrayObject *m1, PyObject *m2) +{ + static PyObject *matmul = NULL; + + npy_cache_pyfunc("numpy.core.multiarray", "matmul", &matmul); + if (matmul == NULL) { + return NULL; + } + GIVE_UP_IF_HAS_RIGHT_BINOP(m1, m2, "__matmul__", "__rmatmul__", + 0, nb_matrix_multiply); + return PyArray_GenericBinaryFunction(m1, m2, matmul); +} +#endif + /* Determine if object is a scalar and if so, convert the object * to a double and place it in the out_exponent argument * and return the "scalar kind" as a result. If the object is @@ -723,6 +740,7 @@ array_inplace_true_divide(PyArrayObject *m1, PyObject *m2) n_ops.true_divide); } + static int _array_nonzero(PyArrayObject *mp) { @@ -1066,5 +1084,9 @@ NPY_NO_EXPORT PyNumberMethods array_as_number = { (binaryfunc)array_true_divide, /*nb_true_divide*/ (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/ (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/ - (unaryfunc)array_index, /* nb_index */ + (unaryfunc)array_index, /*nb_index */ +#if PY_VERSION_HEX >= 0x03050000 + (binaryfunc)array_matrix_multiply, /*nb_matrix_multiply*/ + (binaryfunc)NULL, /*nb_inplacematrix_multiply*/ +#endif }; |