Imported Upstream version 1.21.0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / one_op_tests / Neg.test.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_Neg_Float32)
20 {
21   CircleGen cgen;
22   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
23   int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
24   cgen.addOperatorNeg({{in}, {out}});
25   cgen.setInputsAndOutputs({in}, {out});
26
27   _context = std::make_unique<GenModelTestContext>(cgen.finish());
28   _context->addTestCase(uniformTCD<float>({{1.1, -2.2, 3.3, -4.4}}, {{-1.1, 2.2, -3.3, 4.4}}));
29   _context->setBackends({"cpu"});
30
31   SUCCEED();
32 }
33
34 TEST_F(GenModelTest, OneOp_Neg_Int32)
35 {
36   CircleGen cgen;
37   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
38   int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
39   cgen.addOperatorNeg({{in}, {out}});
40   cgen.setInputsAndOutputs({in}, {out});
41
42   _context = std::make_unique<GenModelTestContext>(cgen.finish());
43   _context->addTestCase(uniformTCD<int32_t>({{1, -2, 3, -4}}, {{-1, 2, -3, 4}}));
44   _context->setBackends({"cpu"});
45
46   SUCCEED();
47 }
48
49 TEST_F(GenModelTest, OneOp_Neg_Int64)
50 {
51   CircleGen cgen;
52   int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT64});
53   int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT64});
54   cgen.addOperatorNeg({{in}, {out}});
55   cgen.setInputsAndOutputs({in}, {out});
56
57   _context = std::make_unique<GenModelTestContext>(cgen.finish());
58   _context->addTestCase(uniformTCD<int64_t>({{1, -2, 3, -4}}, {{-1, 2, -3, 4}}));
59   _context->setBackends({"cpu"});
60
61   SUCCEED();
62 }
63
64 TEST_F(GenModelTest, neg_OneOp_Neg_Float32_TwoOperand)
65 {
66   CircleGen cgen;
67   int in1 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
68   int in2 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
69   int out1 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
70   int out2 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
71   cgen.addOperatorCos({{in1, in2}, {out1, out2}});
72   cgen.setInputsAndOutputs({in1, in2}, {out1, out2});
73
74   _context = std::make_unique<GenModelTestContext>(cgen.finish());
75   _context->setBackends({"cpu"});
76   _context->expectFailModelLoad();
77
78   SUCCEED();
79 }
80
81 TEST_F(GenModelTest, neg_OneOp_Neg_Int32_TwoOperand)
82 {
83   CircleGen cgen;
84   int in1 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
85   int in2 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
86   int out1 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
87   int out2 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
88   cgen.addOperatorCos({{in1, in2}, {out1, out2}});
89   cgen.setInputsAndOutputs({in1, in2}, {out1, out2});
90
91   _context = std::make_unique<GenModelTestContext>(cgen.finish());
92   _context->setBackends({"cpu"});
93   _context->expectFailModelLoad();
94
95   SUCCEED();
96 }
97
98 TEST_F(GenModelTest, neg_OneOp_Neg_Int64_TwoOperand)
99 {
100   CircleGen cgen;
101   int in1 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT64});
102   int in2 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT64});
103   int out1 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT64});
104   int out2 = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT64});
105   cgen.addOperatorCos({{in1, in2}, {out1, out2}});
106   cgen.setInputsAndOutputs({in1, in2}, {out1, out2});
107
108   _context = std::make_unique<GenModelTestContext>(cgen.finish());
109   _context->setBackends({"cpu"});
110   _context->expectFailModelLoad();
111
112   SUCCEED();
113 }