1#ifndef TMVA_SOFIE_ROPERATOR_BASICNARY
2#define TMVA_SOFIE_ROPERATOR_BASICNARY
13namespace Experimental{
18template<
typename T, EBasicNaryOperator Op>
23 static const std::string
Name() {
return "Max";}
24 static std::string
Op(
const std::string& res, std::vector<std::string>& inputs) {
25 std::stringstream out;
26 out <<
"\t" <<
"\t" << res <<
" = " << inputs[0] <<
";\n";
27 for (
size_t i = 1; i < inputs.size(); i++) {
28 out <<
"\t" <<
"\t" << res <<
" = std::max(" << res <<
", " << inputs[i] <<
");\n";
36 static const std::string
Name() {
return "Min";}
37 static std::string
Op(
const std::string& res, std::vector<std::string>& inputs) {
38 std::stringstream out;
39 out <<
"\t" <<
"\t" << res <<
" = " << inputs[0] <<
";\n";
40 for (
size_t i = 1; i < inputs.size(); i++) {
41 out <<
"\t" <<
"\t" << res <<
" = std::min(" << res <<
", " << inputs[i] <<
");\n";
52 static const std::string
Name() {
return "Mean";}
53 static std::string
Op(
const std::string& res, std::vector<std::string>& inputs) {
54 std::stringstream out;
55 out <<
"\t" <<
"\t" << res <<
" = (" << inputs[0];
56 for (
size_t i = 1; i < inputs.size(); i++) {
57 out <<
" + " << inputs[i];
59 out <<
") / float(" << inputs.size() <<
");\n";
66 static const std::string
Name() {
return "Sum";}
67 static std::string
Op(
const std::string& res, std::vector<std::string>& inputs) {
68 std::stringstream out;
69 out <<
"\t" <<
"\t" << res <<
" = " << inputs[0];
70 for (
size_t i = 1; i < inputs.size(); i++) {
71 out <<
" + " << inputs[i];
78template <
typename T, EBasicNaryOperator Op>
99 fNY(UTILITY::Clean_name(nameY)){
100 fNInputs.reserve(inputNames.size());
101 for (
auto &
name : inputNames)
112 auto ret = std::vector<std::vector<size_t>>(1,
input[0]);
119 throw std::runtime_error(
"TMVA SOFIE BasicNary Op Input Tensor " + it +
" is not found in model");
129 for (
size_t i = 0; i <
N; i++) {
143 OpName =
"op_" + OpName;
145 throw std::runtime_error(
"TMVA SOFIE BasicNary called to Generate without being initialized first");
147 std::stringstream out;
149 out <<
SP <<
"\n//------ BasicNary operator\n";
151 for (
size_t i = 0; i <
fNInputs.size(); i++) {
154 out <<
SP <<
SP <<
"{\n";
158 out <<
SP <<
SP <<
SP <<
"delete[] data;\n";
159 out <<
SP <<
SP <<
"}\n";
165 out <<
SP <<
"std::copy(tensor_" <<
fNInputs[0] <<
", tensor_" <<
fNInputs[0] <<
" + ";
166 out <<
length <<
", tensor_" <<
fNY <<
");\n";
172 out <<
SP <<
"for (size_t id = 0; id < " <<
length <<
"; id++) {\n";
173 out << NaryOperatorTraits<T,Op>::Op(
"tensor_" +
fNY +
"[id]", inputs);
179 std::vector<std::string>
GetStdLibs() {
return { std::string(
"cmath") }; }
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
const ETensorType & GetTensorType(std::string name)
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< std::size_t > shape)
bool CheckIfTensorAlreadyExist(std::string tensor_name)
const std::vector< size_t > & GetTensorShape(std::string name)
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input)
std::vector< std::vector< size_t > > fShapeInputs
std::vector< std::string > GetStdLibs()
void Initialize(RModel &model)
std::vector< size_t > fShapeY
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input)
std::vector< std::string > fNBroadcastedInputs
std::string Generate(std::string OpName)
ROperator_BasicNary(const std::vector< std::string > &inputNames, const std::string &nameY)
std::vector< std::string > fNInputs
const std::string SP
space used to correctly indent the generated C++ code
bool AreSameShape(const std::vector< size_t > &, const std::vector< size_t > &)
std::string Clean_name(std::string input_tensor_name)
std::vector< size_t > MultidirectionalBroadcastShape(std::vector< std::vector< size_t > >)
std::string ConvertShapeToString(std::vector< size_t > shape)
std::string ConvertTypeToString(ETensorType type)
std::size_t ConvertShapeToLength(std::vector< size_t > shape)
create variable transformations
static std::string Op(const std::string &res, std::vector< std::string > &inputs)
static const std::string Name()
static std::string Op(const std::string &res, std::vector< std::string > &inputs)
static const std::string Name()
static const std::string Name()
static std::string Op(const std::string &res, std::vector< std::string > &inputs)
static const std::string Name()
static std::string Op(const std::string &res, std::vector< std::string > &inputs)