From 1bdb547e3d7ce5175ecc2a954c25cf49cc0d4be0 Mon Sep 17 00:00:00 2001 From: pszmel Date: Wed, 21 Jul 2021 11:22:54 +0200 Subject: [PATCH 01/21] update docs --- docs/ops/logical/LogicalAnd_1.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/ops/logical/LogicalAnd_1.md b/docs/ops/logical/LogicalAnd_1.md index 4f39b236fefbb7..d1f0d683911ac4 100644 --- a/docs/ops/logical/LogicalAnd_1.md +++ b/docs/ops/logical/LogicalAnd_1.md @@ -6,6 +6,14 @@ **Short description**: *LogicalAnd* performs element-wise logical AND operation with two given tensors applying multi-directional broadcast rules. +**Detailed description**: Before performing logical operation, input tensors *a* and *b* are broadcasted if their shapes are different and `auto_broadcast` attributes is not `none`. Broadcasting is performed according to `auto_broadcast` value. + +After broadcasting *LogicalAnd* does the following with the input tensors *a* and *b*: + +\f[ +o_{i} = a_{i} and b_{i} +\f] + **Attributes**: * *auto_broadcast* @@ -20,25 +28,17 @@ **Inputs** -* **1**: A tensor of type *T*. **Required.** -* **2**: A tensor of type *T*. **Required.** +* **1**: A tensor of type *T* and arbitrary shape. **Required.** +* **2**: A tensor of type *T* and arbitrary shape. **Required.** **Outputs** -* **1**: The result of element-wise logical AND operation. A tensor of type boolean. +* **1**: The result of element-wise *LogicalAnd* operation. A tensor of type boolean. **Types** * *T*: boolean type. -**Detailed description** -Before performing logical operation, input tensors *a* and *b* are broadcasted if their shapes are different and `auto_broadcast` attributes is not `none`. Broadcasting is performed according to `auto_broadcast` value. - -After broadcasting *LogicalAnd* does the following with the input tensors *a* and *b*: - -\f[ -o_{i} = a_{i} and b_{i} -\f] **Examples** From c476ddab22dbe493cf4d3b330da459ec56bd25c6 Mon Sep 17 00:00:00 2001 From: pszmel Date: Wed, 21 Jul 2021 11:23:40 +0200 Subject: [PATCH 02/21] add host tensors validation --- ngraph/core/src/op/and.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ngraph/core/src/op/and.cpp b/ngraph/core/src/op/and.cpp index 4c81190083b95c..5da74d6fbe9665 100644 --- a/ngraph/core/src/op/and.cpp +++ b/ngraph/core/src/op/and.cpp @@ -7,6 +7,8 @@ #include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/reference/and.hpp" +#include "ngraph/validation_util.hpp" + using namespace std; using namespace ngraph; @@ -77,6 +79,7 @@ bool op::v1::LogicalAnd::evaluate(const HostTensorVector& outputs, const HostTensorVector& inputs) const { NGRAPH_OP_SCOPE(v1_LogicalAnd_evaluate); + NGRAPH_CHECK(validate_host_tensor_vector(outputs, 1) && validate_host_tensor_vector(inputs, 2)); return logand::evaluate_logand(inputs[0], inputs[1], outputs[0], get_autob()); } From ad7b50e91e1ad69da9d34abb24e8e80df19dbc23 Mon Sep 17 00:00:00 2001 From: pszmel Date: Wed, 21 Jul 2021 11:25:14 +0200 Subject: [PATCH 03/21] create type_prop tests --- ngraph/test/CMakeLists.txt | 4 +- ngraph/test/type_prop/logical_and.cpp | 127 ++++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 ngraph/test/type_prop/logical_and.cpp diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index cc265ed2456cf1..8e923748915ab0 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -151,12 +151,13 @@ set(SRC type_prop/hswish.cpp type_prop/idft.cpp type_prop/interpolate.cpp + type_prop/logical_and.cpp type_prop/lrn.cpp type_prop/lstm_cell.cpp type_prop/lstm_sequence.cpp type_prop/loop.cpp type_prop/matmul.cpp - type_prop/matrix_nms.cpp + type_prop/matrix_nms.cpp type_prop/maximum.cpp type_prop/max_pool.cpp type_prop/minimum.cpp @@ -259,6 +260,7 @@ set(SRC visitors/op/group_conv.cpp visitors/op/interpolate.cpp visitors/op/log.cpp + visitors/op/logical_and.cpp visitors/op/logical_xor.cpp visitors/op/lrn.cpp visitors/op/lstm_cell.cpp diff --git a/ngraph/test/type_prop/logical_and.cpp b/ngraph/test/type_prop/logical_and.cpp new file mode 100644 index 00000000000000..c3c692bc94e22f --- /dev/null +++ b/ngraph/test/type_prop/logical_and.cpp @@ -0,0 +1,127 @@ +// 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; + +TEST(type_prop, logical_and_incorrect_type_f32) +{ + auto input1 = make_shared(element::f32, Shape{1, 3, 6}); + auto input2 = make_shared(element::f32, Shape{1, 3, 6}); + try + { + auto logical_and = make_shared(input1, input2); + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Operands for logical operators must have boolean element type but have element type f32")); + } + +} + +TEST(type_prop, logical_and_incorrect_type_f64) +{ + auto input1 = make_shared(element::f64, Shape{1, 3, 6}); + auto input2 = make_shared(element::f64, Shape{1, 3, 6}); + try + { + auto logical_and = make_shared(input1, input2); + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Operands for logical operators must have boolean element type but have element type f64")); + } +} + +TEST(type_prop, logical_and_incorrect_type_i32) +{ + auto input1 = make_shared(element::i32, Shape{1, 3, 6}); + auto input2 = make_shared(element::i32, Shape{1, 3, 6}); + try + { + auto logical_and = make_shared(input1, input2); + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Operands for logical operators must have boolean element type but have element type i32")); + } +} + +TEST(type_prop, logical_and_incorrect_type_i64) +{ + auto input1 = make_shared(element::i64, Shape{1, 3, 6}); + auto input2 = make_shared(element::i64, Shape{1, 3, 6}); + try + { + auto logical_and = make_shared(input1, input2); + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Operands for logical operators must have boolean element type but have element type i64")); + } +} + +TEST(type_prop, logical_and_incorrect_type_u32) +{ + auto input1 = make_shared(element::u32, Shape{1, 3, 6}); + auto input2 = make_shared(element::u32, Shape{1, 3, 6}); + try + { + auto logical_and = make_shared(input1, input2); + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Operands for logical operators must have boolean element type but have element type u32")); + } +} + +TEST(type_prop, logical_and_incorrect_type_u64) +{ + auto input1 = make_shared(element::u64, Shape{1, 3, 6}); + auto input2 = make_shared(element::u64, Shape{1, 3, 6}); + try + { + auto logical_and = make_shared(input1, input2); + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Operands for logical operators must have boolean element type but have element type u64")); + } +} + +TEST(type_prop, logical_and_incorrect_shape) +{ + auto input1 = make_shared(element::boolean, Shape{1, 3, 6}); + auto input2 = make_shared(element::boolean, Shape{1, 2, 6}); + try + { + auto logical_and = make_shared(input1, input2); + } + catch (const NodeValidationFailure& error) + { + EXPECT_HAS_SUBSTRING(error.what(), + std::string("Argument shapes are inconsistent")); + } +} + +TEST(type_prop, logical_and_broadcast) +{ + auto input1 = make_shared(element::boolean, Shape{1, 1, 6}); + auto input2 = make_shared(element::boolean, Shape{1, 3, 1}); + + auto logical_and = make_shared(input1, input2); + + ASSERT_EQ(logical_and->get_element_type(), element::boolean); + ASSERT_EQ(logical_and->get_shape(), (Shape{1, 3, 6})); +} From 364495285844c0b328c13aa707ca51c676bdd71d Mon Sep 17 00:00:00 2001 From: pszmel Date: Wed, 21 Jul 2021 11:26:02 +0200 Subject: [PATCH 04/21] create serialization single layer test --- .../serialization/single_layer/logical.cpp | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 inference-engine/tests/functional/inference_engine/serialization/single_layer/logical.cpp diff --git a/inference-engine/tests/functional/inference_engine/serialization/single_layer/logical.cpp b/inference-engine/tests/functional/inference_engine/serialization/single_layer/logical.cpp new file mode 100644 index 00000000000000..48424131944fb2 --- /dev/null +++ b/inference-engine/tests/functional/inference_engine/serialization/single_layer/logical.cpp @@ -0,0 +1,84 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "shared_test_classes/single_layer/logical.hpp" +#include "common_test_utils/test_constants.hpp" + +using namespace LayerTestsDefinitions; +using namespace LayerTestsDefinitions::LogicalParams; + +namespace { +TEST_P(LogicalLayerTest, Serialize) { + Serialize(); +} + +std::map, std::vector>> inputShapes = { + {{1}, {{1}, {17}, {1, 1}, {2, 18}, {1, 1, 2}, {2, 2, 3}, {1, 1, 2, 3}}}, + {{5}, {{1}, {1, 1}, {2, 5}, {1, 1, 1}, {2, 2, 5}}}, + {{2, 200}, {{1}, {200}, {1, 200}, {2, 200}, {2, 2, 200}}}, + {{1, 3, 20}, {{20}, {2, 1, 1}}}, + {{2, 17, 3, 4}, {{4}, {1, 3, 4}, {2, 1, 3, 4}}}, + {{2, 1, 1, 3, 1}, {{1}, {1, 3, 4}, {2, 1, 3, 4}, {1, 1, 1, 1, 1}}}, +}; + +std::map, std::vector>> inputShapesNot = { + {{1}, {}}, + {{5}, {}}, + {{2, 200}, {}}, + {{1, 3, 20}, {}}, + {{2, 17, 3, 4}, {}}, + {{2, 1, 1, 3, 1}, {}}, +}; + +std::vector inputsPrecisions = { + InferenceEngine::Precision::BOOL, +}; + +std::vector logicalOpTypes = { + ngraph::helpers::LogicalTypes::LOGICAL_AND, + ngraph::helpers::LogicalTypes::LOGICAL_OR, + ngraph::helpers::LogicalTypes::LOGICAL_XOR, +}; + +std::vector secondInputTypes = { + ngraph::helpers::InputLayerType::CONSTANT, + ngraph::helpers::InputLayerType::PARAMETER, +}; + +std::vector netPrecisions = { + InferenceEngine::Precision::FP32, +}; + +std::map additional_config = {}; + +const auto LogicalTestParams = ::testing::Combine( + ::testing::ValuesIn(LogicalLayerTest::combineShapes(inputShapes)), + ::testing::ValuesIn(logicalOpTypes), + ::testing::ValuesIn(secondInputTypes), + ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(inputsPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(additional_config)); + +const auto LogicalTestParamsNot = ::testing::Combine( + ::testing::ValuesIn(LogicalLayerTest::combineShapes(inputShapesNot)), + ::testing::Values(ngraph::helpers::LogicalTypes::LOGICAL_NOT), + ::testing::Values(ngraph::helpers::InputLayerType::CONSTANT), + ::testing::ValuesIn(netPrecisions), + ::testing::ValuesIn(inputsPrecisions), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(InferenceEngine::Layout::ANY), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(additional_config)); + +INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, LogicalLayerTest, LogicalTestParams, LogicalLayerTest::getTestCaseName); + +INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefsNot, LogicalLayerTest, LogicalTestParamsNot, LogicalLayerTest::getTestCaseName); + +} // namespace From d1527c6e38378316f9a84e32b52b353a169c8b27 Mon Sep 17 00:00:00 2001 From: pszmel Date: Wed, 21 Jul 2021 11:27:31 +0200 Subject: [PATCH 05/21] create visitor test --- ngraph/test/visitors/op/logical_and.cpp | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ngraph/test/visitors/op/logical_and.cpp diff --git a/ngraph/test/visitors/op/logical_and.cpp b/ngraph/test/visitors/op/logical_and.cpp new file mode 100644 index 00000000000000..a8fc5e74c81b31 --- /dev/null +++ b/ngraph/test/visitors/op/logical_and.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "gtest/gtest.h" + +#include "ngraph/ngraph.hpp" +#include "ngraph/op/util/attr_types.hpp" +#include "ngraph/opsets/opset1.hpp" + + +#include "util/visitor.hpp" + +using namespace std; +using namespace ngraph; +using ngraph::test::NodeBuilder; +using ngraph::test::ValueMap; + +TEST(attributes, logical_and_op) +{ + NodeBuilder::get_ops().register_factory(); + auto x1 = make_shared(element::boolean, Shape{200}); + auto x2 = make_shared(element::boolean, Shape{200}); + + auto auto_broadcast = op::AutoBroadcastType::NUMPY; + + auto logical_and = make_shared(x1, x2, auto_broadcast); + NodeBuilder builder(logical_and); + auto g_logical_and = as_type_ptr(builder.create()); + + EXPECT_EQ(g_logical_and->get_autob(), logical_and->get_autob()); +} From dec1cec876b6c111c62d1590167d17fe1b6922e5 Mon Sep 17 00:00:00 2001 From: pszmel Date: Wed, 21 Jul 2021 11:27:59 +0200 Subject: [PATCH 06/21] create op_reference test --- .../functional/op_reference/logical_and.cpp | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 docs/template_plugin/tests/functional/op_reference/logical_and.cpp diff --git a/docs/template_plugin/tests/functional/op_reference/logical_and.cpp b/docs/template_plugin/tests/functional/op_reference/logical_and.cpp new file mode 100644 index 00000000000000..3256776d4d124b --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/logical_and.cpp @@ -0,0 +1,97 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include +#include +#include + +#include "base_reference_test.hpp" + +using namespace ngraph; +using namespace InferenceEngine; + +namespace { +struct LogicalAndParams { + template + LogicalAndParams(const ngraph::PartialShape& input_shape1, const ngraph::PartialShape& input_shape2 , const ngraph::element::Type& iType, + const ngraph::element::Type& oType, const std::vector& iValues1, const std::vector& iValues2, const std::vector& oValues) + : pshape1(input_shape1), pshape2(input_shape2), inType(iType), outType(oType), inputData1(CreateBlob(iType, iValues1)), + inputData2(CreateBlob(iType, iValues2)), refData(CreateBlob(oType, 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, 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& 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 CreateFunction(const PartialShape& input_shape1, const PartialShape& input_shape2, const element::Type& input_type) { + const auto in = std::make_shared(input_type, input_shape1); + const auto in2 = std::make_shared(input_type, input_shape2); + const auto logical_and = std::make_shared(in, in2); + return std::make_shared(NodeVector {logical_and}, ParameterVector {in, in2}); + } +}; + +TEST_P(ReferenceLogicalAndLayerTest, CompareWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateLogicalAndParams(const ngraph::element::Type& type) { + using T = typename element_type_traits::value_type; + std::vector logicalAndParams { + // 1D // 2D // 3D // 4D + LogicalAndParams(ngraph::PartialShape {2, 2}, ngraph::PartialShape {2, 2}, type, ngraph::element::boolean, + std::vector {1, 0, 1, 0}, + std::vector {0, 1, 1, 0}, + std::vector {0, 0, 1, 0}), + LogicalAndParams(ngraph::PartialShape {1}, ngraph::PartialShape {1}, type, ngraph::element::boolean, + std::vector {1}, + std::vector {1}, + std::vector {1}), + + LogicalAndParams(ngraph::PartialShape {2, 1, 2, 1}, ngraph::PartialShape {1, 1, 2, 1}, type, ngraph::element::boolean, + std::vector {1, 0, 1, 0}, + std::vector {1, 0}, + std::vector {1, 0, 1, 0})}; + return logicalAndParams; +} + +std::vector generateLogicalAndCombinedParams() { + const std::vector> logicalAndTypeParams {generateLogicalAndParams(ngraph::element::boolean)}; + std::vector combinedParams; + std::for_each(logicalAndTypeParams.begin(), logicalAndTypeParams.end(), [&](std::vector params) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + }); + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P(smoke_LogicalAnd_With_Hardcoded_Refs, ReferenceLogicalAndLayerTest, ::testing::ValuesIn(generateLogicalAndCombinedParams()), + ReferenceLogicalAndLayerTest::getTestCaseName); +} // namespace From bdf9cf7f2e5a374b5dc701c83824503e4fa13295 Mon Sep 17 00:00:00 2001 From: pszmel Date: Wed, 21 Jul 2021 11:28:29 +0200 Subject: [PATCH 07/21] add logicalAnd to constants.py --- .../functional_test_utils/layer_tests_summary/utils/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py index a90c904a83cfe2..6d021448cd2e39 100644 --- a/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py +++ b/inference-engine/tests/ie_test_utils/functional_test_utils/layer_tests_summary/utils/constants.py @@ -52,6 +52,7 @@ 'LRN-1', 'LSTMCell-4', 'LSTMSequence-5', + 'LogicalAnd-1' 'LogSoftmax-5', 'Loop-5', 'MVN-6', From b424abe254b6333de4379f36b03bd402e76d92e2 Mon Sep 17 00:00:00 2001 From: pszmel Date: Wed, 21 Jul 2021 12:09:42 +0200 Subject: [PATCH 08/21] create additional op_reference tests --- .../functional/op_reference/logical_and.cpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/template_plugin/tests/functional/op_reference/logical_and.cpp b/docs/template_plugin/tests/functional/op_reference/logical_and.cpp index 3256776d4d124b..9a2196d6c4dcd4 100644 --- a/docs/template_plugin/tests/functional/op_reference/logical_and.cpp +++ b/docs/template_plugin/tests/functional/op_reference/logical_and.cpp @@ -68,18 +68,22 @@ std::vector generateLogicalAndParams(const ngraph::element::Ty std::vector logicalAndParams { // 1D // 2D // 3D // 4D LogicalAndParams(ngraph::PartialShape {2, 2}, ngraph::PartialShape {2, 2}, type, ngraph::element::boolean, - std::vector {1, 0, 1, 0}, - std::vector {0, 1, 1, 0}, - std::vector {0, 0, 1, 0}), + std::vector {true, false, true, false}, + std::vector {false, true, true, false}, + std::vector {false, false, true, false}), LogicalAndParams(ngraph::PartialShape {1}, ngraph::PartialShape {1}, type, ngraph::element::boolean, - std::vector {1}, - std::vector {1}, - std::vector {1}), + std::vector {true}, + std::vector {true}, + std::vector {true}), LogicalAndParams(ngraph::PartialShape {2, 1, 2, 1}, ngraph::PartialShape {1, 1, 2, 1}, type, ngraph::element::boolean, - std::vector {1, 0, 1, 0}, - std::vector {1, 0}, - std::vector {1, 0, 1, 0})}; + std::vector {true, false, true, false}, + std::vector {true, false}, + std::vector {true, false, true, false}), + LogicalAndParams(ngraph::PartialShape {3, 4}, ngraph::PartialShape {3, 4}, type, ngraph::element::boolean, + std::vector {true, true, true, true, true, false, true, false, false, true, true, true}, + std::vector {true, true, true, true, true, false, true, false, false, true, true, false}, + std::vector {true, true, true, true, true, false, true, false, false, true, true, false})}; return logicalAndParams; } From 884ca76db7934be74bb2f6fc24d1df78015203a9 Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 26 Jul 2021 12:27:07 +0200 Subject: [PATCH 09/21] add check for number of visited attributes in visitor test --- ngraph/test/visitors/op/logical_and.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ngraph/test/visitors/op/logical_and.cpp b/ngraph/test/visitors/op/logical_and.cpp index a8fc5e74c81b31..eff336d6c3c5e4 100644 --- a/ngraph/test/visitors/op/logical_and.cpp +++ b/ngraph/test/visitors/op/logical_and.cpp @@ -27,6 +27,8 @@ TEST(attributes, logical_and_op) auto logical_and = make_shared(x1, x2, auto_broadcast); NodeBuilder builder(logical_and); auto g_logical_and = as_type_ptr(builder.create()); + const auto expected_attr_count = 1; + EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); EXPECT_EQ(g_logical_and->get_autob(), logical_and->get_autob()); } From fe172363c6f26e01a7fd3be5dfc3fba3789ebb13 Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 26 Jul 2021 12:51:55 +0200 Subject: [PATCH 10/21] update auto_broadcast description --- docs/ops/logical/LogicalAnd_1.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/ops/logical/LogicalAnd_1.md b/docs/ops/logical/LogicalAnd_1.md index d1f0d683911ac4..085e0316c4e469 100644 --- a/docs/ops/logical/LogicalAnd_1.md +++ b/docs/ops/logical/LogicalAnd_1.md @@ -12,7 +12,7 @@ After broadcasting *LogicalAnd* does the following with the input tensors *a* an \f[ o_{i} = a_{i} and b_{i} -\f] +\f]z **Attributes**: @@ -20,8 +20,9 @@ o_{i} = a_{i} and b_{i} * **Description**: specifies rules used for auto-broadcasting of input tensors. * **Range of values**: - * *none* - no auto-broadcasting is allowed, all input shapes should match - * *numpy* - numpy broadcasting rules, aligned with ONNX Broadcasting. Description is available in ONNX docs. + * *none* - no auto-broadcasting is allowed, all input shapes must match, + * *numpy* - numpy broadcasting rules, description is available in [Broadcast Rules For Elementwise Operations](../broadcast_rules.md), + * *pdpd* - PaddlePaddle-style implicit broadcasting, description is available in [Broadcast Rules For Elementwise Operations](../broadcast_rules.md). * **Type**: string * **Default value**: "numpy" * **Required**: *no* From c489ca998ef5d284f21bcc22d2b68ad3d4a3df37 Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 26 Jul 2021 13:35:20 +0200 Subject: [PATCH 11/21] remoove backend test --- ngraph/test/backend/logical_and.in.cpp | 34 -------------------------- 1 file changed, 34 deletions(-) delete mode 100644 ngraph/test/backend/logical_and.in.cpp diff --git a/ngraph/test/backend/logical_and.in.cpp b/ngraph/test/backend/logical_and.in.cpp deleted file mode 100644 index 20ac74bedb2cd6..00000000000000 --- a/ngraph/test/backend/logical_and.in.cpp +++ /dev/null @@ -1,34 +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_and) -{ - Shape shape{3, 4}; - auto A = make_shared(element::boolean, shape); - auto B = make_shared(element::boolean, shape); - auto f = - make_shared(std::make_shared(A, B), ParameterVector{A, B}); - - std::vector a{true, true, true, true, true, false, true, false, false, true, true, true}; - std::vector b{true, true, true, true, true, false, true, false, false, true, true, false}; - - auto test_case_1 = test::TestCase(f); - test_case_1.add_multiple_inputs({a, b}); - test_case_1.add_expected_output(shape, {1., 1., 1., 1., 1., 0., 1., 0., 0., 1., 1., 0.}); - test_case_1.run(); -} From 9ded5afa24574768f48ee123f3cf1b72da0c8527 Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 26 Jul 2021 13:35:48 +0200 Subject: [PATCH 12/21] update LogicalNot params name --- .../inference_engine/serialization/single_layer/logical.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inference-engine/tests/functional/inference_engine/serialization/single_layer/logical.cpp b/inference-engine/tests/functional/inference_engine/serialization/single_layer/logical.cpp index 48424131944fb2..aff8081509bdfb 100644 --- a/inference-engine/tests/functional/inference_engine/serialization/single_layer/logical.cpp +++ b/inference-engine/tests/functional/inference_engine/serialization/single_layer/logical.cpp @@ -65,7 +65,7 @@ const auto LogicalTestParams = ::testing::Combine( ::testing::Values(CommonTestUtils::DEVICE_CPU), ::testing::Values(additional_config)); -const auto LogicalTestParamsNot = ::testing::Combine( +const auto LogicalNotTestParams = ::testing::Combine( ::testing::ValuesIn(LogicalLayerTest::combineShapes(inputShapesNot)), ::testing::Values(ngraph::helpers::LogicalTypes::LOGICAL_NOT), ::testing::Values(ngraph::helpers::InputLayerType::CONSTANT), @@ -79,6 +79,6 @@ const auto LogicalTestParamsNot = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, LogicalLayerTest, LogicalTestParams, LogicalLayerTest::getTestCaseName); -INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefsNot, LogicalLayerTest, LogicalTestParamsNot, LogicalLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefsNot, LogicalLayerTest, LogicalNotTestParams, LogicalLayerTest::getTestCaseName); } // namespace From 67205ef218707494a30d236bc39b5e0dc1f539e6 Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 26 Jul 2021 14:12:17 +0200 Subject: [PATCH 13/21] remove backend test from CMakeList --- ngraph/test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/ngraph/test/CMakeLists.txt b/ngraph/test/CMakeLists.txt index d5a95a244f1216..e27bb3b418ae32 100644 --- a/ngraph/test/CMakeLists.txt +++ b/ngraph/test/CMakeLists.txt @@ -437,7 +437,6 @@ set(MULTI_TEST_SRC backend/interpolate.in.cpp backend/log.in.cpp backend/log_softmax.in.cpp - backend/logical_and.in.cpp backend/logical_not.in.cpp backend/logical_or.in.cpp backend/logical_xor.in.cpp From 9af44bff5b1602c540939026d7fbaa0bb13442fa Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 26 Jul 2021 14:13:18 +0200 Subject: [PATCH 14/21] create util function for type_prop tests --- ngraph/test/type_prop/logical_and.cpp | 101 ++++++-------------------- 1 file changed, 23 insertions(+), 78 deletions(-) diff --git a/ngraph/test/type_prop/logical_and.cpp b/ngraph/test/type_prop/logical_and.cpp index c3c692bc94e22f..2a8699cfbe86a7 100644 --- a/ngraph/test/type_prop/logical_and.cpp +++ b/ngraph/test/type_prop/logical_and.cpp @@ -9,110 +9,55 @@ using namespace std; using namespace ngraph; -TEST(type_prop, logical_and_incorrect_type_f32) -{ - auto input1 = make_shared(element::f32, Shape{1, 3, 6}); - auto input2 = make_shared(element::f32, Shape{1, 3, 6}); - try - { - auto logical_and = make_shared(input1, input2); - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("Operands for logical operators must have boolean element type but have element type f32")); +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(type, shape1); + auto input2 = make_shared(type, shape2); + try + { + auto logical_and = make_shared(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) { - auto input1 = make_shared(element::f64, Shape{1, 3, 6}); - auto input2 = make_shared(element::f64, Shape{1, 3, 6}); - try - { - auto logical_and = make_shared(input1, input2); - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("Operands for logical operators must have boolean element type but have element 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) { - auto input1 = make_shared(element::i32, Shape{1, 3, 6}); - auto input2 = make_shared(element::i32, Shape{1, 3, 6}); - try - { - auto logical_and = make_shared(input1, input2); - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("Operands for logical operators must have boolean element type but have element 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) { - auto input1 = make_shared(element::i64, Shape{1, 3, 6}); - auto input2 = make_shared(element::i64, Shape{1, 3, 6}); - try - { - auto logical_and = make_shared(input1, input2); - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("Operands for logical operators must have boolean element type but have element 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) { - auto input1 = make_shared(element::u32, Shape{1, 3, 6}); - auto input2 = make_shared(element::u32, Shape{1, 3, 6}); - try - { - auto logical_and = make_shared(input1, input2); - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("Operands for logical operators must have boolean element type but have element 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) { - auto input1 = make_shared(element::u64, Shape{1, 3, 6}); - auto input2 = make_shared(element::u64, Shape{1, 3, 6}); - try - { - auto logical_and = make_shared(input1, input2); - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("Operands for logical operators must have boolean element type but have element 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) { - auto input1 = make_shared(element::boolean, Shape{1, 3, 6}); - auto input2 = make_shared(element::boolean, Shape{1, 2, 6}); - try - { - auto logical_and = make_shared(input1, input2); - } - catch (const NodeValidationFailure& error) - { - EXPECT_HAS_SUBSTRING(error.what(), - std::string("Argument shapes are inconsistent")); - } + incorrect_init(element::boolean, "Argument shapes are inconsistent", Shape {1, 3, 6}, Shape {1, 2, 3}); } TEST(type_prop, logical_and_broadcast) From c7f84cbeeea37762adf20c5a70e777239c1a2a85 Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 26 Jul 2021 14:14:05 +0200 Subject: [PATCH 15/21] update op_reference tests --- .../functional/op_reference/logical_and.cpp | 63 +++++++------------ 1 file changed, 22 insertions(+), 41 deletions(-) diff --git a/docs/template_plugin/tests/functional/op_reference/logical_and.cpp b/docs/template_plugin/tests/functional/op_reference/logical_and.cpp index 9a2196d6c4dcd4..0a2bc26452301b 100644 --- a/docs/template_plugin/tests/functional/op_reference/logical_and.cpp +++ b/docs/template_plugin/tests/functional/op_reference/logical_and.cpp @@ -15,13 +15,14 @@ using namespace ngraph; using namespace InferenceEngine; -namespace { + struct LogicalAndParams { template - LogicalAndParams(const ngraph::PartialShape& input_shape1, const ngraph::PartialShape& input_shape2 , const ngraph::element::Type& iType, - const ngraph::element::Type& oType, const std::vector& iValues1, const std::vector& iValues2, const std::vector& oValues) - : pshape1(input_shape1), pshape2(input_shape2), inType(iType), outType(oType), inputData1(CreateBlob(iType, iValues1)), - inputData2(CreateBlob(iType, iValues2)), refData(CreateBlob(oType, oValues)) {} + LogicalAndParams(const ngraph::PartialShape& input_shape1, const ngraph::PartialShape& input_shape2 , + const std::vector& iValues1, const std::vector& iValues2, const std::vector& 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; @@ -50,7 +51,8 @@ class ReferenceLogicalAndLayerTest : public testing::TestWithParam CreateFunction(const PartialShape& input_shape1, const PartialShape& input_shape2, const element::Type& input_type) { + static std::shared_ptr CreateFunction(const PartialShape& input_shape1, + const PartialShape& input_shape2, const element::Type& input_type) { const auto in = std::make_shared(input_type, input_shape1); const auto in2 = std::make_shared(input_type, input_shape2); const auto logical_and = std::make_shared(in, in2); @@ -62,40 +64,19 @@ TEST_P(ReferenceLogicalAndLayerTest, CompareWithHardcodedRefs) { Exec(); } -template -std::vector generateLogicalAndParams(const ngraph::element::Type& type) { - using T = typename element_type_traits::value_type; - std::vector logicalAndParams { - // 1D // 2D // 3D // 4D - LogicalAndParams(ngraph::PartialShape {2, 2}, ngraph::PartialShape {2, 2}, type, ngraph::element::boolean, - std::vector {true, false, true, false}, - std::vector {false, true, true, false}, +INSTANTIATE_TEST_SUITE_P( + smoke_LogicalAnd_With_Hardcoded_Refs, ReferenceLogicalAndLayerTest, + ::testing::Values( + LogicalAndParams(ngraph::PartialShape {2, 2}, ngraph::PartialShape {2, 2}, + std::vector {true, false, true, false}, + std::vector {false, true, true, false}, std::vector {false, false, true, false}), - LogicalAndParams(ngraph::PartialShape {1}, ngraph::PartialShape {1}, type, ngraph::element::boolean, - std::vector {true}, - std::vector {true}, - std::vector {true}), - - LogicalAndParams(ngraph::PartialShape {2, 1, 2, 1}, ngraph::PartialShape {1, 1, 2, 1}, type, ngraph::element::boolean, - std::vector {true, false, true, false}, - std::vector {true, false}, + LogicalAndParams(ngraph::PartialShape {2, 1, 2, 1}, ngraph::PartialShape {1, 1, 2, 1}, + std::vector {true, false, true, false}, + std::vector {true, false}, std::vector {true, false, true, false}), - LogicalAndParams(ngraph::PartialShape {3, 4}, ngraph::PartialShape {3, 4}, type, ngraph::element::boolean, - std::vector {true, true, true, true, true, false, true, false, false, true, true, true}, - std::vector {true, true, true, true, true, false, true, false, false, true, true, false}, - std::vector {true, true, true, true, true, false, true, false, false, true, true, false})}; - return logicalAndParams; -} - -std::vector generateLogicalAndCombinedParams() { - const std::vector> logicalAndTypeParams {generateLogicalAndParams(ngraph::element::boolean)}; - std::vector combinedParams; - std::for_each(logicalAndTypeParams.begin(), logicalAndTypeParams.end(), [&](std::vector params) { - combinedParams.insert(combinedParams.end(), params.begin(), params.end()); - }); - return combinedParams; -} - -INSTANTIATE_TEST_SUITE_P(smoke_LogicalAnd_With_Hardcoded_Refs, ReferenceLogicalAndLayerTest, ::testing::ValuesIn(generateLogicalAndCombinedParams()), - ReferenceLogicalAndLayerTest::getTestCaseName); -} // namespace + LogicalAndParams(ngraph::PartialShape {3, 4}, ngraph::PartialShape {3, 4}, + std::vector {true, true, true, true, true, false, true, false, false, true, true, true}, + std::vector {true, true, true, true, true, false, true, false, false, true, true, false}, + std::vector {true, true, true, true, true, false, true, false, false, true, true, false})), + ReferenceLogicalAndLayerTest::getTestCaseName); From 565a32f8284841151174c3e67bfa353f8edd907a Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 26 Jul 2021 22:29:52 +0200 Subject: [PATCH 16/21] remove typo in docs --- docs/ops/logical/LogicalAnd_1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ops/logical/LogicalAnd_1.md b/docs/ops/logical/LogicalAnd_1.md index 085e0316c4e469..b61f5375a199dc 100644 --- a/docs/ops/logical/LogicalAnd_1.md +++ b/docs/ops/logical/LogicalAnd_1.md @@ -12,7 +12,7 @@ After broadcasting *LogicalAnd* does the following with the input tensors *a* an \f[ o_{i} = a_{i} and b_{i} -\f]z +\f] **Attributes**: From 256ce97b6d00190e5fa85c20e5c8028871902822 Mon Sep 17 00:00:00 2001 From: pszmel Date: Tue, 27 Jul 2021 13:08:41 +0200 Subject: [PATCH 17/21] remove unsupported types from evaluate --- ngraph/core/src/op/and.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ngraph/core/src/op/and.cpp b/ngraph/core/src/op/and.cpp index 5da74d6fbe9665..02773875920f6a 100644 --- a/ngraph/core/src/op/and.cpp +++ b/ngraph/core/src/op/and.cpp @@ -63,12 +63,6 @@ namespace logand switch (arg0->get_element_type()) { NGRAPH_TYPE_CASE(evaluate_logand, boolean, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_logand, i32, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_logand, i64, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_logand, u32, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_logand, u64, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_logand, f16, arg0, arg1, out, broadcast_spec); - NGRAPH_TYPE_CASE(evaluate_logand, f32, arg0, arg1, out, broadcast_spec); default: rc = false; break; } return rc; From 37ff06e5273826d3bf65902ae69494caf6d76f06 Mon Sep 17 00:00:00 2001 From: pszmel Date: Tue, 27 Jul 2021 20:08:30 +0200 Subject: [PATCH 18/21] fix bug in op_reference test --- .../tests/functional/op_reference/logical_and.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/template_plugin/tests/functional/op_reference/logical_and.cpp b/docs/template_plugin/tests/functional/op_reference/logical_and.cpp index 0a2bc26452301b..0313874533e97b 100644 --- a/docs/template_plugin/tests/functional/op_reference/logical_and.cpp +++ b/docs/template_plugin/tests/functional/op_reference/logical_and.cpp @@ -12,6 +12,7 @@ #include "base_reference_test.hpp" +using namespace reference_tests; using namespace ngraph; using namespace InferenceEngine; From 0b9d034fdc88055f1ebf6250dd01d551f0a1f293 Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 2 Aug 2021 10:46:00 +0200 Subject: [PATCH 19/21] refactor visitor test --- ngraph/test/visitors/op/logical_and.cpp | 33 +++++-------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/ngraph/test/visitors/op/logical_and.cpp b/ngraph/test/visitors/op/logical_and.cpp index eff336d6c3c5e4..919e89ea9c6126 100644 --- a/ngraph/test/visitors/op/logical_and.cpp +++ b/ngraph/test/visitors/op/logical_and.cpp @@ -2,33 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "gtest/gtest.h" - -#include "ngraph/ngraph.hpp" -#include "ngraph/op/util/attr_types.hpp" +#include "binary_ops.hpp" #include "ngraph/opsets/opset1.hpp" +using Type = ::testing::Types>; -#include "util/visitor.hpp" - -using namespace std; -using namespace ngraph; -using ngraph::test::NodeBuilder; -using ngraph::test::ValueMap; - -TEST(attributes, logical_and_op) -{ - NodeBuilder::get_ops().register_factory(); - auto x1 = make_shared(element::boolean, Shape{200}); - auto x2 = make_shared(element::boolean, Shape{200}); - - auto auto_broadcast = op::AutoBroadcastType::NUMPY; - - auto logical_and = make_shared(x1, x2, auto_broadcast); - NodeBuilder builder(logical_and); - auto g_logical_and = as_type_ptr(builder.create()); - const auto expected_attr_count = 1; - - EXPECT_EQ(builder.get_value_map_size(), expected_attr_count); - EXPECT_EQ(g_logical_and->get_autob(), logical_and->get_autob()); -} +INSTANTIATE_TYPED_TEST_SUITE_P(visitor_with_auto_broadcast, + BinaryOperatorVisitor, + Type, + BinaryOperatorTypeName); From f495387a9509c351a103dd2fdfcf6fcf758681a5 Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 2 Aug 2021 10:57:34 +0200 Subject: [PATCH 20/21] update math formula in the spec --- docs/ops/logical/LogicalAnd_1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ops/logical/LogicalAnd_1.md b/docs/ops/logical/LogicalAnd_1.md index b61f5375a199dc..a653d1abbc29f2 100644 --- a/docs/ops/logical/LogicalAnd_1.md +++ b/docs/ops/logical/LogicalAnd_1.md @@ -11,7 +11,7 @@ After broadcasting *LogicalAnd* does the following with the input tensors *a* and *b*: \f[ -o_{i} = a_{i} and b_{i} +o_{i} = a_{i} \wedge b_{i} \f] **Attributes**: From 79cfec5cf403d837694e324e7e8daadc446345a4 Mon Sep 17 00:00:00 2001 From: pszmel Date: Mon, 2 Aug 2021 11:02:43 +0200 Subject: [PATCH 21/21] update has_evaluate types --- ngraph/core/src/op/and.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ngraph/core/src/op/and.cpp b/ngraph/core/src/op/and.cpp index 02773875920f6a..945b0e1918e77d 100644 --- a/ngraph/core/src/op/and.cpp +++ b/ngraph/core/src/op/and.cpp @@ -82,13 +82,7 @@ bool op::v1::LogicalAnd::has_evaluate() const NGRAPH_OP_SCOPE(v1_LogicalAnd_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;