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.
21 from generator import generator, generate
23 from mo.graph.graph import Node
24 from mo.ops.permute import Permute
25 from mo.utils.unittest.graph import build_graph
29 class TestPermuteOp(unittest.TestCase):
33 'shape': np.array([1, 3, 224, 224])
38 'reverse_order': False,
47 def _create_graph_with_transpose(self, order):
48 graph = build_graph(self.nodes_attributes,
49 [('data_1', 'transpose'),
50 ('transpose', 'data_2')],
51 {'transpose': {'order': order}})
54 @generate(*[list(order) for order in list(itertools.permutations(np.arange(4)))])
55 def test_transpose_infer_1(self, order):
56 graph = self._create_graph_with_transpose(order)
57 transpose_node = Node(graph, 'transpose')
59 Permute.infer(transpose_node)
61 ref = [transpose_node.in_node().shape[i] for i in order]
62 self.assertTrue(np.array_equal(transpose_node.out_node().shape, np.array(ref)))
64 def test_transpose_infer_2(self):
66 graph = self._create_graph_with_transpose(order)
67 transpose_node = Node(graph, 'transpose')
68 transpose_node['reverse_order'] = True
70 Permute.infer(transpose_node)
72 ref = np.array([x for x in reversed(transpose_node.in_node().shape)])
73 self.assertTrue(np.array_equal(transpose_node.out_node().shape, ref),
74 "Shapes are not the same: {} and {}".format(transpose_node.out_node().shape, ref))
76 def test_transpose_infer_neg_1(self):
77 order = np.array([0, 1, 2, 3])
78 graph = self._create_graph_with_transpose(order)
79 transpose_node = Node(graph, 'transpose')
80 transpose_node['reverse_order'] = True
82 Permute.infer(transpose_node)
85 self.assertTrue(transpose_node.out_node().shape is None, "Output shape should be None")
87 def test_transpose_infer_neg_2(self):
89 graph = self._create_graph_with_transpose(order)
90 transpose_node = Node(graph, 'transpose')
91 transpose_node['reverse_order'] = False
93 Permute.infer(transpose_node)
96 self.assertTrue(transpose_node.out_node().shape is None, "Output shape should be None")