blib/lib/PDL/Types.pm

filter: Statementstmt 80.8% 97 / 120 Branchbran 47.7% 21 / 44 Conditioncond 64.7% 11 / 17 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 75.7% 25 / 33 Podpod 50.0% 5 / 10 totaltotal 68.0% 160 / 235 CC 35 SCAR 15.8
CC
35
Cov
71%
typefld
12.0
typefld
12.0
new
9.7
CRAP 4.8
« blib/lib/PDL/FFT.pm ↑ Summary blib/lib/PDL/Install/Files.pm »
1 package PDL::Types;
2 77 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 77 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 0 require Exporter;
5 77 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 77 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 our @ISA = qw( Exporter );
9  
10 0 my @TYPE_CHECK = qw/
11 realctype ppforcetype usenan real unsigned integer identifier ctype
12 /;
13 77 my @TYPE_VERBATIM = (@TYPE_CHECK, qw(
14 ioname convertfunc defbval shortctype ppsym numval sym floatsuffix
15 ));
16 77 my @TYPE_MODIFIED = qw(realversion complexversion isnan isfinite);
17  
18 77 ▶sub packtypeof_PDL_Indx {
Subroutine packtypeof_PDL_Indx: called CC=3 SCAR=18.4
Pod undocumented
19 77 ▶ return 'q*' if $Config{ptrsize} == 8;
Subroutine packtypeof_PDL_Indx: not called CC=3 SCAR=18.4
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Types::Config{"ptrsize"} == 8 77 0 77
20 0 ▶ return 'l*' if $Config{ptrsize} == 4;
Branch: 1 branch
BranchTrueFalseTotal
if $PDL::Types::Config{"ptrsize"} == 4 0 0 0
21 0 die "PDL::Types: packtype for ptrsize==$Config{ptrsize} not handled\n";
22 }
23  
24 # Data types *must* be listed in order of complexity!!
25 # this is critical for type conversions!!!
26 #
27 77 my @HASHES = (
28 {
29 identifier => 'SB',
30 onecharident => 'A', # only needed if different from identifier
31 ctype => 'PDL_SByte',# to be defined in pdl.h
32 realctype => 'signed char', # CORE21 change to int8_t
33 ppforcetype => 'sbyte', # for some types different from ctype
34 usenan => 0, # do we need NaN handling for this type?
35 packtype => 'c*', # the perl pack type
36 defbval => 'SCHAR_MIN',
37 real=>1,
38 integer=>1,
39 unsigned=>0,
40 },
41 {
42 identifier => 'B',
43 ctype => 'PDL_Byte',# to be defined in pdl.h
44 realctype => 'unsigned char',
45 ppforcetype => 'byte', # for some types different from ctype
46 usenan => 0, # do we need NaN handling for this type?
47 packtype => 'C*', # the perl pack type
48 defbval => 'UCHAR_MAX',
49 real=>1,
50 integer=>1,
51 unsigned=>1,
52 },
53 {
54 identifier => 'S',
55 ctype => 'PDL_Short',
56 realctype => 'short',
57 ppforcetype => 'short',
58 usenan => 0,
59 packtype => 's*',
60 defbval => 'SHRT_MIN',
61 real=>1,
62 integer=>1,
63 unsigned=>0,
64 },
65 {
66 identifier => 'US',
67 onecharident => 'U', # only needed if different from identifier
68 ctype => 'PDL_Ushort',
69 realctype => 'unsigned short',
70 ppforcetype => 'ushort',
71 usenan => 0,
72 packtype => 'S*',
73 defbval => 'USHRT_MAX',
74 real=>1,
75 integer=>1,
76 unsigned=>1,
77 },
78 {
79 identifier => 'L',
80 ctype => 'PDL_Long',
81 realctype => 'int32_t',
82 ppforcetype => 'int',
83 usenan => 0,
84 packtype => 'l*',
85 defbval => 'INT32_MIN',
86 real=>1,
87 integer=>1,
88 unsigned=>0,
89 },
90 {
91 identifier => 'UL',
92 onecharident => 'K', # only needed if different from identifier
93 ctype => 'PDL_ULong',
94 realctype => 'uint32_t',
95 ppforcetype => 'uint',
96 usenan => 0,
97 packtype => 'L*',
98 defbval => 'UINT32_MAX',
99 real=>1,
100 integer=>1,
101 unsigned=>1,
102 },
103 {
104 identifier => 'IND',
105 onecharident => 'N', # only needed if different from identifier
106 ctype => 'PDL_Indx',
107 realctype => 'ptrdiff_t',
108 ppforcetype => 'indx',
109 usenan => 0,
110 packtype => &packtypeof_PDL_Indx,
111 defbval => 'PTRDIFF_MIN',
112 real=>1,
113 integer=>1,
114 unsigned=>0,
115 },
116 # note that the I/O routines have *not* been updated to be aware of
117 # such a type yet
118 { # this one before LL so last integer is signed, to avoid default-type (last in list) changing to unsigned
119 identifier => 'ULL',
120 onecharident => 'P', # only needed if different from identifier
121 ctype => 'PDL_ULongLong',
122 realctype => 'uint64_t',
123 ppforcetype => 'ulonglong',
124 usenan => 0,
125 packtype => 'Q*',
126 defbval => 'UINT64_MAX',
127 real=>1,
128 integer=>1,
129 unsigned=>1,
130 },
131 {
132 identifier => 'LL',
133 onecharident => 'Q', # only needed if different from identifier
134 ctype => 'PDL_LongLong',
135 realctype => 'int64_t',
136 ppforcetype => 'longlong',
137 usenan => 0,
138 packtype => 'q*',
139 defbval => 'INT64_MIN',
140 real=>1,
141 integer=>1,
142 unsigned=>0,
143 },
144 # IMPORTANT:
145 # PDL_F *must* be the first non-integer type in this list
146 # as there are many places in the code (.c/.xs/.pm/.pd)
147 # with tests like this:
148 # if (ndarraytype < PDL_F) { ... }
149 {
150 identifier => 'F',
151 ctype => 'PDL_Float',
152 realctype => 'float',
153 ppforcetype => 'float',
154 usenan => 1,
155 packtype => 'f*',
156 defbval => '-FLT_MAX',
157 real=>1,
158 complexversion=> 'G',
159 integer=>0,
160 unsigned=>0,
161 isnan=>'isnan(%1$s)',
162 isfinite=>'isfinite(%1$s)',
163 floatsuffix=>'f',
164 },
165 {
166 identifier => 'D',
167 ctype => 'PDL_Double',
168 realctype => 'double',
169 ppforcetype => 'double',
170 usenan => 1,
171 packtype => 'd*',
172 defbval => '-DBL_MAX',
173 real=>1,
174 complexversion=> 'C',
175 integer=>0,
176 unsigned=>0,
177 isnan=>'isnan(%1$s)',
178 isfinite=>'isfinite(%1$s)',
179 floatsuffix=>'',
180 },
181 {
182 identifier => 'LD',
183 onecharident => 'E', # only needed if different from identifier
184 ctype => 'PDL_LDouble',
185 realctype => 'long double',
186 ppforcetype => 'ldouble',
187 usenan => 1,
188 packtype => 'D*',
189 defbval => '-LDBL_MAX',
190 real=>1,
191 complexversion=> 'CLD',
192 integer=>0,
193 unsigned=>0,
194 isnan=>'isnan(%1$s)',
195 isfinite=>'isfinite(%1$s)',
196 floatsuffix=>'l',
197 },
198 # the complex types need to be in the same order as their real
199 # counterparts, because the "real" ppforcetype relies on a fixed interval
200 # between each real and complex version
201 # they also need to occur at the end of the types, as a < PDL_CF
202 # comparison is done at C level to see if a type is real, analogous to
203 # the < PDL_F above
204 {
205 identifier => 'CF',
206 onecharident => 'G', # only needed if different from identifier
207 ctype => 'PDL_CFloat',
208 realctype => 'complex float',
209 ppforcetype => 'cfloat',
210 usenan => 1,
211 packtype => '(ff)*',
212 defbval => '(-FLT_MAX - I*FLT_MAX)',
213 real=>0,
214 realversion=>'F',
215 integer=>0,
216 unsigned=>0,
217 isnan=>'(isnan(crealf(%1$s)) || isnan(cimagf(%1$s)))',
218 isfinite=>'(isfinite(crealf(%1$s)) && isfinite(cimagf(%1$s)))',
219 floatsuffix=>'f',
220 },
221 {
222 identifier => 'CD',
223 onecharident => 'C', # only needed if different from identifier
224 ctype => 'PDL_CDouble',
225 realctype => 'complex double',
226 ppforcetype => 'cdouble',
227 usenan => 1,
228 packtype => '(dd)*',
229 defbval => '(-DBL_MAX - I*DBL_MAX)',
230 real=>0,
231 realversion=>'D',
232 integer=>0,
233 unsigned=>0,
234 isnan=>'(isnan(creal(%1$s)) || isnan(cimag(%1$s)))',
235 isfinite=>'(isfinite(creal(%1$s)) && isfinite(cimag(%1$s)))',
236 floatsuffix=>'',
237 },
238 {
239 identifier => 'CLD',
240 onecharident => 'H', # only needed if different from identifier
241 ctype => 'PDL_CLDouble',
242 realctype => 'complex long double',
243 ppforcetype => 'cldouble',
244 usenan => 1,
245 packtype => '(DD)*',
246 defbval => '(-LDBL_MAX - I*LDBL_MAX)',
247 real=>0,
248 realversion=>'LD',
249 integer=>0,
250 unsigned=>0,
251 isnan=>'(isnan(creall(%1$s)) || isnan(cimagl(%1$s)))',
252 isfinite=>'(isfinite(creall(%1$s)) && isfinite(cimagl(%1$s)))',
253 floatsuffix=>'l',
254 },
255 );
256  
257 77 my $i = 0;
258 77 my @check_keys = (@TYPE_CHECK, qw(
259 identifier packtype defbval
260 ));
261 77 for my $type (@HASHES) {
262 1155 ▶ die "type is not a HASH ref but ".ref($type) unless ref $type eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $type eq "HASH" 0 1155 1155
unless ref $type eq "HASH" 0 0 0
263 1155 my @missing_keys = grep !exists $type->{$_}, @check_keys;
264 1155 ▶ die "type hash missing (@missing_keys)" if @missing_keys;
Branch: 2 branches
BranchTrueFalseTotal
if @missing_keys 0 1155 1155
if @missing_keys 0 0 0
265 1155 $type->{shortctype} = $type->{ctype} =~ s/PDL_//r;
266 1155 $type->{ioname} = $type->{convertfunc} = lc $type->{shortctype};
267 1155 ▶ $type->{ppsym} = $type->{onecharident} || $type->{identifier};
Condition66%2/3
$type->{'onecharident'} || $type->{'identifier'}
l!l&&r!l&&!r
7703850
MC/DC0%0/2
$type->{'onecharident'} || $type->{'identifier'}
$type->{'onecharident'} $type->{'identifier'}
Truth table66%2/3
A || B
A= $type->{'onecharident'}B= $type->{'identifier'}
ABresult
1X1
011
000
268 1155 $type->{numval} = $i++;
269 1155 $type->{sym} = "PDL_$type->{identifier}";
270 1155 ▶ $type->{realversion} ||= $type->{ppsym};
Condition66%2/3
$type->{"realversion"} ||= $type->{"ppsym"}
l!l&&r!l&&!r
2319240
MC/DC0%0/2
$type->{"realversion"} ||= $type->{"ppsym"}
$type->{"realversion"} $type->{"ppsym"}
Truth table66%2/3
A ||= B
A= $type->{"realversion"}B= $type->{"ppsym"}
ABresult
1X1
011
000
271 1155 ▶ $type->{complexversion} ||= !$type->{real} ? $type->{ppsym} : 'G';
Branch: 1 branch
BranchTrueFalseTotal
!$type->{'real'} ? : 231 693 924
Condition66%2/3
$type->{"complexversion"} ||= !$type->{"real"} ? $type->{"ppsym"} : "G"
l!l&&r!l&&!r
2319240
MC/DC0%0/2
$type->{"complexversion"} ||= !$type->{"real"} ? $type->{"ppsym"} : "G"
$type->{"complexversion"} !$type->{"real"} ? $type->{"ppsym"} : "G"
Truth table66%2/3
A ||= not(B)
A= $type->{"complexversion"}B= !$type->{"real"} ? $type->{"ppsym"} : "G"
ABresult
1X1
011
000
272 1155 ▶ $type->{floatsuffix} //= 'INVALID';
Condition100%2/2
$type->{"floatsuffix"} //= "INVALID"
l!l
462693
MC/DC100%1/1
$type->{"floatsuffix"} //= "INVALID"
$type->{"floatsuffix"}
Truth table100%2/2
A
A= $type->{"floatsuffix"}
Aresult
11
00
273  
274 }
275  
276 77 our @EXPORT = (qw(@pack %typehash), my @typevars = map "\$$_->{sym}", @HASHES);
277 77 our @EXPORT_OK = (@EXPORT,
278 qw/types typesrtkeys mapfld typefld
279 ppdefs ppdefs_complex ppdefs_all
280 /
281 );
282 77 our %EXPORT_TAGS = (
283 All=>\@EXPORT_OK,
284 );
285  
286 77 eval "our ( @{[ join ',', @typevars ]} ) = (0..$#HASHES)";
287 77 ▶die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 77 77
288 # Corresponding pack types
289 77 our @pack= map $_->{packtype}, @HASHES;
290 77 our @names= map $_->{sym}, @HASHES;
291  
292 our %typehash = map {
293 77 my $type = $_;
294 $type->{sym} => +{
295 1155 (map +($_ => $type->{$_}), @TYPE_VERBATIM, @TYPE_MODIFIED),
296 };
297 } @HASHES;
298  
299 # Cross-reference by common names
300 77 our %typenames;
301 77 for my $h (@HASHES) {
302 1155 my $n = $h->{numval};
303 1155 $typenames{$_} = $n for $n, @$h{qw(sym ioname ctype ppforcetype ppsym identifier)};
304 }
305  
306 =head1 NAME
307  
308 PDL::Types - define fundamental PDL Datatypes
309  
310 =head1 SYNOPSIS
311  
312 use PDL::Types;
313  
314 $pdl = ushort( 2.0, 3.0 );
315 print "The actual c type used to store ushort's is '" .
316 $pdl->type->realctype() . "'\n";
317 The actual c type used to store ushort's is 'unsigned short'
318  
319 =head1 DESCRIPTION
320  
321 Internal module - holds all the PDL Type info. The type info can be
322 accessed easily using the C<PDL::Type> object returned by
323 the L<type|PDL::Core/type> method as shown in the synopsis.
324  
325 Skip to the end of this document to find out how to change
326 the set of types supported by PDL.
327  
328 =head1 FUNCTIONS
329  
330 A number of functions are available for module writers
331 to get/process type information. These are used in various
332 places (e.g. C<PDL::PP>, C<PDL::Core>) to generate the
333 appropriate type loops, etc.
334  
335 =head2 typesrtkeys
336  
337 =for ref
338  
339 Returns an array of keys of typehash sorted in order of type complexity
340  
341 =for example
342  
343 pdl> @typelist = PDL::Types::typesrtkeys;
344 pdl> print @typelist;
345 PDL_SB PDL_B PDL_S PDL_US PDL_L PDL_UL PDL_IND PDL_ULL PDL_LL PDL_F PDL_D PDL_LD PDL_CF PDL_CD PDL_CLD
346 =cut
347  
348 0 ▶sub typesrtkeys { @names }
Subroutine typesrtkeys: not called CC=1 SCAR=6.9
Pod documented
349  
350 =head2 ppdefs
351  
352 =for ref
353  
354 Returns an array of pp symbols for all real types. This informs the
355 default C<GenericTypes> for C<pp_def> functions, making support for
356 complex types require an "opt-in".
357  
358 =for example
359  
360 pdl> print PDL::Types::ppdefs
361 A B S U L K N P Q F D E
362  
363 =cut
364  
365 77 my @PPDEFS = map $_->{ppsym}, grep $_->{real}, @HASHES;
366 47 ▶sub ppdefs { @PPDEFS }
Subroutine ppdefs: called CC=1 SCAR=0.0
Pod documented
367  
368 =head2 ppdefs_complex
369  
370 =for ref
371  
372 Returns an array of pp symbols for all complex types.
373  
374 =for example
375  
376 pdl> print PDL::Types::ppdefs_complex
377 G C H
378  
379 =cut
380  
381 77 my @PPDEFS_CPLX = map $_->{ppsym}, grep !$_->{real}, @HASHES;
382 1 ▶sub ppdefs_complex { @PPDEFS_CPLX }
Subroutine ppdefs_complex: called CC=1 SCAR=0.0
Pod documented
383  
384 =head2 ppdefs_all
385  
386 =for ref
387  
388 Returns an array of pp symbols for all types including complex.
389  
390 =for example
391  
392 pdl> print PDL::Types::ppdefs_all
393 A B S U L K N P Q F D E G C H
394  
395 =cut
396  
397 77 my @PPDEFS_ALL = map $_->{ppsym}, @HASHES;
398 14 ▶sub ppdefs_all { @PPDEFS_ALL }
Subroutine ppdefs_all: called CC=1 SCAR=0.0
Pod documented
399  
400 0 ▶sub typefld {
Subroutine typefld: not called CC=3 SCAR=24.8
Pod undocumented
401 0 my ($type,$fld) = @_;
402 0 ▶ croak "unknown type $type" unless exists $typehash{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $PDL::Types::typehash{$type} 0 0 0
403 croak "unknown field $fld in type $type"
404 0 ▶ unless exists $typehash{$type}->{$fld};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $PDL::Types::typehash{$type}{$fld} 0 0 0
405 0 return $typehash{$type}->{$fld};
406 }
407  
408 0 ▶sub mapfld {
Subroutine mapfld: not called CC=2 SCAR=17.9
Pod undocumented
409 0 my ($type,$src,$trg) = @_;
410 0 my @keys = grep {$typehash{$_}->{$src} eq $type} typesrtkeys;
411 0 ▶ return @keys > 0 ? $typehash{$keys[0]}->{$trg} : undef;
Branch: 1 branch
BranchTrueFalseTotal
@keys > 0 ? : 0 0 0
412 }
413  
414 =head2 typesynonyms
415  
416 =for ref
417  
418 return type related synonym definitions to be included in pdl.h .
419 This routine must be updated to include new types as required.
420 Mostly the automatic updating should take care of the vital
421 things.
422  
423 =cut
424  
425 0 ▶sub typesynonyms {
Subroutine typesynonyms: not called CC=1 SCAR=6.9
Pod documented
426 my $add = join "\n",
427 0 map {"#define PDL_".typefld($_,'ppsym')." ".typefld($_,'sym')}
428 0 grep {"PDL_".typefld($_,'ppsym') ne typefld($_,'sym')} typesrtkeys;
429 0 return "$add\n";
430 }
431  
432 =head1 PDL TYPES OVERVIEW
433  
434 As of 2.065, PDL supports these types:
435  
436 =over
437  
438 =item SByte
439  
440 Signed 8-bit value.
441  
442 =item Byte
443  
444 Unsigned 8-bit value.
445  
446 =item Short
447  
448 Signed 16-bit value.
449  
450 =item UShort
451  
452 Unsigned 16-bit value.
453  
454 =item Long
455  
456 Signed 32-bit value.
457  
458 =item ULong
459  
460 Unsigned 32-bit value.
461  
462 =item Indx
463  
464 Signed value, same size as a pointer on the system in use.
465  
466 =item ULongLong
467  
468 Unsigned 64-bit value.
469  
470 =item LongLong
471  
472 Signed 64-bit value.
473  
474 =item Float
475  
476 L<IEEE 754|https://en.wikipedia.org/wiki/IEEE_754> single-precision real
477 floating-point value.
478  
479 =item Double
480  
481 IEEE 754 double-precision real value.
482  
483 =item LDouble
484  
485 A C99 "long double", defined as "at least as precise as a double",
486 but often more precise.
487  
488 =item CFloat
489  
490 A C99 complex single-precision floating-point value.
491  
492 =item CDouble
493  
494 A C99 complex double-precision floating-point value.
495  
496 =item CLDouble
497  
498 A C99 complex "long double" - see above for description.
499  
500 =back
501  
502 As of 2.099, documentation for L<PDL::Type> is separate. See there for more.
503  
504 =cut
505  
506 77 my @CACHED_TYPES = map bless([$_->{numval}, $_], 'PDL::Type'), @HASHES;
507 # return all known types as type objects
508 304 ▶sub types { @CACHED_TYPES }
Subroutine types: called CC=1 SCAR=0.0
Pod undocumented
509  
510 {
511 package PDL::Type;
512  
513 77 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
514 14863 ▶sub new {
Subroutine new: called CC=7 SCAR=22.7
515 14863 my ($type,$val) = @_;
516 14863 ▶ return $val if "PDL::Type" eq ref $val;
Branch: 1 branch
BranchTrueFalseTotal
if "PDL::Type" eq ref $val 347 14516 14863
517 14516 ▶ if (ref $val and UNIVERSAL::isa($val, 'PDL')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val and UNIVERSAL::isa($val, "PDL")) 0 14516 14516
Condition33%1/3
ref $val and UNIVERSAL::isa($val, "PDL")
!ll&&!rl&&r
1451600
MC/DC0%0/2
ref $val and UNIVERSAL::isa($val, "PDL")
ref $val UNIVERSAL::isa($val, "PDL")
Truth table33%1/3
A and B
A= ref $valB= UNIVERSAL::isa($val, "PDL")
ABresult
0X0
100
111
518 0 ▶ PDL::Core::barf("Can't make a type out of non-scalar ndarray $val!")
Branch: 1 branch
BranchTrueFalseTotal
if $val->getndims != 0 0 0 0
519 if $val->getndims != 0;
520 0 $val = $val->at;
521 }
522 14516 ▶ confess "Can't make a type out of non-scalar $val (".
Branch: 1 branch
BranchTrueFalseTotal
if ref $val 0 14516 14516
523 (ref $val).")!" if ref $val;
524 confess "Unknown type string '$val' (should be one of ".
525 join(",",map $PDL::Types::typehash{$_}{ioname}, @names).
526 ")\n"
527 14516 ▶ if !defined $PDL::Types::typenames{$val};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $PDL::Types::typenames{$val} 1 14515 14516
528 14515 $CACHED_TYPES[$PDL::Types::typenames{$val}];
529 }
530  
531 10421 ▶sub enum { $_[0][0] }
Subroutine enum: called CC=1 SCAR=0.0
532 77 *symbol = \&sym;
533  
534 0 ▶sub realversion {
Subroutine realversion: not called CC=1 SCAR=6.9
535 0 $CACHED_TYPES[$PDL::Types::typenames{ $_[0][1]{realversion} }];
536 }
537 71 ▶sub complexversion {
Subroutine complexversion: called CC=1 SCAR=0.0
538 71 $CACHED_TYPES[$PDL::Types::typenames{ $_[0][1]{complexversion} }];
539 }
540 0 ▶sub isnan { sprintf $_[0][1]{isnan}, $_[1] }
Subroutine isnan: not called CC=1 SCAR=6.9
541 0 ▶sub isfinite { sprintf $_[0][1]{isfinite}, $_[1] }
Subroutine isfinite: not called CC=1 SCAR=6.9
542  
543 77 my (%bswap_cache, %howbig_cache);
544 7940 ▶sub bswap {
Subroutine bswap: called CC=5 SCAR=16.2
545 7940 ▶ PDL::Core::barf('Usage: $type->bswap with no args') if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 7940 7940
546 7940 ▶ return $bswap_cache{$_[0][0]} if $bswap_cache{$_[0][0]};
Branch: 1 branch
BranchTrueFalseTotal
if $bswap_cache{$_[0][0]} 7897 43 7940
547 43 my $size = $_[0]->howbig;
548 43 ▶ return $bswap_cache{$_[0][0]} = sub {} if $size < 2;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $size < 2 8 35 43
549 35 require PDL::IO::Misc;
550 35 my $swapper = PDL->can("bswap$size");
551 35 ▶ PDL::Core::barf("Type::bswap couldn't find swap function for $_[0][1]{shortctype}, size was '$size'") if !defined $swapper;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $swapper 0 35 35
552 35 $bswap_cache{$_[0][0]} = $swapper;
553 }
554  
555 65 ▶sub howbig {
Subroutine howbig: called CC=2 SCAR=7.2
556 65 ▶ $howbig_cache{$_[0][0]} ||= PDL::Core::howbig($_[0][0]);
Condition66%2/3
$howbig_cache{$_[0][0]} ||= PDL::Core::howbig($_[0][0])
l!l&&r!l&&!r
7580
MC/DC0%0/2
$howbig_cache{$_[0][0]} ||= PDL::Core::howbig($_[0][0])
$howbig_cache{$_[0][0]} PDL::Core::howbig($_[0][0])
Truth table66%2/3
A ||= B
A= $howbig_cache{$_[0][0]}B= PDL::Core::howbig($_[0][0])
ABresult
1X1
011
000
557 }
558  
559 77 foreach my $name (@TYPE_VERBATIM) {
560 77 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
561 8060 ▶ *$name = sub { $_[0][1]{$name}; };
Subroutine __ANON__: called CC=1 SCAR=0.0
562 }
563  
564 114 ▶sub badvalue {
Subroutine badvalue: called CC=1 SCAR=0.0
565 114 PDL::Bad::_badvalue_int( $_[1], $_[0][0] );
566 }
567 5 ▶sub orig_badvalue {
Subroutine orig_badvalue: called CC=1 SCAR=0.0
568 5 PDL::Bad::_default_badvalue_int($_[0][0]);
569 }
570  
571 # make life a bit easier
572 77 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
573 1319 ▶ '""' => sub { lc $_[0]->shortctype },
Subroutine __ANON__: called CC=1 SCAR=0.0
574 236 ▶ "eq" => sub { my ($self, $other, $swap) = @_; ("$self" eq $other); },
Subroutine __ANON__: called CC=1 SCAR=0.0
575 2 ▶ "cmp" => sub { my ($self, $other, $swap) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
576 2 ▶ $swap ? $other cmp "$self" : "$self" cmp $other;
Branch: 1 branch
BranchTrueFalseTotal
$swap ? : 1 1 2
577 },
578 1951 ▶ "<=>" => sub { $_[2] ? $_[1][0] <=> $_[0][0] : $_[0][0] <=> $_[1][0] },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 1951 1951
579 77 );
580 } # package: PDL::Type
581 # Return
582 77 1;
583  
584 __END__
« blib/lib/PDL/FFT.pm ↑ Summary blib/lib/PDL/Install/Files.pm »