Unique-10 tests and improvements (#14315)

This commit is contained in:
Tomasz Dołbniak 2022-12-06 17:09:30 +01:00 committed by GitHub
parent 79f04a704c
commit 6da95784c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 236 additions and 163 deletions

View File

@ -130,24 +130,24 @@ bool convert_precision(ov::pass::PassBase& pass,
}; };
auto convert_node_output_precision = [&](const std::shared_ptr<ngraph::Node>& node) { auto convert_node_output_precision = [&](const std::shared_ptr<ngraph::Node>& node) {
for (const auto& output : node->outputs()) { bool res = false;
if (output.get_element_type() == from) { // Handle case with Constants as they can have consumers from other nGraph Function object
// Handle case with Constants as they can have consumers from other nGraph const auto constant = ov::as_type_ptr<opset10::Constant>(node);
// Function object const auto it = const_to_internal_output.find(node.get());
auto it = const_to_internal_output.find(node.get()); if (constant && constant->get_output_element_type(0) == from && it != const_to_internal_output.end()) {
if (it != const_to_internal_output.end()) {
return fuse_type_to_constant(node, to, it->second); return fuse_type_to_constant(node, to, it->second);
} }
for (const auto& output : node->outputs()) {
if (output.get_element_type() == from) {
// Check that node type exists in map and we can fuse type into node // 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()); const 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())) { if (t2f_it != type_to_fuse.end()) {
// We need to break if original node was replaced res |= t2f_it->second(node, to, output.get_index());
return true;
} }
} }
} }
return false; return res;
}; };
auto convert_node_input_precision = [&](const std::shared_ptr<ngraph::Node>& node) { auto convert_node_input_precision = [&](const std::shared_ptr<ngraph::Node>& node) {
@ -347,17 +347,19 @@ bool fuse_type_to_random_uniform_v8(const std::shared_ptr<ngraph::Node>& node, o
} }
bool fuse_type_to_unique_v10(const std::shared_ptr<Node>& node, ov::element::Type to, size_t idx) { bool fuse_type_to_unique_v10(const std::shared_ptr<Node>& node, ov::element::Type to, size_t idx) {
bool res = false;
if (auto unique = ov::as_type_ptr<opset10::Unique>(node)) { if (auto unique = ov::as_type_ptr<opset10::Unique>(node)) {
if (to == ov::element::i32 || to == ov::element::i64) { if (to == ov::element::i32 || to == ov::element::i64) {
if (idx == 1 || idx == 2) { if (idx == 1 || idx == 2) {
unique->set_index_element_type(to); unique->set_index_element_type(to);
res = true;
} else if (idx == 3) { } else if (idx == 3) {
unique->set_count_element_type(to); unique->set_count_element_type(to);
res = true;
} }
} }
} }
// No node replacement, so always return false return res;
return false;
} }
bool fuse_type_to_range_v4(const std::shared_ptr<ngraph::Node>& node, ov::element::Type to, size_t idx) { bool fuse_type_to_range_v4(const std::shared_ptr<ngraph::Node>& node, ov::element::Type to, size_t idx) {

View File

@ -40,7 +40,7 @@ public:
const Output<Node>& axis, const Output<Node>& axis,
const bool sorted = true, const bool sorted = true,
const element::Type& index_element_type = element::i64, 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; bool visit_attributes(AttributeVisitor& visitor) override;
void validate_and_infer_types() override; void validate_and_infer_types() override;

View File

@ -108,6 +108,11 @@ UniqueElements<Index_t, Count_t> find_unique_elements(const Data_t* data,
const auto data_shape_strides = ngraph::row_major_strides(data_shape); 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<Index_t, Count_t>& lhs, const auto ascending_order = [&data](const TensorSlice<Index_t, Count_t>& lhs,
const TensorSlice<Index_t, Count_t>& rhs) { const TensorSlice<Index_t, Count_t>& rhs) {
return *(data + lhs.idx) < *(data + rhs.idx); return *(data + lhs.idx) < *(data + rhs.idx);
@ -137,6 +142,10 @@ UniqueElements<Index_t, Count_t> find_unique_elements(const Data_t* data,
if (*(data + lhs_elem_idx) < *(data + rhs_elem_idx)) { if (*(data + lhs_elem_idx) < *(data + rhs_elem_idx)) {
return true; return true;
} else if (*(data + lhs_elem_idx) > *(data + rhs_elem_idx)) {
return false;
} else {
continue;
} }
} }
@ -269,6 +278,10 @@ std::tuple<Shape, Shape, Shape> make_tensor_shapes(const UniqueElements<Index_t,
const Shape& data_shape, const Shape& data_shape,
std::unique_ptr<int64_t> axis) { std::unique_ptr<int64_t> axis) {
if (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 // 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 // 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 // all other dimensions stay the same as in the original data_shape

View File

@ -4201,7 +4201,7 @@ bool evaluate(const shared_ptr<op::v9::SoftSign>& op, const HostTensorVector& ou
return true; return true;
} }
template <typename Data_t, typename Index_t> template <typename Data_t, typename Index_t, typename Count_t>
void execute_unique(const HostTensorVector& outputs, void execute_unique(const HostTensorVector& outputs,
const HostTensorVector& inputs, const HostTensorVector& inputs,
const shared_ptr<op::v10::Unique>& op) { const shared_ptr<op::v10::Unique>& op) {
@ -4217,7 +4217,7 @@ void execute_unique(const HostTensorVector& outputs,
}; };
const auto unique_elements = const auto unique_elements =
runtime::reference::find_unique_elements<Data_t, Index_t>(inputs[0]->get_data_ptr<Data_t>(), runtime::reference::find_unique_elements<Data_t, Index_t, Count_t>(inputs[0]->get_data_ptr<Data_t>(),
inputs[0]->get_shape(), inputs[0]->get_shape(),
maybe_extract_axis(), maybe_extract_axis(),
op->get_sorted()); op->get_sorted());
@ -4237,7 +4237,7 @@ void execute_unique(const HostTensorVector& outputs,
runtime::reference::unique(out_unique_elements->get_data_ptr<Data_t>(), runtime::reference::unique(out_unique_elements->get_data_ptr<Data_t>(),
out_indices->get_data_ptr<Index_t>(), out_indices->get_data_ptr<Index_t>(),
out_rev_indices->get_data_ptr<Index_t>(), out_rev_indices->get_data_ptr<Index_t>(),
out_counts->get_data_ptr<int64_t>(), out_counts->get_data_ptr<Count_t>(),
inputs[0]->get_data_ptr<Data_t>(), inputs[0]->get_data_ptr<Data_t>(),
inputs[0]->get_shape(), inputs[0]->get_shape(),
std::get<0>(tensor_shapes), std::get<0>(tensor_shapes),
@ -4247,10 +4247,14 @@ void execute_unique(const HostTensorVector& outputs,
template <element::Type_t Data_ET> template <element::Type_t Data_ET>
bool evaluate(const shared_ptr<op::v10::Unique>& op, const HostTensorVector& outputs, const HostTensorVector& inputs) { bool evaluate(const shared_ptr<op::v10::Unique>& op, const HostTensorVector& outputs, const HostTensorVector& inputs) {
using Data_t = typename element_type_traits<Data_ET>::value_type; using Data_t = typename element_type_traits<Data_ET>::value_type;
if (op->get_index_element_type() == element::i32) { if (op->get_index_element_type() == element::i32 && op->get_count_element_type() == element::i32) {
execute_unique<Data_t, int32_t>(outputs, inputs, op); execute_unique<Data_t, int32_t, int32_t>(outputs, inputs, op);
} else if (op->get_index_element_type() == element::i64) { } else if (op->get_index_element_type() == element::i64 && op->get_count_element_type() == element::i64) {
execute_unique<Data_t, int64_t>(outputs, inputs, op); execute_unique<Data_t, int64_t, int64_t>(outputs, inputs, op);
} else if (op->get_index_element_type() == element::i32 && op->get_count_element_type() == element::i64) {
execute_unique<Data_t, int32_t, int64_t>(outputs, inputs, op);
} else if (op->get_index_element_type() == element::i64 && op->get_count_element_type() == element::i32) {
execute_unique<Data_t, int64_t, int32_t>(outputs, inputs, op);
} else { } else {
return false; return false;
} }

View File

@ -19,19 +19,20 @@ std::shared_ptr<op::v0::Constant> make_axis(const int64_t axis, const element::T
} }
struct UniqueParams { struct UniqueParams {
template <typename Data_t, typename Index_t> template <typename Data_t, typename Index_t, typename Count_t>
UniqueParams(const Shape& data_shape, UniqueParams(const Shape& data_shape,
const std::vector<Data_t>& input_data, const std::vector<Data_t>& input_data,
const std::vector<Data_t>& expected_unique_values, const std::vector<Data_t>& expected_unique_values,
const std::vector<Index_t>& expected_indices, const std::vector<Index_t>& expected_indices,
const std::vector<Index_t>& expected_rev_indices, const std::vector<Index_t>& expected_rev_indices,
const std::vector<int64_t>& expected_counts, const std::vector<Count_t>& expected_counts,
std::shared_ptr<op::v0::Constant> axis_descritptor = nullptr, std::shared_ptr<op::v0::Constant> axis_descritptor = nullptr,
const bool sorted = true, const bool sorted = true,
const std::string& tested_case = "") const std::string& tested_case = "")
: m_data_shape{data_shape}, : m_data_shape{data_shape},
m_data_type{element::from<Data_t>()}, m_data_type{element::from<Data_t>()},
m_index_type{element::from<Index_t>()}, m_index_type{element::from<Index_t>()},
m_counts_type{element::from<Count_t>()},
m_input_data{CreateTensor(m_data_type, input_data)}, m_input_data{CreateTensor(m_data_type, input_data)},
m_axis{axis_descritptor}, m_axis{axis_descritptor},
m_sorted{sorted}, m_sorted{sorted},
@ -39,12 +40,13 @@ struct UniqueParams {
m_expected_outputs[0] = CreateTensor(m_data_type, expected_unique_values); m_expected_outputs[0] = CreateTensor(m_data_type, expected_unique_values);
m_expected_outputs[1] = CreateTensor(m_index_type, expected_indices); m_expected_outputs[1] = CreateTensor(m_index_type, expected_indices);
m_expected_outputs[2] = CreateTensor(m_index_type, expected_rev_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; Shape m_data_shape;
element::Type m_data_type; element::Type m_data_type;
element::Type m_index_type; element::Type m_index_type;
element::Type m_counts_type;
ov::Tensor m_input_data; ov::Tensor m_input_data;
ov::TensorVector m_expected_outputs = ov::TensorVector(4); ov::TensorVector m_expected_outputs = ov::TensorVector(4);
std::shared_ptr<op::v0::Constant> m_axis = nullptr; std::shared_ptr<op::v0::Constant> m_axis = nullptr;
@ -52,7 +54,7 @@ struct UniqueParams {
std::string m_tested_case; std::string m_tested_case;
}; };
class ReferenceUniqueLayerTest_NoAxis : public testing::TestWithParam<UniqueParams>, public CommonReferenceTest { class ReferenceUniqueLayerTest : public testing::TestWithParam<UniqueParams>, public CommonReferenceTest {
public: public:
void SetUp() override { void SetUp() override {
const auto& params = GetParam(); const auto& params = GetParam();
@ -68,6 +70,7 @@ public:
result << "data_shape=" << param.m_data_shape << "; "; result << "data_shape=" << param.m_data_shape << "; ";
result << "data_type=" << param.m_data_type << "; "; result << "data_type=" << param.m_data_type << "; ";
result << "index_type=" << param.m_index_type << "; "; result << "index_type=" << param.m_index_type << "; ";
result << "counts_type=" << param.m_counts_type << "; ";
result << "sorted=" << param.m_sorted << "; "; result << "sorted=" << param.m_sorted << "; ";
if (param.m_axis) { if (param.m_axis) {
result << "axis=" << param.m_axis->cast_vector<int64_t>()[0] << "; "; result << "axis=" << param.m_axis->cast_vector<int64_t>()[0] << "; ";
@ -84,15 +87,19 @@ private:
const auto in = std::make_shared<op::v0::Parameter>(params.m_data_type, params.m_data_shape); const auto in = std::make_shared<op::v0::Parameter>(params.m_data_type, params.m_data_shape);
std::shared_ptr<Node> unique; std::shared_ptr<Node> unique;
if (params.m_axis) { if (params.m_axis) {
unique = std::make_shared<op::v10::Unique>(in, params.m_axis, params.m_sorted, params.m_index_type); unique = std::make_shared<op::v10::Unique>(in,
params.m_axis,
params.m_sorted,
params.m_index_type,
params.m_counts_type);
} else { } else {
unique = std::make_shared<op::v10::Unique>(in, params.m_sorted, params.m_index_type); unique = std::make_shared<op::v10::Unique>(in, params.m_sorted, params.m_index_type, params.m_counts_type);
} }
return std::make_shared<ov::Model>(unique, ParameterVector{in}); return std::make_shared<ov::Model>(unique, ParameterVector{in});
} }
}; };
TEST_P(ReferenceUniqueLayerTest_NoAxis, CompareWithHardcodedRefs) { TEST_P(ReferenceUniqueLayerTest, CompareWithHardcodedRefs) {
Exec(); Exec();
} }
@ -108,7 +115,7 @@ std::vector<T> flatten(std::initializer_list<std::vector<T>> test_cases) {
return flattened; return flattened;
} }
template <typename Data_t, typename Index_t> template <typename Data_t, typename Index_t, typename Count_t>
std::vector<UniqueParams> params_unique_int() { std::vector<UniqueParams> params_unique_int() {
static_assert(std::numeric_limits<Data_t>::is_integer, "Integer type expected"); static_assert(std::numeric_limits<Data_t>::is_integer, "Integer type expected");
std::vector<UniqueParams> scalar_and_1D{UniqueParams{Shape{}, std::vector<UniqueParams> scalar_and_1D{UniqueParams{Shape{},
@ -116,7 +123,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1}, std::vector<Data_t>{1},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<int64_t>{1}, std::vector<Count_t>{1},
nullptr, nullptr,
false}, false},
UniqueParams{Shape{}, UniqueParams{Shape{},
@ -124,7 +131,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1}, std::vector<Data_t>{1},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<int64_t>{1}, std::vector<Count_t>{1},
nullptr, nullptr,
true}, true},
UniqueParams{Shape{1}, UniqueParams{Shape{1},
@ -132,7 +139,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{2}, std::vector<Data_t>{2},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<int64_t>{1}, std::vector<Count_t>{1},
nullptr, nullptr,
false}, false},
UniqueParams{Shape{1}, UniqueParams{Shape{1},
@ -140,7 +147,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{2}, std::vector<Data_t>{2},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<int64_t>{1}, std::vector<Count_t>{1},
nullptr, nullptr,
true}, true},
UniqueParams{Shape{5}, UniqueParams{Shape{5},
@ -148,7 +155,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{5, 4, 3, 2, 1}, std::vector<Data_t>{5, 4, 3, 2, 1},
std::vector<Index_t>{0, 1, 2, 3, 4}, std::vector<Index_t>{0, 1, 2, 3, 4},
std::vector<Index_t>{0, 1, 2, 3, 4}, std::vector<Index_t>{0, 1, 2, 3, 4},
std::vector<int64_t>{1, 1, 1, 1, 1}, std::vector<Count_t>{1, 1, 1, 1, 1},
nullptr, nullptr,
false, false,
"1D no duplicates"}, "1D no duplicates"},
@ -157,7 +164,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1, 2, 3, 4, 5}, std::vector<Data_t>{1, 2, 3, 4, 5},
std::vector<Index_t>{4, 3, 2, 1, 0}, std::vector<Index_t>{4, 3, 2, 1, 0},
std::vector<Index_t>{4, 3, 2, 1, 0}, std::vector<Index_t>{4, 3, 2, 1, 0},
std::vector<int64_t>{1, 1, 1, 1, 1}, std::vector<Count_t>{1, 1, 1, 1, 1},
nullptr, nullptr,
true, true,
"1D no duplicates"}, "1D no duplicates"},
@ -166,7 +173,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1, 3, 5, 2, 4}, std::vector<Data_t>{1, 3, 5, 2, 4},
std::vector<Index_t>{0, 1, 2, 4, 5}, std::vector<Index_t>{0, 1, 2, 4, 5},
std::vector<Index_t>{0, 1, 2, 1, 3, 4, 3}, std::vector<Index_t>{0, 1, 2, 1, 3, 4, 3},
std::vector<int64_t>{1, 2, 1, 2, 1}, std::vector<Count_t>{1, 2, 1, 2, 1},
nullptr, nullptr,
false, false,
"1D with duplicates"}, "1D with duplicates"},
@ -175,7 +182,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1, 2, 3, 4, 5}, std::vector<Data_t>{1, 2, 3, 4, 5},
std::vector<Index_t>{0, 4, 1, 5, 2}, std::vector<Index_t>{0, 4, 1, 5, 2},
std::vector<Index_t>{0, 2, 4, 2, 1, 3, 1}, std::vector<Index_t>{0, 2, 4, 2, 1, 3, 1},
std::vector<int64_t>{1, 2, 2, 1, 1}, std::vector<Count_t>{1, 2, 2, 1, 1},
nullptr, nullptr,
true, true,
"1D with duplicates"}, "1D with duplicates"},
@ -184,7 +191,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1, 2, 3, 4, 5}, std::vector<Data_t>{1, 2, 3, 4, 5},
std::vector<Index_t>{1, 4, 0, 5, 2}, std::vector<Index_t>{1, 4, 0, 5, 2},
std::vector<Index_t>{2, 0, 4, 2, 1, 3, 1}, std::vector<Index_t>{2, 0, 4, 2, 1, 3, 1},
std::vector<int64_t>{1, 2, 2, 1, 1}, std::vector<Count_t>{1, 2, 2, 1, 1},
nullptr, nullptr,
true, true,
"1D with duplicates, sort 1st element"}, "1D with duplicates, sort 1st element"},
@ -193,7 +200,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{2, 3, 4, 5}, std::vector<Data_t>{2, 3, 4, 5},
std::vector<Index_t>{4, 0, 5, 2}, std::vector<Index_t>{4, 0, 5, 2},
std::vector<Index_t>{1, 1, 3, 1, 0, 2, 0}, std::vector<Index_t>{1, 1, 3, 1, 0, 2, 0},
std::vector<int64_t>{2, 3, 1, 1}, std::vector<Count_t>{2, 3, 1, 1},
nullptr, nullptr,
true, true,
"1D with duplicates in row, sort 1st element"}, "1D with duplicates in row, sort 1st element"},
@ -202,7 +209,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1, 2, 3, 4, 5}, std::vector<Data_t>{1, 2, 3, 4, 5},
std::vector<Index_t>{0, 4, 1, 5, 2}, std::vector<Index_t>{0, 4, 1, 5, 2},
std::vector<Index_t>{0, 2, 4, 2, 1, 3, 1}, std::vector<Index_t>{0, 2, 4, 2, 1, 3, 1},
std::vector<int64_t>{1, 2, 2, 1, 1}, std::vector<Count_t>{1, 2, 2, 1, 1},
make_axis(0), make_axis(0),
true, true,
"1D with duplicates and axis"}}; "1D with duplicates and axis"}};
@ -212,7 +219,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{3, 5, 2, 4, 1, 6}, std::vector<Data_t>{3, 5, 2, 4, 1, 6},
std::vector<Index_t>{0, 1, 3, 4, 6, 11}, std::vector<Index_t>{0, 1, 3, 4, 6, 11},
std::vector<Index_t>{0, 1, 0, 2, 3, 2, 4, 2, 0, 3, 1, 5}, std::vector<Index_t>{0, 1, 0, 2, 3, 2, 4, 2, 0, 3, 1, 5},
std::vector<int64_t>{3, 2, 3, 2, 1, 1}, std::vector<Count_t>{3, 2, 3, 2, 1, 1},
nullptr, nullptr,
false, false,
"2D no axis"}, "2D no axis"},
@ -221,7 +228,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1, 2, 3, 4, 1, 2, 3, 5}, std::vector<Data_t>{1, 2, 3, 4, 1, 2, 3, 5},
std::vector<Index_t>{0, 1}, std::vector<Index_t>{0, 1},
std::vector<Index_t>{0, 1}, std::vector<Index_t>{0, 1},
std::vector<int64_t>{1, 1}, std::vector<Count_t>{1, 1},
make_axis(0), make_axis(0),
false, false,
"2D no duplicates"}, "2D no duplicates"},
@ -230,7 +237,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1, 2, 3, 4, 1, 2, 3, 5}, std::vector<Data_t>{1, 2, 3, 4, 1, 2, 3, 5},
std::vector<Index_t>{0, 1, 2, 3}, std::vector<Index_t>{0, 1, 2, 3},
std::vector<Index_t>{0, 1, 2, 3}, std::vector<Index_t>{0, 1, 2, 3},
std::vector<int64_t>{1, 1, 1, 1}, std::vector<Count_t>{1, 1, 1, 1},
make_axis(1), make_axis(1),
false, false,
"2D no duplicates"}, "2D no duplicates"},
@ -239,28 +246,47 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{1, 2, 4, 1, 2, 5}, std::vector<Data_t>{1, 2, 4, 1, 2, 5},
std::vector<Index_t>{0, 1, 3}, std::vector<Index_t>{0, 1, 3},
std::vector<Index_t>{0, 1, 1, 2}, std::vector<Index_t>{0, 1, 1, 2},
std::vector<int64_t>{1, 2, 1}, std::vector<Count_t>{1, 2, 1},
make_axis(1), make_axis(1),
false, false,
"2D with duplicates"}}; "2D with duplicates"}};
std::vector<UniqueParams> N_D_layout{UniqueParams{Shape{2, 2, 3}, std::vector<UniqueParams> N_D_layout{
UniqueParams{Shape{2, 2, 3},
// 2 identical 2D slices over axis 0 // 2 identical 2D slices over axis 0
std::vector<Data_t>{1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6}, std::vector<Data_t>{1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6},
std::vector<Data_t>{1, 2, 3, 4, 5, 6}, std::vector<Data_t>{1, 2, 3, 4, 5, 6},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0, 0}, std::vector<Index_t>{0, 0},
std::vector<int64_t>{2}, std::vector<Count_t>{2},
make_axis(0), make_axis(0),
false, false,
"3D with duplicates"}, "3D with duplicates"},
UniqueParams{Shape{2, 3, 2},
std::vector<Data_t>{-3, -2, -5, 4, -3, 2, 3, -4, 1, 2, -1, 4},
std::vector<Data_t>{-3, -2, -5, 4, -3, 2, 3, -4, 1, 2, -1, 4},
std::vector<Index_t>{0, 1},
std::vector<Index_t>{0, 1},
std::vector<Count_t>{1, 1},
make_axis(0),
true,
"3D, already sorted, no duplicates"},
UniqueParams{Shape{2, 3, 2},
std::vector<Data_t>{-3, -2, -5, 4, -3, 2, 3, -4, 1, 2, -1, 4},
std::vector<Data_t>{-3, -2, -5, 4, -3, 2, 3, -4, 1, 2, -1, 4},
std::vector<Index_t>{0, 1},
std::vector<Index_t>{0, 1},
std::vector<Count_t>{1, 1},
make_axis(0),
false,
"3D, already sorted, no duplicates"},
UniqueParams{Shape{2, 2, 3}, UniqueParams{Shape{2, 2, 3},
// 2 identical 2D slices over axis 1 // 2 identical 2D slices over axis 1
std::vector<Data_t>{6, 5, 4, 6, 5, 4, 3, 2, 1, 3, 2, 1}, std::vector<Data_t>{6, 5, 4, 6, 5, 4, 3, 2, 1, 3, 2, 1},
std::vector<Data_t>{6, 5, 4, 3, 2, 1}, std::vector<Data_t>{6, 5, 4, 3, 2, 1},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0, 0}, std::vector<Index_t>{0, 0},
std::vector<int64_t>{2}, std::vector<Count_t>{2},
make_axis(1), make_axis(1),
false, false,
"3D with duplicates"}, "3D with duplicates"},
@ -270,7 +296,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{-1, 2, 5, -3, 7, -8, 4, 4}, std::vector<Data_t>{-1, 2, 5, -3, 7, -8, 4, 4},
std::vector<Index_t>{0, 1}, std::vector<Index_t>{0, 1},
std::vector<Index_t>{0, 1, 0}, std::vector<Index_t>{0, 1, 0},
std::vector<int64_t>{2, 1}, std::vector<Count_t>{2, 1},
make_axis(2), make_axis(2),
false, false,
"3D with duplicates(1 & 3)"}, "3D with duplicates(1 & 3)"},
@ -280,7 +306,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{-1, 2, 5, -3, 7, -8, 4, 4}, std::vector<Data_t>{-1, 2, 5, -3, 7, -8, 4, 4},
std::vector<Index_t>{0, 2}, std::vector<Index_t>{0, 2},
std::vector<Index_t>{0, 0, 1}, std::vector<Index_t>{0, 0, 1},
std::vector<int64_t>{2, 1}, std::vector<Count_t>{2, 1},
make_axis(2), make_axis(2),
false, false,
"3D with duplicates (1 & 2)"}, "3D with duplicates (1 & 2)"},
@ -290,7 +316,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{2, -1, -3, 5, -8, 7, 4, 4}, std::vector<Data_t>{2, -1, -3, 5, -8, 7, 4, 4},
std::vector<Index_t>{0, 1}, std::vector<Index_t>{0, 1},
std::vector<Index_t>{0, 1, 1}, std::vector<Index_t>{0, 1, 1},
std::vector<int64_t>{1, 2}, std::vector<Count_t>{1, 2},
make_axis(2), make_axis(2),
false, false,
"3D with duplicates (2 & 3)"}, "3D with duplicates (2 & 3)"},
@ -300,17 +326,26 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Data_t>{-1, 2, 5, -3, 7, -8, 4, 4}, std::vector<Data_t>{-1, 2, 5, -3, 7, -8, 4, 4},
std::vector<Index_t>{1, 0}, std::vector<Index_t>{1, 0},
std::vector<Index_t>{1, 0, 0}, std::vector<Index_t>{1, 0, 0},
std::vector<int64_t>{2, 1}, std::vector<Count_t>{2, 1},
make_axis(2), make_axis(2),
true, true,
"3D with duplicates (2 & 3), output sorted"}, "3D with duplicates (2 & 3), output sorted"},
UniqueParams{Shape{2, 2, 3},
std::vector<Data_t>{2, -1, -1, -3, 5, 5, -8, 7, 7, 4, 4, 4},
std::vector<Data_t>{-1, 2, 5, -3, 7, -8, 4, 4},
std::vector<Index_t>{1, 0},
std::vector<Index_t>{1, 0, 0},
std::vector<Count_t>{2, 1},
make_axis(-1),
true,
"3D with duplicates (2 & 3), output sorted"},
UniqueParams{Shape{2, 2, 3}, UniqueParams{Shape{2, 2, 3},
// the second and the third slice over axis 2 are equal // the second and the third slice over axis 2 are equal
std::vector<Data_t>{-1, -1, -1, 3, 2, 2, 6, 7, 7, 4, 4, 4}, std::vector<Data_t>{-1, -1, -1, 3, 2, 2, 6, 7, 7, 4, 4, 4},
std::vector<Data_t>{-1, -1, 2, 3, 7, 6, 4, 4}, std::vector<Data_t>{-1, -1, 2, 3, 7, 6, 4, 4},
std::vector<Index_t>{1, 0}, std::vector<Index_t>{1, 0},
std::vector<Index_t>{1, 0, 0}, std::vector<Index_t>{1, 0, 0},
std::vector<int64_t>{2, 1}, std::vector<Count_t>{2, 1},
make_axis(2), make_axis(2),
true, true,
"3D with duplicates (2 & 3), first elements equal, output sorted"}, "3D with duplicates (2 & 3), first elements equal, output sorted"},
@ -326,7 +361,7 @@ std::vector<UniqueParams> params_unique_int() {
std::vector<Index_t>{29, 2, 9, 25, 1, 24, 6, 10, 23, 32, 3, 7, 8, 5, 12, 16, std::vector<Index_t>{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, 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}, 17, 27, 21, 13, 26, 11, 18, 10, 34, 32, 3, 31, 20, 5, 12, 28},
std::vector<int64_t>{1, 1, 1, 2, 1, 3, 1, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 1, std::vector<Count_t>{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}, 1, 1, 1, 1, 1, 2, 2, 1, 2, 1, 2, 1, 1, 1, 3, 1, 1},
nullptr, nullptr,
true, true,
@ -335,7 +370,7 @@ std::vector<UniqueParams> params_unique_int() {
return flatten({std::move(scalar_and_1D), std::move(N_C_layout), std::move(N_D_layout)}); return flatten({std::move(scalar_and_1D), std::move(N_C_layout), std::move(N_D_layout)});
} }
template <typename Data_t, typename Index_t> template <typename Data_t, typename Index_t, typename Count_t>
std::vector<UniqueParams> params_unique_float() { std::vector<UniqueParams> params_unique_float() {
static_assert(!std::numeric_limits<Data_t>::is_integer, "Floating point type expected"); static_assert(!std::numeric_limits<Data_t>::is_integer, "Floating point type expected");
// just some fancy numbers to be used in the input tensors // just some fancy numbers to be used in the input tensors
@ -349,7 +384,7 @@ std::vector<UniqueParams> params_unique_float() {
std::vector<Data_t>{pi}, std::vector<Data_t>{pi},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<int64_t>{1}, std::vector<Count_t>{1},
nullptr, nullptr,
false}, false},
UniqueParams{Shape{}, UniqueParams{Shape{},
@ -357,7 +392,7 @@ std::vector<UniqueParams> params_unique_float() {
std::vector<Data_t>{pi}, std::vector<Data_t>{pi},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<int64_t>{1}, std::vector<Count_t>{1},
nullptr, nullptr,
true}, true},
UniqueParams{Shape{1}, UniqueParams{Shape{1},
@ -365,7 +400,7 @@ std::vector<UniqueParams> params_unique_float() {
std::vector<Data_t>{-e}, std::vector<Data_t>{-e},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<int64_t>{1}, std::vector<Count_t>{1},
nullptr, nullptr,
false}, false},
UniqueParams{Shape{1}, UniqueParams{Shape{1},
@ -373,7 +408,7 @@ std::vector<UniqueParams> params_unique_float() {
std::vector<Data_t>{-e}, std::vector<Data_t>{-e},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<Index_t>{0}, std::vector<Index_t>{0},
std::vector<int64_t>{1}, std::vector<Count_t>{1},
nullptr, nullptr,
true}, true},
UniqueParams{Shape{6}, UniqueParams{Shape{6},
@ -381,7 +416,7 @@ std::vector<UniqueParams> params_unique_float() {
std::vector<Data_t>{pi, -pi, -e, e, sq3, sq2}, std::vector<Data_t>{pi, -pi, -e, e, sq3, sq2},
std::vector<Index_t>{0, 1, 2, 3, 4, 5}, std::vector<Index_t>{0, 1, 2, 3, 4, 5},
std::vector<Index_t>{0, 1, 2, 3, 4, 5}, std::vector<Index_t>{0, 1, 2, 3, 4, 5},
std::vector<int64_t>{1, 1, 1, 1, 1, 1}, std::vector<Count_t>{1, 1, 1, 1, 1, 1},
nullptr, nullptr,
false, false,
"1D no duplicates"}, "1D no duplicates"},
@ -390,33 +425,52 @@ std::vector<UniqueParams> params_unique_float() {
std::vector<Data_t>{-pi, -e, sq2, sq3, e, pi}, std::vector<Data_t>{-pi, -e, sq2, sq3, e, pi},
std::vector<Index_t>{1, 2, 5, 4, 3, 0}, std::vector<Index_t>{1, 2, 5, 4, 3, 0},
std::vector<Index_t>{5, 0, 1, 4, 3, 2}, std::vector<Index_t>{5, 0, 1, 4, 3, 2},
std::vector<int64_t>{1, 1, 1, 1, 1, 1}, std::vector<Count_t>{1, 1, 1, 1, 1, 1},
nullptr, nullptr,
true, true,
"1D no duplicates"}}; "1D no duplicates"},
UniqueParams{Shape{2, 2, 3},
std::vector<Data_t>{1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6},
std::vector<Data_t>{1, 2, 3, 4, 5, 6},
std::vector<Index_t>{0},
std::vector<Index_t>{0, 0},
std::vector<Count_t>{2},
make_axis(-3),
false,
"3D with duplicates"},
UniqueParams{Shape{2, 2, 3},
std::vector<Data_t>{2, -1, -1, -3, 5, 5, -8, 7, 7, 4, 4, 4},
std::vector<Data_t>{-1, 2, 5, -3, 7, -8, 4, 4},
std::vector<Index_t>{1, 0},
std::vector<Index_t>{1, 0, 0},
std::vector<Count_t>{2, 1},
make_axis(2),
true,
"3D with duplicates (2 & 3), output sorted"}};
return params; return params;
} }
INSTANTIATE_TEST_SUITE_P(smoke_ReferenceUniqueLayerTest_NoAxis, INSTANTIATE_TEST_SUITE_P(
ReferenceUniqueLayerTest_NoAxis, smoke_ReferenceUniqueLayerTest,
::testing::ValuesIn(flatten({params_unique_float<float16, int32_t>(), ReferenceUniqueLayerTest,
params_unique_float<float16, int64_t>(), ::testing::ValuesIn(
params_unique_float<bfloat16, int32_t>(), flatten({params_unique_float<float16, int32_t, int32_t>(), params_unique_float<float16, int32_t, int64_t>(),
params_unique_float<bfloat16, int64_t>(), params_unique_float<float16, int64_t, int32_t>(), params_unique_float<float16, int64_t, int64_t>(),
params_unique_float<float, int32_t>(), params_unique_float<bfloat16, int32_t, int32_t>(), params_unique_float<bfloat16, int32_t, int64_t>(),
params_unique_float<float, int64_t>(), params_unique_float<bfloat16, int64_t, int32_t>(), params_unique_float<bfloat16, int64_t, int64_t>(),
params_unique_float<double, int32_t>(), params_unique_float<float, int32_t, int32_t>(), params_unique_float<float, int32_t, int64_t>(),
params_unique_float<double, int64_t>(), params_unique_float<float, int64_t, int32_t>(), params_unique_float<float, int64_t, int64_t>(),
params_unique_int<int16_t, int32_t>(), params_unique_float<double, int32_t, int32_t>(), params_unique_float<double, int32_t, int64_t>(),
params_unique_int<int8_t, int64_t>(), params_unique_float<double, int64_t, int32_t>(), params_unique_float<double, int64_t, int64_t>(),
params_unique_int<int8_t, int32_t>(), params_unique_int<int16_t, int32_t, int32_t>(), params_unique_int<int16_t, int32_t, int64_t>(),
params_unique_int<int16_t, int64_t>(), params_unique_int<int8_t, int64_t, int32_t>(), params_unique_int<int8_t, int64_t, int64_t>(),
params_unique_int<int32_t, int32_t>(), params_unique_int<int8_t, int32_t, int32_t>(), params_unique_int<int8_t, int32_t, int64_t>(),
params_unique_int<int32_t, int64_t>(), params_unique_int<int16_t, int64_t, int32_t>(), params_unique_int<int16_t, int64_t, int64_t>(),
params_unique_int<int64_t, int32_t>(), params_unique_int<int32_t, int32_t, int32_t>(), params_unique_int<int32_t, int32_t, int64_t>(),
params_unique_int<int64_t, int64_t>()})), params_unique_int<int32_t, int64_t, int32_t>(), params_unique_int<int32_t, int64_t, int64_t>(),
params_unique_int<int64_t, int32_t, int32_t>(), params_unique_int<int64_t, int32_t, int64_t>(),
ReferenceUniqueLayerTest_NoAxis::getTestCaseName); params_unique_int<int64_t, int64_t, int32_t>(), params_unique_int<int64_t, int64_t, int64_t>()})),
ReferenceUniqueLayerTest::getTestCaseName);
} // namespace } // namespace