ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PALSelectV2.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef LUCI_INTERPRETER_PAL_SELECT_V2_COMMON_H
18#define LUCI_INTERPRETER_PAL_SELECT_V2_COMMON_H
19
20#include "PALUtils.h"
22
24{
25
26template <typename D, typename T>
27void Select(const luci_interpreter::RuntimeShape &input_condition_shape,
28 const D *input_condition_data, const luci_interpreter::RuntimeShape &input_x_shape,
29 const T *input_x_data, const luci_interpreter::RuntimeShape &input_y_shape,
30 const T *input_y_data, const luci_interpreter::RuntimeShape &output_shape,
31 T *output_data)
32{
33 int64_t flatsize;
34 // Allow select operator executions on mixed scalar tensors and one element
35 // tensors.
36 if (input_condition_shape.flatSize() == 1 && input_x_shape.flatSize() == 1 &&
37 input_y_shape.flatSize() == 1 && output_shape.flatSize() == 1)
38 {
39 flatsize = 1;
40 }
41 else
42 {
43 flatsize = input_condition_shape.flatSize();
44 }
45 for (int64_t i = 0; i < flatsize; ++i)
46 {
47 output_data[i] = input_condition_data[i] ? input_x_data[i] : input_y_data[i];
48 }
49}
50
51} // namespace luci_interpreter_pal
52
53#endif // LUCI_INTERPRETER_PAL_SELECT_V2_COMMON_H
const luci_interpreter::RuntimeShape output_shape
void Select(const luci_interpreter::RuntimeShape &input_condition_shape, const D *input_condition_data, const luci_interpreter::RuntimeShape &input_x_shape, const T *input_x_data, const luci_interpreter::RuntimeShape &input_y_shape, const T *input_y_data, const luci_interpreter::RuntimeShape &output_shape, T *output_data)
Definition PALSelectV2.h:27