diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-03-26 00:55:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-26 00:55:10 -0700 |
commit | 342f0e34c4921a20f193c339e4ca15e0d70a10ae (patch) | |
tree | 655576a814ecee9b7a6c2ec508d41e85b68707a5 | |
parent | eca4175abcdff3fc506992c74fbab67aeb48153e (diff) | |
parent | a1146a9a473b7dc229fe457a383afd5394cd5cf2 (diff) | |
download | python-numpy-342f0e34c4921a20f193c339e4ca15e0d70a10ae.tar.gz python-numpy-342f0e34c4921a20f193c339e4ca15e0d70a10ae.tar.bz2 python-numpy-342f0e34c4921a20f193c339e4ca15e0d70a10ae.zip |
Merge pull request #10798 from jaimefrio/einsum_mapping
BUG: error checking before mapping of einsum axes.
-rw-r--r-- | numpy/core/src/multiarray/einsum.c.src | 7 | ||||
-rw-r--r-- | numpy/core/tests/test_einsum.py | 6 |
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): |