Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseIf.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9ParserFuncSignature ParseIf = [] (RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
10 //ETensorType input_type;
11
12 auto input_name = nodeproto.input(0);
13 if (!parser.IsRegisteredTensorType(input_name)) {
14 throw std::runtime_error("TMVA::SOFIE ONNX Parser If op has input tensor" + input_name +
15 " but its type is not yet registered");
16 }
17 // attributes containing the graphs
18 if (nodeproto.attribute_size() != 2) {
19 throw std::runtime_error("TMVA::SOFIE ONNX Parser If op has not 2 attributes");
20 }
21 int then_index = -1;
22 int else_index = -1;
23 for (int_t i = 0; i < nodeproto.attribute_size(); i++) {
24 std::string attribute_name = nodeproto.attribute(i).name();
25 if (attribute_name == "then_branch") {
26 then_index = i;
27 }
28 else if (attribute_name == "else_branch") {
29 else_index = i;
30 }
31 }
32 if (else_index < 0 || then_index < 0)
33 throw std::runtime_error("TMVA::SOFIE ONNX Parser If has wrong attributes");
34
35 auto then_graph = nodeproto.attribute(then_index).g();
36 auto else_graph = nodeproto.attribute(else_index).g();
37 // need here to parse the graphs
38
39 auto model_then = std::make_unique<RModel>(then_graph.name(),"");
40 auto model_else = std::make_unique<RModel>(else_graph.name(),"");
41
42 std::vector<std::string> outputNames;
43 for (int i = 0; i < nodeproto.output_size(); i++) {
44 outputNames.push_back(nodeproto.output(i));
45 }
46 parser.ParseONNXGraph(*model_then, then_graph);
47 parser.ParseONNXGraph(*model_else, else_graph);
48
49
50 std::unique_ptr<ROperator> op(new ROperator_If(input_name, outputNames, std::move(model_then), std::move(model_else)));
51 // output of if are the output of the branches
52 for (size_t i = 0; i < outputNames.size(); i++) {
53 // get type from the output of subgraph models
54 std::string out_g_name = then_graph.output(i).name();
55 auto type = parser.GetTensorType(out_g_name);
56 std::string output_name = outputNames[i];
57 if (!parser.IsRegisteredTensorType(output_name))
58 parser.RegisterTensorType(output_name, type);
59 }
60 return op;
61};
62
63} // namespace SOFIE
64} // namespace Experimental
65} // namespace TMVA
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
void ParseONNXGraph(RModel &model, const onnx::GraphProto &g, std::string name="")
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
ParserFuncSignature ParseIf
Definition ParseIf.cxx:9
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
create variable transformations