blob: abc0512021a3f7a37bef5bc354f947180402bce4 [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
Teresa Charlin5306dc82023-10-30 22:29:58 +000010#include <armnn/utility/IgnoreUnused.hpp>
Matthew Sloyan171214c2020-09-09 09:07:37 +010011#include <armnn/utility/NumericCast.hpp>
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010012
13namespace armnn
14{
15
Inki Daed4619e22020-09-10 15:33:54 +090016template <typename OUT>
17void ArgMinMax(Decoder<float>& in, OUT* out, const TensorInfo& inputTensorInfo,
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010018 const TensorInfo& outputTensorInfo, ArgMinMaxFunction function, int axis)
19{
Jan Eilers8eb25602020-03-09 12:13:48 +000020 IgnoreUnused(outputTensorInfo);
Derek Lamberti901ea112019-12-10 22:07:09 +000021
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010022 unsigned int uAxis = armnnUtils::GetUnsignedAxis(inputTensorInfo.GetNumDimensions(), axis);
23
24 const unsigned int outerElements = armnnUtils::GetNumElementsBetween(inputTensorInfo.GetShape(), 0, uAxis);
25 const unsigned int axisSize = inputTensorInfo.GetShape()[uAxis];
26 const unsigned int innerElements = armnnUtils::GetNumElementsBetween(inputTensorInfo.GetShape(),
27 uAxis + 1,
28 inputTensorInfo.GetNumDimensions());
29
30 for (unsigned int outer = 0; outer < outerElements; ++outer) {
31 for (unsigned int inner = 0; inner < innerElements; ++inner) {
32 in[outer * axisSize * innerElements + inner];
33 auto tmpValue = in.Get();
34 unsigned int tmpIndex = 0;
35 for (unsigned int i = 1; i < axisSize; ++i) {
36 in[(outer * axisSize * innerElements) + (i * innerElements) + inner];
37 const auto& value = in.Get();
38 if ((function == armnn::ArgMinMaxFunction::Min && value < tmpValue) ||
39 (function == armnn::ArgMinMaxFunction::Max && value > tmpValue)) {
40 tmpValue = value;
41 tmpIndex = i;
42 }
43 }
Inki Daed4619e22020-09-10 15:33:54 +090044
45 out[outer * innerElements + inner] = armnn::numeric_cast<OUT>(tmpIndex);
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010046 }
47 }
48}
49
Inki Daed4619e22020-09-10 15:33:54 +090050template void ArgMinMax(Decoder<float>& in, int32_t* out, const TensorInfo& inputTensorInfo,
51 const TensorInfo& outputTensorInfo, ArgMinMaxFunction function, int axis);
52
53template void ArgMinMax(Decoder<float>& in, int64_t* out, const TensorInfo& inputTensorInfo,
54 const TensorInfo& outputTensorInfo, ArgMinMaxFunction function, int axis);
55
Narumol Prangnawarat4dc64a62019-09-16 17:00:22 +010056} //namespace armnn