From 54e708fc3a474ee9ed47a0f40812b58b239c01a3 Mon Sep 17 00:00:00 2001 From: Ed J Date: Sat, 2 Oct 2021 14:24:42 +0100 Subject: [PATCH] use dummy dim to do all calculation in one go, not in for-loop --- src/perl/fbench-pdl.pl | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/perl/fbench-pdl.pl b/src/perl/fbench-pdl.pl index 92ced61..cadc6fa 100644 --- a/src/perl/fbench-pdl.pl +++ b/src/perl/fbench-pdl.pl @@ -224,28 +224,27 @@ my ($od_fline, $od_cline); -for (my $itercount = 0; $itercount < $niter; $itercount++) { - my @inputs = ( - $testcase, - $spectral_line, - pdl(0, 1, 0, 0), # paraxial - pdl(4, 4, 3, 6), # spectral line - main trace in D light, marginal in C,F - pdl($clear_aperture / 2), # ray height, threads so no need to repeat - ); - my ($od, $sa) = PDL::trace_line(@inputs); - my $pdl_od_sa = pdl($od, $sa)->slice("(3)")->transpose; # slice as only last col is of interest - @od_sa = @{ $pdl_od_sa->slice(",0:1")->unpdl }; - ($od_cline, $od_fline) = @{ $pdl_od_sa->slice("(0),2:3")->unpdl }; - $aberr_lspher = $od_sa[1][0] - $od_sa[0][0]; - $aberr_osc = 1 - ($od_sa[1][0] * $od_sa[1][1]) / - (sin($od_sa[0][1]) * $od_sa[0][0]); - $aberr_lchrom = $od_fline - $od_cline; - $max_lspher = sin($od_sa[0][1]); - # D light - $max_lspher = 0.0000926 / ($max_lspher * $max_lspher); - $max_osc = 0.0025; - $max_lchrom = $max_lspher; -} +my @inputs = ( + $testcase, + $spectral_line, + pdl(0, 1, 0, 0)->dummy(-1, $niter), # paraxial + pdl(4, 4, 3, 6)->dummy(-1, $niter), # spectral line - main trace in D light, marginal in C,F + pdl($clear_aperture / 2), # ray height, threads so no need to repeat +); +# slice as only last col of dim 0 is of interest, and only last result=dim 2 +my ($od, $sa) = map $_->slice('(-1),,(-1)'), PDL::trace_line(@inputs); +my $pdl_od_sa = pdl($od, $sa)->transpose; +@od_sa = @{ $pdl_od_sa->slice(",0:1")->unpdl }; +($od_cline, $od_fline) = @{ $pdl_od_sa->slice("(0),2:3")->unpdl }; +$aberr_lspher = $od_sa[1][0] - $od_sa[0][0]; +$aberr_osc = 1 - ($od_sa[1][0] * $od_sa[1][1]) / + (sin($od_sa[0][1]) * $od_sa[0][0]); +$aberr_lchrom = $od_fline - $od_cline; +$max_lspher = sin($od_sa[0][1]); +# D light +$max_lspher = 0.0000926 / ($max_lspher * $max_lspher); +$max_osc = 0.0025; +$max_lchrom = $max_lspher; my $interval = tv_interval(\@t); print "Time taken: $interval\n";