Skip to content

Commit

Permalink
Revise NotEqual (#7198)
Browse files Browse the repository at this point in the history
* Hiding the problem, Validate() changes 'function'

* Template plugin tests

* Undo the changes that are not necessary

* Align code style

* Added \n at end of file

* Removing an unused implementation

* New version with Code Style checking

* Cleaning backend tests

* Reworked the tests the right way

* Removed visit_attributes()

* Removed visit_attributes() in source file

* Added NGRAPH_CHECK macros to evaluate()

* Removed zero_sized_not_equal mention from unit_test.manifest

* Added function name to the constants.py

* Revert "Added function name to the constants.py"

This reverts commit 5b74780.

* Return visit_attributes() for op::v1::NotEqual due to NotEqual being moved to another location
  • Loading branch information
nsemaev authored Sep 8, 2021
1 parent 5d68e89 commit 3c22b2a
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 64 deletions.
123 changes: 123 additions & 0 deletions docs/template_plugin/tests/functional/op_reference/not_equal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <gtest/gtest.h>

#include <ie_core.hpp>
#include <ie_ngraph_utils.hpp>
#include <ngraph/ngraph.hpp>
#include <shared_test_classes/base/layer_test_utils.hpp>

#include "comparison.hpp"

using namespace ngraph;
using namespace InferenceEngine;
using ComparisonTypes = ngraph::helpers::ComparisonTypes;


namespace reference_tests {
namespace ComparisonOpsRefTestDefinitions {
namespace {

template <element::Type_t IN_ET>
std::vector<RefComparisonParams> generateComparisonParams(const element::Type& type) {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<RefComparisonParams> compParams {
// 1D // 2D // 3D // 4D
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{2, 2}, type, std::vector<T> {1, 0, 10, 255}})
.input2({{2, 2}, type, std::vector<T> {1, 0, 10, 255}})
.expected({{2, 2}, element::boolean, std::vector<char> {0, 0, 0, 0}}),
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{2, 3}, type, std::vector<T> {0, 15, 45, 10, 5, 10}})
.input2({{2, 3}, type, std::vector<T> {1, 15, 5, 10, 50, 10}})
.expected({{2, 3}, element::boolean, std::vector<char> {1, 0, 1, 0, 1, 0}}),
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{1}, type, std::vector<T> {20}})
.input2({{1}, type, std::vector<T> {10}})
.expected({{1}, element::boolean, std::vector<char> {1}}),
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{2, 4}, type, std::vector<T> {0, 12, 23, 0, 1, 5, 12, 8}})
.input2({{2, 4}, type, std::vector<T> {0, 12, 23, 0, 10, 5, 11, 8}})
.expected({{2, 4}, element::boolean, std::vector<char> {0, 0, 0, 0, 1, 0, 1, 0}}),
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{3, 1, 2}, type, std::vector<T> {2, 7, 4, 7, 3, 7}})
.input2({{1, 2, 1}, type, std::vector<T> {7, 7}})
.expected({{3, 2, 2}, element::boolean, std::vector<char> {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0}}),
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{2, 1, 2, 1}, type, std::vector<T> {1, 2, 1, 4}})
.input2({{1, 2, 1}, type, std::vector<T> {1, 1}})
.expected({{2, 1, 2, 1}, element::boolean, std::vector<char> {0, 1, 0, 1}})};
return compParams;
}

std::vector<RefComparisonParams> generateComparisonCombinedParams() {
const std::vector<std::vector<RefComparisonParams>> compTypeParams {
generateComparisonParams<element::Type_t::f32>(element::f32),
generateComparisonParams<element::Type_t::f16>(element::f16),
generateComparisonParams<element::Type_t::i32>(element::i32),
generateComparisonParams<element::Type_t::u32>(element::u32),
generateComparisonParams<element::Type_t::u8>(element::boolean)};
std::vector<RefComparisonParams> combinedParams;

for (const auto& params : compTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}

INSTANTIATE_TEST_SUITE_P(smoke_Comparison_With_Hardcoded_Refs, ReferenceComparisonLayerTest,
::testing::ValuesIn(generateComparisonCombinedParams()),
ReferenceComparisonLayerTest::getTestCaseName);

template <element::Type_t IN_ET>
std::vector<RefComparisonParams> generateNumericParams(const element::Type& type) {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<RefComparisonParams> compParams {
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{4}, type, std::vector<T> {-2.5f, 25.5f, 2.25f, NAN}})
.input2({{4}, type, std::vector<T> {10.0f, 5.0f, 2.25f, 10.0f}})
.expected({{4}, element::boolean, std::vector<char> {1, 1, 0, 1}}),
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{2, 3}, type, std::vector<T> {0.0f, NAN, NAN, 1.0f, 21.0f, -INFINITY}})
.input2({{2, 3}, type, std::vector<T> {1.0f, NAN, 23.0f, 1.0f, 19.0f, 21.0f}})
.expected({{2, 3}, element::boolean, std::vector<char> {1, 1, 1, 0, 1, 1}}),
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{1}, type, std::vector<T> {INFINITY}})
.input2({{1}, type, std::vector<T> {INFINITY}})
.expected({{1}, element::boolean, std::vector<char> {0}}),
Builder {}
.compType(ComparisonTypes::NOT_EQUAL)
.input1({{5}, type, std::vector<T> {-2.5f, 25.5f, 2.25f, INFINITY, 6.0f}})
.input2({{5}, type, std::vector<T> {10.0f, 5.0f, 2.25f, 10.0f, -INFINITY}})
.expected({{5}, element::boolean, std::vector<char> {1, 1, 0, 1, 1}})};
return compParams;
}

std::vector<RefComparisonParams> generateNumericCombinedParams() {
const std::vector<std::vector<RefComparisonParams>> compTypeParams {
generateNumericParams<element::Type_t::f16>(element::f16),
generateNumericParams<element::Type_t::f32>(element::f32)};
std::vector<RefComparisonParams> combinedParams;

for (const auto& params : compTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}

INSTANTIATE_TEST_SUITE_P(smoke_Numeric_With_Hardcoded_Refs, ReferenceComparisonLayerTest, ::testing::ValuesIn(generateNumericCombinedParams()),
ReferenceComparisonLayerTest::getTestCaseName);
} // namespace
} // namespace ComparisonOpsRefTestDefinitions
} // namespace reference_tests
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@
namespace ngraph {
namespace runtime {
namespace reference {
template <typename T>
void not_equal(const T* arg0,
const T* arg1,
char* out,
size_t count) // TODO: using char for bool, is this right?
{
for (size_t i = 0; i < count; i++) {
out[i] = arg0[i] != arg1[i];
}
}

template <typename T, typename U>
void not_equal(const T* arg0,
const T* arg1,
Expand Down
2 changes: 2 additions & 0 deletions ngraph/core/src/op/not_equal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "itt.hpp"
#include "ngraph/runtime/host_tensor.hpp"
#include "ngraph/runtime/reference/not_equal.hpp"
#include "ngraph/validation_util.hpp"

using namespace std;
using namespace ngraph;
Expand Down Expand Up @@ -65,6 +66,7 @@ shared_ptr<Node> op::v1::NotEqual::clone_with_new_inputs(const OutputVector& new

bool op::v1::NotEqual::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const {
NGRAPH_OP_SCOPE(v1_NotEqual_evaluate);
NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2));
return not_equalop::evaluate_not_equal(inputs[0], inputs[1], outputs[0], get_autob());
}

Expand Down
1 change: 0 additions & 1 deletion ngraph/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ set(MULTI_TEST_SRC
backend/bucketize.in.cpp
backend/builder_reduce_ops_opset1.in.cpp
backend/ceiling.in.cpp
backend/comparison.in.cpp
backend/concat.in.cpp
backend/constant.in.cpp
backend/convolution_backprop.in.cpp
Expand Down
47 changes: 0 additions & 47 deletions ngraph/test/backend/comparison.in.cpp

This file was deleted.

4 changes: 0 additions & 4 deletions ngraph/test/backend/zero_sized.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,6 @@ NGRAPH_TEST(${BACKEND_NAME}, zero_sized_multiply) {
make_binary_empty_test<op::v1::Multiply>("${BACKEND_NAME}");
}

NGRAPH_TEST(${BACKEND_NAME}, zero_sized_not_equal) {
make_binary_empty_test<op::v1::NotEqual>("${BACKEND_NAME}", true);
}

NGRAPH_TEST(${BACKEND_NAME}, zero_sized_power) {
make_binary_empty_test<op::v1::Power>("${BACKEND_NAME}");
}
Expand Down
1 change: 0 additions & 1 deletion ngraph/test/runtime/ie/unit_test.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ zero_sized_lesseq
zero_sized_maximum
zero_sized_minimum
zero_sized_multiply
zero_sized_not_equal
zero_sized_power
zero_sized_subtract
sum_trivial
Expand Down

0 comments on commit 3c22b2a

Please sign in to comment.