kotlin-numpy icon indicating copy to clipboard operation
kotlin-numpy copied to clipboard

Param `mean` in Random.multivariateNormal doesn't need to be a KtNDArray

Open alshan opened this issue 5 years ago • 6 comments

It is 1-D array_like thing and can be just a std Kotiln collection.

Instead of

Random.multivariateNormal(mean=array(listOf(-2,0)), ...

would be nice to have:

Random.multivariateNormal(mean=listOf(-2,0), ...

alshan avatar Jun 29 '20 19:06 alshan

Alright. I thought that the user will work mainly with ndarray, but in cases where mean is calculated in ndarray, it will be possible to convert using toList().

devcrocod avatar Jun 30 '20 13:06 devcrocod

If KtNDArray implements Iterable then even toList wont be necessary, providing that mean argument had type Iterable.

alshan avatar Jun 30 '20 15:06 alshan

There is one more problem. If we use ndarray, then we simply pass a pointer to it in python, and if we use jvm structure (array, list), then we need to convert it to python array. This is additional overhead.

devcrocod avatar Jun 30 '20 17:06 devcrocod

Isn't the overhead there in any case? mean=array(listOf(-2,0)

alshan avatar Jul 01 '20 01:07 alshan

Would be nice also to relax the type of parameter cov because now I have to create KtNDArrays when I don't really need them.

Compare how Python is so much more concise than Kotlin:

Py: https://nbviewer.jupyter.org/github/JetBrains/lets-plot/blob/master/docs/examples/jupyter-notebooks/density_2d.ipynb Kt: https://nbviewer.jupyter.org/github/JetBrains/lets-plot-kotlin/blob/master/docs/examples/jupyter-notebooks/density_2d.ipynb

alshan avatar Jul 02 '20 19:07 alshan

Isn't the overhead there in any case?

Yes, there is overhead. Only in case of reuse mean will give an improvement.

I agree that it is necessary to support iterable for mean. I will save the signature with KtNDArray and add method with signature for Iterable. I will also find similar methods where this is necessary.

Of course, all this would be easier if KtNDarray implemented the Iterable interface. Here I described what are the difficulties of this.

devcrocod avatar Jul 04 '20 23:07 devcrocod