Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROperator_Range.hxx
Go to the documentation of this file.
1#ifndef TMVA_SOFIE_ROPERATOR_RANGE
2#define TMVA_SOFIE_ROPERATOR_RANGE
3
5#include "TMVA/ROperator.hxx"
6#include "TMVA/RModel.hxx"
7
8#include <sstream>
9
10namespace TMVA{
11namespace Experimental{
12namespace SOFIE{
13
14template <typename T>
15class ROperator_Range final : public ROperator
16{
17private:
18
19 std::string fNStart;
20 std::string fNLimit;
21 std::string fNDelta;
22 std::string fNOutput;
23 std::vector<Dim> fShape;
24 std::string fType;
25
26public:
28
29 ROperator_Range(std::string start, std::string limit, std::string delta, std::string nameOutput):
30 fNStart(start), fNLimit(limit), fNDelta(delta),
31 fNOutput(UTILITY::Clean_name(nameOutput)) {
32 if (std::is_same<T, float>::value) {
33 fType = "float";
34 } else if (std::is_same<T, int64_t>::value) {
35 fType = "int64_t";
36 }
37 static_assert( (std::is_same_v<T, float> || std::is_same_v<T, int64_t>),
38 "TMVA::SOFIE - Unsupported type by Range operator");
39 }
40
41 std::vector<ETensorType> TypeInference(std::vector<ETensorType> input) override {
42 return input;
43 }
44
45 std::vector<std::vector<size_t>> ShapeInference(std::vector<std::vector<size_t>> input) override {
46 auto ret = input; //suggest copy to compiler
47 return ret;
48 }
49
50 void Initialize(RModel& model) override {
51 //input must be a graph input, or already initialized intermediate tensor
53 throw
54 std::runtime_error("TMVA SOFIE Range Op Input Tensor " + fNStart + "is not found in model");
55 }
57 throw
58 std::runtime_error("TMVA SOFIE Range Op Input Tensor " + fNLimit + "is not found in model");
59 }
61 throw
62 std::runtime_error("TMVA SOFIE Range Op Input Tensor " + fNDelta + "is not found in model");
63 }
65 fShape = {Dim{"range_size"}};
67 }
68
69 std::string Generate(std::string OpName) override {
70 OpName = "op_" + OpName;
71 if (fShape.empty()) {
72 throw std::runtime_error("TMVA SOFIE Range operator called to Generate without being initialized first");
73 }
74 std::stringstream out;
75 out << "\n//------ Range\n";
76 std::string sizeName = fShape[0].param;
77 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";
78 out << SP << "if (" << sizeName << " > " << "fTensor_" << fNOutput << ".size() ){\n";
79 out << SP << SP << "fTensor_" << fNOutput << ".resize(" << sizeName << ");\n";
80 // need to re-initialized pointer to tensor data
81 out << SP << SP << "tensor_" << fNOutput << " = fTensor_" << fNOutput << ".data();\n";
82 out << SP << "}\n";
83 out << SP << "for (size_t i = 0; i < " << sizeName << "; i++) {\n";
84 out << SP << SP << "fTensor_" << fNOutput << "[i] = *tensor_" << fNStart << " + i * (*tensor_" << fNDelta << ");\n";
85 out << SP << "}\n";
86 return out.str();
87 }
88};
89
90}//SOFIE
91}//Experimental
92}//TMVA
93
94#endif //TMVA_SOFIE_ROPERATOR_RANGE
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)
Definition RModel.cxx:116
void AddDynamicTensor(std::string tensor_name, ETensorType type, std::vector< Dim > shape)
Definition RModel.cxx:204
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< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
std::string Generate(std::string OpName) override
const std::string SP
space used to correctly indent the generated C++ code
Definition ROperator.hxx:41
ETensorType ConvertStringToType(std::string type)
create variable transformations