blob: 637aa17013bdafd8595015635b0e1800183eead6 [file] [log] [blame]
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ArgMinMax.hpp"
7
Matteo Martincighe011d202019-11-28 11:35:47 +00008#include <armnnUtils/TensorUtils.hpp>
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +01009
10#include <boost/numeric/conversion/cast.hpp>
11
12namespace armnn
13{
14
15void ArgMinMax(Decoder<float>& in, int32_t* out, const TensorInfo& inputTensorInfo,
16 const TensorInfo& outputTensorInfo, ArgMinMaxFunction function, int axis)
17{
Jan Eilers8eb25602020-03-09 12:13:48 +000018 IgnoreUnused(outputTensorInfo);
Derek Lamberti901ea112019-12-10 22:07:09 +000019
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010020 unsigned int uAxis = armnnUtils::GetUnsignedAxis(inputTensorInfo.GetNumDimensions(), axis);
21
22 const unsigned int outerElements = armnnUtils::GetNumElementsBetween(inputTensorInfo.GetShape(), 0, uAxis);
23 const unsigned int axisSize = inputTensorInfo.GetShape()[uAxis];
24 const unsigned int innerElements = armnnUtils::GetNumElementsBetween(inputTensorInfo.GetShape(),
25 uAxis + 1,
26 inputTensorInfo.GetNumDimensions());
27
28 for (unsigned int outer = 0; outer < outerElements; ++outer) {
29 for (unsigned int inner = 0; inner < innerElements; ++inner) {
30 in[outer * axisSize * innerElements + inner];
31 auto tmpValue = in.Get();
32 unsigned int tmpIndex = 0;
33 for (unsigned int i = 1; i < axisSize; ++i) {
34 in[(outer * axisSize * innerElements) + (i * innerElements) + inner];
35 const auto& value = in.Get();
36 if ((function == armnn::ArgMinMaxFunction::Min && value < tmpValue) ||
37 (function == armnn::ArgMinMaxFunction::Max && value > tmpValue)) {
38 tmpValue = value;
39 tmpIndex = i;
40 }
41 }
42 out[outer * innerElements + inner] = boost::numeric_cast<int32_t>(tmpIndex);
43 }
44 }
45}
46
47} //namespace armnn