Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ROperator_Custom.hxx
Go to the documentation of this file.
1#ifndef TMVA_SOFIE_ROPERATOR_Custom
2#define TMVA_SOFIE_ROPERATOR_Custom
3
4
6#include "TMVA/ROperator.hxx"
7#include "TMVA/RModel.hxx"
8
9namespace TMVA{
10namespace Experimental{
11namespace SOFIE{
12
13
14template<typename T>
15class ROperator_Custom final : public ROperator
16{
17
18private:
19 std::string fOpName;
20 std::vector<std::string> fInputNames;
21 std::vector<std::string> fOutputNames;
22 std::vector<std::vector<std::size_t>> fOutputShapes;
23 std::string fHeaderName;
24
25public:
27 ROperator_Custom(std::string OpName, std::vector<std::string>Inputs, std::vector<std::string>Outputs, std::vector<std::vector<std::size_t>> OutputShapes, std::string HeaderName){
28 fOpName = OpName;
29 fOutputShapes = OutputShapes;
30 fHeaderName = HeaderName;
31 for(auto& it:Inputs){
32 fInputNames.emplace_back(UTILITY::Clean_name(it));
33 }
34 for(auto& it:Outputs){
35 fOutputNames.emplace_back(UTILITY::Clean_name(it));
36 }
37 }
38
39 std::vector<std::vector<size_t>> ShapeInference(std::vector<std::vector<size_t>>) {return {{}};};
40 std::vector<ETensorType> TypeInference(std::vector<ETensorType>){ return {};};
41
42 void Initialize(RModel& model){
44 for(auto& it:fInputNames){
45 if (model.CheckIfTensorAlreadyExist(it) == false){
46 throw std::runtime_error("TMVA SOFIE Custom " + fOpName + " Op Input Tensor " + it + " is not found in model");
47 }
48 }
49
50 if(fOutputNames.size() != fOutputShapes.size()){
51 throw std::runtime_error("TMVA SOFIE Custom "+ fOpName + " Op was not intialized with the names/shapes of all the output tensors");
52 }
53
54 for(long unsigned int i=0; i<fOutputNames.size(); ++i){
56 }
58 }
59
60 std::string Generate(std::string OpName){
61 OpName = "op_" + OpName;
62 std::stringstream out;
63 out << "\n//------ "<<fOpName<<" \n";
64 std::string args;
65 for(long unsigned int i = 0; i<fInputNames.size(); ++i){
66 args+="fTensor_"+fInputNames[i]+",";
67 }
68
69 for(long unsigned int i = 0; i<fOutputNames.size(); ++i){
70 args+="fTensor_"+fOutputNames[i]+",";
71 }
72 args.pop_back();
73 out << SP << fOpName<<"::Compute("+args+");\n";
74 return out.str();
75 }
76
77};
78
79
80}//SOFIE
81}//Experimental
82}//TMVA
83
84
85#endif //TMVA_SOFIE_ROPERATOR_Custom
void AddNeededCustomHeader(std::string filename)
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
Definition RModel.cxx:187
bool CheckIfTensorAlreadyExist(std::string tensor_name)
Definition RModel.cxx:116
void UpdateOutputTensorList(std::vector< std::string > curr_output_tensor, std::vector< std::string > modify_output_tensor)
Definition RModel.cxx:232
ROperator_Custom(std::string OpName, std::vector< std::string >Inputs, std::vector< std::string >Outputs, std::vector< std::vector< std::size_t > > OutputShapes, std::string HeaderName)
std::string Generate(std::string OpName)
std::vector< ETensorType > TypeInference(std::vector< ETensorType >)
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > >)
std::vector< std::vector< std::size_t > > fOutputShapes
const std::string SP
space used to correctly indent the generated C++ code
Definition ROperator.hxx:41
std::string Clean_name(std::string input_tensor_name)
create variable transformations