ROOT
master
Reference Guide
Loading...
Searching...
No Matches
ParseEinsum.cxx
Go to the documentation of this file.
1
#include "
TMVA/RModelParser_ONNX.hxx
"
2
#include "
TMVA/ROperator_Einsum.hxx
"
3
#include "
onnx.hxx
"
4
5
namespace
TMVA
{
6
namespace
Experimental {
7
namespace
SOFIE {
8
9
ParserFuncSignature
ParseEinsum
= [](
RModelParser_ONNX
&
parser
,
const
onnx::NodeProto
&
nodeproto
) {
10
11
ETensorType
input_type
=
ETensorType::UNDEFINED
;
12
int
input_size =
nodeproto
.input_size();
13
std::vector<std::string>
input_names
(input_size);
14
for
(
int
i = 0; i < input_size; i++) {
15
if
(!
parser
.IsRegisteredTensorType(
nodeproto
.input(i))){
16
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser Einsum op has input tensor "
+
nodeproto
.input(i)
17
+
" but its type is not yet registered"
);
18
}
19
if
(i == 0)
20
input_type
=
parser
.GetTensorType(
nodeproto
.input(0));
21
if
(
parser
.GetTensorType(
nodeproto
.input(i)) !=
input_type
) {
22
throw
std::runtime_error(
"TMVA::SOFIE ONNX parser Einsum op has input tensors of different types: "
+
23
nodeproto
.input(i) +
" : "
+
ConvertTypeToString
(
parser
.GetTensorType(
nodeproto
.input(2))) +
24
" and "
+
nodeproto
.input(0) +
" : "
+
ConvertTypeToString
(
input_type
));
25
}
26
input_names
[i] =
nodeproto
.input(i);
27
}
28
29
// equation attribute should be existing
30
if
(
nodeproto
.attribute_size() == 0)
31
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser Einsum op has no attribute defining the equation"
);
32
if
(
nodeproto
.attribute(0).name() !=
"equation"
)
33
throw
std::runtime_error(
"TMVA::SOFIE ONNX Parser Einsum op has wrong attribute name: "
+
nodeproto
.attribute(0).name());
34
std::string
equation
=
nodeproto
.attribute(0).s();
35
36
std::unique_ptr<ROperator>
op
;
37
std::string
output_name
=
nodeproto
.output(0);
38
39
40
41
switch
(
input_type
) {
42
case
ETensorType::FLOAT
:
43
op
.reset(
new
ROperator_Einsum<float>
(
equation
,
input_names
,
output_name
));
44
break
;
45
default
:
46
throw
std::runtime_error(
"TMVA::SOFIE - Unsupported - Einsum Operator does not yet support input type "
+
47
std::to_string(
static_cast<
int
>
(
input_type
)));
48
}
49
50
// Infer the output type
51
if
(!
parser
.IsRegisteredTensorType(
output_name
)) {
52
parser
.RegisterTensorType(
output_name
,
input_type
);
53
}
54
55
return
op
;
56
};
57
58
59
}
// namespace SOFIE
60
}
// namespace Experimental
61
}
// namespace TMVA
RModelParser_ONNX.hxx
ROperator_Einsum.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::UNDEFINED
@ UNDEFINED
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::ParseEinsum
ParserFuncSignature ParseEinsum
Definition
ParseEinsum.cxx:9
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
ParseEinsum.cxx
ROOTmaster - Reference Guide Generated on Sat Sep 5 2026 04:37:47 (GVA Time) using Doxygen 1.10.0