Re: [eigen] Using Eigen with CppAD scalar types

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


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
>>
>>
>>
>>
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/