2 Copyright (c) 2018-2019 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.
19 from mo.front.common.partial_infer.utils import int64_array
20 from mo.graph.graph import Node, Graph
21 from mo.ops.op import Op
27 def __init__(self, graph: Graph, attrs: dict):
30 'infer': __class__.merge_infer
32 super().__init__(graph, mandatory_props, attrs)
35 def merge_infer(node: Node):
36 # we infer only through executable input nodes
37 inferred_nodes = [n for n in node.in_nodes().values() if n['is_partial_inferred']]
38 assert len(inferred_nodes) != 0
40 if len(inferred_nodes) < len(node.in_nodes()):
41 node['is_not_fully_inferred'] = True
43 node['is_not_fully_inferred'] = False
44 assert np.all(node.shape == inferred_nodes[0].shape for node in inferred_nodes)
46 inferred_and_executable = [n for n in node.in_nodes().values() if n['is_partial_inferred'] and
47 'executable' in n and n['executable']]
48 tensor = inferred_and_executable[0]
50 if all([np.all(tensor.value == n.value) for n in inferred_and_executable]):
51 node.out_node().value = tensor.value.copy() if tensor.has_valid('value') else None
53 tensor = inferred_nodes[0]
54 node.out_node().shape = int64_array(tensor.shape)