diff options
author | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-04-01 17:44:48 +0200 |
---|---|---|
committer | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-04-01 17:44:48 +0200 |
commit | 1cb8de12501b3db3d12774774cbbe12983243cee (patch) | |
tree | f3fbdf8f347c2ddee13f2b357b103508143bef46 /unsupported/test/autodiff.cpp | |
parent | 56c4851323376876977a9d408cb5aec2a6159c54 (diff) |
Make some actual verifications inside the autodiff unit test
Diffstat (limited to 'unsupported/test/autodiff.cpp')
-rw-r--r-- | unsupported/test/autodiff.cpp | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/unsupported/test/autodiff.cpp b/unsupported/test/autodiff.cpp index 6eb417e8d..087e7c542 100644 --- a/unsupported/test/autodiff.cpp +++ b/unsupported/test/autodiff.cpp @@ -127,46 +127,47 @@ template<typename Func> void forward_jacobian(const Func& f) VERIFY_IS_APPROX(j, jref); } + +// TODO also check actual derivatives! void test_autodiff_scalar() { - std::cerr << foo<float>(1,2) << "\n"; + Vector2f p = Vector2f::Random(); typedef AutoDiffScalar<Vector2f> AD; - AD ax(1,Vector2f::UnitX()); - AD ay(2,Vector2f::UnitY()); + AD ax(p.x(),Vector2f::UnitX()); + AD ay(p.y(),Vector2f::UnitY()); AD res = foo<AD>(ax,ay); - std::cerr << res.value() << " <> " - << res.derivatives().transpose() << "\n\n"; + VERIFY_IS_APPROX(res.value(), foo(p.x(),p.y())); } +// TODO also check actual derivatives! void test_autodiff_vector() { - std::cerr << foo<Vector2f>(Vector2f(1,2)) << "\n"; + Vector2f p = Vector2f::Random(); typedef AutoDiffScalar<Vector2f> AD; typedef Matrix<AD,2,1> VectorAD; - VectorAD p(AD(1),AD(-1)); - p.x().derivatives() = Vector2f::UnitX(); - p.y().derivatives() = Vector2f::UnitY(); + VectorAD ap = p.cast<AD>(); + ap.x().derivatives() = Vector2f::UnitX(); + ap.y().derivatives() = Vector2f::UnitY(); - AD res = foo<VectorAD>(p); - std::cerr << res.value() << " <> " - << res.derivatives().transpose() << "\n\n"; + AD res = foo<VectorAD>(ap); + VERIFY_IS_APPROX(res.value(), foo(p)); } void test_autodiff_jacobian() { - for(int i = 0; i < g_repeat; i++) { - CALL_SUBTEST(( forward_jacobian(TestFunc1<double,2,2>()) )); - CALL_SUBTEST(( forward_jacobian(TestFunc1<double,2,3>()) )); - CALL_SUBTEST(( forward_jacobian(TestFunc1<double,3,2>()) )); - CALL_SUBTEST(( forward_jacobian(TestFunc1<double,3,3>()) )); - CALL_SUBTEST(( forward_jacobian(TestFunc1<double>(3,3)) )); - } + CALL_SUBTEST(( forward_jacobian(TestFunc1<double,2,2>()) )); + CALL_SUBTEST(( forward_jacobian(TestFunc1<double,2,3>()) )); + CALL_SUBTEST(( forward_jacobian(TestFunc1<double,3,2>()) )); + CALL_SUBTEST(( forward_jacobian(TestFunc1<double,3,3>()) )); + CALL_SUBTEST(( forward_jacobian(TestFunc1<double>(3,3)) )); } void test_autodiff() { - test_autodiff_scalar(); - test_autodiff_vector(); -// test_autodiff_jacobian(); + for(int i = 0; i < g_repeat; i++) { + CALL_SUBTEST_1( test_autodiff_scalar() ); + CALL_SUBTEST_2( test_autodiff_vector() ); + CALL_SUBTEST_3( test_autodiff_jacobian() ); + } } |