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.
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 return array of keys of typehash sorted in order of type complexity
31
32 ppdefs
33 return array of pp symbols for all known types
34
35 typefld
36 return specified field ($fld) for specified type ($type) by querying
37 type hash
38
39 mapfld
40 map a given source field to the corresponding target field by querying
41 the type hash
42
43 typesynonyms
44 return type related synonym definitions to be included in pdl.h . This
45 routine must be updated to include new types as required. Mostly the
46 automatic updating should take care of the vital things.
47
49 This module declares one class - "PDL::Type" - objects of this class
50 are returned by the type method of a piddle. It has several methods,
51 listed below, which provide an easy way to access type information:
52
53 Additionally, comparison and stringification are overloaded so that you
54 can compare and print type objects, e.g.
55
56 $nofloat = 1 if $pdl->type < float;
57 die "must be double" if $type != double;
58
59 For further examples check again the type method.
60
61 enum
62 Returns the number representing this datatype (see get_datatype).
63
64 symbol
65 Returns one of 'PDL_B', 'PDL_S', 'PDL_US', 'PDL_L', 'PDL_LL',
66 'PDL_F' or 'PDL_D'.
67
68 ctype
69 Returns the macro used to represent this type in C code (eg
70 'PDL_Long').
71
72 ppsym
73 The letter used to represent this type in PP code code (eg 'U' for
74 ushort).
75
76 realctype
77 The actual C type used to store this type.
78
79 shortctype
80 The value returned by "ctype" without the 'PDL_' prefix.
81
82 badvalue
83 Returns the value used to indicate a missing (or bad) element for
84 the given data type. See the badvalue routine in PDL::Bad for more
85 details.
86
87 orig_badvalue
88 Returns the original value used to represent bad values for a given
89 type. See the orig_badvalue routine in PDL::Bad for more details.
90
92 You can change the types that PDL knows about by editing entries in the
93 definition of the variable @types that appears close to the top of the
94 file Types.pm.PL (i.e. the file from which this module was generated).
95
96 Format of a type entry
97 Each entry in the @types array is a hash reference. Here is an example
98 taken from the actual code that defines the "ushort" type:
99
100 {
101 identifier => 'US',
102 onecharident => 'U', # only needed if different from identifier
103 pdlctype => 'PDL_Ushort',
104 realctype => 'unsigned short',
105 ppforcetype => 'ushort',
106 usenan => 0,
107 packtype => 'S*',
108 },
109
110 Before we start to explain the fields please take this important
111 message on board: entries must be listed in order of increasing
112 complexity. This is critical to ensure that PDL"s type conversion works
113 correctly. Basically, a less complex type will be converted to a more
114 complex type as required.
115
116 Fields in a type entry
117 Each type entry has a number of required and optional entry.
118
119 A list of all the entries:
120
121 · identifier
122
123 Required. A short sequence of upercase letters that identifies this
124 type uniquely. More than three characters is probably overkill.
125
126 · onecharident
127
128 Optional. Only required if the "identifier" has more than one
129 character. This should be a unique uppercase character that will
130 be used to reference this type in PP macro expressions of the
131 "TBSULFD" type. If you don't know what I am talking about read the
132 PP manpage or ask on the mailing list.
133
134 · pdlctype
135
136 Required. The "typedefed" name that will be used to access this
137 type from C code.
138
139 · realctype
140
141 Required. The C compiler type that is used to implement this type.
142 For portability reasons this one might be platform dependent.
143
144 · ppforcetype
145
146 Required. The type name used in PP signatures to refer to this
147 type.
148
149 · usenan
150
151 Required. Flag that signals if this type has to deal with NaN
152 issues. Generally only required for floating point types.
153
154 · packtype
155
156 Required. The Perl pack type used to pack Perl values into the
157 machine representation for this type. For details see "perldoc -f
158 pack".
159
160 Also have a look at the entries at the top of Types.pm.PL.
161
162 The syntax is not written into stone yet and might change as the
163 concept matures.
164
165 Other things you need to do
166 You need to check modules that do I/O (generally in the IO part of the
167 directory tree). In the future we might add fields to type entries to
168 automate this. This requires changes to those IO modules first though.
169
170 You should also make sure that any type macros in PP files (i.e.
171 "$TBSULFD...") are updated to reflect the new type. PDL::PP::Dump has a
172 mode to check for type macros requiring updating. Do something like
173
174 find . -name \*.pd -exec perl -Mblib=. -M'PDL::PP::Dump=typecheck' {} \;
175
176 from the PDL root directory after updating Types.pm.PL to check for
177 such places.
178
179
180
181perl v5.12.3 2011-03-31 Types(3)