File: primitive2.t

package info (click to toggle)
pdl 2.005-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,200 kB
  • ctags: 3,301
  • sloc: perl: 14,876; ansic: 7,223; fortran: 3,417; makefile: 54; sh: 16
file content (93 lines) | stat: -rw-r--r-- 1,925 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Script to test some of the primitive operations for returning the correct values.
#
#  
#  Testing utility functions:
sub ok {
        my $no = shift ;
        my $result = shift ;
        print "not " unless $result ;
        print "ok $no\n" ;
}

sub approx {
        my($a,$b) = @_;
        my $c = abs($a-$b);
        my $d = ref($c) ? max($c) : $c ;  # don't do a make if were are dealing 
					  # with a scalar
        $c < 0.01;
}


###### Testing Begins #########
print "1..18\n";  


use PDL::LiteF;


$im = new PDL [
  [ 1, 2,  3,  3 , 5],
  [ 2,  3,  4,  5,  6],
  [13, 13, 13, 13, 13],
  [ 1,  3,  1,  3,  1],
  [10, 10,  2,  2,  2,]
 ];


my @minMax = $im->minmax;
# print "MinMax = ".join(", ",@minMax)."\n";

my $testNo = 1;

ok($testNo++, $minMax[0] == 1 );
ok($testNo++, $minMax[1] == 13 );


ok($testNo++, ($im x $im)->sum == 3429 );


my @statsRes = $im->stats;

ok($testNo++, approx($statsRes[0],5.36) );
ok($testNo++, approx($statsRes[1],4.4621) );
ok($testNo++, approx($statsRes[2],3) );
ok($testNo++, approx($statsRes[3],1) );
ok($testNo++, approx($statsRes[4],13) );

# print "StatRes = ".join(", ",@statsRes)."\n";


my $ones = ones(5,5);

@statsRes = $im->stats($ones);

# print "StatRes with moments = ".join(", ",@statsRes)."\n";
ok($testNo++, approx($statsRes[0],5.36) );
ok($testNo++, approx($statsRes[1],4.4621) );
ok($testNo++, approx($statsRes[2],3) );
ok($testNo++, approx($statsRes[3],1) );
ok($testNo++, approx($statsRes[4],13) );


# which ND test
my $a= PDL->sequence(10,10,3,4);  

($x, $y, $z, $w)=whichND($a == 203);

ok($testNo++,$a->at($x->list,$y->list,$z->list,$w->list) == 203 );
 

# clip tests
ok($testNo++, approx($im->hclip(5)->sum,83) );

ok($testNo++, approx($im->lclip(5)->sum,176) );


ok($testNo++, approx($im->clip(5,7)->sum,140) );

# indadd Test:
$a = pdl( 1,2,3);
$ind = pdl( 1,4,6);
$sum = zeroes(10);
indadd($a,$ind, $sum);
ok($testNo++, approx($sum->sum,6) );