aboutsummaryrefslogtreecommitdiff
path: root/delegate/test/SpaceDepthTest.cpp
blob: add51b4a211e5461189b735165735edb905c1a5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// Copyright © 2021, 2023-2024 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "SpaceDepthTestHelper.hpp"

#include <doctest/doctest.h>

namespace armnnDelegate
{

void DepthToSpaceFp32Test(int blockSize)
{
    // Set input data
    std::vector<int32_t> inputShape { 1, 2, 2, 4 };
    std::vector<int32_t> outputShape { 1, 4, 4, 1 };

    std::vector<float> inputValues = { 1.f,  2.f,  3.f,  4.f,
                                       5.f,  6.f,  7.f,  8.f,
                                       9.f, 10.f, 11.f, 12.f,
                                       13.f, 14.f, 15.f, 16.f };

    std::vector<float> expectedOutputValues = { 1.f,   2.f,   5.f,   6.f,
                                                3.f,   4.f,   7.f,   8.f,
                                                9.f,  10.f,  13.f,  14.f,
                                                11.f,  12.f,  15.f,  16.f };

    SpaceDepthTest<float>(tflite::BuiltinOperator_DEPTH_TO_SPACE,
                          ::tflite::TensorType_FLOAT32,
                          inputShape,
                          outputShape,
                          inputValues,
                          expectedOutputValues,
                          {},
                          blockSize);
}

void DepthToSpaceUint8Test(int blockSize)
{
    // Set input data
    std::vector<int32_t> inputShape { 2, 1, 1, 4 };
    std::vector<int32_t> outputShape { 2, 2, 2, 1 };

    std::vector<uint8_t> inputValues = { 1,  2,  3,  4,
                                         5,  6,  7,  8 };

    std::vector<uint8_t> expectedOutputValues = { 1,  2,  3,  4,
                                                  5,  6,  7,  8 };

    SpaceDepthTest<uint8_t>(tflite::BuiltinOperator_DEPTH_TO_SPACE,
                            ::tflite::TensorType_UINT8,
                            inputShape,
                            outputShape,
                            inputValues,
                            expectedOutputValues,
                            {},
                            blockSize);
}

void SpaceToDepthFp32Test(int blockSize)
{
    // Set input data
    std::vector<int32_t> inputShape { 1, 2, 2, 2 };
    std::vector<int32_t> outputShape { 1, 1, 1, 8 };

    std::vector<float> inputValues = { 1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f };
    std::vector<float> expectedOutputValues = { 1.4f, 2.3f, 3.2f, 4.1f, 5.4f, 6.3f, 7.2f, 8.1f };

    SpaceDepthTest<float>(tflite::BuiltinOperator_SPACE_TO_DEPTH,
                          ::tflite::TensorType_FLOAT32,
                          inputShape,
                          outputShape,
                          inputValues,
                          expectedOutputValues,
                          {},
                          blockSize);
}

void SpaceToDepthUint8Test(int blockSize)
{
    // Set input data
    std::vector<int32_t> inputShape { 1, 2, 2, 1 };
    std::vector<int32_t> outputShape { 1, 1, 1, 4 };

    std::vector<uint8_t> inputValues = { 1, 2, 3, 2 };
    std::vector<uint8_t> expectedOutputValues = { 1, 2, 3, 2 };

    SpaceDepthTest<uint8_t>(tflite::BuiltinOperator_SPACE_TO_DEPTH,
                            ::tflite::TensorType_UINT8,
                            inputShape,
                            outputShape,
                            inputValues,
                            expectedOutputValues,
                            {},
                            blockSize);
}

TEST_SUITE("DepthToSpaceTests")
{

TEST_CASE ("DepthToSpaceFp32Test_Test")
{
    DepthToSpaceFp32Test(2);
}

TEST_CASE ("DepthToSpaceUint8Test_Test")
{
    DepthToSpaceUint8Test(2);
}

} // TEST_SUITE("DepthToSpaceTests")


TEST_SUITE("SpaceToDepthTests")
{

TEST_CASE ("SpaceToDepthFp32Test_Test")
{
    SpaceToDepthFp32Test(2);
}

TEST_CASE ("SpaceToDepthUint8Test_Test")
{
    SpaceToDepthUint8Test(2);
}

} // TEST_SUITE("SpaceToDepthTests")

} // namespace armnnDelegate