|
| 1 | +#include <numeric> |
| 2 | + |
1 | 3 | #include "Linear_16_FromONNX.hxx" |
2 | 4 | #include "input_models/references/Linear_16.ref.hxx" |
3 | 5 |
|
|
7 | 9 | #include "Linear_64_FromONNX.hxx" |
8 | 10 | #include "input_models/references/Linear_64.ref.hxx" |
9 | 11 |
|
| 12 | +#include "ConvWithPadding_FromONNX.hxx" |
| 13 | +#include "input_models/references/ConvWithPadding.ref.hxx" |
| 14 | + |
| 15 | +#include "ConvWithoutPadding_FromONNX.hxx" |
| 16 | +#include "input_models/references/ConvWithoutPadding.ref.hxx" |
| 17 | + |
| 18 | +#include "ConvWithAutopadSameLower_FromONNX.hxx" |
| 19 | +#include "input_models/references/ConvWithAutopadSameLower.ref.hxx" |
| 20 | + |
| 21 | +#include "ConvWithStridesPadding_FromONNX.hxx" |
| 22 | +#include "input_models/references/ConvWithStridesPadding.ref.hxx" |
| 23 | + |
| 24 | +#include "ConvWithStridesNoPadding_FromONNX.hxx" |
| 25 | +#include "input_models/references/ConvWithStridesNoPadding.ref.hxx" |
| 26 | + |
| 27 | +#include "ConvWithAsymmetricPadding_FromONNX.hxx" |
| 28 | +#include "input_models/references/ConvWithAsymmetricPadding.ref.hxx" |
| 29 | + |
10 | 30 | #include "gtest/gtest.h" |
11 | 31 |
|
12 | 32 | constexpr float DEFAULT_TOLERANCE = 1e-6f; |
@@ -72,3 +92,129 @@ TEST(ONNX, Linear64) |
72 | 92 | EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE); |
73 | 93 | } |
74 | 94 | } |
| 95 | + |
| 96 | + |
| 97 | +TEST(ONNX, ConvWithPadding) |
| 98 | +{ |
| 99 | + constexpr float TOLERANCE = DEFAULT_TOLERANCE; |
| 100 | + |
| 101 | + // Preparing the standard all-ones input |
| 102 | + std::vector<float> input(25); |
| 103 | + std::iota(input.begin(), input.end(), 0.0f); |
| 104 | + std::vector<float> output = TMVA_SOFIE_ConvWithPadding::infer(input.data()); |
| 105 | + |
| 106 | + // Checking output size |
| 107 | + EXPECT_EQ(output.size(), sizeof(ConvWithPadding_ExpectedOutput::all_ones) / sizeof(float)); |
| 108 | + |
| 109 | + float *correct = ConvWithPadding_ExpectedOutput::all_ones; |
| 110 | + |
| 111 | + // Checking every output value, one by one |
| 112 | + for (size_t i = 0; i < output.size(); ++i) { |
| 113 | + EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE); |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | + |
| 118 | +TEST(ONNX, ConvWithoutPadding) |
| 119 | +{ |
| 120 | + constexpr float TOLERANCE = DEFAULT_TOLERANCE; |
| 121 | + |
| 122 | + // Preparing the standard all-ones input |
| 123 | + std::vector<float> input(25); |
| 124 | + std::iota(input.begin(), input.end(), 0.0f); |
| 125 | + std::vector<float> output = TMVA_SOFIE_ConvWithoutPadding::infer(input.data()); |
| 126 | + |
| 127 | + // Checking output size |
| 128 | + EXPECT_EQ(output.size(), sizeof(ConvWithoutPadding_ExpectedOutput::all_ones) / sizeof(float)); |
| 129 | + |
| 130 | + float *correct = ConvWithoutPadding_ExpectedOutput::all_ones; |
| 131 | + |
| 132 | + // Checking every output value, one by one |
| 133 | + for (size_t i = 0; i < output.size(); ++i) { |
| 134 | + EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE); |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | + |
| 139 | +TEST(ONNX, ConvWithAutopadSameLower) |
| 140 | +{ |
| 141 | + constexpr float TOLERANCE = DEFAULT_TOLERANCE; |
| 142 | + |
| 143 | + // Preparing the standard all-ones input |
| 144 | + std::vector<float> input(25); |
| 145 | + std::iota(input.begin(), input.end(), 0.0f); |
| 146 | + std::vector<float> output = TMVA_SOFIE_ConvWithAutopadSameLower::infer(input.data()); |
| 147 | + |
| 148 | + // Checking output size |
| 149 | + EXPECT_EQ(output.size(), sizeof(ConvWithAutopadSameLower_ExpectedOutput::all_ones) / sizeof(float)); |
| 150 | + |
| 151 | + float *correct = ConvWithAutopadSameLower_ExpectedOutput::all_ones; |
| 152 | + |
| 153 | + // Checking every output value, one by one |
| 154 | + for (size_t i = 0; i < output.size(); ++i) { |
| 155 | + EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE); |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | + |
| 160 | +TEST(ONNX, ConvWithStridesPadding) |
| 161 | +{ |
| 162 | + constexpr float TOLERANCE = DEFAULT_TOLERANCE; |
| 163 | + |
| 164 | + // Preparing the standard all-ones input |
| 165 | + std::vector<float> input(35); |
| 166 | + std::iota(input.begin(), input.end(), 0.0f); |
| 167 | + std::vector<float> output = TMVA_SOFIE_ConvWithStridesPadding::infer(input.data()); |
| 168 | + |
| 169 | + // Checking output size |
| 170 | + EXPECT_EQ(output.size(), sizeof(ConvWithStridesPadding_ExpectedOutput::all_ones) / sizeof(float)); |
| 171 | + |
| 172 | + float *correct = ConvWithStridesPadding_ExpectedOutput::all_ones; |
| 173 | + |
| 174 | + // Checking every output value, one by one |
| 175 | + for (size_t i = 0; i < output.size(); ++i) { |
| 176 | + EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE); |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | + |
| 181 | +TEST(ONNX, ConvWithStridesNoPadding) |
| 182 | +{ |
| 183 | + constexpr float TOLERANCE = DEFAULT_TOLERANCE; |
| 184 | + |
| 185 | + // Preparing the standard all-ones input |
| 186 | + std::vector<float> input(35); |
| 187 | + std::iota(input.begin(), input.end(), 0.0f); |
| 188 | + std::vector<float> output = TMVA_SOFIE_ConvWithStridesNoPadding::infer(input.data()); |
| 189 | + |
| 190 | + // Checking output size |
| 191 | + EXPECT_EQ(output.size(), sizeof(ConvWithStridesNoPadding_ExpectedOutput::all_ones) / sizeof(float)); |
| 192 | + |
| 193 | + float *correct = ConvWithStridesNoPadding_ExpectedOutput::all_ones; |
| 194 | + |
| 195 | + // Checking every output value, one by one |
| 196 | + for (size_t i = 0; i < output.size(); ++i) { |
| 197 | + EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE); |
| 198 | + } |
| 199 | +} |
| 200 | + |
| 201 | + |
| 202 | +TEST(ONNX, ConvWithAsymmetricPadding) |
| 203 | +{ |
| 204 | + constexpr float TOLERANCE = DEFAULT_TOLERANCE; |
| 205 | + |
| 206 | + // Preparing the standard all-ones input |
| 207 | + std::vector<float> input(35); |
| 208 | + std::iota(input.begin(), input.end(), 0.0f); |
| 209 | + std::vector<float> output = TMVA_SOFIE_ConvWithAsymmetricPadding::infer(input.data()); |
| 210 | + |
| 211 | + // Checking output size |
| 212 | + EXPECT_EQ(output.size(), sizeof(ConvWithAsymmetricPadding_ExpectedOutput::all_ones) / sizeof(float)); |
| 213 | + |
| 214 | + float *correct = ConvWithAsymmetricPadding_ExpectedOutput::all_ones; |
| 215 | + |
| 216 | + // Checking every output value, one by one |
| 217 | + for (size_t i = 0; i < output.size(); ++i) { |
| 218 | + EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE); |
| 219 | + } |
| 220 | +} |
0 commit comments