ef0c5fe825a36b5f53dc81a6f289906ec5ce5343
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / Reverse.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_ReverseV2_3D)
20 {
21   CircleGen cgen;
22
23   int in = cgen.addTensor({{4, 3, 2}, circle::TensorType::TensorType_FLOAT32});
24   std::vector<int32_t> axis_data{1};
25   uint32_t axis_buf = cgen.addBuffer(axis_data);
26   int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
27   int out = cgen.addTensor({{4, 3, 2}, circle::TensorType::TensorType_FLOAT32});
28
29   cgen.addOperatorReverseV2({{in, axis}, {out}});
30   cgen.setInputsAndOutputs({in}, {out});
31
32   _context = std::make_unique<GenModelTestContext>(cgen.finish());
33   _context->setBackends({"acl_cl", "cpu"});
34   _context->addTestCase(uniformTCD<float>(
35       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}},
36       {{5, 6, 3, 4, 1, 2, 11, 12, 9, 10, 7, 8, 17, 18, 15, 16, 13, 14, 23, 24, 21, 22, 19, 20}}));
37
38   SUCCEED();
39 }
40
41 TEST_F(GenModelTest, OneOp_ReverseV2_1D)
42 {
43   CircleGen cgen;
44
45   int in = cgen.addTensor({{4}, circle::TensorType::TensorType_FLOAT32});
46   std::vector<int32_t> axis_data{0};
47   uint32_t axis_buf = cgen.addBuffer(axis_data);
48   int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
49   int out = cgen.addTensor({{4}, circle::TensorType::TensorType_FLOAT32});
50
51   cgen.addOperatorReverseV2({{in, axis}, {out}});
52   cgen.setInputsAndOutputs({in}, {out});
53
54   _context = std::make_unique<GenModelTestContext>(cgen.finish());
55   _context->setBackends({"acl_cl", "cpu"});
56   _context->addTestCase(uniformTCD<float>({{1, 2, 3, 4}}, {{4, 3, 2, 1}}));
57
58   SUCCEED();
59 }