| 1 | ############################################## | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package # hide from PAUSE/MetaCPAN | ||||||||||||||||||||||||||||||||||||||||||
| 3 | PDL::PP::PdlDimsObj; # Hold more dims | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 247 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 247 | my($type) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 247 | bless {},$type; | |||||||||||||||||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 160 | ▶ | sub get_indobj_make { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_indobj_make: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 160 | my ($this,$expr,$calc,$orig_inds,$par_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 160 | ▶ | my ($name, $val) = $expr =~ /^([a-zA-Z0-9]+)(?:=([0-9]+))?$/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | or confess "Invalid index expr in Par '$par_name' '$expr' while parsing '$orig_inds'\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 160 | ▶ | confess "Error: both simple value '$val' and CALC '$calc'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$calc and defined $val
MC/DC0%0/2
$calc and defined $val
$calc
defined $val
Truth table66%2/3
A and B
A= $calcB= defined $val
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | if $calc && defined $val; | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 160 | ▶ | $val //= $calc; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$val //= $calc
MC/DC100%2/2
$val //= $calc
$val
$calc
Truth table100%3/3
A //= B
A= $valB= $calc
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 160 | ▶ | my $indobj = $this->{$name} //= PDL::PP::Ind->new($name); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$this->{$name} //= "PDL::PP::Ind"->new($name)
MC/DC0%0/2
$this->{$name} //= "PDL::PP::Ind"->new($name)
$this->{$name}
"PDL::PP::Ind"->new($name)
Truth table66%2/3
A //= B
A= $this->{$name}B= "PDL::PP::Ind"->new($name)
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 160 | ▶ | $indobj->add_value($val) if defined $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 160 | return $indobj; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 103 | ▶ | sub ind_obj {$_[0]{$_[1]}} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ind_obj: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 264 | ▶ | sub ind_names {keys %{$_[0]}} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ind_names: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 59 | ▶ | sub ind_fromcomp {grep defined $_->{From}, values %{$_[0]}} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ind_fromcomp: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 59 | ▶ | sub ind_notfromcomp {grep !defined $_->{From}, values %{$_[0]}} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ind_notfromcomp: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # Encapsulate one index. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | package # hide from PAUSE/MetaCPAN | ||||||||||||||||||||||||||||||||||||||||||
| 35 | PDL::PP::Ind; | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 118 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 118 | my($type,$name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 118 | bless {Name => $name},$type; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | # set the value of an index, also used by perl level broadcasting | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 57 | ▶ | sub add_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_value: called CC=8 SCAR=21.3
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 57 | my($this,$val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 57 | ▶ | croak("index values for $this->{Name} must be positive") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$val =~ /^\d+$/ and $val <= 0
MC/DC0%0/2
$val =~ /^\d+$/ and $val <= 0
$val =~ /^\d+$/
$val <= 0
Truth table66%2/3
A and B
A= $val =~ /^\d+$/B= $val <= 0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | if $val =~ /^\d+$/ and $val <= 0; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | return $this->{Value} = $val if | ||||||||||||||||||||||||||||||||||||||||||
| 49 | !defined $this->{Value} or | ||||||||||||||||||||||||||||||||||||||||||
| 50 | $this->{Value} == -1 or | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 57 | ▶ | $this->{Value} == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not defined $this->{"Value"} or $this->{"Value"} == -1 or $this->{"Value"} == 1
not defined $this->{"Value"} or $this->{"Value"} == -1
MC/DC33%1/3
not defined $this->{"Value"} or $this->{"Value"} == -1 or $this->{"Value"} == 1
not defined $this->{"Value"}
$this->{"Value"} == -1
$this->{"Value"} == 1
Truth table50%2/4
not(A) or B or C
A= not defined $this->{"Value"}B= $this->{"Value"} == -1C= $this->{"Value"} == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | croak "For index $this->{Name} conflicting values $this->{Value} and $val given\n" if $val != 1 && $val != $this->{Value}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$val != 1 and $val != $this->{"Value"}
MC/DC100%2/2
$val != 1 and $val != $this->{"Value"}
$val != 1
$val != $this->{"Value"}
Truth table100%3/3
A and B
A= $val != 1B= $val != $this->{"Value"}
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # This index will take its size value from outside parameter ... | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | sub set_from { my($this,$otherpar) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_from: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | $this->{From} = $otherpar; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 417 | ▶ | sub name {$_[0]{Name}} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # where it occurs in the C arrays that track it (at least name and size) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 94 | ▶ | sub set_index { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_index: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 94 | my ($this, $i) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 94 | $this->{Index} = $i; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 56 | ▶ | sub get_index {$_[0]{Index} // confess "unknown index for $_[0]{Name}"} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_index: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]{"Index"} // confess(qq[unknown index for $_[0]{"Name"}])
MC/DC0%0/1
$_[0]{"Index"} // confess(qq[unknown index for $_[0]{"Name"}])
$_[0]{"Index"}
Truth table50%1/2
A
A= $_[0]{"Index"}
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 58 | ▶ | sub get_initdim { my($this) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_initdim: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | my $init = $this->{Value} // | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 58 | ▶ | ($this->{From} ? "\$COMP(".$this->{From}{ProtoName}.")" : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$this->{"Value"} // ($this->{"From"} ? '$COMP(' . $this->{"From"}{"ProtoName"} . ')' : undef)
MC/DC100%1/1
$this->{"Value"} // ($this->{"From"} ? '$COMP(' . $this->{"From"}{"ProtoName"} . ')' : undef)
$this->{"Value"}
Truth table100%2/2
A
A= $this->{"Value"}
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 58 | ▶ | return if !defined $init; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | $this->get_size." = $init;" | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 17 | ▶ | sub get_size { my($this) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_size: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 17 | "\$PRIV(ind_sizes)[@{[$this->get_index]}]" | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||