1#ifndef TMVA_SOFIE_ROPERATOR_RANGE
2#define TMVA_SOFIE_ROPERATOR_RANGE
30 ROperator_Range(std::string start, std::string limit, std::string delta, std::string nameOutput):
33 if (std::is_same<T, float>::value) {
35 }
else if (std::is_same<T, int64_t>::value) {
38 static_assert( (std::is_same_v<T, float> || std::is_same_v<T, int64_t>),
39 "TMVA::SOFIE - Unsupported type by Range operator");
50 std::runtime_error(
"TMVA SOFIE Range Op Input Tensor " +
fNStart +
"is not found in model");
54 std::runtime_error(
"TMVA SOFIE Range Op Input Tensor " +
fNLimit +
"is not found in model");
58 std::runtime_error(
"TMVA SOFIE Range Op Input Tensor " +
fNDelta +
"is not found in model");
64 auto analyzeInput = [&](
const std::string & tName, T &
value,
Dim & dim) {
69 throw std::runtime_error(
"TMVA SOFIE Range Op Input Tensor has invalid input data");
76 value =
static_cast<T
>(dim.dim);
90 int res1 = analyzeInput(
fNStart, start_value, start_dim);
91 int res2 = analyzeInput(
fNLimit, limit_value, limit_dim);
92 int res3 = analyzeInput(
fNDelta, delta_value, delta_dim);
93 if (res1 == 0 || res2 == 0 || res3 == 0) {
98 }
else if (res1 == 1 && res2 == 1 && res3 == 1) {
99 size_t number_of_elements = std::max(
static_cast<int>(std::ceil((limit_value - start_value) / delta_value )) , 0 );
103 std::vector<T> output(number_of_elements);
104 for (
size_t i=0; i<number_of_elements; ++i) {
105 output[i] = start_value + (i * delta_value);
107 std::vector<size_t> shape = {number_of_elements};
112 std::string start = (res1 == 1) ? std::to_string(start_value) : start_dim.
GetVal();
113 std::string limit = (res2 == 1) ? std::to_string(limit_value) : limit_dim.
GetVal();
114 std::string delta = (res3 == 1) ? std::to_string(delta_value) : delta_dim.
GetVal();
117 if (delta_value == 1)
118 s <<
"std::max(std::ceil("<< limit <<
" - " << start <<
"),0.0f)";
120 s <<
"std::max(std::ceil(("<< limit <<
" - " << start <<
")/" << delta <<
"),0.0f)";
126 s <<
"std::max((" << limit <<
" - " << start <<
"),0L)";
129 s <<
"((" << limit <<
")/" << delta <<
")";
131 s <<
"std::max((" << limit <<
" - " << start <<
")/"<< delta <<
"),0L)";
139 fShape = {
Dim {s.str(),
static_cast<size_t>(-1)} };
147 std::cout << std::endl;
151 std::string
Generate(std::string opName)
override {
153 std::stringstream out;
157 opName =
"op_" + opName;
159 throw std::runtime_error(
"TMVA SOFIE Range operator called to Generate without being initialized first");
162 std::string outputSizeVar;
163 std::string outputSize =
fShape[0].param;
164 if (outputSize.find(
"range_size") != std::string::npos) {
165 outputSizeVar = outputSize;
166 outputSize =
"static_cast<size_t>(std::max(std::ceil((static_cast<float>(*tensor_" +
fNLimit +
167 ") - static_cast<float>(*tensor_" +
fNStart +
")) / static_cast<float>(*tensor_" +
fNDelta +
")), 0.0f))";
169 outputSizeVar =
"range_" + opName;
171 out <<
SP <<
"size_t " << outputSizeVar <<
" = " << outputSize <<
";\n";
172 out <<
SP <<
"for (size_t i = 0; i < " << outputSizeVar <<
"; i++) {\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 value
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
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)
void AddDynamicTensor(std::string tensor_name, ETensorType type, std::vector< Dim > shape)
bool IsShapeTensor(const std::string &name) const
check if a tensor is a shape tensor
bool IsInitializedTensor(const std::string &name) const
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
std::vector< T > GetTensorData(const std::string &name)
const std::vector< Dim > & GetShapeTensorValues(const std::string &tensor_name) const
ROperator_Range(std::string start, std::string limit, std::string delta, std::string nameOutput)
std::vector< Dim > fShape
std::string Generate(std::string opName) override
void Initialize(RModel &model) override
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::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::string ConvertTypeToString(ETensorType type)
ETensorType ConvertStringToType(std::string type)
create variable transformations
std::string GetVal() const