From 0e6888260459b31dac1bd3411b0e8f688f6d22a2 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 23 Mar 2016 09:46:42 -0700 Subject: [PATCH] Added the ability to divide a half float by an index --- Eigen/src/Core/arch/CUDA/Half.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Eigen/src/Core/arch/CUDA/Half.h b/Eigen/src/Core/arch/CUDA/Half.h index f997735aa..08f6005e4 100644 --- a/Eigen/src/Core/arch/CUDA/Half.h +++ b/Eigen/src/Core/arch/CUDA/Half.h @@ -234,6 +234,12 @@ static inline EIGEN_DEVICE_FUNC bool operator > (const half& a, const half& b) { #endif // Emulate support for half floats +// Division by an index. Do it in full float precision to avoid accuracy +// issues in converting the denominator to half. +static inline EIGEN_DEVICE_FUNC half operator / (const half& a, Index b) { + return Eigen::half(static_cast(a) / static_cast(b)); +} + // Conversion routines, including fallbacks for the host or older CUDA. // Note that newer Intel CPUs (Haswell or newer) have vectorized versions of // these in hardware. If we need more performance on older/other CPUs, they are