Github user MLnick commented on a diff in the pull request:
https://github.com/apache/spark/pull/17845#discussion_r115425530
--- Diff: mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala
---
@@ -372,11 +385,43 @@ 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
--- End diff --
Anyway the `iter.next()` code is a bit ugly and since it's at most `k`
elements it's not really performance critical, so could just use `foreach` I
think
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]