Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Composing operations on piddles

by lin0 (Curate)
on Jun 15, 2007 at 21:37 UTC ( [id://621528]=CUFP: print w/replies, xml ) Need Help??

What are Piddles?

They are a new data structure defined in the Perl Data Language. As indicated in RFC: Getting Started with PDL (the Perl Data Language):

Piddles are numerical arrays stored in column major order (meaning that the fastest varying dimension represent the columns following computational convention rather than the rows as mathematicians prefer). Even though, piddles look like Perl arrays, they are not. Unlike Perl arrays, piddles are stored in consecutive memory locations facilitating the passing of piddles to the C and FORTRAN code that handles the element by element arithmetic. One more thing to note about piddles is that they are referenced with a leading $

Now, given two piddles ($piddle1 and $piddle2) of the same size, this snippet shows you how you can easily compose operations in which the first operation is applied on an element by element basis. In this particular example, I was interested in finding the sum of the smaller elements. For the first operation, I used the minimum and for the second one, I used the sum. Note that for the first operation there are several options available (depending on what you want to do), such as minimum, maximum, average, and medover. For the second operation there are also several options available (depending, of course, on what you want to do), such as sum, prod, max, and min. For a more complete list of operations, please have a look at RFC: PDL Cheat Sheet.

Cheers,

lin0

Updates:

  1. Added the definition of piddle. Thanks blazar for the suggestion
use PDL; my $sum = sum( minimum( cat($piddle1->copy->flat, $piddle2->copy->flat +)->xchg(0,1) ) );

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-19 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found