Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseComparision.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9template <EComparisionOperator Op>
10std::unique_ptr<ROperator> ParseComparision(RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto)
11{
13
14 for (int i = 0; i < 2; ++i) {
15 auto input_name = nodeproto.input(i);
16 if (parser.IsRegisteredTensorType(input_name)) {
17 // according to ONNX both inputs have same type
18 if (i == 0)
19 input_type = parser.GetTensorType(input_name);
20 else
21 if (input_type != parser.GetTensorType(input_name)) {
22 throw
23 std::runtime_error("TMVA::SOFIE ONNX parser Comparision op has input tensors of different types");
24 }
25 } else {
26 throw std::runtime_error("TMVA::SOFIE ONNX Parser Comparision op has input tensor " + input_name +
27 " but its type is not yet registered");
28 }
29 }
30
31 std::unique_ptr<ROperator> op;
32 std::string output_name = nodeproto.output(0);
33
34 switch (input_type) {
36 op.reset(new ROperator_Comparision<float, Op>(nodeproto.input(0), nodeproto.input(1), output_name));
37 break;
38 default:
39 throw std::runtime_error("TMVA::SOFIE - Unsupported - Comparision Operator does not yet support input type " +
40 std::to_string(static_cast<int>(input_type)));
41 }
42
43 // Infer the output type
44 if (!parser.IsRegisteredTensorType(output_name)) {
45 parser.RegisterTensorType(output_name, ETensorType::BOOL);
46 }
47
48 return op;
49};
50
51// Parse Equal
52ParserFuncSignature ParseEq = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
53 return ParseComparision<EComparisionOperator::Eq>(parser, nodeproto);
54};
55
56// Parse Less
57ParserFuncSignature ParseLess = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
58 return ParseComparision<EComparisionOperator::Less>(parser, nodeproto);
59};
60
61// Parse Mul
62ParserFuncSignature ParseLessEq = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
63 return ParseComparision<EComparisionOperator::LessEq>(parser, nodeproto);
64};
65
66// Parse Div
67ParserFuncSignature ParseGreater = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
68 return ParseComparision<EComparisionOperator::Greater>(parser, nodeproto);
69};
70
71// Parse Pow
72ParserFuncSignature ParseGreaterEq = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
73 return ParseComparision<EComparisionOperator::GreaterEq>(parser, nodeproto);
74};
75
76} // namespace SOFIE
77} // namespace Experimental
78} // namespace TMVA
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
ParserFuncSignature ParseGreater
ParserFuncSignature ParseEq
ParserFuncSignature ParseLess
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
ParserFuncSignature ParseGreaterEq
ParserFuncSignature ParseLessEq
std::unique_ptr< ROperator > ParseComparision(RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto)
create variable transformations