blib/lib/Math/Histo/2D.pm

filter: Statementstmt 93.0% 67 / 72 Branchbran 56.2% 18 / 32 Conditioncond 41.3% 12 / 29 MC/DCmcdc 13.3% 2 / 15 Subroutinesub 92.8% 13 / 14 Podpod 80.0% 4 / 5 totaltotal 69.4% 116 / 167 CC 27 SCAR 26.0
CC
27
Cov
73%
new
24.7
plot
16.0
__ANON__
3.2
CRAP 13.4
↑ Summary blib/lib/Math/Histo.pm »
1 package Math::Histo::2D;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Math::Histo ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Math::Histo::Constants qw(:flags);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 our $VERSION = '0.4.2';
9  
10  
11 6 ▶sub new {
Subroutine new: called CC=13 SCAR=32.1
Pod documented
12 6 my ($class, %args) = @_;
13 6 ▶ my $flags = $args{flags} // HISTO_FLAG_NONE;
Condition50%1/2
$args{"flags"} // 0
l!l
06
MC/DC0%0/1
$args{"flags"} // 0
$args{"flags"}
Truth table50%1/2
A
A= $args{"flags"}
Aresult
11
00
14 6 ▶ $flags |= HISTO_FLAG_TRACK_SUMW2 if $args{sumw2} || $args{track_sumw2};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"sumw2"} or $args{"track_sumw2"} 2 4 6
Condition66%2/3
$args{"sumw2"} or $args{"track_sumw2"}
l!l&&r!l&&!r
204
MC/DC50%1/2
$args{"sumw2"} or $args{"track_sumw2"}
$args{"sumw2"} $args{"track_sumw2"}
Truth table66%2/3
A or B
A= $args{"sumw2"}B= $args{"track_sumw2"}
ABresult
1X1
011
000
15 6 ▶ $flags |= HISTO_FLAG_EXACT_MOMENTS if $args{exact_moments};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"exact_moments"} 0 6 6
16  
17 6 ▶ if (exists $args{xedges} && exists $args{yedges}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $args{'xedges'} and exists $args{'yedges'}) { } 1 5 6
elsif (exists $args{'xbins'} and exists $args{'xmin'} and exists $args{'xmax'} and exists $args{'ybins'} and exists $args{'ymin'} and exists $args{'ymax'}) { } 5 0 5
Condition66%2/3
exists $args{"xedges"} and exists $args{"yedges"}
!ll&&!rl&&r
501
MC/DC50%1/2
exists $args{"xedges"} and exists $args{"yedges"}
exists $args{"xedges"} exists $args{"yedges"}
Truth table66%2/3
A and B
A= exists $args{"xedges"}B= exists $args{"yedges"}
ABresult
0X0
100
111
18 1 return $class->_create_variable($args{xedges}, $args{yedges}, $flags);
19 ▶ } elsif (exists $args{xbins} && exists $args{xmin} && exists $args{xmax} &&
Condition33%5/15
exists $args{"xbins"} and exists $args{"xmin"} and exists $args{"xmax"} and exists $args{"ybins"} and exists $args{"ymin"} and exists $args{"ymax"}
!ll&&!rl&&r
005
exists $args{"xbins"} and exists $args{"xmin"} and exists $args{"xmax"} and exists $args{"ybins"} and exists $args{"ymin"}
!ll&&!rl&&r
005
exists $args{"xbins"} and exists $args{"xmin"} and exists $args{"xmax"} and exists $args{"ybins"}
!ll&&!rl&&r
005
exists $args{"xbins"} and exists $args{"xmin"} and exists $args{"xmax"}
!ll&&!rl&&r
005
exists $args{"xbins"} and exists $args{"xmin"}
!ll&&!rl&&r
005
MC/DC0%0/6
exists $args{"xbins"} and exists $args{"xmin"} and exists $args{"xmax"} and exists $args{"ybins"} and exists $args{"ymin"} and exists $args{"ymax"}
exists $args{"xbins"} exists $args{"xmin"} exists $args{"xmax"} exists $args{"ybins"} exists $args{"ymin"} exists $args{"ymax"}
Truth table14%1/7
A and B and C and D and E and F
A= exists $args{"xbins"}B= exists $args{"xmin"}C= exists $args{"xmax"}D= exists $args{"ybins"}E= exists $args{"ymin"}F= exists $args{"ymax"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
20 exists $args{ybins} && exists $args{ymin} && exists $args{ymax}) {
21 return $class->_create_uniform(
22 $args{xbins}, $args{xmin}, $args{xmax},
23 $args{ybins}, $args{ymin}, $args{ymax},
24 5 $flags
25 );
26 } else {
27 0 die "Math::Histo::2D->new: missing required binning parameters (specify xbins/xmin/xmax/ybins/ymin/ymax or xedges/yedges)";
28 }
29 }
30  
31 4 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
32 4 my ($self) = @_;
33 4 return $self->_clone;
34 }
35  
36 1 ▶sub from_binary {
Subroutine from_binary: called CC=1 SCAR=0.0
Pod documented
37 1 my ($class, $blob) = @_;
38 1 return $class->_deserialize_binary($blob);
39 }
40  
41 0 ▶sub from_json {
Subroutine from_json: not called CC=1 SCAR=6.9
Pod documented
42 0 my ($class, $json_str) = @_;
43 0 return $class->_deserialize_json($json_str);
44 }
45  
46 1 ▶sub plot {
Subroutine plot: called CC=12 SCAR=27.7
Pod undocumented
47 1 my ($self, %opts) = @_;
48 1 require Math::Histo::CLI;
49 1 require File::Temp;
50  
51 1 my @cmd = ('plot');
52 1 ▶ push @cmd, "--style=$opts{style}" if defined $opts{style};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"style"} 0 1 1
53 1 ▶ if (exists $opts{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"color"}) 1 0 1
54 1 ▶ push @cmd, $opts{color} ? '--color=always' : '--color=never';
Branch: 1 branch
BranchTrueFalseTotal
$opts{'color'} ? : 0 1 1
55 }
56 1 ▶ push @cmd, "--palette=$opts{palette}" if defined $opts{palette};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"palette"} 1 0 1
57 1 ▶ push @cmd, "-w=$opts{width}" if defined $opts{width};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"width"} 0 1 1
58 1 ▶ push @cmd, "-H=$opts{height}" if defined $opts{height};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"height"} 0 1 1
59 1 ▶ push @cmd, '-l' if $opts{log};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"log"} 0 1 1
60  
61 1 my $tf = File::Temp->new(SUFFIX => '.json', UNLINK => 1);
62 1 print $tf $self->serialize_json;
63 1 close $tf;
64 1 push @cmd, $tf->filename;
65  
66 1 my ($code, $out, $err) = Math::Histo::CLI->capture(@cmd);
67 1 ▶ die "Math::Histo::2D::plot failed: $err" if $code != 0 && $err;
Branch: 1 branch
BranchTrueFalseTotal
if $code != 0 and $err 0 1 1
Condition33%1/3
$code != 0 and $err
!ll&&!rl&&r
100
MC/DC0%0/2
$code != 0 and $err
$code != 0 $err
Truth table33%1/3
A and B
A= $code != 0B= $err
ABresult
0X0
100
111
68 1 ▶ print $out if !defined $opts{show} || $opts{show};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $opts{"show"} or $opts{"show"} 0 1 1
Condition33%1/3
not defined $opts{"show"} or $opts{"show"}
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $opts{"show"} or $opts{"show"}
not defined $opts{"show"} $opts{"show"}
Truth table33%1/3
not(A) or B
A= not defined $opts{"show"}B= $opts{"show"}
ABresult
1X1
011
000
69 1 return $out;
70 }
71  
72 use overload
73 1 ▶ '+' => sub { my ($a, $b) = @_; my $c = $a->clone; $c->add($b); $c },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
74 1 ▶ '-' => sub { my ($a, $b) = @_; my $c = $a->clone; $c->subtract($b); $c },
Subroutine __ANON__: called CC=1 SCAR=0.0
75 1 ▶ '*' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
76 1 my ($a, $b, $swap) = @_;
77 1 my $c = $a->clone;
78 0 ▶ if (ref($b)) { $c->multiply($b); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $b) { } 0 1 1
79 1 else { $c->scale($b); }
80 1 $c;
81 },
82 1 ▶ '/' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.6
83 1 my ($a, $b, $swap) = @_;
84 1 my $c = $a->clone;
85 0 ▶ if (ref($b)) { $c->divide($b); }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $b) { } 0 1 1
86 1 ▶ else { die "Division by zero" if $b == 0; $c->scale(1.0 / $b); }
Branch: 1 branch
BranchTrueFalseTotal
if $b == 0 0 1 1
87 1 $c;
88 },
89 11 fallback => 1;
90  
91 11 *fill_packed = \&fill_packed_f64;
92  
93 11 1;
94  
95  
96 __END__
↑ Summary blib/lib/Math/Histo.pm »