> Do you need 'sever's in there to break the dataflow
> connections?
>
> --Chris

It seems to work as-is, what would sever do to help? What I think I am
doing is unrolling each dimension of the piddle until it is a "vector"
and then using list to create an arrayref which then is passed back up
the recursion chain. It doesn't seem to me that even if the original
input were a slice or if there is some memory retained in the dog
process (is there?) that my concept wouldn't work. Though I am no
expert by any means.

I take it by your response that there is no built-in that does this
then however.

> Are you looking for the list function? See 
> pdl.perl.org/?docs=Core&title=PDL::Core#list
>
> David

I actually use the list function in my implementation of unroll. The
problem I had, (and I think I was using it correctly) was that it
flattened the piddle as it returned the list so that an NxN array
became a 1x(N+N) vector. Unroll makes an array reference of N array
references each of length N.

--------------------

The reasoning is that my module Math::GSLx::ODEIV2 doesn't use PDL for
data storage, but I want it to be able to if PDL is present. When the
module is compiled the functionality is obvious, an AoA is returned.
If compiled with PDL however, internally during the calculation the
data would be in a PDL (so that there is the option of returning a
piddle and I don't need to create so many SV*s), however this presents
a problem if the user expects the function to return an AoA. Therefore
a PDL=>1 option would return a piddle, but otherwise I need to unroll
the piddle into an AoA.

Perhaps this seems crazy and perhaps it is crazy, but I think it should work.

Joel

On Wed, Aug 31, 2011 at 2:34 PM, Joel Berger <[email protected]> wrote:
> For not just purely academic reasons, I am wondering if there is a
> better/builtin way of converting a PDL of arbitrary size into its pure
> perl equivalent. (call it the inverse of the pdl() function). Here's
> what I came up with, is there something better or can someone be more
> clever?
>
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
>
> use PDL;
> use Test::More tests => 1;
>
> my $array = [
>  [[1,2],
>   [3,4]],
>  [[5,6],
>   [7,8]],
>  [[9,10],
>   [11,12]]
> ];
> my $pdl = pdl $array;
>
> is_deeply( unroll($pdl), $array, "back convert 3d");
>
> sub unroll {
>  my $in = shift;
>
>  if (ref $in and ref $in eq 'PDL') {
>    if ($in->ndims > 1) {
>      return [ map {unroll($_)} dog $in ];
>    } else {
>      return [list $in];
>    }
>  } else {
>    return $in;
>  }
>
> }
>

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to