Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-1535] ALS: Avoid the garbage-creating ctor of DoubleMatrix #442

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class ALS private (
private def computeYtY(factors: RDD[(Int, Array[Array[Double]])]) = {
val n = rank * (rank + 1) / 2
val LYtY = factors.values.aggregate(new DoubleMatrix(n))( seqOp = (L, Y) => {
Y.foreach(y => dspr(1.0, new DoubleMatrix(y), L))
Y.foreach(y => dspr(1.0, wrapDoubleArray(y), L))
L
}, combOp = (L1, L2) => {
L1.addi(L2)
Expand Down Expand Up @@ -302,6 +302,15 @@ class ALS private (
}
}

/**
* Wrap a double array in a DoubleMatrix without creating garbage.
* This is a temporary fix for jblas 1.2.3; it should be safe to move back to the
* DoubleMatrix(double[]) constructor come jblas 1.2.4.
*/
private def wrapDoubleArray(v: Array[Double]): DoubleMatrix = {
new DoubleMatrix(v.length, 1, v: _*)
}

/**
* Flatten out blocked user or product factors into an RDD of (id, factor vector) pairs
*/
Expand Down Expand Up @@ -455,7 +464,7 @@ class ALS private (
// block
for (productBlock <- 0 until numBlocks) {
for (p <- 0 until blockFactors(productBlock).length) {
val x = new DoubleMatrix(blockFactors(productBlock)(p))
val x = wrapDoubleArray(blockFactors(productBlock)(p))
tempXtX.fill(0.0)
dspr(1.0, x, tempXtX)
val (us, rs) = inLinkBlock.ratingsForBlock(productBlock)(p)
Expand Down