1#ifndef TMVA_SOFIE_ROPERATOR_Concat
2 #define TMVA_SOFIE_ROPERATOR_Concat
16 namespace Experimental{
41 [](
const std::string& s) -> std::string_view { return s; });
47 std::vector<std::vector<size_t>>
ret(1);
53 throw std::runtime_error(
"TMVA SOFIE Concat Op - invalid axis value ");
58 for (
size_t i = 0; i <
inputs.size(); i++) {
60 throw std::runtime_error(
"TMVA SOFIE Concat Op - input tensors have different shapes " +
66 throw std::runtime_error(
"TMVA SOFIE Concat Op - input tensors have wrong shapes " +
76 std::vector<int> stack;
79 for(
size_t i = 0; i <
inputs.size(); i++) {
81 throw std::runtime_error(
"TMVA SOFIE Concat Op - input tensors have different shapes " +
fInputs[i] +
" : " +
88 throw std::runtime_error(
"TMVA SOFIE Concat Op - input tensors have wrong shapes " +
108 throw std::runtime_error(
"TMVA SOFIE Concat Op - invalid axis value ");
112 for (
size_t i = 0; i <
inputs.size(); i++) {
114 throw std::runtime_error(
"TMVA SOFIE Concat Op - input tensors have different shapes " +
fInputs[i] +
" : " +
124 static_cast<size_t>(-1)};
133 throw std::runtime_error(
"TMVA SOFIE Concat Op - input tensors have wrong shapes " +
143 auto &
dimNames = model.GetDimShapeNames();
164 throw std::runtime_error(
"TMVA SOFIE Concat Op - stacking (i.e. COncatFromSequence with new_axis=1) is not supported ");
171 model.AddNeededHelperFunction(
"Copy");
174 if (model.CheckIfTensorAlreadyExist(it) ==
false) {
175 throw std::runtime_error(
"TMVA SOFIE Concat Op Input Tensor " + it +
" is not found in model");
178 if (!model.IsDynamicTensor(it)) {
187 std::cout <<
"Initialize Concat operator with defined inputs shapes, "
194 std::cout <<
"Initialize Concat operator with dynamic inputs shapes, "
206 if (model.IsDynamicTensor(
input)) {
211 if (!model.IsInitializedTensor(
input)) {
212 if (model.IsShapeTensor(
input)) {
242 auto inputData =
static_cast<int64_t *
>(model.GetInitializedTensorData(
input).get());
248 model.SetNotWritableInitializedTensor(
input);
251 if (model.Verbose()) {
258 throw std::runtime_error(
"TMVA SOFIE Concat Op - output shape for shape tensor must have rank 1");
266 if (model.IsShapeTensor(
input)) {
268 }
else if (model.IsInitializedTensor(
input)) {
270 auto intData =
static_cast<int64_t *
>(model.GetInitializedTensorData(
input).get());
271 for (
size_t i = 0; i <
inputData.size(); i++)
275 throw std::runtime_error(
"TMVA SOFIE Concat Operator- invalid tensor input " +
input +
276 " for shape output type");
284 if (model.Verbose()) {
292 if (model.Verbose()) {
300 std::stringstream out;
307 out <<
"// output is a shape tensor defined by the concatenation of the input shapes\n";
316 for(
int i = 0; i<
fAxis; ++i){
324 for(
size_t i=0; i<
fInputs.size(); ++i) {
330 out <<
", " <<
"tensor_" <<
fInputs[i] <<
", " +
length <<
");\n";
342 for (
int i = 0; i <
fAxis; ++i) {
344 out <<
SP <<
"for (size_t i" << i <<
" = 0; i" << i <<
" < " <<
fOutputShape[i].GetVal() <<
"; ++i" << i <<
") {\n";
347 out <<
SP <<
SP <<
SP <<
"int idxOut = ";
348 for (
int k = 0; k <
fAxis; k++) {
349 if (k > 0) out <<
" + ";
350 out <<
outStride[k].GetVal() <<
"*i" << k;
357 out <<
SP <<
SP <<
SP <<
"int idxIn" <<
j <<
" = ";
358 for (
int k = 0; k <
fAxis; k++) {
359 if (k > 0) out <<
" + ";
363 out <<
SP <<
SP <<
SP <<
"for (size_t iC = 0; iC < " <<
inStrides[
j][
fAxis-1].GetVal() <<
"; ++iC) {\n";
364 out <<
SP <<
SP <<
SP <<
SP <<
"tensor_" <<
fOutput <<
"[idxOut+iC] = tensor_" <<
fInputs[
j] <<
"[idxIn" <<
j <<
"+iC];\n";
365 out <<
SP <<
SP <<
SP <<
"}\n";
368 for (
int i = 0; i <
fAxis; ++i) {
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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 Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
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 Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
const_iterator begin() const
const_iterator end() const
std::vector< std::string > fInputs
std::vector< Dim > ShapeInference(const std::vector< std::vector< Dim > > &inputs, const RModel &model)
std::vector< Dim > fOutputShape
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > inputs)
std::vector< std::vector< Dim > > fInputShapes
ROperator_Concat(std::vector< std::string > inputs, int axis, int newAxis, std::string output)
void Initialize(RModel &model) override
std::string Generate(std::string opName) override
std::vector< Dim > fOutputShapeData
std::vector< std::string_view > fInputTensorNames
bool fIsOutputParamShape
flag to identify of the output represents a parametric shape (can be known at compile time)
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::string Clean_name(std::string input_tensor_name)
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::size_t ConvertShapeToLength(const std::vector< size_t > &shape)
std::string ConvertValuesToString(size_t n, const T *data, size_t maxprint=-1)
std::vector< Dim > ConvertShapeToDim(const std::vector< size_t > &shape)
Convert shape from integer format to dynamic one (based on Dim)
std::vector< size_t > ConvertShapeToInt(const std::vector< Dim > &shape)
Convert shape based on Dim to integer format.
std::string ConvertDimShapeToLength(const std::vector< Dim > &shape)
std::string ConvertShapeToString(const std::vector< size_t > &shape)
create variable transformations