diff --git a/src/bindings/python/tests/test_graph/test_create_op.py b/src/bindings/python/tests/test_graph/test_create_op.py index 6cd4311f57d..20db104019c 100644 --- a/src/bindings/python/tests/test_graph/test_create_op.py +++ b/src/bindings/python/tests/test_graph/test_create_op.py @@ -2201,7 +2201,7 @@ def test_interpolate_opset10(dtype, expected_shape, shape_calculation_mode): assert list(node.get_output_shape(0)) == expected_shape -def test_in_finite_opset10(): +def test_is_finite_opset10(): input_shape = [1, 2, 3, 4] input_node = ov.parameter(input_shape, np.float, name="InputData") node = ov_opset10.is_finite(input_node) @@ -2261,7 +2261,7 @@ def test_is_inf_opset10_custom_all_attributes(): assert node_attributes["detect_negative"] is False -def test_in_nan_opset10(): +def test_is_nan_opset10(): input_shape = [1, 2, 3, 4] input_node = ov.parameter(input_shape, np.float, name="InputData") node = ov_opset10.is_nan(input_node) diff --git a/src/bindings/python/tests_compatibility/test_ngraph/test_create_op.py b/src/bindings/python/tests_compatibility/test_ngraph/test_create_op.py index 180fae7c489..df6e5afdb56 100644 --- a/src/bindings/python/tests_compatibility/test_ngraph/test_create_op.py +++ b/src/bindings/python/tests_compatibility/test_ngraph/test_create_op.py @@ -2266,7 +2266,7 @@ def test_interpolate_opset10(dtype, expected_shape, shape_calculation_mode): assert list(node.get_output_shape(0)) == expected_shape -def test_in_finite_opset10(): +def test_is_finite_opset10(): input_shape = [1, 2, 3, 4] input_node = ng.parameter(input_shape, np.float, name="InputData") node = ng_opset10.is_finite(input_node) @@ -2325,7 +2325,7 @@ def test_is_inf_opset10_custom_all_attributes(): assert node_attributes["detect_negative"] is False -def test_in_nan_opset10(): +def test_is_nan_opset10(): input_shape = [1, 2, 3, 4] input_node = ng.parameter(input_shape, np.float, name="InputData") node = ng_opset10.is_nan(input_node) diff --git a/src/core/include/openvino/op/is_inf.hpp b/src/core/include/openvino/op/is_inf.hpp index da612292fb3..f7906daf9e7 100644 --- a/src/core/include/openvino/op/is_inf.hpp +++ b/src/core/include/openvino/op/is_inf.hpp @@ -14,7 +14,6 @@ namespace v10 { class OPENVINO_API IsInf : public Op { public: OPENVINO_OP("IsInf", "opset10"); - /// \brief A Structure which contains all IsInf attributes struct Attributes { // A flag which specifies whether to map negative infinities to true. diff --git a/src/core/reference/include/ngraph/runtime/reference/is_finite.hpp b/src/core/reference/include/ngraph/runtime/reference/is_finite.hpp new file mode 100644 index 00000000000..ed5d17ffa50 --- /dev/null +++ b/src/core/reference/include/ngraph/runtime/reference/is_finite.hpp @@ -0,0 +1,32 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +namespace ngraph { +namespace runtime { +namespace reference { +template +typename std::enable_if::value, void>::type is_finite(const T* input, + U* output, + size_t count) { + std::transform(input, input + count, output, [](T x) -> U { + return std::isfinite(x); + }); +} + +// used for float16 and bfloat 16 datatypes +template +typename std::enable_if::value, void>::type is_finite(const T* input, U* output, size_t count) { + std::transform(input, input + count, output, [](T x) -> U { + return std::isfinite(static_cast(x)); + }); +} + +} // namespace reference +} // namespace runtime +} // namespace ngraph diff --git a/src/core/reference/include/ngraph/runtime/reference/is_inf.hpp b/src/core/reference/include/ngraph/runtime/reference/is_inf.hpp new file mode 100644 index 00000000000..08e4deb4dfa --- /dev/null +++ b/src/core/reference/include/ngraph/runtime/reference/is_inf.hpp @@ -0,0 +1,58 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +namespace ngraph { +namespace runtime { +namespace reference { +template +typename std::enable_if::value, void>::type +is_inf(const T* input, U* output, size_t count, const ov::op::v10::IsInf::Attributes& attributes) { + if (attributes.detect_negative && attributes.detect_positive) { + std::transform(input, input + count, output, [](T x) -> U { + return std::isinf(x); + }); + } else if (!attributes.detect_negative && attributes.detect_positive) { + std::transform(input, input + count, output, [](T x) -> U { + return (x == std::numeric_limits::infinity()); + }); + } else if (attributes.detect_negative && !attributes.detect_positive) { + std::transform(input, input + count, output, [](T x) -> U { + return (x == -std::numeric_limits::infinity()); + }); + } else { + std::memset(output, 0, count); + } +} + +// used for float16 and bfloat 16 datatypes +template +typename std::enable_if::value, void>::type is_inf(const T* input, + U* output, + size_t count, + const ov::op::v10::IsInf::Attributes& attributes) { + if (attributes.detect_negative && attributes.detect_positive) { + std::transform(input, input + count, output, [](T x) -> U { + return std::isinf(static_cast(x)); + }); + } else if (!attributes.detect_negative && attributes.detect_positive) { + std::transform(input, input + count, output, [](T x) -> U { + return (static_cast(x) == std::numeric_limits::infinity()); + }); + } else if (attributes.detect_negative && !attributes.detect_positive) { + std::transform(input, input + count, output, [](T x) -> U { + return (static_cast(x) == -std::numeric_limits::infinity()); + }); + } else { + std::memset(output, 0, count); + } +} + +} // namespace reference +} // namespace runtime +} // namespace ngraph diff --git a/src/core/reference/include/ngraph/runtime/reference/is_nan.hpp b/src/core/reference/include/ngraph/runtime/reference/is_nan.hpp new file mode 100644 index 00000000000..5b0945db723 --- /dev/null +++ b/src/core/reference/include/ngraph/runtime/reference/is_nan.hpp @@ -0,0 +1,29 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#pragma once + +#include +#include + +namespace ngraph { +namespace runtime { +namespace reference { +template +typename std::enable_if::value, void>::type is_nan(const T* input, U* output, size_t count) { + std::transform(input, input + count, output, [](T x) { + return std::isnan(static_cast(x)); + }); +} + +// used for float16 and bfloat 16 datatypes +template +typename std::enable_if::value, void>::type is_nan(const T* input, U* output, size_t count) { + std::transform(input, input + count, output, [](T x) -> U { + return std::isnan(static_cast(x)); + }); +} +} // namespace reference +} // namespace runtime +} // namespace ngraph diff --git a/src/core/src/op/is_finite.cpp b/src/core/src/op/is_finite.cpp index eb7c1948724..860ed4d74f0 100644 --- a/src/core/src/op/is_finite.cpp +++ b/src/core/src/op/is_finite.cpp @@ -5,7 +5,6 @@ #include "openvino/op/is_finite.hpp" #include "itt.hpp" -#include "ngraph/runtime/host_tensor.hpp" ov::op::v10::IsFinite::IsFinite(const Output& data) : op::Op{{data}} { constructor_validate_and_infer_types(); diff --git a/src/frontends/onnx/tests/onnx_import.in.cpp b/src/frontends/onnx/tests/onnx_import.in.cpp index 95d7aa2aae0..752281efc88 100644 --- a/src/frontends/onnx/tests/onnx_import.in.cpp +++ b/src/frontends/onnx/tests/onnx_import.in.cpp @@ -5971,7 +5971,8 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_trilu_dynamic_shapes) { } NGRAPH_TEST(${BACKEND_NAME}, onnx_is_finite) { - const auto function = onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/is_finite.onnx")); + const auto function = onnx_import::import_onnx_model( + file_util::path_join(CommonTestUtils::getExecutableDirectory(), SERIALIZED_ZOO, "onnx/is_finite.onnx")); auto test_case = test::TestCase(function, s_device); @@ -5996,8 +5997,6 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_is_inf_default) { // clang-format off - test_case.add_input(Shape{1, 2, 3}, {std::nanf(""), std::numeric_limits::infinity(), -0.6000f, -1.0000f, std::nanf(""), -1.0000f}); - test_case.add_input( Shape{2, 2, 2}, std::vector{ std::numeric_limits::infinity(), 0.0000f, @@ -6091,7 +6090,8 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_is_inf_detect_none) { } NGRAPH_TEST(${BACKEND_NAME}, onnx_is_nan) { - const auto function = onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/is_nan.onnx")); + const auto function = onnx_import::import_onnx_model( + file_util::path_join(CommonTestUtils::getExecutableDirectory(), SERIALIZED_ZOO, "onnx/is_nan.onnx")); auto test_case = test::TestCase(function, s_device); @@ -6099,7 +6099,7 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_is_nan) { test_case.add_input(Shape{1, 2, 3}, {std::nanf(""), std::nanf(""), -0.6000f, -1.0000f, std::nanf(""), -1.0000f}); - test_case.add_expected_output( + test_case.add_expected_output( Shape{1, 2, 3}, {true, true, false, false, true, false}); diff --git a/src/frontends/onnx/tests/runtime/ie/unit_test.manifest b/src/frontends/onnx/tests/runtime/ie/unit_test.manifest index e8ec820244d..583de22930b 100644 --- a/src/frontends/onnx/tests/runtime/ie/unit_test.manifest +++ b/src/frontends/onnx/tests/runtime/ie/unit_test.manifest @@ -426,11 +426,9 @@ IE_CPU.onnx_softmax_crossentropy_loss_mean # Cannot find blob with name: Y IE_CPU.onnx_bool_init_and -onnx_is_finite - -onnx_is_inf_default -onnx_is_inf_positive_only -onnx_is_inf_negative_only -onnx_is_inf_detect_none - -onnx_is_nan +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/frontends/onnx/tests/runtime/interpreter/unit_test.manifest b/src/frontends/onnx/tests/runtime/interpreter/unit_test.manifest index 56650202ffb..53819b14a8d 100644 --- a/src/frontends/onnx/tests/runtime/interpreter/unit_test.manifest +++ b/src/frontends/onnx/tests/runtime/interpreter/unit_test.manifest @@ -82,12 +82,3 @@ onnx_clip_no_min_no_max_int64 # z node not found in graph cache - ticket: 81976 INTERPRETER.onnx_expand_context_dependent_function INTERPRETER.onnx_softmax_crossentropy_loss_mean - -onnx_is_finite - -onnx_is_inf_default -onnx_is_inf_positive_only -onnx_is_inf_negative_only -onnx_is_inf_detect_none - -onnx_is_nan diff --git a/src/plugins/template/backend/evaluates_map.cpp b/src/plugins/template/backend/evaluates_map.cpp index 0e7a2421065..4235b58eeda 100644 --- a/src/plugins/template/backend/evaluates_map.cpp +++ b/src/plugins/template/backend/evaluates_map.cpp @@ -52,6 +52,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -4197,6 +4200,102 @@ bool evaluate(const shared_ptr& op, const HostTensorVector& ou return true; } +template +bool evaluate(const shared_ptr& op, + const HostTensorVector& outputs, + const HostTensorVector& inputs) { + element::Type input_et = op->get_input_element_type(0); + switch (input_et) { + case element::Type_t::f64: + ngraph::runtime::reference::is_finite(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape())); + break; + case element::Type_t::f32: + ngraph::runtime::reference::is_finite(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape())); + break; + case element::Type_t::f16: + ngraph::runtime::reference::is_finite(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape())); + break; + case element::Type_t::bf16: + ngraph::runtime::reference::is_finite(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape())); + break; + default: + return false; + } + return true; +} + +template +bool evaluate(const shared_ptr& op, const HostTensorVector& outputs, const HostTensorVector& inputs) { + element::Type input_et = op->get_input_element_type(0); + switch (input_et) { + case element::Type_t::f64: + ngraph::runtime::reference::is_inf(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape()), + op->get_attributes()); + break; + case element::Type_t::f32: + ngraph::runtime::reference::is_inf(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape()), + op->get_attributes()); + break; + case element::Type_t::f16: + ngraph::runtime::reference::is_inf(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape()), + op->get_attributes()); + break; + case element::Type_t::bf16: + ngraph::runtime::reference::is_inf(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape()), + op->get_attributes()); + break; + default: + return false; + } + return true; +} + +template +bool evaluate(const shared_ptr& op, const HostTensorVector& outputs, const HostTensorVector& inputs) { + element::Type input_et = op->get_input_element_type(0); + switch (input_et) { + case element::Type_t::f64: + ngraph::runtime::reference::is_nan(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape())); + break; + case element::Type_t::f32: + ngraph::runtime::reference::is_nan(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape())); + break; + case element::Type_t::f16: + ngraph::runtime::reference::is_nan(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape())); + break; + case element::Type_t::bf16: + ngraph::runtime::reference::is_nan(inputs[0]->get_data_ptr(), + outputs[0]->get_data_ptr(), + shape_size(inputs[0]->get_shape())); + break; + default: + return false; + } + return true; +} + template bool evaluate(const shared_ptr& op, const HostTensorVector& outputs, diff --git a/src/plugins/template/backend/opset_int_tbl.hpp b/src/plugins/template/backend/opset_int_tbl.hpp index c9b6830b924..5cfba92f21f 100644 --- a/src/plugins/template/backend/opset_int_tbl.hpp +++ b/src/plugins/template/backend/opset_int_tbl.hpp @@ -141,5 +141,9 @@ _OPENVINO_OP_REG(ROIAlign, op::v9) _OPENVINO_OP_REG(SoftSign, op::v9) _OPENVINO_OP_REG(MulticlassNms, op::v9) +_OPENVINO_OP_REG(IsFinite, op::v10) +_OPENVINO_OP_REG(IsInf, op::v10) +_OPENVINO_OP_REG(IsNaN, op::v10) + _OPENVINO_OP_REG(AUGRUCell, ov::op::internal) _OPENVINO_OP_REG(AUGRUSequence, ov::op::internal) diff --git a/src/plugins/template/tests/functional/op_reference/is_finite.cpp b/src/plugins/template/tests/functional/op_reference/is_finite.cpp new file mode 100644 index 00000000000..5a6a52ed9ff --- /dev/null +++ b/src/plugins/template/tests/functional/op_reference/is_finite.cpp @@ -0,0 +1,108 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/is_finite.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct IsFiniteParams { + template + IsFiniteParams(const PartialShape& shape, + const element::Type& iType, + const element::Type& oType, + const std::vector& iValues, + const std::vector& oValues) + : pshape(shape), + inType(iType), + outType(oType), + inputData(CreateTensor(iType, iValues)), + refData(CreateTensor(oType, oValues)) {} + + PartialShape pshape; + element::Type inType; + element::Type outType; + ov::Tensor inputData; + ov::Tensor refData; +}; + +class ReferenceIsFiniteLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape, params.inType, params.outType); + inputData = {params.inputData}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "shape=" << param.pshape << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in = std::make_shared(input_type, input_shape); + const auto is_finite = std::make_shared(in); + return std::make_shared(NodeVector{is_finite}, ParameterVector{in}); + } +}; + +TEST_P(ReferenceIsFiniteLayerTest, IsFiniteWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForIsFiniteFloat() { + using T = typename element_type_traits::value_type; + using U = typename element_type_traits::value_type; + + std::vector params{ + IsFiniteParams(ov::PartialShape{8}, + IN_ET, element::Type_t::boolean, + std::vector{std::numeric_limits::infinity(), 0.0000f, + std::numeric_limits::max(), -0.5000f, + -std::numeric_limits::infinity(), 1.0000f, + std::numeric_limits::min(), std::nanf("")}, + std::vector{false, true, + true, true, + false, true, + true, false}) + }; + return params; +} + +std::vector generateCombinedParamsForIsFinite() { + const std::vector> allTypeParams{ + generateParamsForIsFiniteFloat(), + generateParamsForIsFiniteFloat(), + generateParamsForIsFiniteFloat(), + generateParamsForIsFiniteFloat(), + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_IsFinite_With_Hardcoded_Refs, + ReferenceIsFiniteLayerTest, + ::testing::ValuesIn(generateCombinedParamsForIsFinite()), + ReferenceIsFiniteLayerTest::getTestCaseName); +} // namespace diff --git a/src/plugins/template/tests/functional/op_reference/is_inf.cpp b/src/plugins/template/tests/functional/op_reference/is_inf.cpp new file mode 100644 index 00000000000..dd1fc563a30 --- /dev/null +++ b/src/plugins/template/tests/functional/op_reference/is_inf.cpp @@ -0,0 +1,202 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/is_inf.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct IsInfParams { + template + IsInfParams(const std::string testcaseName, + const PartialShape& shape, + const element::Type& iType, + const element::Type& oType, + const std::vector& iValues, + const std::vector& oValues, + op::v10::IsInf::Attributes& attrs) + : testcaseName(testcaseName), + pshape(shape), + inType(iType), + outType(oType), + inputData(CreateTensor(iType, iValues)), + refData(CreateTensor(oType, oValues)), + attrs(attrs) {} + + std::string testcaseName; + PartialShape pshape; + element::Type inType; + element::Type outType; + ov::Tensor inputData; + ov::Tensor refData; + op::v10::IsInf::Attributes attrs; +}; + +class ReferenceIsInfLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape, params.inType, params.outType, params.attrs); + inputData = {params.inputData}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "shape=" << param.pshape << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + if (!param.testcaseName.empty()) { + result << "_=" << param.testcaseName; + } + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape, + const element::Type& input_type, + const element::Type& expected_output_type, + op::v10::IsInf::Attributes attrs) { + const auto in = std::make_shared(input_type, input_shape); + const auto is_inf = std::make_shared(in, attrs); + return std::make_shared(NodeVector{is_inf}, ParameterVector{in}); + } +}; + +TEST_P(ReferenceIsInfLayerTest, IsInfWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForIsInfDefault() { + using T = typename element_type_traits::value_type; + using U = typename element_type_traits::value_type; + op::v10::IsInf::Attributes attrs{}; + std::vector params{ + IsInfParams("IsInfDefault", ov::PartialShape{8}, + IN_ET, element::Type_t::boolean, + std::vector{std::numeric_limits::infinity(), 0.0000f, + std::numeric_limits::max(), -0.5000f, + -std::numeric_limits::infinity(), 1.0000f, + std::numeric_limits::min(), std::nanf("")}, + std::vector{true, false, + false, false, + true, false, + false, false}, + attrs + ) + }; + return params; +} + +template +std::vector generateParamsForIsInfPositive() { + using T = typename element_type_traits::value_type; + using U = typename element_type_traits::value_type; + op::v10::IsInf::Attributes attrs{}; + attrs.detect_negative = false; + std::vector params{ + IsInfParams("IsInfPositiveOnly", ov::PartialShape{8}, + IN_ET, element::Type_t::boolean, + std::vector{std::numeric_limits::infinity(), 0.0000f, + std::numeric_limits::max(), -0.5000f, + -std::numeric_limits::infinity(), 1.0000f, + std::numeric_limits::min(), std::nanf("")}, + std::vector{true, false, + false, false, + false, false, + false, false}, + attrs + ) + }; + return params; +} + +template +std::vector generateParamsForIsInfNegative() { + using T = typename element_type_traits::value_type; + using U = typename element_type_traits::value_type; + op::v10::IsInf::Attributes attrs{}; + attrs.detect_positive = false; + std::vector params{ + IsInfParams("IsInfNegativeOnly", ov::PartialShape{8}, + IN_ET, element::Type_t::boolean, + std::vector{std::numeric_limits::infinity(), 0.0000f, + std::numeric_limits::max(), -0.5000f, + -std::numeric_limits::infinity(), 1.0000f, + std::numeric_limits::min(), std::nanf("")}, + std::vector{false, false, + false, false, + true, false, + false, false}, + attrs + ) + }; + return params; +} + +template +std::vector generateParamsForIsInfNone() { + using T = typename element_type_traits::value_type; + using U = typename element_type_traits::value_type; + op::v10::IsInf::Attributes attrs{}; + attrs.detect_negative = false; + attrs.detect_positive = false; + std::vector params{ + IsInfParams("IsInfDetectNone", ov::PartialShape{8}, + IN_ET, element::Type_t::boolean, + std::vector{std::numeric_limits::infinity(), 0.0000f, + std::numeric_limits::max(), -0.5000f, + -std::numeric_limits::infinity(), 1.0000f, + std::numeric_limits::min(), std::nanf("")}, + std::vector{false, false, + false, false, + false, false, + false, false}, + attrs + ) + }; + return params; +} + +std::vector generateCombinedParamsForIsInf() { + const std::vector> allTypeParams{ + generateParamsForIsInfDefault(), + generateParamsForIsInfDefault(), + generateParamsForIsInfDefault(), + generateParamsForIsInfDefault(), + generateParamsForIsInfPositive(), + generateParamsForIsInfPositive(), + generateParamsForIsInfPositive(), + generateParamsForIsInfPositive(), + generateParamsForIsInfNegative(), + generateParamsForIsInfNegative(), + generateParamsForIsInfNegative(), + generateParamsForIsInfNegative(), + generateParamsForIsInfNone(), + generateParamsForIsInfNone(), + generateParamsForIsInfNone(), + generateParamsForIsInfNone(), + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_IsInf_With_Hardcoded_Refs, + ReferenceIsInfLayerTest, + ::testing::ValuesIn(generateCombinedParamsForIsInf()), + ReferenceIsInfLayerTest::getTestCaseName); +} // namespace diff --git a/src/plugins/template/tests/functional/op_reference/is_nan.cpp b/src/plugins/template/tests/functional/op_reference/is_nan.cpp new file mode 100644 index 00000000000..a3b71f01fd8 --- /dev/null +++ b/src/plugins/template/tests/functional/op_reference/is_nan.cpp @@ -0,0 +1,108 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include "base_reference_test.hpp" +#include "openvino/op/is_nan.hpp" + +using namespace ov; +using namespace reference_tests; + +namespace { + +struct IsNaNParams { + template + IsNaNParams(const PartialShape& shape, + const element::Type& iType, + const element::Type& oType, + const std::vector& iValues, + const std::vector& oValues) + : pshape(shape), + inType(iType), + outType(oType), + inputData(CreateTensor(iType, iValues)), + refData(CreateTensor(oType, oValues)) {} + + PartialShape pshape; + element::Type inType; + element::Type outType; + ov::Tensor inputData; + ov::Tensor refData; +}; + +class ReferenceIsNaNLayerTest : public testing::TestWithParam, public CommonReferenceTest { +public: + void SetUp() override { + auto params = GetParam(); + function = CreateFunction(params.pshape, params.inType, params.outType); + inputData = {params.inputData}; + refOutData = {params.refData}; + } + + static std::string getTestCaseName(const testing::TestParamInfo& obj) { + auto param = obj.param; + std::ostringstream result; + result << "shape=" << param.pshape << "_"; + result << "iType=" << param.inType << "_"; + result << "oType=" << param.outType; + return result.str(); + } + +private: + static std::shared_ptr CreateFunction(const PartialShape& input_shape, + const element::Type& input_type, + const element::Type& expected_output_type) { + const auto in = std::make_shared(input_type, input_shape); + const auto is_nan = std::make_shared(in); + return std::make_shared(NodeVector{is_nan}, ParameterVector{in}); + } +}; + +TEST_P(ReferenceIsNaNLayerTest, IsNaNWithHardcodedRefs) { + Exec(); +} + +template +std::vector generateParamsForIsNaNFloat() { + using T = typename element_type_traits::value_type; + using U = typename element_type_traits::value_type; + + std::vector params{ + IsNaNParams(ov::PartialShape{8}, + IN_ET, element::Type_t::boolean, + std::vector{std::numeric_limits::infinity(), 0.0000f, + std::numeric_limits::max(), -0.5000f, + -std::numeric_limits::infinity(), 1.0000f, + std::numeric_limits::min(), std::nanf("")}, + std::vector{false, false, + false, false, + false, false, + false, true}) + }; + return params; +} + +std::vector generateCombinedParamsForIsNaN() { + const std::vector> allTypeParams{ + generateParamsForIsNaNFloat(), + generateParamsForIsNaNFloat(), + generateParamsForIsNaNFloat(), + generateParamsForIsNaNFloat(), + }; + + std::vector combinedParams; + + for (const auto& params : allTypeParams) { + combinedParams.insert(combinedParams.end(), params.begin(), params.end()); + } + + return combinedParams; +} + +INSTANTIATE_TEST_SUITE_P( + smoke_IsNaN_With_Hardcoded_Refs, + ReferenceIsNaNLayerTest, + ::testing::ValuesIn(generateCombinedParamsForIsNaN()), + ReferenceIsNaNLayerTest::getTestCaseName); +} // namespace