Skip to content

Commit 2fd97a0

Browse files
author
Peng Meng
committed
change code format
1 parent ae03124 commit 2fd97a0

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,39 +277,38 @@ object MatrixFactorizationModel extends Loader[MatrixFactorizationModel] {
277277
num: Int): RDD[(Int, Array[(Int, Double)])] = {
278278
val srcBlocks = blockify(rank, srcFeatures)
279279
val dstBlocks = blockify(rank, dstFeatures)
280-
val ratings = srcBlocks.cartesian(dstBlocks).flatMap {
281-
case (users, items) =>
282-
val m = users.size
283-
val n = math.min(items.size, num)
280+
val ratings = srcBlocks.cartesian(dstBlocks).flatMap { case (srcIter, dstIter) =>
281+
val m = srcIter.size
282+
val n = math.min(dstIter.size, num)
284283
val output = new Array[(Int, (Int, Double))](m * n)
285284
var j = 0
286-
users.foreach (user => {
285+
srcIter.foreach { case (srcId, srcFactor) =>
287286
def order(a: (Int, Double)) = a._2
288287
val pq: BoundedPriorityQueue[(Int, Double)] =
289288
new BoundedPriorityQueue[(Int, Double)](n)(Ordering.by(order))
290-
items.foreach (item => {
289+
dstIter.foreach { case (dstId, dstFactor) =>
291290
/**
292291
* blas.ddot (F2jBLAS) is the same performance with the following code.
293292
* the performace of blas.ddot with NativeBLAS is very bad.
294293
* blas.ddot (F2jBLAS) is about 10% improvement comparing with linalg.dot.
295294
* val rate = blas.ddot(rank, user._2, 1, item._2, 1)
296295
*/
297-
var rate: Double = 0
296+
var score: Double = 0
298297
var k = 0
299-
while(k < rank) {
300-
rate += user._2(k) * item._2(k)
298+
while (k < rank) {
299+
score += srcFactor(k) * dstFactor(k)
301300
k += 1
302301
}
303-
pq += ((item._1, rate))
304-
})
302+
pq += ((dstId, score))
303+
}
305304
val pqIter = pq.iterator
306305
var i = 0
307-
while(i < n) {
308-
output(j + i) = (user._1, pqIter.next())
306+
while (i < n) {
307+
output(j + i) = (srcId, pqIter.next())
309308
i += 1
310309
}
311310
j += n
312-
})
311+
}
313312
output.toSeq
314313
}
315314
ratings.topByKey(num)(Ordering.by(_._2))

0 commit comments

Comments
 (0)