2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2018 The TensorFlow Authors. All Rights Reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef __NNFW_CKER_ELEMENTWISE_H__
19 #define __NNFW_CKER_ELEMENTWISE_H__
21 #include "cker/eigen/Utils.h"
22 #include "cker/Shape.h"
23 #include "cker/Types.h"
31 inline void Sin(const Shape &input_shape, const float *input_data, const Shape &output_shape,
34 const int size = MatchingFlatSize(input_shape, output_shape);
35 for (int i = 0; i < size; i++)
37 output_data[i] = std::sin(input_data[i]);
41 inline void Cos(const Shape &input_shape, const float *input_data, const Shape &output_shape,
44 const int size = MatchingFlatSize(input_shape, output_shape);
45 for (int i = 0; i < size; i++)
47 output_data[i] = std::cos(input_data[i]);
51 inline void Abs(const Shape &input_shape, const float *input_data, const Shape &output_shape,
54 auto input_map = MapAsVector(input_data, input_shape);
55 auto output_map = MapAsVector(output_data, output_shape);
56 output_map.array() = input_map.array().abs();
59 inline void Rsqrt(const Shape &input_shape, const float *input_data, const Shape &output_shape,
62 const int size = MatchingFlatSize(input_shape, output_shape);
63 for (int i = 0; i < size; i++)
65 output_data[i] = 1.f / std::sqrt(input_data[i]);
70 inline void Neg(const Shape &input_shape, const T *input_data, const Shape &output_shape,
73 const int size = MatchingFlatSize(input_shape, output_shape);
74 for (int i = 0; i < size; i++)
76 output_data[i] = -input_data[i];
80 inline void Log(const Shape &input_shape, const float *input_data, const Shape &output_shape,
83 const int size = MatchingFlatSize(input_shape, output_shape);
84 for (int i = 0; i < size; i++)
86 output_data[i] = std::log(input_data[i]);
90 inline void Floor(const Shape &input_shape, const float *input_data, const Shape &output_shape,
93 const int flat_size = MatchingFlatSize(input_shape, output_shape);
95 for (int i = 0; i < flat_size; i++)
97 output_data[i] = std::floor(input_data[i]);
104 #endif // __NNFW_CKER_ELEMENTWISE_H__