update adolc support wrt "new" NumTraits mechanism

This commit is contained in:
Gael Guennebaud 2012-06-18 21:32:56 +02:00
parent 148587e229
commit 791e28f25d
2 changed files with 26 additions and 20 deletions

View File

@ -79,33 +79,22 @@ namespace Eigen {
} // namespace Eigen } // namespace Eigen
// the Adolc's type adouble is defined in the adtl namespace // Eigen's require a few additional functions which must be defined in the same namespace
// therefore, the following internal::* functions *must* be defined // than the custom scalar type own namespace
// in the same namespace namespace adtl {
namespace Eigen {
namespace internal { inline const adouble& conj(const adouble& x) { return x; }
inline const adouble& real(const adouble& x) { return x; }
inline const adtl::adouble& conj(const adtl::adouble& x) { return x; } inline adouble imag(const adouble&) { return 0.; }
inline const adtl::adouble& real(const adtl::adouble& x) { return x; } inline adouble abs(const adouble& x) { return fabs(x); }
inline adtl::adouble imag(const adtl::adouble&) { return 0.; } inline adouble abs2(const adouble& x) { return x*x; }
inline adtl::adouble abs(const adtl::adouble& x) { return adtl::fabs(x); }
inline adtl::adouble abs2(const adtl::adouble& x) { return x*x; }
using adtl::sqrt;
using adtl::exp;
using adtl::log;
using adtl::sin;
using adtl::cos;
using adtl::pow;
}
} }
namespace Eigen { namespace Eigen {
template<> struct NumTraits<adtl::adouble> template<> struct NumTraits<adtl::adouble>
: NumTraits<double>
{ {
typedef adtl::adouble Real; typedef adtl::adouble Real;
typedef adtl::adouble NonInteger; typedef adtl::adouble NonInteger;

View File

@ -23,11 +23,20 @@
// Eigen. If not, see <http://www.gnu.org/licenses/>. // Eigen. If not, see <http://www.gnu.org/licenses/>.
#include "main.h" #include "main.h"
#include <Eigen/Dense>
#define NUMBER_DIRECTIONS 16 #define NUMBER_DIRECTIONS 16
#include <unsupported/Eigen/AdolcForward> #include <unsupported/Eigen/AdolcForward>
int adtl::ADOLC_numDir; int adtl::ADOLC_numDir;
template<typename Vector>
EIGEN_DONT_INLINE typename Vector::Scalar foo(const Vector& p)
{
typedef typename Vector::Scalar Scalar;
return (p-Vector(Scalar(-1),Scalar(1.))).norm() + (p.array().sqrt().abs() * p.array().sin()).sum() + p.dot(p);
}
template<typename _Scalar, int NX=Dynamic, int NY=Dynamic> template<typename _Scalar, int NX=Dynamic, int NY=Dynamic>
struct TestFunc1 struct TestFunc1
{ {
@ -138,4 +147,12 @@ void test_forward_adolc()
CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,3,3>()) )); CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,3,3>()) ));
CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double>(3,3)) )); CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double>(3,3)) ));
} }
{
// simple instanciation tests
Matrix<adtl::adouble,2,1> x;
foo(x);
Matrix<adtl::adouble,Dynamic,Dynamic> A(4,4);;
A.selfadjointView<Lower>().eigenvalues();
}
} }