mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
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:
@@ -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)) ));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user