Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17459#discussion_r111074033
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/linalg/distributed/IndexedRowMatrixSuite.scala
 ---
    @@ -87,21 +87,74 @@ 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(_ && _))
    +  }
    +
    +  test("toBlockMatrix sparse backing") {
    +    val sparseData = Seq(
    +      (3L, Vectors.sparse(3, Seq((0, 4.0))))
    +    ).map(x => IndexedRow(x._1, x._2))
    +
    +    val idxRowMatSparse = new IndexedRowMatrix(sc.parallelize(sparseData))
    +
    +    // Tests when n % colsPerBlock != 0
    +    val blockMat = idxRowMatSparse.toBlockMatrix(2, 2)
    +    assert(blockMat.numRows() === m)
    +    assert(blockMat.numCols() === n)
    +    assert(blockMat.toBreeze() === idxRowMatSparse.toBreeze())
    +
    +    // Tests when m % rowsPerBlock != 0
    +    val blockMat2 = idxRowMatSparse.toBlockMatrix(3, 1)
    +    assert(blockMat2.numRows() === m)
    +    assert(blockMat2.numCols() === n)
    +    assert(blockMat2.toBreeze() === idxRowMatSparse.toBreeze())
    +
    +    assert(blockMat.blocks.map { case (_, matrix: Matrix) =>
    +      matrix.isInstanceOf[SparseMatrix]}.reduce(_ && _))
    +  }
    +
    +  test("toBlockMatrix mixed backing") {
    +    val mixedData = Seq(
    +      (0L, Vectors.dense(1, 2, 3)),
    +      (3L, Vectors.sparse(3, Seq((0, 4.0)))))
    +
    +    val idxRowMatMixed = new IndexedRowMatrix(
    +      sc.parallelize(mixedData.map(x => IndexedRow(x._1, x._2))))
    --- End diff --
    
    To be consistent with above, can we move the call `.map(x => 
IndexedRow(x._1, x._2))` to `mixedData`?


---
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]

Reply via email to