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) ) );

In reply to Composing operations on piddles by lin0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.