Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseGather.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4#include <stdexcept>
5
6namespace TMVA {
7namespace Experimental {
8namespace SOFIE {
9
10ParserFuncSignature ParseGather = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
12 auto input_name = nodeproto.input(0);
13 if (parser.IsRegisteredTensorType(input_name)) {
14 input_type = parser.GetTensorType(input_name);
15 } else {
16 throw std::runtime_error("TMVA::SOFIE ONNX Parser Gather op has input tensor" + input_name +
17 " but its type is not yet registered");
18 }
19
21 auto indices_name = nodeproto.input(1);
22 // indices_type can be an initialized tensor, no need to emit an error if it is not registered
23 if (parser.IsRegisteredTensorType(indices_name)) {
24 indices_type = parser.GetTensorType(indices_name);
25 if (indices_type != ETensorType::INT64 && indices_type != ETensorType::INT32) {
26 throw
27 std::runtime_error("TMVA::SOFIE ONNX Parser Gather op Indices tensor type not supported.");
28 }
29 }
30
31 std::unique_ptr<ROperator> op;
32 std::string output_name = nodeproto.output(0);
33 int64_t attr_axis = 0;
34 if (nodeproto.attribute_size() == 1) {
35 attr_axis = nodeproto.attribute(0).i();
36 }
37
38 switch (input_type) {
40 op.reset(new ROperator_Gather<float>(attr_axis, input_name, indices_name, nodeproto.output(0)));
41 break;
42 default:
43 throw std::runtime_error("TMVA::SOFIE - Unsupported - Operator Gather does not yet support input type " +
44 ConvertTypeToString(input_type));
45 }
46
47 if (!parser.IsRegisteredTensorType(output_name)) {
48 parser.RegisterTensorType(output_name, input_type);
49 }
50
51 return op;
52};
53
54} // namespace SOFIE
55} // namespace Experimental
56} // namespace TMVA
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
ParserFuncSignature ParseGather
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
std::string ConvertTypeToString(ETensorType type)
create variable transformations