Skip to content

Commit 53a9a4c

Browse files
committed
Made the required changes to resolve the generated code errors
1 parent b7bef8e commit 53a9a4c

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

tmva/sofie/inc/TMVA/ROperator_Reduce.hxx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ public:
110110
else
111111
out << " };\n";
112112
}
113-
// no compute indices as function of strides
114-
// as in the example I have sent you
115113

116114
for (size_t k = 0; k < dim; k++) {
117115
size_t j;
@@ -125,7 +123,7 @@ public:
125123
// out << SP << "assert(idx[" << fAttrAxes << "] == 0);\n"; // we can avoid computing this for the reduction axis which by definition is always zero
126124

127125
out << SP << "float sum = 0;\n";
128-
out << SP << SP << " for (size_t k = 0; k < " << fShapeX[fAttrAxes] <<"; k++) { \n";
126+
out << SP << " for (size_t k = 0; k < " << fShapeX[fAttrAxes] <<"; k++) { \n";
129127
out << SP << SP << " idx_" << fAttrAxes << " = k;\n";
130128
// compute input index j
131129
out << SP << "std::vector<size_t> inputStrides = {" ;
@@ -137,13 +135,13 @@ public:
137135
out << " };\n";
138136
}
139137
out << SP << SP << "size_t l = 0;\n";
140-
for (size_t m = 0; m < dim; m++) {
141-
size_t n;
142-
for(n = 0; n < m; n++ )
138+
139+
size_t n ;
140+
for(n = 0; n < dim-1; n++ )
143141
out << SP << "l += idx_" << n << " * inputStrides[" << n << "];\n";
144142

145-
out << SP << "l += idx_" << m << ";\n";
146-
}
143+
out << SP << "l += idx_" << n << ";\n";
144+
147145
if(fReduceOpMode == ReduceMean){
148146
out << SP << SP << "sum += tensor_" << fNX << "[l];\n";
149147
out << SP << SP << "};\n";

tmva/sofie/test/TestCustomModelsFromONNX.cxx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include "ReduceMean_FromONNX.hxx"
3737
#include "input_models/references/ReduceMean.ref.hxx"
3838

39+
#include "ReduceProd_FromONNX.hxx"
40+
#include "input_models/references/ReduceProd.ref.hxx"
41+
3942
#include "LinearWithLeakyRelu_FromONNX.hxx"
4043
#include "input_models/references/LinearWithLeakyRelu.ref.hxx"
4144

@@ -751,6 +754,28 @@ TEST(ONNX, AvgPool){
751754

752755
}
753756

757+
TEST(ONNX, ReduceProd){
758+
constexpr float TOLERANCE = DEFAULT_TOLERANCE;
759+
760+
// Preparing the standard input
761+
std::vector<float> input({
762+
5, 2, 3,
763+
5, 5, 4
764+
});
765+
766+
TMVA_SOFIE_ReduceProd::Session s("ReduceProd_FromONNX.dat");
767+
std::vector<float> output = s.infer(input.data());
768+
// Checking output size
769+
EXPECT_EQ(output.size(), sizeof(ReduceProd_ExpectedOutput::output) / sizeof(float));
770+
771+
float *correct = ReduceProd_ExpectedOutput::output;
772+
773+
// Checking every output value, one by one
774+
for (size_t i = 0; i < output.size(); ++i) {
775+
EXPECT_LE(std::abs(output[i] - correct[i]), TOLERANCE);
776+
}
777+
778+
}
754779

755780
TEST(ONNX, RNNBatchwise)
756781
{
14 Bytes
Binary file not shown.
181 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace Reduce_mean_ExpectedOutput{
22
float output[] = {
3-
4
3+
5.0, 3.5, 3.5
44
};
55
} // namespace Reduce_mean_ExpectedOutput
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Reduce_mean_ExpectedOutput{
2+
float output[] = {
3+
25.0, 10.0, 12.0
4+
};
5+
} // namespace Reduce_mean_ExpectedOutput

0 commit comments

Comments
 (0)