ROOT
master
Reference Guide
Loading...
Searching...
No Matches
ParseClip.cxx
Go to the documentation of this file.
1
#include "
TMVA/RModelParser_ONNX.hxx
"
2
#include "
TMVA/ROperator_Clip.hxx
"
3
#include "
onnx.hxx
"
4
5
namespace
TMVA
{
6
namespace
Experimental {
7
namespace
SOFIE {
8
9
// ---------------------------------------------------------------------------
10
// ParseClip
11
//
12
// ONNX Clip node inputs (all optional except X):
13
// input(0) : X — data tensor to clip (required)
14
// input(1) : min — scalar lower bound (optional)
15
// input(2) : max — scalar upper bound (optional)
16
//
17
// ONNX Clip node output:
18
// output(0): Y — clipped output tensor
19
//
20
// If min / max inputs are absent the node may have input_size < 3.
21
// An absent optional input is represented in the ONNX protobuf as an
22
// empty string "".
23
// ---------------------------------------------------------------------------
24
25
ParserFuncSignature
ParseClip
= [](
RModelParser_ONNX
&
parser
,
26
const
onnx::NodeProto
&
nodeproto
) {
27
28
// ---- validate input count -------------------------------------------
29
// Clip requires at least 1 input (X); min and max are optional
30
if
(
nodeproto
.input_size() < 1) {
31
throw
std::runtime_error(
32
"TMVA::SOFIE ONNX Parser Clip op has invalid input size "
+
33
std::to_string(
nodeproto
.input_size()) +
" (expected 1, 2 or 3)"
);
34
}
35
36
// ---- main input X must be registered --------------------------------
37
if
(!
parser
.IsRegisteredTensorType(
nodeproto
.input(0))) {
38
throw
std::runtime_error(
39
"TMVA::SOFIE ONNX Parser Clip op has input tensor "
+
40
nodeproto
.input(0) +
" but its type is not yet registered"
);
41
}
42
43
ETensorType
input_type
=
parser
.GetTensorType(
nodeproto
.input(0));
44
45
46
std::string
minName
= (
nodeproto
.input_size() > 1) ?
nodeproto
.input(1) :
""
;
47
std::string
maxName
= (
nodeproto
.input_size() > 2) ?
nodeproto
.input(2) :
""
;
48
49
// ---- if min/max are provided they must match the data type ----------
50
if
(!
minName
.empty() &&
parser
.IsRegisteredTensorType(
minName
)) {
51
if
(
parser
.GetTensorType(
minName
) !=
input_type
) {
52
throw
std::runtime_error(
53
"TMVA::SOFIE ONNX Parser Clip op: min tensor "
+
minName
+
54
" type "
+
ConvertTypeToString
(
parser
.GetTensorType(
minName
)) +
55
" does not match input type "
+
ConvertTypeToString
(
input_type
));
56
}
57
}
58
if
(!
maxName
.empty() &&
parser
.IsRegisteredTensorType(
maxName
)) {
59
if
(
parser
.GetTensorType(
maxName
) !=
input_type
) {
60
throw
std::runtime_error(
61
"TMVA::SOFIE ONNX Parser Clip op: max tensor "
+
maxName
+
62
" type "
+
ConvertTypeToString
(
parser
.GetTensorType(
maxName
)) +
63
" does not match input type "
+
ConvertTypeToString
(
input_type
));
64
}
65
}
66
67
// ---- build the operator ---------------------------------------------
68
std::unique_ptr<ROperator>
op
;
69
std::string
output_name
=
nodeproto
.output(0);
70
71
switch
(
input_type
) {
72
case
ETensorType::FLOAT
:
73
op
.reset(
new
ROperator_Clip<float>
(
74
nodeproto
.input(0),
output_name
,
minName
,
maxName
));
75
break
;
76
case
ETensorType::DOUBLE
:
77
op
.reset(
new
ROperator_Clip<double>
(
78
nodeproto
.input(0),
output_name
,
minName
,
maxName
));
79
break
;
80
case
ETensorType::INT32
:
81
op
.reset(
new
ROperator_Clip<int32_t>
(
82
nodeproto
.input(0),
output_name
,
minName
,
maxName
));
83
break
;
84
case
ETensorType::INT64
:
85
op
.reset(
new
ROperator_Clip<int64_t>
(
86
nodeproto
.input(0),
output_name
,
minName
,
maxName
));
87
break
;
88
default
:
89
throw
std::runtime_error(
90
"TMVA::SOFIE - Unsupported - Clip Operator does not yet support "
91
"input type "
+
ConvertTypeToString
(
input_type
));
92
}
93
94
// ---- register output tensor type ------------------------------------
95
if
(!
parser
.IsRegisteredTensorType(
output_name
)) {
96
parser
.RegisterTensorType(
output_name
,
input_type
);
97
}
98
99
return
op
;
100
};
101
102
}
// namespace SOFIE
103
}
// namespace Experimental
104
}
// namespace TMVA
RModelParser_ONNX.hxx
ROperator_Clip.hxx
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:359
ROOT::Detail::TRangeCast
Definition
TCollection.h:312
TMVA::Experimental::SOFIE::RModelParser_ONNX
Definition
RModelParser_ONNX.hxx:30
TMVA::Experimental::SOFIE::onnx::NodeProto
Definition
onnx.hxx:504
TMVA::Experimental::SOFIE::ETensorType
ETensorType
Definition
SOFIE_common.hxx:29
TMVA::Experimental::SOFIE::ETensorType::INT64
@ INT64
TMVA::Experimental::SOFIE::ETensorType::INT32
@ INT32
TMVA::Experimental::SOFIE::ETensorType::FLOAT
@ FLOAT
TMVA::Experimental::SOFIE::ETensorType::DOUBLE
@ DOUBLE
TMVA::Experimental::SOFIE::ParserFuncSignature
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
Definition
RModelParser_ONNX.hxx:25
TMVA::Experimental::SOFIE::ParseClip
ParserFuncSignature ParseClip
Definition
ParseClip.cxx:25
TMVA::Experimental::SOFIE::ConvertTypeToString
std::string ConvertTypeToString(ETensorType type)
Definition
SOFIE_common.cxx:66
TMVA
create variable transformations
Definition
GeneticMinimizer.h:22
onnx.hxx
tmva
sofie_parsers
src
ParseClip.cxx
ROOTmaster - Reference Guide Generated on Sat Sep 5 2026 04:37:47 (GVA Time) using Doxygen 1.10.0