Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseCast.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9ParserFuncSignature ParseCast = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
10 ETensorType input_type;
11 auto input_name = nodeproto.input(0);
12 if (parser.IsRegisteredTensorType(input_name)) {
13 input_type = parser.GetTensorType(input_name);
14 } else {
15 throw std::runtime_error("TMVA::SOFIE ONNX Parser Cast op has input tensor" + input_name +
16 " but its type is not yet registered");
17 }
18
19 std::unique_ptr<ROperator> op;
20 std::string attr_type;
21
22 for (int_t i = 0; i < nodeproto.attribute_size(); i++) {
23 std::string attribute_name = nodeproto.attribute(i).name();
24 if (attribute_name == "to")
25 attr_type = ConvertTypeToString(static_cast<ETensorType>(nodeproto.attribute(i).i()));
26 }
27
28 std::string output_name = nodeproto.output(0);
29 switch (input_type) {
33 case ETensorType::INT32: op.reset(new ROperator_Cast<float>(attr_type, nodeproto.input(0), output_name)); break;
34 default:
35 throw std::runtime_error("TMVA::SOFIE - Unsupported - Operator Cast does not yet support input type " +
36 std::to_string(static_cast<int>(input_type)));
37 }
38
39 if (!parser.IsRegisteredTensorType(output_name)) {
40 ETensorType output_type = ConvertStringToType(attr_type);
41 parser.RegisterTensorType(output_name, output_type);
42 }
43
44 return op;
45};
46
47} // namespace SOFIE
48} // namespace Experimental
49} // 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 ParseCast
Definition ParseCast.cxx:9
std::string ConvertTypeToString(ETensorType type)
ETensorType ConvertStringToType(std::string type)
create variable transformations