ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ArgMinMax.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef __NNFW_CKER_ARGMINMAX_H__
19#define __NNFW_CKER_ARGMINMAX_H__
20
21#include "cker/Shape.h"
22
23namespace nnfw
24{
25namespace cker
26{
27
28template <typename T1, typename T2, typename Cmp>
29void ArgMinMax(const Shape &input1_shape, const T1 *input1_data,
30 [[maybe_unused]] const Shape &output_shape, T2 *output_data, int32_t axis,
31 const Cmp &cmp)
32{
33 assert(input1_shape.DimensionsCount() > 0);
34 assert(input1_shape.DimensionsCount() - 1 == output_shape.DimensionsCount());
35 if (axis < 0)
36 {
37 axis += input1_shape.DimensionsCount();
38 }
39 const int axis_size = input1_shape.Dims(axis);
40
41 int outer_size = 1;
42 for (int i = 0; i < axis; ++i)
43 {
44 assert(input1_shape.Dims(i) == output_shape.Dims(i));
45 outer_size *= input1_shape.Dims(i);
46 }
47
48 int inner_size = 1;
49 const int dims_count = input1_shape.DimensionsCount();
50 for (int i = axis + 1; i < dims_count; ++i)
51 {
52 assert(input1_shape.Dims(i) == output_shape.Dims(i - 1));
53 inner_size *= input1_shape.Dims(i);
54 }
55 for (int outer = 0; outer < outer_size; ++outer)
56 {
57 for (int inner = 0; inner < inner_size; ++inner)
58 {
59 auto min_max_value = input1_data[outer * axis_size * inner_size + inner];
60 T2 min_max_index = 0;
61 for (int i = 1; i < axis_size; ++i)
62 {
63 const auto &curr_value = input1_data[(outer * axis_size + i) * inner_size + inner];
64 if (cmp(curr_value, min_max_value))
65 {
66 min_max_value = curr_value;
67 min_max_index = static_cast<T2>(i);
68 }
69 }
70 output_data[outer * inner_size + inner] = min_max_index;
71 }
72 }
73}
74
75} // namespace cker
76} // namespace nnfw
77
78#endif // __NNFW_CKER_ARGMINMAX_H__
int32_t DimensionsCount() const
Definition Shape.h:91
int32_t Dims(int i) const
Definition Shape.h:92
const luci_interpreter::RuntimeShape output_shape
void ArgMinMax(const Shape &input1_shape, const T1 *input1_data, const Shape &output_shape, T2 *output_data, int32_t axis, const Cmp &cmp)
Definition ArgMinMax.h:29
Definition topk_v2.h:30