Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/9980#discussion_r46220915
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/recommendation/MatrixFactorizationModel.scala
---
@@ -275,16 +276,13 @@ object MatrixFactorizationModel extends
Loader[MatrixFactorizationModel] {
num: Int): RDD[(Int, Array[(Int, Double)])] = {
val srcBlocks = blockify(rank, srcFeatures)
val dstBlocks = blockify(rank, dstFeatures)
+ val output = new ArrayBuffer[(Int, (Int, Double))]()
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
+ output.clear()
ratings.foreachActive { (i, j, r) =>
--- End diff --
We don't need `output` to hold the buffer. The following should work,
though it doesn't really fix the GC problem:
~~~scala
for (i <- 0 until m; j <- 0 until n) yield {
(srcIds(i), dstIds(j), ratings(i, j))
}
~~~
---
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]