source: trunk/test_more/cppad_eigen.cpp @ 3688

Last change on this file since 3688 was 3070, checked in by bradbell, 6 years ago

revert back to explicit for ctor from any type as default

  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/* $Id: cppad_eigen.cpp 3070 2013-12-31 15:09:11Z bradbell $ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Eclipse Public License Version 1.0.
8
9A copy of this license is included in the COPYING file of this distribution.
10Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
11-------------------------------------------------------------------------- */
12
13/*
14Test of Eigen Interface to CppAD Scalar Types
15$end
16*/
17# include <cppad/example/cppad_eigen.hpp>
18
19bool cppad_eigen(void)
20{       bool ok = true;
21        using CppAD::AD;
22        using Eigen::Dynamic;
23        using Eigen::Matrix;
24
25        typedef Eigen::NumTraits<AD<double> >         traits;
26
27        ok &= traits::IsComplex              == 0;
28        ok &= traits::IsInteger              == 0;
29        ok &= traits::IsSigned               == 1;
30        ok &= traits::RequireInitialization  == 1;
31        ok &= traits::ReadCost               == 1;
32        ok &= traits::AddCost                == 2;
33        ok &= traits::MulCost                == 2;
34
35        ok &= traits::epsilon() == 
36                std::numeric_limits<double>::epsilon();
37        ok &= traits::dummy_precision() == 
38                100.* std::numeric_limits<double>::epsilon();
39        ok &= traits::highest() == 
40                std::numeric_limits<double>::max();
41        ok &= traits::lowest() == 
42                std::numeric_limits<double>::min();
43
44        AD<double> x = 2.0;
45        ok  &= conj(x)  == x;
46        ok  &= real(x)  == x;
47        ok  &= imag(x)  == 0.0;
48        ok  &= abs2(x)  == 4.0;
49
50        // Outputing a matrix used to fail before partial specialization of
51        // struct significant_decimals_default_impl in cppad_eigen.hpp.
52        Matrix< AD<double>, 1, 1> X;
53        X(0, 0) = AD<double>(1);
54        std::stringstream stream_out;
55        stream_out << X;
56        ok &= "1" == stream_out.str();
57
58# if ! CPPAD_IMPLICIT_CTOR_FROM_ANY_TYPE
59        // multiplying three matrices together used to cause warning
60        // before making ctor from arbitrary type to AD<Base> explicit.
61        typedef CppAD::AD<double> AScalar;
62        Matrix<AScalar, Dynamic, Dynamic> A(1,1), B(1,1), C(1,1), D(1,1);
63        A(0,0) = 1.0;
64        B(0,0) = 2.0;
65        C(0,0) = 3.0;
66        D      = A * B * C; 
67        ok    &= D(0,0) == 6.0 ;
68# endif
69       
70        return ok;
71}
Note: See TracBrowser for help on using the repository browser.