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

    https://github.com/apache/spark/pull/4109#discussion_r23589803
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/mllib/linalg/MatricesSuite.scala ---
    @@ -161,6 +161,68 @@ class MatricesSuite extends FunSuite {
         assert(deMat1.toArray === deMat2.toArray)
       }
     
    +  test("transpose") {
    +    val dA =
    +      new DenseMatrix(4, 3, Array(0.0, 1.0, 0.0, 0.0, 2.0, 0.0, 1.0, 0.0, 
0.0, 0.0, 0.0, 3.0))
    +    val sA = new SparseMatrix(4, 3, Array(0, 1, 3, 4), Array(1, 0, 2, 3), 
Array(1.0, 2.0, 1.0, 3.0))
    +
    +    val dAT = dA.transpose.asInstanceOf[DenseMatrix]
    +    val sAT = sA.transpose.asInstanceOf[SparseMatrix]
    +    val dATexpected =
    +      new DenseMatrix(3, 4, Array(0.0, 2.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 
0.0, 0.0, 0.0, 3.0))
    +    val sATexpected =
    +      new SparseMatrix(3, 4, Array(0, 1, 2, 3, 4), Array(1, 0, 1, 2), 
Array(2.0, 1.0, 1.0, 3.0))
    +
    +    assert(dAT.toBreeze === dATexpected.toBreeze)
    +    assert(sAT.toBreeze === sATexpected.toBreeze)
    +    assert(dA(1, 0) === dAT(0, 1))
    +    assert(dA(2, 1) === dAT(1, 2))
    +    assert(sA(1, 0) === sAT(0, 1))
    +    assert(sA(2, 1) === sAT(1, 2))
    +
    +    assert(!dA.toArray.eq(dAT.toArray), "has to have a new array")
    +    assert(dA.toArray.eq(dAT.transpose.toArray), "should not copy array")
    +
    +    assert(dAT.toSparse().toBreeze === sATexpected.toBreeze)
    +    assert(sAT.toDense().toBreeze === dATexpected.toBreeze)
    +  }
    +
    +  test("foreachActive") {
    +    val m = 3
    +    val n = 2
    +    val values = Array(1.0, 2.0, 4.0, 5.0)
    +    val allValues = Array(1.0, 2.0, 0.0, 0.0, 4.0, 5.0)
    +    val colPtrs = Array(0, 2, 4)
    +    val rowIndices = Array(0, 1, 1, 2)
    +
    +    val sp = new SparseMatrix(m, n, colPtrs, rowIndices, values)
    +    val dn = new DenseMatrix(m, n, allValues)
    +
    +    val dnMap = scala.collection.mutable.Map[(Int, Int), Double]()
    --- End diff --
    
    `import scala.collection.mutable` and use `mutable.Map` here.


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