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 }
61 // switch (input_type) {
62 // case ETensorType::FLOAT:
63 // op.reset(new ROperator_Reduce<float, Op>(attr_keepdims, attr_axes, input_name, axes_name, output_name));
64 // break;
65 // default:
66 // throw std::runtime_error("TMVA::SOFIE - Unsupported - Reduce Operator does not yet support input type " +
67 // std::to_string(static_cast<int>(input_type)));
68 // }
69
72 }
73 return op;
74}
75
76// Parse ReduceMean
80
81// Parse ReduceSumSquare
85
86// Parse ReduceProd
90
91// Parse ReduceSum
95
96} // namespace SOFIE
97} // namespace Experimental
98} // 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