Re: [eigen] Using custom scalar types.

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


Hi,

indeed, there is no nice solution yet. Nevertheless, here is a lot simpler one:

namespace Eigen {
  namespace internal {
    template<class Base>
    struct significant_decimals_impl< CppAD::AD<Base> >
      : significant_decimals_impl<Base>
    {};
  }
}

A general solution would to add a new type to NumTraits that would
export the "atomic" numeric type on which the given scalar type is
based on. This is also this type that should be used to define
epsilon(), and the likes. It would also be required to properly
support array of array... The only pb is that adding such a new type
would break the source compatibility for anyone that would have
defined custom scalar types...

Also, this routine is only needed when the user ask for full-precision
through the withFormat() function. So at least, we could avoid calling
this routine if no format is specified.

gael.


On Sun, Apr 28, 2013 at 11:44 AM, Brad Bell <bradbell@xxxxxxxxxx> wrote:
> I was able to fix this problem by defining a partial specialization for
>     template<typename Scalar, bool IsInteger>
>     struct significant_decimals_default_impl
> which is defined in Eigen/src/Core/IO.h. The partial specialization can be
> in the change set
>     https://projects.coin-or.org/CppAD/changeset/2792#file10
>
> Perhaps there is some other way (without defining a cast from AD<Base> to
> int) that the same thing can be accomplished and that is documented and
> hence part of the Eigen API ?
>
>
>
>
> On 04/22/2013 07:15 PM, Brad Bell wrote:
>>
>> If I compile the program:
>> ====================
>> # 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;
>> }
>> ====================
>> using eigen-3.1.3 with the trunk for the package
>> http://www.coin-or.org/CppAD/
>> I get the error message
>> .../include/Eigen/src/Core/IO.h:132:97: error: no matching function for
>> call to ‘ceil(CppAD::AD<double>)’
>> Looking at the corresponding code I see the code
>> return
>> cast<RealScalar,int>(ceil(-log(NumTraits<RealScalar>::epsilon())/log(RealScalar(10))));
>>
>> On the page
>> http://eigen.tuxfamily.org/dox-devel/TopicCustomizingEigen.html
>> under the heading
>> Using custom scalar types
>> I see mention of
>> "define the math functions that makes sense for your type."
>> and perhaps ceil could be considered one such function. But I do not see
>> mention of conversion from the scalar type to int, which also seems to be
>> required ?
>>
>> The problem is that, for AD types, I think that implicit conversion to int
>> is dangerous because the AD information is lost and hence CppAD provides an
>> explicit function for this purpose
>> http://www.coin-or.org/CppAD/Doc/integer.xml
>>
>> Perhaps it would be OK if one restricts the casting operator to be
>> explicit, but as I understand this is a c++11 extension and not available in
>> c++98.
>>
>>
>>
>>
>>
>>
>
>
>
>
>



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