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

    https://github.com/apache/spark/pull/5909#discussion_r35711056
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/RowMatrix.scala 
---
    @@ -498,6 +498,65 @@ class RowMatrix(
       }
     
       /**
    +   * Compute QR decomposition for rowMatrix. The implementation is 
designed to optimize the QR
    +   * decomposition (factorizations) for the RowMatrix of a tall and skinny 
shape, yet it applies
    +   * to RowMatrix in general.
    +   *
    +   * Reference:
    +   *  Austin R. Benson, David F. Gleich, James Demmel. "Direct QR 
factorizations for tall-and
    +   *  -skinny matrices in MapReduce architectures", 2013 IEEE 
International Conference on Big Data
    +   * @param computeQ: whether to computeQ, which is quite expensive.
    +   * @return the decomposition result as (Option[Q], R), where Q is a 
RowMatrix and R is Matrix.
    +   */
    +  def TSQR(computeQ: Boolean = false): (Option[RowMatrix], Matrix) = {
    +    val col = numCols().toInt
    +
    +    // split rows horizontally into smaller matrices, and compute QR for 
each of them
    +    val blockQRs = rows.mapPartitions(rowsIterator =>{
    +      val partRows = rowsIterator.toArray
    +      val rowCount = partRows.size
    +      var bdm = BDM.zeros[Double](partRows.size, col)
    +      var i = 0
    +      partRows.foreach(row =>{
    +        bdm(i, ::) := row.toBreeze.t
    +        i += 1
    +      })
    +
    +      val blockQR = breeze.linalg.qr.reduced(bdm)
    +      Iterator((blockQR.r, blockQR.q))
    +    }).cache
    +
    +    // combine the R part from previous results horizontally into a tall 
matrix
    +    val blockRsRdd = blockQRs.map(_._1).collect()
    +    val CombinedR = blockRsRdd.reduceLeft((r1, r2) => BDM.vertcat(r1, r2))
    +
    +    val CombinedRDecomposition = breeze.linalg.qr.reduced(CombinedR)
    +    val finalR = 
Matrices.fromBreeze(CombinedRDecomposition.r.toDenseMatrix)
    +
    +    val finalQ = if(computeQ){
    --- End diff --
    
    See my comments on the PR page about computing `Q`.


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