spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mengxr <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-4409][MLlib] Additional Linear Algebra ...
Date Thu, 18 Dec 2014 20:56:18 GMT
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3319#discussion_r22070486
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala ---
    @@ -197,6 +331,145 @@ 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
    +  }
    +
    +  /** Generate a `DenseMatrix` from the given `SparseMatrix`. */
    +  def toDense(): DenseMatrix = {
    +    new DenseMatrix(numRows, numCols, toArray)
    +  }
    +}
    +
    +/**
    + * Factory methods for [[org.apache.spark.mllib.linalg.SparseMatrix]].
    + */
    +object SparseMatrix {
    +
    +  /**
    +   * Generate a `SparseMatrix` from Coordinate List (COO) format. Input must be an array
of
    +   * (row, column, value) tuples. Array must be sorted first by *column* index and then
by row
    +   * index.
    +   * @param numRows number of rows of the matrix
    +   * @param numCols number of columns of the matrix
    +   * @param entries Array of ((row, column), value) tuples
    +   * @return The corresponding `SparseMatrix`
    +   */
    +  def fromCOO(numRows: Int, numCols: Int, entries: Array[((Int, Int), Double)]): SparseMatrix
= {
    --- End diff --
    
    `(Int, Int, Double)` should be sufficient and it saves one object.


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

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


Mime
View raw message