2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "kernels/Pow.h"
18 #include "kernels/Utils.h"
20 #include <tensorflow/lite/kernels/internal/reference/reference_ops.h>
22 namespace luci_interpreter
27 Pow::Pow(const Tensor *input1, const Tensor *input2, Tensor *output)
28 : Kernel({input1, input2}, {output})
34 LUCI_INTERPRETER_CHECK(input1()->element_type() == input2()->element_type());
35 LUCI_INTERPRETER_CHECK(input1()->element_type() == output()->element_type());
36 // TODO: enable it only if kernel with dynamic shapes
37 output()->resize(calculateShapeForBroadcast(input1()->shape(), input2()->shape()));
40 void Pow::execute() const
42 switch (input1()->element_type())
44 case DataType::FLOAT32:
51 assert(false && "Unsupported type.");
55 template <typename T> void Pow::eval() const
57 tflite::ArithmeticParams params{};
59 const bool need_broadcast = tflite::reference_ops::ProcessBroadcastShapes(
60 getTensorShape(input1()), getTensorShape(input2()), ¶ms);
64 tflite::reference_ops::BroadcastPow4DSlow(getTensorShape(input1()), getTensorData<T>(input1()),
65 getTensorShape(input2()), getTensorData<T>(input2()),
66 getTensorShape(output()), getTensorData<T>(output()));
70 tflite::reference_ops::Pow(getTensorShape(input1()), getTensorData<T>(input1()),
71 getTensorShape(input2()), getTensorData<T>(input2()),
72 getTensorShape(output()), getTensorData<T>(output()));
76 } // namespace kernels
77 } // namespace luci_interpreter