I know what you mean. I was able to verify the problem you pointed out with the following example:
pdl> $a = sequence(byte,10) + 48; pdl> $aref = $a->get_dataref; pdl> p $a; [48 49 50 51 52 53 54 55 56 57] pdl> p "$$aref"; 0123456789 pdl> p unpack "C*", $$aref 48 49 50 51 52 53 54 55 56 57 pdl> $b = $a(1:3); pdl> $bref = $b->get_dataref; pdl> p $b [49 50 51] pdl> p "$$bref" 123 pdl> $A = pack "C", 65; pdl> substr($$bref,1,1,$A); pdl> p $b; [49 50 51] pdl> $b->upd_data; pdl> p $b; [49 50 51] pdl> p $$bref; 1A3 pdl> p length $$bref; 3 pdl> p $b->get_dataref; SCALAR(0x36ccee0) pdl> p $bref; SCALAR(0x36ccee0) pdl> p $$aref; 0123456789 pdl> substr $$aref,2,1,$A; pdl> p $$aref; 01A3456789 pdl> p $a; [48 49 65 51 52 53 54 55 56 57] pdl> $a->upd_data; pdl> p $a; [48 49 65 51 52 53 54 55 56 57] So you can see, for the plain piddle, the upd_data() appears to work however for the slice piddle, the value of the data ref doesn't change, the data in the scalar is changed but the piddle doesn't show the change---ever. We should add this to Known_problems and a caution in the docs for get_dataref and upd_data until the issue is resolved. --Chris On Thu, Sep 13, 2012 at 1:21 PM, David Mertens <[email protected]> wrote: > FYI - > > I've spent a few hours investigating this. I can't write an email > without sounding irritated and making it very long-winded, so I'm just > going to keep it short: This Irritates Me. > > I'll try to amend the docs so that our new readers' expectations for > get_dataref and upd_data are not higher than they ought to be. > > David > > On Thu, Sep 13, 2012 at 8:36 AM, Chris Marshall <[email protected]> > wrote: >> On Wed, Sep 12, 2012 at 11:55 PM, David Mertens >> <[email protected]> wrote: >>> >>> At any rate, if a slice gets modified by PDL::PP code, there is >>> machinery to flow those changes both to the slice's parent and to any >>> of the slice's children. I had assumed that the data-flow machinery >>> behind the $P() macro access in PDL::PP was the same as the stuff >>> behind upd_data, just as you had, but clearly we were both wrong. This >>> smells like a bug to me and something worth investigating whenever >>> core diving happens. >> >> This is covered in the PDL::API docs. As mentioned >> previously in this thread, get_dataref and upd_data are >> used to access/move piddle data to/from perl routines. >> >> get_dataref gives you a reference to a perl scalar value >> containing the data in the piddle. >> >> upd_data updates the data pointer in the pdl struct to >> match the associated SV (since manipulation at the >> perl level could result in memory re-allocations). >> >> If there is some clarification that could be added to the >> docs or the book to avoid this confusion going forward, >> please do so. It should be unambiguous where the >> perl world stops and the PDL::PP one begins. :-) >> >> --Chris > > > > -- > "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
