Skip to content

Commit

Permalink
use std::numeric_limits function to replace macro NAN in test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
liubo-intel committed Jan 15, 2024
1 parent abf7b56 commit 873e605
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
9 changes: 6 additions & 3 deletions src/core/tests/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1028,19 +1028,22 @@ TEST(eval, evaluate_sign) {
ASSERT_EQ(result_val, expec);
}

TEST(eval, evaluate_sign_2) {
TEST(eval, evaluate_sign_nan) {
auto p = make_shared<ov::op::v0::Parameter>(element::f16, Shape{2, 3});
auto sign = make_shared<op::v0::Sign>(p);
auto model = make_shared<Model>(OutputVector{sign}, ParameterVector{p});
auto result = ov::Tensor();
auto out_vector = ov::TensorVector{result};
auto in_vector = ov::TensorVector{make_tensor<element::Type_t::f16>(Shape{2, 3}, {NAN, -2, 0, -4.8f, 4.8f, -0.0f})};
auto in_vector = ov::TensorVector{
make_tensor<element::Type_t::f16>(Shape{2, 3},
{std::numeric_limits<float>::quiet_NaN(), -2, 0, -4.8f, 4.8f, -0.0f})};
ASSERT_TRUE(model->evaluate(out_vector, in_vector));
result = out_vector.at(0);

EXPECT_EQ(result.get_element_type(), element::f16);
EXPECT_THAT(read_vector<float16>(result),
Pointwise(NanSensitiveFloatEq(), std::vector<float16>{NAN, -1, 0, -1, 1, 0}));
Pointwise(NanSensitiveFloatEq(),
std::vector<float16>{std::numeric_limits<float>::quiet_NaN(), -1, 0, -1, 1, 0}));
}

TEST(eval, evaluate_sin) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void ActivationLayerCPUTest::generate_inputs(const std::vector<ov::Shape>& targe
// cover Sign NAN test case
if ((activationType == utils::ActivationTypes::Sign) && targetInputStaticShapes[i].size() == 8 &&
funcInput.get_element_type() == ov::element::f32) {
static_cast<float*>(tensor.data())[0] = NAN;
static_cast<float*>(tensor.data())[0] = std::numeric_limits<float>::quiet_NaN();
}
} else {
tensor = ov::test::utils::create_and_fill_tensor(funcInput.get_element_type(), targetInputStaticShapes[i]);
Expand Down
78 changes: 40 additions & 38 deletions src/plugins/template/tests/functional/op_reference/sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,41 +59,43 @@ TEST_P(ReferenceSignLayerTest, CompareWithHardcodedRefs) {
Exec();
}

INSTANTIATE_TEST_SUITE_P(smoke_Sign_With_Hardcoded_Refs,
ReferenceSignLayerTest,
::testing::Values(SignParams(PartialShape{6},
element::f32,
element::f32,
std::vector<float>{1, -2, 0, -4.8f, 4.8f, -0.0f},
std::vector<float>{1, -1, 0, -1, 1, 0}),
SignParams(PartialShape{7},
element::f32,
element::f32,
std::vector<float>{1, -2, 0, NAN, -4.8f, 4.8f, -0.0f},
std::vector<float>{1, -1, 0, NAN, -1, 1, 0}),
SignParams(PartialShape{6},
element::f16,
element::f16,
std::vector<float16>{1, -2, 0, -4.8f, 4.8f, -0.0f},
std::vector<float16>{1, -1, 0, -1, 1, 0}),
SignParams(PartialShape{6},
element::u64,
element::u64,
std::vector<uint64_t>{1, 2, 0, 4, 4, 0},
std::vector<uint64_t>{1, 1, 0, 1, 1, 0}),
SignParams(PartialShape{6},
element::u32,
element::u32,
std::vector<uint32_t>{1, 2, 0, 4, 4, 0},
std::vector<uint32_t>{1, 1, 0, 1, 1, 0}),
SignParams(PartialShape{6},
element::i32,
element::i32,
std::vector<int32_t>{1, -2, 0, -4, 4, -0},
std::vector<int32_t>{1, -1, 0, -1, 1, 0}),
SignParams(PartialShape{6},
element::i64,
element::i64,
std::vector<int64_t>{1, -2, 0, -4, 4, -0},
std::vector<int64_t>{1, -1, 0, -1, 1, 0})),
ReferenceSignLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(
smoke_Sign_With_Hardcoded_Refs,
ReferenceSignLayerTest,
::testing::Values(
SignParams(PartialShape{6},
element::f32,
element::f32,
std::vector<float>{1, -2, 0, -4.8f, 4.8f, -0.0f},
std::vector<float>{1, -1, 0, -1, 1, 0}),
SignParams(PartialShape{7},
element::f32,
element::f32,
std::vector<float>{1, -2, 0, std::numeric_limits<float>::quiet_NaN(), -4.8f, 4.8f, -0.0f},
std::vector<float>{1, -1, 0, std::numeric_limits<float>::quiet_NaN(), -1, 1, 0}),
SignParams(PartialShape{6},
element::f16,
element::f16,
std::vector<float16>{1, -2, 0, -4.8f, 4.8f, -0.0f},
std::vector<float16>{1, -1, 0, -1, 1, 0}),
SignParams(PartialShape{6},
element::u64,
element::u64,
std::vector<uint64_t>{1, 2, 0, 4, 4, 0},
std::vector<uint64_t>{1, 1, 0, 1, 1, 0}),
SignParams(PartialShape{6},
element::u32,
element::u32,
std::vector<uint32_t>{1, 2, 0, 4, 4, 0},
std::vector<uint32_t>{1, 1, 0, 1, 1, 0}),
SignParams(PartialShape{6},
element::i32,
element::i32,
std::vector<int32_t>{1, -2, 0, -4, 4, -0},
std::vector<int32_t>{1, -1, 0, -1, 1, 0}),
SignParams(PartialShape{6},
element::i64,
element::i64,
std::vector<int64_t>{1, -2, 0, -4, 4, -0},
std::vector<int64_t>{1, -1, 0, -1, 1, 0})),
ReferenceSignLayerTest::getTestCaseName);

0 comments on commit 873e605

Please sign in to comment.