aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/MathFunctions.h
diff options
context:
space:
mode:
authorGravatar Joel Holdsworth <joel@airwebreathe.org.uk>2020-03-19 17:45:20 +0000
committerGravatar Rasmus Munk Larsen <rmlarsen@google.com>2020-03-19 17:45:20 +0000
commitd5c665742beb8dc00ce0f6eab633f719a9218e03 (patch)
tree2cea4f868303064d37e9321c810cd07c0fcfceac /Eigen/src/Core/MathFunctions.h
parent6ff5a14091151ce0d722878de93b57025976facb (diff)
Add absolute_difference coefficient-wise binary Array function
Diffstat (limited to 'Eigen/src/Core/MathFunctions.h')
-rw-r--r--Eigen/src/Core/MathFunctions.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h
index 090ad43bd..96cb24fcb 100644
--- a/Eigen/src/Core/MathFunctions.h
+++ b/Eigen/src/Core/MathFunctions.h
@@ -1181,6 +1181,36 @@ inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) abs2(const Scalar& x)
EIGEN_DEVICE_FUNC
inline bool abs2(bool x) { return x; }
+template<typename T>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE T absdiff(const T& x, const T& y)
+{
+ return x > y ? x - y : y - x;
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE float absdiff(const float& x, const float& y)
+{
+ return fabsf(x - y);
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE double absdiff(const double& x, const double& y)
+{
+ return fabs(x - y);
+}
+template<>
+EIGEN_DEVICE_FUNC
+EIGEN_ALWAYS_INLINE long double absdiff(const long double& x, const long double& y)
+{
+#if defined(EIGEN_HIPCC)
+ // no "fabsl" on HIP yet
+ return (x > y) ? x : y;
+#else
+ return fabsl(x - y);
+#endif
+}
+
template<typename Scalar>
EIGEN_DEVICE_FUNC
inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(const Scalar& x)