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"
21 TEST_F(GenModelTest, OneOp_ArgMax_AxisToConst)
24 const auto output_type = circle::TensorType::TensorType_INT32;
25 std::vector<int32_t> axis_data{1};
26 uint32_t axis_buf = cgen.addBuffer(axis_data);
27 int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
28 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
29 int out = cgen.addTensor({{1, 2, 1}, output_type});
30 cgen.addOperatorArgMax({{in, axis}, {out}}, output_type);
31 cgen.setInputsAndOutputs({in}, {out});
33 _context = std::make_unique<GenModelTestContext>(cgen.finish());
34 _context->addTestCase(TestCaseData{}.addInput<float>({1, 4, 2, 3}).addOutput<int32_t>({1, 0}));
35 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
40 TEST_F(GenModelTest, OneOp_ArgMax_Int64_AxisToConst)
43 const auto output_type = circle::TensorType::TensorType_INT64;
44 std::vector<int32_t> axis_data{1};
45 uint32_t axis_buf = cgen.addBuffer(axis_data);
46 int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
47 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
48 int out = cgen.addTensor({{1, 2, 1}, output_type});
49 cgen.addOperatorArgMax({{in, axis}, {out}}, output_type);
50 cgen.setInputsAndOutputs({in}, {out});
52 _context = std::make_unique<GenModelTestContext>(cgen.finish());
53 _context->addTestCase(TestCaseData{}.addInput<float>({1, 4, 2, 3}).addOutput<int64_t>({1, 0}));
54 _context->setBackends({"acl_cl"});
59 TEST_F(GenModelTest, OneOp_ArgMax_AxisToVar)
62 const auto output_type = circle::TensorType::TensorType_INT32;
63 int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32});
64 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
65 int out = cgen.addTensor({{1, 2, 1}, output_type});
66 cgen.addOperatorArgMax({{in, axis}, {out}}, output_type);
67 cgen.setInputsAndOutputs({in, axis}, {out});
69 _context = std::make_unique<GenModelTestContext>(cgen.finish());
70 _context->addTestCase(TestCaseData{}
71 .addInput<float>({1, 4, 2, 3})
72 .addInput<int32_t>({-3})
73 .addOutput<int32_t>({1, 0}));
74 _context->setBackends({"cpu"});
79 TEST_F(GenModelTest, neg_OneOp_ArgMax_InvalidAxis0)
82 const auto output_type = circle::TensorType::TensorType_INT32;
83 std::vector<int32_t> axis_data{4};
84 uint32_t axis_buf = cgen.addBuffer(axis_data);
85 int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
86 int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
87 int out = cgen.addTensor({{1, 2, 1}, output_type});
88 cgen.addOperatorArgMax({{in, axis}, {out}}, output_type);
89 cgen.setInputsAndOutputs({in}, {out});
91 _context = std::make_unique<GenModelTestContext>(cgen.finish());
92 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
93 _context->expectFailCompile();
98 TEST_F(GenModelTest, neg_OneOp_ArgMax_InvalidAxis1)
101 const auto output_type = circle::TensorType::TensorType_INT32;
102 std::vector<int32_t> axis_data{-3};
103 uint32_t axis_buf = cgen.addBuffer(axis_data);
104 int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
105 int in = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_FLOAT32});
106 int out = cgen.addTensor({{2}, output_type});
107 cgen.addOperatorArgMax({{in, axis}, {out}}, output_type);
108 cgen.setInputsAndOutputs({in}, {out});
110 _context = std::make_unique<GenModelTestContext>(cgen.finish());
111 _context->setBackends({"acl_cl", "acl_neon", "cpu"});
112 _context->expectFailCompile();