1#ifndef TMVA_EXPERIMENTAL_SOFIE_ROPERATOR_BASIC_UNARY
2#define TMVA_EXPERIMENTAL_SOFIE_ROPERATOR_BASIC_UNARY
12enum class EBasicUnaryOperator {
kReciprocal,
kSqrt ,
kNeg,
kExp,
kLog,
kSin,
kCos,
kAbs,
kSoftplus,
kAtan,
kFloor };
14template <
typename T, EBasicUnaryOperator Op>
20 static std::string
Name() {
return "Reciprocal"; }
21 static std::string
Op(
const std::string &
X) {
return "1/" +
X; }
26 static std::string
Name() {
return "Sqrt"; }
27 static std::string
Op(
const std::string &
X) {
return "std::sqrt(" +
X +
")"; }
32 static std::string
Name() {
return "Neg"; }
33 static std::string
Op(
const std::string &
X) {
return "-" +
X; }
38 static std::string
Name() {
return "Exp"; }
39 static std::string
Op(
const std::string &
X) {
return "std::exp(" +
X +
")"; }
44 static std::string
Name() {
return "Log"; }
45 static std::string
Op(
const std::string &
X) {
return "std::log(" +
X +
")"; }
50 static std::string
Name() {
return "Sin"; }
51 static std::string
Op(
const std::string &
X) {
return "std::sin(" +
X +
")"; }
56 static std::string
Name() {
return "Cos"; }
57 static std::string
Op(
const std::string &
X) {
return "std::cos(" +
X +
")"; }
62 static std::string
Name() {
return "Abs"; }
63 static std::string
Op(
const std::string &
X) {
return "std::abs(" +
X +
")"; }
68 static std::string
Name() {
return "Softplus"; }
69 static std::string
Op(
const std::string &
X) {
return "std::log(std::exp(" +
X +
") + 1)"; }
74 static std::string
Name() {
return "Atan"; }
75 static std::string
Op(
const std::string &
X) {
return "std::atan(" +
X +
")"; }
80 static std::string
Name() {
return "Floor"; }
81 static std::string
Op(
const std::string &
X) {
return "std::floor(" +
X +
")"; }
84template <
typename T, EBasicUnaryOperator Op>
103 std::vector<std::vector<size_t>>
ShapeInference(std::vector<std::vector<size_t>> input)
override {
return input; }
105 std::vector<ETensorType>
TypeInference(std::vector<ETensorType> input)
override {
return input; }
108 if (!model.CheckIfTensorAlreadyExist(
fNX)) {
109 throw std::runtime_error(
"TMVA::SOFIE - Tensor " +
fNX +
" not found.");
113 model.AddIntermediateTensor(
fNY, model.GetTensorType(
fNX),
fShapeY);
115 model.AddNeededStdLib(
"cmath");
120 OpName =
"op_" + OpName;
121 std::stringstream out;
125 out <<
SP <<
"for (size_t i = 0; i < " << length <<
"; i++) {\n";
132 return { std::string(
"cmath") };
std::vector< ETensorType > TypeInference(std::vector< ETensorType > input) override
std::vector< Dim > fShapeY
std::string Generate(std::string OpName) override
ROperator_BasicUnary(std::string nameX, std::string nameY)
std::vector< Dim > fShapeX
std::vector< std::string > GetStdLibs() override
std::vector< std::vector< size_t > > ShapeInference(std::vector< std::vector< size_t > > input) override
void Initialize(RModel &model) 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
std::string ConvertDimShapeToLength(const std::vector< Dim > &shape)
create variable transformations
static std::string Op(const std::string &X)
static std::string Name()
static std::string Name()
static std::string Op(const std::string &X)
static std::string Op(const std::string &X)
static std::string Name()
static std::string Op(const std::string &X)
static std::string Name()
static std::string Name()
static std::string Op(const std::string &X)
static std::string Op(const std::string &X)
static std::string Name()
static std::string Name()
static std::string Op(const std::string &X)
static std::string Name()
static std::string Op(const std::string &X)
static std::string Name()
static std::string Op(const std::string &X)
static std::string Op(const std::string &X)
static std::string Name()
static std::string Op(const std::string &X)
static std::string Name()