21201641840bbe81ec0443baf0702b7264fccdb0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / Split.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_Split)
20 {
21   CircleGen cgen;
22   int in = cgen.addTensor({{2, 4}, circle::TensorType::TensorType_FLOAT32});
23   std::vector<int32_t> axis_data{1};
24   uint32_t axis_buf = cgen.addBuffer(axis_data);
25   int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
26
27   int out1 = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_FLOAT32});
28   int out2 = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_FLOAT32});
29
30   cgen.addOperatorSplit({{axis, in}, {out1, out2}}, 2);
31   cgen.setInputsAndOutputs({in}, {out1, out2});
32
33   _context = std::make_unique<GenModelTestContext>(cgen.finish());
34   _context->addTestCase(
35       uniformTCD<float>({{1, 2, 3, 4, 5, 6, 7, 8}}, {{1, 2, 5, 6}, {3, 4, 7, 8}}));
36   _context->setBackends({"cpu", "acl_cl", "acl_neon"});
37
38   SUCCEED();
39 }
40
41 TEST_F(GenModelTest, OneOp_SplitNonConstAxis)
42 {
43   CircleGen cgen;
44   int in = cgen.addTensor({{2, 4}, circle::TensorType::TensorType_FLOAT32});
45   int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32});
46
47   int out1 = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_FLOAT32});
48   int out2 = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_FLOAT32});
49
50   cgen.addOperatorSplit({{axis, in}, {out1, out2}}, 2);
51   cgen.setInputsAndOutputs({axis, in}, {out1, out2});
52
53   _context = std::make_unique<GenModelTestContext>(cgen.finish());
54   _context->addTestCase(TestCaseData{}
55                             .addInput<int32_t>({1})
56                             .addInput<float>({1, 2, 3, 4, 5, 6, 7, 8})
57                             .addOutput<float>({1, 2, 5, 6})
58                             .addOutput<float>({3, 4, 7, 8}));
59   _context->setBackends({"cpu"});
60
61   SUCCEED();
62 }