Github user MLnick commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17742#discussion_r113761236
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala
 ---
    @@ -277,17 +278,39 @@ object MatrixFactorizationModel extends 
Loader[MatrixFactorizationModel] {
         val srcBlocks = blockify(rank, srcFeatures)
         val dstBlocks = blockify(rank, dstFeatures)
         val ratings = srcBlocks.cartesian(dstBlocks).flatMap {
    -      case ((srcIds, srcFactors), (dstIds, dstFactors)) =>
    -        val m = srcIds.length
    -        val n = dstIds.length
    -        val ratings = srcFactors.transpose.multiply(dstFactors)
    -        val output = new Array[(Int, (Int, Double))](m * n)
    -        var k = 0
    -        ratings.foreachActive { (i, j, r) =>
    -          output(k) = (srcIds(i), (dstIds(j), r))
    -          k += 1
    -        }
    -        output.toSeq
    +      case (users, items) =>
    +      val m = users.size
    +      val n = math.min(items.size, num)
    +      val output = new Array[(Int, (Int, Double))](m * n)
    +      var j = 0
    +      users.foreach (user => {
    +          def order(a: (Int, Double)) = a._2
    +          val pq: BoundedPriorityQueue[(Int, Double)] =
    +            new BoundedPriorityQueue[(Int, Double)](n)(Ordering.by(order))
    +          items.foreach (item => {
    +              /**
    +               * blas.ddot (F2jBLAS) is the same performance with the 
following code.
    +               * the performace of blas.ddot with NativeBLAS is very bad.
    +               * blas.ddot (F2jBLAS) is about 10% improvement comparing 
with linalg.dot.
    +               * val rate = blas.ddot(rank, user._2, 1, item._2, 1)
    +               */
    +              var rate: Double = 0
    +              var k = 0
    +              while(k < rank) {
    +                rate += user._2(k) * item._2(k)
    +                k += 1
    +              }
    +              pq += ((item._1, rate))
    +            })
    +          val pqIter = pq.iterator
    +          var i = 0
    +          while(i < n) {
    +            output(j + i) = (user._1, pqIter.next())
    --- End diff --
    
    Ah right - good point. Fine to leave as it is 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to