Github user dbtsai commented on a diff in the pull request:
https://github.com/apache/spark/pull/15628#discussion_r107835213
--- Diff:
mllib-local/src/test/scala/org/apache/spark/ml/linalg/MatricesSuite.scala ---
@@ -160,22 +160,395 @@ class MatricesSuite extends SparkMLFunSuite {
assert(sparseMat.values(2) === 10.0)
}
- test("toSparse, toDense") {
- val m = 3
- val n = 2
- val values = Array(1.0, 2.0, 4.0, 5.0)
- val allValues = Array(1.0, 2.0, 0.0, 0.0, 4.0, 5.0)
- val colPtrs = Array(0, 2, 4)
- val rowIndices = Array(0, 1, 1, 2)
+ test("dense to dense") {
+ /*
+ dm1 = 4.0 2.0 -8.0
+ -1.0 7.0 4.0
+
+ dm2 = 5.0 -9.0 4.0
+ 1.0 -3.0 -8.0
+ */
+ val dm1 = new DenseMatrix(2, 3, Array(4.0, -1.0, 2.0, 7.0, -8.0, 4.0))
+ val dm2 = new DenseMatrix(2, 3, Array(5.0, -9.0, 4.0, 1.0, -3.0,
-8.0), isTransposed = true)
+
+ val dm3 = dm1.toDense
+ assert(dm3 === dm1)
+ assert(!dm3.isTransposed)
+ assert(dm3.values.equals(dm1.values))
+
+ val dm4 = dm1.toDenseRowMajor
+ assert(dm4 === dm1)
+ assert(dm4.isTransposed)
+ assert(dm4.values === Array(4.0, 2.0, -8.0, -1.0, 7.0, 4.0))
+
+ val dm5 = dm2.toDenseColMajor
+ assert(dm5 === dm2)
+ assert(!dm5.isTransposed)
+ assert(dm5.values === Array(5.0, 1.0, -9.0, -3.0, 4.0, -8.0))
+
+ val dm6 = dm2.toDenseRowMajor
+ assert(dm6 === dm2)
+ assert(dm6.isTransposed)
+ assert(dm6.values.equals(dm2.values))
+
+ val dm7 = dm1.toDenseRowMajor
+ assert(dm7 === dm1)
+ assert(dm7.isTransposed)
+ assert(dm7.values === Array(4.0, 2.0, -8.0, -1.0, 7.0, 4.0))
+
+ val dm8 = dm1.toDenseColMajor
+ assert(dm8 === dm1)
+ assert(!dm8.isTransposed)
+ assert(dm8.values.equals(dm1.values))
+
+ val dm9 = dm2.toDense
+ assert(dm9 === dm2)
+ assert(dm9.isTransposed)
+ assert(dm9.values.equals(dm2.values))
+ }
- val spMat1 = new SparseMatrix(m, n, colPtrs, rowIndices, values)
- val deMat1 = new DenseMatrix(m, n, allValues)
+ test("dense to sparse") {
+ /*
+ dm1 = 0.0 4.0 5.0
+ 0.0 2.0 0.0
+
+ dm2 = 0.0 4.0 5.0
+ 0.0 2.0 0.0
- val spMat2 = deMat1.toSparse
- val deMat2 = spMat1.toDense
+ dm3 = 0.0 0.0 0.0
+ 0.0 0.0 0.0
+ */
+ val dm1 = new DenseMatrix(2, 3, Array(0.0, 0.0, 4.0, 2.0, 5.0, 0.0))
+ val dm2 = new DenseMatrix(2, 3, Array(0.0, 4.0, 5.0, 0.0, 2.0, 0.0),
isTransposed = true)
+ val dm3 = new DenseMatrix(2, 3, Array(0.0, 0.0, 0.0, 0.0, 0.0, 0.0))
+
+ val sm1 = dm1.toSparseColMajor
+ assert(sm1 === dm1)
+ assert(!sm1.isTransposed)
+ assert(sm1.values === Array(4.0, 2.0, 5.0))
+
--- End diff --
You tested `dm1.toSparseColMajor` twice.
Will be nice to group them like
```scala
val sm1 = dm1.toSparseColMajor
val sm2 = dm2.toSparseColMajor
val sm3 = dm3.toSparseColMajor
val sm4 = dm1.toSparseRowMajor
val sm5 = dm2.toSparseRowMajor
val sm6 = dm3.toSparseRowMajor
val sm7 = dm1.toSparse
val sm8 = dm2.toSparse
val sm9 = dm3.toSparse
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]