Migrate ngraph backend test of condition operations (#7907)
* Add test cases for PReLU in cpu plugin * For case when slope is vector * Add Bucketize and NonZero template plugin reference tests * Apply supported types for NonZero * Edit float_t and double_t to float and double * Edit std::vector<bool> to std::vector<char>
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "openvino/op/bucketize.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
struct BucketizeParams {
|
||||
template <class IT, class BT, class OT>
|
||||
BucketizeParams(const element::Type& input_type, const PartialShape& input_pshape, const std::vector<IT>& input,
|
||||
const element::Type& bucket_type, const PartialShape& bucket_pshape, const std::vector<BT>& buckets, bool with_right_bound,
|
||||
const element::Type& output_type, const std::vector<OT>& expected_output)
|
||||
: input_type(input_type),
|
||||
input_pshape(input_pshape),
|
||||
input(CreateTensor(input_type, input)),
|
||||
bucket_type(bucket_type),
|
||||
bucket_pshape(bucket_pshape),
|
||||
buckets(CreateTensor(bucket_type, buckets)),
|
||||
with_right_bound(with_right_bound),
|
||||
output_type(output_type),
|
||||
expected_output(CreateTensor(output_type, expected_output)) {}
|
||||
|
||||
element::Type input_type;
|
||||
PartialShape input_pshape;
|
||||
runtime::Tensor input;
|
||||
element::Type bucket_type;
|
||||
PartialShape bucket_pshape;
|
||||
runtime::Tensor buckets;
|
||||
bool with_right_bound;
|
||||
element::Type output_type;
|
||||
runtime::Tensor expected_output;
|
||||
};
|
||||
|
||||
class ReferenceBucketizeLayerTest : public testing::TestWithParam<BucketizeParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params.input_type, params.input_pshape, params.bucket_type, params.bucket_pshape,
|
||||
params.with_right_bound, params.output_type);
|
||||
inputData = {params.input, params.buckets};
|
||||
refOutData = {params.expected_output};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<BucketizeParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "input_type=" << param.input_type << "_";
|
||||
result << "input_pshape=" << param.input_pshape << "_";
|
||||
result << "bucket_type=" << param.bucket_type << "_";
|
||||
result << "bucket_pshape=" << param.bucket_pshape << "_";
|
||||
result << "with_right_bound=" << param.with_right_bound << "_";
|
||||
result << "output_type=" << param.output_type;
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const element::Type& input_type, const PartialShape& input_pshape,
|
||||
const element::Type& bucket_type, const PartialShape& bucket_pshape,
|
||||
const bool with_right_bound, const element::Type& output_type) {
|
||||
auto data = std::make_shared<op::v0::Parameter>(input_type, input_pshape);
|
||||
auto buckets = std::make_shared<op::v0::Parameter>(bucket_type, bucket_pshape);
|
||||
return std::make_shared<Function>(std::make_shared<op::v3::Bucketize>(data, buckets, output_type, with_right_bound),
|
||||
ParameterVector {data, buckets});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceBucketizeLayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_Bucketize_With_Hardcoded_Refs, ReferenceBucketizeLayerTest,
|
||||
::testing::Values(
|
||||
// fp32, int32, with_right_bound
|
||||
BucketizeParams(element::f32,
|
||||
PartialShape {10, 1},
|
||||
std::vector<float> {8.f, 1.f, 2.f, 1.1f, 8.f, 10.f, 1.f, 10.2f, 0.f, 20.f},
|
||||
element::i32,
|
||||
PartialShape {4},
|
||||
std::vector<int32_t> {1, 4, 10, 20},
|
||||
true,
|
||||
element::i32,
|
||||
std::vector<int32_t> {2, 0, 1, 1, 2, 2, 0, 3, 0, 3}),
|
||||
// fp32, int32, with_right_bound
|
||||
BucketizeParams(element::i32,
|
||||
PartialShape {1, 1, 10},
|
||||
std::vector<int32_t> {8, 1, 2, 1, 8, 5, 1, 5, 0, 20},
|
||||
element::i32,
|
||||
PartialShape {4},
|
||||
std::vector<int32_t> {1, 4, 10, 20},
|
||||
false,
|
||||
element::i32,
|
||||
std::vector<int32_t> {2, 1, 1, 1, 2, 2, 1, 2, 0, 4})),
|
||||
ReferenceBucketizeLayerTest::getTestCaseName);
|
||||
262
docs/template_plugin/tests/functional/op_reference/nonzero.cpp
Normal file
262
docs/template_plugin/tests/functional/op_reference/nonzero.cpp
Normal file
@@ -0,0 +1,262 @@
|
||||
// Copyright (C) 2021 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <random>
|
||||
#include "openvino/op/non_zero.hpp"
|
||||
#include "base_reference_test.hpp"
|
||||
|
||||
using namespace reference_tests;
|
||||
using namespace ov;
|
||||
|
||||
namespace {
|
||||
struct NonZeroParams {
|
||||
template <class IT, class OT>
|
||||
NonZeroParams(const PartialShape& dynamicShape, const PartialShape& inputShape,
|
||||
const element::Type& inType, const element::Type& refType,
|
||||
const std::vector<IT>& inputData, const std::vector<OT>& refData,
|
||||
const std::string& test_name = "")
|
||||
: dynamicShape(dynamicShape),
|
||||
inputShape(inputShape),
|
||||
inType(inType),
|
||||
refType(refType),
|
||||
inputData(CreateTensor(inType, inputData)),
|
||||
refData(CreateTensor(refType, refData)),
|
||||
testcaseName(test_name) {}
|
||||
|
||||
PartialShape dynamicShape;
|
||||
PartialShape inputShape;
|
||||
element::Type inType;
|
||||
element::Type refType;
|
||||
runtime::Tensor inputData;
|
||||
runtime::Tensor refData;
|
||||
std::string testcaseName;
|
||||
};
|
||||
|
||||
class ReferenceNonZeroLayerTest : public testing::TestWithParam<NonZeroParams>, public CommonReferenceTest {
|
||||
public:
|
||||
void SetUp() override {
|
||||
auto params = GetParam();
|
||||
function = CreateFunction(params.dynamicShape, params.inType, params.refType);
|
||||
inputData = {params.inputData};
|
||||
refOutData = {params.refData};
|
||||
}
|
||||
|
||||
static std::string getTestCaseName(const testing::TestParamInfo<NonZeroParams>& obj) {
|
||||
auto param = obj.param;
|
||||
std::ostringstream result;
|
||||
result << "dShape=" << param.dynamicShape << "_";
|
||||
result << "iShape=" << param.inputShape << "_";
|
||||
result << "iType=" << param.inType << "_";
|
||||
if (param.testcaseName != "") {
|
||||
result << "oType=" << param.refType << "_";
|
||||
result << param.testcaseName;
|
||||
} else {
|
||||
result << "oType=" << param.refType;
|
||||
}
|
||||
return result.str();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<Function> CreateFunction(const PartialShape& input_shape, const element::Type& input_type,
|
||||
const element::Type& output_type) {
|
||||
const auto in = std::make_shared<op::v0::Parameter>(input_type, input_shape);
|
||||
const auto NonZero = std::make_shared<op::v3::NonZero>(in, output_type);
|
||||
return std::make_shared<Function>(NodeVector {NonZero}, ParameterVector {in});
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReferenceNonZeroLayerTest, CompareWithHardcodedRefs) {
|
||||
Exec();
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_NonZero_With_Hardcoded_Refs, ReferenceNonZeroLayerTest,
|
||||
::testing::Values(
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i32,
|
||||
element::i32,
|
||||
std::vector<int32_t>{1, 1, 1, 1, 1, 1},
|
||||
std::vector<int32_t>{0, 0, 1, 1, 2, 2, 0, 1, 0, 1, 0, 1},
|
||||
"all_1s"),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i32,
|
||||
element::i32,
|
||||
std::vector<int32_t>{0, 0, 0, 0, 0, 0},
|
||||
std::vector<int32_t>{},
|
||||
"all_0s"),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i32,
|
||||
element::i64,
|
||||
std::vector<int32_t>{1, 1, 1, 1, 1, 1},
|
||||
std::vector<int64_t>{0, 0, 1, 1, 2, 2, 0, 1, 0, 1, 0, 1},
|
||||
"all_1s_int64"),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i32,
|
||||
element::i64,
|
||||
std::vector<int32_t>{0, 0, 0, 0, 0, 0},
|
||||
std::vector<int64_t>{},
|
||||
"all_0s_int64"),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::boolean,
|
||||
element::i32,
|
||||
std::vector<char>{false, false, false, false, true, true},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i8,
|
||||
element::i32,
|
||||
std::vector<int8_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i16,
|
||||
element::i32,
|
||||
std::vector<int16_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i32,
|
||||
element::i32,
|
||||
std::vector<int32_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i64,
|
||||
element::i32,
|
||||
std::vector<int64_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::u8,
|
||||
element::i32,
|
||||
std::vector<uint8_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::u16,
|
||||
element::i32,
|
||||
std::vector<uint16_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::u32,
|
||||
element::i32,
|
||||
std::vector<uint32_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::u64,
|
||||
element::i32,
|
||||
std::vector<uint64_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::bf16,
|
||||
element::i32,
|
||||
std::vector<bfloat16>{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 3.0f},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::f16,
|
||||
element::i32,
|
||||
std::vector<float16>{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 3.0f},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::f32,
|
||||
element::i32,
|
||||
std::vector<float>{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 3.0f},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::f64,
|
||||
element::i32,
|
||||
std::vector<double>{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 3.0f},
|
||||
std::vector<int32_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::boolean,
|
||||
element::i64,
|
||||
std::vector<char>{false, false, false, false, true, true},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i8,
|
||||
element::i64,
|
||||
std::vector<int8_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i16,
|
||||
element::i64,
|
||||
std::vector<int16_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i32,
|
||||
element::i64,
|
||||
std::vector<int32_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::i64,
|
||||
element::i64,
|
||||
std::vector<int64_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::u8,
|
||||
element::i64,
|
||||
std::vector<uint8_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::u16,
|
||||
element::i64,
|
||||
std::vector<uint16_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::u32,
|
||||
element::i64,
|
||||
std::vector<uint32_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::u64,
|
||||
element::i64,
|
||||
std::vector<uint64_t>{0, 0, 0, 0, 1, 3},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::bf16,
|
||||
element::i64,
|
||||
std::vector<bfloat16>{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 3.0f},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::f16,
|
||||
element::i64,
|
||||
std::vector<float16>{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 3.0f},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::f32,
|
||||
element::i64,
|
||||
std::vector<float>{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 3.0f},
|
||||
std::vector<int64_t>{2, 2, 0, 1}),
|
||||
NonZeroParams(PartialShape{3, 2},
|
||||
PartialShape{3, 2},
|
||||
element::f64,
|
||||
element::i64,
|
||||
std::vector<double>{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 3.0f},
|
||||
std::vector<int64_t>{2, 2, 0, 1})),
|
||||
ReferenceNonZeroLayerTest::getTestCaseName);
|
||||
} // namespace
|
||||
@@ -460,7 +460,6 @@ set(MULTI_TEST_SRC
|
||||
backend/batch_norm.in.cpp
|
||||
backend/batch_to_space.in.cpp
|
||||
backend/broadcast.in.cpp
|
||||
backend/bucketize.in.cpp
|
||||
backend/builder_reduce_ops_opset1.in.cpp
|
||||
backend/ceiling.in.cpp
|
||||
backend/concat.in.cpp
|
||||
@@ -507,7 +506,6 @@ set(MULTI_TEST_SRC
|
||||
backend/node_name.in.cpp
|
||||
backend/normalize_l2.in.cpp
|
||||
backend/non_max_suppression.in.cpp
|
||||
backend/non_zero.in.cpp
|
||||
backend/one_hot.in.cpp
|
||||
backend/pad.in.cpp
|
||||
backend/parameter_as_output.in.cpp
|
||||
|
||||
@@ -1,57 +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"
|
||||
|
||||
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}, bucketize_right_edge) {
|
||||
Shape data_shape{10, 1};
|
||||
Shape bucket_shape{4};
|
||||
|
||||
const auto data = make_shared<op::Parameter>(element::f32, data_shape);
|
||||
const auto buckets = make_shared<op::Parameter>(element::i32, bucket_shape);
|
||||
const auto bucketize = make_shared<op::v3::Bucketize>(data, buckets, element::i32, true);
|
||||
const auto f = make_shared<Function>(bucketize, ParameterVector{data, buckets});
|
||||
|
||||
vector<float> data_vect = {8.f, 1.f, 2.f, 1.1f, 8.f, 10.f, 1.f, 10.2f, 0.f, 20.f};
|
||||
vector<int32_t> buckets_vect = {1, 4, 10, 20};
|
||||
vector<int32_t> expected_vect = {2, 0, 1, 1, 2, 2, 0, 3, 0, 3};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<float>(data_shape, data_vect);
|
||||
test_case.add_input<int32_t>(bucket_shape, buckets_vect);
|
||||
test_case.add_expected_output<int32_t>(data_shape, expected_vect);
|
||||
test_case.run();
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, bucketize_left_edge) {
|
||||
Shape data_shape{1, 1, 10};
|
||||
Shape bucket_shape{4};
|
||||
|
||||
const auto data = make_shared<op::Parameter>(element::i32, data_shape);
|
||||
const auto buckets = make_shared<op::Parameter>(element::f32, bucket_shape);
|
||||
const auto bucketize = make_shared<op::v3::Bucketize>(data, buckets, element::i32, false);
|
||||
const auto f = make_shared<Function>(bucketize, ParameterVector{data, buckets});
|
||||
|
||||
vector<int32_t> data_vect = {8, 1, 2, 1, 8, 5, 1, 5, 0, 20};
|
||||
vector<float> buckets_vect = {1.f, 4.f, 10.f, 20.f};
|
||||
vector<int32_t> expected_vect = {2, 1, 1, 1, 2, 2, 1, 2, 0, 4};
|
||||
|
||||
auto test_case = test::TestCase<TestEngine>(f);
|
||||
test_case.add_input<int32_t>(data_shape, data_vect);
|
||||
test_case.add_input<float>(bucket_shape, buckets_vect);
|
||||
test_case.add_expected_output<int32_t>(data_shape, expected_vect);
|
||||
test_case.run();
|
||||
}
|
||||
@@ -1,90 +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 "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}, non_zero) {
|
||||
PartialShape p_shape = PartialShape::dynamic();
|
||||
auto p = make_shared<op::Parameter>(element::f32, p_shape);
|
||||
auto non_zero = make_shared<op::v3::NonZero>(p, element::i32);
|
||||
auto fun = make_shared<Function>(OutputVector{non_zero}, ParameterVector{p});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
auto cfun = backend->compile(fun);
|
||||
|
||||
auto input = backend->create_tensor(element::f32, Shape{3, 2});
|
||||
copy_data(input, vector<float>{0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 3.0f});
|
||||
|
||||
std::vector<int32_t> expected_result{2, 2, 0, 1};
|
||||
Shape expected_output_shape{2, 2};
|
||||
|
||||
auto result = make_shared<HostTensor>();
|
||||
cfun->call_with_validate({result}, {input});
|
||||
|
||||
EXPECT_EQ(result->get_element_type(), element::i32);
|
||||
EXPECT_EQ(result->get_shape(), expected_output_shape);
|
||||
auto result_data = read_vector<int32_t>(result);
|
||||
ASSERT_EQ(result_data, expected_result);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, non_zero_all_1s) {
|
||||
PartialShape p_shape = PartialShape::dynamic();
|
||||
auto p = make_shared<op::Parameter>(element::i32, p_shape);
|
||||
auto non_zero = make_shared<op::v3::NonZero>(p, element::i64);
|
||||
auto fun = make_shared<Function>(OutputVector{non_zero}, ParameterVector{p});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
auto cfun = backend->compile(fun);
|
||||
|
||||
Shape input_shape{3, 2};
|
||||
vector<int32_t> input_data(shape_size(input_shape), 1);
|
||||
auto input = backend->create_tensor(element::i32, input_shape);
|
||||
copy_data(input, input_data);
|
||||
|
||||
std::vector<int64_t> expected_result{0, 0, 1, 1, 2, 2, 0, 1, 0, 1, 0, 1};
|
||||
Shape expected_output_shape{2, 6};
|
||||
|
||||
auto result = make_shared<HostTensor>();
|
||||
cfun->call_with_validate({result}, {input});
|
||||
|
||||
EXPECT_EQ(result->get_element_type(), element::i64);
|
||||
EXPECT_EQ(result->get_shape(), expected_output_shape);
|
||||
auto result_data = read_vector<int64_t>(result);
|
||||
ASSERT_EQ(result_data, expected_result);
|
||||
}
|
||||
|
||||
NGRAPH_TEST(${BACKEND_NAME}, non_zero_all_0s) {
|
||||
PartialShape p_shape = PartialShape::dynamic();
|
||||
auto p = make_shared<op::Parameter>(element::i32, p_shape);
|
||||
auto non_zero = make_shared<op::v3::NonZero>(p, element::i64);
|
||||
auto fun = make_shared<Function>(OutputVector{non_zero}, ParameterVector{p});
|
||||
|
||||
auto backend = runtime::Backend::create("${BACKEND_NAME}");
|
||||
auto cfun = backend->compile(fun);
|
||||
|
||||
Shape input_shape{3, 2};
|
||||
vector<int32_t> input_data(shape_size(input_shape), 0);
|
||||
auto input = backend->create_tensor(element::i32, input_shape);
|
||||
copy_data(input, input_data);
|
||||
|
||||
Shape expected_output_shape{input_shape.size(), 0};
|
||||
|
||||
auto result = make_shared<HostTensor>();
|
||||
cfun->call_with_validate({result}, {input});
|
||||
|
||||
EXPECT_EQ(result->get_element_type(), element::i64);
|
||||
EXPECT_EQ(result->get_shape(), expected_output_shape);
|
||||
auto result_data = read_vector<int64_t>(result);
|
||||
ASSERT_EQ(result_data.data(), nullptr);
|
||||
}
|
||||
Reference in New Issue
Block a user