1#ifndef TMVA_SOFIE_ROPERATOR_GATHER
2#define TMVA_SOFIE_ROPERATOR_GATHER
13namespace Experimental{
54 if (!model.CheckIfTensorAlreadyExist(
fNX)) {
55 throw std::runtime_error(
"TMVA SOFIE Gather Op Input Tensor " +
fNX +
" is not found in model");
73 if (model.IsInitializedTensor(
fNIndices)) {
77 int64_t*
data =
static_cast<int64_t*
>(model.GetInitializedTensorData(
fNIndices).get());
108 for (
size_t i = 0; i <
q; i++) {
115 if (model.IsInitializedTensor(
fNX) &&
q <= 1 &&
r == 1 &&
fIndices.size() > 0) {
119 auto inputData =
static_cast<int64_t*
>(model.GetInitializedTensorData(
fNX).get());
131 else if (model.IsShapeTensor(
fNX) &&
q <=1 &&
fIndices.size() > 0) {
150 <<
" and values {" <<
value <<
"} (constant) " << std::endl;
155 model.AddIntermediateTensor(
fNY, model.GetTensorType(
fNX),
fShapeY);
165 std::stringstream out;
169 out <<
"//--------------------(constant)----------\n";
174 out <<
"//--------------------(shape)----------\n";
195 std::string
index =
"j_" + std::to_string(
j);
196 for (
size_t k = 0; k <=
j; k++) out <<
SP;
200 for (
size_t i = 0; i <
q; i++) {
201 std::string
index =
"i_" + std::to_string(i);
202 for (
size_t k = 0; k <= i +
fAttrAxis; k++) out <<
SP;
207 std::string
index =
"j_" + std::to_string(
q+
j);
208 for (
size_t k = 0; k <=
q +
j; k++) out <<
SP;
214 out <<
SP <<
"{ // scalar case \n";
217 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
218 out <<
"size_t y_index = ";
220 if (
j > 0) out <<
" + ";
224 for (
size_t i = 0; i <
q; i++) {
230 if (
j +
q > 0) out <<
" + ";
240 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
241 out <<
"size_t i_index = ";
242 for (
size_t i = 0; i <
q; i++) {
243 if (i > 0) out <<
" + ";
255 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
257 out <<
"int64_t k_i = static_cast<int64_t>(tensor_" <<
fNIndices <<
"[i_index]);\n";
258 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
259 out <<
"size_t k = static_cast<size_t>(k_i < 0 ? k_i + " <<
fShapeX[
fAttrAxis] <<
" : k_i);\n";
261 out <<
"size_t k = static_cast<size_t>(" <<
"tensor_" <<
fNIndices <<
"[i_index]" <<
");\n";
264 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
265 out <<
"size_t x_index = k";
280 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
281 out <<
"tensor_" <<
fNY <<
"[y_index] = tensor_" <<
fNX <<
"[x_index];\n";
284 for (
size_t j =
q+
r-1;
j > 0;
j--) {
285 for (
size_t k = 0; k <
j; k++) out <<
SP;
290 out <<
SP <<
"} // close Gather scope for scalar case \n";
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 data
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 WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
void Initialize(RModel &model) override
std::vector< int64_t > fIndices
std::string Generate(std::string opName) override
ROperator_Gather(int64_t attrAxis, std::string nameX, std::string nameIndices, std::string nameY)
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input) override
std::vector< Dim > fShapeY
std::vector< Dim > fShapeX
std::vector< Dim > fShapeIndices
std::vector< Dim > fOutputShapeData
std::vector< std::string_view > fInputTensorNames
bool fIsOutputParamShape
flag to identify of the output represents a parametric shape (can be known at compile time)
bool fIsOutputConstant
flag to identify if operator has a constant output (no need to generate code)
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::string ConvertDimShapeToString(const std::vector< Dim > &shape)
std::size_t ConvertShapeToLength(const std::vector< size_t > &shape)
std::string ConvertValuesToString(size_t n, const T *data, size_t maxprint=-1)
std::vector< size_t > ConvertShapeToInt(const std::vector< Dim > &shape)
Convert shape based on Dim to integer format.
std::string ConvertTypeToString(ETensorType type)
std::string ConvertShapeToString(const std::vector< size_t > &shape)
create variable transformations