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 extensions.ops.gather import Gather
22 from mo.front.common.partial_infer.utils import int64_array
23 from mo.graph.graph import Node
24 from mo.utils.unittest.graph import build_graph
27 class TestGatherPartialInfer(unittest.TestCase):
30 nodes_attributes = {'gather_input': {'shape': None, 'value': None, 'kind': 'data'},
31 'gather_input2': {'shape': None, 'value': None, 'kind': 'data'},
32 'gather_node': {'op': 'Gather', 'kind': 'op'},
33 'gather_output': {'shape': None, 'value': None, 'kind': 'data'}
35 return build_graph(nodes_attributes,
37 ('gather_input', 'gather_node'), ('gather_node', 'gather_output'), ('gather_input2', 'gather_node')
40 'gather_input': {'shape': int64_array([10, 15]), 'value': np.ones((3, 15))},
41 'gather_input2': {'shape': int64_array([2]), 'value': np.array([0, 2])},
42 'gather_node': {'axis': 0},
45 def test_gather_infer(self):
46 graph = self._create_graph()
48 gather_node = Node(graph, 'gather_node')
49 Gather.infer(gather_node)
51 exp_shape = int64_array([2, 15])
52 res_shape = graph.node['gather_output']['shape']
53 res_value = graph.node['gather_output']['value']
55 self.assertTrue(np.array_equal(exp_shape, res_shape),
56 'shapes do not match expected: {} and given: {}'.format(exp_shape, res_shape))
58 self.assertTrue(np.array_equal(res_value, np.ones(exp_shape)),
59 'shapes do not match expected: {} and given: {}'.format(exp_shape, res_shape))