1#ifndef TMVA_SOFIE_ROPERATOR_PRelu
2#define TMVA_SOFIE_ROPERATOR_PRelu
11namespace Experimental {
28 :
fNX(UTILITY::Clean_name(nameX)),
fNSlope(UTILITY::Clean_name(nameSlope)),
fNY(UTILITY::Clean_name(nameY))
30 if (std::is_same<T, float>::value) {
33 throw std::runtime_error(
"TMVA SOFIE Encountered unsupported type parsing a PRelu operator");
40 if (model.CheckIfTensorAlreadyExist(
fNX) ==
false || model.CheckIfTensorAlreadyExist(
fNSlope) ==
false) {
41 throw std::runtime_error(
"TMVA SOFIE PRelu Op Input Tensor is not found in model");
50 }
catch (
const std::runtime_error &
e) {
51 throw std::runtime_error(
"TMVA SOFIE PRelu Op slope tensor " +
fNSlope +
52 " cannot be broadcast to input tensor " +
fNX +
": " +
e.what());
55 model.AddIntermediateTensor(
fNY, model.GetTensorType(
fNX),
fShapeX);
57 std::string
Generate(std::string OpName)
override
59 OpName =
"op_" + OpName;
62 throw std::runtime_error(
"TMVA SOFIE Operator PRelu called to Generate without being initialized first");
75 if (!slopeIdx.empty())
78 slopeIdx +=
"id % " + std::to_string(
fShapeX[k]);
80 slopeIdx +=
"(id / " + std::to_string(stridesX[k]) +
") % " + std::to_string(
fShapeX[k]);
81 if (stridesSlope[k] != 1)
82 slopeIdx +=
" * " + std::to_string(stridesSlope[k]);
87 std::stringstream out;
89 out <<
"\n//------ PRELU\n";
90 out <<
SP <<
"for (int id = 0; id < " <<
length <<
" ; id++){\n";
91 out <<
SP <<
SP <<
"tensor_" <<
fNY <<
"[id] = ((tensor_" <<
fNX <<
"[id] >= 0 )? tensor_" <<
fNX
92 <<
"[id] : tensor_" <<
fNSlope <<
"[" << slopeIdx <<
"] * tensor_" <<
fNX <<
"[id]);\n";
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 > fShapeSlope
void Initialize(RModel &model) override
ROperator_PRelu(std::string nameX, std::string nameSlope, std::string nameY)
std::vector< size_t > fShapeX
std::string Generate(std::string OpName) override
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
bool AreSameShape(const std::vector< size_t > &, const std::vector< size_t > &)
std::vector< size_t > UnidirectionalBroadcastShape(std::vector< size_t > &, 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::size_t ConvertShapeToLength(const std::vector< size_t > &shape)
create variable transformations