cf8948d912d0f9ea824f5442901248697585273a
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / Fill.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_Fill_Int32)
20 {
21   CircleGen cgen;
22   std::vector<int32_t> value_data{13};
23   uint32_t value_buf = cgen.addBuffer(value_data);
24
25   int in = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
26   int value = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, value_buf});
27   int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_INT32});
28   cgen.addOperatorFill({{in, value}, {out}});
29   cgen.setInputsAndOutputs({in}, {out});
30
31   _context = std::make_unique<GenModelTestContext>(cgen.finish());
32   _context->addTestCase(
33       TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<int32_t>({13, 13, 13, 13, 13, 13}));
34   _context->setBackends({"cpu"});
35
36   SUCCEED();
37 }
38
39 TEST_F(GenModelTest, OneOp_Fill_Int64)
40 {
41   CircleGen cgen;
42   std::vector<int64_t> value_data{13};
43   uint32_t value_buf = cgen.addBuffer(value_data);
44
45   int in = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
46   int value = cgen.addTensor({{1}, circle::TensorType::TensorType_INT64, value_buf});
47   int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_INT64});
48   cgen.addOperatorFill({{in, value}, {out}});
49   cgen.setInputsAndOutputs({in}, {out});
50
51   _context = std::make_unique<GenModelTestContext>(cgen.finish());
52   _context->addTestCase(
53       TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<int64_t>({13, 13, 13, 13, 13, 13}));
54   _context->setBackends({"cpu"});
55
56   SUCCEED();
57 }
58
59 TEST_F(GenModelTest, OneOp_Fill_Float32)
60 {
61   CircleGen cgen;
62   std::vector<float> value_data{1.3};
63   uint32_t value_buf = cgen.addBuffer(value_data);
64
65   int in = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
66   int value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32, value_buf});
67   int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_FLOAT32});
68   cgen.addOperatorFill({{in, value}, {out}});
69   cgen.setInputsAndOutputs({in}, {out});
70
71   _context = std::make_unique<GenModelTestContext>(cgen.finish());
72   _context->addTestCase(
73       TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<float>({1.3, 1.3, 1.3, 1.3, 1.3, 1.3}));
74   _context->setBackends({"cpu"});
75
76   SUCCEED();
77 }
78
79 TEST_F(GenModelTest, neg_OneOp_Fill_Int32_oneoperand)
80 {
81   CircleGen cgen;
82
83   int in = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
84   int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_INT32});
85   cgen.addOperatorFill({{in}, {out}});
86   cgen.setInputsAndOutputs({in}, {out});
87
88   _context = std::make_unique<GenModelTestContext>(cgen.finish());
89   _context->addTestCase(
90       TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<int32_t>({13, 13, 13, 13, 13, 13}));
91   _context->setBackends({"cpu"});
92   _context->expectFailModelLoad();
93
94   SUCCEED();
95 }
96
97 TEST_F(GenModelTest, neg_OneOp_Fill_Int64_oneoperand)
98 {
99   CircleGen cgen;
100
101   int in = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
102   int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_INT64});
103   cgen.addOperatorFill({{in}, {out}});
104   cgen.setInputsAndOutputs({in}, {out});
105
106   _context = std::make_unique<GenModelTestContext>(cgen.finish());
107   _context->addTestCase(
108       TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<int64_t>({13, 13, 13, 13, 13, 13}));
109   _context->setBackends({"cpu"});
110   _context->expectFailModelLoad();
111
112   SUCCEED();
113 }
114
115 TEST_F(GenModelTest, neg_OneOp_Fill_Float32_oneoperand)
116 {
117   CircleGen cgen;
118
119   int in = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
120   int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_FLOAT32});
121   cgen.addOperatorFill({{in}, {out}});
122   cgen.setInputsAndOutputs({in}, {out});
123
124   _context = std::make_unique<GenModelTestContext>(cgen.finish());
125   _context->addTestCase(
126       TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<float>({1.3, 1.3, 1.3, 1.3, 1.3, 1.3}));
127   _context->setBackends({"cpu"});
128   _context->expectFailModelLoad();
129
130   SUCCEED();
131 }