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

Support 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       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 (in_value, in_key, out_key)
40       Map a given source field to the corresponding target field by querying
41       the type hash. This gives you a way to say, "Find the type whose
42       $in_key is equal to $value, and return that type's value for $out_key.
43       For example:
44
45        # Does byte type use nan?
46        $uses_nan = PDL::Types::mapfld(byte => 'ppforcetype', 'usenan');
47        # Equivalent:
48        $uses_nan = byte->usenan;
49
50        # What is the actual C type for the value that we call 'long'?
51        $type_name = PDL::Types::mapfld(long => 'convertfunc', 'realctype');
52        # Equivalent:
53        $type_name = long->realctype;
54
55       As you can see, the equivalent examples are much shorter and legible,
56       so you should only use mapfld if you were given the type index (in
57       which case the actual type is not immediately obvious):
58
59        $type_index = 4;
60        $type_name = PDL::Types::mapfld($type_index => numval, 'realctype');
61
62   typesynonyms
63       return type related synonym definitions to be included in pdl.h .  This
64       routine must be updated to include new types as required.  Mostly the
65       automatic updating should take care of the vital things.
66
67   datatypes_header
68       return C header text for pdl.h and pdlsimple.h.
69

PDL::Type OBJECTS

71       This module declares one class - "PDL::Type" - objects of this class
72       are returned by the type method of a piddle.  It has several methods,
73       listed below, which provide an easy way to access type information:
74
75       Additionally, comparison and stringification are overloaded so that you
76       can compare and print type objects, e.g.
77
78         $nofloat = 1 if $pdl->type < float;
79         die "must be double" if $type != double;
80
81       For further examples check again the type method.
82
83       enum
84           Returns the number representing this datatype (see get_datatype).
85
86       symbol
87           Returns one of 'PDL_B', 'PDL_S', 'PDL_US', 'PDL_L', 'PDL_IND',
88           'PDL_LL', 'PDL_F' or 'PDL_D'.
89
90       ctype
91           Returns the macro used to represent this type in C code (eg
92           'PDL_Long').
93
94       ppsym
95           The letter used to represent this type in PP code code (eg 'U' for
96           ushort).
97
98       realctype
99           The actual C type used to store this type.
100
101       shortctype
102           The value returned by "ctype" without the 'PDL_' prefix.
103
104       badvalue
105           The special numerical value used to represent bad values for this
106           type.  See badvalue routine in PDL::Bad for more details.
107
108       orig_badvalue
109           The default special numerical value used to represent bad values
110           for this type. (You can change the value that represents bad values
111           for each type during runtime.) See the orig_badvalue routine in
112           PDL::Bad for more details.
113

Adding/removing types

115       You can change the types that PDL knows about by editing entries in the
116       definition of the variable @types that appears close to the top of the
117       file Types.pm.PL (i.e. the file from which this module was generated).
118
119   Format of a type entry
120       Each entry in the @types array is a hash reference. Here is an example
121       taken from the actual code that defines the "ushort" type:
122
123                    {
124                     identifier => 'US',
125                     onecharident => 'U',   # only needed if different from identifier
126                     pdlctype => 'PDL_Ushort',
127                     realctype => 'unsigned short',
128                     ppforcetype => 'ushort',
129                     usenan => 0,
130                     packtype => 'S*',
131                    },
132
133       Before we start to explain the fields please take this important
134       message on board: entries must be listed in order of increasing
135       complexity. This is critical to ensure that PDL's type conversion works
136       correctly.  Basically, a less complex type will be converted to a more
137       complex type as required.
138
139   Fields in a type entry
140       Each type entry has a number of required and optional entry.
141
142       A list of all the entries:
143
144       ·   identifier
145
146           Required. A short sequence of upercase letters that identifies this
147           type uniquely. More than three characters is probably overkill.
148
149       ·   onecharident
150
151           Optional. Only required if the "identifier" has more than one
152           character.  This should be a unique uppercase character that will
153           be used to reference this type in PP macro expressions of the
154           "TBSULFD" type. If you don't know what I am talking about read the
155           PP manpage or ask on the mailing list.
156
157       ·   pdlctype
158
159           Required. The "typedefed" name that will be used to access this
160           type from C code.
161
162       ·   realctype
163
164           Required. The C compiler type that is used to implement this type.
165           For portability reasons this one might be platform dependent.
166
167       ·   ppforcetype
168
169           Required. The type name used in PP signatures to refer to this
170           type.
171
172       ·   usenan
173
174           Required. Flag that signals if this type has to deal with NaN
175           issues.  Generally only required for floating point types.
176
177       ·   packtype
178
179           Required. The Perl pack type used to pack Perl values into the
180           machine representation for this type. For details see "perldoc -f
181           pack".
182
183       Also have a look at the entries at the top of Types.pm.PL.
184
185       The syntax is not written into stone yet and might change as the
186       concept matures.
187
188   Other things you need to do
189       You need to check modules that do I/O (generally in the IO part of the
190       directory tree). In the future we might add fields to type entries to
191       automate this. This requires changes to those IO modules first though.
192
193       You should also make sure that any type macros in PP files (i.e.
194       "$TBSULFD...") are updated to reflect the new type. PDL::PP::Dump has a
195       mode to check for type macros requiring updating. Do something like
196
197           find . -name \*.pd -exec perl -Mblib=. -M'PDL::PP::Dump=typecheck' {} \;
198
199       from the PDL root directory after updating Types.pm.PL to check for
200       such places.
201
202
203
204perl v5.28.0                      2018-07-23                          Types(3)
Impressum