Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseBasicUnary.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9template <EBasicUnaryOperator Op>
10std::unique_ptr<ROperator> ParseBasicUnary(RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto)
11{
13
14 std::string input_name = nodeproto.input(0);
15 if (parser.IsRegisteredTensorType(input_name)) {
16 input_type = parser.GetTensorType(input_name);
17 } else {
18 throw
19 std::runtime_error("TMVA::SOFIE ONNX Parser Unary op has input tensor " + input_name +
20 " but its type is not yet registered");
21 }
22
23 std::unique_ptr<ROperator> op;
24 std::string output_name = nodeproto.output(0);
25
26 switch (input_type) {
28 op.reset(new ROperator_BasicUnary<float, Op>(input_name, output_name));
29 break;
30 default:
31 throw std::runtime_error("TMVA::SOFIE - Unsupported - Binary Operator does not yet support input type " +
32 std::to_string(static_cast<int>(input_type)));
33 }
34
35 // Infer the output type
36 if (!parser.IsRegisteredTensorType(output_name)) {
37 parser.RegisterTensorType(output_name, input_type);
38 }
39
40 return op;
41};
42
43// Parse Sqrt
44ParserFuncSignature ParseSqrt = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
45 return ParseBasicUnary<EBasicUnaryOperator::kSqrt>(parser, nodeproto);
46};
47
48// Parse Reciprocal
49ParserFuncSignature ParseReciprocal = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
50 return ParseBasicUnary<EBasicUnaryOperator::kReciprocal>(parser, nodeproto);
51};
52
53// Parse Neg
54ParserFuncSignature ParseNeg = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
55 return ParseBasicUnary<EBasicUnaryOperator::kNeg>(parser, nodeproto);
56};
57
58// Parse Exp
59ParserFuncSignature ParseExp = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
60 return ParseBasicUnary<EBasicUnaryOperator::kExp>(parser, nodeproto);
61};
62
63// Parse Log
64ParserFuncSignature ParseLog = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
65 return ParseBasicUnary<EBasicUnaryOperator::kLog>(parser, nodeproto);
66};
67
68} // namespace SOFIE
69} // namespace Experimental
70} // namespace TMVA
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
ParserFuncSignature ParseSqrt
ParserFuncSignature ParseNeg
ParserFuncSignature ParseLog
std::unique_ptr< ROperator > ParseBasicUnary(RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto)
ParserFuncSignature ParseExp
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
ParserFuncSignature ParseReciprocal
create variable transformations