Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: PDL: efficient self-referencing math?

by Corion (Patriarch)
on Sep 04, 2011 at 08:02 UTC ( [id://924048]=note: print w/replies, xml ) Need Help??


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:

  1. Create a matrix to calculate the shifted, negative piddle (can be cached)
  2. Multiply the source piddle by the matrix to create the shifted negative source piddle
  3. 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;

Replies are listed 'Best First'.
Re^2: PDL: efficient self-referencing math?
by BrowserUk (Patriarch) on Sep 04, 2011 at 08:30 UTC

    That's an interesting approach.

    My piddle is just a 1D vector so maybe if I create a second 1D vector that is a copy of the first minus the first element, I can just subtract one from the other and produce the result I need?

    Hm. Need to play.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://924048]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-16 10:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found