Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise Less #6728

Merged
merged 14 commits into from
Jul 28, 2021
24 changes: 13 additions & 11 deletions docs/ops/comparison/Less_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@

**Short description**: *Less* performs element-wise comparison operation with two given tensors applying multi-directional broadcast rules.

**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 *Less* 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>.
* **Type**: string
* *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*

Expand All @@ -31,15 +42,6 @@

* *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 *Less* does the following with the input tensors *a* and *b*:

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

**Examples**

*Example 1*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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 "base_reference_test.hpp"
#include "ngraph_functions/builders.hpp"

namespace ComparisonOpsRefTestDefinitions {
struct RefComparisonParams {
template <class IT, class OT>
RefComparisonParams(const ngraph::helpers::ComparisonTypes comp, const ngraph::PartialShape& input_shape1, const ngraph::PartialShape& input_shape2,
const ngraph::element::Type& iType, const ngraph::element::Type& oType, const std::vector<IT>& iValues1,
const std::vector<IT>& iValues2, const std::vector<OT>& oValues)
: comparisonType(comp),
pshape1(input_shape1),
pshape2(input_shape2),
inType(iType),
outType(oType),
inputData1(CreateBlob(iType, iValues1)),
inputData2(CreateBlob(iType, iValues2)),
refData(CreateBlob(oType, oValues)) {}
ngraph::helpers::ComparisonTypes comparisonType;
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 ReferenceComparisonLayerTest : public testing::TestWithParam<RefComparisonParams>, public CommonReferenceTest {
blesniewski marked this conversation as resolved.
Show resolved Hide resolved
blesniewski marked this conversation as resolved.
Show resolved Hide resolved
public:
void SetUp() override {
const auto& params = GetParam();
function = CreateFunction(params.comparisonType, params.pshape1, params.pshape2, params.inType, params.outType);
inputData = {params.inputData1, params.inputData2};
refOutData = {params.refData};
}
static std::string getTestCaseName(const testing::TestParamInfo<RefComparisonParams>& obj) {
const auto& param = obj.param;
std::ostringstream result;
result << "comparisonType=" << param.comparisonType << "_";
result << "inpt_shape1=" << param.pshape1 << "_";
result << "inpt_shape2=" << param.pshape2 << "_";
result << "iType=" << param.inType << "_";
result << "oType=" << param.outType;
return result.str();
}

private:
static std::shared_ptr<ngraph::Function> CreateFunction(ngraph::helpers::ComparisonTypes comp_op_type, const ngraph::PartialShape& input_shape1,
const ngraph::PartialShape& input_shape2, const ngraph::element::Type& input_type,
const ngraph::element::Type& expected_output_type) {
const auto in = std::make_shared<ngraph::op::Parameter>(input_type, input_shape1);
const auto in2 = std::make_shared<ngraph::op::Parameter>(input_type, input_shape2);
const auto comp = ngraph::builder::makeComparison(in, in2, comp_op_type);
return std::make_shared<ngraph::Function>(ngraph::NodeVector {comp}, ngraph::ParameterVector {in, in2});
}
};
} // namespace ComparisonOpsRefTestDefinitions
75 changes: 75 additions & 0 deletions docs/template_plugin/tests/functional/op_reference/equal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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 "comparison.hpp"

using namespace ngraph;
using namespace InferenceEngine;
using ComparisonTypes = ngraph::helpers::ComparisonTypes;

namespace ComparisonOpsRefTestDefinitions {
namespace {

TEST_P(ReferenceComparisonLayerTest, EqualCompareWithHardcodedRefs) {
Exec();
}

template <element::Type_t IN_ET>
std::vector<RefComparisonParams> generateComparisonParams(const element::Type& type) {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<RefComparisonParams> compParams {
// 1D // 2D // 3D // 4D
RefComparisonParams(ComparisonTypes::EQUAL, PartialShape {2, 2}, PartialShape {2, 2}, type, element::boolean,
std::vector<T> {0, 12, 23, 0},
std::vector<T> {0, 12, 23, 0},
std::vector<char> {1, 1, 1, 1}),
RefComparisonParams(ComparisonTypes::EQUAL, PartialShape {2, 3}, PartialShape {2, 3}, type, element::boolean,
std::vector<T> {0, 6, 45, 1, 21, 21},
std::vector<T> {1, 18, 23, 1, 19, 21},
std::vector<char> {0, 0, 0, 1, 0, 1}),
RefComparisonParams(ComparisonTypes::EQUAL, PartialShape {1}, PartialShape {1}, type, element::boolean,
std::vector<T> {53},
std::vector<T> {53},
std::vector<char> {1}),
RefComparisonParams(ComparisonTypes::EQUAL, PartialShape {2, 4}, PartialShape {2, 4}, type, element::boolean,
std::vector<T> {0, 12, 23, 0, 1, 5, 11, 8},
std::vector<T> {0, 12, 23, 0, 10, 5, 11, 8},
std::vector<char> {1, 1, 1, 1, 0, 1, 1, 1}),
RefComparisonParams(ComparisonTypes::EQUAL, PartialShape {3, 1, 2}, PartialShape {1, 2, 1}, type, element::boolean,
std::vector<T> {2, 1, 4, 1, 3, 1},
std::vector<T> {1, 1},
std::vector<char> {0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}),
RefComparisonParams(ComparisonTypes::EQUAL, PartialShape {2, 1, 2, 1}, PartialShape {1, 2, 1}, type, element::boolean,
std::vector<T> {2, 1, 4, 1},
std::vector<T> {1, 1},
std::vector<char> {0, 1, 0, 1})};
return compParams;
}

std::vector<RefComparisonParams> generateComparisonCombinedParams() {
const std::vector<std::vector<RefComparisonParams>> compTypeParams {
generateComparisonParams<element::Type_t::f32>(element::f32),
generateComparisonParams<element::Type_t::f16>(element::f16),
generateComparisonParams<element::Type_t::i32>(element::i32),
generateComparisonParams<element::Type_t::u32>(element::u32),
generateComparisonParams<element::Type_t::u8>(element::boolean)};
std::vector<RefComparisonParams> combinedParams;

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

INSTANTIATE_TEST_SUITE_P(smoke_Comparison_With_Hardcoded_Refs, ReferenceComparisonLayerTest, ::testing::ValuesIn(generateComparisonCombinedParams()),
ReferenceComparisonLayerTest::getTestCaseName);
} // namespace
} // namespace ComparisonOpsRefTestDefinitions
75 changes: 75 additions & 0 deletions docs/template_plugin/tests/functional/op_reference/less.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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 "comparison.hpp"

using namespace ngraph;
using namespace InferenceEngine;
using ComparisonTypes = ngraph::helpers::ComparisonTypes;


namespace ComparisonOpsRefTestDefinitions {
namespace {
TEST_P(ReferenceComparisonLayerTest, LessCompareWithHardcodedRefs) {
Exec();
}

template <element::Type_t IN_ET>
std::vector<RefComparisonParams> generateComparisonParams(const element::Type& type) {
using T = typename element_type_traits<IN_ET>::value_type;
std::vector<RefComparisonParams> compParams {
// 1D // 2D // 3D // 4D
RefComparisonParams(ComparisonTypes::LESS, PartialShape {2, 2}, PartialShape {2, 2}, type, element::boolean,
std::vector<T> {0, 12, 23, 0},
std::vector<T> {0, 12, 23, 0},
std::vector<char> {0, 0, 0, 0}),
RefComparisonParams(ComparisonTypes::LESS, PartialShape {2, 3}, PartialShape {2, 3}, type, element::boolean,
std::vector<T> {0, 6, 45, 1, 21, 21},
std::vector<T> {1, 18, 23, 1, 19, 21},
std::vector<char> {1, 1, 0, 0, 0, 0}),
RefComparisonParams(ComparisonTypes::LESS, PartialShape {1}, PartialShape {1}, type, element::boolean,
std::vector<T> {53},
std::vector<T> {53},
std::vector<char> {0}),
RefComparisonParams(ComparisonTypes::LESS, PartialShape {2, 4}, PartialShape {2, 4}, type, element::boolean,
std::vector<T> {0, 12, 23, 0, 1, 5, 11, 8},
std::vector<T> {0, 12, 23, 0, 10, 5, 11, 8},
std::vector<char> {0, 0, 0, 0, 1, 0, 0, 0}),
RefComparisonParams(ComparisonTypes::LESS, PartialShape {3, 1, 2}, PartialShape {1, 2, 1}, type, element::boolean,
std::vector<T> {2, 1, 4, 1, 3, 1},
std::vector<T> {1, 1},
std::vector<char> {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}),
RefComparisonParams(ComparisonTypes::LESS, PartialShape {2, 1, 2, 1}, PartialShape {1, 2, 1}, type, element::boolean,
std::vector<T> {2, 1, 4, 1},
std::vector<T> {1, 1},
std::vector<char> {0, 0, 0, 0})};
return compParams;
}

std::vector<RefComparisonParams> generateComparisonCombinedParams() {
const std::vector<std::vector<RefComparisonParams>> compTypeParams {
generateComparisonParams<element::Type_t::f32>(element::f32),
generateComparisonParams<element::Type_t::f16>(element::f16),
generateComparisonParams<element::Type_t::i32>(element::i32),
generateComparisonParams<element::Type_t::u32>(element::u32),
generateComparisonParams<element::Type_t::u8>(element::boolean)};
std::vector<RefComparisonParams> 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
'HSwish-4',
'HardSigmoid-1',
'Interpolate-4',
'Less-1',
'LRN-1',
'LSTMCell-4',
'LSTMSequence-5',
Expand Down