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-5321] Support for transposing local mat...
Date Tue, 27 Jan 2015 06:40:09 GMT
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4109#discussion_r23589806
  
    --- 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]()
    +    dn.foreachActive { (i, j, value) =>
    +      dnMap.put((i, j), value)
    +    }
    +    assert(dnMap.size === 6)
    +    assert(dnMap.get(0, 0) === Some(1.0))
    +    assert(dnMap.get(1, 0) === Some(2.0))
    +    assert(dnMap.get(2, 0) === Some(0.0))
    +    assert(dnMap.get(0, 1) === Some(0.0))
    +    assert(dnMap.get(1, 1) === Some(4.0))
    +    assert(dnMap.get(2, 1) === Some(5.0))
    +
    +    val spMap = scala.collection.mutable.Map[Int, Double]()
    +    var cnt = 0
    +    sp.foreachActive { (i, j, value) =>
    +      spMap.put(cnt, value)
    +      cnt += 1
    +    }
    +    assert(spMap.size === 4)
    +    assert(spMap.get(0) === Some(1.0))
    --- End diff --
    
    We are asserting on the ordering of `foreachActive`. This is not part of the contract.
Shall we use `(i, j)` as the key (similar to `dnMap`)?


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