| 1 | ##-*- Mode: CPerl -*- | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Test::More; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | ##-- common subs | ||||||||||||||||||||||||||||
| 7 | 1 | my $TEST_DIR; | |||||||||||||||||||||||||||
| 8 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | $TEST_DIR = Cwd::abs_path dirname( __FILE__ ); | |||||||||||||||||||||||||||
| 12 | 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
| |||||||||||||||||||||||||||||
| 13 | #do "$TEST_DIR/common.plt" or die("$0: failed to load $TEST_DIR/common.plt: $@"); | ||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | ##-- common modules | ||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use PDL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use PDL::CCS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use_ok('PDL::CCS::IO::Common'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use_ok('PDL::CCS::IO::FastRaw'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use_ok('PDL::CCS::IO::FITS'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use_ok('PDL::CCS::IO::MatrixMarket'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use_ok('PDL::CCS::IO::LDAC'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use_ok('PDL::CCS::IO::PETSc'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | $| = 1; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | ##-- basic data | ||||||||||||||||||||||||||||
| 31 | 1 | my $a = pdl(double, [ | |||||||||||||||||||||||||||
| 32 | [10,0,0,0,-2], | ||||||||||||||||||||||||||||
| 33 | [3,9,0,0,0], | ||||||||||||||||||||||||||||
| 34 | [0,7,8,7,0], | ||||||||||||||||||||||||||||
| 35 | [3,0,8,7,5], | ||||||||||||||||||||||||||||
| 36 | [0,8,0,9,9], | ||||||||||||||||||||||||||||
| 37 | [0,4,0,0,2], | ||||||||||||||||||||||||||||
| 38 | ]); | ||||||||||||||||||||||||||||
| 39 | 1 | my $ccs = $a->toccs(); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | ##-- pdl equality | ||||||||||||||||||||||||||||
| 42 | 14 | ▶ | sub pdleq { | ||||||||||||||||||||||||||
|
Subroutine
pdleq: called CC=6 SCAR=19.9
| |||||||||||||||||||||||||||||
| 43 | 14 | my ($a,$b) = @_; | |||||||||||||||||||||||||||
| 44 | 14 | ▶ | return 0 if (!$a->ndims == $b->ndims || !all(pdl(long,[$a->dims])==pdl(long,[$b->dims]))); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
!$a->ndims == $b->ndims or not all(pdl(long(), [$a->dims]) == pdl(long(), [$b->dims]))
MC/DC0%0/2
!$a->ndims == $b->ndims or not all(pdl(long(), [$a->dims]) == pdl(long(), [$b->dims]))
!$a->ndims == $b->ndims
not all(pdl(long(), [$a->dims]) == pdl(long(), [$b->dims]))
Truth table33%1/3
not(A) or not(B)
A= !$a->ndims == $b->ndimsB= not all(pdl(long(), [$a->dims]) == pdl(long(), [$b->dims]))
| |||||||||||||||||||||||||||||
| 45 | 14 | ▶ | if (UNIVERSAL::isa($a,'PDL::CCS::Nd')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 12 | ▶ | return 0 if ($a->_nnz_p != $b->_nnz_p); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 12 | ▶ | return all($a->_whichND==$b->_whichND) && all($a->_vals==$b->_vals); | ||||||||||||||||||||||||||
|
Condition33%1/3
all($a->_whichND == $b->_whichND) && all($a->_vals == $b->_vals)
MC/DC0%0/2
all($a->_whichND == $b->_whichND) && all($a->_vals == $b->_vals)
all($a->_whichND == $b->_whichND)
all($a->_vals == $b->_vals)
Truth table33%1/3
A && B
A= all($a->_whichND == $b->_whichND)B= all($a->_vals == $b->_vals)
| |||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||
| 49 | 2 | return all($a==$b); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | ##-- *6: i/o testing | ||||||||||||||||||||||||||||
| 54 | 14 | ▶ | sub iotest { | ||||||||||||||||||||||||||
|
Subroutine
iotest: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 55 | 14 | my ($p, $file, $reader,$writer, $opts) = @_; | |||||||||||||||||||||||||||
| 56 | 14 | my ($q); | |||||||||||||||||||||||||||
| 57 | 14 | ▶ | $reader = $p->can($reader) if (!ref($reader)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 14 | ▶ | $writer = $p->can($writer) if (!ref($writer)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 14 | ok(defined($writer), "$file - writer sub"); | |||||||||||||||||||||||||||
| 60 | 14 | ok(defined($reader), "$file - reader sub"); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 14 | ok($writer->($p,"$TEST_DIR/$file",$opts), "$file - write"); | |||||||||||||||||||||||||||
| 63 | 14 | ok(defined($q = $reader->("$TEST_DIR/$file",$opts)), "$file - read"); | |||||||||||||||||||||||||||
| 64 | 14 | is(ref($q), ref($p), "$file - ref"); | |||||||||||||||||||||||||||
| 65 | 14 | ok(pdleq($p,$q), "$file - data"); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | ##-- unlink test data | ||||||||||||||||||||||||||||
| 68 | #unlink($_) foreach (glob("$TEST_DIR/$file*")); | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | ##-- x1 : raw | ||||||||||||||||||||||||||||
| 72 | 1 | iotest($ccs, 'ccs.raw', qw(readfraw writefraw)); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | ##-- x2 : fits | ||||||||||||||||||||||||||||
| 75 | 1 | iotest($ccs, 'ccs.fits', qw(rfits wfits)); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | ##-- x3-x8 : mm | ||||||||||||||||||||||||||||
| 78 | 1 | do { | |||||||||||||||||||||||||||
| 79 | 1 | iotest($ccs, 'ccs.mm', qw(readmm writemm)); ##-- mm: sparse | |||||||||||||||||||||||||||
| 80 | 1 | iotest($ccs, 'ccs.mm0', qw(readmm writemm), {header=>0}); ##-- mm: sparse, no header | |||||||||||||||||||||||||||
| 81 | 1 | iotest($a, 'dense.mm', qw(readmm writemm)); ##-- mm: dense | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 1 | my $a3 = $a->cat($a->rotate(1)); | |||||||||||||||||||||||||||
| 84 | 1 | my $ccs3 = $a3->toccs; | |||||||||||||||||||||||||||
| 85 | 1 | iotest($ccs3, 'ccs3.mm', qw(readmm writemm)); ##-- mm3: sparse | |||||||||||||||||||||||||||
| 86 | 1 | iotest($ccs3, 'ccs3.mm0', qw(readmm writemm), {header=>0}); ##-- mm3: sparse, no header | |||||||||||||||||||||||||||
| 87 | 1 | iotest($a3, 'dense3.mm', qw(readmm writemm)); ##-- mm3: dense | |||||||||||||||||||||||||||
| 88 | }; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | ##-- x9-x12 : ldac | ||||||||||||||||||||||||||||
| 91 | 1 | do { | |||||||||||||||||||||||||||
| 92 | 1 | iotest($ccs, 'ccs.ldac', qw(readldac writeldac)); ##-- ldac: natural | |||||||||||||||||||||||||||
| 93 | 1 | iotest($ccs, 'ccs.ldac0', qw(readldac writeldac), {header=>0}); ##-- ldac: natural, no-header | |||||||||||||||||||||||||||
| 94 | 1 | iotest($ccs, 'ccs.ldact', qw(readldac writeldac), {transpose=>1}); ##-- ldac: transposed | |||||||||||||||||||||||||||
| 95 | 1 | iotest($ccs, 'ccs.ldact0', qw(readldac writeldac), {header=>0,transpose=>1}); ##-- ldac: transposed, no-header | |||||||||||||||||||||||||||
| 96 | }; | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | ##-- x13-x14: petsc | ||||||||||||||||||||||||||||
| 99 | 1 | do { | |||||||||||||||||||||||||||
| 100 | 1 | iotest($ccs, 'ccs.petsc', qw(rpetsc wpetsc)); ##-- petsc: bin | |||||||||||||||||||||||||||
| 101 | 1 | iotest($ccs, 'ccs.petscb', qw(rpetsc wpetsc), {ioblock=>2}); ##-- petsc: bin, with block i/o | |||||||||||||||||||||||||||
| 102 | }; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | done_testing; | |||||||||||||||||||||||||||