Skip to content

Commit 54e708f

Browse files
committed
use dummy dim to do all calculation in one go, not in for-loop
1 parent c998070 commit 54e708f

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

src/perl/fbench-pdl.pl

+21-22
Original file line numberDiff line numberDiff line change
@@ -224,28 +224,27 @@
224224

225225
my ($od_fline, $od_cline);
226226

227-
for (my $itercount = 0; $itercount < $niter; $itercount++) {
228-
my @inputs = (
229-
$testcase,
230-
$spectral_line,
231-
pdl(0, 1, 0, 0), # paraxial
232-
pdl(4, 4, 3, 6), # spectral line - main trace in D light, marginal in C,F
233-
pdl($clear_aperture / 2), # ray height, threads so no need to repeat
234-
);
235-
my ($od, $sa) = PDL::trace_line(@inputs);
236-
my $pdl_od_sa = pdl($od, $sa)->slice("(3)")->transpose; # slice as only last col is of interest
237-
@od_sa = @{ $pdl_od_sa->slice(",0:1")->unpdl };
238-
($od_cline, $od_fline) = @{ $pdl_od_sa->slice("(0),2:3")->unpdl };
239-
$aberr_lspher = $od_sa[1][0] - $od_sa[0][0];
240-
$aberr_osc = 1 - ($od_sa[1][0] * $od_sa[1][1]) /
241-
(sin($od_sa[0][1]) * $od_sa[0][0]);
242-
$aberr_lchrom = $od_fline - $od_cline;
243-
$max_lspher = sin($od_sa[0][1]);
244-
# D light
245-
$max_lspher = 0.0000926 / ($max_lspher * $max_lspher);
246-
$max_osc = 0.0025;
247-
$max_lchrom = $max_lspher;
248-
}
227+
my @inputs = (
228+
$testcase,
229+
$spectral_line,
230+
pdl(0, 1, 0, 0)->dummy(-1, $niter), # paraxial
231+
pdl(4, 4, 3, 6)->dummy(-1, $niter), # spectral line - main trace in D light, marginal in C,F
232+
pdl($clear_aperture / 2), # ray height, threads so no need to repeat
233+
);
234+
# slice as only last col of dim 0 is of interest, and only last result=dim 2
235+
my ($od, $sa) = map $_->slice('(-1),,(-1)'), PDL::trace_line(@inputs);
236+
my $pdl_od_sa = pdl($od, $sa)->transpose;
237+
@od_sa = @{ $pdl_od_sa->slice(",0:1")->unpdl };
238+
($od_cline, $od_fline) = @{ $pdl_od_sa->slice("(0),2:3")->unpdl };
239+
$aberr_lspher = $od_sa[1][0] - $od_sa[0][0];
240+
$aberr_osc = 1 - ($od_sa[1][0] * $od_sa[1][1]) /
241+
(sin($od_sa[0][1]) * $od_sa[0][0]);
242+
$aberr_lchrom = $od_fline - $od_cline;
243+
$max_lspher = sin($od_sa[0][1]);
244+
# D light
245+
$max_lspher = 0.0000926 / ($max_lspher * $max_lspher);
246+
$max_osc = 0.0025;
247+
$max_lchrom = $max_lspher;
249248

250249
my $interval = tv_interval(\@t);
251250
print "Time taken: $interval\n";

0 commit comments

Comments
 (0)