Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /t/fftw.t [000000] .. [f1f585] Maximize Restore

  Switch to unified view

a b/t/fftw.t
1
use strict;
2
3
use PDL;
4
use PDL::FFT;
5
use Test::More;
6
7
eval "use PDL::FFTW;";
8
my $loaded = ($@ ? 0 : 1);
9
10
# this value is add-hoc and adjusted each time we find a problem with a
11
# given OS or library version of FFTW...
12
#
13
# We use the PDL::Core::approx() routine for comparing piddles
14
#
15
use constant ABSDIFF => 1.2e-4;
16
17
if ($loaded) {
18
   plan tests => 9;
19
} else {
20
   plan skip_all => "PDL::FFTW not available";
21
}
22
23
# get the type (double or float) used by the FFTW library and module
24
# The eval() is to avoid warning messages from Perl
25
#
26
my $datatype = eval('$PDL::FFTW::COMPILED_TYPE');
27
28
my $n = 30;
29
my $m = 40;
30
31
my ( $ir, $ii, $i, $fi, $fir, $fii, $ffi );
32
$ir = zeroes($n,$m)->$datatype();
33
$ii = zeroes($n,$m)->$datatype();
34
$ir = random $ir;
35
$ii = random $ii;
36
37
$i = cat $ir,$ii;
38
$i = $i->mv(2,0);
39
$fi = ifftw $i;
40
41
$fir = $ir->copy;
42
$fii = $ii->copy;
43
fftnd $fir,$fii;
44
$ffi = cat $fir,$fii;
45
$ffi = $ffi->mv(2,0);
46
47
my ( $t, $orig, $i2, $sffi );
48
$t = ($ffi-$fi)*($ffi-$fi);
49
50
# print diff fftnd and ifftw: ",sqrt($t->sum),"\n";
51
ok(approx(sqrt($t->sum),pdl(0),ABSDIFF),
52
   "fftnd() and ifftw()");
53
54
$orig = fftw $fi;
55
$orig /= $n*$m;
56
57
$t = ($orig-$i)*($orig-$i);
58
# print "diff ifftw fftw and orig: ",sqrt($t->sum),"\n";
59
ok(approx(sqrt($t->sum),pdl(0),ABSDIFF),
60
   "ifftw() fftw() and original");
61
62
# Inplace FFT
63
$i2 = $i->copy;
64
65
infftw($i2);
66
67
$t = ($i2-$ffi)*($i2-$ffi);
68
# print "diff fftnd and infftw: ",sqrt($t->sum),"\n";
69
ok(approx(sqrt($t->sum),pdl(0),ABSDIFF),
70
   "fftnd and infftw");
71
72
$i2 = nfftw $i2;
73
$i2 /= $n*$m;
74
75
$t = ($i-$i2)*($i-$i2);
76
# print "diff infftw nfftw and orig: ",sqrt($t->sum),"\n";
77
ok(approx(sqrt($t->sum),pdl(0),ABSDIFF),
78
   "infftw nfftw and original");
79
80
$ir = zeroes($n,$m)->$datatype();
81
$ii = zeroes($n,$m)->$datatype();
82
$ir = random $ir;
83
84
$fir = $ir->copy;
85
$fii = $ii->copy;
86
ifftnd $fir,$fii;
87
$ffi = cat $fir,$fii;
88
$ffi = $ffi->mv(2,0);
89
$ffi *= $n*$m;
90
$sffi = $ffi->mslice('X',[0,$n/2],'X');
91
92
$fi = rfftw $ir;
93
94
$t = ($sffi-$fi)*($sffi-$fi);
95
# print "diff rfftw and infft: ",sqrt($t->sum),"\n";
96
ok(approx(sqrt($t->sum),pdl(0),ABSDIFF),
97
   "rfftw() and infft()");
98
99
$orig = irfftw $fi;
100
$orig /= $n*$m;
101
102
$t = ($orig-$ir)*($orig-$ir);
103
# print "diff ifftw fftw and orig: ",sqrt($t->sum),"\n";
104
ok(approx(sqrt($t->sum),pdl(0),ABSDIFF),
105
   "ifftw() fftw() and original");
106
107
my ( $rin, $srin, $tmp );
108
$rin = zeroes(2*(int($n/2)+1),$m)->$datatype();
109
$tmp = $rin->mslice([0,$n-1],'X');
110
$tmp .= $ir;
111
$srin = $rin->copy;
112
113
$rin = nrfftw $rin;
114
115
$t = ($sffi-$rin)*($sffi-$rin);
116
# print "diff nrfftw and infft: ",sqrt($t->sum),"\n";
117
ok(approx(sqrt($t->sum),pdl(0),ABSDIFF),
118
   "nrfftw() and infft()");
119
120
$rin = inrfftw $rin;
121
$rin /= $n*$m;
122
123
$rin = $rin->mslice([0,$n-1],'X');
124
$srin = $srin->mslice([0,$n-1],'X');
125
126
$t = ($srin-$rin)*($srin-$rin);
127
# print "diff inrfftw nrfftw and orig: ",sqrt($t->sum),"\n";
128
ok(approx(sqrt($t->sum),pdl(0),ABSDIFF),
129
   "inrfftw() nrfftw() and original");
130
131
# do the inplace routines work with slices?
132
my $a = ones(2,4)->$datatype();
133
my $fa = fftw $a;
134
nfftw $a->slice('');
135
ok(approx($fa,$a,ABSDIFF)->all,
136
   "inplace routine (nfftw) works with slices");
137
#print "$a\n$fa\n";