PDL::Types(3pm)

✨ NAME ✨

PDL::Types β€” define fundamental PDL Datatypes

hey bestie 🫢 you're reading PDL::Types(3pm), straight out of the User Contributed Perl Documentation collection. it's the page that spills everything about the datatypes PDL is built on. let's get into it πŸ’–


🌈 SYNOPSIS 🌈

use PDL::Types;

$pdl = ushort( 2.0, 3.0 );
print "The actual c type used to store ushort's is '" .
   $pdl->type->realctype() . "'\n";
The actual c type used to store ushort's is 'unsigned short'

πŸ’… DESCRIPTION πŸ’…

okay so real talk: this is an internal module πŸ™ˆ β€” it holds all the PDL type info. and how do you get at that info? easy. you use the PDL::Type object that the type method hands back, exactly like the synopsis shows. slay, no cap.

and if you're curious about how to change the whole set of types that PDL supports? skip to the end of this document β€” everything you need is chillin' down there for you ✨


πŸ”₯ FUNCTIONS πŸ”₯

for all my module-writer besties out there: there is a whole pile of functions here for getting and processing type information πŸ“š. they get used all over the place (think PDL::PP, PDL::Core) to generate the right type loops and all that good stuff. iconic behaviour tbh πŸ‘‘

typesrtkeys

hands you back an array of keys of typehash, sorted in order of type complexity ✨

pdl> @typelist = PDL::Types::typesrtkeys;
pdl> print @typelist;
PDL_SB PDL_B PDL_S PDL_US PDL_L PDL_UL PDL_IND PDL_ULL PDL_LL PDL_F PDL_D PDL_LD PDL_CF PDL_CD PDL_CLD

ppdefs

hands you back an array of pp symbols covering all the real types. this is what sets the default GenericTypes for pp_def functions, which means supporting complex types is a whole opt-in situation πŸ’…

pdl> print PDL::Types::ppdefs
A B S U L K N P Q F D E

ppdefs_complex

hands you back an array of pp symbols covering all the complex types πŸ¦‹

pdl> print PDL::Types::ppdefs_complex
G C H

ppdefs_all

hands you back an array of pp symbols covering all types, complex ones included 🌈

pdl> print PDL::Types::ppdefs_all
A B S U L K N P Q F D E G C H

typesynonyms

returns the type-related synonym definitions that get included in pdl.h . heads up though: this routine has to be updated by hand whenever new types show up β€” that's a requirement, not a suggestion πŸ™ˆ. luckily the automatic updating handles most of the vital stuff for you, so it's giving "low-maintenance, mostly" πŸ’–


πŸ‘‘ PDL TYPES OVERVIEW πŸ‘‘

as of 2.065, PDL supports these types:

  • SByte β€” signed 8-bit value.
  • Byte β€” unsigned 8-bit value.
  • Short β€” signed 16-bit value.
  • UShort β€” unsigned 16-bit value.
  • Long β€” signed 32-bit value.
  • ULong β€” unsigned 32-bit value.
  • Indx β€” signed value, same size as a pointer on whatever system you're on πŸ–₯️
  • ULongLong β€” unsigned 64-bit value.
  • LongLong β€” signed 64-bit value.
  • Float β€” IEEE 754 (https://en.wikipedia.org/wiki/IEEE_754) single-precision real floating-point value.
  • Double β€” IEEE 754 double-precision real value.
  • LDouble β€” a C99 long double, defined as at least as precise as a double, but often more precise ✨
  • CFloat β€” a C99 complex single-precision floating-point value.
  • CDouble β€” a C99 complex double-precision floating-point value.
  • CLDouble β€” a C99 complex long double β€” see above for the description, bestie.

and as of 2.099, the documentation for PDL::Type is separate πŸ™ˆ. see there for more.


πŸŽ€ DEVELOPER NOTES ON ADDING/REMOVING TYPES πŸŽ€

you can totally change the types PDL knows about β€” just edit the entries in the definition of the variable @types that lives close to the top of the file lib/PDL/Types.pm.

πŸ¦‹ Format of a type entry πŸ¦‹

every entry in the @HASHES array is a hash reference. here's an example, taken straight from the actual code that defines the ushort type:

{
  identifier => 'US',
  onecharident => 'U',   # only needed if different from identifier
  ctype => 'PDL_Ushort',
  realctype => 'unsigned short',
  ppforcetype => 'ushort',
  usenan => 0,
  packtype => 'S*',
  defbval => 'USHRT_MAX',
  real=>1,
  integer=>1,
  unsigned=>1,
},

before we start explaining the fields, please please please take this important message on board: entries must be listed in order of increasing complexity. this is critical to make sure PDL's type conversion works correctly. basically, a less complex type gets converted to a more complex type whenever that's what's needed. periodt πŸ’…

πŸ’œ Fields in a type entry πŸ’œ

each type entry has a number of required and optional entries. here's the list of all of them:

  • identifier β€” Required. a short sequence of uppercase letters that identifies this type uniquely. more than three characters is probably overkill ngl.
  • onecharident β€” Optional. only needed if the identifier has more than one character. this should be a unique uppercase character that'll be used to reference this type in PP macro expressions of the TBSULFD kind β€” see $T in PDL::PP.
  • ctype β€” Required. the typedefed name that'll be used to access this type from C code.
  • realctype β€” Required. the C compiler type used to implement this type. for portability reasons this one might be platform dependent.
  • ppforcetype β€” Required. the type name used in PP signatures to refer to this type.
  • usenan β€” Required. a flag that signals whether this type has to deal with NaN issues. generally only needed for floating point types.
  • packtype β€” Required. the Perl pack type used to pack Perl values into the machine representation for this type. for the details, see perldoc -f pack.
  • integer β€” Required. boolean β€” is this an integer type?
  • unsigned β€” Required. boolean β€” is this an unsigned type?
  • real β€” Required. boolean β€” is this a real (not complex) type?
  • realversion β€” string β€” the real version of this type (e.g. cdouble -> 'D').
  • complexversion β€” string β€” the complex version of this type (e.g. double -> 'C').

also go peek at the entries at the top of lib/PDL/Types.pm πŸ‘€

🌸 Other things you need to do 🌸

you need to check the modules that do I/O (generally in the IO part of the directory tree). in the future we might add fields to type entries to automate this β€” but that requires changes to those IO modules first, so, y'know, one thing at a time πŸ™ˆ

you may also need to update any type macros in PP files (i.e. $TBSULFD...) so they reflect the new type. heads up: PP will throw an error if you've got a $T... macro that's missing types the operation supports. so don't skip this step, bestie πŸ’€


and that's the whole page!! go forth and type responsibly 🫢

okay bye ily, this was PDL::Types(3pm) from the User Contributed Perl Documentation, built against perl v5.42.3 and dated 2026-08-20. stay iconic πŸ‘‘πŸ’–βœ¨

πŸ“¦ where this page comes from