dongjoon-hyun commented on code in PR #59559:
URL: https://github.com/apache/spark/pull/59559#discussion_r4299508210


##########
mllib-local/src/test/scala/org/apache/spark/ml/linalg/MatricesSuite.scala:
##########
@@ -123,6 +123,30 @@ class MatricesSuite extends SparkMLFunSuite {
     assert(!sparseMat.toArray.eq(sparseCopy.toArray))
   }
 
+  test("DenseMatrix.hashCode is consistent with equals") {
+    val dm = new DenseMatrix(3, 2, Array(1.0, -0.0, 2.0, 0.0, 3.0, 0.0))
+    assert(dm.hashCode === dm.hashCode)
+    assert(dm.copy === dm)
+    assert(dm.copy.hashCode === dm.hashCode)
+
+    // The same matrix with the values stored in row major.
+    val dmt = new DenseMatrix(3, 2, Array(1.0, 0.0, -0.0, 3.0, 2.0, 0.0), 
isTransposed = true)
+    val dmtColMajor = dmt.toDenseColMajor
+    assert(!dmtColMajor.isTransposed)
+    assert(dmt === dmtColMajor)
+    assert(dmt.hashCode === dmtColMajor.hashCode)
+
+    // The same matrix with an explicit 0.0 and an explicit -0.0.
+    val sm = new SparseMatrix(3, 2, Array(0, 3, 5), Array(0, 1, 2, 0, 1),
+      Array(1.0, 0.0, 2.0, -0.0, 3.0))
+    Seq(dm, dmt).foreach { m =>
+      assert(m === sm)
+      assert(m.hashCode === sm.hashCode)
+      assert(m.transpose === sm.transpose)
+      assert(m.transpose.hashCode === sm.transpose.hashCode)

Review Comment:
   Thank you for the review and the nice catch, @sarutak. I added the 
`4294967297.0` case to the ml suite.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to