From 6da95784c73b6616409bff73987783b6e2d3f7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Do=C5=82bniak?= Date: Tue, 6 Dec 2022 17:09:30 +0100 Subject: [PATCH] Unique-10 tests and improvements (#14315) --- .../src/transformations/convert_precision.cpp | 30 +- src/core/include/openvino/op/unique.hpp | 2 +- .../ngraph/runtime/reference/unique.hpp | 13 + .../template/backend/evaluates_map.cpp | 24 +- .../tests/functional/op_reference/unique.cpp | 330 ++++++++++-------- 5 files changed, 236 insertions(+), 163 deletions(-) diff --git a/src/common/transformations/src/transformations/convert_precision.cpp b/src/common/transformations/src/transformations/convert_precision.cpp index 4e8357cf858..06cfde3cb61 100644 --- a/src/common/transformations/src/transformations/convert_precision.cpp +++ b/src/common/transformations/src/transformations/convert_precision.cpp @@ -130,24 +130,24 @@ bool convert_precision(ov::pass::PassBase& pass, }; auto convert_node_output_precision = [&](const std::shared_ptr& node) { + bool res = false; + // Handle case with Constants as they can have consumers from other nGraph Function object + const auto constant = ov::as_type_ptr(node); + const auto it = const_to_internal_output.find(node.get()); + if (constant && constant->get_output_element_type(0) == from && it != const_to_internal_output.end()) { + return fuse_type_to_constant(node, to, it->second); + } + for (const auto& output : node->outputs()) { if (output.get_element_type() == from) { - // Handle case with Constants as they can have consumers from other nGraph - // Function object - auto it = const_to_internal_output.find(node.get()); - if (it != const_to_internal_output.end()) { - return fuse_type_to_constant(node, to, it->second); - } - // Check that node type exists in map and we can fuse type into node - auto t2f_it = type_to_fuse.find(node->get_type_info()); - if (t2f_it != type_to_fuse.end() && t2f_it->second(node, to, output.get_index())) { - // We need to break if original node was replaced - return true; + const auto t2f_it = type_to_fuse.find(node->get_type_info()); + if (t2f_it != type_to_fuse.end()) { + res |= t2f_it->second(node, to, output.get_index()); } } } - return false; + return res; }; auto convert_node_input_precision = [&](const std::shared_ptr& node) { @@ -347,17 +347,19 @@ bool fuse_type_to_random_uniform_v8(const std::shared_ptr& node, o } bool fuse_type_to_unique_v10(const std::shared_ptr& node, ov::element::Type to, size_t idx) { + bool res = false; if (auto unique = ov::as_type_ptr(node)) { if (to == ov::element::i32 || to == ov::element::i64) { if (idx == 1 || idx == 2) { unique->set_index_element_type(to); + res = true; } else if (idx == 3) { unique->set_count_element_type(to); + res = true; } } } - // No node replacement, so always return false - return false; + return res; } bool fuse_type_to_range_v4(const std::shared_ptr& node, ov::element::Type to, size_t idx) { diff --git a/src/core/include/openvino/op/unique.hpp b/src/core/include/openvino/op/unique.hpp index 7766e96d5b6..f65db31e06f 100644 --- a/src/core/include/openvino/op/unique.hpp +++ b/src/core/include/openvino/op/unique.hpp @@ -40,7 +40,7 @@ public: const Output& axis, const bool sorted = true, const element::Type& index_element_type = element::i64, - const element::Type& ount_element_type = element::i64); + const element::Type& count_element_type = element::i64); bool visit_attributes(AttributeVisitor& visitor) override; void validate_and_infer_types() override; diff --git a/src/core/reference/include/ngraph/runtime/reference/unique.hpp b/src/core/reference/include/ngraph/runtime/reference/unique.hpp index 9c5d4a8f1b3..56e562857c1 100644 --- a/src/core/reference/include/ngraph/runtime/reference/unique.hpp +++ b/src/core/reference/include/ngraph/runtime/reference/unique.hpp @@ -108,6 +108,11 @@ UniqueElements find_unique_elements(const Data_t* data, const auto data_shape_strides = ngraph::row_major_strides(data_shape); + if (axis && *axis < 0) { + const auto normalized_axis = *axis + data_shape.size(); + *axis = normalized_axis; + } + const auto ascending_order = [&data](const TensorSlice& lhs, const TensorSlice& rhs) { return *(data + lhs.idx) < *(data + rhs.idx); @@ -137,6 +142,10 @@ UniqueElements find_unique_elements(const Data_t* data, if (*(data + lhs_elem_idx) < *(data + rhs_elem_idx)) { return true; + } else if (*(data + lhs_elem_idx) > *(data + rhs_elem_idx)) { + return false; + } else { + continue; } } @@ -269,6 +278,10 @@ std::tuple make_tensor_shapes(const UniqueElements axis) { if (axis) { + if (*axis < 0) { + const auto normalized_axis = *axis + data_shape.size(); + *axis = normalized_axis; + } // if the axis was specified we need to return a data shape with a modified dimension-at-axis // this is where we need to insert the number of detected unique elements // all other dimensions stay the same as in the original data_shape diff --git a/src/plugins/template/backend/evaluates_map.cpp b/src/plugins/template/backend/evaluates_map.cpp index 5db5cc3c645..d46f2ee6d69 100644 --- a/src/plugins/template/backend/evaluates_map.cpp +++ b/src/plugins/template/backend/evaluates_map.cpp @@ -4201,7 +4201,7 @@ bool evaluate(const shared_ptr& op, const HostTensorVector& ou return true; } -template +template void execute_unique(const HostTensorVector& outputs, const HostTensorVector& inputs, const shared_ptr& op) { @@ -4217,10 +4217,10 @@ void execute_unique(const HostTensorVector& outputs, }; const auto unique_elements = - runtime::reference::find_unique_elements(inputs[0]->get_data_ptr(), - inputs[0]->get_shape(), - maybe_extract_axis(), - op->get_sorted()); + runtime::reference::find_unique_elements(inputs[0]->get_data_ptr(), + inputs[0]->get_shape(), + maybe_extract_axis(), + op->get_sorted()); const auto tensor_shapes = runtime::reference::make_tensor_shapes(unique_elements, inputs[0]->get_shape(), maybe_extract_axis()); @@ -4237,7 +4237,7 @@ void execute_unique(const HostTensorVector& outputs, runtime::reference::unique(out_unique_elements->get_data_ptr(), out_indices->get_data_ptr(), out_rev_indices->get_data_ptr(), - out_counts->get_data_ptr(), + out_counts->get_data_ptr(), inputs[0]->get_data_ptr(), inputs[0]->get_shape(), std::get<0>(tensor_shapes), @@ -4247,10 +4247,14 @@ void execute_unique(const HostTensorVector& outputs, template bool evaluate(const shared_ptr& op, const HostTensorVector& outputs, const HostTensorVector& inputs) { using Data_t = typename element_type_traits::value_type; - if (op->get_index_element_type() == element::i32) { - execute_unique(outputs, inputs, op); - } else if (op->get_index_element_type() == element::i64) { - execute_unique(outputs, inputs, op); + if (op->get_index_element_type() == element::i32 && op->get_count_element_type() == element::i32) { + execute_unique(outputs, inputs, op); + } else if (op->get_index_element_type() == element::i64 && op->get_count_element_type() == element::i64) { + execute_unique(outputs, inputs, op); + } else if (op->get_index_element_type() == element::i32 && op->get_count_element_type() == element::i64) { + execute_unique(outputs, inputs, op); + } else if (op->get_index_element_type() == element::i64 && op->get_count_element_type() == element::i32) { + execute_unique(outputs, inputs, op); } else { return false; } diff --git a/src/plugins/template/tests/functional/op_reference/unique.cpp b/src/plugins/template/tests/functional/op_reference/unique.cpp index 9e831fb5c38..9bea62a46f9 100644 --- a/src/plugins/template/tests/functional/op_reference/unique.cpp +++ b/src/plugins/template/tests/functional/op_reference/unique.cpp @@ -19,19 +19,20 @@ std::shared_ptr make_axis(const int64_t axis, const element::T } struct UniqueParams { - template + template UniqueParams(const Shape& data_shape, const std::vector& input_data, const std::vector& expected_unique_values, const std::vector& expected_indices, const std::vector& expected_rev_indices, - const std::vector& expected_counts, + const std::vector& expected_counts, std::shared_ptr axis_descritptor = nullptr, const bool sorted = true, const std::string& tested_case = "") : m_data_shape{data_shape}, m_data_type{element::from()}, m_index_type{element::from()}, + m_counts_type{element::from()}, m_input_data{CreateTensor(m_data_type, input_data)}, m_axis{axis_descritptor}, m_sorted{sorted}, @@ -39,12 +40,13 @@ struct UniqueParams { m_expected_outputs[0] = CreateTensor(m_data_type, expected_unique_values); m_expected_outputs[1] = CreateTensor(m_index_type, expected_indices); m_expected_outputs[2] = CreateTensor(m_index_type, expected_rev_indices); - m_expected_outputs[3] = CreateTensor(element::i64, expected_counts); + m_expected_outputs[3] = CreateTensor(m_counts_type, expected_counts); } Shape m_data_shape; element::Type m_data_type; element::Type m_index_type; + element::Type m_counts_type; ov::Tensor m_input_data; ov::TensorVector m_expected_outputs = ov::TensorVector(4); std::shared_ptr m_axis = nullptr; @@ -52,7 +54,7 @@ struct UniqueParams { std::string m_tested_case; }; -class ReferenceUniqueLayerTest_NoAxis : public testing::TestWithParam, public CommonReferenceTest { +class ReferenceUniqueLayerTest : public testing::TestWithParam, public CommonReferenceTest { public: void SetUp() override { const auto& params = GetParam(); @@ -68,6 +70,7 @@ public: result << "data_shape=" << param.m_data_shape << "; "; result << "data_type=" << param.m_data_type << "; "; result << "index_type=" << param.m_index_type << "; "; + result << "counts_type=" << param.m_counts_type << "; "; result << "sorted=" << param.m_sorted << "; "; if (param.m_axis) { result << "axis=" << param.m_axis->cast_vector()[0] << "; "; @@ -84,15 +87,19 @@ private: const auto in = std::make_shared(params.m_data_type, params.m_data_shape); std::shared_ptr unique; if (params.m_axis) { - unique = std::make_shared(in, params.m_axis, params.m_sorted, params.m_index_type); + unique = std::make_shared(in, + params.m_axis, + params.m_sorted, + params.m_index_type, + params.m_counts_type); } else { - unique = std::make_shared(in, params.m_sorted, params.m_index_type); + unique = std::make_shared(in, params.m_sorted, params.m_index_type, params.m_counts_type); } return std::make_shared(unique, ParameterVector{in}); } }; -TEST_P(ReferenceUniqueLayerTest_NoAxis, CompareWithHardcodedRefs) { +TEST_P(ReferenceUniqueLayerTest, CompareWithHardcodedRefs) { Exec(); } @@ -108,7 +115,7 @@ std::vector flatten(std::initializer_list> test_cases) { return flattened; } -template +template std::vector params_unique_int() { static_assert(std::numeric_limits::is_integer, "Integer type expected"); std::vector scalar_and_1D{UniqueParams{Shape{}, @@ -116,7 +123,7 @@ std::vector params_unique_int() { std::vector{1}, std::vector{0}, std::vector{0}, - std::vector{1}, + std::vector{1}, nullptr, false}, UniqueParams{Shape{}, @@ -124,7 +131,7 @@ std::vector params_unique_int() { std::vector{1}, std::vector{0}, std::vector{0}, - std::vector{1}, + std::vector{1}, nullptr, true}, UniqueParams{Shape{1}, @@ -132,7 +139,7 @@ std::vector params_unique_int() { std::vector{2}, std::vector{0}, std::vector{0}, - std::vector{1}, + std::vector{1}, nullptr, false}, UniqueParams{Shape{1}, @@ -140,7 +147,7 @@ std::vector params_unique_int() { std::vector{2}, std::vector{0}, std::vector{0}, - std::vector{1}, + std::vector{1}, nullptr, true}, UniqueParams{Shape{5}, @@ -148,7 +155,7 @@ std::vector params_unique_int() { std::vector{5, 4, 3, 2, 1}, std::vector{0, 1, 2, 3, 4}, std::vector{0, 1, 2, 3, 4}, - std::vector{1, 1, 1, 1, 1}, + std::vector{1, 1, 1, 1, 1}, nullptr, false, "1D no duplicates"}, @@ -157,7 +164,7 @@ std::vector params_unique_int() { std::vector{1, 2, 3, 4, 5}, std::vector{4, 3, 2, 1, 0}, std::vector{4, 3, 2, 1, 0}, - std::vector{1, 1, 1, 1, 1}, + std::vector{1, 1, 1, 1, 1}, nullptr, true, "1D no duplicates"}, @@ -166,7 +173,7 @@ std::vector params_unique_int() { std::vector{1, 3, 5, 2, 4}, std::vector{0, 1, 2, 4, 5}, std::vector{0, 1, 2, 1, 3, 4, 3}, - std::vector{1, 2, 1, 2, 1}, + std::vector{1, 2, 1, 2, 1}, nullptr, false, "1D with duplicates"}, @@ -175,7 +182,7 @@ std::vector params_unique_int() { std::vector{1, 2, 3, 4, 5}, std::vector{0, 4, 1, 5, 2}, std::vector{0, 2, 4, 2, 1, 3, 1}, - std::vector{1, 2, 2, 1, 1}, + std::vector{1, 2, 2, 1, 1}, nullptr, true, "1D with duplicates"}, @@ -184,7 +191,7 @@ std::vector params_unique_int() { std::vector{1, 2, 3, 4, 5}, std::vector{1, 4, 0, 5, 2}, std::vector{2, 0, 4, 2, 1, 3, 1}, - std::vector{1, 2, 2, 1, 1}, + std::vector{1, 2, 2, 1, 1}, nullptr, true, "1D with duplicates, sort 1st element"}, @@ -193,7 +200,7 @@ std::vector params_unique_int() { std::vector{2, 3, 4, 5}, std::vector{4, 0, 5, 2}, std::vector{1, 1, 3, 1, 0, 2, 0}, - std::vector{2, 3, 1, 1}, + std::vector{2, 3, 1, 1}, nullptr, true, "1D with duplicates in row, sort 1st element"}, @@ -202,7 +209,7 @@ std::vector params_unique_int() { std::vector{1, 2, 3, 4, 5}, std::vector{0, 4, 1, 5, 2}, std::vector{0, 2, 4, 2, 1, 3, 1}, - std::vector{1, 2, 2, 1, 1}, + std::vector{1, 2, 2, 1, 1}, make_axis(0), true, "1D with duplicates and axis"}}; @@ -212,7 +219,7 @@ std::vector params_unique_int() { std::vector{3, 5, 2, 4, 1, 6}, std::vector{0, 1, 3, 4, 6, 11}, std::vector{0, 1, 0, 2, 3, 2, 4, 2, 0, 3, 1, 5}, - std::vector{3, 2, 3, 2, 1, 1}, + std::vector{3, 2, 3, 2, 1, 1}, nullptr, false, "2D no axis"}, @@ -221,7 +228,7 @@ std::vector params_unique_int() { std::vector{1, 2, 3, 4, 1, 2, 3, 5}, std::vector{0, 1}, std::vector{0, 1}, - std::vector{1, 1}, + std::vector{1, 1}, make_axis(0), false, "2D no duplicates"}, @@ -230,7 +237,7 @@ std::vector params_unique_int() { std::vector{1, 2, 3, 4, 1, 2, 3, 5}, std::vector{0, 1, 2, 3}, std::vector{0, 1, 2, 3}, - std::vector{1, 1, 1, 1}, + std::vector{1, 1, 1, 1}, make_axis(1), false, "2D no duplicates"}, @@ -239,103 +246,131 @@ std::vector params_unique_int() { std::vector{1, 2, 4, 1, 2, 5}, std::vector{0, 1, 3}, std::vector{0, 1, 1, 2}, - std::vector{1, 2, 1}, + std::vector{1, 2, 1}, make_axis(1), false, "2D with duplicates"}}; - std::vector N_D_layout{UniqueParams{Shape{2, 2, 3}, - // 2 identical 2D slices over axis 0 - std::vector{1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6}, - std::vector{1, 2, 3, 4, 5, 6}, - std::vector{0}, - std::vector{0, 0}, - std::vector{2}, - make_axis(0), - false, - "3D with duplicates"}, - UniqueParams{Shape{2, 2, 3}, - // 2 identical 2D slices over axis 1 - std::vector{6, 5, 4, 6, 5, 4, 3, 2, 1, 3, 2, 1}, - std::vector{6, 5, 4, 3, 2, 1}, - std::vector{0}, - std::vector{0, 0}, - std::vector{2}, - make_axis(1), - false, - "3D with duplicates"}, - UniqueParams{Shape{2, 2, 3}, - // the first and the last slice over axis 2 are equal - std::vector{-1, 2, -1, 5, -3, 5, 7, -8, 7, 4, 4, 4}, - std::vector{-1, 2, 5, -3, 7, -8, 4, 4}, - std::vector{0, 1}, - std::vector{0, 1, 0}, - std::vector{2, 1}, - make_axis(2), - false, - "3D with duplicates(1 & 3)"}, - UniqueParams{Shape{2, 2, 3}, - // the first and the second slice over axis 2 are equal - std::vector{-1, -1, 2, 5, 5, -3, 7, 7, -8, 4, 4, 4}, - std::vector{-1, 2, 5, -3, 7, -8, 4, 4}, - std::vector{0, 2}, - std::vector{0, 0, 1}, - std::vector{2, 1}, - make_axis(2), - false, - "3D with duplicates (1 & 2)"}, - UniqueParams{Shape{2, 2, 3}, - // the second and the third slice over axis 2 are equal - std::vector{2, -1, -1, -3, 5, 5, -8, 7, 7, 4, 4, 4}, - std::vector{2, -1, -3, 5, -8, 7, 4, 4}, - std::vector{0, 1}, - std::vector{0, 1, 1}, - std::vector{1, 2}, - make_axis(2), - false, - "3D with duplicates (2 & 3)"}, - UniqueParams{Shape{2, 2, 3}, - // the second and the third slice over axis 2 are equal - std::vector{2, -1, -1, -3, 5, 5, -8, 7, 7, 4, 4, 4}, - std::vector{-1, 2, 5, -3, 7, -8, 4, 4}, - std::vector{1, 0}, - std::vector{1, 0, 0}, - std::vector{2, 1}, - make_axis(2), - true, - "3D with duplicates (2 & 3), output sorted"}, - UniqueParams{Shape{2, 2, 3}, - // the second and the third slice over axis 2 are equal - std::vector{-1, -1, -1, 3, 2, 2, 6, 7, 7, 4, 4, 4}, - std::vector{-1, -1, 2, 3, 7, 6, 4, 4}, - std::vector{1, 0}, - std::vector{1, 0, 0}, - std::vector{2, 1}, - make_axis(2), - true, - "3D with duplicates (2 & 3), first elements equal, output sorted"}, - UniqueParams{ - Shape{1, 3, 16}, - std::vector{15, -20, -11, 10, -21, 8, -15, -10, 7, 20, -19, -14, -13, -16, -7, -2, - -17, -4, 21, -6, 11, 8, 17, 6, 7, 20, -3, 2, -13, -16, -23, 14, - -1, 12, 5, -6, 11, -8, 1, -10, 23, 20, -19, 18, 3, -16, -7, 14}, - std::vector{-23, -21, -20, -19, -17, -16, -15, -14, -13, -11, -10, -8, -7, -6, -4, -3, -2, -1, - 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 14, 15, 17, 18, 20, 21, 23}, - std::vector{30, 4, 1, 10, 16, 13, 6, 11, 12, 2, 7, 37, 14, 19, 17, 26, 15, 32, - 38, 27, 44, 34, 23, 8, 5, 3, 20, 33, 31, 0, 22, 43, 9, 18, 40}, - std::vector{29, 2, 9, 25, 1, 24, 6, 10, 23, 32, 3, 7, 8, 5, 12, 16, - 4, 14, 33, 13, 26, 24, 30, 22, 23, 32, 15, 19, 8, 5, 0, 28, - 17, 27, 21, 13, 26, 11, 18, 10, 34, 32, 3, 31, 20, 5, 12, 28}, - std::vector{1, 1, 1, 2, 1, 3, 1, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 2, 2, 1, 2, 1, 2, 1, 1, 1, 3, 1, 1}, - nullptr, - true, - "3D flattened with duplicates, output sorted"}}; + std::vector N_D_layout{ + UniqueParams{Shape{2, 2, 3}, + // 2 identical 2D slices over axis 0 + std::vector{1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6}, + std::vector{1, 2, 3, 4, 5, 6}, + std::vector{0}, + std::vector{0, 0}, + std::vector{2}, + make_axis(0), + false, + "3D with duplicates"}, + UniqueParams{Shape{2, 3, 2}, + std::vector{-3, -2, -5, 4, -3, 2, 3, -4, 1, 2, -1, 4}, + std::vector{-3, -2, -5, 4, -3, 2, 3, -4, 1, 2, -1, 4}, + std::vector{0, 1}, + std::vector{0, 1}, + std::vector{1, 1}, + make_axis(0), + true, + "3D, already sorted, no duplicates"}, + UniqueParams{Shape{2, 3, 2}, + std::vector{-3, -2, -5, 4, -3, 2, 3, -4, 1, 2, -1, 4}, + std::vector{-3, -2, -5, 4, -3, 2, 3, -4, 1, 2, -1, 4}, + std::vector{0, 1}, + std::vector{0, 1}, + std::vector{1, 1}, + make_axis(0), + false, + "3D, already sorted, no duplicates"}, + UniqueParams{Shape{2, 2, 3}, + // 2 identical 2D slices over axis 1 + std::vector{6, 5, 4, 6, 5, 4, 3, 2, 1, 3, 2, 1}, + std::vector{6, 5, 4, 3, 2, 1}, + std::vector{0}, + std::vector{0, 0}, + std::vector{2}, + make_axis(1), + false, + "3D with duplicates"}, + UniqueParams{Shape{2, 2, 3}, + // the first and the last slice over axis 2 are equal + std::vector{-1, 2, -1, 5, -3, 5, 7, -8, 7, 4, 4, 4}, + std::vector{-1, 2, 5, -3, 7, -8, 4, 4}, + std::vector{0, 1}, + std::vector{0, 1, 0}, + std::vector{2, 1}, + make_axis(2), + false, + "3D with duplicates(1 & 3)"}, + UniqueParams{Shape{2, 2, 3}, + // the first and the second slice over axis 2 are equal + std::vector{-1, -1, 2, 5, 5, -3, 7, 7, -8, 4, 4, 4}, + std::vector{-1, 2, 5, -3, 7, -8, 4, 4}, + std::vector{0, 2}, + std::vector{0, 0, 1}, + std::vector{2, 1}, + make_axis(2), + false, + "3D with duplicates (1 & 2)"}, + UniqueParams{Shape{2, 2, 3}, + // the second and the third slice over axis 2 are equal + std::vector{2, -1, -1, -3, 5, 5, -8, 7, 7, 4, 4, 4}, + std::vector{2, -1, -3, 5, -8, 7, 4, 4}, + std::vector{0, 1}, + std::vector{0, 1, 1}, + std::vector{1, 2}, + make_axis(2), + false, + "3D with duplicates (2 & 3)"}, + UniqueParams{Shape{2, 2, 3}, + // the second and the third slice over axis 2 are equal + std::vector{2, -1, -1, -3, 5, 5, -8, 7, 7, 4, 4, 4}, + std::vector{-1, 2, 5, -3, 7, -8, 4, 4}, + std::vector{1, 0}, + std::vector{1, 0, 0}, + std::vector{2, 1}, + make_axis(2), + true, + "3D with duplicates (2 & 3), output sorted"}, + UniqueParams{Shape{2, 2, 3}, + std::vector{2, -1, -1, -3, 5, 5, -8, 7, 7, 4, 4, 4}, + std::vector{-1, 2, 5, -3, 7, -8, 4, 4}, + std::vector{1, 0}, + std::vector{1, 0, 0}, + std::vector{2, 1}, + make_axis(-1), + true, + "3D with duplicates (2 & 3), output sorted"}, + UniqueParams{Shape{2, 2, 3}, + // the second and the third slice over axis 2 are equal + std::vector{-1, -1, -1, 3, 2, 2, 6, 7, 7, 4, 4, 4}, + std::vector{-1, -1, 2, 3, 7, 6, 4, 4}, + std::vector{1, 0}, + std::vector{1, 0, 0}, + std::vector{2, 1}, + make_axis(2), + true, + "3D with duplicates (2 & 3), first elements equal, output sorted"}, + UniqueParams{ + Shape{1, 3, 16}, + std::vector{15, -20, -11, 10, -21, 8, -15, -10, 7, 20, -19, -14, -13, -16, -7, -2, + -17, -4, 21, -6, 11, 8, 17, 6, 7, 20, -3, 2, -13, -16, -23, 14, + -1, 12, 5, -6, 11, -8, 1, -10, 23, 20, -19, 18, 3, -16, -7, 14}, + std::vector{-23, -21, -20, -19, -17, -16, -15, -14, -13, -11, -10, -8, -7, -6, -4, -3, -2, -1, + 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 14, 15, 17, 18, 20, 21, 23}, + std::vector{30, 4, 1, 10, 16, 13, 6, 11, 12, 2, 7, 37, 14, 19, 17, 26, 15, 32, + 38, 27, 44, 34, 23, 8, 5, 3, 20, 33, 31, 0, 22, 43, 9, 18, 40}, + std::vector{29, 2, 9, 25, 1, 24, 6, 10, 23, 32, 3, 7, 8, 5, 12, 16, + 4, 14, 33, 13, 26, 24, 30, 22, 23, 32, 15, 19, 8, 5, 0, 28, + 17, 27, 21, 13, 26, 11, 18, 10, 34, 32, 3, 31, 20, 5, 12, 28}, + std::vector{1, 1, 1, 2, 1, 3, 1, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 2, 1, 2, 1, 2, 1, 1, 1, 3, 1, 1}, + nullptr, + true, + "3D flattened with duplicates, output sorted"}}; return flatten({std::move(scalar_and_1D), std::move(N_C_layout), std::move(N_D_layout)}); } -template +template std::vector params_unique_float() { static_assert(!std::numeric_limits::is_integer, "Floating point type expected"); // just some fancy numbers to be used in the input tensors @@ -349,7 +384,7 @@ std::vector params_unique_float() { std::vector{pi}, std::vector{0}, std::vector{0}, - std::vector{1}, + std::vector{1}, nullptr, false}, UniqueParams{Shape{}, @@ -357,7 +392,7 @@ std::vector params_unique_float() { std::vector{pi}, std::vector{0}, std::vector{0}, - std::vector{1}, + std::vector{1}, nullptr, true}, UniqueParams{Shape{1}, @@ -365,7 +400,7 @@ std::vector params_unique_float() { std::vector{-e}, std::vector{0}, std::vector{0}, - std::vector{1}, + std::vector{1}, nullptr, false}, UniqueParams{Shape{1}, @@ -373,7 +408,7 @@ std::vector params_unique_float() { std::vector{-e}, std::vector{0}, std::vector{0}, - std::vector{1}, + std::vector{1}, nullptr, true}, UniqueParams{Shape{6}, @@ -381,7 +416,7 @@ std::vector params_unique_float() { std::vector{pi, -pi, -e, e, sq3, sq2}, std::vector{0, 1, 2, 3, 4, 5}, std::vector{0, 1, 2, 3, 4, 5}, - std::vector{1, 1, 1, 1, 1, 1}, + std::vector{1, 1, 1, 1, 1, 1}, nullptr, false, "1D no duplicates"}, @@ -390,33 +425,52 @@ std::vector params_unique_float() { std::vector{-pi, -e, sq2, sq3, e, pi}, std::vector{1, 2, 5, 4, 3, 0}, std::vector{5, 0, 1, 4, 3, 2}, - std::vector{1, 1, 1, 1, 1, 1}, + std::vector{1, 1, 1, 1, 1, 1}, nullptr, true, - "1D no duplicates"}}; + "1D no duplicates"}, + UniqueParams{Shape{2, 2, 3}, + std::vector{1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6}, + std::vector{1, 2, 3, 4, 5, 6}, + std::vector{0}, + std::vector{0, 0}, + std::vector{2}, + make_axis(-3), + false, + "3D with duplicates"}, + UniqueParams{Shape{2, 2, 3}, + std::vector{2, -1, -1, -3, 5, 5, -8, 7, 7, 4, 4, 4}, + std::vector{-1, 2, 5, -3, 7, -8, 4, 4}, + std::vector{1, 0}, + std::vector{1, 0, 0}, + std::vector{2, 1}, + make_axis(2), + true, + "3D with duplicates (2 & 3), output sorted"}}; return params; } -INSTANTIATE_TEST_SUITE_P(smoke_ReferenceUniqueLayerTest_NoAxis, - ReferenceUniqueLayerTest_NoAxis, - ::testing::ValuesIn(flatten({params_unique_float(), - params_unique_float(), - params_unique_float(), - params_unique_float(), - params_unique_float(), - params_unique_float(), - params_unique_float(), - params_unique_float(), - params_unique_int(), - params_unique_int(), - params_unique_int(), - params_unique_int(), - params_unique_int(), - params_unique_int(), - params_unique_int(), - params_unique_int()})), - - ReferenceUniqueLayerTest_NoAxis::getTestCaseName); +INSTANTIATE_TEST_SUITE_P( + smoke_ReferenceUniqueLayerTest, + ReferenceUniqueLayerTest, + ::testing::ValuesIn( + flatten({params_unique_float(), params_unique_float(), + params_unique_float(), params_unique_float(), + params_unique_float(), params_unique_float(), + params_unique_float(), params_unique_float(), + params_unique_float(), params_unique_float(), + params_unique_float(), params_unique_float(), + params_unique_float(), params_unique_float(), + params_unique_float(), params_unique_float(), + params_unique_int(), params_unique_int(), + params_unique_int(), params_unique_int(), + params_unique_int(), params_unique_int(), + params_unique_int(), params_unique_int(), + params_unique_int(), params_unique_int(), + params_unique_int(), params_unique_int(), + params_unique_int(), params_unique_int(), + params_unique_int(), params_unique_int()})), + ReferenceUniqueLayerTest::getTestCaseName); } // namespace