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_ExpandDims)
23 std::vector<int32_t> axis_data{1};
24 uint32_t axis_buf = cgen.addBuffer(axis_data);
25 int in = cgen.addTensor({{1, 4, 1}, circle::TensorType::TensorType_FLOAT32});
26 int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
27 int out = cgen.addTensor({{1, 1, 4, 1}, circle::TensorType::TensorType_FLOAT32});
28 cgen.addOperatorExpandDims({{in, axis}, {out}});
29 cgen.setInputsAndOutputs({in}, {out});
31 _context = std::make_unique<GenModelTestContext>(cgen.finish());
32 _context->addTestCase(
33 TestCaseData{}.addInput<float>({0.1, 0.3, 0.5, 0.7}).addOutput<float>({0.1, 0.3, 0.5, 0.7}));
34 _context->setBackends({"cpu"});
39 TEST_F(GenModelTest, OneOp_ExpandDims_Int64AxisNeg)
43 std::vector<int64_t> axis_data{-1};
44 uint32_t axis_buf = cgen.addBuffer(axis_data);
45 int in = cgen.addTensor({{1, 4, 1}, circle::TensorType::TensorType_FLOAT32});
46 int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT64, axis_buf});
47 int out = cgen.addTensor({{1, 4, 1, 1}, circle::TensorType::TensorType_FLOAT32});
48 cgen.addOperatorExpandDims({{in, axis}, {out}});
49 cgen.setInputsAndOutputs({in}, {out});
51 _context = std::make_unique<GenModelTestContext>(cgen.finish());
52 _context->addTestCase(
53 TestCaseData{}.addInput<float>({0.1, 0.3, 0.5, 0.7}).addOutput<float>({0.1, 0.3, 0.5, 0.7}));
54 _context->setBackends({"cpu"});
59 TEST_F(GenModelTest, OneOp_neg_ExpandDims_Axis)
63 std::vector<int32_t> axis_data{4};
64 uint32_t axis_buf = cgen.addBuffer(axis_data);
65 int in = cgen.addTensor({{1, 4, 1}, circle::TensorType::TensorType_FLOAT32});
66 int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
67 int out = cgen.addTensor({{1, 1, 4, 1}, circle::TensorType::TensorType_FLOAT32});
68 cgen.addOperatorExpandDims({{in, axis}, {out}});
69 cgen.setInputsAndOutputs({in}, {out});
71 _context = std::make_unique<GenModelTestContext>(cgen.finish());
72 _context->setBackends({"cpu"});
73 _context->expectFailCompile();
78 TEST_F(GenModelTest, OneOp_neg_ExpandDims_AxisNegInput)
82 int in = cgen.addTensor({{1, 4, 1}, circle::TensorType::TensorType_FLOAT32});
83 int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32});
84 int out = cgen.addTensor({{1, 1, 4, 1}, circle::TensorType::TensorType_FLOAT32});
85 cgen.addOperatorExpandDims({{in, axis}, {out}});
86 cgen.setInputsAndOutputs({in, axis}, {out});
88 _context = std::make_unique<GenModelTestContext>(cgen.finish());
89 _context->addTestCase(TestCaseData{}
90 .addInput<float>({0.1, 0.3, 0.5, 0.7})
91 .addInput<int32_t>({-5})
92 .addOutput<float>({0.1, 0.3, 0.5, 0.7})
94 _context->setBackends({"cpu"});