Skip to content

Commit

Permalink
rNfft to check output is native-complex
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Dec 2, 2024
1 parent 113ac67 commit ddc8a37
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
23 changes: 13 additions & 10 deletions fftw3.pd
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ EOF
sub validateArgumentDimensions_complex
{
my ( $rank, $thisfunction, $arg ) = @_;
my $is_native = !$arg->type->real;
barf "Tried to compute a complex FFT, but non-native-complex argument given"
if $arg->type->real;
my $dims_cmp = $arg->ndims;
barf <<EOF if $dims_cmp < $rank;
Tried to compute a $rank-dimensional FFT, but an array has fewer than $rank dimensions.
Expand All @@ -415,16 +416,18 @@ sub validateArgumentDimensions_real {

# real FFT. Forward transform takes in real and spits out complex;
# backward transform does the reverse
if ( !$is_native && $arg->dim(0) != 2 ) {
my ($verb, $var);
if ( !$is_native_output && !$do_inverse_fft && $iarg == 1 ) {
($verb, $var) = qw(produces output);
} elsif ( $do_inverse_fft && $iarg == 0 ) {
($verb, $var) = qw(takes input);
if (!!$do_inverse_fft == !!($iarg == 0)) { # need complex for this
my ($verb, $var, $reason) = ($iarg == 0) ? qw(takes input) : qw(produces output);
if ( ($iarg == 1 && $is_native_output && !$is_native) ||
($iarg == 0 && !$is_native)
) {
$reason = "\$$var should be native-complex";
} elsif (!$is_native && $arg->dim(0) != 2) {
$reason = "\$$var->dim(0) == 2 should be true";
}
barf <<EOF if $verb;
$thisfunction $verb complex $var, so \$$var->dim(0) == 2 should be true,
but it's not (in @{[$arg->info]}: $arg). This is the (real,imag) dimension. Giving up.
barf <<EOF if $reason;
$thisfunction $verb complex $var, so $reason,
but it's not (in @{[$arg->info]}: $arg). Giving up.
EOF
}

Expand Down
29 changes: 19 additions & 10 deletions t/fftw.t
Original file line number Diff line number Diff line change
Expand Up @@ -621,30 +621,39 @@ my $Nplans = 0;
ok_should_reuse_plan( ! $@, "real ffts shouldn't work inplace - baseline forward" );
eval { rfft1( inplace sequence(6) ) };
ok( $@, "real ffts shouldn't work inplace - forward" );
eval { rNfft1( sequence(6) ) };
ok_should_reuse_plan( ! $@, "real->N ffts shouldn't work inplace - baseline forward" );
eval { rNfft1( inplace sequence(6) ) };
like $@, qr/in-place real FFTs are not supported/, "real->N ffts shouldn't work inplace - forward";
}

{
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" );
eval { irfft1( inplace sequence(cdouble,4) ) };
like $@, qr/in-place real FFTs are not supported/, "real ffts shouldn't work inplace - backward";
}

{
eval { rfft1( sequence(7), sequence(2,4) ) };
ok_should_reuse_plan( ! $@, "real fft dims - baseline");

eval { rfft1( sequence(7), sequence(3,4) ) };
ok( $@, "real fft dimensionality 1");

like $@, qr/produces complex output/, "real fft dimensionality 1";
eval { rfft1( sequence(7), sequence(1,4) ) };
ok( $@, "real fft dimensionality 2");

like $@, qr/produces complex output/, "real fft dimensionality 2";
eval { rfft1( sequence(7), sequence(2,5) ) };
ok( $@, "real fft dimensionality 3");

like $@, qr/mismatched first dimension/, "real fft dimensionality 3";
eval { rfft1( sequence(7), sequence(2,3) ) };
ok( $@, "real fft dimensionality 4");
like $@, qr/mismatched first dimension/, "real fft dimensionality 4";

eval { rNfft1( sequence(7), sequence(4) ) };
like $@, qr/produces complex output/, "real->N fft type";
eval { rNfft1( sequence(7), sequence(cdouble,4) ) };
ok_should_reuse_plan( ! $@, "real fft dims - baseline");
eval { rNfft1( sequence(7), sequence(cdouble,5) ) };
like $@, qr/mismatched first dimension/, "real->N fft dimensionality 1";
eval { rNfft1( sequence(7), sequence(cdouble,3) ) };
like $@, qr/mismatched first dimension/, "real->N fft dimensionality 2";
}

{
Expand Down

0 comments on commit ddc8a37

Please sign in to comment.