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 << res <<
" = std::max({ " <<
inputs[0];
27 for (
size_t i = 1; i <
inputs.size(); i++) {
37 static const std::string
Name() {
return "Min";}
38 static std::string
Op(
const std::string& res, std::vector<std::string>&
inputs) {
39 std::stringstream out;
40 out << res <<
" = std::min({ " <<
inputs[0];
41 for (
size_t i = 1; i <
inputs.size(); i++) {
54 static const std::string
Name() {
return "Mean";}
55 static std::string
Op(
const std::string& res, std::vector<std::string>&
inputs) {
56 std::stringstream out;
57 out << res <<
" = (" <<
inputs[0];
58 for (
size_t i = 1; i <
inputs.size(); i++) {
61 out <<
") / float(" <<
inputs.size() <<
");\n";
68 static const std::string
Name() {
return "Sum";}
69 static std::string
Op(
const std::string& res, std::vector<std::string>&
inputs) {
70 std::stringstream out;
71 out << res <<
" = " <<
inputs[0];
72 for (
size_t i = 1; i <
inputs.size(); i++) {
80template <
typename T, EBasicNaryOperator Op>
109 [](
const std::string& s) -> std::string_view { return s; });
120 auto ret = std::vector<std::vector<size_t>>(1,
input[0]);
128 throw std::runtime_error(
"TMVA SOFIE BasicNary Op Input Tensor " + it +
" is not found in model");
133 throw std::runtime_error(
"TMVA SOFIE BasicNary : supports only 2 inputs for dynamic tensors");
157 if (
i_s.isParam &&
i_s.param ==
p)
165 for (
size_t i = 0; i <
fDimShapeY.size(); i++) {
167 if (s.isParam && s.param.find(
"std::max") != std::string::npos) {
195 std::cout << NaryOperatorTraits<T, Op>::Name() <<
" : ";
206 throw std::runtime_error(
"TMVA SOFIE BasicNary called to Generate without being initialized first");
208 std::stringstream out;
210 out <<
SP <<
"\n//------ BasicNary operator\n";
215 out <<
SP <<
"std::copy(tensor_" <<
fNInputs[0] <<
", tensor_" <<
fNInputs[0] <<
" + ";
216 out <<
length <<
", tensor_" <<
fNY <<
");\n";
221 for (
int i = 0; i <
nInputs; i++)
233 for (
size_t i = 0; i <
fDimShapeY.size(); ++i) {
237 out <<
"for (size_t idx_" << i <<
" = 0; idx_" << i <<
" < " <<
fDimShapeY[i]
238 <<
"; ++idx_" << i <<
"){\n";
246 for (
int j = 0;
j < 3;
j++)
256 std::all_of(shape.begin(), shape.end(), [](
Dim d) { return d.dim == 1 || d.GetVal() ==
"1"; })) {
259 for (
size_t i = 0; i < shape.size(); ++i) {
260 if (shape[i].dim == 1 || shape[i].GetVal() ==
"1")
263 if (
stride[i].GetVal() !=
"1")
268 for (
int j = 0;
j < 3;
j++)
275 for (
int j = 0;
j <
nloop + 1;
j++) out <<
SP;
279 for (
int i =
nloop; i > 0; i--) {
280 for (
int j = 0;
j < i;
j++) out <<
SP;
287 std::vector<std::string>
GetStdLibs()
override {
return { std::string(
"cmath") }; }
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
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
std::vector< size_t > GetTensorShape(const std::string &name) const
std::vector< Dim > GetDimTensorShape(const std::string &name) const
void AddIntermediateTensor(std::string tensor_name, ETensorType type, std::vector< Dim > dim_shape)
bool CheckIfTensorAlreadyExist(std::string tensor_name)
bool IsDimInputTensor(const std::string &name) const
ETensorType GetTensorType(std::string name) const
const std::vector< std::string > & GetInputTensorNames() const
std::vector< std::vector< Dim > > fShapeInputs
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input) override
std::vector< size_t > fShapeY
std::vector< std::string > fNBroadcastedInputs
ROperator_BasicNary(const std::vector< std::string > &inputNames, const std::string &nameY)
std::vector< std::string > GetStdLibs() override
std::string Generate(std::string OpName) override
void Initialize(RModel &model) override
std::vector< std::string > fNInputs
std::vector< Dim > fDimShapeY
std::vector< std::string_view > fInputTensorNames
const std::string SP
space used to correctly indent the generated C++ code
std::vector< std::string_view > fOutputTensorNames
std::string Clean_name(std::string input_tensor_name)
std::vector< size_t > MultidirectionalBroadcastShape(std::vector< std::vector< size_t > >)
std::vector< size_t > ComputeStrideFromShape(const std::vector< size_t > &shape)
compute stride of a tensor given its shape (assume layout is row-major)
std::vector< Dim > ConvertShapeToDim(const std::vector< size_t > &shape)
Convert shape from integer format to dynamic one (based on Dim)
std::string ConvertTypeToString(ETensorType type)
std::string ConvertDimShapeToLength(const std::vector< Dim > &shape)
std::string ConvertShapeToString(const 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)