blib/lib/PDL/PP/PdlParObj.pm

filter: Statementstmt 58.5% 148 / 253 Branchbran 30.2% 29 / 96 Conditioncond 22.5% 18 / 80 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 68.7% 22 / 32 Podpod 0.0% 0 / 26 totaltotal 42.3% 217 / 512 CC 87 SCAR 43.1
CC
87
Cov
45%
new
201.9
splitprotected
132.0
do_indterm
56.0
CRAP 74.7
« blib/lib/PDL/Core/Dev.pm ↑ Summary blib/lib/PDL/Doc/Perldl.pm »
1 ##############################################
2  
3 ##############################################
4  
5 package PDL::PP::PdlParObj;
6  
7 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use PDL::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # check for bad value support
11 #
12 3 ▶use PDL::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶my $usenan = $PDL::Config{BADVAL_USENAN} || 0;
Condition50%1/2
$PDL::Config{'BADVAL_USENAN'} || 0
l!l
03
MC/DC0%0/1
$PDL::Config{'BADVAL_USENAN'} || 0
$PDL::Config{'BADVAL_USENAN'}
Truth table50%1/2
A
A= $PDL::Config{'BADVAL_USENAN'}
Aresult
11
00
14  
15 3 our %Typemap = ();
16 3 ▶use PDL::Types ':All';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # build a typemap for our translation purposes
19 # again from info in PDL::Types
20 3 for my $typ (typesrtkeys) {
21 24 $Typemap{typefld($typ,'ppforcetype')} = {
22 Ctype => typefld($typ,'ctype'),
23 Cenum => typefld($typ,'sym'),
24 Val => typefld($typ,'numval'),
25 };
26 }
27  
28 # Try to load Text::Balanced
29 3 my $hasTB = 0;
30 3 ▶eval q{
Subroutine BEGIN: called CC=1 SCAR=0.0
31 use Text::Balanced;
32 $hasTB = 1;
33 };
34  
35 # split regex $re separated arglist
36 # but ignore bracket-protected bits
37 # (i.e. text that is within matched brackets)
38 # fallback to simple split if we can't find Text::Balanced
39 3 my $prebrackreg = qr/^([^\(\{\[]*)/;
40 sub splitprotected ($$) {
41 0 ▶ my ($re,$txt) = @_;
Subroutine splitprotected: not called CC=11 SCAR=48.8
Pod undocumented
42 0 ▶ return split $re, $txt unless $hasTB;
Branch: 1 branch
BranchTrueFalseTotal
unless $hasTB 0 0 0
43 0 ▶ return () if !defined $txt || $txt =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $txt or $txt =~ /^\s*$/ 0 0 0
Condition0%0/3
not defined $txt or $txt =~ /^\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $txt or $txt =~ /^\s*$/
not defined $txt $txt =~ /^\s*$/
Truth table0%0/3
not(A) or B
A= not defined $txtB= $txt =~ /^\s*$/
ABresult
1X1
011
000
44 0 my ($got,$pre) = (1,'');
45 0 my @chunks = ('');
46 0 my $ct = 0; # infinite loop protection
47 0 ▶ while ($got && $txt =~ /[({\[]/ && $ct++ < 1000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got and $txt =~ /[({\[]/ and $ct++ < 1000) 0 0 0
Condition0%0/6
$got and $txt =~ /[({\[]/ and $ct++ < 1000
!ll&&!rl&&r
000
$got and $txt =~ /[({\[]/
!ll&&!rl&&r
000
MC/DC0%0/3
$got and $txt =~ /[({\[]/ and $ct++ < 1000
$got $txt =~ /[({\[]/ $ct++ < 1000
Truth table0%0/4
A and B and C
A= $gotB= $txt =~ /[({\[]/C= $ct++ < 1000
ABCresult
0XX0
10X0
1100
1111
48 # print "iteration $ct\n";
49 0 ($got,$txt,$pre) =
50 Text::Balanced::extract_bracketed($txt,'{}()[]',$prebrackreg);
51 0 my @partialargs = split $re, $pre, -1;
52 0 ▶ $chunks[-1] .= shift @partialargs if @partialargs;
Branch: 1 branch
BranchTrueFalseTotal
if @partialargs 0 0 0
53 0 push @chunks, @partialargs;
54 0 $chunks[-1] .= $got;
55 }
56 0 ▶ confess "possible infinite parse loop, splitting '$txt' "
Branch: 1 branch
BranchTrueFalseTotal
if $ct >= 1000 0 0 0
57 if $ct >= 1000;
58 0 my @partialargs = split $re, $txt, -1;
59 0 ▶ $chunks[-1] .= shift @partialargs if @partialargs;
Branch: 1 branch
BranchTrueFalseTotal
if @partialargs 0 0 0
60 0 ▶ push @chunks, @partialargs if @partialargs;
Branch: 1 branch
BranchTrueFalseTotal
if @partialargs 0 0 0
61 # print STDERR "args found: $#chunks\n";
62 # print STDERR "splitprotected $txt on $re: [",join('|',@chunks),"]\n";
63 0 return @chunks;
64 }
65  
66 # null != [0]
67 # - in Core.
68  
69 #{package PDL;
70 # sub isnull {
71 # my $this = shift;
72 # return ($this->getndims==1 && $this->getdim(0)==0) ? 1:0 }
73 #}
74  
75 3 1;
76  
77 #__DATA__
78  
79 # need for $badflag is due to hacked get_xsdatapdecl()
80 # - this should disappear when (if?) things are done sensibly
81 #
82 3 my $typeregex = join '|', map {typefld($_,'ppforcetype')} typesrtkeys;
83 3 our $pars_re = qr/^
84 \s*((?:$typeregex)[+]*|)\s* # $1: first option
85 (?:
86 \[([^]]*)\] # $2: The initial [option] part
87 )?\s*
88 (\w+) # $3: The name
89 \(([^)]*)\) # $4: The indices
90 /x;
91 sub new {
92 9 ▶ my($type,$string,$number,$badflag) = @_;
Subroutine new: called CC=32 SCAR=53.1
Pod undocumented
93 9 ▶ $badflag ||= 0;
Condition50%1/2
$badflag ||= 0
l!l
09
MC/DC0%0/1
$badflag ||= 0
$badflag
Truth table50%1/2
A
A= $badflag
Aresult
11
00
94 9 my $this = bless {Number => $number, BadFlag => $badflag},$type;
95 # Parse the parameter string. Note that the regexes for this match were
96 # originally defined here, but were moved to PDL::PP for FullDoc parsing.
97 9 ▶ $string =~ $pars_re
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /$pars_re/x or confess("Invalid pdl def $string (regex $typeregex)\n") 0 9 9
98 or confess "Invalid pdl def $string (regex $typeregex)\n";
99 9 my($opt1,$opt2,$name,$inds) = ($1,$2,$3,$4);
100 9 ▶ map {$_ = '' unless defined($_)} ($opt1,$opt2,$inds); # shut up -w
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 8 19 27
101 9 ▶ print "PDL: '$opt1', '$opt2', '$name', '$inds'\n"
Branch: 1 branch
BranchTrueFalseTotal
if $main::PP_VERBOSE 0 9 9
102 if $::PP_VERBOSE;
103 # Set my internal variables
104 9 $this->{Name} = $name;
105 9 ▶ $this->{Flags} = [(split ',',$opt2),($opt1?$opt1:())];
Branch: 1 branch
BranchTrueFalseTotal
$opt1 ? : 0 9 9
106 9 for(@{$this->{Flags}}) {
107 /^io$/ and $this->{FlagW}=1 or
108 /^nc$/ and $this->{FlagNCreat}=1 or
109 /^o$/ and $this->{FlagOut}=1 and $this->{FlagCreat}=1 and $this->{FlagW}=1 or
110 /^oca$/ and $this->{FlagOut}=1 and $this->{FlagCreat}=1 and $this->{FlagW}=1
111 and $this->{FlagCreateAlways}=1 or
112 /^t$/ and $this->{FlagTemp}=1 and $this->{FlagCreat}=1 and $this->{FlagW}=1 or
113 /^phys$/ and $this->{FlagPhys} = 1 or
114 1 ▶ /^((?:$typeregex)[+]*)$/ and $this->{Type} = $1 and $this->{FlagTyped} = 1 or
Branch: 1 branch
BranchTrueFalseTotal
/^io$/ and $this->{"FlagW"} = 1 or /^nc$/ and $this->{"FlagNCreat"} = 1 or /^o$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^oca$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 and $this->{"FlagCreateAlways"} = 1 or /^t$/ and $this->{"FlagTemp"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^phys$/ and $this->{"FlagPhys"} = 1 or /^((?:$typeregex)[+]*)$/ and $this->{"Type"} = $1 and $this->{"FlagTyped"} = 1 or confess("Invalid flag $_ given for $string\n") 0 1 1
Condition22%11/49
/^io$/ and $this->{"FlagW"} = 1 or /^nc$/ and $this->{"FlagNCreat"} = 1 or /^o$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^oca$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 and $this->{"FlagCreateAlways"} = 1 or /^t$/ and $this->{"FlagTemp"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^phys$/ and $this->{"FlagPhys"} = 1 or /^((?:$typeregex)[+]*)$/ and $this->{"Type"} = $1 and $this->{"FlagTyped"} = 1
l!l&&r!l&&!r
100
/^io$/ and $this->{"FlagW"} = 1 or /^nc$/ and $this->{"FlagNCreat"} = 1 or /^o$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^oca$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 and $this->{"FlagCreateAlways"} = 1 or /^t$/ and $this->{"FlagTemp"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^phys$/ and $this->{"FlagPhys"} = 1
l!l&&r!l&&!r
100
/^io$/ and $this->{"FlagW"} = 1 or /^nc$/ and $this->{"FlagNCreat"} = 1 or /^o$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^oca$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 and $this->{"FlagCreateAlways"} = 1 or /^t$/ and $this->{"FlagTemp"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1
l!l&&r!l&&!r
100
/^io$/ and $this->{"FlagW"} = 1 or /^nc$/ and $this->{"FlagNCreat"} = 1 or /^o$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^oca$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 and $this->{"FlagCreateAlways"} = 1
l!l&&r!l&&!r
100
/^io$/ and $this->{"FlagW"} = 1 or /^nc$/ and $this->{"FlagNCreat"} = 1 or /^o$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1
l!l&&r!l&&!r
010
/^io$/ and $this->{"FlagW"} = 1 or /^nc$/ and $this->{"FlagNCreat"} = 1
l!l&&r!l&&!r
001
/^io$/ and $this->{"FlagW"} = 1
!ll
10
/^nc$/ and $this->{"FlagNCreat"} = 1
!ll
10
/^o$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1
!ll
01
/^o$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1
!ll
01
/^o$/ and $this->{"FlagOut"} = 1
!ll
01
/^oca$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 and $this->{"FlagCreateAlways"} = 1
!ll
00
/^oca$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1
!ll
00
/^oca$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1
!ll
00
/^oca$/ and $this->{"FlagOut"} = 1
!ll
00
/^t$/ and $this->{"FlagTemp"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1
!ll
00
/^t$/ and $this->{"FlagTemp"} = 1 and $this->{"FlagCreat"} = 1
!ll
00
/^t$/ and $this->{"FlagTemp"} = 1
!ll
00
/^phys$/ and $this->{"FlagPhys"} = 1
!ll
00
/^((?:$typeregex)[+]*)$/ and $this->{"Type"} = $1 and $this->{"FlagTyped"} = 1
!ll
00
/^((?:$typeregex)[+]*)$/ and $this->{"Type"} = $1
!ll&&!rl&&r
000
MC/DC0%0/8
/^io$/ and $this->{"FlagW"} = 1 or /^nc$/ and $this->{"FlagNCreat"} = 1 or /^o$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^oca$/ and $this->{"FlagOut"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 and $this->{"FlagCreateAlways"} = 1 or /^t$/ and $this->{"FlagTemp"} = 1 and $this->{"FlagCreat"} = 1 and $this->{"FlagW"} = 1 or /^phys$/ and $this->{"FlagPhys"} = 1 or /^((?:$typeregex)[+]*)$/ and $this->{"Type"} = $1 and $this->{"FlagTyped"} = 1
/^io$/ /^nc$/ /^o$/ /^oca$/ /^t$/ /^phys$/ /^((?:$typeregex)[+]*)$/ $this->{"Type"} = $1
Truth table11%1/9
A or B or C or D or E or F or G and H
A= /^io$/B= /^nc$/C= /^o$/D= /^oca$/E= /^t$/F= /^phys$/G= /^((?:$typeregex)[+]*)$/H= $this->{"Type"} = $1
ABCDEFGHresult
1XXXXXXX1
01XXXXXX1
001XXXXX1
0001XXXX1
00001XXX1
000001XX1
000000111
0000000X0
000000100
115 confess("Invalid flag $_ given for $string\n");
116 }
117 # if($this->{FlagPhys}) {
118 # # warn("Warning: physical flag not implemented yet");
119 # }
120 9 ▶ if ($this->{FlagTyped} && $this->{Type} =~ s/[+]$// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"FlagTyped"} and $this->{"Type"} =~ s/[+]$//) 0 9 9
Condition33%1/3
$this->{"FlagTyped"} and $this->{"Type"} =~ s/[+]$//
!ll&&!rl&&r
900
MC/DC0%0/2
$this->{"FlagTyped"} and $this->{"Type"} =~ s/[+]$//
$this->{"FlagTyped"} $this->{"Type"} =~ s/[+]$//
Truth table33%1/3
A and B
A= $this->{"FlagTyped"}B= $this->{"Type"} =~ s/[+]$//
ABresult
0X0
100
111
121 0 $this->{FlagTplus} = 1;
122 }
123 9 ▶ if($this->{FlagNCreat}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"FlagNCreat"}) 0 9 9
124 0 delete $this->{FlagCreat};
125 0 delete $this->{FlagCreateAlways};
126 }
127 my @inds = map{
128 9 s/\s//g; # Remove spaces
129 9 $_;
130 } split ',', $inds;
131 9 $this->{RawInds} = [@inds];
132 9 return $this;
133 }
134  
135 18 ▶sub name {return (shift)->{Name}}
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
136  
137 sub add_inds {
138 11 ▶ my($this,$dimsobj) = @_;
Subroutine add_inds: called CC=1 SCAR=0.0
Pod undocumented
139 11 $this->{IndObjs} = [map {$dimsobj->get_indobj_make($_)}
140 11 @{$this->{RawInds}}];
141 11 my %indcount;
142 $this->{IndCounts} = [
143 map {
144 11 0+($indcount{$_->name}++);
145 11 } @{$this->{IndObjs}}
146 ];
147 $this->{IndTotCounts} = [
148 map {
149 11 ($indcount{$_->name});
150 11 } @{$this->{IndObjs}}
151 ];
152 }
153  
154  
155 # do the dimension checking for perl level threading
156 # assumes that IndObjs have been created
157 sub perldimcheck {
158 9 ▶ my ($this,$pdl) = @_;
Subroutine perldimcheck: called CC=6 SCAR=18.1
Pod undocumented
159 croak ("can't create ".$this->name) if $pdl->isnull &&
160 9 ▶ !$this->{FlagCreat};
Branch: 1 branch
BranchTrueFalseTotal
if $pdl->isnull and not $this->{"FlagCreat"} 0 9 9
Condition66%2/3
$pdl->isnull and not $this->{"FlagCreat"}
!ll&&!rl&&r
810
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
161 9 ▶ return 1 if $pdl->isnull;
Branch: 1 branch
BranchTrueFalseTotal
if $pdl->isnull 1 8 9
162 8 my $rdims = @{$this->{RawInds}};
163 8 ▶ croak ("not enough dimensions for ".$this->name)
Branch: 1 branch
BranchTrueFalseTotal
if ($pdl->threadids)[0] < $rdims 0 8 8
164 if ($pdl->threadids)[0] < $rdims;
165 8 my @dims = $pdl->dims;
166 8 my ($i,$ind) = (0,undef);
167 8 for $ind (@{$this->{IndObjs}}) {
168 9 $ind->add_value($dims[$i++]);
169 }
170 6 return 0; # not creating
171 }
172  
173 sub finalcheck {
174 6 ▶ my ($this,$pdl) = @_;
Subroutine finalcheck: called CC=4 SCAR=13.9
Pod undocumented
175 6 ▶ return [] if $pdl->isnull;
Branch: 1 branch
BranchTrueFalseTotal
if $pdl->isnull 1 5 6
176 5 my @corr = ();
177 5 my @dims = $pdl->dims;
178 5 my ($i,$ind) = (0,undef);
179 5 for $ind (@{$this->{IndObjs}}) {
180 6 ▶ push @corr,[$i-1,$ind->{Value},$dims[$i-1]] if $dims[$i++] != $ind->{Value};
Branch: 1 branch
BranchTrueFalseTotal
if $dims[$i++] != $ind->{"Value"} 1 5 6
181 }
182 5 return [@corr];
183 }
184  
185 # get index sizes for a parameter that has to be created
186 sub getcreatedims {
187 1 ▶ my $this = shift;
Subroutine getcreatedims: called CC=3 SCAR=18.1
Pod undocumented
188 return map
189 { croak "can't create: index size ".$_->name." not initialised"
190 0 ▶ if !defined($_->{Value}) || $_->{Value} < 1;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $_->{"Value"} or $_->{"Value"} < 1 0 0 0
Condition0%0/3
not defined $_->{"Value"} or $_->{"Value"} < 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $_->{"Value"} or $_->{"Value"} < 1
not defined $_->{"Value"} $_->{"Value"} < 1
Truth table0%0/3
not(A) or B
A= not defined $_->{"Value"}B= $_->{"Value"} < 1
ABresult
1X1
011
000
191 1 $_->{Value} } @{$this->{IndObjs}};
192 }
193  
194  
195 # find the value for a given PDL type
196 sub typeval {
197 0 ▶ my $ctype = shift;
Subroutine typeval: not called CC=2 SCAR=13.0
Pod undocumented
198 0 my @match = grep {$Typemap{$_}->{Ctype} =~ /^$ctype$/} keys(%Typemap);
199 0 ▶ if ($#match < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#match < 0) 0 0 0
200 3 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
201 0 print Dumper \%Typemap;
202 0 croak "unknown PDL type '$ctype'" ;
203 }
204 0 return $Typemap{$match[0]}->{Val};
205 }
206  
207 # return the PDL type for this pdl
208 sub ctype {
209 4 ▶ my ($this,$generic) = @_;
Subroutine ctype: called CC=5 SCAR=28.8
Pod undocumented
210 4 ▶ return $generic unless $this->{FlagTyped};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"FlagTyped"} 4 0 4
211 croak "ctype: unknownn type"
212 0 ▶ unless defined($Typemap{$this->{Type}});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Typemap{$this->{"Type"}} 0 0 0
213 0 my $type = $Typemap{$this->{Type}}->{Ctype};
214 0 ▶ if ($this->{FlagTplus}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"FlagTplus"}) 0 0 0
215 $type = $Typemap{$this->{Type}}->{Val} >
216 PDL::PP::PdlParObj::typeval($generic) ?
217 0 ▶ $Typemap{$this->{Type}}->{Ctype} : $generic;
Branch: 1 branch
BranchTrueFalseTotal
$Typemap{$this->{'Type'}}{'Val'} > typeval($generic) ? : 0 0 0
218 }
219 0 return $type;
220 }
221  
222 # return the enum type for a parobj; it'd better be typed
223 sub cenum {
224 0 ▶ my $this = shift;
Subroutine cenum: not called CC=2 SCAR=17.9
Pod undocumented
225 croak "cenum: unknown type [" . $this->{Type} . "]"
226 0 ▶ unless defined($PDL::PP::PdlParObj::Typemap{$this->{Type}});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Typemap{$this->{"Type"}} 0 0 0
227 0 return $PDL::PP::PdlParObj::Typemap{$this->{Type}}->{Cenum};
228 }
229  
230 5 ▶sub get_nname{ my($this) = @_;
Subroutine get_nname: called CC=1 SCAR=0.0
Pod undocumented
231 5 "(\$PRIV(pdls[$this->{Number}]))";
232 }
233  
234 4 ▶sub get_nnflag { my($this) = @_;
Subroutine get_nnflag: called CC=1 SCAR=0.0
Pod undocumented
235 4 "(\$PRIV(vtable->per_pdl_flags[$this->{Number}]))";
236 }
237  
238  
239 # XXX There might be weird backprop-of-changed stuff for [phys].
240 #
241 # Have changed code to assume that, if(!$this->{FlagCreat})
242 # then __creating[] will == 0
243 # -- see make_redodims_thread() in ../PP.pm
244 #
245 sub get_xsnormdimchecks {
246 1 ▶ my($this) = @_;
Subroutine get_xsnormdimchecks: called CC=7 SCAR=22.1
Pod undocumented
247 1 my $pdl = $this->get_nname;
248 1 my $iref = $this->{IndObjs};
249 1 my $ninds = 0+scalar(@$iref);
250  
251 1 my $str = "";
252 1 ▶ $str .= "if(!__creating[$this->{Number}]) {\n" if $this->{FlagCreat};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"FlagCreat"} 0 1 1
253
254 # Dimensional Promotion when number of dims is less than required:
255 # Previous warning message now commented out,
256 # which means we only need include the code if $ninds > 0
257 #
258 1 ▶ if ( $ninds > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ninds > 0) 1 0 1
259 $str .= " if(($pdl)->ndims < $ninds) {\n" .
260 join('', map {
261 1 my $size = $iref->[$_-1]->get_size();
262 1 " if (($pdl)->ndims < $_ && $size <= 1) $size = 1;\n"
263 } (1..$ninds))
264 # XXX why is this here, commented, and not removed? If re-inserted, be sure to use PDL_COMMENT
265 ## ." /* \$CROAK(\"Too few dimensions for argument \'$this->{Name}\'\\n\"); */\n"
266 . " }\n";
267 }
268  
269 # Now, the real check.
270 1 my $no = 0;
271 1 for( @$iref ) {
272 1 my $siz = $_->get_size();
273 1 my $dim = "($pdl)->dims[$no]";
274 1 my $ndims = "($pdl)->ndims";
275 1 $str .= " if($siz == -1 || ($ndims > $no && $siz == 1)) {\n" .
276 " $siz = $dim;\n" .
277 " } else if($ndims > $no && $siz != $dim) {\n" .
278 # XXX should these lines simply be removed? If re-inserted, be sure to use PDL_COMMENT
279 # " if($dim == 1) {\n" .
280 # " /* Do nothing */ /* XXX Careful, increment? */" .
281 # " } else {\n" .
282 " if($dim != 1) {\n" .
283 " \$CROAK(\"Wrong dims\\n\");\n" .
284 " }\n }\n";
285 1 $no++;
286 }
287  
288 1 ▶ $str .= "PDL->make_physical(($pdl));\n" if $this->{FlagPhys};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"FlagPhys"} 0 1 1
289  
290 1 ▶ if ( $this->{FlagCreat} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"FlagCreat"}) 0 1 1
291 0 $str .= "} else {\n";
292
293 # We are creating this pdl.
294 0 $str .= " PDL_Indx dims[".($ninds+1)."]; PDL_COMMENT(\"Use ninds+1 to avoid smart (stupid) compilers\")";
295 $str .= join "",
296 0 (map {"dims[$_] = ".$iref->[$_]->get_size().";"} 0 .. $#$iref);
297 0 ▶ my $istemp = $this->{FlagTemp} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$this->{'FlagTemp'} ? : 0 0 0
298 0 $str .="\n PDL->thread_create_parameter(&\$PRIV(__pdlthread),$this->{Number},dims,$istemp);\n";
299 0 $str .= "}";
300 }
301 1 return $str;
302
303 } # sub: get_xsnormdimchecks()
304  
305 sub get_incname {
306 10 ▶ my($this,$ind) = @_;
Subroutine get_incname: called CC=2 SCAR=7.6
Pod undocumented
307 10 ▶ if($this->{IndTotCounts}[$ind] > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'IndTotCounts'}[$ind] > 1) { } 0 10 10
308 0 "__inc_".$this->{Name}."_".($this->{IndObjs}[$ind]->name).$this->{IndCounts}[$ind];
309 } else {
310 10 "__inc_".$this->{Name}."_".($this->{IndObjs}[$ind]->name);
311 }
312 }
313  
314 sub get_incdecls {
315 1 ▶ my($this) = @_;
Subroutine get_incdecls: called CC=2 SCAR=7.1
Pod undocumented
316 1 ▶ if(scalar(@{$this->{IndObjs}}) == 0) {return "";}
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$this->{"IndObjs"};} == 0) 0 1 1
317 (join '',map {
318 1 "PDL_Indx ".($this->get_incname($_)).";";
319 1 } (0..$#{$this->{IndObjs}}) ) . ";"
320 }
321  
322 sub get_incregisters {
323 3 ▶ my($this) = @_;
Subroutine get_incregisters: called CC=2 SCAR=7.1
Pod undocumented
324 3 ▶ if(scalar(@{$this->{IndObjs}}) == 0) {return "";}
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$this->{"IndObjs"};} == 0) 0 3 3
325 (join '',map {
326 3 "register PDL_Indx ".($this->get_incname($_))." = \$PRIV(".
327 ($this->get_incname($_)).");\n";
328 3 } (0..$#{$this->{IndObjs}}) )
329 }
330  
331 sub get_incdecl_copy {
332 1 ▶ my($this,$fromsub,$tosub) = @_;
Subroutine get_incdecl_copy: called CC=1 SCAR=0.0
Pod undocumented
333 join '',map {
334 1 my $iname = $this->get_incname($_);
335 1 &$fromsub($iname)."=".&$tosub($iname).";";
336 1 } (0..$#{$this->{IndObjs}})
337 }
338  
339 sub get_incsets {
340 1 ▶ my($this,$str) = @_;
Subroutine get_incsets: called CC=2 SCAR=7.0
Pod undocumented
341 1 my $no=0;
342 (join '',map {
343 "if($str->ndims <= $_ || $str->dims[$_] <= 1)
344 \$PRIV(".($this->get_incname($_)).") = 0; else
345 \$PRIV(".($this->get_incname($_)).
346 ") = ".($this->{FlagPhys}?
347 1 ▶ "$str->dimincs[$_];" :
Branch: 1 branch
BranchTrueFalseTotal
$this->{'FlagPhys'} ? : 0 1 1
348 "PDL_REPRINC($str,$_);");
349 1 } (0..$#{$this->{IndObjs}}) )
350 }
351  
352 # Print an access part.
353 sub do_access {
354 0 ▶ my($this,$inds,$context) = @_;
Subroutine do_access: not called CC=3 SCAR=24.8
Pod undocumented
355 0 my $pdl = $this->{Name};
356 # Parse substitutions into hash
357 my %subst = map
358 0 ▶ {/^\s*(\w+)\s*=>\s*(\S*)\s*$/ or confess "Invalid subst $_\n"; ($1,$2)}
Branch: 1 branch
BranchTrueFalseTotal
/^\s*(\w+)\s*=>\s*(\S*)\s*$/ or confess("Invalid subst $_\n") 0 0 0
359 splitprotected ',',$inds;
360 # Generate the text
361 0 my $text;
362 0 $text = "(${pdl}_datap)"."[";
363 $text .= join '+','0',map {
364 0 $this->do_indterm($pdl,$_,\%subst,$context);
365 0 } (0..$#{$this->{IndObjs}});
366 0 $text .= "]";
367 # If not all substitutions made, the user probably made a spelling
368 # error. Barf.
369 0 ▶ if(scalar(keys %subst) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %subst != 0) 0 0 0
370 0 confess("Substitutions left: ".(join ',',keys %subst)."\n");
371 }
372 0 return "$text PDL_COMMENT(\"ACCESS($access)\") ";
373 }
374  
375 sub has_dim {
376 0 ▶ my($this,$ind) = @_;
Subroutine has_dim: not called CC=3 SCAR=24.8
Pod undocumented
377 0 my $h = 0;
378 0 for(@{$this->{IndObjs}}) {
379 0 ▶ $h++ if $_->name eq $ind;
Branch: 1 branch
BranchTrueFalseTotal
if $_->name eq $ind 0 0 0
380 }
381 0 return $h;
382 }
383  
384 sub do_resize {
385 0 ▶ my($this,$ind,$size) = @_;
Subroutine do_resize: not called CC=3 SCAR=24.8
Pod undocumented
386 0 my @c;my $index = 0;
387 0 for(@{$this->{IndObjs}}) {
388 0 ▶ push @c,$index if $_->name eq $ind; $index ++;
Branch: 1 branch
BranchTrueFalseTotal
if $_->name eq $ind 0 0 0
389 }
390 0 my $pdl = $this->get_nname;
391 0 return (join '',map {"$pdl->dims[$_] = $size;\n"} @c).
392 "PDL->resize_defaultincs($pdl);PDL->allocdata($pdl);".
393 $this->get_xsdatapdecl(undef,1);
394 }
395  
396 sub do_pdlaccess {
397 0 ▶ my($this) = @_;
Subroutine do_pdlaccess: not called CC=1 SCAR=6.9
Pod undocumented
398 0 return '$PRIV(pdls['.$this->{Number}.'])';
399  
400 }
401  
402 sub do_pointeraccess {
403 0 ▶ my($this) = @_;
Subroutine do_pointeraccess: not called CC=1 SCAR=6.9
Pod undocumented
404 0 return $this->{Name}."_datap";
405 }
406  
407 sub do_physpointeraccess {
408 0 ▶ my($this) = @_;
Subroutine do_physpointeraccess: not called CC=1 SCAR=6.9
Pod undocumented
409 0 return $this->{Name}."_physdatap";
410 }
411  
412 0 ▶sub do_indterm { my($this,$pdl,$ind,$subst,$context) = @_;
Subroutine do_indterm: not called CC=7 SCAR=40.3
Pod undocumented
413 # Get informed
414 0 my $indname = $this->{IndObjs}[$ind]->name;
415 0 my $indno = $this->{IndCounts}[$ind];
416 0 my $indtot = $this->{IndTotCounts}[$ind];
417 # See if substitutions
418 0 ▶ my $substname = ($indtot>1 ? $indname.$indno : $indname);
Branch: 1 branch
BranchTrueFalseTotal
$indtot > 1 ? : 0 0 0
419 0 ▶ my $incname = $indname.($indtot>1 ? $indno : "");
Branch: 1 branch
BranchTrueFalseTotal
$indtot > 1 ? : 0 0 0
420 0 my $index;
421 0 ▶ if(defined $subst->{$substname}) {$index = delete $subst->{$substname};}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subst->{$substname}) { } 0 0 0
422 else {
423 # No => get the one from the nearest context.
424 0 for(reverse @$context) {
425 0 ▶ if($_->[0] eq $indname) {$index = $_->[1]; last;}
Branch: 1 branch
BranchTrueFalseTotal
if ($_->[0] eq $indname) 0 0 0
426 }
427 }
428 0 ▶ if(!defined $index) {confess "Access Index not found: $pdl, $ind, $indname
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $index) 0 0 0
429 0 On stack:".(join ' ',map {"($_->[0],$_->[1])"} @$context)."\n" ;}
430 # return "\$PRIV(".($this->get_incname($ind))."*". $index .")";
431 # Now we have them in register variables -> no PRIV
432 return ("(".($this->get_incname($ind))."*".
433 0 "PP_INDTERM(".$this->{IndObjs}[$ind]->get_size().", $index))");
434 }
435  
436 # XXX hacked to create a variable containing the bad value for
437 # this piddle.
438 # This is a HACK (Doug Burke 07/08/00)
439 # XXX
440 #
441 sub get_xsdatapdecl {
442 4 ▶ my($this,$genlooptype,$asgnonly) = @_;
Subroutine get_xsdatapdecl: called CC=8 SCAR=27.3
Pod undocumented
443 4 my $type;
444 4 my $pdl = $this->get_nname;
445 4 my $flag = $this->get_nnflag;
446 4 my $name = $this->{Name};
447 4 ▶ $type = $this->ctype($genlooptype) if defined $genlooptype;
Branch: 1 branch
BranchTrueFalseTotal
if defined $genlooptype 4 0 4
448 4 ▶ my $declini = ($asgnonly ? "" : "\t$type *");
Branch: 1 branch
BranchTrueFalseTotal
$asgnonly ? : 0 4 4
449 4 ▶ my $cast = ($type ? "($type *)" : "");
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 4 0 4
450 # ThreadLoop does this for us.
451 # return "$declini ${name}_datap = ($cast((${_})->data)) + (${_})->offs;\n";
452
453 4 my $str = "$declini ${name}_datap = ($cast(PDL_REPRP_TRANS($pdl,$flag)));\n" .
454 "$declini ${name}_physdatap = ($cast($pdl->data));\n";
455  
456 # assuming we always need this
457 # - may not be true - eg if $asgnonly ??
458 # - not needed for floating point types when using NaN as bad values
459 4 ▶ if ( $this->{BadFlag} and $type and
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"BadFlag"} and $type and $usenan == 0 || !($type =~ /^PDL_(Float|Double)$/)) 0 4 4
Condition22%2/9
$this->{"BadFlag"} and $type and $usenan == 0 || !($type =~ /^PDL_(Float|Double)$/)
!ll&&!rl&&r
400
$this->{"BadFlag"} and $type
!ll&&!rl&&r
400
$usenan == 0 or not $type =~ /^PDL_(Float|Double)$/
l!l&&r!l&&!r
000
MC/DC0%0/4
$this->{"BadFlag"} and $type and $usenan == 0 || !($type =~ /^PDL_(Float|Double)$/)
$this->{"BadFlag"} $type $usenan == 0 not $type =~ /^PDL_(Float|Double)$/
Truth table20%1/5
A and B and C or not(D)
A= $this->{"BadFlag"}B= $typeC= $usenan == 0D= not $type =~ /^PDL_(Float|Double)$/
ABCDresult
0XXX0
10XX0
11000
111X1
11011
460 ( $usenan == 0 or $type !~ /^PDL_(Float|Double)$/ ) ) {
461 0 my $cname = $type; $cname =~ s/^PDL_//;
462 0 $str .= "\t$type ${name}_badval = 0;\n";
463 0 $str .= "\tPDL_Anyval ${name}_anyval_badval = PDL->get_pdl_badvalue($pdl);\n";
464 0 $str .= "\tANYVAL_TO_CTYPE(${name}_badval, ${type}, ${name}_anyval_badval);\n";
465 }
466  
467 4 return "$str\n";
468 }
469  
470 3 1;
« blib/lib/PDL/Core/Dev.pm ↑ Summary blib/lib/PDL/Doc/Perldl.pm »