Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / DepthToSpace.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "GenModelTest.h"
18
19 struct DepthToSpaceVariationParam
20 {
21   TestCaseData tcd;
22   circle::TensorType type = circle::TensorType::TensorType_FLOAT32;
23   float scale = 0.0f;
24   int64_t zero_point = 0;
25 };
26
27 class DepthToSpaceVariation : public GenModelTest,
28                               public ::testing::WithParamInterface<DepthToSpaceVariationParam>
29 {
30 };
31
32 INSTANTIATE_TEST_CASE_P(
33   GenModelTest, DepthToSpaceVariation,
34   ::testing::Values(
35     // Float
36     DepthToSpaceVariationParam{
37       uniformTCD<float>({{1, 2, 3, 4, 5, 6, 7, 8}}, {{1, 2, 5, 6, 3, 4, 7, 8}})},
38     // Int32
39     DepthToSpaceVariationParam{
40       uniformTCD<int32_t>({{1, 2, 3, 4, 5, 6, 7, 8}}, {{1, 2, 5, 6, 3, 4, 7, 8}}),
41       circle::TensorType::TensorType_INT32},
42     // Int64
43     DepthToSpaceVariationParam{
44       uniformTCD<int64_t>({{1, 2, 3, 4, 5, 6, 7, 8}}, {{1, 2, 5, 6, 3, 4, 7, 8}}),
45       circle::TensorType::TensorType_INT64},
46     // Uint8
47     DepthToSpaceVariationParam{
48       uniformTCD<uint8_t>({{1, 2, 3, 4, 5, 6, 7, 8}}, {{1, 2, 5, 6, 3, 4, 7, 8}}),
49       circle::TensorType::TensorType_UINT8, 1.0f, -2},
50     // Int8
51     DepthToSpaceVariationParam{
52       uniformTCD<int8_t>({{1, 2, 3, 4, 5, 6, 7, 8}}, {{1, 2, 5, 6, 3, 4, 7, 8}}),
53       circle::TensorType::TensorType_INT8, 1.0f, -2}));
54
55 // Input shape: {1, 1, 2, 4}
56 // Block size: 2
57 // Output shape: {1, 2, 4, 1}
58 TEST_P(DepthToSpaceVariation, Test)
59 {
60   auto &param = GetParam();
61
62   CircleGen cgen;
63   int in = cgen.addTensor({{1, 1, 2, 4}, param.type}, param.scale, param.zero_point);
64   int out = cgen.addTensor({{1, 2, 4, 1}, param.type}, param.scale, param.zero_point);
65   cgen.addOperatorDepthToSpace({{in}, {out}}, 2);
66   cgen.setInputsAndOutputs({in}, {out});
67
68   _context = std::make_unique<GenModelTestContext>(cgen.finish());
69   _context->addTestCase(param.tcd);
70   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
71
72   SUCCEED();
73 }
74
75 TEST_F(GenModelTest, neg_OneOp_DepthToSpace_Blocksize)
76 {
77   CircleGen cgen;
78   circle::TensorType data_type = circle::TensorType::TensorType_FLOAT32;
79   int in = cgen.addTensor({{1, 1, 2, 4}, data_type});
80   int out = cgen.addTensor({{1, 2, 4, 1}, data_type});
81   cgen.addOperatorDepthToSpace({{in}, {out}}, -2);
82   cgen.setInputsAndOutputs({in}, {out});
83
84   _context = std::make_unique<GenModelTestContext>(cgen.finish());
85   _context->expectFailModelLoad();
86
87   SUCCEED();
88 }