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");
100 for (
size_t i = 0; i <
q; i++) {
142 <<
" and values {" <<
value <<
"} (constant) " << std::endl;
158 return "//---------------------------------------\n";
161 std::stringstream out;
175 out <<
SP <<
"// correct in case of negative gather indices\n";
176 out <<
SP <<
"for (size_t i = 0; i < " <<
indicesLength <<
"; i++){\n";
177 out <<
SP <<
SP <<
"if (tensor_" <<
fNIndices <<
"[i] < 0)\n";
188 std::string
index =
"j_" + std::to_string(
j);
189 for (
size_t k = 0; k <=
j; k++) out <<
SP;
193 for (
size_t i = 0; i <
q; i++) {
194 std::string
index =
"i_" + std::to_string(i);
195 for (
size_t k = 0; k <= i +
fAttrAxis; k++) out <<
SP;
200 std::string
index =
"j_" + std::to_string(
q+
j);
201 for (
size_t k = 0; k <=
q +
j; k++) out <<
SP;
207 out <<
SP <<
"{ // scalar case \n";
210 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
211 out <<
"size_t y_index = ";
213 if (
j > 0) out <<
" + ";
217 for (
size_t i = 0; i <
q; i++) {
223 if (
j +
q > 0) out <<
" + ";
233 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
234 out <<
"size_t i_index = ";
235 for (
size_t i = 0; i <
q; i++) {
236 if (i > 0) out <<
" + ";
246 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
247 out <<
"size_t k = static_cast<size_t>(" <<
"tensor_" <<
fNIndices <<
"[i_index]" <<
");\n";
249 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
250 out <<
"size_t x_index = k";
265 for (
size_t k = 0; k <
q +
r; k++) out <<
SP;
266 out <<
"tensor_" <<
fNY <<
"[y_index] = tensor_" <<
fNX <<
"[x_index];\n";
269 for (
size_t j =
q+
r-1;
j > 0;
j--) {
270 for (
size_t k = 0; k <
j; k++) out <<
SP;
275 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 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< size_t > GetTensorShape(const std::string &name) const
std::vector< Dim > GetDimTensorShape(const std::string &name) const
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 IsShapeTensor(const std::string &name) const
check if a tensor is a shape tensor
bool IsInitializedTensor(const std::string &name) const
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
void SetNotWritableInitializedTensor(const std::string &tensor_name)
ETensorType GetTensorType(std::string name) const
const std::vector< Dim > & GetShapeTensorValues(const std::string &tensor_name) const
void AddShapeTensor(const std::string &name, const std::vector< Dim > &shapeValues, bool scalar=false)
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< 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::size_t ConvertShapeToLength(const std::vector< size_t > &shape)
std::string ConvertValuesToString(size_t n, const T *data)
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 ConvertDimShapeToLength(const std::vector< Dim > &shape)
std::string ConvertShapeToString(const std::vector< size_t > &shape)
create variable transformations