Skip to content
Closed
Changes from 1 commit
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
Next Next commit
Helper function for wrapping Array[Double]'s with DoubleMatrix's.
  • Loading branch information
tmyklebu committed Apr 18, 2014
commit a09904f4e50ad5f15308c5bf515e4dd49f5ba718
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,13 @@ class ALS private (
}
}

/**
* Wrap a double array in a DoubleMatrix without creating garbage.
*/
private def wrapDoubleArray(v: Array[Double]): DoubleMatrix = {
new DoubleMatrix(v.length, 1, v:_*)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put a space after :

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(PS might also note in the comment that it's safe to go back to the old DoubleMatrix constructor at jblas 1.2.4 or later.)

}

/**
* Flatten out blocked user or product factors into an RDD of (id, factor vector) pairs
*/
Expand Down Expand Up @@ -455,7 +462,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