2 Copyright (C) 2020 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.
19 from mo.front.common.partial_infer.utils import int64_array
20 from mo.graph.graph import Node, Graph
21 from mo.ops.op import Op
24 class LookupTableInsert(Op):
26 This operation has only output control flow edges and no output data edges in some models.
27 And for these cases implementation of the shape inference is needed since the shape inference is executed
28 before control flow edges resolving. This operation has non-tensor output so the output shape is empty.
31 op = 'LookupTableInsert'
33 def __init__(self, graph: Graph, attrs: dict):
41 super().__init__(graph, mandatory_props, attrs)
44 def infer(node: Node):
45 node_name = node.soft_get('name', node.id)
46 connected_in_ports = [port for port in node.in_ports().values() if not port.disconnected()]
47 assert len(connected_in_ports) == 3, \
48 "Incorrect number of inputs for {} node".format(node_name)
50 # check shapes of input tensors
51 keys_shape = node.in_port(1).data.get_shape()
52 values_shape = node.in_port(2).data.get_shape()
53 assert np.array_equal(keys_shape, values_shape), \
54 'Shapes of tensors with keys and values must be equal for {} node'.format(node_name)
56 # set output shape that must be empty
57 # since output is not a tensor
58 node.out_port(0).data.set_shape(int64_array([]))