summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime Fernandez <jaime.frio@gmail.com>2018-03-26 00:45:59 +0200
committerJaime Fernandez <jaime.frio@gmail.com>2018-03-26 00:45:59 +0200
commita1146a9a473b7dc229fe457a383afd5394cd5cf2 (patch)
treef81d6d65d6c9789fa87cda359b3a31261a7e599f
parente4d678a2f5859d29a853d617e9e5bbd4b6241898 (diff)
downloadpython-numpy-a1146a9a473b7dc229fe457a383afd5394cd5cf2.tar.gz
python-numpy-a1146a9a473b7dc229fe457a383afd5394cd5cf2.tar.bz2
python-numpy-a1146a9a473b7dc229fe457a383afd5394cd5cf2.zip
BUG: Incorrect mapping of einsum axes.
-rw-r--r--numpy/core/src/multiarray/einsum.c.src7
-rw-r--r--numpy/core/tests/test_einsum.py6
2 files changed, 9 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/einsum.c.src b/numpy/core/src/multiarray/einsum.c.src
index 7db606194..e482d3280 100644
--- a/numpy/core/src/multiarray/einsum.c.src
+++ b/numpy/core/src/multiarray/einsum.c.src
@@ -2185,7 +2185,7 @@ get_combined_dims_view(PyArrayObject *op, int iop, char *labels)
{
npy_intp new_strides[NPY_MAXDIMS];
npy_intp new_dims[NPY_MAXDIMS];
- int i, idim, ndim, icombine, combineoffset, label;
+ int idim, ndim, icombine, combineoffset;
int icombinemap[NPY_MAXDIMS];
PyArrayObject *ret = NULL;
@@ -2205,7 +2205,7 @@ get_combined_dims_view(PyArrayObject *op, int iop, char *labels)
* The char type may be either signed or unsigned, we
* need it to be signed here.
*/
- label = (signed char)labels[idim];
+ int label = (signed char)labels[idim];
/* If this label says to merge axes, get the actual label */
if (label < 0) {
combineoffset = label;
@@ -2225,7 +2225,7 @@ get_combined_dims_view(PyArrayObject *op, int iop, char *labels)
}
else {
/* Update the combined axis dimensions and strides */
- i = idim + combineoffset;
+ int i = icombinemap[idim + combineoffset];
if (combineoffset < 0 && new_dims[i] != 0 &&
new_dims[i] != PyArray_DIM(op, idim)) {
PyErr_Format(PyExc_ValueError,
@@ -2235,7 +2235,6 @@ get_combined_dims_view(PyArrayObject *op, int iop, char *labels)
(int)PyArray_DIM(op, idim));
return NULL;
}
- i = icombinemap[i];
new_dims[i] = PyArray_DIM(op, idim);
new_strides[i] += PyArray_STRIDE(op, idim);
}
diff --git a/numpy/core/tests/test_einsum.py b/numpy/core/tests/test_einsum.py
index 9bd85fdb9..5863c11ad 100644
--- a/numpy/core/tests/test_einsum.py
+++ b/numpy/core/tests/test_einsum.py
@@ -791,6 +791,12 @@ class TestEinSum(object):
self.optimize_compare('dba,ead,cad->bce')
self.optimize_compare('aef,fbc,dca->bde')
+ def test_combined_views_mapping(self):
+ # gh-10792
+ a = np.arange(9).reshape(1, 1, 3, 1, 3)
+ b = np.einsum('bbcdc->d', a)
+ assert_equal(b, [12])
+
class TestEinSumPath(object):
def build_operands(self, string, size_dict=global_size_dict):