New user self-registration is disabled due to spam. Please email eigen-core-team @ if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 1182 - Implementation of abs2_impl seems incorrect
Summary: Implementation of abs2_impl seems incorrect
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.2
Hardware: All All
: Normal Compilation Problem
Assignee: Nobody
Depends on:
Reported: 2016-03-18 18:54 UTC by Nilay
Modified: 2016-03-19 08:42 UTC (History)
4 users (show)

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:

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