ROOT
master
Reference Guide
Loading...
Searching...
No Matches
ParseRandom.cxx
Go to the documentation of this file.
1
#include "
TMVA/RModelParser_ONNX.hxx
"
2
#include "
TMVA/ROperator_Random.hxx
"
3
#include "
onnx.hxx
"
4
5
namespace
TMVA
{
6
namespace
Experimental {
7
namespace
SOFIE {
8
9
ParserFuncSignature
ParseRandom
= [](
RModelParser_ONNX
&
parser
,
const
onnx::NodeProto
&
nodeproto
) {
10
11
RandomOpMode
opMode
=
kUniform
;
12
auto
op_type =
nodeproto
.op_type();
13
if
(op_type ==
"RandomNormal"
|| op_type ==
"RandomNormalLike"
)
14
opMode
=
kNormal
;
15
16
17
ETensorType
input_type
=
ETensorType::FLOAT
;
// default value
18
std::string
input_name
;
19
// case of NormalLike and UniformLike , type is given by the input
20
if
(
nodeproto
.input_size() > 0) {
21
input_name
=
nodeproto
.input(0);
22
if
(
parser
.IsRegisteredTensorType(
input_name
)) {
23
input_type
=
parser
.GetTensorType(
input_name
);
24
}
else
{
25
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser Randomr op has input tensor"
+
input_name
+
26
" but its type is not yet registered"
);
27
}
28
}
29
// get attributes
30
float
seed = 0;
31
std::map<std::string, float>
paramMap
;
32
std::vector<size_t> shape;
33
for
(
int
i = 0; i <
nodeproto
.attribute_size(); i++) {
34
std::string
attribute_name
=
nodeproto
.attribute(i).name();
35
auto
attr_type
=
nodeproto
.attribute(i).type();
36
if
(
attribute_name
==
"dtype"
)
37
input_type
=
static_cast<
ETensorType
>
(
nodeproto
.attribute(i).i());
38
else
if
(
attribute_name
==
"seed"
) {
39
if
(
attr_type
==
onnx::AttributeProto::FLOAT
)
40
seed =
nodeproto
.attribute(i).f();
41
else
if
(
attr_type
==
onnx::AttributeProto::INT
)
42
seed =
nodeproto
.attribute(i).i();
43
else
44
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser Random op has invalid type for attribute seed"
);
45
}
46
else
if
(
attribute_name
==
"shape"
) {
47
if
(
attr_type
!=
onnx::AttributeProto::INTS
)
48
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser Random op has invalid type for attribute shape"
);
49
shape = std::vector<size_t>(
nodeproto
.attribute(i).ints().
begin
(),
nodeproto
.attribute(i).ints().
end
());
50
}
51
else
{
52
float
value
= 0;
53
if
(
attr_type
==
onnx::AttributeProto::FLOAT
)
54
value
=
nodeproto
.attribute(i).f();
55
else
if
(
attr_type
==
onnx::AttributeProto::INT
)
56
value
=
nodeproto
.attribute(i).i();
57
else
58
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser Random op has invalid type for attribute "
+
attribute_name
);
59
paramMap
[
attribute_name
] =
value
;
60
}
61
}
62
63
std::string
output_name
=
nodeproto
.output(0);
64
65
std::unique_ptr<ROperator>
op
(
new
ROperator_Random
(
opMode
,
input_type
,
input_name
,
output_name
, shape,
paramMap
, seed));
66
67
if
(!
parser
.IsRegisteredTensorType(
output_name
)) {
68
parser
.RegisterTensorType(
output_name
,
input_type
);
69
}
70
71
return
op
;
72
};
73
74
}
// namespace SOFIE
75
}
// namespace Experimental
76
}
// namespace TMVA
RModelParser_ONNX.hxx
ROperator_Random.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
value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Definition
TGWin32VirtualXProxy.cxx:142
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::ROperator_Random
Definition
ROperator_Random.hxx:19
TMVA::Experimental::SOFIE::onnx::AttributeProto::INTS
@ INTS
Definition
onnx.hxx:464
TMVA::Experimental::SOFIE::onnx::AttributeProto::INT
@ INT
Definition
onnx.hxx:459
TMVA::Experimental::SOFIE::onnx::AttributeProto::FLOAT
@ FLOAT
Definition
onnx.hxx:458
TMVA::Experimental::SOFIE::onnx::NodeProto
Definition
onnx.hxx:504
TMVA::Experimental::SOFIE::ETensorType
ETensorType
Definition
SOFIE_common.hxx:29
TMVA::Experimental::SOFIE::ETensorType::FLOAT
@ FLOAT
TMVA::Experimental::SOFIE::ParserFuncSignature
std::function< std::unique_ptr< ROperator >(RModelParser_ONNX &, const onnx::NodeProto &)> ParserFuncSignature
Definition
RModelParser_ONNX.hxx:25
TMVA::Experimental::SOFIE::ParseRandom
ParserFuncSignature ParseRandom
Definition
ParseRandom.cxx:9
TMVA::Experimental::SOFIE::RandomOpMode
RandomOpMode
Definition
ROperator_Random.hxx:16
TMVA::Experimental::SOFIE::kNormal
@ kNormal
Definition
ROperator_Random.hxx:16
TMVA::Experimental::SOFIE::kUniform
@ kUniform
Definition
ROperator_Random.hxx:16
TMVA
create variable transformations
Definition
GeneticMinimizer.h:22
onnx.hxx
tmva
sofie_parsers
src
ParseRandom.cxx
ROOTmaster - Reference Guide Generated on Sat Sep 5 2026 04:37:47 (GVA Time) using Doxygen 1.10.0