cannam@95: @node FFTW Reference, Multi-threaded FFTW, Other Important Topics, Top cannam@95: @chapter FFTW Reference cannam@95: cannam@95: This chapter provides a complete reference for all sequential (i.e., cannam@95: one-processor) FFTW functions. Parallel transforms are described in cannam@95: later chapters. cannam@95: cannam@95: @menu cannam@95: * Data Types and Files:: cannam@95: * Using Plans:: cannam@95: * Basic Interface:: cannam@95: * Advanced Interface:: cannam@95: * Guru Interface:: cannam@95: * New-array Execute Functions:: cannam@95: * Wisdom:: cannam@95: * What FFTW Really Computes:: cannam@95: @end menu cannam@95: cannam@95: @c ------------------------------------------------------------ cannam@95: @node Data Types and Files, Using Plans, FFTW Reference, FFTW Reference cannam@95: @section Data Types and Files cannam@95: cannam@95: All programs using FFTW should include its header file: cannam@95: cannam@95: @example cannam@95: #include cannam@95: @end example cannam@95: cannam@95: You must also link to the FFTW library. On Unix, this cannam@95: means adding @code{-lfftw3 -lm} at the @emph{end} of the link command. cannam@95: cannam@95: @menu cannam@95: * Complex numbers:: cannam@95: * Precision:: cannam@95: * Memory Allocation:: cannam@95: @end menu cannam@95: cannam@95: @c =========> cannam@95: @node Complex numbers, Precision, Data Types and Files, Data Types and Files cannam@95: @subsection Complex numbers cannam@95: cannam@95: The default FFTW interface uses @code{double} precision for all cannam@95: floating-point numbers, and defines a @code{fftw_complex} type to hold cannam@95: complex numbers as: cannam@95: cannam@95: @example cannam@95: typedef double fftw_complex[2]; cannam@95: @end example cannam@95: @tindex fftw_complex cannam@95: cannam@95: Here, the @code{[0]} element holds the real part and the @code{[1]} cannam@95: element holds the imaginary part. cannam@95: cannam@95: Alternatively, if you have a C compiler (such as @code{gcc}) that cannam@95: supports the C99 revision of the ANSI C standard, you can use C's new cannam@95: native complex type (which is binary-compatible with the typedef above). cannam@95: In particular, if you @code{#include } @emph{before} cannam@95: @code{}, then @code{fftw_complex} is defined to be the native cannam@95: complex type and you can manipulate it with ordinary arithmetic cannam@95: (e.g. @code{x = y * (3+4*I)}, where @code{x} and @code{y} are cannam@95: @code{fftw_complex} and @code{I} is the standard symbol for the cannam@95: imaginary unit); cannam@95: @cindex C99 cannam@95: cannam@95: cannam@95: C++ has its own @code{complex} template class, defined in the cannam@95: standard @code{} header file. Reportedly, the C++ standards cannam@95: committee has recently agreed to mandate that the storage format used cannam@95: for this type be binary-compatible with the C99 type, i.e. an array cannam@95: @code{T[2]} with consecutive real @code{[0]} and imaginary @code{[1]} cannam@95: parts. (See report cannam@95: @uref{http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2002/n1388.pdf cannam@95: WG21/N1388}.) Although not part of the official standard as of this cannam@95: writing, the proposal stated that: ``This solution has been tested with cannam@95: all current major implementations of the standard library and shown to cannam@95: be working.'' To the extent that this is true, if you have a variable cannam@95: @code{complex *x}, you can pass it directly to FFTW via cannam@95: @code{reinterpret_cast(x)}. cannam@95: @cindex C++ cannam@95: @cindex portability cannam@95: cannam@95: @c =========> cannam@95: @node Precision, Memory Allocation, Complex numbers, Data Types and Files cannam@95: @subsection Precision cannam@95: @cindex precision cannam@95: cannam@95: You can install single and long-double precision versions of FFTW, cannam@95: which replace @code{double} with @code{float} and @code{long double}, cannam@95: respectively (@pxref{Installation and Customization}). To use these cannam@95: interfaces, you: cannam@95: cannam@95: @itemize @bullet cannam@95: cannam@95: @item cannam@95: Link to the single/long-double libraries; on Unix, @code{-lfftw3f} or cannam@95: @code{-lfftw3l} instead of (or in addition to) @code{-lfftw3}. (You cannam@95: can link to the different-precision libraries simultaneously.) cannam@95: cannam@95: @item cannam@95: Include the @emph{same} @code{} header file. cannam@95: cannam@95: @item cannam@95: Replace all lowercase instances of @samp{fftw_} with @samp{fftwf_} or cannam@95: @samp{fftwl_} for single or long-double precision, respectively. cannam@95: (@code{fftw_complex} becomes @code{fftwf_complex}, @code{fftw_execute} cannam@95: becomes @code{fftwf_execute}, etcetera.) cannam@95: cannam@95: @item cannam@95: Uppercase names, i.e. names beginning with @samp{FFTW_}, remain the cannam@95: same. cannam@95: cannam@95: @item cannam@95: Replace @code{double} with @code{float} or @code{long double} for cannam@95: subroutine parameters. cannam@95: cannam@95: @end itemize cannam@95: cannam@95: Depending upon your compiler and/or hardware, @code{long double} may not cannam@95: be any more precise than @code{double} (or may not be supported at all, cannam@95: although it is standard in C99). cannam@95: @cindex C99 cannam@95: cannam@95: cannam@95: We also support using the nonstandard @code{__float128} cannam@95: quadruple-precision type provided by recent versions of @code{gcc} on cannam@95: 32- and 64-bit x86 hardware (@pxref{Installation and Customization}). cannam@95: To use this type, link with @code{-lfftw3q -lquadmath -lm} (the cannam@95: @code{libquadmath} library provided by @code{gcc} is needed for cannam@95: quadruple-precision trigonometric functions) and use @samp{fftwq_} cannam@95: identifiers. cannam@95: cannam@95: @c =========> cannam@95: @node Memory Allocation, , Precision, Data Types and Files cannam@95: @subsection Memory Allocation cannam@95: cannam@95: @example cannam@95: void *fftw_malloc(size_t n); cannam@95: void fftw_free(void *p); cannam@95: @end example cannam@95: @findex fftw_malloc cannam@95: @findex fftw_free cannam@95: cannam@95: These are functions that behave identically to @code{malloc} and cannam@95: @code{free}, except that they guarantee that the returned pointer obeys cannam@95: any special alignment restrictions imposed by any algorithm in FFTW cannam@95: (e.g. for SIMD acceleration). @xref{SIMD alignment and fftw_malloc}. cannam@95: @cindex alignment cannam@95: cannam@95: cannam@95: Data allocated by @code{fftw_malloc} @emph{must} be deallocated by cannam@95: @code{fftw_free} and not by the ordinary @code{free}. cannam@95: cannam@95: These routines simply call through to your operating system's cannam@95: @code{malloc} or, if necessary, its aligned equivalent cannam@95: (e.g. @code{memalign}), so you normally need not worry about any cannam@95: significant time or space overhead. You are @emph{not required} to use cannam@95: them to allocate your data, but we strongly recommend it. cannam@95: cannam@95: Note: in C++, just as with ordinary @code{malloc}, you must typecast cannam@95: the output of @code{fftw_malloc} to whatever pointer type you are cannam@95: allocating. cannam@95: @cindex C++ cannam@95: cannam@95: cannam@95: We also provide the following two convenience functions to allocate cannam@95: real and complex arrays with @code{n} elements, which are equivalent cannam@95: to @code{(double *) fftw_malloc(sizeof(double) * n)} and cannam@95: @code{(fftw_complex *) fftw_malloc(sizeof(fftw_complex) * n)}, cannam@95: respectively: cannam@95: cannam@95: @example cannam@95: double *fftw_alloc_real(size_t n); cannam@95: fftw_complex *fftw_alloc_complex(size_t n); cannam@95: @end example cannam@95: @findex fftw_alloc_real cannam@95: @findex fftw_alloc_complex cannam@95: cannam@95: The equivalent functions in other precisions allocate arrays of @code{n} cannam@95: elements in that precision. e.g. @code{fftwf_alloc_real(n)} is cannam@95: equivalent to @code{(float *) fftwf_malloc(sizeof(float) * n)}. cannam@95: @cindex precision cannam@95: cannam@95: @c ------------------------------------------------------------ cannam@95: @node Using Plans, Basic Interface, Data Types and Files, FFTW Reference cannam@95: @section Using Plans cannam@95: cannam@95: Plans for all transform types in FFTW are stored as type cannam@95: @code{fftw_plan} (an opaque pointer type), and are created by one of the cannam@95: various planning routines described in the following sections. cannam@95: @tindex fftw_plan cannam@95: An @code{fftw_plan} contains all information necessary to compute the cannam@95: transform, including the pointers to the input and output arrays. cannam@95: cannam@95: @example cannam@95: void fftw_execute(const fftw_plan plan); cannam@95: @end example cannam@95: @findex fftw_execute cannam@95: cannam@95: This executes the @code{plan}, to compute the corresponding transform on cannam@95: the arrays for which it was planned (which must still exist). The plan cannam@95: is not modified, and @code{fftw_execute} can be called as many times as cannam@95: desired. cannam@95: cannam@95: To apply a given plan to a different array, you can use the new-array execute cannam@95: interface. @xref{New-array Execute Functions}. cannam@95: cannam@95: @code{fftw_execute} (and equivalents) is the only function in FFTW cannam@95: guaranteed to be thread-safe; see @ref{Thread safety}. cannam@95: cannam@95: This function: cannam@95: @example cannam@95: void fftw_destroy_plan(fftw_plan plan); cannam@95: @end example cannam@95: @findex fftw_destroy_plan cannam@95: deallocates the @code{plan} and all its associated data. cannam@95: cannam@95: FFTW's planner saves some other persistent data, such as the cannam@95: accumulated wisdom and a list of algorithms available in the current cannam@95: configuration. If you want to deallocate all of that and reset FFTW cannam@95: to the pristine state it was in when you started your program, you can cannam@95: call: cannam@95: cannam@95: @example cannam@95: void fftw_cleanup(void); cannam@95: @end example cannam@95: @findex fftw_cleanup cannam@95: cannam@95: After calling @code{fftw_cleanup}, all existing plans become undefined, cannam@95: and you should not attempt to execute them nor to destroy them. You can cannam@95: however create and execute/destroy new plans, in which case FFTW starts cannam@95: accumulating wisdom information again. cannam@95: cannam@95: @code{fftw_cleanup} does not deallocate your plans, however. To prevent cannam@95: memory leaks, you must still call @code{fftw_destroy_plan} before cannam@95: executing @code{fftw_cleanup}. cannam@95: cannam@95: Occasionally, it may useful to know FFTW's internal ``cost'' metric cannam@95: that it uses to compare plans to one another; this cost is cannam@95: proportional to an execution time of the plan, in undocumented units, cannam@95: if the plan was created with the @code{FFTW_MEASURE} or other cannam@95: timing-based options, or alternatively is a heuristic cost function cannam@95: for @code{FFTW_ESTIMATE} plans. (The cost values of measured and cannam@95: estimated plans are not comparable, being in different units. Also, cannam@95: costs from different FFTW versions or the same version compiled cannam@95: differently may not be in the same units. Plans created from wisdom cannam@95: have a cost of 0 since no timing measurement is performed for them. cannam@95: Finally, certain problems for which only one top-level algorithm was cannam@95: possible may have required no measurements of the cost of the whole cannam@95: plan, in which case @code{fftw_cost} will also return 0.) The cost cannam@95: metric for a given plan is returned by: cannam@95: cannam@95: @example cannam@95: double fftw_cost(const fftw_plan plan); cannam@95: @end example cannam@95: @findex fftw_cost cannam@95: cannam@95: The following two routines are provided purely for academic purposes cannam@95: (that is, for entertainment). cannam@95: cannam@95: @example cannam@95: void fftw_flops(const fftw_plan plan, cannam@95: double *add, double *mul, double *fma); cannam@95: @end example cannam@95: @findex fftw_flops cannam@95: cannam@95: Given a @code{plan}, set @code{add}, @code{mul}, and @code{fma} to an cannam@95: exact count of the number of floating-point additions, multiplications, cannam@95: and fused multiply-add operations involved in the plan's execution. The cannam@95: total number of floating-point operations (flops) is @code{add + mul + cannam@95: 2*fma}, or @code{add + mul + fma} if the hardware supports fused cannam@95: multiply-add instructions (although the number of FMA operations is only cannam@95: approximate because of compiler voodoo). (The number of operations cannam@95: should be an integer, but we use @code{double} to avoid overflowing cannam@95: @code{int} for large transforms; the arguments are of type @code{double} cannam@95: even for single and long-double precision versions of FFTW.) cannam@95: cannam@95: @example cannam@95: void fftw_fprint_plan(const fftw_plan plan, FILE *output_file); cannam@95: void fftw_print_plan(const fftw_plan plan); cannam@95: @end example cannam@95: @findex fftw_fprint_plan cannam@95: @findex fftw_print_plan cannam@95: cannam@95: This outputs a ``nerd-readable'' representation of the @code{plan} to cannam@95: the given file or to @code{stdout}, respectively. cannam@95: cannam@95: @c ------------------------------------------------------------ cannam@95: @node Basic Interface, Advanced Interface, Using Plans, FFTW Reference cannam@95: @section Basic Interface cannam@95: @cindex basic interface cannam@95: cannam@95: Recall that the FFTW API is divided into three parts@footnote{@i{Gallia est cannam@95: omnis divisa in partes tres} (Julius Caesar).}: the @dfn{basic interface} cannam@95: computes a single transform of contiguous data, the @dfn{advanced cannam@95: interface} computes transforms of multiple or strided arrays, and the cannam@95: @dfn{guru interface} supports the most general data layouts, cannam@95: multiplicities, and strides. This section describes the the basic cannam@95: interface, which we expect to satisfy the needs of most users. cannam@95: cannam@95: @menu cannam@95: * Complex DFTs:: cannam@95: * Planner Flags:: cannam@95: * Real-data DFTs:: cannam@95: * Real-data DFT Array Format:: cannam@95: * Real-to-Real Transforms:: cannam@95: * Real-to-Real Transform Kinds:: cannam@95: @end menu cannam@95: cannam@95: @c =========> cannam@95: @node Complex DFTs, Planner Flags, Basic Interface, Basic Interface cannam@95: @subsection Complex DFTs cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_dft_1d(int n0, cannam@95: fftw_complex *in, fftw_complex *out, cannam@95: int sign, unsigned flags); cannam@95: fftw_plan fftw_plan_dft_2d(int n0, int n1, cannam@95: fftw_complex *in, fftw_complex *out, cannam@95: int sign, unsigned flags); cannam@95: fftw_plan fftw_plan_dft_3d(int n0, int n1, int n2, cannam@95: fftw_complex *in, fftw_complex *out, cannam@95: int sign, unsigned flags); cannam@95: fftw_plan fftw_plan_dft(int rank, const int *n, cannam@95: fftw_complex *in, fftw_complex *out, cannam@95: int sign, unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_dft_1d cannam@95: @findex fftw_plan_dft_2d cannam@95: @findex fftw_plan_dft_3d cannam@95: @findex fftw_plan_dft cannam@95: cannam@95: Plan a complex input/output discrete Fourier transform (DFT) in zero or cannam@95: more dimensions, returning an @code{fftw_plan} (@pxref{Using Plans}). cannam@95: cannam@95: Once you have created a plan for a certain transform type and cannam@95: parameters, then creating another plan of the same type and parameters, cannam@95: but for different arrays, is fast and shares constant data with the cannam@95: first plan (if it still exists). cannam@95: cannam@95: The planner returns @code{NULL} if the plan cannot be created. In the cannam@95: standard FFTW distribution, the basic interface is guaranteed to return cannam@95: a non-@code{NULL} plan. A plan may be @code{NULL}, however, if you are cannam@95: using a customized FFTW configuration supporting a restricted set of cannam@95: transforms. cannam@95: cannam@95: @subsubheading Arguments cannam@95: @itemize @bullet cannam@95: cannam@95: @item cannam@95: @code{rank} is the rank of the transform (it should be the size of the cannam@95: array @code{*n}), and can be any non-negative integer. (@xref{Complex cannam@95: Multi-Dimensional DFTs}, for the definition of ``rank''.) The cannam@95: @samp{_1d}, @samp{_2d}, and @samp{_3d} planners correspond to a cannam@95: @code{rank} of @code{1}, @code{2}, and @code{3}, respectively. The rank cannam@95: may be zero, which is equivalent to a rank-1 transform of size 1, i.e. a cannam@95: copy of one number from input to output. cannam@95: cannam@95: @item cannam@95: @code{n0}, @code{n1}, @code{n2}, or @code{n[0..rank-1]} (as appropriate cannam@95: for each routine) specify the size of the transform dimensions. They cannam@95: can be any positive integer. cannam@95: cannam@95: @itemize @minus cannam@95: @item cannam@95: @cindex row-major cannam@95: Multi-dimensional arrays are stored in row-major order with dimensions: cannam@95: @code{n0} x @code{n1}; or @code{n0} x @code{n1} x @code{n2}; or cannam@95: @code{n[0]} x @code{n[1]} x ... x @code{n[rank-1]}. cannam@95: @xref{Multi-dimensional Array Format}. cannam@95: @item cannam@95: FFTW is best at handling sizes of the form cannam@95: @ifinfo cannam@95: @math{2^a 3^b 5^c 7^d 11^e 13^f}, cannam@95: @end ifinfo cannam@95: @tex cannam@95: $2^a 3^b 5^c 7^d 11^e 13^f$, cannam@95: @end tex cannam@95: @html cannam@95: 2a 3b 5c 7d cannam@95: 11e 13f, cannam@95: @end html cannam@95: where @math{e+f} is either @math{0} or @math{1}, and the other exponents cannam@95: are arbitrary. Other sizes are computed by means of a slow, cannam@95: general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). It is possible to customize FFTW cannam@95: for different array sizes; see @ref{Installation and Customization}. cannam@95: Transforms whose sizes are powers of @math{2} are especially fast. cannam@95: @end itemize cannam@95: cannam@95: @item cannam@95: @code{in} and @code{out} point to the input and output arrays of the cannam@95: transform, which may be the same (yielding an in-place transform). cannam@95: @cindex in-place cannam@95: These arrays are overwritten during planning, unless cannam@95: @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be cannam@95: initialized, but they must be allocated.) cannam@95: cannam@95: If @code{in == out}, the transform is @dfn{in-place} and the input cannam@95: array is overwritten. If @code{in != out}, the two arrays must cannam@95: not overlap (but FFTW does not check for this condition). cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_FORWARD cannam@95: @ctindex FFTW_BACKWARD cannam@95: @code{sign} is the sign of the exponent in the formula that defines the cannam@95: Fourier transform. It can be @math{-1} (= @code{FFTW_FORWARD}) or cannam@95: @math{+1} (= @code{FFTW_BACKWARD}). cannam@95: cannam@95: @item cannam@95: @cindex flags cannam@95: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, cannam@95: as defined in @ref{Planner Flags}. cannam@95: cannam@95: @end itemize cannam@95: cannam@95: FFTW computes an unnormalized transform: computing a forward followed by cannam@95: a backward transform (or vice versa) will result in the original data cannam@95: multiplied by the size of the transform (the product of the dimensions). cannam@95: @cindex normalization cannam@95: For more information, see @ref{What FFTW Really Computes}. cannam@95: cannam@95: @c =========> cannam@95: @node Planner Flags, Real-data DFTs, Complex DFTs, Basic Interface cannam@95: @subsection Planner Flags cannam@95: cannam@95: All of the planner routines in FFTW accept an integer @code{flags} cannam@95: argument, which is a bitwise OR (@samp{|}) of zero or more of the flag cannam@95: constants defined below. These flags control the rigor (and time) of cannam@95: the planning process, and can also impose (or lift) restrictions on the cannam@95: type of transform algorithm that is employed. cannam@95: cannam@95: @emph{Important:} the planner overwrites the input array during cannam@95: planning unless a saved plan (@pxref{Wisdom}) is available for that cannam@95: problem, so you should initialize your input data after creating the cannam@95: plan. The only exceptions to this are the @code{FFTW_ESTIMATE} and cannam@95: @code{FFTW_WISDOM_ONLY} flags, as mentioned below. cannam@95: cannam@95: In all cases, if wisdom is available for the given problem that was cannam@95: created with equal-or-greater planning rigor, then the more rigorous cannam@95: wisdom is used. For example, in @code{FFTW_ESTIMATE} mode any available cannam@95: wisdom is used, whereas in @code{FFTW_PATIENT} mode only wisdom created cannam@95: in patient or exhaustive mode can be used. @xref{Words of Wisdom-Saving cannam@95: Plans}. cannam@95: cannam@95: @subsubheading Planning-rigor flags cannam@95: @itemize @bullet cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_ESTIMATE cannam@95: @code{FFTW_ESTIMATE} specifies that, instead of actual measurements of cannam@95: different algorithms, a simple heuristic is used to pick a (probably cannam@95: sub-optimal) plan quickly. With this flag, the input/output arrays are cannam@95: not overwritten during planning. cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_MEASURE cannam@95: @code{FFTW_MEASURE} tells FFTW to find an optimized plan by actually cannam@95: @emph{computing} several FFTs and measuring their execution time. cannam@95: Depending on your machine, this can take some time (often a few cannam@95: seconds). @code{FFTW_MEASURE} is the default planning option. cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_PATIENT cannam@95: @code{FFTW_PATIENT} is like @code{FFTW_MEASURE}, but considers a wider cannam@95: range of algorithms and often produces a ``more optimal'' plan cannam@95: (especially for large transforms), but at the expense of several times cannam@95: longer planning time (especially for large transforms). cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_EXHAUSTIVE cannam@95: @code{FFTW_EXHAUSTIVE} is like @code{FFTW_PATIENT}, but considers an cannam@95: even wider range of algorithms, including many that we think are cannam@95: unlikely to be fast, to produce the most optimal plan but with a cannam@95: substantially increased planning time. cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_WISDOM_ONLY cannam@95: @code{FFTW_WISDOM_ONLY} is a special planning mode in which the plan cannam@95: is only created if wisdom is available for the given problem, and cannam@95: otherwise a @code{NULL} plan is returned. This can be combined with cannam@95: other flags, e.g. @samp{FFTW_WISDOM_ONLY | FFTW_PATIENT} creates a cannam@95: plan only if wisdom is available that was created in cannam@95: @code{FFTW_PATIENT} or @code{FFTW_EXHAUSTIVE} mode. The cannam@95: @code{FFTW_WISDOM_ONLY} flag is intended for users who need to detect cannam@95: whether wisdom is available; for example, if wisdom is not available cannam@95: one may wish to allocate new arrays for planning so that user data is cannam@95: not overwritten. cannam@95: cannam@95: @end itemize cannam@95: cannam@95: @subsubheading Algorithm-restriction flags cannam@95: @itemize @bullet cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_DESTROY_INPUT cannam@95: @code{FFTW_DESTROY_INPUT} specifies that an out-of-place transform is cannam@95: allowed to @emph{overwrite its input} array with arbitrary data; this cannam@95: can sometimes allow more efficient algorithms to be employed. cannam@95: @cindex out-of-place cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_PRESERVE_INPUT cannam@95: @code{FFTW_PRESERVE_INPUT} specifies that an out-of-place transform must cannam@95: @emph{not change its input} array. This is ordinarily the cannam@95: @emph{default}, except for c2r and hc2r (i.e. complex-to-real) cannam@95: transforms for which @code{FFTW_DESTROY_INPUT} is the default. In the cannam@95: latter cases, passing @code{FFTW_PRESERVE_INPUT} will attempt to use cannam@95: algorithms that do not destroy the input, at the expense of worse cannam@95: performance; for multi-dimensional c2r transforms, however, no cannam@95: input-preserving algorithms are implemented and the planner will return cannam@95: @code{NULL} if one is requested. cannam@95: @cindex c2r cannam@95: @cindex hc2r cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_UNALIGNED cannam@95: @cindex alignment cannam@95: @code{FFTW_UNALIGNED} specifies that the algorithm may not impose any cannam@95: unusual alignment requirements on the input/output arrays (i.e. no cannam@95: SIMD may be used). This flag is normally @emph{not necessary}, since cannam@95: the planner automatically detects misaligned arrays. The only use for cannam@95: this flag is if you want to use the new-array execute interface to cannam@95: execute a given plan on a different array that may not be aligned like cannam@95: the original. (Using @code{fftw_malloc} makes this flag unnecessary cannam@95: even then.) cannam@95: cannam@95: @end itemize cannam@95: cannam@95: @subsubheading Limiting planning time cannam@95: cannam@95: @example cannam@95: extern void fftw_set_timelimit(double seconds); cannam@95: @end example cannam@95: @findex fftw_set_timelimit cannam@95: cannam@95: This function instructs FFTW to spend at most @code{seconds} seconds cannam@95: (approximately) in the planner. If @code{seconds == cannam@95: FFTW_NO_TIMELIMIT} (the default value, which is negative), then cannam@95: planning time is unbounded. Otherwise, FFTW plans with a cannam@95: progressively wider range of algorithms until the the given time limit cannam@95: is reached or the given range of algorithms is explored, returning the cannam@95: best available plan. cannam@95: @ctindex FFTW_NO_TIMELIMIT cannam@95: cannam@95: cannam@95: For example, specifying @code{FFTW_PATIENT} first plans in cannam@95: @code{FFTW_ESTIMATE} mode, then in @code{FFTW_MEASURE} mode, then cannam@95: finally (time permitting) in @code{FFTW_PATIENT}. If cannam@95: @code{FFTW_EXHAUSTIVE} is specified instead, the planner will further cannam@95: progress to @code{FFTW_EXHAUSTIVE} mode. cannam@95: cannam@95: Note that the @code{seconds} argument specifies only a rough limit; in cannam@95: practice, the planner may use somewhat more time if the time limit is cannam@95: reached when the planner is in the middle of an operation that cannot cannam@95: be interrupted. At the very least, the planner will complete planning cannam@95: in @code{FFTW_ESTIMATE} mode (which is thus equivalent to a time limit cannam@95: of 0). cannam@95: cannam@95: cannam@95: @c =========> cannam@95: @node Real-data DFTs, Real-data DFT Array Format, Planner Flags, Basic Interface cannam@95: @subsection Real-data DFTs cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_dft_r2c_1d(int n0, cannam@95: double *in, fftw_complex *out, cannam@95: unsigned flags); cannam@95: fftw_plan fftw_plan_dft_r2c_2d(int n0, int n1, cannam@95: double *in, fftw_complex *out, cannam@95: unsigned flags); cannam@95: fftw_plan fftw_plan_dft_r2c_3d(int n0, int n1, int n2, cannam@95: double *in, fftw_complex *out, cannam@95: unsigned flags); cannam@95: fftw_plan fftw_plan_dft_r2c(int rank, const int *n, cannam@95: double *in, fftw_complex *out, cannam@95: unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_dft_r2c_1d cannam@95: @findex fftw_plan_dft_r2c_2d cannam@95: @findex fftw_plan_dft_r2c_3d cannam@95: @findex fftw_plan_dft_r2c cannam@95: @cindex r2c cannam@95: cannam@95: Plan a real-input/complex-output discrete Fourier transform (DFT) in cannam@95: zero or more dimensions, returning an @code{fftw_plan} (@pxref{Using cannam@95: Plans}). cannam@95: cannam@95: Once you have created a plan for a certain transform type and cannam@95: parameters, then creating another plan of the same type and parameters, cannam@95: but for different arrays, is fast and shares constant data with the cannam@95: first plan (if it still exists). cannam@95: cannam@95: The planner returns @code{NULL} if the plan cannot be created. A cannam@95: non-@code{NULL} plan is always returned by the basic interface unless cannam@95: you are using a customized FFTW configuration supporting a restricted cannam@95: set of transforms, or if you use the @code{FFTW_PRESERVE_INPUT} flag cannam@95: with a multi-dimensional out-of-place c2r transform (see below). cannam@95: cannam@95: @subsubheading Arguments cannam@95: @itemize @bullet cannam@95: cannam@95: @item cannam@95: @code{rank} is the rank of the transform (it should be the size of the cannam@95: array @code{*n}), and can be any non-negative integer. (@xref{Complex cannam@95: Multi-Dimensional DFTs}, for the definition of ``rank''.) The cannam@95: @samp{_1d}, @samp{_2d}, and @samp{_3d} planners correspond to a cannam@95: @code{rank} of @code{1}, @code{2}, and @code{3}, respectively. The rank cannam@95: may be zero, which is equivalent to a rank-1 transform of size 1, i.e. a cannam@95: copy of one real number (with zero imaginary part) from input to output. cannam@95: cannam@95: @item cannam@95: @code{n0}, @code{n1}, @code{n2}, or @code{n[0..rank-1]}, (as appropriate cannam@95: for each routine) specify the size of the transform dimensions. They cannam@95: can be any positive integer. This is different in general from the cannam@95: @emph{physical} array dimensions, which are described in @ref{Real-data cannam@95: DFT Array Format}. cannam@95: cannam@95: @itemize @minus cannam@95: @item cannam@95: FFTW is best at handling sizes of the form cannam@95: @ifinfo cannam@95: @math{2^a 3^b 5^c 7^d 11^e 13^f}, cannam@95: @end ifinfo cannam@95: @tex cannam@95: $2^a 3^b 5^c 7^d 11^e 13^f$, cannam@95: @end tex cannam@95: @html cannam@95: 2a 3b 5c 7d cannam@95: 11e 13f, cannam@95: @end html cannam@95: where @math{e+f} is either @math{0} or @math{1}, and the other exponents cannam@95: are arbitrary. Other sizes are computed by means of a slow, cannam@95: general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). (It is possible to customize FFTW cannam@95: for different array sizes; see @ref{Installation and Customization}.) cannam@95: Transforms whose sizes are powers of @math{2} are especially fast, and cannam@95: it is generally beneficial for the @emph{last} dimension of an r2c/c2r cannam@95: transform to be @emph{even}. cannam@95: @end itemize cannam@95: cannam@95: @item cannam@95: @code{in} and @code{out} point to the input and output arrays of the cannam@95: transform, which may be the same (yielding an in-place transform). cannam@95: @cindex in-place cannam@95: These arrays are overwritten during planning, unless cannam@95: @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be cannam@95: initialized, but they must be allocated.) For an in-place transform, it cannam@95: is important to remember that the real array will require padding, cannam@95: described in @ref{Real-data DFT Array Format}. cannam@95: @cindex padding cannam@95: cannam@95: @item cannam@95: @cindex flags cannam@95: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, cannam@95: as defined in @ref{Planner Flags}. cannam@95: cannam@95: @end itemize cannam@95: cannam@95: The inverse transforms, taking complex input (storing the non-redundant cannam@95: half of a logically Hermitian array) to real output, are given by: cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_dft_c2r_1d(int n0, cannam@95: fftw_complex *in, double *out, cannam@95: unsigned flags); cannam@95: fftw_plan fftw_plan_dft_c2r_2d(int n0, int n1, cannam@95: fftw_complex *in, double *out, cannam@95: unsigned flags); cannam@95: fftw_plan fftw_plan_dft_c2r_3d(int n0, int n1, int n2, cannam@95: fftw_complex *in, double *out, cannam@95: unsigned flags); cannam@95: fftw_plan fftw_plan_dft_c2r(int rank, const int *n, cannam@95: fftw_complex *in, double *out, cannam@95: unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_dft_c2r_1d cannam@95: @findex fftw_plan_dft_c2r_2d cannam@95: @findex fftw_plan_dft_c2r_3d cannam@95: @findex fftw_plan_dft_c2r cannam@95: @cindex c2r cannam@95: cannam@95: The arguments are the same as for the r2c transforms, except that the cannam@95: input and output data formats are reversed. cannam@95: cannam@95: FFTW computes an unnormalized transform: computing an r2c followed by a cannam@95: c2r transform (or vice versa) will result in the original data cannam@95: multiplied by the size of the transform (the product of the logical cannam@95: dimensions). cannam@95: @cindex normalization cannam@95: An r2c transform produces the same output as a @code{FFTW_FORWARD} cannam@95: complex DFT of the same input, and a c2r transform is correspondingly cannam@95: equivalent to @code{FFTW_BACKWARD}. For more information, see @ref{What cannam@95: FFTW Really Computes}. cannam@95: cannam@95: @c =========> cannam@95: @node Real-data DFT Array Format, Real-to-Real Transforms, Real-data DFTs, Basic Interface cannam@95: @subsection Real-data DFT Array Format cannam@95: @cindex r2c/c2r multi-dimensional array format cannam@95: cannam@95: The output of a DFT of real data (r2c) contains symmetries that, in cannam@95: principle, make half of the outputs redundant (@pxref{What FFTW Really cannam@95: Computes}). (Similarly for the input of an inverse c2r transform.) In cannam@95: practice, it is not possible to entirely realize these savings in an cannam@95: efficient and understandable format that generalizes to cannam@95: multi-dimensional transforms. Instead, the output of the r2c cannam@95: transforms is @emph{slightly} over half of the output of the cannam@95: corresponding complex transform. We do not ``pack'' the data in any cannam@95: way, but store it as an ordinary array of @code{fftw_complex} values. cannam@95: In fact, this data is simply a subsection of what would be the array in cannam@95: the corresponding complex transform. cannam@95: cannam@95: Specifically, for a real transform of @math{d} (= @code{rank}) cannam@95: dimensions @ndims{}, the complex data is an @ndimshalf array of cannam@95: @code{fftw_complex} values in row-major order (with the division rounded cannam@95: down). That is, we only store the @emph{lower} half (non-negative cannam@95: frequencies), plus one element, of the last dimension of the data from cannam@95: the ordinary complex transform. (We could have instead taken half of cannam@95: any other dimension, but implementation turns out to be simpler if the cannam@95: last, contiguous, dimension is used.) cannam@95: cannam@95: @cindex out-of-place cannam@95: For an out-of-place transform, the real data is simply an array with cannam@95: physical dimensions @ndims in row-major order. cannam@95: cannam@95: @cindex in-place cannam@95: @cindex padding cannam@95: For an in-place transform, some complications arise since the complex data cannam@95: is slightly larger than the real data. In this case, the final cannam@95: dimension of the real data must be @emph{padded} with extra values to cannam@95: accommodate the size of the complex data---two extra if the last cannam@95: dimension is even and one if it is odd. That is, the last dimension of cannam@95: the real data must physically contain cannam@95: @tex cannam@95: $2 (n_{d-1}/2+1)$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: 2 * (n[d-1]/2+1) cannam@95: @end ifinfo cannam@95: @html cannam@95: 2 * (nd-1/2+1) cannam@95: @end html cannam@95: @code{double} values (exactly enough to hold the complex data). This cannam@95: physical array size does not, however, change the @emph{logical} array cannam@95: size---only cannam@95: @tex cannam@95: $n_{d-1}$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: n[d-1] cannam@95: @end ifinfo cannam@95: @html cannam@95: nd-1 cannam@95: @end html cannam@95: values are actually stored in the last dimension, and cannam@95: @tex cannam@95: $n_{d-1}$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: n[d-1] cannam@95: @end ifinfo cannam@95: @html cannam@95: nd-1 cannam@95: @end html cannam@95: is the last dimension passed to the planner. cannam@95: cannam@95: @c =========> cannam@95: @node Real-to-Real Transforms, Real-to-Real Transform Kinds, Real-data DFT Array Format, Basic Interface cannam@95: @subsection Real-to-Real Transforms cannam@95: @cindex r2r cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_r2r_1d(int n, double *in, double *out, cannam@95: fftw_r2r_kind kind, unsigned flags); cannam@95: fftw_plan fftw_plan_r2r_2d(int n0, int n1, double *in, double *out, cannam@95: fftw_r2r_kind kind0, fftw_r2r_kind kind1, cannam@95: unsigned flags); cannam@95: fftw_plan fftw_plan_r2r_3d(int n0, int n1, int n2, cannam@95: double *in, double *out, cannam@95: fftw_r2r_kind kind0, cannam@95: fftw_r2r_kind kind1, cannam@95: fftw_r2r_kind kind2, cannam@95: unsigned flags); cannam@95: fftw_plan fftw_plan_r2r(int rank, const int *n, double *in, double *out, cannam@95: const fftw_r2r_kind *kind, unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_r2r_1d cannam@95: @findex fftw_plan_r2r_2d cannam@95: @findex fftw_plan_r2r_3d cannam@95: @findex fftw_plan_r2r cannam@95: cannam@95: Plan a real input/output (r2r) transform of various kinds in zero or cannam@95: more dimensions, returning an @code{fftw_plan} (@pxref{Using Plans}). cannam@95: cannam@95: Once you have created a plan for a certain transform type and cannam@95: parameters, then creating another plan of the same type and parameters, cannam@95: but for different arrays, is fast and shares constant data with the cannam@95: first plan (if it still exists). cannam@95: cannam@95: The planner returns @code{NULL} if the plan cannot be created. A cannam@95: non-@code{NULL} plan is always returned by the basic interface unless cannam@95: you are using a customized FFTW configuration supporting a restricted cannam@95: set of transforms, or for size-1 @code{FFTW_REDFT00} kinds (which are cannam@95: not defined). cannam@95: @ctindex FFTW_REDFT00 cannam@95: cannam@95: @subsubheading Arguments cannam@95: @itemize @bullet cannam@95: cannam@95: @item cannam@95: @code{rank} is the dimensionality of the transform (it should be the cannam@95: size of the arrays @code{*n} and @code{*kind}), and can be any cannam@95: non-negative integer. The @samp{_1d}, @samp{_2d}, and @samp{_3d} cannam@95: planners correspond to a @code{rank} of @code{1}, @code{2}, and cannam@95: @code{3}, respectively. A @code{rank} of zero is equivalent to a copy cannam@95: of one number from input to output. cannam@95: cannam@95: @item cannam@95: @code{n}, or @code{n0}/@code{n1}/@code{n2}, or @code{n[rank]}, cannam@95: respectively, gives the (physical) size of the transform dimensions. cannam@95: They can be any positive integer. cannam@95: cannam@95: @itemize @minus cannam@95: @item cannam@95: @cindex row-major cannam@95: Multi-dimensional arrays are stored in row-major order with dimensions: cannam@95: @code{n0} x @code{n1}; or @code{n0} x @code{n1} x @code{n2}; or cannam@95: @code{n[0]} x @code{n[1]} x ... x @code{n[rank-1]}. cannam@95: @xref{Multi-dimensional Array Format}. cannam@95: @item cannam@95: FFTW is generally best at handling sizes of the form cannam@95: @ifinfo cannam@95: @math{2^a 3^b 5^c 7^d 11^e 13^f}, cannam@95: @end ifinfo cannam@95: @tex cannam@95: $2^a 3^b 5^c 7^d 11^e 13^f$, cannam@95: @end tex cannam@95: @html cannam@95: 2a 3b 5c 7d cannam@95: 11e 13f, cannam@95: @end html cannam@95: where @math{e+f} is either @math{0} or @math{1}, and the other exponents cannam@95: are arbitrary. Other sizes are computed by means of a slow, cannam@95: general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). (It is possible to customize FFTW cannam@95: for different array sizes; see @ref{Installation and Customization}.) cannam@95: Transforms whose sizes are powers of @math{2} are especially fast. cannam@95: @item cannam@95: For a @code{REDFT00} or @code{RODFT00} transform kind in a dimension of cannam@95: size @math{n}, it is @math{n-1} or @math{n+1}, respectively, that cannam@95: should be factorizable in the above form. cannam@95: @end itemize cannam@95: cannam@95: @item cannam@95: @code{in} and @code{out} point to the input and output arrays of the cannam@95: transform, which may be the same (yielding an in-place transform). cannam@95: @cindex in-place cannam@95: These arrays are overwritten during planning, unless cannam@95: @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be cannam@95: initialized, but they must be allocated.) cannam@95: cannam@95: @item cannam@95: @code{kind}, or @code{kind0}/@code{kind1}/@code{kind2}, or cannam@95: @code{kind[rank]}, is the kind of r2r transform used for the cannam@95: corresponding dimension. The valid kind constants are described in cannam@95: @ref{Real-to-Real Transform Kinds}. In a multi-dimensional transform, cannam@95: what is computed is the separable product formed by taking each cannam@95: transform kind along the corresponding dimension, one dimension after cannam@95: another. cannam@95: cannam@95: @item cannam@95: @cindex flags cannam@95: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, cannam@95: as defined in @ref{Planner Flags}. cannam@95: cannam@95: @end itemize cannam@95: cannam@95: @c =========> cannam@95: @node Real-to-Real Transform Kinds, , Real-to-Real Transforms, Basic Interface cannam@95: @subsection Real-to-Real Transform Kinds cannam@95: @cindex kind (r2r) cannam@95: cannam@95: FFTW currently supports 11 different r2r transform kinds, specified by cannam@95: one of the constants below. For the precise definitions of these cannam@95: transforms, see @ref{What FFTW Really Computes}. For a more colloquial cannam@95: introduction to these transform kinds, see @ref{More DFTs of Real Data}. cannam@95: cannam@95: For dimension of size @code{n}, there is a corresponding ``logical'' cannam@95: dimension @code{N} that determines the normalization (and the optimal cannam@95: factorization); the formula for @code{N} is given for each kind below. cannam@95: Also, with each transform kind is listed its corrsponding inverse cannam@95: transform. FFTW computes unnormalized transforms: a transform followed cannam@95: by its inverse will result in the original data multiplied by @code{N} cannam@95: (or the product of the @code{N}'s for each dimension, in cannam@95: multi-dimensions). cannam@95: @cindex normalization cannam@95: cannam@95: @itemize @bullet cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_R2HC cannam@95: @code{FFTW_R2HC} computes a real-input DFT with output in cannam@95: ``halfcomplex'' format, i.e. real and imaginary parts for a transform of cannam@95: size @code{n} stored as: cannam@95: @tex cannam@95: $$ cannam@95: r_0, r_1, r_2, \ldots, r_{n/2}, i_{(n+1)/2-1}, \ldots, i_2, i_1 cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: r0, r1, r2, r(n/2), i((n+1)/2-1), ..., i2, i1 cannam@95: @end ifinfo cannam@95: @html cannam@95:

cannam@95: r0, r1, r2, ..., rn/2, i(n+1)/2-1, ..., i2, i1 cannam@95:

cannam@95: @end html cannam@95: (Logical @code{N=n}, inverse is @code{FFTW_HC2R}.) cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_HC2R cannam@95: @code{FFTW_HC2R} computes the reverse of @code{FFTW_R2HC}, above. cannam@95: (Logical @code{N=n}, inverse is @code{FFTW_R2HC}.) cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_DHT cannam@95: @code{FFTW_DHT} computes a discrete Hartley transform. cannam@95: (Logical @code{N=n}, inverse is @code{FFTW_DHT}.) cannam@95: @cindex discrete Hartley transform cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_REDFT00 cannam@95: @code{FFTW_REDFT00} computes an REDFT00 transform, i.e. a DCT-I. cannam@95: (Logical @code{N=2*(n-1)}, inverse is @code{FFTW_REDFT00}.) cannam@95: @cindex discrete cosine transform cannam@95: @cindex DCT cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_REDFT10 cannam@95: @code{FFTW_REDFT10} computes an REDFT10 transform, i.e. a DCT-II (sometimes called ``the'' DCT). cannam@95: (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT01}.) cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_REDFT01 cannam@95: @code{FFTW_REDFT01} computes an REDFT01 transform, i.e. a DCT-III (sometimes called ``the'' IDCT, being the inverse of DCT-II). cannam@95: (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT=10}.) cannam@95: @cindex IDCT cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_REDFT11 cannam@95: @code{FFTW_REDFT11} computes an REDFT11 transform, i.e. a DCT-IV. cannam@95: (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT11}.) cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_RODFT00 cannam@95: @code{FFTW_RODFT00} computes an RODFT00 transform, i.e. a DST-I. cannam@95: (Logical @code{N=2*(n+1)}, inverse is @code{FFTW_RODFT00}.) cannam@95: @cindex discrete sine transform cannam@95: @cindex DST cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_RODFT10 cannam@95: @code{FFTW_RODFT10} computes an RODFT10 transform, i.e. a DST-II. cannam@95: (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT01}.) cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_RODFT01 cannam@95: @code{FFTW_RODFT01} computes an RODFT01 transform, i.e. a DST-III. cannam@95: (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT=10}.) cannam@95: cannam@95: @item cannam@95: @ctindex FFTW_RODFT11 cannam@95: @code{FFTW_RODFT11} computes an RODFT11 transform, i.e. a DST-IV. cannam@95: (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT11}.) cannam@95: cannam@95: @end itemize cannam@95: cannam@95: @c ------------------------------------------------------------ cannam@95: @node Advanced Interface, Guru Interface, Basic Interface, FFTW Reference cannam@95: @section Advanced Interface cannam@95: @cindex advanced interface cannam@95: cannam@95: FFTW's ``advanced'' interface supplements the basic interface with four cannam@95: new planner routines, providing a new level of flexibility: you can plan cannam@95: a transform of multiple arrays simultaneously, operate on non-contiguous cannam@95: (strided) data, and transform a subset of a larger multi-dimensional cannam@95: array. Other than these additional features, the planner operates in cannam@95: the same fashion as in the basic interface, and the resulting cannam@95: @code{fftw_plan} is used in the same way (@pxref{Using Plans}). cannam@95: cannam@95: @menu cannam@95: * Advanced Complex DFTs:: cannam@95: * Advanced Real-data DFTs:: cannam@95: * Advanced Real-to-real Transforms:: cannam@95: @end menu cannam@95: cannam@95: @c =========> cannam@95: @node Advanced Complex DFTs, Advanced Real-data DFTs, Advanced Interface, Advanced Interface cannam@95: @subsection Advanced Complex DFTs cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_many_dft(int rank, const int *n, int howmany, cannam@95: fftw_complex *in, const int *inembed, cannam@95: int istride, int idist, cannam@95: fftw_complex *out, const int *onembed, cannam@95: int ostride, int odist, cannam@95: int sign, unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_many_dft cannam@95: cannam@95: This routine plans multiple multidimensional complex DFTs, and it cannam@95: extends the @code{fftw_plan_dft} routine (@pxref{Complex DFTs}) to cannam@95: compute @code{howmany} transforms, each having rank @code{rank} and size cannam@95: @code{n}. In addition, the transform data need not be contiguous, but cannam@95: it may be laid out in memory with an arbitrary stride. To account for cannam@95: these possibilities, @code{fftw_plan_many_dft} adds the new parameters cannam@95: @code{howmany}, @{@code{i},@code{o}@}@code{nembed}, cannam@95: @{@code{i},@code{o}@}@code{stride}, and cannam@95: @{@code{i},@code{o}@}@code{dist}. The FFTW basic interface cannam@95: (@pxref{Complex DFTs}) provides routines specialized for ranks 1, 2, cannam@95: and@tie{}3, but the advanced interface handles only the general-rank cannam@95: case. cannam@95: cannam@95: @code{howmany} is the number of transforms to compute. The resulting cannam@95: plan computes @code{howmany} transforms, where the input of the cannam@95: @code{k}-th transform is at location @code{in+k*idist} (in C pointer cannam@95: arithmetic), and its output is at location @code{out+k*odist}. Plans cannam@95: obtained in this way can often be faster than calling FFTW multiple cannam@95: times for the individual transforms. The basic @code{fftw_plan_dft} cannam@95: interface corresponds to @code{howmany=1} (in which case the @code{dist} cannam@95: parameters are ignored). cannam@95: @cindex howmany parameter cannam@95: @cindex dist cannam@95: cannam@95: cannam@95: Each of the @code{howmany} transforms has rank @code{rank} and size cannam@95: @code{n}, as in the basic interface. In addition, the advanced cannam@95: interface allows the input and output arrays of each transform to be cannam@95: row-major subarrays of larger rank-@code{rank} arrays, described by cannam@95: @code{inembed} and @code{onembed} parameters, respectively. cannam@95: @{@code{i},@code{o}@}@code{nembed} must be arrays of length @code{rank}, cannam@95: and @code{n} should be elementwise less than or equal to cannam@95: @{@code{i},@code{o}@}@code{nembed}. Passing @code{NULL} for an cannam@95: @code{nembed} parameter is equivalent to passing @code{n} (i.e. same cannam@95: physical and logical dimensions, as in the basic interface.) cannam@95: cannam@95: The @code{stride} parameters indicate that the @code{j}-th element of cannam@95: the input or output arrays is located at @code{j*istride} or cannam@95: @code{j*ostride}, respectively. (For a multi-dimensional array, cannam@95: @code{j} is the ordinary row-major index.) When combined with the cannam@95: @code{k}-th transform in a @code{howmany} loop, from above, this means cannam@95: that the (@code{j},@code{k})-th element is at @code{j*stride+k*dist}. cannam@95: (The basic @code{fftw_plan_dft} interface corresponds to a stride of 1.) cannam@95: @cindex stride cannam@95: cannam@95: cannam@95: For in-place transforms, the input and output @code{stride} and cannam@95: @code{dist} parameters should be the same; otherwise, the planner may cannam@95: return @code{NULL}. cannam@95: cannam@95: Arrays @code{n}, @code{inembed}, and @code{onembed} are not used after cannam@95: this function returns. You can safely free or reuse them. cannam@95: cannam@95: @strong{Examples}: cannam@95: One transform of one 5 by 6 array contiguous in memory: cannam@95: @example cannam@95: int rank = 2; cannam@95: int n[] = @{5, 6@}; cannam@95: int howmany = 1; cannam@95: int idist = odist = 0; /* unused because howmany = 1 */ cannam@95: int istride = ostride = 1; /* array is contiguous in memory */ cannam@95: int *inembed = n, *onembed = n; cannam@95: @end example cannam@95: cannam@95: Transform of three 5 by 6 arrays, each contiguous in memory, cannam@95: stored in memory one after another: cannam@95: @example cannam@95: int rank = 2; cannam@95: int n[] = @{5, 6@}; cannam@95: int howmany = 3; cannam@95: int idist = odist = n[0]*n[1]; /* = 30, the distance in memory cannam@95: between the first element cannam@95: of the first array and the cannam@95: first element of the second array */ cannam@95: int istride = ostride = 1; /* array is contiguous in memory */ cannam@95: int *inembed = n, *onembed = n; cannam@95: @end example cannam@95: cannam@95: Transform each column of a 2d array with 10 rows and 3 columns: cannam@95: @example cannam@95: int rank = 1; /* not 2: we are computing 1d transforms */ cannam@95: int n[] = @{10@}; /* 1d transforms of length 10 */ cannam@95: int howmany = 3; cannam@95: int idist = odist = 1; cannam@95: int istride = ostride = 3; /* distance between two elements in cannam@95: the same column */ cannam@95: int *inembed = n, *onembed = n; cannam@95: @end example cannam@95: cannam@95: @c =========> cannam@95: @node Advanced Real-data DFTs, Advanced Real-to-real Transforms, Advanced Complex DFTs, Advanced Interface cannam@95: @subsection Advanced Real-data DFTs cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_many_dft_r2c(int rank, const int *n, int howmany, cannam@95: double *in, const int *inembed, cannam@95: int istride, int idist, cannam@95: fftw_complex *out, const int *onembed, cannam@95: int ostride, int odist, cannam@95: unsigned flags); cannam@95: fftw_plan fftw_plan_many_dft_c2r(int rank, const int *n, int howmany, cannam@95: fftw_complex *in, const int *inembed, cannam@95: int istride, int idist, cannam@95: double *out, const int *onembed, cannam@95: int ostride, int odist, cannam@95: unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_many_dft_r2c cannam@95: @findex fftw_plan_many_dft_c2r cannam@95: cannam@95: Like @code{fftw_plan_many_dft}, these two functions add @code{howmany}, cannam@95: @code{nembed}, @code{stride}, and @code{dist} parameters to the cannam@95: @code{fftw_plan_dft_r2c} and @code{fftw_plan_dft_c2r} functions, but cannam@95: otherwise behave the same as the basic interface. cannam@95: cannam@95: The interpretation of @code{howmany}, @code{stride}, and @code{dist} are cannam@95: the same as for @code{fftw_plan_many_dft}, above. Note that the cannam@95: @code{stride} and @code{dist} for the real array are in units of cannam@95: @code{double}, and for the complex array are in units of cannam@95: @code{fftw_complex}. cannam@95: cannam@95: If an @code{nembed} parameter is @code{NULL}, it is interpreted as what cannam@95: it would be in the basic interface, as described in @ref{Real-data DFT cannam@95: Array Format}. That is, for the complex array the size is assumed to be cannam@95: the same as @code{n}, but with the last dimension cut roughly in half. cannam@95: For the real array, the size is assumed to be @code{n} if the transform cannam@95: is out-of-place, or @code{n} with the last dimension ``padded'' if the cannam@95: transform is in-place. cannam@95: cannam@95: If an @code{nembed} parameter is non-@code{NULL}, it is interpreted as cannam@95: the physical size of the corresponding array, in row-major order, just cannam@95: as for @code{fftw_plan_many_dft}. In this case, each dimension of cannam@95: @code{nembed} should be @code{>=} what it would be in the basic cannam@95: interface (e.g. the halved or padded @code{n}). cannam@95: cannam@95: Arrays @code{n}, @code{inembed}, and @code{onembed} are not used after cannam@95: this function returns. You can safely free or reuse them. cannam@95: cannam@95: @c =========> cannam@95: @node Advanced Real-to-real Transforms, , Advanced Real-data DFTs, Advanced Interface cannam@95: @subsection Advanced Real-to-real Transforms cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_many_r2r(int rank, const int *n, int howmany, cannam@95: double *in, const int *inembed, cannam@95: int istride, int idist, cannam@95: double *out, const int *onembed, cannam@95: int ostride, int odist, cannam@95: const fftw_r2r_kind *kind, unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_many_r2r cannam@95: cannam@95: Like @code{fftw_plan_many_dft}, this functions adds @code{howmany}, cannam@95: @code{nembed}, @code{stride}, and @code{dist} parameters to the cannam@95: @code{fftw_plan_r2r} function, but otherwise behave the same as the cannam@95: basic interface. The interpretation of those additional parameters are cannam@95: the same as for @code{fftw_plan_many_dft}. (Of course, the cannam@95: @code{stride} and @code{dist} parameters are now in units of cannam@95: @code{double}, not @code{fftw_complex}.) cannam@95: cannam@95: Arrays @code{n}, @code{inembed}, @code{onembed}, and @code{kind} are not cannam@95: used after this function returns. You can safely free or reuse them. cannam@95: cannam@95: @c ------------------------------------------------------------ cannam@95: @node Guru Interface, New-array Execute Functions, Advanced Interface, FFTW Reference cannam@95: @section Guru Interface cannam@95: @cindex guru interface cannam@95: cannam@95: The ``guru'' interface to FFTW is intended to expose as much as possible cannam@95: of the flexibility in the underlying FFTW architecture. It allows one cannam@95: to compute multi-dimensional ``vectors'' (loops) of multi-dimensional cannam@95: transforms, where each vector/transform dimension has an independent cannam@95: size and stride. cannam@95: @cindex vector cannam@95: One can also use more general complex-number formats, e.g. separate real cannam@95: and imaginary arrays. cannam@95: cannam@95: For those users who require the flexibility of the guru interface, it is cannam@95: important that they pay special attention to the documentation lest they cannam@95: shoot themselves in the foot. cannam@95: cannam@95: @menu cannam@95: * Interleaved and split arrays:: cannam@95: * Guru vector and transform sizes:: cannam@95: * Guru Complex DFTs:: cannam@95: * Guru Real-data DFTs:: cannam@95: * Guru Real-to-real Transforms:: cannam@95: * 64-bit Guru Interface:: cannam@95: @end menu cannam@95: cannam@95: @c =========> cannam@95: @node Interleaved and split arrays, Guru vector and transform sizes, Guru Interface, Guru Interface cannam@95: @subsection Interleaved and split arrays cannam@95: cannam@95: The guru interface supports two representations of complex numbers, cannam@95: which we call the interleaved and the split format. cannam@95: cannam@95: The @dfn{interleaved} format is the same one used by the basic and cannam@95: advanced interfaces, and it is documented in @ref{Complex numbers}. cannam@95: In the interleaved format, you provide pointers to the real part of a cannam@95: complex number, and the imaginary part understood to be stored in the cannam@95: next memory location. cannam@95: @cindex interleaved format cannam@95: cannam@95: cannam@95: The @dfn{split} format allows separate pointers to the real and cannam@95: imaginary parts of a complex array. cannam@95: @cindex split format cannam@95: cannam@95: cannam@95: Technically, the interleaved format is redundant, because you can cannam@95: always express an interleaved array in terms of a split array with cannam@95: appropriate pointers and strides. On the other hand, the interleaved cannam@95: format is simpler to use, and it is common in practice. Hence, FFTW cannam@95: supports it as a special case. cannam@95: cannam@95: @c =========> cannam@95: @node Guru vector and transform sizes, Guru Complex DFTs, Interleaved and split arrays, Guru Interface cannam@95: @subsection Guru vector and transform sizes cannam@95: cannam@95: The guru interface introduces one basic new data structure, cannam@95: @code{fftw_iodim}, that is used to specify sizes and strides for cannam@95: multi-dimensional transforms and vectors: cannam@95: cannam@95: @example cannam@95: typedef struct @{ cannam@95: int n; cannam@95: int is; cannam@95: int os; cannam@95: @} fftw_iodim; cannam@95: @end example cannam@95: @tindex fftw_iodim cannam@95: cannam@95: Here, @code{n} is the size of the dimension, and @code{is} and @code{os} cannam@95: are the strides of that dimension for the input and output arrays. (The cannam@95: stride is the separation of consecutive elements along this dimension.) cannam@95: cannam@95: The meaning of the stride parameter depends on the type of the array cannam@95: that the stride refers to. @emph{If the array is interleaved complex, cannam@95: strides are expressed in units of complex numbers cannam@95: (@code{fftw_complex}). If the array is split complex or real, strides cannam@95: are expressed in units of real numbers (@code{double}).} This cannam@95: convention is consistent with the usual pointer arithmetic in the C cannam@95: language. An interleaved array is denoted by a pointer @code{p} to cannam@95: @code{fftw_complex}, so that @code{p+1} points to the next complex cannam@95: number. Split arrays are denoted by pointers to @code{double}, in cannam@95: which case pointer arithmetic operates in units of cannam@95: @code{sizeof(double)}. cannam@95: @cindex stride cannam@95: cannam@95: cannam@95: The guru planner interfaces all take a (@code{rank}, @code{dims[rank]}) cannam@95: pair describing the transform size, and a (@code{howmany_rank}, cannam@95: @code{howmany_dims[howmany_rank]}) pair describing the ``vector'' size (a cannam@95: multi-dimensional loop of transforms to perform), where @code{dims} and cannam@95: @code{howmany_dims} are arrays of @code{fftw_iodim}. cannam@95: cannam@95: For example, the @code{howmany} parameter in the advanced complex-DFT cannam@95: interface corresponds to @code{howmany_rank} = 1, cannam@95: @code{howmany_dims[0].n} = @code{howmany}, @code{howmany_dims[0].is} = cannam@95: @code{idist}, and @code{howmany_dims[0].os} = @code{odist}. cannam@95: @cindex howmany loop cannam@95: @cindex dist cannam@95: (To compute a single transform, you can just use @code{howmany_rank} = 0.) cannam@95: cannam@95: cannam@95: A row-major multidimensional array with dimensions @code{n[rank]} cannam@95: (@pxref{Row-major Format}) corresponds to @code{dims[i].n} = cannam@95: @code{n[i]} and the recurrence @code{dims[i].is} = @code{n[i+1] * cannam@95: dims[i+1].is} (similarly for @code{os}). The stride of the last cannam@95: (@code{i=rank-1}) dimension is the overall stride of the array. cannam@95: e.g. to be equivalent to the advanced complex-DFT interface, you would cannam@95: have @code{dims[rank-1].is} = @code{istride} and cannam@95: @code{dims[rank-1].os} = @code{ostride}. cannam@95: @cindex row-major cannam@95: cannam@95: cannam@95: In general, we only guarantee FFTW to return a non-@code{NULL} plan if cannam@95: the vector and transform dimensions correspond to a set of distinct cannam@95: indices, and for in-place transforms the input/output strides should cannam@95: be the same. cannam@95: cannam@95: @c =========> cannam@95: @node Guru Complex DFTs, Guru Real-data DFTs, Guru vector and transform sizes, Guru Interface cannam@95: @subsection Guru Complex DFTs cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_guru_dft( cannam@95: int rank, const fftw_iodim *dims, cannam@95: int howmany_rank, const fftw_iodim *howmany_dims, cannam@95: fftw_complex *in, fftw_complex *out, cannam@95: int sign, unsigned flags); cannam@95: cannam@95: fftw_plan fftw_plan_guru_split_dft( cannam@95: int rank, const fftw_iodim *dims, cannam@95: int howmany_rank, const fftw_iodim *howmany_dims, cannam@95: double *ri, double *ii, double *ro, double *io, cannam@95: unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_guru_dft cannam@95: @findex fftw_plan_guru_split_dft cannam@95: cannam@95: These two functions plan a complex-data, multi-dimensional DFT cannam@95: for the interleaved and split format, respectively. cannam@95: Transform dimensions are given by (@code{rank}, @code{dims}) over a cannam@95: multi-dimensional vector (loop) of dimensions (@code{howmany_rank}, cannam@95: @code{howmany_dims}). @code{dims} and @code{howmany_dims} should point cannam@95: to @code{fftw_iodim} arrays of length @code{rank} and cannam@95: @code{howmany_rank}, respectively. cannam@95: cannam@95: @cindex flags cannam@95: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, cannam@95: as defined in @ref{Planner Flags}. cannam@95: cannam@95: In the @code{fftw_plan_guru_dft} function, the pointers @code{in} and cannam@95: @code{out} point to the interleaved input and output arrays, cannam@95: respectively. The sign can be either @math{-1} (= cannam@95: @code{FFTW_FORWARD}) or @math{+1} (= @code{FFTW_BACKWARD}). If the cannam@95: pointers are equal, the transform is in-place. cannam@95: cannam@95: In the @code{fftw_plan_guru_split_dft} function, cannam@95: @code{ri} and @code{ii} point to the real and imaginary input arrays, cannam@95: and @code{ro} and @code{io} point to the real and imaginary output cannam@95: arrays. The input and output pointers may be the same, indicating an cannam@95: in-place transform. For example, for @code{fftw_complex} pointers cannam@95: @code{in} and @code{out}, the corresponding parameters are: cannam@95: cannam@95: @example cannam@95: ri = (double *) in; cannam@95: ii = (double *) in + 1; cannam@95: ro = (double *) out; cannam@95: io = (double *) out + 1; cannam@95: @end example cannam@95: cannam@95: Because @code{fftw_plan_guru_split_dft} accepts split arrays, strides cannam@95: are expressed in units of @code{double}. For a contiguous cannam@95: @code{fftw_complex} array, the overall stride of the transform should cannam@95: be 2, the distance between consecutive real parts or between cannam@95: consecutive imaginary parts; see @ref{Guru vector and transform cannam@95: sizes}. Note that the dimension strides are applied equally to the cannam@95: real and imaginary parts; real and imaginary arrays with different cannam@95: strides are not supported. cannam@95: cannam@95: There is no @code{sign} parameter in @code{fftw_plan_guru_split_dft}. cannam@95: This function always plans for an @code{FFTW_FORWARD} transform. To cannam@95: plan for an @code{FFTW_BACKWARD} transform, you can exploit the cannam@95: identity that the backwards DFT is equal to the forwards DFT with the cannam@95: real and imaginary parts swapped. For example, in the case of the cannam@95: @code{fftw_complex} arrays above, the @code{FFTW_BACKWARD} transform cannam@95: is computed by the parameters: cannam@95: cannam@95: @example cannam@95: ri = (double *) in + 1; cannam@95: ii = (double *) in; cannam@95: ro = (double *) out + 1; cannam@95: io = (double *) out; cannam@95: @end example cannam@95: cannam@95: @c =========> cannam@95: @node Guru Real-data DFTs, Guru Real-to-real Transforms, Guru Complex DFTs, Guru Interface cannam@95: @subsection Guru Real-data DFTs cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_guru_dft_r2c( cannam@95: int rank, const fftw_iodim *dims, cannam@95: int howmany_rank, const fftw_iodim *howmany_dims, cannam@95: double *in, fftw_complex *out, cannam@95: unsigned flags); cannam@95: cannam@95: fftw_plan fftw_plan_guru_split_dft_r2c( cannam@95: int rank, const fftw_iodim *dims, cannam@95: int howmany_rank, const fftw_iodim *howmany_dims, cannam@95: double *in, double *ro, double *io, cannam@95: unsigned flags); cannam@95: cannam@95: fftw_plan fftw_plan_guru_dft_c2r( cannam@95: int rank, const fftw_iodim *dims, cannam@95: int howmany_rank, const fftw_iodim *howmany_dims, cannam@95: fftw_complex *in, double *out, cannam@95: unsigned flags); cannam@95: cannam@95: fftw_plan fftw_plan_guru_split_dft_c2r( cannam@95: int rank, const fftw_iodim *dims, cannam@95: int howmany_rank, const fftw_iodim *howmany_dims, cannam@95: double *ri, double *ii, double *out, cannam@95: unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_guru_dft_r2c cannam@95: @findex fftw_plan_guru_split_dft_r2c cannam@95: @findex fftw_plan_guru_dft_c2r cannam@95: @findex fftw_plan_guru_split_dft_c2r cannam@95: cannam@95: Plan a real-input (r2c) or real-output (c2r), multi-dimensional DFT with cannam@95: transform dimensions given by (@code{rank}, @code{dims}) over a cannam@95: multi-dimensional vector (loop) of dimensions (@code{howmany_rank}, cannam@95: @code{howmany_dims}). @code{dims} and @code{howmany_dims} should point cannam@95: to @code{fftw_iodim} arrays of length @code{rank} and cannam@95: @code{howmany_rank}, respectively. As for the basic and advanced cannam@95: interfaces, an r2c transform is @code{FFTW_FORWARD} and a c2r transform cannam@95: is @code{FFTW_BACKWARD}. cannam@95: cannam@95: The @emph{last} dimension of @code{dims} is interpreted specially: cannam@95: that dimension of the real array has size @code{dims[rank-1].n}, but cannam@95: that dimension of the complex array has size @code{dims[rank-1].n/2+1} cannam@95: (division rounded down). The strides, on the other hand, are taken to cannam@95: be exactly as specified. It is up to the user to specify the strides cannam@95: appropriately for the peculiar dimensions of the data, and we do not cannam@95: guarantee that the planner will succeed (return non-@code{NULL}) for cannam@95: any dimensions other than those described in @ref{Real-data DFT Array cannam@95: Format} and generalized in @ref{Advanced Real-data DFTs}. (That is, cannam@95: for an in-place transform, each individual dimension should be able to cannam@95: operate in place.) cannam@95: @cindex in-place cannam@95: cannam@95: cannam@95: @code{in} and @code{out} point to the input and output arrays for r2c cannam@95: and c2r transforms, respectively. For split arrays, @code{ri} and cannam@95: @code{ii} point to the real and imaginary input arrays for a c2r cannam@95: transform, and @code{ro} and @code{io} point to the real and imaginary cannam@95: output arrays for an r2c transform. @code{in} and @code{ro} or cannam@95: @code{ri} and @code{out} may be the same, indicating an in-place cannam@95: transform. (In-place transforms where @code{in} and @code{io} or cannam@95: @code{ii} and @code{out} are the same are not currently supported.) cannam@95: cannam@95: @cindex flags cannam@95: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, cannam@95: as defined in @ref{Planner Flags}. cannam@95: cannam@95: In-place transforms of rank greater than 1 are currently only cannam@95: supported for interleaved arrays. For split arrays, the planner will cannam@95: return @code{NULL}. cannam@95: @cindex in-place cannam@95: cannam@95: @c =========> cannam@95: @node Guru Real-to-real Transforms, 64-bit Guru Interface, Guru Real-data DFTs, Guru Interface cannam@95: @subsection Guru Real-to-real Transforms cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_guru_r2r(int rank, const fftw_iodim *dims, cannam@95: int howmany_rank, cannam@95: const fftw_iodim *howmany_dims, cannam@95: double *in, double *out, cannam@95: const fftw_r2r_kind *kind, cannam@95: unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_guru_r2r cannam@95: cannam@95: Plan a real-to-real (r2r) multi-dimensional @code{FFTW_FORWARD} cannam@95: transform with transform dimensions given by (@code{rank}, @code{dims}) cannam@95: over a multi-dimensional vector (loop) of dimensions cannam@95: (@code{howmany_rank}, @code{howmany_dims}). @code{dims} and cannam@95: @code{howmany_dims} should point to @code{fftw_iodim} arrays of length cannam@95: @code{rank} and @code{howmany_rank}, respectively. cannam@95: cannam@95: The transform kind of each dimension is given by the @code{kind} cannam@95: parameter, which should point to an array of length @code{rank}. Valid cannam@95: @code{fftw_r2r_kind} constants are given in @ref{Real-to-Real Transform cannam@95: Kinds}. cannam@95: cannam@95: @code{in} and @code{out} point to the real input and output arrays; they cannam@95: may be the same, indicating an in-place transform. cannam@95: cannam@95: @cindex flags cannam@95: @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags, cannam@95: as defined in @ref{Planner Flags}. cannam@95: cannam@95: @c =========> cannam@95: @node 64-bit Guru Interface, , Guru Real-to-real Transforms, Guru Interface cannam@95: @subsection 64-bit Guru Interface cannam@95: @cindex 64-bit architecture cannam@95: cannam@95: When compiled in 64-bit mode on a 64-bit architecture (where addresses cannam@95: are 64 bits wide), FFTW uses 64-bit quantities internally for all cannam@95: transform sizes, strides, and so on---you don't have to do anything cannam@95: special to exploit this. However, in the ordinary FFTW interfaces, cannam@95: you specify the transform size by an @code{int} quantity, which is cannam@95: normally only 32 bits wide. This means that, even though FFTW is cannam@95: using 64-bit sizes internally, you cannot specify a single transform cannam@95: dimension larger than cannam@95: @ifinfo cannam@95: 2^31-1 cannam@95: @end ifinfo cannam@95: @html cannam@95: 231−1 cannam@95: @end html cannam@95: @tex cannam@95: $2^31-1$ cannam@95: @end tex cannam@95: numbers. cannam@95: cannam@95: We expect that few users will require transforms larger than this, but, cannam@95: for those who do, we provide a 64-bit version of the guru interface in cannam@95: which all sizes are specified as integers of type @code{ptrdiff_t} cannam@95: instead of @code{int}. (@code{ptrdiff_t} is a signed integer type cannam@95: defined by the C standard to be wide enough to represent address cannam@95: differences, and thus must be at least 64 bits wide on a 64-bit cannam@95: machine.) We stress that there is @emph{no performance advantage} to cannam@95: using this interface---the same internal FFTW code is employed cannam@95: regardless---and it is only necessary if you want to specify very cannam@95: large transform sizes. cannam@95: @tindex ptrdiff_t cannam@95: cannam@95: cannam@95: In particular, the 64-bit guru interface is a set of planner routines cannam@95: that are exactly the same as the guru planner routines, except that cannam@95: they are named with @samp{guru64} instead of @samp{guru} and they take cannam@95: arguments of type @code{fftw_iodim64} instead of @code{fftw_iodim}. cannam@95: For example, instead of @code{fftw_plan_guru_dft}, we have cannam@95: @code{fftw_plan_guru64_dft}. cannam@95: cannam@95: @example cannam@95: fftw_plan fftw_plan_guru64_dft( cannam@95: int rank, const fftw_iodim64 *dims, cannam@95: int howmany_rank, const fftw_iodim64 *howmany_dims, cannam@95: fftw_complex *in, fftw_complex *out, cannam@95: int sign, unsigned flags); cannam@95: @end example cannam@95: @findex fftw_plan_guru64_dft cannam@95: cannam@95: The @code{fftw_iodim64} type is similar to @code{fftw_iodim}, with the cannam@95: same interpretation, except that it uses type @code{ptrdiff_t} instead cannam@95: of type @code{int}. cannam@95: cannam@95: @example cannam@95: typedef struct @{ cannam@95: ptrdiff_t n; cannam@95: ptrdiff_t is; cannam@95: ptrdiff_t os; cannam@95: @} fftw_iodim64; cannam@95: @end example cannam@95: @tindex fftw_iodim64 cannam@95: cannam@95: Every other @samp{fftw_plan_guru} function also has a cannam@95: @samp{fftw_plan_guru64} equivalent, but we do not repeat their cannam@95: documentation here since they are identical to the 32-bit versions cannam@95: except as noted above. cannam@95: cannam@95: @c ----------------------------------------------------------- cannam@95: @node New-array Execute Functions, Wisdom, Guru Interface, FFTW Reference cannam@95: @section New-array Execute Functions cannam@95: @cindex execute cannam@95: @cindex new-array execution cannam@95: cannam@95: Normally, one executes a plan for the arrays with which the plan was cannam@95: created, by calling @code{fftw_execute(plan)} as described in @ref{Using cannam@95: Plans}. cannam@95: @findex fftw_execute cannam@95: However, it is possible for sophisticated users to apply a given plan cannam@95: to a @emph{different} array using the ``new-array execute'' functions cannam@95: detailed below, provided that the following conditions are met: cannam@95: cannam@95: @itemize @bullet cannam@95: cannam@95: @item cannam@95: The array size, strides, etcetera are the same (since those are set by cannam@95: the plan). cannam@95: cannam@95: @item cannam@95: The input and output arrays are the same (in-place) or different cannam@95: (out-of-place) if the plan was originally created to be in-place or cannam@95: out-of-place, respectively. cannam@95: cannam@95: @item cannam@95: For split arrays, the separations between the real and imaginary cannam@95: parts, @code{ii-ri} and @code{io-ro}, are the same as they were for cannam@95: the input and output arrays when the plan was created. (This cannam@95: condition is automatically satisfied for interleaved arrays.) cannam@95: cannam@95: @item cannam@95: The @dfn{alignment} of the new input/output arrays is the same as that cannam@95: of the input/output arrays when the plan was created, unless the plan cannam@95: was created with the @code{FFTW_UNALIGNED} flag. cannam@95: @ctindex FFTW_UNALIGNED cannam@95: Here, the alignment is a platform-dependent quantity (for example, it is cannam@95: the address modulo 16 if SSE SIMD instructions are used, but the address cannam@95: modulo 4 for non-SIMD single-precision FFTW on the same machine). In cannam@95: general, only arrays allocated with @code{fftw_malloc} are guaranteed to cannam@95: be equally aligned (@pxref{SIMD alignment and fftw_malloc}). cannam@95: cannam@95: @end itemize cannam@95: cannam@95: @cindex alignment cannam@95: The alignment issue is especially critical, because if you don't use cannam@95: @code{fftw_malloc} then you may have little control over the alignment cannam@95: of arrays in memory. For example, neither the C++ @code{new} function cannam@95: nor the Fortran @code{allocate} statement provide strong enough cannam@95: guarantees about data alignment. If you don't use @code{fftw_malloc}, cannam@95: therefore, you probably have to use @code{FFTW_UNALIGNED} (which cannam@95: disables most SIMD support). If possible, it is probably better for cannam@95: you to simply create multiple plans (creating a new plan is quick once cannam@95: one exists for a given size), or better yet re-use the same array for cannam@95: your transforms. cannam@95: cannam@95: If you are tempted to use the new-array execute interface because you cannam@95: want to transform a known bunch of arrays of the same size, you should cannam@95: probably go use the advanced interface instead (@pxref{Advanced cannam@95: Interface})). cannam@95: cannam@95: The new-array execute functions are: cannam@95: cannam@95: @example cannam@95: void fftw_execute_dft( cannam@95: const fftw_plan p, cannam@95: fftw_complex *in, fftw_complex *out); cannam@95: cannam@95: void fftw_execute_split_dft( cannam@95: const fftw_plan p, cannam@95: double *ri, double *ii, double *ro, double *io); cannam@95: cannam@95: void fftw_execute_dft_r2c( cannam@95: const fftw_plan p, cannam@95: double *in, fftw_complex *out); cannam@95: cannam@95: void fftw_execute_split_dft_r2c( cannam@95: const fftw_plan p, cannam@95: double *in, double *ro, double *io); cannam@95: cannam@95: void fftw_execute_dft_c2r( cannam@95: const fftw_plan p, cannam@95: fftw_complex *in, double *out); cannam@95: cannam@95: void fftw_execute_split_dft_c2r( cannam@95: const fftw_plan p, cannam@95: double *ri, double *ii, double *out); cannam@95: cannam@95: void fftw_execute_r2r( cannam@95: const fftw_plan p, cannam@95: double *in, double *out); cannam@95: @end example cannam@95: @findex fftw_execute_dft cannam@95: @findex fftw_execute_split_dft cannam@95: @findex fftw_execute_dft_r2c cannam@95: @findex fftw_execute_split_dft_r2c cannam@95: @findex fftw_execute_dft_c2r cannam@95: @findex fftw_execute_split_dft_c2r cannam@95: @findex fftw_execute_r2r cannam@95: cannam@95: These execute the @code{plan} to compute the corresponding transform on cannam@95: the input/output arrays specified by the subsequent arguments. The cannam@95: input/output array arguments have the same meanings as the ones passed cannam@95: to the guru planner routines in the preceding sections. The @code{plan} cannam@95: is not modified, and these routines can be called as many times as cannam@95: desired, or intermixed with calls to the ordinary @code{fftw_execute}. cannam@95: cannam@95: The @code{plan} @emph{must} have been created for the transform type cannam@95: corresponding to the execute function, e.g. it must be a complex-DFT cannam@95: plan for @code{fftw_execute_dft}. Any of the planner routines for that cannam@95: transform type, from the basic to the guru interface, could have been cannam@95: used to create the plan, however. cannam@95: cannam@95: @c ------------------------------------------------------------ cannam@95: @node Wisdom, What FFTW Really Computes, New-array Execute Functions, FFTW Reference cannam@95: @section Wisdom cannam@95: @cindex wisdom cannam@95: @cindex saving plans to disk cannam@95: cannam@95: This section documents the FFTW mechanism for saving and restoring cannam@95: plans from disk. This mechanism is called @dfn{wisdom}. cannam@95: cannam@95: @menu cannam@95: * Wisdom Export:: cannam@95: * Wisdom Import:: cannam@95: * Forgetting Wisdom:: cannam@95: * Wisdom Utilities:: cannam@95: @end menu cannam@95: cannam@95: @c =========> cannam@95: @node Wisdom Export, Wisdom Import, Wisdom, Wisdom cannam@95: @subsection Wisdom Export cannam@95: cannam@95: @example cannam@95: int fftw_export_wisdom_to_filename(const char *filename); cannam@95: void fftw_export_wisdom_to_file(FILE *output_file); cannam@95: char *fftw_export_wisdom_to_string(void); cannam@95: void fftw_export_wisdom(void (*write_char)(char c, void *), void *data); cannam@95: @end example cannam@95: @findex fftw_export_wisdom cannam@95: @findex fftw_export_wisdom_to_filename cannam@95: @findex fftw_export_wisdom_to_file cannam@95: @findex fftw_export_wisdom_to_string cannam@95: cannam@95: These functions allow you to export all currently accumulated wisdom cannam@95: in a form from which it can be later imported and restored, even cannam@95: during a separate run of the program. (@xref{Words of Wisdom-Saving cannam@95: Plans}.) The current store of wisdom is not affected by calling any cannam@95: of these routines. cannam@95: cannam@95: @code{fftw_export_wisdom} exports the wisdom to any output cannam@95: medium, as specified by the callback function cannam@95: @code{write_char}. @code{write_char} is a @code{putc}-like function that cannam@95: writes the character @code{c} to some output; its second parameter is cannam@95: the @code{data} pointer passed to @code{fftw_export_wisdom}. For cannam@95: convenience, the following three ``wrapper'' routines are provided: cannam@95: cannam@95: @code{fftw_export_wisdom_to_filename} writes wisdom to a file named cannam@95: @code{filename} (which is created or overwritten), returning @code{1} cannam@95: on success and @code{0} on failure. A lower-level function, which cannam@95: requires you to open and close the file yourself (e.g. if you want to cannam@95: write wisdom to a portion of a larger file) is cannam@95: @code{fftw_export_wisdom_to_file}. This writes the wisdom to the cannam@95: current position in @code{output_file}, which should be open with cannam@95: write permission; upon exit, the file remains open and is positioned cannam@95: at the end of the wisdom data. cannam@95: cannam@95: @code{fftw_export_wisdom_to_string} returns a pointer to a cannam@95: @code{NULL}-terminated string holding the wisdom data. This string is cannam@95: dynamically allocated, and it is the responsibility of the caller to cannam@95: deallocate it with @code{free} when it is no longer needed. cannam@95: cannam@95: All of these routines export the wisdom in the same format, which we cannam@95: will not document here except to say that it is LISP-like ASCII text cannam@95: that is insensitive to white space. cannam@95: cannam@95: @c =========> cannam@95: @node Wisdom Import, Forgetting Wisdom, Wisdom Export, Wisdom cannam@95: @subsection Wisdom Import cannam@95: cannam@95: @example cannam@95: int fftw_import_system_wisdom(void); cannam@95: int fftw_import_wisdom_from_filename(const char *filename); cannam@95: int fftw_import_wisdom_from_string(const char *input_string); cannam@95: int fftw_import_wisdom(int (*read_char)(void *), void *data); cannam@95: @end example cannam@95: @findex fftw_import_wisdom cannam@95: @findex fftw_import_system_wisdom cannam@95: @findex fftw_import_wisdom_from_filename cannam@95: @findex fftw_import_wisdom_from_file cannam@95: @findex fftw_import_wisdom_from_string cannam@95: cannam@95: These functions import wisdom into a program from data stored by the cannam@95: @code{fftw_export_wisdom} functions above. (@xref{Words of cannam@95: Wisdom-Saving Plans}.) The imported wisdom replaces any wisdom cannam@95: already accumulated by the running program. cannam@95: cannam@95: @code{fftw_import_wisdom} imports wisdom from any input medium, as cannam@95: specified by the callback function @code{read_char}. @code{read_char} is cannam@95: a @code{getc}-like function that returns the next character in the cannam@95: input; its parameter is the @code{data} pointer passed to cannam@95: @code{fftw_import_wisdom}. If the end of the input data is reached cannam@95: (which should never happen for valid data), @code{read_char} should cannam@95: return @code{EOF} (as defined in @code{}). For convenience, cannam@95: the following three ``wrapper'' routines are provided: cannam@95: cannam@95: @code{fftw_import_wisdom_from_filename} reads wisdom from a file named cannam@95: @code{filename}. A lower-level function, which requires you to open cannam@95: and close the file yourself (e.g. if you want to read wisdom from a cannam@95: portion of a larger file) is @code{fftw_import_wisdom_from_file}. This cannam@95: reads wisdom from the current position in @code{input_file} (which cannam@95: should be open with read permission); upon exit, the file remains cannam@95: open, but the position of the read pointer is unspecified. cannam@95: cannam@95: @code{fftw_import_wisdom_from_string} reads wisdom from the cannam@95: @code{NULL}-terminated string @code{input_string}. cannam@95: cannam@95: @code{fftw_import_system_wisdom} reads wisdom from an cannam@95: implementation-defined standard file (@code{/etc/fftw/wisdom} on Unix cannam@95: and GNU systems). cannam@95: @cindex wisdom, system-wide cannam@95: cannam@95: cannam@95: The return value of these import routines is @code{1} if the wisdom was cannam@95: read successfully and @code{0} otherwise. Note that, in all of these cannam@95: functions, any data in the input stream past the end of the wisdom data cannam@95: is simply ignored. cannam@95: cannam@95: @c =========> cannam@95: @node Forgetting Wisdom, Wisdom Utilities, Wisdom Import, Wisdom cannam@95: @subsection Forgetting Wisdom cannam@95: cannam@95: @example cannam@95: void fftw_forget_wisdom(void); cannam@95: @end example cannam@95: @findex fftw_forget_wisdom cannam@95: cannam@95: Calling @code{fftw_forget_wisdom} causes all accumulated @code{wisdom} cannam@95: to be discarded and its associated memory to be freed. (New cannam@95: @code{wisdom} can still be gathered subsequently, however.) cannam@95: cannam@95: @c =========> cannam@95: @node Wisdom Utilities, , Forgetting Wisdom, Wisdom cannam@95: @subsection Wisdom Utilities cannam@95: cannam@95: FFTW includes two standalone utility programs that deal with wisdom. We cannam@95: merely summarize them here, since they come with their own @code{man} cannam@95: pages for Unix and GNU systems (with HTML versions on our web site). cannam@95: cannam@95: The first program is @code{fftw-wisdom} (or @code{fftwf-wisdom} in cannam@95: single precision, etcetera), which can be used to create a wisdom file cannam@95: containing plans for any of the transform sizes and types supported by cannam@95: FFTW. It is preferable to create wisdom directly from your executable cannam@95: (@pxref{Caveats in Using Wisdom}), but this program is useful for cannam@95: creating global wisdom files for @code{fftw_import_system_wisdom}. cannam@95: @cindex fftw-wisdom utility cannam@95: cannam@95: cannam@95: The second program is @code{fftw-wisdom-to-conf}, which takes a wisdom cannam@95: file as input and produces a @dfn{configuration routine} as output. The cannam@95: latter is a C subroutine that you can compile and link into your cannam@95: program, replacing a routine of the same name in the FFTW library, that cannam@95: determines which parts of FFTW are callable by your program. cannam@95: @code{fftw-wisdom-to-conf} produces a configuration routine that links cannam@95: to only those parts of FFTW needed by the saved plans in the wisdom, cannam@95: greatly reducing the size of statically linked executables (which should cannam@95: only attempt to create plans corresponding to those in the wisdom, cannam@95: however). cannam@95: @cindex fftw-wisdom-to-conf utility cannam@95: @cindex configuration routines cannam@95: cannam@95: @c ------------------------------------------------------------ cannam@95: @node What FFTW Really Computes, , Wisdom, FFTW Reference cannam@95: @section What FFTW Really Computes cannam@95: cannam@95: In this section, we provide precise mathematical definitions for the cannam@95: transforms that FFTW computes. These transform definitions are fairly cannam@95: standard, but some authors follow slightly different conventions for the cannam@95: normalization of the transform (the constant factor in front) and the cannam@95: sign of the complex exponent. We begin by presenting the cannam@95: one-dimensional (1d) transform definitions, and then give the cannam@95: straightforward extension to multi-dimensional transforms. cannam@95: cannam@95: @menu cannam@95: * The 1d Discrete Fourier Transform (DFT):: cannam@95: * The 1d Real-data DFT:: cannam@95: * 1d Real-even DFTs (DCTs):: cannam@95: * 1d Real-odd DFTs (DSTs):: cannam@95: * 1d Discrete Hartley Transforms (DHTs):: cannam@95: * Multi-dimensional Transforms:: cannam@95: @end menu cannam@95: cannam@95: @c =========> cannam@95: @node The 1d Discrete Fourier Transform (DFT), The 1d Real-data DFT, What FFTW Really Computes, What FFTW Really Computes cannam@95: @subsection The 1d Discrete Fourier Transform (DFT) cannam@95: cannam@95: @cindex discrete Fourier transform cannam@95: @cindex DFT cannam@95: The forward (@code{FFTW_FORWARD}) discrete Fourier transform (DFT) of a cannam@95: 1d complex array @math{X} of size @math{n} computes an array @math{Y}, cannam@95: where: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = \sum_{j = 0}^{n - 1} X_j e^{-2\pi j k \sqrt{-1}/n} \ . cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(-2 pi j k sqrt(-1)/n) . cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: The backward (@code{FFTW_BACKWARD}) DFT computes: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = \sum_{j = 0}^{n - 1} X_j e^{2\pi j k \sqrt{-1}/n} \ . cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(2 pi j k sqrt(-1)/n) . cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: cannam@95: @cindex normalization cannam@95: FFTW computes an unnormalized transform, in that there is no coefficient cannam@95: in front of the summation in the DFT. In other words, applying the cannam@95: forward and then the backward transform will multiply the input by cannam@95: @math{n}. cannam@95: cannam@95: @cindex frequency cannam@95: From above, an @code{FFTW_FORWARD} transform corresponds to a sign of cannam@95: @math{-1} in the exponent of the DFT. Note also that we use the cannam@95: standard ``in-order'' output ordering---the @math{k}-th output cannam@95: corresponds to the frequency @math{k/n} (or @math{k/T}, where @math{T} cannam@95: is your total sampling period). For those who like to think in terms of cannam@95: positive and negative frequencies, this means that the positive cannam@95: frequencies are stored in the first half of the output and the negative cannam@95: frequencies are stored in backwards order in the second half of the cannam@95: output. (The frequency @math{-k/n} is the same as the frequency cannam@95: @math{(n-k)/n}.) cannam@95: cannam@95: @c =========> cannam@95: @node The 1d Real-data DFT, 1d Real-even DFTs (DCTs), The 1d Discrete Fourier Transform (DFT), What FFTW Really Computes cannam@95: @subsection The 1d Real-data DFT cannam@95: cannam@95: The real-input (r2c) DFT in FFTW computes the @emph{forward} transform cannam@95: @math{Y} of the size @code{n} real array @math{X}, exactly as defined cannam@95: above, i.e. cannam@95: @tex cannam@95: $$ cannam@95: Y_k = \sum_{j = 0}^{n - 1} X_j e^{-2\pi j k \sqrt{-1}/n} \ . cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(-2 pi j k sqrt(-1)/n) . cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: This output array @math{Y} can easily be shown to possess the cannam@95: ``Hermitian'' symmetry cannam@95: @cindex Hermitian cannam@95: @tex cannam@95: $Y_k = Y_{n-k}^*$, cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[k] = Y[n-k]*, cannam@95: @end ifinfo cannam@95: @html cannam@95: Yk = Yn-k*, cannam@95: @end html cannam@95: where we take @math{Y} to be periodic so that cannam@95: @tex cannam@95: $Y_n = Y_0$. cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[n] = Y[0]. cannam@95: @end ifinfo cannam@95: @html cannam@95: Yn = Y0. cannam@95: @end html cannam@95: cannam@95: As a result of this symmetry, half of the output @math{Y} is redundant cannam@95: (being the complex conjugate of the other half), and so the 1d r2c cannam@95: transforms only output elements @math{0}@dots{}@math{n/2} of @math{Y} cannam@95: (@math{n/2+1} complex numbers), where the division by @math{2} is cannam@95: rounded down. cannam@95: cannam@95: Moreover, the Hermitian symmetry implies that cannam@95: @tex cannam@95: $Y_0$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[0] cannam@95: @end ifinfo cannam@95: @html cannam@95: Y0 cannam@95: @end html cannam@95: and, if @math{n} is even, the cannam@95: @tex cannam@95: $Y_{n/2}$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[n/2] cannam@95: @end ifinfo cannam@95: @html cannam@95: Yn/2 cannam@95: @end html cannam@95: element, are purely real. So, for the @code{R2HC} r2r transform, these cannam@95: elements are not stored in the halfcomplex output format. cannam@95: @cindex r2r cannam@95: @ctindex R2HC cannam@95: @cindex halfcomplex format cannam@95: cannam@95: cannam@95: The c2r and @code{H2RC} r2r transforms compute the backward DFT of the cannam@95: @emph{complex} array @math{X} with Hermitian symmetry, stored in the cannam@95: r2c/@code{R2HC} output formats, respectively, where the backward cannam@95: transform is defined exactly as for the complex case: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = \sum_{j = 0}^{n - 1} X_j e^{2\pi j k \sqrt{-1}/n} \ . cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(2 pi j k sqrt(-1)/n) . cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: The outputs @code{Y} of this transform can easily be seen to be purely cannam@95: real, and are stored as an array of real numbers. cannam@95: cannam@95: @cindex normalization cannam@95: Like FFTW's complex DFT, these transforms are unnormalized. In other cannam@95: words, applying the real-to-complex (forward) and then the cannam@95: complex-to-real (backward) transform will multiply the input by cannam@95: @math{n}. cannam@95: cannam@95: @c =========> cannam@95: @node 1d Real-even DFTs (DCTs), 1d Real-odd DFTs (DSTs), The 1d Real-data DFT, What FFTW Really Computes cannam@95: @subsection 1d Real-even DFTs (DCTs) cannam@95: cannam@95: The Real-even symmetry DFTs in FFTW are exactly equivalent to the unnormalized cannam@95: forward (and backward) DFTs as defined above, where the input array cannam@95: @math{X} of length @math{N} is purely real and is also @dfn{even} symmetry. In cannam@95: this case, the output array is likewise real and even symmetry. cannam@95: @cindex real-even DFT cannam@95: @cindex REDFT cannam@95: cannam@95: cannam@95: @ctindex REDFT00 cannam@95: For the case of @code{REDFT00}, this even symmetry means that cannam@95: @tex cannam@95: $X_j = X_{N-j}$, cannam@95: @end tex cannam@95: @ifinfo cannam@95: X[j] = X[N-j], cannam@95: @end ifinfo cannam@95: @html cannam@95: Xj = XN-j, cannam@95: @end html cannam@95: where we take @math{X} to be periodic so that cannam@95: @tex cannam@95: $X_N = X_0$. cannam@95: @end tex cannam@95: @ifinfo cannam@95: X[N] = X[0]. cannam@95: @end ifinfo cannam@95: @html cannam@95: XN = X0. cannam@95: @end html cannam@95: Because of this redundancy, only the first @math{n} real numbers are cannam@95: actually stored, where @math{N = 2(n-1)}. cannam@95: cannam@95: The proper definition of even symmetry for @code{REDFT10}, cannam@95: @code{REDFT01}, and @code{REDFT11} transforms is somewhat more intricate cannam@95: because of the shifts by @math{1/2} of the input and/or output, although cannam@95: the corresponding boundary conditions are given in @ref{Real even/odd cannam@95: DFTs (cosine/sine transforms)}. Because of the even symmetry, however, cannam@95: the sine terms in the DFT all cancel and the remaining cosine terms are cannam@95: written explicitly below. This formulation often leads people to call cannam@95: such a transform a @dfn{discrete cosine transform} (DCT), although it is cannam@95: really just a special case of the DFT. cannam@95: @cindex discrete cosine transform cannam@95: @cindex DCT cannam@95: cannam@95: cannam@95: In each of the definitions below, we transform a real array @math{X} of cannam@95: length @math{n} to a real array @math{Y} of length @math{n}: cannam@95: cannam@95: @subsubheading REDFT00 (DCT-I) cannam@95: @ctindex REDFT00 cannam@95: An @code{REDFT00} transform (type-I DCT) in FFTW is defined by: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = X_0 + (-1)^k X_{n-1} cannam@95: + 2 \sum_{j=1}^{n-2} X_j \cos [ \pi j k / (n-1)]. cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[k] = X[0] + (-1)^k X[n-1] + 2 (sum for j = 1 to n-2 of X[j] cos(pi jk /(n-1))). cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: Note that this transform is not defined for @math{n=1}. For @math{n=2}, cannam@95: the summation term above is dropped as you might expect. cannam@95: cannam@95: @subsubheading REDFT10 (DCT-II) cannam@95: @ctindex REDFT10 cannam@95: An @code{REDFT10} transform (type-II DCT, sometimes called ``the'' DCT) in FFTW is defined by: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = 2 \sum_{j=0}^{n-1} X_j \cos [\pi (j+1/2) k / n]. cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[k] = 2 (sum for j = 0 to n-1 of X[j] cos(pi (j+1/2) k / n)). cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: cannam@95: @subsubheading REDFT01 (DCT-III) cannam@95: @ctindex REDFT01 cannam@95: An @code{REDFT01} transform (type-III DCT) in FFTW is defined by: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = X_0 + 2 \sum_{j=1}^{n-1} X_j \cos [\pi j (k+1/2) / n]. cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[k] = X[0] + 2 (sum for j = 1 to n-1 of X[j] cos(pi j (k+1/2) / n)). cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: In the case of @math{n=1}, this reduces to cannam@95: @tex cannam@95: $Y_0 = X_0$. cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[0] = X[0]. cannam@95: @end ifinfo cannam@95: @html cannam@95: Y0 = X0. cannam@95: @end html cannam@95: Up to a scale factor (see below), this is the inverse of @code{REDFT10} (``the'' DCT), and so the @code{REDFT01} (DCT-III) is sometimes called the ``IDCT''. cannam@95: @cindex IDCT cannam@95: cannam@95: @subsubheading REDFT11 (DCT-IV) cannam@95: @ctindex REDFT11 cannam@95: An @code{REDFT11} transform (type-IV DCT) in FFTW is defined by: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = 2 \sum_{j=0}^{n-1} X_j \cos [\pi (j+1/2) (k+1/2) / n]. cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[k] = 2 (sum for j = 0 to n-1 of X[j] cos(pi (j+1/2) (k+1/2) / n)). cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: cannam@95: @subsubheading Inverses and Normalization cannam@95: cannam@95: These definitions correspond directly to the unnormalized DFTs used cannam@95: elsewhere in FFTW (hence the factors of @math{2} in front of the cannam@95: summations). The unnormalized inverse of @code{REDFT00} is cannam@95: @code{REDFT00}, of @code{REDFT10} is @code{REDFT01} and vice versa, and cannam@95: of @code{REDFT11} is @code{REDFT11}. Each unnormalized inverse results cannam@95: in the original array multiplied by @math{N}, where @math{N} is the cannam@95: @emph{logical} DFT size. For @code{REDFT00}, @math{N=2(n-1)} (note that cannam@95: @math{n=1} is not defined); otherwise, @math{N=2n}. cannam@95: @cindex normalization cannam@95: cannam@95: cannam@95: In defining the discrete cosine transform, some authors also include cannam@95: additional factors of cannam@95: @ifinfo cannam@95: sqrt(2) cannam@95: @end ifinfo cannam@95: @html cannam@95: √2 cannam@95: @end html cannam@95: @tex cannam@95: $\sqrt{2}$ cannam@95: @end tex cannam@95: (or its inverse) multiplying selected inputs and/or outputs. This is a cannam@95: mostly cosmetic change that makes the transform orthogonal, but cannam@95: sacrifices the direct equivalence to a symmetric DFT. cannam@95: cannam@95: @c =========> cannam@95: @node 1d Real-odd DFTs (DSTs), 1d Discrete Hartley Transforms (DHTs), 1d Real-even DFTs (DCTs), What FFTW Really Computes cannam@95: @subsection 1d Real-odd DFTs (DSTs) cannam@95: cannam@95: The Real-odd symmetry DFTs in FFTW are exactly equivalent to the unnormalized cannam@95: forward (and backward) DFTs as defined above, where the input array cannam@95: @math{X} of length @math{N} is purely real and is also @dfn{odd} symmetry. In cannam@95: this case, the output is odd symmetry and purely imaginary. cannam@95: @cindex real-odd DFT cannam@95: @cindex RODFT cannam@95: cannam@95: cannam@95: @ctindex RODFT00 cannam@95: For the case of @code{RODFT00}, this odd symmetry means that cannam@95: @tex cannam@95: $X_j = -X_{N-j}$, cannam@95: @end tex cannam@95: @ifinfo cannam@95: X[j] = -X[N-j], cannam@95: @end ifinfo cannam@95: @html cannam@95: Xj = -XN-j, cannam@95: @end html cannam@95: where we take @math{X} to be periodic so that cannam@95: @tex cannam@95: $X_N = X_0$. cannam@95: @end tex cannam@95: @ifinfo cannam@95: X[N] = X[0]. cannam@95: @end ifinfo cannam@95: @html cannam@95: XN = X0. cannam@95: @end html cannam@95: Because of this redundancy, only the first @math{n} real numbers cannam@95: starting at @math{j=1} are actually stored (the @math{j=0} element is cannam@95: zero), where @math{N = 2(n+1)}. cannam@95: cannam@95: The proper definition of odd symmetry for @code{RODFT10}, cannam@95: @code{RODFT01}, and @code{RODFT11} transforms is somewhat more intricate cannam@95: because of the shifts by @math{1/2} of the input and/or output, although cannam@95: the corresponding boundary conditions are given in @ref{Real even/odd cannam@95: DFTs (cosine/sine transforms)}. Because of the odd symmetry, however, cannam@95: the cosine terms in the DFT all cancel and the remaining sine terms are cannam@95: written explicitly below. This formulation often leads people to call cannam@95: such a transform a @dfn{discrete sine transform} (DST), although it is cannam@95: really just a special case of the DFT. cannam@95: @cindex discrete sine transform cannam@95: @cindex DST cannam@95: cannam@95: cannam@95: In each of the definitions below, we transform a real array @math{X} of cannam@95: length @math{n} to a real array @math{Y} of length @math{n}: cannam@95: cannam@95: @subsubheading RODFT00 (DST-I) cannam@95: @ctindex RODFT00 cannam@95: An @code{RODFT00} transform (type-I DST) in FFTW is defined by: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [ \pi (j+1) (k+1) / (n+1)]. cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1)(k+1) / (n+1))). cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: cannam@95: @subsubheading RODFT10 (DST-II) cannam@95: @ctindex RODFT10 cannam@95: An @code{RODFT10} transform (type-II DST) in FFTW is defined by: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [\pi (j+1/2) (k+1) / n]. cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1/2) (k+1) / n)). cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: cannam@95: @subsubheading RODFT01 (DST-III) cannam@95: @ctindex RODFT01 cannam@95: An @code{RODFT01} transform (type-III DST) in FFTW is defined by: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = (-1)^k X_{n-1} + 2 \sum_{j=0}^{n-2} X_j \sin [\pi (j+1) (k+1/2) / n]. cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[k] = (-1)^k X[n-1] + 2 (sum for j = 0 to n-2 of X[j] sin(pi (j+1) (k+1/2) / n)). cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: In the case of @math{n=1}, this reduces to cannam@95: @tex cannam@95: $Y_0 = X_0$. cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[0] = X[0]. cannam@95: @end ifinfo cannam@95: @html cannam@95: Y0 = X0. cannam@95: @end html cannam@95: cannam@95: @subsubheading RODFT11 (DST-IV) cannam@95: @ctindex RODFT11 cannam@95: An @code{RODFT11} transform (type-IV DST) in FFTW is defined by: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [\pi (j+1/2) (k+1/2) / n]. cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1/2) (k+1/2) / n)). cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: cannam@95: @subsubheading Inverses and Normalization cannam@95: cannam@95: These definitions correspond directly to the unnormalized DFTs used cannam@95: elsewhere in FFTW (hence the factors of @math{2} in front of the cannam@95: summations). The unnormalized inverse of @code{RODFT00} is cannam@95: @code{RODFT00}, of @code{RODFT10} is @code{RODFT01} and vice versa, and cannam@95: of @code{RODFT11} is @code{RODFT11}. Each unnormalized inverse results cannam@95: in the original array multiplied by @math{N}, where @math{N} is the cannam@95: @emph{logical} DFT size. For @code{RODFT00}, @math{N=2(n+1)}; cannam@95: otherwise, @math{N=2n}. cannam@95: @cindex normalization cannam@95: cannam@95: cannam@95: In defining the discrete sine transform, some authors also include cannam@95: additional factors of cannam@95: @ifinfo cannam@95: sqrt(2) cannam@95: @end ifinfo cannam@95: @html cannam@95: √2 cannam@95: @end html cannam@95: @tex cannam@95: $\sqrt{2}$ cannam@95: @end tex cannam@95: (or its inverse) multiplying selected inputs and/or outputs. This is a cannam@95: mostly cosmetic change that makes the transform orthogonal, but cannam@95: sacrifices the direct equivalence to an antisymmetric DFT. cannam@95: cannam@95: @c =========> cannam@95: @node 1d Discrete Hartley Transforms (DHTs), Multi-dimensional Transforms, 1d Real-odd DFTs (DSTs), What FFTW Really Computes cannam@95: @subsection 1d Discrete Hartley Transforms (DHTs) cannam@95: cannam@95: @cindex discrete Hartley transform cannam@95: @cindex DHT cannam@95: The discrete Hartley transform (DHT) of a 1d real array @math{X} of size cannam@95: @math{n} computes a real array @math{Y} of the same size, where: cannam@95: @tex cannam@95: $$ cannam@95: Y_k = \sum_{j = 0}^{n - 1} X_j [ \cos(2\pi j k / n) + \sin(2\pi j k / n)]. cannam@95: $$ cannam@95: @end tex cannam@95: @ifinfo cannam@95: @center Y[k] = sum for j = 0 to (n - 1) of X[j] * [cos(2 pi j k / n) + sin(2 pi j k / n)]. cannam@95: @end ifinfo cannam@95: @html cannam@95:
.
cannam@95: @end html cannam@95: cannam@95: @cindex normalization cannam@95: FFTW computes an unnormalized transform, in that there is no coefficient cannam@95: in front of the summation in the DHT. In other words, applying the cannam@95: transform twice (the DHT is its own inverse) will multiply the input by cannam@95: @math{n}. cannam@95: cannam@95: @c =========> cannam@95: @node Multi-dimensional Transforms, , 1d Discrete Hartley Transforms (DHTs), What FFTW Really Computes cannam@95: @subsection Multi-dimensional Transforms cannam@95: cannam@95: The multi-dimensional transforms of FFTW, in general, compute simply the cannam@95: separable product of the given 1d transform along each dimension of the cannam@95: array. Since each of these transforms is unnormalized, computing the cannam@95: forward followed by the backward/inverse multi-dimensional transform cannam@95: will result in the original array scaled by the product of the cannam@95: normalization factors for each dimension (e.g. the product of the cannam@95: dimension sizes, for a multi-dimensional DFT). cannam@95: cannam@95: @tex cannam@95: As an explicit example, consider the following exact mathematical cannam@95: definition of our multi-dimensional DFT. Let $X$ be a $d$-dimensional cannam@95: complex array whose elements are $X[j_1, j_2, \ldots, j_d]$, where $0 cannam@95: \leq j_s < n_s$ for all~$s \in \{ 1, 2, \ldots, d \}$. Let also cannam@95: $\omega_s = e^{2\pi \sqrt{-1}/n_s}$, for all ~$s \in \{ 1, 2, \ldots, d cannam@95: \}$. cannam@95: cannam@95: The forward transform computes a complex array~$Y$, whose cannam@95: structure is the same as that of~$X$, defined by cannam@95: cannam@95: $$ cannam@95: Y[k_1, k_2, \ldots, k_d] = cannam@95: \sum_{j_1 = 0}^{n_1 - 1} cannam@95: \sum_{j_2 = 0}^{n_2 - 1} cannam@95: \cdots cannam@95: \sum_{j_d = 0}^{n_d - 1} cannam@95: X[j_1, j_2, \ldots, j_d] cannam@95: \omega_1^{-j_1 k_1} cannam@95: \omega_2^{-j_2 k_2} cannam@95: \cdots cannam@95: \omega_d^{-j_d k_d} \ . cannam@95: $$ cannam@95: cannam@95: The backward transform computes cannam@95: $$ cannam@95: Y[k_1, k_2, \ldots, k_d] = cannam@95: \sum_{j_1 = 0}^{n_1 - 1} cannam@95: \sum_{j_2 = 0}^{n_2 - 1} cannam@95: \cdots cannam@95: \sum_{j_d = 0}^{n_d - 1} cannam@95: X[j_1, j_2, \ldots, j_d] cannam@95: \omega_1^{j_1 k_1} cannam@95: \omega_2^{j_2 k_2} cannam@95: \cdots cannam@95: \omega_d^{j_d k_d} \ . cannam@95: $$ cannam@95: cannam@95: Computing the forward transform followed by the backward transform cannam@95: will multiply the array by $\prod_{s=1}^{d} n_d$. cannam@95: @end tex cannam@95: cannam@95: @cindex r2c cannam@95: The definition of FFTW's multi-dimensional DFT of real data (r2c) cannam@95: deserves special attention. In this case, we logically compute the full cannam@95: multi-dimensional DFT of the input data; since the input data are purely cannam@95: real, the output data have the Hermitian symmetry and therefore only one cannam@95: non-redundant half need be stored. More specifically, for an @ndims multi-dimensional real-input DFT, the full (logical) complex output array cannam@95: @tex cannam@95: $Y[k_0, k_1, \ldots, k_{d-1}]$ cannam@95: @end tex cannam@95: @html cannam@95: Y[k0, k1, ..., cannam@95: kd-1] cannam@95: @end html cannam@95: @ifinfo cannam@95: Y[k[0], k[1], ..., k[d-1]] cannam@95: @end ifinfo cannam@95: has the symmetry: cannam@95: @tex cannam@95: $$ cannam@95: Y[k_0, k_1, \ldots, k_{d-1}] = Y[n_0 - k_0, n_1 - k_1, \ldots, n_{d-1} - k_{d-1}]^* cannam@95: $$ cannam@95: @end tex cannam@95: @html cannam@95: Y[k0, k1, ..., cannam@95: kd-1] = Y[n0 - cannam@95: k0, n1 - k1, ..., cannam@95: nd-1 - kd-1]* cannam@95: @end html cannam@95: @ifinfo cannam@95: Y[k[0], k[1], ..., k[d-1]] = Y[n[0] - k[0], n[1] - k[1], ..., n[d-1] - k[d-1]]* cannam@95: @end ifinfo cannam@95: (where each dimension is periodic). Because of this symmetry, we only cannam@95: store the cannam@95: @tex cannam@95: $k_{d-1} = 0 \cdots n_{d-1}/2$ cannam@95: @end tex cannam@95: @html cannam@95: kd-1 = 0...nd-1/2+1 cannam@95: @end html cannam@95: @ifinfo cannam@95: k[d-1] = 0...n[d-1]/2 cannam@95: @end ifinfo cannam@95: elements of the @emph{last} dimension (division by @math{2} is rounded cannam@95: down). (We could instead have cut any other dimension in half, but the cannam@95: last dimension proved computationally convenient.) This results in the cannam@95: peculiar array format described in more detail by @ref{Real-data DFT cannam@95: Array Format}. cannam@95: cannam@95: The multi-dimensional c2r transform is simply the unnormalized inverse cannam@95: of the r2c transform. i.e. it is the same as FFTW's complex backward cannam@95: multi-dimensional DFT, operating on a Hermitian input array in the cannam@95: peculiar format mentioned above and outputting a real array (since the cannam@95: DFT output is purely real). cannam@95: cannam@95: We should remind the user that the separable product of 1d transforms cannam@95: along each dimension, as computed by FFTW, is not always the same thing cannam@95: as the usual multi-dimensional transform. A multi-dimensional cannam@95: @code{R2HC} (or @code{HC2R}) transform is not identical to the cannam@95: multi-dimensional DFT, requiring some post-processing to combine the cannam@95: requisite real and imaginary parts, as was described in @ref{The cannam@95: Halfcomplex-format DFT}. Likewise, FFTW's multidimensional cannam@95: @code{FFTW_DHT} r2r transform is not the same thing as the logical cannam@95: multi-dimensional discrete Hartley transform defined in the literature, cannam@95: as discussed in @ref{The Discrete Hartley Transform}. cannam@95: