diff options
Diffstat (limited to 'src/armnnUtils/TensorUtils.cpp')
-rw-r--r-- | src/armnnUtils/TensorUtils.cpp | 28 |
1 files changed, 28 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); +} + } |