63d02ab88d2cbe7fcb69ce5a9947c38a5fc7ee3f
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / Pad.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 TEST_F(GenModelTest, OneOp_Pad)
20 {
21   CircleGen cgen;
22   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
23   std::vector<int32_t> padding_data{0, 0, 1, 1, 1, 1, 0, 0};
24   uint32_t padding_buf = cgen.addBuffer(padding_data);
25   int padding = cgen.addTensor({{4, 2}, circle::TensorType::TensorType_INT32, padding_buf});
26   int out = cgen.addTensor({{1, 4, 4, 1}, circle::TensorType::TensorType_FLOAT32});
27
28   cgen.addOperatorPad({{in, padding}, {out}});
29   cgen.setInputsAndOutputs({in}, {out});
30   _context = std::make_unique<GenModelTestContext>(cgen.finish());
31   _context->addTestCase(
32       uniformTCD<float>({{1, 2, 3, 4}}, {{0, 0, 0, 0, 0, 1, 2, 0, 0, 3, 4, 0, 0, 0, 0, 0}}));
33   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
34
35   SUCCEED();
36 }
37
38 TEST_F(GenModelTest, neg_OneOp_Pad_InvalidPadRank)
39 {
40   CircleGen cgen;
41   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
42   std::vector<int32_t> padding_data{1, 1, 1, 1};
43   uint32_t padding_buf = cgen.addBuffer(padding_data);
44   int padding = cgen.addTensor({{4}, circle::TensorType::TensorType_INT32, padding_buf});
45   int out = cgen.addTensor({{1, 4, 4, 1}, circle::TensorType::TensorType_FLOAT32});
46
47   cgen.addOperatorPad({{in, padding}, {out}});
48   cgen.setInputsAndOutputs({in}, {out});
49
50   _context = std::make_unique<GenModelTestContext>(cgen.finish());
51   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
52   _context->expectFailCompile();
53
54   SUCCEED();
55 }
56
57 TEST_F(GenModelTest, neg_OneOp_Pad_InvalidPadDim0)
58 {
59   CircleGen cgen;
60   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
61   std::vector<int32_t> padding_data{1, 1, 1, 1};
62   uint32_t padding_buf = cgen.addBuffer(padding_data);
63   int padding = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_INT32, padding_buf});
64   int out = cgen.addTensor({{1, 4, 4, 1}, circle::TensorType::TensorType_FLOAT32});
65
66   cgen.addOperatorPad({{in, padding}, {out}});
67   cgen.setInputsAndOutputs({in}, {out});
68
69   _context = std::make_unique<GenModelTestContext>(cgen.finish());
70   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
71   _context->expectFailCompile();
72
73   SUCCEED();
74 }
75
76 TEST_F(GenModelTest, neg_OneOp_Pad_InvalidPadDim1)
77 {
78   CircleGen cgen;
79   int in = cgen.addTensor({{1, 1, 1, 1}, circle::TensorType::TensorType_FLOAT32});
80   std::vector<int32_t> padding_data{1, 1, 1, 1};
81   uint32_t padding_buf = cgen.addBuffer(padding_data);
82   int padding = cgen.addTensor({{4, 1}, circle::TensorType::TensorType_INT32, padding_buf});
83   int out = cgen.addTensor({{2, 2, 2, 2}, circle::TensorType::TensorType_FLOAT32});
84
85   cgen.addOperatorPad({{in, padding}, {out}});
86   cgen.setInputsAndOutputs({in}, {out});
87
88   _context = std::make_unique<GenModelTestContext>(cgen.finish());
89   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
90   _context->expectFailCompile();
91
92   SUCCEED();
93 }