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

    https://github.com/apache/spark/pull/10839#discussion_r56881462
  
    --- 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)
    +        case (idx, v: BSV[_]) => BSV.zeros[Double](numCols().toInt)
    +        case _ => throw new SparkException(s"Cannot convert an empty 
vector to an indexed row")
    +      }
    +
    +      vectors.foreach { case (blockColIdx: Int, vec: BV[Double]) =>
    +        val offset = colsPerBlock * blockColIdx
    +        wholeVector(offset until offset + vec.size) := vec
    --- End diff --
    
    (minor) `vec.size` should be the same as `colsPerBlock`.


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