From add3b11880c42b2333b8945b6491b27be0a9d4f7 Mon Sep 17 00:00:00 2001 From: Nikolay Shchegolev Date: Thu, 1 Dec 2022 16:34:39 +0400 Subject: [PATCH] [CPU] New operations: IsFinite, IsInf, IsNaN. (#14314) --- src/bindings/python/tests/__init__.py | 2 - .../python/tests/test_onnx/test_backend.py | 8 -- .../python/tests_compatibility/__init__.py | 2 - .../test_onnx/test_backend.py | 8 -- .../onnx/tests/runtime/ie/unit_test.manifest | 7 -- src/plugins/intel_cpu/src/cpu_types.cpp | 6 ++ src/plugins/intel_cpu/src/cpu_types.h | 3 + src/plugins/intel_cpu/src/nodes/eltwise.cpp | 23 +++++ .../single_layer_tests/comparison.cpp | 18 ++++ .../single_layer_tests/is_inf.cpp | 73 +++++++++++++++ .../include/single_layer_tests/is_inf.hpp | 37 ++++++++ .../shared/src/single_layer_tests/is_inf.cpp | 91 +++++++++++++++++++ .../single_layer/comparison.hpp | 2 + .../src/single_layer/comparison.cpp | 39 ++++++-- .../ngraph_functions/utils/ngraph_helpers.hpp | 3 + .../ngraph_functions/src/comparison.cpp | 12 ++- .../src/utils/ngraph_helpers.cpp | 9 ++ tests/layer_tests/common/utils/tf_utils.py | 2 +- .../tensorflow_tests/test_tf_IsFinite.py | 1 - .../tensorflow_tests/test_tf_IsInf.py | 1 - .../tensorflow_tests/test_tf_IsNan.py | 1 - 21 files changed, 307 insertions(+), 41 deletions(-) create mode 100644 src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/is_inf.cpp create mode 100644 src/tests/functional/plugin/shared/include/single_layer_tests/is_inf.hpp create mode 100644 src/tests/functional/plugin/shared/src/single_layer_tests/is_inf.cpp diff --git a/src/bindings/python/tests/__init__.py b/src/bindings/python/tests/__init__.py index c3d2c0bb121..95bafaaa833 100644 --- a/src/bindings/python/tests/__init__.py +++ b/src/bindings/python/tests/__init__.py @@ -34,8 +34,6 @@ xfail_issue_33488 = xfail_test(reason="RuntimeError: OV does not support the fol "MaxUnpool") skip_issue_38084 = pytest.mark.skip(reason="Aborted (core dumped) Assertion " "`(layer->get_output_partial_shape(i).is_static())' failed.") -xfail_issue_33589 = xfail_test(reason="OV does not support the following ONNX operations: " - "IsNaN and isInf") xfail_issue_33595 = xfail_test(reason="RuntimeError: OV does not support the following ONNX operations: " "Unique") xfail_issue_33596 = xfail_test(reason="RuntimeError: OV does not support different sequence operations: " diff --git a/src/bindings/python/tests/test_onnx/test_backend.py b/src/bindings/python/tests/test_onnx/test_backend.py index ee9deec7572..95bd7e5915e 100644 --- a/src/bindings/python/tests/test_onnx/test_backend.py +++ b/src/bindings/python/tests/test_onnx/test_backend.py @@ -10,7 +10,6 @@ from tests import ( skip_rng_tests, xfail_issue_33488, xfail_issue_33581, - xfail_issue_33589, xfail_issue_33595, xfail_issue_33596, xfail_issue_33606, @@ -223,13 +222,6 @@ tests_expected_to_fail = [ "OnnxBackendNodeModelTest.test_maxunpool_export_with_output_shape_cpu", "OnnxBackendNodeModelTest.test_maxunpool_export_without_output_shape_cpu", ), - ( - xfail_issue_33589, - "OnnxBackendNodeModelTest.test_isnan_cpu", - "OnnxBackendNodeModelTest.test_isinf_positive_cpu", - "OnnxBackendNodeModelTest.test_isinf_negative_cpu", - "OnnxBackendNodeModelTest.test_isinf_cpu", - ), (xfail_issue_38724, "OnnxBackendNodeModelTest.test_resize_tf_crop_and_resize_cpu"), ( xfail_issue_33606, diff --git a/src/bindings/python/tests_compatibility/__init__.py b/src/bindings/python/tests_compatibility/__init__.py index 771f6ffb7bb..3bd5872fef2 100644 --- a/src/bindings/python/tests_compatibility/__init__.py +++ b/src/bindings/python/tests_compatibility/__init__.py @@ -31,8 +31,6 @@ xfail_issue_33488 = xfail_test(reason="RuntimeError: nGraph does not support the "MaxUnpool") skip_issue_38084 = pytest.mark.skip(reason="Aborted (core dumped) Assertion " "`(layer->get_output_partial_shape(i).is_static())' failed.") -xfail_issue_33589 = xfail_test(reason="nGraph does not support the following ONNX operations: " - "IsNaN and isInf") xfail_issue_33595 = xfail_test(reason="RuntimeError: nGraph does not support the following ONNX operations: " "Unique") xfail_issue_33596 = xfail_test(reason="RuntimeError: nGraph does not support different sequence operations: " diff --git a/src/bindings/python/tests_compatibility/test_onnx/test_backend.py b/src/bindings/python/tests_compatibility/test_onnx/test_backend.py index cec63ca96c2..bc14c1543d9 100644 --- a/src/bindings/python/tests_compatibility/test_onnx/test_backend.py +++ b/src/bindings/python/tests_compatibility/test_onnx/test_backend.py @@ -10,7 +10,6 @@ from tests_compatibility import ( xfail_unsupported_by_legacy_api, xfail_issue_33488, xfail_issue_33581, - xfail_issue_33589, xfail_issue_33595, xfail_issue_33596, xfail_issue_33606, @@ -224,13 +223,6 @@ tests_expected_to_fail = [ "OnnxBackendNodeModelTest.test_maxunpool_export_with_output_shape_cpu", "OnnxBackendNodeModelTest.test_maxunpool_export_without_output_shape_cpu", ), - ( - xfail_issue_33589, - "OnnxBackendNodeModelTest.test_isnan_cpu", - "OnnxBackendNodeModelTest.test_isinf_positive_cpu", - "OnnxBackendNodeModelTest.test_isinf_negative_cpu", - "OnnxBackendNodeModelTest.test_isinf_cpu", - ), (xfail_issue_38724, "OnnxBackendNodeModelTest.test_resize_tf_crop_and_resize_cpu"), ( xfail_issue_33606, diff --git a/src/frontends/onnx/tests/runtime/ie/unit_test.manifest b/src/frontends/onnx/tests/runtime/ie/unit_test.manifest index 583de22930b..f839dcf5fa3 100644 --- a/src/frontends/onnx/tests/runtime/ie/unit_test.manifest +++ b/src/frontends/onnx/tests/runtime/ie/unit_test.manifest @@ -425,10 +425,3 @@ IE_CPU.onnx_softmax_crossentropy_loss_mean # Cannot find blob with name: Y IE_CPU.onnx_bool_init_and - -IE_CPU.onnx_is_finite -IE_CPU.onnx_is_inf_default -IE_CPU.onnx_is_inf_negative_only -IE_CPU.onnx_is_inf_positive_only -IE_CPU.onnx_is_inf_detect_none -IE_CPU.onnx_is_nan diff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cpp index 905d8c04aca..86a2458b910 100644 --- a/src/plugins/intel_cpu/src/cpu_types.cpp +++ b/src/plugins/intel_cpu/src/cpu_types.cpp @@ -26,6 +26,9 @@ const InferenceEngine::details::caseless_unordered_map type_t { "AdaptiveMaxPool", Type::AdaptivePooling}, { "AdaptiveAvgPool", Type::AdaptivePooling}, { "Add", Type::Eltwise }, + { "IsFinite", Type::Eltwise }, + { "IsInf", Type::Eltwise }, + { "IsNaN", Type::Eltwise }, { "Subtract", Type::Eltwise }, { "Multiply", Type::Eltwise }, { "Divide", Type::Eltwise }, @@ -416,6 +419,9 @@ std::string algToString(const Algorithm alg) { CASE(DeconvolutionCommon); CASE(DeconvolutionGrouped); CASE(EltwiseAdd); + CASE(EltwiseIsFinite); + CASE(EltwiseIsInf); + CASE(EltwiseIsNaN); CASE(EltwiseMultiply); CASE(EltwiseSubtract); CASE(EltwiseDivide); diff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.h index be1558eb43a..671efdd5bef 100644 --- a/src/plugins/intel_cpu/src/cpu_types.h +++ b/src/plugins/intel_cpu/src/cpu_types.h @@ -134,6 +134,9 @@ enum class Algorithm { // Elementwise algorithms EltwiseAdd, + EltwiseIsFinite, + EltwiseIsInf, + EltwiseIsNaN, EltwiseMultiply, EltwiseSubtract, EltwiseDivide, diff --git a/src/plugins/intel_cpu/src/nodes/eltwise.cpp b/src/plugins/intel_cpu/src/nodes/eltwise.cpp index 17f2c0a90b5..6c9762605f6 100644 --- a/src/plugins/intel_cpu/src/nodes/eltwise.cpp +++ b/src/plugins/intel_cpu/src/nodes/eltwise.cpp @@ -940,6 +940,18 @@ const std::map Eltwise::in {ngraph::op::v1::NotEqual::get_type_info_static(), [](const std::shared_ptr& op, Eltwise& node) { node.algorithm = Algorithm::EltwiseNotEqual; }}, + {ov::op::v10::IsFinite::get_type_info_static(), [](const std::shared_ptr& op, Eltwise& node) { + node.algorithm = Algorithm::EltwiseIsFinite; + }}, + {ov::op::v10::IsInf::get_type_info_static(), [](const std::shared_ptr& op, Eltwise& node) { + node.algorithm = Algorithm::EltwiseIsInf; + const auto& attributes = ov::as_type_ptr(op)->get_attributes(); + node.alpha = attributes.detect_negative; + node.beta = attributes.detect_positive; + }}, + {ov::op::v10::IsNaN::get_type_info_static(), [](const std::shared_ptr& op, Eltwise& node) { + node.algorithm = Algorithm::EltwiseIsNaN; + }}, {ngraph::op::v1::Greater::get_type_info_static(), [](const std::shared_ptr& op, Eltwise& node) { node.algorithm = Algorithm::EltwiseGreater; }}, @@ -1562,6 +1574,12 @@ public: case Algorithm::EltwisePrelu: *dst_ptr_f = src_f[0] > 0 ? src_f[0] : src_f[0] * src_f[1]; break; case Algorithm::EltwiseErf: *dst_ptr_f = std::erf(src_f[0]); break; case Algorithm::EltwiseSoftSign: *dst_ptr_f = src_f[0] / (1 + std::fabs(src_f[0])); break; + case Algorithm::EltwiseIsFinite: *dst_ptr_f = std::isfinite(src_f[0]); break; + case Algorithm::EltwiseIsInf: + *dst_ptr_f = _opData.alpha && (src_f[0] == -std::numeric_limits::infinity()) || + _opData.beta && (src_f[0] == std::numeric_limits::infinity()); + break; + case Algorithm::EltwiseIsNaN: *dst_ptr_f = std::isnan(src_f[0]); break; default: IE_THROW() << "Unsupported operation type for Eltwise executor"; } } @@ -1646,6 +1664,9 @@ Eltwise::Eltwise(const std::shared_ptr& op, const dnnl::engine& en size_t Eltwise::getOpInputsNum() const { switch (getAlgorithm()) { + case Algorithm::EltwiseIsFinite: + case Algorithm::EltwiseIsInf: + case Algorithm::EltwiseIsNaN: case Algorithm::EltwiseRelu: case Algorithm::EltwiseGelu: case Algorithm::EltwiseElu: @@ -1729,6 +1750,8 @@ void Eltwise::initSupportedPrimitiveDescriptors() { // if dim rank is greater than the maximum possible, we should use the reference execution canUseOptimizedImpl = mayiuse(x64::sse41) && getInputShapeAtPort(0).getRank() <= MAX_ELTWISE_DIM_RANK; + // 98206 to add JIT implementation. + canUseOptimizedImpl &= !one_of(getAlgorithm(), Algorithm::EltwiseIsFinite, Algorithm::EltwiseIsInf, Algorithm::EltwiseIsNaN); if (!canUseOptimizedImpl && !fusedWith.empty()) { IE_THROW(Unexpected) << "Eltwise node with name '" << getName() << "' uses reference impl, but unexpectedly fused with other ops"; diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/comparison.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/comparison.cpp index 450749c4745..a66e4fe6cc2 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/comparison.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/comparison.cpp @@ -55,4 +55,22 @@ const auto ComparisonTestParams = ::testing::Combine( INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ComparisonLayerTest, ComparisonTestParams, ComparisonLayerTest::getTestCaseName); +std::vector comparisonOpTypesIs = { + ngraph::helpers::ComparisonTypes::IS_FINITE, + ngraph::helpers::ComparisonTypes::IS_INF, + ngraph::helpers::ComparisonTypes::IS_NAN +}; + +const auto ComparisonTestParamsIs = ::testing::Combine( + ::testing::ValuesIn(CommonTestUtils::combineParams(inputShapes)), + ::testing::Values(InferenceEngine::Precision::FP32), + ::testing::ValuesIn(comparisonOpTypesIs), + ::testing::Values(ngraph::helpers::InputLayerType::CONSTANT), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(InferenceEngine::Precision::UNSPECIFIED), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(additional_config)); + +INSTANTIATE_TEST_SUITE_P(smoke_IsOp, ComparisonLayerTest, ComparisonTestParamsIs, ComparisonLayerTest::getTestCaseName); + } // namespace \ No newline at end of file diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/is_inf.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/is_inf.cpp new file mode 100644 index 00000000000..dd3d03c30ca --- /dev/null +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/is_inf.cpp @@ -0,0 +1,73 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "single_layer_tests/is_inf.hpp" + +using namespace ov::test; +using namespace ov::test::subgraph; + +namespace { +std::vector> inShapesStatic = { + { {{}, {{2}}} }, + { {{}, {{2, 200}}} }, + { {{}, {{10, 200}}} }, + { {{}, {{1, 10, 100}}} }, + { {{}, {{4, 4, 16}}} }, + { {{}, {{1, 1, 1, 3}}} }, + { {{}, {{2, 17, 5, 4}}} }, + { {{}, {{2, 17, 5, 1}}} }, + { {{}, {{1, 2, 4}}} }, + { {{}, {{1, 4, 4}}} }, + { {{}, {{1, 4, 4, 1}}} }, + { {{}, {{16, 16, 16, 16, 16}}} }, + { {{}, {{16, 16, 16, 16, 1}}} }, + { {{}, {{16, 16, 16, 1, 16}}} }, + { {{}, {{16, 32, 1, 1, 1}}} }, + { {{}, {{1, 1, 1, 1, 1, 1, 3}}} }, + { {{}, {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}} } +}; + +std::vector> inShapesDynamic = { + {{{ngraph::Dimension(1, 10), 200}, {{2, 200}, {1, 200}}}} +}; + +std::vector netPrecisions = { + ov::element::f32 +}; + +std::vector detectNegative = { + true, false +}; + +std::vector detectPositive = { + true, false +}; + +std::map additional_config = {}; + +const auto isInfParams = ::testing::Combine( + ::testing::ValuesIn(inShapesStatic), + ::testing::ValuesIn(detectNegative), + ::testing::ValuesIn(detectPositive), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(additional_config)); + +const auto isInfParamsDyn = ::testing::Combine( + ::testing::ValuesIn(inShapesDynamic), + ::testing::ValuesIn(detectNegative), + ::testing::ValuesIn(detectPositive), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_CPU), + ::testing::Values(additional_config)); + + +TEST_P(IsInfLayerTest, CompareWithRefs) { + run(); +} + +INSTANTIATE_TEST_SUITE_P(smoke_static, IsInfLayerTest, isInfParams, IsInfLayerTest::getTestCaseName); +INSTANTIATE_TEST_SUITE_P(smoke_dynamic, IsInfLayerTest, isInfParamsDyn, IsInfLayerTest::getTestCaseName); +} // namespace diff --git a/src/tests/functional/plugin/shared/include/single_layer_tests/is_inf.hpp b/src/tests/functional/plugin/shared/include/single_layer_tests/is_inf.hpp new file mode 100644 index 00000000000..96971c3705c --- /dev/null +++ b/src/tests/functional/plugin/shared/include/single_layer_tests/is_inf.hpp @@ -0,0 +1,37 @@ +// Copyright (C) 2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +#include "shared_test_classes/base/ov_subgraph.hpp" + +namespace ov { +namespace test { +namespace subgraph { + +using IsInfParams = std::tuple< + std::vector, // Data shape + bool, // Detect negative + bool, // Detect positive + ElementType, // Data precision + std::string, // Device name + std::map // Additional config + >; + +class IsInfLayerTest : public testing::WithParamInterface, + virtual public SubgraphBaseTest { +public: + static std::string getTestCaseName(const testing::TestParamInfo& obj); + +protected: + void SetUp() override; + void generate_inputs(const std::vector& targetInputStaticShapes) override; +}; + +} // namespace subgraph +} // namespace test +} // namespace ov diff --git a/src/tests/functional/plugin/shared/src/single_layer_tests/is_inf.cpp b/src/tests/functional/plugin/shared/src/single_layer_tests/is_inf.cpp new file mode 100644 index 00000000000..1776375fd91 --- /dev/null +++ b/src/tests/functional/plugin/shared/src/single_layer_tests/is_inf.cpp @@ -0,0 +1,91 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "single_layer_tests/is_inf.hpp" +#include "ngraph_functions/builders.hpp" +#include "ie_test_utils/common_test_utils/ov_tensor_utils.hpp" +#include "ie_plugin_config.hpp" + +using namespace ov::test::subgraph; + +std::string IsInfLayerTest::getTestCaseName(const testing::TestParamInfo& obj) { + std::vector inputShapes; + ElementType dataPrc; + bool detectNegative, detectPositive; + std::string targetName; + std::map additionalConfig; + std::tie(inputShapes, detectNegative, detectPositive, dataPrc, targetName, additionalConfig) = obj.param; + std::ostringstream result; + + result << "IS=("; + for (size_t i = 0lu; i < inputShapes.size(); i++) { + result << CommonTestUtils::partialShape2str({inputShapes[i].first}) << (i < inputShapes.size() - 1lu ? "_" : ""); + } + result << ")_TS="; + for (size_t i = 0lu; i < inputShapes.front().second.size(); i++) { + result << "{"; + for (size_t j = 0lu; j < inputShapes.size(); j++) { + result << CommonTestUtils::vec2str(inputShapes[j].second[i]) << (j < inputShapes.size() - 1lu ? "_" : ""); + } + result << "}_"; + } + result << ")_detectNegative=" << (detectNegative ? "True" : "False") << "_"; + result << "detectPositive=" << (detectPositive ? "True" : "False") << "_"; + result << "dataPrc=" << dataPrc << "_"; + result << "trgDev=" << targetName; + + if (!additionalConfig.empty()) { + result << "_PluginConf"; + for (auto &item : additionalConfig) { + if (item.second == InferenceEngine::PluginConfigParams::YES) + result << "_" << item.first << "=" << item.second; + } + } + + return result.str(); +} + +void IsInfLayerTest::SetUp() { + std::vector shapes; + ElementType dataPrc; + bool detectNegative, detectPositive; + std::string targetName; + std::map additionalConfig; + std::tie(shapes, detectNegative, detectPositive, dataPrc, targetDevice, additionalConfig) = this->GetParam(); + + init_input_shapes(shapes); + configuration.insert(additionalConfig.begin(), additionalConfig.end()); + + auto parameters = ngraph::builder::makeDynamicParams(dataPrc, inputDynamicShapes); + parameters[0]->set_friendly_name("Data"); + auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes(parameters)); + + ov::op::v10::IsInf::Attributes attributes {detectNegative, detectPositive}; + auto isInf = std::make_shared(paramOuts[0], attributes); + ov::ResultVector results; + for (int i = 0; i < isInf->get_output_size(); i++) { + results.push_back(std::make_shared(isInf->output(i))); + } + + function = std::make_shared(results, parameters, "IsInf"); +} + +void IsInfLayerTest::generate_inputs(const std::vector& targetInputStaticShapes) { + inputs.clear(); + const auto& funcInputs = function->inputs(); + const auto& input = funcInputs[0]; + + int32_t range = std::accumulate(targetInputStaticShapes[0].begin(), targetInputStaticShapes[0].end(), 1u, std::multiplies()); + auto tensor = utils::create_and_fill_tensor( + input.get_element_type(), targetInputStaticShapes[0], range, -range / 2, 1); + + auto pointer = tensor.data::value_type>(); + testing::internal::Random random(1); + + for (size_t i = 0; i < range / 2; i++) { + pointer[random.Generate(range)] = i % 2 == 0 ? std::numeric_limits::infinity() : -std::numeric_limits::infinity(); + } + + inputs.insert({input.get_node_shared_ptr(), tensor}); +} diff --git a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/comparison.hpp b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/comparison.hpp index e9e2292cc42..01023e43663 100644 --- a/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/comparison.hpp +++ b/src/tests/functional/shared_test_classes/include/shared_test_classes/single_layer/comparison.hpp @@ -32,10 +32,12 @@ typedef std::tuple< class ComparisonLayerTest : public testing::WithParamInterface, virtual public LayerTestsUtils::LayerTestsCommon { + ngraph::helpers::ComparisonTypes comparisonOpType; protected: void SetUp() override; public: static std::string getTestCaseName(const testing::TestParamInfo &obj); + InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo &inputInfo) const override; }; } // namespace LayerTestsDefinitions diff --git a/src/tests/functional/shared_test_classes/src/single_layer/comparison.cpp b/src/tests/functional/shared_test_classes/src/single_layer/comparison.cpp index e097f8688e5..6500661e7d6 100644 --- a/src/tests/functional/shared_test_classes/src/single_layer/comparison.cpp +++ b/src/tests/functional/shared_test_classes/src/single_layer/comparison.cpp @@ -6,13 +6,14 @@ #include "shared_test_classes/single_layer/comparison.hpp" using namespace LayerTestsDefinitions::ComparisonParams; +using namespace ngraph::helpers; namespace LayerTestsDefinitions { std::string ComparisonLayerTest::getTestCaseName(const testing::TestParamInfo &obj) { InputShapesTuple inputShapes; InferenceEngine::Precision ngInputsPrecision; - ngraph::helpers::ComparisonTypes comparisonOpType; - ngraph::helpers::InputLayerType secondInputType; + ComparisonTypes comparisonOpType; + InputLayerType secondInputType; InferenceEngine::Precision ieInPrecision; InferenceEngine::Precision ieOutPrecision; std::string targetName; @@ -45,8 +46,7 @@ std::string ComparisonLayerTest::getTestCaseName(const testing::TestParamInfo(secondInput)); + if (secondInputType == InputLayerType::PARAMETER) { + inputs.push_back(std::dynamic_pointer_cast(secondInput)); } auto comparisonNode = ngraph::builder::makeComparison(inputs[0], secondInput, comparisonOpType); - function = std::make_shared(comparisonNode, inputs, "Comparison"); + function = std::make_shared(comparisonNode, inputs, "Comparison"); } + +InferenceEngine::Blob::Ptr ComparisonLayerTest::GenerateInput(const InferenceEngine::InputInfo &inputInfo) const { + auto blob = LayerTestsUtils::LayerTestsCommon::GenerateInput(inputInfo); + + if (comparisonOpType == ComparisonTypes::IS_FINITE || comparisonOpType == ComparisonTypes::IS_NAN) { + auto *dataPtr = blob->buffer().as(); + auto range = blob->size(); + testing::internal::Random random(1); + + if (comparisonOpType == ComparisonTypes::IS_FINITE) { + for (size_t i = 0; i < range / 2; i++) { + dataPtr[random.Generate(range)] = + i % 3 == 0 ? std::numeric_limits::infinity() : i % 3 == 1 ? -std::numeric_limits::infinity() : + std::numeric_limits::quiet_NaN(); + } + } else { + for (size_t i = 0; i < range / 2; i++) { + dataPtr[random.Generate(range)] = std::numeric_limits::quiet_NaN(); + } + } + } + + return blob; +} + } // namespace LayerTestsDefinitions diff --git a/src/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/utils/ngraph_helpers.hpp b/src/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/utils/ngraph_helpers.hpp index 5ba1ad03b07..c4432cd6999 100644 --- a/src/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/utils/ngraph_helpers.hpp +++ b/src/tests/ngraph_helpers/ngraph_functions/include/ngraph_functions/utils/ngraph_helpers.hpp @@ -142,6 +142,9 @@ enum EltwiseTypes { enum ComparisonTypes { EQUAL, NOT_EQUAL, + IS_FINITE, + IS_INF, + IS_NAN, LESS, LESS_EQUAL, GREATER, diff --git a/src/tests/ngraph_helpers/ngraph_functions/src/comparison.cpp b/src/tests/ngraph_helpers/ngraph_functions/src/comparison.cpp index ae25002802a..9a79acec188 100644 --- a/src/tests/ngraph_helpers/ngraph_functions/src/comparison.cpp +++ b/src/tests/ngraph_helpers/ngraph_functions/src/comparison.cpp @@ -9,9 +9,9 @@ namespace ngraph { namespace builder { -std::shared_ptr makeComparison(const ngraph::Output &in0, - const ngraph::Output &in1, - ngraph::helpers::ComparisonTypes comparisonType) { +std::shared_ptr makeComparison(const ov::Output &in0, + const ov::Output &in1, + ngraph::helpers::ComparisonTypes comparisonType) { switch (comparisonType) { case ngraph::helpers::ComparisonTypes::EQUAL: return std::make_shared(in0, in1); @@ -21,6 +21,12 @@ std::shared_ptr makeComparison(const ngraph::Output &in0, return std::make_shared(in0, in1); case ngraph::helpers::ComparisonTypes::GREATER_EQUAL: return std::make_shared(in0, in1); + case ngraph::helpers::ComparisonTypes::IS_FINITE: + return std::make_shared(in0); + case ngraph::helpers::ComparisonTypes::IS_INF: + return std::make_shared(in0); + case ngraph::helpers::ComparisonTypes::IS_NAN: + return std::make_shared(in0); case ngraph::helpers::ComparisonTypes::LESS: return std::make_shared(in0, in1); case ngraph::helpers::ComparisonTypes::LESS_EQUAL: diff --git a/src/tests/ngraph_helpers/ngraph_functions/src/utils/ngraph_helpers.cpp b/src/tests/ngraph_helpers/ngraph_functions/src/utils/ngraph_helpers.cpp index de548ad6e27..5befe2ed878 100644 --- a/src/tests/ngraph_helpers/ngraph_functions/src/utils/ngraph_helpers.cpp +++ b/src/tests/ngraph_helpers/ngraph_functions/src/utils/ngraph_helpers.cpp @@ -722,6 +722,15 @@ std::ostream& operator<<(std::ostream & os, ngraph::helpers::ComparisonTypes typ case ngraph::helpers::ComparisonTypes::GREATER_EQUAL: os << "GreaterEqual"; break; + case ngraph::helpers::ComparisonTypes::IS_FINITE: + os << "IsFinite"; + break; + case ngraph::helpers::ComparisonTypes::IS_INF: + os << "IsInf"; + break; + case ngraph::helpers::ComparisonTypes::IS_NAN: + os << "IsNaN"; + break; case ngraph::helpers::ComparisonTypes::LESS: os << "Less"; break; diff --git a/tests/layer_tests/common/utils/tf_utils.py b/tests/layer_tests/common/utils/tf_utils.py index 65eb3cb613a..5f40713baf8 100644 --- a/tests/layer_tests/common/utils/tf_utils.py +++ b/tests/layer_tests/common/utils/tf_utils.py @@ -13,7 +13,7 @@ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' def mix_array_with_value(input_array, value): - input_shape = input_array + input_shape = input_array.shape mask = np.random.randint(0, 2, input_shape).astype(bool) return np.where(mask, input_array, value) diff --git a/tests/layer_tests/tensorflow_tests/test_tf_IsFinite.py b/tests/layer_tests/tensorflow_tests/test_tf_IsFinite.py index 0019c177866..d2f13a68f74 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_IsFinite.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_IsFinite.py @@ -37,7 +37,6 @@ class TestIsFinite(CommonTFLayerTest): ] @pytest.mark.parametrize("params", test_data_basic) - @pytest.mark.xfail(reason="94741") @pytest.mark.precommit_tf_fe def test_is_finite_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): diff --git a/tests/layer_tests/tensorflow_tests/test_tf_IsInf.py b/tests/layer_tests/tensorflow_tests/test_tf_IsInf.py index 0b22c903f9d..1ce9211dd23 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_IsInf.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_IsInf.py @@ -35,7 +35,6 @@ class TestIsInf(CommonTFLayerTest): ] @pytest.mark.parametrize("params", test_data_basic) - @pytest.mark.xfail(reason="94753") @pytest.mark.precommit_tf_fe def test_is_inf_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api): diff --git a/tests/layer_tests/tensorflow_tests/test_tf_IsNan.py b/tests/layer_tests/tensorflow_tests/test_tf_IsNan.py index b172ec2bfeb..86e20e17121 100644 --- a/tests/layer_tests/tensorflow_tests/test_tf_IsNan.py +++ b/tests/layer_tests/tensorflow_tests/test_tf_IsNan.py @@ -37,7 +37,6 @@ class TestIsNan(CommonTFLayerTest): ] @pytest.mark.parametrize("params", test_data_basic) - @pytest.mark.xfail(reason="94721") @pytest.mark.precommit_tf_fe def test_is_nan_basic(self, params, ie_device, precision, ir_version, temp_dir, use_new_frontend, use_old_api):