CCS/Ufunc/t/01_ufunc.t

filter: Statementstmt 100% 98 / 98 Branchbran 72.2% 13 / 18 Conditioncond 77.7% 7 / 9 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 16 / 16 Podpod n/a totaltotal 93.2% 137 / 147 CC 13 SCAR 14.0
CC
13
Cov
94%
test_ufunc
9.2
test_borover_output_type
3.0
BEGIN
3.0
CRAP 4.1
« CCS/t/05_binops.t ↑ Summary CCS/t/04_unops.t »
1 # -*- Mode: CPerl -*-
2 # t/01_ufunc.t
3 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 ##-- common subs
9 1 my $TEST_DIR;
10 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
11 1 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶ use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 $TEST_DIR = Cwd::abs_path dirname( __FILE__ );
14 1 ▶ eval qq{use lib ("$TEST_DIR/$_/blib/lib","$TEST_DIR/$_/blib/arch");} foreach (qw(../../.. ../.. ..));
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶ do "$TEST_DIR/common.plt" or die("$0: failed to load $TEST_DIR/common.plt: $@");
Branch: 1 branch
BranchTrueFalseTotal
do "$TEST_DIR/common.plt" or die "$0: failed to load $TEST_DIR/common.plt: $@" 1 0 1
16 }
17  
18 ##-- common modules
19 1 ▶use PDL;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use PDL::CCS::Ufunc;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use PDL::VectorValued;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 ##-- basic data
25 1 my $a = pdl(double, [
26 [10,0,0,0,-2],
27 [3,9,0,0,0],
28 [0,7,8,7,0],
29 [3,0,8,7,5],
30 [0,8,0,9,9],
31 [0,4,0,0,2],
32 ]);
33  
34 1 my $agood = ($a!=0);
35 1 my $abad = !$agood;
36 1 my $awhich = $a->whichND;
37 1 my $awhich1 = $awhich->slice("(1)")->qsort->slice("*1,");
38 1 my $awhich1i = $awhich->slice("(1)")->qsorti;
39 1 my $avals = $a->indexND($awhich)->index($awhich1i);
40  
41 ##-- i..(i+2): test_ufunc($pdl_ufunc_name, $ccs_ufunc_name, $missing_val)
42 52 ▶sub test_ufunc {
Subroutine test_ufunc: called CC=9 SCAR=22.2
43 52 my ($pdl_ufunc_name, $ccs_ufunc_name, $missing_val) = @_;
44 52 print "test_ufunc($pdl_ufunc_name, $ccs_ufunc_name, $missing_val)\n";
45  
46 52 ▶ my $ccs_ufunc = PDL->can("ccs_accum_${ccs_ufunc_name}")
Branch: 1 branch
BranchTrueFalseTotal
my $ccs_ufunc = "PDL"->can("ccs_accum_$ccs_ufunc_name") or die "no CCS Ufunc ccs_accum_$ccs_ufunc_name defined!" 52 0 52
47 or die("no CCS Ufunc ccs_accum_${ccs_ufunc_name} defined!");
48 52 ▶ my $pdl_ufunc = PDL->can("${pdl_ufunc_name}")
Branch: 1 branch
BranchTrueFalseTotal
my $pdl_ufunc = "PDL"->can("$pdl_ufunc_name") or die "no PDL Ufunc $pdl_ufunc_name defined!" 52 0 52
49 or die("no PDL Ufunc ${pdl_ufunc_name} defined!");
50  
51 52 ▶ $missing_val = 0 if (!defined($missing_val));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $missing_val 0 52 52
52 52 $missing_val = PDL->topdl($missing_val);
53 52 ▶ if ($missing_val->isbad) { $a = $a->setbadif($abad); }
Branch: 1 branch
BranchTrueFalseTotal
if ($missing_val->isbad) { } 13 39 52
54 39 else { $a->where($abad) .= $missing_val; $a->badflag(0); }
55  
56 52 $missing_val = $missing_val->convert($a->type);
57 52 ▶ my @amissing = $missing_val->isbad && $ccs_ufunc_name !~ /^n(?:bad|good)/ ? (0,0) : ($missing_val,$a->dim(0));
Branch: 1 branch
BranchTrueFalseTotal
$missing_val->isbad && !($ccs_ufunc_name =~ /^n(?:bad|good)/) ? : 11 41 52
Condition100%3/3
$missing_val->isbad and not $ccs_ufunc_name =~ /^n(?:bad|good)/
!ll&&!rl&&r
39211
MC/DC100%2/2
$missing_val->isbad and not $ccs_ufunc_name =~ /^n(?:bad|good)/
$missing_val->isbad not $ccs_ufunc_name =~ /^n(?:bad|good)/
Truth table100%3/3
A and not(B)
A= $missing_val->isbadB= not $ccs_ufunc_name =~ /^n(?:bad|good)/
ABresult
0X0
100
111
58  
59 52 my $dense_rc = $pdl_ufunc->($a);
60 52 my ($which_rc,$nzvals_rc) = $ccs_ufunc->($awhich1, $avals, @amissing);
61 52 my $decoded_rc = $dense_rc->zeroes;
62 52 $decoded_rc .= $missing_val;
63 52 $decoded_rc->indexND($which_rc) .= $nzvals_rc;
64  
65 52 my $label = "${pdl_ufunc_name}:missing=$missing_val";
66  
67 ##-- exceptions
68 SKIP: {
69 ##-- RT bug #126294 (see also analogous tests in CCS/t/03_ufuncs.t)
70 ## - maybe test ($Config{stdchar}=~/unsigned/) or ($Config{stdchar} eq 'unsigned char') instead
71 52 ▶ skip("RT #126294 - PDL::borover() appears to be broken", 1)
Branch: 1 branch
BranchTrueFalseTotal
if $label eq "borover:missing=BAD" and pdl([10, 0, -2])->setvaltobad(0)->borover->sclr != -2 0 52 52
Condition66%2/3
$label eq "borover:missing=BAD" and pdl([10, 0, -2])->setvaltobad(0)->borover->sclr != -2
!ll&&!rl&&r
5110
MC/DC0%0/2
$label eq "borover:missing=BAD" and pdl([10, 0, -2])->setvaltobad(0)->borover->sclr != -2
$label eq "borover:missing=BAD" pdl([10, 0, -2])->setvaltobad(0)->borover->sclr != -2
Truth table66%2/3
A and B
A= $label eq "borover:missing=BAD"B= pdl([10, 0, -2])->setvaltobad(0)->borover->sclr != -2
ABresult
0X0
100
111
72 if ($label eq 'borover:missing=BAD' && pdl([10,0,-2])->setvaltobad(0)->borover->sclr != -2);
73  
74 ##-- actual test
75 52 pdlok("${label}:vals", $decoded_rc, $dense_rc);
76 }
77 }
78  
79 1 my $BAD = pdl(0)->setvaltobad(0);
80  
81 ##----------------------------------------------------------------------
82 ## generic tests
83  
84 1 for my $missing (0,1,31,$BAD) {
85 4 for my $pdl_ufunc_name (
86 #qw(sumover),
87 qw(sumover prodover dsumover dprodover),
88 qw(andover orover bandover borover),
89 qw(maximum minimum),
90 qw(nbadover ngoodover), #nnz
91 qw(average),
92 )
93 {
94 52 my $ccs_ufunc_name = $pdl_ufunc_name;
95 52 $ccs_ufunc_name =~ s/over$//;
96 52 test_ufunc($pdl_ufunc_name, $ccs_ufunc_name, $missing);
97 }
98 }
99  
100  
101 ##----------------------------------------------------------------------
102 ## specific tests
103  
104 ##-- test explicit output allocation
105 1 my $dense_rv = $a->sumover;
106 1 my $which_prealloc = zeroes(indx, 1, 6);
107 1 my $nzvals_prealloc = zeroes($a->type, 6);
108 1 foreach (
109 [null, null],
110 [null, $nzvals_prealloc],
111 [$which_prealloc, null],
112 [$which_prealloc, $nzvals_prealloc],
113 ) {
114 4 ▶ my $label = "sumover with explicit output PDLs (".join(', ', map {$_->isnull ? 'null' : 'pre-allocated'} @$_).")";
Branch: 1 branch
BranchTrueFalseTotal
$_->isnull ? : 4 4 8
115 4 my ($tmp_which, $tmp_nzvals) = @$_;
116 4 my ($which_rv,$nzvals_rv) = ccs_accum_sum($awhich1, $avals, 0, 0, $tmp_which, $tmp_nzvals);
117 4 my $decoded_rv = $dense_rv->zeroes;
118 4 $decoded_rv->indexND($which_rv) .= $nzvals_rv;
119  
120 4 pdlok($label, $decoded_rv, $dense_rv);
121 }
122  
123 ##-- test unexpected output type: https://github.com/moocow-the-bovine/PDL-CCS/issues/18
124 2 ▶sub test_borover_output_type {
Subroutine test_borover_output_type: called CC=3 SCAR=11.0
125 2 my ($label, $missing) = @_;
126 2 PDL::_ccs_accum_bor_int(
127 my $ixIn=PDL->pdl(indx, [[0]]),
128 my $nzvalsIn=pdl(double, [65536]),
129 $missing,
130 0,
131 my $ixOut=null,
132 my $nzvalsOut=null,
133 my $nOut=null
134 );
135 SKIP: {
136 2 ▶ skip("expect the unexpected if missing is passed as a scalar", 1)
Branch: 1 branch
BranchTrueFalseTotal
if not ref $missing and "version"->parse($PDL::VERSION) >= "version"->parse("2.096") 1 1 2
Condition66%2/3
not ref $missing and "version"->parse($PDL::VERSION) >= "version"->parse("2.096")
!ll&&!rl&&r
101
MC/DC50%1/2
not ref $missing and "version"->parse($PDL::VERSION) >= "version"->parse("2.096")
not ref $missing "version"->parse($PDL::VERSION) >= "version"->parse("2.096")
Truth table66%2/3
not(A) and B
A= not ref $missingB= "version"->parse($PDL::VERSION) >= "version"->parse("2.096")
ABresult
0X0
100
111
137 if (!ref($missing) && version->parse($PDL::VERSION) >= version->parse('2.096'));
138  
139 1 isok("test_borover_output_type:$label:type", $nzvalsOut->type, longlong);
140 1 pdlok("test_borover_output_type:$label:vals", $nzvalsOut, $nzvalsIn);
141 }
142 }
143 1 test_borover_output_type('missing=double', pdl(double, 0));
144 1 test_borover_output_type('missing=scalar', 0);
145  
146 1 print "\n";
147  
148 1 done_testing;
« CCS/t/05_binops.t ↑ Summary CCS/t/04_unops.t »