PDL::ApplyDim

Many operations in PDL act on the first dimension, so a very common idiom is

$pdl->mv($dim,0)->function($some, $extra, $args)->mv(0, $dim);

to move the dimension $dim to the front, operate with the function and the move the dimension back to its original place. The idea is to hide the mv operations and write this as

$pdl->apply_to(\&function, $dim, $some, $extra, $args);

or

apply_to($pdl, "function", $dim, $some, $extra, $args);

Similarly

$pdl->apply_not_to(\&function, $dim, $some, $extra, $args);

moves the dimension to the back. Besides a number, $dim may also be an array reference, such as as [$d0, $d1...], to move the dimensions $d0, $d1... to the front or to the back instead of just a single dimension.

The package may be found in Github and in CPAN.

Written on January 4, 2025