Skip to content

Commit cf7ba5d

Browse files
committed
Added the tests for all 4 Binary Operators
1 parent 7cb26bc commit cf7ba5d

File tree

9 files changed

+200
-0
lines changed

9 files changed

+200
-0
lines changed

tmva/sofie/test/TestCustomModelsFromONNX.cxx

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
#include "LinearWithSelu_FromONNX.hxx"
1313
#include "input_models/references/LinearWithSelu.ref.hxx"
1414

15+
#include "Sub_FromONNX.hxx"
16+
#include "input_models/references/Sub.ref.hxx"
17+
18+
#include "Add_FromONNX.hxx"
19+
#include "input_models/references/Add.ref.hxx"
20+
21+
#include "Mul_FromONNX.hxx"
22+
#include "input_models/references/Mul.ref.hxx"
23+
24+
#include "Div_FromONNX.hxx"
25+
#include "input_models/references/Div.ref.hxx"
26+
1527
#include "LinearWithLeakyRelu_FromONNX.hxx"
1628
#include "input_models/references/LinearWithLeakyRelu.ref.hxx"
1729

@@ -134,6 +146,110 @@ TEST(ONNX, Linear32)
134146
}
135147
}
136148

149+
TEST(ONNX, Sub)
150+
{
151+
constexpr float TOLERANCE = DEFAULT_TOLERANCE;
152+
153+
// Preparing the standard input
154+
std::vector<float> input1({
155+
1, 2
156+
});
157+
std::vector<float> input2({
158+
0, 1
159+
});
160+
TMVA_SOFIE_Sub::Session s("Sub_FromONNX.dat");
161+
162+
std::vector<float> output = s.infer(input2.data(),input1.data());
163+
164+
// Checking output size
165+
EXPECT_EQ(output.size(), sizeof(Sub_ExpectedOutput::outputs) / sizeof(float));
166+
167+
float *correct = Sub_ExpectedOutput::outputs;
168+
169+
// Checking every output value, one by one
170+
for (size_t i = 0; i < output.size(); ++i) {
171+
EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE);
172+
}
173+
}
174+
175+
176+
TEST(ONNX, Add)
177+
{
178+
constexpr float TOLERANCE = DEFAULT_TOLERANCE;
179+
180+
// Preparing the standard input
181+
std::vector<float> input1({
182+
1, 2
183+
});
184+
std::vector<float> input2({
185+
0, 1
186+
});
187+
TMVA_SOFIE_Add::Session s("Add_FromONNX.dat");
188+
189+
std::vector<float> output = s.infer(input1.data(),input2.data());
190+
191+
// Checking output size
192+
EXPECT_EQ(output.size(), sizeof(Add_ExpectedOutput::outputs) / sizeof(float));
193+
194+
float *correct = Add_ExpectedOutput::outputs;
195+
196+
// Checking every output value, one by one
197+
for (size_t i = 0; i < output.size(); ++i) {
198+
EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE);
199+
}
200+
}
201+
202+
TEST(ONNX, Mul)
203+
{
204+
constexpr float TOLERANCE = DEFAULT_TOLERANCE;
205+
206+
// Preparing the standard input
207+
std::vector<float> input1({
208+
1, 2
209+
});
210+
std::vector<float> input2({
211+
0, 1
212+
});
213+
TMVA_SOFIE_Mul::Session s("Mul_FromONNX.dat");
214+
215+
std::vector<float> output = s.infer(input1.data(),input2.data());
216+
217+
// Checking output size
218+
EXPECT_EQ(output.size(), sizeof(Mul_ExpectedOutput::outputs) / sizeof(float));
219+
220+
float *correct = Mul_ExpectedOutput::outputs;
221+
222+
// Checking every output value, one by one
223+
for (size_t i = 0; i < output.size(); ++i) {
224+
EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE);
225+
}
226+
}
227+
228+
TEST(ONNX, Div)
229+
{
230+
constexpr float TOLERANCE = DEFAULT_TOLERANCE;
231+
232+
// Preparing the standard input
233+
std::vector<float> input1({
234+
4, 2
235+
});
236+
std::vector<float> input2({
237+
2, 2
238+
});
239+
TMVA_SOFIE_Div::Session s("Div_FromONNX.dat");
240+
241+
std::vector<float> output = s.infer(input2.data(),input1.data());
242+
243+
// Checking output size
244+
EXPECT_EQ(output.size(), sizeof(Div_ExpectedOutput::outputs) / sizeof(float));
245+
246+
float *correct = Div_ExpectedOutput::outputs;
247+
248+
// Checking every output value, one by one
249+
for (size_t i = 0; i < output.size(); ++i) {
250+
EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE);
251+
}
252+
}
137253

138254
TEST(ONNX, Linear64)
139255
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pytorch1.11.0:�
2+
)
3+
onnx::Add_0
4+
onnx::Add_12Add_0"Addtorch-jit-exportZ
5+
onnx::Add_0
6+
7+

8+
Z
9+
onnx::Add_1
10+
11+

12+
b
13+
2
14+
15+

16+
B
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pytorch1.11.0:�
2+
)
3+
onnx::Div_0
4+
onnx::Div_12Div_0"Divtorch-jit-exportZ
5+
onnx::Div_0
6+
7+

8+
Z
9+
onnx::Div_1
10+
11+

12+
b
13+
2
14+
15+

16+
B
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pytorch1.11.0:�
2+
)
3+
onnx::Mul_0
4+
onnx::Mul_12Mul_0"Multorch-jit-exportZ
5+
onnx::Mul_0
6+
7+

8+
Z
9+
onnx::Mul_1
10+
11+

12+
b
13+
2
14+
15+

16+
B
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pytorch1.11.0:�
2+
)
3+
onnx::Sub_0
4+
onnx::Sub_12Sub_0"Subtorch-jit-exportZ
5+
onnx::Sub_0
6+
7+

8+
Z
9+
onnx::Sub_1
10+
11+

12+
b
13+
2
14+
15+

16+
B
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Add_ExpectedOutput{
2+
float outputs[] = {
3+
1, 3
4+
};
5+
} // namespace Add_ExpectedOutput
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Div_ExpectedOutput{
2+
float outputs[] = {
3+
2, 1
4+
};
5+
} // namespace Div_ExpectedOutput
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Mul_ExpectedOutput{
2+
float outputs[] = {
3+
0, 2
4+
};
5+
} // namespace Mul_ExpectedOutput
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Sub_ExpectedOutput{
2+
float outputs[] = {
3+
1, 1
4+
};
5+
} // namespace Sub_ExpectedOutput

0 commit comments

Comments
 (0)