diff options
Diffstat (limited to 'src/armnnUtils')
-rw-r--r-- | src/armnnUtils/TensorUtils.cpp | 28 | ||||
-rw-r--r-- | src/armnnUtils/TensorUtils.hpp | 2 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/armnnUtils/TensorUtils.cpp b/src/armnnUtils/TensorUtils.cpp index 57f823fe13..c2fbbe0bcc 100644 --- a/src/armnnUtils/TensorUtils.cpp +++ b/src/armnnUtils/TensorUtils.cpp @@ -4,6 +4,7 @@ // #include "TensorUtils.hpp" +#include <backendsCommon/ITensorHandle.hpp> namespace armnnUtils { @@ -47,4 +48,31 @@ armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, } } +std::pair<float, float> FindMinMax(armnn::ITensorHandle* tensorHandle) +{ + auto tensor_data = static_cast<const float *>(tensorHandle->Map(true)); + auto tensor_size = tensorHandle->GetShape().GetNumElements(); + + // Set min/max initially to first value in tensor + float min = tensor_data[0]; + float max = tensor_data[0]; + + // Loop over rest of tensor and update min/max if necessary + for (unsigned int val = 1; val < tensor_size; val++) + { + if (tensor_data[val] < min) + { + min = tensor_data[val]; + } + else if (tensor_data[val] > max) + { + max = tensor_data[val]; + } + } + + tensorHandle->Unmap(); + + return std::make_pair(min, max); +} + } diff --git a/src/armnnUtils/TensorUtils.hpp b/src/armnnUtils/TensorUtils.hpp index fb5e6eb10d..c273b497b3 100644 --- a/src/armnnUtils/TensorUtils.hpp +++ b/src/armnnUtils/TensorUtils.hpp @@ -22,4 +22,6 @@ armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, const armnn::DataLayout dataLayout, const armnn::DataType dataType); +std::pair<float, float> FindMinMax(armnn::ITensorHandle* tensorHandle); + } // namespace armnnUtils |