New user self-registration is currently disabled. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 1182 - Implementation of abs2_impl seems incorrect
Implementation of abs2_impl seems incorrect
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Core - general
3.2
All All
: Normal Compilation Problem
Assigned To: Nobody
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-03-18 18:54 UTC by Nilay
Modified: 2016-03-19 08:42 UTC (History)
4 users (show)



Attachments
Possible fix for the problem mentioned above. (424 bytes, text/plain)
2016-03-18 18:54 UTC, Nilay
no flags Details

Description Nilay 2016-03-18 18:54:05 UTC
Created attachment 668 [details]
Possible fix for the problem mentioned above.

I am trying to write a program that uses a C++ wrappers around mpfr_t as complex and real types.  While compiling, I got into trouble with the following code from Eigen/src/Core/MathFunctions.h.

template<typename Scalar>
struct abs2_impl
{
  typedef typename NumTraits<Scalar>::Real RealScalar;
  static inline RealScalar run(const Scalar& x)
  {
    return x*x;
  }
};


The compiler tries to instantiate the function run() for a complex type.  The multiplication operator * for the complex type returns a complex value, not a real scalar as required.  I think the intent here was to return real(x) * real(x) + imag(x) + imag(x).  This also agrees with the name of the function.
Comment 1 Christoph Hertzberg 2016-03-19 08:42:03 UTC
Well, your suggestion is not good, since it could create overhead for real-valued abs2 calls.
I backported the implementation from the devel-branch to 3.2:
https://bitbucket.org/eigen/eigen/commits/60d16ce411ff5b7

Note You need to log in before you can comment on or make changes to this bug.