aboutsummaryrefslogtreecommitdiff
path: root/mllib-local
diff options
context:
space:
mode:
authorPeng, Meng <peng.meng@intel.com>2016-08-26 11:54:10 -0700
committerDB Tsai <dbt@netflix.com>2016-08-26 11:54:10 -0700
commitc0949dc944b7e2fc8a4465acc68a8f2713b3fa13 (patch)
tree712dc694c3bc764f50d13485e756edd6c4961539 /mllib-local
parent9812f7d5381f7cd8112fd30c7e45ae4f0eab6e88 (diff)
[SPARK-17207][MLLIB] fix comparing Vector bug in TestingUtils
## What changes were proposed in this pull request? fix comparing Vector bug in TestingUtils. There is the same bug for Matrix comparing. How to check the length of Matrix should be discussed first. ## How was this patch tested? (Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests) (If this patch involves UI changes, please attach a screenshot; otherwise, remove this) Author: Peng, Meng <peng.meng@intel.com> Closes #14785 from mpjlu/testUtils.
Diffstat (limited to 'mllib-local')
-rw-r--r--mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtils.scala10
-rw-r--r--mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtilsSuite.scala277
2 files changed, 281 insertions, 6 deletions
diff --git a/mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtils.scala b/mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtils.scala
index 2bebaa35ba..2327917e2c 100644
--- a/mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtils.scala
+++ b/mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtils.scala
@@ -154,7 +154,7 @@ object TestingUtils {
*/
def absTol(eps: Double): CompareVectorRightSide = CompareVectorRightSide(
(x: Vector, y: Vector, eps: Double) => {
- x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 absTol eps)
+ x.size == y.size && x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 absTol eps)
}, x, eps, ABS_TOL_MSG)
/**
@@ -164,7 +164,7 @@ object TestingUtils {
*/
def relTol(eps: Double): CompareVectorRightSide = CompareVectorRightSide(
(x: Vector, y: Vector, eps: Double) => {
- x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 relTol eps)
+ x.size == y.size && x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 relTol eps)
}, x, eps, REL_TOL_MSG)
override def toString: String = x.toString
@@ -217,7 +217,8 @@ object TestingUtils {
*/
def absTol(eps: Double): CompareMatrixRightSide = CompareMatrixRightSide(
(x: Matrix, y: Matrix, eps: Double) => {
- x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 absTol eps)
+ x.numRows == y.numRows && x.numCols == y.numCols &&
+ x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 absTol eps)
}, x, eps, ABS_TOL_MSG)
/**
@@ -227,7 +228,8 @@ object TestingUtils {
*/
def relTol(eps: Double): CompareMatrixRightSide = CompareMatrixRightSide(
(x: Matrix, y: Matrix, eps: Double) => {
- x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 relTol eps)
+ x.numRows == y.numRows && x.numCols == y.numCols &&
+ x.toArray.zip(y.toArray).forall(x => x._1 ~= x._2 relTol eps)
}, x, eps, REL_TOL_MSG)
override def toString: String = x.toString
diff --git a/mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtilsSuite.scala b/mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtilsSuite.scala
index e374165f75..5cbf2f04e6 100644
--- a/mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtilsSuite.scala
+++ b/mllib-local/src/test/scala/org/apache/spark/ml/util/TestingUtilsSuite.scala
@@ -20,7 +20,7 @@ package org.apache.spark.ml.util
import org.scalatest.exceptions.TestFailedException
import org.apache.spark.ml.SparkMLFunSuite
-import org.apache.spark.ml.linalg.Vectors
+import org.apache.spark.ml.linalg.{Matrices, Vectors}
import org.apache.spark.ml.util.TestingUtils._
class TestingUtilsSuite extends SparkMLFunSuite {
@@ -109,6 +109,10 @@ class TestingUtilsSuite extends SparkMLFunSuite {
assert(Vectors.dense(Array(3.1, 3.5)) !~= Vectors.dense(Array(3.135, 3.534)) relTol 0.01)
assert(!(Vectors.dense(Array(3.1, 3.5)) !~= Vectors.dense(Array(3.130, 3.534)) relTol 0.01))
assert(!(Vectors.dense(Array(3.1, 3.5)) ~= Vectors.dense(Array(3.135, 3.534)) relTol 0.01))
+ assert(Vectors.dense(Array(3.1)) !~= Vectors.dense(Array(3.130, 3.534)) relTol 0.01)
+ assert(Vectors.dense(Array[Double]()) !~= Vectors.dense(Array(3.130, 3.534)) relTol 0.01)
+ assert(Vectors.dense(Array(3.1)) !~== Vectors.dense(Array(3.130, 3.534)) relTol 0.01)
+ assert(Vectors.dense(Array[Double]()) !~== Vectors.dense(Array(3.130, 3.534)) relTol 0.01)
// Should throw exception with message when test fails.
intercept[TestFailedException](
@@ -117,6 +121,12 @@ class TestingUtilsSuite extends SparkMLFunSuite {
intercept[TestFailedException](
Vectors.dense(Array(3.1, 3.5)) ~== Vectors.dense(Array(3.135, 3.534)) relTol 0.01)
+ intercept[TestFailedException](
+ Vectors.dense(Array(3.1)) ~== Vectors.dense(Array(3.535, 3.534)) relTol 0.01)
+
+ intercept[TestFailedException](
+ Vectors.dense(Array[Double]()) ~== Vectors.dense(Array(3.135)) relTol 0.01)
+
// Comparing against zero should fail the test and throw exception with message
// saying that the relative error is meaningless in this situation.
intercept[TestFailedException](
@@ -125,12 +135,18 @@ class TestingUtilsSuite extends SparkMLFunSuite {
intercept[TestFailedException](
Vectors.dense(Array(3.1, 0.01)) ~== Vectors.sparse(2, Array(0), Array(3.13)) relTol 0.01)
- // Comparisons of two sparse vectors
+ // Comparisons of a sparse vector and a dense vector
assert(Vectors.dense(Array(3.1, 3.5)) ~==
Vectors.sparse(2, Array(0, 1), Array(3.130, 3.534)) relTol 0.01)
assert(Vectors.dense(Array(3.1, 3.5)) !~==
Vectors.sparse(2, Array(0, 1), Array(3.135, 3.534)) relTol 0.01)
+
+ assert(Vectors.dense(Array(3.1)) !~==
+ Vectors.sparse(2, Array(0, 1), Array(3.130, 3.534)) relTol 0.01)
+
+ assert(Vectors.dense(Array[Double]()) !~==
+ Vectors.sparse(2, Array(0, 1), Array(3.130, 3.534)) relTol 0.01)
}
test("Comparing vectors using absolute error.") {
@@ -154,6 +170,21 @@ class TestingUtilsSuite extends SparkMLFunSuite {
assert(!(Vectors.dense(Array(3.1, 3.5, 0.0)) ~=
Vectors.dense(Array(3.1 + 1E-5, 3.5 + 2E-7, 1 + 1E-3)) absTol 1E-6))
+ assert(Vectors.dense(Array(3.1)) !~=
+ Vectors.dense(Array(3.1 + 1E-6, 3.5 + 2E-7)) absTol 1E-5)
+
+ assert(!(Vectors.dense(Array(3.1)) ~=
+ Vectors.dense(Array(3.1 + 1E-6, 3.5 + 2E-7)) absTol 1E-5))
+
+ assert(Vectors.dense(Array[Double]()) !~=
+ Vectors.dense(Array(3.1 + 1E-6, 3.5 + 2E-7)) absTol 1E-5)
+
+ assert(!(Vectors.dense(Array[Double]()) ~=
+ Vectors.dense(Array(3.1 + 1E-6, 3.5 + 2E-7)) absTol 1E-5))
+
+ assert(Vectors.dense(Array[Double]()) ~=
+ Vectors.dense(Array[Double]()) absTol 1E-5)
+
// Should throw exception with message when test fails.
intercept[TestFailedException](Vectors.dense(Array(3.1, 3.5, 0.0)) !~==
Vectors.dense(Array(3.1 + 1E-8, 3.5 + 2E-7, 1E-8)) absTol 1E-6)
@@ -161,6 +192,12 @@ class TestingUtilsSuite extends SparkMLFunSuite {
intercept[TestFailedException](Vectors.dense(Array(3.1, 3.5, 0.0)) ~==
Vectors.dense(Array(3.1 + 1E-5, 3.5 + 2E-7, 1 + 1E-3)) absTol 1E-6)
+ intercept[TestFailedException](Vectors.dense(Array(3.1)) ~==
+ Vectors.dense(Array(3.1 + 1E-5, 3.5 + 2E-7)) absTol 1E-6)
+
+ intercept[TestFailedException](Vectors.dense(Array[Double]()) ~==
+ Vectors.dense(Array(3.1 + 1E-5, 3.5 + 2E-7)) absTol 1E-6)
+
// Comparisons of two sparse vectors
assert(Vectors.sparse(3, Array(0, 2), Array(3.1, 2.4)) ~==
Vectors.sparse(3, Array(0, 2), Array(3.1 + 1E-8, 2.4 + 1E-7)) absTol 1E-6)
@@ -174,6 +211,12 @@ class TestingUtilsSuite extends SparkMLFunSuite {
assert(Vectors.sparse(3, Array(0, 2), Array(3.1 + 1E-3, 2.4)) !~==
Vectors.sparse(3, Array(0, 2), Array(3.1, 2.4)) absTol 1E-6)
+ assert(Vectors.sparse(3, Array(0, 2), Array(3.1 + 1E-6, 2.4)) !~==
+ Vectors.sparse(1, Array(0), Array(3.1)) absTol 1E-3)
+
+ assert(Vectors.sparse(0, Array[Int](), Array[Double]()) !~==
+ Vectors.sparse(1, Array(0), Array(3.1)) absTol 1E-3)
+
// Comparisons of a dense vector and a sparse vector
assert(Vectors.sparse(3, Array(0, 2), Array(3.1, 2.4)) ~==
Vectors.dense(Array(3.1 + 1E-8, 0, 2.4 + 1E-7)) absTol 1E-6)
@@ -183,5 +226,235 @@ class TestingUtilsSuite extends SparkMLFunSuite {
assert(Vectors.sparse(3, Array(0, 2), Array(3.1, 2.4)) !~==
Vectors.dense(Array(3.1, 1E-3, 2.4)) absTol 1E-6)
+
+ assert(Vectors.sparse(3, Array(0, 2), Array(3.1, 2.4)) !~==
+ Vectors.dense(Array(3.1)) absTol 1E-6)
+
+ assert(Vectors.dense(Array[Double]()) !~==
+ Vectors.sparse(3, Array(0, 2), Array(0, 2.4)) absTol 1E-6)
+
+ assert(Vectors.sparse(1, Array(0), Array(3.1)) !~==
+ Vectors.dense(Array(3.1, 3.2)) absTol 1E-6)
+
+ assert(Vectors.dense(Array(3.1)) !~==
+ Vectors.sparse(0, Array[Int](), Array[Double]()) absTol 1E-6)
+ }
+
+ test("Comparing Matrices using absolute error.") {
+
+ // Comparisons of two dense Matrices
+ assert(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) ~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 3.5 + 2E-7, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) ~=
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 3.5 + 2E-7, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) !~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-5, 3.5 + 2E-6, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) !~=
+ Matrices.dense(2, 2, Array(3.1 + 1E-5, 3.5 + 2E-6, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(!(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) ~=
+ Matrices.dense(2, 2, Array(3.1 + 1E-5, 3.5 + 2E-6, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6))
+
+ assert(!(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) !~=
+ Matrices.dense(2, 2, Array(3.1 + 1E-7, 3.5 + 2E-8, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6))
+
+ assert(Matrices.dense(2, 1, Array(3.1, 3.5)) !~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-7, 3.5 + 2E-8, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.dense(2, 1, Array(3.1, 3.5)) !~=
+ Matrices.dense(2, 2, Array(3.1 + 1E-7, 3.5 + 2E-8, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.dense(0, 0, Array()) !~=
+ Matrices.dense(2, 2, Array(3.1 + 1E-7, 3.5 + 2E-8, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.dense(0, 0, Array()) !~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-7, 3.5 + 2E-8, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ // Should throw exception with message when test fails.
+ intercept[TestFailedException](Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) !~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 3.5 + 2E-7, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ intercept[TestFailedException](Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) ~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 3.5 + 2E-7, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-9)
+
+ intercept[TestFailedException](Matrices.dense(2, 1, Array(3.1, 3.5)) ~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 3.5 + 2E-7, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-5)
+
+ intercept[TestFailedException](Matrices.dense(0, 0, Array()) ~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 3.5 + 2E-7, 3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-5)
+
+ // Comparisons of two sparse Matrices
+ assert(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) ~==
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) ~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) !~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-9)
+
+ assert(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) !~==
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-9)
+
+ assert(!(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) ~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5)) absTol 1E-9))
+
+ assert(!(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) !~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5)) absTol 1E-6))
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-9)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~==
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.sparse(0, 0, Array(1), Array(0), Array(0)) !~==
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.sparse(0, 0, Array(1), Array(0), Array(0)) !~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1 + 1E-8, 3.5 + 1E-7)) absTol 1E-6)
+
+ // Comparisons of a dense Matrix and a sparse Matrix
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) ~=
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 0, 0, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) ~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 0, 0, 3.5 + 1E-7)) absTol 1E-6)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 0, 0, 3.5 + 1E-7)) absTol 1E-9)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~==
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 0, 0, 3.5 + 1E-7)) absTol 1E-9)
+
+ assert(!(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) ~=
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 0, 0, 3.5 + 1E-7)) absTol 1E-9))
+
+ assert(!(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~=
+ Matrices.dense(2, 2, Array(3.1 + 1E-8, 0, 0, 3.5 + 1E-7)) absTol 1E-6))
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~=
+ Matrices.dense(2, 1, Array(3.1 + 1E-8, 0)) absTol 1E-6)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~==
+ Matrices.dense(2, 1, Array(3.1 + 1E-8, 0)) absTol 1E-6)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~==
+ Matrices.dense(0, 0, Array()) absTol 1E-6)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~=
+ Matrices.dense(0, 0, Array()) absTol 1E-6)
+ }
+
+ test("Comparing Matrices using relative error.") {
+
+ // Comparisons of two dense Matrices
+ assert(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) ~==
+ Matrices.dense(2, 2, Array(3.130, 3.534, 3.130, 3.534)) relTol 0.01)
+
+ assert(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) ~=
+ Matrices.dense(2, 2, Array(3.130, 3.534, 3.130, 3.534)) relTol 0.01)
+
+ assert(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) !~==
+ Matrices.dense(2, 2, Array(3.135, 3.534, 3.135, 3.534)) relTol 0.01)
+
+ assert(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) !~=
+ Matrices.dense(2, 2, Array(3.135, 3.534, 3.135, 3.534)) relTol 0.01)
+
+ assert(!(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) ~=
+ Matrices.dense(2, 2, Array(3.134, 3.535, 3.134, 3.535)) relTol 0.01))
+
+ assert(!(Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) !~=
+ Matrices.dense(2, 2, Array(3.130, 3.534, 3.130, 3.534)) relTol 0.01))
+
+ assert(Matrices.dense(2, 1, Array(3.1, 3.5)) !~==
+ Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) relTol 0.01)
+
+ assert(Matrices.dense(2, 1, Array(3.1, 3.5)) !~=
+ Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) relTol 0.01)
+
+ assert(Matrices.dense(0, 0, Array()) !~=
+ Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) relTol 0.01)
+
+ assert(Matrices.dense(0, 0, Array()) !~==
+ Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) relTol 0.01)
+
+ // Should throw exception with message when test fails.
+ intercept[TestFailedException](Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) !~==
+ Matrices.dense(2, 2, Array(3.130, 3.534, 3.130, 3.534)) relTol 0.01)
+
+ intercept[TestFailedException](Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) ~==
+ Matrices.dense(2, 2, Array(3.135, 3.534, 3.135, 3.534)) relTol 0.01)
+
+ intercept[TestFailedException](Matrices.dense(2, 1, Array(3.1, 3.5)) ~==
+ Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) relTol 0.01)
+
+ intercept[TestFailedException](Matrices.dense(0, 0, Array()) ~==
+ Matrices.dense(2, 2, Array(3.1, 3.5, 3.1, 3.5)) relTol 0.01)
+
+ // Comparisons of two sparse Matrices
+ assert(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) ~==
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.130, 3.534)) relTol 0.01)
+
+ assert(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) ~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.130, 3.534)) relTol 0.01)
+
+ assert(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) !~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.135, 3.534)) relTol 0.01)
+
+ assert(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) !~==
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.135, 3.534)) relTol 0.01)
+
+ assert(!(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) ~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.135, 3.534)) relTol 0.01))
+
+ assert(!(Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) !~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.130, 3.534)) relTol 0.01))
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) relTol 0.01)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~==
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) relTol 0.01)
+
+ assert(Matrices.sparse(0, 0, Array(1), Array(0), Array(0)) !~==
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) relTol 0.01)
+
+ assert(Matrices.sparse(0, 0, Array(1), Array(0), Array(0)) !~=
+ Matrices.sparse(3, 2, Array(0, 1, 2), Array(1, 2), Array(3.1, 3.5)) relTol 0.01)
+
+ // Comparisons of a dense Matrix and a sparse Matrix
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) ~=
+ Matrices.dense(2, 2, Array(3.130, 0, 0, 3.534)) relTol 0.01)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) ~==
+ Matrices.dense(2, 2, Array(3.130, 0, 0, 3.534)) relTol 0.01)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~=
+ Matrices.dense(2, 2, Array(3.135, 0, 0, 3.534)) relTol 0.01)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~==
+ Matrices.dense(2, 2, Array(3.135, 0, 0, 3.534)) relTol 0.01)
+
+ assert(!(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) ~=
+ Matrices.dense(2, 2, Array(3.135, 0, 0, 3.534)) relTol 0.01))
+
+ assert(!(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~=
+ Matrices.dense(2, 2, Array(3.130, 0, 0, 3.534)) relTol 0.01))
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~=
+ Matrices.dense(2, 1, Array(3.1, 0)) relTol 0.01)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~==
+ Matrices.dense(2, 1, Array(3.1, 0)) relTol 0.01)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~==
+ Matrices.dense(0, 0, Array()) relTol 0.01)
+
+ assert(Matrices.sparse(2, 2, Array(0, 1, 2), Array(0, 1), Array(3.1, 3.5)) !~=
+ Matrices.dense(0, 0, Array()) relTol 0.01)
}
}