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 struct FillVariationParam
22 const uint8_t *value_data = nullptr;
23 circle::TensorType data_type = circle::TensorType::TensorType_FLOAT32;
26 class FillVariation : public GenModelTest, public ::testing::WithParamInterface<FillVariationParam>
31 TEST_P(FillVariation, Test)
33 auto ¶m = GetParam();
38 (param.data_type == circle::TensorType::TensorType_INT64) ? sizeof(int64_t) : sizeof(int32_t);
39 uint32_t value_buf = cgen.addBuffer(param.value_data, value_size);
41 int dims = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
42 int value = cgen.addTensor({{1}, param.data_type, value_buf});
43 int out = cgen.addTensor({{2, 3}, param.data_type});
44 cgen.addOperatorFill({{dims, value}, {out}});
45 cgen.setInputsAndOutputs({dims}, {out});
47 _context = std::make_unique<GenModelTestContext>(cgen.finish());
48 _context->addTestCase(param.tcd);
49 _context->setBackends({"cpu"});
54 const int32_t test_int32 = 13;
55 const int64_t test_int64 = 1052;
56 const float test_float = 5.2;
58 // Test with different value type
59 INSTANTIATE_TEST_CASE_P(
60 GenModelTest, FillVariation,
64 TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<float>({5.2, 5.2, 5.2, 5.2, 5.2, 5.2}),
65 reinterpret_cast<const uint8_t *>(&test_float)},
68 TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<int32_t>({13, 13, 13, 13, 13, 13}),
69 reinterpret_cast<const uint8_t *>(&test_int32), circle::TensorType::TensorType_INT32},
72 TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<int64_t>({1052, 1052, 1052, 1052, 1052,
74 reinterpret_cast<const uint8_t *>(&test_int64), circle::TensorType::TensorType_INT64}));
76 TEST_F(GenModelTest, OneOp_Fill_Int64_Shape)
79 std::vector<float> value_data{1.3};
80 uint32_t value_buf = cgen.addBuffer(value_data);
82 int dims = cgen.addTensor({{2}, circle::TensorType::TensorType_INT64});
83 int value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32, value_buf});
84 int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_FLOAT32});
85 cgen.addOperatorFill({{dims, value}, {out}});
86 cgen.setInputsAndOutputs({dims}, {out});
88 _context = std::make_unique<GenModelTestContext>(cgen.finish());
89 _context->addTestCase(
90 TestCaseData{}.addInput<int64_t>({2, 3}).addOutput<float>({1.3, 1.3, 1.3, 1.3, 1.3, 1.3}));
91 _context->setBackends({"cpu"});
96 TEST_F(GenModelTest, neg_OneOp_Fill_Int32_oneoperand)
100 int in = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
101 int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_INT32});
102 cgen.addOperatorFill({{in}, {out}});
103 cgen.setInputsAndOutputs({in}, {out});
105 _context = std::make_unique<GenModelTestContext>(cgen.finish());
106 _context->addTestCase(
107 TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<int32_t>({13, 13, 13, 13, 13, 13}));
108 _context->setBackends({"cpu"});
109 _context->expectFailModelLoad();
114 TEST_F(GenModelTest, neg_OneOp_Fill_Int64_oneoperand)
118 int in = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
119 int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_INT64});
120 cgen.addOperatorFill({{in}, {out}});
121 cgen.setInputsAndOutputs({in}, {out});
123 _context = std::make_unique<GenModelTestContext>(cgen.finish());
124 _context->addTestCase(
125 TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<int64_t>({13, 13, 13, 13, 13, 13}));
126 _context->setBackends({"cpu"});
127 _context->expectFailModelLoad();
132 TEST_F(GenModelTest, neg_OneOp_Fill_Float32_oneoperand)
136 int in = cgen.addTensor({{2}, circle::TensorType::TensorType_INT32});
137 int out = cgen.addTensor({{2, 3}, circle::TensorType::TensorType_FLOAT32});
138 cgen.addOperatorFill({{in}, {out}});
139 cgen.setInputsAndOutputs({in}, {out});
141 _context = std::make_unique<GenModelTestContext>(cgen.finish());
142 _context->addTestCase(
143 TestCaseData{}.addInput<int32_t>({2, 3}).addOutput<float>({1.3, 1.3, 1.3, 1.3, 1.3, 1.3}));
144 _context->setBackends({"cpu"});
145 _context->expectFailModelLoad();