From b9d5c0f298d9c6cd6962f0508af875fbba11455a Mon Sep 17 00:00:00 2001 From: Ed J Date: Thu, 28 Nov 2024 20:11:58 +0000 Subject: [PATCH] TEMPLATE_REAL_C2R is native-only so only need TGC etc --- fftw3.pd | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/fftw3.pd b/fftw3.pd index b986b7c..e3027b9 100644 --- a/fftw3.pd +++ b/fftw3.pd @@ -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. @@ -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 @@ -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'; @@ -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 ); }