Migrate normalization to template plugin test (#8240)

* Migrate normalization to template plugin test

* Migrate result, parameter to template plugin test
This commit is contained in:
David Nam
2021-10-30 23:58:33 +09:00
committed by GitHub
parent f4530516c7
commit cc457e003e
11 changed files with 1654 additions and 1309 deletions

View File

@@ -0,0 +1,261 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "base_reference_test.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/batch_norm.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct BatchNormParams {
template <class T>
BatchNormParams(const Shape& input_shape,
const Shape& expected_shape,
const element::Type& input_type,
const element::Type& expected_type,
const std::vector<T>& input_value,
const std::vector<T>& expected_value,
const std::vector<T>& gamma,
const std::vector<T>& beta,
const std::vector<T>& mean,
const std::vector<T>& variance,
const float epsilon)
: m_input_shape(input_shape),
m_expected_shape(expected_shape),
m_input_type(input_type),
m_expected_type(expected_type),
m_input_value(CreateTensor(input_type, input_value)),
m_expected_value(CreateTensor(expected_type, expected_value)),
m_gamma(CreateTensor(Shape{input_shape.at(1)}, input_type, gamma)),
m_beta(CreateTensor(Shape{input_shape.at(1)}, input_type, beta)),
m_mean(CreateTensor(Shape{input_shape.at(1)}, input_type, mean)),
m_variance(CreateTensor(Shape{input_shape.at(1)}, input_type, variance)),
m_epsilon(epsilon) {}
Shape m_input_shape;
Shape m_expected_shape;
element::Type m_input_type;
element::Type m_expected_type;
runtime::Tensor m_input_value;
runtime::Tensor m_expected_value;
runtime::Tensor m_gamma;
runtime::Tensor m_beta;
runtime::Tensor m_mean;
runtime::Tensor m_variance;
float m_epsilon;
};
class ReferenceBatchNormV0LayerTest : public testing::TestWithParam<BatchNormParams>, public CommonReferenceTest {
public:
void SetUp() override {
const auto params = GetParam();
function = CreateFunction(params.m_input_shape, params.m_input_type, params.m_epsilon);
inputData = {params.m_input_value, params.m_gamma, params.m_beta, params.m_mean, params.m_variance};
refOutData = {params.m_expected_value};
}
static std::string getTestCaseName(const testing::TestParamInfo<BatchNormParams>& obj) {
const auto param = obj.param;
std::ostringstream result;
result << "input_shape=" << param.m_input_shape << "; ";
result << "output_shape=" << param.m_expected_shape << "; ";
result << "input_type=" << param.m_input_type << "; ";
result << "output_type=" << param.m_expected_type << "; ";
result << "gamma=" << param.m_gamma.data() << "; ";
result << "beta=" << param.m_beta.data() << "; ";
result << "mean=" << param.m_mean.data() << "; ";
result << "variance=" << param.m_variance.data();
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& input_shape,
const element::Type_t& input_type,
const float epsilon) {
Shape channel_shape{input_shape.at(1)};
auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
auto gamma = std::make_shared<op::v0::Parameter>(input_type, channel_shape);
auto beta = std::make_shared<op::v0::Parameter>(input_type, channel_shape);
auto mean = std::make_shared<op::v0::Parameter>(input_type, channel_shape);
auto variance = std::make_shared<op::v0::Parameter>(input_type, channel_shape);
auto batch_norm = std::make_shared<op::v0::BatchNormInference>(in, gamma, beta, mean, variance, epsilon);
return std::make_shared<ov::Function>(batch_norm, ParameterVector{in, gamma, beta, mean, variance});
}
};
class ReferenceBatchNormV5LayerTest : public ReferenceBatchNormV0LayerTest {
public:
void SetUp() override {
const auto params = GetParam();
function = CreateFunction(params.m_input_shape, params.m_input_type, params.m_epsilon);
inputData = {params.m_input_value, params.m_gamma, params.m_beta, params.m_mean, params.m_variance};
refOutData = {params.m_expected_value};
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& input_shape,
const element::Type_t& input_type,
const float epsilon) {
Shape channel_shape{input_shape.at(1)};
auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
auto gamma = std::make_shared<op::v0::Parameter>(input_type, channel_shape);
auto beta = std::make_shared<op::v0::Parameter>(input_type, channel_shape);
auto mean = std::make_shared<op::v0::Parameter>(input_type, channel_shape);
auto variance = std::make_shared<op::v0::Parameter>(input_type, channel_shape);
auto batch_norm = std::make_shared<op::v5::BatchNormInference>(in, gamma, beta, mean, variance, epsilon);
return std::make_shared<ov::Function>(batch_norm, ParameterVector{in, gamma, beta, mean, variance});
}
};
TEST_P(ReferenceBatchNormV0LayerTest, CompareWithHardcodedRefs) {
Exec();
}
TEST_P(ReferenceBatchNormV5LayerTest, CompareWithHardcodedRefs) {
Exec();
}
template <element::Type_t ET>
std::vector<BatchNormParams> generateParamsForBatchNorm() {
using T = typename element_type_traits<ET>::value_type;
std::vector<BatchNormParams> params{
/*------------- 2d --------------*/
BatchNormParams(Shape{2, 3},
Shape{2, 3},
ET,
ET,
std::vector<T>{1, 2, 3, -1, -2, -3},
std::vector<T>{2, 6, 12, -2, -6, -12},
std::vector<T>{2.0, 3.0, 4.0},
std::vector<T>{0.0, 0.0, 0.0},
std::vector<T>{0.0, 0.0, 0.0},
std::vector<T>{0.75, 0.75, 0.75},
0.25),
BatchNormParams(Shape{2, 3},
Shape{2, 3},
ET,
ET,
std::vector<T>{1, 2, 3, -1, -2, -3},
std::vector<T>{3, 0, 6, 1, -4, 0},
std::vector<T>{1.0, 1.0, 1.0},
std::vector<T>{2.0, -2.0, 3.0},
std::vector<T>{0.0, 0.0, 0.0},
std::vector<T>{0.75, 0.75, 0.75},
0.25),
BatchNormParams(Shape{2, 3},
Shape{2, 3},
ET,
ET,
std::vector<T>{1, 2, 3, -1, -2, -3},
std::vector<T>{3, 0, 6, 1, -4, 0},
std::vector<T>{1.0, 1.0, 1.0},
std::vector<T>{0.0, 0.0, 0.0},
std::vector<T>{-2.0, 2.0, -3.0},
std::vector<T>{0.75, 0.75, 0.75},
0.25),
BatchNormParams(Shape{2, 3},
Shape{2, 3},
ET,
ET,
std::vector<T>{3, 5, 1, -3, -5, -1},
std::vector<T>{2, 2, 2, -2, -2, -2},
std::vector<T>{1.0, 1.0, 1.0},
std::vector<T>{0.0, 0.0, 0.0},
std::vector<T>{0.0, 0.0, 0.0},
std::vector<T>{2.0, 6.0, 0.0},
0.25),
/*------------- 4d --------------*/
BatchNormParams(Shape{2, 2, 2, 1},
Shape{2, 2, 2, 1},
ET,
ET,
std::vector<T>{0.54881352f,
0.71518934f,
0.60276335f,
0.54488319f,
0.42365479f,
0.64589411f,
0.4375872f,
0.89177299f},
std::vector<T>{0.54903894f,
0.71533161f,
0.60296183f,
0.54511058f,
0.42394274f,
0.64607101f,
0.43786817f,
0.89182704f},
std::vector<T>{1.0, 1.0},
std::vector<T>{1.0, 1.0},
std::vector<T>{1.0, 1.0},
std::vector<T>{1.0, 1.0},
0.001),
BatchNormParams(Shape{2, 2, 2, 1},
Shape{2, 2, 2, 1},
ET,
ET,
std::vector<T>{0.54881352f,
0.71518934f,
0.60276335f,
0.54488319f,
0.42365479f,
0.64589411f,
0.4375872f,
0.89177299f},
std::vector<T>{-0.30327f,
1.1561f,
-0.096382f,
-0.434702f,
-1.4011f,
0.548275f,
-1.06187f,
1.59295f},
std::vector<T>{1.0, 1.0},
std::vector<T>{0.0f, 0.0f},
std::vector<T>{0.583388f, 0.619252f},
std::vector<T>{0.0119972f, 0.0282681f},
0.001),
};
return params;
}
std::vector<BatchNormParams> generateCombinedParamsForBatchNorm() {
const std::vector<std::vector<BatchNormParams>> allTypeParams{
generateParamsForBatchNorm<element::Type_t::f32>(),
generateParamsForBatchNorm<element::Type_t::f16>()
};
std::vector<BatchNormParams> combinedParams;
for (const auto& params : allTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(
smoke_BatchNorm_With_Hardcoded_Refs,
ReferenceBatchNormV0LayerTest,
::testing::ValuesIn(generateCombinedParamsForBatchNorm()),
ReferenceBatchNormV0LayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(
smoke_BatchNorm_With_Hardcoded_Refs,
ReferenceBatchNormV5LayerTest,
::testing::ValuesIn(generateCombinedParamsForBatchNorm()),
ReferenceBatchNormV5LayerTest::getTestCaseName);
} // namespace

View File

@@ -0,0 +1,355 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "base_reference_test.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/lrn.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct LRNParams {
template <class T>
LRNParams(const Shape& input_shape,
const Shape& expected_shape,
const element::Type& input_type,
const element::Type& expected_type,
const std::vector<T>& input_value,
const std::vector<T>& expected_value,
const float& alpha,
const float& beta,
const float& bias,
const size_t& size,
const std::shared_ptr<op::v0::Constant>& axes) {
m_input_shape = input_shape;
m_expected_shape = expected_shape;
m_input_type = input_type;
m_expected_type = expected_type;
m_input_value = CreateTensor(input_type, input_value);
m_expected_value = CreateTensor(expected_type, expected_value);
m_alpha = alpha;
m_beta = beta;
m_bias = bias;
m_size = size;
m_axes = axes;
}
template <class T>
LRNParams(const Shape& input_shape,
const Shape& expected_shape,
const element::Type& input_type,
const element::Type& expected_type,
const T& input_value_step,
const std::vector<T>& expected_value,
const float& alpha,
const float& beta,
const float& bias,
const size_t& size,
const std::shared_ptr<op::v0::Constant>& axes) {
m_input_shape = input_shape;
m_expected_shape = expected_shape;
m_input_type = input_type;
m_expected_type = expected_type;
std::vector<T> input_value(shape_size(input_shape));
std::iota(std::begin(input_value), std::end(input_value), input_value_step);
m_input_value = CreateTensor(input_type, input_value);
m_expected_value = CreateTensor(expected_type, expected_value);
m_alpha = alpha;
m_beta = beta;
m_bias = bias;
m_size = size;
m_axes = axes;
}
Shape m_input_shape;
Shape m_expected_shape;
element::Type m_input_type;
element::Type m_expected_type;
runtime::Tensor m_input_value;
runtime::Tensor m_expected_value;
float m_alpha;
float m_beta;
float m_bias;
size_t m_size;
std::shared_ptr<op::v0::Constant> m_axes;
};
class ReferenceLRNLayerTest : public testing::TestWithParam<LRNParams>, public CommonReferenceTest {
public:
void SetUp() override {
const auto params = GetParam();
function = CreateFunction(params.m_input_shape,
params.m_input_type,
params.m_alpha,
params.m_beta,
params.m_bias,
params.m_size,
params.m_axes);
inputData = {params.m_input_value};
refOutData = {params.m_expected_value};
}
static std::string getTestCaseName(const testing::TestParamInfo<LRNParams>& obj) {
const auto param = obj.param;
std::ostringstream result;
result << "input_shape=" << param.m_input_shape << "; ";
result << "output_shape=" << param.m_expected_shape << "; ";
result << "input_type=" << param.m_input_type << "; ";
result << "output_type=" << param.m_expected_type << "; ";
if (param.m_axes != NULL) {
result << "axes=" << param.m_axes << "; ";
}
result << "gamma=" << param.m_alpha << "; ";
result << "beta=" << param.m_beta << "; ";
result << "mean=" << param.m_bias << "; ";
result << "variance=" << param.m_size << "; ";
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& input_shape,
const element::Type_t& input_type,
const float& alpah,
const float& beta,
const float& bias,
const size_t& size,
const std::shared_ptr<op::v0::Constant>& axes) {
auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
std::shared_ptr<op::v0::LRN> lrn;
if (axes != NULL) {
lrn = std::make_shared<op::v0::LRN>(in, axes, alpah, beta, bias, size);
} else {
lrn = std::make_shared<op::v0::LRN>(in, alpah, beta, bias, size);
}
return std::make_shared<ov::Function>(lrn, ParameterVector{in});
}
};
TEST_P(ReferenceLRNLayerTest, CompareWithHardcodedRefs) {
Exec();
}
template <element::Type_t ET>
std::vector<LRNParams> generateParamsForLRN() {
using T = typename element_type_traits<ET>::value_type;
std::vector<LRNParams> params{
// lrn_across_channel
LRNParams(Shape{2, 3, 2, 1},
Shape{2, 3, 2, 1},
ET,
ET,
std::vector<T>{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f},
std::vector<T>{0.0000000f,
0.3015113f,
0.4364358f,
0.5000000f,
0.8728716f,
0.8451542f,
0.5970223f,
0.6115928f,
0.5642765f,
0.5669467f,
0.7784989f,
0.7720487f},
3, 0.5, 1, 3,
NULL),
// lrn_across_h
LRNParams(Shape{2, 3, 2, 1},
Shape{2, 3, 2, 1},
ET,
ET,
std::vector<T>{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f},
std::vector<T>{0.0000000f,
0.7071068f,
0.5345225f,
0.8017837f,
0.6172134f,
0.7715167f,
0.6469966f,
0.7548294f,
0.6620847f,
0.7448453f,
0.6711560f,
0.7382717f},
3, 0.5, 1, 3,
std::make_shared<op::v0::Constant>(element::Type_t::i64, Shape{1}, std::vector<int64_t>{2})),
// lrn_across_hw
LRNParams(Shape{2, 3, 2, 1},
Shape{2, 3, 2, 1},
ET,
ET,
std::vector<T>{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f},
std::vector<T>{0.0000000f,
0.8660254f,
0.8660254f,
1.2990381f,
1.0444659f,
1.3055824f,
1.1078234f,
1.2924607f,
1.1389896f,
1.2813632f,
1.1572751f,
1.2730026f},
3, 0.5, 1, 3,
std::make_shared<op::v0::Constant>(element::Type_t::i64, Shape{2}, std::vector<int64_t>{2, 3})),
// lrn_across_all_dims
LRNParams(Shape{2, 3, 2, 1},
Shape{2, 3, 2, 1},
ET,
ET,
std::vector<T>{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f},
std::vector<T>{0.0000000f,
0.3156438f,
0.4501407f,
0.6752110f,
0.9830783f,
1.2288479f,
1.8938627f,
2.2095065f,
1.8005627f,
2.0256331f,
2.4576957f,
2.7034652f},
3, 0.5, 1, 3,
std::make_shared<op::v0::Constant>(element::Type_t::i64, Shape{4}, std::vector<int64_t>{0, 1, 2, 3})),
// lrn_across_nw
LRNParams(Shape{2, 3, 2, 1},
Shape{2, 3, 2, 1},
ET,
ET,
std::vector<T>{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f},
std::vector<T>{0.0000000f,
0.2379155f,
0.4111132f,
0.5388159f,
0.6351073f,
0.7094756f,
1.6641006f,
1.6654084f,
1.6444529f,
1.6164477f,
1.5877683f,
1.5608464f},
3, 0.5, 1, 3,
std::make_shared<op::v0::Constant>(element::Type_t::i64, Shape{2}, std::vector<int64_t>{0, 3})),
// lrn_across_empty
LRNParams(Shape{2, 3, 2, 1},
Shape{2, 3, 2, 1},
ET,
ET,
std::vector<T>{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f},
std::vector<T>{0.0000000f,
0.5000000f,
0.5547002f,
0.5669467f,
0.5714286f,
0.5735393f,
0.5746958f,
0.5753965f,
0.5758526f,
0.5761660f,
0.5763904f,
0.5765567f},
3, 0.5, 1, 3,
std::make_shared<op::v0::Constant>(element::Type_t::i64, Shape{0}, std::vector<int64_t>{})),
// lrn_6D_across_2_axes
LRNParams(Shape{2, 3, 2, 2, 1, 1},
Shape{2, 3, 2, 2, 1, 1},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0.0000000f, 0.4200840f, 0.8401681f, 1.2602521f, 0.6099943f, 0.7624928f,
0.9149914f, 1.0674900f, 0.7213357f, 0.8115027f, 0.9016696f, 0.9918366f,
0.7656109f, 0.8294119f, 0.8932127f, 0.9570137f, 0.7892218f, 0.8385482f,
0.8878745f, 0.9372009f, 0.8038679f, 0.8440613f, 0.8842546f, 0.9244481f},
3, 0.5, 1, 3,
std::make_shared<op::v0::Constant>(element::Type_t::i64, Shape{2}, std::vector<int64_t>{2, 3})),
// lrn_2d_across_empty
LRNParams(Shape{12},
Shape{12},
ET,
ET,
std::vector<T>{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f},
std::vector<T>{0.0000000f,
0.5000000f,
0.5547002f,
0.5669467f,
0.5714286f,
0.5735393f,
0.5746958f,
0.5753964f,
0.5758526f,
0.5761660f,
0.5763904f,
0.5765566f},
3, 0.5, 1, 3,
std::make_shared<op::v0::Constant>(element::Type_t::i64, Shape{0}, std::vector<int64_t>{})),
// lrn_2d_across_empty
LRNParams(Shape{6, 2},
Shape{6, 2},
ET,
ET,
std::vector<T>{0.64915806f,
0.21213771f,
-1.48256505f,
-1.41040838f,
0.58189541f,
0.11432108f,
-0.22993855f,
-0.13325502f,
-0.03083259f,
-0.48450908f,
0.50342429f,
-0.99551708f},
std::vector<T>{0.4590040f,
0.1499989f,
-1.0482801f,
-0.9972753f,
0.4114444f,
0.0808345f,
-0.1625900f,
-0.0942251f,
-0.0218018f,
-0.3425926f,
0.3559732f,
-0.7039225f},
0.0002, 0.5, 2.0, 3,
std::make_shared<op::v0::Constant>(element::Type_t::i64, Shape{1}, std::vector<int64_t>{0})),
};
return params;
}
std::vector<LRNParams> generateCombinedParamsForLRN() {
const std::vector<std::vector<LRNParams>> allTypeParams{
generateParamsForLRN<element::Type_t::f64>(),
generateParamsForLRN<element::Type_t::f32>()
};
std::vector<LRNParams> combinedParams;
for (const auto& params : allTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(
smoke_LRN_With_Hardcoded_Refs,
ReferenceLRNLayerTest,
::testing::ValuesIn(generateCombinedParamsForLRN()),
ReferenceLRNLayerTest::getTestCaseName);
} // namespace

View File

@@ -0,0 +1,801 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "base_reference_test.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/normalize_l2.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct NormalizeL2Params {
template <class T>
NormalizeL2Params(const Shape& input_shape,
const Shape& expected_shape,
const element::Type& input_type,
const element::Type& expected_type,
const std::vector<T>& input_value,
const std::vector<T>& expected_value,
const std::vector<int32_t>& axes,
const op::EpsMode& eps_mode,
const float& eps,
const std::string test_name) {
m_input_shape = input_shape;
m_expected_shape = expected_shape;
m_input_type = input_type;
m_expected_type = expected_type;
m_input_value = CreateTensor(input_type, input_value);
m_expected_value = CreateTensor(expected_type, expected_value);
m_axes = axes;
m_eps_mode = eps_mode;
m_eps = eps;
m_test_name = test_name;
}
template <class T>
NormalizeL2Params(const Shape& input_shape,
const Shape& expected_shape,
const element::Type& input_type,
const element::Type& expected_type,
const T& input_value_step,
const std::vector<T>& expected_value,
const std::vector<int32_t>& axes,
const op::EpsMode& eps_mode,
const float& eps,
const std::string test_name) {
m_input_shape = input_shape;
m_expected_shape = expected_shape;
m_input_type = input_type;
m_expected_type = expected_type;
std::vector<T> input_value(shape_size(input_shape));
std::iota(begin(input_value), end(input_value), input_value_step);
m_input_value = CreateTensor(input_type, input_value);
m_expected_value = CreateTensor(expected_type, expected_value);
m_axes = axes;
m_eps_mode = eps_mode;
m_eps = eps;
m_test_name = test_name;
}
Shape m_input_shape;
Shape m_expected_shape;
element::Type m_input_type;
element::Type m_expected_type;
runtime::Tensor m_input_value;
runtime::Tensor m_expected_value;
std::vector<int32_t> m_axes;
op::EpsMode m_eps_mode;
float m_eps;
std::string m_test_name;
};
class ReferenceNormalizeL2LayerTest : public testing::TestWithParam<NormalizeL2Params>, public CommonReferenceTest {
public:
void SetUp() override {
const auto params = GetParam();
function = CreateFunction(params.m_input_shape,
params.m_input_type,
params.m_axes,
params.m_eps_mode,
params.m_eps);
inputData = {params.m_input_value};
refOutData = {params.m_expected_value};
}
static std::string getTestCaseName(const testing::TestParamInfo<NormalizeL2Params>& obj) {
const auto param = obj.param;
std::ostringstream result;
result << "input_shape=" << param.m_input_shape << "; ";
result << "output_shape=" << param.m_expected_shape << "; ";
result << "input_type=" << param.m_input_type << "; ";
result << "output_type=" << param.m_expected_type << "; ";
result << "axes=" << param.m_axes.data() << "; ";
result << "eps_mode=" << param.m_eps_mode << "; ";
result << "eps=" << param.m_eps << "; ";
result << "test=" << param.m_test_name;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& input_shape,
const element::Type_t& input_type,
const std::vector<int32_t>& axes,
const op::EpsMode& eps_mode,
const float& eps) {
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
const auto axes_data = std::make_shared<op::v0::Constant>(element::Type_t::i32, Shape{axes.size()}, axes);
auto normalize = std::make_shared<op::v0::NormalizeL2>(in, axes_data, eps, eps_mode);
return std::make_shared<ov::Function>(normalize, ParameterVector{in});
}
};
TEST_P(ReferenceNormalizeL2LayerTest, CompareWithHardcodedRefs) {
Exec();
}
template <element::Type_t ET>
std::vector<NormalizeL2Params> generateParamsForNormalizeL2() {
using T = typename element_type_traits<ET>::value_type;
std::vector<NormalizeL2Params> params{
NormalizeL2Params(Shape{4},
Shape{4},
ET,
ET,
std::vector<T>{0, 3, 0, 8},
std::vector<T>{0, 1, 0, 1},
std::vector<int32_t>{},
op::EpsMode::ADD,
1e-7,
"normalize_l2_1D_axes_empty_add"),
NormalizeL2Params(Shape{4},
Shape{4},
ET,
ET,
std::vector<T>{0, 3, 0, 8},
std::vector<T>{0, 1, 0, 1},
std::vector<int32_t>{},
op::EpsMode::MAX,
1e-7,
"normalize_l2_1D_axes_empty_max"),
NormalizeL2Params(Shape{4},
Shape{4},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.18257418, 0.36514837, 0.5477226, 0.73029673},
std::vector<int32_t>{0},
op::EpsMode::ADD,
1e-7,
"normalize_l2_1D_axes_0_add"),
NormalizeL2Params(Shape{4},
Shape{4},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.18257418, 0.36514837, 0.5477226, 0.73029673},
std::vector<int32_t>{0},
op::EpsMode::MAX,
1e-7,
"normalize_l2_1D_axes_0_max"),
NormalizeL2Params(Shape{2, 2},
Shape{2, 2},
ET,
ET,
std::vector<T>{0, 3, 0, 8},
std::vector<T>{0, 1, 0, 1},
std::vector<int32_t>{},
op::EpsMode::ADD,
1e-7,
"normalize_l2_2D_axes_empty_add"),
NormalizeL2Params(Shape{2, 2},
Shape{2, 2},
ET,
ET,
std::vector<T>{0, 3, 0, 8},
std::vector<T>{0, 1, 0, 1},
std::vector<int32_t>{},
op::EpsMode::MAX,
1e-7,
"normalize_l2_2D_axes_empty_max"),
NormalizeL2Params(Shape{2, 2},
Shape{2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.31622776, 0.4472136, 0.94868326, 0.8944272},
std::vector<int32_t>{0},
op::EpsMode::ADD,
1e-7,
"normalize_l2_2D_axes_0_add"),
NormalizeL2Params(Shape{2, 2},
Shape{2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.31622776, 0.4472136, 0.94868326, 0.8944272},
std::vector<int32_t>{0},
op::EpsMode::MAX,
1e-7,
"normalize_l2_2D_axes_0_max"),
NormalizeL2Params(Shape{2, 2},
Shape{2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.4472136, 0.8944272, 0.6, 0.8},
std::vector<int32_t>{1},
op::EpsMode::ADD,
1e-7,
"normalize_l2_2D_axes_1_add"),
NormalizeL2Params(Shape{2, 2},
Shape{2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.4472136, 0.8944272, 0.6, 0.8},
std::vector<int32_t>{1},
op::EpsMode::MAX,
1e-7,
"normalize_l2_2D_axes_1_max"),
NormalizeL2Params(Shape{2, 2},
Shape{2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.18257418, 0.36514837, 0.5477226, 0.73029673},
std::vector<int32_t>{0, 1},
op::EpsMode::ADD,
1e-7,
"normalize_l2_2D_axes_01_add"),
NormalizeL2Params(Shape{2, 2},
Shape{2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.18257419, 0.36514837, 0.5477226, 0.73029674},
std::vector<int32_t>{0, 1},
op::EpsMode::MAX,
1e-7,
"normalize_l2_2D_axes_01_max"),
NormalizeL2Params(Shape{1, 2, 2},
Shape{1, 2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.31622776, 0.4472136, 0.94868326, 0.8944272},
std::vector<int32_t>{1},
op::EpsMode::ADD,
1e-7,
"normalize_l2_3D_axes_1_add"),
NormalizeL2Params(Shape{1, 2, 2},
Shape{1, 2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.31622776, 0.4472136, 0.94868326, 0.8944272},
std::vector<int32_t>{1},
op::EpsMode::MAX,
1e-7,
"normalize_l2_3D_axes_1_max"),
NormalizeL2Params(Shape{1, 2, 2},
Shape{1, 2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.4472136, 0.8944272, 0.6, 0.8},
std::vector<int32_t>{2},
op::EpsMode::ADD,
1e-7,
"normalize_l2_3D_axes_2_add"),
NormalizeL2Params(Shape{1, 2, 2},
Shape{1, 2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 4},
std::vector<T>{0.4472136, 0.8944272, 0.6, 0.8},
std::vector<int32_t>{2},
op::EpsMode::MAX,
1e-7,
"normalize_l2_3D_axes_2_max"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(1),
std::vector<T>(2 * 2 * 3 * 4, 1),
std::vector<int32_t>{},
op::EpsMode::ADD,
0.1,
"normalize_l2_4D_axes_empty_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(1),
std::vector<T>(2 * 2 * 3 * 4, 1),
std::vector<int32_t>{},
op::EpsMode::MAX,
0.1,
"normalize_l2_4D_axes_empty_max"),
NormalizeL2Params(
Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.0399648, 0.0766909, 0.110424, 0.141413, 0.169897, 0.196106, 0.22025,
0.242524, 0.263106, 0.282155, 0.299815, 0.316217, 0.331475, 0.345695, 0.358969,
0.371381, 0.383005, 0.39391, 0.404155, 0.413794, 0.422877, 0.431447, 0.439545,
0.999913, 0.999121, 0.996981, 0.993816, 0.989888, 0.985403, 0.980528, 0.975393,
0.970098, 0.964723, 0.959327, 0.953958, 0.94865, 0.94343, 0.938315, 0.933319,
0.928452, 0.923719, 0.919123, 0.914666, 0.910347, 0.906165, 0.902117, 0.8982},
std::vector<int32_t>{0},
op::EpsMode::ADD,
0.1,
"normalize_l2_4D_axes_0_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.03996804, 0.07669649, 0.11043153, 0.14142135, 0.1699069, 0.19611612, 0.22026087,
0.2425356, 0.26311737, 0.2821663, 0.2998266, 0.31622776, 0.331486, 0.34570533, 0.35897905,
0.37139067, 0.38301498, 0.3939193, 0.40416384, 0.41380292, 0.42288542, 0.43145543, 0.43955287,
0.99999994, 0.9992009, 0.9970544, 0.9938838, 0.98994946, 0.98546, 0.9805806, 0.97544104,
0.9701424, 0.96476364, 0.9593654, 0.95399374, 0.9486833, 0.9434601, 0.93834305, 0.93334556,
0.9284767, 0.923742, 0.919145, 0.91468656, 0.9103665, 0.90618306, 0.90213406, 0.8982167},
std::vector<int32_t>{0},
op::EpsMode::MAX,
0.1,
"normalize_l2_4D_axes_0_max"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.07667395, 0.14138602, 0.19607423, 0.24249104, 0.28212142, 0.31618387, 0.3456632,
0.37135068, 0.3938816, 0.41376755, 0.43142232, 0.9996529, 0.9967614, 0.9897021, 0.9803712,
0.96996415, 0.9592128, 0.94855154, 0.93822867, 0.9283767, 0.9190571, 0.9102886, 0.9020648,
0.5546854, 0.55984336, 0.56467056, 0.56919736, 0.5734503, 0.57745326, 0.58122724, 0.5847912,
0.58816177, 0.59135413, 0.594382, 0.59725744, 0.8320281, 0.8285682, 0.82528776, 0.82217395,
0.8192147, 0.8163994, 0.8137182, 0.81116194, 0.8087224, 0.806392, 0.8041638, 0.8020314},
std::vector<int32_t>{1},
op::EpsMode::ADD,
0.1,
"normalize_l2_4D_axes_1_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.07669649, 0.14142135, 0.19611612, 0.2425356, 0.2821663, 0.31622776, 0.34570533,
0.37139067, 0.3939193, 0.41380292, 0.43145543, 0.99999994, 0.9970544, 0.98994946, 0.9805806,
0.9701424, 0.9593654, 0.9486833, 0.93834305, 0.9284767, 0.919145, 0.9103665, 0.90213406,
0.5547002, 0.55985737, 0.56468385, 0.5692099, 0.57346237, 0.57746464, 0.58123815, 0.5848015,
0.58817166, 0.59136367, 0.59439105, 0.5972662, 0.83205026, 0.82858896, 0.8253072, 0.8221921,
0.8192319, 0.81641555, 0.8137334, 0.8111763, 0.808736, 0.80640495, 0.8041761, 0.8020432},
std::vector<int32_t>{1},
op::EpsMode::MAX,
0.1,
"normalize_l2_4D_axes_1_max"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0, 0.0966285, 0.168971, 0.224168, 0.446934, 0.483143, 0.506912, 0.523058,
0.893869, 0.869657, 0.844853, 0.821949, 0.424238, 0.43355, 0.441814, 0.449194,
0.56565, 0.56695, 0.568047, 0.56898, 0.707063, 0.70035, 0.694279, 0.688765,
0.491529, 0.494579, 0.497422, 0.500077, 0.57345, 0.573712, 0.573949, 0.574163,
0.655372, 0.652845, 0.650475, 0.648248, 0.517886, 0.519373, 0.520787, 0.522135,
0.575429, 0.575521, 0.575607, 0.575687, 0.632972, 0.63167, 0.630427, 0.629239},
std::vector<int32_t>{2},
op::EpsMode::ADD,
0.1,
"normalize_l2_4D_axes_2_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.09667365, 0.16903085, 0.22423053, 0.4472136, 0.48336822, 0.50709254, 0.52320457,
0.8944272, 0.8700628, 0.8451542, 0.8221786, 0.42426404, 0.4335743, 0.4418361, 0.4492145,
0.5656854, 0.5669818, 0.56807494, 0.569005, 0.7071067, 0.70038927, 0.6943139, 0.68879557,
0.49153918, 0.4945891, 0.49743116, 0.5000857, 0.57346237, 0.5737234, 0.57395905, 0.5741725,
0.65538555, 0.6528576, 0.6504869, 0.6482592, 0.51789176, 0.5193782, 0.52079225, 0.5221394,
0.5754353, 0.5755272, 0.57561255, 0.5756921, 0.63297886, 0.6316762, 0.6304327, 0.62924486},
std::vector<int32_t>{2},
op::EpsMode::MAX,
0.1,
"normalize_l2_4D_axes_2_max"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0, 0.266312, 0.532624, 0.798935, 0.356207, 0.445259, 0.534311, 0.623362,
0.41811, 0.470373, 0.522637, 0.574901, 0.442898, 0.479806, 0.516714, 0.553622,
0.456194, 0.484706, 0.513219, 0.541731, 0.464476, 0.4877, 0.510924, 0.534148,
0.470128, 0.489716, 0.509305, 0.528893, 0.474229, 0.491166, 0.508102, 0.525039,
0.477341, 0.492258, 0.507175, 0.522092, 0.479783, 0.49311, 0.506437, 0.519764,
0.481749, 0.493793, 0.505837, 0.517881, 0.483368, 0.494353, 0.505339, 0.516325},
std::vector<int32_t>{3},
op::EpsMode::ADD,
0.1,
"normalize_l2_4D_axes_3_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.26726124, 0.5345225, 0.8017837, 0.3563483, 0.44543537, 0.5345225, 0.62360954,
0.41816667, 0.4704375, 0.52270836, 0.5749792, 0.44292808, 0.47983873, 0.5167494, 0.5536601,
0.45621273, 0.484726, 0.5132393, 0.54175264, 0.4644887, 0.4877131, 0.5109376, 0.534162,
0.47013652, 0.48972553, 0.50931454, 0.5289036, 0.47423577, 0.49117276, 0.50810975, 0.5250467,
0.47734618, 0.49226326, 0.50718033, 0.5220974, 0.4797868, 0.49311423, 0.50644165, 0.5197691,
0.48175293, 0.49379677, 0.5058406, 0.51788443, 0.48337057, 0.49435627, 0.50534195, 0.5163277},
std::vector<int32_t>{3},
op::EpsMode::MAX,
0.1,
"normalize_l2_4D_axes_3_max"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.04445103, 0.08890206, 0.1333531, 0.17780413, 0.22225516, 0.2667062, 0.31115723,
0.35560825, 0.40005928, 0.4445103, 0.48896134, 0.19420375, 0.2103874, 0.22657104, 0.24275468,
0.2589383, 0.275122, 0.29130563, 0.30748928, 0.32367292, 0.33985656, 0.3560402, 0.37222385,
0.2332616, 0.24298084, 0.25270006, 0.2624193, 0.27213854, 0.2818578, 0.291577, 0.30129623,
0.3110155, 0.3207347, 0.33045393, 0.34017318, 0.2495545, 0.25648656, 0.26341864, 0.27035072,
0.27728277, 0.28421485, 0.29114693, 0.29807898, 0.30501106, 0.3119431, 0.3188752, 0.32580727},
std::vector<int32_t>{2, 3},
op::EpsMode::ADD,
0.1,
"normalize_l2_4D_axes_23_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.04445542, 0.08891085, 0.13336627, 0.1778217, 0.22227712, 0.26673254, 0.31118798,
0.3556434, 0.4000988, 0.44455424, 0.48900968, 0.19420628, 0.21039014, 0.226574, 0.24275786,
0.2589417, 0.27512556, 0.29130942, 0.30749327, 0.32367712, 0.339861, 0.35604486, 0.3722287,
0.23326269, 0.24298197, 0.25270125, 0.26242054, 0.2721398, 0.28185907, 0.29157835, 0.30129763,
0.31101692, 0.3207362, 0.33045548, 0.34017476, 0.24955511, 0.2564872, 0.26341927, 0.27035138,
0.27728346, 0.28421554, 0.29114762, 0.2980797, 0.3050118, 0.3119439, 0.31887597, 0.32580805},
std::vector<int32_t>{2, 3},
op::EpsMode::MAX,
0.1,
"normalize_l2_4D_axes_23_max"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0, 0.0152075, 0.030415, 0.0456224, 0.0608299, 0.0760374, 0.0912449, 0.106452, 0.12166, 0.136867,
0.152075, 0.167282, 0.18249, 0.197697, 0.212905, 0.228112, 0.24332, 0.258527, 0.273735, 0.288942,
0.30415, 0.319357, 0.334565, 0.349772, 0.135448, 0.141092, 0.146736, 0.15238, 0.158023, 0.163667,
0.169311, 0.174954, 0.180598, 0.186242, 0.191885, 0.197529, 0.203173, 0.208816, 0.21446, 0.220104,
0.225747, 0.231391, 0.237035, 0.242678, 0.248322, 0.253966, 0.25961, 0.265253},
std::vector<int32_t>{1, 2, 3},
op::EpsMode::ADD,
1e-9,
"normalize_l2_4D_axes_123_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.01520748, 0.03041495, 0.04562243, 0.06082991, 0.07603738, 0.09124486, 0.10645234,
0.12165982, 0.13686728, 0.15207477, 0.16728225, 0.18248972, 0.19769719, 0.21290468, 0.22811216,
0.24331963, 0.2585271, 0.27373457, 0.28894207, 0.30414954, 0.319357, 0.3345645, 0.34977198,
0.13544846, 0.14109215, 0.14673583, 0.15237951, 0.15802321, 0.16366689, 0.16931057, 0.17495427,
0.18059795, 0.18624163, 0.19188532, 0.197529, 0.20317268, 0.20881638, 0.21446006, 0.22010374,
0.22574744, 0.23139112, 0.2370348, 0.2426785, 0.24832217, 0.25396585, 0.25960955, 0.26525325},
std::vector<int32_t>{1, 2, 3},
op::EpsMode::MAX,
0.1,
"normalize_l2_4D_axes_123_max"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0, 0.0152066, 0.0304132, 0.0456198, 0.0608264, 0.076033, 0.0912396, 0.106446, 0.121653, 0.136859,
0.152066, 0.167273, 0.182479, 0.197686, 0.212892, 0.228099, 0.243306, 0.258512, 0.273719, 0.288925,
0.304132, 0.319339, 0.334545, 0.349752, 0.135447, 0.141091, 0.146735, 0.152378, 0.158022, 0.163666,
0.169309, 0.174953, 0.180597, 0.18624, 0.191884, 0.197527, 0.203171, 0.208815, 0.214458, 0.220102,
0.225746, 0.231389, 0.237033, 0.242677, 0.24832, 0.253964, 0.259607, 0.265251},
std::vector<int32_t>{1, 2, 3},
op::EpsMode::ADD,
0.5,
"normalize_l2_4D_axes_123_big_eps_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.01520748, 0.03041495, 0.04562243, 0.06082991, 0.07603738, 0.09124486, 0.10645234,
0.12165982, 0.13686728, 0.15207477, 0.16728225, 0.18248972, 0.19769719, 0.21290468, 0.22811216,
0.24331963, 0.2585271, 0.27373457, 0.28894207, 0.30414954, 0.319357, 0.3345645, 0.34977198,
0.13544846, 0.14109215, 0.14673583, 0.15237951, 0.15802321, 0.16366689, 0.16931057, 0.17495427,
0.18059795, 0.18624163, 0.19188532, 0.197529, 0.20317268, 0.20881638, 0.21446006, 0.22010374,
0.22574744, 0.23139112, 0.2370348, 0.2426785, 0.24832217, 0.25396585, 0.25960955, 0.26525325},
std::vector<int32_t>{1, 2, 3},
op::EpsMode::MAX,
100,
"normalize_l2_4D_axes_123_big_eps_max"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0, 0.0152075, 0.030415, 0.0456224, 0.0608299, 0.0760374, 0.0912449, 0.106452, 0.12166, 0.136867,
0.152075, 0.167282, 0.18249, 0.197697, 0.212905, 0.228112, 0.24332, 0.258527, 0.273735, 0.288942,
0.30415, 0.319357, 0.334565, 0.349772, 0.135448, 0.141092, 0.146736, 0.15238, 0.158023, 0.163667,
0.169311, 0.174954, 0.180598, 0.186242, 0.191885, 0.197529, 0.203173, 0.208816, 0.21446, 0.220104,
0.225747, 0.231391, 0.237035, 0.242678, 0.248322, 0.253966, 0.25961, 0.265253},
std::vector<int32_t>{3, 1, 2},
op::EpsMode::ADD,
1e-9,
"normalize_l2_4D_axes_unsorted_312_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.01520748, 0.03041495, 0.04562243, 0.06082991, 0.07603738, 0.09124486, 0.10645234,
0.12165982, 0.13686728, 0.15207477, 0.16728225, 0.18248972, 0.19769719, 0.21290468, 0.22811216,
0.24331963, 0.2585271, 0.27373457, 0.28894207, 0.30414954, 0.319357, 0.3345645, 0.34977198,
0.13544846, 0.14109215, 0.14673583, 0.15237951, 0.15802321, 0.16366689, 0.16931057, 0.17495427,
0.18059795, 0.18624163, 0.19188532, 0.197529, 0.20317268, 0.20881638, 0.21446006, 0.22010374,
0.22574744, 0.23139112, 0.2370348, 0.2426785, 0.24832217, 0.25396585, 0.25960955, 0.26525325},
std::vector<int32_t>{3, 1, 2},
op::EpsMode::MAX,
0.1,
"normalize_l2_4D_axes_unsorted_312_max"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.00529108, 0.01058216, 0.01587324, 0.02116432, 0.02645539, 0.03174648, 0.03703756,
0.04232863, 0.04761971, 0.05291079, 0.05820187, 0.06349295, 0.06878403, 0.07407511, 0.07936618,
0.08465727, 0.08994835, 0.09523942, 0.10053051, 0.10582158, 0.11111266, 0.11640374, 0.12169482,
0.12698591, 0.13227698, 0.13756806, 0.14285913, 0.14815022, 0.1534413, 0.15873237, 0.16402346,
0.16931453, 0.17460561, 0.1798967, 0.18518777, 0.19047885, 0.19576994, 0.20106101, 0.20635208,
0.21164316, 0.21693425, 0.22222532, 0.2275164, 0.23280749, 0.23809856, 0.24338964, 0.24868073},
std::vector<int32_t>{0, 1, 2, 3},
op::EpsMode::ADD,
0.1,
"normalize_l2_4D_axes_0123_add"),
NormalizeL2Params(Shape{2, 2, 3, 4},
Shape{2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.00529108, 0.01058216, 0.01587324, 0.02116432, 0.02645539, 0.03174648, 0.03703756,
0.04232863, 0.04761971, 0.05291079, 0.05820187, 0.06349295, 0.06878403, 0.07407511, 0.07936618,
0.08465727, 0.08994835, 0.09523942, 0.10053051, 0.10582158, 0.11111266, 0.11640374, 0.12169482,
0.12698591, 0.13227698, 0.13756806, 0.14285913, 0.14815022, 0.1534413, 0.15873237, 0.16402346,
0.16931453, 0.17460561, 0.1798967, 0.18518777, 0.19047885, 0.19576994, 0.20106101, 0.20635208,
0.21164316, 0.21693425, 0.22222532, 0.2275164, 0.23280749, 0.23809856, 0.24338964, 0.24868073},
std::vector<int32_t>{0, 1, 2, 3},
op::EpsMode::MAX,
0.1,
"normalize_l2_4D_axes_0123_max"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(1),
std::vector<T>(1 * 2 * 2 * 3 * 4, 1),
std::vector<int32_t>{},
op::EpsMode::ADD,
0.1,
"normalize_l2_5D_axes_empty_add"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(1),
std::vector<T>(1 * 2 * 2 * 3 * 4, 1),
std::vector<int32_t>{},
op::EpsMode::MAX,
0.1,
"normalize_l2_5D_axes_empty_max"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0, 0.0399648, 0.0766909, 0.110424, 0.141413, 0.169897, 0.196106, 0.22025,
0.242524, 0.263106, 0.282155, 0.299815, 0.316217, 0.331475, 0.345695, 0.358969,
0.371381, 0.383005, 0.39391, 0.404155, 0.413794, 0.422877, 0.431447, 0.439545,
0.999913, 0.999121, 0.996981, 0.993816, 0.989888, 0.985403, 0.980528, 0.975393,
0.970098, 0.964723, 0.959327, 0.953958, 0.94865, 0.94343, 0.938315, 0.933319,
0.928452, 0.923719, 0.919123, 0.914666, 0.910347, 0.906165, 0.902117, 0.8982},
std::vector<int32_t>{1},
op::EpsMode::ADD,
0.1,
"normalize_l2_5D_axes_1_add"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.03996804, 0.07669649, 0.11043153, 0.14142135, 0.1699069, 0.19611612, 0.22026087,
0.2425356, 0.26311737, 0.2821663, 0.2998266, 0.31622776, 0.331486, 0.34570533, 0.35897905,
0.37139067, 0.38301498, 0.3939193, 0.40416384, 0.41380292, 0.42288542, 0.43145543, 0.43955287,
0.99999994, 0.9992009, 0.9970544, 0.9938838, 0.98994946, 0.98546, 0.9805806, 0.97544104,
0.9701424, 0.96476364, 0.9593654, 0.95399374, 0.9486833, 0.9434601, 0.93834305, 0.93334556,
0.9284767, 0.923742, 0.919145, 0.91468656, 0.9103665, 0.90618306, 0.90213406, 0.8982167},
std::vector<int32_t>{1},
op::EpsMode::MAX,
0.1,
"normalize_l2_5D_axes_1_max"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.07667395, 0.14138602, 0.19607423, 0.24249104, 0.28212142, 0.31618387, 0.3456632,
0.37135068, 0.3938816, 0.41376755, 0.43142232, 0.9996529, 0.9967614, 0.9897021, 0.9803712,
0.96996415, 0.9592128, 0.94855154, 0.93822867, 0.9283767, 0.9190571, 0.9102886, 0.9020648,
0.5546854, 0.55984336, 0.56467056, 0.56919736, 0.5734503, 0.57745326, 0.58122724, 0.5847912,
0.58816177, 0.59135413, 0.594382, 0.59725744, 0.8320281, 0.8285682, 0.82528776, 0.82217395,
0.8192147, 0.8163994, 0.8137182, 0.81116194, 0.8087224, 0.806392, 0.8041638, 0.8020314},
std::vector<int32_t>{2},
op::EpsMode::ADD,
0.1,
"normalize_l2_5D_axes_2_add"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.07669649, 0.14142135, 0.19611612, 0.2425356, 0.2821663, 0.31622776, 0.34570533,
0.37139067, 0.3939193, 0.41380292, 0.43145543, 0.99999994, 0.9970544, 0.98994946, 0.9805806,
0.9701424, 0.9593654, 0.9486833, 0.93834305, 0.9284767, 0.919145, 0.9103665, 0.90213406,
0.5547002, 0.55985737, 0.56468385, 0.5692099, 0.57346237, 0.57746464, 0.58123815, 0.5848015,
0.58817166, 0.59136367, 0.59439105, 0.5972662, 0.83205026, 0.82858896, 0.8253072, 0.8221921,
0.8192319, 0.81641555, 0.8137334, 0.8111763, 0.808736, 0.80640495, 0.8041761, 0.8020432},
std::vector<int32_t>{2},
op::EpsMode::MAX,
0.1,
"normalize_l2_5D_axes_2_max"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0, 0.0966285, 0.168971, 0.224168, 0.446934, 0.483143, 0.506912, 0.523058,
0.893869, 0.869657, 0.844853, 0.821949, 0.424238, 0.43355, 0.441814, 0.449194,
0.56565, 0.56695, 0.568047, 0.56898, 0.707063, 0.70035, 0.694279, 0.688765,
0.491529, 0.494579, 0.497422, 0.500077, 0.57345, 0.573712, 0.573949, 0.574163,
0.655372, 0.652845, 0.650475, 0.648248, 0.517886, 0.519373, 0.520787, 0.522135,
0.575429, 0.575521, 0.575607, 0.575687, 0.632972, 0.63167, 0.630427, 0.629239},
std::vector<int32_t>{3},
op::EpsMode::ADD,
0.1,
"normalize_l2_5D_axes_3_add"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.09667365, 0.16903085, 0.22423053, 0.4472136, 0.48336822, 0.50709254, 0.52320457,
0.8944272, 0.8700628, 0.8451542, 0.8221786, 0.42426404, 0.4335743, 0.4418361, 0.4492145,
0.5656854, 0.5669818, 0.56807494, 0.569005, 0.7071067, 0.70038927, 0.6943139, 0.68879557,
0.49153918, 0.4945891, 0.49743116, 0.5000857, 0.57346237, 0.5737234, 0.57395905, 0.5741725,
0.65538555, 0.6528576, 0.6504869, 0.6482592, 0.51789176, 0.5193782, 0.52079225, 0.5221394,
0.5754353, 0.5755272, 0.57561255, 0.5756921, 0.63297886, 0.6316762, 0.6304327, 0.62924486},
std::vector<int32_t>{3},
op::EpsMode::MAX,
0.1,
"normalize_l2_5D_axes_3_max"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0, 0.266312, 0.532624, 0.798935, 0.356207, 0.445259, 0.534311, 0.623362,
0.41811, 0.470373, 0.522637, 0.574901, 0.442898, 0.479806, 0.516714, 0.553622,
0.456194, 0.484706, 0.513219, 0.541731, 0.464476, 0.4877, 0.510924, 0.534148,
0.470128, 0.489716, 0.509305, 0.528893, 0.474229, 0.491166, 0.508102, 0.525039,
0.477341, 0.492258, 0.507175, 0.522092, 0.479783, 0.49311, 0.506437, 0.519764,
0.481749, 0.493793, 0.505837, 0.517881, 0.483368, 0.494353, 0.505339, 0.516325},
std::vector<int32_t>{4},
op::EpsMode::ADD,
0.1,
"normalize_l2_5D_axes_4_add"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.26726124, 0.5345225, 0.8017837, 0.3563483, 0.44543537, 0.5345225, 0.62360954,
0.41816667, 0.4704375, 0.52270836, 0.5749792, 0.44292808, 0.47983873, 0.5167494, 0.5536601,
0.45621273, 0.484726, 0.5132393, 0.54175264, 0.4644887, 0.4877131, 0.5109376, 0.534162,
0.47013652, 0.48972553, 0.50931454, 0.5289036, 0.47423577, 0.49117276, 0.50810975, 0.5250467,
0.47734618, 0.49226326, 0.50718033, 0.5220974, 0.4797868, 0.49311423, 0.50644165, 0.5197691,
0.48175293, 0.49379677, 0.5058406, 0.51788443, 0.48337057, 0.49435627, 0.50534195, 0.5163277},
std::vector<int32_t>{4},
op::EpsMode::MAX,
0.1,
"normalize_l2_5D_axes_4_max"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.04445103, 0.08890206, 0.1333531, 0.17780413, 0.22225516, 0.2667062, 0.31115723,
0.35560825, 0.40005928, 0.4445103, 0.48896134, 0.19420375, 0.2103874, 0.22657104, 0.24275468,
0.2589383, 0.275122, 0.29130563, 0.30748928, 0.32367292, 0.33985656, 0.3560402, 0.37222385,
0.2332616, 0.24298084, 0.25270006, 0.2624193, 0.27213854, 0.2818578, 0.291577, 0.30129623,
0.3110155, 0.3207347, 0.33045393, 0.34017318, 0.2495545, 0.25648656, 0.26341864, 0.27035072,
0.27728277, 0.28421485, 0.29114693, 0.29807898, 0.30501106, 0.3119431, 0.3188752, 0.32580727},
std::vector<int32_t>{3, 4},
op::EpsMode::ADD,
0.1,
"normalize_l2_5D_axes_34_add"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.04445542, 0.08891085, 0.13336627, 0.1778217, 0.22227712, 0.26673254, 0.31118798,
0.3556434, 0.4000988, 0.44455424, 0.48900968, 0.19420628, 0.21039014, 0.226574, 0.24275786,
0.2589417, 0.27512556, 0.29130942, 0.30749327, 0.32367712, 0.339861, 0.35604486, 0.3722287,
0.23326269, 0.24298197, 0.25270125, 0.26242054, 0.2721398, 0.28185907, 0.29157835, 0.30129763,
0.31101692, 0.3207362, 0.33045548, 0.34017476, 0.24955511, 0.2564872, 0.26341927, 0.27035138,
0.27728346, 0.28421554, 0.29114762, 0.2980797, 0.3050118, 0.3119439, 0.31887597, 0.32580805},
std::vector<int32_t>{3, 4},
op::EpsMode::MAX,
0.1,
"normalize_l2_5D_axes_34_max"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.0152073, 0.0304146, 0.0456219, 0.0608292, 0.07603651, 0.0912438, 0.10645111,
0.12165841, 0.1368657, 0.15207301, 0.16728032, 0.1824876, 0.19769491, 0.21290222, 0.22810951,
0.24331681, 0.25852412, 0.2737314, 0.28893873, 0.30414602, 0.3193533, 0.33456063, 0.34976792,
0.13544825, 0.14109191, 0.1467356, 0.15237927, 0.15802296, 0.16366662, 0.1693103, 0.17495398,
0.18059766, 0.18624133, 0.19188501, 0.19752869, 0.20317237, 0.20881604, 0.21445972, 0.2201034,
0.22574706, 0.23139074, 0.23703443, 0.2426781, 0.24832177, 0.25396547, 0.25960913, 0.2652528},
std::vector<int32_t>{2, 3, 4},
op::EpsMode::ADD,
0.1,
"normalize_l2_5D_axes_234_add"),
NormalizeL2Params(Shape{1, 2, 2, 3, 4},
Shape{1, 2, 2, 3, 4},
ET,
ET,
static_cast<T>(0),
std::vector<T>{0., 0.01520748, 0.03041495, 0.04562243, 0.06082991, 0.07603738, 0.09124486, 0.10645234,
0.12165982, 0.13686728, 0.15207477, 0.16728225, 0.18248972, 0.19769719, 0.21290468, 0.22811216,
0.24331963, 0.2585271, 0.27373457, 0.28894207, 0.30414954, 0.319357, 0.3345645, 0.34977198,
0.13544846, 0.14109215, 0.14673583, 0.15237951, 0.15802321, 0.16366689, 0.16931057, 0.17495427,
0.18059795, 0.18624163, 0.19188532, 0.197529, 0.20317268, 0.20881638, 0.21446006, 0.22010374,
0.22574744, 0.23139112, 0.2370348, 0.2426785, 0.24832217, 0.25396585, 0.25960955, 0.26525325},
std::vector<int32_t>{2, 3, 4},
op::EpsMode::MAX,
0.1,
"normalize_l2_5D_axes_234_max"),
};
return params;
}
std::vector<NormalizeL2Params> generateCombinedParamsForNormalizeL2() {
const std::vector<std::vector<NormalizeL2Params>> allTypeParams{
generateParamsForNormalizeL2<element::Type_t::f32>()
};
std::vector<NormalizeL2Params> combinedParams;
for (const auto& params : allTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(
smoke_NormalizeL2_With_Hardcoded_Refs,
ReferenceNormalizeL2LayerTest,
::testing::ValuesIn(generateCombinedParamsForNormalizeL2()),
ReferenceNormalizeL2LayerTest::getTestCaseName);
} // namespace

View File

@@ -0,0 +1,118 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "base_reference_test.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/parameter.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct ParameterParams {
template <class T>
ParameterParams(const Shape& input_shape,
const Shape& expected_shape,
const element::Type& input_type,
const element::Type& expected_type,
const std::vector<T>& input_value,
const std::vector<T>& expected_value)
: m_input_shape(input_shape),
m_expected_shape(expected_shape),
m_input_type(input_type),
m_expected_type(expected_type),
m_input_value(CreateTensor(input_type, input_value)),
m_expected_value(CreateTensor(expected_type, expected_value)) {}
Shape m_input_shape;
Shape m_expected_shape;
element::Type m_input_type;
element::Type m_expected_type;
runtime::Tensor m_input_value;
runtime::Tensor m_expected_value;
};
class ReferenceParameterLayerTest : public testing::TestWithParam<ParameterParams>, public CommonReferenceTest {
public:
void SetUp() override {
const auto params = GetParam();
function = CreateFunction(params.m_input_shape, params.m_input_type);
inputData = {params.m_input_value};
refOutData = {params.m_expected_value};
}
static std::string getTestCaseName(const testing::TestParamInfo<ParameterParams>& obj) {
const auto param = obj.param;
std::ostringstream result;
result << "input_shape=" << param.m_input_shape << "; ";
result << "output_shape=" << param.m_expected_shape << "; ";
result << "input_type=" << param.m_input_type << "; ";
result << "output_type=" << param.m_expected_type;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& input_shape, const element::Type_t& input_type) {
auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
return std::make_shared<ov::Function>(in, ParameterVector{in});
}
};
TEST_P(ReferenceParameterLayerTest, CompareWithHardcodedRefs) {
Exec();
}
template <element::Type_t ET>
std::vector<ParameterParams> generateParamsForParameter() {
using T = typename element_type_traits<ET>::value_type;
std::vector<ParameterParams> params{
ParameterParams(Shape{3, 4},
Shape{3, 4},
ET,
ET,
std::vector<T>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
std::vector<T>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11})
};
return params;
}
std::vector<ParameterParams> generateCombinedParamsForParameter() {
const std::vector<std::vector<ParameterParams>> allTypeParams{
generateParamsForParameter<element::Type_t::boolean>(),
generateParamsForParameter<element::Type_t::f32>(),
generateParamsForParameter<element::Type_t::f16>(),
generateParamsForParameter<element::Type_t::bf16>(),
generateParamsForParameter<element::Type_t::i64>(),
generateParamsForParameter<element::Type_t::i32>(),
generateParamsForParameter<element::Type_t::i16>(),
generateParamsForParameter<element::Type_t::i8>(),
generateParamsForParameter<element::Type_t::u64>(),
generateParamsForParameter<element::Type_t::u32>(),
generateParamsForParameter<element::Type_t::u16>(),
generateParamsForParameter<element::Type_t::u8>()
};
std::vector<ParameterParams> combinedParams;
for (const auto& params : allTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(
smoke_Parameter_With_Hardcoded_Refs,
ReferenceParameterLayerTest,
::testing::ValuesIn(generateCombinedParamsForParameter()),
ReferenceParameterLayerTest::getTestCaseName);
} // namespace

View File

@@ -0,0 +1,119 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <gtest/gtest.h>
#include "base_reference_test.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/result.hpp"
using namespace reference_tests;
using namespace ov;
namespace {
struct ResultParams {
template <class T>
ResultParams(const Shape& input_shape,
const Shape& expected_shape,
const element::Type& input_type,
const element::Type& expected_type,
const std::vector<T>& input_value,
const std::vector<T>& expected_value)
: m_input_shape(input_shape),
m_expected_shape(expected_shape),
m_input_type(input_type),
m_expected_type(expected_type),
m_input_value(CreateTensor(input_type, input_value)),
m_expected_value(CreateTensor(expected_type, expected_value)) {}
Shape m_input_shape;
Shape m_expected_shape;
element::Type m_input_type;
element::Type m_expected_type;
runtime::Tensor m_input_value;
runtime::Tensor m_expected_value;
};
class ReferenceResultLayerTest : public testing::TestWithParam<ResultParams>, public CommonReferenceTest {
public:
void SetUp() override {
const auto params = GetParam();
function = CreateFunction(params.m_input_shape, params.m_input_type);
inputData = {params.m_input_value};
refOutData = {params.m_expected_value};
}
static std::string getTestCaseName(const testing::TestParamInfo<ResultParams>& obj) {
const auto param = obj.param;
std::ostringstream result;
result << "input_shape=" << param.m_input_shape << "; ";
result << "output_shape=" << param.m_expected_shape << "; ";
result << "input_type=" << param.m_input_type << "; ";
result << "output_type=" << param.m_expected_type;
return result.str();
}
private:
static std::shared_ptr<Function> CreateFunction(const Shape& input_shape, const element::Type_t& input_type) {
auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
auto result = std::make_shared<op::v0::Result>(in);
return std::make_shared<ov::Function>(result, ParameterVector{in});
}
};
TEST_P(ReferenceResultLayerTest, CompareWithHardcodedRefs) {
Exec();
}
template <element::Type_t ET>
std::vector<ResultParams> generateParamsForResult() {
using T = typename element_type_traits<ET>::value_type;
std::vector<ResultParams> params{
ResultParams(Shape{2, 2},
Shape{2, 2},
ET,
ET,
std::vector<T>{1, 2, 3, 5},
std::vector<T>{1, 2, 3, 5})
};
return params;
}
std::vector<ResultParams> generateCombinedParamsForResult() {
const std::vector<std::vector<ResultParams>> allTypeParams{
generateParamsForResult<element::Type_t::boolean>(),
generateParamsForResult<element::Type_t::f32>(),
generateParamsForResult<element::Type_t::f16>(),
generateParamsForResult<element::Type_t::bf16>(),
generateParamsForResult<element::Type_t::i64>(),
generateParamsForResult<element::Type_t::i32>(),
generateParamsForResult<element::Type_t::i16>(),
generateParamsForResult<element::Type_t::i8>(),
generateParamsForResult<element::Type_t::u64>(),
generateParamsForResult<element::Type_t::u32>(),
generateParamsForResult<element::Type_t::u16>(),
generateParamsForResult<element::Type_t::u8>()
};
std::vector<ResultParams> combinedParams;
for (const auto& params : allTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(
smoke_Result_With_Hardcoded_Refs,
ReferenceResultLayerTest,
::testing::ValuesIn(generateCombinedParamsForResult()),
ReferenceResultLayerTest::getTestCaseName);
} // namespace

View File

@@ -459,7 +459,6 @@ set(MULTI_TEST_SRC
backend/aliased_output.in.cpp
backend/api.in.cpp
backend/auto_broadcast.in.cpp
backend/batch_norm.in.cpp
backend/batch_to_space.in.cpp
backend/broadcast.in.cpp
backend/builder_reduce_ops_opset1.in.cpp
@@ -482,17 +481,14 @@ set(MULTI_TEST_SRC
backend/gather_elements.in.cpp
backend/gather_nd.in.cpp
backend/interpolate.in.cpp
backend/lrn.in.cpp
backend/matrix_nms.in.cpp
backend/multiclass_nms.in.cpp
backend/multiple_backends.in.cpp
backend/multiple_result.in.cpp
backend/node_name.in.cpp
backend/normalize_l2.in.cpp
backend/non_max_suppression.in.cpp
backend/one_hot.in.cpp
backend/pad.in.cpp
backend/parameter_as_output.in.cpp
backend/prior_box_clustered.in.cpp
backend/prior_box.in.cpp
backend/proposal.in.cpp
@@ -500,7 +496,6 @@ set(MULTI_TEST_SRC
backend/recurrent_cells.in.cpp
backend/region_yolo.in.cpp
backend/reorg_yolo.in.cpp
backend/result.in.cpp
backend/roll.in.cpp
backend/space_to_depth.in.cpp
backend/shuffle_channels.in.cpp

View File

@@ -1,114 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
template <typename T>
struct BatchNormTestParams {
std::vector<T> in;
Shape in_shape;
std::vector<T> in_g;
std::vector<T> in_b;
std::vector<T> in_m;
std::vector<T> in_v;
float epsilon;
std::vector<T> out;
};
template <typename T>
static void BatchNormInferenceTest(const BatchNormTestParams<T>& p) {
const Shape ch_shape{p.in_shape.at(1)};
auto input = make_shared<op::Parameter>(element::from<T>(), p.in_shape);
auto gamma = make_shared<op::Parameter>(element::from<T>(), ch_shape);
auto beta = make_shared<op::Parameter>(element::from<T>(), ch_shape);
auto mean = make_shared<op::Parameter>(element::from<T>(), ch_shape);
auto variance = make_shared<op::Parameter>(element::from<T>(), ch_shape);
auto batch_norm = make_shared<op::v5::BatchNormInference>(input, gamma, beta, mean, variance, p.epsilon);
auto f = make_shared<Function>(batch_norm, ParameterVector{input, gamma, beta, mean, variance});
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<T>(p.in_shape, p.in);
test_case.add_input<T>(ch_shape, p.in_g);
test_case.add_input<T>(ch_shape, p.in_b);
test_case.add_input<T>(ch_shape, p.in_m);
test_case.add_input<T>(ch_shape, p.in_v);
test_case.add_expected_output<T>(p.in_shape, p.out);
test_case.run_with_tolerance_as_fp(1e-4f);
}
NGRAPH_TEST(${BACKEND_NAME}, batch_norm_inference_2d_f32) {
const std::vector<BatchNormTestParams<float>> batch_norm_tests{
BatchNormTestParams<float>{{1.0, 2.0, 3.0, -1.0, -2.0, -3.0},
Shape{2, 3},
{2.0, 3.0, 4.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{0.75, 0.75, 0.75},
0.25,
{2.0, 6.0, 12.0, -2.0, -6.0, -12.0}},
BatchNormTestParams<float>{{1.0, 2.0, 3.0, -1.0, -2.0, -3.0},
Shape{2, 3},
{1.0, 1.0, 1.0},
{2.0, -2.0, 3.0},
{0.0, 0.0, 0.0},
{0.75, 0.75, 0.75},
0.25,
{3.0, 0.0, 6.0, 1.0, -4.0, 0.0}},
BatchNormTestParams<float>{{1.0, 2.0, 3.0, -1.0, -2.0, -3.0},
Shape{2, 3},
{1.0, 1.0, 1.0},
{0.0, 0.0, 0.0},
{-2.0, 2.0, -3.0},
{0.75, 0.75, 0.75},
0.25,
{3.0, 0.0, 6.0, 1.0, -4.0, 0.0}},
BatchNormTestParams<float>{{3.0, 5.0, 1.0, -3.0, -5.0, -1.0},
Shape{2, 3},
{1.0, 1.0, 1.0},
{0.0, 0.0, 0.0},
{0.0, 0.0, 0.0},
{2.0, 6.0, 0.0},
0.25,
{2.0, 2.0, 2.0, -2.0, -2.0, -2.0}},
};
for (const auto& test_case : batch_norm_tests) {
BatchNormInferenceTest(test_case);
}
}
NGRAPH_TEST(${BACKEND_NAME}, batch_norm_inference_4d_f32) {
float eps = 0.001;
Shape in_shape{2, 2, 2, 1};
std::vector<float>
in{0.54881352f, 0.71518934f, 0.60276335f, 0.54488319f, 0.42365479f, 0.64589411f, 0.4375872f, 0.89177299f};
std::vector<std::vector<float>> ch_in_1{{1.0, 1.0}, {1.0, 1.0}, {1.0, 1.0}, {1.0, 1.0}};
std::vector<float>
out_1{0.54903894f, 0.71533161f, 0.60296183f, 0.54511058f, 0.42394274f, 0.64607101f, 0.43786817f, 0.89182704f};
std::vector<std::vector<float>> ch_in_2{{1.0, 1.0}, {0.0f, 0.0f}, {0.583388f, 0.619252f}, {0.0119972f, 0.0282681f}};
std::vector<float> out_2{-0.30327f, 1.1561f, -0.096382f, -0.434702f, -1.4011f, 0.548275f, -1.06187f, 1.59295f};
const std::vector<BatchNormTestParams<float>> batch_norm_tests{
BatchNormTestParams<float>{in, in_shape, ch_in_1[0], ch_in_1[1], ch_in_1[2], ch_in_1[3], eps, out_1},
BatchNormTestParams<float>{in, in_shape, ch_in_2[0], ch_in_2[1], ch_in_2[2], ch_in_2[3], eps, out_2}};
for (const auto& test_case : batch_norm_tests) {
BatchNormInferenceTest(test_case);
}
}

View File

@@ -1,317 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
// clang-format off
#ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
#endif
#ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
#endif
// clang-format on
#include <numeric>
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "engines_util/test_engines.hpp"
#include "engines_util/test_case.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_channel) {
Shape shape{2, 3, 2, 1};
auto A = make_shared<op::Parameter>(element::f32, shape);
double alpha = 3;
double beta = 0.5;
double bias = 1;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0000000f,
0.3015113f,
0.4364358f,
0.5000000f,
0.8728716f,
0.8451542f,
0.5970223f,
0.6115928f,
0.5642765f,
0.5669467f,
0.7784989f,
0.7720487f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_h) {
Shape shape{2, 3, 2, 1};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto axes = make_shared<op::Constant>(element::i64, Shape{1}, vector<int64_t>{2});
double alpha = 3;
double beta = 0.5;
double bias = 1;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0000000f,
0.7071068f,
0.5345225f,
0.8017837f,
0.6172134f,
0.7715167f,
0.6469966f,
0.7548294f,
0.6620847f,
0.7448453f,
0.6711560f,
0.7382717f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_hw) {
Shape shape{2, 3, 2, 1};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto axes = make_shared<op::Constant>(element::i64, Shape{2}, vector<int64_t>{2, 3});
double alpha = 3;
double beta = 0.5;
double bias = 1;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0000000f,
0.8660254f,
0.8660254f,
1.2990381f,
1.0444659f,
1.3055824f,
1.1078234f,
1.2924607f,
1.1389896f,
1.2813632f,
1.1572751f,
1.2730026f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_all_dims) {
Shape shape{2, 3, 2, 1};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto axes = make_shared<op::Constant>(element::i64, Shape{4}, vector<int64_t>{0, 1, 2, 3});
double alpha = 3;
double beta = 0.5;
double bias = 1;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0000000f,
0.3156438f,
0.4501407f,
0.6752110f,
0.9830783f,
1.2288479f,
1.8938627f,
2.2095065f,
1.8005627f,
2.0256331f,
2.4576957f,
2.7034652f});
test_case.run(DEFAULT_FLOAT_TOLERANCE_BITS + 1);
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_nw) {
Shape shape{2, 3, 2, 1};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto axes = make_shared<op::Constant>(element::i64, Shape{2}, vector<int64_t>{0, 3});
double alpha = 3;
double beta = 0.5;
double bias = 1;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0000000f,
0.2379155f,
0.4111132f,
0.5388159f,
0.6351073f,
0.7094756f,
1.6641006f,
1.6654084f,
1.6444529f,
1.6164477f,
1.5877683f,
1.5608464f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_across_empty) {
Shape shape{2, 3, 2, 1};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto axes = make_shared<op::Constant>(element::i64, Shape{0}, vector<int64_t>{});
double alpha = 3;
double beta = 0.5;
double bias = 1;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0000000f,
0.5000000f,
0.5547002f,
0.5669467f,
0.5714286f,
0.5735393f,
0.5746958f,
0.5753965f,
0.5758526f,
0.5761660f,
0.5763904f,
0.5765567f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_6D_across_2_axes) {
Shape shape{2, 3, 2, 2, 1, 1};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto axes = make_shared<op::Constant>(element::i64, Shape{2}, vector<int64_t>{2, 3});
double alpha = 3;
double beta = 0.5;
double bias = 1;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
std::vector<float> a(24);
std::iota(std::begin(a), std::end(a), 0);
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(
shape,
{0.0000000f, 0.4200840f, 0.8401681f, 1.2602521f, 0.6099943f, 0.7624928f, 0.9149914f, 1.0674900f,
0.7213357f, 0.8115027f, 0.9016696f, 0.9918366f, 0.7656109f, 0.8294119f, 0.8932127f, 0.9570137f,
0.7892218f, 0.8385482f, 0.8878745f, 0.9372009f, 0.8038679f, 0.8440613f, 0.8842546f, 0.9244481f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_2d_across_empty) {
Shape shape{12};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto axes = make_shared<op::Constant>(element::i64, Shape{0}, vector<int64_t>{});
double alpha = 3;
double beta = 0.5;
double bias = 1;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
std::vector<float> a{0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.0000000f,
0.5000000f,
0.5547002f,
0.5669467f,
0.5714286f,
0.5735393f,
0.5746958f,
0.5753964f,
0.5758526f,
0.5761660f,
0.5763904f,
0.5765566f});
test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, lrn_2d_across_outermost_axis) {
Shape shape{6, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto axes = make_shared<op::Constant>(element::i64, Shape{1}, vector<int64_t>{0});
double alpha = 0.0002;
double beta = 0.5;
double bias = 2.0;
size_t size = 3;
auto lrn = make_shared<op::LRN>(A, axes, alpha, beta, bias, size);
auto f = make_shared<Function>(lrn, ParameterVector{A});
std::vector<float> a{0.64915806f,
0.21213771f,
-1.48256505f,
-1.41040838f,
0.58189541f,
0.11432108f,
-0.22993855f,
-0.13325502f,
-0.03083259f,
-0.48450908f,
0.50342429f,
-0.99551708f};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(shape, a);
test_case.add_expected_output<float>(shape,
{0.4590040f,
0.1499989f,
-1.0482801f,
-0.9972753f,
0.4114444f,
0.0808345f,
-0.1625900f,
-0.0942251f,
-0.0218018f,
-0.3425926f,
0.3559732f,
-0.7039225f});
test_case.run(23);
}

View File

@@ -1,809 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <algorithm>
#include <cinttypes>
#include <cmath>
#include <cstdlib>
#include <numeric>
#include <random>
#include <string>
#include "engines_util/execute_tools.hpp"
#include "engines_util/random.hpp"
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
static void normalize_l2_results_test(std::vector<float>& data,
Shape& data_shape,
std::vector<int32_t>& axes,
ngraph::op::EpsMode eps_mode,
float eps,
std::vector<float>& expected_output) {
auto data_input = std::make_shared<op::Parameter>(element::f32, data_shape);
const auto axes_input = std::make_shared<op::Constant>(element::i32, Shape{axes.size()}, axes);
auto normalize = std::make_shared<op::v0::NormalizeL2>(data_input, axes_input, eps, eps_mode);
auto function = std::make_shared<Function>(normalize, ParameterVector{data_input});
auto test_case = test::TestCase<TestEngine>(function);
test_case.add_input<float>(data);
test_case.add_expected_output<float>(data_shape, expected_output);
test_case.run(DEFAULT_FLOAT_TOLERANCE_BITS + 4);
}
// 1D
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_1D_axes_empty_add) {
std::vector<float> data{0, 3, 0, 8};
Shape data_shape{4};
std::vector<int32_t> axes{};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0, 1, 0, 1};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_1D_axes_empty_max) {
std::vector<float> data{0, 3, 0, 8};
Shape data_shape{4};
std::vector<int32_t> axes{};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{0, 1, 0, 1};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_1D_axes_0_add) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{4};
std::vector<int32_t> axes{0};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0.18257418, 0.36514837, 0.5477226, 0.73029673};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_1D_axes_0_max) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{4};
std::vector<int32_t> axes{0};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{0.18257418, 0.36514837, 0.5477226, 0.73029673};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
// 2D
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_2D_axes_empty_add) {
std::vector<float> data{0, 3, 0, 8};
Shape data_shape{2, 2};
std::vector<int32_t> axes{};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0, 1, 0, 1};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_2D_axes_empty_max) {
std::vector<float> data{0, 3, 0, 8};
Shape data_shape{2, 2};
std::vector<int32_t> axes{};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{0, 1, 0, 1};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_2D_axes_0_add) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{2, 2};
std::vector<int32_t> axes{0};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0.31622776, 0.4472136, 0.94868326, 0.8944272};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_2D_axes_0_max) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{2, 2};
std::vector<int32_t> axes{0};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{0.31622777, 0.4472136, 0.9486833, 0.89442719};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_2D_axes_1_add) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{2, 2};
std::vector<int32_t> axes{1};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0.4472136, 0.8944272, 0.6, 0.8};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_2D_axes_1_max) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{2, 2};
std::vector<int32_t> axes{1};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{0.4472136, 0.89442719, 0.6, 0.8};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_2D_axes_01_add) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{2, 2};
std::vector<int32_t> axes{0, 1};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0.18257418, 0.36514837, 0.5477226, 0.73029673};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_2D_axes_01_max) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{2, 2};
std::vector<int32_t> axes{0, 1};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{0.18257419, 0.36514837, 0.54772256, 0.73029674};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
// 3D
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_3D_axes_1_add) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{1, 2, 2};
std::vector<int32_t> axes{1};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0.31622776, 0.4472136, 0.94868326, 0.8944272};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_3D_axes_1_max) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{1, 2, 2};
std::vector<int32_t> axes{1};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{0.31622776, 0.4472136, 0.94868326, 0.8944272};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_3D_axes_2_add) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{1, 2, 2};
std::vector<int32_t> axes{2};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0.4472136, 0.8944272, 0.6, 0.8};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_3D_axes_2_max) {
std::vector<float> data{1, 2, 3, 4};
Shape data_shape{1, 2, 2};
std::vector<int32_t> axes{2};
float eps = 1e-7;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{0.4472136, 0.8944272, 0.6, 0.8};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
// 4D
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_empty_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 1);
std::vector<int32_t> axes{};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output(shape_size(data_shape), 1);
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_empty_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 1);
std::vector<int32_t> axes{};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output(shape_size(data_shape), 1);
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_0_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{0};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.03996804, 0.07669649, 0.11043153, 0.14142135, 0.1699069, 0.19611612, 0.22026087,
0.2425356, 0.26311737, 0.2821663, 0.2998266, 0.31622776, 0.331486, 0.34570533, 0.35897905,
0.37139067, 0.38301498, 0.3939193, 0.40416384, 0.41380292, 0.42288542, 0.43145543, 0.43955287,
0.99999994, 0.9992009, 0.9970544, 0.9938838, 0.98994946, 0.98546, 0.9805806, 0.97544104,
0.9701424, 0.96476364, 0.9593654, 0.95399374, 0.9486833, 0.9434601, 0.93834305, 0.93334556,
0.9284767, 0.923742, 0.919145, 0.91468656, 0.9103665, 0.90618306, 0.90213406, 0.8982167};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_0_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{0};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0, 0.0399648, 0.0766909, 0.110424, 0.141413, 0.169897, 0.196106, 0.22025,
0.242524, 0.263106, 0.282155, 0.299815, 0.316217, 0.331475, 0.345695, 0.358969,
0.371381, 0.383005, 0.39391, 0.404155, 0.413794, 0.422877, 0.431447, 0.439545,
0.999913, 0.999121, 0.996981, 0.993816, 0.989888, 0.985403, 0.980528, 0.975393,
0.970098, 0.964723, 0.959327, 0.953958, 0.94865, 0.94343, 0.938315, 0.933319,
0.928452, 0.923719, 0.919123, 0.914666, 0.910347, 0.906165, 0.902117, 0.8982};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_1_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{1};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.07669649, 0.14142135, 0.19611612, 0.2425356, 0.2821663, 0.31622776, 0.34570533,
0.37139067, 0.3939193, 0.41380292, 0.43145543, 0.99999994, 0.9970544, 0.98994946, 0.9805806,
0.9701424, 0.9593654, 0.9486833, 0.93834305, 0.9284767, 0.919145, 0.9103665, 0.90213406,
0.5547002, 0.55985737, 0.56468385, 0.5692099, 0.57346237, 0.57746464, 0.58123815, 0.5848015,
0.58817166, 0.59136367, 0.59439105, 0.5972662, 0.83205026, 0.82858896, 0.8253072, 0.8221921,
0.8192319, 0.81641555, 0.8137334, 0.8111763, 0.808736, 0.80640495, 0.8041761, 0.8020432};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_1_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{1};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{
0., 0.07667395, 0.14138602, 0.19607423, 0.24249104, 0.28212142, 0.31618387, 0.3456632,
0.37135068, 0.3938816, 0.41376755, 0.43142232, 0.9996529, 0.9967614, 0.9897021, 0.9803712,
0.96996415, 0.9592128, 0.94855154, 0.93822867, 0.9283767, 0.9190571, 0.9102886, 0.9020648,
0.5546854, 0.55984336, 0.56467056, 0.56919736, 0.5734503, 0.57745326, 0.58122724, 0.5847912,
0.58816177, 0.59135413, 0.594382, 0.59725744, 0.8320281, 0.8285682, 0.82528776, 0.82217395,
0.8192147, 0.8163994, 0.8137182, 0.81116194, 0.8087224, 0.806392, 0.8041638, 0.8020314};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_2_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{2};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.09667365, 0.16903085, 0.22423053, 0.4472136, 0.48336822, 0.50709254, 0.52320457,
0.8944272, 0.8700628, 0.8451542, 0.8221786, 0.42426404, 0.4335743, 0.4418361, 0.4492145,
0.5656854, 0.5669818, 0.56807494, 0.569005, 0.7071067, 0.70038927, 0.6943139, 0.68879557,
0.49153918, 0.4945891, 0.49743116, 0.5000857, 0.57346237, 0.5737234, 0.57395905, 0.5741725,
0.65538555, 0.6528576, 0.6504869, 0.6482592, 0.51789176, 0.5193782, 0.52079225, 0.5221394,
0.5754353, 0.5755272, 0.57561255, 0.5756921, 0.63297886, 0.6316762, 0.6304327, 0.62924486};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_2_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{2};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0, 0.0966285, 0.168971, 0.224168, 0.446934, 0.483143, 0.506912, 0.523058,
0.893869, 0.869657, 0.844853, 0.821949, 0.424238, 0.43355, 0.441814, 0.449194,
0.56565, 0.56695, 0.568047, 0.56898, 0.707063, 0.70035, 0.694279, 0.688765,
0.491529, 0.494579, 0.497422, 0.500077, 0.57345, 0.573712, 0.573949, 0.574163,
0.655372, 0.652845, 0.650475, 0.648248, 0.517886, 0.519373, 0.520787, 0.522135,
0.575429, 0.575521, 0.575607, 0.575687, 0.632972, 0.63167, 0.630427, 0.629239};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_3_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{3};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.26726124, 0.5345225, 0.8017837, 0.3563483, 0.44543537, 0.5345225, 0.62360954,
0.41816667, 0.4704375, 0.52270836, 0.5749792, 0.44292808, 0.47983873, 0.5167494, 0.5536601,
0.45621273, 0.484726, 0.5132393, 0.54175264, 0.4644887, 0.4877131, 0.5109376, 0.534162,
0.47013652, 0.48972553, 0.50931454, 0.5289036, 0.47423577, 0.49117276, 0.50810975, 0.5250467,
0.47734618, 0.49226326, 0.50718033, 0.5220974, 0.4797868, 0.49311423, 0.50644165, 0.5197691,
0.48175293, 0.49379677, 0.5058406, 0.51788443, 0.48337057, 0.49435627, 0.50534195, 0.5163277};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_3_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{3};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0, 0.266312, 0.532624, 0.798935, 0.356207, 0.445259, 0.534311, 0.623362,
0.41811, 0.470373, 0.522637, 0.574901, 0.442898, 0.479806, 0.516714, 0.553622,
0.456194, 0.484706, 0.513219, 0.541731, 0.464476, 0.4877, 0.510924, 0.534148,
0.470128, 0.489716, 0.509305, 0.528893, 0.474229, 0.491166, 0.508102, 0.525039,
0.477341, 0.492258, 0.507175, 0.522092, 0.479783, 0.49311, 0.506437, 0.519764,
0.481749, 0.493793, 0.505837, 0.517881, 0.483368, 0.494353, 0.505339, 0.516325};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_23_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{2, 3};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.04445542, 0.08891085, 0.13336627, 0.1778217, 0.22227712, 0.26673254, 0.31118798,
0.3556434, 0.4000988, 0.44455424, 0.48900968, 0.19420628, 0.21039014, 0.226574, 0.24275786,
0.2589417, 0.27512556, 0.29130942, 0.30749327, 0.32367712, 0.339861, 0.35604486, 0.3722287,
0.23326269, 0.24298197, 0.25270125, 0.26242054, 0.2721398, 0.28185907, 0.29157835, 0.30129763,
0.31101692, 0.3207362, 0.33045548, 0.34017476, 0.24955511, 0.2564872, 0.26341927, 0.27035138,
0.27728346, 0.28421554, 0.29114762, 0.2980797, 0.3050118, 0.3119439, 0.31887597, 0.32580805};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_23_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{2, 3};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{
0., 0.04445103, 0.08890206, 0.1333531, 0.17780413, 0.22225516, 0.2667062, 0.31115723,
0.35560825, 0.40005928, 0.4445103, 0.48896134, 0.19420375, 0.2103874, 0.22657104, 0.24275468,
0.2589383, 0.275122, 0.29130563, 0.30748928, 0.32367292, 0.33985656, 0.3560402, 0.37222385,
0.2332616, 0.24298084, 0.25270006, 0.2624193, 0.27213854, 0.2818578, 0.291577, 0.30129623,
0.3110155, 0.3207347, 0.33045393, 0.34017318, 0.2495545, 0.25648656, 0.26341864, 0.27035072,
0.27728277, 0.28421485, 0.29114693, 0.29807898, 0.30501106, 0.3119431, 0.3188752, 0.32580727};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_123_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{1, 2, 3};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.01520748, 0.03041495, 0.04562243, 0.06082991, 0.07603738, 0.09124486, 0.10645234,
0.12165982, 0.13686728, 0.15207477, 0.16728225, 0.18248972, 0.19769719, 0.21290468, 0.22811216,
0.24331963, 0.2585271, 0.27373457, 0.28894207, 0.30414954, 0.319357, 0.3345645, 0.34977198,
0.13544846, 0.14109215, 0.14673583, 0.15237951, 0.15802321, 0.16366689, 0.16931057, 0.17495427,
0.18059795, 0.18624163, 0.19188532, 0.197529, 0.20317268, 0.20881638, 0.21446006, 0.22010374,
0.22574744, 0.23139112, 0.2370348, 0.2426785, 0.24832217, 0.25396585, 0.25960955, 0.26525325};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_123_big_eps_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{1, 2, 3};
float eps = 100;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.01520748, 0.03041495, 0.04562243, 0.06082991, 0.07603738, 0.09124486, 0.10645234,
0.12165982, 0.13686728, 0.15207477, 0.16728225, 0.18248972, 0.19769719, 0.21290468, 0.22811216,
0.24331963, 0.2585271, 0.27373457, 0.28894207, 0.30414954, 0.319357, 0.3345645, 0.34977198,
0.13544846, 0.14109215, 0.14673583, 0.15237951, 0.15802321, 0.16366689, 0.16931057, 0.17495427,
0.18059795, 0.18624163, 0.19188532, 0.197529, 0.20317268, 0.20881638, 0.21446006, 0.22010374,
0.22574744, 0.23139112, 0.2370348, 0.2426785, 0.24832217, 0.25396585, 0.25960955, 0.26525325};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_123_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{1, 2, 3};
float eps = 1e-9;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{
0, 0.0152075, 0.030415, 0.0456224, 0.0608299, 0.0760374, 0.0912449, 0.106452, 0.12166, 0.136867,
0.152075, 0.167282, 0.18249, 0.197697, 0.212905, 0.228112, 0.24332, 0.258527, 0.273735, 0.288942,
0.30415, 0.319357, 0.334565, 0.349772, 0.135448, 0.141092, 0.146736, 0.15238, 0.158023, 0.163667,
0.169311, 0.174954, 0.180598, 0.186242, 0.191885, 0.197529, 0.203173, 0.208816, 0.21446, 0.220104,
0.225747, 0.231391, 0.237035, 0.242678, 0.248322, 0.253966, 0.25961, 0.265253};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_123_big_eps_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{1, 2, 3};
float eps = 0.5;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{
0, 0.0152066, 0.0304132, 0.0456198, 0.0608264, 0.076033, 0.0912396, 0.106446, 0.121653, 0.136859,
0.152066, 0.167273, 0.182479, 0.197686, 0.212892, 0.228099, 0.243306, 0.258512, 0.273719, 0.288925,
0.304132, 0.319339, 0.334545, 0.349752, 0.135447, 0.141091, 0.146735, 0.152378, 0.158022, 0.163666,
0.169309, 0.174953, 0.180597, 0.18624, 0.191884, 0.197527, 0.203171, 0.208815, 0.214458, 0.220102,
0.225746, 0.231389, 0.237033, 0.242677, 0.24832, 0.253964, 0.259607, 0.265251};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_unsorted_312_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{3, 1, 2};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.01520748, 0.03041495, 0.04562243, 0.06082991, 0.07603738, 0.09124486, 0.10645234,
0.12165982, 0.13686728, 0.15207477, 0.16728225, 0.18248972, 0.19769719, 0.21290468, 0.22811216,
0.24331963, 0.2585271, 0.27373457, 0.28894207, 0.30414954, 0.319357, 0.3345645, 0.34977198,
0.13544846, 0.14109215, 0.14673583, 0.15237951, 0.15802321, 0.16366689, 0.16931057, 0.17495427,
0.18059795, 0.18624163, 0.19188532, 0.197529, 0.20317268, 0.20881638, 0.21446006, 0.22010374,
0.22574744, 0.23139112, 0.2370348, 0.2426785, 0.24832217, 0.25396585, 0.25960955, 0.26525325};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_unsorted_312_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{3, 1, 2};
float eps = 1e-9;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{
0, 0.0152075, 0.030415, 0.0456224, 0.0608299, 0.0760374, 0.0912449, 0.106452, 0.12166, 0.136867,
0.152075, 0.167282, 0.18249, 0.197697, 0.212905, 0.228112, 0.24332, 0.258527, 0.273735, 0.288942,
0.30415, 0.319357, 0.334565, 0.349772, 0.135448, 0.141092, 0.146736, 0.15238, 0.158023, 0.163667,
0.169311, 0.174954, 0.180598, 0.186242, 0.191885, 0.197529, 0.203173, 0.208816, 0.21446, 0.220104,
0.225747, 0.231391, 0.237035, 0.242678, 0.248322, 0.253966, 0.25961, 0.265253};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_0123_max) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{0, 1, 2, 3};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.00529108, 0.01058216, 0.01587324, 0.02116432, 0.02645539, 0.03174648, 0.03703756,
0.04232863, 0.04761971, 0.05291079, 0.05820187, 0.06349295, 0.06878403, 0.07407511, 0.07936618,
0.08465727, 0.08994835, 0.09523942, 0.10053051, 0.10582158, 0.11111266, 0.11640374, 0.12169482,
0.12698591, 0.13227698, 0.13756806, 0.14285913, 0.14815022, 0.1534413, 0.15873237, 0.16402346,
0.16931453, 0.17460561, 0.1798967, 0.18518777, 0.19047885, 0.19576994, 0.20106101, 0.20635208,
0.21164316, 0.21693425, 0.22222532, 0.2275164, 0.23280749, 0.23809856, 0.24338964, 0.24868073};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_4D_axes_0123_add) {
Shape data_shape{2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{0, 1, 2, 3};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{
0., 0.00529108, 0.01058216, 0.01587324, 0.02116432, 0.02645539, 0.03174648, 0.03703756,
0.04232863, 0.04761971, 0.05291079, 0.05820187, 0.06349295, 0.06878403, 0.07407511, 0.07936618,
0.08465727, 0.08994835, 0.09523942, 0.10053051, 0.10582158, 0.11111266, 0.11640374, 0.12169482,
0.12698591, 0.13227698, 0.13756806, 0.14285913, 0.14815022, 0.1534413, 0.15873237, 0.16402346,
0.16931453, 0.17460561, 0.1798967, 0.18518777, 0.19047885, 0.19576994, 0.20106101, 0.20635208,
0.21164316, 0.21693425, 0.22222532, 0.2275164, 0.23280749, 0.23809856, 0.24338964, 0.24868073};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_empty_max) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 1);
std::vector<int32_t> axes{};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output(shape_size(data_shape), 1);
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_empty_add) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 1);
std::vector<int32_t> axes{};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output(shape_size(data_shape), 1);
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_1_max) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{1};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.03996804, 0.07669649, 0.11043153, 0.14142135, 0.1699069, 0.19611612, 0.22026087,
0.2425356, 0.26311737, 0.2821663, 0.2998266, 0.31622776, 0.331486, 0.34570533, 0.35897905,
0.37139067, 0.38301498, 0.3939193, 0.40416384, 0.41380292, 0.42288542, 0.43145543, 0.43955287,
0.99999994, 0.9992009, 0.9970544, 0.9938838, 0.98994946, 0.98546, 0.9805806, 0.97544104,
0.9701424, 0.96476364, 0.9593654, 0.95399374, 0.9486833, 0.9434601, 0.93834305, 0.93334556,
0.9284767, 0.923742, 0.919145, 0.91468656, 0.9103665, 0.90618306, 0.90213406, 0.8982167};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_1_add) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{1};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0, 0.0399648, 0.0766909, 0.110424, 0.141413, 0.169897, 0.196106, 0.22025,
0.242524, 0.263106, 0.282155, 0.299815, 0.316217, 0.331475, 0.345695, 0.358969,
0.371381, 0.383005, 0.39391, 0.404155, 0.413794, 0.422877, 0.431447, 0.439545,
0.999913, 0.999121, 0.996981, 0.993816, 0.989888, 0.985403, 0.980528, 0.975393,
0.970098, 0.964723, 0.959327, 0.953958, 0.94865, 0.94343, 0.938315, 0.933319,
0.928452, 0.923719, 0.919123, 0.914666, 0.910347, 0.906165, 0.902117, 0.8982};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_2_max) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{2};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.07669649, 0.14142135, 0.19611612, 0.2425356, 0.2821663, 0.31622776, 0.34570533,
0.37139067, 0.3939193, 0.41380292, 0.43145543, 0.99999994, 0.9970544, 0.98994946, 0.9805806,
0.9701424, 0.9593654, 0.9486833, 0.93834305, 0.9284767, 0.919145, 0.9103665, 0.90213406,
0.5547002, 0.55985737, 0.56468385, 0.5692099, 0.57346237, 0.57746464, 0.58123815, 0.5848015,
0.58817166, 0.59136367, 0.59439105, 0.5972662, 0.83205026, 0.82858896, 0.8253072, 0.8221921,
0.8192319, 0.81641555, 0.8137334, 0.8111763, 0.808736, 0.80640495, 0.8041761, 0.8020432};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_2_add) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{2};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{
0., 0.07667395, 0.14138602, 0.19607423, 0.24249104, 0.28212142, 0.31618387, 0.3456632,
0.37135068, 0.3938816, 0.41376755, 0.43142232, 0.9996529, 0.9967614, 0.9897021, 0.9803712,
0.96996415, 0.9592128, 0.94855154, 0.93822867, 0.9283767, 0.9190571, 0.9102886, 0.9020648,
0.5546854, 0.55984336, 0.56467056, 0.56919736, 0.5734503, 0.57745326, 0.58122724, 0.5847912,
0.58816177, 0.59135413, 0.594382, 0.59725744, 0.8320281, 0.8285682, 0.82528776, 0.82217395,
0.8192147, 0.8163994, 0.8137182, 0.81116194, 0.8087224, 0.806392, 0.8041638, 0.8020314};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_3_max) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{3};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.09667365, 0.16903085, 0.22423053, 0.4472136, 0.48336822, 0.50709254, 0.52320457,
0.8944272, 0.8700628, 0.8451542, 0.8221786, 0.42426404, 0.4335743, 0.4418361, 0.4492145,
0.5656854, 0.5669818, 0.56807494, 0.569005, 0.7071067, 0.70038927, 0.6943139, 0.68879557,
0.49153918, 0.4945891, 0.49743116, 0.5000857, 0.57346237, 0.5737234, 0.57395905, 0.5741725,
0.65538555, 0.6528576, 0.6504869, 0.6482592, 0.51789176, 0.5193782, 0.52079225, 0.5221394,
0.5754353, 0.5755272, 0.57561255, 0.5756921, 0.63297886, 0.6316762, 0.6304327, 0.62924486};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_3_add) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{3};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0, 0.0966285, 0.168971, 0.224168, 0.446934, 0.483143, 0.506912, 0.523058,
0.893869, 0.869657, 0.844853, 0.821949, 0.424238, 0.43355, 0.441814, 0.449194,
0.56565, 0.56695, 0.568047, 0.56898, 0.707063, 0.70035, 0.694279, 0.688765,
0.491529, 0.494579, 0.497422, 0.500077, 0.57345, 0.573712, 0.573949, 0.574163,
0.655372, 0.652845, 0.650475, 0.648248, 0.517886, 0.519373, 0.520787, 0.522135,
0.575429, 0.575521, 0.575607, 0.575687, 0.632972, 0.63167, 0.630427, 0.629239};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_4_max) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{4};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.26726124, 0.5345225, 0.8017837, 0.3563483, 0.44543537, 0.5345225, 0.62360954,
0.41816667, 0.4704375, 0.52270836, 0.5749792, 0.44292808, 0.47983873, 0.5167494, 0.5536601,
0.45621273, 0.484726, 0.5132393, 0.54175264, 0.4644887, 0.4877131, 0.5109376, 0.534162,
0.47013652, 0.48972553, 0.50931454, 0.5289036, 0.47423577, 0.49117276, 0.50810975, 0.5250467,
0.47734618, 0.49226326, 0.50718033, 0.5220974, 0.4797868, 0.49311423, 0.50644165, 0.5197691,
0.48175293, 0.49379677, 0.5058406, 0.51788443, 0.48337057, 0.49435627, 0.50534195, 0.5163277};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_4_add) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{4};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{0, 0.266312, 0.532624, 0.798935, 0.356207, 0.445259, 0.534311, 0.623362,
0.41811, 0.470373, 0.522637, 0.574901, 0.442898, 0.479806, 0.516714, 0.553622,
0.456194, 0.484706, 0.513219, 0.541731, 0.464476, 0.4877, 0.510924, 0.534148,
0.470128, 0.489716, 0.509305, 0.528893, 0.474229, 0.491166, 0.508102, 0.525039,
0.477341, 0.492258, 0.507175, 0.522092, 0.479783, 0.49311, 0.506437, 0.519764,
0.481749, 0.493793, 0.505837, 0.517881, 0.483368, 0.494353, 0.505339, 0.516325};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_34_max) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{3, 4};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.04445542, 0.08891085, 0.13336627, 0.1778217, 0.22227712, 0.26673254, 0.31118798,
0.3556434, 0.4000988, 0.44455424, 0.48900968, 0.19420628, 0.21039014, 0.226574, 0.24275786,
0.2589417, 0.27512556, 0.29130942, 0.30749327, 0.32367712, 0.339861, 0.35604486, 0.3722287,
0.23326269, 0.24298197, 0.25270125, 0.26242054, 0.2721398, 0.28185907, 0.29157835, 0.30129763,
0.31101692, 0.3207362, 0.33045548, 0.34017476, 0.24955511, 0.2564872, 0.26341927, 0.27035138,
0.27728346, 0.28421554, 0.29114762, 0.2980797, 0.3050118, 0.3119439, 0.31887597, 0.32580805};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_34_add) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{3, 4};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{
0., 0.04445103, 0.08890206, 0.1333531, 0.17780413, 0.22225516, 0.2667062, 0.31115723,
0.35560825, 0.40005928, 0.4445103, 0.48896134, 0.19420375, 0.2103874, 0.22657104, 0.24275468,
0.2589383, 0.275122, 0.29130563, 0.30748928, 0.32367292, 0.33985656, 0.3560402, 0.37222385,
0.2332616, 0.24298084, 0.25270006, 0.2624193, 0.27213854, 0.2818578, 0.291577, 0.30129623,
0.3110155, 0.3207347, 0.33045393, 0.34017318, 0.2495545, 0.25648656, 0.26341864, 0.27035072,
0.27728277, 0.28421485, 0.29114693, 0.29807898, 0.30501106, 0.3119431, 0.3188752, 0.32580727};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_234_max) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{2, 3, 4};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::MAX;
std::vector<float> expected_output{
0., 0.01520748, 0.03041495, 0.04562243, 0.06082991, 0.07603738, 0.09124486, 0.10645234,
0.12165982, 0.13686728, 0.15207477, 0.16728225, 0.18248972, 0.19769719, 0.21290468, 0.22811216,
0.24331963, 0.2585271, 0.27373457, 0.28894207, 0.30414954, 0.319357, 0.3345645, 0.34977198,
0.13544846, 0.14109215, 0.14673583, 0.15237951, 0.15802321, 0.16366689, 0.16931057, 0.17495427,
0.18059795, 0.18624163, 0.19188532, 0.197529, 0.20317268, 0.20881638, 0.21446006, 0.22010374,
0.22574744, 0.23139112, 0.2370348, 0.2426785, 0.24832217, 0.25396585, 0.25960955, 0.26525325};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}
NGRAPH_TEST(${BACKEND_NAME}, normalize_l2_5D_axes_234_add) {
Shape data_shape{1, 2, 2, 3, 4};
std::vector<float> data(shape_size(data_shape));
iota(begin(data), end(data), 0);
std::vector<int32_t> axes{2, 3, 4};
float eps = 0.1;
auto eps_mode = ngraph::op::EpsMode::ADD;
std::vector<float> expected_output{
0., 0.0152073, 0.0304146, 0.0456219, 0.0608292, 0.07603651, 0.0912438, 0.10645111,
0.12165841, 0.1368657, 0.15207301, 0.16728032, 0.1824876, 0.19769491, 0.21290222, 0.22810951,
0.24331681, 0.25852412, 0.2737314, 0.28893873, 0.30414602, 0.3193533, 0.33456063, 0.34976792,
0.13544825, 0.14109191, 0.1467356, 0.15237927, 0.15802296, 0.16366662, 0.1693103, 0.17495398,
0.18059766, 0.18624133, 0.19188501, 0.19752869, 0.20317237, 0.20881604, 0.21445972, 0.2201034,
0.22574706, 0.23139074, 0.23703443, 0.2426781, 0.24832177, 0.25396547, 0.25960913, 0.2652528};
normalize_l2_results_test(data, data_shape, axes, eps_mode, eps, expected_output);
}

View File

@@ -1,37 +0,0 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/execute_tools.hpp"
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/runtime/tensor.hpp"
#include "runtime/backend.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
#include "util/test_control.hpp"
using namespace std;
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
NGRAPH_TEST(${BACKEND_NAME}, parameter_as_output) {
Shape shape{3, 4};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(A, ParameterVector{A});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
shared_ptr<runtime::Tensor> a = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::Tensor> result = backend->create_tensor(element::f32, shape);
vector<float> expected{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
vector<float> zero(shape_size(shape), 0);
copy_data(a, expected);
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}

View File

@@ -1,27 +0,0 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "engines_util/test_case.hpp"
#include "engines_util/test_engines.hpp"
#include "gtest/gtest.h"
#include "ngraph/op/result.hpp"
#include "util/test_control.hpp"
using namespace ngraph;
static std::string s_manifest = "${MANIFEST}";
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, result) {
Shape shape_a{2, 2};
auto a = std::make_shared<op::Parameter>(element::f32, shape_a);
auto f = std::make_shared<Function>(std::make_shared<op::v0::Result>(a), ParameterVector{a});
std::vector<float> a_values{1, 2, 3, 5};
auto test_case = test::TestCase<TestEngine>(f);
test_case.add_input<float>(a_values);
test_case.add_expected_output<float>(shape_a, a_values);
test_case.run();
}