Skip to content

Commit

Permalink
merge while loop together
Browse files Browse the repository at this point in the history
  • Loading branch information
yinxusen committed Apr 10, 2014
1 parent 69e1f37 commit 1fba230
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ private class VectorRDDStatisticsAggregator(
var totalCnt: Double,
val nnz: BDV[Double],
val currMax: BDV[Double],
val currMin: BDV[Double]) extends VectorRDDStatisticalSummary with Serializable {
val currMin: BDV[Double])
extends VectorRDDStatisticalSummary with Serializable {

// lazy val is used for computing only once time. Same below.
override def mean = {
Expand Down Expand Up @@ -130,31 +131,22 @@ private class VectorRDDStatisticsAggregator(

var i = 0
while (i < other.currMean.length) {
if (other.currMean(i) != 0.0)
// merge mean together
if (other.currMean(i) != 0.0) {
currMean(i) = (currMean(i) * nnz(i) + other.currMean(i) * other.nnz(i)) /
(nnz(i) + other.nnz(i))
i += 1
}
}

i = 0
while (i < currM2n.size) {
(nnz(i), other.nnz(i)) match {
case (0.0, 0.0) =>
case _ => currM2n(i) +=
other.currM2n(i) + deltaMean(i) * deltaMean(i) * nnz(i) * other.nnz(i) / (nnz(i)+other.nnz(i))
// merge m2n together
if (nnz(i) + other.nnz(i) != 0.0) {
currM2n(i) += other.currM2n(i) + deltaMean(i) * deltaMean(i) * nnz(i) * other.nnz(i) /
(nnz(i)+other.nnz(i))
}
i += 1
}

i = 0
while (i < other.currMax.length) {
if (currMax(i) < other.currMax(i)) currMax(i) = other.currMax(i)
i += 1
}

i = 0
while (i < other.currMin.length) {
if (currMin(i) > other.currMin(i)) currMin(i) = other.currMin(i)

i += 1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class VectorRDDFunctionsSuite extends FunSuite with LocalSparkContext {
}

object VectorRDDFunctionsSuite {

def equivVector(lhs: Vector, rhs: Vector): Boolean = {
(lhs.toBreeze - rhs.toBreeze).norm(2) < 1e-9
}
Expand Down

0 comments on commit 1fba230

Please sign in to comment.