437cfd1e7e893d8b8eb2907755d81a381d438e6d
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / ResizeBilinear.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 #include <memory>
20
21 TEST_F(GenModelTest, OneOp_ResizeBilinear_SizeToConst)
22 {
23   CircleGen cgen;
24   std::vector<int32_t> size_data{3, 3};
25   uint32_t size_buf = cgen.addBuffer(size_data);
26   int size = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, size_buf});
27   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
28   int out = cgen.addTensor({{1, 3, 3, 1}, circle::TensorType::TensorType_FLOAT32});
29   cgen.addOperatorResizeBilinear({{in, size}, {out}});
30   cgen.setInputsAndOutputs({in}, {out});
31
32   _context = std::make_unique<GenModelTestContext>(cgen.finish());
33   _context->addTestCase(uniformTCD<float>(
34       {{1, 1, 2, 2}}, {{1, 1, 1, 1.666666667, 1.666666667, 1.666666667, 2, 2, 2}}));
35   _context->setBackends({"acl_cl", "acl_neon", "cpu"});
36
37   SUCCEED();
38 }
39
40 TEST_F(GenModelTest, OneOp_ResizeBilinear_SizeToVar)
41 {
42   CircleGen cgen;
43   int size = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
44   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
45   int out = cgen.addTensor({{1, 2, 1}, circle::TensorType::TensorType_FLOAT32});
46   cgen.addOperatorResizeBilinear({{in, size}, {out}});
47   cgen.setInputsAndOutputs({in, size}, {out});
48
49   _context = std::make_unique<GenModelTestContext>(cgen.finish());
50   // FIXME enable a test case the below is not a valid test case
51   //_context->addTestCase(TestCaseData{}.addInput<int32_t>({3, 3}).addInput<float>({1, 1, 2,
52   // 2}).addOutput<float>({1, 1, 1, 1.666666667, 1.666666667, 1.666666667, 2, 2, 2}));
53   _context->setBackends({"cpu"});
54
55   SUCCEED();
56 }
57
58 TEST_F(GenModelTest, neg_OneOp_ResizeBilinear_InvalidSizeVal)
59 {
60   CircleGen cgen;
61   std::vector<int32_t> size_data{-3, 3};
62   uint32_t size_buf = cgen.addBuffer(size_data);
63   int size = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, size_buf});
64   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
65   int out = cgen.addTensor({{1, 2, 1}, circle::TensorType::TensorType_FLOAT32});
66   cgen.addOperatorResizeBilinear({{in, size}, {out}});
67   cgen.setInputsAndOutputs({in}, {out});
68
69   _context = std::make_unique<GenModelTestContext>(cgen.finish());
70   _context->setBackends({"cpu"});
71   _context->expectFailCompile();
72
73   SUCCEED();
74 }