This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 1182 - Implementation of abs2_impl seems incorrect
Summary: Implementation of abs2_impl seems incorrect
Status: RESOLVED FIXED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.2
Hardware: All All
: Normal Compilation Problem
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-18 18:54 UTC by Nilay
Modified: 2019-12-04 15:33 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
Comment 2 Nobody 2019-12-04 15:33:47 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1182.

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