blob: a335a48f818d79290a711363896180ea8b413cc3 [file] [log] [blame]
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +00001/*
2 * Copyright (c) 2023 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010024#ifndef CKW_TESTS_UTILSTEST_H
25#define CKW_TESTS_UTILSTEST_H
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000026
27#include "ckw/TensorInfo.h"
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010028#include "ckw/types/TensorDataLayout.h"
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000029#include "common/Common.h"
Nikolaj Jensenacea4072023-07-03 09:44:42 +010030#include "src/TensorUtils.h"
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000031
32#include <vector>
33
34namespace ckw
35{
36class UtilsTest : public ITest
37{
38public:
39 UtilsTest()
40 {
41 _layout.push_back(TensorDataLayout::Nhwc);
42 _layout.push_back(TensorDataLayout::Nhwc);
43 _layout.push_back(TensorDataLayout::Nhwc);
44 _layout.push_back(TensorDataLayout::Nhwc);
45 _layout.push_back(TensorDataLayout::Ndhwc);
46 _layout.push_back(TensorDataLayout::Ndhwc);
47 _layout.push_back(TensorDataLayout::Ndhwc);
48 _layout.push_back(TensorDataLayout::Ndhwc);
49 _layout.push_back(TensorDataLayout::Ndhwc);
50
51 _component.push_back(TensorDataLayoutComponent::N);
52 _component.push_back(TensorDataLayoutComponent::H);
53 _component.push_back(TensorDataLayoutComponent::W);
54 _component.push_back(TensorDataLayoutComponent::C);
55 _component.push_back(TensorDataLayoutComponent::N);
56 _component.push_back(TensorDataLayoutComponent::D);
57 _component.push_back(TensorDataLayoutComponent::H);
58 _component.push_back(TensorDataLayoutComponent::W);
59 _component.push_back(TensorDataLayoutComponent::C);
60
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010061 _expected.push_back(TensorComponentType::Dim3);
62 _expected.push_back(TensorComponentType::Dim2);
63 _expected.push_back(TensorComponentType::Dim1);
64 _expected.push_back(TensorComponentType::Dim0);
65 _expected.push_back(TensorComponentType::Dim4);
66 _expected.push_back(TensorComponentType::Dim3);
67 _expected.push_back(TensorComponentType::Dim2);
68 _expected.push_back(TensorComponentType::Dim1);
69 _expected.push_back(TensorComponentType::Dim0);
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000070 }
71
72 bool run() override
73 {
74 // The status of this variable can change in VALIDATE_TEST()
75 bool all_tests_passed = true;
76
77 VALIDATE_ON_MSG(_layout.size() == _component.size(), "The number of layouts and components does not match");
Nikolaj Jensenacea4072023-07-03 09:44:42 +010078 VALIDATE_ON_MSG(_layout.size() == _expected.size(),
79 "The number of layouts and expected outputs does not match");
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000080 const size_t num_tests = _layout.size();
81 for(size_t i = 0; i < num_tests; ++i)
82 {
83 const TensorDataLayout layout = _layout[i];
84 const TensorDataLayoutComponent component = _component[i];
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +010085 const TensorComponentType expected = _expected[i];
86 const TensorComponentType out = get_tensor_dimension(layout, component);
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +000087 VALIDATE_TEST(out == expected, all_tests_passed, i);
88 }
89 return all_tests_passed;
90 }
91
92 std::string name() override
93 {
94 return "UtilsTest";
95 }
96
97private:
Nikolaj Jensenacea4072023-07-03 09:44:42 +010098 std::vector<TensorDataLayout> _layout{};
99 std::vector<TensorDataLayoutComponent> _component{};
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100100 std::vector<TensorComponentType> _expected{};
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +0000101};
Nikolaj Jensenacea4072023-07-03 09:44:42 +0100102} // namespace ckw
Gian Marco Iodice6c113ed2023-01-19 17:14:26 +0000103
Gian Marco Iodiceebfdb5a2023-07-07 11:25:57 +0100104#endif // CKW_TESTS_UTILSTEST_H