Dear all, thanks for the many replies. What got me a little bit upset (because it was unexpected) was the different behaviour of sever when working on entire piddles ($a=$b) in contrast to slices ($a=$b(:). I must admit I should have looked at the docs as it is clearly stated there. I apologise for not doing that, I thought I knew what sever should do, apparently I was wrong. Ingo
On 08/26/2016 07:13 PM, Craig DeForest wrote: > Now that I’m on examples like this, there’s yet another wart to watch for: > > > $a=rvals(5,5) > $b = $a; > $c = $b->sever; > $c->(0) .= 100; > > will change $a!!! > > That is because the “$b=$a” does not create a flow relationship (as > understood by PDL). It literally copies the pointer to $a so that $b and $a > refer to exactly the same data structure. > > All that arises because Perl 5 doesn’t allow overloading of ordinary > assignment. So in the above example, there’s no dataflow relationship to > sever between $a and $b: they are literally the same PDL. > > In the below example (from my last email) $a and $b are different PDLs that > have a dataflow relationship. > > >> On Aug 26, 2016, at 11:09 AM, Craig DeForest <[email protected]> >> wrote: >> >> The “sever" severs $a from its flow affiliates (if any), returning the >> severed child ($a). >> >> You seem to be expecting “sever” to act like “copy”. That is an API wart, >> and may need improvement in the documentation. It is specifically called >> out in the current “sever” documentation, but may not be prominent enough. >> >> If you’d said: >> >> $a = rvals(5,5) >> $b = $a->(:,:); >> $c = $b->sever; >> >> $c->(0) .= 100; >> >> then $a would be unchanged (although $b would be changed). >> >> >> >>> On Aug 26, 2016, at 4:23 AM, Ingo Schmid <[email protected]> wrote: >>> >>> >>> Hi, >>> >>> I got this unexpected behaviour recently: I think it is a bug. If it is, >>> it is very serious, I would say. >>> v2.016. >>> >>> Ingo >>> >>> pdl> $a=rvals(5,5) >>> >>> pdl> $b=$a->sever >>> >>> pdl> p $a >>> >>> [ >>> [ 2.8284271 2.236068 2 2.236068 2.8284271] >>> [ 2.236068 1.4142136 1 1.4142136 2.236068] >>> [ 2 1 0 1 2] >>> [ 2.236068 1.4142136 1 1.4142136 2.236068] >>> [ 2.8284271 2.236068 2 2.236068 2.8284271] >>> ] >>> >>> >>> pdl> p $b >>> >>> [ >>> [ 2.8284271 2.236068 2 2.236068 2.8284271] >>> [ 2.236068 1.4142136 1 1.4142136 2.236068] >>> [ 2 1 0 1 2] >>> [ 2.236068 1.4142136 1 1.4142136 2.236068] >>> [ 2.8284271 2.236068 2 2.236068 2.8284271] >>> ] >>> >>> >>> pdl> $b(0,).=100 >>> >>> pdl> p $b >>> >>> [ >>> [ 100 2.236068 2 2.236068 2.8284271] >>> [ 100 1.4142136 1 1.4142136 2.236068] >>> [ 100 1 0 1 2] >>> [ 100 1.4142136 1 1.4142136 2.236068] >>> [ 100 2.236068 2 2.236068 2.8284271] >>> ] >>> >>> >>> pdl> p $a >>> >>> [ >>> [ 100 2.236068 2 2.236068 2.8284271] >>> [ 100 1.4142136 1 1.4142136 2.236068] >>> [ 100 1 0 1 2] >>> [ 100 1.4142136 1 1.4142136 2.236068] >>> [ 100 2.236068 2 2.236068 2.8284271] >>> ] >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> pdl-general mailing list >>> [email protected] >>> https://lists.sourceforge.net/lists/listinfo/pdl-general >>> >> ------------------------------------------------------------------------------ _______________________________________________ pdl-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pdl-general
