| 1 | ############################################## | ||||||||||||||||||||||||||||||||
| 2 | package PDL::PP::PdlDimsObj; # Hold more dims | ||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | sub new { | ||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | my($type) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 7 | bless {},$type; | |||||||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | sub get_indobj_make { | ||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | my($this,$expr) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_indobj_make: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | $expr =~ /^([a-zA-Z0-9]+)(?:=([0-9]+))?$/ or confess "Invalid index expr '$expr'\n"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 13 | 11 | my $name = $1; my $val = $2; | |||||||||||||||||||||||||||||||
| 14 | 11 | my $indobj; | |||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | if(defined $this->{$name}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 16 | 3 | $indobj = $this->{$name}; | |||||||||||||||||||||||||||||||
| 17 | } else { | ||||||||||||||||||||||||||||||||
| 18 | 8 | $indobj = PDL::PP::Ind->new($name); | |||||||||||||||||||||||||||||||
| 19 | 8 | $this->{$name}=$indobj; | |||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||
| 21 | 11 | ▶ | if(defined $val) { $indobj->add_value($val); } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 22 | 11 | return $indobj; | |||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | ##################################################################### | ||||||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||||||
| 27 | # Encapsulate one index. | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | package PDL::PP::Ind; | ||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | sub new { | ||||||||||||||||||||||||||||||||
| 33 | 8 | ▶ | my($type,$name) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 34 | 8 | my $this = bless {Name => $name},$type; | |||||||||||||||||||||||||||||||
| 35 | 8 | return $this; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | # set the value of an index, also used by perl level threading | ||||||||||||||||||||||||||||||||
| 39 | sub add_value { | ||||||||||||||||||||||||||||||||
| 40 | 10 | ▶ | my($this,$val) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
add_value: called CC=7 SCAR=20.4
| |||||||||||||||||||||||||||||||||
| 41 | 10 | ▶ | croak("index values for $this->{Name} must be positive") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | unless $val > 0; | ||||||||||||||||||||||||||||||||
| 43 | 10 | ▶ | if(defined $this->{Value}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | 4 | ▶ | if ($this->{Value} == -1 || $this->{Value} == 1) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$this->{"Value"} == -1 or $this->{"Value"} == 1
MC/DC0%0/2
$this->{"Value"} == -1 or $this->{"Value"} == 1
$this->{"Value"} == -1
$this->{"Value"} == 1
Truth table33%1/3
A or B
A= $this->{"Value"} == -1B= $this->{"Value"} == 1
| |||||||||||||||||||||||||||||||||
| 45 | 0 | { $this->{Value} = $val } | |||||||||||||||||||||||||||||||
| 46 | ▶ | elsif($val != 1 && $val != $this->{Value}) { | |||||||||||||||||||||||||||||||
|
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"}
| |||||||||||||||||||||||||||||||||
| 47 | 2 | croak("For index $this->{Name} conflicting values $this->{Value} and $val given\n"); | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||||||
| 50 | 6 | $this->{Value} = $val; | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | # This index will take its size value from outside parameter ... | ||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub set_from { my($this,$otherpar) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
set_from: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 56 | 0 | $this->{From} = $otherpar; | |||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 32 | ▶ | sub name {return (shift)->{Name}} | ||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 1 | ▶ | sub get_decldim { my($this) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_decldim: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 62 | 1 | return "PDL_Indx __$this->{Name}_size;"; | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub get_initdim { my($this) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_initdim: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||
| 66 | 1 | my $init = '-1'; | |||||||||||||||||||||||||||||||
| 67 | $init = "\$COMP(".$this->{From}->{ProtoName}.")" | ||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | if $this->{From}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | $init = $this->{Value} if defined $this->{Value}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | 1 | "\$PRIV(__$this->{Name}_size) = $init;" | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | sub get_copydim { my($this,$fromsub,$tosub) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_copydim: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 74 | 1 | my($iname) = "__$this->{Name}_size"; | |||||||||||||||||||||||||||||||
| 75 | 1 | &$tosub($iname) ."=". &$fromsub($iname) .";" ; | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | sub get_size { my($this) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
get_size: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 79 | 2 | "\$PRIV(__$this->{Name}_size)" | |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 3 | 1; | |||||||||||||||||||||||||||||||