From fe983b0e7d62359275a92c2adaae8a635d7dd5d8 Mon Sep 17 00:00:00 2001 From: Li Pu Date: Wed, 4 Jun 2014 00:01:29 -0700 Subject: [PATCH] improve scala style --- .../linalg/EigenValueDecomposition.scala | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/mllib/src/main/scala/org/apache/spark/mllib/linalg/EigenValueDecomposition.scala b/mllib/src/main/scala/org/apache/spark/mllib/linalg/EigenValueDecomposition.scala index fc283cbe1472d..99e104feb2207 100644 --- a/mllib/src/main/scala/org/apache/spark/mllib/linalg/EigenValueDecomposition.scala +++ b/mllib/src/main/scala/org/apache/spark/mllib/linalg/EigenValueDecomposition.scala @@ -17,10 +17,11 @@ package org.apache.spark.mllib.linalg -import org.apache.spark.annotation.Experimental import breeze.linalg.{DenseMatrix => BDM, DenseVector => BDV} -import org.netlib.util.{intW, doubleW} import com.github.fommil.netlib.ARPACK +import org.netlib.util.{intW, doubleW} + +import org.apache.spark.annotation.Experimental /** * :: Experimental :: @@ -46,11 +47,11 @@ object EigenValueDecomposition { : (BDV[Double], BDM[Double]) = { require(n > k, s"Number of required eigenvalues $k must be smaller than matrix dimension $n") - val arpack = ARPACK.getInstance() + val arpack = ARPACK.getInstance() val tolW = new doubleW(tol) val nev = new intW(k) - val ncv = scala.math.min(2*k,n) + val ncv = scala.math.min(2 * k, n) val bmat = "I" val which = "LM" @@ -63,9 +64,9 @@ object EigenValueDecomposition { var ido = new intW(0) var info = new intW(0) var resid:Array[Double] = new Array[Double](n) - var v = new Array[Double](n*ncv) - var workd = new Array[Double](3*n) - var workl = new Array[Double](ncv*(ncv+8)) + var v = new Array[Double](n * ncv) + var workd = new Array[Double](n * 3) + var workl = new Array[Double](ncv * (ncv + 8)) var ipntr = new Array[Int](11) // first call to ARPACK @@ -74,9 +75,10 @@ object EigenValueDecomposition { val w = BDV(workd) - while(ido.`val` !=99) { - if (ido.`val` != -1 && ido.`val` != 1) + while(ido.`val` != 99) { + if (ido.`val` != -1 && ido.`val` != 1) { throw new IllegalStateException("ARPACK returns ido = " + ido.`val`) + } // multiply working vector with the matrix val inputOffset = ipntr(0) - 1 val outputOffset = ipntr(1) - 1 @@ -88,8 +90,9 @@ object EigenValueDecomposition { workd, workl, workl.length, info) } - if (info.`val` != 0) + if (info.`val` != 0) { throw new IllegalStateException("ARPACK returns non-zero info = " + info.`val`) + } val d = new Array[Double](nev.`val`) val select = new Array[Boolean](ncv) @@ -118,4 +121,4 @@ object EigenValueDecomposition { (BDV(sortedEigenPairs.map(_._1)), sortedU) } -} \ No newline at end of file +}