blob: bd35347b6913cfbf3fedda0a6358a71eefa4756e [file] [log] [blame]
Tracy Narine7306bbe2023-07-17 16:06:26 +01001//
Colm Donelan7bcae3c2024-01-22 10:07:14 +00002// Copyright © 2023-2024 Arm Ltd and Contributors. All rights reserved.
Tracy Narine7306bbe2023-07-17 16:06:26 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "ReverseV2TestHelper.hpp"
7
Tracy Narine7306bbe2023-07-17 16:06:26 +01008#include <doctest/doctest.h>
9
10namespace armnnDelegate
11{
12
Colm Donelan7bcae3c2024-01-22 10:07:14 +000013void ReverseV2Float32Test(const std::vector<armnn::BackendId>& backends = {})
Tianle Cheng21a9f332023-11-09 13:56:53 +000014{
15 // Set input data
16 std::vector<float> inputValues =
Tracy Narine7306bbe2023-07-17 16:06:26 +010017 {
Tianle Cheng21a9f332023-11-09 13:56:53 +000018 1.0f, 2.0f, 3.0f,
19 4.0f, 5.0f, 6.0f,
20 7.0f, 8.0f, 9.0f,
Tracy Narine7306bbe2023-07-17 16:06:26 +010021
Tianle Cheng21a9f332023-11-09 13:56:53 +000022 11.0f, 12.0f, 13.0f,
23 14.0f, 15.0f, 16.0f,
24 17.0f, 18.0f, 19.0f,
Tracy Narine7306bbe2023-07-17 16:06:26 +010025
Tianle Cheng21a9f332023-11-09 13:56:53 +000026 21.0f, 22.0f, 23.0f,
27 24.0f, 25.0f, 26.0f,
28 27.0f, 28.0f, 29.0f
29 };
Tracy Narine7306bbe2023-07-17 16:06:26 +010030
Tianle Cheng21a9f332023-11-09 13:56:53 +000031 // The output data
32 std::vector<float> expectedOutputValues =
33 {
34 3.0f, 2.0f, 1.0f,
35 6.0f, 5.0f, 4.0f,
36 9.0f, 8.0f, 7.0f,
Tracy Narine7306bbe2023-07-17 16:06:26 +010037
Tianle Cheng21a9f332023-11-09 13:56:53 +000038 13.0f, 12.0f, 11.0f,
39 16.0f, 15.0f, 14.0f,
40 19.0f, 18.0f, 17.0f,
Tracy Narine7306bbe2023-07-17 16:06:26 +010041
Tianle Cheng21a9f332023-11-09 13:56:53 +000042 23.0f, 22.0f, 21.0f,
43 26.0f, 25.0f, 24.0f,
44 29.0f, 28.0f, 27.0f
45 };
Tracy Narine7306bbe2023-07-17 16:06:26 +010046
Tianle Cheng21a9f332023-11-09 13:56:53 +000047 // The axis to reverse
48 const std::vector<int32_t> axisValues = {2};
Tracy Narine7306bbe2023-07-17 16:06:26 +010049
Tianle Cheng21a9f332023-11-09 13:56:53 +000050 // Shapes
51 const std::vector<int32_t> inputShape = {3, 3, 3};
52 const std::vector<int32_t> axisShapeDims = {1};
53 const std::vector<int32_t> expectedOutputShape = {3, 3, 3};
Tracy Narine7306bbe2023-07-17 16:06:26 +010054
Tianle Cheng21a9f332023-11-09 13:56:53 +000055 ReverseV2FP32TestImpl(tflite::BuiltinOperator_REVERSE_V2,
Tianle Cheng21a9f332023-11-09 13:56:53 +000056 inputValues,
57 inputShape,
58 axisValues,
59 axisShapeDims,
60 expectedOutputValues,
61 expectedOutputShape);
62}
63
Colm Donelan7bcae3c2024-01-22 10:07:14 +000064void ReverseV2NegativeAxisFloat32Test(const std::vector<armnn::BackendId>& backends = {})
Tianle Cheng21a9f332023-11-09 13:56:53 +000065{
66 // Set input data
67 std::vector<float> inputValues =
68 {
69 1.0f, 2.0f, 3.0f,
70 4.0f, 5.0f, 6.0f,
71 7.0f, 8.0f, 9.0f,
72
73 11.0f, 12.0f, 13.0f,
74 14.0f, 15.0f, 16.0f,
75 17.0f, 18.0f, 19.0f,
76
77 21.0f, 22.0f, 23.0f,
78 24.0f, 25.0f, 26.0f,
79 27.0f, 28.0f, 29.0f
80 };
81
82 // The output data
83 std::vector<float> expectedOutputValues =
84 {
85 7.0f, 8.0f, 9.0f,
86 4.0f, 5.0f, 6.0f,
87 1.0f, 2.0f, 3.0f,
88
89 17.0f, 18.0f, 19.0f,
90 14.0f, 15.0f, 16.0f,
91 11.0f, 12.0f, 13.0f,
92
93 27.0f, 28.0f, 29.0f,
94 24.0f, 25.0f, 26.0f,
95 21.0f, 22.0f, 23.0f
96 };
97
98 // The axis to reverse
99 const std::vector<int32_t> axisValues = {-2};
100
101 // Shapes
102 const std::vector<int32_t> inputShape = {3, 3, 3};
103 const std::vector<int32_t> axisShapeDims = {1};
104 const std::vector<int32_t> expectedOutputShape = {3, 3, 3};
105
106 ReverseV2FP32TestImpl(tflite::BuiltinOperator_REVERSE_V2,
Tianle Cheng21a9f332023-11-09 13:56:53 +0000107 inputValues,
108 inputShape,
109 axisValues,
110 axisShapeDims,
111 expectedOutputValues,
112 expectedOutputShape);
113}
114
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000115TEST_SUITE("ReverseV2TestsTests")
Tianle Cheng21a9f332023-11-09 13:56:53 +0000116{
117
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000118 TEST_CASE ("ReverseV2_Float32_Test")
Tianle Cheng21a9f332023-11-09 13:56:53 +0000119 {
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000120 ReverseV2Float32Test();
Tracy Narine7306bbe2023-07-17 16:06:26 +0100121 }
122
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000123 TEST_CASE ("ReverseV2_NegativeAxis_Float32_Test")
Tracy Narine7306bbe2023-07-17 16:06:26 +0100124 {
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000125 ReverseV2NegativeAxisFloat32Test();
Tracy Narine7306bbe2023-07-17 16:06:26 +0100126 }
127
Colm Donelan7bcae3c2024-01-22 10:07:14 +0000128} // TEST_SUITE("ReverseV2TestsTests")
Tracy Narine7306bbe2023-07-17 16:06:26 +0100129
130} // namespace armnnDelegate