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 extensions.middle.TensorIteratorOutput import SmartOutputMatcher
21 from mo.utils.unittest.graph import build_graph_with_attrs, compare_graphs
24 class SmartOutputMatcherTests(unittest.TestCase):
26 pattern_matcher = SmartOutputMatcher()
27 pattern = pattern_matcher.pattern()
29 graph = build_graph_with_attrs(nodes_with_attrs=pattern['nodes'], edges_with_attrs=pattern['edges'],
30 # update_edge_attrs=None,
31 new_nodes_with_attrs=[('index', {'kind': 'data'}),
32 ('value', {'kind': 'data'}),
33 ('ta_size', {'kind': 'data'}),
35 new_edges_with_attrs=[('index', 'TensorArrayWrite', {'in':1}),
36 ('value', 'TensorArrayWrite', {'in': 2}),
37 ('ta_size', 'TensorArray')
39 update_nodes_attributes=[('WriteEnter_data', {'value': np.array([1, 1])}),
41 ('start_data', {'value': np.array([0])}),
42 ('delta_data', {'value': np.array([1])}),
45 pattern_matcher.find_and_replace_pattern(graph)
47 graph_ref = build_graph_with_attrs(
49 ('TensorIteratorOutput', {'kind': 'op', 'op': 'TensorIteratorOutput'}),
50 ('TensorArrayGather_data', {'kind': 'data'}),
51 ('index', {'kind': 'data'}),
52 ('value', {'kind': 'data'}),
53 ('ta_size', {'kind': 'data'}), ],
54 edges_with_attrs=[('ta_size', 'TensorIteratorOutput', {'in': 0}),
55 ('index', 'TensorIteratorOutput', {'in': 2}),
56 ('value', 'TensorIteratorOutput', {'in': 1}),
57 ('TensorIteratorOutput', 'TensorArrayGather_data')],
58 update_edge_attrs=None,
59 new_nodes_with_attrs=[],
60 new_edges_with_attrs=[],
62 (flag, resp) = compare_graphs(graph, graph_ref, 'TensorArrayGather_data', check_op_attrs=True)
63 self.assertTrue(flag, resp)