QDP++
qdp_qdpsubtype.h
Go to the documentation of this file.
1// -*- C++ -*-
7
8#ifndef QDP_QDPSUBTYPE_H
9#define QDP_QDPSUBTYPE_H
10
11namespace QDP {
12
13
15
20template<class T, class C>
22{
24 typedef typename QDPSubTypeTrait<C>::Type_t CC;
25
26public:
29
32
35
36
37 //---------------------------------------------------------
38 // Operators
39
40 inline
41 void assign(const typename WordType<C>::Type_t& rhs)
42 {
44 if (getOwnsMemory()) {
45 evaluate_F(getF(),OpAssign(),PETE_identity(Scalar_t(rhs)),subset());
46 } else {
47 C tmp(getF(),1.0);
48 evaluate(tmp,OpAssign(),PETE_identity(Scalar_t(rhs)),subset());
49 }
50 }
51
52 inline
53 void assign(const Zero&)
54 {
55 if (getOwnsMemory()) {
57 } else {
58 C tmp(getF(),1.0);
59 zero_rep(tmp,subset());
60 }
61 }
62
63 template<class T1,class C1>
64 inline
65 void assign(const QDPType<T1,C1>& rhs)
66 {
67 if (getOwnsMemory()) {
69 } else {
70 C tmp(getF(),1.0);
72 }
73 }
74
75
76 template<class T1,class C1>
77 inline
78 void assign(const QDPSubType<T1,C1>& rhs)
79 {
80 if (getOwnsMemory() && rhs.getOwnsMemory()) {
81 //std::cout << "own = own\n";
82 if (subset().numSiteTable() != rhs.subset().numSiteTable())
83 QDP_error_exit("assignment with incompatible subset sizes");
84 for(int j=0; j < subset().numSiteTable(); ++j)
85 getF()[j] = rhs.getF()[j];
86 } else
87
88#if 0
89 if (!getOwnsMemory() && rhs.getOwnsMemory()) {
90 //std::cout << "view = own\n";
91 if (subset().numSiteTable() != rhs.subset().numSiteTable())
92 QDP_error_exit("assignment with incompatible subset sizes");
93 const int *tab = subset().siteTable().slice();
94 for(int j=0; j < subset().numSiteTable(); ++j) {
95 int i = tab[j];
96 getF()[i] = rhs.getF()[j];
97 }
98 }
99 if (getOwnsMemory() && !rhs.getOwnsMemory()) {
100 //std::cout << "own = view\n";
101 if (subset().numSiteTable() != rhs.subset().numSiteTable())
102 QDP_error_exit("assignment with incompatible subset sizes");
103 const int *tab = rhs.subset().siteTable().slice();
104 for(int j=0; j < rhs.subset().numSiteTable(); ++j) {
105 int i = tab[j];
106 getF()[j] = rhs.getF()[i];
107 }
108 }
109 if (!getOwnsMemory() && !rhs.getOwnsMemory())
110#endif
111 QDP_error_exit("assignment of two view subtypes is not supported");
112 }
113
114
115 template<class T1,class C1>
116 inline
117 void assign(const QDPExpr<T1,C1>& rhs)
118 {
119 if (getOwnsMemory()) {
120 evaluate_F(getF(),OpAssign(),rhs,subset());
121 } else {
122 C tmp(getF(),1.0);
123 evaluate(tmp,OpAssign(),rhs,subset());
124 }
125 }
126
127 inline
128 void operator+=(const typename WordType<C>::Type_t& rhs)
129 {
130 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
131 if (getOwnsMemory()) {
132 evaluate_F(getF(),OpAddAssign(),PETE_identity(Scalar_t(rhs)),subset());
133 } else {
134 C tmp(getF(),1.0);
135 evaluate(tmp,OpAddAssign(),PETE_identity(Scalar_t(rhs)),subset());
136 }
137 }
138
139 template<class T1,class C1>
140 inline
141 void operator+=(const QDPType<T1,C1>& rhs)
142 {
143 if (getOwnsMemory()) {
145 } else {
146 C tmp(getF(),1.0);
148 }
149 }
150
151 template<class T1,class C1>
152 inline
153 void operator+=(const QDPExpr<T1,C1>& rhs)
154 {
155 if (getOwnsMemory()) {
157 } else {
158 C tmp(getF(),1.0);
159 evaluate(tmp,OpAddAssign(),rhs,subset());
160 }
161 }
162
163 inline
164 void operator-=(const typename WordType<C>::Type_t& rhs)
165 {
166 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
167 if (getOwnsMemory()) {
169 } else {
170 C tmp(getF(),1.0);
171 evaluate(tmp,OpSubtractAssign(),PETE_identity(Scalar_t(rhs)),subset());
172 }
173 }
174
175 template<class T1,class C1>
176 inline
177 void operator-=(const QDPType<T1,C1>& rhs)
178 {
179 if (getOwnsMemory()) {
181 } else {
182 C tmp(getF(),1.0);
184 }
185 }
186
187 template<class T1,class C1>
188 inline
189 void operator-=(const QDPExpr<T1,C1>& rhs)
190 {
191 if (getOwnsMemory()) {
193 } else {
194 C tmp(getF(),1.0);
195 evaluate(tmp,OpSubtractAssign(),rhs,subset());
196 }
197 }
198
199 inline
200 void operator*=(const typename WordType<C>::Type_t& rhs)
201 {
202 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
203 if (getOwnsMemory()) {
205 } else {
206 C tmp(getF(),1.0);
207 evaluate(tmp,OpMultiplyAssign(),PETE_identity(Scalar_t(rhs)),subset());
208 }
209 }
210
211 template<class T1,class C1>
212 inline
213 void operator*=(const QDPType<T1,C1>& rhs)
214 {
215 if (getOwnsMemory()) {
217 } else {
218 C tmp(getF(),1.0);
220 }
221 }
222
223 template<class T1,class C1>
224 inline
225 void operator*=(const QDPExpr<T1,C1>& rhs)
226 {
227 if (getOwnsMemory()) {
229 } else {
230 C tmp(getF(),1.0);
231 evaluate(tmp,OpMultiplyAssign(),rhs,subset());
232 }
233 }
234
235 inline
236 void operator/=(const typename WordType<C>::Type_t& rhs)
237 {
238 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
239 if (getOwnsMemory()) {
240 evaluate_F(getF(),OpDivideAssign(),PETE_identity(Scalar_t(rhs)),subset());
241 } else {
242 C tmp(getF(),1.0);
243 evaluate(tmp,OpDivideAssign(),PETE_identity(Scalar_t(rhs)),subset());
244 }
245 }
246
247 template<class T1,class C1>
248 inline
249 void operator/=(const QDPType<T1,C1>& rhs)
250 {
251 if (getOwnsMemory()) {
253 } else {
254 C tmp(getF(),1.0);
256 }
257 }
258
259 template<class T1,class C1>
260 inline
261 void operator/=(const QDPExpr<T1,C1>& rhs)
262 {
263 if (getOwnsMemory()) {
265 } else {
266 C tmp(getF(),1.0);
267 evaluate(tmp,OpDivideAssign(),rhs,subset());
268 }
269 }
270
271 inline
272 void operator%=(const typename WordType<C>::Type_t& rhs)
273 {
274 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
275 if (getOwnsMemory()) {
276 evaluate_F(getF(),OpModAssign(),PETE_identity(Scalar_t(rhs)),subset());
277 } else {
278 C tmp(getF(),1.0);
279 evaluate(tmp,OpModAssign(),PETE_identity(Scalar_t(rhs)),subset());
280 }
281 }
282
283 template<class T1,class C1>
284 inline
285 void operator%=(const QDPType<T1,C1>& rhs)
286 {
287 if (getOwnsMemory()) {
289 } else {
290 C tmp(getF(),1.0);
292 }
293 }
294
295 template<class T1,class C1>
296 inline
297 void operator%=(const QDPExpr<T1,C1>& rhs)
298 {
299 if (getOwnsMemory()) {
301 } else {
302 C tmp(getF(),1.0);
303 evaluate(tmp,OpModAssign(),rhs,subset());
304 }
305 }
306
307 inline
308 void operator|=(const typename WordType<C>::Type_t& rhs)
309 {
310 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
311 if (getOwnsMemory()) {
313 } else {
314 C tmp(getF(),1.0);
315 evaluate(tmp,OpBitwiseOrAssign(),PETE_identity(Scalar_t(rhs)),subset());
316 }
317 }
318
319 template<class T1,class C1>
320 inline
321 void operator|=(const QDPType<T1,C1>& rhs)
322 {
323 if (getOwnsMemory()) {
325 } else {
326 C tmp(getF(),1.0);
328 }
329 }
330
331 template<class T1,class C1>
332 inline
333 void operator|=(const QDPExpr<T1,C1>& rhs)
334 {
335 if (getOwnsMemory()) {
337 } else {
338 C tmp(getF(),1.0);
340 }
341 }
342
343 inline
344 void operator&=(const typename WordType<C>::Type_t& rhs)
345 {
346 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
347 if (getOwnsMemory()) {
349 } else {
350 C tmp(getF(),1.0);
351 evaluate(tmp,OpBitwiseAndAssign(),PETE_identity(Scalar_t(rhs)),subset());
352 }
353 }
354
355 template<class T1,class C1>
356 inline
357 void operator&=(const QDPType<T1,C1>& rhs)
358 {
359 if (getOwnsMemory()) {
361 } else {
362 C tmp(getF(),1.0);
364 }
365 }
366
367 template<class T1,class C1>
368 inline
369 void operator&=(const QDPExpr<T1,C1>& rhs)
370 {
371 if (getOwnsMemory()) {
373 } else {
374 C tmp(getF(),1.0);
376 }
377 }
378
379 inline
380 void operator^=(const typename WordType<C>::Type_t& rhs)
381 {
382 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
383 if (getOwnsMemory()) {
385 } else {
386 C tmp(getF(),1.0);
387 evaluate(tmp,OpBitwiseXorAssign(),PETE_identity(Scalar_t(rhs)),subset());
388 }
389 }
390
391 template<class T1,class C1>
392 inline
393 void operator^=(const QDPType<T1,C1>& rhs)
394 {
395 if (getOwnsMemory()) {
397 } else {
398 C tmp(getF(),1.0);
400 }
401 }
402
403 template<class T1,class C1>
404 inline
405 void operator^=(const QDPExpr<T1,C1>& rhs)
406 {
407 if (getOwnsMemory()) {
409 } else {
410 C tmp(getF(),1.0);
412 }
413 }
414
415 inline
416 void operator<<=(const typename WordType<C>::Type_t& rhs)
417 {
418 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
419 if (getOwnsMemory()) {
421 } else {
422 C tmp(getF(),1.0);
423 evaluate(tmp,OpLeftShiftAssign(),PETE_identity(Scalar_t(rhs)),subset());
424 }
425 }
426
427 template<class T1,class C1>
428 inline
430 {
431 if (getOwnsMemory()) {
433 } else {
434 C tmp(getF(),1.0);
436 }
437 }
438
439 template<class T1,class C1>
440 inline
442 {
443 if (getOwnsMemory()) {
445 } else {
446 C tmp(getF(),1.0);
447 evaluate(tmp,OpLeftShiftAssign(),rhs,subset());
448 }
449 }
450
451
452 inline
453 void operator>>=(const typename WordType<C>::Type_t& rhs)
454 {
455 typedef typename SimpleScalar<typename WordType<C>::Type_t>::Type_t Scalar_t;
456 if (getOwnsMemory()) {
458 } else {
459 C tmp(getF(),1.0);
460 evaluate(tmp,OpRightShiftAssign(),PETE_identity(Scalar_t(rhs)),subset());
461 }
462 }
463
464 template<class T1,class C1>
465 inline
467 {
468 if (getOwnsMemory()) {
470 } else {
471 C tmp(getF(),1.0);
473 }
474 }
475
476 template<class T1,class C1>
477 inline
479 {
480 if (getOwnsMemory()) {
482 } else {
483 C tmp(getF(),1.0);
485 }
486 }
487
488private:
490 inline
491 C& operator=(const QDPSubType& rhs) {}
492
493public:
494 //C& field() {return static_cast<CC*>(this)->field();}
495 bool getOwnsMemory() { return static_cast<CC*>(this)->getOwnsMemory(); }
496 bool getOwnsMemory() const { return static_cast<const CC*>(this)->getOwnsMemory(); }
497 T* getF() {return static_cast<CC*>(this)->getF();}
498 T* getF() const {return static_cast<CC const *>(this)->getF();}
499 const Subset& subset() const {return static_cast<const CC*>(this)->subset();}
500
501};
502
503
504} // namespace QDP
505
506#endif
507
508
509
Expression class for QDP.
Definition qdp_qdpexpr.h:16
QDPSubType - type representing a field living on a subset.
const Subset & subset() const
QDPSubType(const QDPSubType &)
Copy constructor.
void operator-=(const typename WordType< C >::Type_t &rhs)
void operator/=(const QDPExpr< T1, C1 > &rhs)
void operator+=(const typename WordType< C >::Type_t &rhs)
void assign(const QDPType< T1, C1 > &rhs)
void assign(const Zero &)
~QDPSubType()
Destructor.
void operator^=(const QDPType< T1, C1 > &rhs)
void operator&=(const QDPExpr< T1, C1 > &rhs)
void operator<<=(const QDPExpr< T1, C1 > &rhs)
void assign(const typename WordType< C >::Type_t &rhs)
void operator%=(const QDPExpr< T1, C1 > &rhs)
void operator%=(const QDPType< T1, C1 > &rhs)
QDPSubType()
Default constructor.
void operator>>=(const QDPType< T1, C1 > &rhs)
void operator^=(const typename WordType< C >::Type_t &rhs)
void operator%=(const typename WordType< C >::Type_t &rhs)
void operator<<=(const QDPType< T1, C1 > &rhs)
void assign(const QDPExpr< T1, C1 > &rhs)
void operator>>=(const QDPExpr< T1, C1 > &rhs)
void operator-=(const QDPType< T1, C1 > &rhs)
bool getOwnsMemory() const
void operator>>=(const typename WordType< C >::Type_t &rhs)
void operator*=(const typename WordType< C >::Type_t &rhs)
void operator&=(const QDPType< T1, C1 > &rhs)
void operator<<=(const typename WordType< C >::Type_t &rhs)
void assign(const QDPSubType< T1, C1 > &rhs)
void operator|=(const typename WordType< C >::Type_t &rhs)
void operator|=(const QDPExpr< T1, C1 > &rhs)
void operator+=(const QDPType< T1, C1 > &rhs)
void operator|=(const QDPType< T1, C1 > &rhs)
void operator&=(const typename WordType< C >::Type_t &rhs)
void operator/=(const typename WordType< C >::Type_t &rhs)
void operator^=(const QDPExpr< T1, C1 > &rhs)
void operator+=(const QDPExpr< T1, C1 > &rhs)
void operator*=(const QDPType< T1, C1 > &rhs)
void operator*=(const QDPExpr< T1, C1 > &rhs)
void operator-=(const QDPExpr< T1, C1 > &rhs)
void operator/=(const QDPType< T1, C1 > &rhs)
QDPType - major type class/container for all QDP objects.
Definition qdp_qdptype.h:29
Subsets - controls how lattices are looped.
Definition qdp_subset.h:39
const multi1d< int > & siteTable() const
Definition qdp_subset.h:83
int numSiteTable() const
Definition qdp_subset.h:84
const T * slice() const
Return ref to a column slice.
Definition qdp_multi.h:225
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
Yet another random number generator.
void QDP_error_exit(const char *format,...)
Simple error display and abort routine.
Definition qdp_util.cc:93
MakeReturn< UnaryNode< OpIdentity, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, OpIdentity >::Type_t >::Expression_t PETE_identity(const QDPExpr< T1, C1 > &l)
Definition qdp.h:5531
void evaluate_F(T *dest, const Op &op, const QDPExpr< RHS, OScalar< T1 > > &rhs, const Subset &s)
Definition qdp_outer.h:242
void zero_rep_F(T *dest, const Subset &s)
Construct simple word type. Default behavior is empty.
Definition qdp_traits.h:93
Simple zero tag.
Definition qdp_traits.h:122