Re: [eigen] Using Eigen with CppAD scalar types |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Using Eigen with CppAD scalar types
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Mon, 18 Jun 2012 22:00:47 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=60s1BWAVAoFixy9H/MtJMAOJThWmuCnyt1sCe0hfVyo=; b=dOQmmQRJrKUoUcDQ21eJ/el79r45hp8W3abZv38ADN7OQJJKHAsF4SUiKgEdK97MFd ddvtiA1aA541LxJ8u+Kxc4eRH1w2VGz7sFJOEjgj79l4AScT1+mmNotxH5TWHBqYPyYC Y+Hrg6wY6VAb3TknD805DlUyY/vRwEFCSHtsKK9q8nkXetWaWtrEX2b+9+HE3eW0gI03 DQt+I9GMwMg0/PH5oRRAzaDlENQEGpIK7lK9M0G4i2zQslyiFEWfWPYNq7KRtJ9dPwwi uP7Kp2HJvImyY5knZ3xhVqAgRvMVD0QF4SO3tZAG/V9toECHP7Wpdy5Y0163cLTIv10G VZOA==
Hi,
thanks for sharing this information. This reminded me that the doc on
custom scalar types, as well as the AdolcForward unsupported module
were both deprecated.So in theory, your support code should be rather
written like:
namespace Eigen {
template <class Base> struct NumTraits< CppAD::AD<Base> >
: NumTraits<Base>
{ typedef CppAD::AD<Base> Real;
typedef CppAD::AD<Base> NonInteger;
typedef CppAD::AD<Base>& Nested;
enum {
IsComplex = 0 ,
IsInteger = 0 ,
IsSigned = 1 ,
RequireInitialization = 1 ,
ReadCost = 1 ,
AddCost = 2 ,
MulCost = 2
};
};
}
Making it inherits from NumTraits<Base> permits to get the epsilon,
dummy_precision, lowest and highest methods defined automatically from
the one of the Base type.
The Nested type should be reference to limit copies.
Then you should only have to implement the few Eigen specific
functions in the CppAD namespace:
namespace CppAD {
// functions that return references
template <class Base> const AD<Base>& conj(const AD<Base>& x)
{ return x; }
template <class Base> const AD<Base>& real(const AD<Base>& x)
{ return x; }
// functions that return values
template <class Base> AD<Base> imag(const AD<Base>& x)
{ return CppAD::AD<Base>(0.); }
template <class Base> AD<Base> abs2(const AD<Base>& x)
{ return x * x; }
}
that's all you should need.
gael
On Mon, Jun 18, 2012 at 4:42 PM, Brad Bell <bradbell@xxxxxxxxxx> wrote:
> On 06/18/2012 07:36 AM, Brad Bell wrote:
>>
>> I think that I have correctly connected CppAD::AD<Base> types to Eigen
>> (for the case where Base is a real type).
>>
>> Here is the Eigen custom scalar type interface
>> http://www.coin-or.org/CppAD/Doc/eigen_det.cpp.xml
>
> Sorry for the second posting, the correct link for the scalar type interface
> is
> http://www.coin-or.org/CppAD/Doc/cppad_eigen.hpp.xml
>
>>
>> Here is an example usage
>> http://www.coin-or.org/CppAD/Doc/eigen_det.cpp.xml
>>
>> Here is the corresponding C++ source code
>>
>> https://projects.coin-or.org/CppAD/browser/trunk/cppad/example/cppad_eigen.hpp
>> https://projects.coin-or.org/CppAD/browser/trunk/example/eigen_det.cpp
>>
>>
>>
>>
>
>
>