Add a section of how to link IE with CMake project (#99)
[platform/upstream/dldt.git] / model-optimizer / mo / ops / div.py
1 """
2  Copyright (c) 2018 Intel Corporation
3
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
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
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.
15 """
16
17 import numpy as np
18 import networkx as nx
19
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
24
25
26 class Div(FrontReplacementOp):
27     op = "Div"
28     enabled = True
29
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_'))
33
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'])])
36                                    ])
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)])
39         return [out_node.id]