ArmNN
 25.11
Loading...
Searching...
No Matches
ArgMinMax.cpp
Go to the documentation of this file.
1//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ArgMinMax.hpp"
7
9
12
13namespace armnn
14{
15
16template <typename OUT>
17void ArgMinMax(Decoder<float>& in, OUT* out, const TensorInfo& inputTensorInfo,
18 const TensorInfo& outputTensorInfo, ArgMinMaxFunction function, int axis)
19{
20 IgnoreUnused(outputTensorInfo);
21
22 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 }
44
45 out[outer * innerElements + inner] = armnn::numeric_cast<OUT>(tmpIndex);
46 }
47 }
48}
49
50template 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
56} //namespace armnn
virtual IType Get() const =0
const TensorShape & GetShape() const
Definition Tensor.hpp:193
unsigned int GetNumDimensions() const
Definition Tensor.hpp:197
Copyright (c) 2021 ARM Limited and Contributors.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
ArgMinMaxFunction
Definition Types.hpp:104
void IgnoreUnused(Ts &&...)
unsigned int GetUnsignedAxis(const unsigned int inputDimension, const int axis)
unsigned int GetNumElementsBetween(const armnn::TensorShape &shape, unsigned int firstAxisInclusive, unsigned int lastAxisExclusive)