Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseSlice.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9ParserFuncSignature ParseSlice = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
10 // make Slice operator
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 Slice op has input tensor" + input_name +
18 " but its type is not yet registered");
19 }
20
21 std::vector<std::string> axisTensorNames;
22 if (nodeproto.input_size() > 1)
23 axisTensorNames.push_back(nodeproto.input(1));
24 if (nodeproto.input_size() > 2)
25 axisTensorNames.push_back(nodeproto.input(1));
26 if (nodeproto.input_size() > 3)
27 axisTensorNames.push_back(nodeproto.input(3));
28 if (nodeproto.input_size() > 4)
29 axisTensorNames.push_back(nodeproto.input(4));
30
31 // not sure how to find here type of the integer inputs
33 // for version < 10
34 std::vector<int64_t> attr_starts = {};
35 std::vector<int64_t> attr_ends = {};
36 std::vector<int64_t> attr_axes = {};
37 if (nodeproto.input_size() == 1) {
38 for (int_t i = 0; i < nodeproto.attribute_size(); i++) {
39 std::string attribute_name = nodeproto.attribute(i).name();
40 if (attribute_name == "starts")
41 attr_starts = {nodeproto.attribute(i).ints().begin(), nodeproto.attribute(i).ints().end()};
42 if (attribute_name == "ends")
43 attr_ends = {nodeproto.attribute(i).ints().begin(), nodeproto.attribute(i).ints().end()};
44 if (attribute_name == "axes")
45 attr_axes = {nodeproto.attribute(i).ints().begin(), nodeproto.attribute(i).ints().end()};
46 }
47 }
48
49 std::unique_ptr<ROperator> op;
50 std::string output_name = nodeproto.output(0);
51 switch (input_type) {
53 if (axisTensorNames.size() > 0) {
54 // for version >= 10
55 if (axis_type == ETensorType::INT32)
56 op.reset(new ROperator_Slice<float, int32_t>(input_name, axisTensorNames, output_name));
57 else if (axis_type == ETensorType::INT64)
58 op.reset(new ROperator_Slice<float, int64_t>(input_name, axisTensorNames, output_name));
59 else
60 throw std::runtime_error(
61 "TMVA::SOFIE - Unsupported - Operator Slice has invalid input type for input axis descriptors " +
62 std::to_string(static_cast<int>(axis_type)));
63 } else if (attr_starts.size() > 0 && attr_ends.size() > 0) {
64 op.reset(new ROperator_Slice<float, int64_t>(input_name, attr_starts, attr_ends, attr_axes, output_name));
65 } else {
66 throw std::runtime_error("TMVA::SOFIE - Unsupported - Operator Slice has invalid attribues");
67 }
68 break;
69 default:
70 throw std::runtime_error("TMVA::SOFIE - Unsupported - Operator Slice does not yet support input type " +
71 std::to_string(static_cast<int>(input_type)));
72 }
73
74 if (!parser.IsRegisteredTensorType(output_name)) {
75 parser.RegisterTensorType(output_name, input_type);
76 }
77
78 return op;
79};
80
81} // namespace SOFIE
82} // namespace Experimental
83} // namespace TMVA
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
ParserFuncSignature ParseSlice
Definition ParseSlice.cxx:9
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
create variable transformations