I just wanted to be sure I understood what to expect from the different ways to share information between perl and pdl. I didn't find this information in the PDL-Book (yet) so I guess it should be included, maybe as a footnote such as 'note: upd_data doesn't work on slices'. As I understand, the $P macro from PDL::PP does work for slices. This surprised me, as $P yields contiguous memory locations, while slices may refer to non-contiguous data in the parent pdl, so I guess $P copies data back and forth. Regards, Luis
On Mon, Sep 10, 2012 at 11:10:49AM -0400, Chris Marshall wrote: > My experience is that it is for moving your > PDL data from piddle space (with dataflow > and all) to perl space (no dataflow here) > so that perl routines could be used to > process piddle data. > > If you want dataflow, doesn't it work with > creating a $tmp piddle pointing at the desired > slice? If not, an argument for that support > could be made but the time could be better > spent on the upcoming core engine refactoring > rather than retrofiting extensive support for > ->get_dataref()... > > --Chris > > On Mon, Sep 10, 2012 at 10:56 AM, David Mertens > <[email protected]> wrote: > > Luis - > > > > When I was working on CUDA::Minimal, I included the ability to > > transfer CUDA data to/from a piddle. I must have struck this problem > > because I included a functional work-around that built a temporary > > piddle and then used .= to assign the just-transfered data to the > > slice piddle. (This work around was also necessary for assigning to > > memory mapped data since you're not allowed to call get_dataref on > > memory mapped data. If I revisit that functionality, I may just write > > a PP function to handle it for me.) > > > > At any rate, I agree that upd_data should invoke data flow to child > > piddles. I don't have time to look at upd_data right now. Are any of > > the other core hackers well versed in the mechanics of upd_data to > > know if this is an outright bug, an underimplementation, or a known > > limitation? > > > > David > > > > On Sun, Sep 9, 2012 at 1:20 PM, Luis Mochan <[email protected]> wrote: > >> I finally got some time to start reading the (very nice) PDL-Book. I > >> started experimenting with get_dataref and upd_data. I believe that > >> they don't work fully with children piddles (for example, with slices), > >> only with the parents. For example, you can fetch the data but you > >> cannot update it when the pdl is a slice. This is illustrated by the > >> small program below, which uses get_dataref and upd_data to multiply a > >> pdl by two and then attempts to multiply a slice: > >> > >> #!/usr/bin/env perl > >> use v5.16; > >> use warnings; > >> use strict; > >> use PDL; > >> use PDL::NiceSlice; > >> my $a=sequence(10); #Initialize a pdl > >> say "\$a=$a"; > >> my $aref=$a->get_dataref; #get ref to its data > >> say "\$\$aref contains ", join " ", unpack "d*", $$aref; > >> $$aref=pack "d*", map 2*$_, unpack "d*", $$aref; #multiply by two > >> say "Now \$\$aref contains ", join " ", unpack "d*", $$aref; > >> $a->upd_data; #update pdl > >> say "Now \$a=$a"; > >> my $b=$a->(0:-1:2); # take a slice > >> say "\$b=\$a->(0:-1:2)=$b"; > >> my $bref=$b->get_dataref; #get ref to its data > >> say "\$\$bref contains ", join " ", unpack "d*", $$bref; > >> $$bref=pack "d*", map 2*$_, unpack "d*", $$bref; #multiply by two > >> say "Now \$\$bref contains ", join " ",unpack "d*", $$bref; > >> $b->upd_data; #update pdl > >> say "But \$b is still $b"; > >> say " and \$a is still $a"; > >> > >> > >> whose output is > >> > >> $a=[0 1 2 3 4 5 6 7 8 9] > >> $$aref contains 0 1 2 3 4 5 6 7 8 9 > >> Now $$aref contains 0 2 4 6 8 10 12 14 16 18 > >> Now $a=[0 2 4 6 8 10 12 14 16 18] > >> $b=$a->nslice([0,-1,2])=[0 4 8 12 16] > >> $$bref contains 0 4 8 12 16 > >> Now $$bref contains 0 8 16 24 32 > >> But $b is still [0 4 8 12 16] > >> and $a is still [0 2 4 6 8 10 12 14 16 18] > >> > >> _______________________________________________ > >> Perldl mailing list > >> [email protected] > >> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > > > > > > > > -- > > "Debugging is twice as hard as writing the code in the first place. > > Therefore, if you write the code as cleverly as possible, you are, > > by definition, not smart enough to debug it." -- Brian Kernighan > > > > _______________________________________________ > > Perldl mailing list > > [email protected] > > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl -- o W. Luis Mochán, | tel:(52)(777)329-1734 /<(*) Instituto de Ciencias Físicas, UNAM | fax:(52)(777)317-5388 `>/ /\ Apdo. Postal 48-3, 62251 | (*)/\/ \ Cuernavaca, Morelos, México | [email protected] /\_/\__/ O< ascii ribbon campaign - stop html mail - www.asciiribbon.org _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
