Re: [eigen] new types / NumTraits

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


Dear Christoph,



Am 22.07.2016 um 17:11 schrieb Christoph Hertzberg:
Hi,

Eigen needs to know how many significant digits a type has, which by default it does using:

cast<RealScalar,int>(numext::ceil(-numext::log(NumTraits<RealScalar>::epsilon())/numext::log(RealScalar(10))))

In your case the easiest solution is to specialize:

namespace Eigen { namespace internal {
   template<>
   struct significant_decimals_impl<TpFloat>
       : public significant_decimals_impl<TpFloatBase>
   { };
} }

Thanks, works fine.

We should probably add this to the documentation (and perhaps consider not putting it into the internal namespace).

Shouldn't that be part of NumTrait? There already  epsilon().

However, there are likely other functions which fail if you can't convert your type to int.

If you want to implement a cast from your type to int, but can't add an operator to your class, you can specialize this struct (in Eigen::internal):

   template<typename OldType, typename NewType>  struct cast_impl;

See the last line of your error to locate the default implementation.

Hmm, I find this a little bit scary as I'm not sure how to map types to int in general,
so might implement it differently as expected by Eigen.
I'll have to check what Eigen does with complex numbers, I just couldn't nail it down in a
first fast search. Is there some documentation where these casts to int are needed?



Best regards,
Peter




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