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.
18 from extensions.front.kaldi.replace_splice_node_pattern import ReplaceSpliceNodePattern
19 from mo.graph.graph import Node
20 from mo.utils.unittest.graph import build_graph
23 class ReplaceSpliceNodePatternTests(unittest.TestCase):
26 cls.nodes_attributes = {
27 'in_node': {'kind': 'op', 'op': 'Input', 'shape': [1, 13]},
28 'slice': {'kind': 'op', 'op': 'Splice', 'context': range(-5, 5)}
30 cls.graph = build_graph(cls.nodes_attributes,
31 [('in_node', 'slice')])
33 ReplaceSpliceNodePattern().find_and_replace_pattern(cls.graph)
35 def test_memory(self):
36 memory_nodes = [node for node in self.graph.nodes(data=True) if node[1]['op'] == 'Memory']
37 self.assertEqual(len(memory_nodes), 2)
38 for memory_node in memory_nodes:
39 node = Node(self.graph, memory_node[0])
40 if len(node.in_nodes()):
41 self.assertEqual(node.index, 0)
42 elif len(node.out_nodes()):
43 self.assertEqual(node.index, 1)
44 self.assertEqual(memory_nodes[0][1]['id'], memory_nodes[1][1]['id'])
47 crop_node = [node for node in self.graph.nodes(data=True) if node[1]['op'] == 'Crop']
48 self.assertEqual(len(crop_node), 1)
49 crop_node = Node(self.graph, crop_node[0][0])
50 self.assertEqual(crop_node.offset, [13])
51 self.assertEqual(crop_node.dim, [13 * 9])
53 def test_concat(self):
54 concat_node = [node for node in self.graph.nodes(data=True) if node[1]['op'] == 'Concat']
55 self.assertEqual(len(concat_node), 1)
56 crop_node = Node(self.graph, concat_node[0][0])
57 self.assertEqual(crop_node.axis, 1)