2 * Copyright (c) 2019 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 "Reciprocal.h"
19 #include "ONNXHelpers.h"
21 #include "mir/ops/ConstantOp.h"
22 #include "mir/ops/DivOp.h"
27 static void convertReciprocal(const onnx::NodeProto &onnx_node, ConverterContext *context)
29 std::vector<mir::Operation::Output *> inputs = context->getNodeInputs(onnx_node);
30 mir::Graph *graph = context->getGraph();
32 assert(inputs.size() == 1);
33 auto input = inputs[0];
35 const float one_value = 1.0f;
36 mir::TensorVariant one_tensor({mir::DataType::FLOAT32, {}}, &one_value);
37 auto one = createOp<mir::ops::ConstantOp>(graph, one_tensor)->getOutput(0);
38 auto result = createOp<mir::ops::DivOp>(graph, input, one)->getOutput(0);
40 context->setNodeOutputs(onnx_node, {result});
43 void convertReciprocalV1(const onnx::NodeProto &onnx_node, ConverterContext *context)
45 convertReciprocal(onnx_node, context);
48 void convertReciprocalV6(const onnx::NodeProto &onnx_node, ConverterContext *context)
50 convertReciprocal(onnx_node, context);
53 } // namespace mir_onnx