in reply to PDL: efficient self-referencing math?
I haven't used PDL at all, but maybe you have enough dimensions in your piddle to make the following approach efficient:
- Create a matrix to calculate the shifted, negative piddle (can be cached)
- Multiply the source piddle by the matrix to create the shifted negative source piddle
- Add the source piddle and the new piddle
The matrix would be (or, would be)
( 0 0 0 ...) ( -1 0 0 ...) ( 0 -1 0 ...) ( 0 0 -1 ...) ...
Reading from the PDL documentation, basically the following code should work (while PDL is installing):
# 4 dimensions my $matrix = pdl([[0,0,0,0],[-1,0,0,0],[0,-1,0,0],[0,0,-1,0]]); my $pdl = pdl(...); my $diff = $pdl x $matrix; # not sure about whether to use left- or ri +ght-multiplication here my $res = $pdl + $diff;
In Section
Seekers of Perl Wisdom