Re: [eigen] Using custom scalar types. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: Re: [eigen] Using custom scalar types.
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Fri, 3 May 2013 18:04:02 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type:content-transfer-encoding; bh=IjnUOvVgXY/5ARFdm5IqmANJ1gRNYViIT3LyRpFghB0=; b=oOurWDB7g25/GFPnnCaOtLUtD+BwysgYKnMbbBrw4QKcVRhZ43P3mOXGH9ErA2xGGs w4IdOje4z09eQSb0B9MH3Y2i0d2kzTT/Hx82Vcr1NsE1SivIcA1Ozgg2p5liyYVh9seo 0ydVMUR0Ay8M0b2LoselA2q7P+rUINZZM208rsSs8e+cYD686ffq8k0XLPZ/tGYLJhgx 7Z+Ee3w3CHYLCjMgDXwX3TCPS8PUWKSI+B9m+D/nPG3UoUqxC8cMd6GOQRyp18NA4IYj a4wfZtGhDHUBAzdY4AvhkheSWQMAx5a/5ijUz+h3vhrcJYvmAhDuMRFGQd3NitV2Y9r3 StAQ==
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.
>>
>>
>>
>>
>>
>>
>
>
>
>
>