Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TMVA/ROperator_Erf.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #ifndef TMVA_SOFIE_ROPERATOR_Erf
0002 #define TMVA_SOFIE_ROPERATOR_Erf
0003 
0004 #include "TMVA/SOFIE_common.hxx"
0005 #include "TMVA/ROperator.hxx"
0006 #include "TMVA/RModel.hxx"
0007 
0008 #include <sstream>
0009 
0010 namespace TMVA{
0011 namespace Experimental{
0012 namespace SOFIE{
0013 
0014 template <typename T>
0015 class ROperator_Erf final : public ROperator
0016 {
0017 
0018 private:
0019 
0020    std::string fNX;
0021    std::string fNY;
0022    std::vector<size_t> fShape;
0023 
0024 public:
0025    ROperator_Erf(){}
0026    ROperator_Erf(std::string nameX, std::string nameY):
0027       fNX(UTILITY::Clean_name(nameX)), fNY(UTILITY::Clean_name(nameY)){
0028          fInputTensorNames = { fNX };
0029          fOutputTensorNames = { fNY };
0030       }
0031 
0032    std::vector<ETensorType> TypeInference(std::vector<ETensorType> input) override {
0033       return input;
0034    }
0035 
0036    std::vector<std::vector<size_t>> ShapeInference(std::vector<std::vector<size_t>> input) override {
0037       auto ret = input; //suggest copy to compiler
0038       return ret;
0039    }
0040 
0041    void Initialize(RModel& model) override {
0042        //input must be a graph input, or already initialized intermediate tensor
0043       if (model.CheckIfTensorAlreadyExist(fNX) == false){
0044         throw std::runtime_error("TMVA SOFIE Erf Op Input Tensor is not found in model");
0045       }
0046       fShape = model.GetTensorShape(fNX);
0047       model.AddIntermediateTensor(fNY, model.GetTensorType(fNX), fShape);
0048    }
0049 
0050 
0051    std::string Generate(std::string OpName) override {
0052       OpName = "op_" + OpName;
0053       if (fShape.empty()) {
0054          throw std::runtime_error("TMVA SOFIE Erf operator called to Generate without being initialized first");
0055       }
0056       std::stringstream out;
0057       size_t length = ConvertShapeToLength(fShape);
0058       out << "\n//------ ERF\n";
0059       out << SP << "for (int id = 0; id < " << length << " ; id++){\n";
0060       out << SP << SP << "tensor_" << fNY << "[id] = std::erf(tensor_" << fNX << "[id]);\n";
0061       out << SP << "}\n";
0062       return out.str();
0063    }
0064 
0065    std::vector<std::string> GetStdLibs() override { return { std::string("cmath") };}
0066    
0067 };
0068 
0069 }//SOFIE
0070 }//Experimental
0071 }//TMVA
0072 
0073 
0074 #endif //TMVA_SOFIE_ROPERATOR_Erf