CCS/t/02_indexing.t

filter: Statementstmt 100% 81 / 81 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 98.9% 94 / 95 CC 3 SCAR 3.6
CC
3
Cov
99%
BEGIN
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« CCS/Utils/t/01_nnz.t ↑ Summary CCS/t/common.plt »
1 # -*- Mode: CPerl -*-
2 # t/02_indexing.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 ##-- common subs
8 1 my $TEST_DIR;
9 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
10 1 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶ use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 $TEST_DIR = Cwd::abs_path dirname( __FILE__ );
13 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
14 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
15 }
16  
17 ##-- common modules
18 1 ▶use PDL;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use PDL::CCS::Nd;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use PDL::VectorValued;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 ##--------------------------------------------------------------
23 ## missing==0
24  
25 1 my $ccs = $a->toccs;
26  
27 ##-- 1: which
28 1 pdlok("which:flat", $ccs->which->qsort, $a->which->qsort);
29  
30 ##-- 2: index (flat) ------------------> NO PSEUDO-THREADING!
31 1 my $find = pdl(long(2,4,6,8));
32 1 pdlok("index:flat", $ccs->index($find), $a->flat->index($find));
33  
34 ##-- 3: indexND
35 1 $find = pdl(long,[[0,0],[1,0],[1,1]]);
36 1 pdlok("indexND", $ccs->indexND($find), $a->indexND($find));
37  
38 ##-- 4..5: dice_axis
39 1 my $axisi = pdl(long,[2,4]);
40 1 pdlok("dice_axis(0)", $a->dice_axis(0,$axisi), $ccs->dice_axis(0,$axisi)->decode);
41 1 pdlok("dice_axis(1)", $a->dice_axis(1,$axisi), $ccs->dice_axis(1,$axisi)->decode);
42  
43 ##-- 6..8: at,set
44 1 my @nzindex = (4,3);
45 1 my @zindex = (3,1);
46 1 isok("at():nz", $ccs->at(@nzindex), $a->at(@nzindex));
47 1 isok("at:z", $ccs->at(@zindex), $a->at(@zindex));
48 1 pdlok("set():nz", $ccs->set(@nzindex,42)->decode, $a->set(@nzindex,42));
49  
50 ##-- 9..10: reorder
51 1 pdlok("reorder(1,0)", $ccs->reorder(1,0)->decode, $a->reorder(1,0));
52 1 pdlok("post-reorder(1,0):decode", $ccs->decode, $a);
53  
54 ##-- 11..12: xchg(0,1)
55 1 pdlok("xchg(0,1)", $ccs->xchg(0,1)->decode, $a->xchg(0,1));
56 1 pdlok("post-xchg(0,1):decode", $ccs->decode, $a);
57  
58 ##-- 13..14: xchg(0,-1)
59 1 pdlok("xchg(0,-1)", $ccs->xchg(0,-1)->decode, $a->xchg(0,-1));
60 1 pdlok("post-xchg(0,-1):decode", $ccs->decode, $a);
61  
62 ##-- 15..16: mv(0,1)
63 1 pdlok("mv(0,1)", $ccs->mv(0,1)->decode, $a->mv(0,1));
64 1 pdlok("post-mv(0,1):decode", $ccs->decode, $a);
65  
66 ##-- 17..18: mv(1,0)
67 1 pdlok("mv(1,0)", $ccs->mv(1,0)->decode, $a->mv(1,0));
68 1 pdlok("post-mv(1,0):decode", $ccs->decode, $a);
69  
70 ##-- 19..22: xsubset2d
71 1 my $ai = pdl(long, [1,2,4]);
72 1 my $bi = pdl(long, [2,4]);
73 1 my $wnd = $ai->slice("*".$bi->nelem.",")->cat($bi)->clump(2)->xchg(0,1);
74 1 my $abi = $wnd->vsearchvec($ccs->_whichND);
75 1 my $abi_mask = ($wnd==$ccs->_whichND->dice_axis(1,$abi))->andover;
76 1 $abi = $abi->where($abi_mask);
77 1 my $absub = $ccs->xsubset2d($ai,$bi);
78 1 isok("xsubset2d:defined", defined($absub));
79 1 pdlok("xsubset2d:which", $absub->_whichND, $ccs->_whichND->dice_axis(1,$abi));
80 1 pdlok("xsubset2d:nzvals", $absub->_nzvals, $ccs->_nzvals->index($abi));
81 1 pdlok("xsubset2d:missing", $absub->missing, $ccs->missing);
82  
83 ##-- 23..24: xsubset1d
84 1 my $xi = pdl(long, [0,2]);
85 1 my $sub1 = $ccs->xsubset1d($xi);
86 1 isok("xsubset1d:defined", defined($sub1));
87 1 pdlok("xsubset1d:vals", $sub1->decode->dice_axis(0,$xi), $a->dice_axis(0,$xi));
88  
89 ##-- 25..26: pxsubset1d
90 1 my $yi = pdl(long, [1,3]);
91 1 my $sub2 = $ccs->pxsubset1d(1,$yi);
92 1 isok("pxsubset1d:defined", defined($sub2));
93 1 pdlok("pxsubset1d:vals", $sub2->decode->dice_axis(1,$yi), $a->dice_axis(1,$yi));
94  
95 1 done_testing;
« CCS/Utils/t/01_nnz.t ↑ Summary CCS/t/common.plt »