Skip to content

Default/OpenBLAS matrix.transpose() dot vector yields NaNs and Zeroes compared to Kotlin implementation #345

Description

@nekrozofbrionac

Multik version

0.3.1

Module

multik-default or multik-openblas

Platform

JVM

Operating System

Linux

Description

When using the default or openblas module (on linux), matrix vecctor multiplication yields a corrupted vector when transposing the matrix first, especially if the matrix is not square.

Interestingly, this does not happen when importing the kotlin only module.

Reproducer

// in build.gradle.kts
dependencies {
    implementation("org.jetbrains.kotlinx:multik-default:0.3.1")
    // or
    // implementation("org.jetbrains.kotlinx:multik-openblas:0.3.1")

    // Compare this to 
    // implementation("org.jetbrains.kotlinx:multik-kotlin:0.3.1")
    // when testing
}


// snippet to test 
fun main() {
  val m1 = mk.d2array<Float>(20, 1000) { Random.nextFloat() }
  val v1 = mk.d1array<Float>(20) { Random.nextFloat() }

  val bug = m1.transpose() dot v1

  println(bug.shape.contentToString())
  println("amount of NaNs: " + bug.count { isNaN(it)  })
  println("amount of zeroes: " + bug.count { it == 0f })
}

// This yields 20 NaNs, and 980 zeroes using default, but none of both on kotlin

Additional information

This also does not seem to happen when you reshape the vector as a Nx1 matrix first, but nonetheless it still deviates from expected behaviour.

Let me know if you need more infos to reproduce or similar, i was just certain that this should definitely not be expected

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions