Skip to content
Closed
Show file tree
Hide file tree
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 @@ -613,7 +613,7 @@ class SparseMatrix @Since("1.3.0") (

private[mllib] def update(i: Int, j: Int, v: Double): Unit = {
val ind = index(i, j)
if (ind == -1) {
if (ind < 0) {
throw new NoSuchElementException("The given row and column indices correspond to a zero " +
"value. Only non-zero elements in Sparse Matrices can be updated.")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ class MatricesSuite extends SparkFunSuite {
sparseMat.update(0, 0, 10.0)
}

intercept[NoSuchElementException] {
sparseMat.update(2, 1, 10.0)
}

sparseMat.update(0, 1, 10.0)
assert(sparseMat(0, 1) === 10.0)
assert(sparseMat.values(2) === 10.0)
Expand Down