Hi Luis, I like this, thank you!
For completeness sake, I have written PDL::Dims a long time ago, which allows accessing dims via names (and, to some extent units), which sort of does that.
Ingo On 12.01.25 2:10 AM, Luis Mochan wrote:
Hi again, By the way, I made a small package which may be useful (unless its functionality is already part of PDL and I missed it): PDL::ApplyDim. The idea is to factor out a common shuffling and unshuffling of indices before calling pdl functions/methods that act only on the first dimension(s). So, instead of $pdl->mv($dim,0)->function($some, $extra, $args)->mv(0, $dim); one may write $pdl->apply_to(\&function, $dim, $some, $extra, $args); $pdl->apply_to("function", $dim, $some, $extra, $args); apply_to($pdl, \&function", $dim, $some, $extra, $args); or apply_to($pdl, "function", $dim, $some, $extra, $args); ... For example, a scalar time dependent field, f(x,y,z,t) may be represented by a 4D ndarray $f. We have $f->xvals, $f->yvals, $f->zvals, but no $f->tvals. We could define sub tvals($pdl){$pdl->apply_to(3, \&xvals) Similarly, instead of $pdl->reorder(3,2,0,1)->function(@otherargs)->reorder(2,3,1,0); to move dimensions 3 and 2 to the front and shift the rest towards the end, apply the function and then recover the original order, one may write $pdl->apply_to(\&function, [3,2], @otherargs); or more generally $pdl->apply_to(\&function, [$d0, $d1, $d2...], @otherargs); The converse function is apply_not_to, to move the given dimensions to the end, applying the function and then restoring them back to the front. For example, to make a D-dimensional Fourier transform of a rank 3 tensor field, represented by a (D+3)-dimensional ndarray, one would have to move the first three dimensions (the tesorial indices) to the end, perform the D-dimensional Fourier transform over the first D indices and then bring the tensorial indices back to the front. Regards, Luis On Sat, Jan 11, 2025 at 11:52:53AM -0600, Luis Mochan wrote:I didn't know (or had forgotten) about the pptemplate; I'll try it, thanks.
_______________________________________________ pdl-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pdl-general
