Skip to content

Commit b7c6d46

Browse files
bszmelczandrei-cv
authored andcommitted
Revise equal (openvinotoolkit#6605)
* update spec, init backend file for equal op * add backend, visitors, serialize SLT tests * add backend test to manifest cause of mismatch of output type with cpu plugin * add equal to list of trusted ops and to cmakelist file * refactor backend tests to the new template * refactor spec * remove external link in numpy broadcast and update example * remove comparison.in.cpp file and related tests from manifest * fix example * remove redundant arguments * refactor backend tests * add pdpd broadcast to the spec, and different precison to SLT test * add precisions to SLT cpu * remove unsupported type from SLT * revert the deletion of comparison.in.cpp file * remove visitors test, since it will be added in the other PR * remove equal from CMakeLists.txt * refactor links in the spec * revert unwanted changes * remove equal from unit test manifest * revert links modification in spec * add namespace * split SSLTs for comaprison ops into seperate files * fix SSLTs names * add missing new lines * udpate output type in spec * rafactor numeric backend test to template * merge numeric template tests into equal
1 parent 6f0176d commit b7c6d46

File tree

14 files changed

+461
-88
lines changed

14 files changed

+461
-88
lines changed

docs/ops/comparison/Equal_1.md

+21-17
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,51 @@
44

55
**Category**: Comparison binary operation
66

7-
**Short description**: *Equal* performs element-wise comparison operation with two given tensors applying multi-directional broadcast rules.
7+
**Short description**: *Equal* performs element-wise comparison operation with two given input tensors applying multi-directional broadcast rules specified in the *auto_broadcast* attribute.
8+
9+
**Detailed description**
10+
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.
11+
12+
After broadcasting *Equal* does the following with the input tensors *a* and *b*:
13+
14+
\f[
15+
o_{i} = a_{i} == b_{i}
16+
\f]
817

918
**Attributes**:
1019

1120
* *auto_broadcast*
1221

1322
* **Description**: specifies rules used for auto-broadcasting of input tensors.
1423
* **Range of values**:
15-
* *none* - no auto-broadcasting is allowed, all input shapes should match
16-
* *numpy* - numpy broadcasting rules, aligned with ONNX Broadcasting. Description is available in <a href="https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md">ONNX docs</a>.
24+
* *none* - no auto-broadcasting is allowed, all input shapes should match,
25+
* *numpy* - numpy broadcasting rules, description is available in [Broadcast Rules For Elementwise Operations](../broadcast_rules.md),
26+
* *pdpd* - PaddlePaddle-style implicit broadcasting, description is available in [Broadcast Rules For Elementwise Operations](../broadcast_rules.md).
1727
* **Type**: string
1828
* **Default value**: "numpy"
1929
* **Required**: *no*
2030

2131
**Inputs**
2232

23-
* **1**: A tensor of type *T*. **Required.**
24-
* **2**: A tensor of type *T*. **Required.**
33+
* **1**: A tensor of type *T* and arbitrary shape. **Required.**
34+
* **2**: A tensor of type *T* and arbitrary shape. **Required.**
2535

2636
**Outputs**
2737

28-
* **1**: The result of element-wise comparison operation. A tensor of type boolean.
38+
* **1**: The result of element-wise **comparison** operation applied to the input tensors. A tensor of type *T_BOOL* and the same shape equal to broadcasted shape of two inputs.
2939

3040
**Types**
3141

3242
* *T*: arbitrary supported type.
33-
34-
**Detailed description**
35-
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.
36-
37-
After broadcasting *Equal* does the following with the input tensors *a* and *b*:
38-
39-
\f[
40-
o_{i} = a_{i} == b_{i}
41-
\f]
43+
* *T_BOOL*: `boolean`.
4244

4345
**Examples**
4446

45-
*Example 1*
47+
*Example 1: no broadcast*
4648

4749
```xml
4850
<layer ... type="Equal">
51+
<data auto_broadcast="none"/>
4952
<input>
5053
<port id="0">
5154
<dim>256</dim>
@@ -65,9 +68,10 @@ o_{i} = a_{i} == b_{i}
6568
</layer>
6669
```
6770

68-
*Example 2: broadcast*
71+
*Example 2: numpy broadcast*
6972
```xml
7073
<layer ... type="Equal">
74+
<data auto_broadcast="numpy"/>
7175
<input>
7276
<port id="0">
7377
<dim>8</dim>

docs/template_plugin/tests/functional/op_reference/equal.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,48 @@ std::vector<RefComparisonParams> generateComparisonCombinedParams() {
7575

7676
INSTANTIATE_TEST_SUITE_P(smoke_Comparison_With_Hardcoded_Refs, ReferenceComparisonLayerTest, ::testing::ValuesIn(generateComparisonCombinedParams()),
7777
ReferenceComparisonLayerTest::getTestCaseName);
78+
79+
template <element::Type_t IN_ET>
80+
std::vector<RefComparisonParams> generateNumericParams(const element::Type& type) {
81+
using T = typename element_type_traits<IN_ET>::value_type;
82+
std::vector<RefComparisonParams> compParams {
83+
Builder {}
84+
.compType(ComparisonTypes::EQUAL)
85+
.input1({{4}, type, std::vector<T> {-2.5f, 25.5f, 2.25f, NAN}})
86+
.input2({{4}, type, std::vector<T> {10.0f, 5.0f, 2.25f, 10.0f}})
87+
.expected({{4}, element::boolean, std::vector<char> {0, 0, 1, 0, }}),
88+
Builder {}
89+
.compType(ComparisonTypes::EQUAL)
90+
.input1({{2, 3}, type, std::vector<T> {0.0f, NAN, NAN, 1.0f, 21.0f, -INFINITY}})
91+
.input2({{2, 3}, type, std::vector<T> {1.0f, NAN, 23.0f, 1.0f, 19.0f, 21.0f}})
92+
.expected({{2, 3}, element::boolean, std::vector<char> {0, 0, 0, 1, 0, 0}}),
93+
Builder {}
94+
.compType(ComparisonTypes::EQUAL)
95+
.input1({{1}, type, std::vector<T> {INFINITY}})
96+
.input2({{1}, type, std::vector<T> {INFINITY}})
97+
.expected({{1}, element::boolean, std::vector<char> {1}}),
98+
Builder {}
99+
.compType(ComparisonTypes::EQUAL)
100+
.input1({{5}, type, std::vector<T> {-2.5f, 25.5f, 2.25f, INFINITY, 6.0f}})
101+
.input2({{5}, type, std::vector<T> {10.0f, 5.0f, 2.25f, 10.0f, -INFINITY}})
102+
.expected({{5}, element::boolean, std::vector<char> {0, 0, 1, 0, 0}})};
103+
return compParams;
104+
}
105+
106+
std::vector<RefComparisonParams> generateNumericCombinedParams() {
107+
const std::vector<std::vector<RefComparisonParams>> compTypeParams {
108+
generateNumericParams<element::Type_t::f16>(element::f16),
109+
generateNumericParams<element::Type_t::f32>(element::f32)};
110+
std::vector<RefComparisonParams> combinedParams;
111+
112+
for (const auto& params : compTypeParams) {
113+
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
114+
}
115+
return combinedParams;
116+
}
117+
118+
INSTANTIATE_TEST_SUITE_P(smoke_Numeric_With_Hardcoded_Refs, ReferenceComparisonLayerTest, ::testing::ValuesIn(generateNumericCombinedParams()),
119+
ReferenceComparisonLayerTest::getTestCaseName);
78120
} // namespace
79121
} // namespace ComparisonOpsRefTestDefinitions
80122
} // namespace reference_tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (C) 2018-2021 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "shared_test_classes/single_layer/comparison.hpp"
6+
7+
struct ComparisionOpsData {
8+
const std::map<std::vector<size_t>, std::vector<std::vector<size_t>>> inputShapes;
9+
const std::vector<InferenceEngine::Precision> inputsPrecisions;
10+
const std::vector<ngraph::helpers::InputLayerType> secondInputTypes;
11+
const std::map<std::string, std::string> additional_config;
12+
const ngraph::helpers::ComparisonTypes opType;
13+
const InferenceEngine::Precision ieInputPrecision;
14+
const InferenceEngine::Precision ieOutputPrecision;
15+
const std::string deviceName;
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (C) 2018-2021 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "comparison_ops.hpp"
6+
7+
using namespace LayerTestsDefinitions;
8+
using namespace LayerTestsDefinitions::ComparisonParams;
9+
10+
namespace {
11+
TEST_P(ComparisonLayerTest, Serialize) {
12+
Serialize();
13+
}
14+
15+
ComparisionOpsData data = {
16+
// inputsShape
17+
{
18+
{{1}, {{1}, {17}, {1, 1}, {2, 18}, {1, 1, 2}, {2, 2, 3}, {1, 1, 2, 3}}},
19+
{{5}, {{1}, {1, 1}, {2, 5}, {1, 1, 1}, {2, 2, 5}}},
20+
{{2, 200}, {{1}, {200}, {1, 200}, {2, 200}, {2, 2, 200}}},
21+
{{1, 3, 20}, {{20}, {2, 1, 1}}},
22+
{{2, 17, 3, 4}, {{4}, {1, 3, 4}, {2, 1, 3, 4}}},
23+
{{2, 17, 3, 4}, {{4}, {1, 3, 4}, {141, 1, 3, 4}}},
24+
{{2, 1, 1, 3, 1}, {{1}, {1, 3, 4}, {2, 1, 3, 4}, {1, 1, 1, 1, 1}}},
25+
},
26+
// inputsPrecisions
27+
{
28+
InferenceEngine::Precision::FP64,
29+
InferenceEngine::Precision::FP32,
30+
InferenceEngine::Precision::FP16,
31+
InferenceEngine::Precision::I32,
32+
InferenceEngine::Precision::U32,
33+
InferenceEngine::Precision::BOOL,
34+
},
35+
// secondIinputsType
36+
{
37+
ngraph::helpers::InputLayerType::CONSTANT,
38+
ngraph::helpers::InputLayerType::PARAMETER,
39+
},
40+
// additionalConfig
41+
{},
42+
// opType
43+
ngraph::helpers::ComparisonTypes::EQUAL,
44+
// ieInputPrecision
45+
InferenceEngine::Precision::UNSPECIFIED,
46+
// ieOutputPrecision
47+
InferenceEngine::Precision::UNSPECIFIED,
48+
// deviceName
49+
CommonTestUtils::DEVICE_CPU,
50+
};
51+
52+
const auto SerializeEqualTestParams = ::testing::Combine(
53+
::testing::ValuesIn(CommonTestUtils::combineParams(data.inputShapes)),
54+
::testing::ValuesIn(data.inputsPrecisions),
55+
::testing::Values(data.opType),
56+
::testing::ValuesIn(data.secondInputTypes),
57+
::testing::Values(data.ieInputPrecision),
58+
::testing::Values(data.ieOutputPrecision),
59+
::testing::Values(data.deviceName),
60+
::testing::Values(data.additional_config));
61+
62+
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ComparisonLayerTest, SerializeEqualTestParams, ComparisonLayerTest::getTestCaseName);
63+
} // namespace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (C) 2018-2021 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "comparison_ops.hpp"
6+
7+
using namespace LayerTestsDefinitions;
8+
using namespace LayerTestsDefinitions::ComparisonParams;
9+
10+
namespace {
11+
TEST_P(ComparisonLayerTest, Serialize) {
12+
Serialize();
13+
}
14+
15+
ComparisionOpsData data = {
16+
// inputsShape
17+
{
18+
{{1}, {{1}, {17}, {1, 1}, {2, 18}, {1, 1, 2}, {2, 2, 3}, {1, 1, 2, 3}}},
19+
{{5}, {{1}, {1, 1}, {2, 5}, {1, 1, 1}, {2, 2, 5}}},
20+
{{2, 200}, {{1}, {200}, {1, 200}, {2, 200}, {2, 2, 200}}},
21+
{{1, 3, 20}, {{20}, {2, 1, 1}}},
22+
{{2, 17, 3, 4}, {{4}, {1, 3, 4}, {2, 1, 3, 4}}},
23+
{{2, 17, 3, 4}, {{4}, {1, 3, 4}, {141, 1, 3, 4}}},
24+
{{2, 1, 1, 3, 1}, {{1}, {1, 3, 4}, {2, 1, 3, 4}, {1, 1, 1, 1, 1}}},
25+
},
26+
// inputsPrecisions
27+
{
28+
InferenceEngine::Precision::FP64,
29+
InferenceEngine::Precision::FP32,
30+
InferenceEngine::Precision::FP16,
31+
InferenceEngine::Precision::I32,
32+
InferenceEngine::Precision::U32,
33+
InferenceEngine::Precision::BOOL,
34+
},
35+
// secondIinputsType
36+
{
37+
ngraph::helpers::InputLayerType::CONSTANT,
38+
ngraph::helpers::InputLayerType::PARAMETER,
39+
},
40+
// additionalConfig
41+
{},
42+
// opType
43+
ngraph::helpers::ComparisonTypes::GREATER,
44+
// ieInputPrecision
45+
InferenceEngine::Precision::UNSPECIFIED,
46+
// ieOutputPrecision
47+
InferenceEngine::Precision::UNSPECIFIED,
48+
// deviceName
49+
CommonTestUtils::DEVICE_CPU,
50+
};
51+
52+
const auto SerializeGreaterTestParams = ::testing::Combine(
53+
::testing::ValuesIn(CommonTestUtils::combineParams(data.inputShapes)),
54+
::testing::ValuesIn(data.inputsPrecisions),
55+
::testing::Values(data.opType),
56+
::testing::ValuesIn(data.secondInputTypes),
57+
::testing::Values(data.ieInputPrecision),
58+
::testing::Values(data.ieOutputPrecision),
59+
::testing::Values(data.deviceName),
60+
::testing::Values(data.additional_config));
61+
62+
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ComparisonLayerTest, SerializeGreaterTestParams, ComparisonLayerTest::getTestCaseName);
63+
} // namespace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright (C) 2018-2021 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "comparison_ops.hpp"
6+
7+
using namespace LayerTestsDefinitions;
8+
using namespace LayerTestsDefinitions::ComparisonParams;
9+
10+
namespace {
11+
TEST_P(ComparisonLayerTest, Serialize) {
12+
Serialize();
13+
}
14+
15+
ComparisionOpsData data = {
16+
// inputsShape
17+
{
18+
{{1}, {{1}, {17}, {1, 1}, {2, 18}, {1, 1, 2}, {2, 2, 3}, {1, 1, 2, 3}}},
19+
{{5}, {{1}, {1, 1}, {2, 5}, {1, 1, 1}, {2, 2, 5}}},
20+
{{2, 200}, {{1}, {200}, {1, 200}, {2, 200}, {2, 2, 200}}},
21+
{{1, 3, 20}, {{20}, {2, 1, 1}}},
22+
{{2, 17, 3, 4}, {{4}, {1, 3, 4}, {2, 1, 3, 4}}},
23+
{{2, 17, 3, 4}, {{4}, {1, 3, 4}, {141, 1, 3, 4}}},
24+
{{2, 1, 1, 3, 1}, {{1}, {1, 3, 4}, {2, 1, 3, 4}, {1, 1, 1, 1, 1}}},
25+
},
26+
// inputsPrecisions
27+
{
28+
InferenceEngine::Precision::FP64,
29+
InferenceEngine::Precision::FP32,
30+
InferenceEngine::Precision::FP16,
31+
InferenceEngine::Precision::I32,
32+
InferenceEngine::Precision::U32,
33+
InferenceEngine::Precision::BOOL,
34+
},
35+
// secondIinputsType
36+
{
37+
ngraph::helpers::InputLayerType::CONSTANT,
38+
ngraph::helpers::InputLayerType::PARAMETER,
39+
},
40+
// additionalConfig
41+
{},
42+
// opType
43+
ngraph::helpers::ComparisonTypes::GREATER_EQUAL,
44+
// ieInputPrecision
45+
InferenceEngine::Precision::UNSPECIFIED,
46+
// ieOutputPrecision
47+
InferenceEngine::Precision::UNSPECIFIED,
48+
// deviceName
49+
CommonTestUtils::DEVICE_CPU,
50+
};
51+
52+
const auto SerializeGreaterEqualTestParams = ::testing::Combine(
53+
::testing::ValuesIn(CommonTestUtils::combineParams(data.inputShapes)),
54+
::testing::ValuesIn(data.inputsPrecisions),
55+
::testing::Values(data.opType),
56+
::testing::ValuesIn(data.secondInputTypes),
57+
::testing::Values(data.ieInputPrecision),
58+
::testing::Values(data.ieOutputPrecision),
59+
::testing::Values(data.deviceName),
60+
::testing::Values(data.additional_config));
61+
62+
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ComparisonLayerTest, SerializeGreaterEqualTestParams, ComparisonLayerTest::getTestCaseName);
63+
} // namespace

0 commit comments

Comments
 (0)