Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseTopK.cxx
Go to the documentation of this file.
3#include "onnx_proto3.pb.h"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9ParserFuncSignature ParseTopK = [](RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto) {
11
12 std::string 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 TopK op has input tensor " + input_name +
17 " but its type is not yet registered");
18 }
19 std::string k_name = nodeproto.input(1);
20 if (!parser.IsRegisteredTensorType(k_name)) {
21 throw std::runtime_error("TMVA::SOFIE ONNX Parser TopK op has input tensor " + k_name +
22 " but its type is not yet registered");
23 }
24
25 std::unique_ptr<ROperator> op;
26
27 std::string outputVal_name = nodeproto.output(0);
28 std::string outputInd_name = nodeproto.output(1);
29 int attr_axis = -1;
30 int attr_largest = 1;
31 int attr_sorted = 1;
32
33 for (int_t i = 0; i < nodeproto.attribute_size(); i++) {
34 std::string attribute_name = nodeproto.attribute(i).name();
35 if (attribute_name == "axis")
36 attr_axis = nodeproto.attribute(i).i();
37 if (attribute_name == "largest")
38 attr_largest = nodeproto.attribute(i).i();
39 if (attribute_name == "sorted")
40 attr_sorted = nodeproto.attribute(i).i();
41 }
42 op.reset(new ROperator_TopK<float>(attr_axis, attr_largest, attr_sorted, k_name, input_name, outputVal_name, outputInd_name));
43
44 if (!parser.IsRegisteredTensorType(outputVal_name)) {
45 parser.RegisterTensorType(outputVal_name, input_type);
46 }
47 if (!parser.IsRegisteredTensorType(outputInd_name)) {
48 parser.RegisterTensorType(outputInd_name, ETensorType::INT64);
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 ParseTopK
Definition ParseTopK.cxx:9
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
create variable transformations