Skip to content

Commit

Permalink
Refactor ComparisonLayerTest, ClampLayerTest (openvinotoolkit#19681)
Browse files Browse the repository at this point in the history
* Refactor ClampLayerTest

* Refactor ComparisonLayerTest
  • Loading branch information
olpipi authored and yangwang201911 committed Sep 13, 2023
1 parent 5e93fbf commit 67f64f7
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@

#include <vector>

#include "single_layer_tests/clamp.hpp"
#include "single_op_tests/clamp.hpp"
#include "common_test_utils/test_constants.hpp"

using namespace LayerTestsDefinitions;
namespace {
using ov::test::ClampLayerTest;

const std::vector<std::vector<size_t>> inShapes = {
{50},
{10, 10},
{1, 20, 20}
const std::vector<std::vector<ov::Shape>> input_shapes_static = {
{{ 50 }},
{{ 10, 10 }},
{{ 1, 20, 20 }}
};


const std::vector<std::pair<float, float>> intervals = {
{-20.1, -10.5},
{-10.0, 10.0},
Expand All @@ -27,26 +29,27 @@ const std::vector<std::pair<float, float>> intervals_unsigned = {
{10.6, 20.6}
};

const std::vector<InferenceEngine::Precision> netPrc = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I64,
InferenceEngine::Precision::I32
const std::vector<ov::element::Type> model_type = {
ov::element::f32,
ov::element::f16,
ov::element::i64,
ov::element::i32
};

const auto test_Clamp_signed = ::testing::Combine(
::testing::ValuesIn(inShapes),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)),
::testing::ValuesIn(intervals),
::testing::ValuesIn(netPrc),
::testing::ValuesIn(model_type),
::testing::Values(ov::test::utils::DEVICE_CPU)
);

const auto test_Clamp_unsigned = ::testing::Combine(
::testing::ValuesIn(inShapes),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)),
::testing::ValuesIn(intervals_unsigned),
::testing::Values(InferenceEngine::Precision::U64),
::testing::Values(ov::element::u64),
::testing::Values(ov::test::utils::DEVICE_CPU)
);

INSTANTIATE_TEST_SUITE_P(smoke_TestsClamp_signed, ClampLayerTest, test_Clamp_signed, ClampLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsClamp_unsigned, ClampLayerTest, test_Clamp_unsigned, ClampLayerTest::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
//

#include <vector>
#include "single_layer_tests/comparison.hpp"
#include "single_op_tests/comparison.hpp"
#include "common_test_utils/test_constants.hpp"

using namespace LayerTestsDefinitions;
using namespace LayerTestsDefinitions::ComparisonParams;

namespace {
using ov::test::ComparisonLayerTest;

std::map<std::vector<size_t>, std::vector<std::vector<size_t>>> inputShapes = {
std::map<ov::Shape, std::vector<ov::Shape>> input_shapes_combinations = {
{{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}}},
Expand All @@ -20,11 +18,23 @@ std::map<std::vector<size_t>, std::vector<std::vector<size_t>>> inputShapes = {
{{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,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::BOOL,
auto input_shapes_pair_vector = ov::test::utils::combineParams(input_shapes_combinations);

auto converter = [] (const std::vector<std::pair<ov::Shape, ov::Shape>>& shapes) {
std::vector<std::vector<ov::Shape>> result;
for (const auto& shape : shapes) {
result.push_back({shape.first, shape.second});
}
return result;
};

auto input_shapes_static = converter(input_shapes_pair_vector);

std::vector<ov::element::Type> model_type = {
ov::element::f32,
ov::element::f16,
ov::element::i32,
ov::element::boolean,
};

std::vector<ngraph::helpers::ComparisonTypes> comparisonOpTypes = {
Expand All @@ -44,19 +54,17 @@ std::vector<ngraph::helpers::InputLayerType> secondInputTypes = {
std::map<std::string, std::string> additional_config = {};

const auto ComparisonTestParams = ::testing::Combine(
::testing::ValuesIn(ov::test::utils::combineParams(inputShapes)),
::testing::ValuesIn(inputsPrecisions),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_static)),
::testing::ValuesIn(comparisonOpTypes),
::testing::ValuesIn(secondInputTypes),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::ValuesIn(model_type),
::testing::Values(ov::test::utils::DEVICE_CPU),
::testing::Values(additional_config));

INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs, ComparisonLayerTest, ComparisonTestParams, ComparisonLayerTest::getTestCaseName);


std::vector<InputShapesTuple> inputShapesIsOps = {
std::vector<std::vector<ov::Shape>> input_shapes_is_ops_static = {
{{1}, {1}},
{{1, 2}, {1}},
{{3, 1}, {1}},
Expand All @@ -79,12 +87,10 @@ std::vector<ngraph::helpers::ComparisonTypes> comparisonOpTypesIs = {
};

const auto ComparisonTestParamsIs = ::testing::Combine(
::testing::ValuesIn(inputShapesIsOps),
::testing::Values(InferenceEngine::Precision::FP32),
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(input_shapes_is_ops_static)),
::testing::ValuesIn(comparisonOpTypesIs),
::testing::Values(ngraph::helpers::InputLayerType::CONSTANT),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(InferenceEngine::Precision::UNSPECIFIED),
::testing::Values(ov::element::f32),
::testing::Values(ov::test::utils::DEVICE_CPU),
::testing::Values(additional_config));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "shared_test_classes/single_op/clamp.hpp"

namespace ov {
namespace test {
TEST_P(ClampLayerTest, Inference) {
run();
}
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <shared_test_classes/single_op/comparison.hpp>

namespace ov {
namespace test {
TEST_P(ComparisonLayerTest, Inference) {
run();
}
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include <tuple>
#include <string>

#include "shared_test_classes/base/ov_subgraph.hpp"

namespace ov {
namespace test {

using clampParamsTuple = std::tuple<
std::vector<InputShape>, // Input shape
std::pair<float, float>, // Interval [min, max]
ov::element::Type, // Model precision
std::string>; // Device name

class ClampLayerTest : public testing::WithParamInterface<clampParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<clampParamsTuple>& obj);
protected:
void SetUp() override;
};

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

#pragma once


#include <map>

#include "gtest/gtest.h"
#include "shared_test_classes/base/ov_subgraph.hpp"
#include "common_test_utils/test_constants.hpp"
#include "ngraph_functions/utils/ngraph_helpers.hpp"

namespace ov {
namespace test {

typedef std::tuple<
std::vector<InputShape>, // Input shapes tuple
ngraph::helpers::ComparisonTypes, // Comparison op type
ngraph::helpers::InputLayerType, // Second input type
ov::element::Type, // Model type
std::string, // Device name
std::map<std::string, std::string> // Additional network configuration
> ComparisonTestParams;

class ComparisonLayerTest : public testing::WithParamInterface<ComparisonTestParams>,
virtual public ov::test::SubgraphBaseTest {
ngraph::helpers::ComparisonTypes comparison_op_type;
protected:
void SetUp() override;
void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;
public:
static std::string getTestCaseName(const testing::TestParamInfo<ComparisonTestParams> &obj);
};
} // namespace test
} // namespace ov
50 changes: 50 additions & 0 deletions src/tests/functional/shared_test_classes/src/single_op/clamp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "shared_test_classes/single_op/clamp.hpp"

namespace ov {
namespace test {
std::string ClampLayerTest::getTestCaseName(const testing::TestParamInfo<clampParamsTuple>& obj) {
std::vector<InputShape> shapes;
std::pair<float, float> interval;
ov::element::Type model_type;
std::string target_device;

std::tie(shapes, interval, model_type, target_device) = obj.param;

std::ostringstream result;
result << "IS=(";
for (size_t i = 0lu; i < shapes.size(); i++) {
result << ov::test::utils::partialShape2str({shapes[i].first}) << (i < shapes.size() - 1lu ? "_" : "");
}
result << ")_TS=";
for (size_t i = 0lu; i < shapes.front().second.size(); i++) {
result << "{";
for (size_t j = 0lu; j < shapes.size(); j++) {
result << ov::test::utils::vec2str(shapes[j].second[i]) << (j < shapes.size() - 1lu ? "_" : "");
}
result << "}_";
}
result << "min=" << interval.first << "_";
result << "max=" << interval.second << "_";
result << "netPrc=" << model_type.get_type_name() << "_";
result << "trgDev=" << target_device;
return result.str();
}

void ClampLayerTest::SetUp() {
std::vector<InputShape> shapes;
std::pair<float, float> interval;
ov::element::Type model_type;
std::tie(shapes, interval, model_type, targetDevice) = this->GetParam();
init_input_shapes(shapes);

auto input = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.front());
auto clamp = std::make_shared<ov::op::v0::Clamp>(input, interval.first, interval.second);
auto result = std::make_shared<ov::op::v0::Result>(clamp);
function = std::make_shared<ov::Model>(result, ngraph::ParameterVector{input});
}
} // namespace test
} // namespace ov
Loading

0 comments on commit 67f64f7

Please sign in to comment.