1#ifndef TMVA_SOFIE_ROPERATOR_RANGE
2#define TMVA_SOFIE_ROPERATOR_RANGE
12namespace Experimental{
30 ROperator_Range(std::string start, std::string limit, std::string delta, std::string nameOutput):
32 fNOutput(UTILITY::Clean_name(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");
55 std::runtime_error(
"TMVA SOFIE Range Op Input Tensor " +
fNStart +
"is not found in model");
59 std::runtime_error(
"TMVA SOFIE Range Op Input Tensor " +
fNLimit +
"is not found in model");
63 std::runtime_error(
"TMVA SOFIE Range Op Input Tensor " +
fNDelta +
"is not found in model");
70 if (!start || !delta || !limit)
71 std::runtime_error(
"TMVA SOFIE Range Op Input Tensor has invalid input data");
75 int number_of_elements = std::max(
static_cast<double>(std::ceil( (
b -
a) /
d )) , 0. );
76 std::vector<T>
output(number_of_elements);
77 for (
int i=0; i<number_of_elements; ++i) {
80 std::vector<size_t> shape = {
static_cast<size_t>(number_of_elements)};
93 std::cout <<
"Range -> output is " <<
fNOutput <<
" ";
99 std::string
Generate(std::string OpName)
override {
101 std::stringstream out;
102 out <<
"\n//------ Range\n";
105 OpName =
"op_" + OpName;
107 throw std::runtime_error(
"TMVA SOFIE Range operator called to Generate without being initialized first");
110 std::string sizeName =
fShape[0].param;
111 out <<
SP <<
"size_t " << sizeName <<
" = static_cast<size_t>(std::max(std::ceil((static_cast<float>(*tensor_" <<
fNLimit <<
") - static_cast<float>(*tensor_" <<
fNStart <<
")) / static_cast<float>(*tensor_" <<
fNDelta <<
")), 0.0f));\n";
112 out <<
SP <<
"if (" << sizeName <<
" > " <<
"fTensor_" <<
fNOutput <<
".size() ){\n";
113 out <<
SP <<
SP <<
"fTensor_" <<
fNOutput <<
".resize(" << sizeName <<
");\n";
117 out <<
SP <<
"for (size_t i = 0; i < " << sizeName <<
"; i++) {\n";
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 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 IsInitializedTensor(const std::string &name) const
const std::vector< size_t > & GetTensorShape(std::string name)
std::shared_ptr< void > GetInitializedTensorData(std::string tensor_name)
void SetNotWritableInitializedTensor(const std::string &tensor_name)
ROperator_Range(std::string start, std::string limit, std::string delta, std::string nameOutput)
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input) override
std::vector< Dim > fShape
void Initialize(RModel &model) override
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
std::string Generate(std::string OpName) override
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::string ConvertShapeToString(std::vector< size_t > shape)
std::string ConvertDynamicShapeToString(std::vector< Dim > shape)
ETensorType ConvertStringToType(std::string type)
create variable transformations