QDP++
qdp_simpleword.h
Go to the documentation of this file.
1// -*- C++ -*-
2
6
7#ifndef QDP_SIMPLEWORD_H
8#define QDP_SIMPLEWORD_H
9
10#include <cmath>
11
12namespace QDP {
13
14using std::abs;
15using std::div;
16using std::acos;
17using std::asin;
18using std::atan;
19using std::atan2;
20using std::ceil;
21using std::cos;
22using std::cosh;
23using std::exp;
24using std::fabs;
25using std::floor;
26using std::fmod;
27using std::frexp;
28using std::ldexp;
29using std::log;
30using std::log10;
31using std::modf;
32using std::pow;
33using std::sin;
34using std::sinh;
35using std::sqrt;
36using std::tan;
37using std::tanh;
38
39using std::isnan;
40using std::isinf;
41using std::isfinite;
42using std::isnormal;
43
44
54
55// All these are explicit to avoid any general template clashes
56
58inline
59void zero_rep(int& dest)
60{
61 dest = 0;
62}
63
65inline
66void zero_rep(float& dest)
67{
68 dest = 0;
69}
70
72inline
73void zero_rep(double& dest)
74{
75 dest = 0;
76}
77
79
80
82inline
83void copymask(int& d, bool mask, int s1)
84{
85 if (mask)
86 d = s1;
87}
88
90inline
91void copymask(float& d, bool mask, float s1)
92{
93 if (mask)
94 d = s1;
95}
96
98inline
99void copymask(double& d, bool mask, double s1)
100{
101 if (mask)
102 d = s1;
103}
104
105
106//---------------------------
108inline
109void cast_rep(float& d, int s1)
110{
111 d = float(s1);
112}
113
115inline
116void cast_rep(float& d, float s1)
117{
118 d = float(s1);
119}
120
122inline
123void cast_rep(float& d, double s1)
124{
125 d = float(s1);
126}
127
128
130inline
131void cast_rep(double& d, int s1)
132{
133 d = double(s1);
134}
135
137inline
138void cast_rep(double& d, float s1)
139{
140 d = double(s1);
141}
142
144inline
145void cast_rep(double& d, double s1)
146{
147 d = double(s1);
148}
149
150
151//---------------------------
153inline
154void recast_rep(float& d, int s1)
155{
156 cast_rep(d,s1);
157}
158
160inline
161void recast_rep(float& d, float s1)
162{
163 cast_rep(d,s1);
164}
165
167inline
168void recast_rep(float& d, double s1)
169{
170 cast_rep(d,s1);
171}
172
173
175inline
176void recast_rep(double& d, int s1)
177{
178 cast_rep(d,s1);
179}
180
182inline
183void recast_rep(double& d, float s1)
184{
185 cast_rep(d,s1);
186}
187
189inline
190void recast_rep(double& d, double s1)
191{
192 cast_rep(d,s1);
193}
194
195
196
197
198
199//-------------------------------------------------------
200// Functions
201
202// Conjugate
203inline
204float conj(float l)
205{
206 return l;
207}
208
209// Conjugate
210inline
211double conj(double l)
212{
213 return l;
214}
215
216// Conjugate
217inline
218int conj(int l)
219{
220 return l;
221}
222
223
224// Transpose
225inline
226float transpose(float l)
227{
228 return l;
229}
230
231// Transpose
232inline
233double transpose(double l)
234{
235 return l;
236}
237
238// Transpose
239inline
240int transpose(int l)
241{
242 return l;
243}
244
245
246
247// TRACE
248// trace = Trace(source1)
249inline
250float trace(float s1)
251{
252 return s1;
253}
254
255
256// trace = Trace(source1)
257inline
258double trace(double s1)
259{
260 return s1;
261}
262
263
264// trace = Trace(source1)
265inline
266int trace(int s1)
267{
268 return s1;
269}
270
271
272// GetSite is only non-trivial at an inner grid sit
273inline float getSite(float s1, int innersite) {return s1;}
274inline double getSite(double s1, int innersite) {return s1;}
275inline int getSite(int s1, int innersite) {return s1;}
276inline bool getSite(bool s1, int innersite) {return s1;}
277
278
279
280// int = toInt(source1)
281inline
282int toInt(int s1)
283{
284 return s1;
285}
286
287// float = toFloat(source1)
288inline
289float toFloat(float s1)
290{
291 return s1;
292}
293
294// double = toDouble(source1)
295inline
296double toDouble(double s1)
297{
298 return s1;
299}
300
301// bool = toBool(source1)
302inline
303bool toBool(bool s1)
304{
305 return s1;
306}
307
308
309// int = toWordType(<int>)
310inline
311int toWordType(int s1)
312{
313 return s1;
314}
315
316// float = toWordType(<float>)
317inline
318float toWordType(float s1)
319{
320 return s1;
321}
322
323// double = toWordType(<double>)
324inline
325double toWordType(double s1)
326{
327 return s1;
328}
329
330// bool = toWordType(<bool>)
331inline
332bool toWordType(bool s1)
333{
334 return s1;
335}
336
337
338
339// Where is the ? operator
340inline
341int where(bool a, int b, int c)
342{
343 if (a) return b; else return c;
344}
345
346inline
347float where(bool a, float b, float c)
348{
349 if (a) return b; else return c;
350}
351
352inline
353double where(bool a, double b, double c)
354{
355 if (a) return b; else return c;
356}
357
358
359
360// Global sum over site indices only
361inline
362int sum(int s1)
363{
364 return s1;
365}
366
367inline
368int localNorm2(int s1)
369{
370 return s1*s1;
371}
372
373inline
374int localInnerProduct(int s1, int s2)
375{
376 return s1*s2;
377}
378
379inline
380int localColorInnerProduct(int s1, int s2)
381{
382 return s1*s2;
383}
384
385inline
386unsigned int sum(unsigned int s1)
387{
388 return s1;
389}
390
391inline
392unsigned int localNorm2(unsigned int s1)
393{
394 return s1*s1;
395}
396
397inline
398unsigned int localInnerProduct(unsigned int s1, unsigned int s2)
399{
400 return s1*s2;
401}
402inline
403unsigned int localColorInnerProduct(unsigned int s1, unsigned int s2)
404{
405 return s1*s2;
406}
407
408inline
409double sum(float s1)
410{
411 return double(s1);
412}
413
414inline
415double localNorm2(float s1)
416{
417 return double(s1*s1);
418}
419
420inline
421double localInnerProduct(float s1, float s2)
422{
423 return double(s1*s2);
424}
425inline
426double localColorInnerProduct(float s1, float s2)
427{
428 return double(s1*s2);
429}
430
431inline
432double sum(double s1)
433{
434 return s1;
435}
436
437inline
438double localNorm2(double s1)
439{
440 return s1*s1;
441}
442
443inline
444double localInnerProduct(float s1, double s2)
445{
446 return double(s1)*s2;
447}
448
449inline
450double localColorInnerProduct(float s1, double s2)
451{
452 return double(s1)*s2;
453}
454
455inline
456double localInnerProduct(double s1, float s2)
457{
458 return s1*double(s2);
459}
460
461inline
462double localColorInnerProduct(double s1, float s2)
463{
464 return s1*double(s2);
465}
466
467inline
468double localInnerProduct(double s1, double s2)
469{
470 return s1*s2;
471}
472
473inline
474double localColorInnerProduct(double s1, double s2)
475{
476 return s1*s2;
477}
478
479
480 // end of group simpleword
482
483//-----------------------------------------------------------------------------
484// Traits classes
485//-----------------------------------------------------------------------------
486
487// Return types
488template<>
490 typedef float Type_t;
491};
492
493template<>
494struct UnaryReturn<int, FnSum> {
495 typedef int Type_t;
496};
497
498template<>
500 typedef int Type_t;
501};
502
503template<>
505 typedef int Type_t;
506};
507
508template<>
510 typedef int Type_t;
511};
512
513template<>
514struct UnaryReturn<int, FnNorm2> {
515 typedef int Type_t;
516};
517
518template<>
519struct BinaryReturn<int, int, FnInnerProduct> {
520 typedef int Type_t;
521};
522
523template<>
525 typedef int Type_t;
526};
527
528template<>
530 typedef int Type_t;
531};
532
533template<>
535 typedef int Type_t;
536};
537
538template<>
539struct TrinaryReturn<bool, int, int, FnWhere> {
540 typedef int Type_t;
541};
542
543
544template<>
545struct UnaryReturn<float, FnSum> {
546 typedef double Type_t;
547};
548
549template<>
550struct UnaryReturn<float, FnGlobalMax> {
551 typedef float Type_t;
552};
553
554template<>
555struct UnaryReturn<float, FnGlobalMin> {
556 typedef float Type_t;
557};
558
559template<>
560struct UnaryReturn<float, FnSumMulti> {
561 typedef double Type_t;
562};
563
564template<>
565struct UnaryReturn<float, FnNorm2> {
566 typedef double Type_t;
567};
568
569template<>
570struct BinaryReturn<float, float, FnInnerProduct> {
571 typedef double Type_t;
572};
573
574template<>
575struct UnaryReturn<float, FnLocalNorm2> {
576 typedef double Type_t;
577};
578
579template<>
580struct BinaryReturn<float, float, FnLocalInnerProduct> {
581 typedef double Type_t;
582};
583
584template<>
586 typedef double Type_t;
587};
588
589template<>
590struct TrinaryReturn<bool, float, float, FnWhere> {
591 typedef float Type_t;
592};
593
594
595template<>
596struct UnaryReturn<double, FnSum> {
597 typedef double Type_t;
598};
599
600template<>
601struct UnaryReturn<double, FnGlobalMax> {
602 typedef double Type_t;
603};
604
605template<>
606struct UnaryReturn<double, FnGlobalMin> {
607 typedef double Type_t;
608};
609
610template<>
611struct UnaryReturn<double, FnSumMulti> {
612 typedef double Type_t;
613};
614
615template<>
616struct UnaryReturn<double, FnNorm2> {
617 typedef double Type_t;
618};
619
620template<>
621struct BinaryReturn<double, double, FnInnerProduct> {
622 typedef double Type_t;
623};
624
625template<>
626struct UnaryReturn<double, FnLocalNorm2> {
627 typedef double Type_t;
628};
629
630template<>
631struct BinaryReturn<double, double, FnLocalInnerProduct> {
632 typedef double Type_t;
633};
634
635template<>
636struct BinaryReturn<double, double, FnLocalColorInnerProduct> {
637 typedef double Type_t;
638};
639
640template<>
641struct TrinaryReturn<bool, double, double, FnWhere> {
642 typedef double Type_t;
643};
644
645
646
647template<>
648struct BinaryReturn<int, int, OpAssign> {
649 typedef int Type_t;
650};
651
652template<>
653struct BinaryReturn<int, int, OpAddAssign> {
654 typedef int Type_t;
655};
656
657template<>
659 typedef int Type_t;
660};
661
662template<>
664 typedef int Type_t;
665};
666
667template<>
668struct BinaryReturn<int, int, OpDivideAssign> {
669 typedef int Type_t;
670};
671
672template<>
673struct BinaryReturn<int, int, OpModAssign> {
674 typedef int Type_t;
675};
676
677template<>
679 typedef int Type_t;
680};
681
682template<>
684 typedef int Type_t;
685};
686
687template<>
689 typedef int Type_t;
690};
691
692template<>
694 typedef int Type_t;
695};
696
697template<>
699 typedef int Type_t;
700};
701
702
703template<>
704struct BinaryReturn<float, float, OpAssign> {
705 typedef float Type_t;
706};
707
708template<>
709struct BinaryReturn<float, float, OpAddAssign> {
710 typedef float Type_t;
711};
712
713template<>
714struct BinaryReturn<float, float, OpSubtractAssign> {
715 typedef float Type_t;
716};
717
718template<>
719struct BinaryReturn<float, float, OpMultiplyAssign> {
720 typedef float Type_t;
721};
722
723template<>
724struct BinaryReturn<float, float, OpDivideAssign> {
725 typedef float Type_t;
726};
727
728template<>
729struct BinaryReturn<float, float, OpModAssign> {
730 typedef float Type_t;
731};
732
733template<>
734struct BinaryReturn<float, float, OpBitwiseOrAssign> {
735 typedef float Type_t;
736};
737
738template<>
739struct BinaryReturn<float, float, OpBitwiseAndAssign> {
740 typedef float Type_t;
741};
742
743template<>
744struct BinaryReturn<float, float, OpBitwiseXorAssign> {
745 typedef float Type_t;
746};
747
748template<>
749struct BinaryReturn<float, float, OpLeftShiftAssign> {
750 typedef float Type_t;
751};
752
753template<>
754struct BinaryReturn<float, float, OpRightShiftAssign> {
755 typedef float Type_t;
756};
757
758
759template<>
760struct BinaryReturn<double, double, OpAssign> {
761 typedef double Type_t;
762};
763
764template<>
765struct BinaryReturn<double, double, OpAddAssign> {
766 typedef double Type_t;
767};
768
769template<>
770struct BinaryReturn<double, double, OpSubtractAssign> {
771 typedef double Type_t;
772};
773
774template<>
775struct BinaryReturn<double, double, OpMultiplyAssign> {
776 typedef double Type_t;
777};
778
779template<>
780struct BinaryReturn<double, double, OpDivideAssign> {
781 typedef double Type_t;
782};
783
784template<>
785struct BinaryReturn<double, double, OpModAssign> {
786 typedef double Type_t;
787};
788
789template<>
790struct BinaryReturn<double, double, OpBitwiseOrAssign> {
791 typedef double Type_t;
792};
793
794template<>
795struct BinaryReturn<double, double, OpBitwiseAndAssign> {
796 typedef double Type_t;
797};
798
799template<>
800struct BinaryReturn<double, double, OpBitwiseXorAssign> {
801 typedef double Type_t;
802};
803
804template<>
805struct BinaryReturn<double, double, OpLeftShiftAssign> {
806 typedef double Type_t;
807};
808
809template<>
810struct BinaryReturn<double, double, OpRightShiftAssign> {
811 typedef double Type_t;
812};
813
814
815template<>
816struct BinaryReturn<bool, bool, OpAssign> {
817 typedef bool Type_t;
818};
819
820
821
822template<>
823struct TrinaryReturn<float, float, float, FnColorContract> {
824 typedef float Type_t;
825};
826
827} // namespace QDP
828
829#endif
UnaryReturn< C, FnSum >::Type_t sum(const QDPType< T, C > &s1)
OScalar = sum(source).
int toInt(const IScalar< T > &s)
QDP Int to int primitive in conversion routine.
Definition qdp_inner.h:1615
WordType< IScalar< T > > toWordType(const IScalar< T > &s)
QDP Wordtype to primitive wordtype.
Definition qdp_inner.h:1647
void zero_rep(IScalar< T > &dest)
dest = 0
Definition qdp_inner.h:1841
void copymask(IScalar< T > &d, const IScalar< T1 > &mask, const IScalar< T > &s1)
dest = (mask) ? s1 : dest
Definition qdp_inner.h:1656
double toDouble(const IScalar< T > &s)
QDP Double to double primitive in conversion routine.
Definition qdp_inner.h:1631
bool toBool(const IScalar< T > &s)
QDP Boolean to bool primitive in conversion routine.
Definition qdp_inner.h:1639
void cast_rep(T &d, const IScalar< T1 > &s1)
dest [float type] = source [int type]
Definition qdp_inner.h:1664
void recast_rep(IScalar< T > &d, const IScalar< T1 > &s1)
dest [float type] = source [int type]
Definition qdp_inner.h:1673
UnaryReturn< IScalar< T >, FnGetSite >::Type_t getSite(const IScalar< T > &s1, int innersite)
Definition qdp_inner.h:1605
float toFloat(const IScalar< T > &s)
QDP Real to float primitive in conversion routine.
Definition qdp_inner.h:1623
Yet another random number generator.
MakeReturn< TrinaryNode< FnWhere, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPType< T2, C2 > >::Leaf_t, typenameCreateLeaf< typenameSimpleScalar< typenameWordType< C1 >::Type_t >::Type_t >::Leaf_t >, typenameTrinaryReturn< C1, C2, typenameSimpleScalar< typenameWordType< C1 >::Type_t >::Type_t, FnWhere >::Type_t >::Expression_t where(const QDPType< T1, C1 > &a, const QDPType< T2, C2 > &b, const typename WordType< C1 >::Type_t &c)
Definition qdp.h:4576
MakeReturn< UnaryNode< FnTrace, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnTrace >::Type_t >::Expression_t trace(const QDPExpr< T1, C1 > &l)
Definition qdp.h:4907
MakeReturn< UnaryNode< FnConjugate, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnConjugate >::Type_t >::Expression_t conj(const QDPExpr< T1, C1 > &l)
Definition qdp.h:4855
MakeReturn< BinaryNode< FnLocalColorInnerProduct, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPExpr< T2, C2 > >::Leaf_t >, typenameBinaryReturn< C1, C2, FnLocalColorInnerProduct >::Type_t >::Expression_t localColorInnerProduct(const QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r)
Definition qdp.h:2444
MakeReturn< BinaryNode< FnLocalInnerProduct, typenameCreateLeaf< QDPType< T1, C1 > >::Leaf_t, typenameCreateLeaf< QDPExpr< T2, C2 > >::Leaf_t >, typenameBinaryReturn< C1, C2, FnLocalInnerProduct >::Type_t >::Expression_t localInnerProduct(const QDPType< T1, C1 > &l, const QDPExpr< T2, C2 > &r)
Definition qdp.h:2412
MakeReturn< UnaryNode< FnTranspose, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnTranspose >::Type_t >::Expression_t transpose(const QDPExpr< T1, C1 > &l)
Definition qdp.h:4868
MakeReturn< UnaryNode< FnLocalNorm2, typenameCreateLeaf< QDPExpr< T1, C1 > >::Leaf_t >, typenameUnaryReturn< C1, FnLocalNorm2 >::Type_t >::Expression_t localNorm2(const QDPExpr< T1, C1 > &l)
Definition qdp.h:4998