Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix ndarray indexing bug #16895

Merged
merged 3 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add test from 16647
  • Loading branch information
reminisce committed Dec 5, 2019
commit 604d9bdad40b0224b3a21196a8409283dc223b88
2 changes: 1 addition & 1 deletion src/ndarray/ndarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ NDArray NDArray::Reshape(const mxnet::TShape &shape) const {
<< "current shape.";
} else {
CHECK_GE(shape_.Size(), shape.Size())
<< "NDArray.Reshape: target shape size is larger current shape";
<< "NDArray.Reshape: target shape size is larger than the current shape";
}
NDArray ret = this->Detach();
// If the shape doesn't change, we can just return it now.
Expand Down
16 changes: 16 additions & 0 deletions tests/python/unittest/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ def test_ndarray_setitem():
assert x.shape == trivial_shape
assert same(x.asnumpy(), x_np)

# test https://github.com/apache/incubator-mxnet/issues/16647
dst = mx.nd.zeros((1, 3, 1)) # destination array
src = [1, 2, 3]
dst[0, :len(src), 0] = src
assert same(dst.asnumpy(), np.array([1, 2, 3], dtype=dst.dtype).reshape(dst.shape))

dst = mx.nd.zeros((1, 3, 1)) # destination array
src = [1, 2, 3]
dst[0, :len(src), 0] = mx.nd.array(src)
assert same(dst.asnumpy(), np.array([1, 2, 3], dtype=dst.dtype).reshape(dst.shape))

dst = mx.nd.zeros((1, 3, 1)) # destination array
src = [1, 2]
dst[0, :len(src), 0] = src
assert same(dst.asnumpy(), np.array([1, 2, 0], dtype=dst.dtype).reshape(dst.shape))


@with_seed()
def test_ndarray_elementwise():
Expand Down