1#ifndef TMVA_SOFIE_ROPERATOR_Reduce
2#define TMVA_SOFIE_ROPERATOR_Reduce
16namespace Experimental{
21template <
typename T, EReduceOpMode Op>
67 throw std::runtime_error(
"TMVA SOFIE Reduce Op Input Tensor " +
fNX +
" is not found in model");
77 OpName =
"op_" + OpName;
79 throw std::runtime_error(
"TMVA SOFIE Reduce Op called to Generate without being initialized first");
95 std::stringstream out;
96 out <<
"\n//---- operator " <<
Name() <<
" " << OpName <<
"\n";
97 out <<
SP <<
"for (size_t i = 0; i < " << outputLength <<
"; i++) {\n";
102 out <<
SP <<
SP <<
"size_t idx_0 = i / " << outputStrides[0] <<
";\n" ;
103 out <<
SP <<
SP <<
"size_t itmp = i;\n";
104 for (
size_t k = 1; k < dim; k++) {
105 out <<
SP <<
SP <<
"itmp = itmp % " << outputStrides[k-1] <<
";\n" ;
107 out <<
SP <<
SP <<
"size_t idx_" << k <<
" = itmp / " << outputStrides[k] <<
";\n" ;
110 out <<
SP <<
SP <<
"size_t idx_" << k <<
" = itmp;\n";
116 out <<
SP <<
SP <<
"float sum = 1;\n";
118 out <<
SP <<
SP <<
"float sum = 0;\n";
123 out <<
SP <<
SP <<
SP <<
"size_t l = ";
124 for(
int n = dim-1;
n >=0;
n--) {
128 out <<
" + " <<
"idx_" <<
n <<
" * " << inputStrides[
n];
133 out <<
SP <<
SP <<
SP <<
"sum += tensor_" <<
fNX <<
"[l];\n";
134 out <<
SP <<
SP <<
"}\n";
135 out <<
SP <<
SP <<
"float reduceResult = sum/static_cast<float>(" <<
fShapeX[
fAttrAxes] <<
");\n";
138 out <<
SP <<
SP <<
SP <<
"sum += tensor_" <<
fNX <<
"[l];\n";
139 out <<
SP <<
SP <<
"}\n";
140 out <<
SP <<
SP <<
"float reduceResult = sum;\n";
143 out <<
SP <<
SP <<
SP <<
"sum += tensor_" <<
fNX <<
"[l] * tensor_" <<
fNX <<
"[l];\n";
144 out <<
SP <<
SP <<
"}\n";
145 out <<
SP <<
SP <<
"float reduceResult = sum;\n";
148 out <<
SP <<
SP <<
SP <<
"sum *= tensor_" <<
fNX <<
"[l];\n";
149 out <<
SP <<
SP <<
"}\n";
150 out <<
SP <<
SP <<
"float reduceResult = sum;\n";
153 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< Dim > dim_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