Skip to content

Commit

Permalink
TEMPLATE_REAL_C2R is native-only so only need TGC etc
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Nov 28, 2024
1 parent 9b2b924 commit b9d5c0f
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions fftw3.pd
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,18 @@ EOF
my $TEMPLATE_REAL_C2R = <<'EOF';
// RANK is replaced with the rank of this transform
// make sure the PDL data type I'm using matches the FFTW data type
static_assert_fftw(sizeof($GENERIC())*2 == sizeof($TFD(fftwf_,fftw_)complex));
$TFD(fftwf_,fftw_)plan plan = INT2PTR($TFD(fftwf_,fftw_)plan, $COMP(plan));
static_assert_fftw(sizeof($GENERIC()) == sizeof($TGC(fftwf_,fftw_)complex));
$TGC(fftwf_,fftw_)plan plan = INT2PTR($TGC(fftwf_,fftw_)plan, $COMP(plan));
// FFTW inverse real transforms clobber their input. I thus make a new
// buffer and transform from there
unsigned long nelem = 1;
for( int i=0; i<=RANK; i++ )
nelem *= $PDL(complexv)->dims[i];
unsigned long elem_scale = sizeof($GENERIC()) / sizeof( $TFD(float,double) ); /* native complex */
/* explicit C types here means when changed to $TGC will still be right */
$TFD(float,double)* input_copy = $TFD(fftwf_,fftw_)alloc_real( nelem * elem_scale );
unsigned long elem_scale = sizeof($GENERIC()) / sizeof( $TGC(float,double) ); /* native complex */
void *input_copy = $TGC(fftwf_,fftw_)alloc_real( nelem * elem_scale );
memcpy( input_copy, $P(complexv), sizeof($GENERIC()) * nelem );
$TFD(fftwf_,fftw_)execute_dft_c2r( plan, (void*)input_copy, (void*)$P(real) );
$TFD(fftwf_,fftw_)free( input_copy );
$TGC(fftwf_,fftw_)execute_dft_c2r( plan, (void*)input_copy, (void*)$P(real) );
$TGC(fftwf_,fftw_)free( input_copy );
EOF
my $TEMPLATE_COMPLEX = <<'EOF';
// This is the template used by PP to generate the FFTW routines.
Expand Down Expand Up @@ -714,7 +713,6 @@ sub generateDefinitions
$dims_complex[1] = 'nhalf'; # first complex dim is real->dim(0)/2+1
my $dims_real_string = join(',', @dims_real);
my $dims_complex_string = join(',', @dims_complex);
my $code_real_backward = $TEMPLATE_REAL_C2R =~ s/RANK/$rank/gr;

# forward
# I have the real dimensions, but not nhalf
Expand Down Expand Up @@ -745,7 +743,6 @@ EOF
$dims_complex[0] = 'nhalf'; # first complex dim is real->dim(0)/2+1
$dims_real_string = join(',', @dims_real);
$dims_complex_string = join(',', @dims_complex);
$code_real_backward = $TEMPLATE_REAL_C2R =~ s/RANK/$rank-1/gre;

# forward
$pp_def{RedoDimsCode} = <<'EOF';
Expand All @@ -763,9 +760,7 @@ if( $PDL(real)->dims[0] <= 0 )
$SIZE(n1) = 2*$PDL(complexv)->dims[0] - 2;
EOF
$pp_def{Pars} = "complexv($dims_complex_string); real [o]real($dims_real_string);";
$code_real_backward =~ s/TFD/TGC/g;
$code_real_backward =~ s/\*2//g; # the sizeof-doubling
$pp_def{Code} = $code_real_backward;
$pp_def{Code} = $TEMPLATE_REAL_C2R =~ s/RANK/$rank-1/gre;
$pp_def{GenericTypes} = [qw(G C)];
pp_def( "__irNfft$rank", %pp_def );
}
Expand Down

0 comments on commit b9d5c0f

Please sign in to comment.