Files
openvino/model-optimizer/extensions/ops/gatherelements_test.py
T
Pavel Esir d2a23680f2 nGraph 'shell' implementation for GatherElements-6 and MO 'shell' implementation (#3467)
* Initial support of GatherElements in MO and nGraph

* apply_style

* added lost extractor for GatherElements

* Corrected GatherElements::validate_and_infer_types

* updated package_BOM.txt

* Type_t added

* started to implement ngraph shape_type_infer unit-tests

* finally implemented all ngraph shape_inference unit-tests

* updated Supported_Frameworks_Layers.md

* added correct handling of dynamic shapes in nGraph, added unit-tests for dynamic cases, fixed dump typos in MO, replaced axis type from int -> int64_t

* implemented shape infer for dynamic shapes with intervals

* finalized MO implementation

* applied comment from review

* style-apply

* spec correction

* removed conflict

* fixed typos

* removed obsolete comments form type_prop

* significant corrections in validate_and_infer_types

* style-apply

* data_rank check for axis
2020-12-21 15:45:15 +03:00

116 lines
3.1 KiB
Python

"""
Copyright (C) 2017-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import unittest
import numpy as np
from generator import generator, generate
from extensions.ops.gatherelements import GatherElements
from mo.front.common.partial_infer.utils import int64_array
from mo.graph.graph import Node
from mo.utils.unittest.graph import build_graph, regular_op_with_empty_data, result, connect, \
valued_const_with_data
@generator
class GatherElementsInferTest(unittest.TestCase):
@generate(*[
([[1, 2],
[3, 4]],
[[0, 1],
[0, 0]],
0, # axis
[[1, 4], # ref_res
[1, 2]]),
([[1, 2],
[3, 4]],
[[0, 1],
[0, 0]],
1, # axis
[[1, 2], # ref_res
[3, 3]]),
([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]],
[[1, 2, 0],
[2, 0, 0]],
0, # axis
[[4, 8, 3], # ref_res
[7, 2, 3]]),
([[1, 2],
[3, 4]],
[[0, 1],
[0, 0]],
-1, # axis
[[1, 2], # ref_res
[3, 3]]),
([ # 3D case
[[1, 2],
[3, 4]],
[[5, 6],
[7, 8]],
[[9, 10],
[11, 12]]
],
[
[[1, 0],
[0, 1]],
[[1, 1],
[1, 0]],
[[0, 0],
[1, 1]]
],
-1, # axis
[
[[2, 1],
[3, 4]],
[[6, 6],
[8, 7]],
[[9, 9],
[12, 12]]
]),
])
def test_gatherelements_value_infer(self, data, indices, axis, ref_res):
nodes = {
**valued_const_with_data('data', int64_array(data)),
**valued_const_with_data('indices', int64_array(indices)),
**regular_op_with_empty_data('gather_elements', {'op': 'GatherElements', 'axis': axis}),
**result()
}
graph = build_graph(nodes_attrs=nodes, edges=[
*connect('data', '0:gather_elements'),
*connect('indices', '1:gather_elements'),
*connect('gather_elements', 'output')
], nodes_with_edges_only=True)
graph.stage = 'middle'
gather_el_node = Node(graph, 'gather_elements')
GatherElements.infer(gather_el_node)
res_output_shape = gather_el_node.out_node().shape
self.assertTrue(np.array_equal(int64_array(ref_res).shape, res_output_shape))
res_output_value = gather_el_node.out_node().value
if res_output_value is not None:
self.assertTrue(np.array_equal(int64_array(ref_res), res_output_value))