source: trunk/test_more/cppad_eigen.cpp @ 3008

Last change on this file since 3008 was 2870, checked in by bradbell, 7 years ago

Fix g++ 4.8.1 warnings about unused local types.

check_doxygen.sh: new version of doxygen has warnings that need to be fixed.
check_simple_vector.hpp: fix minor typos in documentation.

  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1/* $Id: cppad_eigen.cpp 2870 2013-07-28 17:00:59Z 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# include <cppad/cppad.hpp>
19
20bool cppad_eigen(void)
21{       bool ok = true;
22        using CppAD::AD;
23        using Eigen::Dynamic;
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_epsilon() == 
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 paritali specialization of
51        // struct significant_decimals_default_impl in cppad_eigen.hpp.
52        Eigen::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        return ok;
59}
Note: See TracBrowser for help on using the repository browser.