Add a section of how to link IE with CMake project (#99)
[platform/upstream/dldt.git] / model-optimizer / extensions / front / div.py
1 """
2  Copyright (c) 2018-2019 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
19 from mo.front.common.replacement import FrontReplacementOp
20 from mo.graph.graph import Node, Graph
21 from mo.ops.eltwise import Eltwise
22 from mo.ops.power import Power
23
24
25 class Div(FrontReplacementOp):
26     op = "Div"
27     enabled = True
28
29     def replace_op(self, graph: Graph, node: Node):
30         reciprocal = Power(graph, {'scale': 1, 'power': np.float64(-1), 'shift': 0,
31                                    'name': node.name + '/reciprocal_'}).create_node()
32         mul = Eltwise(graph, {'operation': 'mul', 'name': node.name + '/mul_'}).create_node()
33
34         # Connect nodes
35         node.in_port(1).get_connection().set_destination(reciprocal.in_port(0))
36         node.in_port(0).get_connection().set_destination(mul.in_port(1))
37         reciprocal.out_port(0).connect(mul.in_port(0))
38
39         # The "explicit" version of the return value is: [(out_node.id, 0)])
40         return [mul.id]