1#ifndef TMVA_SOFIE_ROPERATOR_GATHER
2#define TMVA_SOFIE_ROPERATOR_GATHER
13namespace Experimental{
36 ROperator_Gather(int64_t attrAxis, std::string nameX, std::string nameIndices, std::string nameY):
37 fAttrAxis(attrAxis),
fNX(UTILITY::Clean_name(nameX)),
fNIndices(UTILITY::Clean_name(nameIndices)),
fNY(UTILITY::Clean_name(nameY)) {
51 throw std::runtime_error(
"TMVA SOFIE Gather Op Input Tensor " +
fNX +
" is not found in model");
71 for (
size_t i = 0; i < indicesLength; i++) {
72 if (indicesData[i] < 0) {
77 fIndices = std::vector<int64_t>(indicesData, indicesData + indicesLength);
90 for (
size_t i = 0; i <
q; i++) {
102 outputData[0] = inputData[
fIndices[0]];
123 return "//---------------------------------------\n";
125 OpName =
"op_" + OpName;
126 std::stringstream out;
127 out <<
"//--------- Gather operator \n";
140 out <<
SP <<
"// correct in case of negative gather indices\n";
141 out <<
SP <<
"for (size_t i = 0; i < " << indicesLength <<
"; i++){\n";
142 out <<
SP <<
SP <<
"if (tensor_" <<
fNIndices <<
"[i] < 0)\n";
152 for (
size_t j = 0; j < size_t(
fAttrAxis); j++) {
153 std::string
index =
"j_" + std::to_string(j);
158 out <<
SP <<
SP <<
"{\n";
159 for (
size_t i = 0; i <
q; i++) {
160 std::string
index =
"i_" + std::to_string(i);
165 std::string
index =
"j_" + std::to_string(j);
169 out <<
SP <<
SP <<
SP <<
"size_t y_index = 0;\n";
170 for (
size_t j = 0; j < size_t(
fAttrAxis); j++) {
171 out <<
SP <<
SP <<
SP <<
"y_index += j_" + std::to_string(j) +
" * " << stridesY[j] <<
";\n";
173 for (
size_t i = 0; i <
q; i++) {
174 out <<
SP <<
SP <<
SP <<
"y_index += i_" + std::to_string(i) +
" * " << stridesY[
fAttrAxis + i] <<
";\n";
177 out <<
SP <<
SP <<
SP <<
"y_index += j_" + std::to_string(j) +
" * " << stridesY[
q + j] <<
";\n";
180 out <<
SP <<
SP <<
SP <<
"size_t i_index = 0;\n";
181 for (
size_t i = 0; i <
q; i++) {
182 out <<
SP <<
SP <<
SP <<
"i_index += i_" + std::to_string(i) +
" * " << stridesIndices[i] <<
";\n";
185 out <<
SP <<
SP <<
SP <<
"size_t k = static_cast<size_t>(" <<
"tensor_" <<
fNIndices <<
"[i_index]" <<
");\n";
187 out <<
SP <<
SP <<
SP <<
"size_t x_index = k * " << stridesX[
fAttrAxis] <<
";\n";
188 for (
size_t j = 0; j < size_t(
fAttrAxis); j++) {
189 out <<
SP <<
SP <<
SP <<
"x_index += j_" + std::to_string(j) +
" * " << stridesX[j] <<
";\n";
192 out <<
SP <<
SP <<
SP <<
"x_index += j_" + std::to_string(j - 1) +
" * " << stridesX[j] <<
";\n";
194 out <<
SP <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[y_index] = tensor_" <<
fNX <<
"[x_index];\n";
198 out <<
SP <<
SP <<
SP <<
"}\n";
202 out <<
SP <<
SP <<
"}\n";
203 for (
size_t i = 0; i <
q; i++) {
204 out <<
SP <<
SP <<
"}\n";
207 for (
size_t j = 0; j < size_t(
fAttrAxis); j++) {
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::string Generate(std::string OpName)
void Initialize(RModel &model)
std::vector< size_t > fShapeIndices
std::vector< size_t > fShapeY
std::vector< int64_t > fIndices
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input)
std::vector< size_t > fShapeX
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input)
ROperator_Gather(int64_t attrAxis, std::string nameX, std::string nameIndices, std::string nameY)
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< 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