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

    https://github.com/apache/spark/pull/4274#discussion_r23875903
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/BlockMatrix.scala
 ---
    @@ -246,4 +248,86 @@ class BlockMatrix(
         val localMat = toLocalMatrix()
         new BDM[Double](localMat.numRows, localMat.numCols, localMat.toArray)
       }
    +
    +  /** Adds two block matrices together. The matrices must have the same 
size and matching
    +    * `rowsPerBlock` and `colsPerBlock` values. If one of the blocks that 
are being added are
    +    * instances of [[SparseMatrix]], the resulting sub matrix will also be 
a [[SparseMatrix]], even
    +    * if it is being added to a [[DenseMatrix]]. If two dense matrices are 
added, the output will
    +    * also be a [[DenseMatrix]].
    +    */
    +  def add(other: BlockMatrix): BlockMatrix = {
    +    require(numRows() == other.numRows(), "Both matrices must have the 
same number of rows. " +
    +      s"A.numRows: ${numRows()}, B.numRows: ${other.numRows()}")
    +    require(numCols() == other.numCols(), "Both matrices must have the 
same number of columns. " +
    +      s"A.numCols: ${numCols()}, B.numCols: ${other.numCols()}")
    +    if (rowsPerBlock == other.rowsPerBlock && colsPerBlock == 
other.colsPerBlock) {
    +      val addedBlocks = blocks.cogroup(other.blocks, createPartitioner())
    +        .map { case ((blockRowIndex, blockColIndex), (a, b)) =>
    +          if (a.size > 1 || b.size > 1) {
    +            throw new SparkException("There are MatrixBlocks with 
duplicate indices. Please " +
    --- End diff --
    
    Put `blockRowIndex` and `blockColIndex` in the message.


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