Documentation of CSL
libraryfunction.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef CSL_LIBRARYFUNCTION_H_INCLUDED
24 #define CSL_LIBRARYFUNCTION_H_INCLUDED
25 
26 #include <string>
27 #include "abstract.h"
28 #include "indicial.h"
29 #include "default_move_cpy.h"
30 #include "libraryevaluator.h"
31 
32 namespace csl {
33 
34  class LibraryGroup;
35 
36  struct LibParameter {
37  std::string name;
38  std::string type;
39  };
40 
41  inline bool operator<(LibParameter const &A, LibParameter const &B) {
42  return A.name < B.name;
43  }
44 
45  class LibFunction {
46 
47  public:
48 
49  static inline size_t nParamThresholdStructure = 10;
50 
51  DEFINE_DEFAULT_CPY_MV(LibFunction)
52 
53  LibFunction(std::string_view t_name,
54  Expr const& t_expression,
55  std::shared_ptr<LibraryGroup> const &t_group);
56 
57  ~LibFunction() {}
58 
59  std::string const& getName() const;
60  std::string getTensorName(csl::Parent const &tensor) const;
61  LibraryGroup const &getGroup() const { return *group; }
62  LibraryGroup &getGroup() { return *group; }
63  Expr& getExpression();
64  Expr const& getExpression() const;
65  bool isTensorial() const;
66  int getPosTensorParameter() const { return tensorParameter; }
67  void setPosTensorParameter(int t_pos) { tensorParameter = t_pos; }
68  std::vector<csl::Tensor> const& getTensors() const;
69  std::vector<csl::Tensor>& getTensors();
70  std::vector<std::string> const& getIntermediateSteps() const;
71  std::vector<std::string>& getIntermediateSteps();
72  std::vector<LibParameter> const& getParameters() const;
73 
74  void setName(std::string_view t_name);
75  void setExpression(Expr const& t_expression);
76  void setTensorial(bool t_tensorial);
77  void addTensor(Expr const& tensor);
78  void setTensors(std::vector<csl::Tensor> const& t_tensors);
79  Expr addIntermediate(Expr const& intermediate);
80  void setIntermediateSteps(std::vector<std::string> const& t_interm);
81  void addParameter(std::string const &param);
82  void setParameters(std::vector<LibParameter> const& t_parameters);
83  void removeParameter(std::string_view param);
84  void addInitInstruction(std::string const &t_inst);
85 
86  static
87  void cutParameters(
88  std::vector<LibParameter> &parameters,
89  int &tensorParameter
90  );
91  static
92  void sortParameters(
93  std::vector<LibParameter> &parameters,
94  int tensorParameter
95  );
96 
97  void print(std::ostream& out,
98  bool header,
99  std::string const &initInstruction = ""
100  ) const;
101 
102  private:
103 
104  void printName(std::ostream& out) const;
105  void printBody(
106  std::ostream& out,
107  std::string const &initInstruction
108  ) const;
109  void printExpression(std::ostream& out,
110  Expr const& expression,
111  int indent,
112  std::string const& beginning = "") const;
113 
114  void parse();
115 
116  private:
117 
118  std::string name;
119 
120  std::string varType;
121 
122  Expr expression;
123 
124  bool tensorial;
125 
126  mutable
127  LibEvalSession session;
128 
129  mutable
131 
133 
134  std::vector<csl::Tensor> tensors;
135 
136  std::vector<std::string> intermediateSteps;
137 
138  std::vector<std::string> initInstructions;
139 
140  std::vector<LibParameter> parameters;
141 
142  int tensorParameter = -1;
143  };
144 
145 } // End of namespace csl
146 
147 #endif // ifndef CSL_LIBRARYFUNCTION_H_INCLUDED
Namespace for csl library.
Definition: abreviation.h:34
Definition: parent.h:439
Definition: libraryfunction.h:45
Definition: libraryfunction.h:36
Definition: diagonalization.h:34
Definition: librarygroup.h:23
Definition: libraryevaluator.h:111
Base classes for all exprs in the program.
Objects handling indexed expressions in order to perform indicial tensor calculations.
bool operator<(const Expr &a, const Expr &b)
see Abstract::operator<()
Definition: abstract.cpp:1423
Definition: libraryevaluator.h:119
Expression type/.
Definition: abstract.h:1573