Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/4459#discussion_r24436979
--- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/BLAS.scala ---
@@ -255,6 +266,15 @@ private[spark] object BLAS extends Serializable with
Logging {
}
}
+ // Workaround for SparseVectors.
+ private def syr(alpha: Double, x: SparseVector, A: DenseMatrix, nA: Int)
{
+ val zipIndVal = (x.indices zip x.values)
--- End diff --
This is slow because it creates a temp array. Use while loop instead (I
didn't check the correctness of the code):
~~~
val xIndices = x.indices
val xValues = x.values
val nnz = xValues.length
val aValues = a.values
var i = 0
while (i < nnz) {
val idx = xIndices(i)
val offset = idx * A.numRows
val xi = xValues(i)
val multiplier = alpha * xi
aValues(offset + idx) += multiplier * xi
var j = i + 1
while (j < nnz) {
aValues(offset + xIndices(j)) += multiplier * xValues(j)
j += 1
}
i += 1
}
// fill in the lower triangular part of A
~~~
Please also add a unit test for `syr` with a sparse vector.
---
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]