PDL::Core#
Build ndarrays, ask them about themselves, and convert between types.
use PDL;
my $x = pdl([1, 2, 3], [4, 5, 6]);
print join(",", $x->dims), " ", $x->nelem, " ", $x->type, " ", $x->at(2, 1), "\n"; # 3,2 6 double 6
print $x->info, "\n"; # PDL: Double D [3,2]
print zeroes(byte, 2), ones(2), " ", sequence(3)->convert(float)->type, "\n"; # [0 0][1 1] float
my @l = $x->list;
print "@l ", short(1.7), " ", pdl(5)->sclr + 1, "\n"; # 1 2 3 4 5 6 1 6
my $v = $x->slice(":,(0)");
$v .= 0;
print $x->flat, " ", $x->copy->sever->isnull, "\n"; # [0 0 0 4 5 6] 0
print cat(pdl(1, 2), pdl(3, 4))->flat, " ", $x->badflag, "\n"; # [1 2 3 4] 0
PDL::Core is the foundation the rest of PDL rests on. It holds the constructors (pdl, null, zeroes, ones, empty, cat), the accessors that report shape and contents (dims, shape, ndims, nelem, at, set, list, unpdl, info), the type system (type, convert, get_datatype, howbig), and the bad-value flag (badflag; the rest of the bad-value machinery is PDL::Bad).
Two ideas run through all of it. Ndarrays are typed: an ndarray of byte and one of double hold different things, and convert moves between them. And ndarrays can share data: a slice or a reshape is a view onto its parent, so sever and copy exist for the times you want a snapshot that stops tracking the original.
The types and their constructors, each type(...) an ndarray of that type and a bare type the type itself (as in zeroes(float, 3)): sbyte, byte, short, ushort, long, ulong, indx, ulonglong, longlong, float, double, ldouble, cfloat, cdouble, cldouble. piddle is the old name of pdl.
The state of an ndarray, as methods returning 0 or 1: allocated, anychgd, datachgd, dimschgd, donttouch, fflows, is_inplace, is_readonly, vaffine; set_inplace changes it, and getdim and getndims are dim and ndims. address, address_data and address_datasv are the memory addresses behind an ndarray, for debugging, new_from_specification is zeroes’ engine, is_scalar_SvPOK is a helper of pdl’s, and howbig_c is the one of howbig.
This is PDL::Core of PDL 2.106. Its XS is pperl’s, native; its Perl (cat, ones, empty, info, convert, copy, reshape, squeeze, dummy, clump, mslice, barf, approx, howbig, isempty, shape, type, list, fhdr and the rest) is upstream’s, unchanged.
Functions#
Constructors#
alltopdl#
PDL::Core::alltopdl($class, $value, $type), see [alltopdl].
pdl_avref#
Core.xs pdl_avref(array_ref, class, type).
Elements and data#
at_bad_c#
PDL::Core::at_bad_c($pdl, [@pos]) (also at_c): the element at @pos, “BAD” for a bad value - what $pdl->at(@pos) is built on.
set_c#
PDL::Core::set_c($pdl, [@pos], $value): store $value at @pos - what $pdl->set(@pos, $value) is built on.
listref_c#
PDL::Core::listref_c($pdl): the elements as a nested array ref, “BAD” for bad values - what list is built on.
Parallel processing#
online_cpus#
PDL::Core::online_cpus() - how many threads PDL can split an operation across.
pthreads_enabled#
PDL::Core::pthreads_enabled() - 1: operations can be split across threads.
Miscellaneous#
seed#
PDL::Core::seed(): a seed for the random number generators, from the time and the process id.
set_debugging#
PDL::Core::set_debugging($on) - set the engine’s debugging flag and return its previous value.