Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / Rank.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 // WORKAROUND Handle int32_t type input/output
20 union float_int {
21   int32_t i;
22   float f;
23 };
24
25 TEST_F(GenModelTest, OneOp_Rank)
26 {
27   CircleGen cgen;
28   int in = cgen.addTensor({{1, 3, 3, 2}, circle::TensorType::TensorType_FLOAT32});
29   int out = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32});
30
31   // TODO handle many type in addTestCase
32   float_int output_data;
33   output_data.i = 4;
34
35   cgen.addOperatorRank({{in}, {out}});
36   cgen.setInputsAndOutputs({in}, {out});
37   _context = std::make_unique<GenModelTestContext>(cgen.finish());
38   _context->addTestCase(
39       {{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}}, {{output_data.f}}});
40   _context->setBackends({"cpu"});
41
42   SUCCEED();
43 }
44
45 TEST_F(GenModelTest, OneOp_Rank_Int32)
46 {
47   CircleGen cgen;
48   int in = cgen.addTensor({{1, 3, 3, 2}, circle::TensorType::TensorType_INT32});
49   int out = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32});
50
51   // TODO handle many type in addTestCase
52   float_int output_data;
53   output_data.i = 4;
54
55   cgen.addOperatorRank({{in}, {out}});
56   cgen.setInputsAndOutputs({in}, {out});
57   _context = std::make_unique<GenModelTestContext>(cgen.finish());
58   _context->addTestCase(
59       {{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}}, {{output_data.f}}});
60   _context->setBackends({"cpu"});
61
62   SUCCEED();
63 }