ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Sin.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2018 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#include "kernels/Sin.h"
19
20#include "kernels/Utils.h"
21
22#include <cmath>
23
24namespace luci_interpreter
25{
26namespace kernels
27{
28
29namespace
30{
31
32template <typename T>
33inline void CalcSin(const T *input_data, const size_t num_elements, T *output_data)
34{
35 for (size_t idx = 0; idx < num_elements; ++idx)
36 {
37 output_data[idx] = std::sin(input_data[idx]);
38 }
39}
40
41} // namespace
42
43Sin::Sin(const Tensor *input, Tensor *output) : Kernel({input}, {output}) {}
44
46{
47 LUCI_INTERPRETER_CHECK(input()->element_type() == DataType::FLOAT32);
48 LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type());
49 output()->resize(input()->shape());
50}
51
52void Sin::execute() const
53{
54 switch (input()->element_type())
55 {
56 case DataType::FLOAT32:
57 evalFloat();
58 break;
59 default:
60 throw std::runtime_error("luci-intp Sin Unsupported type.");
61 }
62}
63
64void Sin::evalFloat() const
65{
66 const int size = tflite::MatchingFlatSize(getTensorShape(input()), getTensorShape(output()));
67 CalcSin(getTensorData<float>(input()), size, getTensorData<float>(output()));
68}
69
70} // namespace kernels
71} // namespace luci_interpreter
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
void configure() override
Definition Sin.cpp:45
void execute() const override
Definition Sin.cpp:52
Tensor * output() const
Definition Sin.h:34
const Tensor * input() const
Definition Sin.h:33
Sin(const Tensor *input, Tensor *output)
Definition Sin.cpp:43
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194
uint32_t num_elements(const Shape &shape)
The number of elements of a feature map of a given shape.
Definition Shape.h:59
int32_t size[5]
Definition Slice.cpp:35