Skip to content

Commit

Permalink
BUG: fix broadcast_to for reference types
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyer committed Mar 1, 2015
1 parent 50e4eb8 commit d5a67b5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions numpy/lib/stride_tricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def _broadcast_to(array, shape, subok, readonly):
if any(size < 0 for size in shape):
raise ValueError('all elements of broadcast shape must be non-'
'negative')
broadcast = np.nditer((array,), flags=['multi_index', 'zerosize_ok'],
op_flags=['readonly'], itershape=shape, order='C'
).itviews[0]
broadcast = np.nditer(
(array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'],
op_flags=['readonly'], itershape=shape, order='C').itviews[0]
result = _maybe_view_as_subclass(array, broadcast)
if not readonly and array.flags.writeable:
result.flags.writeable = True
Expand Down
10 changes: 10 additions & 0 deletions numpy/lib/tests/test_stride_tricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,5 +364,15 @@ def test_writeable():
assert_equal(result.flags.writeable, False)


def test_reference_types():
input_array = np.array('a', dtype=object)
expected = np.array(['a'] * 3, dtype=object)
actual = broadcast_to(input_array, (3,))
assert_array_equal(expected, actual)

actual, _ = broadcast_arrays(input_array, np.ones(3))
assert_array_equal(expected, actual)


if __name__ == "__main__":
run_module_suite()

0 comments on commit d5a67b5

Please sign in to comment.