blob: 3bf2853a20f430e94981a69322b14957238ec2a7 [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
Matthew Sloyan171214c2020-09-09 09:07:37 +010010#include <armnn/utility/NumericCast.hpp>
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010011
12namespace armnn
13{
14
Inki Daed4619e22020-09-10 15:33:54 +090015template <typename OUT>
16void ArgMinMax(Decoder<float>& in, OUT* out, const TensorInfo& inputTensorInfo,
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010017 const TensorInfo& outputTensorInfo, ArgMinMaxFunction function, int axis)
18{
Jan Eilers8eb25602020-03-09 12:13:48 +000019 IgnoreUnused(outputTensorInfo);
Derek Lamberti901ea112019-12-10 22:07:09 +000020
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010021 unsigned int uAxis = armnnUtils::GetUnsignedAxis(inputTensorInfo.GetNumDimensions(), axis);
22
23 const unsigned int outerElements = armnnUtils::GetNumElementsBetween(inputTensorInfo.GetShape(), 0, uAxis);
24 const unsigned int axisSize = inputTensorInfo.GetShape()[uAxis];
25 const unsigned int innerElements = armnnUtils::GetNumElementsBetween(inputTensorInfo.GetShape(),
26 uAxis + 1,
27 inputTensorInfo.GetNumDimensions());
28
29 for (unsigned int outer = 0; outer < outerElements; ++outer) {
30 for (unsigned int inner = 0; inner < innerElements; ++inner) {
31 in[outer * axisSize * innerElements + inner];
32 auto tmpValue = in.Get();
33 unsigned int tmpIndex = 0;
34 for (unsigned int i = 1; i < axisSize; ++i) {
35 in[(outer * axisSize * innerElements) + (i * innerElements) + inner];
36 const auto& value = in.Get();
37 if ((function == armnn::ArgMinMaxFunction::Min && value < tmpValue) ||
38 (function == armnn::ArgMinMaxFunction::Max && value > tmpValue)) {
39 tmpValue = value;
40 tmpIndex = i;
41 }
42 }
Inki Daed4619e22020-09-10 15:33:54 +090043
44 out[outer * innerElements + inner] = armnn::numeric_cast<OUT>(tmpIndex);
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010045 }
46 }
47}
48
Inki Daed4619e22020-09-10 15:33:54 +090049template void ArgMinMax(Decoder<float>& in, int32_t* out, const TensorInfo& inputTensorInfo,
50 const TensorInfo& outputTensorInfo, ArgMinMaxFunction function, int axis);
51
52template void ArgMinMax(Decoder<float>& in, int64_t* out, const TensorInfo& inputTensorInfo,
53 const TensorInfo& outputTensorInfo, ArgMinMaxFunction function, int axis);
54
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010055} //namespace armnn