Github user johnc1231 commented on a diff in the pull request:
https://github.com/apache/spark/pull/17459#discussion_r111492414
--- Diff:
mllib/src/test/scala/org/apache/spark/mllib/linalg/distributed/IndexedRowMatrixSuite.scala
---
@@ -87,19 +87,92 @@ class IndexedRowMatrixSuite extends SparkFunSuite with
MLlibTestSparkContext {
assert(coordMat.toBreeze() === idxRowMat.toBreeze())
}
- test("toBlockMatrix") {
- val idxRowMat = new IndexedRowMatrix(indexedRows)
- val blockMat = idxRowMat.toBlockMatrix(2, 2)
+ test("toBlockMatrix dense backing") {
+ val idxRowMatDense = new IndexedRowMatrix(indexedRows)
+
+ // Tests when n % colsPerBlock != 0
+ val blockMat = idxRowMatDense.toBlockMatrix(2, 2)
assert(blockMat.numRows() === m)
assert(blockMat.numCols() === n)
- assert(blockMat.toBreeze() === idxRowMat.toBreeze())
+ assert(blockMat.toBreeze() === idxRowMatDense.toBreeze())
+
+ // Tests when m % rowsPerBlock != 0
+ val blockMat2 = idxRowMatDense.toBlockMatrix(3, 1)
+ assert(blockMat2.numRows() === m)
+ assert(blockMat2.numCols() === n)
+ assert(blockMat2.toBreeze() === idxRowMatDense.toBreeze())
intercept[IllegalArgumentException] {
- idxRowMat.toBlockMatrix(-1, 2)
+ idxRowMatDense.toBlockMatrix(-1, 2)
}
intercept[IllegalArgumentException] {
- idxRowMat.toBlockMatrix(2, 0)
+ idxRowMatDense.toBlockMatrix(2, 0)
}
+
+ assert(blockMat.blocks.map { case (_, matrix: Matrix) =>
+ matrix.isInstanceOf[DenseMatrix]}.reduce(_ && _))
+ assert(blockMat2.blocks.map { case (_, matrix: Matrix) =>
+ matrix.isInstanceOf[DenseMatrix]}.reduce(_ && _))
+ }
+
+ test("toBlockMatrix sparse backing") {
+ val sparseData = Seq(
+ (2L, Vectors.sparse(3, Seq((0, 4.0))))
--- End diff --
If you look at the constructor for the IndexedRowMatrix, I passed it a
width and height so that this would not be an issue. I guess that's not a good
idea though, since that invalidates the tests of dimensionality. I'll just make
the matrix bigger than 4 x 3 so that it'll be easy to make something sparse.
---
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]