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"
21 TEST_F(GenModelTest, OneOp_OneHot_OffValueToConst)
24 std::vector<int32_t> depth_data{3};
25 uint32_t depth_buf = cgen.addBuffer(depth_data);
26 std::vector<float> off_value_data{0};
27 uint32_t off_value_buf = cgen.addBuffer(off_value_data);
28 int indices = cgen.addTensor({{1, 2, 2}, circle::TensorType::TensorType_INT32});
29 int depth = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, depth_buf});
30 int on_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
31 int off_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32, off_value_buf});
33 int out = cgen.addTensor({{1, 2, 3, 2}, circle::TensorType::TensorType_FLOAT32});
34 cgen.addOperatorOneHot({{indices, depth, on_value, off_value}, {out}}, axis);
35 cgen.setInputsAndOutputs({indices, on_value}, {out});
37 _context = std::make_unique<GenModelTestContext>(cgen.finish());
38 _context->addTestCase(TestCaseData{}
39 .addInput<int32_t>({1, 2, 0, 2})
41 .addOutput<float>({0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1}));
42 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
47 TEST_F(GenModelTest, OneOp_OneHot_OffValueToNotZero)
50 std::vector<int32_t> depth_data{3};
51 uint32_t depth_buf = cgen.addBuffer(depth_data);
52 int indices = cgen.addTensor({{1, 2, 2}, circle::TensorType::TensorType_INT32});
53 int depth = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, depth_buf});
54 int on_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
55 int off_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
57 int out = cgen.addTensor({{1, 2, 3, 2}, circle::TensorType::TensorType_FLOAT32});
58 cgen.addOperatorOneHot({{indices, depth, on_value, off_value}, {out}}, axis);
59 cgen.setInputsAndOutputs({indices, on_value, off_value}, {out});
61 _context = std::make_unique<GenModelTestContext>(cgen.finish());
62 _context->addTestCase(TestCaseData{}
63 .addInput<int32_t>({1, 2, 0, 2})
65 .addInput<float>({-1})
66 .addOutput<float>({-1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1}));
67 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
72 TEST_F(GenModelTest, OneOp_OneHot_IndicesValueToNeg_OffValueToConst)
75 std::vector<int32_t> depth_data{3};
76 uint32_t depth_buf = cgen.addBuffer(depth_data);
77 std::vector<float> off_value_data{0};
78 uint32_t off_value_buf = cgen.addBuffer(off_value_data);
79 int indices = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_INT32});
80 int depth = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, depth_buf});
81 int on_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
82 int off_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32, off_value_buf});
84 int out = cgen.addTensor({{2, 2, 3}, circle::TensorType::TensorType_FLOAT32});
85 cgen.addOperatorOneHot({{indices, depth, on_value, off_value}, {out}}, axis);
86 cgen.setInputsAndOutputs({indices, on_value}, {out});
88 _context = std::make_unique<GenModelTestContext>(cgen.finish());
89 _context->addTestCase(TestCaseData{}
90 .addInput<int32_t>({1, 2, 0, -1})
92 .addOutput<float>({0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0}));
93 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
98 TEST_F(GenModelTest, OneOp_OneHot_IndicesValueToNeg_OffValueToVar)
101 std::vector<int32_t> depth_data{3};
102 uint32_t depth_buf = cgen.addBuffer(depth_data);
103 int indices = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_INT32});
104 int depth = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, depth_buf});
105 int on_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
106 int off_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
108 int out = cgen.addTensor({{2, 2, 3}, circle::TensorType::TensorType_FLOAT32});
109 cgen.addOperatorOneHot({{indices, depth, on_value, off_value}, {out}}, axis);
110 cgen.setInputsAndOutputs({indices, on_value, off_value}, {out});
112 _context = std::make_unique<GenModelTestContext>(cgen.finish());
113 _context->addTestCase(TestCaseData{}
114 .addInput<int32_t>({1, 2, 0, -1})
115 .addInput<float>({1})
116 .addInput<float>({0})
117 .addOutput<float>({0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0}));
118 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
123 TEST_F(GenModelTest, neg_OneOp_OneHot_OneOperand)
126 int indices = cgen.addTensor({{1, 2, 2}, circle::TensorType::TensorType_INT32});
128 int out = cgen.addTensor({{1, 2, 3, 2}, circle::TensorType::TensorType_FLOAT32});
129 cgen.addOperatorOneHot({{indices}, {out}}, axis);
130 cgen.setInputsAndOutputs({indices}, {out});
132 _context = std::make_unique<GenModelTestContext>(cgen.finish());
133 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
134 _context->expectFailModelLoad();
139 TEST_F(GenModelTest, neg_OneOp_OneHot_TwoOperands)
142 std::vector<int> depth_data{3};
143 uint32_t depth_buf = cgen.addBuffer(depth_data);
144 int indices = cgen.addTensor({{1, 2, 2}, circle::TensorType::TensorType_INT32});
145 int depth = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, depth_buf});
147 int out = cgen.addTensor({{1, 2, 3, 2}, circle::TensorType::TensorType_FLOAT32});
148 cgen.addOperatorOneHot({{indices, depth}, {out}}, axis);
149 cgen.setInputsAndOutputs({indices}, {out});
151 _context = std::make_unique<GenModelTestContext>(cgen.finish());
152 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
153 _context->expectFailModelLoad();
158 TEST_F(GenModelTest, neg_OneOp_OneHot_ThreeOperands)
161 std::vector<int> depth_data{3};
162 uint32_t depth_buf = cgen.addBuffer(depth_data);
163 int indices = cgen.addTensor({{1, 2, 2}, circle::TensorType::TensorType_INT32});
164 int depth = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, depth_buf});
165 int on_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
167 int out = cgen.addTensor({{1, 2, 3, 2}, circle::TensorType::TensorType_FLOAT32});
168 cgen.addOperatorOneHot({{indices, depth, on_value}, {out}}, axis);
169 cgen.setInputsAndOutputs({indices, on_value}, {out});
171 _context = std::make_unique<GenModelTestContext>(cgen.finish());
172 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
173 _context->expectFailModelLoad();
178 TEST_F(GenModelTest, neg_OneOp_OneHot_InvalidAxis)
181 std::vector<int> depth_data{3};
182 uint32_t depth_buf = cgen.addBuffer(depth_data);
183 int indices = cgen.addTensor({{1, 2, 2}, circle::TensorType::TensorType_INT32});
184 int depth = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, depth_buf});
185 int on_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
186 int off_value = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32});
188 int out = cgen.addTensor({{1, 2, 3, 2}, circle::TensorType::TensorType_FLOAT32});
189 cgen.addOperatorOneHot({{indices, depth, on_value, off_value}, {out}}, axis);
190 cgen.setInputsAndOutputs({indices, on_value, off_value}, {out});
192 _context = std::make_unique<GenModelTestContext>(cgen.finish());
193 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
194 _context->expectFailCompile();