aboutsummaryrefslogtreecommitdiff
path: root/mllib/src/test
diff options
context:
space:
mode:
authorDoris Xin <doris.s.xin@gmail.com>2014-08-12 23:47:42 -0700
committerXiangrui Meng <meng@databricks.com>2014-08-12 23:47:42 -0700
commitfe4735958e62b1b32a01960503876000f3d2e520 (patch)
tree4d17db757f96e2d70017cb2990b2b020d5cdc4b1 /mllib/src/test
parent2bd812639c3d8c62a725fb7577365ef0816f2898 (diff)
downloadspark-fe4735958e62b1b32a01960503876000f3d2e520.tar.gz
spark-fe4735958e62b1b32a01960503876000f3d2e520.tar.bz2
spark-fe4735958e62b1b32a01960503876000f3d2e520.zip
[SPARK-2993] [MLLib] colStats (wrapper around MultivariateStatisticalSummary) in Statistics
For both Scala and Python. The ser/de util functions were moved out of `PythonMLLibAPI` and into their own object to avoid creating the `PythonMLLibAPI` object inside of `MultivariateStatisticalSummarySerialized`, which is then referenced inside of a method in `PythonMLLibAPI`. `MultivariateStatisticalSummarySerialized` was created to serialize the `Vector` fields in `MultivariateStatisticalSummary`. Author: Doris Xin <doris.s.xin@gmail.com> Closes #1911 from dorx/colStats and squashes the following commits: 77b9924 [Doris Xin] developerAPI tag de9cbbe [Doris Xin] reviewer comments and moved more ser/de 459faba [Doris Xin] colStats in Statistics for both Scala and Python
Diffstat (limited to 'mllib/src/test')
-rw-r--r--mllib/src/test/scala/org/apache/spark/mllib/api/python/PythonMLLibAPISuite.scala17
1 files changed, 8 insertions, 9 deletions
diff --git a/mllib/src/test/scala/org/apache/spark/mllib/api/python/PythonMLLibAPISuite.scala b/mllib/src/test/scala/org/apache/spark/mllib/api/python/PythonMLLibAPISuite.scala
index bd413a80f5..092d67bbc5 100644
--- a/mllib/src/test/scala/org/apache/spark/mllib/api/python/PythonMLLibAPISuite.scala
+++ b/mllib/src/test/scala/org/apache/spark/mllib/api/python/PythonMLLibAPISuite.scala
@@ -23,7 +23,6 @@ import org.apache.spark.mllib.linalg.{Matrices, Vectors}
import org.apache.spark.mllib.regression.LabeledPoint
class PythonMLLibAPISuite extends FunSuite {
- val py = new PythonMLLibAPI
test("vector serialization") {
val vectors = Seq(
@@ -34,8 +33,8 @@ class PythonMLLibAPISuite extends FunSuite {
Vectors.sparse(1, Array.empty[Int], Array.empty[Double]),
Vectors.sparse(2, Array(1), Array(-2.0)))
vectors.foreach { v =>
- val bytes = py.serializeDoubleVector(v)
- val u = py.deserializeDoubleVector(bytes)
+ val bytes = SerDe.serializeDoubleVector(v)
+ val u = SerDe.deserializeDoubleVector(bytes)
assert(u.getClass === v.getClass)
assert(u === v)
}
@@ -50,8 +49,8 @@ class PythonMLLibAPISuite extends FunSuite {
LabeledPoint(1.0, Vectors.sparse(1, Array.empty[Int], Array.empty[Double])),
LabeledPoint(-0.5, Vectors.sparse(2, Array(1), Array(-2.0))))
points.foreach { p =>
- val bytes = py.serializeLabeledPoint(p)
- val q = py.deserializeLabeledPoint(bytes)
+ val bytes = SerDe.serializeLabeledPoint(p)
+ val q = SerDe.deserializeLabeledPoint(bytes)
assert(q.label === p.label)
assert(q.features.getClass === p.features.getClass)
assert(q.features === p.features)
@@ -60,8 +59,8 @@ class PythonMLLibAPISuite extends FunSuite {
test("double serialization") {
for (x <- List(123.0, -10.0, 0.0, Double.MaxValue, Double.MinValue, Double.NaN)) {
- val bytes = py.serializeDouble(x)
- val deser = py.deserializeDouble(bytes)
+ val bytes = SerDe.serializeDouble(x)
+ val deser = SerDe.deserializeDouble(bytes)
// We use `equals` here for comparison because we cannot use `==` for NaN
assert(x.equals(deser))
}
@@ -70,14 +69,14 @@ class PythonMLLibAPISuite extends FunSuite {
test("matrix to 2D array") {
val values = Array[Double](0, 1.2, 3, 4.56, 7, 8)
val matrix = Matrices.dense(2, 3, values)
- val arr = py.to2dArray(matrix)
+ val arr = SerDe.to2dArray(matrix)
val expected = Array(Array[Double](0, 3, 7), Array[Double](1.2, 4.56, 8))
assert(arr === expected)
// Test conversion for empty matrix
val empty = Array[Double]()
val emptyMatrix = Matrices.dense(0, 0, empty)
- val empty2D = py.to2dArray(emptyMatrix)
+ val empty2D = SerDe.to2dArray(emptyMatrix)
assert(empty2D === Array[Array[Double]]())
}
}