Skip to content

Commit

Permalink
Add func test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnyoung-paul committed Jan 30, 2025
1 parent 5b559ea commit 27dc531
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

#include <vector>

#include "single_op_tests/conversion.hpp"
#include "gtest/gtest.h"
#include "common_test_utils/test_constants.hpp"
#include "common_test_utils/data_utils.hpp"
#include "common_test_utils/ov_tensor_utils.hpp"
#include "conversion.hpp"

namespace {
using ov::test::ConversionLayerTest;
using ov::test::ConvertToBooleanLayerTest;

const std::vector<ov::test::utils::ConversionTypes> conversionOpTypes = {
ov::test::utils::ConversionTypes::CONVERT,
ov::test::utils::ConversionTypes::CONVERT_LIKE,
Expand All @@ -31,5 +36,85 @@ INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, ConversionLayerTest,
::testing::ValuesIn(netPrecisions),
::testing::Values(ov::test::utils::DEVICE_GPU)),
ConversionLayerTest::getTestCaseName);
}

namespace ov {
namespace test {

void ConvertToBooleanLayerTest::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {
inputs.clear();
const auto& funcInputs = function->inputs();

auto shape = targetInputStaticShapes.front();
auto size = shape_size(shape);
auto input_type = funcInputs[0].get_element_type();

ov::Tensor tensor = ov::Tensor(input_type, shape);
const auto first_part_size = size / 2;
const auto second_part_size = size - first_part_size;

// 1). Validate the nearest to zero values (Abs + Ceil)
{
double start_from = -2;
uint32_t range = 4;
int32_t resolution = size;
if (input_type == ov::element::f32) {
auto* rawBlobDataPtr = static_cast<float*>(tensor.data());
ov::test::utils::fill_data_random(rawBlobDataPtr, first_part_size, range, start_from, resolution);
} else if (input_type == ov::element::f16) {
auto* rawBlobDataPtr = static_cast<ov::float16*>(tensor.data());
ov::test::utils::fill_data_random(rawBlobDataPtr, first_part_size, range, start_from, resolution);
} else {
FAIL() << "Generating inputs with precision " << input_type.to_string() << " isn't supported, if output precision is boolean.";
}
}

// 2). Validate the values that are more than UINT8_MAX in absolute (Abs + Min)
{
ov::test::utils::InputGenerateData in_data_neg;
double neg_start_from = -1.5 * std::numeric_limits<uint8_t>::max();
double pos_start_from = 0.5 * std::numeric_limits<uint8_t>::max();
uint32_t range = 256;
auto neg_size = second_part_size / 2;
auto pos_size = second_part_size - neg_size;
int32_t resolution = 1;

if (input_type == ov::element::f32) {
auto* rawBlobDataPtr = static_cast<float*>(tensor.data());
ov::test::utils::fill_data_random(rawBlobDataPtr + first_part_size, neg_size, range, neg_start_from, resolution);
ov::test::utils::fill_data_random(rawBlobDataPtr + first_part_size + neg_size, pos_size, range, pos_start_from, resolution);
} else if (input_type == ov::element::f16) {
auto* rawBlobDataPtr = static_cast<ov::float16*>(tensor.data());
ov::test::utils::fill_data_random(rawBlobDataPtr + first_part_size, neg_size, range, neg_start_from, resolution);
ov::test::utils::fill_data_random(rawBlobDataPtr + first_part_size + neg_size, pos_size, range, pos_start_from, resolution);
} else {
FAIL() << "Generating inputs with precision " << input_type.to_string() << " isn't supported, if output precision is boolean.";
}
}

inputs.insert({funcInputs[0].get_node_shared_ptr(), tensor});
}

} // namespace test
} // namespace ov

namespace {
TEST_P(ConvertToBooleanLayerTest, CompareWithRefs) {
run();
};

const std::vector<ov::element::Type> precisions_floating_point = {
ov::element::f32,
ov::element::f16
};

INSTANTIATE_TEST_SUITE_P(smoke_NoReshape, ConvertToBooleanLayerTest,
::testing::Combine(
::testing::ValuesIn({ov::test::utils::ConversionTypes::CONVERT}),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(inShape)),
::testing::ValuesIn(precisions_floating_point),
::testing::Values(ov::element::boolean),
::testing::Values(ov::test::utils::DEVICE_GPU)),
ConvertToBooleanLayerTest::getTestCaseName);

} // namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "shared_test_classes/base/ov_subgraph.hpp"
#include "common_test_utils/ov_tensor_utils.hpp"
#include "gtest/gtest.h"
#include "single_op_tests/conversion.hpp"


namespace ov {
namespace test {

class ConvertToBooleanLayerTest : public ConversionLayerTest {
protected:
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;
};

} // namespace test
} // namespace ov

0 comments on commit 27dc531

Please sign in to comment.