2 Copyright (c) 2018 Intel Corporation
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.
20 from mo.front.common.replacement import FrontReplacementOp
21 from mo.graph.graph import Node
22 from mo.ops.eltwise import Eltwise
23 from mo.ops.power import Power
26 class Div(FrontReplacementOp):
30 def replace_op(self, graph: nx.MultiDiGraph, node: Node):
31 reciprocal = Power(graph, dict(scale=1, power=np.float64(-1), shift=0, name=node.name + '/reciprocal_'))
32 mul = Eltwise(graph, dict(operation='mul', name=node.name + '/mul_'))
34 out_node = mul.create_node([(node.in_node(0), node.in_edge(0)['out']),
35 reciprocal.create_node([(node.in_node(1), node.in_edge(1)['out'])])
37 # Replace edge from out port 0 of the matched node with a edge from node out_node.id with port 0.
38 # The "explicit" version of the return value is: [(out_node.id, 0)])