aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Antonio Sanchez <cantonios@google.com>2021-05-07 08:24:32 -0700
committerGravatar Rasmus Munk Larsen <rmlarsen@google.com>2021-05-07 16:26:57 +0000
commit90e9a33e1ce3e4e7663dd67e6c1f225afaf5c206 (patch)
treecee0ab2ff0da2c4785a9a97546b206933869fc9e /Eigen
parent722ca0b665666f3af579002ad752541d7319d1b6 (diff)
Fix numext::arg return type.
The cxx11 path for `numext::arg` incorrectly returned the complex type instead of the real type, leading to compile errors. Fixed this and added tests. Related to !477, which uncovered the issue.
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/src/Core/MathFunctions.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h
index 29201214f..67b1d8263 100644
--- a/Eigen/src/Core/MathFunctions.h
+++ b/Eigen/src/Core/MathFunctions.h
@@ -592,8 +592,9 @@ struct arg_default_impl;
template<typename Scalar>
struct arg_default_impl<Scalar, true> {
+ typedef typename NumTraits<Scalar>::Real RealScalar;
EIGEN_DEVICE_FUNC
- static inline Scalar run(const Scalar& x)
+ static inline RealScalar run(const Scalar& x)
{
#if defined(EIGEN_HIP_DEVICE_COMPILE)
// HIP does not seem to have a native device side implementation for the math routine "arg"
@@ -601,7 +602,7 @@ struct arg_default_impl<Scalar, true> {
#else
EIGEN_USING_STD(arg);
#endif
- return static_cast<Scalar>(arg(x));
+ return static_cast<RealScalar>(arg(x));
}
};
@@ -612,7 +613,7 @@ struct arg_default_impl<Scalar, false> {
EIGEN_DEVICE_FUNC
static inline RealScalar run(const Scalar& x)
{
- return (x < Scalar(0)) ? Scalar(EIGEN_PI) : Scalar(0);
+ return (x < Scalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0);
}
};
#else
@@ -623,7 +624,7 @@ struct arg_default_impl
EIGEN_DEVICE_FUNC
static inline RealScalar run(const Scalar& x)
{
- return (x < Scalar(0)) ? Scalar(EIGEN_PI) : Scalar(0);
+ return (x < RealScalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0);
}
};