Skip to content

Commit

Permalink
Return PDL::Complex types for some arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
wlmb authored and mohawk2 committed Mar 23, 2021
1 parent fff36d8 commit 816204c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- PDL::Complex outputs where appropriate - thanks @wlmb

0.11 2021-03-23
- support PDL 2.027+ "native complex" inputs for fftn and ifftn

Expand Down
10 changes: 5 additions & 5 deletions FFTW3_header_include.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ EOF
eval { no strict 'refs'; $internal_function->( $in, $out, $plan ) };
barf $@ if $@;

return $out;
($in->isa('PDL::Complex') && !($do_inverse_fft && $is_real_fft))
? $out->complex : $out;
}

sub getOutArgs {
Expand Down Expand Up @@ -131,10 +132,9 @@ EOF

my $type = ref $arg;
$type = 'scalar' unless defined $arg;

barf <<EOF unless ref $arg && ($type eq 'PDL' or (!$is_real_fft and $type eq 'PDL::Complex'));
$thisfunction arguments must be of type 'PDL'. Instead I got an arg of
type '$type'. Giving up.
barf <<EOF unless ref $arg && $arg->isa('PDL');
$thisfunction arguments must be of type 'PDL' (including 'PDL::Complex').
Instead I got an arg of type '$type'. Giving up.
EOF
}

Expand Down
13 changes: 12 additions & 1 deletion t/fftw.t
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ sub other2native {

my $x_cplx = cplx $x;
my $cplx_result = fft1($x_cplx);
ok_should_make_plan( all( approx( $cplx_result, $Xref, approx_eps_double) ),
ok_should_make_plan( all( approx( $cplx_result, $Xref->cplx, approx_eps_double) ),
"Basic 1D complex FFT with PDL::Complex" );
isa_ok($cplx_result, 'PDL::Complex', "PDL::Complex return type");

ok_should_make_plan( all( approx( ifft1(fft1($x)), $x, approx_eps_double) ),
"Basic 1D complex FFT - inverse(forward) should be the same (normalized)" );
Expand Down Expand Up @@ -520,6 +521,16 @@ sub other2native {
ok_should_make_plan( all( approx( $x7, $x7_back, approx_eps_double) ),
"rfft basic test - backward - 7long" );

# Test real fft's with PDL::Complex arguments
my $fx6c=rfft1($x6, zeroes(2,4)->cplx);
isa_ok($fx6c, 'PDL::Complex', 'type of real to PDL::Complex forward transform');
ok_should_reuse_plan(all( approx($fx6c, $fx6_ref->slice(':,0:3')->cplx, approx_eps_double) ),
'value of real to PDL::Complex forward transform');
my $x6c_back=irfft1($fx6c);
ok($x6c_back->isa('PDL') && !$x6c_back->isa('PDL::Complex'),
'type of PDL::Complex to real backward transform');
ok(all( approx($x6c_back, $x6, approx_eps_double) ),
'value of PDL::Complex to real backward transform');

# Currently a single plan is made for ALL the thread slices. These tests are
# meant to exercise cases where this is a bad assumption. I.e. where some
Expand Down

0 comments on commit 816204c

Please sign in to comment.