aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2012-06-18 21:32:56 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2012-06-18 21:32:56 +0200
commit791e28f25d75941a6e0fc317464cbb52cb312944 (patch)
tree0b66089eef286d443bbf0b8cdaa2a5a5a99a251c /unsupported
parent148587e229479ee5e0a6853bb0ae2dac0f34436f (diff)
update adolc support wrt "new" NumTraits mechanism
Diffstat (limited to 'unsupported')
-rw-r--r--unsupported/Eigen/AdolcForward29
-rw-r--r--unsupported/test/forward_adolc.cpp17
2 files changed, 26 insertions, 20 deletions
diff --git a/unsupported/Eigen/AdolcForward b/unsupported/Eigen/AdolcForward
index 6c0a68d67..477c75378 100644
--- a/unsupported/Eigen/AdolcForward
+++ b/unsupported/Eigen/AdolcForward
@@ -79,33 +79,22 @@ namespace Eigen {
} // namespace Eigen
-// the Adolc's type adouble is defined in the adtl namespace
-// therefore, the following internal::* functions *must* be defined
-// in the same namespace
-namespace Eigen {
-
- namespace internal {
-
- inline const adtl::adouble& conj(const adtl::adouble& x) { return x; }
- inline const adtl::adouble& real(const adtl::adouble& x) { return x; }
- inline adtl::adouble imag(const adtl::adouble&) { return 0.; }
- 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;
+// Eigen's require a few additional functions which must be defined in the same namespace
+// than the custom scalar type own namespace
+namespace adtl {
- }
+inline const adouble& conj(const adouble& x) { return x; }
+inline const adouble& real(const adouble& x) { return x; }
+inline adouble imag(const adouble&) { return 0.; }
+inline adouble abs(const adouble& x) { return fabs(x); }
+inline adouble abs2(const adouble& x) { return x*x; }
}
namespace Eigen {
template<> struct NumTraits<adtl::adouble>
+ : NumTraits<double>
{
typedef adtl::adouble Real;
typedef adtl::adouble NonInteger;
diff --git a/unsupported/test/forward_adolc.cpp b/unsupported/test/forward_adolc.cpp
index 1971d883b..07959a668 100644
--- a/unsupported/test/forward_adolc.cpp
+++ b/unsupported/test/forward_adolc.cpp
@@ -23,11 +23,20 @@
// Eigen. If not, see <http://www.gnu.org/licenses/>.
#include "main.h"
+#include <Eigen/Dense>
+
#define NUMBER_DIRECTIONS 16
#include <unsupported/Eigen/AdolcForward>
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>
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)) ));
}
+
+ {
+ // simple instanciation tests
+ Matrix<adtl::adouble,2,1> x;
+ foo(x);
+ Matrix<adtl::adouble,Dynamic,Dynamic> A(4,4);;
+ A.selfadjointView<Lower>().eigenvalues();
+ }
}