1#ifndef TMVA_SOFIE_ROPERATOR_Pad
2#define TMVA_SOFIE_ROPERATOR_Pad
11namespace Experimental{
30 std::vector<std::pair<int64_t, int64_t>>
fPads;
36 const std::string &
nameAX,
const std::string &
nameY,
const std::string &
mode) :
42 if (
mode ==
"constant")
44 else if (
mode ==
"reflect")
46 else if (
mode ==
"edge")
48 else if (
mode ==
"wrap")
56 if (model.CheckIfTensorAlreadyExist(
fNX) ==
false){
57 throw std::runtime_error(
"TMVA SOFIE Pad Op Input Tensor is not found in model");
63 throw std::runtime_error(
"TMVA SOFIE Pad Op supports now only Constant mode");
68 if (model.IsInitializedTensor(
fNP)) {
69 padsData =
static_cast<int64_t*
>(model.GetInitializedTensorData(
fNP).get());
71 throw std::runtime_error(
"TMVA SOFIE Pad Op supports now only initialized Pads data");
76 if (model.IsInitializedTensor(
fNCV)) {
77 T *
cData =
static_cast<T*
>(model.GetInitializedTensorData(
fNCV).get());
80 throw std::runtime_error(
"TMVA SOFIE Pad Op supports now only initialized Constant Value data");
83 std::vector<int64_t> axes;
85 if (model.IsInitializedTensor(
fNAX)) {
86 auto shape = model.GetTensorShape(
fNAX);
88 size_t nax = shape[0];
91 auto data =
static_cast<int64_t*
>(model.GetInitializedTensorData(
fNAX).get());
94 auto data =
static_cast<int32_t*
>(model.GetInitializedTensorData(
fNAX).get());
96 for (
size_t i = 0; i <
nax; i++)
99 throw std::runtime_error(
"TMVA SOFIE Pad Op invalid input Axes type");
102 throw std::runtime_error(
"TMVA SOFIE Pad Op supports now only initialized Axes data");
118 if (axes[i] == int64_t(i)) {
123 throw std::runtime_error(
"TMVA SOFIE Pad Op : invalid Pads values");
130 if (model.Verbose()) {
131 std::cout <<
"initializing Pad operator with pads .. : ";
133 std::cout <<
"{ " <<
p.first <<
" , " <<
p.second <<
"} ";
134 std::cout << std::endl;
145 throw std::runtime_error(
"TMVA SOFIE Operator Pad called to Generate without being initialized first");
147 std::stringstream out;
150 out <<
"\n//------ Pad\n";
154 out <<
"std::fill(tensor_" <<
fNY <<
", tensor_" <<
fNY <<
" + " <<
length <<
","
158 for (
int i = 0; i < dims; i++) {
159 for (
int j = 1;
j < i;
j++) out <<
SP;
160 out <<
"for (int id" << i <<
" = 0; id" << i <<
" < " <<
fInputShape[i] <<
"; id"
165 for (
int j = 0;
j < dims;
j++) out <<
SP;
166 out <<
"tensor_" <<
fNY <<
"[";
167 for (
int i = 0; i < dims; i++) {
169 if (
fPads[i].first != 0) out <<
" + " <<
fPads[i].first;
171 if (i < dims-1) out <<
" * " <<
outStride[i] <<
" + ";
173 out <<
"] =\n tensor_" <<
fNX <<
"[";
174 for (
int i = 0; i < dims; i++) {
176 if (i < dims-1) out <<
" * " <<
inputStride[i] <<
" + ";
179 for (
int i = dims-1; i >= 0; i--) {
180 for (
int j = 1;
j < i;
j++) out <<
SP;
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char mode
std::vector< size_t > fInputShape
std::vector< size_t > fOutputShape
void Initialize(RModel &model) override
std::string Generate(std::string OpName) override
std::vector< std::pair< int64_t, int64_t > > fPads
ROperator_Pad(const std::string &nameX, const std::string &nameP, const std::string &nameCV, const std::string &nameAX, const std::string &nameY, const std::string &mode)
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::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(const std::vector< size_t > &shape)
std::string ConvertShapeToString(const std::vector< size_t > &shape)
create variable transformations