ONE - On-device Neural Engine
Loading...
Searching...
No Matches
LogicalOr.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_LOGICAL_OR_H__
19#define __NNFW_CKER_LOGICAL_OR_H__
20
21#include "cker/Shape.h"
22#include "cker/Utils.h"
23
24namespace nnfw
25{
26namespace cker
27{
28
29template <typename T>
30inline void LogicalOrBroadcast(const Shape &unextended_input1_shape, const T *input1_data,
31 const Shape &unextended_input2_shape, const T *input2_data,
32 const Shape &unextended_output_shape, T *output_data)
33{
34 assert(unextended_input1_shape.DimensionsCount() <= 4);
35 assert(unextended_input2_shape.DimensionsCount() <= 4);
36 assert(unextended_output_shape.DimensionsCount() <= 4);
37 const Shape output_shape = Shape::ExtendedShape(4, unextended_output_shape);
38
41 NdArrayDescsForElementwiseBroadcast(unextended_input1_shape, unextended_input2_shape, &desc1,
42 &desc2);
43
44 for (int b = 0; b < output_shape.Dims(0); ++b)
45 {
46 for (int y = 0; y < output_shape.Dims(1); ++y)
47 {
48 for (int x = 0; x < output_shape.Dims(2); ++x)
49 {
50 for (int c = 0; c < output_shape.Dims(3); ++c)
51 {
52 auto out_idx = Offset(output_shape, b, y, x, c);
53 auto in1_idx = SubscriptToIndex(desc1, b, y, x, c);
54 auto in2_idx = SubscriptToIndex(desc2, b, y, x, c);
55 auto in1_val = input1_data[in1_idx];
56 auto in2_val = input2_data[in2_idx];
57 output_data[out_idx] = in1_val || in2_val;
58 }
59 }
60 }
61 }
62}
63
64template <typename T>
65inline void LogicalOrElementwise(const Shape &shape, const T *input1_data, const T *input2_data,
66 T *output_data)
67{
68
69 int num_elements = shape.FlatSize();
70
71 for (int t = 0; t < num_elements; t++)
72 {
73 output_data[t] = input1_data[t] || input2_data[t];
74 }
75}
76
77} // namespace cker
78} // namespace nnfw
79
80#endif // __NNFW_CKER_LOGICAL_OR_H___
int32_t DimensionsCount() const
Definition Shape.h:91
int FlatSize() const
Definition Shape.h:181
NdArrayDesc< 4 > desc1
const luci_interpreter::RuntimeShape output_shape
NdArrayDesc< 4 > desc2
int Offset(const Shape &shape, int i0, int i1, int i2, int i3)
Definition Shape.h:237
void LogicalOrBroadcast(const Shape &unextended_input1_shape, const T *input1_data, const Shape &unextended_input2_shape, const T *input2_data, const Shape &unextended_output_shape, T *output_data)
Definition LogicalOr.h:30
void NdArrayDescsForElementwiseBroadcast(const Shape &input0_shape, const Shape &input1_shape, NdArrayDesc< N > *desc0_out, NdArrayDesc< N > *desc1_out)
Definition Utils.h:290
void LogicalOrElementwise(const Shape &shape, const T *input1_data, const T *input2_data, T *output_data)
Definition LogicalOr.h:65
int SubscriptToIndex(const NdArrayDesc< 4 > &desc, int i0, int i1, int i2, int i3)
Definition Utils.h:255
Definition topk_v2.h:30