Re: [eigen] MathFunctions.h patch

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


Patch attached.

Thanks,

Trevor


2010/1/7 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
2010/1/7 Trevor Irons <trevorirons@xxxxxxxxx>:
> Ah, I was surprised, but understand.
>
> I am doing electromagnetic modelling, and this is necessary sometimes
> (often).
>
> From what I can tell std::sqrt returns the root in either the first or
> fourth quadrant of the complex plane, same as FORTRAN (I think).
> (Arbitrary, but useful for me)
>
> I can work around using for loops if you prefer not to include this in
> Eigen, but my *very* small vote would say to support it.
>
> I guess I don't really understand your argument fully. Is the behaviour of
> std::sqrt() for complexes not mandated by the C++ standard committee?  Or
> does this vary across compilers? If it is at least supposed to be
> consistent, then all you are doing is passing along expected behaviour of
> C++ to Eigen users, right?

Right, so, since you have a real use case, which is what I was trying
to filter for, let's go for it.
Could you just please generate a real patch:
 - configure your id
 - hg commit, write your commit msg
 - hg export tip
http://eigen.tuxfamily.org/index.php?title=Developer%27s_Corner#Generating_a_patch

Thanks
Benoit

>
> Thanks,
> -Trevor
>
>
> 2010/1/7 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
>>
>> It is on purpose that we excluded sqrt for complex numbers:
>>  - there is no canonical choice between the 2 determinations of the square
>> root.
>>  - no important use case was known to us.
>>
>> Do you have a use case?
>>
>> Benoit
>>
>> 2010/1/7 Trevor Irons <trevorirons@xxxxxxxxx>:
>> > Any problem adding the following patch, or something similiar, to
>> > MathFunctions.h to support std::complex<>.sqrt() ?
>> >
>> > 218d217
>> > < inline std::complex<float> ei_sqrt(std::complex<float>x)  { return
>> > std::sqrt(x); }
>> > 256d254
>> > < inline std::complex<double> ei_sqrt(std::complex<double>x)  { return
>> > std::sqrt(x); }
>> >
>> >
>> > -trevor
>> >
>>
>>
>
>



# HG changeset patch
# User Trevor Irons <tirons@xxxxxxxxx>
# Date 1262901831 25200
# Node ID 3b3443abc4cb9e178f50b5bfccc74a5f15e34ce0
# Parent  9625a2059cfcc2042c1c77e8acd80a0fdd496f82
Added std::sqrt(std::complex<float>) and std::sqrt(std::complex<double>) support to MathFunctions.h

diff -r 9625a2059cfc -r 3b3443abc4cb Eigen/src/Core/MathFunctions.h
--- a/Eigen/src/Core/MathFunctions.h	Thu Jan 07 21:15:32 2010 +0100
+++ b/Eigen/src/Core/MathFunctions.h	Thu Jan 07 15:03:51 2010 -0700
@@ -215,6 +215,7 @@
 inline float ei_abs(const std::complex<float>& x) { return std::abs(x); }
 inline float ei_abs2(const std::complex<float>& x) { return std::norm(x); }
 inline float ei_norm1(const std::complex<float> &x) { return(ei_abs(x.real()) + ei_abs(x.imag())); }
+inline std::complex<float> ei_sqrt(std::complex<float>x)  { return std::sqrt(x); }
 inline std::complex<float> ei_exp(std::complex<float> x)  { return std::exp(x); }
 inline std::complex<float> ei_sin(std::complex<float> x)  { return std::sin(x); }
 inline std::complex<float> ei_cos(std::complex<float> x)  { return std::cos(x); }
@@ -252,6 +253,7 @@
 inline double ei_abs(const std::complex<double>& x) { return std::abs(x); }
 inline double ei_abs2(const std::complex<double>& x) { return std::norm(x); }
 inline double ei_norm1(const std::complex<double> &x) { return(ei_abs(x.real()) + ei_abs(x.imag())); }
+inline std::complex<double> ei_sqrt(std::complex<double>x)  { return std::sqrt(x); }
 inline std::complex<double> ei_exp(std::complex<double> x)  { return std::exp(x); }
 inline std::complex<double> ei_sin(std::complex<double> x)  { return std::sin(x); }
 inline std::complex<double> ei_cos(std::complex<double> x)  { return std::cos(x); }


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