Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
10 changes: 8 additions & 2 deletions mllib-local/src/main/scala/org/apache/spark/ml/linalg/BLAS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,18 @@ private[spark] object BLAS extends Serializable {
val indEnd = Arows(rowCounter + 1)
var sum = 0.0
var k = 0
while (k < xNnz && i < indEnd) {
while (i < indEnd && k < xNnz) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: an unnecessary change?

if (xIndices(k) == Acols(i)) {
sum += Avals(i) * xValues(k)
k += 1
i += 1
}
else if (xIndices(k) < Acols(i)) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: pull the elses up onto the previous line. Does this affect the non-transposed case below too? I believe your change is indeed correct and the tests demonstrate that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

elses on previous line, done. I must admit I haven't gone through the non-transpose case in as much detail, but that does not seem affected by this bug. Should I perhaps add a test that shows the non-transpose case is/remains unaffected?

Copy link
Member

Choose a reason for hiding this comment

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

I think that would be ideal if it's not already covered, just to be sure. It ought to be a straightforward modification of a bit of test code you just added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

check

k += 1
}
else {
i += 1
}
k += 1
}
yValues(rowCounter) = sum * alpha + beta * yValues(rowCounter)
rowCounter += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,17 @@ class BLASSuite extends SparkMLFunSuite {
}
}

val y17 = new DenseVector(Array(0.0, 0.0))
val sA3 = new SparseMatrix(3, 2, Array(0, 2, 4), Array(1, 2, 0, 1), Array(2.0, 1.0, 1.0, 2.0))
.transpose
val sx3 = new SparseVector(3, Array(1, 2), Array(2.0, 1.0))

val expected4 = new DenseVector(Array(5.0, 4.0))

gemv(1.0, sA3, sx3, 0.0, y17)

assert(y17 ~== expected4 absTol 1e-15)

val dAT =
new DenseMatrix(3, 4, Array(0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 3.0))
val sAT =
Expand Down
10 changes: 8 additions & 2 deletions mllib/src/main/scala/org/apache/spark/mllib/linalg/BLAS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,18 @@ private[spark] object BLAS extends Serializable with Logging {
val indEnd = Arows(rowCounter + 1)
var sum = 0.0
var k = 0
while (k < xNnz && i < indEnd) {
while (i < indEnd && k < xNnz) {
if (xIndices(k) == Acols(i)) {
sum += Avals(i) * xValues(k)
k += 1
i += 1
}
else if (xIndices(k) < Acols(i)) {
k += 1
}
else {
i += 1
}
k += 1
}
yValues(rowCounter) = sum * alpha + beta * yValues(rowCounter)
rowCounter += 1
Expand Down
11 changes: 11 additions & 0 deletions mllib/src/test/scala/org/apache/spark/mllib/linalg/BLASSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,17 @@ class BLASSuite extends SparkFunSuite {
}
}

val y17 = new DenseVector(Array(0.0, 0.0))
val sA3 = new SparseMatrix(3, 2, Array(0, 2, 4), Array(1, 2, 0, 1), Array(2.0, 1.0, 1.0, 2.0))
.transpose
val sx3 = new SparseVector(3, Array(1, 2), Array(2.0, 1.0))

val expected4 = new DenseVector(Array(5.0, 4.0))

gemv(1.0, sA3, sx3, 0.0, y17)

assert(y17 ~== expected4 absTol 1e-15)

val dAT =
new DenseMatrix(3, 4, Array(0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 3.0))
val sAT =
Expand Down