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 struct EqualVariationParam
22 circle::TensorType input_type = circle::TensorType::TensorType_FLOAT32;
23 const std::vector<std::string> backends = {"acl_cl", "acl_neon", "cpu"};
26 class EqualVariation : public GenModelTest,
27 public ::testing::WithParamInterface<EqualVariationParam>
33 // Brodcast: {1} on of two input
34 // Output shape: {1, 2, 2, 1}
35 // Input type: Non-quantization type
37 // Test with different input type and value
38 INSTANTIATE_TEST_SUITE_P(GenModelTest, EqualVariation,
41 EqualVariationParam{TestCaseData{}
42 .addInput<float>({0.1, 0.3, 0.5, 0.7})
43 .addInput<float>({0.1, 0.2, 0.3, 0.4})
44 .addOutput<bool>({true, false, false, false})},
45 // Float type - broadcast
46 EqualVariationParam{TestCaseData{}
47 .addInput<float>({0.1, 0.3, 0.5, 0.7})
48 .addInput<float>({0.3})
49 .addOutput<bool>({false, true, false, false})},
51 EqualVariationParam{TestCaseData{}
52 .addInput<int32_t>({1, 3, 5, 7})
53 .addInput<int32_t>({1, 2, 3, 4})
54 .addOutput<bool>({true, false, false, false}),
55 circle::TensorType::TensorType_INT32},
56 // Int32 type - broadcast
57 EqualVariationParam{TestCaseData{}
58 .addInput<int32_t>({1, 3, 5, 7})
59 .addInput<int32_t>({5})
60 .addOutput<bool>({false, false, true, false}),
61 circle::TensorType::TensorType_INT32},
64 EqualVariationParam{TestCaseData{}
65 .addInput<int64_t>({1, 3, 5, 7})
66 .addInput<int64_t>({1, 2, 3, 4})
67 .addOutput<bool>({true, false, false, false}),
68 circle::TensorType::TensorType_INT64,
70 // Int64 type - broadcast
72 EqualVariationParam{TestCaseData{}
73 .addInput<int64_t>({1, 3, 5, 7})
74 .addInput<int64_t>({1})
75 .addOutput<bool>({true, false, false, false}),
76 circle::TensorType::TensorType_INT64,
79 EqualVariationParam{TestCaseData{}
80 .addInput<bool>({true, true, false, false})
81 .addInput<bool>({true, false, true, false})
82 .addOutput<bool>({true, false, false, true}),
83 circle::TensorType::TensorType_BOOL},
84 // Bool type - broadcast
85 EqualVariationParam{TestCaseData{}
86 .addInput<bool>({true, true, false, false})
87 .addInput<bool>({true})
88 .addOutput<bool>({true, true, false, false}),
89 circle::TensorType::TensorType_BOOL}
93 TEST_P(EqualVariation, Test)
95 auto ¶m = GetParam();
97 auto lhs_data = param.tcd.inputs.at(0);
98 auto rhs_data = param.tcd.inputs.at(1);
100 bool broadcast_lhs = false;
101 bool broadcast_rhs = false;
102 if (lhs_data.size() != rhs_data.size())
104 if (lhs_data.size() < rhs_data.size())
105 broadcast_lhs = true;
107 broadcast_rhs = true;
111 const auto output_type = circle::TensorType::TensorType_BOOL;
113 int lhs = broadcast_lhs ? cgen.addTensor({{1}, param.input_type})
114 : cgen.addTensor({{1, 2, 2, 1}, param.input_type});
115 int rhs = broadcast_rhs ? cgen.addTensor({{1}, param.input_type})
116 : cgen.addTensor({{1, 2, 2, 1}, param.input_type});
117 int out = cgen.addTensor({{1, 2, 2, 1}, output_type});
118 cgen.addOperatorEqual({{lhs, rhs}, {out}});
119 cgen.setInputsAndOutputs({lhs, rhs}, {out});
121 _context = std::make_unique<GenModelTestContext>(cgen.finish());
122 _context->addTestCase(param.tcd);
123 _context->setBackends(param.backends);
128 TEST_F(GenModelTest, neg_OneOp_Equal_DifferentType)
131 int lhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
132 int rhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
133 int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_BOOL});
134 cgen.addOperatorEqual({{lhs, rhs}, {out}});
135 cgen.setInputsAndOutputs({lhs, rhs}, {out});
137 _context = std::make_unique<GenModelTestContext>(cgen.finish());
138 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
139 _context->expectFailModelLoad();
144 TEST_F(GenModelTest, neg_OneOp_Equal_InvalidType)
147 int lhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
148 int rhs = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
149 int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_INT32});
150 cgen.addOperatorEqual({{lhs, rhs}, {out}});
151 cgen.setInputsAndOutputs({lhs, rhs}, {out});
153 _context = std::make_unique<GenModelTestContext>(cgen.finish());
154 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
155 _context->expectFailModelLoad();