diff options
author | Sebastian Berg <sebastianb@nvidia.com> | 2022-11-17 11:40:22 +0100 |
---|---|---|
committer | Sebastian Berg <sebastianb@nvidia.com> | 2022-12-02 00:29:32 +0100 |
commit | bb59cd8da569837335c67091caa50291e74032a3 (patch) | |
tree | 98bdf6f9b8ecab7f089bc840c1f46882cf8c89fe /numpy | |
parent | 402545b801aedd7034d4a861d3e4b3d1fc61e2ce (diff) | |
download | numpy-bb59cd8da569837335c67091caa50291e74032a3.tar.gz |
MAINT: Move check and expand error message slightly
In principle, this is probably still not 100% correct always since
we convert the the other object to an array upfront (to get the
error). But the alternative solution using `axes=` seems tricky
as well...
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/number.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/number.c b/numpy/core/src/multiarray/number.c index 0b5b46fc5..2c037d918 100644 --- a/numpy/core/src/multiarray/number.c +++ b/numpy/core/src/multiarray/number.c @@ -355,6 +355,9 @@ array_inplace_matrix_multiply(PyArrayObject *m1, PyObject *m2) int m1_ndim; int m2_ndim; + INPLACE_GIVE_UP_IF_NEEDED(m1, m2_array, + nb_inplace_matrix_multiply, array_inplace_matrix_multiply); + /* Explicitly raise a ValueError when the output would * otherwise be broadcasted to `m1`. Three conditions must be met: * * `m1.ndim in [1, 2]` @@ -368,12 +371,12 @@ array_inplace_matrix_multiply(PyArrayObject *m1, PyObject *m2) && (PyArray_DIMS(m1)[m1_ndim - 1] == PyArray_DIMS(m2_array)[0])) { PyErr_Format(PyExc_ValueError, "output parameter has the wrong number of dimensions: " - "Found %d but expected %d", m1_ndim - 1, m1_ndim); + "Found %d but expected %d. Certain broadcasts may be " + "accepted for `np.matmul(a, b, out=a)`.", + m1_ndim - 1, m1_ndim); return NULL; } - INPLACE_GIVE_UP_IF_NEEDED(m1, m2_array, - nb_inplace_matrix_multiply, array_inplace_matrix_multiply); return PyArray_GenericInplaceBinaryFunction(m1, (PyObject *)m2_array, n_ops.matmul); } |