diff --git a/docs/ops/comparison/LessEqual_1.md b/docs/ops/comparison/LessEqual_1.md index 4144095bed41df..a8b7c8101816dd 100644 --- a/docs/ops/comparison/LessEqual_1.md +++ b/docs/ops/comparison/LessEqual_1.md @@ -4,7 +4,16 @@ **Category**: Comparison binary operation -**Short description**: *LessEqual* performs element-wise comparison operation with two given tensors applying multi-directional broadcast rules. +**Short description**: *LessEqual* performs element-wise comparison operation with two given tensors applying broadcast rules specified in the *auto_broadcast* attribute. + +**Detailed description** +Before performing arithmetic 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 *LessEqual* does the following with the input tensors *a* and *b*: + +\f[ +o_{i} = a_{i} <= b_{i} +\f] **Attributes**: @@ -12,40 +21,33 @@ * **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 should 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* **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 comparison operation. A tensor of type boolean. +* **1**: The result of element-wise comparison operation applied to the input tensors. A tensor of type **boolean** and shape equal to broadcasted shape of two inputs. **Types** * *T*: arbitrary supported type. -**Detailed description** -Before performing arithmetic 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 *LessEqual* does the following with the input tensors *a* and *b*: - -\f[ -o_{i} = a_{i} <= b_{i} -\f] - **Examples** -*Example 1* +*Example 1: no broadcast* ```xml + 256 @@ -65,9 +67,10 @@ o_{i} = a_{i} <= b_{i} ``` -*Example 2: broadcast* +*Example 2: numpy broadcast* ```xml + 8 diff --git a/docs/template_plugin/tests/functional/op_reference/less_eq.cpp b/docs/template_plugin/tests/functional/op_reference/less_eq.cpp new file mode 100644 index 00000000000000..f530867f847f5d --- /dev/null +++ b/docs/template_plugin/tests/functional/op_reference/less_eq.cpp @@ -0,0 +1,82 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include +#include +#include +#include + +#include "comparison.hpp" + +using namespace ngraph; +using namespace InferenceEngine; +using ComparisonTypes = ngraph::helpers::ComparisonTypes; + +namespace reference_tests { +namespace ComparisonOpsRefTestDefinitions { +namespace { +TEST_P(ReferenceComparisonLayerTest, LessEqualCompareWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateComparisonParams(const element::Type& type) { + using T = typename element_type_traits::value_type; + std::vector compParams { + // 1D // 2D // 3D // 4D + Builder {} + .compType(ComparisonTypes::LESS_EQUAL) + .input1({{2, 2}, type, std::vector {0, 12, 23, 0}}) + .input2({{2, 2}, type, std::vector {0, 12, 23, 0}}) + .expected({{2, 2}, element::boolean, std::vector {1, 1, 1, 1}}), + Builder {} + .compType(ComparisonTypes::LESS_EQUAL) + .input1({{2, 3}, type, std::vector {0, 6, 45, 1, 21, 21}}) + .input2({{2, 3}, type, std::vector {1, 18, 23, 1, 19, 21}}) + .expected({{2, 3}, element::boolean, std::vector {1, 1, 0, 1, 0, 1}}), + Builder {} + .compType(ComparisonTypes::LESS_EQUAL) + .input1({{1}, type, std::vector {53}}) + .input2({{1}, type, std::vector {53}}) + .expected({{1}, element::boolean, std::vector {1}}), + Builder {} + .compType(ComparisonTypes::LESS_EQUAL) + .input1({{2, 4}, type, std::vector {0, 12, 23, 0, 1, 5, 11, 8}}) + .input2({{2, 4}, type, std::vector {0, 12, 23, 0, 10, 5, 11, 8}}) + .expected({{2, 4}, element::boolean, std::vector {1, 1, 1, 1, 1, 1, 1, 1}}), + Builder {} + .compType(ComparisonTypes::LESS_EQUAL) + .input1({{3, 1, 2}, type, std::vector {2, 1, 4, 1, 3, 1}}) + .input2({{1, 2, 1}, type, std::vector {1, 1}}) + .expected({{3, 2, 2}, element::boolean, std::vector {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}}), + Builder {} + .compType(ComparisonTypes::LESS_EQUAL) + .input1({{2, 1, 2, 1}, type, std::vector {2, 1, 4, 1}}) + .input2({{1, 2, 1}, type, std::vector {1, 1}}) + .expected({{2, 1, 2, 1}, element::boolean, std::vector {0, 1, 0, 1}})}; + return compParams; +} + +std::vector generateComparisonCombinedParams() { + const std::vector> compTypeParams { + generateComparisonParams(element::f32), + generateComparisonParams(element::f16), + generateComparisonParams(element::i32), + generateComparisonParams(element::u32), + generateComparisonParams(element::boolean)}; + std::vector combinedParams; + + for (const auto& params : compTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + return combinedParams; +} + +} // namespace +INSTANTIATE_TEST_SUITE_P(smoke_Comparison_With_Hardcoded_Refs, ReferenceComparisonLayerTest, ::testing::ValuesIn(generateComparisonCombinedParams()), + ReferenceComparisonLayerTest::getTestCaseName); +} // namespace ComparisonOpsRefTestDefinitions +} // namespace reference_tests \ No newline at end of file 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 ee68f19184dedc..fee2d9ba6d2e47 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 @@ -54,6 +54,7 @@ 'HardSigmoid-1', 'Interpolate-4', 'Less-1', + 'LessEqual-1' 'LRN-1', 'LSTMCell-4', 'LSTMSequence-5', diff --git a/ngraph/test/backend/comparison.in.cpp b/ngraph/test/backend/comparison.in.cpp index 5ba46f0ba9380c..2ba2cd34282a16 100644 --- a/ngraph/test/backend/comparison.in.cpp +++ b/ngraph/test/backend/comparison.in.cpp @@ -109,70 +109,3 @@ NGRAPH_TEST(${BACKEND_NAME}, greatereq) handle->call_with_validate({result}, {a, b}); EXPECT_EQ((vector{1, 1, 1, 1, 0, 1, 1, 0}), read_vector(result)); } - -NGRAPH_TEST(${BACKEND_NAME}, lesseq) -{ - Shape shape{2, 2, 2}; - auto A = make_shared(element::f32, shape); - auto B = make_shared(element::f32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::f32, shape); - copy_data(a, vector{1, 8, -8, 17, -0.5, 0, 2, 1}); - auto b = backend->create_tensor(element::f32, shape); - copy_data(b, vector{1, 2, -8, 8, 0, 0, 0.5, 1.5}); - auto result = backend->create_tensor(element::boolean, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{1, 0, 1, 0, 1, 1, 0, 1}), read_vector(result)); -} - -NGRAPH_TEST(${BACKEND_NAME}, lesseq_int32) -{ - Shape shape{2, 2}; - auto A = make_shared(element::i32, shape); - auto B = make_shared(element::i32, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::i32, shape); - copy_data(a, vector{0x40000170, 0x40000005, 0x40000005, -5}); - auto b = backend->create_tensor(element::i32, shape); - copy_data(b, vector{0x40000140, 0x40000001, 0x40000005, 0}); - auto result = backend->create_tensor(element::boolean, shape); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{0, 0, 1, 1}), read_vector(result)); // NNP result {1, 1, 0, 1} -} - -NGRAPH_TEST(${BACKEND_NAME}, lesseq_bool) -{ - Shape shape{2, 2, 2}; - auto A = make_shared(element::boolean, shape); - auto B = make_shared(element::boolean, shape); - auto f = make_shared(make_shared(A, B), ParameterVector{A, B}); - - auto backend = runtime::Backend::create("${BACKEND_NAME}"); - - // Create some tensors for input/output - auto a = backend->create_tensor(element::boolean, shape); - copy_data(a, vector{1, 1, 1, 1, 1, 1, 1, 1}); - auto b = backend->create_tensor(element::boolean, shape); - copy_data(b, vector{0, 0, 0, 0, 0, 0, 0, 0}); - auto result = backend->create_tensor(element::boolean, shape); - - // Overwrite the initial result vector to make sure we're not just coincidentally getting the - // right value. - copy_data(result, vector{1, 1, 1, 1, 1, 1, 1, 1}); - - auto handle = backend->compile(f); - handle->call_with_validate({result}, {a, b}); - EXPECT_EQ((vector{0, 0, 0, 0, 0, 0, 0, 0}), read_vector(result)); -} diff --git a/ngraph/test/runtime/ie/unit_test.manifest b/ngraph/test/runtime/ie/unit_test.manifest index 44f7f880e6fbe9..48030903c33a31 100644 --- a/ngraph/test/runtime/ie/unit_test.manifest +++ b/ngraph/test/runtime/ie/unit_test.manifest @@ -426,7 +426,6 @@ notequal greater greatereq less -lesseq sum_3d_to_scalar_int32 sum_2d_to_scalar_int8 max_pool_uint8 @@ -489,7 +488,6 @@ logical_xor logical_or logical_and gather_axis_0_bool -lesseq_bool auto_bcast_binary_elementwise auto_bcast_binary_elementwise_pdpd any_2x2_to_scalar_true @@ -758,7 +756,6 @@ strided_slice_stride_optional divide_int32 divide_cpp_rounding_int32 divide_python_rounding_int32 -lesseq_int32 # Constant and Low Precision constant_equality_u4_2x2x3