Kotlin / multik

Multidimensional array library for Kotlin
https://kotlin.github.io/multik/
Apache License 2.0
632 stars 39 forks source link

Strange dot behaviour with row from a D2 array #153

Closed davydes closed 1 year ago

davydes commented 1 year ago

I faced with a bug, see below:

import org.jetbrains.kotlinx.multik.api.linalg.dot
import org.jetbrains.kotlinx.multik.api.mk
import org.jetbrains.kotlinx.multik.api.ndarray
import org.jetbrains.kotlinx.multik.ndarray.data.get

class Test {
  companion object {
    @JvmStatic
    fun main(args: Array<String>) {
      val v = mk.ndarray(mk[1.0, 1.0])
      val m = mk.ndarray(mk[mk[1.0, 2.0], mk[3.0, 4.0]])

      println("${m[0]} x $v = ${m[0] dot v}")
      println("${m[1]} x $v = ${m[1] dot v}")
    }
  }
}
[1.0, 2.0] x [1.0, 1.0] = 3.0
[3.0, 4.0] x [1.0, 1.0] = 3.0
devcrocod commented 1 year ago

What exactly is wrong?

davydes commented 1 year ago

What does mean the result? The first result is ok, the second is wrong [3.0, 4.0] x [1.0, 1.0] = 3 + 4 = 7

devcrocod commented 1 year ago

I didn't notice right away. This bug is due to incorrect stride in native code, in multik-kotlin it works correctly. I'll fix this bug and publish a new version of the library.