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

[Numpy] Bug of basic indexing #16887

Closed
sxjscience opened this issue Nov 22, 2019 · 2 comments · Fixed by #16902
Closed

[Numpy] Bug of basic indexing #16887

sxjscience opened this issue Nov 22, 2019 · 2 comments · Fixed by #16902
Assignees

Comments

@sxjscience
Copy link
Member

Found this bug when writing random test cases for symbolic indexing.

import mxnet as mx
from mxnet import gluon
mx.npx.set_np()

a = mx.np.random.normal(0, 1, (5, 5, 5, 5))
b = mx.np.random.normal(0, 1, (5, 5, 5, 5))
index1 = (slice(3, 0, -1), slice(1, 0, -1), slice(2, 0, -1), slice(3, 0, -1))
index2 = (slice(2, 3, 2), slice(0, 1, 2), slice(1, 2, 2), slice(1, 3, 2))

class Foo(gluon.HybridBlock):
    def hybrid_forward(self, F, x, y):
        return (x[()][index1] + y[()][index1])[index2]

net = Foo()
with mx.autograd.record():
    out = net(a, b)

Error:

MXNetError: [07:04:22] src/ndarray/ndarray.cc:263: Check failed: shape_.Size() == shape.Size() (2 vs. 1) : NDArray.Reshape: target shape must have the same size as current shape when recording with autograd.
Stack trace:
  [bt] (0) /home/ubuntu/mxnet/python/mxnet/../../lib/libmxnet.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x32) [0x7f1da2489c42]
  [bt] (1) /home/ubuntu/mxnet/python/mxnet/../../lib/libmxnet.so(mxnet::NDArray::ReshapeWithRecord(mxnet::TShape const&)+0x187) [0x7f1da59d4877]
  [bt] (2) /home/ubuntu/mxnet/python/mxnet/../../lib/libmxnet.so(MXNDArrayReshape64+0xa7) [0x7f1da612f2e7]
  [bt] (3) /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(ffi_call_unix64+0x4c) [0x7f1e6fc14e20]
  [bt] (4) /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(ffi_call+0x2eb) [0x7f1e6fc1488b]
  [bt] (5) /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(_ctypes_callproc+0x49a) [0x7f1e6fc0f01a]
  [bt] (6) /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so(+0x9fcb) [0x7f1e6fc02fcb]
  [bt] (7) /usr/bin/python3(PyObject_Call+0x47) [0x5c3bd7]
  [bt] (8) /usr/bin/python3(PyEval_EvalFrameEx+0x4f2f) [0x5354af]
@reminisce
Copy link
Contributor

NDArray._basic_indexing_contiguous_flat_begin_end has a bug. I will send in a fix.

@sxjscience
Copy link
Member Author

sxjscience commented Nov 22, 2019

Another case fails after I changed https://github.com/apache/incubator-mxnet/blob/4da14a22385622c35e9a5c9c3e8a17c07f718cad/python/mxnet/ndarray/ndarray.py#L902. Will need more time to debug this problem.

import mxnet as mx
from mxnet import gluon
mx.npx.set_np()
a = mx.np.random.normal(0, 1, (5, 5, 5, 5))
b = mx.np.random.normal(0, 1, (5, 5, 5, 5))
index1 = (slice(4, 1, -1), slice(2, 1, -1), 3, 0)
index2 = (slice(2, 3, 1), slice(0, 1, 1))

class Foo(gluon.HybridBlock):
    def hybrid_forward(self, F, x, y):
        return (x[()][index1] + y[()][index1])[index2]

net = Foo()
with mx.autograd.record():
    out = net(a, b)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants