spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MLnick <...@git.apache.org>
Subject [GitHub] spark pull request #17845: [SPARK-20587][ML] Improve performance of ML ALS r...
Date Thu, 04 May 2017 06:35:20 GMT
Github user MLnick commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17845#discussion_r114706857
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala ---
    @@ -372,11 +385,45 @@ class ALSModel private[ml] (
           num: Int): DataFrame = {
         import srcFactors.sparkSession.implicits._
     
    -    val ratings = srcFactors.crossJoin(dstFactors)
    -      .select(
    -        srcFactors("id"),
    -        dstFactors("id"),
    -        predict(srcFactors("features"), dstFactors("features")))
    +    val srcFactorsBlocked = blockify(srcFactors.as[(Int, Array[Float])])
    +    val dstFactorsBlocked = blockify(dstFactors.as[(Int, Array[Float])])
    +    val ratings = srcFactorsBlocked.crossJoin(dstFactorsBlocked)
    +      .as[(Seq[(Int, Array[Float])], Seq[(Int, Array[Float])])]
    +      .flatMap { case (srcIter, dstIter) =>
    +        val m = srcIter.size
    +        val n = math.min(dstIter.size, num)
    +        val output = new Array[(Int, Int, Float)](m * n)
    +        var j = 0
    +        val pq = new BoundedPriorityQueue[(Int, Float)](num)(Ordering.by(_._2))
    +        srcIter.foreach { case (srcId, srcFactor) =>
    +          dstIter.foreach { case (dstId, dstFactor) =>
    +            /**
    +             * The below code is equivalent to
    +             * val score = blas.sdot(rank, srcFactor, 1, dstFactor, 1)
    +             * Compared with BLAS.dot, the hand-written version used below is more efficient
than
    +             * a call to the native BLAS backend and the same performance as the fallback
    +             * F2jBLAS backend.
    +             */
    +            var score = 0.0f
    +            var k = 0
    +            while (k < rank) {
    +              score += srcFactor(k) * dstFactor(k)
    +              k += 1
    +            }
    +            pq += { (dstId, score) }
    --- End diff --
    
    sure


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message