Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Put with NDArrayIndex.empty() fails #6940
The following two test cases fail:
The first crashes with the following exception:
and the second sets all elements to 0 (expect none to be set).
Btw, issue surfaced in code which tried to be clever by putting an element of an INDArrayIndex array to empty to create a no-op at a later stage. It was obviously easy to work around.
Please indicate relevant versions, including, if relevant:
Given this is an error and not just misunderstanding of the empty INDArrayIndex, I can take a stab at it if you don't have time. I guess it is at least possible to work around by just checking if any element is the empty element.
Hm... I didn't realize we even had an NDArrayIndex.empty()
I see two possible options here:
Thoughts? Unless there's a reasonable use case here, I'm in favor of just removing it.
Even though I do have a something resembling a use case in the method shiftDim in https://github.com/DrChainsaw/neuralODE4j/blob/master/src/main/java/util/preproc/ShiftDim.java, I don't think it is significant enough to make it worthwhile to either introduce the concept of empty INDArrays (or what else would be the result of arr.get(NDArrayIndex.empty()?) and define what it means to do operations including them or to accept the inconsistency that empty only means "put is a noop" and exception everywhere else.
Note: I'm assuming empty INDArrays are not defined or supported as I recally that (accidental) attempts to create such (e.g through Nd4j.zeros(0) because "yes, I want an array with only zeros") results in an exception.
We do already support empty INDArrays (Nd4j.empty() and Nd4j.empty(DataType) on master) - not because we think it's necessarily a good idea, but rather because we mainly need it for tensorflow import compatibility. That said, empty arrays do have a few use cases (for ops like 'put all elements matching condition X into a new array' where no elements match the condition). However, indexing operations (get/set ops) on empty arrays doesn't really make sense.
No strong opinion from me on that. The "use case" might look something like this: