2 Copyright (c) 2017-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.
22 from mo.graph.graph import Node, Graph
23 from mo.ops.op import Op
29 def __init__(self, graph: Graph, attrs: dict):
36 'infer': __class__.infer,
38 super().__init__(graph, mandatory_props, attrs)
40 def supported_attrs(self):
46 def infer(node: Node):
47 assert len(node.in_nodes()) == 2 or len(node.in_nodes()) == 3
49 # There may be three inputs in TensorFlow. The third input is axis
50 if len(node.in_nodes()) == 3:
51 if node.in_node(2).value is None:
52 log.error("Gather is supported only with constant axis value")
54 node.axis = node.in_node(2).value.item()
55 node.graph.remove_edge(node.in_node(2).id, node.id)
58 data = node.in_node(0)
59 indices = node.in_node(1)
61 # both inputs are constant
62 if data.value is not None and indices.value is not None:
63 node.out_node(0).value = np.take(data.value, indices.value, axis)
64 node.out_node(0).shape = np.array(node.out_node(0).value.shape, dtype=np.int64)
67 shape = np.concatenate((data.shape[:axis], indices.shape))
68 if axis < len(data.shape) - 1:
69 shape = np.concatenate((shape, data.shape[axis + 1:]))
71 node.out_node(0).shape = np.array(shape, dtype=np.int64)