1Types(3) User Contributed Perl Documentation Types(3)
2
3
4
6 PDL::Types - define fundamental PDL Datatypes
7
9 use PDL::Types;
10
11 $pdl = ushort( 2.0, 3.0 );
12 print "The actual c type used to store ushort's is '" .
13 $pdl->type->realctype() . "'\n";
14 The actual c type used to store ushort's is 'unsigned short'
15
17 Internal module - holds all the PDL Type info. The type info can be
18 accessed easily using the "PDL::Type" object returned by the type
19 method as shown in the synopsis.
20
21 Skip to the end of this document to find out how to change the set of
22 types supported by PDL.
23
25 A number of functions are available for module writers to get/process
26 type information. These are used in various places (e.g. "PDL::PP",
27 "PDL::Core") to generate the appropriate type loops, etc.
28
29 typesrtkeys
30 Returns an array of keys of typehash sorted in order of type complexity
31
32 pdl> @typelist = PDL::Types::typesrtkeys;
33 pdl> print @typelist;
34 PDL_SB PDL_B PDL_S PDL_US PDL_L PDL_UL PDL_IND PDL_ULL PDL_LL PDL_F PDL_D PDL_LD PDL_CF PDL_CD PDL_CLD
35
36 ppdefs
37 Returns an array of pp symbols for all real types. This informs the
38 default "GenericTypes" for "pp_def" functions, making support for
39 complex types require an "opt-in".
40
41 pdl> print PDL::Types::ppdefs
42 A B S U L K N P Q F D E
43
44 ppdefs_complex
45 Returns an array of pp symbols for all complex types.
46
47 pdl> print PDL::Types::ppdefs_complex
48 G C H
49
50 ppdefs_all
51 Returns an array of pp symbols for all types including complex.
52
53 pdl> print PDL::Types::ppdefs_all
54 A B S U L K N P Q F D E G C H
55
56 typesynonyms
57 return type related synonym definitions to be included in pdl.h . This
58 routine must be updated to include new types as required. Mostly the
59 automatic updating should take care of the vital things.
60
62 As of 2.065, PDL supports these types:
63
64 SByte
65 Signed 8-bit value.
66
67 Byte
68 Unsigned 8-bit value.
69
70 Short
71 Signed 16-bit value.
72
73 UShort
74 Unsigned 16-bit value.
75
76 Long
77 Signed 32-bit value.
78
79 ULong
80 Unsigned 32-bit value.
81
82 Indx
83 Signed value, same size as a pointer on the system in use.
84
85 ULongLong
86 Unsigned 64-bit value.
87
88 LongLong
89 Signed 64-bit value.
90
91 Float
92 IEEE 754 <https://en.wikipedia.org/wiki/IEEE_754> single-precision
93 real floating-point value.
94
95 Double
96 IEEE 754 double-precision real value.
97
98 LDouble
99 A C99 "long double", defined as "at least as precise as a double",
100 but often more precise.
101
102 CFloat
103 A C99 complex single-precision floating-point value.
104
105 CDouble
106 A C99 complex double-precision floating-point value.
107
108 CLDouble
109 A C99 complex "long double" - see above for description.
110
112 This module declares one class - "PDL::Type" - objects of this class
113 are returned by the type method of an ndarray. It has several methods,
114 listed below, which provide an easy way to access type information:
115
116 Additionally, comparison and stringification are overloaded so that you
117 can compare and print type objects, e.g.
118
119 $nofloat = 1 if $pdl->type < float;
120 die "must be double" if $type != double;
121
122 For further examples check again the type method.
123
124 enum
125 Returns the number representing this datatype (see get_datatype).
126
127 symbol
128 Returns one of 'PDL_SB', 'PDL_B', 'PDL_S', 'PDL_US', 'PDL_L',
129 'PDL_UL', 'PDL_IND', 'PDL_ULL', 'PDL_LL', 'PDL_F', 'PDL_D',
130 'PDL_LD', 'PDL_CF', 'PDL_CD', or 'PDL_CLD'.
131
132 ctype
133 Returns the macro used to represent this type in C code (eg
134 'PDL_Long').
135
136 convertfunc
137 Synonym for "ctype".
138
139 ppsym
140 The letter used to represent this type in PP code (eg 'U' for
141 ushort).
142
143 realctype
144 The actual C type used to store this type.
145
146 shortctype
147 The value returned by "ctype" without the 'PDL_' prefix.
148
149 badvalue
150 The special numerical value used to represent bad values for this
151 type. See "badvalue" in PDL::Bad for more details.
152
153 isnan
154 Given a string representing a C value, will return a C expression
155 for this type that indicates whether that value is NaN (for complex
156 values, if either is NaN).
157
158 isfinite
159 Given a string representing a C value, will return a C expression
160 for this type that indicates whether that value is finite (for
161 complex values, if both are finite).
162
163 floatsuffix
164 The string appended to floating-point functions for this floating-
165 point type. Dies if called on non-floating-point type.
166
167 orig_badvalue
168 The default special numerical value used to represent bad values
169 for this type. (You can change the value that represents bad values
170 for each type during runtime.) See the orig_badvalue routine in
171 PDL::Bad for more details.
172
173 bswap
174 Returns the appropriate "bswap*" from PDL::IO::Misc for the size of
175 this type, including a no-op for types of size 1. Note this means a
176 one-line construction means you must call the return value:
177
178 $pdl->type->bswap->($pdl);
179
180 real
181 Returns whether the type is real-only (true) or can hold complex
182 values (false).
183
184 die "Real data only!" if !$pdl->type->real;
185
186 unsigned
187 Returns whether the type can hold signed values (false) or not
188 (true).
189
190 integer
191 Returns whether the type can hold non-integer, a.k.a. floating-
192 point, values (false) or not (true).
193
195 You can change the types that PDL knows about by editing entries in the
196 definition of the variable @types that appears close to the top of the
197 file Types.pm.PL (i.e. the file from which this module was generated).
198
199 Format of a type entry
200 Each entry in the @types array is a hash reference. Here is an example
201 taken from the actual code that defines the "ushort" type:
202
203 {
204 identifier => 'US',
205 onecharident => 'U', # only needed if different from identifier
206 pdlctype => 'PDL_Ushort',
207 realctype => 'unsigned short',
208 ppforcetype => 'ushort',
209 usenan => 0,
210 packtype => 'S*',
211 defaultbadval => 'USHRT_MAX',
212 real=>1,
213 integer=>1,
214 unsigned=>1,
215 },
216
217 Before we start to explain the fields please take this important
218 message on board: entries must be listed in order of increasing
219 complexity. This is critical to ensure that PDL's type conversion works
220 correctly. Basically, a less complex type will be converted to a more
221 complex type as required.
222
223 Fields in a type entry
224 Each type entry has a number of required and optional entry.
225
226 A list of all the entries:
227
228 • identifier
229
230 Required. A short sequence of uppercase letters that identifies
231 this type uniquely. More than three characters is probably
232 overkill.
233
234 • onecharident
235
236 Optional. Only required if the "identifier" has more than one
237 character. This should be a unique uppercase character that will
238 be used to reference this type in PP macro expressions of the
239 "TBSULFD" type - see "$T" in PDL::PP.
240
241 • pdlctype
242
243 Required. The "typedef"ed name that will be used to access this
244 type from C code.
245
246 • realctype
247
248 Required. The C compiler type that is used to implement this type.
249 For portability reasons this one might be platform dependent.
250
251 • ppforcetype
252
253 Required. The type name used in PP signatures to refer to this
254 type.
255
256 • usenan
257
258 Required. Flag that signals if this type has to deal with NaN
259 issues. Generally only required for floating point types.
260
261 • packtype
262
263 Required. The Perl pack type used to pack Perl values into the
264 machine representation for this type. For details see "perldoc -f
265 pack".
266
267 • integer
268
269 Required. Boolean - is this an integer type?
270
271 • unsigned
272
273 Required. Boolean - is this an unsigned type?
274
275 • real
276
277 Required. Boolean - is this a real (not complex) type?
278
279 • realversion
280
281 String - the real version of this type (e.g. cdouble -> 'D').
282
283 • complexversion
284
285 String - the complex version of this type (e.g. double -> 'C').
286
287 Also have a look at the entries at the top of Types.pm.PL.
288
289 The syntax is not written into stone yet and might change as the
290 concept matures.
291
292 Other things you need to do
293 You need to check modules that do I/O (generally in the IO part of the
294 directory tree). In the future we might add fields to type entries to
295 automate this. This requires changes to those IO modules first though.
296
297 You should also make sure that any type macros in PP files (i.e.
298 "$TBSULFD...") are updated to reflect the new type. PDL::PP::Dump has a
299 mode to check for type macros requiring updating. Do something like
300
301 find . -name \*.pd -exec perl -Mblib=. -M'PDL::PP::Dump=typecheck' {} \;
302
303 from the PDL root directory after updating Types.pm.PL to check for
304 such places.
305
306
307
308perl v5.38.0 2023-07-21 Types(3)