aboutsummaryrefslogtreecommitdiff
path: root/mllib-local/src/test
diff options
context:
space:
mode:
authorJeff Zhang <zjffdu@apache.org>2016-08-19 12:38:15 +0100
committerSean Owen <sowen@cloudera.com>2016-08-19 12:38:15 +0100
commit072acf5e1460d66d4b60b536d5b2ccddeee80794 (patch)
tree82627c726b931b61da6850b5e4b557d4b62e8bc1 /mllib-local/src/test
parent864be9359ae2f8409e6dbc38a7a18593f9cc5692 (diff)
downloadspark-072acf5e1460d66d4b60b536d5b2ccddeee80794.tar.gz
spark-072acf5e1460d66d4b60b536d5b2ccddeee80794.tar.bz2
spark-072acf5e1460d66d4b60b536d5b2ccddeee80794.zip
[SPARK-16965][MLLIB][PYSPARK] Fix bound checking for SparseVector.
## What changes were proposed in this pull request? 1. In scala, add negative low bound checking and put all the low/upper bound checking in one place 2. In python, add low/upper bound checking of indices. ## How was this patch tested? unit test added Author: Jeff Zhang <zjffdu@apache.org> Closes #14555 from zjffdu/SPARK-16965.
Diffstat (limited to 'mllib-local/src/test')
-rw-r--r--mllib-local/src/test/scala/org/apache/spark/ml/linalg/VectorsSuite.scala6
1 files changed, 6 insertions, 0 deletions
diff --git a/mllib-local/src/test/scala/org/apache/spark/ml/linalg/VectorsSuite.scala b/mllib-local/src/test/scala/org/apache/spark/ml/linalg/VectorsSuite.scala
index 614be460a4..ea22c2787f 100644
--- a/mllib-local/src/test/scala/org/apache/spark/ml/linalg/VectorsSuite.scala
+++ b/mllib-local/src/test/scala/org/apache/spark/ml/linalg/VectorsSuite.scala
@@ -72,6 +72,12 @@ class VectorsSuite extends SparkMLFunSuite {
}
}
+ test("sparse vector construction with negative indices") {
+ intercept[IllegalArgumentException] {
+ Vectors.sparse(3, Array(-1, 1), Array(3.0, 5.0))
+ }
+ }
+
test("dense to array") {
val vec = Vectors.dense(arr).asInstanceOf[DenseVector]
assert(vec.toArray.eq(arr))