8000 fixed #5147 collapsingbug in einsum by tovrstra · Pull Request #5152 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/einsum.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ get_combined_dims_view(PyArrayObject *op, int iop, char *labels)
else {
/* Update the combined axis dimensions and strides */
i = idim + combineoffset;
if (combineoffset < 0 &&
if (combineoffset < 0 && new_dims[i] != 0 &&
new_dims[i] != PyArray_DIM(op, idim)) {
PyErr_Format(PyExc_ValueError,
"dimensions in operand %d for collapsing "
Expand Down
10 changes: 10 additions & 0 deletions numpy/core/tests/test_einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,16 @@ def test_einsum_fixedstridebug(self):
tp = np.tensordot(A,B, axes=(0,0))
assert_equal(es, tp)

def test_einsum_fixed_collapsingbug(self):
# Issue #5147.
# The bug only occured when output argument of einssum was used.
x = np.random.normal(0, 1, (5, 5, 5, 5))
y1 = np.zeros((5, 5))
np.einsum('aabb->ab', x, out=y1)
idx = np.arange(5)
y2 = x[idx[:, None], idx[:, None], idx, idx]
assert_equal(y1, y2)


if __name__ == "__main__":
run_module_suite()
0