Home > Software design >  Difference between PDL::Core and PDL::Core ':Internal'
Difference between PDL::Core and PDL::Core ':Internal'

Time:07-06

I just started using PDL and saw in the docmentation that there is 2 possible ways of importing PDL´s core function:

use PDL::Core;
use PDL::Core ':Internal';

What is exactly the difference here? The documentation makes a comment on the second method:"Hairy routines". I also could not find anything about whats meant by that.

CodePudding user response:

use PDL::Core;

is equivalent to

use PDL::Core ':Func';

which is equivalent to

use PDL::Core
   qw( piddle pdl null barf ),
   ( map $_->convertfunc, PDL::Types::types() ),
   qw(
      nelem dims shape null empty dup dupN inflateN
      convert inplace zeroes zeros ones nan inf i list listindices unpdl
      set at flows broadcast_define over reshape dog cat barf type
      thread_define dummy mslice approx flat sclr squeeze
      get_autopthread_targ set_autopthread_targ get_autopthread_actual
      get_autopthread_dim get_autopthread_size set_autopthread_size
   );

use PDL::Core ':Internal';

is equivalent to

use PDL::Core qw( howbig broadcastids topdl );

CodePudding user response:

As @ikegami says,

use PDL::Core ':Internal';

is indeed equivalent to

use PDL::Core qw( howbig broadcastids topdl );

This can be seen in the implementing code on GitHub. However, as can also be seen there, use PDL::Core; imports considerably more than just qw(piddle pdl null barf).

The three "internal" routines respectively give how many bytes for a given PDL-internal datatype ID, which dimensions in an ndarray have been marked for broadcasting, and converting any Perl value to an ndarray if it isn't one already. The last two should probably always be called as a method (respectively object and class), and the first one is not useful for normal PDL use (which is generally maths-y). They are all still available via the PDL::Core package, just not exported.

Generally speaking, it isn't recommended practice to explicitly import PDL::Core, nor any of the "core" PDL packages (PDL::Primitive, PDL::Ops, etc); instead import one of PDL::LiteF (only exports minimal functions) or PDL::Lite (exports none). use PDL imports extra non-"core" packages such as PDL::IO::FITS for historical reasons.

  • Related