Warning, file /include/root/TMVA/ROperator_EyeLike.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_EyeLike
0002 #define TMVA_SOFIE_ROPERATOR_EyeLike
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 class ROperator_EyeLike final : public ROperator
0015 {
0016
0017 private:
0018
0019 int fdtype = static_cast<int>(ETensorType::FLOAT);
0020 int fk = 0;
0021 std::string fNX;
0022 std::string fNY;
0023 std::vector<size_t> fShape;
0024
0025 public:
0026 ROperator_EyeLike(){}
0027 ROperator_EyeLike(int dtype, int k, std::string nameX, std::string nameY):
0028 fdtype(dtype), fk(k), fNX(UTILITY::Clean_name(nameX)), fNY(UTILITY::Clean_name(nameY)){
0029 fInputTensorNames = { fNX };
0030 fOutputTensorNames = { fNY };
0031 }
0032
0033 std::vector<ETensorType> TypeInference(std::vector<ETensorType> input) override {
0034 return input;
0035 }
0036
0037 std::vector<std::vector<size_t>> ShapeInference(std::vector<std::vector<size_t>> input) override {
0038 auto ret = input;
0039 return ret;
0040 }
0041
0042 void Initialize(RModel& model) override {
0043 if (model.CheckIfTensorAlreadyExist(fNX) == false){
0044 throw std::runtime_error("TMVA SOFIE EyeLike Op Input Tensor is not found in model");
0045 }
0046 fShape = model.GetTensorShape(fNX);
0047 if (fShape.size() != 2)
0048 throw std::runtime_error("TMVA SOFIE EyeLike Op Input Tensor is not of rank 2");
0049
0050 if(fdtype){
0051 ETensorType extractedType = static_cast<ETensorType>(fdtype);
0052 model.AddIntermediateTensor(fNY, extractedType, fShape);
0053 }
0054 else{
0055 model.AddIntermediateTensor(fNY, model.GetTensorType(fNX), fShape);
0056 }
0057 }
0058
0059
0060 std::string Generate(std::string OpName) override {
0061 OpName = "op_" + OpName;
0062 if (fShape.empty()){
0063 throw std::runtime_error("TMVA SOFIE Operator EyeLike called to Generate without being initialized first");
0064 }
0065 auto length = ConvertShapeToLength(fShape);
0066 auto stride = TMVA::Experimental::SOFIE::UTILITY::ComputeStrideFromShape(fShape);
0067 std::stringstream out;
0068 out << SP << "///--------EyeLike operator\n" << std::endl;
0069
0070 out << SP << "(void) tensor_" << fNX << ";\n";
0071
0072 out << SP << "std::fill(tensor_" << fNY << ", tensor_" << fNY << " + " << length << ","
0073 << 0 << ");\n";
0074 out << SP << "for (int i = 0; i < " << fShape[0] << "; i++) {\n";
0075 out << SP << SP << "int j = i +" << fk << ";\n";
0076 out << SP << SP << "if (j >= 0 && j < " << fShape[1] << ")\n";
0077 out << SP << SP << SP << "tensor_" << fNY << "[i * " << fShape[1] << "+ j] = 1;\n";
0078 out << SP << "}\n";
0079 return out.str();
0080 }
0081
0082 };
0083
0084 }
0085 }
0086 }
0087
0088
0089 #endif