QDP++
qdp_qdptype.h
Go to the documentation of this file.
1// -*- C++ -*-
2
6
7#ifndef QDP_QDPTYPE_H
8#define QDP_QDPTYPE_H
9
10namespace QDP {
11
12
20
21
23
27template<class T, class C>
29{
30public:
32 typedef T Subtype_t;
33
35 typedef C Container_t;
36
39
41 QDPType(const QDPType&) {}
42
45
46
47 //---------------------------------------------------------
48 // Operators
49
50 inline
51 C& assign(const typename WordType<C>::Type_t& rhs)
52 {
53 C* me = static_cast<C*>(this);
55 evaluate(*me,OpAssign(),PETE_identity(Scalar_t(rhs)),all);
56 return *me;
57 }
58
59 inline
60 C& assign(const Zero&)
61 {
62 C* me = static_cast<C*>(this);
63 zero_rep(*me);
64 return *me;
65 }
66
67 template<class T1,class C1>
68 inline
69 C& assign(const QDPType<T1,C1>& rhs)
70 {
71 C* me = static_cast<C*>(this);
73 return *me;
74 }
75
76 template<class T1,class C1>
77 inline
78 C& assign(const QDPExpr<T1,C1>& rhs)
79 {
80 C* me = static_cast<C*>(this);
81 evaluate(*me,OpAssign(),rhs,all);
82 return *me;
83 }
84
85
87 inline
88 C& operator=(const QDPType& rhs)
89 {
90 return assign(rhs);
91 }
92
93
94 inline
95 C& operator+=(const typename WordType<C>::Type_t& rhs)
96 {
97 C* me = static_cast<C*>(this);
99 evaluate(*me,OpAddAssign(),PETE_identity(Scalar_t(rhs)),all);
100 return *me;
101 }
102
103 template<class T1,class C1>
104 inline
106 {
107 C* me = static_cast<C*>(this);
109 return *me;
110 }
111
112 template<class T1,class C1>
113 inline
115 {
116 C* me = static_cast<C*>(this);
117 evaluate(*me,OpAddAssign(),rhs,all);
118 return *me;
119 }
120
121
122 inline
123 C& operator-=(const typename WordType<C>::Type_t& rhs)
124 {
125 C* me = static_cast<C*>(this);
126 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
127 evaluate(*me,OpSubtractAssign(),PETE_identity(Scalar_t(rhs)),all);
128 return *me;
129 }
130
131 template<class T1,class C1>
132 inline
134 {
135 C* me = static_cast<C*>(this);
137 return *me;
138 }
139
140 template<class T1,class C1>
141 inline
143 {
144 C* me = static_cast<C*>(this);
145 evaluate(*me,OpSubtractAssign(),rhs,all);
146 return *me;
147 }
148
149
150 inline
151 C& operator*=(const typename WordType<C>::Type_t& rhs)
152 {
153 C* me = static_cast<C*>(this);
154 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
155 evaluate(*me,OpMultiplyAssign(),PETE_identity(Scalar_t(rhs)),all);
156 return *me;
157 }
158
159 template<class T1,class C1>
160 inline
162 {
163 C* me = static_cast<C*>(this);
165 return *me;
166 }
167
168 template<class T1,class C1>
169 inline
171 {
172 C* me = static_cast<C*>(this);
173 evaluate(*me,OpMultiplyAssign(),rhs,all);
174 return *me;
175 }
176
177
178 inline
179 C& operator/=(const typename WordType<C>::Type_t& rhs)
180 {
181 C* me = static_cast<C*>(this);
182 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
183 evaluate(*me,OpDivideAssign(),PETE_identity(Scalar_t(rhs)),all);
184 return *me;
185 }
186
187 template<class T1,class C1>
188 inline
190 {
191 C* me = static_cast<C*>(this);
193 return *me;
194 }
195
196 template<class T1,class C1>
197 inline
199 {
200 C* me = static_cast<C*>(this);
201 evaluate(*me,OpDivideAssign(),rhs,all);
202 return *me;
203 }
204
205
206 inline
207 C& operator%=(const typename WordType<C>::Type_t& rhs)
208 {
209 C* me = static_cast<C*>(this);
210 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
211 evaluate(*me,OpModAssign(),PETE_identity(Scalar_t(rhs)),all);
212 return *me;
213 }
214
215 template<class T1,class C1>
216 inline
218 {
219 C* me = static_cast<C*>(this);
221 return *me;
222 }
223
224 template<class T1,class C1>
225 inline
227 {
228 C* me = static_cast<C*>(this);
229 evaluate(*me,OpModAssign(),rhs,all);
230 return *me;
231 }
232
233
234 inline
235 C& operator|=(const typename WordType<C>::Type_t& rhs)
236 {
237 C* me = static_cast<C*>(this);
238 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
239 evaluate(*me,OpBitwiseOrAssign(),PETE_identity(Scalar_t(rhs)),all);
240 return *me;
241 }
242
243 template<class T1,class C1>
244 inline
246 {
247 C* me = static_cast<C*>(this);
249 return *me;
250 }
251
252 template<class T1,class C1>
253 inline
255 {
256 C* me = static_cast<C*>(this);
258 return *me;
259 }
260
261
262 inline
263 C& operator&=(const typename WordType<C>::Type_t& rhs)
264 {
265 C* me = static_cast<C*>(this);
266 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
267 evaluate(*me,OpBitwiseAndAssign(),PETE_identity(Scalar_t(rhs)),all);
268 return *me;
269 }
270
271 template<class T1,class C1>
272 inline
274 {
275 C* me = static_cast<C*>(this);
277 return *me;
278 }
279
280 template<class T1,class C1>
281 inline
283 {
284 C* me = static_cast<C*>(this);
286 return *me;
287 }
288
289
290 inline
291 C& operator^=(const typename WordType<C>::Type_t& rhs)
292 {
293 C* me = static_cast<C*>(this);
294 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
295 evaluate(*me,OpBitwiseXorAssign(),PETE_identity(Scalar_t(rhs)),all);
296 return *me;
297 }
298
299 template<class T1,class C1>
300 inline
302 {
303 C* me = static_cast<C*>(this);
305 return *me;
306 }
307
308 template<class T1,class C1>
309 inline
311 {
312 C* me = static_cast<C*>(this);
314 return *me;
315 }
316
317
318 inline
319 C& operator<<=(const typename WordType<C>::Type_t& rhs)
320 {
321 C* me = static_cast<C*>(this);
322 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
323 evaluate(*me,OpLeftShiftAssign(),PETE_identity(Scalar_t(rhs)),all);
324 return *me;
325 }
326
327 template<class T1,class C1>
328 inline
330 {
331 C* me = static_cast<C*>(this);
333 return *me;
334 }
335
336 template<class T1,class C1>
337 inline
339 {
340 C* me = static_cast<C*>(this);
341 evaluate(*me,OpLeftShiftAssign(),rhs,all);
342 return *me;
343 }
344
345
346 inline
347 C& operator>>=(const typename WordType<C>::Type_t& rhs)
348 {
349 C* me = static_cast<C*>(this);
350 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
351 evaluate(*me,OpRightShiftAssign(),PETE_identity(Scalar_t(rhs)),all);
352 return *me;
353 }
354
355 template<class T1,class C1>
356 inline
358 {
359 C* me = static_cast<C*>(this);
361 return *me;
362 }
363
364 template<class T1,class C1>
365 inline
367 {
368 C* me = static_cast<C*>(this);
370 return *me;
371 }
372
373
374 template<class T1,class C1>
375 inline
376 void assign(const QDPSubType<T1,C1>& rhs)
377 {
378 if (!rhs.getOwnsMemory())
379 QDP_error_exit("Assigning subtype(view) to qdptype is not supported");
380
381 //QDP_info("qdptype = subtype(own) %d",rhs.subset().numSiteTable());
382
383 const int *tab = rhs.subset().siteTable().slice();
384 for(int j=0; j < rhs.subset().numSiteTable(); ++j) {
385 int i = tab[j];
386 elem(i) = rhs.getF()[j];
387 }
388 }
389
390
391
392
393public:
394 T& elem(int i) {return static_cast<C*>(this)->elem(i);}
395 const T& elem(int i) const {return static_cast<const C*>(this)->elem(i);}
396
397 T& elem() {return static_cast<const C*>(this)->elem();}
398 const T& elem() const {return static_cast<const C*>(this)->elem();}
399};
400 // end of group1
402
403//-----------------------------------------------------------------------------
404// Traits classes to support return types
405//-----------------------------------------------------------------------------
406
407// Default unary(QDPType) -> QDPType
408template<class T1, class C1, class Op>
413
414// Default binary(QDPType,QDPType) -> QDPType
415template<class T1, class C1, class T2, class C2, class Op>
420
421// Currently, the only trinary operator is ``where'', so return
422// based on T2 and T3
423// Default trinary(QDPType,QDPType,QDPType) -> QDPType
424template<class T1, class C1, class T2, class C2, class T3, class C3, class Op>
429
430
431//-----------------------------------------------------------------------------
432// We need to specialize CreateLeaf<T> for our class, so that operators
433// know what to stick in the leaves of the expression tree.
434//-----------------------------------------------------------------------------
435
436template<class T, class C>
438{
441// typedef Inp_t Leaf_t;
442 inline static
443 Leaf_t make(const Inp_t &a) { return Leaf_t(a); }
444};
445
446
447//-----------------------------------------------------------------------------
448// Specialization of LeafFunctor class for applying the EvalLeaf1
449// tag to a QDPType. The apply method simply returns the array
450// evaluated at the point.
451//-----------------------------------------------------------------------------
452
453template<class T, class C>
455{
457// typedef T Type_t;
458 inline static Type_t apply(const QDPType<T,C> &a, const ElemLeaf &f)
459 {
460 return Type_t(a.elem());
461 }
462};
463
464template<class T, class C>
466{
468// typedef T Type_t;
469 inline static Type_t apply(const QDPType<T,C> &a, const EvalLeaf1 &f)
470 {
471 return Type_t(a.elem(f.val1()));
472 }
473};
474
475} // namespace QDP
476
477#endif
478
Expression class for QDP.
Definition qdp_qdpexpr.h:16
QDPSubType - type representing a field living on a subset.
const Subset & subset() const
QDPType - major type class/container for all QDP objects.
Definition qdp_qdptype.h:29
C & operator+=(const typename WordType< C >::Type_t &rhs)
Definition qdp_qdptype.h:95
C & operator<<=(const QDPType< T1, C1 > &rhs)
QDPType(const QDPType &)
Copy constructor.
Definition qdp_qdptype.h:41
C & operator*=(const typename WordType< C >::Type_t &rhs)
C & operator|=(const QDPExpr< T1, C1 > &rhs)
C & operator>>=(const QDPExpr< T1, C1 > &rhs)
C & operator+=(const QDPType< T1, C1 > &rhs)
C & assign(const Zero &)
Definition qdp_qdptype.h:60
C & assign(const QDPType< T1, C1 > &rhs)
Definition qdp_qdptype.h:69
C & operator/=(const QDPType< T1, C1 > &rhs)
C Container_t
Type of the container class.
Definition qdp_qdptype.h:35
C & operator|=(const typename WordType< C >::Type_t &rhs)
C & operator%=(const QDPType< T1, C1 > &rhs)
C & operator>>=(const typename WordType< C >::Type_t &rhs)
C & operator&=(const QDPExpr< T1, C1 > &rhs)
C & operator=(const QDPType &rhs)
Use this for default operator=.
Definition qdp_qdptype.h:88
C & operator<<=(const typename WordType< C >::Type_t &rhs)
C & operator<<=(const QDPExpr< T1, C1 > &rhs)
void assign(const QDPSubType< T1, C1 > &rhs)
C & operator^=(const typename WordType< C >::Type_t &rhs)
T Subtype_t
Type of the first argument.
Definition qdp_qdptype.h:32
~QDPType()
Destructor.
Definition qdp_qdptype.h:44
T & elem(int i)
C & operator-=(const QDPType< T1, C1 > &rhs)
C & operator>>=(const QDPType< T1, C1 > &rhs)
C & assign(const typename WordType< C >::Type_t &rhs)
Definition qdp_qdptype.h:51
C & operator&=(const QDPType< T1, C1 > &rhs)
C & operator^=(const QDPType< T1, C1 > &rhs)
QDPType()
Main constructor.
Definition qdp_qdptype.h:38
C & operator|=(const QDPType< T1, C1 > &rhs)
C & operator&=(const typename WordType< C >::Type_t &rhs)
C & assign(const QDPExpr< T1, C1 > &rhs)
Definition qdp_qdptype.h:78
C & operator%=(const typename WordType< C >::Type_t &rhs)
C & operator/=(const QDPExpr< T1, C1 > &rhs)
C & operator-=(const typename WordType< C >::Type_t &rhs)
C & operator-=(const QDPExpr< T1, C1 > &rhs)
const T & elem(int i) const
C & operator%=(const QDPExpr< T1, C1 > &rhs)
C & operator+=(const QDPExpr< T1, C1 > &rhs)
C & operator^=(const QDPExpr< T1, C1 > &rhs)
const T & elem() const
C & operator*=(const QDPType< T1, C1 > &rhs)
C & operator*=(const QDPExpr< T1, C1 > &rhs)
C & operator/=(const typename WordType< C >::Type_t &rhs)
const multi1d< int > & siteTable() const
Definition qdp_subset.h:83
const T * slice() const
Return ref to a column slice.
Definition qdp_multi.h:225
MakeReturn< UnaryNode< OpIdentity, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, OpIdentity >::Type_t >::Expression_t PETE_identity(const QDPType< T1, C1 > &l)
Identity operator.
Definition qdp.h:1485
void zero_rep(IScalar< T > &dest)
dest = 0
Definition qdp_inner.h:1841
void evaluate(OLattice< DCol > &d, const OpAssign &op, const QDPExpr< BinaryNode< OpMultiply, Reference< QDPType< DCol, OLattice< DCol > > >, Reference< QDPType< DCol, OLattice< DCol > > > >, OLattice< DCol > > &rhs, const Subset &s)
OLattice< PScalar< PColorMatrix< RComplexFloat, 3 > > > C
Subset all
Default all subset.
Definition qdp_subset.cc:16
Yet another random number generator.
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
Definition qdp_util.cc:93
QDPType< typename BinaryReturn< T1, T2, Op >::Type_t, typename BinaryReturn< C1, C2, Op >::Type_t > Type_t
Promote< T1, T2 >::Type_t Type_t
Definition qdp.h:377
static Leaf_t make(const Inp_t &a)
Scalar< T > Leaf_t
Definition qdp.h:97
int val1() const
Definition qdp.h:97
static Type_t apply(const QDPType< T, C > &a, const ElemLeaf &f)
static Type_t apply(const QDPType< T, C > &a, const EvalLeaf1 &f)
Construct simple word type. Default behavior is empty.
Definition qdp_traits.h:93
QDPType< typename BinaryReturn< T2, T3, Op >::Type_t, typename BinaryReturn< C2, C3, Op >::Type_t > Type_t
QDPType< typename UnaryReturn< T1, Op >::Type_t, typename UnaryReturn< C1, Op >::Type_t > Type_t
Simple zero tag.
Definition qdp_traits.h:122