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

    https://github.com/apache/spark/pull/3319#discussion_r22010767
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala 
---
    @@ -197,6 +300,171 @@ class SparseMatrix(
       }
     
       override def copy = new SparseMatrix(numRows, numCols, colPtrs, 
rowIndices, values.clone())
    +
    +  private[mllib] def map(f: Double => Double) =
    +    new SparseMatrix(numRows, numCols, colPtrs, rowIndices, values.map(f))
    +
    +  private[mllib] def update(f: Double => Double): SparseMatrix = {
    +    val len = values.length
    +    var i = 0
    +    while (i < len) {
    +      values(i) = f(values(i))
    +      i += 1
    +    }
    +    this
    +  }
    +}
    +
    +/**
    + * Factory methods for [[org.apache.spark.mllib.linalg.SparseMatrix]].
    + */
    +object SparseMatrix {
    +
    +  /**
    +   * Generate an Identity Matrix in `SparseMatrix` format.
    +   * @param n number of rows and columns of the matrix
    +   * @return `SparseMatrix` with size `n` x `n` and values of ones on the 
diagonal
    +   */
    +  def speye(n: Int): SparseMatrix = {
    +    new SparseMatrix(n, n, (0 to n).toArray, (0 until n).toArray, 
Array.fill(n)(1.0))
    +  }
    +
    +  /** Generates a SparseMatrix given an Array[Double] of size numRows * 
numCols. The number of
    +    * non-zeros in `raw` is provided for efficiency. */
    +  private def genRand(
    --- End diff --
    
    This is a little confusing. First of all, there is no randomness. Secondly, 
the doc doesn't describe how the values gets fill-in. Is it supposed to be a 
method in `DenseMatrix` called `toSparse`?


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