1#ifndef TMVA_SOFIE_ROperator_Expand
2#define TMVA_SOFIE_ROperator_Expand
44 if (!model.CheckIfTensorAlreadyExist(
fNX)) {
45 throw std::runtime_error(
"TMVA SOFIE Expand Op Input Tensor " +
fNX +
" is not found in model");
48 if (model.IsInitializedTensor(
fNShape)) {
51 static_cast<int64_t *
>(model.GetInitializedTensorData(
fNShape).get());
54 throw std::runtime_error(
"TMVA::SOFIE - Expand operator shape must be a 1d tensor.");
58 for (
size_t i = 0; i <
N; i++) {
59 if ( shapeData[i] < 0)
60 throw std::runtime_error(
"TMVA::SOFIE - Expand: invalid shape value " + std::to_string(shapeData[i]));
62 std::vector<size_t> shape(shapeData, shapeData +
N);
64 }
else if (model.IsShapeTensor(
fNShape)) {
70 auto shapeOfInputShape = model.GetTensorShape(
fNShape);
72 for (
size_t i = 0; i <
fShapeDim.size(); i++) {
81 std::vector<size_t> shapeX;
82 std::vector<size_t> shapeY;
92 assert(!shapeX.empty() && !shapeY.empty());
95 auto data = model.GetInitializedTensorData(
fNX);
97 std::shared_ptr<void> broadcastedData(
99 std::default_delete<T[]>());
101 model.UpdateInitializedTensor(
fNX, model.GetTensorType(
fNX), shapeY, broadcastedData);
104 model.SetNotWritableInitializedTensor(
fNX);
105 data = broadcastedData;
109 model.AddConstantTensor(
fNY, model.GetTensorType(
fNX), shapeY,
data);
112 model.AddIntermediateTensor(
fNY, model.GetTensorType(
fNX), shapeY);
116 model.AddIntermediateTensor(
fNY, model.GetTensorType(
fNX),
fShapeY);
119 if (model.Verbose()) {
126 std::stringstream out;
130 out <<
"// Copying initialized tensor " <<
fNX <<
" to " <<
fNY <<
"\n";
131 out <<
SP <<
"std::copy(tensor_" <<
fNX <<
", " <<
"tensor_" <<
fNX <<
" + " <<
length <<
", tensor_" <<
fNY <<
");\n";
136 std::string
Generate(std::string opName)
override {
138 opName =
"op_" + opName;
140 throw std::runtime_error(
"TMVA SOFIE Expand Op called to Generate without being initialized first");
142 std::stringstream out;
146 for (
size_t i = 0; i <
fShapeDim.size(); i++) {
147 out <<
SP <<
"size_t " <<
fShapeDim[i] <<
" = " <<
"tensor_" <<
fNShape <<
"[" << i <<
"];\n";
153 if (lengthX != lengthY) {
154 out <<
SP <<
"if ( (" << lengthX <<
") < (" << lengthY <<
") ) {\n";
155 out <<
SP <<
SP <<
"// Broadcasting uninitialized tensor " <<
fNX <<
"\n";
157 <<
", tensor_"<<
fNY<<
");\n";
158 out <<
SP <<
"} else {\n";
159 out <<
SP <<
SP <<
"std::copy(tensor_" <<
fNX <<
", " <<
"tensor_" <<
fNX <<
" + (" << lengthX <<
"), tensor_" <<
fNY <<
");\n";
163 out <<
SP <<
"std::copy(tensor_" <<
fNX <<
", " <<
"tensor_" <<
fNX <<
" + (" << lengthX <<
"), tensor_" <<
fNY <<
");\n";
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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
std::vector< size_t > fShape
ROperator_Expand(std::string nameX, std::string nameShape, std::string nameY)
void Initialize(RModel &model) override
std::vector< Dim > fShapeX
std::string GenerateInitCode() override
std::vector< Dim > fShapeY
std::string Generate(std::string opName) override
std::vector< Dim > fShapeDim
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
bool AreSameShape(const std::vector< size_t > &, const std::vector< size_t > &)
std::vector< size_t > MultidirectionalBroadcastShape(std::vector< std::vector< size_t > >)
T * UnidirectionalBroadcast(const T *data, const std::vector< size_t > &shape, const std::vector< size_t > &targetShape)
std::string ConvertDimShapeToString(const std::vector< Dim > &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 ConvertTypeToString(ETensorType type)
std::string ConvertDimShapeToLength(const std::vector< Dim > &shape)
create variable transformations