1#ifndef TMVA_SOFIE_ROPERATOR_GatherND
2#define TMVA_SOFIE_ROPERATOR_GatherND
13namespace Experimental{
35 ROperator_GatherND(
int batch_dims, std::string nameX, std::string nameIndices, std::string nameY):
36 fBatchDims(batch_dims),
fNX(UTILITY::Clean_name(nameX)),
fNIndices(UTILITY::Clean_name(nameIndices)),
fNY(UTILITY::Clean_name(nameY)) {
42 if (!model.CheckIfTensorAlreadyExist(
fNX)) {
43 throw std::runtime_error(
"TMVA SOFIE GatherND Op Input Tensor " +
fNX +
" is not found in model");
56 throw std::runtime_error(
"TMVA SOFIE GatherND : rank of Indices is < 1");
59 throw std::runtime_error(
"TMVA SOFIE GatherND : rank of input tensor is < 1");
62 throw std::runtime_error(
"TMVA SOFIE GatherND : invalid batch dim value");
69 throw std::runtime_error(
"TMVA SOFIE GatherND : invalid input or index shape for " + std::to_string(i));
76 throw std::runtime_error(
"TMVA SOFIE GatherND : Index_shape(-1) is not known");
81 if (last_index_shape < 1 || last_index_shape >
r -
fBatchDims) {
82 throw std::runtime_error(
"TMVA SOFIE GatherND : Index_shape(-1) has wrong value " +
83 std::to_string(last_index_shape));
86 size_t output_rank =
r +
q -1 - last_index_shape -
fBatchDims;
91 if (
fShapeY.size() != output_rank) {
95 <<
" and output rank should be " << output_rank << std::endl;
96 throw std::runtime_error(
"TMVA SOFIE GatherND : Something is wrong in initialization ");
101 model.AddIntermediateTensor(
fNY, model.GetTensorType(
fNX),
fShapeY);
172 std::string
Generate(std::string opName)
override {
175 return "//---------------------------------------\n";
177 opName =
"op_" + opName;
178 std::stringstream out;
195 std::string outIndex;
199 std::string
index =
"i_" + std::to_string(j);
200 for (
size_t k = 0; k <= j; k++) out <<
SP;
208 if (stridesY[j].GetVal() !=
"1")
209 outIndex +=
" * " + stridesY[j].GetVal();
211 if (stridesX[j].GetVal() !=
"1")
212 inIndex +=
" * " + stridesX[j].GetVal();
214 if (stridesIndices[j].GetVal() !=
"1")
215 idIndex +=
" * " + stridesIndices[j].GetVal();
219 std::string
index =
"i_" + std::to_string(j);
220 for (
size_t k = 0; k <= j; k++) out <<
SP;
227 if (stridesY[j].GetVal() !=
"1")
228 outIndex +=
" * " + stridesY[j].GetVal();
230 if (stridesIndices[j].GetVal() !=
"1")
231 idIndex +=
" * " + stridesIndices[j].GetVal();
235 for (
size_t l = 0;
l < ss;
l++) {
236 std::string indexIndex =
237 idIndex.empty() ? std::to_string(
l) : (
l > 0 ? idIndex +
" + " + std::to_string(
l) : idIndex);
238 for (
size_t k = 0; k <=
q - 1; k++)
240 out <<
"int64_t index_" <<
l <<
" = tensor_" <<
fNIndices <<
"[" << indexIndex <<
"];\n";
241 for (
size_t k = 0; k <=
q - 1; k++)
245 for (
size_t k = 0; k <=
q - 1; k++) out <<
SP;
246 out <<
"size_t inputIndex = " << inIndex;
247 for (
size_t l = 0;
l < ss;
l++) {
249 if (!inIndex.empty() ||
l > 0)
251 out <<
"index_" <<
l;
256 for (
size_t k = 0; k <=
q - 1; k++) out <<
SP;
259 out <<
"tensor_" <<
fNY <<
"[" << outIndex <<
"] = "
260 <<
"tensor_" <<
fNX <<
"[inputIndex];\n";
263 out <<
"std::copy(tensor_" <<
fNX <<
" + inputIndex, tensor_" <<
fNX <<
" + inputIndex + "
265 <<
"tensor_" <<
fNY <<
"+" << outIndex <<
");\n";
270 for (
size_t j =
q-1; j > 0; j--) {
271 for (
size_t k = 0; k <j; k++) out <<
SP;
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
ROperator_GatherND(int batch_dims, std::string nameX, std::string nameIndices, std::string nameY)
std::vector< int64_t > fIndices
void Initialize(RModel &model) override
std::vector< Dim > fShapeIndices
std::vector< Dim > fShapeY
std::string Generate(std::string opName) override
std::vector< Dim > fShapeX
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 ConvertDimShapeToString(const std::vector< Dim > &shape)
std::string ConvertTypeToString(ETensorType type)
create variable transformations