Skip to content

Instantly share code, notes, and snippets.

@natemurthy
Created April 23, 2015 03:59
Show Gist options
  • Save natemurthy/5a508259ec0cbed34c3c to your computer and use it in GitHub Desktop.
Save natemurthy/5a508259ec0cbed34c3c to your computer and use it in GitHub Desktop.
import breeze.linalg._
def generateMat(n: Int): DenseMatrix[Double] = {
val mat = DenseMatrix.zeros[Double](n,n)
for (k <- 0 until n) {
var rv = DenseVector.ones[Double](n)
rv = rv*math.random
rv(k) = rv(k)*(k+1)
mat(k,::) := rv.t
}
mat
}
// preload netlib-native_system-linux-x86_64.so
val preload = generateMat(1)
val N = 2000
// matrix construction
val s = System.nanoTime; val A = generateMat(N); val e = System.nanoTime; println((e-s)/1e9) // 0.12378400 sec
// matrix inverse
val s = System.nanoTime; val result = inv(A); val e = System.nanoTime; println((e-s)/1e9) // 7.52344470 sec
// matrix eigen[values/vectors]
val s = System.nanoTime; val result = eig(A); val e = System.nanoTime; println((e-s)/1e9) // 29.50494831 sec
// singular value decomposition
val s = System.nanoTime; val result = svd(A); val e = System.nanoTime; println((e-s)/1e9) // 14.71855718 sec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment