Kotlin / Kotlin/multik

3 dimensional arrays don't do dot product of sub-matrices correctly

Open
#212 3 comments 0 reactions 0 assignees View on GitHub
bug engine-native
Dominant language
Kotlin
Stars
734
Forks
51
Avg merge
9h 52m
Merged PRs (30d)
6

Description

3 dimensional arrays don't do dot product correctly (unless they have only one top-level element).
Reproducer:
```
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

fun main() {

val a = mk.ndarray(
mk[
mk[
mk[1.0],
mk[0.0],
],
],
)
val b = mk.ndarray(
mk[
mk[
mk[1.0],
mk[0.0],
],
mk[
mk[1.0],
mk[0.0],
],
],
)
println("a[0] dot a[0].T: (CORRECT)")
println(a[0] dot a[0].transpose())

println("\nb[0] dot b[0].T: (WRONG)")
println(b[0] dot b[0].transpose())

println("\nb[1] dot b[1].T: (WRONG)")
println(b[1] dot b[1].transpose())
}
```
prints
```
a[0] dot a[0].T: (CORRECT)
[[1.0, 0.0],
[0.0, 0.0]]

b[0] dot b[0].T: (WRONG)
[[0.0, 0.0],
[0.0, 0.0]]

b[1] dot b[1].T: (WRONG)
[[0.0, 0.0],
[0.0, 0.0]]
```

Contributor guide

Open the contributing guide

Research direction

Start with the linalg.dot implementation used by org.jetbrains.kotlinx.multik.api.linalg.dot and inspect how ndarray slicing and transpose are handled for 3D inputs. Run the reproducer from the issue, compare the one-element and two-element cases, and confirm that each sub-matrix dot product returns the expected nonzero result.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.