Kotlin / kotlin-numpy

Kotlin bindings for NumPy
Apache License 2.0
316 stars 11 forks source link

Random.multivariateNormal failure #15

Closed alshan closed 4 years ago

alshan commented 4 years ago

Jupyter notebook, Kotlin kernel.

I'm getting an error when evaluating code:

%use lets-plot(apiVersion=0.0.20-SNAPSHOT)
%use numpy(v=0.1.4)

import org.jetbrains.numkt.core.*
import org.jetbrains.numkt.math.*
import org.jetbrains.numkt.random.Random
import org.jetbrains.numkt.*
val cov0 = array<Double>(listOf(listOf(1, -.8),
                        listOf(-.8, 1)))
val cov1 = array<Double>(listOf(listOf(1, .8),
                        listOf(.8, 1)))
val cov2 = array<Double>(listOf(listOf(10, .1),
                        listOf(.1, .1)))

val xy0 = Random.multivariateNormal(mean=array(listOf(-2,0)), cov=cov0, size=intArrayOf(400)).transpose()

Output:

org.jetbrains.numkt.NumKtException: <class 'ValueError'>: check_valid must equal 'warn', 'raise', or 'ignore'
mtrand.numpy.random.mtrand.RandomState.multivariate_normal(mtrand.pyx:4086)
org.jetbrains.numkt.Interpreter.callFunc$kotlin_numpy(Native Method)
org.jetbrains.numkt.UtilsKt.callFunc(Utils.kt:59)
org.jetbrains.numkt.UtilsKt.callFunc$default(Utils.kt:57)
org.jetbrains.numkt.random.Random$Companion.multivariateNormal(Random.kt:532)
org.jetbrains.numkt.random.Random$Companion.multivariateNormal$default(Random.kt:530)
Line_11_jupyter.<init>(Line_11.jupyter.kts:8)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults(BasicJvmScriptEvaluator.kt:96)
kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke$suspendImpl(BasicJvmScriptEvaluator.kt:41)
kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke(BasicJvmScriptEvaluator.kt)
kotlin.script.experimental.jvm.BasicJvmReplEvaluator.eval(BasicJvmReplEvaluator.kt:51)
org.jetbrains.kotlin.jupyter.ReplForJupyterImpl$doEval$resultWithDiagnostics$1.invokeSuspend(repl.kt:475)
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:238)
kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.kt:116)
kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:80)
kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:54)
kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:36)
kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
org.jetbrains.kotlin.jupyter.ReplForJupyterImpl.doEval(repl.kt:475)
org.jetbrains.kotlin.jupyter.ReplForJupyterImpl.eval(repl.kt:345)
org.jetbrains.kotlin.jupyter.ProtocolKt$shellMessagesHandler$res$1.invoke(protocol.kt:143)
org.jetbrains.kotlin.jupyter.ProtocolKt$shellMessagesHandler$res$1.invoke(protocol.kt)
org.jetbrains.kotlin.jupyter.ProtocolKt.evalWithIO(protocol.kt:356)
org.jetbrains.kotlin.jupyter.ProtocolKt.shellMessagesHandler(protocol.kt:142)
org.jetbrains.kotlin.jupyter.IkotlinKt.kernelServer(ikotlin.kt:104)
org.jetbrains.kotlin.jupyter.IkotlinKt.main(ikotlin.kt:59)

I'm not sure if something wrong with my code or this is numpy-kotlin issue.

Trying to reproduce this notebook (py): https://nbviewer.jupyter.org/github/JetBrains/lets-plot/blob/master/docs/examples/jupyter-notebooks/density_2d.ipynb

devcrocod commented 4 years ago

Since numpy 1.17, the multivariate_normal method has default values for the check_valid and tol parameters. In kotlin-numpy, for these parameters None is default.