From 0170eb0dbecb69814716e3c89263d472dbd363ec Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 1 Apr 2009 14:43:37 +0000 Subject: add an auto-diff module in unsupported. it is similar to adolc's forward mode but the advantage of using Eigen's expression template to compute the derivatives (unless you nest an AutoDiffScalar into an Eigen's matrix). --- unsupported/test/forward_adolc.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'unsupported/test/forward_adolc.cpp') diff --git a/unsupported/test/forward_adolc.cpp b/unsupported/test/forward_adolc.cpp index 016e20cdb..aa7618bff 100644 --- a/unsupported/test/forward_adolc.cpp +++ b/unsupported/test/forward_adolc.cpp @@ -28,7 +28,7 @@ int adtl::ADOLC_numDir; -template +template struct TestFunc1 { typedef _Scalar Scalar; @@ -39,6 +39,14 @@ struct TestFunc1 typedef Matrix InputType; typedef Matrix ValueType; typedef Matrix JacobianType; + + int m_inputs, m_values; + + TestFunc1() : m_inputs(InputsAtCompileTime), m_values(ValuesAtCompileTime) {} + TestFunc1(int inputs, int values) : m_inputs(inputs), m_values(values) {} + + int inputs() const { return m_inputs; } + int values() const { return m_values } template void operator() (const Matrix& x, Matrix* _v) const @@ -47,16 +55,16 @@ struct TestFunc1 v[0] = 2 * x[0] * x[0] + x[0] * x[1]; v[1] = 3 * x[1] * x[0] + 0.5 * x[1] * x[1]; - if(NX>2) + if(inputs()>2) { v[0] += 0.5 * x[2]; v[1] += x[2]; } - if(NY>2) + if(values()>2) { v[2] = 3 * x[1] * x[0] * x[0]; } - if (NX>2 && NY>2) + if (inputs()>2 && values()>2) v[2] *= x[2]; } @@ -74,17 +82,17 @@ struct TestFunc1 j(0,1) = x[0]; j(1,1) = 3 * x[0] + 2 * 0.5 * x[1]; - if (NX>2) + if (inputs()>2) { j(0,2) = 0.5; j(1,2) = 1; } - if(NY>2) + if(values()>2) { j(2,0) = 3 * x[1] * 2 * x[0]; j(2,1) = 3 * x[0] * x[0]; } - if (NX>2 && NY>2) + if (inputs()>2 && values()>2) { j(2,0) *= x[2]; j(2,1) *= x[2]; @@ -128,5 +136,6 @@ void test_forward_adolc() CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1()) )); CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1()) )); CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1()) )); + CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1(3,3)) )); } } -- cgit v1.2.3