diff options
author | Mark Wiebe <mwwiebe@gmail.com> | 2011-03-10 12:07:49 -0800 |
---|---|---|
committer | Mark Wiebe <mwwiebe@gmail.com> | 2011-03-10 12:08:49 -0800 |
commit | 9e28fce21a7bec4c9f1e8c686f63c57ea475c439 (patch) | |
tree | f0ea03a80c6468028811fedb5a04bf13696d917e | |
parent | 326afcaacb9b7105dbca2a8295e0cb5dfd562501 (diff) | |
download | numpy-9e28fce21a7bec4c9f1e8c686f63c57ea475c439.tar.gz |
BUG: Broadcast shape was backwards in error message (Ticket #1762)
-rw-r--r-- | numpy/core/src/multiarray/new_iterator.c.src | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_new_iterator.py | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/new_iterator.c.src b/numpy/core/src/multiarray/new_iterator.c.src index 3d8566f05..9f628ec55 100644 --- a/numpy/core/src/multiarray/new_iterator.c.src +++ b/numpy/core/src/multiarray/new_iterator.c.src @@ -3766,7 +3766,7 @@ operand_different_than_broadcast: { /* Fill in the broadcast shape */ axisdata = NIT_AXISDATA(iter); for (idim = 0; idim < ndim; ++idim) { - remdims[idim] = NAD_SHAPE(axisdata); + remdims[ndim-idim-1] = NAD_SHAPE(axisdata); NIT_ADVANCE_AXISDATA(axisdata, 1); } diff --git a/numpy/core/tests/test_new_iterator.py b/numpy/core/tests/test_new_iterator.py index d796b3cf2..404735223 100644 --- a/numpy/core/tests/test_new_iterator.py +++ b/numpy/core/tests/test_new_iterator.py @@ -595,6 +595,23 @@ def test_iter_broadcasting_errors(): [arange(8).reshape(2,4,1), arange(24).reshape(2,3,4)], [], [['readonly']]*2) + # Verify that the error message mentions the right shapes + try: + i = newiter([arange(2).reshape(1,2,1), + arange(3).reshape(1,3), + arange(6).reshape(2,3)], + [], + [['readonly'], ['readonly'], ['writeonly','no_broadcast']]) + assert_(False, 'Should have raised a broadcast error') + except ValueError, e: + msg = str(e) + # The message should contain the shape of the 3rd operand + assert_(msg.find('(2,3)') >= 0, + 'Message "%s" doesn\'t contain operand shape (2,3)' % msg) + # The message should contain the broadcast shape + assert_(msg.find('(1,2,3)') >= 0, + 'Message "%s" doesn\'t contain broadcast shape (1,2,3)' % msg) + def test_iter_flags_errors(): # Check that bad combinations of flags produce errors |