1#ifndef TMVA_SOFIE_ROPERATOR_GATHER
2#define TMVA_SOFIE_ROPERATOR_GATHER
13namespace Experimental{
53 throw std::runtime_error(
"TMVA SOFIE Gather Op Input Tensor " +
fNX +
" is not found in model");
92 for (
size_t i = 0; i <
q; i++) {
125 return "//---------------------------------------\n";
128 std::stringstream out;
129 out <<
"//--------- Gather operator \n";
142 out <<
SP <<
"// correct in case of negative gather indices\n";
143 out <<
SP <<
"for (size_t i = 0; i < " <<
indicesLength <<
"; i++){\n";
144 out <<
SP <<
SP <<
"if (tensor_" <<
fNIndices <<
"[i] < 0)\n";
155 std::string
index =
"j_" + std::to_string(
j);
160 out <<
SP <<
SP <<
"{\n";
161 for (
size_t i = 0; i <
q; i++) {
162 std::string
index =
"i_" + std::to_string(i);
167 std::string
index =
"j_" + std::to_string(
j);
171 out <<
SP <<
SP <<
SP <<
"size_t y_index = 0;\n";
173 out <<
SP <<
SP <<
SP <<
"y_index += j_" + std::to_string(
j) +
" * " <<
stridesY[
j] <<
";\n";
175 for (
size_t i = 0; i <
q; i++) {
179 out <<
SP <<
SP <<
SP <<
"y_index += j_" + std::to_string(
j) +
" * " <<
stridesY[
q +
j] <<
";\n";
182 out <<
SP <<
SP <<
SP <<
"size_t i_index = 0;\n";
183 for (
size_t i = 0; i <
q; i++) {
184 out <<
SP <<
SP <<
SP <<
"i_index += i_" + std::to_string(i) +
" * " <<
stridesIndices[i] <<
";\n";
187 out <<
SP <<
SP <<
SP <<
"size_t k = static_cast<size_t>(" <<
"tensor_" <<
fNIndices <<
"[i_index]" <<
");\n";
191 out <<
SP <<
SP <<
SP <<
"x_index += j_" + std::to_string(
j) +
" * " <<
stridesX[
j] <<
";\n";
194 out <<
SP <<
SP <<
SP <<
"x_index += j_" + std::to_string(
j - 1) +
" * " <<
stridesX[
j] <<
";\n";
196 out <<
SP <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[y_index] = tensor_" <<
fNX <<
"[x_index];\n";
200 out <<
SP <<
SP <<
SP <<
"}\n";
204 out <<
SP <<
SP <<
"}\n";
205 for (
size_t i = 0; i <
q; i++) {
206 out <<
SP <<
SP <<
"}\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 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
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)
void AddConstantTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape, std::shared_ptr< void > data)
bool IsInitializedTensor(const std::string &name) const
const std::vector< size_t > & GetTensorShape(std::string name)
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
void SetNotWritableInitializedTensor(const std::string &tensor_name)
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
void Initialize(RModel &model) override
std::vector< size_t > fShapeIndices
std::vector< size_t > fShapeY
std::vector< int64_t > fIndices
std::vector< size_t > fShapeX
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< std::string_view > fInputTensorNames
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 ConvertValuesToString(size_t n, const T *data)
std::string ConvertShapeToString(std::vector< size_t > shape)
std::string ConvertTypeToString(ETensorType type)
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations