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

PDL::Type OBJECTS

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

Adding/removing types

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