Created
February 6, 2017 13:11
-
-
Save yousry/6ce5863de5f7ffb64e7f0fb4db31e101 to your computer and use it in GitHub Desktop.
Playing with Breeze
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.yousry.linearalgebra | |
import scala.language.postfixOps | |
import breeze.linalg.{DenseMatrix, DenseVector} | |
import breeze.numerics._ | |
import com.typesafe.scalalogging.LazyLogging | |
// To Start: LD_PRELOAD=/usr/lib/libcblas.so sbt | |
/** | |
* Created by yousry on 06.02.17. | |
*/ | |
object Main extends App with LazyLogging { | |
logger.debug("Main") | |
val p = DenseVector[Float](0,1,0) | |
logger.debug("Vector p: " + p ) | |
val pLength = sqrt(p.map(pow(_,2)).reduceLeft(_+_)) | |
logger.debug("|p|: " + pLength ) | |
val rotX = toRadians(90.0) | |
val m = DenseMatrix.zeros[Float](4,4) | |
m(0,0) = 1.0F | |
m(0,1) = 0 | |
m(0,2) = 0 | |
m(0,3) = 0 | |
m(1,0) = 0 | |
m(1,1) = cos(rotX).toFloat | |
m(1,2) = -sin(rotX).toFloat | |
m(1,3) = 0 | |
m(2,0) = 0 | |
m(2,1) = sin(rotX).toFloat | |
m(2,2) = cos(rotX).toFloat | |
m(2,3) = 0 | |
m(3,0) = 0 | |
m(3,1) = 0 | |
m(3,2) = 0 | |
m(3,3) = 1 | |
logger.debug("m: \n" + m ) | |
// doesn't work: val r = m * p | |
val q = DenseVector[Float](0,1,0,1) | |
val startTime = System.nanoTime() | |
val r = m * q; | |
val duration : Double = (System.nanoTime() - startTime).toDouble / 1000000000.0 | |
logger.debug(f"Computation Time: $duration%.5f") | |
val r3d = Vector() ++ (List() ++ r.toArray).init.map(_/r(3)) | |
logger.debug("r3d:" + r3d) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment