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

    https://github.com/apache/spark/pull/2294#discussion_r17709106
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala ---
    @@ -36,4 +36,79 @@ class MatricesSuite extends FunSuite {
           Matrices.dense(3, 2, Array(0.0, 1.0, 2.0))
         }
       }
    +
    +  test("sparse matrix construction") {
    +    val m = 3
    +    val n = 2
    +    val values = Array(1.0, 2.0, 4.0, 5.0)
    +    val colIndices = Array(0, 2, 4)
    +    val rowIndices = Array(1, 2, 1, 2)
    +    val mat = Matrices.sparse(m, n, colIndices, rowIndices, 
values).asInstanceOf[SparseMatrix]
    +    assert(mat.numRows === m)
    +    assert(mat.numCols === n)
    +    assert(mat.values.eq(values), "should not copy data")
    +  }
    +
    +  test("sparse matrix construction with wrong number of elements") {
    +    intercept[RuntimeException] {
    +      Matrices.sparse(3, 2, Array(0, 1), Array(1, 2, 1), Array(0.0, 1.0, 
2.0))
    +    }
    +
    +    intercept[RuntimeException] {
    +      Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(0.0, 1.0, 
2.0))
    +    }
    +  }
    +
    +  test("matrix copies are deep copies") {
    +    val m = 3
    +    val n = 2
    +
    +    val denseMat = Matrices.dense(m, n, Array(0.0, 1.0, 2.0, 3.0, 4.0, 
5.0))
    +    val denseCopy = denseMat.copy
    +
    +    assert(!denseMat.toArray.eq(denseCopy.toArray))
    +
    +    val values = Array(1.0, 2.0, 4.0, 5.0)
    +    val colIndices = Array(0, 2, 4)
    +    val rowIndices = Array(1, 2, 1, 2)
    +    val sparseMat = Matrices.sparse(m, n, colIndices, rowIndices, values)
    +    val sparseCopy = sparseMat.copy
    +
    +    assert(!sparseMat.toArray.eq(sparseCopy.toArray))
    +  }
    +
    +  test("matrix indexing and updating") {
    +    val m = 3
    +    val n = 2
    +    val allValues = Array(0.0, 1.0, 2.0, 3.0, 4.0, 0.0)
    +
    +    val denseMat = new DenseMatrix(m, n, allValues)
    +
    +    assert(denseMat(0, 1) == 3.0)
    +    assert(denseMat(0, 1) == denseMat.values(3))
    +    assert(denseMat(0, 1) == denseMat(3))
    +    assert(denseMat(0, 0) == 0.0)
    +
    +    denseMat.update(0, 0, 10.0)
    +    assert(denseMat(0, 0) == 10.0)
    +    assert(denseMat.values(0) == 10.0)
    +
    +    val sparseValues = Array(1.0, 2.0, 3.0, 4.0)
    +    val colIndices = Array(0, 2, 4)
    +    val rowIndices = Array(1, 2, 0, 1)
    +    val sparseMat = new SparseMatrix(m, n, colIndices, rowIndices, 
sparseValues)
    +
    +    assert(sparseMat(0, 1) == 3.0)
    +    assert(sparseMat(0, 1) == sparseMat.values(2))
    +    assert(sparseMat(0, 1) == sparseMat(2))
    +    assert(sparseMat(0, 0) == 0.0)
    +
    +    intercept[IllegalArgumentException] {
    +      sparseMat.update(0, 0, 10.0)
    +    }
    +
    +    sparseMat.update(0, 1, 10.0)
    +    assert(sparseMat(0, 1) == 10.0)
    --- End diff --
    
    `==` -> `===` (please update others as well)


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