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(2));
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
52 if (axisTensorNames.size() > 0) {
53 // for version >= 10
54 if (axis_type == ETensorType::INT32)
55 op.reset(new ROperator_Slice<int32_t>(input_name, axisTensorNames, output_name));
56 else if (axis_type == ETensorType::INT64)
57 op.reset(new ROperator_Slice<int64_t>(input_name, axisTensorNames, output_name));
58 else
59 throw std::runtime_error(
60 "TMVA::SOFIE - Unsupported - Operator Slice has invalid input type for input axis descriptors " +
61 std::to_string(static_cast<int>(axis_type)));
62 } else if (attr_starts.size() > 0 && attr_ends.size() > 0) {
63 op.reset(new ROperator_Slice<int64_t>(input_name, attr_starts, attr_ends, attr_axes, output_name));
64 } else {
65 throw std::runtime_error("TMVA::SOFIE - Unsupported - Operator Slice has invalid attribues");
66 }
67
68
69 if (!parser.IsRegisteredTensorType(output_name)) {
70 parser.RegisterTensorType(output_name, input_type);
71 }
72
73 return op;
74};
75
76} // namespace SOFIE
77} // namespace Experimental
78} // 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