Skip to content

Commit

Permalink
[tmva][sofie] Add test for ReduceSum
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoneta committed Nov 15, 2024
1 parent d74cdce commit f812f98
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tmva/sofie/test/TestCustomModelsFromONNX.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "ReduceProd_FromONNX.hxx"
#include "input_models/references/ReduceProd.ref.hxx"

#include "ReduceSum_FromONNX.hxx" // hardcode reference

#include "Shape_FromONNX.hxx"
#include "input_models/references/Shape.ref.hxx"

Expand Down Expand Up @@ -1179,6 +1181,33 @@ TEST(ONNX, Pow_broadcast){

}

TEST(ONNX, ReduceSum){
constexpr float TOLERANCE = DEFAULT_TOLERANCE;


// Preparing the standard input
std::vector<float> input({
5, 2, 3,
5, 5, 4
});

// test Reduce sum in all axis and keeping the dimension
// input tensor is shape [1,2,3]
// output tensod is shape [1,1,1] and value = 24 (sum of all elements)

TMVA_SOFIE_ReduceSum::Session s("ReduceSum_FromONNX.dat");
std::vector<float> output = s.infer(input.data());
// Checking output size
EXPECT_EQ(output.size(), 1);

float correct[] = {24};

// Checking every output value, one by one
for (size_t i = 0; i < output.size(); ++i) {
EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE);
}
}

TEST(ONNX, Max)
{
constexpr float TOLERANCE = DEFAULT_TOLERANCE;
Expand Down
Binary file added tmva/sofie/test/input_models/ReduceSum.onnx
Binary file not shown.

0 comments on commit f812f98

Please sign in to comment.