1#ifndef TMVA_SOFIE_ROPERATOR_Reduce
2#define TMVA_SOFIE_ROPERATOR_Reduce
16namespace Experimental{
21template <
typename T, EReduceOpMode Op>
66 throw std::runtime_error(
"TMVA SOFIE Reduce Op Input Tensor " +
fNX +
" is not found in model");
76 OpName =
"op_" + OpName;
78 throw std::runtime_error(
"TMVA SOFIE Reduce Op called to Generate without being initialized first");
94 std::stringstream out;
95 out <<
"\n//---- operator " <<
Name() <<
" " << OpName <<
"\n";
96 out <<
SP <<
"for (size_t i = 0; i < " << outputLength <<
"; i++) {\n";
101 out <<
SP <<
SP <<
"size_t idx_0 = i / " << outputStrides[0] <<
";\n" ;
102 out <<
SP <<
SP <<
"size_t itmp = i;\n";
103 for (
size_t k = 1; k < dim; k++) {
104 out <<
SP <<
SP <<
"itmp = itmp % " << outputStrides[k-1] <<
";\n" ;
106 out <<
SP <<
SP <<
"size_t idx_" << k <<
" = itmp / " << outputStrides[k] <<
";\n" ;
109 out <<
SP <<
SP <<
"size_t idx_" << k <<
" = itmp;\n";
115 out <<
SP <<
SP <<
"float sum = 1;\n";
117 out <<
SP <<
SP <<
"float sum = 0;\n";
122 out <<
SP <<
SP <<
SP <<
"size_t l = ";
123 for(
int n = dim-1;
n >=0;
n--) {
127 out <<
" + " <<
"idx_" <<
n <<
" * " << inputStrides[
n];
132 out <<
SP <<
SP <<
SP <<
"sum += tensor_" <<
fNX <<
"[l];\n";
133 out <<
SP <<
SP <<
"}\n";
134 out <<
SP <<
SP <<
"float reduceResult = sum/static_cast<float>(" <<
fShapeX[
fAttrAxes] <<
");\n";
137 out <<
SP <<
SP <<
SP <<
"sum += tensor_" <<
fNX <<
"[l] * tensor_" <<
fNX <<
"[l];\n";
138 out <<
SP <<
SP <<
"}\n";
139 out <<
SP <<
SP <<
"float reduceResult = sum;\n";
142 out <<
SP <<
SP <<
SP <<
"sum *= tensor_" <<
fNX <<
"[l];\n";
143 out <<
SP <<
SP <<
"}\n";
144 out <<
SP <<
SP <<
"float reduceResult = sum;\n";
147 out <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[i] = reduceResult;\n";
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
const ETensorType & GetTensorType(std::string name)
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape)
bool CheckIfTensorAlreadyExist(std::string tensor_name)
const std::vector< size_t > & GetTensorShape(std::string name)
ROperator_Reduce(int keepdims, int attrAxes, std::string nameX, std::string nameY)
std::vector< size_t > fShapeX
void Initialize(RModel &model)
EReduceOpMode fReduceOpMode
std::string Generate(std::string OpName)
std::vector< size_t > fShapeY
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input)
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input)
const std::string SP
space used to correctly indent the generated C++ code
bool fUseSession
flag to identify if using the session class
std::vector< size_t > ComputeStrideFromShape(const std::vector< size_t > &shape)
compute stride of a tensor given its shape (assume layout is row-major)
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations