blob: 5a930620ceaa83c0899d3878ff013fee8b4d1395 [file] [log] [blame]
Georgios Pinitas0b5af9f2020-06-19 23:22:08 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2020 Arm Limited.
Georgios Pinitas0b5af9f2020-06-19 23:22:08 +01003 *
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 */
24#include "arm_compute/core/SubTensorInfo.h"
25#include "arm_compute/core/TensorInfo.h"
26#include "arm_compute/core/Types.h"
27#include "tests/framework/Asserts.h"
28#include "tests/framework/Macros.h"
29#include "tests/validation/Validation.h"
30#include "utils/TypePrinter.h"
31
32namespace arm_compute
33{
34namespace test
35{
36namespace validation
37{
38TEST_SUITE(UNIT)
39TEST_SUITE(SubTensorInfo)
40
41/** Validate sub-tensor creation
42 *
43 * Test performed:
44 *
45 * - Negative testing on X indexing
46 * - Negative testing on Y indexing
47 * - Positive testing by indexing on X,Y indexing
48 * */
49TEST_CASE(SubTensorCreation, framework::DatasetMode::ALL)
50{
51 // Create tensor info
52 TensorInfo info(TensorShape(23U, 17U, 3U), 1, DataType::F32);
53
54 // Negative testing on X
55 ARM_COMPUTE_EXPECT_THROW(SubTensorInfo(&info, TensorShape(13U, 17U, 3U), Coordinates(24, 0, 0)), framework::LogLevel::ERRORS);
56 ARM_COMPUTE_EXPECT_THROW(SubTensorInfo(&info, TensorShape(13U, 17U, 3U), Coordinates(15, 0, 0)), framework::LogLevel::ERRORS);
57
58 // Negative testing on Y
59 ARM_COMPUTE_EXPECT_THROW(SubTensorInfo(&info, TensorShape(23U, 8U, 3U), Coordinates(0, 18, 0)), framework::LogLevel::ERRORS);
60 ARM_COMPUTE_EXPECT_THROW(SubTensorInfo(&info, TensorShape(23U, 8U, 3U), Coordinates(0, 13, 0)), framework::LogLevel::ERRORS);
61
62 // Positive testing on XY indexing
63 ARM_COMPUTE_EXPECT_NO_THROW(SubTensorInfo(&info, TensorShape(4U, 3U, 2U), Coordinates(5, 2, 1)), framework::LogLevel::ERRORS);
64}
65
66/** Validate when extending padding on sub-tensor
67 *
68 * Tests performed:
69 * - A) Extend padding when SubTensor XY does not match parent tensor should fail
70 * B) Extend with zero padding when SubTensor XY does not match parent tensor should succeed
71 * - C) Extend padding when SubTensor XY matches parent tensor should succeed
72 */
73TEST_CASE(SubTensorPaddingExpansion, framework::DatasetMode::ALL)
74{
75 // Test A
76 {
77 TensorInfo tensor_info(TensorShape(23U, 17U, 3U), 1, DataType::F32);
78 SubTensorInfo sub_tensor_info(&tensor_info, TensorShape(4U, 3U, 2U), Coordinates(5, 2, 1));
79 ARM_COMPUTE_EXPECT_THROW(sub_tensor_info.extend_padding(PaddingSize(2, 1)), framework::LogLevel::ERRORS);
80 }
81
82 // Test B
83 {
84 TensorInfo tensor_info(TensorShape(23U, 17U, 3U), 1, DataType::F32);
85 SubTensorInfo sub_tensor_info(&tensor_info, TensorShape(4U, 3U, 1U), Coordinates(5, 2, 1));
86 ARM_COMPUTE_EXPECT_NO_THROW(sub_tensor_info.extend_padding(PaddingSize(0, 0)), framework::LogLevel::ERRORS);
87 ARM_COMPUTE_EXPECT(tensor_info.padding().uniform(), framework::LogLevel::ERRORS);
88 }
89
90 // Test C
91 {
92 TensorInfo tensor_info(TensorShape(23U, 17U, 3U), 1, DataType::F32);
93 SubTensorInfo sub_tensor_info(&tensor_info, TensorShape(23U, 17U, 1U), Coordinates(0, 0, 1));
94 ARM_COMPUTE_EXPECT_NO_THROW(sub_tensor_info.extend_padding(PaddingSize(2, 1)), framework::LogLevel::ERRORS);
95 ARM_COMPUTE_EXPECT(tensor_info.padding().top == 2, framework::LogLevel::ERRORS);
96 ARM_COMPUTE_EXPECT(tensor_info.padding().right == 1, framework::LogLevel::ERRORS);
97 }
98}
99
100TEST_SUITE_END() // SubTensorInfo
101TEST_SUITE_END()
102} // namespace validation
103} // namespace test
104} // namespace arm_compute