Skip to content

Commit

Permalink
use "while" loop instead of "for"
Browse files Browse the repository at this point in the history
set stack size > 128 and comments added
  • Loading branch information
hqzizania committed Jun 28, 2016
1 parent 7e3d238 commit 3607bdc
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,19 @@ object ALS extends DefaultParamsReadable[ALS] with Logging {
}

private def copyToTri(): Unit = {
var i = 0
var j = 0
var ii = 0
for(i <- 0 until k)
for(j <- 0 to i) {
ata(ii) += ata2(i * k + j)
while (i < k) {
val temp = i * k
j = 0
while (j <= i) {
ata(ii) += ata2(temp + j)
j += 1
ii += 1
}
i += 1
}
}

/** Adds an observation. */
Expand Down Expand Up @@ -1316,7 +1323,9 @@ object ALS extends DefaultParamsReadable[ALS] with Logging {
}
var i = srcPtrs(j)
var numExplicits = 0
val doStack = if (srcPtrs(j + 1) - srcPtrs(j) > 10) true else false
// Stacking factors(vectors) in matrices to speed up the computation,
// when the number of factors and the rank is large enough.
val doStack = srcPtrs(j + 1) - srcPtrs(j) > 128 && rank > 128
val srcFactorBuffer = mutable.ArrayBuilder.make[Double]
val bBuffer = mutable.ArrayBuilder.make[Double]
while (i < srcPtrs(j + 1)) {
Expand Down

0 comments on commit 3607bdc

Please sign in to comment.