aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/jacobisvd.cpp
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-10-14 10:14:43 -0400
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-10-14 10:14:43 -0400
commit8f0e80fe304ad34b520a869ae58bbff8b64c63f2 (patch)
tree5c2cc43f147811448899955c5fe86b340ed7aee6 /test/jacobisvd.cpp
parent47197065da5191824bad8418d9d19bdd76febaab (diff)
JacobiSVD:
* fix preallocating constructors, allocate U and V of the right size for computation options * complete documentation and internal comments * improve unit test, test inf/nan values
Diffstat (limited to 'test/jacobisvd.cpp')
-rw-r--r--test/jacobisvd.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/test/jacobisvd.cpp b/test/jacobisvd.cpp
index a6dbcf2e8..7d8c36308 100644
--- a/test/jacobisvd.cpp
+++ b/test/jacobisvd.cpp
@@ -196,6 +196,23 @@ template<typename MatrixType> void jacobisvd_verify_assert(const MatrixType& m)
}
}
+template<typename MatrixType>
+void jacobisvd_inf_nan()
+{
+ JacobiSVD<MatrixType> svd;
+ typedef typename MatrixType::Scalar Scalar;
+ Scalar some_inf = Scalar(1) / Scalar(0);
+ svd.compute(MatrixType::Constant(10,10,some_inf), ComputeFullU | ComputeFullV);
+ Scalar some_nan = Scalar(0) / Scalar(0);
+ svd.compute(MatrixType::Constant(10,10,some_nan), ComputeFullU | ComputeFullV);
+ MatrixType m = MatrixType::Zero(10,10);
+ m(ei_random<int>(0,9), ei_random<int>(0,9)) = some_inf;
+ svd.compute(m, ComputeFullU | ComputeFullV);
+ m = MatrixType::Zero(10,10);
+ m(ei_random<int>(0,9), ei_random<int>(0,9)) = some_nan;
+ svd.compute(m, ComputeFullU | ComputeFullV);
+}
+
void test_jacobisvd()
{
CALL_SUBTEST_3(( jacobisvd_verify_assert(Matrix3f()) ));
@@ -211,10 +228,15 @@ void test_jacobisvd()
m << 1, 0,
1, 0;
CALL_SUBTEST_1(( jacobisvd(m, false) ));
+
Matrix2d n;
- n << 1, 1,
- 1, -1;
+ n << 0, 0,
+ 0, 0;
+ CALL_SUBTEST_2(( jacobisvd(n, false) ));
+ n << 0, 0,
+ 0, 1;
CALL_SUBTEST_2(( jacobisvd(n, false) ));
+
CALL_SUBTEST_3(( jacobisvd<Matrix3f>() ));
CALL_SUBTEST_4(( jacobisvd<Matrix4d>() ));
CALL_SUBTEST_5(( jacobisvd<Matrix<float,3,5> >() ));
@@ -226,8 +248,14 @@ void test_jacobisvd()
CALL_SUBTEST_8(( jacobisvd<MatrixXcd>(MatrixXcd(r,c)) ));
(void) r;
(void) c;
+
+ // Test on inf/nan matrix
+ CALL_SUBTEST_7( jacobisvd_inf_nan<MatrixXf>() );
}
- CALL_SUBTEST_7(( jacobisvd<MatrixXf>(MatrixXf(ei_random<int>(200, 300), ei_random<int>(200, 300))) ));
- CALL_SUBTEST_8(( jacobisvd<MatrixXcd>(MatrixXcd(ei_random<int>(100, 120), ei_random<int>(100, 120))) ));
+ CALL_SUBTEST_7(( jacobisvd<MatrixXf>(MatrixXf(ei_random<int>(100, 150), ei_random<int>(100, 150))) ));
+ CALL_SUBTEST_8(( jacobisvd<MatrixXcd>(MatrixXcd(ei_random<int>(80, 100), ei_random<int>(80, 100))) ));
+
+ // Test problem size constructors
+ CALL_SUBTEST_7( JacobiSVD<MatrixXf>(10,10) );
}