diff options
author | Gael Guennebaud <g.gael@free.fr> | 2009-04-01 14:43:37 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2009-04-01 14:43:37 +0000 |
commit | 0170eb0dbecb69814716e3c89263d472dbd363ec (patch) | |
tree | b656db9931dbb4da06fcfd88acb8be95e2ada786 /unsupported/test/forward_adolc.cpp | |
parent | 0f8e692b3f5edcab61d586d0a996a2e30bbb68a2 (diff) |
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).
Diffstat (limited to 'unsupported/test/forward_adolc.cpp')
-rw-r--r-- | unsupported/test/forward_adolc.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
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<typename _Scalar, int NX, int NY> +template<typename _Scalar, int NX=Dynamic, int NY=Dynamic> struct TestFunc1 { typedef _Scalar Scalar; @@ -39,6 +39,14 @@ struct TestFunc1 typedef Matrix<Scalar,InputsAtCompileTime,1> InputType; typedef Matrix<Scalar,ValuesAtCompileTime,1> ValueType; typedef Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime> 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<typename T> void operator() (const Matrix<T,InputsAtCompileTime,1>& x, Matrix<T,ValuesAtCompileTime,1>* _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<double,2,3>()) )); CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,3,2>()) )); CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,3,3>()) )); + CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double>(3,3)) )); } } |