QDP++
qdp_specializations.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// QDP data parallel interface
4//
5
6#ifndef QDP_SPECIALIZATIONS_H
7#define QDP_SPECIALIZATIONS_H
8
9namespace QDP {
10
11
12//
13// Conversion routines. These cannot be implicit conversion functions
14// since they foul up the PETE defs in QDPOperators.h using primitive
15// types
16//
17
19inline int
20toInt(const Integer& s)
21{
22 return toInt(s.elem());
23}
24
26inline float
27toFloat(const Real32& s)
28{
29 return toFloat(s.elem());
30}
31
33inline double
34toDouble(const Real64& s)
35{
36 return toDouble(s.elem());
37}
38
40inline bool
41toBool(const Boolean& s)
42{
43 return toBool(s.elem());
44}
45
46#ifdef QDP_USE_LIBXML2
47// XML readers
48template<>
49void read(XMLReader& xml, const std::string& s, multi1d<Integer>& d);
50template<>
51void read(XMLReader& xml, const std::string& s, multi1d<Real32>& d);
52template<>
53void read(XMLReader& xml, const std::string& s, multi1d<Real64>& d);
54template<>
55void read(XMLReader& xml, const std::string& s, multi1d<Boolean>& d);
56
57template<>
58void read(XMLReader& xml, const std::string& s, std::vector<Integer>& d);
59template<>
60void read(XMLReader& xml, const std::string& s, std::vector<Real32>& d);
61template<>
62void read(XMLReader& xml, const std::string& s, std::vector<Real64>& d);
63template<>
64void read(XMLReader& xml, const std::string& s, std::vector<Boolean>& d);
65
66template<>
67void read(XMLReader& xml, const std::string& s, std::list<Integer>& d);
68template<>
69void read(XMLReader& xml, const std::string& s, std::list<Real32>& d);
70template<>
71void read(XMLReader& xml, const std::string& s, std::list<Real64>& d);
72template<>
73void read(XMLReader& xml, const std::string& s, std::list<Boolean>& d);
74
75// XML writers
76template<>
77void write(XMLWriter& xml, const std::string& s, const multi1d<Integer>& d);
78template<>
79void write(XMLWriter& xml, const std::string& s, const multi1d<Real32>& d);
80template<>
81void write(XMLWriter& xml, const std::string& s, const multi1d<Real64>& d);
82template<>
83void write(XMLWriter& xml, const std::string& s, const multi1d<Boolean>& d);
84
85template<>
86void write(XMLWriter& xml, const std::string& s, const std::vector<Integer>& d);
87template<>
88void write(XMLWriter& xml, const std::string& s, const std::vector<Real32>& d);
89template<>
90void write(XMLWriter& xml, const std::string& s, const std::vector<Real64>& d);
91template<>
92void write(XMLWriter& xml, const std::string& s, const std::vector<Boolean>& d);
93
94template<>
95void write(XMLWriter& xml, const std::string& s, const std::list<Integer>& d);
96template<>
97void write(XMLWriter& xml, const std::string& s, const std::list<Real32>& d);
98template<>
99void write(XMLWriter& xml, const std::string& s, const std::list<Real64>& d);
100template<>
101void write(XMLWriter& xml, const std::string& s, const std::list<Boolean>& d);
102
103#endif
104
105//
106// Return an equivalent QDP type given some simple machine type
107//
108template<>
109struct SimpleScalar<float>
110{
111 typedef Real32 Type_t;
112};
113
114// Construct simple float word
115template<>
116struct SimpleScalar<int>
117{
119};
120
121// Construct simple double word
122template<>
123struct SimpleScalar<double>
124{
125 typedef Real64 Type_t;
126};
127
128// Construct simple boolean word
129template<>
130struct SimpleScalar<bool>
131{
133};
134
135
136//
137// Type constructors for QDP types within the type system. Namely,
138// at some level like a primitive, sometimes scalar temporaries are needed
139// These are the bottom most constructors given a machine type
140//
141// Construct simple word
142template<>
143struct InternalScalar<float>
144{
145 typedef float Type_t;
146};
147
148template<>
149struct InternalScalar<int>
150{
151 typedef int Type_t;
152};
153
154template<>
155struct InternalScalar<double>
156{
157 typedef double Type_t;
158};
159
160template<>
161struct InternalScalar<bool>
162{
163 typedef bool Type_t;
164};
165
166
167// Makes a primitive scalar leaving grid alone
168template<>
169struct PrimitiveScalar<float>
170{
171 typedef float Type_t;
172};
173
174template<>
176{
177 typedef int Type_t;
178};
179
180template<>
181struct PrimitiveScalar<double>
182{
183 typedef double Type_t;
184};
185
186template<>
187struct PrimitiveScalar<bool>
188{
189 typedef bool Type_t;
190};
191
192
193
194// Makes a lattice scalar leaving primitive indices alone
195template<>
196struct LatticeScalar<float>
197{
198 typedef float Type_t;
199};
200
201template<>
202struct LatticeScalar<int>
203{
204 typedef int Type_t;
205};
206
207template<>
208struct LatticeScalar<double>
209{
210 typedef double Type_t;
211};
212
213template<>
214struct LatticeScalar<bool>
215{
216 typedef bool Type_t;
217};
218
219
220
221// Internally used real scalars
222template<>
223struct RealScalar<int> {
224 typedef REAL32 Type_t;
225};
226
227template<>
228struct RealScalar<float> {
229 typedef REAL32 Type_t;
230};
231
232template<>
233struct RealScalar<double> {
234 typedef REAL64 Type_t;
235};
236
237
238
239//
240// Leaf constructors for simple machine types. These are a specialization over the
241// default constructors. The point is to avoid wrapping the simple types in
242// references which do not help much (primitive objects are word size!),
243// but get in the way of type computations.
244//
245template<>
246struct CreateLeaf<int>
247{
248 typedef int Inp_t;
250 inline static
251 Leaf_t make(const Inp_t &a) { return Leaf_t(a); }
252};
253
254template<>
255struct CreateLeaf<float>
256{
257 typedef float Inp_t;
258 typedef Real32 Leaf_t;
259 inline static
260 Leaf_t make(const Inp_t &a) { return Leaf_t(a); }
261};
262
263template<>
264struct CreateLeaf<double>
265{
266 typedef double Inp_t;
267 typedef Real64 Leaf_t;
268 inline static
269 Leaf_t make(const Inp_t &a) { return Leaf_t(a); }
270};
271
272template<>
273struct CreateLeaf<bool>
274{
275 typedef bool Inp_t;
277 inline static
278 Leaf_t make(const Inp_t &a) { return Leaf_t(a); }
279};
280
281
282template<>
284{
286 inline static
287 Leaf_t make(const OScalar<IntReal32> &a) { return Leaf_t(a); }
288};
289
290template<>
292{
294 inline static
295 Leaf_t make(const OScalar<IntReal64> &a) { return Leaf_t(a); }
296};
297
298template<>
300{
302 inline static
303 Leaf_t make(const OScalar<IntInteger> &a) { return Leaf_t(a); }
304};
305
306
307template<>
309{
311 inline static
312 Leaf_t make(const OScalar<IntBoolean> &a) { return Leaf_t(a); }
313};
314
315
316} // namespace QDP
317
318#endif
Outer grid Scalar class *‍/.
Definition qdp_outer.h:37
Real32 word class - builtin machine word type over flow.
Definition qdp_word.h:50
Real64 word class - wrapper over builtin double type.
Definition qdp_word.h:81
T & elem()
Definition qdp_word.h:35
OScalar< PScalar< PScalar< RScalar< LOGICAL > > > > Boolean
OScalar< PScalar< PScalar< RScalar< INTEGER32 > > > > Integer
PScalar< PScalar< RScalar< REAL32 > > > IntReal32
PScalar< PScalar< RScalar< INTEGER32 > > > IntInteger
PScalar< PScalar< RScalar< LOGICAL > > > IntBoolean
PScalar< PScalar< RScalar< REAL64 > > > IntReal64
double REAL64
void write(BinaryWriter &bin, const std::string &output)
Definition qdp_io.cc:1204
void read(BinaryReader &bin, std::string &input, size_t maxBytes)
Definition qdp_io.cc:778
int toInt(const IScalar< T > &s)
QDP Int to int primitive in conversion routine.
Definition qdp_inner.h:1615
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
float toFloat(const IScalar< T > &s)
QDP Real to float primitive in conversion routine.
Definition qdp_inner.h:1623
Yet another random number generator.
static Leaf_t make(const OScalar< IntBoolean > &a)
static Leaf_t make(const OScalar< IntInteger > &a)
static Leaf_t make(const OScalar< IntReal32 > &a)
static Leaf_t make(const OScalar< IntReal64 > &a)
static Leaf_t make(const Inp_t &a)
static Leaf_t make(const Inp_t &a)
static Leaf_t make(const Inp_t &a)
static Leaf_t make(const Inp_t &a)
Scalar< T > Leaf_t
Definition qdp.h:97
Construct simple word type used at some level within primitives.
Definition qdp_traits.h:98
Makes a lattice scalar leaving primitive indices alone.
Definition qdp_traits.h:108
Makes a primitive scalar leaving grid alone.
Definition qdp_traits.h:103
Construct simple word type used at some level within primitives.
Definition qdp_traits.h:113
Construct simple word type. Default behavior is empty.
Definition qdp_traits.h:93