Repository: spark Updated Branches: refs/heads/branch-1.5 1bba62e93 -> 7e5a90651
[SPARK-14187][MLLIB] Fix incorrect use of binarySearch in SparseMatrix ## What changes were proposed in this pull request? Fix incorrect use of binarySearch in SparseMatrix ## How was this patch tested? Unit test added. Author: Chenliang Xu <[email protected]> Closes #11992 from luckyrandom/SPARK-14187. (cherry picked from commit c8388297c436691a236520d2396deaf556aedb0e) Signed-off-by: Xiangrui Meng <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/7e5a9065 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/7e5a9065 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/7e5a9065 Branch: refs/heads/branch-1.5 Commit: 7e5a9065190898caddf3d9ea0e09a0218d9da6d9 Parents: 1bba62e Author: Chenliang Xu <[email protected]> Authored: Mon Mar 28 08:33:37 2016 -0700 Committer: Xiangrui Meng <[email protected]> Committed: Mon Mar 28 08:35:03 2016 -0700 ---------------------------------------------------------------------- .../src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala | 2 +- .../test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/spark/blob/7e5a9065/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala ---------------------------------------------------------------------- diff --git a/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala b/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala index c02ba42..013c511 100644 --- a/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala +++ b/mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala @@ -579,7 +579,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 { http://git-wip-us.apache.org/repos/asf/spark/blob/7e5a9065/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala ---------------------------------------------------------------------- diff --git a/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala b/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala index bfd6d54..5e28167 100644 --- a/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala +++ b/mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala @@ -139,6 +139,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) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
