Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
term.h
Go to the documentation of this file.
1 #ifndef __TERM_H__
2 #define __TERM_H__
3 
4 #include <map>
5 #include <set>
6 #include "../tensor/untyped_tensor.h"
7 
8 namespace CTF {
9  class Idx_Tensor;
10 }
11 
12 namespace CTF_int {
18  class Sum_Term;
19  class Contract_Term;
20 
26  bool operator()(CTF::Idx_Tensor* A, CTF::Idx_Tensor* B);
27  };
28 
29 
33  class Term {
34  public:
35  char * scale;
37 
38  Term(algstrct const * sr);
39 
40  virtual ~Term();
41 
45  virtual Term * clone(std::map<tensor*, tensor*>* remap = NULL) const = 0;
46 
51  virtual void execute(CTF::Idx_Tensor output) const = 0;
52 
57  virtual double estimate_time(CTF::Idx_Tensor output) const = 0;
58 
66  virtual CTF::Idx_Tensor estimate_time(double & cost, std::vector<char> out_inds) const = 0;
67 
68 
74  virtual CTF::Idx_Tensor execute(std::vector<char> out_inds) const = 0;
75 
80  virtual std::vector<char> get_uniq_inds() const = 0;
81 
85  virtual void get_inputs(std::set<CTF::Idx_Tensor*, tensor_name_less >* inputs_set) const = 0;
86 
90  void mult_scl(char const * mulscl);
91 
96  Contract_Term operator*(Term const & A) const;
101  Contract_Term operator*(int64_t scl) const;
102  Contract_Term operator*(double scl) const;
103 
108  Sum_Term operator+(Term const & A) const;
109  Sum_Term operator+(double scl) const;
110  Sum_Term operator+(int64_t scl) const;
111 
116  Sum_Term operator-(Term const & A) const;
117 
118  Sum_Term operator-(double scl) const;
119  Sum_Term operator-(int64_t scl) const;
120 
121  Term & operator-();
122 
127  void operator=(CTF::Idx_Tensor const & B);
128  void operator=(Term const & B);
129  void operator+=(Term const & B);
130  void operator-=(Term const & B);
131  void operator*=(Term const & B);
132 
133  void operator=(double scl);
134  void operator+=(double scl);
135  void operator<<(CTF_int::Term const & B);
136  void operator<<(double scl);
137 
138 
139  void operator-=(double scl);
140  void operator*=(double scl);
141 
142  void operator=(int64_t scl);
143  void operator+=(int64_t scl);
144  void operator-=(int64_t scl);
145  void operator*=(int64_t scl);
146 
147  void operator=(int scl);
148  void operator+=(int scl);
149  void operator-=(int scl);
150  void operator*=(int scl);
154  virtual CTF::World * where_am_i() const = 0;
155 
160  operator float() const;
161 
166  operator double() const;
167 
172  operator int64_t() const;
173 
178  operator int() const;
179  };
180 
181  class Sum_Term : public Term {
182  public:
183  std::vector< Term* > operands;
184 
190  Sum_Term(Term * B, Term * A);
191 
192  // destructor frees operands
193  ~Sum_Term();
194 
195  // copy constructor
196  Sum_Term(Sum_Term const & other,
197  std::map<tensor*, tensor*>* remap = NULL);
198 
199  // dervied clone calls copy constructor
200  Term* clone(std::map<tensor*, tensor*>* remap = NULL) const;
201 
206  //Sum_Term(CTF::Idx_Tensor const & tsr);
207 
212  void execute(CTF::Idx_Tensor output) const;
213 
220  CTF::Idx_Tensor execute(std::vector<char> out_inds) const;
221 
226  double estimate_time(CTF::Idx_Tensor output) const;
227 
235  CTF::Idx_Tensor estimate_time(double & cost, std::vector<char> out_inds) const;
236 
241  std::vector<char> get_uniq_inds() const;
242 
246  void get_inputs(std::set<CTF::Idx_Tensor*, tensor_name_less >* inputs_set) const;
247 
252  Sum_Term operator+(Term const & A) const;
253 
258  Sum_Term operator-(Term const & A) const;
259 
263 // Sum_Term operator-() const;
264 
265 
269  CTF::World * where_am_i() const;
270  };
271 
275  class Contract_Term : public Term {
276  public:
277  std::vector< Term* > operands;
278 
279 
285  Contract_Term(Term * B, Term * A);
286 
287 
288  // \brief destructor frees operands
289  ~Contract_Term();
290 
291  // \brief copy constructor
292  Contract_Term(Contract_Term const & other,
293  std::map<tensor*, tensor*>* remap = NULL);
294 
295  // \brief dervied clone calls copy constructor
296  Term * clone(std::map<tensor*, tensor*>* remap = NULL) const;
297 
302  void execute(CTF::Idx_Tensor output) const;
303 
308  std::vector<char> get_uniq_inds() const;
309 
313  void get_inputs(std::set<CTF::Idx_Tensor*, tensor_name_less >* inputs_set) const;
314 
321  CTF::Idx_Tensor execute(std::vector<char> out_inds) const;
322 
327  double estimate_time(CTF::Idx_Tensor output) const;
328 
336  CTF::Idx_Tensor estimate_time(double & cost, std::vector<char> out_inds) const;
337 
338 
343  Contract_Term operator*(Term const & A) const;
344 
348 // Contract_Term operator-() const;
349 
353  CTF::World * where_am_i() const;
354  };
355 
356 
357  //FIXME: what if noncommutative?
358  inline CTF_int::Contract_Term operator*(double const & d, CTF_int::Term const & tsr){
359  return (tsr*d);
360  }
361 
362  //FIXME: what if noncommutative?
363  inline CTF_int::Contract_Term operator*(int64_t const & i, CTF_int::Term const & tsr){
364  return (tsr*i);
365  }
366 
367  void operator-=(double & d, CTF_int::Term const & tsr);
368 
369  void operator+=(double & d, CTF_int::Term const & tsr);
370 
371  void operator-=(int64_t & d, CTF_int::Term const & tsr);
372 
373  void operator+=(int64_t & d, CTF_int::Term const & tsr);
374 
375 
380 }
381 
382 #endif
a term is an abstract object representing some expression of tensors
Definition: term.h:33
algstrct * sr
Definition: term.h:36
an instance of the CTF library (world) on a MPI communicator
Definition: world.h:19
void operator+=(double &d, CTF_int::Term const &tsr)
Definition: term.cxx:744
std::vector< Term * > operands
Definition: term.h:277
comparison function for sets of tensor pointers This ensures the set iteration order is consistent ac...
Definition: term.h:25
void operator-=(double &d, CTF_int::Term const &tsr)
Definition: term.cxx:733
CTF_int::Contract_Term operator*(int64_t const &i, CTF_int::Term const &tsr)
Definition: term.h:363
algstrct (algebraic structure) defines the elementwise operations computed in each tensor contraction...
Definition: algstrct.h:34
Definition: apsp.cxx:17
char * scale
Definition: term.h:35
An experession representing a contraction of a set of tensors contained in operands.
Definition: term.h:275
a tensor with an index map associated with it (necessary for overloaded operators) ...
Definition: idx_tensor.h:15
std::vector< Term * > operands
Definition: term.h:183