1Types(3)              User Contributed Perl Documentation             Types(3)
2
3
4

NAME

6       PDL::Types - define fundamental PDL Datatypes
7

SYNOPSIS

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

DESCRIPTION

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

FUNCTIONS

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_B PDL_S PDL_US PDL_L PDL_IND PDL_LL PDL_F PDL_D
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        B S U L N Q F D
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
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        B S U L N Q F D G C
55
56   typefld
57       Returns specified field ($fld) for specified type ($type) by querying
58       type hash
59
60       PDL::Types::typefld($type,$fld);
61
62        pdl> print PDL::Types::typefld('PDL_IND',realctype)
63        long
64
65   mapfld
66       Map a given source field to the corresponding target field by querying
67       the type hash. This gives you a way to say, "Find the type whose
68       $in_key is equal to $value, and return that type's value for $out_key.
69       For example:
70
71        # Does byte type use nan?
72        $uses_nan = PDL::Types::mapfld(byte => 'ppforcetype', 'usenan');
73        # Equivalent:
74        $uses_nan = byte->usenan;
75
76        # What is the actual C type for the value that we call 'long'?
77        $type_name = PDL::Types::mapfld(long => 'convertfunc', 'realctype');
78        # Equivalent:
79        $type_name = long->realctype;
80
81       As you can see, the equivalent examples are much shorter and legible,
82       so you should only use mapfld if you were given the type index (in
83       which case the actual type is not immediately obvious):
84
85        $type_index = 4;
86        $type_name = PDL::Types::mapfld($type_index => numval, 'realctype');
87
88   typesynonyms
89       return type related synonym definitions to be included in pdl.h .  This
90       routine must be updated to include new types as required.  Mostly the
91       automatic updating should take care of the vital things.
92
93   datatypes_header
94       return C header text for pdl.h and pdlsimple.h.
95

PDL::Type OBJECTS

97       This module declares one class - "PDL::Type" - objects of this class
98       are returned by the type method of an ndarray.  It has several methods,
99       listed below, which provide an easy way to access type information:
100
101       Additionally, comparison and stringification are overloaded so that you
102       can compare and print type objects, e.g.
103
104         $nofloat = 1 if $pdl->type < float;
105         die "must be double" if $type != double;
106
107       For further examples check again the type method.
108
109       enum
110           Returns the number representing this datatype (see get_datatype).
111
112       symbol
113           Returns one of 'PDL_B', 'PDL_S', 'PDL_US', 'PDL_L', 'PDL_IND',
114           'PDL_LL', 'PDL_F' or 'PDL_D'.
115
116       ctype
117           Returns the macro used to represent this type in C code (eg
118           'PDL_Long').
119
120       ppsym
121           The letter used to represent this type in PP code code (eg 'U' for
122           ushort).
123
124       realctype
125           The actual C type used to store this type.
126
127       shortctype
128           The value returned by "ctype" without the 'PDL_' prefix.
129
130       badvalue
131           The special numerical value used to represent bad values for this
132           type.  See badvalue routine in PDL::Bad for more details.
133
134       isnan
135           Given a string representing a C value, will return a C expression
136           for this type that indicates whether that value is NaN.
137
138       floatsuffix
139           The string appended to floating-point functions for this floating-
140           point type. Dies if called on non-floating-point type.
141
142       orig_badvalue
143           The default special numerical value used to represent bad values
144           for this type. (You can change the value that represents bad values
145           for each type during runtime.) See the orig_badvalue routine in
146           PDL::Bad for more details.
147

Adding/removing types

149       You can change the types that PDL knows about by editing entries in the
150       definition of the variable @types that appears close to the top of the
151       file Types.pm.PL (i.e. the file from which this module was generated).
152
153   Format of a type entry
154       Each entry in the @types array is a hash reference. Here is an example
155       taken from the actual code that defines the "ushort" type:
156
157                    {
158                     identifier => 'US',
159                     onecharident => 'U',   # only needed if different from identifier
160                     pdlctype => 'PDL_Ushort',
161                     realctype => 'unsigned short',
162                     ppforcetype => 'ushort',
163                     usenan => 0,
164                     packtype => 'S*',
165                     defaultbadval => 'USHRT_MAX',
166                     real=>1,
167                     integer=>1,
168                     unsigned=>1,
169                    },
170
171       Before we start to explain the fields please take this important
172       message on board: entries must be listed in order of increasing
173       complexity. This is critical to ensure that PDL's type conversion works
174       correctly.  Basically, a less complex type will be converted to a more
175       complex type as required.
176
177   Fields in a type entry
178       Each type entry has a number of required and optional entry.
179
180       A list of all the entries:
181
182       •   identifier
183
184           Required. A short sequence of upercase letters that identifies this
185           type uniquely. More than three characters is probably overkill.
186
187       •   onecharident
188
189           Optional. Only required if the "identifier" has more than one
190           character.  This should be a unique uppercase character that will
191           be used to reference this type in PP macro expressions of the
192           "TBSULFD" type. If you don't know what I am talking about read the
193           PP manpage or ask on the mailing list.
194
195       •   pdlctype
196
197           Required. The "typedefed" name that will be used to access this
198           type from C code.
199
200       •   realctype
201
202           Required. The C compiler type that is used to implement this type.
203           For portability reasons this one might be platform dependent.
204
205       •   ppforcetype
206
207           Required. The type name used in PP signatures to refer to this
208           type.
209
210       •   usenan
211
212           Required. Flag that signals if this type has to deal with NaN
213           issues.  Generally only required for floating point types.
214
215       •   packtype
216
217           Required. The Perl pack type used to pack Perl values into the
218           machine representation for this type. For details see "perldoc -f
219           pack".
220
221       •   integer
222
223           Required. Boolean - is this an integer type?
224
225       •   unsigned
226
227           Required. Boolean - is this an unsigned type?
228
229       •   real
230
231           Required. Boolean - is this a real (not complex) type?
232
233       •   realversion
234
235           String - the real version of this type (e.g. cdouble -> 'D').
236
237       •   complexversion
238
239           String - the complex version of this type (e.g. double -> 'C').
240
241       Also have a look at the entries at the top of Types.pm.PL.
242
243       The syntax is not written into stone yet and might change as the
244       concept matures.
245
246   Other things you need to do
247       You need to check modules that do I/O (generally in the IO part of the
248       directory tree). In the future we might add fields to type entries to
249       automate this. This requires changes to those IO modules first though.
250
251       You should also make sure that any type macros in PP files (i.e.
252       "$TBSULFD...") are updated to reflect the new type. PDL::PP::Dump has a
253       mode to check for type macros requiring updating. Do something like
254
255           find . -name \*.pd -exec perl -Mblib=. -M'PDL::PP::Dump=typecheck' {} \;
256
257       from the PDL root directory after updating Types.pm.PL to check for
258       such places.
259
260
261
262perl v5.34.0                      2021-08-16                          Types(3)
Impressum