diff --git a/src/mlpack/core/data/load_numeric_csv.hpp b/src/mlpack/core/data/load_numeric_csv.hpp index a43bdd02de..6cfbbdd389 100644 --- a/src/mlpack/core/data/load_numeric_csv.hpp +++ b/src/mlpack/core/data/load_numeric_csv.hpp @@ -14,8 +14,31 @@ #include "load_csv.hpp" -namespace mlpack{ -namespace data{ +namespace mlpack { +namespace data { + +/** + * A safe function to get negative or positive infinity, which avoids unary + * minus on an unsigned type. This works around a Visual Studio warning. + */ +template +inline eT SafeNegInf( + const bool neg, + const typename std::enable_if::value>::type* = 0) +{ + // For an unsigned type, we cannot return negative infinity, so instead return + // 0. + return neg ? 0 : std::numeric_limits::infinity(); +} + +template +inline eT SafeNegInf( + const bool neg, + const typename std::enable_if::value>::type* = 0) +{ + return neg ? -(std::numeric_limits::infinity()) : + std::numeric_limits::infinity(); +} template bool LoadCSV::ConvertToken(eT& val, @@ -49,8 +72,7 @@ bool LoadCSV::ConvertToken(eT& val, ((sigB == 'n') || (sigB == 'N')) && ((sigC == 'f') || (sigC == 'F'))) { - val = neg ? -(std::numeric_limits - ::infinity()) : std::numeric_limits::infinity(); + val = SafeNegInf(neg); return true; } else if (((sigA == 'n') || (sigA == 'N')) &&