2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "GenModelTest.h"
19 TEST_F(GenModelTest, OneOp_Fill_Int32)
22 std::vector<int32_t> value_data{13};
23 uint32_t value_buf = cgen.addBuffer(value_data);
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});
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"});
39 TEST_F(GenModelTest, OneOp_Fill_Int64)
42 std::vector<int64_t> value_data{13};
43 uint32_t value_buf = cgen.addBuffer(value_data);
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});
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"});
59 TEST_F(GenModelTest, OneOp_Fill_Float32)
62 std::vector<float> value_data{1.3};
63 uint32_t value_buf = cgen.addBuffer(value_data);
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});
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"});
79 TEST_F(GenModelTest, neg_OneOp_Fill_Int32_oneoperand)
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});
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();
97 TEST_F(GenModelTest, neg_OneOp_Fill_Int64_oneoperand)
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});
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();
115 TEST_F(GenModelTest, neg_OneOp_Fill_Float32_oneoperand)
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});
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();