blib/lib/PDL/PP/PdlParObj.pm

filter: Statementstmt 90.1% 119 / 132 Branchbran 66.1% 41 / 62 Conditioncond 55.0% 11 / 20 MC/DCmcdc 30.7% 4 / 13 Subroutinesub 95.2% 20 / 21 Podpod 0.0% 0 / 17 totaltotal 73.5% 195 / 265 CC 43 SCAR 20.5
CC
43
Cov
80%
new
15.4
do_indterm
12.0
adjusted_type
11.1
CRAP 7.8
« blib/lib/PDL/PP/Signature.pm ↑ Summary blib/lib/PDL/IO/Dumper.pm »
1 package # hide from PAUSE/MetaCPAN
2 PDL::PP::PdlParObj;
3  
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use PDL::Types ':All';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 our %INVALID_PAR = map +($_=>1), qw(
10 I
11 );
12  
13 4 my $typeregex = join '|', map $_->ppforcetype, types;
14 4 my $complex_regex = join '|', qw(real complex !real !complex);
15 4 our $sqbr_re = qr/\[([^]]*)\]/x;
16 4 our $pars_re = qr/^
17 \s*(?:($complex_regex|$typeregex)\b([+]*)|)\s* # $1,2: first option then plus
18 (?:$sqbr_re)?\s* # $3: The initial [option] part
19 (\w+) # $4: The name
20 \((.*)\) # $5: The indices
21 \s*\Z # that's all
22 /xs;
23 4 my %flag2info = (
24 io => [[qw(FlagW)]],
25 o => [[qw(FlagOut FlagCreat FlagW)]],
26 oca => [[qw(FlagOut FlagCreat FlagW FlagCreateAlways)]],
27 t => [[qw(FlagTemp FlagCreat FlagW)]],
28 phys => [[qw(FlagPhys)]],
29 real => [[qw(FlagTypeOverride FlagReal)]],
30 complex => [[qw(FlagTypeOverride FlagComplex)]],
31 '!real' => [[qw(FlagTypeOverride FlagNotReal)]],
32 '!complex' => [[qw(FlagTypeOverride FlagNotComplex)]],
33 (map +($_->ppforcetype => [[qw(FlagTypeOverride FlagTyped)], 'Type']), types),
34 );
35 4 my %flag2c = qw(
36 FlagReal PDL_PARAM_ISREAL
37 FlagComplex PDL_PARAM_ISCOMPLEX
38 FlagNotReal PDL_PARAM_ISNOTREAL
39 FlagNotComplex PDL_PARAM_ISNOTCOMPLEX
40 FlagTyped PDL_PARAM_ISTYPED
41 FlagTplus PDL_PARAM_ISTPLUS
42 FlagCreat PDL_PARAM_ISCREAT
43 FlagCreateAlways PDL_PARAM_ISCREATEALWAYS
44 FlagOut PDL_PARAM_ISOUT
45 FlagTemp PDL_PARAM_ISTEMP
46 FlagW PDL_PARAM_ISWRITE
47 FlagPhys PDL_PARAM_ISPHYS
48 FlagIgnore PDL_PARAM_ISIGNORE
49 );
50 4 my $calc_re = qr{
51 (\w+)\s*=\s* # paren group 1 (dim name) - from perlre/PARNO
52 CALC
53 ( # paren group 2 (parens)
54 \(
55 ( # paren group 3 (contents of parens)
56 (?:
57 (?> [^()]+ ) # Non-parens without backtracking
58 |
59 (?2) # Recurse to start of paren group 2
60 )*
61 )
62 \)
63 )
64 }xo;
65 sub new {
66 125 ▶ my ($type,$string,$opname) = @_;
Subroutine new: called CC=15 SCAR=27.4
Pod undocumented
67 125 ▶ $string =~ $pars_re or croak "pp_def($opname): Invalid pdl def $string (regex $pars_re)\n";
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /$PDL::PP::PdlParObj::pars_re/sx or croak("pp_def($opname): Invalid pdl def $string (regex $PDL::PP::PdlParObj::pars_re)\n") 0 125 125
68 125 my $this = bless {Number => "PDL_UNDEF_NUMBER", OpName=>$opname},$type;
69 125 ▶ my($opt1,$opt_plus,$sqbr_opt,$name,$inds) = map $_ // '', $1,$2,$3,$4,$5;
Condition100%2/2
$_ // ""
l!l
390235
MC/DC100%1/1
$_ // ""
$_
Truth table100%2/2
A
A= $_
Aresult
11
00
70 125 $this->{OrigInds} = $inds;
71 125 ▶ print "PDL: '$opt1$opt_plus', '$sqbr_opt', '$name', '$inds'\n"
Branch: 1 branch
BranchTrueFalseTotal
if $main::PP_VERBOSE 0 125 125
72 if $::PP_VERBOSE;
73 125 ▶ croak "pp_def($opname): Invalid Pars name: $name" if $INVALID_PAR{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::PP::PdlParObj::INVALID_PAR{$name} 1 124 125
74 # Set my internal variables
75 124 $this->{Name} = $name;
76 124 ▶ $this->{Flags} = [(split ',',$sqbr_opt),($opt1?$opt1:())];
Branch: 1 branch
BranchTrueFalseTotal
$opt1 ? : 4 120 124
77 124 for(@{$this->{Flags}}) {
78 croak("pp_def($opname): Invalid flag $_ given for $string\n")
79 53 ▶ unless my ($set, $store) = @{ $flag2info{$_} || [] };
Branch: 2 branches
BranchTrueFalseTotal
unless () = @{$flag2info{$_} or [];} 0 53 53
$flag2info{$_} or [] 0 53 53
80 53 ▶ $this->{$store} = $_ if $store;
Branch: 1 branch
BranchTrueFalseTotal
if $store 4 49 53
81 53 $this->{$_} = 1 for @$set;
82 }
83 124 ▶ $this->{FlagTplus} = 1 if $this->{FlagTyped} && $opt_plus;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"FlagTyped"} and $opt_plus 1 123 124
Condition100%3/3
$this->{"FlagTyped"} and $opt_plus
!ll&&!rl&&r
12031
MC/DC100%2/2
$this->{"FlagTyped"} and $opt_plus
$this->{"FlagTyped"} $opt_plus
Truth table100%3/3
A and B
A= $this->{"FlagTyped"}B= $opt_plus
ABresult
0X0
100
111
84 124 ▶ $this->{Type} &&= PDL::Type->new($this->{Type});
Condition66%2/3
$this->{"Type"} &&= "PDL::Type"->new($this->{"Type"})
!ll&&!rl&&r
12004
MC/DC50%1/2
$this->{"Type"} &&= "PDL::Type"->new($this->{"Type"})
$this->{"Type"} "PDL::Type"->new($this->{"Type"})
Truth table66%2/3
A &&= B
A= $this->{"Type"}B= "PDL::Type"->new($this->{"Type"})
ABresult
0X0
100
111
85 124 $this->{Ind2Calc} = \my %ind2calc;
86 124 ▶ $ind2calc{$1} = $3 while $inds =~ s#$calc_re#$1#;
Branch: 1 branch
BranchTrueFalseTotal
$inds =~ s/$calc_re/$1/x and do { $ind2calc{$1} = $3 } 0 124 124
87 $this->{RawInds} = [map{
88 124 s/\s//g; # Remove spaces
89 114 $_;
90 } split ',', $inds];
91 124 return $this;
92 }
93  
94 sub cflags {
95 16 ▶ my ($this) = @_;
Subroutine cflags: called CC=1 SCAR=0.0
Pod undocumented
96 16 map $flag2c{$_}, grep $this->{$_}, sort keys %flag2c;
97 }
98  
99 420 ▶sub name {$_[0]{Name}}
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
100  
101 sub add_inds {
102 154 ▶ my($this,$dimsobj) = @_;
Subroutine add_inds: called CC=1 SCAR=0.0
Pod undocumented
103 154 $this->{IndObjs} = [my @objs = map $dimsobj->get_indobj_make($_, $this->{Ind2Calc}{$_}, $this->{OrigInds}, $this->{Name}), @{$this->{RawInds}}];
104 154 my %indcount;
105 154 $this->{IndCounts} = [ map 0+($indcount{$_->name}++), @objs ];
106 154 $this->{IndTotCounts} = [ map $indcount{$_->name}, @objs ];
107 }
108  
109  
110 # do the dimension checking for perl level broadcasting
111 # assumes that IndObjs have been created
112 sub perldimcheck {
113 30 ▶ my ($this,$pdl) = @_;
Subroutine perldimcheck: called CC=6 SCAR=18.1
Pod undocumented
114 croak ("can't create ".$this->name) if $pdl->isnull &&
115 30 ▶ !$this->{FlagCreat};
Branch: 1 branch
BranchTrueFalseTotal
if $pdl->isnull and not $this->{"FlagCreat"} 0 30 30
Condition66%2/3
$pdl->isnull and not $this->{"FlagCreat"}
!ll&&!rl&&r
2280
MC/DC0%0/2
$pdl->isnull and not $this->{"FlagCreat"}
$pdl->isnull not $this->{"FlagCreat"}
Truth table66%2/3
A and not(B)
A= $pdl->isnullB= not $this->{"FlagCreat"}
ABresult
0X0
100
111
116 30 ▶ return 1 if $pdl->isnull;
Branch: 1 branch
BranchTrueFalseTotal
if $pdl->isnull 8 22 30
117 22 my $rdims = @{$this->{RawInds}};
118 22 ▶ croak ("not enough dimensions for ".$this->name)
Branch: 1 branch
BranchTrueFalseTotal
if ($pdl->broadcastids)[0] < $rdims 0 22 22
119 if ($pdl->broadcastids)[0] < $rdims;
120 22 my @dims = $pdl->dims;
121 22 my ($i,$ind) = (0,undef);
122 22 for $ind (@{$this->{IndObjs}}) {
123 18 $ind->add_value($dims[$i++]);
124 }
125 20 return 0; # not creating
126 }
127  
128 sub finalcheck {
129 27 ▶ my ($this,$pdl) = @_;
Subroutine finalcheck: called CC=4 SCAR=13.9
Pod undocumented
130 27 ▶ return [] if $pdl->isnull;
Branch: 1 branch
BranchTrueFalseTotal
if $pdl->isnull 8 19 27
131 19 my @corr = ();
132 19 my @dims = $pdl->dims;
133 19 my $i = 0;
134 19 for my $ind (@{$this->{IndObjs}}) {
135 15 ▶ push @corr,[$i-1,$ind->{Value},$dims[$i-1]] if $dims[$i++] != $ind->{Value};
Branch: 1 branch
BranchTrueFalseTotal
if $dims[$i++] != $ind->{"Value"} 1 14 15
136 }
137 19 return \@corr;
138 }
139  
140 # get index sizes for a parameter that has to be created
141 sub getcreatedims {
142 8 ▶ my $this = shift;
Subroutine getcreatedims: called CC=3 SCAR=11.8
Pod undocumented
143 return map
144 { croak "pp_def($this->{OpName}): can't create: index size ".$_->name." not initialised"
145 1 ▶ if !defined($_->{Value}) || $_->{Value} < 1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_->{"Value"} or $_->{"Value"} < 1 0 1 1
Condition33%1/3
not defined $_->{"Value"} or $_->{"Value"} < 1
l!l&&r!l&&!r
001
MC/DC0%0/2
not defined $_->{"Value"} or $_->{"Value"} < 1
not defined $_->{"Value"} $_->{"Value"} < 1
Truth table33%1/3
not(A) or B
A= not defined $_->{"Value"}B= $_->{"Value"} < 1
ABresult
1X1
011
000
146 8 $_->{Value} } @{$this->{IndObjs}};
147 }
148  
149 sub adjusted_type {
150 168 ▶ my ($this, $generic) = @_;
Subroutine adjusted_type: called CC=8 SCAR=24.0
Pod undocumented
151 168 ▶ confess "adjusted_type given undefined generic type\n" if !defined $generic;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $generic 0 168 168
152 168 ▶ return $generic->realversion if $this->{FlagReal} || $this->{FlagNotComplex};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"FlagReal"} or $this->{"FlagNotComplex"} 0 168 168
Condition33%1/3
$this->{"FlagReal"} or $this->{"FlagNotComplex"}
l!l&&r!l&&!r
00168
MC/DC0%0/2
$this->{"FlagReal"} or $this->{"FlagNotComplex"}
$this->{"FlagReal"} $this->{"FlagNotComplex"}
Truth table33%1/3
A or B
A= $this->{"FlagReal"}B= $this->{"FlagNotComplex"}
ABresult
1X1
011
000
153 168 ▶ return $generic->complexversion if $this->{FlagComplex};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"FlagComplex"} 0 168 168
154 168 ▶ return $generic unless $this->{FlagTyped};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"FlagTyped"} 120 48 168
155 return $this->{Type}->numval > $generic->numval
156 ? $this->{Type} : $generic
157 48 ▶ if $this->{FlagTplus};
Branch: 2 branches
BranchTrueFalseTotal
if $this->{"FlagTplus"} 0 48 48
$this->{'Type'}->numval > $generic->numval ? : 0 0 0
158 48 $this->{Type};
159 }
160  
161 22 ▶sub get_nname{ my($this) = @_;
Subroutine get_nname: called CC=1 SCAR=0.0
Pod undocumented
162 22 "(\$PRIV(pdls)[$this->{Number}])";
163 }
164  
165 sub get_substname {
166 18 ▶ my($this,$ind) = @_;
Subroutine get_substname: called CC=2 SCAR=7.2
Pod undocumented
167 18 ▶ $this->{IndObjs}[$ind]->name.($this->{IndTotCounts}[$ind] > 1 ? $this->{IndCounts}[$ind] : '');
Branch: 1 branch
BranchTrueFalseTotal
$this->{'IndTotCounts'}[$ind] > 1 ? : 0 18 18
168 }
169  
170 sub get_incname {
171 36 ▶ my($this,$ind,$for_local) = @_;
Subroutine get_incname: called CC=2 SCAR=6.9
Pod undocumented
172 36 ▶ return "inc_sizes[PDL_INC_ID(__privtrans->vtable,$this->{Number},$ind)]" if !$for_local;
Branch: 1 branch
BranchTrueFalseTotal
unless $for_local 18 18 36
173 18 "__inc_$this->{Name}_".$this->get_substname($ind);
174 }
175  
176 sub get_incregisters {
177 18 ▶ my($this) = @_;
Subroutine get_incregisters: called CC=2 SCAR=6.9
Pod undocumented
178 18 ▶ return '' if scalar(@{$this->{IndObjs}}) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$this->{"IndObjs"};} == 0 2 16 18
179 join '', map {
180 18 my $x = $_;
181 18 my ($name, $for_local) = map $this->get_incname($x, $_), 0, 1;
182 18 "register PDL_Indx $for_local = __privtrans->$name; (void)$for_local;";
183 16 } 0..$#{$this->{IndObjs}};
184 }
185  
186 # Print an access part.
187 sub do_access {
188 2 ▶ my($this,$inds,$context) = @_;
Subroutine do_access: called CC=6 SCAR=20.7
Pod undocumented
189 2 my $pdl = $this->{Name};
190 my %subst = map {
191 2 ▶ if (!/^\s*(\w+)\s*=>\s*(\S*)\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^\s*(\w+)\s*=>\s*(\S*)\s*$/) 2 0 2
192 2 my $msg = "Invalid subst '$_' in \$$pdl($inds):";
193 2 ▶ $msg .= " no '=>' seen" if !/=>/;
Branch: 1 branch
BranchTrueFalseTotal
unless /=>/ 1 1 2
194 2 ▶ $msg .= " invalid dim name '$1'" if /^\s*([^\w]*?)\s*=>/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*([^\w]*?)\s*=>/ 0 2 2
195 2 ▶ $msg .= " (no spaces in => value)" if /=>\s*\S\s*\S/;
Branch: 1 branch
BranchTrueFalseTotal
if /=>\s*\S\s*\S/ 1 1 2
196 2 croak "pp_def($this->{OpName}): $msg\n";
197 }
198 0 ($1,$2)
199 } PDL::PP::Rule::Substitute::split_cpp($inds);
200 my $text = "(${pdl}_datap)[" .
201 0 join('+','0', map $this->do_indterm($pdl,$_,\%subst,$context), 0..$#{$this->{IndObjs}})
202 . "]";
203 # If not all substitutions made, the user probably made a spelling error
204 0 ▶ croak "pp_def($this->{OpName}): Substitutions left for \$$pdl($inds): ".(join ',',sort keys %subst)."\n"
Branch: 1 branch
BranchTrueFalseTotal
if keys %subst != 0 0 0 0
205 if keys(%subst) != 0;
206 0 $text;
207 }
208  
209 sub do_pdlaccess {
210 20 ▶ my($this) = @_;
Subroutine do_pdlaccess: called CC=1 SCAR=0.0
Pod undocumented
211 20 '$PRIV(pdls)['.$this->{Number}.']';
212 }
213  
214 sub do_pointeraccess {
215 196 ▶ my($this) = @_;
Subroutine do_pointeraccess: called CC=1 SCAR=0.0
Pod undocumented
216 196 return $this->{Name}."_datap";
217 }
218  
219 0 ▶sub do_indterm { my($this,$pdl,$ind,$subst,$context) = @_;
Subroutine do_indterm: not called CC=3 SCAR=24.8
Pod undocumented
220 0 my $substname = $this->get_substname($ind);
221 # See if substitutions
222 0 ▶ my $index = delete($subst->{$substname}) //
Condition0%0/3
delete $subst->{$substname} // (grep(($_ eq $substname), map($_->[1], reverse(@$context))))[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $subst->{$substname} // (grep(($_ eq $substname), map($_->[1], reverse(@$context))))[0]
delete $subst->{$substname} (grep(($_ eq $substname), map($_->[1], reverse(@$context))))[0]
Truth table0%0/3
A // B
A= delete $subst->{$substname}B= (grep(($_ eq $substname), map($_->[1], reverse(@$context))))[0]
ABresult
1X1
011
000
223 # No => get the one from the nearest context.
224 (grep $_ eq $substname, map $_->[1], reverse @$context)[0];
225 0 ▶ if (!defined $index) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $index) 0 0 0
226 croak "pp_def($this->{OpName}): no value given for ndarray '$pdl' index '$substname'
227 0 You supplied (@{[sort keys %$subst]})
228 0 On stack: ".(join ' ',map {"($_->[0],$_->[1])"} @$context)."\n"
229 }
230 0 "(".($this->get_incname($ind,1))."*($index))";
231 }
232  
233 sub get_xsdatapdecl {
234 22 ▶ my ($this,$ctype,$nulldatacheck,$ppsym,$badflag) = @_;
Subroutine get_xsdatapdecl: called CC=2 SCAR=6.9
Pod undocumented
235 22 my $pdl = $this->get_nname;
236 22 my $name = $this->{Name};
237 22 ▶ my $macro = "PDL_DECLARE_PARAMETER".($badflag ? "_BADVAL" : "");
Branch: 1 branch
BranchTrueFalseTotal
$badflag ? : 4 18 22
238 22 "$macro($ctype, $name, $pdl, $nulldatacheck, $ppsym)";
239 }
240  
241 4 1;
« blib/lib/PDL/PP/Signature.pm ↑ Summary blib/lib/PDL/IO/Dumper.pm »