.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Types 3pm" .TH Types 3pm "2016-10-10" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" PDL::Types \- define fundamental PDL Datatypes .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use PDL::Types; \& \& $pdl = ushort( 2.0, 3.0 ); \& print "The actual c type used to store ushort\*(Aqs is \*(Aq" . \& $pdl\->type\->realctype() . "\*(Aq\en"; \& The actual c type used to store ushort\*(Aqs is \*(Aqunsigned short\*(Aq .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Internal module \- holds all the \s-1PDL\s0 Type info. The type info can be accessed easily using the \f(CW\*(C`PDL::Type\*(C'\fR object returned by the type method. .PP Skip to the end of this document to find out how to change the set of types supported by \s-1PDL.\s0 .SH "Support functions" .IX Header "Support functions" A number of functions are available for module writers to get/process type information. These are used in various places (e.g. \f(CW\*(C`PDL::PP\*(C'\fR, \f(CW\*(C`PDL::Core\*(C'\fR) to generate the appropriate type loops, etc. .SS "typesrtkeys" .IX Subsection "typesrtkeys" return array of keys of typehash sorted in order of type complexity .SS "ppdefs" .IX Subsection "ppdefs" return array of pp symbols for all known types .SS "typefld" .IX Subsection "typefld" return specified field (\f(CW$fld\fR) for specified type (\f(CW$type\fR) by querying type hash .SS "mapfld (in_value, in_key, out_key)" .IX Subsection "mapfld (in_value, in_key, out_key)" Map a given source field to the corresponding target field by querying the type hash. This gives you a way to say, "Find the type whose \f(CW$in_key\fR is equal to \f(CW$value\fR, and return that type's value for \f(CW$out_key\fR. For example: .PP .Vb 4 \& # Does byte type use nan? \& $uses_nan = PDL::Types::mapfld(byte => \*(Aqppforcetype\*(Aq, \*(Aqusenan\*(Aq); \& # Equivalent: \& $uses_nan = byte\->usenan; \& \& # What is the actual C type for the value that we call \*(Aqlong\*(Aq? \& $type_name = PDL::Types::mapfld(long => \*(Aqconvertfunc\*(Aq, \*(Aqrealctype\*(Aq); \& # Equivalent: \& $type_name = long\->realctype; .Ve .PP As you can see, the equivalent examples are much shorter and legible, so you should only use mapfld if you were given the type index (in which case the actual type is not immediately obvious): .PP .Vb 2 \& $type_index = 4; \& $type_name = PDL::Types::mapfld($type_index => numval, \*(Aqrealctype\*(Aq); .Ve .SS "typesynonyms" .IX Subsection "typesynonyms" return type related synonym definitions to be included in pdl.h . This routine must be updated to include new types as required. Mostly the automatic updating should take care of the vital things. .SS "datatypes_header" .IX Subsection "datatypes_header" return C header text for \fIpdl.h\fR and \fIpdlsimple.h\fR. .SH "PDL::Type OBJECTS" .IX Header "PDL::Type OBJECTS" This module declares one class \- \f(CW\*(C`PDL::Type\*(C'\fR \- objects of this class are returned by the type method of a piddle. It has several methods, listed below, which provide an easy way to access type information: .PP Additionally, comparison and stringification are overloaded so that you can compare and print type objects, e.g. .PP .Vb 2 \& $nofloat = 1 if $pdl\->type < float; \& die "must be double" if $type != double; .Ve .PP For further examples check again the type method. .IP "enum" 4 .IX Item "enum" Returns the number representing this datatype (see get_datatype). .IP "symbol" 4 .IX Item "symbol" Returns one of '\s-1PDL_B\s0', '\s-1PDL_S\s0', '\s-1PDL_US\s0', '\s-1PDL_L\s0', '\s-1PDL_IND\s0', '\s-1PDL_LL\s0', \&'\s-1PDL_F\s0' or '\s-1PDL_D\s0'. .IP "ctype" 4 .IX Item "ctype" Returns the macro used to represent this type in C code (eg 'PDL_Long'). .IP "ppsym" 4 .IX Item "ppsym" The letter used to represent this type in \s-1PP\s0 code code (eg 'U' for ushort). .IP "realctype" 4 .IX Item "realctype" The actual C type used to store this type. .IP "shortctype" 4 .IX Item "shortctype" The value returned by \f(CW\*(C`ctype\*(C'\fR without the '\s-1PDL_\s0' prefix. .IP "badvalue" 4 .IX Item "badvalue" The special numerical value used to represent bad values for this type. See badvalue routine in PDL::Bad for more details. .IP "orig_badvalue" 4 .IX Item "orig_badvalue" The default special numerical value used to represent bad values for this type. (You can change the value that represents bad values for each type during runtime.) See the orig_badvalue routine in PDL::Bad for more details. .SH "Adding/removing types" .IX Header "Adding/removing types" You can change the types that \s-1PDL\s0 knows about by editing entries in the definition of the variable \f(CW@types\fR that appears close to the top of the file \fITypes.pm.PL\fR (i.e. the file from which this module was generated). .SS "Format of a type entry" .IX Subsection "Format of a type entry" Each entry in the \f(CW@types\fR array is a hash reference. Here is an example taken from the actual code that defines the \f(CW\*(C`ushort\*(C'\fR type: .PP .Vb 9 \& { \& identifier => \*(AqUS\*(Aq, \& onecharident => \*(AqU\*(Aq, # only needed if different from identifier \& pdlctype => \*(AqPDL_Ushort\*(Aq, \& realctype => \*(Aqunsigned short\*(Aq, \& ppforcetype => \*(Aqushort\*(Aq, \& usenan => 0, \& packtype => \*(AqS*\*(Aq, \& }, .Ve .PP Before we start to explain the fields please take this important message on board: \&\fIentries must be listed in order of increasing complexity\fR. This is critical to ensure that \s-1PDL\s0's type conversion works correctly. Basically, a less complex type will be converted to a more complex type as required. .SS "Fields in a type entry" .IX Subsection "Fields in a type entry" Each type entry has a number of required and optional entry. .PP A list of all the entries: .IP "\(bu" 4 identifier .Sp \&\fIRequired\fR. A short sequence of upercase letters that identifies this type uniquely. More than three characters is probably overkill. .IP "\(bu" 4 onecharident .Sp \&\fIOptional\fR. Only required if the \f(CW\*(C`identifier\*(C'\fR has more than one character. This should be a unique uppercase character that will be used to reference this type in \s-1PP\s0 macro expressions of the \f(CW\*(C`TBSULFD\*(C'\fR type. If you don't know what I am talking about read the \s-1PP\s0 manpage or ask on the mailing list. .IP "\(bu" 4 pdlctype .Sp \&\fIRequired\fR. The \f(CW\*(C`typedefed\*(C'\fR name that will be used to access this type from C code. .IP "\(bu" 4 realctype .Sp \&\fIRequired\fR. The C compiler type that is used to implement this type. For portability reasons this one might be platform dependent. .IP "\(bu" 4 ppforcetype .Sp \&\fIRequired\fR. The type name used in \s-1PP\s0 signatures to refer to this type. .IP "\(bu" 4 usenan .Sp \&\fIRequired\fR. Flag that signals if this type has to deal with NaN issues. Generally only required for floating point types. .IP "\(bu" 4 packtype .Sp \&\fIRequired\fR. The Perl pack type used to pack Perl values into the machine representation for this type. For details see \f(CW\*(C`perldoc \-f pack\*(C'\fR. .PP Also have a look at the entries at the top of \fITypes.pm.PL\fR. .PP The syntax is not written into stone yet and might change as the concept matures. .SS "Other things you need to do" .IX Subsection "Other things you need to do" You need to check modules that do I/O (generally in the \fI\s-1IO\s0\fR part of the directory tree). In the future we might add fields to type entries to automate this. This requires changes to those \s-1IO\s0 modules first though. .PP You should also make sure that any type macros in \s-1PP\s0 files (i.e. \f(CW\*(C`$TBSULFD...\*(C'\fR) are updated to reflect the new type. PDL::PP::Dump has a mode to check for type macros requiring updating. Do something like .PP .Vb 1 \& find . \-name \e*.pd \-exec perl \-Mblib=. \-M\*(AqPDL::PP::Dump=typecheck\*(Aq {} \e; .Ve .PP from the \s-1PDL\s0 root directory \fIafter\fR updating \fITypes.pm.PL\fR to check for such places.