Github user MLnick commented on a diff in the pull request:
https://github.com/apache/spark/pull/12574#discussion_r60825409
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala
---
@@ -261,58 +261,93 @@ object MatrixFactorizationModel extends
Loader[MatrixFactorizationModel] {
}
/**
- * Makes recommendations for all users (or products).
- * @param rank rank
- * @param srcFeatures src features to receive recommendations
- * @param dstFeatures dst features used to make recommendations
- * @param num number of recommendations for each record
- * @return an RDD of (srcId: Int, recommendations), where
recommendations are stored as an array
- * of (dstId, rating) pairs.
+ * Makes recommendations for all users (or items).
+ *
+ * @param rank rank the dimension of the factor vectors
+ * @param srcFactors src factor to receive recommendations
+ * @param dstFactors dst factor used to make recommendations
+ * @param num number of recommendations for each user (or item)
+ * @return an RDD of (srcId, recommendations) pairs, where
recommendations are stored as an array
+ * of (dstId, score) pairs.
*/
- private def recommendForAll(
+ private[spark] def recommendForAll[T: ClassTag : Fractional](
rank: Int,
- srcFeatures: RDD[(Int, Array[Double])],
- dstFeatures: RDD[(Int, Array[Double])],
- num: Int): RDD[(Int, Array[(Int, Double)])] = {
- val srcBlocks = blockify(rank, srcFeatures)
- val dstBlocks = blockify(rank, dstFeatures)
+ srcFactors: RDD[(Int, Array[T])],
+ dstFactors: RDD[(Int, Array[T])],
+ num: Int): RDD[(Int, Array[(Int, T)])] = {
+ val srcBlocks = blockify(rank, srcFactors)
+ val dstBlocks = blockify(rank, dstFactors)
+ val tag = implicitly[ClassTag[T]].runtimeClass
val ratings = srcBlocks.cartesian(dstBlocks).flatMap {
case ((srcIds, srcFactors), (dstIds, dstFactors)) =>
--- End diff --
This is essentially using the approach already used in `mllib` package. I
agree ideally a BlockMatrix could be used and would improve performance. I'll
probably keep it like this for a first cut, but will add a follow up note &
JIRA to look at BlockMatrix and investigate the performance difference.
---
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]