Skip to content

Commit

Permalink
FFT tests replace tapprox with is_pdl - #34
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Oct 29, 2024
1 parent 4db9639 commit 6551403
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions Basic/Lib-FFT/t/fft.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use PDL;
use PDL::FFT;
use Test::More;
use Test::Exception;

sub tapprox {
my($pa,$pb) = @_;
all approx $pa, $pb, 0.01;
}
use Test::PDL -atol => 0.01, -require_equal_types => 0;

foreach my $type(double,float,cdouble,cfloat){
my $pa = pdl($type,1,-1,1,-1);
Expand All @@ -29,35 +25,35 @@ fft($pb,$pc);
ifft($pb,$pc);
fft($pd);
ifft($pd);
ok (tapprox($pc,0), "fft zeroes");
ok (tapprox($pd->im,0), "fft zeroes using complex ndarrays");
ok (tapprox($pa,$pb), "original image recovered");
is_pdl $pc, $pb->zeroes, "fft zeroes";
is_pdl $pd->im, $pb->zeroes, "fft zeroes using complex ndarrays";
is_pdl $pa, $pb, "original image recovered";
}

{
my $pb = $pa->copy;
my $pc = $pb->zeroes;
my $pd=czip($pb, $pc);
fftnd($pb,$pc); ifftnd($pb,$pc);
ok ( tapprox($pc,0), "fftnd zeroes");
ok ( tapprox($pa,$pb), "fftnd real image");
is_pdl $pc, $pb->zeroes, "fftnd zeroes";
is_pdl $pa, $pb, "fftnd real image";
fftnd($pd); ifftnd($pd);
ok ( tapprox($pd,$pb), "fftnd native complex image with imag zeroes");
is_pdl $pd, $pb, "fftnd native complex image with imag zeroes";
}

{
my $pb = $pa->slice("1:35,1:69");
my $pc = $pb->copy; fftnd($pb,$pc); ifftnd($pb,$pc);
ok ( tapprox($pc,$pb), "fftnd real and imaginary");
ok ( tapprox($pa->slice("1:35,1:69"),$pb), "fftnd original restored");
is_pdl $pc, $pb, "fftnd real and imaginary";
is_pdl $pa->slice("1:35,1:69"), $pb, "fftnd original restored";
}

{
my $pb = $pa->copy;
# Test real ffts
realfft($pb);
realifft($pb);
ok( tapprox($pa,$pb), "realfft");
is_pdl $pa, $pb, "realfft";
}

# Test that errors are properly caught
Expand Down

0 comments on commit 6551403

Please sign in to comment.