[CppAD] cout problem with AD<double> based Eigen vector

Brad Bell bradbell at seanet.com
Sun Apr 28 05:36:29 EDT 2013


This problem has been fixed in trunk/cppad/example/cppad_eigen.hpp; see
     https://projects.coin-or.org/CppAD/changeset/2792#file10
Versions of cppad at or after 20130428 should have this change.

Thanks to Di Liu for the bug report

Brad.


On 04/20/2013 06:48 AM, Brad Bell wrote:
> I am able to recreate this problem below with eigen-3.1.3 and the 
> current CppAD trunk
>     https://projects.coin-or.org/CppAD/browser/trunk
> using the code:
> ---------------------------------------
> # include <cppad/cppad.hpp>
> # include <cppad/example/cppad_eigen.hpp>
>
> int main()
> {
>      typedef Eigen::Matrix< CppAD::AD<double>, 1, 1> MatrixAD;
>      MatrixAD X;
>      X(0, 0) = 1;
>
>      std::cout << X << std::endl;
>      return 0;
> }
> --------------------------------------------------
>
> The corresponding error message is:
> .../Eigen/src/Core/IO.h:132:97: error: no matching function for call 
> to ‘ceil(CppAD::AD<double>)’
>
> Looking at the code in IO.h, line 132, we have:
>  return 
> cast<RealScalar,int>(ceil(-log(NumTraits<RealScalar>::epsilon())/log(RealScalar(10))));
>
> So it appears that Eigen requires its scalar types to support the ceil 
> function as well as casting to integer values, but I do not see any 
> reference to how one is supposed to support the cast under the heading
>     Using Custom Scalar Types
> on the page
> http://eigen.tuxfamily.org/dox-devel/TopicCustomizingEigen.html
> but it appears to require
>     static_cast<int>( AD<double> )
>
> AD<double> only has the explicit Integer function
>     http://www.coin-or.org/CppAD/Doc/integer.xml
> instead of the casting operator so as to make it explicit that the 
> corresponding AD information is lost. It appears that
>     static_cast<int>( AD<double> )
> must be added to in order to get Eigen to work.
>
>
> On 04/19/2013 01:29 PM, Di Liu wrote:
>> Hello,
>>
>> I am trying to do "cout << X", where X is of
>> Eigen::Matrix<AD<double>,Dynamic,Dynamic> . However, the GNU g++
>> compiler gives me errors such as:" lib/eigen/Eigen/src/Core/IO.h:132:
>> error: no matching function for call to ‘ceil(CppAD::AD<double>)"
>>
>> The original code is:
>>
>> #include <cppad/cppad.hpp>
>> #include <cppad/example/cppad_eigen.hpp>
>> #include <iostream>
>>
>> using CppAD::AD;
>> using namespace Eigen;
>> using std::cout;
>> using std::endl;
>>
>> int main()
>> {
>>    size_t n=2;
>>    typedef Matrix< AD<double>,Dynamic,Dynamic > MatrixXAD;
>>    MatrixXAD X(2,2);
>>    X<< 1, 2,
>>    3,4;
>>    /*
>>    for (int i=0;i<4;++i)
>>      cout << X(i)<<endl;
>>    */
>>    cout << X;
>> }
>>
>> Thank you very much.
>>
>> Di
>>
>> _______________________________________________
>> CppAD mailing list
>> CppAD at list.coin-or.org
>> http://list.coin-or.org/mailman/listinfo/cppad
>>
>
> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cppad
>



More information about the CppAD mailing list