Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParsePRelu.cxx
Go to the documentation of this file.
3#include "onnx.hxx"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
10 ETensorType input_type;
11 ETensorType slope_type;
12
13 auto input_name = nodeproto.input(0);
14 if (parser.IsRegisteredTensorType(input_name)) {
15 input_type = parser.GetTensorType(input_name);
16 } else {
17 throw std::runtime_error("TMVA::SOFIE ONNX Parser PRelu op has input tensor " + input_name +
18 " but its type is not yet registered");
19 }
20 auto slope_name = nodeproto.input(1);
21 if (parser.IsRegisteredTensorType(slope_name)) {
22 slope_type = parser.GetTensorType(slope_name);
23 } else {
24 throw std::runtime_error("TMVA::SOFIE ONNX Parser PRelu op has slope tensor " + slope_name +
25 " but its type is not yet registered");
26 }
27 if (slope_type != input_type) {
28 throw std::runtime_error("TMVA::SOFIE ONNX Parser PRelu op has slope tensor " + slope_name + " of type " +
29 ConvertTypeToString(slope_type) + " but input tensor " + input_name + " is of type " +
30 ConvertTypeToString(input_type) + "; they must be the same");
31 }
32
33 std::unique_ptr<ROperator> op;
34 std::string output_name = nodeproto.output(0);
35
36 // PRelu has no attributes (the legacy opset-1 'consumed_inputs' is ignored)
37 switch (input_type) {
38 case ETensorType::FLOAT: op.reset(new ROperator_PRelu<float>(input_name, slope_name, output_name)); break;
39 default:
40 throw std::runtime_error("TMVA::SOFIE - Unsupported - Operator PRelu does not yet support input type " +
41 ConvertTypeToString(input_type));
42 }
43 if (!parser.IsRegisteredTensorType(output_name)) {
44 parser.RegisterTensorType(output_name, input_type);
45 }
46
47 return op;
48};
49
50} // namespace SOFIE
51} // namespace Experimental
52} // namespace TMVA
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
ParserFuncSignature ParsePRelu
Definition ParsePRelu.cxx:9
std::string ConvertTypeToString(ETensorType type)
create variable transformations