1#ifndef TMVA_SOFIE_ROPERATOR_GATHER
2#define TMVA_SOFIE_ROPERATOR_GATHER
13namespace Experimental{
37 ROperator_Gather(int64_t attrAxis, std::string nameX, std::string nameIndices, std::string nameY):
38 fAttrAxis(attrAxis),
fNX(UTILITY::Clean_name(nameX)),
fNIndices(UTILITY::Clean_name(nameIndices)),
fNY(UTILITY::Clean_name(nameY)) {
52 throw std::runtime_error(
"TMVA SOFIE Gather Op Input Tensor " +
fNX +
" is not found in model");
57 std::runtime_error(
"TMVA::SOFIE - Tensor " +
fNIndices +
" is not initialized.");
71 fIndices = std::vector<int64_t>(indicesData, indicesData + indicesLength);
72 for (
size_t i = 0; i < indicesLength; i++) {
85 for (
size_t i = 0; i <
q; i++) {
97 OpName =
"op_" + OpName;
98 std::stringstream out;
108 out <<
SP <<
"std::vector<int64_t> " << OpName <<
"_indices = {";
110 for (
size_t i = 0; i < indicesLength; i++) {
111 out <<
fIndices[i] << (i + 1 < indicesLength?
", " :
"};\n");
117 for (
size_t j = 0; j < size_t(
fAttrAxis); j++) {
118 std::string
index =
"j_" + std::to_string(j);
122 for (
size_t i = 0; i <
q; i++) {
123 std::string
index =
"i_" + std::to_string(i);
128 std::string
index =
"j_" + std::to_string(j);
132 out <<
SP <<
SP <<
SP <<
"size_t y_index = 0;\n";
133 for (
size_t j = 0; j < size_t(
fAttrAxis); j++) {
134 out <<
SP <<
SP <<
SP <<
"y_index += j_" + std::to_string(j) +
" * " << stridesY[j] <<
";\n";
136 for (
size_t i = 0; i <
q; i++) {
137 out <<
SP <<
SP <<
SP <<
"y_index += i_" + std::to_string(i) +
" * " << stridesY[
fAttrAxis + i] <<
";\n";
140 out <<
SP <<
SP <<
SP <<
"y_index += j_" + std::to_string(j) +
" * " << stridesY[
q + j] <<
";\n";
143 out <<
SP <<
SP <<
SP <<
"size_t i_index = 0;\n";
144 for (
size_t i = 0; i <
q; i++) {
145 out <<
SP <<
SP <<
SP <<
"i_index += i_" + std::to_string(i) +
" * " << stridesIndices[i] <<
";\n";
148 out <<
SP <<
SP <<
SP <<
"size_t k = static_cast<size_t>(" << OpName <<
"_indices[i_index]" <<
");\n";
150 out <<
SP <<
SP <<
SP <<
"size_t x_index = k * " << stridesX[
fAttrAxis] <<
";\n";
151 for (
size_t j = 0; j < size_t(
fAttrAxis); j++) {
152 out <<
SP <<
SP <<
SP <<
"x_index += j_" + std::to_string(j) +
" * " << stridesX[j] <<
";\n";
155 out <<
SP <<
SP <<
SP <<
"x_index += j_" + std::to_string(j - 1) +
" * " << stridesX[j] <<
";\n";
157 out <<
SP <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[y_index] = tensor_" <<
fNX <<
"[x_index];\n";
161 out <<
SP <<
SP <<
SP <<
"}\n";
164 for (
size_t i = 0; i <
q; i++) {
165 out <<
SP <<
SP <<
"}\n";
168 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< std::size_t > shape)
bool CheckIfTensorAlreadyExist(std::string tensor_name)
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)
std::string Generate(std::string OpName)
std::vector< size_t > fShapeIndices
ROperator_Gather(int64_t attrAxis, std::string nameX, std::string nameIndices, std::string nameY)
void Initialize(RModel &model)
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input)
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input)
std::vector< int64_t > fIndices
std::vector< size_t > fShapeY
std::vector< size_t > fShapeX
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 ConvertTypeToString(ETensorType type)
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations