blib/lib/PDL/Graphics/Limits.pm

filter: Statementstmt 90.7% 355 / 391 Branchbran 73.0% 165 / 226 Conditioncond 67.7% 42 / 62 MC/DCmcdc 35.2% 12 / 34 Subroutinesub 96.9% 32 / 33 Podpod 8.3% 1 / 12 totaltotal 80.0% 607 / 758 CC 159 SCAR 28.5
CC
159
Cov
83%
parse_limits
35.1
limits
23.7
normalize_hash_dset
21.6
CRAP 17.3
↑ Summary
1 package PDL::Graphics::Limits;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 require Exporter;
7  
8 8 our @ISA = qw(Exporter);
9  
10 8 our %EXPORT_TAGS = ( 'all' => [ qw(
11 limits
12 ) ] );
13  
14 8 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
15  
16 8 our @EXPORT = qw(
17 limits
18 );
19  
20 8 our $VERSION = '0.031';
21 8 $VERSION = eval $VERSION;
22  
23 # Preloaded methods go here.
24  
25 8 ▶use PDL::Core qw( cat pdl );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 8 ▶use PDL::Primitive qw( append );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 8 ▶use PDL::Fit::Polynomial;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 8 ▶use PDL::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 8 ▶use PDL::Bad;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 8 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 8 ▶use POSIX qw( log10 );
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 ################################################################################
37 # figure out what's good in an ndarray after a possible transformation which could
38 # generate Infs or NaN's.
39 sub set_mask
40 188 ▶{
Subroutine set_mask: called CC=1 SCAR=0.0
Pod undocumented
41 188 my ( $mask, $data ) = @_;
42 188 my $badflag = $data->badflag();
43 188 $data->badflag(1);
44 188 $mask .= ( $data->isfinite & ! $data->isbad );
45 188 $data->badflag($badflag);
46 }
47  
48  
49  
50 {
51 package PDL::Graphics::Limits::DSet;
52  
53 8 ▶ use PDL::Core qw( cat pdl );
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 8 *set_mask = \*PDL::Graphics::Limits::set_mask;
56  
57 sub new
58 124 ▶ {
Subroutine new: called CC=1 SCAR=0.0
59 124 my $class = shift;
60 124 my $self = bless {}, $class;
61  
62 124 my ( $min, $max ) = splice( @_, 0, 2 );
63  
64 124 $self->{Vectors} = [ @_ ];
65 124 $self->{MinMax} = [ map{ [ $min, $max ] } 1..@{$self->{Vectors}} ];
66  
67 124 $self;
68 }
69  
70 219 ▶ sub ndim { scalar @{$_[0]->{Vectors}} }
Subroutine ndim: called CC=1 SCAR=0.0
71  
72 sub validate
73 120 ▶ {
Subroutine validate: called CC=11 SCAR=24.1
74 120 my ( $self, $attr) = @_;
75  
76 120 my $ivec = 0;
77 120 my $n;
78 120 foreach my $vec ( @{$self->{Vectors}} )
79 {
80 die( 'vector ', $ivec+1, ": no data?\n" )
81 239 ▶ unless defined $vec->{data};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vec->{"data"} 0 239 239
82  
83 239 ▶ $n = $vec->{data}->nelem unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 120 119 239
84  
85 # if a data set vector has no transformation function, use the
86 # default in $attr{Trans}
87 $vec->{trans} = $attr->{Trans}[$ivec]
88 239 ▶ if ! exists $vec->{trans} && exists $attr->{Trans}[$ivec];
Branch: 1 branch
BranchTrueFalseTotal
if not exists $vec->{"trans"} and exists $attr->{"Trans"}[$ivec] 21 218 239
Condition100%3/3
not exists $vec->{"trans"} and exists $attr->{"Trans"}[$ivec]
!ll&&!rl&&r
1620221
MC/DC100%2/2
not exists $vec->{"trans"} and exists $attr->{"Trans"}[$ivec]
not exists $vec->{"trans"} exists $attr->{"Trans"}[$ivec]
Truth table100%3/3
not(A) and B
A= not exists $vec->{"trans"}B= exists $attr->{"Trans"}[$ivec]
ABresult
0X0
100
111
89  
90 # remove explicitly undefined trans
91 delete $vec->{trans}
92 239 ▶ if exists $vec->{trans} && ! defined $vec->{trans};
Branch: 1 branch
BranchTrueFalseTotal
if exists $vec->{"trans"} and not defined $vec->{"trans"} 13 226 239
Condition100%3/3
exists $vec->{"trans"} and not defined $vec->{"trans"}
!ll&&!rl&&r
2022413
MC/DC100%2/2
exists $vec->{"trans"} and not defined $vec->{"trans"}
exists $vec->{"trans"} not defined $vec->{"trans"}
Truth table100%3/3
A and not(B)
A= exists $vec->{"trans"}B= not defined $vec->{"trans"}
ABresult
0X0
100
111
93  
94 # ensure that data and errors have the same length.
95 die( 'vector ', $ivec+1, ": attribute $_: ",
96 "inconsistent number of elements",
97 "expected $n, got ", $vec->{$_}->nelem, "\n" )
98 239 foreach
99 grep { exists $vec->{$_} &&
100 defined $vec->{$_} &&
101 717 ▶ $vec->{$_}->nelem != $n }
Condition66%4/6
exists $vec->{$_} && defined $vec->{$_} && $vec->{$_}->nelem != $n
!ll&&!rl&&r
4782390
exists $vec->{$_} and defined $vec->{$_}
!ll&&!rl&&r
4780239
MC/DC0%0/3
exists $vec->{$_} && defined $vec->{$_} && $vec->{$_}->nelem != $n
exists $vec->{$_} defined $vec->{$_} $vec->{$_}->nelem != $n
Truth table50%2/4
A and B && C
A= exists $vec->{$_}B= defined $vec->{$_}C= $vec->{$_}->nelem != $n
ABCresult
0XX0
10X0
1100
1111
102 qw( data en ep );
103 }
104 continue
105 {
106 239 $ivec++;
107 }
108  
109 }
110  
111 sub vector
112 13 ▶ {
Subroutine vector: called CC=1 SCAR=0.0
113 13 $_[0]->{Vectors}[$_[1]];
114 }
115  
116 sub set_minmax
117 358 ▶ {
Subroutine set_minmax: called CC=3 SCAR=11.0
118 358 my ( $dset, $min, $max, $axis ) = @_;
119  
120 358 my $mm = $dset->{MinMax}[$axis];
121  
122 358 ▶ $mm->[0] = $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 203 155 358
123 358 ▶ $mm->[1] = $max if defined $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 203 155 358
124 }
125  
126 sub upd_minmax
127 0 ▶ {
Subroutine upd_minmax: not called CC=3 SCAR=24.8
128 0 my ( $dset, $min, $max, $axis ) = @_;
129  
130 0 my $mm = $dset->{MinMax}[$axis];
131  
132 0 ▶ $mm->[0] = $min if $mm->[0] > $min;
Branch: 1 branch
BranchTrueFalseTotal
if $mm->[0] > $min 0 0 0
133 0 ▶ $mm->[1] = $max if $mm->[1] < $max;
Branch: 1 branch
BranchTrueFalseTotal
if $mm->[1] < $max 0 0 0
134 }
135  
136 sub get_minmax
137 96 ▶ {
Subroutine get_minmax: called CC=1 SCAR=0.0
138 96 my ( $dset ) = @_;
139 96 cat( map { pdl( $dset->{MinMax}[$_] ) } 0..$dset->ndim-1 );
140 }
141  
142 sub calc_minmax
143 154 ▶ {
Subroutine calc_minmax: called CC=3 SCAR=11.2
144 154 my $dset = shift;
145  
146 154 ▶ my @axes = @_ ? ( $_[0] ) : ( 0 ..$dset->ndims-1 );
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 154 0 154
147  
148 154 $dset->calc_minmax_axis( $_ ) foreach @axes;
149 }
150  
151 #####################################################################
152 # determine the limits for a dataset.
153 sub calc_minmax_axis
154 154 ▶ {
Subroutine calc_minmax_axis: called CC=6 SCAR=17.9
155 154 my ( $dset, $axis ) = @_;
156  
157 154 my $vec = $dset->{Vectors}[$axis];
158 154 my $data = $vec->{data};
159  
160 154 my $xfrm = defined $vec->{trans};
161  
162 # we need the transformed data point min max in case
163 # a transformed data + error is out of range of the transform
164 # function (e.g. log(0)).
165  
166 154 my @minmax;
167  
168 # reuse these as much as possible to reduce memory hit
169 my $tmp;
170 154 my $mask = PDL::null;
171  
172 # i know of no way of determining whether a function can be applied inplace.
173 # assume not.
174  
175 # if xfrm is true, $tmp will be an independent ndarray, else its an alias for data
176 # no need to create a new ndarray unless necessary.
177 154 ▶ $tmp = $xfrm ? $vec->{trans}->($data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
$xfrm ? : 17 137 154
178 154 set_mask( $mask, $tmp );
179 154 push @minmax, $tmp->where($mask)->minmax;
180  
181 154 ▶ if ( defined $vec->{errn} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vec->{"errn"}) 9 145 154
182 {
183 # worry about not overwriting the original data!
184 9 ▶ if ( $xfrm ) { $tmp .= $vec->{trans}->($data - $vec->{errn}) }
Branch: 1 branch
BranchTrueFalseTotal
if ($xfrm) { } 3 6 9
185 6 else { $tmp = $data - $vec->{errn} }
186 9 set_mask( $mask, $tmp );
187 9 push @minmax, $tmp->where($mask)->minmax;
188 }
189  
190 154 ▶ if ( defined $vec->{errp} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vec->{"errp"}) 12 142 154
191 {
192 # worry about not overwriting the original data!
193 12 ▶ if ( $xfrm ) { $tmp .= $vec->{trans}->($data + $vec->{errp}) }
Branch: 1 branch
BranchTrueFalseTotal
if ($xfrm) { } 4 8 12
194 8 else { $tmp = $data + $vec->{errp} }
195 12 set_mask( $mask, $tmp );
196 12 push @minmax, $tmp->where($mask)->minmax;
197 }
198  
199 154 my ( $min, $max ) = PDL::Core::pdl( @minmax )->minmax;
200  
201 154 $dset->set_minmax( $min, $max, $axis );
202 }
203  
204 }
205  
206 #####################################################################
207  
208 sub range_frac
209 8 ▶{
Subroutine range_frac: called CC=6 SCAR=26.0
Pod undocumented
210 2 my ( $axis, $frac, $zerofix ) = @_;
211  
212 2 my $expand = $frac * ( $axis->[1] - $axis->[0] );
213 2 my $min = $axis->[0] - $expand;
214 2 my $max = $axis->[1] + $expand;
215  
216 2 ▶ if ( $zerofix )
Branch: 1 branch
BranchTrueFalseTotal
if ($zerofix) 0 2 2
217 {
218 0 ▶ $min = 0.0
Branch: 1 branch
BranchTrueFalseTotal
if $min < 0 and $axis->[0] >= 0 0 0 0
Condition0%0/3
$min < 0 and $axis->[0] >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$min < 0 and $axis->[0] >= 0
$min < 0 $axis->[0] >= 0
Truth table0%0/3
A and B
A= $min < 0B= $axis->[0] >= 0
ABresult
0X0
100
111
219 if $min < 0 && $axis->[0] >= 0.0;
220  
221 0 ▶ $max = 0.0
Branch: 1 branch
BranchTrueFalseTotal
if $max > 0 and $axis->[1] <= 0 0 0 0
Condition0%0/3
$max > 0 and $axis->[1] <= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$max > 0 and $axis->[1] <= 0
$max > 0 $axis->[1] <= 0
Truth table0%0/3
A and B
A= $max > 0B= $axis->[1] <= 0
ABresult
0X0
100
111
222 if $max > 0 && $axis->[1] <= 0.0;
223 }
224  
225 2 @{$axis} = ( $min, $max );
226 }
227  
228 #####################################################################
229  
230 # routine to find the closest "round" number to X, a "round" number
231 # being 1, 2 or 5 times a power of 10.
232  
233 # If X is negative, round_pow(X) = -round_pow(abs(X)).
234 # If X is zero, the value returned is zero.
235  
236 # round_pow( direction, $x )
237 # where direction is up, down, or both i.e.
238 # $ub = round ( up => $x );
239 # $lb = round ( down => $x );
240  
241 8 our @nice = ( 1, 2, 5, 10 );
242 8 our %flip = ( 'up' => 'down', 'down' => 'up' );
243 sub round_pow
244 78 ▶{
Subroutine round_pow: called CC=21 SCAR=30.6
Pod undocumented
245 78 my ( $what, $x ) = @_;
246  
247 78 ▶ croak( "incorrect number of arguments" )
Branch: 1 branch
BranchTrueFalseTotal
unless 2 == @_ 0 78 78
248 unless 2 == @_;
249  
250 78 ▶ if ( $x != 0.0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($x != 0) 76 2 78
251 {
252 76 my $xx = abs($x);
253 76 my $xlog = log10($xx);
254 76 my $ilog = int($xlog);
255  
256 76 ▶ $what = $flip{$what} if $x < 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if $x < 0 36 40 76
257  
258 76 ▶ $ilog--
Branch: 1 branch
BranchTrueFalseTotal
if $xlog <= 0 and "down" eq $what || $xlog != $ilog or $xlog > 0 and "down" eq $what and $xlog == $ilog 44 32 76
Condition100%15/15
$xlog <= 0 and "down" eq $what || $xlog != $ilog or $xlog > 0 and "down" eq $what and $xlog == $ilog
l!l&&r!l&&!r
40432
$xlog <= 0 and "down" eq $what || $xlog != $ilog
!ll&&!rl&&r
30640
"down" eq $what or $xlog != $ilog
l!l&&r!l&&!r
24166
$xlog > 0 and "down" eq $what and $xlog == $ilog
!ll&&!rl&&r
22104
$xlog > 0 and "down" eq $what
!ll&&!rl&&r
61614
MC/DC83%5/6
$xlog <= 0 and "down" eq $what || $xlog != $ilog or $xlog > 0 and "down" eq $what and $xlog == $ilog
$xlog <= 0 "down" eq $what $xlog != $ilog $xlog > 0 "down" eq $what $xlog == $ilog
Truth table60%6/10
A and B or C or D and E and F
A= $xlog <= 0B= "down" eq $whatC= $xlog != $ilogD= $xlog > 0E= "down" eq $whatF= $xlog == $ilog
ABCDEFresult
11XXXX1
101XXX1
0XX1111
1001111
0XX0XX0
0XX10X0
0XX1100
1000XX0
10010X0
1001100
259 if ( $xlog <= 0 && ( 'down' eq $what || $xlog != $ilog ) )
260 ||
261 ( $xlog > 0 && 'down' eq $what && $xlog == $ilog ) ;
262  
263 76 my $pwr = 10 ** $ilog;
264 76 my $frac = $xx / $pwr;
265  
266 76 my $i;
267 76 ▶ if ( 'up' eq $what )
Branch: 2 branches
BranchTrueFalseTotal
if ('up' eq $what) { } 38 38 76
elsif ('down' eq $what) { } 38 0 38
268 {
269 38 $i = 3;
270 38 ▶ $i = 2 if $frac < $nice[2];
Branch: 1 branch
BranchTrueFalseTotal
if $frac < $PDL::Graphics::Limits::nice[2] 26 12 38
271 38 ▶ $i = 1 if $frac < $nice[1];
Branch: 1 branch
BranchTrueFalseTotal
if $frac < $PDL::Graphics::Limits::nice[1] 12 26 38
272 38 ▶ $i = 0 if $frac < $nice[0];
Branch: 1 branch
BranchTrueFalseTotal
if $frac < $PDL::Graphics::Limits::nice[0] 0 38 38
273 38 ▶ my $t = ( $x < 0 ? -1 : 1 ) * $pwr * $nice[$i];
Branch: 1 branch
BranchTrueFalseTotal
$x < 0 ? : 18 20 38
274 0 ▶ if(abs($t - $x) < 0.0000001) {$i++}
Branch: 1 branch
BranchTrueFalseTotal
if (abs $t - $x < "1e-07") 0 38 38
275 }
276  
277 elsif ( 'down' eq $what )
278 {
279 38 $i = 0;
280 38 ▶ $i = 1 if $frac > $nice[1];
Branch: 1 branch
BranchTrueFalseTotal
if $frac > $PDL::Graphics::Limits::nice[1] 30 8 38
281 38 ▶ $i = 2 if $frac > $nice[2];
Branch: 1 branch
BranchTrueFalseTotal
if $frac > $PDL::Graphics::Limits::nice[2] 18 20 38
282 38 ▶ $i = 3 if $frac > $nice[3];
Branch: 1 branch
BranchTrueFalseTotal
if $frac > $PDL::Graphics::Limits::nice[3] 0 38 38
283 }
284  
285 76 ▶ $x = ( $x < 0 ? -1 : 1 ) * $pwr * $nice[$i];
Branch: 1 branch
BranchTrueFalseTotal
$x < 0 ? : 36 40 76
286 }
287  
288 78 $x;
289 }
290  
291 #####################################################################
292  
293 sub setup_multi
294 2 ▶{
Subroutine setup_multi: called CC=3 SCAR=13.1
Pod undocumented
295 2 my ( $common, $dim, $keys ) = @_;
296  
297 2 my @arr;
298  
299 2 ▶ if ( 'ARRAY' eq ref $common )
Branch: 2 branches
BranchTrueFalseTotal
if ('ARRAY' eq ref $common) { } 0 2 2
elsif ('HASH' eq ref $common) { } 0 2 2
300 {
301 0 return $common;
302 }
303  
304 elsif ( 'HASH' eq ref $common )
305 {
306 0 @arr[ 0..($dim-1)] = map { $common->{$_->{data}} } @{$keys};
307 }
308  
309 else
310 {
311 2 my $value = $common;
312 2 @arr = ($value) x $dim;
313 }
314  
315 2 \@arr;
316 }
317  
318 #####################################################################
319 # normalize_dsets
320 #
321 # transform the user's heterogeneous list of data sets into a regular
322 # list of data sets, each with the form
323 # { Vectors => \@vectors }
324 # where each vector is a hashref with the following keys:
325 # { data => $data,
326 # en => $err_n,
327 # ep => $err_p,
328 # trans => $trans }
329  
330 sub normalize_dsets
331 70 ▶{
Subroutine normalize_dsets: called CC=9 SCAR=22.4
Pod undocumented
332 70 my ( $attr, @udsets ) = @_;
333 70 my @dsets;
334  
335 70 ▶ while ( @udsets )
Branch: 1 branch
BranchTrueFalseTotal
if (@udsets) 109 69 178
336 {
337 109 my $ds = shift @udsets;
338 109 my $ref = ref $ds;
339  
340 # peek inside the array to see what's there. we can have the following
341 # [ scalar|ndarray, scalar|ndarray, ... ] -> a zero dimensional data set
342 # [ \@a, \@b, \@c, \%d, ... ] -> a bunch of data sets
343 # [ \%h, @keys ] -> a hash with its keys
344  
345 # scalar or ndarray, turn it into its own data set
346 109 ▶ if ( ! $ref || UNIVERSAL::isa($ds, 'PDL') )
Branch: 2 branches
BranchTrueFalseTotal
if (not $ref or UNIVERSAL::isa($ds, 'PDL')) { } 2 107 109
elsif ('ARRAY' eq $ref) { } 107 0 107
Condition66%2/3
not $ref or UNIVERSAL::isa($ds, "PDL")
l!l&&r!l&&!r
02107
MC/DC50%1/2
not $ref or UNIVERSAL::isa($ds, "PDL")
not $ref UNIVERSAL::isa($ds, "PDL")
Truth table66%2/3
not(A) or B
A= not $refB= UNIVERSAL::isa($ds, "PDL")
ABresult
1X1
011
000
347 {
348 push @dsets,
349 PDL::Graphics::Limits::DSet->new( $attr->{Min}, $attr->{Max},
350 2 { data => PDL::Core::topdl( $ds ) } );
351 }
352  
353 elsif ( 'ARRAY' eq $ref )
354 {
355 107 normalize_array( \@dsets, $attr, $ds );
356 }
357  
358 else
359 {
360 0 die( "data set: ", scalar @dsets + 1,
361 "illegal type in data set list: not an arrayref, scalar, or ndarray\n" );
362 }
363  
364 }
365  
366 # ensure data sets have the same dimensions
367 69 my %dim;
368 69 $dim{$_->ndim}++ foreach @dsets;
369  
370 # whoops. only one allowed
371 69 ▶ die( "data sets do not all have the same dimensionality\n" )
Branch: 1 branch
BranchTrueFalseTotal
if keys %dim > 1 1 68 69
372 if keys %dim > 1;
373  
374 68 ( $attr->{dims} ) = keys %dim;
375  
376 # clean up datasets.
377 68 my $idset = -1;
378 68 foreach my $dset ( @dsets )
379 {
380 120 $idset++;
381  
382 120 eval { $dset->validate( $attr ) };
383 120 ▶ if ( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 120 120
384 {
385 0 chomp $@;
386 0 die( "data set $idset: $@\n" );
387 }
388 }
389  
390 68 @dsets;
391 }
392  
393 #####################################################################
394  
395 # array refs in data set lists may be just a plain ol' data set, or
396 # it may contain a bunch of other stuff. here we deal with a single
397 # array ref. we tear it apart and (re)build data sets.
398 sub normalize_array
399 107 ▶{
Subroutine normalize_array: called CC=15 SCAR=27.4
Pod undocumented
400 107 my ( $dsets, $attr, $aref ) = @_;
401  
402 # if the first element is a hash, it's either a hash based data set
403 # with a bunch of attributes specific to that hash:
404 # [ \%h, @keys ] -> a hash with its keys
405 # in which case the rest of the elements are scalars, or its
406 # all hashes.
407  
408 eval
409 107 {
410 107 ▶ if ( 'HASH' eq ref $aref->[0] )
Branch: 1 branch
BranchTrueFalseTotal
if ('HASH' eq ref $aref->[0]) { } 27 80 107
411 {
412  
413 # all hashes?
414 27 ▶ if ( @$aref == grep { 'HASH' eq ref $_ } @$aref )
Branch: 2 branches
BranchTrueFalseTotal
if (@$aref == grep({'HASH' eq ref $_;} @$aref)) { } 20 7 27
elsif (@$aref > 1 and 1 == grep({ref $_;} @$aref)) { } 7 0 7
415 {
416 # can't do anything unless we've been told which hash keys
417 # we should use, as this format doesn't allow local specification
418 die( "must specify hash keys for hash based data set spec\n" )
419 20 ▶ unless defined $attr->{KeySpec} && scalar @{$attr->{KeySpec}};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attr->{"KeySpec"} and scalar @{$attr->{"KeySpec"};} 0 20 20
Condition50%1/2
defined $attr->{"KeySpec"} and scalar @{$attr->{"KeySpec"};}
!ll
020
MC/DC0%0/1
defined $attr->{"KeySpec"} and scalar @{$attr->{"KeySpec"};}
defined $attr->{"KeySpec"}
Truth table50%1/2
A
A= defined $attr->{"KeySpec"}
Aresult
00
11
420  
421 20 foreach ( @{$aref} )
422 {
423 36 push @$dsets, normalize_hash_dset($attr, $_, @{$attr->{Keys}} );
424 }
425 }
426  
427 # hash + scalars?
428 20 ▶ elsif ( @$aref > 1 && 1 == grep { ref $_ } @$aref )
Condition33%1/3
@$aref > 1 and 1 == grep({ref $_;} @$aref)
!ll&&!rl&&r
007
MC/DC0%0/2
@$aref > 1 and 1 == grep({ref $_;} @$aref)
@$aref > 1 1 == grep({ref $_;} @$aref)
Truth table33%1/3
A and B
A= @$aref > 1B= 1 == grep({ref $_;} @$aref)
ABresult
0X0
100
111
429 {
430 7 push @$dsets, normalize_hash_dset( $attr, @{$aref} )
431 }
432  
433 # something wrong
434 else
435 {
436 0 die( "hash based data specification has an unexpected element" );
437 }
438  
439 }
440  
441 # must be a list of vectors as either scalars, ndarrays, or array
442 # refs (vectors with attributes)
443 else
444 {
445 # for array based data sets, we have to accumulate vectors as we iterate
446 # through the array. they are stored here
447 80 my @vecs;
448  
449 80 for my $vec ( @$aref )
450 {
451 159 my $ref = ref $vec;
452  
453 eval
454 159 {
455 # naked scalar or ndarray: data vector with no attributes
456 159 ▶ if ( ! $ref || UNIVERSAL::isa($vec, 'PDL') )
Branch: 2 branches
BranchTrueFalseTotal
if (not $ref or UNIVERSAL::isa($vec, 'PDL')) { } 139 20 159
elsif ('ARRAY' eq $ref) { } 19 1 20
Condition100%3/3
not $ref or UNIVERSAL::isa($vec, "PDL")
l!l&&r!l&&!r
413520
MC/DC100%2/2
not $ref or UNIVERSAL::isa($vec, "PDL")
not $ref UNIVERSAL::isa($vec, "PDL")
Truth table100%3/3
not(A) or B
A= not $refB= UNIVERSAL::isa($vec, "PDL")
ABresult
1X1
011
000
457 {
458 139 push @vecs, { data => PDL::Core::topdl( $vec ) };
459 }
460  
461 # array: data vector with attributes
462 elsif ( 'ARRAY' eq $ref )
463 {
464 19 push @vecs, normalize_array_vec( $vec );
465 }
466  
467 else
468 {
469 1 die( 'vector ', @vecs+1, ": unexpected data type ($ref) in list of data sets\n" );
470 }
471 };
472  
473 159 ▶ if ( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 158 159
474 {
475 1 chomp $@;
476 1 die( 'vector ', @vecs+1, ": $@\n" );
477 }
478 }
479  
480 push @$dsets,
481 79 ▶ PDL::Graphics::Limits::DSet->new( $attr->{Min}, $attr->{Max}, @vecs )
Branch: 1 branch
BranchTrueFalseTotal
if @vecs 79 0 79
482 if @vecs;
483 }
484 };
485  
486 107 ▶ if ( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 106 107
487 {
488 1 chomp $@;
489 1 die( 'data set ', @$dsets+1, ": $@\n" );
490 }
491 }
492  
493 #####################################################################
494  
495 # parse an array based vector
496 sub normalize_array_vec
497 19 ▶{
Subroutine normalize_array_vec: called CC=12 SCAR=25.3
Pod undocumented
498 19 my ( $vec ) = @_;
499  
500 # we should have
501 # [ $data, [ $err | $err_n, $err_p ], [ \&func ] ]
502  
503 19 my @el = @$vec;
504  
505 19 ▶ die( "too few or too many entries in array based data set spec\n" )
Branch: 1 branch
BranchTrueFalseTotal
if @el < 1 or @el > 4 0 19 19
Condition33%1/3
@el < 1 or @el > 4
l!l&&r!l&&!r
0019
MC/DC0%0/2
@el < 1 or @el > 4
@el < 1 @el > 4
Truth table33%1/3
A or B
A= @el < 1B= @el > 4
ABresult
1X1
011
000
506 if @el < 1 || @el > 4;
507  
508 19 my %vec;
509 19 $vec{data} = PDL::Core::topdl( shift @el);
510  
511 # if last value is CODE, it's a trans
512 19 ▶ $vec{trans} = pop @el if 'CODE' eq ref $el[-1];
Branch: 1 branch
BranchTrueFalseTotal
if "CODE" eq ref $el[-1] 5 14 19
513  
514 19 ▶ if ( exists $el[2] )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $el[2]) 2 17 19
515 {
516 # if we have 3 elements and the last isn't undef, it's an error.
517 # it can't be CODE as we'd have stripped it off in the last statement
518 2 ▶ die( "illegal value for trans func: $el[2]\n" )
Branch: 1 branch
BranchTrueFalseTotal
if defined $el[2] 0 2 2
519 if defined $el[2];
520  
521 # we need to turn off trans for this element
522 2 $vec{trans} = undef;
523 2 pop @el;
524 }
525  
526 # two values? asymmetric errors
527 19 ▶ if ( @el == 2 )
Branch: 2 branches
BranchTrueFalseTotal
if (@el == 2) { } 8 11 19
elsif (@el == 1) { } 6 5 11
528 {
529 8 ▶ $vec{errn} = PDL::Core::topdl($el[0]) if defined $el[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $el[0] 3 5 8
530 8 ▶ $vec{errp} = PDL::Core::topdl($el[1]) if defined $el[1];
Branch: 1 branch
BranchTrueFalseTotal
if defined $el[1] 5 3 8
531 }
532  
533 # one value? symmetric errors
534 elsif ( @el == 1 )
535 {
536 6 ▶ $vec{errn} = PDL::Core::topdl($el[0]) if defined $el[0];
Branch: 1 branch
BranchTrueFalseTotal
if defined $el[0] 6 0 6
537 6 ▶ $vec{errp} = $vec{errn} if defined $vec{errn};
Branch: 1 branch
BranchTrueFalseTotal
if defined $vec{"errn"} 6 0 6
538 }
539  
540 19 \%vec;
541 }
542  
543 #####################################################################
544  
545 # this takes a hash and a hash key spec and generates a regularized
546 # data set array of the form
547 # [ { data => $data, ep => ..., en => ..., trans => }, ... ]
548 sub normalize_hash_dset
549 43 ▶{
Subroutine normalize_hash_dset: called CC=20 SCAR=30.7
Pod undocumented
550 43 my ( $attr, $ds, @keys ) = @_;
551  
552 43 my $KeySpec = $attr->{KeySpec};
553  
554 43 my @dset;
555  
556 die( "too many local VecKeys (", scalar @keys,
557 0 ") and global VecKeys (", scalar @{$KeySpec}, ")\n" )
558 43 ▶ if @keys && @{$KeySpec} && @{$KeySpec} <= @keys;
Branch: 1 branch
BranchTrueFalseTotal
if @keys and @{$KeySpec;} and @{$KeySpec;} <= @keys 0 43 43
Condition83%5/6
@keys and @{$KeySpec;} and @{$KeySpec;} <= @keys
!ll&&!rl&&r
4210
@keys and @{$KeySpec;}
!ll&&!rl&&r
3661
MC/DC0%0/3
@keys and @{$KeySpec;} and @{$KeySpec;} <= @keys
@keys @{$KeySpec;} @{$KeySpec;} <= @keys
Truth table75%3/4
A and B and C
A= @keysB= @{$KeySpec;}C= @{$KeySpec;} <= @keys
ABCresult
0XX0
10X0
1100
1111
559  
560 43 my @spec;
561  
562 # handle local keys
563 43 ▶ if ( @keys )
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) { } 7 36 43
564 {
565 7 my $nvec = 0;
566 7 for my $key ( @keys )
567 {
568 13 my %spec;
569  
570  
571 # parse the specs for this vector
572 13 eval { %spec = parse_vecspec( $key ) };
573 0 ▶ do { chomp $@; die( "vector $nvec: $@" ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 13 13
574 if $@;
575  
576  
577 # now, merge it with the global KeySpecs
578  
579 13 ▶ if ( @{$KeySpec} )
Branch: 1 branch
BranchTrueFalseTotal
if (@{$KeySpec;}) 1 12 13
580 {
581 1 my $Spec = $KeySpec->[$nvec];
582  
583 1 foreach ( keys %{$Spec} )
584 {
585 # only copy from Spec if not present in spec
586 1 ▶ $spec{$_} = $Spec->{$_} if ! exists $spec{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $spec{$_} 1 0 1
587 }
588 }
589  
590 13 push @spec, \%spec;
591 }
592 continue
593 {
594 13 $nvec++;
595 }
596  
597 # handle case where local VecKeys are a subst of global VecKeys
598 7 ▶ while ( @{$KeySpec} > @spec )
Branch: 1 branch
BranchTrueFalseTotal
if (@{$KeySpec;} > @spec) 1 7 8
599 {
600 1 push @spec, $KeySpec->[$nvec++];
601 }
602 }
603  
604 # no local keys; use global KeySpec
605 else
606 {
607 36 @spec = @{$KeySpec};
608 }
609  
610 43 my $nvec = 0;
611 43 for my $spec ( @spec )
612 {
613 86 $nvec++;
614 86 my %vec;
615  
616 die( "vector $nvec: no data spec?\n" )
617 86 ▶ unless exists $spec->{data};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $spec->{"data"} 0 86 86
618  
619 86 for my $el ( qw( data errn errp trans ) )
620 {
621 344 ▶ if ( exists $spec->{$el} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $spec->{$el}) 108 236 344
622 {
623  
624 # if not defined, don't bother looking for it in the data set
625 108 ▶ unless ( defined $spec->{$el} )
Branch: 3 branches
BranchTrueFalseTotal
if (defined $spec->{$el}) { } 107 1 108
if (do { exists $$ds{$spec->{$el}} }) { } 101 6 107
elsif ($attr->{'KeyCroak'}) { } 0 6 6
626 {
627 # trans is different from the others in that we need to pass
628 # it as undef if $spec->{trans} is undef (as full handling of
629 # trans is done elsewhere.
630 1 ▶ $vec{trans} = undef if 'trans' eq $el;
Branch: 1 branch
BranchTrueFalseTotal
if "trans" eq $el 1 0 1
631 }
632  
633 elsif ( exists $ds->{$spec->{$el}} )
634 {
635 101 $vec{$el} = $ds->{$spec->{$el}};
636 }
637  
638 elsif ( $attr->{KeyCroak} )
639 {
640 0 die( "vector $nvec: missing key in data set hash: ", $spec->{$el}, "\n" )
641 }
642 }
643  
644 }
645  
646 # missing data; certainly a fatal error.
647 die( "vector $nvec: no data for key $spec->{data}\n" )
648 86 ▶ unless defined $vec{data};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vec{"data"} 0 86 86
649  
650 86 push @dset, \%vec;
651 }
652  
653 43 PDL::Graphics::Limits::DSet->new( $attr->{Min}, $attr->{Max}, @dset );
654 }
655  
656 #####################################################################
657 # parse specifications for a hash based data set. These are the elements
658 # in the VecKeys attribute. See the docs for more details.
659 # Returns a hashref with keys data, en, ep, trans
660  
661 8 my $colre = qr/[^&<>=]/;
662  
663 # these are the different specs available.
664 8 my %keyre = ( data => qr/^($colre+)/,
665 errn => qr/<($colre*)/,
666 errp => qr/>($colre*)/,
667 err => qr/=($colre*)/,
668 trans => qr/\&($colre*)/
669 );
670  
671 8 my %vecspeckeys = ( data => 1,
672 err => 1,
673 errn => 1,
674 errp => 1,
675 trans => 1 );
676  
677 sub parse_vecspec
678 55 ▶{
Subroutine parse_vecspec: called CC=15 SCAR=30.4
Pod undocumented
679 55 my ( $ukeys ) = @_;
680  
681 55 my %k;
682  
683 # do we get a hash?
684 55 ▶ if ( 'HASH' eq ref $ukeys )
Branch: 1 branch
BranchTrueFalseTotal
if ('HASH' eq ref $ukeys) { } 0 55 55
685 {
686 # complain about keys we don't use
687 0 my @badkeys = grep { ! defined $vecspeckeys{$_} } keys %$ukeys;
688 0 ▶ die( "illegal keys: ", join(' ,', sort @badkeys), "\n" )
Branch: 1 branch
BranchTrueFalseTotal
if @badkeys 0 0 0
689 if @badkeys;
690  
691 # copy keys we need
692 0 ▶ do { $k{$_} = $ukeys->{$_} if exists $ukeys->{$_} }
Branch: 1 branch
BranchTrueFalseTotal
if exists $ukeys->{$_} 0 0 0
693 0 foreach keys %vecspeckeys;
694  
695 }
696  
697 # parse the string.
698 else
699 {
700  
701 # make a local copy, as we modify it in place.
702 55 my $keys = $ukeys;
703  
704 # deal with a "default" spec
705 55 ▶ if ( ! defined $keys )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $keys) { } 1 54 55
706 {
707 1 $keys = '';
708 }
709 else
710 {
711 # spaces and commas are there for human use only
712 54 $keys =~ s/[\s,]//g;
713 }
714  
715  
716 # extract the known specs.
717 55 my ( $what, $re );
718 55 ▶ $keys =~ s/$re// and $k{$what} = $1 while( ($what, $re) = each %keyre);
Branch: 2 branches
BranchTrueFalseTotal
() = each %keyre and do { $keys =~ s/$re// and $k{$what} = $1 } 275 55 330
$keys =~ s/$re// and $k{$what} = $1 81 194 275
719  
720 # if there's anything left, it's bogus
721 55 ▶ die( "illegal key specification: $ukeys\n" )
Branch: 1 branch
BranchTrueFalseTotal
unless $keys eq "" 1 54 55
722 unless $keys eq '';
723  
724 }
725  
726 # check for consistent error bar specs
727 die( "can't specify `=' with `<' or `>'\n" )
728 54 ▶ if exists $k{err} && ( exists $k{errn} || exists $k{errp} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $k{"err"} and exists $k{"errn"} || exists $k{"errp"} 0 54 54
Condition50%3/6
exists $k{"err"} and exists $k{"errn"} || exists $k{"errp"}
!ll&&!rl&&r
5130
exists $k{"errn"} or exists $k{"errp"}
l!l&&r!l&&!r
003
MC/DC0%0/3
exists $k{"err"} and exists $k{"errn"} || exists $k{"errp"}
exists $k{"err"} exists $k{"errn"} exists $k{"errp"}
Truth table50%2/4
A and B or C
A= exists $k{"err"}B= exists $k{"errn"}C= exists $k{"errp"}
ABCresult
0XX0
1000
11X1
1011
729  
730 # error bars are always specified as positive and negative; turn a symmetric
731 # spec into that
732 54 ▶ $k{errn} = $k{errp} = $k{err} if exists $k{err};
Branch: 1 branch
BranchTrueFalseTotal
if exists $k{"err"} 3 51 54
733 54 delete $k{err};
734  
735 # set empty values to undefined ones
736 54 ▶ do { $k{$_} = undef if $k{$_} eq '' } foreach keys %k;
Branch: 1 branch
BranchTrueFalseTotal
if $k{$_} eq "" 5 78 83
737  
738 54 %k;
739 }
740  
741 sub parse_vecspecs
742 50 ▶{
Subroutine parse_vecspecs: called CC=2 SCAR=6.9
Pod undocumented
743 50 my $keys = shift;
744 50 my @specs;
745  
746 push @specs, { parse_vecspec($_) }
747 50 foreach @$keys;
748  
749 50 \@specs;
750 }
751  
752 #####################################################################
753 # normalize user supplied limits
754  
755 sub parse_limits
756 49 ▶{
Subroutine parse_limits: called CC=23 SCAR=35.6
Pod undocumented
757 49 my ( $ndim, $spec, $KeySpec ) = @_;
758  
759 49 ▶ $spec = [] unless defined $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec 0 49 49
760  
761 49 my @limits;
762  
763 # array containing limits (as arrays or scalars)
764 49 ▶ if ( 'ARRAY' eq ref $spec )
Branch: 2 branches
BranchTrueFalseTotal
if ('ARRAY' eq ref $spec) { } 41 8 49
elsif ('HASH' eq ref $spec) { } 8 0 8
765 {
766 # no limits; just move on
767 41 ▶ unless ( @$spec )
Branch: 3 branches
BranchTrueFalseTotal
if (@$spec) { } 16 25 41
if (do { 'ARRAY' eq ref $spec->[0] }) { } 16 0 16
elsif (not ref $spec->[0]) { } 0 0 0
768 {
769 }
770  
771 # multi-dimensional data sets
772 elsif ( 'ARRAY' eq ref $spec->[0] )
773 {
774 16 my $ilim = 0;
775 16 for my $vlim ( @$spec )
776 {
777 25 $ilim++;
778 25 ▶ die( "Limit spec element $ilim: expected array ref\n" )
Branch: 1 branch
BranchTrueFalseTotal
if "ARRAY" ne ref $vlim 0 25 25
779 if 'ARRAY' ne ref $vlim;
780  
781 25 ▶ die( "Limit spec element $ilim: too many values\n" )
Branch: 1 branch
BranchTrueFalseTotal
if @$vlim > 2 0 25 25
782 if @$vlim > 2;
783  
784 die( "Limit spec element $vlim: values must be scalars\n" )
785 25 ▶ if grep { ref $_ } @$vlim;
Branch: 1 branch
BranchTrueFalseTotal
if grep {ref $_;} @$vlim 0 25 25
786  
787 25 my @lims = @$vlim;
788 25 ▶ $lims[0] = undef unless defined $lims[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lims[0] 13 12 25
789 25 ▶ $lims[1] = undef unless defined $lims[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lims[1] 13 12 25
790  
791 25 push @limits, \@lims;
792 }
793 }
794  
795 # one-dimensional data sets
796 elsif ( ! ref $spec->[0] )
797 {
798 die( "unexpected non-scalar element in Limits spec\n" )
799 0 ▶ if grep { ref $_ } @$spec;
Branch: 1 branch
BranchTrueFalseTotal
if grep {ref $_;} @$spec 0 0 0
800  
801 0 my @lims = @$spec;
802 0 ▶ $lims[0] = undef unless defined $lims[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lims[0] 0 0 0
803 0 ▶ $lims[1] = undef unless defined $lims[1];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lims[1] 0 0 0
804  
805 0 push @limits, \@lims;
806 }
807  
808 41 ▶ push @limits, [ undef, undef ]
Branch: 1 branch
BranchTrueFalseTotal
@limits != $ndim and do { push @limits, [undef, undef] } 56 41 97
809 while ( @limits != $ndim );
810  
811 }
812  
813 # hash containing vector names and limits
814 elsif ( 'HASH' eq ref $spec )
815 {
816 # first ensure that VecKeys has been specified
817 8 ▶ die( "cannot use Limits without VecKeys\n" )
Branch: 1 branch
BranchTrueFalseTotal
unless @$KeySpec 0 8 8
818 unless @$KeySpec;
819  
820 # make sure that we've got common keys.
821 8 my %vecs = map { ( $_->{data} => 1) } @$KeySpec;
822  
823 # identify unknown vectors
824 8 my @badvecs = grep { ! defined $vecs{$_} } keys %$spec;
825 8 ▶ die( 'unknown vector(s): ', join(', ', @badvecs), "\n" )
Branch: 1 branch
BranchTrueFalseTotal
if @badvecs 0 8 8
826 if @badvecs;
827  
828 # work our way through the KeySpec's, filling in values from
829 # $spec as appropriate.
830 8 for my $kspec ( @$KeySpec )
831 {
832 16 my @lims = ( undef, undef );
833 16 ▶ if ( exists $spec->{$kspec->{data}} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$spec{$kspec->{"data"}}) 8 8 16
834 {
835 8 my $lspec = $spec->{$kspec->{data}};
836 8 ▶ $lims[0] = $lspec->{min} if exists $lspec->{min};
Branch: 1 branch
BranchTrueFalseTotal
if exists $lspec->{"min"} 6 2 8
837 8 ▶ $lims[1] = $lspec->{max} if exists $lspec->{max};
Branch: 1 branch
BranchTrueFalseTotal
if exists $lspec->{"max"} 6 2 8
838 }
839 16 push @limits, \@lims;
840 }
841 }
842  
843 # say what?
844 else
845 {
846 0 die( "Limits attribute value must be a hashref or arrayref\n" );
847 }
848  
849 49 map { { calc => scalar ( grep { !defined $_ } @{$_} ), range => $_ } } @limits;
850 }
851  
852  
853  
854 #####################################################################
855  
856 sub limits
857 49 ▶{
Subroutine limits: called CC=22 SCAR=31.7
Pod documented
858 49 ▶ my $attr = 'HASH' eq ref $_[-1] ? pop @_ : {};
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq ref $_[-1] ? : 49 0 49
859  
860 49 my @udsets = @_;
861  
862 49 my %attr = iparse( {
863 Min => -1.8e308,
864 Max => +1.8e308,
865 Bounds => 'minmax',
866 Clean => 'RangeFrac',
867 RangeFrac => 0.05,
868 ZeroFix => 0,
869 VecKeys => [],
870 KeyCroak => 1,
871 Limits => [],
872 Trans => [],
873 }, $attr );
874  
875 # turn Trans and VecKeys into arrays if necessary; may be scalars for 1D
876 # data sets
877 $attr{$_} = [ $attr{$_} ]
878 49 ▶ foreach grep { defined $attr{$_} && 'ARRAY' ne ref $attr{$_} }
Condition33%1/3
defined $attr{$_} && 'ARRAY' ne ref $attr{$_}
!ll&&!rl&&r
0980
MC/DC0%0/2
defined $attr{$_} && 'ARRAY' ne ref $attr{$_}
defined $attr{$_} 'ARRAY' ne ref $attr{$_}
Truth table33%1/3
A && B
A= defined $attr{$_}B= 'ARRAY' ne ref $attr{$_}
ABresult
0X0
100
111
879 qw( VecKeys Trans );
880  
881 # parse vector key specs
882 49 $attr{KeySpec} = parse_vecspecs( $attr{VecKeys} );
883  
884 # normalize data sets to make life easier later. also
885 # counts up the number of dimensions and sets $attr{dims}
886 49 my @dsets = normalize_dsets( \%attr, @udsets );
887  
888 # set up the Limits
889 49 my @limits = parse_limits( $attr{dims}, $attr{Limits}, $attr{KeySpec} );
890  
891 49 ▶ if ( 'minmax' eq lc $attr{Bounds} )
Branch: 2 branches
BranchTrueFalseTotal
if ('minmax' eq lc $attr{'Bounds'}) { } 40 9 49
elsif ('zscale' eq lc $attr{'Bounds'}) { } 9 0 9
892 {
893 40 for my $dim ( 0..$attr{dims}-1 )
894 {
895 # only calculate minmax values for those dims which need them.
896 79 my $limits = $limits[$dim];
897  
898 79 foreach ( @dsets )
899 {
900 # calculate min & max
901 $_->calc_minmax( $dim )
902 157 ▶ if $limits->{calc};
Branch: 1 branch
BranchTrueFalseTotal
if $limits->{"calc"} 141 16 157
903  
904 # make sure we pay attention to user specified limits
905 157 $_->set_minmax( @{$limits->{range}}, $dim );
906 }
907 }
908 }
909  
910 elsif ( 'zscale' eq lc $attr{Bounds} )
911 {
912 croak( "zscale only good for dim = 2\n" )
913 9 ▶ unless $attr{dims} == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr{"dims"} == 2 0 9 9
914  
915 9 foreach my $dset ( @dsets )
916 {
917 $dset->calc_minmax( 0 )
918 17 ▶ if $limits[0]{calc};
Branch: 1 branch
BranchTrueFalseTotal
if $limits[0]{"calc"} 13 4 17
919  
920  
921 17 ▶ if ( $limits[1]{calc} )
Branch: 1 branch
BranchTrueFalseTotal
if ($limits[1]{"calc"}) 13 4 17
922 {
923 13 my $y = $dset->vector(1)->{data};
924  
925 # this is a waste, as we don't care about the evaluated
926 # fit values, just the min and max values. since we
927 # get them all anyway, we'll use them.
928  
929 13 my $mask = PDL::null;
930 13 set_mask( $mask, $y );
931  
932 13 my $fit = fitpoly1d( $y->where($mask)->qsort, 2 );
933 13 $dset->set_minmax( $fit->minmax, 1 );
934 }
935  
936 17 $dset->set_minmax( @{$limits[$_]{range}}, $_ ) for 0,1;
937 }
938 }
939 else
940 {
941 0 die( "unknown Bounds type: $attr{Bounds}\n" );
942 }
943  
944 # derive union of minmax limits from data sets
945 49 my $minmax = PDL::Core::null;
946 49 $minmax = append( $minmax, $_->get_minmax ) foreach @dsets;
947  
948 # get overall minmax limits
949 49 $minmax = cat(($minmax->minmaximum)[0,1])->transpose;
950  
951 49 my @minmax = map{ [ $minmax->slice(":,$_")->list ] } 0..$attr{dims}-1;
952  
953 49 ▶ if ( 'rangefrac' eq lc $attr{Clean} )
Branch: 3 branches
BranchTrueFalseTotal
if ('rangefrac' eq lc $attr{'Clean'}) { } 1 48 49
elsif ('roundpow' eq lc $attr{'Clean'}) { } 1 47 48
elsif ('none' eq lc $attr{'Clean'}) { } 47 0 47
954 {
955 my $RangeFrac =
956 1 setup_multi( $attr{RangeFrac}, $attr{dims}, $attr{KeySpec} );
957  
958 my $ZeroFix =
959 1 setup_multi( $attr{ZeroFix}, $attr{dims}, $attr{KeySpec} );
960  
961 range_frac( $minmax[$_], $RangeFrac->[$_], $ZeroFix->[$_] )
962 1 for 0..$attr{dims}-1;
963 }
964  
965 elsif ( 'roundpow' eq lc $attr{Clean} )
966 {
967 $_ = [ round_pow( down => $_->[0] ),
968 round_pow( up => $_->[1] ) ]
969 1 foreach @minmax;
970 }
971  
972 elsif ( 'none' eq lc $attr{Clean} )
973 {
974 # do nothing
975 }
976  
977 else
978 {
979 0 die( "unknown Clean type: $attr{Clean}\n" );
980 }
981  
982 49 ▶ if ( wantarray )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 48 1 49
983 {
984 48 return map { ( @{$_} ) } @minmax;
985 }
986 else
987 {
988 1 my @key;
989 1 ▶ if ( @{$attr{KeySpec}} )
Branch: 1 branch
BranchTrueFalseTotal
if (@{$attr{'KeySpec'};}) { } 0 1 1
990 {
991 0 @key = map { $_->{data} } @{$attr{KeySpec}};
992 }
993 else
994 {
995 1 @key = map { 'q' . $_ } ( 1 .. $attr{dims} );
996 }
997  
998 1 return { map { ( $key[$_] => { min => $minmax[$_][0],
999 max => $minmax[$_][1] } ) }
1000 0.. ( @minmax - 1 ) };
1001 }
1002 }
1003  
1004 8 1;
1005  
1006  
1007 __END__
↑ Summary