Skip to content

Commit

Permalink
use X not N for FFT rank description
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 22, 2021
1 parent ced1da9 commit 26ac555
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
patches/
PDL-FFTW3-*.tar.gz
*~
*.o
*.c
FFTW3.o
FFTW3.c
*.bs
FFTW3.pm
FFTW3.xs
1 change: 0 additions & 1 deletion FFTW3.pd
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ sub generateDefinitions
$pp_def{Code} = slurp('template_complex.c');
pp_def( "__fft$rank", %pp_def );


##################################################################################
####### now I generate the definitions for the real-complex and complex-real cases
my @dims_real = @dims;
Expand Down
41 changes: 12 additions & 29 deletions FFTW3_header_include.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ our $_last_do_double_precision;
# PP-generated internals. Specifically, this function is called BEFORE any PDL
# threading happens. Here I make sure the FFTW plan exists, or if it doesn't, I
# make it. Thus the PP-based internals can safely assume that the plan exists
sub __fft_internal
{
sub __fft_internal {
my $thisfunction = shift;

my ($do_inverse_fft, $is_real_fft, $rank) = $thisfunction =~ /^(i?)((?:r)?).*fft([0-9]+)/;
Expand All @@ -29,47 +28,37 @@ sub __fft_internal
my $Nargs = scalar @_;

my ($in, $out);
if( $Nargs == 2 )
{
if ( $Nargs == 2 ) {
# all variables on stack, read in output and temp vars
($in, $out) = map {defined $_ ? PDL::Core::topdl($_) : $_} @_;
}
elsif( $Nargs == 1 )
{
} elsif ( $Nargs == 1 ) {
$in = PDL::Core::topdl $_[0];
if( $in->is_inplace )
{
if ( $in->is_inplace ) {
barf <<EOF if $is_real_fft;
$thisfunction: in-place real FFTs are not supported since the input/output types and data sizes differ.
Giving up.
EOF

$out = $in;
$in->set_inplace(0);
}
else
{
} else {
$out = PDL::null();
}
}
else
{
} else {
barf( <<EOF );
$thisfunction must be given the input or the input and output as args.
Exactly 1 or 2 arguments are required. Instead I got $Nargs args. Giving up.
EOF
}

# make sure the in/out types match. Convert $in if needed. This needs to
# happen before we instantiante $out (if it's null) to make sure we know the
# happen before we instantiate $out (if it's null) to make sure we know the
# type
processTypes( $thisfunction, \$in, \$out );

# I now create a piddle for the null output. Normally PP does this, but I need
# to have the piddle made to create plans. If I don't, the alignment may
# differ between plan-time and run-time
if( $out->isnull )
{
if ( $out->isnull ) {
my @dims = getOutDims($in, $is_real_fft, $do_inverse_fft);
$out .= zeros($in->type, @dims);
}
Expand All @@ -95,25 +84,19 @@ EOF
return $out;
}

sub getOutDims
{
sub getOutDims {
my ($in, $is_real_fft, $do_inverse_fft) = @_;

my @dims = $in->dims;

if ( !$is_real_fft )
{
if ( !$is_real_fft ) {
# complex fft. Output is the same size as the input.
}
elsif ( !$do_inverse_fft )
{
} elsif ( !$do_inverse_fft ) {
# forward real fft
my $d0 = shift @dims;
unshift @dims, 1+int($d0/2);
unshift @dims, 2;
}
else
{
} else {
# backward real fft
#
# there's an ambiguity here. I want int($out->dim(0)/2) + 1 == $in->dim(1),
Expand Down
14 changes: 7 additions & 7 deletions README.pod
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ including PDL.

=head1 FUNCTIONS

=head2 fftN (fft1, fft2, fft3, ..., fftn)
=head2 fftX (fft1, fft2, fft3, ..., fftn)

The basic complex <-> complex FFT. You can pass in the rank as a
parameter with the C<fftn> form, or append the rank to the function
Expand All @@ -208,7 +208,7 @@ the last argument. If the output piddle is passed in, the user I<must>
make sure the dimensions match.

The 0 dim of the input PDL must have size 2 and run over (real,imaginary)
components. The transform is carried out over dims 1 through N.
components. The transform is carried out over dims 1 through X.

The fftn form takes a minimum of two arguments: the PDL to transform,
and the number of dimensions to transform as a separate argument.
Expand All @@ -220,17 +220,17 @@ The following are equivalent:
fft1( $x, my $X = $x->zeros );


=head2 ifftN (ifft1, ifft2, ifft3, ..., fftn)
=head2 ifftX (ifft1, ifft2, ifft3, ..., ifftn)

The basic, properly normalized, complex <-> complex backward
FFT. Everything is exactly like in the C<fftN> functions, except the
FFT. Everything is exactly like in the C<fftX> functions, except the
inverse transform is computed and normalized, so that (for example)

ifft1( fft1 ( $x ) )

is a good approximation of C<$x> itself.

=head2 rfftN (rfft1, rfft2, rfft3, ..., rfftn)
=head2 rfftX (rfft1, rfft2, rfft3, ..., rfftn)

The real -> complex FFT. You can pass in the rank with the C<rfftn>
form, or append the rank to the function name for ranks up to 9.
Expand All @@ -248,12 +248,12 @@ The following are equivalent:
$X = rfft1( $x );
rfft1( $x, my $X = $x->zeroes );

=head2 irfftN (irfft1, irfft2, irfft3, ..., irfftn)
=head2 irfftX (irfft1, irfft2, irfft3, ..., irfftn)

The complex -> real inverse FFT. You can pass in the rank with the
C<irfftn> form, or append the rank to the function name for ranks up
to 9. Argument passing and interpretation is as described in
C<rfftN> above. Please read L<Data formats> for details about dimension
C<rfftX> above. Please read L<Data formats> for details about dimension
interpretation. There's an ambiguity about the output dimensionality,
which is described in that section.

Expand Down

0 comments on commit 26ac555

Please sign in to comment.