aboutsummaryrefslogtreecommitdiff
path: root/mllib/src/test/scala/org
diff options
context:
space:
mode:
authorMechCoder <manojkumarsivaraj334@gmail.com>2015-10-20 16:35:34 -0700
committerXiangrui Meng <meng@databricks.com>2015-10-20 16:35:34 -0700
commitda46b77afd13df8eb696e4612224ae29cc198c0b (patch)
tree5a3ce59c130846c9a7c5ce84a9c323a879e3e4fa /mllib/src/test/scala/org
parent04521ea067d6ed3c5398067f07904d27c77017ff (diff)
downloadspark-da46b77afd13df8eb696e4612224ae29cc198c0b.tar.gz
spark-da46b77afd13df8eb696e4612224ae29cc198c0b.tar.bz2
spark-da46b77afd13df8eb696e4612224ae29cc198c0b.zip
[SPARK-10082][MLLIB] Validate i, j in apply DenseMatrices and SparseMatrices
Given row_ind should be less than the number of rows Given col_ind should be less than the number of cols. The current code in master gives unpredictable behavior for such cases. Author: MechCoder <manojkumarsivaraj334@gmail.com> Closes #8271 from MechCoder/hash_code_matrices.
Diffstat (limited to 'mllib/src/test/scala/org')
-rw-r--r--mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala11
1 files changed, 11 insertions, 0 deletions
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 bfd6d5495f..b0071c9a02 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
@@ -74,6 +74,17 @@ class MatricesSuite extends SparkFunSuite {
}
}
+ test("index in matrices incorrect input") {
+ val sm = Matrices.sparse(3, 2, Array(0, 2, 3), Array(1, 2, 1), Array(0.0, 1.0, 2.0))
+ val dm = Matrices.dense(3, 2, Array(0.0, 2.3, 1.4, 3.2, 1.0, 9.1))
+ Array(sm, dm).foreach { mat =>
+ intercept[IllegalArgumentException] { mat.index(4, 1) }
+ intercept[IllegalArgumentException] { mat.index(1, 4) }
+ intercept[IllegalArgumentException] { mat.index(-1, 2) }
+ intercept[IllegalArgumentException] { mat.index(1, -2) }
+ }
+ }
+
test("equals") {
val dm1 = Matrices.dense(2, 2, Array(0.0, 1.0, 2.0, 3.0))
assert(dm1 === dm1)