[TESTS] Added Comparison and Logical single layer tests (#1242)

This commit is contained in:
Gorokhov Dmitriy
2020-07-10 13:56:22 +03:00
committed by GitHub
parent 8d1e7a705d
commit 8768313fef
15 changed files with 656 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include "single_layer_tests/comparison.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using namespace LayerTestsDefinitions::ComparisonParams;
namespace {
std::map<std::vector<size_t>, std::vector<std::vector<size_t >>> 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::vector<InferenceEngine::Precision> inputsPrecisions = {
InferenceEngine::Precision::FP32,
};
std::vector<ngraph::helpers::ComparisonTypes> comparisonOpTypes = {
ngraph::helpers::ComparisonTypes::EQUAL,
ngraph::helpers::ComparisonTypes::NOT_EQUAL,
ngraph::helpers::ComparisonTypes::GREATER,
ngraph::helpers::ComparisonTypes::GREATER_EQUAL,
ngraph::helpers::ComparisonTypes::LESS,
ngraph::helpers::ComparisonTypes::LESS_EQUAL,
};
std::vector<ngraph::helpers::InputLayerType> secondInputTypes = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER,
};
std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
};
std::map<std::string, std::string> additional_config = {};
const auto ComparisonTestParams = ::testing::Combine(
::testing::ValuesIn(ComparisonLayerTest::combineShapes(inputShapes)),
::testing::ValuesIn(inputsPrecisions),
::testing::ValuesIn(comparisonOpTypes),
::testing::ValuesIn(secondInputTypes),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::Values(additional_config));
INSTANTIATE_TEST_CASE_P(CompareWithRefs, ComparisonLayerTest, ComparisonTestParams, ComparisonLayerTest::getTestCaseName);
} // namespace

View File

@@ -0,0 +1,75 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include "single_layer_tests/logical.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using namespace LayerTestsDefinitions::LogicalParams;
namespace {
std::map<std::vector<size_t>, std::vector<std::vector<size_t >>> 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<size_t>, std::vector<std::vector<size_t >>> inputShapesNot = {
{{1}, {}},
{{5}, {}},
{{2, 200}, {}},
{{1, 3, 20}, {}},
{{2, 17, 3, 4}, {}},
{{2, 1, 1, 3, 1}, {}},
};
std::vector<InferenceEngine::Precision> inputsPrecisions = {
InferenceEngine::Precision::BOOL,
};
std::vector<ngraph::helpers::LogicalTypes> logicalOpTypes = {
ngraph::helpers::LogicalTypes::LOGICAL_AND,
ngraph::helpers::LogicalTypes::LOGICAL_OR,
ngraph::helpers::LogicalTypes::LOGICAL_XOR,
};
std::vector<ngraph::helpers::InputLayerType> secondInputTypes = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER,
};
std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
};
std::map<std::string, std::string> additional_config = {};
const auto LogicalTestParams = ::testing::Combine(
::testing::ValuesIn(LogicalLayerTest::combineShapes(inputShapes)),
::testing::ValuesIn(inputsPrecisions),
::testing::ValuesIn(logicalOpTypes),
::testing::ValuesIn(secondInputTypes),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::Values(additional_config));
const auto LogicalTestParamsNot = ::testing::Combine(
::testing::ValuesIn(LogicalLayerTest::combineShapes(inputShapesNot)),
::testing::ValuesIn(inputsPrecisions),
::testing::Values(ngraph::helpers::LogicalTypes::LOGICAL_NOT),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::Values(additional_config));
INSTANTIATE_TEST_CASE_P(CompareWithRefs, LogicalLayerTest, LogicalTestParams, LogicalLayerTest::getTestCaseName);
INSTANTIATE_TEST_CASE_P(CompareWithRefsNot, LogicalLayerTest, LogicalTestParamsNot, LogicalLayerTest::getTestCaseName);
} // namespace

View File

@@ -0,0 +1,58 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include "single_layer_tests/comparison.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using namespace LayerTestsDefinitions::ComparisonParams;
namespace {
std::map<std::vector<size_t>, std::vector<std::vector<size_t >>> 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::vector<InferenceEngine::Precision> inputsPrecisions = {
InferenceEngine::Precision::FP32,
};
std::vector<ngraph::helpers::ComparisonTypes> comparisonOpTypes = {
ngraph::helpers::ComparisonTypes::EQUAL,
ngraph::helpers::ComparisonTypes::NOT_EQUAL,
ngraph::helpers::ComparisonTypes::GREATER,
ngraph::helpers::ComparisonTypes::GREATER_EQUAL,
ngraph::helpers::ComparisonTypes::LESS,
ngraph::helpers::ComparisonTypes::LESS_EQUAL,
};
std::vector<ngraph::helpers::InputLayerType> secondInputTypes = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER,
};
std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
};
std::map<std::string, std::string> additional_config = {};
const auto ComparisonTestParams = ::testing::Combine(
::testing::ValuesIn(ComparisonLayerTest::combineShapes(inputShapes)),
::testing::ValuesIn(inputsPrecisions),
::testing::ValuesIn(comparisonOpTypes),
::testing::ValuesIn(secondInputTypes),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_GPU),
::testing::Values(additional_config));
INSTANTIATE_TEST_CASE_P(CompareWithRefs, ComparisonLayerTest, ComparisonTestParams, ComparisonLayerTest::getTestCaseName);
} // namespace

View File

@@ -0,0 +1,75 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <vector>
#include "single_layer_tests/logical.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using namespace LayerTestsDefinitions::LogicalParams;
namespace {
std::map<std::vector<size_t>, std::vector<std::vector<size_t >>> 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<size_t>, std::vector<std::vector<size_t >>> inputShapesNot = {
{{1}, {}},
{{5}, {}},
{{2, 200}, {}},
{{1, 3, 20}, {}},
{{2, 17, 3, 4}, {}},
{{2, 1, 1, 3, 1}, {}},
};
std::vector<InferenceEngine::Precision> inputsPrecisions = {
InferenceEngine::Precision::BOOL,
};
std::vector<ngraph::helpers::LogicalTypes> logicalOpTypes = {
ngraph::helpers::LogicalTypes::LOGICAL_AND,
ngraph::helpers::LogicalTypes::LOGICAL_OR,
ngraph::helpers::LogicalTypes::LOGICAL_XOR,
};
std::vector<ngraph::helpers::InputLayerType> secondInputTypes = {
ngraph::helpers::InputLayerType::CONSTANT,
ngraph::helpers::InputLayerType::PARAMETER,
};
std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32,
};
std::map<std::string, std::string> additional_config = {};
const auto LogicalTestParams = ::testing::Combine(
::testing::ValuesIn(LogicalLayerTest::combineShapes(inputShapes)),
::testing::ValuesIn(inputsPrecisions),
::testing::ValuesIn(logicalOpTypes),
::testing::ValuesIn(secondInputTypes),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::Values(additional_config));
const auto LogicalTestParamsNot = ::testing::Combine(
::testing::ValuesIn(LogicalLayerTest::combineShapes(inputShapesNot)),
::testing::ValuesIn(inputsPrecisions),
::testing::Values(ngraph::helpers::LogicalTypes::LOGICAL_NOT),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::ValuesIn(netPrecisions),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::Values(additional_config));
INSTANTIATE_TEST_CASE_P(CompareWithRefs, LogicalLayerTest, LogicalTestParams, LogicalLayerTest::getTestCaseName);
INSTANTIATE_TEST_CASE_P(CompareWithRefsNot, LogicalLayerTest, LogicalTestParamsNot, LogicalLayerTest::getTestCaseName);
} // namespace

View File

@@ -16,5 +16,7 @@ std::vector<std::string> disabledTestPatterns() {
".*BehaviorTests\\.pluginDoesNotChangeOriginalNetwork.*",
//TODO: Issue: 34349
R"(.*(IEClassLoadNetwork).*(QueryNetworkMULTIWithHETERONoThrow_V10|QueryNetworkHETEROWithMULTINoThrow_V10).*)",
//TODO: Issue: 34748
R"(.*(ComparisonLayerTest).*)",
};
}

View File

@@ -0,0 +1,40 @@
// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
#include <gtest/gtest.h>
#include <map>
#include <functional_test_utils/layer_test_utils.hpp>
#include "common_test_utils/common_layers_params.hpp"
#include "common_test_utils/common_utils.hpp"
#include "common_test_utils/test_common.hpp"
#include "common_test_utils/test_constants.hpp"
#include "ie_core.hpp"
namespace LayerTestsDefinitions {
namespace ComparisonParams {
using InputShapesTuple = std::pair<std::vector<size_t>, std::vector<size_t>>;
} // ComparisonParams
typedef std::tuple<
ComparisonParams::InputShapesTuple, // Input shapes tuple
InferenceEngine::Precision, // Inputs precision
ngraph::helpers::ComparisonTypes, // Comparison op type
ngraph::helpers::InputLayerType, // Second input type
InferenceEngine::Precision, // Net precision
std::string, // Device name
std::map<std::string, std::string> // Additional network configuration
> ComparisonTestParams;
class ComparisonLayerTest : public testing::WithParamInterface<ComparisonTestParams>,
public LayerTestsUtils::LayerTestsCommon {
protected:
void SetUp() override;
public:
static std::string getTestCaseName(testing::TestParamInfo<ComparisonTestParams> obj);
static std::vector<ComparisonParams::InputShapesTuple> combineShapes(const std::map<std::vector<size_t>, std::vector<std::vector<size_t >>>& inputShapes);
};
} // namespace LayerTestsDefinitions

View File

@@ -0,0 +1,40 @@
// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
#include <gtest/gtest.h>
#include <map>
#include <functional_test_utils/layer_test_utils.hpp>
#include "common_test_utils/common_layers_params.hpp"
#include "common_test_utils/common_utils.hpp"
#include "common_test_utils/test_common.hpp"
#include "common_test_utils/test_constants.hpp"
#include "ie_core.hpp"
namespace LayerTestsDefinitions {
namespace LogicalParams {
using InputShapesTuple = std::pair<std::vector<size_t>, std::vector<size_t>>;
} // LogicalParams
typedef std::tuple<
LogicalParams::InputShapesTuple, // Input shapes tuple
InferenceEngine::Precision, // Inputs precision
ngraph::helpers::LogicalTypes, // Logical op type
ngraph::helpers::InputLayerType, // Second input type
InferenceEngine::Precision, // Net precision
std::string, // Device name
std::map<std::string, std::string> // Additional network configuration
> LogicalTestParams;
class LogicalLayerTest : public testing::WithParamInterface<LogicalTestParams>,
public LayerTestsUtils::LayerTestsCommon {
protected:
void SetUp() override;
public:
static std::string getTestCaseName(testing::TestParamInfo<LogicalTestParams> obj);
static std::vector<LogicalParams::InputShapesTuple> combineShapes(const std::map<std::vector<size_t>, std::vector<std::vector<size_t >>>& inputShapes);
};
} // namespace LayerTestsDefinitions

View File

@@ -0,0 +1,79 @@
// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include <map>
#include "functional_test_utils/layer_test_utils.hpp"
#include "ngraph_functions/builders.hpp"
#include "ngraph_functions/utils/ngraph_helpers.hpp"
#include "single_layer_tests/comparison.hpp"
using namespace LayerTestsDefinitions::ComparisonParams;
namespace LayerTestsDefinitions {
std::string ComparisonLayerTest::getTestCaseName(testing::TestParamInfo<ComparisonTestParams> obj) {
InputShapesTuple inputShapes;
InferenceEngine::Precision inputsPrecision;
ngraph::helpers::ComparisonTypes comparisonOpType;
ngraph::helpers::InputLayerType secondInputType;
InferenceEngine::Precision netPrecision;
std::string targetName;
std::map<std::string, std::string> additional_config;
std::tie(inputShapes, inputsPrecision, comparisonOpType, secondInputType, netPrecision, targetName, additional_config) = obj.param;
std::ostringstream results;
results << "IS0=" << CommonTestUtils::vec2str(inputShapes.first) << "_";
results << "IS1=" << CommonTestUtils::vec2str(inputShapes.second) << "_";
results << "inputsPRC=" << inputsPrecision.name() << "_";
results << "comparisonOpType=" << comparisonOpType << "_";
results << "secondInputType=" << secondInputType << "_";
results << "netPRC=" << netPrecision.name() << "_";
results << "targetDevice=" << targetName;
return results.str();
}
std::vector<InputShapesTuple> ComparisonLayerTest::combineShapes(const std::map<std::vector<size_t>, std::vector<std::vector<size_t >>>& inputShapes) {
std::vector<InputShapesTuple> resVec;
for (auto& inputShape : inputShapes) {
for (auto& item : inputShape.second) {
resVec.push_back({inputShape.first, item});
}
}
return resVec;
}
void ComparisonLayerTest::SetUp() {
InputShapesTuple inputShapes;
InferenceEngine::Precision inputsPrecision;
ngraph::helpers::ComparisonTypes comparisonOpType;
ngraph::helpers::InputLayerType secondInputType;
InferenceEngine::Precision netPrecision;
std::string targetName;
std::map<std::string, std::string> additional_config;
std::tie(inputShapes, inputsPrecision, comparisonOpType, secondInputType, netPrecision, targetDevice, additional_config) = this->GetParam();
auto ngInputsPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputsPrecision);
configuration.insert(additional_config.begin(), additional_config.end());
auto inputs = ngraph::builder::makeParams(ngInputsPrc, {inputShapes.first});
auto secondInput = ngraph::builder::makeInputLayer(ngInputsPrc, secondInputType, inputShapes.second);
if (secondInputType == ngraph::helpers::InputLayerType::PARAMETER) {
inputs.push_back(std::dynamic_pointer_cast<ngraph::opset3::Parameter>(secondInput));
}
auto comparisonNode = ngraph::builder::makeComparison(inputs[0], secondInput, comparisonOpType);
function = std::make_shared<ngraph::Function>(comparisonNode, inputs, "Comparison");
}
TEST_P(ComparisonLayerTest, ComparisonTests) {
Run();
}
} // namespace LayerTestsDefinitions

View File

@@ -0,0 +1,88 @@
// Copyright (C) 2020 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include <map>
#include "functional_test_utils/layer_test_utils.hpp"
#include "ngraph_functions/builders.hpp"
#include "ngraph_functions/utils/ngraph_helpers.hpp"
#include "single_layer_tests/logical.hpp"
using namespace LayerTestsDefinitions::LogicalParams;
namespace LayerTestsDefinitions {
std::string LogicalLayerTest::getTestCaseName(testing::TestParamInfo<LogicalTestParams> obj) {
InputShapesTuple inputShapes;
InferenceEngine::Precision inputsPrecision;
ngraph::helpers::LogicalTypes comparisonOpType;
ngraph::helpers::InputLayerType secondInputType;
InferenceEngine::Precision netPrecision;
std::string targetName;
std::map<std::string, std::string> additional_config;
std::tie(inputShapes, inputsPrecision, comparisonOpType, secondInputType, netPrecision, targetName, additional_config) = obj.param;
std::ostringstream results;
results << "IS0=" << CommonTestUtils::vec2str(inputShapes.first) << "_";
results << "IS1=" << CommonTestUtils::vec2str(inputShapes.second) << "_";
results << "inputsPRC=" << inputsPrecision.name() << "_";
results << "comparisonOpType=" << comparisonOpType << "_";
results << "secondInputType=" << secondInputType << "_";
results << "netPRC=" << netPrecision.name() << "_";
results << "targetDevice=" << targetName;
return results.str();
}
std::vector<InputShapesTuple> LogicalLayerTest::combineShapes(const std::map<std::vector<size_t>, std::vector<std::vector<size_t >>>& inputShapes) {
std::vector<InputShapesTuple> resVec;
for (auto& inputShape : inputShapes) {
for (auto& item : inputShape.second) {
resVec.push_back({inputShape.first, item});
}
if (inputShape.second.empty()) {
resVec.push_back({inputShape.first, {}});
}
}
return resVec;
}
void LogicalLayerTest::SetUp() {
InputShapesTuple inputShapes;
InferenceEngine::Precision inputsPrecision;
ngraph::helpers::LogicalTypes logicalOpType;
ngraph::helpers::InputLayerType secondInputType;
InferenceEngine::Precision netPrecision;
std::string targetName;
std::map<std::string, std::string> additional_config;
std::tie(inputShapes, inputsPrecision, logicalOpType, secondInputType, netPrecision, targetDevice, additional_config) = this->GetParam();
auto ngInputsPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(inputsPrecision);
configuration.insert(additional_config.begin(), additional_config.end());
auto inputs = ngraph::builder::makeParams(ngInputsPrc, {inputShapes.first});
std::shared_ptr<ngraph::Node> logicalNode;
if (logicalOpType != ngraph::helpers::LogicalTypes::LOGICAL_NOT) {
auto secondInput = ngraph::builder::makeInputLayer(ngInputsPrc, secondInputType, inputShapes.second);
if (secondInputType == ngraph::helpers::InputLayerType::PARAMETER) {
inputs.push_back(std::dynamic_pointer_cast<ngraph::opset3::Parameter>(secondInput));
}
logicalNode = ngraph::builder::makeLogical(inputs[0], secondInput, logicalOpType);
} else {
logicalNode = ngraph::builder::makeLogical(inputs[0], ngraph::Output<ngraph::Node>(), logicalOpType);
}
function = std::make_shared<ngraph::Function>(logicalNode, inputs, "Logical");
}
TEST_P(LogicalLayerTest, LogicalTests) {
Run();
}
} // namespace LayerTestsDefinitions

View File

@@ -290,5 +290,13 @@ std::shared_ptr<ngraph::Node> makeScatterNDUpdate(const ngraph::Output<Node> &in
const std::vector<size_t>& indices,
const ngraph::Output<Node> &update);
std::shared_ptr<ngraph::Node> makeComparison(const ngraph::Output<Node> &in0,
const ngraph::Output<Node> &in1,
ngraph::helpers::ComparisonTypes comparisonType);
std::shared_ptr<ngraph::Node> makeLogical(const ngraph::Output<Node> &in0,
const ngraph::Output<Node> &in1,
ngraph::helpers::LogicalTypes logicalType);
} // namespace builder
} // namespace ngraph

View File

@@ -115,6 +115,22 @@ enum EltwiseTypes {
SUBTRACT
};
enum ComparisonTypes {
EQUAL,
NOT_EQUAL,
LESS,
LESS_EQUAL,
GREATER,
GREATER_EQUAL
};
enum LogicalTypes {
LOGICAL_AND,
LOGICAL_OR,
LOGICAL_XOR,
LOGICAL_NOT
};
enum SqueezeOpType {
SQUEEZE,
UNSQUEEZE
@@ -204,5 +220,9 @@ std::ostream& operator<<(std::ostream & os, ngraph::helpers::SqueezeOpType type)
std::ostream& operator<<(std::ostream& os, ngraph::helpers::InputLayerType type);
std::ostream& operator<<(std::ostream & os, ngraph::helpers::ComparisonTypes type);
std::ostream& operator<<(std::ostream & os, ngraph::helpers::LogicalTypes type);
} // namespace helpers
} // namespace ngraph

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <memory>
#include <ngraph/opsets/opset3.hpp>
#include "ngraph_functions/utils/ngraph_helpers.hpp"
namespace ngraph {
namespace builder {
std::shared_ptr<ngraph::Node> makeComparison(const ngraph::Output<Node> &in0,
const ngraph::Output<Node> &in1,
ngraph::helpers::ComparisonTypes comparisonType) {
switch (comparisonType) {
case ngraph::helpers::ComparisonTypes::EQUAL:
return std::make_shared<ngraph::opset3::Equal>(in0, in1);
case ngraph::helpers::ComparisonTypes::NOT_EQUAL:
return std::make_shared<ngraph::opset3::NotEqual>(in0, in1);
case ngraph::helpers::ComparisonTypes::GREATER:
return std::make_shared<ngraph::opset3::Greater>(in0, in1);
case ngraph::helpers::ComparisonTypes::GREATER_EQUAL:
return std::make_shared<ngraph::opset3::GreaterEqual>(in0, in1);
case ngraph::helpers::ComparisonTypes::LESS:
return std::make_shared<ngraph::opset3::Less>(in0, in1);
case ngraph::helpers::ComparisonTypes::LESS_EQUAL:
return std::make_shared<ngraph::opset3::LessEqual>(in0, in1);
default: {
throw std::runtime_error("Incorrect type of Comparison operation");
}
}
}
} // namespace builder
} // namespace ngraph

View File

@@ -46,6 +46,7 @@ std::shared_ptr<Node> makeConstant(const element::Type &type, const std::vector<
makeNode(ngraph::element::Type_t::u16);
makeNode(ngraph::element::Type_t::u32);
makeNode(ngraph::element::Type_t::u64);
makeNode(ngraph::element::Type_t::boolean);
#undef makeNode
default:
throw std::runtime_error("Unhandled precision");

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2020 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <memory>
#include <ngraph/opsets/opset3.hpp>
#include "ngraph_functions/utils/ngraph_helpers.hpp"
namespace ngraph {
namespace builder {
std::shared_ptr<ngraph::Node> makeLogical(const ngraph::Output<Node> &in0,
const ngraph::Output<Node> &in1,
ngraph::helpers::LogicalTypes logicalType) {
switch (logicalType) {
case ngraph::helpers::LogicalTypes::LOGICAL_AND:
return std::make_shared<ngraph::opset3::LogicalAnd>(in0, in1);
case ngraph::helpers::LogicalTypes::LOGICAL_OR:
return std::make_shared<ngraph::opset3::LogicalOr>(in0, in1);
case ngraph::helpers::LogicalTypes::LOGICAL_NOT:
return std::make_shared<ngraph::opset3::LogicalNot>(in0);
case ngraph::helpers::LogicalTypes::LOGICAL_XOR:
return std::make_shared<ngraph::opset3::LogicalXor>(in0, in1);
default: {
throw std::runtime_error("Incorrect type of Logical operation");
}
}
}
} // namespace builder
} // namespace ngraph

View File

@@ -560,5 +560,51 @@ std::ostream& operator<<(std::ostream& os, ngraph::helpers::InputLayerType type)
return os;
}
std::ostream& operator<<(std::ostream & os, ngraph::helpers::ComparisonTypes type) {
switch (type) {
case ngraph::helpers::ComparisonTypes::EQUAL:
os << "Equal";
break;
case ngraph::helpers::ComparisonTypes::NOT_EQUAL:
os << "NotEqual";
break;
case ngraph::helpers::ComparisonTypes::GREATER:
os << "Greater";
break;
case ngraph::helpers::ComparisonTypes::GREATER_EQUAL:
os << "GreaterEqual";
break;
case ngraph::helpers::ComparisonTypes::LESS:
os << "Less";
break;
case ngraph::helpers::ComparisonTypes::LESS_EQUAL:
os << "LessEqual";
break;
default:
throw std::runtime_error("NOT_SUPPORTED_OP_TYPE");
}
return os;
}
std::ostream& operator<<(std::ostream & os, ngraph::helpers::LogicalTypes type) {
switch (type) {
case ngraph::helpers::LogicalTypes::LOGICAL_AND:
os << "LogicalAnd";
break;
case ngraph::helpers::LogicalTypes::LOGICAL_OR:
os << "LogicalOr";
break;
case ngraph::helpers::LogicalTypes::LOGICAL_NOT:
os << "LogicalNot";
break;
case ngraph::helpers::LogicalTypes::LOGICAL_XOR:
os << "LogicalXor";
break;
default:
throw std::runtime_error("NOT_SUPPORTED_OP_TYPE");
}
return os;
}
} // namespace helpers
} // namespace ngraph