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
