ROOT
master
Reference Guide
Loading...
Searching...
No Matches
ParseSlice.cxx
Go to the documentation of this file.
1
#include "
TMVA/RModelParser_ONNX.hxx
"
2
#include "
TMVA/ROperator_Slice.hxx
"
3
#include "
onnx.hxx
"
4
5
namespace
TMVA
{
6
namespace
Experimental {
7
namespace
SOFIE {
8
9
ParserFuncSignature
ParseSlice
= [](
RModelParser_ONNX
&
parser
,
const
onnx::NodeProto
&
nodeproto
) {
10
// make Slice operator
11
ETensorType
input_type
=
ETensorType::UNDEFINED
;
12
13
auto
input_name
=
nodeproto
.input(0);
14
if
(
parser
.IsRegisteredTensorType(
input_name
)) {
15
input_type
=
parser
.GetTensorType(
input_name
);
16
}
else
{
17
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser Slice op has input tensor"
+
input_name
+
18
" but its type is not yet registered"
);
19
}
20
21
std::vector<std::string>
axisTensorNames
;
22
if
(
nodeproto
.input_size() > 1)
23
axisTensorNames
.push_back(
nodeproto
.input(1));
24
if
(
nodeproto
.input_size() > 2)
25
axisTensorNames
.push_back(
nodeproto
.input(2));
26
if
(
nodeproto
.input_size() > 3)
27
axisTensorNames
.push_back(
nodeproto
.input(3));
28
if
(
nodeproto
.input_size() > 4)
29
axisTensorNames
.push_back(
nodeproto
.input(4));
30
31
// not sure how to find here type of the integer inputs
32
ETensorType
axis_type
=
ETensorType::INT64
;
33
// for version < 10
34
std::vector<int64_t>
attr_starts
= {};
35
std::vector<int64_t>
attr_ends
= {};
36
std::vector<int64_t>
attr_axes
= {};
37
if
(
nodeproto
.input_size() == 1) {
38
for
(
int_t
i = 0; i <
nodeproto
.attribute_size(); i++) {
39
std::string
attribute_name
=
nodeproto
.attribute(i).name();
40
if
(
attribute_name
==
"starts"
)
41
attr_starts
= {
nodeproto
.attribute(i).ints().
begin
(),
nodeproto
.attribute(i).ints().
end
()};
42
if
(
attribute_name
==
"ends"
)
43
attr_ends
= {
nodeproto
.attribute(i).ints().
begin
(),
nodeproto
.attribute(i).ints().
end
()};
44
if
(
attribute_name
==
"axes"
)
45
attr_axes
= {
nodeproto
.attribute(i).ints().
begin
(),
nodeproto
.attribute(i).ints().
end
()};
46
}
47
}
48
49
std::unique_ptr<ROperator>
op
;
50
std::string
output_name
=
nodeproto
.output(0);
51
52
if
(
axisTensorNames
.size() > 0) {
53
// for version >= 10
54
if
(
axis_type
==
ETensorType::INT32
)
55
op
.reset(
new
ROperator_Slice<int32_t>
(
input_name
,
axisTensorNames
,
output_name
));
56
else
if
(
axis_type
==
ETensorType::INT64
)
57
op
.reset(
new
ROperator_Slice<int64_t>
(
input_name
,
axisTensorNames
,
output_name
));
58
else
59
throw
std::runtime_error(
60
"TMVA::SOFIE - Unsupported - Operator Slice has invalid input type for input axis descriptors "
+
61
std::to_string(
static_cast<
int
>
(
axis_type
)));
62
}
else
if
(
attr_starts
.size() > 0 &&
attr_ends
.size() > 0) {
63
op
.reset(
new
ROperator_Slice<int64_t>
(
input_name
,
attr_starts
,
attr_ends
,
attr_axes
,
output_name
));
64
}
else
{
65
throw
std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Slice has invalid attribues"
);
66
}
67
68
69
if
(!
parser
.IsRegisteredTensorType(
output_name
)) {
70
parser
.RegisterTensorType(
output_name
,
input_type
);
71
}
72
73
return
op
;
74
};
75
76
}
// namespace SOFIE
77
}
// namespace Experimental
78
}
// namespace TMVA
RModelParser_ONNX.hxx
ROperator_Slice.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
ROOT::RRangeCast::begin
const_iterator begin() const
Definition
RRangeCast.hxx:103
ROOT::RRangeCast::end
const_iterator end() const
Definition
RRangeCast.hxx:104
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::UNDEFINED
@ UNDEFINED
TMVA::Experimental::SOFIE::ETensorType::INT64
@ INT64
TMVA::Experimental::SOFIE::ETensorType::INT32
@ INT32
TMVA::Experimental::SOFIE::ParserFuncSignature
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
Definition
RModelParser_ONNX.hxx:25
TMVA::Experimental::SOFIE::ParseSlice
ParserFuncSignature ParseSlice
Definition
ParseSlice.cxx:9
TMVA::Experimental::SOFIE::int_t
std::int64_t int_t
Definition
SOFIE_common.hxx:56
TMVA
create variable transformations
Definition
GeneticMinimizer.h:22
onnx.hxx
tmva
sofie_parsers
src
ParseSlice.cxx
ROOTmaster - Reference Guide Generated on Sat Sep 5 2026 04:37:47 (GVA Time) using Doxygen 1.10.0