Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseReduce.cxx
Go to the documentation of this file.
3#include "onnx.hxx"
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 else if (nodeproto.op_type() == "ReduceMax")
27 else if (nodeproto.op_type() == "ReduceMin")
29
30 if (op_mode == InvalidReduceOp) {
31 throw std::runtime_error("TMVA::SOFIE - Reduce op mode not supported.");
32 }
33
34 auto input_name = nodeproto.input(0);
35 if (parser.IsRegisteredTensorType(input_name)) {
36 input_type = parser.GetTensorType(input_name);
37 } else {
38 throw std::runtime_error("TMVA::SOFIE ONNX Parser Reduce op has input tensor" + input_name +
39 " but its type is not yet registered");
40 }
41 //in the latest version of ONNX axis is not an attribute but an input
42 std::string axes_name;
43 if (nodeproto.input_size() > 1) {
44 axes_name = nodeproto.input(1);
45 if (!parser.IsRegisteredTensorType(axes_name)) {
46 throw std::runtime_error("TMVA::SOFIE ONNX Parser Reduce op has input tensor" + axes_name +
47 " but its type is not yet registered");
48 }
49 }
50
51 std::unique_ptr<ROperator> op;
52 std::string output_name = nodeproto.output(0);
53 int attr_keepdims = 1;
54 std::vector<int64_t> attr_axes;
55 for (int_t i = 0; i < nodeproto.attribute_size(); i++) {
56 std::string attribute_name = nodeproto.attribute(i).name();
57 if (attribute_name == "keepdims")
58 attr_keepdims = nodeproto.attribute(i).i();
59 if (attribute_name == "axes") {
60 attr_axes =
61 std::vector<int64_t>({nodeproto.attribute(i).ints().begin(), nodeproto.attribute(i).ints().end()});
62 }
63 }
65 // switch (input_type) {
66 // case ETensorType::FLOAT:
67 // op.reset(new ROperator_Reduce<float, Op>(attr_keepdims, attr_axes, input_name, axes_name, output_name));
68 // break;
69 // default:
70 // throw std::runtime_error("TMVA::SOFIE - Unsupported - Reduce Operator 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 return op;
78}
79
80// Parse ReduceMean
84
85// Parse ReduceSumSquare
89
90// Parse ReduceProd
94
95// Parse ReduceSum
99
100// Parse ReduceMax
104
105// Parse ReduceMin
109
110} // namespace SOFIE
111} // namespace Experimental
112} // 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
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 ParseReduceMax
ParserFuncSignature ParseReduceSum
ParserFuncSignature ParseReduceSumSquare
ParserFuncSignature ParseReduceMin
create variable transformations