Do you need 'sever's in there to break the dataflow connections? --Chris
On Wed, Aug 31, 2011 at 3: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 > _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
