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

    https://github.com/apache/spark/pull/10839#discussion_r56881327
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/BlockMatrix.scala
 ---
    @@ -263,13 +263,33 @@ class BlockMatrix @Since("1.3.0") (
         new CoordinateMatrix(entryRDD, numRows(), numCols())
       }
     
    +
       /** Converts to IndexedRowMatrix. The number of columns must be within 
the integer range. */
       @Since("1.3.0")
       def toIndexedRowMatrix(): IndexedRowMatrix = {
         require(numCols() < Int.MaxValue, "The number of columns must be 
within the integer range. " +
           s"numCols: ${numCols()}")
    -    // TODO: This implementation may be optimized
    -    toCoordinateMatrix().toIndexedRowMatrix()
    +
    +    val rows = blocks.flatMap { case ((blockRowIdx, blockColIdx), mat) =>
    +      mat.rowIter.zipWithIndex.map {
    +        case (vector, rowIdx) =>
    +          blockRowIdx * rowsPerBlock + rowIdx -> (blockColIdx, 
vector.toBreeze)
    +      }
    +    }.groupByKey().map { case (rowIdx, vectors) =>
    +
    +      val wholeVector = vectors.head match {
    +        case (idx, v: BDV[_]) => BDV.zeros[Double](numCols().toInt)
    --- End diff --
    
    `numCols()` are now called several times in this method. We should save the 
value to a local variable at the beginning of the method.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to