Revise logical not (#6942)

* update spec

* remove backend tests and create op_reference test

* add logicalNot to constants

* add NGRAPH CHECK for number of inputs and outputs

* create type_prop tests

* create visitor test

* add type_op and visitor tests to CMakeLists

* remove backend test from CMakeList

* update T to T_BOOL

* update outputs part in spec

* fix type in the spec

* fixed conflicts in CMakeList

* update ReferenceLogicalLayerTest to also work with unary logical operator

* update logical_not op_reference test to use ReferenceLogicalLayerTest

* fix style

* fix style

* resolve conflict

* resolve conflict

* remove typo

* fix style

* Update ReferenceLogicalLayerTest class tto take input as a vector

* Create makeLogical function that takes ParameterVector as parameter

* update op_reference logical tests to take input as a vector

* Replace elem_type with input.type

* update getTestCaseName method
This commit is contained in:
Piotr Szmelczynski
2021-08-27 05:55:19 +02:00
committed by GitHub
parent 4ef700c6e4
commit 81c8cd711b
14 changed files with 179 additions and 114 deletions

View File

@@ -156,6 +156,7 @@ set(SRC
type_prop/idft.cpp
type_prop/interpolate.cpp
type_prop/logical_and.cpp
type_prop/logical_not.cpp
type_prop/logical_or.cpp
type_prop/logical_xor.cpp
type_prop/lrn.cpp
@@ -282,6 +283,7 @@ set(SRC
visitors/op/log.cpp
visitors/op/logical_and.cpp
visitors/op/logical_or.cpp
visitors/op/logical_not.cpp
visitors/op/logical_xor.cpp
visitors/op/lrn.cpp
visitors/op/lstm_cell.cpp
@@ -459,7 +461,6 @@ set(MULTI_TEST_SRC
backend/interpolate.in.cpp
backend/log.in.cpp
backend/log_softmax.in.cpp
backend/logical_not.in.cpp
backend/lrn.in.cpp
backend/matmul.in.cpp
backend/matrix_nms.in.cpp

View File

@@ -1,59 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <random>
#include <string>
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/engine/test_engines.hpp"
#include "util/test_case.hpp"
#include "util/test_control.hpp"
NGRAPH_SUPPRESS_DEPRECATED_START
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, not) {
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::boolean, shape);
auto f = make_shared<Function>(make_shared<op::v1::LogicalNot>(A), ParameterVector{A});
std::vector<char> a{1, 0, 1, 0};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<char>(shape, a);
test_case.add_expected_output<char>(shape, {0, 1, 0, 1});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, not_i32) {
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::v1::LogicalNot>(A), ParameterVector{A});
std::vector<int32_t> a{1, 0, 2, 0};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<int32_t>(shape, a);
test_case.add_expected_output<int32_t>(shape, {0, 1, 0, 1});
}

View File

@@ -0,0 +1,49 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/type_prop.hpp"
using namespace std;
using namespace ngraph;
namespace {
void type_check(const ngraph::element::Type& type) {
auto input = make_shared<op::Parameter>(type, Shape{1, 3, 6});
auto logical_not = make_shared<op::v1::LogicalNot>(input);
ASSERT_EQ(logical_not->get_element_type(), type);
}
} // namespace
TEST(type_prop, logical_not_i32) {
type_check(element::i32);
}
TEST(type_prop, logical_not_i64) {
type_check(element::i64);
}
TEST(type_prop, logical_not_u32) {
type_check(element::u32);
}
TEST(type_prop, logical_not_u64) {
type_check(element::u64);
}
TEST(type_prop, logical_not_f16) {
type_check(element::f16);
}
TEST(type_prop, logical_not_f32) {
type_check(element::f32);
}
TEST(type_prop, logical_not_shape_inference) {
auto input = make_shared<op::Parameter>(element::boolean, Shape{1, 3, 6});
auto logical_not = make_shared<op::v1::LogicalNot>(input);
ASSERT_EQ(logical_not->get_shape(), (Shape{1, 3, 6}));
}

View File

@@ -0,0 +1,9 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "unary_ops.hpp"
using Type = ::testing::Types<UnaryOperatorType<ngraph::op::v1::LogicalNot, ngraph::element::boolean>>;
INSTANTIATE_TYPED_TEST_SUITE_P(visitor_without_attribute, UnaryOperatorVisitor, Type, UnaryOperatorTypeName);