is the svd function robust

Skip to first unread message

Jim Newton

Apr 4, 2021, 11:58:54 AM4/4/21
to Scala Breeze
I'm trying to use breeze to test some of my own code.
I.e., I have some code that computes exp(M).
I'd like to test using breeze.
My testing code computes (u,s,v) by calling svd(m)
Then I compute: exp(m) = u * ( {x:Double => math.exp(x)}) * v

There are two issues I see.  Are these known issues?  Or do I need to prepare a test case and file a bug report?   I'm a 1st time user, so maybe these are known issues?

1.  I get a bunch of unwanted INFO messages of the form:

Apr 04, 2021 11:35:58 AM com.github.fommil.jni.JniLoader liberalLoad
INFO: successfully loaded 
Apr 04, 2021 11:35:58 AM com.github.fommil.jni.JniLoader load

2. java.lang.IllegalArgumentException on the following code

val dm = DenseMatrix.tabulate(dim, dim){case (i, j) => this(i,j)}
val svd.SVD(u,s,v) = svd(dm)
println("exp lambda = " + ( {x:Double => math.exp(x)}))

val em = u * ( {x:Double => math.exp(x)}) * v

Here is the output

dm=[-0.9315079940605946  -0.8636480438490705  
-0.9371076081540446  0.3813488062121273   ]
u=[-0.8593567106990224  -0.5113766163763811  
-0.5113766163763811  0.8593567106990224   ]
s=[DenseVector(1.39178232086381, 0.8367404849973938)]
v=[0.9194775249120006    0.39314257106258693  
-0.39314257106258693  0.9194775249120006   ]
exp lambda = DenseVector(4.02201218472115, 2.308829035558848)

requirement failed: b.rows == 1 (2 != 1)
java.lang.IllegalArgumentException: requirement failed: b.rows == 1 (2 != 1)
at breeze.linalg.operators.DenseMatrixMultiplyStuff$$anon$3.apply(DenseMatrixOps.scala:126)
at breeze.linalg.operators.DenseMatrixMultiplyStuff$$anon$3.apply(DenseMatrixOps.scala:124)
at breeze.linalg.ImmutableNumericOps.$times(NumericOps.scala:118)
at breeze.linalg.ImmutableNumericOps.$times$(NumericOps.scala:117)
at breeze.linalg.DenseVector.$times(DenseVector.scala:56)
at homework.Transcendentals$sqMatrix.expB(HW-Transcendentals-solution.scala:308)
at TranscendentalsTestSuite.$anonfun$new$76(TranscendentalsTestSuite.scala:515)
at scala.collection.immutable.Vector.foreach(Vector.scala:1856)
at TranscendentalsTestSuite.$anonfun$new$70(TranscendentalsTestSuite.scala:494)
at scala.runtime.java8.JFunction1$mcVI$sp.apply(JFunction1$mcVI$sp.scala:18)
at scala.collection.immutable.List.foreach(List.scala:333)
at TranscendentalsTestSuite.$anonfun$new$69(TranscendentalsTestSuite.scala:493)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)

Jim Newton

Apr 6, 2021, 10:50:35 AM4/6/21
to Scala Breeze
I figured out problem #2.  The middle value returned from svd is not a nxn diagonal matrix, but rather a vector. I can convert it back to a matrix with the diag function

David Hall

Apr 6, 2021, 7:35:36 PM4/6/21
The info messages should only show up the first the time any breeze function is called. Netlib-java uses java's builtin java.util.logging stuff and can be configured that way. It's a bit of a pain to do honestly.

-- David

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
To view this discussion on the web visit
Reply all
Reply to author
0 new messages