| 1 | package Math::Histo::PDL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = '0.4.0'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Math::Histo 0.4.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Math::Histo::2D; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use PDL 2.000 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 4 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | hist1d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | hist2d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | fill_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | fill2d_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | to_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | to_pdl2d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | pdl_to_histo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | histo_to_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | counts_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | edges_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | centers_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | errors_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | matrix_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | x_edges_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | y_edges_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | x_centers_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | y_centers_pdl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | all => \@EXPORT_OK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Internal helper: extract packed byte buffer from a PDL object for zero-copy ingestion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | sub _ensure_packed_double { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 51 | ▶ | my ($pdl) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ensure_packed_double: called CC=7 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 51 | ▶ | if (!eval { $pdl->isa('PDL') }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if (ref($pdl) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $pdl = PDL::pdl(PDL::double(), $pdl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | croak "Math::Histo::PDL: input must be a PDL piddle or arrayref"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 51 | ▶ | return ('', 0) if $pdl->isempty || $pdl->nelem == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pdl->isempty or $pdl->nelem == 0
MC/DC50%1/2
$pdl->isempty or $pdl->nelem == 0
$pdl->isempty
$pdl->nelem == 0
Truth table66%2/3
A or B
A= $pdl->isemptyB= $pdl->nelem == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 48 | ▶ | my $d = ($pdl->type eq 'double') ? $pdl : $pdl->double; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 48 | ▶ | $d = $d->flat unless $d->ndims == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 48 | $d = $d->make_physical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 48 | my $dataref = $d->get_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 48 | return ($$dataref, $d->nelem); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # 1D Ingestion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | sub fill_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 17 | ▶ | my ($self, $data, $weights) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fill_pdl: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | croak "Math::Histo::PDL: first argument must be a Math::Histo object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 17 | ▶ | unless eval { $self->isa('Math::Histo') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 17 | ▶ | croak "Math::Histo::PDL: data piddle is required" unless defined $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 17 | my ($x_bytes, $n_x) = _ensure_packed_double($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 17 | ▶ | return $self if $n_x == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 16 | ▶ | if (defined $weights) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | my ($w_bytes, $n_w) = _ensure_packed_double($weights); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | ▶ | if ($n_w != $n_x) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | croak "Math::Histo::PDL::fill_pdl: weights length ($n_w) must match data length ($n_x)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | $self->fill_packed_f64($x_bytes, $w_bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 13 | $self->fill_packed_f64($x_bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 15 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # 2D Ingestion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | sub fill2d_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | ▶ | my ($self, @args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fill2d_pdl: called CC=15 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | croak "Math::Histo::PDL: first argument must be a Math::Histo::2D object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 15 | ▶ | unless eval { $self->isa('Math::Histo::2D') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | my ($x_pdl, $y_pdl, $weights); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 15 | ▶ | if (@args == 1 || (@args == 2 && eval { $args[0]->isa('PDL') } && $args[0]->ndims == 2)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition88%8/9
@args == 1 or @args == 2 and eval {
do {
$args[0]->isa("PDL")
}
} and $args[0]->ndims == 2
@args == 2 and eval {
do {
$args[0]->isa("PDL")
}
} and $args[0]->ndims == 2
@args == 2 and eval {
do {
$args[0]->isa("PDL")
}
}
MC/DC75%3/4
@args == 1 or @args == 2 and eval {
do {
$args[0]->isa("PDL")
}
} and $args[0]->ndims == 2
@args == 1
@args == 2
eval {
do {
$args[0]->isa("PDL")
}
}
$args[0]->ndims == 2
Truth table80%4/5
A or B and C and D
A= @args == 1B= @args == 2C= eval {
do {
$args[0]->isa("PDL")
}
}D= $args[0]->ndims == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Single 2D coordinate matrix: (2, N) or (N, 2), plus optional weights | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | my $coords = $args[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ▶ | $weights = $args[1] if @args == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | if ($coords->dim(0) == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | $x_pdl = $coords->slice('(0),:')->flat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | $y_pdl = $coords->slice('(1),:')->flat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } elsif ($coords->dim(1) == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $x_pdl = $coords->slice(',(0)')->flat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $y_pdl = $coords->slice(',(1)')->flat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | croak "Math::Histo::PDL::fill2d_pdl: coordinate matrix must have dimension 2 along axis 0 or 1 (got " . join('x', $coords->dims) . ")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | ▶ | } elsif (@args == 2 || @args == 3) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
@args == 2 or @args == 3
MC/DC0%0/2
@args == 2 or @args == 3
@args == 2
@args == 3
Truth table66%2/3
A or B
A= @args == 2B= @args == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 13 | ($x_pdl, $y_pdl, $weights) = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | croak "Math::Histo::PDL::fill2d_pdl: invalid arguments (expected (\$h2d, \$x, \$y, [\$weights]) or (\$h2d, \$coords, [\$weights]))"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 14 | my ($x_bytes, $n_x) = _ensure_packed_double($x_pdl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 14 | my ($y_bytes, $n_y) = _ensure_packed_double($y_pdl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 14 | ▶ | if ($n_x != $n_y) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | croak "Math::Histo::PDL::fill2d_pdl: X length ($n_x) and Y length ($n_y) must match"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 13 | ▶ | return $self if $n_x == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 12 | ▶ | if (defined $weights) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | my ($w_bytes, $n_w) = _ensure_packed_double($weights); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | ▶ | if ($n_w != $n_x) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | croak "Math::Histo::PDL::fill2d_pdl: weights length ($n_w) must match data length ($n_x)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | $self->fill_packed_f64($x_bytes, $y_bytes, $w_bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 9 | $self->fill_packed_f64($x_bytes, $y_bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 11 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # 1D Export to PDL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | sub counts_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
counts_pdl: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | croak "Math::Histo::PDL: argument must be a Math::Histo object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | ▶ | unless eval { $self->isa('Math::Histo') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 5 | my $contents = $self->bin_contents; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | my $packed = pack('d*', @$contents); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | my $p = PDL->new_from_specification(PDL::double(), scalar(@$contents)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | ${$p->get_dataref} = $packed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 5 | $p->upd_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 5 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | sub edges_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
edges_pdl: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | croak "Math::Histo::PDL: argument must be a Math::Histo object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | ▶ | unless eval { $self->isa('Math::Histo') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | my $edges = $self->bin_edges; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | my $packed = pack('d*', @$edges); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | my $p = PDL->new_from_specification(PDL::double(), scalar(@$edges)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 5 | ${$p->get_dataref} = $packed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 5 | $p->upd_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 5 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | sub centers_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
centers_pdl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | my $edges = edges_pdl($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | return ($edges->slice('0:-2') + $edges->slice('1:-1')) / 2.0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | sub errors_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errors_pdl: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | croak "Math::Histo::PDL: argument must be a Math::Histo object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | ▶ | unless eval { $self->isa('Math::Histo') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | my $n = $self->nbins; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | ▶ | my @errors = map { $self->bin_error($_) // 0.0 } 0 .. $n - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->bin_error($_) // 0
MC/DC0%0/1
$self->bin_error($_) // 0
$self->bin_error($_)
Truth table50%1/2
A
A= $self->bin_error($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 3 | my $packed = pack('d*', @errors); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | my $p = PDL->new_from_specification(PDL::double(), $n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | ${$p->get_dataref} = $packed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | $p->upd_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | sub to_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_pdl: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | ▶ | if (wantarray && !%opts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
wantarray and not %opts
MC/DC50%1/2
wantarray and not %opts
wantarray
not %opts
Truth table66%2/3
A and not(B)
A= wantarrayB= not %opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | return (counts_pdl($self), edges_pdl($self), errors_pdl($self)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | ▶ | if ($opts{all}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | counts => counts_pdl($self), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | edges => edges_pdl($self), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | centers => centers_pdl($self), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | errors => errors_pdl($self), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | return counts_pdl($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # 2D Export to PDL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | sub matrix_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
matrix_pdl: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | croak "Math::Histo::PDL: argument must be a Math::Histo::2D object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | ▶ | unless eval { $self->isa('Math::Histo::2D') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 5 | my $nx = $self->nx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | my $ny = $self->ny; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | my $packed = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 5 | for my $iy (0 .. $ny - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 13 | for my $ix (0 .. $nx - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 49 | $packed .= pack('d', $self->bin_content($ix, $iy)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 5 | my $p = PDL->new_from_specification(PDL::double(), $nx, $ny); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 5 | ${$p->get_dataref} = $packed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 5 | $p->upd_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 5 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | sub x_edges_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_edges_pdl: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | croak "Math::Histo::PDL: argument must be a Math::Histo::2D object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 5 | ▶ | unless eval { $self->isa('Math::Histo::2D') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 5 | my $nx = $self->nx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 5 | my @edges; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 5 | for my $ix (0 .. $nx - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 15 | my ($x0, $x1) = $self->bin_bounds($ix, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 15 | push @edges, $x0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 15 | ▶ | push @edges, $x1 if $ix == $nx - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 5 | my $packed = pack('d*', @edges); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 5 | my $p = PDL->new_from_specification(PDL::double(), scalar(@edges)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 5 | ${$p->get_dataref} = $packed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | $p->upd_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 5 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | sub y_edges_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
y_edges_pdl: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | croak "Math::Histo::PDL: argument must be a Math::Histo::2D object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 5 | ▶ | unless eval { $self->isa('Math::Histo::2D') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 5 | my $ny = $self->ny; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 5 | my @edges; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | for my $iy (0 .. $ny - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 10 | my (undef, undef, $y0, $y1) = $self->bin_bounds(0, $iy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 10 | push @edges, $y0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 10 | ▶ | push @edges, $y1 if $iy == $ny - 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | my $packed = pack('d*', @edges); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | my $p = PDL->new_from_specification(PDL::double(), scalar(@edges)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | ${$p->get_dataref} = $packed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 5 | $p->upd_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 5 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | sub x_centers_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
x_centers_pdl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | my $edges = x_edges_pdl($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | return ($edges->slice('0:-2') + $edges->slice('1:-1')) / 2.0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | sub y_centers_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
y_centers_pdl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | my $edges = y_edges_pdl($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | return ($edges->slice('0:-2') + $edges->slice('1:-1')) / 2.0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | sub errors2d_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errors2d_pdl: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | croak "Math::Histo::PDL: argument must be a Math::Histo::2D object" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | ▶ | unless eval { $self->isa('Math::Histo::2D') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | my $nx = $self->nx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | my $ny = $self->ny; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | my $packed = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | for my $iy (0 .. $ny - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | for my $ix (0 .. $nx - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 12 | ▶ | $packed .= pack('d', $self->bin_error($ix, $iy) // 0.0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->bin_error($ix, $iy) // 0
MC/DC0%0/1
$self->bin_error($ix, $iy) // 0
$self->bin_error($ix, $iy)
Truth table50%1/2
A
A= $self->bin_error($ix, $iy)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | my $p = PDL->new_from_specification(PDL::double(), $nx, $ny); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | ${$p->get_dataref} = $packed; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | $p->upd_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | return $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | sub to_pdl2d { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 4 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_pdl2d: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 4 | ▶ | if (wantarray && !%opts) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
wantarray and not %opts
MC/DC50%1/2
wantarray and not %opts
wantarray
not %opts
Truth table66%2/3
A and not(B)
A= wantarrayB= not %opts
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | return (matrix_pdl($self), x_edges_pdl($self), y_edges_pdl($self)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 3 | ▶ | if ($opts{all}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | matrix => matrix_pdl($self), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | x_edges => x_edges_pdl($self), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | y_edges => y_edges_pdl($self), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | x_centers => x_centers_pdl($self), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | y_centers => y_centers_pdl($self), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | errors => errors2d_pdl($self), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | return matrix_pdl($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # High-level functional builders | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | sub hist1d { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 9 | ▶ | my ($data, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hist1d: called CC=21 SCAR=35.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 9 | ▶ | my $pdl = eval { $data->isa('PDL') } ? $data : PDL::pdl($data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 9 | my $weights = delete $opts{weights}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 9 | my $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 9 | ▶ | if (exists $opts{edges}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | my $edges = $opts{edges}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | my @edges_arr = eval { $edges->isa('PDL') } ? $edges->list : @$edges; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | delete $opts{edges}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | $h = Math::Histo->new(edges => \@edges_arr, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | ▶ | } elsif (exists $opts{rule} || exists $opts{auto}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
exists $opts{"rule"} or exists $opts{"auto"}
MC/DC50%1/2
exists $opts{"rule"} or exists $opts{"auto"}
exists $opts{"rule"}
exists $opts{"auto"}
Truth table66%2/3
A or B
A= exists $opts{"rule"}B= exists $opts{"auto"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | ▶ | my $rule = delete $opts{rule} // delete $opts{auto}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $opts{"rule"} // delete $opts{"auto"}
MC/DC0%0/2
delete $opts{"rule"} // delete $opts{"auto"}
delete $opts{"rule"}
delete $opts{"auto"}
Truth table33%1/3
A // B
A= delete $opts{"rule"}B= delete $opts{"auto"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | my @samples = $pdl->list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | my ($nbins, $min, $max) = Math::Histo->estimate_bins(\@samples, $rule); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | if ($min == $max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $min -= 0.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $max += 0.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | my $margin = ($max - $min) * 1e-6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | ▶ | $max += ($margin > 0 ? $margin : 1e-6); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | $h = Math::Histo->new(bins => $nbins, min => $min, max => $max, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 7 | ▶ | my $nbins = delete $opts{bins} // delete $opts{nbins} // 50; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
(delete $opts{"bins"} // delete $opts{"nbins"}) // 50
delete $opts{"bins"} // delete $opts{"nbins"}
MC/DC0%0/2
(delete $opts{"bins"} // delete $opts{"nbins"}) // 50
delete $opts{"bins"}
delete $opts{"nbins"}
Truth table33%1/3
A // B
A= delete $opts{"bins"}B= delete $opts{"nbins"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 7 | my $min = delete $opts{min}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 7 | my $max = delete $opts{max}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 7 | ▶ | if (!defined $min || !defined $max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $min and defined $max
MC/DC50%1/2
defined $min and defined $max
defined $min
defined $max
Truth table66%2/3
A and B
A= defined $minB= defined $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | ▶ | if ($pdl->nelem > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | my ($pmin, $pmax) = $pdl->minmax; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 1 | ▶ | $min //= $pmin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$min //= $pmin
MC/DC0%0/2
$min //= $pmin
$min
$pmin
Truth table33%1/3
A //= B
A= $minB= $pmin
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | ▶ | if (!defined $max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | ▶ | if ($pmin == $pmax) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $min -= 0.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $max = $pmax + 0.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | my $margin = ($pmax - $pmin) * 1e-6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | ▶ | $max = $pmax + ($margin > 0 ? $margin : 1e-6); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | $min //= 0.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$min //= 0
MC/DC0%0/1
$min //= 0
$min
Truth table0%0/2
A
A= $min
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | $max //= 1.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$max //= 1
MC/DC0%0/1
$max //= 1
$max
Truth table0%0/2
A
A= $max
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 7 | $h = Math::Histo->new(bins => $nbins, min => $min, max => $max, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 9 | ▶ | fill_pdl($h, $pdl, $weights) if $pdl->nelem > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 9 | return $h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | sub hist2d { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 9 | ▶ | my (@args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hist2d: called CC=37 SCAR=43.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 9 | my ($x, $y, $coords, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 9 | ▶ | if (@args >= 1 && eval { $args[0]->isa('PDL') } && $args[0]->ndims == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
@args >= 1 and eval {
do {
$args[0]->isa("PDL")
}
} and $args[0]->ndims == 2
@args >= 1 and eval {
do {
$args[0]->isa("PDL")
}
}
MC/DC33%1/3
@args >= 1 and eval {
do {
$args[0]->isa("PDL")
}
} and $args[0]->ndims == 2
@args >= 1
eval {
do {
$args[0]->isa("PDL")
}
}
$args[0]->ndims == 2
Truth table50%2/4
A and B and C
A= @args >= 1B= eval {
do {
$args[0]->isa("PDL")
}
}C= $args[0]->ndims == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 5 | $coords = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 5 | %opts = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 5 | ▶ | if ($coords->dim(0) == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 3 | $x = $coords->slice('(0),:')->flat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | $y = $coords->slice('(1),:')->flat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | } elsif ($coords->dim(1) == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | $x = $coords->slice(',(0)')->flat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | $y = $coords->slice(',(1)')->flat; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | croak "Math::Histo::PDL::hist2d: coordinate matrix must have 2 columns or 2 rows (got " . join('x', $coords->dims) . ")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 4 | $x = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 4 | $y = shift @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 4 | %opts = @args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 4 | ▶ | $x = PDL::pdl($x) unless eval { $x->isa('PDL') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 4 | ▶ | $y = PDL::pdl($y) unless eval { $y->isa('PDL') }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 8 | my $weights = delete $opts{weights}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 8 | my $h2d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 8 | ▶ | if (exists $opts{xedges} && exists $opts{yedges}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $opts{"xedges"} and exists $opts{"yedges"}
MC/DC50%1/2
exists $opts{"xedges"} and exists $opts{"yedges"}
exists $opts{"xedges"}
exists $opts{"yedges"}
Truth table66%2/3
A and B
A= exists $opts{"xedges"}B= exists $opts{"yedges"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | my $xe = delete $opts{xedges}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | my $ye = delete $opts{yedges}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | ▶ | my @x_arr = eval { $xe->isa('PDL') } ? $xe->list : @$xe; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | ▶ | my @y_arr = eval { $ye->isa('PDL') } ? $ye->list : @$ye; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | $h2d = Math::Histo::2D->new(xedges => \@x_arr, yedges => \@y_arr, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 7 | my ($xbins, $ybins); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 7 | ▶ | if (exists $opts{bins}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | my $b = delete $opts{bins}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | ▶ | if (ref($b) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ($xbins, $ybins) = @$b; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | $xbins = $ybins = $b; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 7 | ▶ | $xbins //= delete $opts{xbins} // 50; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$xbins //= delete $opts{"xbins"} // 50
delete $opts{"xbins"} // 50
MC/DC0%0/2
$xbins //= delete $opts{"xbins"} // 50
$xbins
delete $opts{"xbins"}
Truth table66%2/3
A //= B
A= $xbinsB= delete $opts{"xbins"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 7 | ▶ | $ybins //= delete $opts{ybins} // 50; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$ybins //= delete $opts{"ybins"} // 50
delete $opts{"ybins"} // 50
MC/DC0%0/2
$ybins //= delete $opts{"ybins"} // 50
$ybins
delete $opts{"ybins"}
Truth table66%2/3
A //= B
A= $ybinsB= delete $opts{"ybins"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 7 | my $xmin = delete $opts{xmin}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 7 | my $xmax = delete $opts{xmax}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 7 | my $ymin = delete $opts{ymin}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 7 | my $ymax = delete $opts{ymax}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 7 | ▶ | if (!defined $xmin || !defined $xmax) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $xmin and defined $xmax
MC/DC50%1/2
defined $xmin and defined $xmax
defined $xmin
defined $xmax
Truth table66%2/3
A and B
A= defined $xminB= defined $xmax
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | ▶ | if ($x->nelem > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | my ($min, $max) = $x->minmax; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1 | ▶ | $xmin //= $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$xmin //= $min
MC/DC0%0/2
$xmin //= $min
$xmin
$min
Truth table33%1/3
A //= B
A= $xminB= $min
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | ▶ | if (!defined $xmax) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 1 | ▶ | if ($min == $max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $xmin -= 0.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $xmax = $max + 0.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | my $margin = ($max - $min) * 1e-6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | ▶ | $xmax = $max + ($margin > 0 ? $margin : 1e-6); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | $xmin //= 0.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$xmin //= 0
MC/DC0%0/1
$xmin //= 0
$xmin
Truth table0%0/2
A
A= $xmin
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | $xmax //= 1.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$xmax //= 1
MC/DC0%0/1
$xmax //= 1
$xmax
Truth table0%0/2
A
A= $xmax
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 7 | ▶ | if (!defined $ymin || !defined $ymax) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ymin and defined $ymax
MC/DC50%1/2
defined $ymin and defined $ymax
defined $ymin
defined $ymax
Truth table66%2/3
A and B
A= defined $yminB= defined $ymax
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | if ($y->nelem > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | my ($min, $max) = $y->minmax; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | $ymin //= $min; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ymin //= $min
MC/DC0%0/2
$ymin //= $min
$ymin
$min
Truth table33%1/3
A //= B
A= $yminB= $min
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | ▶ | if (!defined $ymax) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | ▶ | if ($min == $max) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $ymin -= 0.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | $ymax = $max + 0.5; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 1 | my $margin = ($max - $min) * 1e-6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 1 | ▶ | $ymax = $max + ($margin > 0 ? $margin : 1e-6); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | ▶ | $ymin //= 0.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ymin //= 0
MC/DC0%0/1
$ymin //= 0
$ymin
Truth table0%0/2
A
A= $ymin
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | $ymax //= 1.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ymax //= 1
MC/DC0%0/1
$ymax //= 1
$ymax
Truth table0%0/2
A
A= $ymax
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 7 | $h2d = Math::Histo::2D->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | xbins => $xbins, xmin => $xmin, xmax => $xmax, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | ybins => $ybins, ymin => $ymin, ymax => $ymax, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | %opts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 8 | ▶ | if ($x->nelem > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 8 | fill2d_pdl($h2d, $x, $y, $weights); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 8 | return $h2d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | sub pdl_to_histo { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 2 | ▶ | my ($pdl, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pdl_to_histo: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 2 | ▶ | if (eval { $pdl->isa('PDL') } && $pdl->ndims == 2 && ($pdl->dim(0) == 2 || $pdl->dim(1) == 2)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
eval {
do {
$pdl->isa("PDL")
}
} and $pdl->ndims == 2 and $pdl->dim(0) == 2 || $pdl->dim(1) == 2
eval {
do {
$pdl->isa("PDL")
}
} and $pdl->ndims == 2
$pdl->dim(0) == 2 or $pdl->dim(1) == 2
MC/DC0%0/4
eval {
do {
$pdl->isa("PDL")
}
} and $pdl->ndims == 2 and $pdl->dim(0) == 2 || $pdl->dim(1) == 2
eval {
do {
$pdl->isa("PDL")
}
}
$pdl->ndims == 2
$pdl->dim(0) == 2
$pdl->dim(1) == 2
Truth table20%1/5
A and B and C or D
A= eval {
do {
$pdl->isa("PDL")
}
}B= $pdl->ndims == 2C= $pdl->dim(0) == 2D= $pdl->dim(1) == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | return hist2d($pdl, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | return hist1d($pdl, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | sub histo_to_pdl { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 2 | ▶ | my ($h, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
histo_to_pdl: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 2 | ▶ | if (eval { $h->isa('Math::Histo::2D') }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | return to_pdl2d($h, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | return to_pdl($h, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # Inject OO extension methods into Math::Histo and Math::Histo::2D upon module load | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 4 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 4 | *Math::Histo::fill_pdl = \&fill_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 4 | *Math::Histo::to_pdl = \&to_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 4 | *Math::Histo::counts_pdl = \&counts_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 4 | *Math::Histo::edges_pdl = \&edges_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 4 | *Math::Histo::centers_pdl = \¢ers_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 4 | *Math::Histo::errors_pdl = \&errors_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 4 | *Math::Histo::2D::fill_pdl = \&fill2d_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 4 | *Math::Histo::2D::to_pdl = \&to_pdl2d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 4 | *Math::Histo::2D::matrix_pdl = \&matrix_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 4 | *Math::Histo::2D::counts_pdl = \&matrix_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 4 | *Math::Histo::2D::x_edges_pdl = \&x_edges_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 4 | *Math::Histo::2D::y_edges_pdl = \&y_edges_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 4 | *Math::Histo::2D::x_centers_pdl = \&x_centers_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 4 | *Math::Histo::2D::y_centers_pdl = \&y_centers_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 4 | *Math::Histo::2D::errors_pdl = \&errors2d_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||