Open safrooze opened 6 years ago
@reminisce
For efficient indexing, __getitem__
slicing would create a view if the sliced elements are contiguous in memory, or a copy if the sliced elements are not contiguous. It's determined by the fact that we only handle NDArray
s with contiguous memory allocation in MXNet.
Operator slice in imperative mode always returns a copy like most of the other operators.
We can make it clear in the docstring of __getitem__
.
That's exactly what I thought is happening. Although keeping efficiency in mind is always great, I see two problems:
Agree it's not a good user experience. Let's add it as a future improvement.
Description
NDArray.__getitem__
has an undocumented and inconsistent behavior with respect to creating a copy or not. Depending on how indexing is called, it may return a pointer to the current buffer or may create a new buffer.Environment info (Required)
Package used (Python/R/Scala/Julia): Python
Minimum reproducible example
The above code results in the following output:
For the record, I also tried NDArray.slice() and mx.nd.slice() calls and they both always create a copy instead of returning a pointer to the existing buffer.