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.
16 from mo.middle.replacement import MiddleReplacementPattern
18 next_ops = ['NextIteration', 'TensorArrayWriteV3']
21 class DeleteSelect(MiddleReplacementPattern):
23 graph_condition = [lambda graph: graph.graph['is_cyclic']]
26 from extensions.middle.AddIsCyclicAttribute import AddIsCyclicAttribute
27 return [AddIsCyclicAttribute]
36 ('Select', dict(kind='op', op='Select')),
37 ('Select_data', dict(kind='data')),
39 ('next_op', dict(kind='op')),
42 ('Select', 'Select_data'),
43 ('Select_data', 'next_op'),
48 def replace_pattern(graph, match: dict):
49 if match['next_op']['op'] not in next_ops:
51 select = match['Select']
52 assert len(select.in_nodes()) == 3
54 default = select.in_node(1)
55 input = select.in_node(2)
57 edge_attrs = graph.get_edge_data(match['Select_data'].id, match['next_op'].id)
58 graph.add_edges_from([(input.id, match['next_op'].id, edge_attrs[0])])
60 graph.remove_edge(input.id, select.id)
62 safe_nodes = ['next_op']
64 for node in match.keys():
65 if node not in safe_nodes:
66 nodes_for_remove.append(match[node].id)
67 graph.remove_nodes_from(nodes_for_remove)