Skip to content

Commit

Permalink
tidy & vectorise example 11, PDL version
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 30, 2024
1 parent f6086a3 commit 9298224
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions t/x11.pl
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,13 @@ sub cmap1_init {

plinit ();

my $z = zeroes (XPTS, YPTS);

my $x = 3 * (sequence (XPTS) - int(XPTS / 2)) / int(XPTS / 2);
my $y = 3 * (sequence (YPTS) - int(YPTS / 2)) / int(YPTS / 2);

# The code below may be vectorized to improve speed
for (my $i = 0; $i < XPTS; $i++) {
my $xx = $x->index ($i);
for (my $j = 0; $j < YPTS; $j++) {
my $yy = $y->index ($j);
$z->slice ("$i,$j") .=
3. * (1.-$xx)*(1.-$xx) * exp(-($xx*$xx) - ($yy+1.)*($yy+1.)) -
10. * ($xx/5. - pow($xx,3.) - pow($yy,5.)) * exp(-$xx*$xx-$yy*$yy) -
1./3. * exp(-($xx+1)*($xx+1) - ($yy*$yy));
}
}

my $zmax = max ($z);
my $zmin = min ($z);
my ($x, $y) = map 3*(sequence($_) - int($_ / 2)) / int($_ / 2), XPTS, YPTS;
my ($xx, $yy) = ($x->dummy(1,YPTS), $y->dummy(0,XPTS));
my $z =
3. * (1.-$xx)*(1.-$xx) * exp(-($xx*$xx) - ($yy+1.)*($yy+1.)) -
10. * ($xx/5. - pow($xx,3.) - pow($yy,5.)) * exp(-$xx*$xx-$yy*$yy) -
1./3. * exp(-($xx+1)*($xx+1) - ($yy*$yy));
my ($zmin, $zmax) = (min($z), max($z));
my $step = ($zmax - $zmin) / ($nlevel + 1);
my $clevel = $zmin + $step + $step * sequence ($nlevel);

Expand Down

0 comments on commit 9298224

Please sign in to comment.