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).
This commit is contained in:
Gael Guennebaud
2009-04-01 14:43:37 +00:00
parent 0f8e692b3f
commit 0170eb0dbe
8 changed files with 863 additions and 7 deletions

View File

@@ -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)) ));
}
}