Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseReduce.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
10template <EReduceOpMode Op>
11std::unique_ptr<ROperator> ParseReduce(RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto)
12{
14
16
17 if (nodeproto.op_type() == "ReduceMean")
19 else if (nodeproto.op_type() == "ReduceSumSquare")
21 else if (nodeproto.op_type() == "ReduceProd")
23 else if (nodeproto.op_type() == "ReduceSum")
25
26 if (op_mode == InvalidReduceOp) {
27 throw std::runtime_error("TMVA::SOFIE - Reduce op mode not supported.");
28 }
29
30 auto input_name = nodeproto.input(0);
33 } else {
34 throw std::runtime_error("TMVA::SOFIE ONNX Parser Reduce op has input tensor" + input_name +
35 " but its type is not yet registered");
36 }
37 //in the latest version of ONNX axis is not an attribute but an input
38 std::string axes_name;
39 if (nodeproto.input_size() > 1) {
40 axes_name = nodeproto.input(1);
41 if (!parser.IsRegisteredTensorType(axes_name)) {
42 throw std::runtime_error("TMVA::SOFIE ONNX Parser Reduce op has input tensor" + axes_name +
43 " but its type is not yet registered");
44 }
45 }
46
47 std::unique_ptr<ROperator> op;
48 std::string output_name = nodeproto.output(0);
49 int attr_keepdims = 1;
50 std::vector<int64_t> attr_axes;
51 for (int_t i = 0; i < nodeproto.attribute_size(); i++) {
52 std::string attribute_name = nodeproto.attribute(i).name();
53 if (attribute_name == "keepdims")
54 attr_keepdims = nodeproto.attribute(i).i();
55 if (attribute_name == "axes") {
56 attr_axes =
57 std::vector<int64_t>({nodeproto.attribute(i).ints().begin(), nodeproto.attribute(i).ints().end()});
58 }
59 }
60 switch (input_type) {
63 break;
64 default:
65 throw std::runtime_error("TMVA::SOFIE - Unsupported - Reduce Operator does not yet support input type " +
66 std::to_string(static_cast<int>(input_type)));
67 }
68
71 }
72 return op;
73}
74
75// Parse ReduceMean
79
80// Parse ReduceSumSquare
84
85// Parse ReduceProd
89
90// Parse ReduceSum
94
95} // namespace SOFIE
96} // namespace Experimental
97} // namespace TMVA
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
const_iterator end() const
void RegisterTensorType(const std::string &, ETensorType)
ETensorType GetTensorType(const std::string &name)
std::unique_ptr< ROperator > ParseReduce(RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto)
ParserFuncSignature ParseReduceMean
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
ParserFuncSignature ParseReduceProd
ParserFuncSignature ParseReduceSum
ParserFuncSignature ParseReduceSumSquare
create variable transformations