Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ParseBasicIs.cxx
Go to the documentation of this file.
3#include "onnx.hxx"
4
5namespace TMVA {
6namespace Experimental {
7namespace SOFIE {
8
9template <EBasicIsOperator Op>
10std::unique_ptr<ROperator> ParseBasicIs(RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto)
11{
12
13 std::string input_name = nodeproto.input(0);
14 if (!parser.IsRegisteredTensorType(input_name)) {
15 throw
16 std::runtime_error("TMVA::SOFIE ONNX Parser " + IsOpTraits<Op>::Name() + " op has input tensor " + input_name +
17 " but its type is not yet registered");
18 }
19
20 // get attributes for the IsInf operator
21 int detect_negative = 1;
22 int detect_positive = 1;
23 for (int_t i = 0; i < nodeproto.attribute_size(); i++) {
24 std::string attribute_name = nodeproto.attribute(i).name();
25 if (attribute_name == "detect_negative")
26 detect_negative = nodeproto.attribute(i).i();
27 if (attribute_name == "detect_positive")
28 detect_positive = nodeproto.attribute(i).i();
29 }
30
31 if (detect_positive == 0 && detect_negative == 0)
32 throw std::runtime_error("TMVA::SOFIE ONNX Parser IsInf op has invalide attributes");
33
34
35 std::unique_ptr<ROperator> op;
36 std::string output_name = nodeproto.output(0);
37
38 if (nodeproto.attribute_size() == 0 || (detect_negative == 1 && detect_positive == 1))
39 op.reset(new ROperator_Basic_Is<Op>(input_name, output_name));
40 else if (nodeproto.attribute_size() > 0) {
41 // case detect_negative or detective_positive are set
42 if (detect_negative == 0)
43 op.reset(new ROperator_Basic_Is<EBasicIsOperator::kIsInfPos>(input_name, output_name));
44 else if (detect_positive == 0)
45 op.reset(new ROperator_Basic_Is<EBasicIsOperator::kIsInfNeg>(input_name, output_name));
46 } else
47 throw std::runtime_error("TMVA::SOFIE ONNX Parser " + IsOpTraits<Op>::Name() + " operator - invalid attributes");
48
49 // Register the output type (is always BOOL)
50 if (!parser.IsRegisteredTensorType(output_name)) {
51 parser.RegisterTensorType(output_name, ETensorType::BOOL);
52 }
53
54 return op;
55};
56
58{
59 parser.RegisterOperator("IsNaN", ParseBasicIs<EBasicIsOperator::kIsNaN>);
60 parser.RegisterOperator("IsInf", ParseBasicIs<EBasicIsOperator::kIsInf>);
61}
62
63} // namespace SOFIE
64} // namespace Experimental
65} // namespace TMVA
void RegisterOperator(const std::string &name, ParserFuncSignature func)
void RegisterTensorType(const std::string &, ETensorType)
const AttributeProto & attribute(int i) const
Definition onnx.hxx:515
const std::string & input(int i) const
Definition onnx.hxx:509
const std::string & output(int i) const
Definition onnx.hxx:512
void RegisterBasicIsParsers(RModelParser_ONNX &parser)
std::unique_ptr< ROperator > ParseBasicIs(RModelParser_ONNX &parser, const onnx::NodeProto &nodeproto)
create variable transformations