ND4J INDArray
slicing is achieved through one of the overloaded get()
methods as answered in java - Get an arbitrary slice of a Nd4j array - Stack Overflow. As an INDArray
takes a continuous block of native memory, does slicing using get()
make a copy of the original memory (especially row slicing, in which it is possible create a new INDArray
with the same backing memory)?
I have found another INDArray
method subArray()
. Does this one make any difference?
I am asking this because I am trying to create a DatasetIterator
that can directly extract data from INDArray
s, and I want to eliminate possible overhead. There is too much abstraction in the source code and I couldn't find the implementation myself.
A similar question about NumPy is asked in python - Numpy: views vs copy by slicing - Stack Overflow, and the answer can be found in Indexing — NumPy v1.16 Manual:
The rule of thumb here can be: in the context of lvalue indexing (i.e. the indices are placed in the left hand side value of an assignment), no view or copy of the array is created (because there is no need to). However, with regular values, the above rules for creating views does apply.