Revise LogicalOr operation reference implementation (#6867)
* add tests for logical or op * remove redundant overrides * add inputs/outputs tensor check * create type_prop typed test for logical ops * add new line in logical_or.cpp file * refactor logical_and type_prop test * update test labels * beautify or.hpp file * fix formatting to match clang-format * beautifyfunctional test files * move validate_and_infer_elementwise_logical() implementation to validate_and_infer_types() * refactor logial or functional test to * refactor logial aA functional test t * update constants file * add file to instantiate TEST_P and avoid test execution duplication * add missing empty lies at the end of files * remove unused variable
This commit is contained in:
parent
565627a416
commit
2a5584791c
@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "logical.hpp"
|
||||
|
||||
namespace reference_tests {
|
||||
namespace LogicalOpsRefTestDefinitions {
|
||||
namespace {
|
||||
|
||||
TEST_P(ReferenceLogicalLayerTest, LogicalWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace LogicalOpsRefTestDefinitions
|
||||
} // namespace reference_tests
|
@ -0,0 +1,62 @@
|
||||
// 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 <vector>
|
||||
|
||||
#include "base_reference_test.hpp"
|
||||
#include "ngraph_functions/builders.hpp"
|
||||
|
||||
namespace reference_tests {
|
||||
namespace LogicalOpsRefTestDefinitions {
|
||||
|
||||
struct RefLogicalParams {
|
||||
ngraph::helpers::LogicalTypes opType;
|
||||
Tensor input1;
|
||||
Tensor input2;
|
||||
Tensor expected;
|
||||
};
|
||||
|
||||
struct Builder : ParamsBuilder<RefLogicalParams> {
|
||||
REFERENCE_TESTS_ADD_SET_PARAM(Builder, opType);
|
||||
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input1);
|
||||
REFERENCE_TESTS_ADD_SET_PARAM(Builder, input2);
|
||||
REFERENCE_TESTS_ADD_SET_PARAM(Builder, expected);
|
||||
};
|
||||
|
||||
class ReferenceLogicalLayerTest : public testing::TestWithParam<RefLogicalParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
const auto& params = GetParam();
|
||||
function = CreateFunction(params.opType, params.input1.shape, params.input2.shape, params.input1.type);
|
||||
inputData = {params.input1.data, params.input2.data};
|
||||
refOutData = {params.expected.data};
|
||||
}
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<RefLogicalParams>& obj) {
|
||||
const auto& param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "LogicalType=" << param.opType << "_";
|
||||
result << "inpt_shape1=" << param.input1.shape << "_";
|
||||
result << "inpt_shape2=" << param.input2.shape << "_";
|
||||
result << "iType=" << param.input1.type << "_";
|
||||
result << "oType=" << param.expected.type;
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<ngraph::Function> CreateFunction(ngraph::helpers::LogicalTypes op_type, const ngraph::PartialShape& input_shape1,
|
||||
const ngraph::PartialShape& input_shape2, const ngraph::element::Type& elem_type) {
|
||||
const auto in1 = std::make_shared<ngraph::op::Parameter>(elem_type, input_shape1);
|
||||
const auto in2 = std::make_shared<ngraph::op::Parameter>(elem_type, input_shape2);
|
||||
const auto logical_op = ngraph::builder::makeLogical(in1, in2, op_type);
|
||||
return std::make_shared<ngraph::Function>(ngraph::NodeVector {logical_op}, ngraph::ParameterVector {in1, in2});
|
||||
}
|
||||
};
|
||||
} // namespace LogicalOpsRefTestDefinitions
|
||||
} // namespace reference_tests
|
@ -10,74 +10,39 @@
|
||||
#include <shared_test_classes/base/layer_test_utils.hpp>
|
||||
#include <tuple>
|
||||
|
||||
#include "base_reference_test.hpp"
|
||||
#include "logical.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ngraph;
|
||||
using namespace InferenceEngine;
|
||||
using LogicalTypes = ngraph::helpers::LogicalTypes;
|
||||
|
||||
namespace reference_tests {
|
||||
namespace LogicalOpsRefTestDefinitions {
|
||||
namespace {
|
||||
|
||||
struct LogicalAndParams {
|
||||
template <class IT, class OT>
|
||||
LogicalAndParams(const ngraph::PartialShape& input_shape1, const ngraph::PartialShape& input_shape2 ,
|
||||
const std::vector<IT>& iValues1, const std::vector<IT>& iValues2, const std::vector<OT>& oValues)
|
||||
: pshape1(input_shape1), pshape2(input_shape2), inType(ngraph::element::boolean), outType(ngraph::element::boolean),
|
||||
inputData1(CreateBlob(ngraph::element::boolean, iValues1)), inputData2(CreateBlob(ngraph::element::boolean, iValues2)),
|
||||
refData(CreateBlob(ngraph::element::boolean, oValues)) {}
|
||||
ngraph::PartialShape pshape1;
|
||||
ngraph::PartialShape pshape2;
|
||||
ngraph::element::Type inType;
|
||||
ngraph::element::Type outType;
|
||||
InferenceEngine::Blob::Ptr inputData1;
|
||||
InferenceEngine::Blob::Ptr inputData2;
|
||||
InferenceEngine::Blob::Ptr refData;
|
||||
};
|
||||
|
||||
class ReferenceLogicalAndLayerTest : public testing::TestWithParam<LogicalAndParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params.pshape1, params.pshape2, params.inType);
|
||||
inputData = {params.inputData1, params.inputData2};
|
||||
refOutData = {params.refData};
|
||||
}
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<LogicalAndParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "input_shape1=" << param.pshape1 << "_";
|
||||
result << "input_shape2=" << param.pshape2 << "_";
|
||||
result << "iType=" << param.inType << "_";
|
||||
result << "oType=" << param.outType;
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const PartialShape& input_shape1,
|
||||
const PartialShape& input_shape2, const element::Type& input_type) {
|
||||
const auto in = std::make_shared<op::Parameter>(input_type, input_shape1);
|
||||
const auto in2 = std::make_shared<op::Parameter>(input_type, input_shape2);
|
||||
const auto logical_and = std::make_shared<op::v1::LogicalAnd>(in, in2);
|
||||
return std::make_shared<Function>(NodeVector {logical_and}, ParameterVector {in, in2});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceLogicalAndLayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
std::vector<RefLogicalParams> generateLogicalParams() {
|
||||
std::vector<RefLogicalParams> logicalParams {
|
||||
Builder {}
|
||||
.opType(LogicalTypes::LOGICAL_AND)
|
||||
.input1({{2, 2}, element::boolean, std::vector<char> {true, false, true, false}})
|
||||
.input2({{2, 2}, element::boolean, std::vector<char> {false, true, true, false}})
|
||||
.expected({{2, 2}, element::boolean, std::vector<char> {false, false, true, false}}),
|
||||
Builder {}
|
||||
.opType(LogicalTypes::LOGICAL_AND)
|
||||
.input1({{2, 1, 2, 1}, element::boolean, std::vector<char> {true, false, true, false}})
|
||||
.input2({{1, 1, 2, 1}, element::boolean, std::vector<char> {true, false}})
|
||||
.expected({{2, 1, 2, 1}, element::boolean, std::vector<char> {true, false, true, false}}),
|
||||
Builder {}
|
||||
.opType(LogicalTypes::LOGICAL_AND)
|
||||
.input1({{3, 4}, element::boolean, std::vector<char> {true, true, true, true, true, false, true, false, false, true, true, true}})
|
||||
.input2({{3, 4}, element::boolean, std::vector<char> {true, true, true, true, true, false, true, false, false, true, true, false}})
|
||||
.expected({{3, 4}, element::boolean, std::vector<char> {true, true, true, true, true, false, true, false, false, true, true, false}})};
|
||||
return logicalParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_LogicalAnd_With_Hardcoded_Refs, ReferenceLogicalAndLayerTest,
|
||||
::testing::Values(
|
||||
LogicalAndParams(ngraph::PartialShape {2, 2}, ngraph::PartialShape {2, 2},
|
||||
std::vector<char> {true, false, true, false},
|
||||
std::vector<char> {false, true, true, false},
|
||||
std::vector<char> {false, false, true, false}),
|
||||
LogicalAndParams(ngraph::PartialShape {2, 1, 2, 1}, ngraph::PartialShape {1, 1, 2, 1},
|
||||
std::vector<char> {true, false, true, false},
|
||||
std::vector<char> {true, false},
|
||||
std::vector<char> {true, false, true, false}),
|
||||
LogicalAndParams(ngraph::PartialShape {3, 4}, ngraph::PartialShape {3, 4},
|
||||
std::vector<char> {true, true, true, true, true, false, true, false, false, true, true, true},
|
||||
std::vector<char> {true, true, true, true, true, false, true, false, false, true, true, false},
|
||||
std::vector<char> {true, true, true, true, true, false, true, false, false, true, true, false})),
|
||||
ReferenceLogicalAndLayerTest::getTestCaseName);
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LogicalAnd_With_Hardcoded_Refs, ReferenceLogicalLayerTest, ::testing::ValuesIn(generateLogicalParams()),
|
||||
ReferenceLogicalLayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
||||
} // namespace LogicalOpsRefTestDefinitions
|
||||
} // namespace reference_tests
|
||||
|
@ -0,0 +1,48 @@
|
||||
// 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 <tuple>
|
||||
|
||||
#include "logical.hpp"
|
||||
|
||||
using namespace ngraph;
|
||||
using namespace InferenceEngine;
|
||||
using LogicalTypes = ngraph::helpers::LogicalTypes;
|
||||
|
||||
namespace reference_tests {
|
||||
namespace LogicalOpsRefTestDefinitions {
|
||||
namespace {
|
||||
|
||||
std::vector<RefLogicalParams> generateLogicalParams() {
|
||||
std::vector<RefLogicalParams> logicalParams {
|
||||
Builder {}
|
||||
.opType(LogicalTypes::LOGICAL_OR)
|
||||
.input1({{2, 2}, element::boolean, std::vector<char> {true, false, true, false}})
|
||||
.input2({{2, 2}, element::boolean, std::vector<char> {false, true, true, false}})
|
||||
.expected({{2, 2}, element::boolean, std::vector<char> {true, true, true, false}}),
|
||||
Builder {}
|
||||
.opType(LogicalTypes::LOGICAL_OR)
|
||||
.input1({{2, 1, 2, 1}, element::boolean, std::vector<char> {true, false, true, false}})
|
||||
.input2({{1, 1, 2, 1}, element::boolean, std::vector<char> {true, false}})
|
||||
.expected({{2, 1, 2, 1}, element::boolean, std::vector<char> {true, false, true, false}}),
|
||||
Builder {}
|
||||
.opType(LogicalTypes::LOGICAL_OR)
|
||||
.input1({{3, 4}, element::boolean, std::vector<char> {true, true, true, true, true, false, true, false, false, true, true, true}})
|
||||
.input2({{3, 4}, element::boolean, std::vector<char> {true, true, true, true, true, true, true, false, false, true, true, false}})
|
||||
.expected({{3, 4}, element::boolean, std::vector<char> {true, true, true, true, true, true, true, false, false, true, true, true}})};
|
||||
return logicalParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LogicalOr_With_Hardcoded_Refs, ReferenceLogicalLayerTest, ::testing::ValuesIn(generateLogicalParams()),
|
||||
ReferenceLogicalLayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
||||
} // namespace LogicalOpsRefTestDefinitions
|
||||
} // namespace reference_tests
|
@ -59,6 +59,7 @@ VERIFIED_OP_REFERENCES = [
|
||||
'LSTMCell-4',
|
||||
'LSTMSequence-5',
|
||||
'LogicalAnd-1'
|
||||
'LogicalOr-1'
|
||||
'LogSoftmax-5',
|
||||
'Loop-5',
|
||||
'MVN-1',
|
||||
|
@ -61,7 +61,6 @@ namespace ngraph
|
||||
bool visit_attributes(AttributeVisitor& visitor) override;
|
||||
|
||||
private:
|
||||
void validate_and_infer_elementwise_logical(const op::AutoBroadcastSpec& autob);
|
||||
AutoBroadcastSpec m_autob = AutoBroadcastSpec::NUMPY;
|
||||
};
|
||||
} // namespace util
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "ngraph/runtime/host_tensor.hpp"
|
||||
#include "ngraph/runtime/reference/or.hpp"
|
||||
|
||||
#include "ngraph/validation_util.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
@ -54,12 +56,6 @@ namespace logor
|
||||
switch (arg0->get_element_type())
|
||||
{
|
||||
NGRAPH_TYPE_CASE(evaluate_logor, boolean, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_logor, i32, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_logor, i64, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_logor, u32, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_logor, u64, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_logor, f16, arg0, arg1, out, broadcast_spec);
|
||||
NGRAPH_TYPE_CASE(evaluate_logor, f32, arg0, arg1, out, broadcast_spec);
|
||||
default: rc = false; break;
|
||||
}
|
||||
return rc;
|
||||
@ -70,6 +66,7 @@ bool op::v1::LogicalOr::evaluate(const HostTensorVector& outputs,
|
||||
const HostTensorVector& inputs) const
|
||||
{
|
||||
NGRAPH_OP_SCOPE(v1_LogicalOr_evaluate);
|
||||
NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2));
|
||||
return logor::evaluate_logor(inputs[0], inputs[1], outputs[0], get_autob());
|
||||
}
|
||||
|
||||
@ -78,13 +75,7 @@ bool op::v1::LogicalOr::has_evaluate() const
|
||||
NGRAPH_OP_SCOPE(v1_LogicalOr_has_evaluate);
|
||||
switch (get_input_element_type(0))
|
||||
{
|
||||
case ngraph::element::boolean:
|
||||
case ngraph::element::i32:
|
||||
case ngraph::element::i64:
|
||||
case ngraph::element::u32:
|
||||
case ngraph::element::u64:
|
||||
case ngraph::element::f16:
|
||||
case ngraph::element::f32: return true;
|
||||
case ngraph::element::boolean: return true;
|
||||
default: break;
|
||||
}
|
||||
return false;
|
||||
|
@ -22,10 +22,11 @@ op::util::BinaryElementwiseLogical::BinaryElementwiseLogical(const Output<Node>&
|
||||
{
|
||||
}
|
||||
|
||||
void op::util::BinaryElementwiseLogical::validate_and_infer_elementwise_logical(
|
||||
const op::AutoBroadcastSpec& autob)
|
||||
void op::util::BinaryElementwiseLogical::validate_and_infer_types()
|
||||
{
|
||||
auto args_et_pshape = op::util::validate_and_infer_elementwise_args(this, autob);
|
||||
NGRAPH_OP_SCOPE(v0_util_BinaryElementwiseLogical_validate_and_infer_types);
|
||||
|
||||
auto args_et_pshape = op::util::validate_and_infer_elementwise_args(this, m_autob);
|
||||
element::Type& args_et = std::get<0>(args_et_pshape);
|
||||
PartialShape& args_pshape = std::get<1>(args_et_pshape);
|
||||
|
||||
@ -39,12 +40,6 @@ void op::util::BinaryElementwiseLogical::validate_and_infer_elementwise_logical(
|
||||
set_output_type(0, element::boolean, args_pshape);
|
||||
}
|
||||
|
||||
void op::util::BinaryElementwiseLogical::validate_and_infer_types()
|
||||
{
|
||||
NGRAPH_OP_SCOPE(v0_util_BinaryElementwiseLogical_validate_and_infer_types);
|
||||
validate_and_infer_elementwise_logical(m_autob);
|
||||
}
|
||||
|
||||
bool op::util::BinaryElementwiseLogical::visit_attributes(AttributeVisitor& visitor)
|
||||
{
|
||||
NGRAPH_OP_SCOPE(v0_util_BinaryElementwiseLogical_visit_attributes);
|
||||
|
@ -153,6 +153,7 @@ set(SRC
|
||||
type_prop/idft.cpp
|
||||
type_prop/interpolate.cpp
|
||||
type_prop/logical_and.cpp
|
||||
type_prop/logical_or.cpp
|
||||
type_prop/lrn.cpp
|
||||
type_prop/lstm_cell.cpp
|
||||
type_prop/lstm_sequence.cpp
|
||||
@ -456,7 +457,6 @@ set(MULTI_TEST_SRC
|
||||
backend/log.in.cpp
|
||||
backend/log_softmax.in.cpp
|
||||
backend/logical_not.in.cpp
|
||||
backend/logical_or.in.cpp
|
||||
backend/logical_xor.in.cpp
|
||||
backend/lrn.in.cpp
|
||||
backend/matmul.in.cpp
|
||||
|
@ -1,33 +0,0 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#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}, logical_or)
|
||||
{
|
||||
Shape shape{2, 2, 2};
|
||||
auto A = make_shared<op::Parameter>(element::boolean, shape);
|
||||
auto B = make_shared<op::Parameter>(element::boolean, shape);
|
||||
auto f = make_shared<Function>(make_shared<op::v1::LogicalOr>(A, B), ParameterVector{A, B});
|
||||
|
||||
std::vector<char> a{1, 0, 1, 1, 1, 0, 1, 0};
|
||||
std::vector<char> b{0, 0, 1, 0, 0, 1, 1, 0};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_multiple_inputs<char>({a, b});
|
||||
test_case.add_expected_output<char>(shape, {1, 0, 1, 1, 1, 1, 1, 0});
|
||||
test_case.run();
|
||||
}
|
@ -485,7 +485,6 @@ IE_CPU.onnx_roi_align_f32
|
||||
# [NOT_IMPLEMENTED] Input image format BOOL is not supported yet...
|
||||
not
|
||||
logical_xor
|
||||
logical_or
|
||||
logical_and
|
||||
gather_axis_0_bool
|
||||
auto_bcast_binary_elementwise
|
||||
|
@ -2,71 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "logical_ops.hpp"
|
||||
#include "util/type_prop.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
using Type =
|
||||
::testing::Types<LogicalOperatorType<ngraph::op::v1::LogicalAnd, ngraph::element::boolean>>;
|
||||
|
||||
namespace {
|
||||
void incorrect_init(const ngraph::element::Type& type, const std::string& err, const Shape& shape1 = {1, 3, 6}, const Shape& shape2 = {1, 3, 6}) {
|
||||
auto input1 = make_shared<op::Parameter>(type, shape1);
|
||||
auto input2 = make_shared<op::Parameter>(type, shape2);
|
||||
try
|
||||
{
|
||||
auto logical_and = make_shared<op::v1::LogicalAnd>(input1, input2);
|
||||
}
|
||||
catch (const NodeValidationFailure& error)
|
||||
{
|
||||
EXPECT_HAS_SUBSTRING(error.what(), err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(type_prop, logical_and_incorrect_type_f32)
|
||||
{
|
||||
incorrect_init(element::f32, "Operands for logical operators must have boolean element type but have element type f32");
|
||||
}
|
||||
|
||||
TEST(type_prop, logical_and_incorrect_type_f64)
|
||||
{
|
||||
incorrect_init(element::f64, "Operands for logical operators must have boolean element type but have element type f64");
|
||||
}
|
||||
|
||||
TEST(type_prop, logical_and_incorrect_type_i32)
|
||||
{
|
||||
incorrect_init(element::i32, "Operands for logical operators must have boolean element type but have element type i32");
|
||||
}
|
||||
|
||||
TEST(type_prop, logical_and_incorrect_type_i64)
|
||||
{
|
||||
incorrect_init(element::i64, "Operands for logical operators must have boolean element type but have element type i64");
|
||||
}
|
||||
|
||||
TEST(type_prop, logical_and_incorrect_type_u32)
|
||||
{
|
||||
incorrect_init(element::u32, "Operands for logical operators must have boolean element type but have element type u32");
|
||||
}
|
||||
|
||||
TEST(type_prop, logical_and_incorrect_type_u64)
|
||||
{
|
||||
incorrect_init(element::u64, "Operands for logical operators must have boolean element type but have element type u64");
|
||||
|
||||
}
|
||||
|
||||
TEST(type_prop, logical_and_incorrect_shape)
|
||||
{
|
||||
incorrect_init(element::boolean, "Argument shapes are inconsistent", Shape {1, 3, 6}, Shape {1, 2, 3});
|
||||
}
|
||||
|
||||
TEST(type_prop, logical_and_broadcast)
|
||||
{
|
||||
auto input1 = make_shared<op::Parameter>(element::boolean, Shape{1, 1, 6});
|
||||
auto input2 = make_shared<op::Parameter>(element::boolean, Shape{1, 3, 1});
|
||||
|
||||
auto logical_and = make_shared<op::v1::LogicalAnd>(input1, input2);
|
||||
|
||||
ASSERT_EQ(logical_and->get_element_type(), element::boolean);
|
||||
ASSERT_EQ(logical_and->get_shape(), (Shape{1, 3, 6}));
|
||||
}
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Type_prop_test,
|
||||
LogicalOperatorTypeProp,
|
||||
Type,
|
||||
LogicalOperatorTypeName);
|
||||
|
139
ngraph/test/type_prop/logical_ops.hpp
Normal file
139
ngraph/test/type_prop/logical_ops.hpp
Normal file
@ -0,0 +1,139 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "util/type_prop.hpp"
|
||||
|
||||
template <typename T, ngraph::element::Type_t ELEMENT_TYPE>
|
||||
class LogicalOperatorType
|
||||
{
|
||||
public:
|
||||
using op_type = T;
|
||||
static constexpr ngraph::element::Type_t element_type = ELEMENT_TYPE;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class LogicalOperatorTypeProp : public testing::Test
|
||||
{
|
||||
};
|
||||
|
||||
class LogicalOperatorTypeName
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int)
|
||||
{
|
||||
using OP_Type = typename T::op_type;
|
||||
const ngraph::Node::type_info_t typeinfo = OP_Type::get_type_info_static();
|
||||
return typeinfo.name;
|
||||
}
|
||||
};
|
||||
|
||||
TYPED_TEST_SUITE_P(LogicalOperatorTypeProp);
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T>
|
||||
void incorrect_init(const ngraph::element::Type& type,
|
||||
const std::string& err,
|
||||
const ngraph::Shape& shape1 = {1, 3, 6},
|
||||
const ngraph::Shape& shape2 = {1, 3, 6})
|
||||
{
|
||||
auto input1 = std::make_shared<ngraph::op::Parameter>(type, shape1);
|
||||
auto input2 = std::make_shared<ngraph::op::Parameter>(type, shape2);
|
||||
try
|
||||
{
|
||||
auto op = std::make_shared<T>(input1, input2);
|
||||
}
|
||||
catch (const ngraph::NodeValidationFailure& error)
|
||||
{
|
||||
EXPECT_HAS_SUBSTRING(error.what(), err);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TYPED_TEST_P(LogicalOperatorTypeProp, incorrect_type_f32)
|
||||
{
|
||||
using OP_Type = typename TypeParam::op_type;
|
||||
incorrect_init<OP_Type>(
|
||||
ngraph::element::f32,
|
||||
"Operands for logical operators must have boolean element type but have element type f32");
|
||||
}
|
||||
|
||||
TYPED_TEST_P(LogicalOperatorTypeProp, incorrect_type_f64)
|
||||
{
|
||||
using OP_Type = typename TypeParam::op_type;
|
||||
incorrect_init<OP_Type>(
|
||||
ngraph::element::f64,
|
||||
"Operands for logical operators must have boolean element type but have element type f64");
|
||||
}
|
||||
|
||||
TYPED_TEST_P(LogicalOperatorTypeProp, incorrect_type_i32)
|
||||
{
|
||||
using OP_Type = typename TypeParam::op_type;
|
||||
incorrect_init<OP_Type>(
|
||||
ngraph::element::i32,
|
||||
"Operands for logical operators must have boolean element type but have element type i32");
|
||||
}
|
||||
|
||||
TYPED_TEST_P(LogicalOperatorTypeProp, incorrect_type_i64)
|
||||
{
|
||||
using OP_Type = typename TypeParam::op_type;
|
||||
incorrect_init<OP_Type>(
|
||||
ngraph::element::i64,
|
||||
"Operands for logical operators must have boolean element type but have element type i64");
|
||||
}
|
||||
|
||||
TYPED_TEST_P(LogicalOperatorTypeProp, incorrect_type_u32)
|
||||
{
|
||||
using OP_Type = typename TypeParam::op_type;
|
||||
incorrect_init<OP_Type>(
|
||||
ngraph::element::u32,
|
||||
"Operands for logical operators must have boolean element type but have element type u32");
|
||||
}
|
||||
|
||||
TYPED_TEST_P(LogicalOperatorTypeProp, incorrect_type_u64)
|
||||
{
|
||||
using OP_Type = typename TypeParam::op_type;
|
||||
incorrect_init<OP_Type>(
|
||||
ngraph::element::u64,
|
||||
"Operands for logical operators must have boolean element type but have element type u64");
|
||||
}
|
||||
|
||||
TYPED_TEST_P(LogicalOperatorTypeProp, incorrect_shape)
|
||||
{
|
||||
using OP_Type = typename TypeParam::op_type;
|
||||
incorrect_init<OP_Type>(ngraph::element::boolean,
|
||||
"Argument shapes are inconsistent",
|
||||
ngraph::Shape{1, 3, 6},
|
||||
ngraph::Shape{1, 2, 3});
|
||||
}
|
||||
|
||||
TYPED_TEST_P(LogicalOperatorTypeProp, broadcast)
|
||||
{
|
||||
using OP_Type = typename TypeParam::op_type;
|
||||
|
||||
auto input1 =
|
||||
std::make_shared<ngraph::op::Parameter>(ngraph::element::boolean, ngraph::Shape{1, 1, 6});
|
||||
auto input2 =
|
||||
std::make_shared<ngraph::op::Parameter>(ngraph::element::boolean, ngraph::Shape{1, 3, 1});
|
||||
|
||||
auto logical_and = std::make_shared<OP_Type>(input1, input2);
|
||||
|
||||
ASSERT_EQ(logical_and->get_element_type(), ngraph::element::boolean);
|
||||
ASSERT_EQ(logical_and->get_shape(), (ngraph::Shape{1, 3, 6}));
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(LogicalOperatorTypeProp,
|
||||
broadcast,
|
||||
incorrect_type_f32,
|
||||
incorrect_type_f64,
|
||||
incorrect_type_i32,
|
||||
incorrect_type_i64,
|
||||
incorrect_type_u32,
|
||||
incorrect_type_u64,
|
||||
incorrect_shape);
|
14
ngraph/test/type_prop/logical_or.cpp
Normal file
14
ngraph/test/type_prop/logical_or.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "logical_ops.hpp"
|
||||
#include "util/type_prop.hpp"
|
||||
|
||||
using Type =
|
||||
::testing::Types<LogicalOperatorType<ngraph::op::v1::LogicalOr, ngraph::element::boolean>>;
|
||||
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Type_prop_test,
|
||||
LogicalOperatorTypeProp,
|
||||
Type,
|
||||
LogicalOperatorTypeName);
|
Loading…
Reference in New Issue
Block a user