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

    https://github.com/apache/spark/pull/2294#discussion_r17709081
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala 
---
    @@ -59,11 +93,113 @@ trait Matrix extends Serializable {
      */
     class DenseMatrix(val numRows: Int, val numCols: Int, val values: 
Array[Double]) extends Matrix {
     
    -  require(values.length == numRows * numCols)
    +  require(values.length == numRows * numCols, "The number of values 
supplied doesn't match the " +
    +    s"size of the matrix! values.length: ${values.length}, numRows * 
numCols: ${numRows * numCols}")
     
       override def toArray: Array[Double] = values
     
    -  private[mllib] override def toBreeze: BM[Double] = new 
BDM[Double](numRows, numCols, values)
    +  private[mllib] def toBreeze: BM[Double] = new BDM[Double](numRows, 
numCols, values)
    +
    +  private[mllib] def apply(i: Int): Double = values(i)
    +
    +  private[mllib] def apply(i: Int, j: Int): Double = values(index(i, j))
    +
    +  private[mllib] def index(i: Int, j: Int): Int = i + numRows * j
    +
    +  private[mllib] def update(i: Int, j: Int, v: Double){
    +    values(index(i, j)) = v
    +  }
    +
    +  override def copy = new DenseMatrix(numRows, numCols, values.clone())
    +}
    +
    +/**
    + * Column-majored sparse matrix.
    + * The entry values are stored in Compressed Sparse Column (CSC) format.
    + * For example, the following matrix
    + * {{{
    + *   1.0 0.0 4.0
    + *   0.0 3.0 5.0
    + *   2.0 0.0 6.0
    + * }}}
    + * is stored as `values: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]`,
    + * `rowIndices=[0, 2, 1, 0, 1, 2]`, `colPointers=[0, 2, 3, 6]`.
    + *
    + * @param numRows number of rows
    + * @param numCols number of columns
    + * @param colPtrs the index corresponding to the start of a new column
    + * @param rowIndices the row index of the entry
    --- End diff --
    
    Let's write down the contract. `rowIndices` should be strictly increasing 
for each column.


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

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

Reply via email to