File: primitive2.t

package info (click to toggle)
pdl 1%3A2.4.7%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 10,128 kB
  • ctags: 5,821
  • sloc: perl: 26,328; fortran: 13,113; ansic: 9,378; makefile: 71; sh: 50; sed: 6
file content (108 lines) | stat: -rw-r--r-- 2,441 bytes parent folder | download | duplicates (4)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 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 tapprox {
        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..27\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++, tapprox($statsRes[0],5.36) );
ok($testNo++, tapprox($statsRes[1],4.554) );
ok($testNo++, tapprox($statsRes[2],3) );
ok($testNo++, tapprox($statsRes[3],1) );
ok($testNo++, tapprox($statsRes[4],13) );
ok($testNo++, tapprox($statsRes[6],4.462));

@statsRes = $im->short->stats; # Make sure that stats are promoted to floating-point

ok($testNo++, tapprox($statsRes[0],5.36) );
ok($testNo++, tapprox($statsRes[1],4.554) );
ok($testNo++, tapprox($statsRes[2],3) );
ok($testNo++, tapprox($statsRes[3],1) );
ok($testNo++, tapprox($statsRes[4],13) );
ok($testNo++, tapprox($statsRes[6],4.462));

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


my $ones = ones(5,5);

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

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

# 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 );
 
$a = pdl(1,2,3,4);
$b = append($a,2);
ok($testNo++,int(sum($b))==12);



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

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


ok($testNo++, tapprox($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++, tapprox($sum->sum,6) );