Re: [eigen] matrix exponential with c++0x |

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] matrix exponential with c++0x*From*: Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>*Date*: Mon, 30 Nov 2009 14:57:30 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=12OtJ0Bwgv9Y2kbFIxKrLdQfnNz0RGiPXv7+SZCe6Qk=; b=W8LauLEbVP4yzf3IPHxZyZQvVUYHV2IXX9k6M92Ih9cCcCsVFTBqQWqXPyaJraEaBg vd2GtWmu6MaPRSHnyQcrUvoe5ie2WqXI8x0/NL+bLF8a/rGGvCLC+vs2ynujINmeICI0 B6Gy2caS5QBmvACn+LKG3yl8NdbojdFteT8c0=*Domainkey-signature*: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=GBqFZUGuwhjBVGhm5jI1UfW85oKJgYL9yxvww83PFpObAeymSTgQ5SGIYGGX3Cmikp BBSWWf0MxDkMcIfs/hqV4gDKH7kH01gDUYIN8MlwCELKg/YjCYEm+pz3V1baj5Hsn9Zc 140vOfOTp/IzeMNSf7dOsMoRspwfXjHsYm3tw=

On Mon, Nov 30, 2009 at 2:37 PM, mmoll <Markus.Moll@xxxxxxxxxxxxxxxx> wrote:

Yeah, true - it's the conversion from double to float. Thanks for the hint since it lead me to the solution. ;)

So this is what seems to happen. When __GXX_EXPERIMENTAL_CXX0X__ is enabled, "complex<_Tp> pow(const complex<_Tp>& __z, int __n)" does not exist any more - from C++0x on, the standard seems to require you to use this "complex<_Tp> pow(const complex<_Tp>& __x, const _Tp& __y)" signature. As a matter of fact I did not find the implementation that caused the generation of a double complex return type. At least not in the complex header. Anyways, changing the implementation to

MatrixType A = *m_M / std::pow(Scalar(2), m_Scalar(squarings));

solves the issue and makes everything future proof.

- Hauke

> The last error is really strange. I tried to play a little bit with> it and

> it seems that std::pow(std::complex<double>(2), int) is returning a

> std::complex<float>. At least I get the error message "conversion

> from

> 'std::complex<double>' to non-scalar type 'const

> std::complex<float>'

> requested" when I try the following code

>

> const Scalar tmp = std::pow(Scalar(2), m_squarings);

> MatrixType A = *m_M / tmp;

This actually indicates the opposite, that std::pow returns a

complex<double> for arguments of type complex<float>.

The conversion constructors that might lose precision (e.g.

complex<double> to complex<float>) have always been explicit, so my

guess is that the rules for overload resolution have changed.

If m_squarings is a double, the call is pow(complex<float>, double).

Probably the compiler previously preferred the conversion double->float

(wow, although it loses precision), but now prefers complex<float> ->

complex<double> (which makes more sense actually). But maybe the type of

m_squarings changed for some reason or previous versions of GCC treated

complex<double> -> complex<float> less strictly than required?

Yeah, true - it's the conversion from double to float. Thanks for the hint since it lead me to the solution. ;)

So this is what seems to happen. When __GXX_EXPERIMENTAL_CXX0X__ is enabled, "complex<_Tp> pow(const complex<_Tp>& __z, int __n)" does not exist any more - from C++0x on, the standard seems to require you to use this "complex<_Tp> pow(const complex<_Tp>& __x, const _Tp& __y)" signature. As a matter of fact I did not find the implementation that caused the generation of a double complex return type. At least not in the complex header. Anyways, changing the implementation to

MatrixType A = *m_M / std::pow(Scalar(2), m_Scalar(squarings));

solves the issue and makes everything future proof.

- Hauke

**References**:**[eigen] matrix exponential with c++0x***From:*Hauke Heibel

**Re: [eigen] matrix exponential with c++0x***From:*mmoll

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] matrix exponential with c++0x** - Next by Date:
**Re: [eigen] matrix exponential with c++0x** - Previous by thread:
**Re: [eigen] matrix exponential with c++0x** - Next by thread:
**Re: [eigen] matrix exponential with c++0x**

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