Migrate shape1,2 to template plugin test (#8200)
* Migrate shape1,2 to template plugin test * Fix member variables order
This commit is contained in:
parent
3ce0f2573a
commit
96af987c46
432
docs/template_plugin/tests/functional/op_reference/reshape.cpp
Normal file
432
docs/template_plugin/tests/functional/op_reference/reshape.cpp
Normal file
@ -0,0 +1,432 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/reshape.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
//using T1 = typename element_type_traits<IT>::value_type;
|
||||
namespace {
|
||||
|
||||
struct ReshapeParams {
|
||||
template <class T>
|
||||
ReshapeParams(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 bool zero_flag) {
|
||||
m_input_shape = input_shape;
|
||||
m_expected_shape = expected_shape;
|
||||
m_input_type = input_type;
|
||||
m_expected_type = expected_type;
|
||||
m_zero_flag = zero_flag;
|
||||
m_input_value = input_shape.size() > 0
|
||||
? CreateTensor(input_shape, input_type, input_value)
|
||||
: CreateTensor(input_type, input_value);
|
||||
m_expected_value = expected_shape.size() > 0
|
||||
? CreateTensor(expected_shape, expected_type, expected_value)
|
||||
: CreateTensor(expected_type, expected_value);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ReshapeParams(const Shape& input_shape,
|
||||
const Shape& expected_shape,
|
||||
const element::Type& input_type,
|
||||
const element::Type& expected_type,
|
||||
const bool zero_flag,
|
||||
T step,
|
||||
const Shape& extra_shape = Shape{}) {
|
||||
m_input_shape = input_shape;
|
||||
m_expected_shape = expected_shape;
|
||||
m_input_type = input_type;
|
||||
m_expected_type = expected_type;
|
||||
m_zero_flag = zero_flag;
|
||||
|
||||
std::vector<T> value(shape_size(input_shape));
|
||||
std::iota(value.begin(), value.end(), static_cast<T>(step));
|
||||
m_input_value = CreateTensor(input_shape, input_type, value);
|
||||
m_expected_value = CreateTensor(expected_shape, expected_type, value);
|
||||
|
||||
if (extra_shape.size() > 0) {
|
||||
m_expected_shape = extra_shape;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
bool m_zero_flag;
|
||||
};
|
||||
|
||||
struct ReshapeShuffleParams {
|
||||
template<class T>
|
||||
ReshapeShuffleParams(const Shape& input_shape1,
|
||||
const Shape& input_shape2,
|
||||
const Shape& input_shape3,
|
||||
const Shape& expected_shape,
|
||||
const element::Type_t& input_type,
|
||||
const element::Type_t& expected_type,
|
||||
const bool zero_flag,
|
||||
T step) {
|
||||
m_input_shape1 = input_shape1;
|
||||
m_input_shape2 = input_shape2;
|
||||
m_input_shape3 = input_shape3;
|
||||
m_expected_shape = expected_shape;
|
||||
m_input_type = input_type;
|
||||
m_expected_type = expected_type;
|
||||
m_zero_flag = zero_flag;
|
||||
|
||||
std::vector<T> value(shape_size(input_shape1));
|
||||
std::iota(value.begin(), value.end(), static_cast<T>(step));
|
||||
m_input_value = CreateTensor(input_shape1, input_type, value);
|
||||
m_expected_value = CreateTensor(expected_shape, expected_type, value);
|
||||
}
|
||||
|
||||
Shape m_input_shape1;
|
||||
Shape m_input_shape2;
|
||||
Shape m_input_shape3;
|
||||
Shape m_expected_shape;
|
||||
element::Type m_input_type;
|
||||
element::Type m_expected_type;
|
||||
runtime::Tensor m_input_value;
|
||||
runtime::Tensor m_expected_value;
|
||||
bool m_zero_flag;
|
||||
};
|
||||
|
||||
class ReferenceReshapeLayerTest : public testing::TestWithParam<ReshapeParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
const auto params = GetParam();
|
||||
function = CreateFunction(params.m_input_type,
|
||||
params.m_expected_type,
|
||||
params.m_input_shape,
|
||||
params.m_expected_shape,
|
||||
params.m_zero_flag);
|
||||
inputData = {params.m_input_value};
|
||||
refOutData = {params.m_expected_value};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<ReshapeParams>& 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 element::Type& input_type,
|
||||
const element::Type& expected_type,
|
||||
const Shape& input_shape,
|
||||
const Shape& expected_shape,
|
||||
const bool zero_flag) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
const auto reshape = std::make_shared<op::v1::Reshape>(
|
||||
in,
|
||||
op::v0::Constant::create(element::Type_t::u64, {expected_shape.size()}, expected_shape),
|
||||
zero_flag);
|
||||
return std::make_shared<Function>(NodeVector{reshape}, ParameterVector{in});
|
||||
}
|
||||
};
|
||||
|
||||
class ReferenceReshapeShuffleLayerTest : public testing::TestWithParam<ReshapeShuffleParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
const auto params = GetParam();
|
||||
function = CreateFunction(params.m_input_type,
|
||||
params.m_expected_type,
|
||||
params.m_input_shape1,
|
||||
params.m_input_shape2,
|
||||
params.m_input_shape3,
|
||||
params.m_expected_shape,
|
||||
params.m_zero_flag);
|
||||
inputData = {params.m_input_value};
|
||||
refOutData = {params.m_expected_value};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<ReshapeShuffleParams>& obj) {
|
||||
const auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
|
||||
result << "input_shape=" << param.m_input_shape1 << "; ";
|
||||
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 element::Type& input_type,
|
||||
const element::Type& expected_type,
|
||||
const Shape& input_shape1,
|
||||
const Shape& input_shape2,
|
||||
const Shape& input_shape3,
|
||||
const Shape& expected_shape,
|
||||
const bool zero_flag) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape1);
|
||||
const auto reshape1 = std::make_shared<op::v1::Reshape>(
|
||||
in,
|
||||
op::v0::Constant::create(element::Type_t::u64, {input_shape2.size()}, input_shape2),
|
||||
zero_flag);
|
||||
const auto reshape2 = std::make_shared<op::v1::Reshape>(
|
||||
reshape1,
|
||||
op::v0::Constant::create(element::Type_t::u64, {input_shape3.size()}, input_shape3),
|
||||
zero_flag);
|
||||
const auto reshape3 = std::make_shared<op::v1::Reshape>(
|
||||
reshape2,
|
||||
op::v0::Constant::create(element::Type_t::u64, {expected_shape.size()}, expected_shape),
|
||||
zero_flag);
|
||||
return std::make_shared<Function>(NodeVector{reshape3}, ParameterVector{in});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceReshapeLayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
TEST_P(ReferenceReshapeShuffleLayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<ReshapeParams> generateParamsForReshape() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
|
||||
std::vector<ReshapeParams> params{
|
||||
ReshapeParams(Shape{2, 2, 3},
|
||||
Shape{12},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
|
||||
false),
|
||||
ReshapeParams(Shape{1, 1, 1},
|
||||
Shape{},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{6},
|
||||
std::vector<T>{6},
|
||||
false),
|
||||
ReshapeParams(Shape{},
|
||||
Shape{1, 1, 1, 1, 1, 1},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{42},
|
||||
std::vector<T>{42},
|
||||
false),
|
||||
ReshapeParams(Shape{3},
|
||||
Shape{3, 1},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1, 2, 3},
|
||||
std::vector<T>{1, 2, 3},
|
||||
false),
|
||||
ReshapeParams(Shape{3},
|
||||
Shape{1, 3},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1, 2, 3},
|
||||
std::vector<T>{1, 2, 3},
|
||||
false),
|
||||
ReshapeParams(Shape{3},
|
||||
Shape{1, 3, 1},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1, 2, 3},
|
||||
std::vector<T>{1, 2, 3},
|
||||
false),
|
||||
ReshapeParams(Shape{3, 3},
|
||||
Shape{3, 3},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9},
|
||||
false),
|
||||
ReshapeParams(Shape{1},
|
||||
Shape{},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1},
|
||||
std::vector<T>{1},
|
||||
false),
|
||||
ReshapeParams(Shape{},
|
||||
Shape{},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1},
|
||||
std::vector<T>{1},
|
||||
false),
|
||||
ReshapeParams(Shape{2, 2, 3, 3, 2, 4},
|
||||
Shape{3, 2, 2, 4, 3, 2},
|
||||
ET,
|
||||
ET,
|
||||
false,
|
||||
static_cast<T>(1)),
|
||||
ReshapeParams(Shape{2, 2, 5, 5},
|
||||
Shape{2, 5, 5, 2},
|
||||
ET,
|
||||
ET,
|
||||
true,
|
||||
static_cast<T>(1),
|
||||
Shape{0, 5, 0, 2})
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<ReshapeParams> generateParamsForReshape8Bit() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
|
||||
std::vector<ReshapeParams> params{
|
||||
ReshapeParams(Shape{2, 2, 3},
|
||||
Shape{12},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
|
||||
std::vector<T>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
|
||||
false),
|
||||
ReshapeParams(Shape{1, 1, 1},
|
||||
Shape{},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{6},
|
||||
std::vector<T>{6},
|
||||
false),
|
||||
ReshapeParams(Shape{},
|
||||
Shape{1, 1, 1, 1, 1, 1},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{42},
|
||||
std::vector<T>{42},
|
||||
false),
|
||||
ReshapeParams(Shape{3},
|
||||
Shape{3, 1},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1, 2, 3},
|
||||
std::vector<T>{1, 2, 3},
|
||||
false),
|
||||
ReshapeParams(Shape{3},
|
||||
Shape{1, 3},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1, 2, 3},
|
||||
std::vector<T>{1, 2, 3},
|
||||
false),
|
||||
ReshapeParams(Shape{3},
|
||||
Shape{1, 3, 1},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1, 2, 3},
|
||||
std::vector<T>{1, 2, 3},
|
||||
false),
|
||||
ReshapeParams(Shape{1},
|
||||
Shape{},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1},
|
||||
std::vector<T>{1},
|
||||
false),
|
||||
ReshapeParams(Shape{},
|
||||
Shape{},
|
||||
ET,
|
||||
ET,
|
||||
std::vector<T>{1},
|
||||
std::vector<T>{1},
|
||||
false)
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
template <element::Type_t ET>
|
||||
std::vector<ReshapeShuffleParams> generateParamsForReshapeShuffle() {
|
||||
using T = typename element_type_traits<ET>::value_type;
|
||||
|
||||
std::vector<ReshapeShuffleParams> params{
|
||||
ReshapeShuffleParams(Shape{1, 112, 56, 56},
|
||||
Shape{1, 4, 28, 56, 56},
|
||||
Shape{1, 28, 4, 56, 56},
|
||||
Shape{1, 112, 56, 56},
|
||||
ET,
|
||||
ET,
|
||||
false,
|
||||
static_cast<T>(1))
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<ReshapeParams> generateCombinedParamsForReshape() {
|
||||
const std::vector<std::vector<ReshapeParams>> allTypeParams{
|
||||
generateParamsForReshape<element::Type_t::f32>(),
|
||||
generateParamsForReshape<element::Type_t::i64>(),
|
||||
generateParamsForReshape<element::Type_t::i32>(),
|
||||
generateParamsForReshape<element::Type_t::i16>(),
|
||||
generateParamsForReshape<element::Type_t::u64>(),
|
||||
generateParamsForReshape<element::Type_t::u32>(),
|
||||
generateParamsForReshape<element::Type_t::u16>(),
|
||||
generateParamsForReshape8Bit<element::Type_t::i8>(),
|
||||
generateParamsForReshape8Bit<element::Type_t::u8>()
|
||||
};
|
||||
|
||||
std::vector<ReshapeParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
std::vector<ReshapeShuffleParams> generateCombinedParamsForReshapeShuffle() {
|
||||
const std::vector<std::vector<ReshapeShuffleParams>> allTypeParams{
|
||||
generateParamsForReshapeShuffle<element::Type_t::f32>(),
|
||||
generateParamsForReshapeShuffle<element::Type_t::i64>(),
|
||||
generateParamsForReshapeShuffle<element::Type_t::i32>(),
|
||||
generateParamsForReshapeShuffle<element::Type_t::i16>(),
|
||||
generateParamsForReshapeShuffle<element::Type_t::i8>(),
|
||||
generateParamsForReshapeShuffle<element::Type_t::u64>(),
|
||||
generateParamsForReshapeShuffle<element::Type_t::u32>(),
|
||||
generateParamsForReshapeShuffle<element::Type_t::u16>(),
|
||||
generateParamsForReshapeShuffle<element::Type_t::u8>(),
|
||||
};
|
||||
|
||||
std::vector<ReshapeShuffleParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_Reshape_With_Hardcoded_Refs,
|
||||
ReferenceReshapeLayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForReshape()),
|
||||
ReferenceReshapeLayerTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_Reshape_Shuffle_With_Hardcoded_Refs,
|
||||
ReferenceReshapeShuffleLayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForReshapeShuffle()),
|
||||
ReferenceReshapeShuffleLayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
311
docs/template_plugin/tests/functional/op_reference/shape_of.cpp
Normal file
311
docs/template_plugin/tests/functional/op_reference/shape_of.cpp
Normal file
@ -0,0 +1,311 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/shape_of.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
|
||||
struct ShapeOfParamsV1 {
|
||||
template <class IT, class OT>
|
||||
ShapeOfParamsV1(const Shape& input_shape,
|
||||
const Shape& expected_shape,
|
||||
const element::Type& input_type,
|
||||
const element::Type& expected_type,
|
||||
const std::vector<IT>& input_value,
|
||||
const std::vector<OT>& 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_shape, input_type, input_value)),
|
||||
m_expected_value(CreateTensor(expected_shape, 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;
|
||||
};
|
||||
|
||||
struct ShapeOfParamsV3 {
|
||||
template <class IT, class OT1, class OT2>
|
||||
ShapeOfParamsV3(const Shape& input_shape,
|
||||
const Shape& expected_shape,
|
||||
const element::Type& input_type,
|
||||
const element::Type& expected_type1,
|
||||
const element::Type& expected_type2,
|
||||
const std::vector<IT>& input_value,
|
||||
const std::vector<OT1>& expected_value1,
|
||||
const std::vector<OT2>& expected_value2)
|
||||
: m_input_shape(input_shape),
|
||||
m_expected_shape(expected_shape),
|
||||
m_input_type(input_type),
|
||||
m_expected_type1(expected_type1),
|
||||
m_expected_type2(expected_type2),
|
||||
m_input_value(CreateTensor(input_shape, input_type, input_value)),
|
||||
m_expected_value1(CreateTensor(expected_shape, expected_type1, expected_value1)),
|
||||
m_expected_value2(CreateTensor(expected_shape, expected_type2, expected_value2)) {}
|
||||
|
||||
Shape m_input_shape;
|
||||
Shape m_expected_shape;
|
||||
element::Type m_input_type;
|
||||
element::Type m_expected_type1;
|
||||
element::Type m_expected_type2;
|
||||
runtime::Tensor m_input_value;
|
||||
runtime::Tensor m_expected_value1;
|
||||
runtime::Tensor m_expected_value2;
|
||||
};
|
||||
|
||||
class ReferenceShapeOfV1LayerTest : public testing::TestWithParam<ShapeOfParamsV1>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
const auto params = GetParam();
|
||||
function = CreateFunction(params.m_input_type, params.m_input_shape);
|
||||
inputData = {params.m_input_value};
|
||||
refOutData = {params.m_expected_value};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<ShapeOfParamsV1>& 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 element::Type& input_type, const Shape& input_shape) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
const auto shapeof = std::make_shared<op::v0::ShapeOf>(in);
|
||||
return std::make_shared<Function>(NodeVector{shapeof}, ParameterVector{in});
|
||||
}
|
||||
};
|
||||
|
||||
class ReferenceShapeOfV3LayerTest : public testing::TestWithParam<ShapeOfParamsV3>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
const auto params = GetParam();
|
||||
function = CreateFunction(params.m_input_type, params.m_input_shape);
|
||||
inputData = {params.m_input_value};
|
||||
refOutData = {params.m_expected_value1, params.m_expected_value2};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<ShapeOfParamsV3>& 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_type1=" << param.m_expected_type1 << "; ";
|
||||
result << "output_type2=" << param.m_expected_type2 << "; ";
|
||||
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const element::Type& input_type, const Shape& input_shape) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
const auto shapeof1 = std::make_shared<op::v3::ShapeOf>(in);
|
||||
const auto shapeof2 = std::make_shared<op::v3::ShapeOf>(in, element::Type_t::i32);
|
||||
return std::make_shared<Function>(OutputVector{shapeof1, shapeof2}, ParameterVector{in});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceShapeOfV1LayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
TEST_P(ReferenceShapeOfV3LayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t IT, element::Type_t OT>
|
||||
std::vector<ShapeOfParamsV1> generateParamsForShapeOfSmall_V1() {
|
||||
using T1 = typename element_type_traits<IT>::value_type;
|
||||
using T2 = typename element_type_traits<OT>::value_type;
|
||||
|
||||
std::vector<ShapeOfParamsV1> params{
|
||||
ShapeOfParamsV1(Shape{2},
|
||||
Shape{1},
|
||||
IT,
|
||||
OT,
|
||||
std::vector<T1>{2, 0},
|
||||
std::vector<T2>{2}),
|
||||
ShapeOfParamsV1(Shape{2, 4},
|
||||
Shape{2},
|
||||
IT,
|
||||
OT,
|
||||
std::vector<T1>{2 * 4, 0},
|
||||
std::vector<T2>{2, 4})
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
template <element::Type_t IT, element::Type_t OT>
|
||||
std::vector<ShapeOfParamsV1> generateParamsForShapeOfBig_V1() {
|
||||
using T1 = typename element_type_traits<IT>::value_type;
|
||||
using T2 = typename element_type_traits<OT>::value_type;
|
||||
|
||||
std::vector<ShapeOfParamsV1> params{
|
||||
ShapeOfParamsV1(Shape{2},
|
||||
Shape{1},
|
||||
IT,
|
||||
OT,
|
||||
std::vector<T1>{2, 0},
|
||||
std::vector<T2>{2}),
|
||||
ShapeOfParamsV1(Shape{2, 4},
|
||||
Shape{2},
|
||||
IT,
|
||||
OT,
|
||||
std::vector<T1>{2 * 4, 0},
|
||||
std::vector<T2>{2, 4}),
|
||||
ShapeOfParamsV1(Shape{2, 4, 8, 16, 32},
|
||||
Shape{5},
|
||||
IT,
|
||||
OT,
|
||||
std::vector<T1>{2 * 4 * 8 * 16 * 32, 0},
|
||||
std::vector<T2>{2, 4, 8, 16, 32})};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
template <element::Type_t IT, element::Type_t OT1, element::Type_t OT2>
|
||||
std::vector<ShapeOfParamsV3> generateParamsForShapeOfSmall_V3() {
|
||||
using T1 = typename element_type_traits<IT>::value_type;
|
||||
using T2 = typename element_type_traits<OT1>::value_type;
|
||||
using T3 = typename element_type_traits<OT2>::value_type;
|
||||
|
||||
std::vector<ShapeOfParamsV3> params{
|
||||
ShapeOfParamsV3(Shape{2},
|
||||
Shape{1},
|
||||
IT,
|
||||
OT1,
|
||||
OT2,
|
||||
std::vector<T1>{2, 0},
|
||||
std::vector<T2>{2},
|
||||
std::vector<T3>{2}),
|
||||
ShapeOfParamsV3(Shape{2, 4},
|
||||
Shape{2},
|
||||
IT,
|
||||
OT1,
|
||||
OT2,
|
||||
std::vector<T1>{2 * 4, 0},
|
||||
std::vector<T2>{2, 4},
|
||||
std::vector<T3>{2, 4})
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
template <element::Type_t IT, element::Type_t OT1, element::Type_t OT2>
|
||||
std::vector<ShapeOfParamsV3> generateParamsForShapeOfBig_V3() {
|
||||
using T1 = typename element_type_traits<IT>::value_type;
|
||||
using T2 = typename element_type_traits<OT1>::value_type;
|
||||
using T3 = typename element_type_traits<OT2>::value_type;
|
||||
|
||||
std::vector<ShapeOfParamsV3> params{
|
||||
ShapeOfParamsV3(Shape{2},
|
||||
Shape{1},
|
||||
IT,
|
||||
OT1,
|
||||
OT2,
|
||||
std::vector<T1>{2, 0},
|
||||
std::vector<T2>{2},
|
||||
std::vector<T3>{2}),
|
||||
ShapeOfParamsV3(Shape{2, 4},
|
||||
Shape{2},
|
||||
IT,
|
||||
OT1,
|
||||
OT2,
|
||||
std::vector<T1>{2 * 4, 0},
|
||||
std::vector<T2>{2, 4},
|
||||
std::vector<T3>{2, 4}),
|
||||
ShapeOfParamsV3(Shape{2, 4, 8, 16, 32},
|
||||
Shape{5},
|
||||
IT,
|
||||
OT1,
|
||||
OT2,
|
||||
std::vector<T1>{2 * 4 * 8 * 16 * 32, 0},
|
||||
std::vector<T2>{2, 4, 8, 16, 32},
|
||||
std::vector<T3>{2, 4, 8, 16, 32})
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<ShapeOfParamsV1> generateCombinedParamsForShapeOfV1() {
|
||||
const std::vector<std::vector<ShapeOfParamsV1>> allTypeParams{
|
||||
generateParamsForShapeOfBig_V1<element::Type_t::f32, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfBig_V1<element::Type_t::f16, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfBig_V1<element::Type_t::bf16, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfBig_V1<element::Type_t::i64, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfBig_V1<element::Type_t::i32, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfBig_V1<element::Type_t::u64, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfBig_V1<element::Type_t::u32, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfSmall_V1<element::Type_t::i16, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfSmall_V1<element::Type_t::i8, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfSmall_V1<element::Type_t::u16, element::Type_t::i64>(),
|
||||
generateParamsForShapeOfSmall_V1<element::Type_t::u8, element::Type_t::i64>()
|
||||
};
|
||||
|
||||
std::vector<ShapeOfParamsV1> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
std::vector<ShapeOfParamsV3> generateCombinedParamsForShapeOfV3() {
|
||||
const std::vector<std::vector<ShapeOfParamsV3>> allTypeParams{
|
||||
generateParamsForShapeOfBig_V3<element::Type_t::f32, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfBig_V3<element::Type_t::f16, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfBig_V3<element::Type_t::bf16, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfBig_V3<element::Type_t::i64, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfBig_V3<element::Type_t::i32, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfBig_V3<element::Type_t::u64, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfBig_V3<element::Type_t::u32, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfSmall_V3<element::Type_t::i16, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfSmall_V3<element::Type_t::i8, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfSmall_V3<element::Type_t::u16, element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForShapeOfSmall_V3<element::Type_t::u8, element::Type_t::i64, element::Type_t::i32>()
|
||||
};
|
||||
|
||||
std::vector<ShapeOfParamsV3> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_ShapeOf_With_Hardcoded_Refs,
|
||||
ReferenceShapeOfV1LayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForShapeOfV1()),
|
||||
ReferenceShapeOfV1LayerTest::getTestCaseName);
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_ShapeOf_With_Hardcoded_Refs,
|
||||
ReferenceShapeOfV3LayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForShapeOfV3()),
|
||||
ReferenceShapeOfV3LayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
174
docs/template_plugin/tests/functional/op_reference/squeeze.cpp
Normal file
174
docs/template_plugin/tests/functional/op_reference/squeeze.cpp
Normal file
@ -0,0 +1,174 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/squeeze.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
|
||||
struct SqueezeParams {
|
||||
template <class IO_T, class Axes_T>
|
||||
SqueezeParams(const Shape& input_shape,
|
||||
const Shape& output_shape,
|
||||
const element::Type& input_type,
|
||||
const element::Type& output_type,
|
||||
const std::vector<IO_T>& input_value,
|
||||
const std::vector<IO_T>& expected_value,
|
||||
const Shape& axes_shape,
|
||||
const element::Type& axes_type,
|
||||
const std::vector<Axes_T>& axes_value)
|
||||
: m_input_shape(input_shape),
|
||||
m_output_shape(output_shape),
|
||||
m_input_type(input_type),
|
||||
m_output_type(output_type),
|
||||
m_input_value(CreateTensor(input_type, input_value)),
|
||||
m_expected_value(CreateTensor(output_type, expected_value)),
|
||||
m_axes_shape(axes_shape),
|
||||
m_axes_type(axes_type),
|
||||
m_axes_value(CreateTensor(axes_type, axes_value)),
|
||||
m_axes_node(true) {}
|
||||
|
||||
template <class IO_T>
|
||||
SqueezeParams(const Shape& input_shape,
|
||||
const Shape& output_shape,
|
||||
const element::Type& input_type,
|
||||
const element::Type& output_type,
|
||||
const std::vector<IO_T>& input_value,
|
||||
const std::vector<IO_T>& expected_value)
|
||||
: m_input_shape(input_shape),
|
||||
m_output_shape(output_shape),
|
||||
m_input_type(input_type),
|
||||
m_output_type(output_type),
|
||||
m_input_value(CreateTensor(input_type, input_value)),
|
||||
m_expected_value(CreateTensor(input_type, expected_value)),
|
||||
m_axes_node(false) {}
|
||||
|
||||
Shape m_input_shape;
|
||||
Shape m_output_shape;
|
||||
element::Type m_input_type;
|
||||
element::Type m_output_type;
|
||||
runtime::Tensor m_input_value;
|
||||
runtime::Tensor m_expected_value;
|
||||
Shape m_axes_shape;
|
||||
element::Type m_axes_type;
|
||||
runtime::Tensor m_axes_value;
|
||||
bool m_axes_node;
|
||||
};
|
||||
|
||||
class ReferenceSqueezeLayerTest : public testing::TestWithParam<SqueezeParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
const auto params = GetParam();
|
||||
function = CreateFunction(params);
|
||||
inputData = {params.m_input_value};
|
||||
refOutData = {params.m_expected_value};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<SqueezeParams>& obj) {
|
||||
const auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
|
||||
result << "input_shape=" << param.m_input_shape << "; ";
|
||||
result << "output_shape=" << param.m_output_shape << "; ";
|
||||
result << "input_type=" << param.m_input_type << "; ";
|
||||
result << "output_type=" << param.m_output_type << "; ";
|
||||
if (param.m_axes_node) {
|
||||
result << "axes_shape=" << param.m_axes_shape << "; ";
|
||||
result << "axes_type=" << param.m_axes_type;
|
||||
}
|
||||
result << "axes_node=" << param.m_axes_node;
|
||||
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const SqueezeParams& params) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(params.m_input_type, params.m_input_shape);
|
||||
std::shared_ptr<op::v0::Constant> axes_node = NULL;
|
||||
std::shared_ptr<op::v0::Squeeze> squeeze = NULL;
|
||||
if (params.m_axes_node) {
|
||||
axes_node = std::make_shared<op::v0::Constant>(params.m_axes_type, params.m_axes_shape, params.m_axes_value.data());
|
||||
squeeze = std::make_shared<op::v0::Squeeze>(in, axes_node);
|
||||
} else {
|
||||
squeeze = std::make_shared<op::v0::Squeeze>(in);
|
||||
}
|
||||
|
||||
return std::make_shared<ov::Function>(squeeze, ParameterVector{in});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceSqueezeLayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t IO_T, element::Type_t Axes_T>
|
||||
std::vector<SqueezeParams> generateParamsForSqueeze() {
|
||||
using T1 = typename element_type_traits<IO_T>::value_type;
|
||||
using T2 = typename element_type_traits<Axes_T>::value_type;
|
||||
|
||||
std::vector<SqueezeParams> params{
|
||||
SqueezeParams(Shape{1, 4, 1, 1, 2},
|
||||
Shape{4, 1, 2},
|
||||
IO_T,
|
||||
IO_T,
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
Shape {2},
|
||||
Axes_T,
|
||||
std::vector<T2>{0, 2}),
|
||||
SqueezeParams(Shape{1, 4, 1, 1, 2},
|
||||
Shape{4, 2},
|
||||
IO_T,
|
||||
IO_T,
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
Shape{0},
|
||||
Axes_T,
|
||||
std::vector<T2>{}),
|
||||
SqueezeParams(Shape{1, 4, 1, 1, 2},
|
||||
Shape{4, 2},
|
||||
IO_T,
|
||||
IO_T,
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8}),
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<SqueezeParams> generateCombinedParamsForSqueeze() {
|
||||
const std::vector<std::vector<SqueezeParams>> allTypeParams{
|
||||
generateParamsForSqueeze<element::Type_t::f32, element::Type_t::i64>(),
|
||||
generateParamsForSqueeze<element::Type_t::i64, element::Type_t::i64>(),
|
||||
generateParamsForSqueeze<element::Type_t::i32, element::Type_t::i64>(),
|
||||
generateParamsForSqueeze<element::Type_t::i16, element::Type_t::i64>(),
|
||||
generateParamsForSqueeze<element::Type_t::i8, element::Type_t::i64>(),
|
||||
generateParamsForSqueeze<element::Type_t::u64, element::Type_t::i64>(),
|
||||
generateParamsForSqueeze<element::Type_t::u32, element::Type_t::i64>(),
|
||||
generateParamsForSqueeze<element::Type_t::u16, element::Type_t::i64>(),
|
||||
generateParamsForSqueeze<element::Type_t::u8, element::Type_t::i64>()
|
||||
};
|
||||
|
||||
std::vector<SqueezeParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_Squeeze_With_Hardcoded_Refs,
|
||||
ReferenceSqueezeLayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForSqueeze()),
|
||||
ReferenceSqueezeLayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
171
docs/template_plugin/tests/functional/op_reference/unsqueeze.cpp
Normal file
171
docs/template_plugin/tests/functional/op_reference/unsqueeze.cpp
Normal file
@ -0,0 +1,171 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/unsqueeze.hpp"
|
||||
#include "openvino/op/constant.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
|
||||
struct UnsqueezeParams {
|
||||
template <class IO_T, class Axes_T>
|
||||
UnsqueezeParams(const Shape& input_shape,
|
||||
const Shape& expected_shape,
|
||||
const element::Type& input_type,
|
||||
const element::Type& expected_type,
|
||||
const std::vector<IO_T>& input_value,
|
||||
const std::vector<IO_T>& expected_value,
|
||||
const Shape& axes_shape,
|
||||
const element::Type& axes_type,
|
||||
const std::vector<Axes_T>& axes_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)),
|
||||
m_axes_shape(axes_shape),
|
||||
m_axes_type(axes_type),
|
||||
m_axes_value(CreateTensor(axes_type, axes_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;
|
||||
Shape m_axes_shape;
|
||||
element::Type m_axes_type;
|
||||
runtime::Tensor m_axes_value;
|
||||
};
|
||||
|
||||
class ReferenceUnsqueezeLayerTest : public testing::TestWithParam<UnsqueezeParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
const auto params = GetParam();
|
||||
function = CreateFunction(params.m_input_type,
|
||||
params.m_input_shape,
|
||||
params.m_axes_type,
|
||||
params.m_axes_shape,
|
||||
params.m_axes_value);
|
||||
inputData = {params.m_input_value};
|
||||
refOutData = {params.m_expected_value};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<UnsqueezeParams>& obj) {
|
||||
const auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
|
||||
result << "input_shape=" << param.m_input_shape << "; ";
|
||||
result << "expected_shape=" << param.m_expected_shape << "; ";
|
||||
result << "input_type=" << param.m_input_type << "; ";
|
||||
result << "expected_type=" << param.m_expected_type << "; ";
|
||||
result << "axes_shape=" << param.m_axes_shape << "; ";
|
||||
result << "axes_type=" << param.m_axes_type << "; ";
|
||||
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const element::Type_t& input_type,
|
||||
const Shape& input_shape,
|
||||
const element::Type& axes_type,
|
||||
const Shape& axes_shape,
|
||||
const runtime::Tensor& axes_value) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
const auto axes = std::make_shared<op::v0::Constant>(axes_type, axes_shape, axes_value.data());
|
||||
const auto unsqueeze = std::make_shared<op::v0::Unsqueeze>(in, axes);
|
||||
return std::make_shared<ov::Function>(unsqueeze, ParameterVector{in});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceUnsqueezeLayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
template <element::Type_t IO_T, element::Type_t Axes_T>
|
||||
std::vector<UnsqueezeParams> generateParamsForUnsqueeze() {
|
||||
using T1 = typename element_type_traits<IO_T>::value_type;
|
||||
using T2 = typename element_type_traits<Axes_T>::value_type;
|
||||
|
||||
std::vector<UnsqueezeParams> params{
|
||||
UnsqueezeParams(Shape{4, 2},
|
||||
Shape{4, 1, 1, 2},
|
||||
IO_T,
|
||||
IO_T,
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
Shape {2},
|
||||
Axes_T,
|
||||
std::vector<T2>{1, 2})
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
template <element::Type_t IO_T, element::Type_t Axes_T>
|
||||
std::vector<UnsqueezeParams> generateParamsForUnsqueezeNegative() {
|
||||
using T1 = typename element_type_traits<IO_T>::value_type;
|
||||
using T2 = typename element_type_traits<Axes_T>::value_type;
|
||||
|
||||
std::vector<UnsqueezeParams> params{
|
||||
UnsqueezeParams(Shape{4, 2},
|
||||
Shape{4, 1, 2, 1},
|
||||
IO_T,
|
||||
IO_T,
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
std::vector<T1>{1, 2, 3, 4, 5, 6, 7, 8},
|
||||
Shape {2},
|
||||
Axes_T,
|
||||
std::vector<T2>{1, -1})
|
||||
};
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
std::vector<UnsqueezeParams> generateCombinedParamsForUnsqueeze() {
|
||||
const std::vector<std::vector<UnsqueezeParams>> allTypeParams{
|
||||
generateParamsForUnsqueeze<element::Type_t::f32, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::f16, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::i64, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::i32, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::u64, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::u32, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::f32, element::Type_t::i32>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::f16, element::Type_t::i32>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::i32, element::Type_t::i32>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::u64, element::Type_t::i32>(),
|
||||
generateParamsForUnsqueeze<element::Type_t::u32, element::Type_t::i32>(),
|
||||
generateParamsForUnsqueezeNegative<element::Type_t::f32, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueezeNegative<element::Type_t::f16, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueezeNegative<element::Type_t::i64, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueezeNegative<element::Type_t::i32, element::Type_t::i64>(),
|
||||
generateParamsForUnsqueezeNegative<element::Type_t::f32, element::Type_t::i32>(),
|
||||
generateParamsForUnsqueezeNegative<element::Type_t::f16, element::Type_t::i32>(),
|
||||
generateParamsForUnsqueezeNegative<element::Type_t::i64, element::Type_t::i32>(),
|
||||
generateParamsForUnsqueezeNegative<element::Type_t::i32, element::Type_t::i32>(),
|
||||
};
|
||||
|
||||
std::vector<UnsqueezeParams> combinedParams;
|
||||
|
||||
for (const auto& params : allTypeParams) {
|
||||
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
|
||||
}
|
||||
|
||||
return combinedParams;
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
smoke_Unsqueeze_With_Hardcoded_Refs,
|
||||
ReferenceUnsqueezeLayerTest,
|
||||
::testing::ValuesIn(generateCombinedParamsForUnsqueeze()),
|
||||
ReferenceUnsqueezeLayerTest::getTestCaseName);
|
||||
|
||||
} // namespace
|
@ -371,6 +371,7 @@ set(SRC
|
||||
visitors/op/select.cpp
|
||||
visitors/op/space_to_depth.cpp
|
||||
visitors/op/selu.cpp
|
||||
visitors/op/shape_of.cpp
|
||||
visitors/op/shuffle_channels.cpp
|
||||
visitors/op/sigmoid.cpp
|
||||
visitors/op/sign.cpp
|
||||
@ -503,23 +504,19 @@ set(MULTI_TEST_SRC
|
||||
backend/recurrent_cells.in.cpp
|
||||
backend/region_yolo.in.cpp
|
||||
backend/reorg_yolo.in.cpp
|
||||
backend/reshape.in.cpp
|
||||
backend/result.in.cpp
|
||||
backend/reverse.in.cpp
|
||||
backend/roll.in.cpp
|
||||
backend/scatter_nd_update.in.cpp
|
||||
backend/space_to_depth.in.cpp
|
||||
backend/shape_of.in.cpp
|
||||
backend/shuffle_channels.in.cpp
|
||||
backend/space_to_batch.in.cpp
|
||||
backend/split.in.cpp
|
||||
backend/sqrt.in.cpp
|
||||
backend/squeeze.in.cpp
|
||||
backend/tile.in.cpp
|
||||
backend/topk.in.cpp
|
||||
backend/transpose.in.cpp
|
||||
backend/unhandled_op.in.cpp
|
||||
backend/unsqueeze.in.cpp
|
||||
backend/validate_call.in.cpp
|
||||
backend/variadic_split.in.cpp
|
||||
backend/zero_sized.in.cpp
|
||||
|
@ -1,363 +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/test_case.hpp"
|
||||
#include "engines_util/test_engines.hpp"
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/builder/reshape.hpp"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/runtime/tensor.hpp"
|
||||
#include "runtime/backend.hpp"
|
||||
#include "util/all_close.hpp"
|
||||
#include "util/all_close_f.hpp"
|
||||
#include "util/ndarray.hpp"
|
||||
#include "util/test_control.hpp"
|
||||
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
|
||||
static string s_manifest = "${MANIFEST}";
|
||||
|
||||
using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_t2v) {
|
||||
Shape shape_a{2, 2, 3};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{12};
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_t2s) {
|
||||
Shape shape_a{1, 1, 1};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{};
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{6});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_s2t) {
|
||||
Shape shape_a{};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{1, 1, 1, 1, 1, 1};
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{42});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{42}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_s2t1) {
|
||||
Shape shape_a{};
|
||||
auto A = make_shared<op::Parameter>(element::boolean, shape_a);
|
||||
Shape shape_r{1};
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::boolean, shape_a);
|
||||
copy_data(a, vector<char>{42});
|
||||
auto result = backend->create_tensor(element::boolean, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_EQ((vector<char>{42}), read_vector<char>(result));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_v2m_col) {
|
||||
Shape shape_a{3};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{3, 1};
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_v2m_row) {
|
||||
Shape shape_a{3};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{1, 3};
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_v2t_middle) {
|
||||
Shape shape_a{3};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{1, 3, 1};
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_m2m_same) {
|
||||
Shape shape_a{3, 3};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{3, 3};
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9});
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9}),
|
||||
read_vector<float>(result),
|
||||
MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_special_zero) {
|
||||
Shape shape_a{2, 2, 5, 5};
|
||||
Shape shape_r{2, 5, 5, 2};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {4}, Shape{0, 5, 0, 2}), true);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
vector<float> a_data(shape_size(shape_a));
|
||||
iota(a_data.begin(), a_data.end(), 1.f);
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, a_data);
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f(a_data, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
||||
|
||||
//
|
||||
// Numpy:
|
||||
//
|
||||
// >>> x = linspace(1,2*2*3*3*2*4,2*2*3*3*2*4)
|
||||
// >>> x.shape=(2,2,3,3,2,4)
|
||||
// >>> y = ascontiguousarray(transpose(x,(2,4,0,5,3,1)))
|
||||
// >>> y.shape=2*2*3*3*2*4
|
||||
// >>> y
|
||||
// array([ 1., 73., 9., 81., 17., 89., 2., 74., 10.,
|
||||
// 82., 18., 90., 3., 75., 11., 83., 19., 91.,
|
||||
// 4., 76., 12., 84., 20., 92., 145., 217., 153.,
|
||||
// 225., 161., 233., 146., 218., 154., 226., 162., 234.,
|
||||
// 147., 219., 155., 227., 163., 235., 148., 220., 156.,
|
||||
// 228., 164., 236., 5., 77., 13., 85., 21., 93.,
|
||||
// 6., 78., 14., 86., 22., 94., 7., 79., 15.,
|
||||
// 87., 23., 95., 8., 80., 16., 88., 24., 96.,
|
||||
// 149., 221., 157., 229., 165., 237., 150., 222., 158.,
|
||||
// 230., 166., 238., 151., 223., 159., 231., 167., 239.,
|
||||
// 152., 224., 160., 232., 168., 240., 25., 97., 33.,
|
||||
// 105., 41., 113., 26., 98., 34., 106., 42., 114.,
|
||||
// 27., 99., 35., 107., 43., 115., 28., 100., 36.,
|
||||
// 108., 44., 116., 169., 241., 177., 249., 185., 257.,
|
||||
// 170., 242., 178., 250., 186., 258., 171., 243., 179.,
|
||||
// 251., 187., 259., 172., 244., 180., 252., 188., 260.,
|
||||
// 29., 101., 37., 109., 45., 117., 30., 102., 38.,
|
||||
// 110., 46., 118., 31., 103., 39., 111., 47., 119.,
|
||||
// 32., 104., 40., 112., 48., 120., 173., 245., 181.,
|
||||
// 253., 189., 261., 174., 246., 182., 254., 190., 262.,
|
||||
// 175., 247., 183., 255., 191., 263., 176., 248., 184.,
|
||||
// 256., 192., 264., 49., 121., 57., 129., 65., 137.,
|
||||
// 50., 122., 58., 130., 66., 138., 51., 123., 59.,
|
||||
// 131., 67., 139., 52., 124., 60., 132., 68., 140.,
|
||||
// 193., 265., 201., 273., 209., 281., 194., 266., 202.,
|
||||
// 274., 210., 282., 195., 267., 203., 275., 211., 283.,
|
||||
// 196., 268., 204., 276., 212., 284., 53., 125., 61.,
|
||||
// 133., 69., 141., 54., 126., 62., 134., 70., 142.,
|
||||
// 55., 127., 63., 135., 71., 143., 56., 128., 64.,
|
||||
// 136., 72., 144., 197., 269., 205., 277., 213., 285.,
|
||||
// 198., 270., 206., 278., 214., 286., 199., 271., 207.,
|
||||
// 279., 215., 287., 200., 272., 208., 280., 216., 288.])
|
||||
//
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_6d) {
|
||||
Shape shape_a{2, 2, 3, 3, 2, 4};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_r{3, 2, 2, 4, 3, 2};
|
||||
|
||||
vector<float> a_data(shape_size(shape_a));
|
||||
iota(a_data.begin(), a_data.end(), 1.f);
|
||||
|
||||
auto r = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r, ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
// Create some tensors for input/output
|
||||
auto a = backend->create_tensor(element::f32, shape_a);
|
||||
copy_data(a, a_data);
|
||||
|
||||
auto result = backend->create_tensor(element::f32, shape_r);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
EXPECT_TRUE(test::all_close_f(a_data, read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
|
||||
EXPECT_EQ(r->get_output_shape(0), shape_r);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, builder_reshape_1D_to_scalar) {
|
||||
const Shape input_shape{1};
|
||||
const auto input = make_shared<op::Parameter>(element::f32, input_shape);
|
||||
const auto reshape_builder = builder::opset1::reshape(input, Shape{});
|
||||
auto function = make_shared<Function>(reshape_builder, ParameterVector{input});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
vector<float> input_values(shape_size(input_shape), 1.f);
|
||||
test_case.add_input<float>(input_shape, input_values);
|
||||
test_case.add_expected_output<float>(Shape{}, vector<float>{1.f});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, builder_reshape_3D_to_scalar) {
|
||||
const Shape input_shape{1, 1, 1};
|
||||
const auto input = make_shared<op::Parameter>(element::f32, input_shape);
|
||||
const auto reshape_builder = builder::opset1::reshape(input, Shape{});
|
||||
auto function = make_shared<Function>(reshape_builder, ParameterVector{input});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
vector<float> input_values(shape_size(input_shape), 1.f);
|
||||
test_case.add_input<float>(input_shape, input_values);
|
||||
test_case.add_expected_output<float>(Shape{}, vector<float>{1.f});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, builder_reshape_1d_to_same_shape) {
|
||||
const Shape input_shape{1};
|
||||
auto param = make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto r =
|
||||
make_shared<op::v1::Reshape>(param, op::Constant::create(element::i64, {}, std::vector<int64_t>{1}), false);
|
||||
auto function = make_shared<Function>(r, ParameterVector{param});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
vector<float> input_values(shape_size(input_shape), 1.f);
|
||||
test_case.add_input<float>(input_shape, input_values);
|
||||
test_case.add_expected_output<float>(Shape{}, vector<float>{1.f});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
NGRAPH_TEST(${BACKEND_NAME}, builder_reshape_to_same_shape) {
|
||||
const Shape input_shape{};
|
||||
auto param = make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto r =
|
||||
make_shared<op::v1::Reshape>(param, op::Constant::create(element::i64, {}, std::vector<int64_t>{1}), false);
|
||||
auto function = make_shared<Function>(r, ParameterVector{param});
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
vector<float> input_values(shape_size(input_shape), 1.f);
|
||||
test_case.add_input<float>(input_shape, input_values);
|
||||
test_case.add_expected_output<float>(Shape{}, vector<float>{1.f});
|
||||
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, reshape_shufflenet_5d) {
|
||||
Shape shape_a{1, 112, 56, 56};
|
||||
auto A = make_shared<op::Parameter>(element::f32, shape_a);
|
||||
Shape shape_b{1, 4, 28, 56, 56};
|
||||
auto B = make_shared<op::Parameter>(element::f32, shape_b);
|
||||
Shape shape_c{1, 28, 4, 56, 56};
|
||||
auto C = make_shared<op::Parameter>(element::f32, shape_c);
|
||||
Shape shape_r{1, 112, 56, 56};
|
||||
|
||||
vector<float> a_data(shape_size(shape_a));
|
||||
iota(a_data.begin(), a_data.end(), 1.f);
|
||||
|
||||
auto r0 = make_shared<op::v1::Reshape>(A, op::Constant::create(element::u64, {shape_b.size()}, shape_b), false);
|
||||
auto r1 = make_shared<op::v1::Reshape>(r0, op::Constant::create(element::u64, {shape_c.size()}, shape_c), false);
|
||||
auto r2 = make_shared<op::v1::Reshape>(r1, op::Constant::create(element::u64, {shape_r.size()}, shape_r), false);
|
||||
auto f = make_shared<Function>(r2, ParameterVector{A});
|
||||
|
||||
auto ref_func = clone_function(*f);
|
||||
auto bk_func = clone_function(*f);
|
||||
|
||||
vector<vector<float>> args;
|
||||
args.push_back(a_data);
|
||||
|
||||
auto ref_results = execute(ref_func, args, "INTERPRETER");
|
||||
auto bk_results = execute(bk_func, args, "${BACKEND_NAME}");
|
||||
|
||||
EXPECT_TRUE(test::all_close_f(ref_results.at(0), bk_results.at(0), MIN_FLOAT_TOLERANCE_BITS));
|
||||
}
|
@ -1,190 +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.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}, shape_of_scalar_v0) {
|
||||
Shape input_shape{};
|
||||
Shape output_shape{0};
|
||||
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto f = std::make_shared<Function>(std::make_shared<op::v0::ShapeOf>(A), ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, input_shape);
|
||||
copy_data(a, vector<float>{0});
|
||||
auto result = backend->create_tensor(element::i64, output_shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
vector<int64_t> expected{};
|
||||
EXPECT_EQ(expected, read_vector<int64_t>(result));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, shape_of_scalar_v3) {
|
||||
Shape input_shape{};
|
||||
Shape output_shape{0};
|
||||
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto f = std::make_shared<Function>(
|
||||
OutputVector{std::make_shared<op::v3::ShapeOf>(A), std::make_shared<op::v3::ShapeOf>(A, element::i32)},
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, input_shape);
|
||||
copy_data(a, vector<float>{0});
|
||||
auto result64 = backend->create_tensor(element::i64, output_shape);
|
||||
auto result32 = backend->create_tensor(element::i32, output_shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result64, result32}, {a});
|
||||
vector<int64_t> expected64{};
|
||||
vector<int32_t> expected32{};
|
||||
EXPECT_EQ(expected64, read_vector<int64_t>(result64));
|
||||
EXPECT_EQ(expected32, read_vector<int32_t>(result32));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, shape_of_vector_v0) {
|
||||
Shape input_shape{2};
|
||||
Shape output_shape{1};
|
||||
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto f = std::make_shared<Function>(std::make_shared<op::v0::ShapeOf>(A), ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, input_shape);
|
||||
copy_data(a, vector<float>(2, 0));
|
||||
auto result = backend->create_tensor(element::i64, output_shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
vector<int64_t> expected{2};
|
||||
EXPECT_EQ(expected, read_vector<int64_t>(result));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, shape_of_vector_v3) {
|
||||
Shape input_shape{2};
|
||||
Shape output_shape{1};
|
||||
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto f = std::make_shared<Function>(
|
||||
OutputVector{std::make_shared<op::v3::ShapeOf>(A), std::make_shared<op::v3::ShapeOf>(A, element::i32)},
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, input_shape);
|
||||
copy_data(a, vector<float>{2, 0});
|
||||
auto result64 = backend->create_tensor(element::i64, output_shape);
|
||||
auto result32 = backend->create_tensor(element::i32, output_shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result64, result32}, {a});
|
||||
vector<int64_t> expected64{2};
|
||||
vector<int32_t> expected32{2};
|
||||
EXPECT_EQ(expected64, read_vector<int64_t>(result64));
|
||||
EXPECT_EQ(expected32, read_vector<int32_t>(result32));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, shape_of_matrix_v0) {
|
||||
Shape input_shape{2, 4};
|
||||
Shape output_shape{2};
|
||||
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto f = std::make_shared<Function>(std::make_shared<op::v0::ShapeOf>(A), ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, input_shape);
|
||||
copy_data(a, vector<float>(2 * 4, 0));
|
||||
auto result = backend->create_tensor(element::i64, output_shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
vector<int64_t> expected{2, 4};
|
||||
EXPECT_EQ(expected, read_vector<int64_t>(result));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, shape_of_matrix_v3) {
|
||||
Shape input_shape{2, 4};
|
||||
Shape output_shape{2};
|
||||
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto f = std::make_shared<Function>(
|
||||
OutputVector{std::make_shared<op::v3::ShapeOf>(A), std::make_shared<op::v3::ShapeOf>(A, element::i32)},
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, input_shape);
|
||||
copy_data(a, vector<float>(2 * 4, 0));
|
||||
auto result64 = backend->create_tensor(element::i64, output_shape);
|
||||
auto result32 = backend->create_tensor(element::i32, output_shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result64, result32}, {a});
|
||||
vector<int64_t> expected64{2, 4};
|
||||
vector<int32_t> expected32{2, 4};
|
||||
EXPECT_EQ(expected64, read_vector<int64_t>(result64));
|
||||
EXPECT_EQ(expected32, read_vector<int32_t>(result32));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, shape_of_5d_v0) {
|
||||
Shape input_shape{2, 4, 8, 16, 32};
|
||||
Shape output_shape{5};
|
||||
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto f = std::make_shared<Function>(std::make_shared<op::v0::ShapeOf>(A), ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, input_shape);
|
||||
copy_data(a, vector<float>(2 * 4 * 8 * 16 * 32, 0));
|
||||
auto result = backend->create_tensor(element::i64, output_shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result}, {a});
|
||||
vector<int64_t> expected{2, 4, 8, 16, 32};
|
||||
EXPECT_EQ(expected, read_vector<int64_t>(result));
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, shape_of_5d_v3) {
|
||||
Shape input_shape{2, 4, 8, 16, 32};
|
||||
Shape output_shape{5};
|
||||
|
||||
auto A = std::make_shared<op::Parameter>(element::f32, input_shape);
|
||||
auto f = std::make_shared<Function>(
|
||||
OutputVector{std::make_shared<op::v3::ShapeOf>(A), std::make_shared<op::v3::ShapeOf>(A, element::i32)},
|
||||
ParameterVector{A});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
|
||||
auto a = backend->create_tensor(element::f32, input_shape);
|
||||
copy_data(a, vector<float>(2 * 4 * 8 * 16 * 32, 0));
|
||||
auto result64 = backend->create_tensor(element::i64, output_shape);
|
||||
auto result32 = backend->create_tensor(element::i32, output_shape);
|
||||
|
||||
auto handle = backend->compile(f);
|
||||
handle->call_with_validate({result64, result32}, {a});
|
||||
vector<int64_t> expected64{2, 4, 8, 16, 32};
|
||||
vector<int32_t> expected32{2, 4, 8, 16, 32};
|
||||
EXPECT_EQ(expected64, read_vector<int64_t>(result64));
|
||||
EXPECT_EQ(expected32, read_vector<int32_t>(result32));
|
||||
}
|
@ -1,56 +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/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});
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, squeeze) {
|
||||
const auto data_node = make_shared<op::Parameter>(element::f32, Shape{1, 4, 1, 1, 2});
|
||||
const auto axes_node = make_shared<ngraph::op::Constant>(element::i64, Shape{2}, vector<int64_t>{0, 2});
|
||||
const auto squeeze = make_shared<op::Squeeze>(data_node, axes_node);
|
||||
|
||||
const auto function = make_shared<Function>(NodeVector{squeeze}, ParameterVector{data_node});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
const auto data = vector<float>{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f};
|
||||
test_case.add_input(data);
|
||||
test_case.add_expected_output<float>(Shape{4, 1, 2}, data);
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, squeeze_default_axes) {
|
||||
const auto data_node = make_shared<op::Parameter>(element::f32, Shape{1, 4, 1, 1, 2});
|
||||
const auto axes_node = make_shared<ngraph::op::Constant>(element::i64, Shape{0}, vector<int64_t>{});
|
||||
const auto squeeze = make_shared<op::Squeeze>(data_node, axes_node);
|
||||
|
||||
const auto function = make_shared<Function>(NodeVector{squeeze}, ParameterVector{data_node});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
const auto data = vector<float>{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f};
|
||||
test_case.add_input(data);
|
||||
test_case.add_expected_output<float>(Shape{4, 2}, data);
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, squeeze_no_axes) {
|
||||
const auto data_node = make_shared<op::Parameter>(element::f32, Shape{1, 4, 1, 1, 2});
|
||||
const auto squeeze = make_shared<op::Squeeze>(data_node);
|
||||
|
||||
const auto function = make_shared<Function>(NodeVector{squeeze}, ParameterVector{data_node});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
const auto data = vector<float>{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f};
|
||||
test_case.add_input(data);
|
||||
test_case.add_expected_output<float>(Shape{4, 2}, data);
|
||||
test_case.run();
|
||||
}
|
@ -1,43 +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/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});
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, unsqueeze) {
|
||||
auto data_node = make_shared<op::Parameter>(element::f32, Shape{4, 2});
|
||||
auto axes_node = make_shared<ngraph::op::Constant>(element::i64, Shape{2}, vector<int64_t>{1, 2});
|
||||
auto squeeze = make_shared<op::v0::Unsqueeze>(data_node, axes_node);
|
||||
|
||||
auto function = make_shared<Function>(NodeVector{squeeze}, ParameterVector{data_node});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
auto data = vector<float>{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f};
|
||||
test_case.add_input(data);
|
||||
test_case.add_expected_output<float>(Shape{4, 1, 1, 2}, data);
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, unsqueeze_negative_axis) {
|
||||
auto data_node = make_shared<op::Parameter>(element::f32, Shape{4, 2});
|
||||
auto axes_node = make_shared<ngraph::op::Constant>(element::i64, Shape{2}, vector<int64_t>{1, -1});
|
||||
auto squeeze = make_shared<op::v0::Unsqueeze>(data_node, axes_node);
|
||||
|
||||
auto function = make_shared<Function>(NodeVector{squeeze}, ParameterVector{data_node});
|
||||
auto test_case = test::TestCase<TestEngine>(function);
|
||||
|
||||
auto data = vector<float>{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f};
|
||||
test_case.add_input(data);
|
||||
test_case.add_expected_output<float>(Shape{4, 1, 2, 1}, data);
|
||||
test_case.run();
|
||||
}
|
38
ngraph/test/visitors/op/shape_of.cpp
Normal file
38
ngraph/test/visitors/op/shape_of.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2018-2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "ngraph/op/util/attr_types.hpp"
|
||||
#include "ngraph/opsets/opset1.hpp"
|
||||
#include "ngraph/opsets/opset3.hpp"
|
||||
#include "ngraph/opsets/opset5.hpp"
|
||||
#include "util/visitor.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace ngraph;
|
||||
using ngraph::test::NodeBuilder;
|
||||
using ngraph::test::ValueMap;
|
||||
|
||||
TEST(attributes, shapeof_op1) {
|
||||
NodeBuilder::get_ops().register_factory<op::v0::ShapeOf>();
|
||||
auto data = make_shared<op::Parameter>(element::i32, Shape{2, 3, 4});
|
||||
auto shapeof = make_shared<op::v0::ShapeOf>(data);
|
||||
NodeBuilder builder(shapeof);
|
||||
auto g_shapeof = ov::as_type_ptr<op::v0::ShapeOf>(builder.create());
|
||||
|
||||
const auto expected_attr_count = 0;
|
||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
||||
}
|
||||
|
||||
TEST(attributes, shapeof_op3) {
|
||||
NodeBuilder::get_ops().register_factory<op::v3::ShapeOf>();
|
||||
auto data = make_shared<op::Parameter>(element::i32, Shape{2, 3, 4});
|
||||
auto shapeof = make_shared<op::v3::ShapeOf>(data, element::Type_t::i64);
|
||||
NodeBuilder builder(shapeof);
|
||||
auto g_shapeof = ov::as_type_ptr<op::v3::ShapeOf>(builder.create());
|
||||
|
||||
const auto expected_attr_count = 1;
|
||||
EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);
|
||||
}
|
Loading…
Reference in New Issue
Block a user