http://qs321.pair.com?node_id=1214046


in reply to Re^2: RFC: 100 PDL Exercises (ported from numpy)
in thread RFC: 100 PDL Exercises (ported from numpy)

Hi, mxb, of course I woudn't mind.

+ Note, your recipe #66 doesn't do what's expected, -- but to shift bytes left manually, as Python guys do, isn't nice neither. I'd do this:

pdl> $x = sequence 2,2,3 # "2x2 planar RGB" image, 4 unique colors pdl> $x = $x-> glue( 0, $x ) # "4x2 RGB" image, 4 unique colors pdl> $x = $x-> glue( 1, $x ) # "4x4 RGB" image, still 4 unique colors pdl> $x-> set( 2,2,2, 100 ) # make them 5 pdl> p$x [ [ [0 1 0 1] [2 3 2 3] [0 1 0 1] [2 3 2 3] ] [ [4 5 4 5] [6 7 6 7] [4 5 4 5] [6 7 6 7] ] [ [ 8 9 8 9] [ 10 11 10 11] [ 8 9 100 9] [ 10 11 10 11] ] ] pdl> p $x-> clump(2)-> transpose-> uniqvec-> getdim( 1 ) 5

-----------------

As to combined assignment operators working in-place, here is simple experiment (Windows), either line #1 or #2 un-commented on different runs:

use strict; use warnings; use feature 'say'; use PDL; my $x = zeroes 1e8; my $y = ones 1e8; $x = $x + $y; # 1 #$x += $y; # 2 say qx{ typeperf "\\Process(perl)\\Working Set Peak" -sc 1 } =~ /.+"(.+)"/s; __END__ >perl pdl180504.pl 2427752448.000000 >perl pdl180504.pl 1627779072.000000