Open alshan opened 4 years ago
The problem with the implementation of the KtNdArray Iterable interface is that Iterable methods are for the most part extensions functions and can't be override.
Not sure why it is necessary to override methods like toList
. KtNDArray will provide an iterator (ListIterator maybe) and all the rest will work out of the box IMO. Alternatively KtNDArray can implement List
interface.
Iterable has functions plus, minus, max, min, etc. Some of these features are required for ndarray.
IMHO this is not an issue. When user works with KtNDArray
all expressions have type KtNDArray
and all extensions work as expected.
A code which doesn't know about kotlin numpy works with std Kotlin collections (all expressions have Iterable, List etc. types) and again all extensions work as expected.
I don't see how user would unintentionally mix those two environments and get confused.
For example:
Iterable.plus
returns a List
and KtNDArray.plus
returns a new KtNdArray
. If KtNDArray
will implement the Iterable interface, then in the following code val a = array(arrayOf(1, 2)) + array(arrayOf(3, 4))
the method that returns List will be used first. Explicit import and type will be required for to use KtNDArray.plus
:
import org.jetbrains.numkt.core.KtNDArray
import org.jetbrains.numkt.math.plus
val a: KtNDArray<Int> = array(arrayOf(1, 2)) + array(arrayOf(3, 4))
Which complicates the use of the library.
To implement Iterable, it is necessary that a primitive type (scalars) be returned during iteration. Currently, iterating returns an NdArray view. This is not the final version, I need to think about a better API iterator. It is necessary to give the user the ability to iterate over slices and scalars.
Yes, (1) certainly is not looking good.
Now when passing 1d KtNDArray as a data series to lets-plot user have to explicitly call
toList()
.