1#ifndef TMVA_SOFIE_ROPERATOR_POOL 
    2#define TMVA_SOFIE_ROPERATOR_POOL 
   16namespace Experimental {
 
   77      if(std::is_same<T, float>::value) {
 
   81            std::runtime_error(
"TMVA SOFIE Encountered unsupported type parsing a Pool operator");
 
 
   98      if (
input.size() != 1 ) {
 
   99         throw std::runtime_error(
"TMVA SOFIE" + 
Name() + 
"Op Shape inference need 1 input tensor");
 
  102         throw std::runtime_error(
"TMVA SOFIE" + 
Name() + 
"Op Shape inference only accept tensor with at least 3 dimensions");
 
  106         throw std::runtime_error(
"TMVA SOFIE" + 
Name() + 
"Op : tensors with dimension " + std::to_string(
input[0].
size()) + 
" are not yet supported");
 
  111            std::runtime_error(
"TMVA SOFIE Pool Op Shape inference - invalid inputs ");
 
  119      size_t i1 = (
fDim > 1) ? ((
fDim > 2) ? 3 : 2) : 1;
 
  120      size_t i2 = (
fDim > 2) ? 4 : 3;
 
  161            std::runtime_error(
"TMVA SOFIE" + 
Name() + 
"Op invalid Autopad value : " + 
fAttrAutopad);
 
 
  209            std::runtime_error(
"TMVA SOFIE Pool op Input Tensor " + 
fNX + 
" is not found in model");
 
  215            std::runtime_error(
"TMVA SOFIE Pool Op input data tensor" + 
fNX + 
" is not of 3,4 or 5 dimensions");
 
 
  241      std::stringstream out;
 
 
  248      std::stringstream out;
 
  251          out << 
"std::vector<" << 
fType << 
"> fVec_" << 
opName << 
"_xpad = std::vector<" << 
fType << 
">(" 
  255          out << 
"std::vector<" << 
fType << 
"> fVec_" << 
opName << 
"_xpad = std::vector<" << 
fType << 
">(" 
  260          out << 
"std::vector<" << 
fType << 
"> fVec_" << 
opName << 
"_xpad = std::vector<" << 
fType << 
">(" 
 
  272         throw std::runtime_error(
"TMVA SOFIE Pool Op called to Generate without being initialized first");
 
  275      std::stringstream out;
 
  277      out << 
"\n//----  operator " << 
Name() << 
"  " << 
OpName << 
"\n";
 
  305      out << 
SP << 
"constexpr int hsize = " << 
fShapeX[2] << 
";\n";
 
  306      out << 
SP << 
"constexpr int hmin = " << 
hmin << 
";\n";
 
  307      out << 
SP << 
"constexpr int hmax = " << 
hmax << 
";\n";
 
  311         out << 
SP << 
"constexpr int wsize = " << 
wsize << 
";\n";
 
  312         out << 
SP << 
"constexpr int wmin = " << 
wmin << 
";\n";
 
  313         out << 
SP << 
"constexpr int wmax = " << 
wmax << 
";\n";
 
  317            out << 
SP << 
"constexpr int dsize = " << 
dsize << 
";\n";
 
  318            out << 
SP << 
"constexpr int dwsize = " << 
dsize*
wsize << 
";\n"; 
 
  319            out << 
SP << 
"constexpr int dmin = " << 
dmin << 
";\n";
 
  320            out << 
SP << 
"constexpr int dmax = " << 
dmax << 
";\n";
 
  333         out << 
SP << 
"size_t outIndex = 0;\n";
 
  334         out << 
SP << 
"for (size_t n = 0; n < " << 
fShapeX[0]*
fShapeX[1] << 
"; n++) {\n";
 
  335         out << 
SP << 
SP << 
"size_t inputOffset = n*" << 
fShapeX[2] << 
";\n";
 
  336         out << 
SP << 
SP << 
"for (int i = hmin; i < hmax; i+=" << 
fAttrStrides[0] << 
") {\n";
 
  339            out << 
SP << 
SP << 
SP << 
SP << 
"float value = -INFINITY;\n";
 
  341            out << 
SP << 
SP << 
SP << 
SP << 
"float value = 0;\n";
 
  343               out << 
SP << 
SP << 
SP << 
SP << 
"int nsum = 0;\n";
 
  345               out << 
SP << 
SP << 
SP << 
SP << 
"constexpr int nsum = kh;\n";
 
  348         out << 
SP << 
SP << 
SP << 
SP  << 
"for (int l = i;  l < i + kh; l++) {\n";
 
  349         out << 
SP << 
SP << 
SP << 
SP  << 
SP << 
"if (l < 0 || l >= hsize) continue;\n";
 
  350         out << 
SP << 
SP << 
SP << 
SP  << 
SP << 
SP <<  
"int index = inputOffset + l;\n";
 
  352         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"auto xval = tensor_" << 
fNX << 
"[index];\n";
 
  353         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"if (xval > value) value = xval;\n";
 
  357            out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"value += tensor_" << 
fNX << 
"[index];\n";
 
  365         out << 
SP << 
SP << 
SP << 
SP << 
"value /= float(nsum);\n";
 
  368         out << 
SP << 
SP << 
SP << 
SP << 
"tensor_" << 
fNY << 
"[outIndex++] = value;\n";
 
  370         out << 
SP << 
SP << 
"}\n";   
 
  375         out << 
SP << 
"size_t outIndex = 0;\n";
 
  376         out << 
SP << 
"for (size_t n = 0; n < " << 
fShapeX[0]*
fShapeX[1] << 
"; n++) {\n";
 
  378         out << 
SP << 
SP << 
"for (int i = hmin; i < hmax; i+=" << 
fAttrStrides[0] << 
") {\n";
 
  379         out << 
SP << 
SP << 
SP << 
"for (int j = wmin; j < wmax; j+=" << 
fAttrStrides[1] << 
") {\n";
 
  382            out << 
SP << 
SP << 
SP << 
SP << 
"float value = -INFINITY;\n";
 
  384            out << 
SP << 
SP << 
SP << 
SP << 
"float value = 0;\n";
 
  386               out << 
SP << 
SP << 
SP << 
SP << 
"int nsum = 0;\n";
 
  388               out << 
SP << 
SP << 
SP << 
SP << 
"constexpr int nsum = kw*kh;\n";
 
  391         out << 
SP << 
SP << 
SP << 
SP << 
"for (int l = i;  l < i + kh; l++) {\n";
 
  392         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
"if (l < 0 || l >= hsize) continue;\n";
 
  394         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
"for (int m = j; m < j + kw; m++) {\n";
 
  395         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"if (m < 0 || m >= wsize) continue;\n";
 
  396         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"int index = inputOffset + l*wsize + m;\n";
 
  398         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"auto xval = tensor_" << 
fNX << 
"[index];\n";
 
  399         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"if (xval > value) value = xval;\n";
 
  403            out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"value += tensor_" << 
fNX << 
"[index];\n";
 
  412            out << 
SP << 
SP << 
SP << 
SP << 
"value /= float(nsum);\n";
 
  414         out << 
SP << 
SP << 
SP << 
SP << 
"tensor_" << 
fNY << 
"[outIndex++] = value;\n";
 
  415         out << 
SP << 
SP << 
SP << 
"}\n";   
 
  416         out << 
SP << 
SP << 
"}\n";   
 
  421         out << 
SP << 
"size_t outIndex = 0;\n";
 
  422         out << 
SP << 
"for (size_t n = 0; n < " << 
fShapeX[0]*
fShapeX[1] << 
"; n++) {\n";
 
  424         out << 
SP << 
SP << 
"for (int i = hmin; i < hmax; i+=" << 
fAttrStrides[0] << 
") {\n";
 
  425         out << 
SP << 
SP << 
SP << 
"for (int j = wmin; j < wmax; j+=" << 
fAttrStrides[1] << 
") {\n";
 
  426         out << 
SP << 
SP << 
SP << 
SP << 
"for (int k = dmin; k < dmax; k+=" << 
fAttrStrides[2] << 
") {\n";
 
  429            out << 
SP << 
SP << 
SP << 
SP << 
"float value = -INFINITY;\n";
 
  431            out << 
SP << 
SP << 
SP << 
SP << 
"float value = 0;\n";
 
  433               out << 
SP << 
SP << 
SP << 
SP << 
"int nsum = 0;\n";
 
  435               out << 
SP << 
SP << 
SP << 
SP << 
"constexpr int nsum = kw*kh*kd;\n";
 
  438         out << 
SP << 
SP << 
SP << 
SP  << 
"for (int l = i;  l < i + kh; l++) {\n";
 
  439         out << 
SP << 
SP << 
SP << 
SP  << 
SP << 
"if (l < 0 || l >= hsize) continue;\n";
 
  441         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
"for (int m = j; m < j + kw; m++) {\n";
 
  442         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"if (m < 0 || m >= wsize) continue;\n";
 
  444         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"for (int p = k; p < k + kd; p++) {\n";
 
  445         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"if (p < 0 || p >= dsize) continue;\n";
 
  446         out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"int index = inputOffset + l*dwsize + m*dsize + p;\n";
 
  449            out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"auto xval = tensor_" << 
fNX << 
"[index];\n";
 
  450            out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"if (xval > value) value = xval;\n";
 
  454            out << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
SP << 
"value += tensor_" << 
fNX << 
"[index];\n";
 
  461         out << 
SP << 
SP << 
SP << 
SP << 
"}\n"; 
 
  464            out << 
SP << 
SP << 
SP << 
SP << 
"value /= float(nsum);\n";
 
  467         out << 
SP << 
SP << 
SP << 
SP << 
"tensor_" << 
fNY << 
"[outIndex++] = value;\n";
 
  468         out << 
SP << 
SP << 
SP << 
SP << 
"}\n" ; 
 
  469         out << 
SP << 
SP << 
SP << 
"}\n";   
 
  470         out << 
SP << 
SP << 
"}\n";   
 
 
 
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t hmin
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t hmax
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t wmin
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t wmax
void AddNeededStdLib(std::string libname)
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
bool CheckIfTensorAlreadyExist(std::string tensor_name)
const ETensorType & GetTensorType(std::string name) const
const std::vector< size_t > & GetTensorShape(std::string name) const
std::string GenerateInitCode() override
std::vector< size_t > fShapeY
size_t fAttrCountIncludePad
std::vector< size_t > fAttrKernelShape
std::vector< size_t > fAttrStrides
std::vector< size_t > fAttrDilations
std::vector< size_t > fAttrPads
virtual std::string GenerateSessionMembersCode(std::string opName) override
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
void Initialize(RModel &model) override
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input) override
std::string Generate(std::string OpName) override
std::vector< size_t > fShapeX
ROperator_Pool(PoolOpMode mode, RAttributes_Pool attr, std::string nameX, std::string nameY)
std::vector< std::string_view > fInputTensorNames
const std::string SP
space used to correctly indent the generated C++ code
std::vector< std::string_view > fOutputTensorNames
std::string ConvertShapeToString(std::vector< size_t > shape)
create variable transformations
std::vector< size_t > pads
std::vector< size_t > kernel_shape
std::vector< size_t > dilations
std::vector< size_t > strides