1#ifndef TMVA_SOFIE_ROPERATOR_Tile
2#define TMVA_SOFIE_ROPERATOR_Tile
11namespace Experimental{
28 ROperator_Tile(std::string nameRepeat, std::string nameInput, std::string nameY):
29 fNRepeats(UTILITY::Clean_name(nameRepeat)),
fNInput(UTILITY::Clean_name(nameInput)),
fNY(UTILITY::Clean_name(nameY)){}
36 std::vector<size_t> ret =
input[0];
38 for(
size_t i=0; i <
input[1].size(); i++) {
39 ret[i]=ret[i]*
input[1][i];
47 throw std::runtime_error(
"TMVA SOFIE Tile Op Input Tensor is not found in model");
50 throw std::runtime_error(
"TMVA SOFIE Tile Op Input Tensor is not found in model");
57 auto repeat_shape =
static_cast<size_t*
>(repptr.get());
59 if (repeat_shape ==
nullptr) {
60 throw std::runtime_error(
"Failed to retrieve the data for the repeats tensor.");
65 if (repeats_shape.size() != 1) {
66 throw std::runtime_error(
"Repeats tensor is not 1D.");
68 size_t num_elements = repeats_shape[0];
70 std::vector<size_t> repeats_vector(repeat_shape, repeat_shape + num_elements);
78 OpName =
"op_" + OpName;
80 throw std::runtime_error(
"TMVA SOFIE Tile Op called to Generate without being initialized first");
87 std::stringstream out;
90 out <<
"///-------- Tile operator\n";
93 std::vector<size_t> repeats =
fShapeY;
94 for (
size_t i = 0; i < repeats.size(); i++)
99 out <<
"int s = 1;\n";
101 out <<
"for (int i = " <<
fShapeInput.size()-1 <<
"; i >=0; i--) {\n";
102 out <<
SP <<
"int r = repeats[i];\n";
105 out <<
SP <<
"int i_offset = 0, o_offset = 0;\n";
106 out <<
SP <<
"s = s * input_shape[i];\n";
109 out <<
SP <<
SP <<
"for (int j = 0; j < inputLength/s ; j++) {\n";
110 out <<
SP <<
SP <<
SP <<
"for (int k = 0; k < r ; k++) {\n";
111 out <<
SP <<
SP <<
SP <<
SP <<
"std::copy(" <<
input <<
"+ i_offset, "
112 <<
input <<
"+ i_offset + s, " <<
output <<
"+ o_offset);\n";
113 out <<
SP <<
SP <<
SP <<
SP <<
"o_offset += s;\n";
114 out <<
SP <<
SP <<
SP <<
"}\n";
115 out <<
SP <<
SP <<
SP <<
"i_offset += s;\n";
116 out <<
SP <<
SP <<
"}\n";
117 out <<
SP <<
"} else {\n";
119 out <<
SP <<
SP <<
"for (int j = inputLength/s - 1 ; j>=0; j--) {\n";
120 out <<
SP <<
SP <<
SP <<
"o_offset = j*s*r;\n";
121 out <<
SP <<
SP <<
SP <<
"i_offset = j*s;\n";
122 out <<
SP <<
SP <<
SP <<
"for (int k = 0; k < r ; k++) {\n";
123 out <<
SP <<
SP <<
SP <<
SP <<
"std::copy(" <<
output <<
"+ i_offset, "
124 <<
output <<
"+ i_offset + s, " <<
output <<
"+ o_offset);\n";
125 out <<
SP <<
SP <<
SP <<
SP <<
"o_offset += s;\n";
126 out <<
SP <<
SP <<
SP <<
"}\n";
127 out <<
SP <<
SP <<
"}\n";
129 out <<
SP <<
"s *= r;\n";
130 out <<
SP <<
"inputLength *= r;\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)
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input)
ROperator_Tile(std::string nameRepeat, std::string nameInput, std::string nameY)
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input)
std::vector< size_t > fShapeY
std::vector< size_t > fShapeInput
std::string Generate(std::string OpName)
void Initialize(RModel &model)
const std::string SP
space used to correctly indent the generated C++ code
std::string ConvertShapeToString(std::vector< size_t > shape)
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations