Skip to content

Commit

Permalink
Revise equal (#6605)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bszmelcz authored Aug 11, 2021
1 parent 5292de5 commit 289df8d
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 88 deletions.
38 changes: 21 additions & 17 deletions docs/ops/comparison/Equal_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,51 @@

**Category**: Comparison binary operation

**Short description**: *Equal* performs element-wise comparison operation with two given tensors applying multi-directional broadcast rules.
**Short description**: *Equal* performs element-wise comparison operation with two given input tensors applying multi-directional 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 *Equal* does the following with the input tensors *a* and *b*:

\f[
o_{i} = a_{i} == b_{i}
\f]

**Attributes**:

* *auto_broadcast*

* **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 <a href="https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md">ONNX docs</a>.
* *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 *T_BOOL* and the same 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 *Equal* does the following with the input tensors *a* and *b*:

\f[
o_{i} = a_{i} == b_{i}
\f]
* *T_BOOL*: `boolean`.

**Examples**

*Example 1*
*Example 1: no broadcast*

```xml
<layer ... type="Equal">
<data auto_broadcast="none"/>
<input>
<port id="0">
<dim>256</dim>
Expand All @@ -65,9 +68,10 @@ o_{i} = a_{i} == b_{i}
</layer>
```

*Example 2: broadcast*
*Example 2: numpy broadcast*
```xml
<layer ... type="Equal">
<data auto_broadcast="numpy"/>
<input>
<port id="0">
<dim>8</dim>
Expand Down
42 changes: 42 additions & 0 deletions docs/template_plugin/tests/functional/op_reference/equal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,48 @@ std::vector<RefComparisonParams> generateComparisonCombinedParams() {

INSTANTIATE_TEST_SUITE_P(smoke_Comparison_With_Hardcoded_Refs, ReferenceComparisonLayerTest, ::testing::ValuesIn(generateComparisonCombinedParams()),
ReferenceComparisonLayerTest::getTestCaseName);

template <element::Type_t IN_ET>
std::vector<RefComparisonParams> generateNumericParams(const element::Type& type) {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<RefComparisonParams> compParams {
Builder {}
.compType(ComparisonTypes::EQUAL)
.input1({{4}, type, std::vector<T> {-2.5f, 25.5f, 2.25f, NAN}})
.input2({{4}, type, std::vector<T> {10.0f, 5.0f, 2.25f, 10.0f}})
.expected({{4}, element::boolean, std::vector<char> {0, 0, 1, 0, }}),
Builder {}
.compType(ComparisonTypes::EQUAL)
.input1({{2, 3}, type, std::vector<T> {0.0f, NAN, NAN, 1.0f, 21.0f, -INFINITY}})
.input2({{2, 3}, type, std::vector<T> {1.0f, NAN, 23.0f, 1.0f, 19.0f, 21.0f}})
.expected({{2, 3}, element::boolean, std::vector<char> {0, 0, 0, 1, 0, 0}}),
Builder {}
.compType(ComparisonTypes::EQUAL)
.input1({{1}, type, std::vector<T> {INFINITY}})
.input2({{1}, type, std::vector<T> {INFINITY}})
.expected({{1}, element::boolean, std::vector<char> {1}}),
Builder {}
.compType(ComparisonTypes::EQUAL)
.input1({{5}, type, std::vector<T> {-2.5f, 25.5f, 2.25f, INFINITY, 6.0f}})
.input2({{5}, type, std::vector<T> {10.0f, 5.0f, 2.25f, 10.0f, -INFINITY}})
.expected({{5}, element::boolean, std::vector<char> {0, 0, 1, 0, 0}})};
return compParams;
}

std::vector<RefComparisonParams> generateNumericCombinedParams() {
const std::vector<std::vector<RefComparisonParams>> compTypeParams {
generateNumericParams<element::Type_t::f16>(element::f16),
generateNumericParams<element::Type_t::f32>(element::f32)};
std::vector<RefComparisonParams> combinedParams;

for (const auto& params : compTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}

INSTANTIATE_TEST_SUITE_P(smoke_Numeric_With_Hardcoded_Refs, ReferenceComparisonLayerTest, ::testing::ValuesIn(generateNumericCombinedParams()),
ReferenceComparisonLayerTest::getTestCaseName);
} // namespace
} // namespace ComparisonOpsRefTestDefinitions
} // namespace reference_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "shared_test_classes/single_layer/comparison.hpp"

struct ComparisionOpsData {
const std::map<std::vector<size_t>, std::vector<std::vector<size_t>>> inputShapes;
const std::vector<InferenceEngine::Precision> inputsPrecisions;
const std::vector<ngraph::helpers::InputLayerType> secondInputTypes;
const std::map<std::string, std::string> additional_config;
const ngraph::helpers::ComparisonTypes opType;
const InferenceEngine::Precision ieInputPrecision;
const InferenceEngine::Precision ieOutputPrecision;
const std::string deviceName;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "comparison_ops.hpp"

using namespace LayerTestsDefinitions;
using namespace LayerTestsDefinitions::ComparisonParams;

namespace {
TEST_P(ComparisonLayerTest, Serialize) {
Serialize();
}

ComparisionOpsData data = {
// inputsShape
{
{{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, 17, 3, 4}, {{4}, {1, 3, 4}, {141, 1, 3, 4}}},
{{2, 1, 1, 3, 1}, {{1}, {1, 3, 4}, {2, 1, 3, 4}, {1, 1, 1, 1, 1}}},
},
// inputsPrecisions
{
InferenceEngine::Precision::FP64,
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::U32,
InferenceEngine::Precision::BOOL,
},
// secondIinputsType
{
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER,
},
// additionalConfig
{},
// opType
ngraph::helpers::ComparisonTypes::EQUAL,
// ieInputPrecision
InferenceEngine::Precision::UNSPECIFIED,
// ieOutputPrecision
InferenceEngine::Precision::UNSPECIFIED,
// deviceName
CommonTestUtils::DEVICE_CPU,
};

const auto SerializeEqualTestParams = ::testing::Combine(
::testing::ValuesIn(CommonTestUtils::combineParams(data.inputShapes)),
::testing::ValuesIn(data.inputsPrecisions),
::testing::Values(data.opType),
::testing::ValuesIn(data.secondInputTypes),
::testing::Values(data.ieInputPrecision),
::testing::Values(data.ieOutputPrecision),
::testing::Values(data.deviceName),
::testing::Values(data.additional_config));

INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ComparisonLayerTest, SerializeEqualTestParams, ComparisonLayerTest::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "comparison_ops.hpp"

using namespace LayerTestsDefinitions;
using namespace LayerTestsDefinitions::ComparisonParams;

namespace {
TEST_P(ComparisonLayerTest, Serialize) {
Serialize();
}

ComparisionOpsData data = {
// inputsShape
{
{{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, 17, 3, 4}, {{4}, {1, 3, 4}, {141, 1, 3, 4}}},
{{2, 1, 1, 3, 1}, {{1}, {1, 3, 4}, {2, 1, 3, 4}, {1, 1, 1, 1, 1}}},
},
// inputsPrecisions
{
InferenceEngine::Precision::FP64,
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::U32,
InferenceEngine::Precision::BOOL,
},
// secondIinputsType
{
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER,
},
// additionalConfig
{},
// opType
ngraph::helpers::ComparisonTypes::GREATER,
// ieInputPrecision
InferenceEngine::Precision::UNSPECIFIED,
// ieOutputPrecision
InferenceEngine::Precision::UNSPECIFIED,
// deviceName
CommonTestUtils::DEVICE_CPU,
};

const auto SerializeGreaterTestParams = ::testing::Combine(
::testing::ValuesIn(CommonTestUtils::combineParams(data.inputShapes)),
::testing::ValuesIn(data.inputsPrecisions),
::testing::Values(data.opType),
::testing::ValuesIn(data.secondInputTypes),
::testing::Values(data.ieInputPrecision),
::testing::Values(data.ieOutputPrecision),
::testing::Values(data.deviceName),
::testing::Values(data.additional_config));

INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ComparisonLayerTest, SerializeGreaterTestParams, ComparisonLayerTest::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "comparison_ops.hpp"

using namespace LayerTestsDefinitions;
using namespace LayerTestsDefinitions::ComparisonParams;

namespace {
TEST_P(ComparisonLayerTest, Serialize) {
Serialize();
}

ComparisionOpsData data = {
// inputsShape
{
{{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, 17, 3, 4}, {{4}, {1, 3, 4}, {141, 1, 3, 4}}},
{{2, 1, 1, 3, 1}, {{1}, {1, 3, 4}, {2, 1, 3, 4}, {1, 1, 1, 1, 1}}},
},
// inputsPrecisions
{
InferenceEngine::Precision::FP64,
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::U32,
InferenceEngine::Precision::BOOL,
},
// secondIinputsType
{
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER,
},
// additionalConfig
{},
// opType
ngraph::helpers::ComparisonTypes::GREATER_EQUAL,
// ieInputPrecision
InferenceEngine::Precision::UNSPECIFIED,
// ieOutputPrecision
InferenceEngine::Precision::UNSPECIFIED,
// deviceName
CommonTestUtils::DEVICE_CPU,
};

const auto SerializeGreaterEqualTestParams = ::testing::Combine(
::testing::ValuesIn(CommonTestUtils::combineParams(data.inputShapes)),
::testing::ValuesIn(data.inputsPrecisions),
::testing::Values(data.opType),
::testing::ValuesIn(data.secondInputTypes),
::testing::Values(data.ieInputPrecision),
::testing::Values(data.ieOutputPrecision),
::testing::Values(data.deviceName),
::testing::Values(data.additional_config));

INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ComparisonLayerTest, SerializeGreaterEqualTestParams, ComparisonLayerTest::getTestCaseName);
} // namespace
Loading

0 comments on commit 289df8d

Please sign in to comment.