Skip to content

Commit

Permalink
zap irfft support for PDL::Complex
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Nov 26, 2024
1 parent 812287f commit 57d390b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 38 deletions.
2 changes: 1 addition & 1 deletion README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ a single-precision floating point transform (and return data of that type).
fft1( $x->byte )

As of 0.20, this module expects complex numbers to be stored as "native
complex" types (C<cfloat>, C<cdouble>). Outputs will also be native
complex" types (C<cfloat>, C<cdouble>). Complex outputs will also be native
complex.

Generally, the sizes of the input and the output must match. This is completely
Expand Down
22 changes: 1 addition & 21 deletions fftw3.pd
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ EOF
($is_native && !$is_real_fft) ? 'N' :
!$is_real_fft ? '' :
($is_native && $do_inverse_fft) ? 'irN' :
$do_inverse_fft ? 'ir' :
$do_inverse_fft ? barf("irfft no longer supports PDL::Complex") :
($is_native_output) ? 'rN' :
'r';
$internal_function .= "fft$rank";
Expand Down Expand Up @@ -755,26 +755,6 @@ EOF
$pp_def{Code} = $code_real_forward;
pp_def( "__rfft$rank", %pp_def );

# backward
# I have the complex dimensions. Have nhalf, but not n1
#
# if we're not given an output, there's an ambiguity. I want
# int($out->dim(0)/2) + 1 != $in->dim(1),
# however this could mean that
# $out->dim(0) = 2*$in->dim(1) - 2
# or
# $out->dim(0) = 2*$in->dim(1) - 1
#
# WITHOUT ANY OTHER INFORMATION, I ASSUME EVEN INPUT SIZES, SO I ASSUME
# $out->dim(0) = 2*$in->dim(1) - 2
$pp_def{RedoDimsCode} = <<'EOF';
if( $PDL(real)->dims[0] <= 0 )
$SIZE(n1) = 2*$PDL(complexv)->dims[1] - 2;
EOF
$pp_def{Pars} = "complexv($dims_complex_string); [o]real($dims_real_string);";
$pp_def{Code} = $code_real_backward;
pp_def( "__irfft$rank", %pp_def );

################################################################################
####### now native-complex version
shift @dims; # drop the (real,imag) dim
Expand Down
32 changes: 16 additions & 16 deletions t/fftw.t
Original file line number Diff line number Diff line change
Expand Up @@ -602,29 +602,29 @@ my $Nplans = 0;


# backward
my $x64_back = irfft2($x64_ref->slice(':,0:3,:') );
my $x64_back = irfft2(PDL::czip($x64_ref->slice(':,0:3,:')->using(0,1)) );
ok_should_make_plan( all( approx( $x64, $x64_back, approx_eps_double) ),
"rfft 2d test - backward - 6,4 - output returned" );

$x64_back = zeros(6,4);
irfft2($x64_ref->slice(':,0:3,:'), $x64_back );
irfft2(PDL::czip($x64_ref->slice(':,0:3,:')->using(0,1)), $x64_back );
ok_should_reuse_plan( all( approx( $x64, $x64_back, approx_eps_double) ),
"rfft 2d test - backward - 6,4 - output in arglist" );

my $x65_back = irfft2($x65_ref->slice(':,0:3,:') );
my $x65_back = irfft2(PDL::czip($x65_ref->slice(':,0:3,:')->using(0,1)) );
ok_should_make_plan( all( approx( $x65, $x65_back, approx_eps_double) ),
"rfft 2d test - backward - 6,5 - output returned" );

$x65_back = zeros(6,5);
irfft2($x65_ref->slice(':,0:3,:'), $x65_back );
irfft2(PDL::czip($x65_ref->slice(':,0:3,:')->using(0,1)), $x65_back );
ok_should_reuse_plan( all( approx( $x65, $x65_back, approx_eps_double) ),
"rfft 2d test - backward - 6,5 - output in arglist" );

my $x74_back = irfft2($x74_ref->slice(':,0:3,:'), zeros(7,4) );
my $x74_back = irfft2(PDL::czip($x74_ref->slice(':,0:3,:')->using(0,1)), zeros(7,4) );
ok_should_make_plan( all( approx( $x74, $x74_back, approx_eps_double) ),
"rfft 2d test - backward - 7,4" );

my $x75_back = irfft2($x75_ref->slice(':,0:3,:'), zeros(7,5) );
my $x75_back = irfft2(PDL::czip($x75_ref->slice(':,0:3,:')->using(0,1)), zeros(7,5) );
ok_should_make_plan( all( approx( $x75, $x75_back, approx_eps_double) ),
"rfft 2d test - backward - 7,5" );
}
Expand All @@ -639,7 +639,7 @@ my $Nplans = 0;
}

{
eval { irfft1( sequence(2,4) ) };
eval { irfft1( sequence(cdouble,4) ) };
ok_should_reuse_plan( ! $@, "real ffts shouldn't work inplace - baseline backward" );
eval { irfft1( inplace sequence(2,4) ) };
ok( $@, "real ffts shouldn't work inplace - backward" );
Expand Down Expand Up @@ -669,7 +669,7 @@ my $Nplans = 0;
eval { rfft4( sequence(5,4,4) ) };
ok( $@, "real dimensionality: too few dimensions should fail" );

eval { irfft4( sequence(2,5,3,4,4) ) };
eval { irfft4( sequence(cdouble,5,3,4,4) ) };
ok_should_make_plan( ! $@, "real-backward dimensionality baseline" );

eval { irfft4( sequence(5,4,4) ) };
Expand Down Expand Up @@ -700,28 +700,28 @@ my $Nplans = 0;
}

{
eval { irfft4( sequence(2,3,3,4,4) ) };
eval { irfft4( sequence(cdouble,3,3,4,4) ) };
ok_should_make_plan( ! $@, "real-backward dimensionality baseline 1" );

eval { irfft4( sequence(2,3,3,4,4), sequence(5,3,4,4) ) };
eval { irfft4( sequence(cdouble,3,3,4,4), sequence(5,3,4,4) ) };
ok_should_make_plan( ! $@, "real-backward dimensionality baseline 2" );

eval { irfft4( sequence(2,3,3,4,4), sequence(5,3,4,4,3) ) };
eval { irfft4( sequence(cdouble,3,3,4,4), sequence(5,3,4,4,3) ) };
ok_should_reuse_plan( ! $@, "real-backward dimensionality baseline - extra dims should be ok" );

eval { irfft4( sequence(3,3,3,4,4,3), sequence(5,3,4,4) ) };
ok( $@, "real-backward dimensionality - input should look like complex numbers" );

eval { irfft4( sequence(2,3,3,4,3), sequence(5,3,4,4) ) };
eval { irfft4( sequence(cdouble,3,3,4,3), sequence(5,3,4,4) ) };
ok( $@, "real-backward dimensionality - different dims should break 1" );

eval { irfft4( sequence(2,3,3,4,5), sequence(5,3,4,4) ) };
eval { irfft4( sequence(cdouble,3,3,4,5), sequence(5,3,4,4) ) };
ok( $@, "real-backward dimensionality - different dims should break 2" );

eval { irfft4( sequence(2,3,3,4,4), sequence(4,3,4,4) ) };
eval { irfft4( sequence(cdouble,3,3,4,4), sequence(4,3,4,4) ) };
ok_should_reuse_plan( !$@, "real-backward dimensionality - slightly different complex dims still ok" );

eval { irfft4( sequence(2,3,3,4,4), sequence(6,3,4,4) ) };
eval { irfft4( sequence(cdouble,3,3,4,4), sequence(6,3,4,4) ) };
ok( $@, "real-backward dimensionality - too different complex dims should break" );
}
}
Expand Down Expand Up @@ -793,7 +793,7 @@ my $Nplans = 0;
"parameterized forward real FFT works (1d on a 3d var)" );

# inverse on 2d -- should be a normalized forward on the non-transformed direction
$c = irfftn($b,2);
$c = irfftn(PDL::czip($b->using(0,1)),2);
$ctemplate = zeroes($a);
$ctemplate->slice('(0),:,(0)') .= 0.25;
ok_should_make_plan( all( approx( $c, $ctemplate, approx_eps_double) ),
Expand Down

0 comments on commit 57d390b

Please sign in to comment.