aboutsummaryrefslogtreecommitdiff
path: root/src/armnn
diff options
context:
space:
mode:
authorAron Virginas-Tar <Aron.Virginas-Tar@arm.com>2019-04-09 14:08:06 +0100
committerAron Virginas-Tar <Aron.Virginas-Tar@arm.com>2019-04-10 15:54:26 +0100
commitd4f0fead9e014f14e1435281f91fc7a48d02d6a1 (patch)
treea65cbc44024d289e34400df094719e285764a322 /src/armnn
parentf30f7d32b22020f80b21da7b008d8302cee9d395 (diff)
downloadarmnn-d4f0fead9e014f14e1435281f91fc7a48d02d6a1.tar.gz
IVGCVSW-2947 Remove boost dependency from include/TypesUtils.hpp
!android-nn-driver:968 Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> Change-Id: I03ccb4842b060a9893567542bfcadc180bbc7311
Diffstat (limited to 'src/armnn')
-rw-r--r--src/armnn/ResolveType.hpp (renamed from src/armnn/TypeUtils.hpp)0
-rw-r--r--src/armnn/TypesUtils.cpp58
-rw-r--r--src/armnn/test/CreateWorkload.hpp2
-rw-r--r--src/armnn/test/UtilsTests.cpp2
4 files changed, 60 insertions, 2 deletions
diff --git a/src/armnn/TypeUtils.hpp b/src/armnn/ResolveType.hpp
index 55269f4620..55269f4620 100644
--- a/src/armnn/TypeUtils.hpp
+++ b/src/armnn/ResolveType.hpp
diff --git a/src/armnn/TypesUtils.cpp b/src/armnn/TypesUtils.cpp
new file mode 100644
index 0000000000..cdc30da8ca
--- /dev/null
+++ b/src/armnn/TypesUtils.cpp
@@ -0,0 +1,58 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#include <armnn/TypesUtils.hpp>
+
+#include <boost/assert.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+
+template<typename QuantizedType>
+QuantizedType armnn::Quantize(float value, float scale, int32_t offset)
+{
+ static_assert(IsQuantizedType<QuantizedType>(), "Not an integer type.");
+ constexpr QuantizedType max = std::numeric_limits<QuantizedType>::max();
+ constexpr QuantizedType min = std::numeric_limits<QuantizedType>::lowest();
+ BOOST_ASSERT(scale != 0.f);
+ BOOST_ASSERT(!std::isnan(value));
+
+ float clampedValue = std::min(std::max(static_cast<float>(round(value/scale) + offset), static_cast<float>(min)),
+ static_cast<float>(max));
+ auto quantizedBits = static_cast<QuantizedType>(clampedValue);
+
+ return quantizedBits;
+}
+
+template <typename QuantizedType>
+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));
+ float dequantized = boost::numeric_cast<float>(value - offset) * scale;
+ return dequantized;
+}
+
+/// Explicit specialization of Quantize for uint8_t
+template
+uint8_t armnn::Quantize<uint8_t>(float value, float scale, int32_t offset);
+
+/// Explicit specialization of Quantize for int16_t
+template
+int16_t armnn::Quantize<int16_t>(float value, float scale, int32_t offset);
+
+/// Explicit specialization of Quantize for int32_t
+template
+int32_t armnn::Quantize<int32_t>(float value, float scale, int32_t offset);
+
+/// Explicit specialization of Dequantize for uint8_t
+template
+float armnn::Dequantize<uint8_t>(uint8_t value, float scale, int32_t offset);
+
+/// Explicit specialization of Dequantize for int16_t
+template
+float armnn::Dequantize<int16_t>(int16_t value, float scale, int32_t offset);
+
+/// Explicit specialization of Dequantize for int32_t
+template
+float armnn::Dequantize<int32_t>(int32_t value, float scale, int32_t offset); \ No newline at end of file
diff --git a/src/armnn/test/CreateWorkload.hpp b/src/armnn/test/CreateWorkload.hpp
index acc5cbdb1a..bdec766067 100644
--- a/src/armnn/test/CreateWorkload.hpp
+++ b/src/armnn/test/CreateWorkload.hpp
@@ -15,7 +15,7 @@
#include <Graph.hpp>
#include <DataLayoutIndexed.hpp>
#include <Network.hpp>
-#include <TypeUtils.hpp>
+#include <ResolveType.hpp>
#include <utility>
diff --git a/src/armnn/test/UtilsTests.cpp b/src/armnn/test/UtilsTests.cpp
index c81a4b67b6..0fa67e5f2a 100644
--- a/src/armnn/test/UtilsTests.cpp
+++ b/src/armnn/test/UtilsTests.cpp
@@ -11,7 +11,7 @@
#include <armnn/Descriptors.hpp>
#include <GraphTopologicalSort.hpp>
#include <Graph.hpp>
-#include "TypeUtils.hpp"
+#include <ResolveType.hpp>
BOOST_AUTO_TEST_SUITE(Utils)