DenseMatrix[Int] multiplication problem

27 views
Skip to first unread message

Sungho Ham

unread,
Jan 16, 2018, 10:53:59 PM1/16/18
to Scala Breeze
Hi.

Multiplication of DenseMatrix.eye[Int] gives zero when matrix size over 2000.
I tested with two BLAS, but they gave same wrong result.

build.sbt
scalaVersion := "2.11.11"
"org.scalanlp" %% "breeze" % "0.13.2"
"org.scalanlp" %% "breeze-natives" % "0.12"

test function
def mulTest(size: Int): Unit = {
val b = BLAS.getInstance()
println(s"BLAS = $b")
val simMatrix1 = DenseMatrix.eye[Int](size)
println((simMatrix1 * simMatrix1).valueAt(0, 0))
}



1. NativeBLAS

----- code -----
mulTest(2000)
mulTest(2001)

----- result -----
BLAS = com.github.fommil.netlib.NativeSystemBLAS@72b6cbcc
1
BLAS = com.github.fommil.netlib.NativeSystemBLAS@72b6cbcc
0


2. F2jBlas

----- VM options ----- 
-Dcom.github.fommil.netlib.BLAS=com.github.fommil.netlib.F2jBLAS
-Dcom.github.fommil.netlib.LAPACK=com.github.fommil.netlib.F2jLAPACK
-Dcom.github.fommil.netlib.ARPACK=com.github.fommil.netlib.F2jARPACK

----- code -----
mulTest(2000)
mulTest(2001)

----- result -----
BLAS = com.github.fommil.netlib.F2jBLAS@4f970963
1
BLAS = com.github.fommil.netlib.F2jBLAS@4f970963
0



Thanks.





David Hall

unread,
Jan 16, 2018, 10:56:17 PM1/16/18
to scala-...@googlegroups.com
Oof.

I have a hand-rolled matrix multiply for ints since it's not in blas, and 2000 is a blocksize threshold. sorry about that. I'll fix it

--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze+unsubscribe@googlegroups.com.
To post to this group, send email to scala-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-breeze/c5bef1d3-e944-42b9-9d45-1f24eb0055ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Hall

unread,
Jan 17, 2018, 12:01:50 AM1/17/18
to scala-...@googlegroups.com
(fixed in master)

Sungho Ham

unread,
Jan 17, 2018, 12:03:21 AM1/17/18
to Scala Breeze
Thank for your help, David!
I will use Double instead of Int for a while.

2018년 1월 17일 수요일 오후 12시 56분 17초 UTC+9, David Hall 님의 말:
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze...@googlegroups.com.

David Hall

unread,
Jan 17, 2018, 12:06:22 AM1/17/18
to scala-...@googlegroups.com
Honestly, assuming you're using native blas and not f2j (and you're not worrying about integer overflow/underflow), doubles are always going to be faster. I almost just made Int/Int matrix multiply just convert everything to doubles, but i decided not to.

To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze+unsubscribe@googlegroups.com.

To post to this group, send email to scala-...@googlegroups.com.

Sungho Ham

unread,
Jan 17, 2018, 12:20:19 AM1/17/18
to Scala Breeze
I agree with your decision. Implicit convert to double will cause unexpected result for user.
Thank you again for your support. 

2018년 1월 17일 수요일 오후 2시 6분 22초 UTC+9, David Hall 님의 말:
Reply all
Reply to author
Forward
0 new messages