PDL::Primitive#

📦 stdpdl

PDL’s primitives: products, selecting by a mask, clipping, searching sorted data, interpolation, set operations on vectors, statistics.

use PDL;
my ($a, $b) = (pdl(1, 2, 3), pdl(4, 5, 6));
print inner($a, $b), " ", crossp($a, $b), " ", norm(pdl(3, 4)), "\n";   # 32 [-3 6 -3] [0.6 0.8]
print $a->clip(1.5, 2.5), " ", which($a > 1), " ", $a->where($a > 1), "\n";   # [1.5 2 2.5] [1 2] [2 3]
print uniq(pdl(3, 1, 3)), " ", append($a, 9), " ", vsearch(2.5, $a), "\n";   # [1 3] [1 2 3 9] 2
print +(pdl([1, 2], [3, 4]) x pdl([1], [1]))->flat, "\n";       # [3 7]
my ($mean, $prms) = stats($b);
print "$mean $prms ", interpol(1.5, $a, $b), "\n";               # 5 1 4.5

where returns a view: $x->where($x < 0) .= 0 zeroes the negative elements of $x. x is matrix multiplication (matmult).

This is PDL::Primitive of PDL 2.106. The kernels are PDL’s own, through pperl’s engine; upstream’s Perl is used unchanged for matmult, append, glue, clip, hclip, lclip, stats, statsover, fibonacci, one2nd, uniq, uniqind, uniqvec, vsearch, interpND, whichND, whichND_both, whereND, whereND_both, where_both, setops, intersect, the ...vec and ..._sorted set operations (unionvec, intersectvec, setdiffvec, union_sorted, intersect_sorted, setdiff_sorted), conv1d, and the random numbers: random (uniform in [0, 1)), randsym (uniform in (0, 1)), grandom (normal, mean 0 and standard deviation 1) and srandom (seeds them).