source: trunk/test_more/cppad_eigen.cpp @ 2794

Last change on this file since 2794 was 2792, checked in by bradbell, 7 years ago
  1. Fix bug demonstrated by bug/eigen_io.sh.
  2. Add eigen and sacado automated tests to jenkins.sh.
  3. Advance version number to cppad-20130428

check_include_omh.sh: add missing file to list.
eigen_io.sh: closer to case originally reported, remove temporary files.
cppad_eigen.cpp: automated test that also demonstrated problem.
get_ipopt.sh: make 'cannot update source' a warning (not error).

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1/* $Id: cppad_eigen.cpp 2792 2013-04-28 09:25:28Z 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        typedef Eigen::Matrix<AD<double>, Dynamic, 1> a_vector;
27        typedef typename a_vector::value_type         a_scalar;
28
29        ok &= traits::IsComplex              == 0;
30        ok &= traits::IsInteger              == 0;
31        ok &= traits::IsSigned               == 1;
32        ok &= traits::RequireInitialization  == 1;
33        ok &= traits::ReadCost               == 1;
34        ok &= traits::AddCost                == 2;
35        ok &= traits::MulCost                == 2;
36
37        ok &= traits::epsilon() == 
38                std::numeric_limits<double>::epsilon();
39        ok &= traits::dummy_epsilon() == 
40                100.* std::numeric_limits<double>::epsilon();
41        ok &= traits::highest() == 
42                std::numeric_limits<double>::max();
43        ok &= traits::lowest() == 
44                std::numeric_limits<double>::min();
45
46        AD<double> x = 2.0;
47        ok  &= conj(x)  == x;
48        ok  &= real(x)  == x;
49        ok  &= imag(x)  == 0.0;
50        ok  &= abs2(x)  == 4.0;
51
52        // Outputing a matrix used to fail before paritali specialization of
53        // struct significant_decimals_default_impl in cppad_eigen.hpp.
54        Eigen::Matrix< AD<double>, 1, 1> X;
55        X(0, 0) = AD<double>(1);
56        std::stringstream stream_out;
57        stream_out << X;
58        ok &= "1" == stream_out.str();
59       
60        return ok;
61}
Note: See TracBrowser for help on using the repository browser.