aboutsummaryrefslogtreecommitdiff
path: root/src/armnn
diff options
context:
space:
mode:
authorRob Hughes <robert.hughes@arm.com>2019-12-16 17:10:51 +0000
committerDerek Lamberti <derek.lamberti@arm.com>2019-12-31 09:54:07 +0000
commitfc6bf05e536ee352a1b304c6acff36c6b9ea0ead (patch)
tree9b3541d20aa23cfae8be15caaf1e258aa12ea7d6 /src/armnn
parent9be61282c8f1fdafa78c1acb33ff13857c6fc543 (diff)
downloadarmnn-fc6bf05e536ee352a1b304c6acff36c6b9ea0ead.tar.gz
Some build fixes for MSVC
Change-Id: I749430918b1268786690c3c8dc9fa2a9542d5d1d Signed-off-by: Robert Hughes <robert.hughes@arm.com>
Diffstat (limited to 'src/armnn')
-rw-r--r--src/armnn/TypesUtils.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/armnn/TypesUtils.cpp b/src/armnn/TypesUtils.cpp
index 83c56c491c..f4f857f67a 100644
--- a/src/armnn/TypesUtils.cpp
+++ b/src/armnn/TypesUtils.cpp
@@ -7,6 +7,26 @@
#include <boost/assert.hpp>
#include <boost/numeric/conversion/cast.hpp>
+namespace
+{
+/// Workaround for std:isnan() not being implemented correctly for integral types in MSVC.
+/// https://stackoverflow.com/a/56356405
+/// @{
+template <typename T, typename std::enable_if<std::is_integral<T>::value, T>::type* = nullptr>
+inline int IsNan(T x)
+{
+ // The spec defines integral types to be handled as if they were casted to doubles.
+ return std::isnan(static_cast<double>(x));
+}
+
+template <typename T, typename std::enable_if<!std::is_integral<T>::value, T>::type * = nullptr>
+inline int IsNan(T x)
+{
+ return std::isnan(x);
+}
+/// @}
+} // namespace std
+
template<typename QuantizedType>
QuantizedType armnn::Quantize(float value, float scale, int32_t offset)
{
@@ -28,7 +48,7 @@ float armnn::Dequantize(QuantizedType value, float scale, int32_t offset)
{
static_assert(IsQuantizedType<QuantizedType>(), "Not an integer type.");
BOOST_ASSERT(scale != 0.f);
- BOOST_ASSERT(!std::isnan(value));
+ BOOST_ASSERT(!IsNan(value));
float dequantized = boost::numeric_cast<float>(value - offset) * scale;
return dequantized;
}