annotate src/fftw-3.3.8/doc/reference.texi @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents bd3cc4d1df30
children
rev   line source
cannam@167 1 @node FFTW Reference, Multi-threaded FFTW, Other Important Topics, Top
cannam@167 2 @chapter FFTW Reference
cannam@167 3
cannam@167 4 This chapter provides a complete reference for all sequential (i.e.,
cannam@167 5 one-processor) FFTW functions. Parallel transforms are described in
cannam@167 6 later chapters.
cannam@167 7
cannam@167 8 @menu
cannam@167 9 * Data Types and Files::
cannam@167 10 * Using Plans::
cannam@167 11 * Basic Interface::
cannam@167 12 * Advanced Interface::
cannam@167 13 * Guru Interface::
cannam@167 14 * New-array Execute Functions::
cannam@167 15 * Wisdom::
cannam@167 16 * What FFTW Really Computes::
cannam@167 17 @end menu
cannam@167 18
cannam@167 19 @c ------------------------------------------------------------
cannam@167 20 @node Data Types and Files, Using Plans, FFTW Reference, FFTW Reference
cannam@167 21 @section Data Types and Files
cannam@167 22
cannam@167 23 All programs using FFTW should include its header file:
cannam@167 24
cannam@167 25 @example
cannam@167 26 #include <fftw3.h>
cannam@167 27 @end example
cannam@167 28
cannam@167 29 You must also link to the FFTW library. On Unix, this
cannam@167 30 means adding @code{-lfftw3 -lm} at the @emph{end} of the link command.
cannam@167 31
cannam@167 32 @menu
cannam@167 33 * Complex numbers::
cannam@167 34 * Precision::
cannam@167 35 * Memory Allocation::
cannam@167 36 @end menu
cannam@167 37
cannam@167 38 @c =========>
cannam@167 39 @node Complex numbers, Precision, Data Types and Files, Data Types and Files
cannam@167 40 @subsection Complex numbers
cannam@167 41
cannam@167 42 The default FFTW interface uses @code{double} precision for all
cannam@167 43 floating-point numbers, and defines a @code{fftw_complex} type to hold
cannam@167 44 complex numbers as:
cannam@167 45
cannam@167 46 @example
cannam@167 47 typedef double fftw_complex[2];
cannam@167 48 @end example
cannam@167 49 @tindex fftw_complex
cannam@167 50
cannam@167 51 Here, the @code{[0]} element holds the real part and the @code{[1]}
cannam@167 52 element holds the imaginary part.
cannam@167 53
cannam@167 54 Alternatively, if you have a C compiler (such as @code{gcc}) that
cannam@167 55 supports the C99 revision of the ANSI C standard, you can use C's new
cannam@167 56 native complex type (which is binary-compatible with the typedef above).
cannam@167 57 In particular, if you @code{#include <complex.h>} @emph{before}
cannam@167 58 @code{<fftw3.h>}, then @code{fftw_complex} is defined to be the native
cannam@167 59 complex type and you can manipulate it with ordinary arithmetic
cannam@167 60 (e.g. @code{x = y * (3+4*I)}, where @code{x} and @code{y} are
cannam@167 61 @code{fftw_complex} and @code{I} is the standard symbol for the
cannam@167 62 imaginary unit);
cannam@167 63 @cindex C99
cannam@167 64
cannam@167 65
cannam@167 66 C++ has its own @code{complex<T>} template class, defined in the
cannam@167 67 standard @code{<complex>} header file. Reportedly, the C++ standards
cannam@167 68 committee has recently agreed to mandate that the storage format used
cannam@167 69 for this type be binary-compatible with the C99 type, i.e. an array
cannam@167 70 @code{T[2]} with consecutive real @code{[0]} and imaginary @code{[1]}
cannam@167 71 parts. (See report
cannam@167 72 @uref{http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2002/n1388.pdf
cannam@167 73 WG21/N1388}.) Although not part of the official standard as of this
cannam@167 74 writing, the proposal stated that: ``This solution has been tested with
cannam@167 75 all current major implementations of the standard library and shown to
cannam@167 76 be working.'' To the extent that this is true, if you have a variable
cannam@167 77 @code{complex<double> *x}, you can pass it directly to FFTW via
cannam@167 78 @code{reinterpret_cast<fftw_complex*>(x)}.
cannam@167 79 @cindex C++
cannam@167 80 @cindex portability
cannam@167 81
cannam@167 82 @c =========>
cannam@167 83 @node Precision, Memory Allocation, Complex numbers, Data Types and Files
cannam@167 84 @subsection Precision
cannam@167 85 @cindex precision
cannam@167 86
cannam@167 87 You can install single and long-double precision versions of FFTW,
cannam@167 88 which replace @code{double} with @code{float} and @code{long double},
cannam@167 89 respectively (@pxref{Installation and Customization}). To use these
cannam@167 90 interfaces, you:
cannam@167 91
cannam@167 92 @itemize @bullet
cannam@167 93
cannam@167 94 @item
cannam@167 95 Link to the single/long-double libraries; on Unix, @code{-lfftw3f} or
cannam@167 96 @code{-lfftw3l} instead of (or in addition to) @code{-lfftw3}. (You
cannam@167 97 can link to the different-precision libraries simultaneously.)
cannam@167 98
cannam@167 99 @item
cannam@167 100 Include the @emph{same} @code{<fftw3.h>} header file.
cannam@167 101
cannam@167 102 @item
cannam@167 103 Replace all lowercase instances of @samp{fftw_} with @samp{fftwf_} or
cannam@167 104 @samp{fftwl_} for single or long-double precision, respectively.
cannam@167 105 (@code{fftw_complex} becomes @code{fftwf_complex}, @code{fftw_execute}
cannam@167 106 becomes @code{fftwf_execute}, etcetera.)
cannam@167 107
cannam@167 108 @item
cannam@167 109 Uppercase names, i.e. names beginning with @samp{FFTW_}, remain the
cannam@167 110 same.
cannam@167 111
cannam@167 112 @item
cannam@167 113 Replace @code{double} with @code{float} or @code{long double} for
cannam@167 114 subroutine parameters.
cannam@167 115
cannam@167 116 @end itemize
cannam@167 117
cannam@167 118 Depending upon your compiler and/or hardware, @code{long double} may not
cannam@167 119 be any more precise than @code{double} (or may not be supported at all,
cannam@167 120 although it is standard in C99).
cannam@167 121 @cindex C99
cannam@167 122
cannam@167 123
cannam@167 124 We also support using the nonstandard @code{__float128}
cannam@167 125 quadruple-precision type provided by recent versions of @code{gcc} on
cannam@167 126 32- and 64-bit x86 hardware (@pxref{Installation and Customization}).
cannam@167 127 To use this type, link with @code{-lfftw3q -lquadmath -lm} (the
cannam@167 128 @code{libquadmath} library provided by @code{gcc} is needed for
cannam@167 129 quadruple-precision trigonometric functions) and use @samp{fftwq_}
cannam@167 130 identifiers.
cannam@167 131
cannam@167 132 @c =========>
cannam@167 133 @node Memory Allocation, , Precision, Data Types and Files
cannam@167 134 @subsection Memory Allocation
cannam@167 135
cannam@167 136 @example
cannam@167 137 void *fftw_malloc(size_t n);
cannam@167 138 void fftw_free(void *p);
cannam@167 139 @end example
cannam@167 140 @findex fftw_malloc
cannam@167 141 @findex fftw_free
cannam@167 142
cannam@167 143 These are functions that behave identically to @code{malloc} and
cannam@167 144 @code{free}, except that they guarantee that the returned pointer obeys
cannam@167 145 any special alignment restrictions imposed by any algorithm in FFTW
cannam@167 146 (e.g. for SIMD acceleration). @xref{SIMD alignment and fftw_malloc}.
cannam@167 147 @cindex alignment
cannam@167 148
cannam@167 149
cannam@167 150 Data allocated by @code{fftw_malloc} @emph{must} be deallocated by
cannam@167 151 @code{fftw_free} and not by the ordinary @code{free}.
cannam@167 152
cannam@167 153 These routines simply call through to your operating system's
cannam@167 154 @code{malloc} or, if necessary, its aligned equivalent
cannam@167 155 (e.g. @code{memalign}), so you normally need not worry about any
cannam@167 156 significant time or space overhead. You are @emph{not required} to use
cannam@167 157 them to allocate your data, but we strongly recommend it.
cannam@167 158
cannam@167 159 Note: in C++, just as with ordinary @code{malloc}, you must typecast
cannam@167 160 the output of @code{fftw_malloc} to whatever pointer type you are
cannam@167 161 allocating.
cannam@167 162 @cindex C++
cannam@167 163
cannam@167 164
cannam@167 165 We also provide the following two convenience functions to allocate
cannam@167 166 real and complex arrays with @code{n} elements, which are equivalent
cannam@167 167 to @code{(double *) fftw_malloc(sizeof(double) * n)} and
cannam@167 168 @code{(fftw_complex *) fftw_malloc(sizeof(fftw_complex) * n)},
cannam@167 169 respectively:
cannam@167 170
cannam@167 171 @example
cannam@167 172 double *fftw_alloc_real(size_t n);
cannam@167 173 fftw_complex *fftw_alloc_complex(size_t n);
cannam@167 174 @end example
cannam@167 175 @findex fftw_alloc_real
cannam@167 176 @findex fftw_alloc_complex
cannam@167 177
cannam@167 178 The equivalent functions in other precisions allocate arrays of @code{n}
cannam@167 179 elements in that precision. e.g. @code{fftwf_alloc_real(n)} is
cannam@167 180 equivalent to @code{(float *) fftwf_malloc(sizeof(float) * n)}.
cannam@167 181 @cindex precision
cannam@167 182
cannam@167 183 @c ------------------------------------------------------------
cannam@167 184 @node Using Plans, Basic Interface, Data Types and Files, FFTW Reference
cannam@167 185 @section Using Plans
cannam@167 186
cannam@167 187 Plans for all transform types in FFTW are stored as type
cannam@167 188 @code{fftw_plan} (an opaque pointer type), and are created by one of the
cannam@167 189 various planning routines described in the following sections.
cannam@167 190 @tindex fftw_plan
cannam@167 191 An @code{fftw_plan} contains all information necessary to compute the
cannam@167 192 transform, including the pointers to the input and output arrays.
cannam@167 193
cannam@167 194 @example
cannam@167 195 void fftw_execute(const fftw_plan plan);
cannam@167 196 @end example
cannam@167 197 @findex fftw_execute
cannam@167 198
cannam@167 199 This executes the @code{plan}, to compute the corresponding transform on
cannam@167 200 the arrays for which it was planned (which must still exist). The plan
cannam@167 201 is not modified, and @code{fftw_execute} can be called as many times as
cannam@167 202 desired.
cannam@167 203
cannam@167 204 To apply a given plan to a different array, you can use the new-array execute
cannam@167 205 interface. @xref{New-array Execute Functions}.
cannam@167 206
cannam@167 207 @code{fftw_execute} (and equivalents) is the only function in FFTW
cannam@167 208 guaranteed to be thread-safe; see @ref{Thread safety}.
cannam@167 209
cannam@167 210 This function:
cannam@167 211 @example
cannam@167 212 void fftw_destroy_plan(fftw_plan plan);
cannam@167 213 @end example
cannam@167 214 @findex fftw_destroy_plan
cannam@167 215 deallocates the @code{plan} and all its associated data.
cannam@167 216
cannam@167 217 FFTW's planner saves some other persistent data, such as the
cannam@167 218 accumulated wisdom and a list of algorithms available in the current
cannam@167 219 configuration. If you want to deallocate all of that and reset FFTW
cannam@167 220 to the pristine state it was in when you started your program, you can
cannam@167 221 call:
cannam@167 222
cannam@167 223 @example
cannam@167 224 void fftw_cleanup(void);
cannam@167 225 @end example
cannam@167 226 @findex fftw_cleanup
cannam@167 227
cannam@167 228 After calling @code{fftw_cleanup}, all existing plans become undefined,
cannam@167 229 and you should not attempt to execute them nor to destroy them. You can
cannam@167 230 however create and execute/destroy new plans, in which case FFTW starts
cannam@167 231 accumulating wisdom information again.
cannam@167 232
cannam@167 233 @code{fftw_cleanup} does not deallocate your plans, however. To prevent
cannam@167 234 memory leaks, you must still call @code{fftw_destroy_plan} before
cannam@167 235 executing @code{fftw_cleanup}.
cannam@167 236
cannam@167 237 Occasionally, it may useful to know FFTW's internal ``cost'' metric
cannam@167 238 that it uses to compare plans to one another; this cost is
cannam@167 239 proportional to an execution time of the plan, in undocumented units,
cannam@167 240 if the plan was created with the @code{FFTW_MEASURE} or other
cannam@167 241 timing-based options, or alternatively is a heuristic cost function
cannam@167 242 for @code{FFTW_ESTIMATE} plans. (The cost values of measured and
cannam@167 243 estimated plans are not comparable, being in different units. Also,
cannam@167 244 costs from different FFTW versions or the same version compiled
cannam@167 245 differently may not be in the same units. Plans created from wisdom
cannam@167 246 have a cost of 0 since no timing measurement is performed for them.
cannam@167 247 Finally, certain problems for which only one top-level algorithm was
cannam@167 248 possible may have required no measurements of the cost of the whole
cannam@167 249 plan, in which case @code{fftw_cost} will also return 0.) The cost
cannam@167 250 metric for a given plan is returned by:
cannam@167 251
cannam@167 252 @example
cannam@167 253 double fftw_cost(const fftw_plan plan);
cannam@167 254 @end example
cannam@167 255 @findex fftw_cost
cannam@167 256
cannam@167 257 The following two routines are provided purely for academic purposes
cannam@167 258 (that is, for entertainment).
cannam@167 259
cannam@167 260 @example
cannam@167 261 void fftw_flops(const fftw_plan plan,
cannam@167 262 double *add, double *mul, double *fma);
cannam@167 263 @end example
cannam@167 264 @findex fftw_flops
cannam@167 265
cannam@167 266 Given a @code{plan}, set @code{add}, @code{mul}, and @code{fma} to an
cannam@167 267 exact count of the number of floating-point additions, multiplications,
cannam@167 268 and fused multiply-add operations involved in the plan's execution. The
cannam@167 269 total number of floating-point operations (flops) is @code{add + mul +
cannam@167 270 2*fma}, or @code{add + mul + fma} if the hardware supports fused
cannam@167 271 multiply-add instructions (although the number of FMA operations is only
cannam@167 272 approximate because of compiler voodoo). (The number of operations
cannam@167 273 should be an integer, but we use @code{double} to avoid overflowing
cannam@167 274 @code{int} for large transforms; the arguments are of type @code{double}
cannam@167 275 even for single and long-double precision versions of FFTW.)
cannam@167 276
cannam@167 277 @example
cannam@167 278 void fftw_fprint_plan(const fftw_plan plan, FILE *output_file);
cannam@167 279 void fftw_print_plan(const fftw_plan plan);
cannam@167 280 char *fftw_sprint_plan(const fftw_plan plan);
cannam@167 281 @end example
cannam@167 282 @findex fftw_fprint_plan
cannam@167 283 @findex fftw_print_plan
cannam@167 284
cannam@167 285 This outputs a ``nerd-readable'' representation of the @code{plan} to
cannam@167 286 the given file, to @code{stdout}, or two a newly allocated
cannam@167 287 NUL-terminated string (which the caller is responsible for deallocating
cannam@167 288 with @code{free}), respectively.
cannam@167 289
cannam@167 290 @c ------------------------------------------------------------
cannam@167 291 @node Basic Interface, Advanced Interface, Using Plans, FFTW Reference
cannam@167 292 @section Basic Interface
cannam@167 293 @cindex basic interface
cannam@167 294
cannam@167 295 Recall that the FFTW API is divided into three parts@footnote{@i{Gallia est
cannam@167 296 omnis divisa in partes tres} (Julius Caesar).}: the @dfn{basic interface}
cannam@167 297 computes a single transform of contiguous data, the @dfn{advanced
cannam@167 298 interface} computes transforms of multiple or strided arrays, and the
cannam@167 299 @dfn{guru interface} supports the most general data layouts,
cannam@167 300 multiplicities, and strides. This section describes the the basic
cannam@167 301 interface, which we expect to satisfy the needs of most users.
cannam@167 302
cannam@167 303 @menu
cannam@167 304 * Complex DFTs::
cannam@167 305 * Planner Flags::
cannam@167 306 * Real-data DFTs::
cannam@167 307 * Real-data DFT Array Format::
cannam@167 308 * Real-to-Real Transforms::
cannam@167 309 * Real-to-Real Transform Kinds::
cannam@167 310 @end menu
cannam@167 311
cannam@167 312 @c =========>
cannam@167 313 @node Complex DFTs, Planner Flags, Basic Interface, Basic Interface
cannam@167 314 @subsection Complex DFTs
cannam@167 315
cannam@167 316 @example
cannam@167 317 fftw_plan fftw_plan_dft_1d(int n0,
cannam@167 318 fftw_complex *in, fftw_complex *out,
cannam@167 319 int sign, unsigned flags);
cannam@167 320 fftw_plan fftw_plan_dft_2d(int n0, int n1,
cannam@167 321 fftw_complex *in, fftw_complex *out,
cannam@167 322 int sign, unsigned flags);
cannam@167 323 fftw_plan fftw_plan_dft_3d(int n0, int n1, int n2,
cannam@167 324 fftw_complex *in, fftw_complex *out,
cannam@167 325 int sign, unsigned flags);
cannam@167 326 fftw_plan fftw_plan_dft(int rank, const int *n,
cannam@167 327 fftw_complex *in, fftw_complex *out,
cannam@167 328 int sign, unsigned flags);
cannam@167 329 @end example
cannam@167 330 @findex fftw_plan_dft_1d
cannam@167 331 @findex fftw_plan_dft_2d
cannam@167 332 @findex fftw_plan_dft_3d
cannam@167 333 @findex fftw_plan_dft
cannam@167 334
cannam@167 335 Plan a complex input/output discrete Fourier transform (DFT) in zero or
cannam@167 336 more dimensions, returning an @code{fftw_plan} (@pxref{Using Plans}).
cannam@167 337
cannam@167 338 Once you have created a plan for a certain transform type and
cannam@167 339 parameters, then creating another plan of the same type and parameters,
cannam@167 340 but for different arrays, is fast and shares constant data with the
cannam@167 341 first plan (if it still exists).
cannam@167 342
cannam@167 343 The planner returns @code{NULL} if the plan cannot be created. In the
cannam@167 344 standard FFTW distribution, the basic interface is guaranteed to return
cannam@167 345 a non-@code{NULL} plan. A plan may be @code{NULL}, however, if you are
cannam@167 346 using a customized FFTW configuration supporting a restricted set of
cannam@167 347 transforms.
cannam@167 348
cannam@167 349 @subsubheading Arguments
cannam@167 350 @itemize @bullet
cannam@167 351
cannam@167 352 @item
cannam@167 353 @code{rank} is the rank of the transform (it should be the size of the
cannam@167 354 array @code{*n}), and can be any non-negative integer. (@xref{Complex
cannam@167 355 Multi-Dimensional DFTs}, for the definition of ``rank''.) The
cannam@167 356 @samp{_1d}, @samp{_2d}, and @samp{_3d} planners correspond to a
cannam@167 357 @code{rank} of @code{1}, @code{2}, and @code{3}, respectively. The rank
cannam@167 358 may be zero, which is equivalent to a rank-1 transform of size 1, i.e. a
cannam@167 359 copy of one number from input to output.
cannam@167 360
cannam@167 361 @item
cannam@167 362 @code{n0}, @code{n1}, @code{n2}, or @code{n[0..rank-1]} (as appropriate
cannam@167 363 for each routine) specify the size of the transform dimensions. They
cannam@167 364 can be any positive integer.
cannam@167 365
cannam@167 366 @itemize @minus
cannam@167 367 @item
cannam@167 368 @cindex row-major
cannam@167 369 Multi-dimensional arrays are stored in row-major order with dimensions:
cannam@167 370 @code{n0} x @code{n1}; or @code{n0} x @code{n1} x @code{n2}; or
cannam@167 371 @code{n[0]} x @code{n[1]} x ... x @code{n[rank-1]}.
cannam@167 372 @xref{Multi-dimensional Array Format}.
cannam@167 373 @item
cannam@167 374 FFTW is best at handling sizes of the form
cannam@167 375 @ifinfo
cannam@167 376 @math{2^a 3^b 5^c 7^d 11^e 13^f},
cannam@167 377 @end ifinfo
cannam@167 378 @tex
cannam@167 379 $2^a 3^b 5^c 7^d 11^e 13^f$,
cannam@167 380 @end tex
cannam@167 381 @html
cannam@167 382 2<sup>a</sup> 3<sup>b</sup> 5<sup>c</sup> 7<sup>d</sup>
cannam@167 383 11<sup>e</sup> 13<sup>f</sup>,
cannam@167 384 @end html
cannam@167 385 where @math{e+f} is either @math{0} or @math{1}, and the other exponents
cannam@167 386 are arbitrary. Other sizes are computed by means of a slow,
cannam@167 387 general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). It is possible to customize FFTW
cannam@167 388 for different array sizes; see @ref{Installation and Customization}.
cannam@167 389 Transforms whose sizes are powers of @math{2} are especially fast.
cannam@167 390 @end itemize
cannam@167 391
cannam@167 392 @item
cannam@167 393 @code{in} and @code{out} point to the input and output arrays of the
cannam@167 394 transform, which may be the same (yielding an in-place transform).
cannam@167 395 @cindex in-place
cannam@167 396 These arrays are overwritten during planning, unless
cannam@167 397 @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be
cannam@167 398 initialized, but they must be allocated.)
cannam@167 399
cannam@167 400 If @code{in == out}, the transform is @dfn{in-place} and the input
cannam@167 401 array is overwritten. If @code{in != out}, the two arrays must
cannam@167 402 not overlap (but FFTW does not check for this condition).
cannam@167 403
cannam@167 404 @item
cannam@167 405 @ctindex FFTW_FORWARD
cannam@167 406 @ctindex FFTW_BACKWARD
cannam@167 407 @code{sign} is the sign of the exponent in the formula that defines the
cannam@167 408 Fourier transform. It can be @math{-1} (= @code{FFTW_FORWARD}) or
cannam@167 409 @math{+1} (= @code{FFTW_BACKWARD}).
cannam@167 410
cannam@167 411 @item
cannam@167 412 @cindex flags
cannam@167 413 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@167 414 as defined in @ref{Planner Flags}.
cannam@167 415
cannam@167 416 @end itemize
cannam@167 417
cannam@167 418 FFTW computes an unnormalized transform: computing a forward followed by
cannam@167 419 a backward transform (or vice versa) will result in the original data
cannam@167 420 multiplied by the size of the transform (the product of the dimensions).
cannam@167 421 @cindex normalization
cannam@167 422 For more information, see @ref{What FFTW Really Computes}.
cannam@167 423
cannam@167 424 @c =========>
cannam@167 425 @node Planner Flags, Real-data DFTs, Complex DFTs, Basic Interface
cannam@167 426 @subsection Planner Flags
cannam@167 427
cannam@167 428 All of the planner routines in FFTW accept an integer @code{flags}
cannam@167 429 argument, which is a bitwise OR (@samp{|}) of zero or more of the flag
cannam@167 430 constants defined below. These flags control the rigor (and time) of
cannam@167 431 the planning process, and can also impose (or lift) restrictions on the
cannam@167 432 type of transform algorithm that is employed.
cannam@167 433
cannam@167 434 @emph{Important:} the planner overwrites the input array during
cannam@167 435 planning unless a saved plan (@pxref{Wisdom}) is available for that
cannam@167 436 problem, so you should initialize your input data after creating the
cannam@167 437 plan. The only exceptions to this are the @code{FFTW_ESTIMATE} and
cannam@167 438 @code{FFTW_WISDOM_ONLY} flags, as mentioned below.
cannam@167 439
cannam@167 440 In all cases, if wisdom is available for the given problem that was
cannam@167 441 created with equal-or-greater planning rigor, then the more rigorous
cannam@167 442 wisdom is used. For example, in @code{FFTW_ESTIMATE} mode any available
cannam@167 443 wisdom is used, whereas in @code{FFTW_PATIENT} mode only wisdom created
cannam@167 444 in patient or exhaustive mode can be used. @xref{Words of Wisdom-Saving
cannam@167 445 Plans}.
cannam@167 446
cannam@167 447 @subsubheading Planning-rigor flags
cannam@167 448 @itemize @bullet
cannam@167 449
cannam@167 450 @item
cannam@167 451 @ctindex FFTW_ESTIMATE
cannam@167 452 @code{FFTW_ESTIMATE} specifies that, instead of actual measurements of
cannam@167 453 different algorithms, a simple heuristic is used to pick a (probably
cannam@167 454 sub-optimal) plan quickly. With this flag, the input/output arrays are
cannam@167 455 not overwritten during planning.
cannam@167 456
cannam@167 457 @item
cannam@167 458 @ctindex FFTW_MEASURE
cannam@167 459 @code{FFTW_MEASURE} tells FFTW to find an optimized plan by actually
cannam@167 460 @emph{computing} several FFTs and measuring their execution time.
cannam@167 461 Depending on your machine, this can take some time (often a few
cannam@167 462 seconds). @code{FFTW_MEASURE} is the default planning option.
cannam@167 463
cannam@167 464 @item
cannam@167 465 @ctindex FFTW_PATIENT
cannam@167 466 @code{FFTW_PATIENT} is like @code{FFTW_MEASURE}, but considers a wider
cannam@167 467 range of algorithms and often produces a ``more optimal'' plan
cannam@167 468 (especially for large transforms), but at the expense of several times
cannam@167 469 longer planning time (especially for large transforms).
cannam@167 470
cannam@167 471 @item
cannam@167 472 @ctindex FFTW_EXHAUSTIVE
cannam@167 473 @code{FFTW_EXHAUSTIVE} is like @code{FFTW_PATIENT}, but considers an
cannam@167 474 even wider range of algorithms, including many that we think are
cannam@167 475 unlikely to be fast, to produce the most optimal plan but with a
cannam@167 476 substantially increased planning time.
cannam@167 477
cannam@167 478 @item
cannam@167 479 @ctindex FFTW_WISDOM_ONLY
cannam@167 480 @code{FFTW_WISDOM_ONLY} is a special planning mode in which the plan
cannam@167 481 is only created if wisdom is available for the given problem, and
cannam@167 482 otherwise a @code{NULL} plan is returned. This can be combined with
cannam@167 483 other flags, e.g. @samp{FFTW_WISDOM_ONLY | FFTW_PATIENT} creates a
cannam@167 484 plan only if wisdom is available that was created in
cannam@167 485 @code{FFTW_PATIENT} or @code{FFTW_EXHAUSTIVE} mode. The
cannam@167 486 @code{FFTW_WISDOM_ONLY} flag is intended for users who need to detect
cannam@167 487 whether wisdom is available; for example, if wisdom is not available
cannam@167 488 one may wish to allocate new arrays for planning so that user data is
cannam@167 489 not overwritten.
cannam@167 490
cannam@167 491 @end itemize
cannam@167 492
cannam@167 493 @subsubheading Algorithm-restriction flags
cannam@167 494 @itemize @bullet
cannam@167 495
cannam@167 496 @item
cannam@167 497 @ctindex FFTW_DESTROY_INPUT
cannam@167 498 @code{FFTW_DESTROY_INPUT} specifies that an out-of-place transform is
cannam@167 499 allowed to @emph{overwrite its input} array with arbitrary data; this
cannam@167 500 can sometimes allow more efficient algorithms to be employed.
cannam@167 501 @cindex out-of-place
cannam@167 502
cannam@167 503 @item
cannam@167 504 @ctindex FFTW_PRESERVE_INPUT
cannam@167 505 @code{FFTW_PRESERVE_INPUT} specifies that an out-of-place transform must
cannam@167 506 @emph{not change its input} array. This is ordinarily the
cannam@167 507 @emph{default}, except for c2r and hc2r (i.e. complex-to-real)
cannam@167 508 transforms for which @code{FFTW_DESTROY_INPUT} is the default. In the
cannam@167 509 latter cases, passing @code{FFTW_PRESERVE_INPUT} will attempt to use
cannam@167 510 algorithms that do not destroy the input, at the expense of worse
cannam@167 511 performance; for multi-dimensional c2r transforms, however, no
cannam@167 512 input-preserving algorithms are implemented and the planner will return
cannam@167 513 @code{NULL} if one is requested.
cannam@167 514 @cindex c2r
cannam@167 515 @cindex hc2r
cannam@167 516
cannam@167 517 @item
cannam@167 518 @ctindex FFTW_UNALIGNED
cannam@167 519 @cindex alignment
cannam@167 520 @findex fftw_malloc
cannam@167 521 @findex fftw_alignment_of
cannam@167 522 @code{FFTW_UNALIGNED} specifies that the algorithm may not impose any
cannam@167 523 unusual alignment requirements on the input/output arrays (i.e. no
cannam@167 524 SIMD may be used). This flag is normally @emph{not necessary}, since
cannam@167 525 the planner automatically detects misaligned arrays. The only use for
cannam@167 526 this flag is if you want to use the new-array execute interface to
cannam@167 527 execute a given plan on a different array that may not be aligned like
cannam@167 528 the original. (Using @code{fftw_malloc} makes this flag unnecessary
cannam@167 529 even then. You can also use @code{fftw_alignment_of} to detect
cannam@167 530 whether two arrays are equivalently aligned.)
cannam@167 531
cannam@167 532 @end itemize
cannam@167 533
cannam@167 534 @subsubheading Limiting planning time
cannam@167 535
cannam@167 536 @example
cannam@167 537 extern void fftw_set_timelimit(double seconds);
cannam@167 538 @end example
cannam@167 539 @findex fftw_set_timelimit
cannam@167 540
cannam@167 541 This function instructs FFTW to spend at most @code{seconds} seconds
cannam@167 542 (approximately) in the planner. If @code{seconds ==
cannam@167 543 FFTW_NO_TIMELIMIT} (the default value, which is negative), then
cannam@167 544 planning time is unbounded. Otherwise, FFTW plans with a
cannam@167 545 progressively wider range of algorithms until the the given time limit
cannam@167 546 is reached or the given range of algorithms is explored, returning the
cannam@167 547 best available plan.
cannam@167 548 @ctindex FFTW_NO_TIMELIMIT
cannam@167 549
cannam@167 550
cannam@167 551 For example, specifying @code{FFTW_PATIENT} first plans in
cannam@167 552 @code{FFTW_ESTIMATE} mode, then in @code{FFTW_MEASURE} mode, then
cannam@167 553 finally (time permitting) in @code{FFTW_PATIENT}. If
cannam@167 554 @code{FFTW_EXHAUSTIVE} is specified instead, the planner will further
cannam@167 555 progress to @code{FFTW_EXHAUSTIVE} mode.
cannam@167 556
cannam@167 557 Note that the @code{seconds} argument specifies only a rough limit; in
cannam@167 558 practice, the planner may use somewhat more time if the time limit is
cannam@167 559 reached when the planner is in the middle of an operation that cannot
cannam@167 560 be interrupted. At the very least, the planner will complete planning
cannam@167 561 in @code{FFTW_ESTIMATE} mode (which is thus equivalent to a time limit
cannam@167 562 of 0).
cannam@167 563
cannam@167 564
cannam@167 565 @c =========>
cannam@167 566 @node Real-data DFTs, Real-data DFT Array Format, Planner Flags, Basic Interface
cannam@167 567 @subsection Real-data DFTs
cannam@167 568
cannam@167 569 @example
cannam@167 570 fftw_plan fftw_plan_dft_r2c_1d(int n0,
cannam@167 571 double *in, fftw_complex *out,
cannam@167 572 unsigned flags);
cannam@167 573 fftw_plan fftw_plan_dft_r2c_2d(int n0, int n1,
cannam@167 574 double *in, fftw_complex *out,
cannam@167 575 unsigned flags);
cannam@167 576 fftw_plan fftw_plan_dft_r2c_3d(int n0, int n1, int n2,
cannam@167 577 double *in, fftw_complex *out,
cannam@167 578 unsigned flags);
cannam@167 579 fftw_plan fftw_plan_dft_r2c(int rank, const int *n,
cannam@167 580 double *in, fftw_complex *out,
cannam@167 581 unsigned flags);
cannam@167 582 @end example
cannam@167 583 @findex fftw_plan_dft_r2c_1d
cannam@167 584 @findex fftw_plan_dft_r2c_2d
cannam@167 585 @findex fftw_plan_dft_r2c_3d
cannam@167 586 @findex fftw_plan_dft_r2c
cannam@167 587 @cindex r2c
cannam@167 588
cannam@167 589 Plan a real-input/complex-output discrete Fourier transform (DFT) in
cannam@167 590 zero or more dimensions, returning an @code{fftw_plan} (@pxref{Using
cannam@167 591 Plans}).
cannam@167 592
cannam@167 593 Once you have created a plan for a certain transform type and
cannam@167 594 parameters, then creating another plan of the same type and parameters,
cannam@167 595 but for different arrays, is fast and shares constant data with the
cannam@167 596 first plan (if it still exists).
cannam@167 597
cannam@167 598 The planner returns @code{NULL} if the plan cannot be created. A
cannam@167 599 non-@code{NULL} plan is always returned by the basic interface unless
cannam@167 600 you are using a customized FFTW configuration supporting a restricted
cannam@167 601 set of transforms, or if you use the @code{FFTW_PRESERVE_INPUT} flag
cannam@167 602 with a multi-dimensional out-of-place c2r transform (see below).
cannam@167 603
cannam@167 604 @subsubheading Arguments
cannam@167 605 @itemize @bullet
cannam@167 606
cannam@167 607 @item
cannam@167 608 @code{rank} is the rank of the transform (it should be the size of the
cannam@167 609 array @code{*n}), and can be any non-negative integer. (@xref{Complex
cannam@167 610 Multi-Dimensional DFTs}, for the definition of ``rank''.) The
cannam@167 611 @samp{_1d}, @samp{_2d}, and @samp{_3d} planners correspond to a
cannam@167 612 @code{rank} of @code{1}, @code{2}, and @code{3}, respectively. The rank
cannam@167 613 may be zero, which is equivalent to a rank-1 transform of size 1, i.e. a
cannam@167 614 copy of one real number (with zero imaginary part) from input to output.
cannam@167 615
cannam@167 616 @item
cannam@167 617 @code{n0}, @code{n1}, @code{n2}, or @code{n[0..rank-1]}, (as appropriate
cannam@167 618 for each routine) specify the size of the transform dimensions. They
cannam@167 619 can be any positive integer. This is different in general from the
cannam@167 620 @emph{physical} array dimensions, which are described in @ref{Real-data
cannam@167 621 DFT Array Format}.
cannam@167 622
cannam@167 623 @itemize @minus
cannam@167 624 @item
cannam@167 625 FFTW is best at handling sizes of the form
cannam@167 626 @ifinfo
cannam@167 627 @math{2^a 3^b 5^c 7^d 11^e 13^f},
cannam@167 628 @end ifinfo
cannam@167 629 @tex
cannam@167 630 $2^a 3^b 5^c 7^d 11^e 13^f$,
cannam@167 631 @end tex
cannam@167 632 @html
cannam@167 633 2<sup>a</sup> 3<sup>b</sup> 5<sup>c</sup> 7<sup>d</sup>
cannam@167 634 11<sup>e</sup> 13<sup>f</sup>,
cannam@167 635 @end html
cannam@167 636 where @math{e+f} is either @math{0} or @math{1}, and the other exponents
cannam@167 637 are arbitrary. Other sizes are computed by means of a slow,
cannam@167 638 general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). (It is possible to customize FFTW
cannam@167 639 for different array sizes; see @ref{Installation and Customization}.)
cannam@167 640 Transforms whose sizes are powers of @math{2} are especially fast, and
cannam@167 641 it is generally beneficial for the @emph{last} dimension of an r2c/c2r
cannam@167 642 transform to be @emph{even}.
cannam@167 643 @end itemize
cannam@167 644
cannam@167 645 @item
cannam@167 646 @code{in} and @code{out} point to the input and output arrays of the
cannam@167 647 transform, which may be the same (yielding an in-place transform).
cannam@167 648 @cindex in-place
cannam@167 649 These arrays are overwritten during planning, unless
cannam@167 650 @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be
cannam@167 651 initialized, but they must be allocated.) For an in-place transform, it
cannam@167 652 is important to remember that the real array will require padding,
cannam@167 653 described in @ref{Real-data DFT Array Format}.
cannam@167 654 @cindex padding
cannam@167 655
cannam@167 656 @item
cannam@167 657 @cindex flags
cannam@167 658 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@167 659 as defined in @ref{Planner Flags}.
cannam@167 660
cannam@167 661 @end itemize
cannam@167 662
cannam@167 663 The inverse transforms, taking complex input (storing the non-redundant
cannam@167 664 half of a logically Hermitian array) to real output, are given by:
cannam@167 665
cannam@167 666 @example
cannam@167 667 fftw_plan fftw_plan_dft_c2r_1d(int n0,
cannam@167 668 fftw_complex *in, double *out,
cannam@167 669 unsigned flags);
cannam@167 670 fftw_plan fftw_plan_dft_c2r_2d(int n0, int n1,
cannam@167 671 fftw_complex *in, double *out,
cannam@167 672 unsigned flags);
cannam@167 673 fftw_plan fftw_plan_dft_c2r_3d(int n0, int n1, int n2,
cannam@167 674 fftw_complex *in, double *out,
cannam@167 675 unsigned flags);
cannam@167 676 fftw_plan fftw_plan_dft_c2r(int rank, const int *n,
cannam@167 677 fftw_complex *in, double *out,
cannam@167 678 unsigned flags);
cannam@167 679 @end example
cannam@167 680 @findex fftw_plan_dft_c2r_1d
cannam@167 681 @findex fftw_plan_dft_c2r_2d
cannam@167 682 @findex fftw_plan_dft_c2r_3d
cannam@167 683 @findex fftw_plan_dft_c2r
cannam@167 684 @cindex c2r
cannam@167 685
cannam@167 686 The arguments are the same as for the r2c transforms, except that the
cannam@167 687 input and output data formats are reversed.
cannam@167 688
cannam@167 689 FFTW computes an unnormalized transform: computing an r2c followed by a
cannam@167 690 c2r transform (or vice versa) will result in the original data
cannam@167 691 multiplied by the size of the transform (the product of the logical
cannam@167 692 dimensions).
cannam@167 693 @cindex normalization
cannam@167 694 An r2c transform produces the same output as a @code{FFTW_FORWARD}
cannam@167 695 complex DFT of the same input, and a c2r transform is correspondingly
cannam@167 696 equivalent to @code{FFTW_BACKWARD}. For more information, see @ref{What
cannam@167 697 FFTW Really Computes}.
cannam@167 698
cannam@167 699 @c =========>
cannam@167 700 @node Real-data DFT Array Format, Real-to-Real Transforms, Real-data DFTs, Basic Interface
cannam@167 701 @subsection Real-data DFT Array Format
cannam@167 702 @cindex r2c/c2r multi-dimensional array format
cannam@167 703
cannam@167 704 The output of a DFT of real data (r2c) contains symmetries that, in
cannam@167 705 principle, make half of the outputs redundant (@pxref{What FFTW Really
cannam@167 706 Computes}). (Similarly for the input of an inverse c2r transform.) In
cannam@167 707 practice, it is not possible to entirely realize these savings in an
cannam@167 708 efficient and understandable format that generalizes to
cannam@167 709 multi-dimensional transforms. Instead, the output of the r2c
cannam@167 710 transforms is @emph{slightly} over half of the output of the
cannam@167 711 corresponding complex transform. We do not ``pack'' the data in any
cannam@167 712 way, but store it as an ordinary array of @code{fftw_complex} values.
cannam@167 713 In fact, this data is simply a subsection of what would be the array in
cannam@167 714 the corresponding complex transform.
cannam@167 715
cannam@167 716 Specifically, for a real transform of @math{d} (= @code{rank})
cannam@167 717 dimensions @ndims{}, the complex data is an @ndimshalf array of
cannam@167 718 @code{fftw_complex} values in row-major order (with the division rounded
cannam@167 719 down). That is, we only store the @emph{lower} half (non-negative
cannam@167 720 frequencies), plus one element, of the last dimension of the data from
cannam@167 721 the ordinary complex transform. (We could have instead taken half of
cannam@167 722 any other dimension, but implementation turns out to be simpler if the
cannam@167 723 last, contiguous, dimension is used.)
cannam@167 724
cannam@167 725 @cindex out-of-place
cannam@167 726 For an out-of-place transform, the real data is simply an array with
cannam@167 727 physical dimensions @ndims in row-major order.
cannam@167 728
cannam@167 729 @cindex in-place
cannam@167 730 @cindex padding
cannam@167 731 For an in-place transform, some complications arise since the complex data
cannam@167 732 is slightly larger than the real data. In this case, the final
cannam@167 733 dimension of the real data must be @emph{padded} with extra values to
cannam@167 734 accommodate the size of the complex data---two extra if the last
cannam@167 735 dimension is even and one if it is odd. That is, the last dimension of
cannam@167 736 the real data must physically contain
cannam@167 737 @tex
cannam@167 738 $2 (n_{d-1}/2+1)$
cannam@167 739 @end tex
cannam@167 740 @ifinfo
cannam@167 741 2 * (n[d-1]/2+1)
cannam@167 742 @end ifinfo
cannam@167 743 @html
cannam@167 744 2 * (n<sub>d-1</sub>/2+1)
cannam@167 745 @end html
cannam@167 746 @code{double} values (exactly enough to hold the complex data). This
cannam@167 747 physical array size does not, however, change the @emph{logical} array
cannam@167 748 size---only
cannam@167 749 @tex
cannam@167 750 $n_{d-1}$
cannam@167 751 @end tex
cannam@167 752 @ifinfo
cannam@167 753 n[d-1]
cannam@167 754 @end ifinfo
cannam@167 755 @html
cannam@167 756 n<sub>d-1</sub>
cannam@167 757 @end html
cannam@167 758 values are actually stored in the last dimension, and
cannam@167 759 @tex
cannam@167 760 $n_{d-1}$
cannam@167 761 @end tex
cannam@167 762 @ifinfo
cannam@167 763 n[d-1]
cannam@167 764 @end ifinfo
cannam@167 765 @html
cannam@167 766 n<sub>d-1</sub>
cannam@167 767 @end html
cannam@167 768 is the last dimension passed to the planner.
cannam@167 769
cannam@167 770 @c =========>
cannam@167 771 @node Real-to-Real Transforms, Real-to-Real Transform Kinds, Real-data DFT Array Format, Basic Interface
cannam@167 772 @subsection Real-to-Real Transforms
cannam@167 773 @cindex r2r
cannam@167 774
cannam@167 775 @example
cannam@167 776 fftw_plan fftw_plan_r2r_1d(int n, double *in, double *out,
cannam@167 777 fftw_r2r_kind kind, unsigned flags);
cannam@167 778 fftw_plan fftw_plan_r2r_2d(int n0, int n1, double *in, double *out,
cannam@167 779 fftw_r2r_kind kind0, fftw_r2r_kind kind1,
cannam@167 780 unsigned flags);
cannam@167 781 fftw_plan fftw_plan_r2r_3d(int n0, int n1, int n2,
cannam@167 782 double *in, double *out,
cannam@167 783 fftw_r2r_kind kind0,
cannam@167 784 fftw_r2r_kind kind1,
cannam@167 785 fftw_r2r_kind kind2,
cannam@167 786 unsigned flags);
cannam@167 787 fftw_plan fftw_plan_r2r(int rank, const int *n, double *in, double *out,
cannam@167 788 const fftw_r2r_kind *kind, unsigned flags);
cannam@167 789 @end example
cannam@167 790 @findex fftw_plan_r2r_1d
cannam@167 791 @findex fftw_plan_r2r_2d
cannam@167 792 @findex fftw_plan_r2r_3d
cannam@167 793 @findex fftw_plan_r2r
cannam@167 794
cannam@167 795 Plan a real input/output (r2r) transform of various kinds in zero or
cannam@167 796 more dimensions, returning an @code{fftw_plan} (@pxref{Using Plans}).
cannam@167 797
cannam@167 798 Once you have created a plan for a certain transform type and
cannam@167 799 parameters, then creating another plan of the same type and parameters,
cannam@167 800 but for different arrays, is fast and shares constant data with the
cannam@167 801 first plan (if it still exists).
cannam@167 802
cannam@167 803 The planner returns @code{NULL} if the plan cannot be created. A
cannam@167 804 non-@code{NULL} plan is always returned by the basic interface unless
cannam@167 805 you are using a customized FFTW configuration supporting a restricted
cannam@167 806 set of transforms, or for size-1 @code{FFTW_REDFT00} kinds (which are
cannam@167 807 not defined).
cannam@167 808 @ctindex FFTW_REDFT00
cannam@167 809
cannam@167 810 @subsubheading Arguments
cannam@167 811 @itemize @bullet
cannam@167 812
cannam@167 813 @item
cannam@167 814 @code{rank} is the dimensionality of the transform (it should be the
cannam@167 815 size of the arrays @code{*n} and @code{*kind}), and can be any
cannam@167 816 non-negative integer. The @samp{_1d}, @samp{_2d}, and @samp{_3d}
cannam@167 817 planners correspond to a @code{rank} of @code{1}, @code{2}, and
cannam@167 818 @code{3}, respectively. A @code{rank} of zero is equivalent to a copy
cannam@167 819 of one number from input to output.
cannam@167 820
cannam@167 821 @item
cannam@167 822 @code{n}, or @code{n0}/@code{n1}/@code{n2}, or @code{n[rank]},
cannam@167 823 respectively, gives the (physical) size of the transform dimensions.
cannam@167 824 They can be any positive integer.
cannam@167 825
cannam@167 826 @itemize @minus
cannam@167 827 @item
cannam@167 828 @cindex row-major
cannam@167 829 Multi-dimensional arrays are stored in row-major order with dimensions:
cannam@167 830 @code{n0} x @code{n1}; or @code{n0} x @code{n1} x @code{n2}; or
cannam@167 831 @code{n[0]} x @code{n[1]} x ... x @code{n[rank-1]}.
cannam@167 832 @xref{Multi-dimensional Array Format}.
cannam@167 833 @item
cannam@167 834 FFTW is generally best at handling sizes of the form
cannam@167 835 @ifinfo
cannam@167 836 @math{2^a 3^b 5^c 7^d 11^e 13^f},
cannam@167 837 @end ifinfo
cannam@167 838 @tex
cannam@167 839 $2^a 3^b 5^c 7^d 11^e 13^f$,
cannam@167 840 @end tex
cannam@167 841 @html
cannam@167 842 2<sup>a</sup> 3<sup>b</sup> 5<sup>c</sup> 7<sup>d</sup>
cannam@167 843 11<sup>e</sup> 13<sup>f</sup>,
cannam@167 844 @end html
cannam@167 845 where @math{e+f} is either @math{0} or @math{1}, and the other exponents
cannam@167 846 are arbitrary. Other sizes are computed by means of a slow,
cannam@167 847 general-purpose algorithm (which nevertheless retains @Onlogn{} performance even for prime sizes). (It is possible to customize FFTW
cannam@167 848 for different array sizes; see @ref{Installation and Customization}.)
cannam@167 849 Transforms whose sizes are powers of @math{2} are especially fast.
cannam@167 850 @item
cannam@167 851 For a @code{REDFT00} or @code{RODFT00} transform kind in a dimension of
cannam@167 852 size @math{n}, it is @math{n-1} or @math{n+1}, respectively, that
cannam@167 853 should be factorizable in the above form.
cannam@167 854 @end itemize
cannam@167 855
cannam@167 856 @item
cannam@167 857 @code{in} and @code{out} point to the input and output arrays of the
cannam@167 858 transform, which may be the same (yielding an in-place transform).
cannam@167 859 @cindex in-place
cannam@167 860 These arrays are overwritten during planning, unless
cannam@167 861 @code{FFTW_ESTIMATE} is used in the flags. (The arrays need not be
cannam@167 862 initialized, but they must be allocated.)
cannam@167 863
cannam@167 864 @item
cannam@167 865 @code{kind}, or @code{kind0}/@code{kind1}/@code{kind2}, or
cannam@167 866 @code{kind[rank]}, is the kind of r2r transform used for the
cannam@167 867 corresponding dimension. The valid kind constants are described in
cannam@167 868 @ref{Real-to-Real Transform Kinds}. In a multi-dimensional transform,
cannam@167 869 what is computed is the separable product formed by taking each
cannam@167 870 transform kind along the corresponding dimension, one dimension after
cannam@167 871 another.
cannam@167 872
cannam@167 873 @item
cannam@167 874 @cindex flags
cannam@167 875 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@167 876 as defined in @ref{Planner Flags}.
cannam@167 877
cannam@167 878 @end itemize
cannam@167 879
cannam@167 880 @c =========>
cannam@167 881 @node Real-to-Real Transform Kinds, , Real-to-Real Transforms, Basic Interface
cannam@167 882 @subsection Real-to-Real Transform Kinds
cannam@167 883 @cindex kind (r2r)
cannam@167 884
cannam@167 885 FFTW currently supports 11 different r2r transform kinds, specified by
cannam@167 886 one of the constants below. For the precise definitions of these
cannam@167 887 transforms, see @ref{What FFTW Really Computes}. For a more colloquial
cannam@167 888 introduction to these transform kinds, see @ref{More DFTs of Real Data}.
cannam@167 889
cannam@167 890 For dimension of size @code{n}, there is a corresponding ``logical''
cannam@167 891 dimension @code{N} that determines the normalization (and the optimal
cannam@167 892 factorization); the formula for @code{N} is given for each kind below.
cannam@167 893 Also, with each transform kind is listed its corrsponding inverse
cannam@167 894 transform. FFTW computes unnormalized transforms: a transform followed
cannam@167 895 by its inverse will result in the original data multiplied by @code{N}
cannam@167 896 (or the product of the @code{N}'s for each dimension, in
cannam@167 897 multi-dimensions).
cannam@167 898 @cindex normalization
cannam@167 899
cannam@167 900 @itemize @bullet
cannam@167 901
cannam@167 902 @item
cannam@167 903 @ctindex FFTW_R2HC
cannam@167 904 @code{FFTW_R2HC} computes a real-input DFT with output in
cannam@167 905 ``halfcomplex'' format, i.e. real and imaginary parts for a transform of
cannam@167 906 size @code{n} stored as:
cannam@167 907 @tex
cannam@167 908 $$
cannam@167 909 r_0, r_1, r_2, \ldots, r_{n/2}, i_{(n+1)/2-1}, \ldots, i_2, i_1
cannam@167 910 $$
cannam@167 911 @end tex
cannam@167 912 @ifinfo
cannam@167 913 r0, r1, r2, r(n/2), i((n+1)/2-1), ..., i2, i1
cannam@167 914 @end ifinfo
cannam@167 915 @html
cannam@167 916 <p align=center>
cannam@167 917 r<sub>0</sub>, r<sub>1</sub>, r<sub>2</sub>, ..., r<sub>n/2</sub>, i<sub>(n+1)/2-1</sub>, ..., i<sub>2</sub>, i<sub>1</sub>
cannam@167 918 </p>
cannam@167 919 @end html
cannam@167 920 (Logical @code{N=n}, inverse is @code{FFTW_HC2R}.)
cannam@167 921
cannam@167 922 @item
cannam@167 923 @ctindex FFTW_HC2R
cannam@167 924 @code{FFTW_HC2R} computes the reverse of @code{FFTW_R2HC}, above.
cannam@167 925 (Logical @code{N=n}, inverse is @code{FFTW_R2HC}.)
cannam@167 926
cannam@167 927 @item
cannam@167 928 @ctindex FFTW_DHT
cannam@167 929 @code{FFTW_DHT} computes a discrete Hartley transform.
cannam@167 930 (Logical @code{N=n}, inverse is @code{FFTW_DHT}.)
cannam@167 931 @cindex discrete Hartley transform
cannam@167 932
cannam@167 933 @item
cannam@167 934 @ctindex FFTW_REDFT00
cannam@167 935 @code{FFTW_REDFT00} computes an REDFT00 transform, i.e. a DCT-I.
cannam@167 936 (Logical @code{N=2*(n-1)}, inverse is @code{FFTW_REDFT00}.)
cannam@167 937 @cindex discrete cosine transform
cannam@167 938 @cindex DCT
cannam@167 939
cannam@167 940 @item
cannam@167 941 @ctindex FFTW_REDFT10
cannam@167 942 @code{FFTW_REDFT10} computes an REDFT10 transform, i.e. a DCT-II (sometimes called ``the'' DCT).
cannam@167 943 (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT01}.)
cannam@167 944
cannam@167 945 @item
cannam@167 946 @ctindex FFTW_REDFT01
cannam@167 947 @code{FFTW_REDFT01} computes an REDFT01 transform, i.e. a DCT-III (sometimes called ``the'' IDCT, being the inverse of DCT-II).
cannam@167 948 (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT=10}.)
cannam@167 949 @cindex IDCT
cannam@167 950
cannam@167 951 @item
cannam@167 952 @ctindex FFTW_REDFT11
cannam@167 953 @code{FFTW_REDFT11} computes an REDFT11 transform, i.e. a DCT-IV.
cannam@167 954 (Logical @code{N=2*n}, inverse is @code{FFTW_REDFT11}.)
cannam@167 955
cannam@167 956 @item
cannam@167 957 @ctindex FFTW_RODFT00
cannam@167 958 @code{FFTW_RODFT00} computes an RODFT00 transform, i.e. a DST-I.
cannam@167 959 (Logical @code{N=2*(n+1)}, inverse is @code{FFTW_RODFT00}.)
cannam@167 960 @cindex discrete sine transform
cannam@167 961 @cindex DST
cannam@167 962
cannam@167 963 @item
cannam@167 964 @ctindex FFTW_RODFT10
cannam@167 965 @code{FFTW_RODFT10} computes an RODFT10 transform, i.e. a DST-II.
cannam@167 966 (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT01}.)
cannam@167 967
cannam@167 968 @item
cannam@167 969 @ctindex FFTW_RODFT01
cannam@167 970 @code{FFTW_RODFT01} computes an RODFT01 transform, i.e. a DST-III.
cannam@167 971 (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT=10}.)
cannam@167 972
cannam@167 973 @item
cannam@167 974 @ctindex FFTW_RODFT11
cannam@167 975 @code{FFTW_RODFT11} computes an RODFT11 transform, i.e. a DST-IV.
cannam@167 976 (Logical @code{N=2*n}, inverse is @code{FFTW_RODFT11}.)
cannam@167 977
cannam@167 978 @end itemize
cannam@167 979
cannam@167 980 @c ------------------------------------------------------------
cannam@167 981 @node Advanced Interface, Guru Interface, Basic Interface, FFTW Reference
cannam@167 982 @section Advanced Interface
cannam@167 983 @cindex advanced interface
cannam@167 984
cannam@167 985 FFTW's ``advanced'' interface supplements the basic interface with four
cannam@167 986 new planner routines, providing a new level of flexibility: you can plan
cannam@167 987 a transform of multiple arrays simultaneously, operate on non-contiguous
cannam@167 988 (strided) data, and transform a subset of a larger multi-dimensional
cannam@167 989 array. Other than these additional features, the planner operates in
cannam@167 990 the same fashion as in the basic interface, and the resulting
cannam@167 991 @code{fftw_plan} is used in the same way (@pxref{Using Plans}).
cannam@167 992
cannam@167 993 @menu
cannam@167 994 * Advanced Complex DFTs::
cannam@167 995 * Advanced Real-data DFTs::
cannam@167 996 * Advanced Real-to-real Transforms::
cannam@167 997 @end menu
cannam@167 998
cannam@167 999 @c =========>
cannam@167 1000 @node Advanced Complex DFTs, Advanced Real-data DFTs, Advanced Interface, Advanced Interface
cannam@167 1001 @subsection Advanced Complex DFTs
cannam@167 1002
cannam@167 1003 @example
cannam@167 1004 fftw_plan fftw_plan_many_dft(int rank, const int *n, int howmany,
cannam@167 1005 fftw_complex *in, const int *inembed,
cannam@167 1006 int istride, int idist,
cannam@167 1007 fftw_complex *out, const int *onembed,
cannam@167 1008 int ostride, int odist,
cannam@167 1009 int sign, unsigned flags);
cannam@167 1010 @end example
cannam@167 1011 @findex fftw_plan_many_dft
cannam@167 1012
cannam@167 1013 This routine plans multiple multidimensional complex DFTs, and it
cannam@167 1014 extends the @code{fftw_plan_dft} routine (@pxref{Complex DFTs}) to
cannam@167 1015 compute @code{howmany} transforms, each having rank @code{rank} and size
cannam@167 1016 @code{n}. In addition, the transform data need not be contiguous, but
cannam@167 1017 it may be laid out in memory with an arbitrary stride. To account for
cannam@167 1018 these possibilities, @code{fftw_plan_many_dft} adds the new parameters
cannam@167 1019 @code{howmany}, @{@code{i},@code{o}@}@code{nembed},
cannam@167 1020 @{@code{i},@code{o}@}@code{stride}, and
cannam@167 1021 @{@code{i},@code{o}@}@code{dist}. The FFTW basic interface
cannam@167 1022 (@pxref{Complex DFTs}) provides routines specialized for ranks 1, 2,
cannam@167 1023 and@tie{}3, but the advanced interface handles only the general-rank
cannam@167 1024 case.
cannam@167 1025
cannam@167 1026 @code{howmany} is the (nonnegative) number of transforms to compute. The resulting
cannam@167 1027 plan computes @code{howmany} transforms, where the input of the
cannam@167 1028 @code{k}-th transform is at location @code{in+k*idist} (in C pointer
cannam@167 1029 arithmetic), and its output is at location @code{out+k*odist}. Plans
cannam@167 1030 obtained in this way can often be faster than calling FFTW multiple
cannam@167 1031 times for the individual transforms. The basic @code{fftw_plan_dft}
cannam@167 1032 interface corresponds to @code{howmany=1} (in which case the @code{dist}
cannam@167 1033 parameters are ignored).
cannam@167 1034 @cindex howmany parameter
cannam@167 1035 @cindex dist
cannam@167 1036
cannam@167 1037
cannam@167 1038 Each of the @code{howmany} transforms has rank @code{rank} and size
cannam@167 1039 @code{n}, as in the basic interface. In addition, the advanced
cannam@167 1040 interface allows the input and output arrays of each transform to be
cannam@167 1041 row-major subarrays of larger rank-@code{rank} arrays, described by
cannam@167 1042 @code{inembed} and @code{onembed} parameters, respectively.
cannam@167 1043 @{@code{i},@code{o}@}@code{nembed} must be arrays of length @code{rank},
cannam@167 1044 and @code{n} should be elementwise less than or equal to
cannam@167 1045 @{@code{i},@code{o}@}@code{nembed}. Passing @code{NULL} for an
cannam@167 1046 @code{nembed} parameter is equivalent to passing @code{n} (i.e. same
cannam@167 1047 physical and logical dimensions, as in the basic interface.)
cannam@167 1048
cannam@167 1049 The @code{stride} parameters indicate that the @code{j}-th element of
cannam@167 1050 the input or output arrays is located at @code{j*istride} or
cannam@167 1051 @code{j*ostride}, respectively. (For a multi-dimensional array,
cannam@167 1052 @code{j} is the ordinary row-major index.) When combined with the
cannam@167 1053 @code{k}-th transform in a @code{howmany} loop, from above, this means
cannam@167 1054 that the (@code{j},@code{k})-th element is at @code{j*stride+k*dist}.
cannam@167 1055 (The basic @code{fftw_plan_dft} interface corresponds to a stride of 1.)
cannam@167 1056 @cindex stride
cannam@167 1057
cannam@167 1058
cannam@167 1059 For in-place transforms, the input and output @code{stride} and
cannam@167 1060 @code{dist} parameters should be the same; otherwise, the planner may
cannam@167 1061 return @code{NULL}.
cannam@167 1062
cannam@167 1063 Arrays @code{n}, @code{inembed}, and @code{onembed} are not used after
cannam@167 1064 this function returns. You can safely free or reuse them.
cannam@167 1065
cannam@167 1066 @strong{Examples}:
cannam@167 1067 One transform of one 5 by 6 array contiguous in memory:
cannam@167 1068 @example
cannam@167 1069 int rank = 2;
cannam@167 1070 int n[] = @{5, 6@};
cannam@167 1071 int howmany = 1;
cannam@167 1072 int idist = odist = 0; /* unused because howmany = 1 */
cannam@167 1073 int istride = ostride = 1; /* array is contiguous in memory */
cannam@167 1074 int *inembed = n, *onembed = n;
cannam@167 1075 @end example
cannam@167 1076
cannam@167 1077 Transform of three 5 by 6 arrays, each contiguous in memory,
cannam@167 1078 stored in memory one after another:
cannam@167 1079 @example
cannam@167 1080 int rank = 2;
cannam@167 1081 int n[] = @{5, 6@};
cannam@167 1082 int howmany = 3;
cannam@167 1083 int idist = odist = n[0]*n[1]; /* = 30, the distance in memory
cannam@167 1084 between the first element
cannam@167 1085 of the first array and the
cannam@167 1086 first element of the second array */
cannam@167 1087 int istride = ostride = 1; /* array is contiguous in memory */
cannam@167 1088 int *inembed = n, *onembed = n;
cannam@167 1089 @end example
cannam@167 1090
cannam@167 1091 Transform each column of a 2d array with 10 rows and 3 columns:
cannam@167 1092 @example
cannam@167 1093 int rank = 1; /* not 2: we are computing 1d transforms */
cannam@167 1094 int n[] = @{10@}; /* 1d transforms of length 10 */
cannam@167 1095 int howmany = 3;
cannam@167 1096 int idist = odist = 1;
cannam@167 1097 int istride = ostride = 3; /* distance between two elements in
cannam@167 1098 the same column */
cannam@167 1099 int *inembed = n, *onembed = n;
cannam@167 1100 @end example
cannam@167 1101
cannam@167 1102 @c =========>
cannam@167 1103 @node Advanced Real-data DFTs, Advanced Real-to-real Transforms, Advanced Complex DFTs, Advanced Interface
cannam@167 1104 @subsection Advanced Real-data DFTs
cannam@167 1105
cannam@167 1106 @example
cannam@167 1107 fftw_plan fftw_plan_many_dft_r2c(int rank, const int *n, int howmany,
cannam@167 1108 double *in, const int *inembed,
cannam@167 1109 int istride, int idist,
cannam@167 1110 fftw_complex *out, const int *onembed,
cannam@167 1111 int ostride, int odist,
cannam@167 1112 unsigned flags);
cannam@167 1113 fftw_plan fftw_plan_many_dft_c2r(int rank, const int *n, int howmany,
cannam@167 1114 fftw_complex *in, const int *inembed,
cannam@167 1115 int istride, int idist,
cannam@167 1116 double *out, const int *onembed,
cannam@167 1117 int ostride, int odist,
cannam@167 1118 unsigned flags);
cannam@167 1119 @end example
cannam@167 1120 @findex fftw_plan_many_dft_r2c
cannam@167 1121 @findex fftw_plan_many_dft_c2r
cannam@167 1122
cannam@167 1123 Like @code{fftw_plan_many_dft}, these two functions add @code{howmany},
cannam@167 1124 @code{nembed}, @code{stride}, and @code{dist} parameters to the
cannam@167 1125 @code{fftw_plan_dft_r2c} and @code{fftw_plan_dft_c2r} functions, but
cannam@167 1126 otherwise behave the same as the basic interface.
cannam@167 1127
cannam@167 1128 The interpretation of @code{howmany}, @code{stride}, and @code{dist} are
cannam@167 1129 the same as for @code{fftw_plan_many_dft}, above. Note that the
cannam@167 1130 @code{stride} and @code{dist} for the real array are in units of
cannam@167 1131 @code{double}, and for the complex array are in units of
cannam@167 1132 @code{fftw_complex}.
cannam@167 1133
cannam@167 1134 If an @code{nembed} parameter is @code{NULL}, it is interpreted as what
cannam@167 1135 it would be in the basic interface, as described in @ref{Real-data DFT
cannam@167 1136 Array Format}. That is, for the complex array the size is assumed to be
cannam@167 1137 the same as @code{n}, but with the last dimension cut roughly in half.
cannam@167 1138 For the real array, the size is assumed to be @code{n} if the transform
cannam@167 1139 is out-of-place, or @code{n} with the last dimension ``padded'' if the
cannam@167 1140 transform is in-place.
cannam@167 1141
cannam@167 1142 If an @code{nembed} parameter is non-@code{NULL}, it is interpreted as
cannam@167 1143 the physical size of the corresponding array, in row-major order, just
cannam@167 1144 as for @code{fftw_plan_many_dft}. In this case, each dimension of
cannam@167 1145 @code{nembed} should be @code{>=} what it would be in the basic
cannam@167 1146 interface (e.g. the halved or padded @code{n}).
cannam@167 1147
cannam@167 1148 Arrays @code{n}, @code{inembed}, and @code{onembed} are not used after
cannam@167 1149 this function returns. You can safely free or reuse them.
cannam@167 1150
cannam@167 1151 @c =========>
cannam@167 1152 @node Advanced Real-to-real Transforms, , Advanced Real-data DFTs, Advanced Interface
cannam@167 1153 @subsection Advanced Real-to-real Transforms
cannam@167 1154
cannam@167 1155 @example
cannam@167 1156 fftw_plan fftw_plan_many_r2r(int rank, const int *n, int howmany,
cannam@167 1157 double *in, const int *inembed,
cannam@167 1158 int istride, int idist,
cannam@167 1159 double *out, const int *onembed,
cannam@167 1160 int ostride, int odist,
cannam@167 1161 const fftw_r2r_kind *kind, unsigned flags);
cannam@167 1162 @end example
cannam@167 1163 @findex fftw_plan_many_r2r
cannam@167 1164
cannam@167 1165 Like @code{fftw_plan_many_dft}, this functions adds @code{howmany},
cannam@167 1166 @code{nembed}, @code{stride}, and @code{dist} parameters to the
cannam@167 1167 @code{fftw_plan_r2r} function, but otherwise behave the same as the
cannam@167 1168 basic interface. The interpretation of those additional parameters are
cannam@167 1169 the same as for @code{fftw_plan_many_dft}. (Of course, the
cannam@167 1170 @code{stride} and @code{dist} parameters are now in units of
cannam@167 1171 @code{double}, not @code{fftw_complex}.)
cannam@167 1172
cannam@167 1173 Arrays @code{n}, @code{inembed}, @code{onembed}, and @code{kind} are not
cannam@167 1174 used after this function returns. You can safely free or reuse them.
cannam@167 1175
cannam@167 1176 @c ------------------------------------------------------------
cannam@167 1177 @node Guru Interface, New-array Execute Functions, Advanced Interface, FFTW Reference
cannam@167 1178 @section Guru Interface
cannam@167 1179 @cindex guru interface
cannam@167 1180
cannam@167 1181 The ``guru'' interface to FFTW is intended to expose as much as possible
cannam@167 1182 of the flexibility in the underlying FFTW architecture. It allows one
cannam@167 1183 to compute multi-dimensional ``vectors'' (loops) of multi-dimensional
cannam@167 1184 transforms, where each vector/transform dimension has an independent
cannam@167 1185 size and stride.
cannam@167 1186 @cindex vector
cannam@167 1187 One can also use more general complex-number formats, e.g. separate real
cannam@167 1188 and imaginary arrays.
cannam@167 1189
cannam@167 1190 For those users who require the flexibility of the guru interface, it is
cannam@167 1191 important that they pay special attention to the documentation lest they
cannam@167 1192 shoot themselves in the foot.
cannam@167 1193
cannam@167 1194 @menu
cannam@167 1195 * Interleaved and split arrays::
cannam@167 1196 * Guru vector and transform sizes::
cannam@167 1197 * Guru Complex DFTs::
cannam@167 1198 * Guru Real-data DFTs::
cannam@167 1199 * Guru Real-to-real Transforms::
cannam@167 1200 * 64-bit Guru Interface::
cannam@167 1201 @end menu
cannam@167 1202
cannam@167 1203 @c =========>
cannam@167 1204 @node Interleaved and split arrays, Guru vector and transform sizes, Guru Interface, Guru Interface
cannam@167 1205 @subsection Interleaved and split arrays
cannam@167 1206
cannam@167 1207 The guru interface supports two representations of complex numbers,
cannam@167 1208 which we call the interleaved and the split format.
cannam@167 1209
cannam@167 1210 The @dfn{interleaved} format is the same one used by the basic and
cannam@167 1211 advanced interfaces, and it is documented in @ref{Complex numbers}.
cannam@167 1212 In the interleaved format, you provide pointers to the real part of a
cannam@167 1213 complex number, and the imaginary part understood to be stored in the
cannam@167 1214 next memory location.
cannam@167 1215 @cindex interleaved format
cannam@167 1216
cannam@167 1217
cannam@167 1218 The @dfn{split} format allows separate pointers to the real and
cannam@167 1219 imaginary parts of a complex array.
cannam@167 1220 @cindex split format
cannam@167 1221
cannam@167 1222
cannam@167 1223 Technically, the interleaved format is redundant, because you can
cannam@167 1224 always express an interleaved array in terms of a split array with
cannam@167 1225 appropriate pointers and strides. On the other hand, the interleaved
cannam@167 1226 format is simpler to use, and it is common in practice. Hence, FFTW
cannam@167 1227 supports it as a special case.
cannam@167 1228
cannam@167 1229 @c =========>
cannam@167 1230 @node Guru vector and transform sizes, Guru Complex DFTs, Interleaved and split arrays, Guru Interface
cannam@167 1231 @subsection Guru vector and transform sizes
cannam@167 1232
cannam@167 1233 The guru interface introduces one basic new data structure,
cannam@167 1234 @code{fftw_iodim}, that is used to specify sizes and strides for
cannam@167 1235 multi-dimensional transforms and vectors:
cannam@167 1236
cannam@167 1237 @example
cannam@167 1238 typedef struct @{
cannam@167 1239 int n;
cannam@167 1240 int is;
cannam@167 1241 int os;
cannam@167 1242 @} fftw_iodim;
cannam@167 1243 @end example
cannam@167 1244 @tindex fftw_iodim
cannam@167 1245
cannam@167 1246 Here, @code{n} is the size of the dimension, and @code{is} and @code{os}
cannam@167 1247 are the strides of that dimension for the input and output arrays. (The
cannam@167 1248 stride is the separation of consecutive elements along this dimension.)
cannam@167 1249
cannam@167 1250 The meaning of the stride parameter depends on the type of the array
cannam@167 1251 that the stride refers to. @emph{If the array is interleaved complex,
cannam@167 1252 strides are expressed in units of complex numbers
cannam@167 1253 (@code{fftw_complex}). If the array is split complex or real, strides
cannam@167 1254 are expressed in units of real numbers (@code{double}).} This
cannam@167 1255 convention is consistent with the usual pointer arithmetic in the C
cannam@167 1256 language. An interleaved array is denoted by a pointer @code{p} to
cannam@167 1257 @code{fftw_complex}, so that @code{p+1} points to the next complex
cannam@167 1258 number. Split arrays are denoted by pointers to @code{double}, in
cannam@167 1259 which case pointer arithmetic operates in units of
cannam@167 1260 @code{sizeof(double)}.
cannam@167 1261 @cindex stride
cannam@167 1262
cannam@167 1263
cannam@167 1264 The guru planner interfaces all take a (@code{rank}, @code{dims[rank]})
cannam@167 1265 pair describing the transform size, and a (@code{howmany_rank},
cannam@167 1266 @code{howmany_dims[howmany_rank]}) pair describing the ``vector'' size (a
cannam@167 1267 multi-dimensional loop of transforms to perform), where @code{dims} and
cannam@167 1268 @code{howmany_dims} are arrays of @code{fftw_iodim}. Each @code{n} field must
cannam@167 1269 be positive for @code{dims} and nonnegative for @code{howmany_dims}, while both
cannam@167 1270 @code{rank} and @code{howmany_rank} must be nonnegative.
cannam@167 1271
cannam@167 1272 For example, the @code{howmany} parameter in the advanced complex-DFT
cannam@167 1273 interface corresponds to @code{howmany_rank} = 1,
cannam@167 1274 @code{howmany_dims[0].n} = @code{howmany}, @code{howmany_dims[0].is} =
cannam@167 1275 @code{idist}, and @code{howmany_dims[0].os} = @code{odist}.
cannam@167 1276 @cindex howmany loop
cannam@167 1277 @cindex dist
cannam@167 1278 (To compute a single transform, you can just use @code{howmany_rank} = 0.)
cannam@167 1279
cannam@167 1280
cannam@167 1281 A row-major multidimensional array with dimensions @code{n[rank]}
cannam@167 1282 (@pxref{Row-major Format}) corresponds to @code{dims[i].n} =
cannam@167 1283 @code{n[i]} and the recurrence @code{dims[i].is} = @code{n[i+1] *
cannam@167 1284 dims[i+1].is} (similarly for @code{os}). The stride of the last
cannam@167 1285 (@code{i=rank-1}) dimension is the overall stride of the array.
cannam@167 1286 e.g. to be equivalent to the advanced complex-DFT interface, you would
cannam@167 1287 have @code{dims[rank-1].is} = @code{istride} and
cannam@167 1288 @code{dims[rank-1].os} = @code{ostride}.
cannam@167 1289 @cindex row-major
cannam@167 1290
cannam@167 1291
cannam@167 1292 In general, we only guarantee FFTW to return a non-@code{NULL} plan if
cannam@167 1293 the vector and transform dimensions correspond to a set of distinct
cannam@167 1294 indices, and for in-place transforms the input/output strides should
cannam@167 1295 be the same.
cannam@167 1296
cannam@167 1297 @c =========>
cannam@167 1298 @node Guru Complex DFTs, Guru Real-data DFTs, Guru vector and transform sizes, Guru Interface
cannam@167 1299 @subsection Guru Complex DFTs
cannam@167 1300
cannam@167 1301 @example
cannam@167 1302 fftw_plan fftw_plan_guru_dft(
cannam@167 1303 int rank, const fftw_iodim *dims,
cannam@167 1304 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@167 1305 fftw_complex *in, fftw_complex *out,
cannam@167 1306 int sign, unsigned flags);
cannam@167 1307
cannam@167 1308 fftw_plan fftw_plan_guru_split_dft(
cannam@167 1309 int rank, const fftw_iodim *dims,
cannam@167 1310 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@167 1311 double *ri, double *ii, double *ro, double *io,
cannam@167 1312 unsigned flags);
cannam@167 1313 @end example
cannam@167 1314 @findex fftw_plan_guru_dft
cannam@167 1315 @findex fftw_plan_guru_split_dft
cannam@167 1316
cannam@167 1317 These two functions plan a complex-data, multi-dimensional DFT
cannam@167 1318 for the interleaved and split format, respectively.
cannam@167 1319 Transform dimensions are given by (@code{rank}, @code{dims}) over a
cannam@167 1320 multi-dimensional vector (loop) of dimensions (@code{howmany_rank},
cannam@167 1321 @code{howmany_dims}). @code{dims} and @code{howmany_dims} should point
cannam@167 1322 to @code{fftw_iodim} arrays of length @code{rank} and
cannam@167 1323 @code{howmany_rank}, respectively.
cannam@167 1324
cannam@167 1325 @cindex flags
cannam@167 1326 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@167 1327 as defined in @ref{Planner Flags}.
cannam@167 1328
cannam@167 1329 In the @code{fftw_plan_guru_dft} function, the pointers @code{in} and
cannam@167 1330 @code{out} point to the interleaved input and output arrays,
cannam@167 1331 respectively. The sign can be either @math{-1} (=
cannam@167 1332 @code{FFTW_FORWARD}) or @math{+1} (= @code{FFTW_BACKWARD}). If the
cannam@167 1333 pointers are equal, the transform is in-place.
cannam@167 1334
cannam@167 1335 In the @code{fftw_plan_guru_split_dft} function,
cannam@167 1336 @code{ri} and @code{ii} point to the real and imaginary input arrays,
cannam@167 1337 and @code{ro} and @code{io} point to the real and imaginary output
cannam@167 1338 arrays. The input and output pointers may be the same, indicating an
cannam@167 1339 in-place transform. For example, for @code{fftw_complex} pointers
cannam@167 1340 @code{in} and @code{out}, the corresponding parameters are:
cannam@167 1341
cannam@167 1342 @example
cannam@167 1343 ri = (double *) in;
cannam@167 1344 ii = (double *) in + 1;
cannam@167 1345 ro = (double *) out;
cannam@167 1346 io = (double *) out + 1;
cannam@167 1347 @end example
cannam@167 1348
cannam@167 1349 Because @code{fftw_plan_guru_split_dft} accepts split arrays, strides
cannam@167 1350 are expressed in units of @code{double}. For a contiguous
cannam@167 1351 @code{fftw_complex} array, the overall stride of the transform should
cannam@167 1352 be 2, the distance between consecutive real parts or between
cannam@167 1353 consecutive imaginary parts; see @ref{Guru vector and transform
cannam@167 1354 sizes}. Note that the dimension strides are applied equally to the
cannam@167 1355 real and imaginary parts; real and imaginary arrays with different
cannam@167 1356 strides are not supported.
cannam@167 1357
cannam@167 1358 There is no @code{sign} parameter in @code{fftw_plan_guru_split_dft}.
cannam@167 1359 This function always plans for an @code{FFTW_FORWARD} transform. To
cannam@167 1360 plan for an @code{FFTW_BACKWARD} transform, you can exploit the
cannam@167 1361 identity that the backwards DFT is equal to the forwards DFT with the
cannam@167 1362 real and imaginary parts swapped. For example, in the case of the
cannam@167 1363 @code{fftw_complex} arrays above, the @code{FFTW_BACKWARD} transform
cannam@167 1364 is computed by the parameters:
cannam@167 1365
cannam@167 1366 @example
cannam@167 1367 ri = (double *) in + 1;
cannam@167 1368 ii = (double *) in;
cannam@167 1369 ro = (double *) out + 1;
cannam@167 1370 io = (double *) out;
cannam@167 1371 @end example
cannam@167 1372
cannam@167 1373 @c =========>
cannam@167 1374 @node Guru Real-data DFTs, Guru Real-to-real Transforms, Guru Complex DFTs, Guru Interface
cannam@167 1375 @subsection Guru Real-data DFTs
cannam@167 1376
cannam@167 1377 @example
cannam@167 1378 fftw_plan fftw_plan_guru_dft_r2c(
cannam@167 1379 int rank, const fftw_iodim *dims,
cannam@167 1380 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@167 1381 double *in, fftw_complex *out,
cannam@167 1382 unsigned flags);
cannam@167 1383
cannam@167 1384 fftw_plan fftw_plan_guru_split_dft_r2c(
cannam@167 1385 int rank, const fftw_iodim *dims,
cannam@167 1386 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@167 1387 double *in, double *ro, double *io,
cannam@167 1388 unsigned flags);
cannam@167 1389
cannam@167 1390 fftw_plan fftw_plan_guru_dft_c2r(
cannam@167 1391 int rank, const fftw_iodim *dims,
cannam@167 1392 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@167 1393 fftw_complex *in, double *out,
cannam@167 1394 unsigned flags);
cannam@167 1395
cannam@167 1396 fftw_plan fftw_plan_guru_split_dft_c2r(
cannam@167 1397 int rank, const fftw_iodim *dims,
cannam@167 1398 int howmany_rank, const fftw_iodim *howmany_dims,
cannam@167 1399 double *ri, double *ii, double *out,
cannam@167 1400 unsigned flags);
cannam@167 1401 @end example
cannam@167 1402 @findex fftw_plan_guru_dft_r2c
cannam@167 1403 @findex fftw_plan_guru_split_dft_r2c
cannam@167 1404 @findex fftw_plan_guru_dft_c2r
cannam@167 1405 @findex fftw_plan_guru_split_dft_c2r
cannam@167 1406
cannam@167 1407 Plan a real-input (r2c) or real-output (c2r), multi-dimensional DFT with
cannam@167 1408 transform dimensions given by (@code{rank}, @code{dims}) over a
cannam@167 1409 multi-dimensional vector (loop) of dimensions (@code{howmany_rank},
cannam@167 1410 @code{howmany_dims}). @code{dims} and @code{howmany_dims} should point
cannam@167 1411 to @code{fftw_iodim} arrays of length @code{rank} and
cannam@167 1412 @code{howmany_rank}, respectively. As for the basic and advanced
cannam@167 1413 interfaces, an r2c transform is @code{FFTW_FORWARD} and a c2r transform
cannam@167 1414 is @code{FFTW_BACKWARD}.
cannam@167 1415
cannam@167 1416 The @emph{last} dimension of @code{dims} is interpreted specially:
cannam@167 1417 that dimension of the real array has size @code{dims[rank-1].n}, but
cannam@167 1418 that dimension of the complex array has size @code{dims[rank-1].n/2+1}
cannam@167 1419 (division rounded down). The strides, on the other hand, are taken to
cannam@167 1420 be exactly as specified. It is up to the user to specify the strides
cannam@167 1421 appropriately for the peculiar dimensions of the data, and we do not
cannam@167 1422 guarantee that the planner will succeed (return non-@code{NULL}) for
cannam@167 1423 any dimensions other than those described in @ref{Real-data DFT Array
cannam@167 1424 Format} and generalized in @ref{Advanced Real-data DFTs}. (That is,
cannam@167 1425 for an in-place transform, each individual dimension should be able to
cannam@167 1426 operate in place.)
cannam@167 1427 @cindex in-place
cannam@167 1428
cannam@167 1429
cannam@167 1430 @code{in} and @code{out} point to the input and output arrays for r2c
cannam@167 1431 and c2r transforms, respectively. For split arrays, @code{ri} and
cannam@167 1432 @code{ii} point to the real and imaginary input arrays for a c2r
cannam@167 1433 transform, and @code{ro} and @code{io} point to the real and imaginary
cannam@167 1434 output arrays for an r2c transform. @code{in} and @code{ro} or
cannam@167 1435 @code{ri} and @code{out} may be the same, indicating an in-place
cannam@167 1436 transform. (In-place transforms where @code{in} and @code{io} or
cannam@167 1437 @code{ii} and @code{out} are the same are not currently supported.)
cannam@167 1438
cannam@167 1439 @cindex flags
cannam@167 1440 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@167 1441 as defined in @ref{Planner Flags}.
cannam@167 1442
cannam@167 1443 In-place transforms of rank greater than 1 are currently only
cannam@167 1444 supported for interleaved arrays. For split arrays, the planner will
cannam@167 1445 return @code{NULL}.
cannam@167 1446 @cindex in-place
cannam@167 1447
cannam@167 1448 @c =========>
cannam@167 1449 @node Guru Real-to-real Transforms, 64-bit Guru Interface, Guru Real-data DFTs, Guru Interface
cannam@167 1450 @subsection Guru Real-to-real Transforms
cannam@167 1451
cannam@167 1452 @example
cannam@167 1453 fftw_plan fftw_plan_guru_r2r(int rank, const fftw_iodim *dims,
cannam@167 1454 int howmany_rank,
cannam@167 1455 const fftw_iodim *howmany_dims,
cannam@167 1456 double *in, double *out,
cannam@167 1457 const fftw_r2r_kind *kind,
cannam@167 1458 unsigned flags);
cannam@167 1459 @end example
cannam@167 1460 @findex fftw_plan_guru_r2r
cannam@167 1461
cannam@167 1462 Plan a real-to-real (r2r) multi-dimensional @code{FFTW_FORWARD}
cannam@167 1463 transform with transform dimensions given by (@code{rank}, @code{dims})
cannam@167 1464 over a multi-dimensional vector (loop) of dimensions
cannam@167 1465 (@code{howmany_rank}, @code{howmany_dims}). @code{dims} and
cannam@167 1466 @code{howmany_dims} should point to @code{fftw_iodim} arrays of length
cannam@167 1467 @code{rank} and @code{howmany_rank}, respectively.
cannam@167 1468
cannam@167 1469 The transform kind of each dimension is given by the @code{kind}
cannam@167 1470 parameter, which should point to an array of length @code{rank}. Valid
cannam@167 1471 @code{fftw_r2r_kind} constants are given in @ref{Real-to-Real Transform
cannam@167 1472 Kinds}.
cannam@167 1473
cannam@167 1474 @code{in} and @code{out} point to the real input and output arrays; they
cannam@167 1475 may be the same, indicating an in-place transform.
cannam@167 1476
cannam@167 1477 @cindex flags
cannam@167 1478 @code{flags} is a bitwise OR (@samp{|}) of zero or more planner flags,
cannam@167 1479 as defined in @ref{Planner Flags}.
cannam@167 1480
cannam@167 1481 @c =========>
cannam@167 1482 @node 64-bit Guru Interface, , Guru Real-to-real Transforms, Guru Interface
cannam@167 1483 @subsection 64-bit Guru Interface
cannam@167 1484 @cindex 64-bit architecture
cannam@167 1485
cannam@167 1486 When compiled in 64-bit mode on a 64-bit architecture (where addresses
cannam@167 1487 are 64 bits wide), FFTW uses 64-bit quantities internally for all
cannam@167 1488 transform sizes, strides, and so on---you don't have to do anything
cannam@167 1489 special to exploit this. However, in the ordinary FFTW interfaces,
cannam@167 1490 you specify the transform size by an @code{int} quantity, which is
cannam@167 1491 normally only 32 bits wide. This means that, even though FFTW is
cannam@167 1492 using 64-bit sizes internally, you cannot specify a single transform
cannam@167 1493 dimension larger than
cannam@167 1494 @ifinfo
cannam@167 1495 2^31-1
cannam@167 1496 @end ifinfo
cannam@167 1497 @html
cannam@167 1498 2<sup><small>31</small></sup>&minus;1
cannam@167 1499 @end html
cannam@167 1500 @tex
cannam@167 1501 $2^{31}-1$
cannam@167 1502 @end tex
cannam@167 1503 numbers.
cannam@167 1504
cannam@167 1505 We expect that few users will require transforms larger than this, but,
cannam@167 1506 for those who do, we provide a 64-bit version of the guru interface in
cannam@167 1507 which all sizes are specified as integers of type @code{ptrdiff_t}
cannam@167 1508 instead of @code{int}. (@code{ptrdiff_t} is a signed integer type
cannam@167 1509 defined by the C standard to be wide enough to represent address
cannam@167 1510 differences, and thus must be at least 64 bits wide on a 64-bit
cannam@167 1511 machine.) We stress that there is @emph{no performance advantage} to
cannam@167 1512 using this interface---the same internal FFTW code is employed
cannam@167 1513 regardless---and it is only necessary if you want to specify very
cannam@167 1514 large transform sizes.
cannam@167 1515 @tindex ptrdiff_t
cannam@167 1516
cannam@167 1517
cannam@167 1518 In particular, the 64-bit guru interface is a set of planner routines
cannam@167 1519 that are exactly the same as the guru planner routines, except that
cannam@167 1520 they are named with @samp{guru64} instead of @samp{guru} and they take
cannam@167 1521 arguments of type @code{fftw_iodim64} instead of @code{fftw_iodim}.
cannam@167 1522 For example, instead of @code{fftw_plan_guru_dft}, we have
cannam@167 1523 @code{fftw_plan_guru64_dft}.
cannam@167 1524
cannam@167 1525 @example
cannam@167 1526 fftw_plan fftw_plan_guru64_dft(
cannam@167 1527 int rank, const fftw_iodim64 *dims,
cannam@167 1528 int howmany_rank, const fftw_iodim64 *howmany_dims,
cannam@167 1529 fftw_complex *in, fftw_complex *out,
cannam@167 1530 int sign, unsigned flags);
cannam@167 1531 @end example
cannam@167 1532 @findex fftw_plan_guru64_dft
cannam@167 1533
cannam@167 1534 The @code{fftw_iodim64} type is similar to @code{fftw_iodim}, with the
cannam@167 1535 same interpretation, except that it uses type @code{ptrdiff_t} instead
cannam@167 1536 of type @code{int}.
cannam@167 1537
cannam@167 1538 @example
cannam@167 1539 typedef struct @{
cannam@167 1540 ptrdiff_t n;
cannam@167 1541 ptrdiff_t is;
cannam@167 1542 ptrdiff_t os;
cannam@167 1543 @} fftw_iodim64;
cannam@167 1544 @end example
cannam@167 1545 @tindex fftw_iodim64
cannam@167 1546
cannam@167 1547 Every other @samp{fftw_plan_guru} function also has a
cannam@167 1548 @samp{fftw_plan_guru64} equivalent, but we do not repeat their
cannam@167 1549 documentation here since they are identical to the 32-bit versions
cannam@167 1550 except as noted above.
cannam@167 1551
cannam@167 1552 @c -----------------------------------------------------------
cannam@167 1553 @node New-array Execute Functions, Wisdom, Guru Interface, FFTW Reference
cannam@167 1554 @section New-array Execute Functions
cannam@167 1555 @cindex execute
cannam@167 1556 @cindex new-array execution
cannam@167 1557
cannam@167 1558 Normally, one executes a plan for the arrays with which the plan was
cannam@167 1559 created, by calling @code{fftw_execute(plan)} as described in @ref{Using
cannam@167 1560 Plans}.
cannam@167 1561 @findex fftw_execute
cannam@167 1562 However, it is possible for sophisticated users to apply a given plan
cannam@167 1563 to a @emph{different} array using the ``new-array execute'' functions
cannam@167 1564 detailed below, provided that the following conditions are met:
cannam@167 1565
cannam@167 1566 @itemize @bullet
cannam@167 1567
cannam@167 1568 @item
cannam@167 1569 The array size, strides, etcetera are the same (since those are set by
cannam@167 1570 the plan).
cannam@167 1571
cannam@167 1572 @item
cannam@167 1573 The input and output arrays are the same (in-place) or different
cannam@167 1574 (out-of-place) if the plan was originally created to be in-place or
cannam@167 1575 out-of-place, respectively.
cannam@167 1576
cannam@167 1577 @item
cannam@167 1578 For split arrays, the separations between the real and imaginary
cannam@167 1579 parts, @code{ii-ri} and @code{io-ro}, are the same as they were for
cannam@167 1580 the input and output arrays when the plan was created. (This
cannam@167 1581 condition is automatically satisfied for interleaved arrays.)
cannam@167 1582
cannam@167 1583 @item
cannam@167 1584 The @dfn{alignment} of the new input/output arrays is the same as that
cannam@167 1585 of the input/output arrays when the plan was created, unless the plan
cannam@167 1586 was created with the @code{FFTW_UNALIGNED} flag.
cannam@167 1587 @ctindex FFTW_UNALIGNED
cannam@167 1588 Here, the alignment is a platform-dependent quantity (for example, it is
cannam@167 1589 the address modulo 16 if SSE SIMD instructions are used, but the address
cannam@167 1590 modulo 4 for non-SIMD single-precision FFTW on the same machine). In
cannam@167 1591 general, only arrays allocated with @code{fftw_malloc} are guaranteed to
cannam@167 1592 be equally aligned (@pxref{SIMD alignment and fftw_malloc}).
cannam@167 1593
cannam@167 1594 @end itemize
cannam@167 1595
cannam@167 1596 @cindex alignment
cannam@167 1597 The alignment issue is especially critical, because if you don't use
cannam@167 1598 @code{fftw_malloc} then you may have little control over the alignment
cannam@167 1599 of arrays in memory. For example, neither the C++ @code{new} function
cannam@167 1600 nor the Fortran @code{allocate} statement provide strong enough
cannam@167 1601 guarantees about data alignment. If you don't use @code{fftw_malloc},
cannam@167 1602 therefore, you probably have to use @code{FFTW_UNALIGNED} (which
cannam@167 1603 disables most SIMD support). If possible, it is probably better for
cannam@167 1604 you to simply create multiple plans (creating a new plan is quick once
cannam@167 1605 one exists for a given size), or better yet re-use the same array for
cannam@167 1606 your transforms.
cannam@167 1607
cannam@167 1608 @findex fftw_alignment_of
cannam@167 1609 For rare circumstances in which you cannot control the alignment of
cannam@167 1610 allocated memory, but wish to determine where a given array is
cannam@167 1611 aligned like the original array for which a plan was created, you can
cannam@167 1612 use the @code{fftw_alignment_of} function:
cannam@167 1613 @example
cannam@167 1614 int fftw_alignment_of(double *p);
cannam@167 1615 @end example
cannam@167 1616 Two arrays have equivalent alignment (for the purposes of applying a
cannam@167 1617 plan) if and only if @code{fftw_alignment_of} returns the same value
cannam@167 1618 for the corresponding pointers to their data (typecast to @code{double*}
cannam@167 1619 if necessary).
cannam@167 1620
cannam@167 1621 If you are tempted to use the new-array execute interface because you
cannam@167 1622 want to transform a known bunch of arrays of the same size, you should
cannam@167 1623 probably go use the advanced interface instead (@pxref{Advanced
cannam@167 1624 Interface})).
cannam@167 1625
cannam@167 1626 The new-array execute functions are:
cannam@167 1627
cannam@167 1628 @example
cannam@167 1629 void fftw_execute_dft(
cannam@167 1630 const fftw_plan p,
cannam@167 1631 fftw_complex *in, fftw_complex *out);
cannam@167 1632
cannam@167 1633 void fftw_execute_split_dft(
cannam@167 1634 const fftw_plan p,
cannam@167 1635 double *ri, double *ii, double *ro, double *io);
cannam@167 1636
cannam@167 1637 void fftw_execute_dft_r2c(
cannam@167 1638 const fftw_plan p,
cannam@167 1639 double *in, fftw_complex *out);
cannam@167 1640
cannam@167 1641 void fftw_execute_split_dft_r2c(
cannam@167 1642 const fftw_plan p,
cannam@167 1643 double *in, double *ro, double *io);
cannam@167 1644
cannam@167 1645 void fftw_execute_dft_c2r(
cannam@167 1646 const fftw_plan p,
cannam@167 1647 fftw_complex *in, double *out);
cannam@167 1648
cannam@167 1649 void fftw_execute_split_dft_c2r(
cannam@167 1650 const fftw_plan p,
cannam@167 1651 double *ri, double *ii, double *out);
cannam@167 1652
cannam@167 1653 void fftw_execute_r2r(
cannam@167 1654 const fftw_plan p,
cannam@167 1655 double *in, double *out);
cannam@167 1656 @end example
cannam@167 1657 @findex fftw_execute_dft
cannam@167 1658 @findex fftw_execute_split_dft
cannam@167 1659 @findex fftw_execute_dft_r2c
cannam@167 1660 @findex fftw_execute_split_dft_r2c
cannam@167 1661 @findex fftw_execute_dft_c2r
cannam@167 1662 @findex fftw_execute_split_dft_c2r
cannam@167 1663 @findex fftw_execute_r2r
cannam@167 1664
cannam@167 1665 These execute the @code{plan} to compute the corresponding transform on
cannam@167 1666 the input/output arrays specified by the subsequent arguments. The
cannam@167 1667 input/output array arguments have the same meanings as the ones passed
cannam@167 1668 to the guru planner routines in the preceding sections. The @code{plan}
cannam@167 1669 is not modified, and these routines can be called as many times as
cannam@167 1670 desired, or intermixed with calls to the ordinary @code{fftw_execute}.
cannam@167 1671
cannam@167 1672 The @code{plan} @emph{must} have been created for the transform type
cannam@167 1673 corresponding to the execute function, e.g. it must be a complex-DFT
cannam@167 1674 plan for @code{fftw_execute_dft}. Any of the planner routines for that
cannam@167 1675 transform type, from the basic to the guru interface, could have been
cannam@167 1676 used to create the plan, however.
cannam@167 1677
cannam@167 1678 @c ------------------------------------------------------------
cannam@167 1679 @node Wisdom, What FFTW Really Computes, New-array Execute Functions, FFTW Reference
cannam@167 1680 @section Wisdom
cannam@167 1681 @cindex wisdom
cannam@167 1682 @cindex saving plans to disk
cannam@167 1683
cannam@167 1684 This section documents the FFTW mechanism for saving and restoring
cannam@167 1685 plans from disk. This mechanism is called @dfn{wisdom}.
cannam@167 1686
cannam@167 1687 @menu
cannam@167 1688 * Wisdom Export::
cannam@167 1689 * Wisdom Import::
cannam@167 1690 * Forgetting Wisdom::
cannam@167 1691 * Wisdom Utilities::
cannam@167 1692 @end menu
cannam@167 1693
cannam@167 1694 @c =========>
cannam@167 1695 @node Wisdom Export, Wisdom Import, Wisdom, Wisdom
cannam@167 1696 @subsection Wisdom Export
cannam@167 1697
cannam@167 1698 @example
cannam@167 1699 int fftw_export_wisdom_to_filename(const char *filename);
cannam@167 1700 void fftw_export_wisdom_to_file(FILE *output_file);
cannam@167 1701 char *fftw_export_wisdom_to_string(void);
cannam@167 1702 void fftw_export_wisdom(void (*write_char)(char c, void *), void *data);
cannam@167 1703 @end example
cannam@167 1704 @findex fftw_export_wisdom
cannam@167 1705 @findex fftw_export_wisdom_to_filename
cannam@167 1706 @findex fftw_export_wisdom_to_file
cannam@167 1707 @findex fftw_export_wisdom_to_string
cannam@167 1708
cannam@167 1709 These functions allow you to export all currently accumulated wisdom
cannam@167 1710 in a form from which it can be later imported and restored, even
cannam@167 1711 during a separate run of the program. (@xref{Words of Wisdom-Saving
cannam@167 1712 Plans}.) The current store of wisdom is not affected by calling any
cannam@167 1713 of these routines.
cannam@167 1714
cannam@167 1715 @code{fftw_export_wisdom} exports the wisdom to any output
cannam@167 1716 medium, as specified by the callback function
cannam@167 1717 @code{write_char}. @code{write_char} is a @code{putc}-like function that
cannam@167 1718 writes the character @code{c} to some output; its second parameter is
cannam@167 1719 the @code{data} pointer passed to @code{fftw_export_wisdom}. For
cannam@167 1720 convenience, the following three ``wrapper'' routines are provided:
cannam@167 1721
cannam@167 1722 @code{fftw_export_wisdom_to_filename} writes wisdom to a file named
cannam@167 1723 @code{filename} (which is created or overwritten), returning @code{1}
cannam@167 1724 on success and @code{0} on failure. A lower-level function, which
cannam@167 1725 requires you to open and close the file yourself (e.g. if you want to
cannam@167 1726 write wisdom to a portion of a larger file) is
cannam@167 1727 @code{fftw_export_wisdom_to_file}. This writes the wisdom to the
cannam@167 1728 current position in @code{output_file}, which should be open with
cannam@167 1729 write permission; upon exit, the file remains open and is positioned
cannam@167 1730 at the end of the wisdom data.
cannam@167 1731
cannam@167 1732 @code{fftw_export_wisdom_to_string} returns a pointer to a
cannam@167 1733 @code{NULL}-terminated string holding the wisdom data. This string is
cannam@167 1734 dynamically allocated, and it is the responsibility of the caller to
cannam@167 1735 deallocate it with @code{free} when it is no longer needed.
cannam@167 1736
cannam@167 1737 All of these routines export the wisdom in the same format, which we
cannam@167 1738 will not document here except to say that it is LISP-like ASCII text
cannam@167 1739 that is insensitive to white space.
cannam@167 1740
cannam@167 1741 @c =========>
cannam@167 1742 @node Wisdom Import, Forgetting Wisdom, Wisdom Export, Wisdom
cannam@167 1743 @subsection Wisdom Import
cannam@167 1744
cannam@167 1745 @example
cannam@167 1746 int fftw_import_system_wisdom(void);
cannam@167 1747 int fftw_import_wisdom_from_filename(const char *filename);
cannam@167 1748 int fftw_import_wisdom_from_string(const char *input_string);
cannam@167 1749 int fftw_import_wisdom(int (*read_char)(void *), void *data);
cannam@167 1750 @end example
cannam@167 1751 @findex fftw_import_wisdom
cannam@167 1752 @findex fftw_import_system_wisdom
cannam@167 1753 @findex fftw_import_wisdom_from_filename
cannam@167 1754 @findex fftw_import_wisdom_from_file
cannam@167 1755 @findex fftw_import_wisdom_from_string
cannam@167 1756
cannam@167 1757 These functions import wisdom into a program from data stored by the
cannam@167 1758 @code{fftw_export_wisdom} functions above. (@xref{Words of
cannam@167 1759 Wisdom-Saving Plans}.) The imported wisdom replaces any wisdom
cannam@167 1760 already accumulated by the running program.
cannam@167 1761
cannam@167 1762 @code{fftw_import_wisdom} imports wisdom from any input medium, as
cannam@167 1763 specified by the callback function @code{read_char}. @code{read_char} is
cannam@167 1764 a @code{getc}-like function that returns the next character in the
cannam@167 1765 input; its parameter is the @code{data} pointer passed to
cannam@167 1766 @code{fftw_import_wisdom}. If the end of the input data is reached
cannam@167 1767 (which should never happen for valid data), @code{read_char} should
cannam@167 1768 return @code{EOF} (as defined in @code{<stdio.h>}). For convenience,
cannam@167 1769 the following three ``wrapper'' routines are provided:
cannam@167 1770
cannam@167 1771 @code{fftw_import_wisdom_from_filename} reads wisdom from a file named
cannam@167 1772 @code{filename}. A lower-level function, which requires you to open
cannam@167 1773 and close the file yourself (e.g. if you want to read wisdom from a
cannam@167 1774 portion of a larger file) is @code{fftw_import_wisdom_from_file}. This
cannam@167 1775 reads wisdom from the current position in @code{input_file} (which
cannam@167 1776 should be open with read permission); upon exit, the file remains
cannam@167 1777 open, but the position of the read pointer is unspecified.
cannam@167 1778
cannam@167 1779 @code{fftw_import_wisdom_from_string} reads wisdom from the
cannam@167 1780 @code{NULL}-terminated string @code{input_string}.
cannam@167 1781
cannam@167 1782 @code{fftw_import_system_wisdom} reads wisdom from an
cannam@167 1783 implementation-defined standard file (@code{/etc/fftw/wisdom} on Unix
cannam@167 1784 and GNU systems).
cannam@167 1785 @cindex wisdom, system-wide
cannam@167 1786
cannam@167 1787
cannam@167 1788 The return value of these import routines is @code{1} if the wisdom was
cannam@167 1789 read successfully and @code{0} otherwise. Note that, in all of these
cannam@167 1790 functions, any data in the input stream past the end of the wisdom data
cannam@167 1791 is simply ignored.
cannam@167 1792
cannam@167 1793 @c =========>
cannam@167 1794 @node Forgetting Wisdom, Wisdom Utilities, Wisdom Import, Wisdom
cannam@167 1795 @subsection Forgetting Wisdom
cannam@167 1796
cannam@167 1797 @example
cannam@167 1798 void fftw_forget_wisdom(void);
cannam@167 1799 @end example
cannam@167 1800 @findex fftw_forget_wisdom
cannam@167 1801
cannam@167 1802 Calling @code{fftw_forget_wisdom} causes all accumulated @code{wisdom}
cannam@167 1803 to be discarded and its associated memory to be freed. (New
cannam@167 1804 @code{wisdom} can still be gathered subsequently, however.)
cannam@167 1805
cannam@167 1806 @c =========>
cannam@167 1807 @node Wisdom Utilities, , Forgetting Wisdom, Wisdom
cannam@167 1808 @subsection Wisdom Utilities
cannam@167 1809
cannam@167 1810 FFTW includes two standalone utility programs that deal with wisdom. We
cannam@167 1811 merely summarize them here, since they come with their own @code{man}
cannam@167 1812 pages for Unix and GNU systems (with HTML versions on our web site).
cannam@167 1813
cannam@167 1814 The first program is @code{fftw-wisdom} (or @code{fftwf-wisdom} in
cannam@167 1815 single precision, etcetera), which can be used to create a wisdom file
cannam@167 1816 containing plans for any of the transform sizes and types supported by
cannam@167 1817 FFTW. It is preferable to create wisdom directly from your executable
cannam@167 1818 (@pxref{Caveats in Using Wisdom}), but this program is useful for
cannam@167 1819 creating global wisdom files for @code{fftw_import_system_wisdom}.
cannam@167 1820 @cindex fftw-wisdom utility
cannam@167 1821
cannam@167 1822
cannam@167 1823 The second program is @code{fftw-wisdom-to-conf}, which takes a wisdom
cannam@167 1824 file as input and produces a @dfn{configuration routine} as output. The
cannam@167 1825 latter is a C subroutine that you can compile and link into your
cannam@167 1826 program, replacing a routine of the same name in the FFTW library, that
cannam@167 1827 determines which parts of FFTW are callable by your program.
cannam@167 1828 @code{fftw-wisdom-to-conf} produces a configuration routine that links
cannam@167 1829 to only those parts of FFTW needed by the saved plans in the wisdom,
cannam@167 1830 greatly reducing the size of statically linked executables (which should
cannam@167 1831 only attempt to create plans corresponding to those in the wisdom,
cannam@167 1832 however).
cannam@167 1833 @cindex fftw-wisdom-to-conf utility
cannam@167 1834 @cindex configuration routines
cannam@167 1835
cannam@167 1836 @c ------------------------------------------------------------
cannam@167 1837 @node What FFTW Really Computes, , Wisdom, FFTW Reference
cannam@167 1838 @section What FFTW Really Computes
cannam@167 1839
cannam@167 1840 In this section, we provide precise mathematical definitions for the
cannam@167 1841 transforms that FFTW computes. These transform definitions are fairly
cannam@167 1842 standard, but some authors follow slightly different conventions for the
cannam@167 1843 normalization of the transform (the constant factor in front) and the
cannam@167 1844 sign of the complex exponent. We begin by presenting the
cannam@167 1845 one-dimensional (1d) transform definitions, and then give the
cannam@167 1846 straightforward extension to multi-dimensional transforms.
cannam@167 1847
cannam@167 1848 @menu
cannam@167 1849 * The 1d Discrete Fourier Transform (DFT)::
cannam@167 1850 * The 1d Real-data DFT::
cannam@167 1851 * 1d Real-even DFTs (DCTs)::
cannam@167 1852 * 1d Real-odd DFTs (DSTs)::
cannam@167 1853 * 1d Discrete Hartley Transforms (DHTs)::
cannam@167 1854 * Multi-dimensional Transforms::
cannam@167 1855 @end menu
cannam@167 1856
cannam@167 1857 @c =========>
cannam@167 1858 @node The 1d Discrete Fourier Transform (DFT), The 1d Real-data DFT, What FFTW Really Computes, What FFTW Really Computes
cannam@167 1859 @subsection The 1d Discrete Fourier Transform (DFT)
cannam@167 1860
cannam@167 1861 @cindex discrete Fourier transform
cannam@167 1862 @cindex DFT
cannam@167 1863 The forward (@code{FFTW_FORWARD}) discrete Fourier transform (DFT) of a
cannam@167 1864 1d complex array @math{X} of size @math{n} computes an array @math{Y},
cannam@167 1865 where:
cannam@167 1866 @tex
cannam@167 1867 $$
cannam@167 1868 Y_k = \sum_{j = 0}^{n - 1} X_j e^{-2\pi j k \sqrt{-1}/n} \ .
cannam@167 1869 $$
cannam@167 1870 @end tex
cannam@167 1871 @ifinfo
cannam@167 1872 @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(-2 pi j k sqrt(-1)/n) .
cannam@167 1873 @end ifinfo
cannam@167 1874 @html
cannam@167 1875 <center><img src="equation-dft.png" align="top">.</center>
cannam@167 1876 @end html
cannam@167 1877 The backward (@code{FFTW_BACKWARD}) DFT computes:
cannam@167 1878 @tex
cannam@167 1879 $$
cannam@167 1880 Y_k = \sum_{j = 0}^{n - 1} X_j e^{2\pi j k \sqrt{-1}/n} \ .
cannam@167 1881 $$
cannam@167 1882 @end tex
cannam@167 1883 @ifinfo
cannam@167 1884 @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(2 pi j k sqrt(-1)/n) .
cannam@167 1885 @end ifinfo
cannam@167 1886 @html
cannam@167 1887 <center><img src="equation-idft.png" align="top">.</center>
cannam@167 1888 @end html
cannam@167 1889
cannam@167 1890 @cindex normalization
cannam@167 1891 FFTW computes an unnormalized transform, in that there is no coefficient
cannam@167 1892 in front of the summation in the DFT. In other words, applying the
cannam@167 1893 forward and then the backward transform will multiply the input by
cannam@167 1894 @math{n}.
cannam@167 1895
cannam@167 1896 @cindex frequency
cannam@167 1897 From above, an @code{FFTW_FORWARD} transform corresponds to a sign of
cannam@167 1898 @math{-1} in the exponent of the DFT. Note also that we use the
cannam@167 1899 standard ``in-order'' output ordering---the @math{k}-th output
cannam@167 1900 corresponds to the frequency @math{k/n} (or @math{k/T}, where @math{T}
cannam@167 1901 is your total sampling period). For those who like to think in terms of
cannam@167 1902 positive and negative frequencies, this means that the positive
cannam@167 1903 frequencies are stored in the first half of the output and the negative
cannam@167 1904 frequencies are stored in backwards order in the second half of the
cannam@167 1905 output. (The frequency @math{-k/n} is the same as the frequency
cannam@167 1906 @math{(n-k)/n}.)
cannam@167 1907
cannam@167 1908 @c =========>
cannam@167 1909 @node The 1d Real-data DFT, 1d Real-even DFTs (DCTs), The 1d Discrete Fourier Transform (DFT), What FFTW Really Computes
cannam@167 1910 @subsection The 1d Real-data DFT
cannam@167 1911
cannam@167 1912 The real-input (r2c) DFT in FFTW computes the @emph{forward} transform
cannam@167 1913 @math{Y} of the size @code{n} real array @math{X}, exactly as defined
cannam@167 1914 above, i.e.
cannam@167 1915 @tex
cannam@167 1916 $$
cannam@167 1917 Y_k = \sum_{j = 0}^{n - 1} X_j e^{-2\pi j k \sqrt{-1}/n} \ .
cannam@167 1918 $$
cannam@167 1919 @end tex
cannam@167 1920 @ifinfo
cannam@167 1921 @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(-2 pi j k sqrt(-1)/n) .
cannam@167 1922 @end ifinfo
cannam@167 1923 @html
cannam@167 1924 <center><img src="equation-dft.png" align="top">.</center>
cannam@167 1925 @end html
cannam@167 1926 This output array @math{Y} can easily be shown to possess the
cannam@167 1927 ``Hermitian'' symmetry
cannam@167 1928 @cindex Hermitian
cannam@167 1929 @tex
cannam@167 1930 $Y_k = Y_{n-k}^*$,
cannam@167 1931 @end tex
cannam@167 1932 @ifinfo
cannam@167 1933 Y[k] = Y[n-k]*,
cannam@167 1934 @end ifinfo
cannam@167 1935 @html
cannam@167 1936 <i>Y<sub>k</sub> = Y<sub>n-k</sub></i><sup>*</sup>,
cannam@167 1937 @end html
cannam@167 1938 where we take @math{Y} to be periodic so that
cannam@167 1939 @tex
cannam@167 1940 $Y_n = Y_0$.
cannam@167 1941 @end tex
cannam@167 1942 @ifinfo
cannam@167 1943 Y[n] = Y[0].
cannam@167 1944 @end ifinfo
cannam@167 1945 @html
cannam@167 1946 <i>Y<sub>n</sub> = Y</i><sub>0</sub>.
cannam@167 1947 @end html
cannam@167 1948
cannam@167 1949 As a result of this symmetry, half of the output @math{Y} is redundant
cannam@167 1950 (being the complex conjugate of the other half), and so the 1d r2c
cannam@167 1951 transforms only output elements @math{0}@dots{}@math{n/2} of @math{Y}
cannam@167 1952 (@math{n/2+1} complex numbers), where the division by @math{2} is
cannam@167 1953 rounded down.
cannam@167 1954
cannam@167 1955 Moreover, the Hermitian symmetry implies that
cannam@167 1956 @tex
cannam@167 1957 $Y_0$
cannam@167 1958 @end tex
cannam@167 1959 @ifinfo
cannam@167 1960 Y[0]
cannam@167 1961 @end ifinfo
cannam@167 1962 @html
cannam@167 1963 <i>Y</i><sub>0</sub>
cannam@167 1964 @end html
cannam@167 1965 and, if @math{n} is even, the
cannam@167 1966 @tex
cannam@167 1967 $Y_{n/2}$
cannam@167 1968 @end tex
cannam@167 1969 @ifinfo
cannam@167 1970 Y[n/2]
cannam@167 1971 @end ifinfo
cannam@167 1972 @html
cannam@167 1973 <i>Y</i><sub><i>n</i>/2</sub>
cannam@167 1974 @end html
cannam@167 1975 element, are purely real. So, for the @code{R2HC} r2r transform, the
cannam@167 1976 halfcomplex format does not store the imaginary parts of these elements.
cannam@167 1977 @cindex r2r
cannam@167 1978 @ctindex R2HC
cannam@167 1979 @cindex halfcomplex format
cannam@167 1980
cannam@167 1981
cannam@167 1982 The c2r and @code{H2RC} r2r transforms compute the backward DFT of the
cannam@167 1983 @emph{complex} array @math{X} with Hermitian symmetry, stored in the
cannam@167 1984 r2c/@code{R2HC} output formats, respectively, where the backward
cannam@167 1985 transform is defined exactly as for the complex case:
cannam@167 1986 @tex
cannam@167 1987 $$
cannam@167 1988 Y_k = \sum_{j = 0}^{n - 1} X_j e^{2\pi j k \sqrt{-1}/n} \ .
cannam@167 1989 $$
cannam@167 1990 @end tex
cannam@167 1991 @ifinfo
cannam@167 1992 @center Y[k] = sum for j = 0 to (n - 1) of X[j] * exp(2 pi j k sqrt(-1)/n) .
cannam@167 1993 @end ifinfo
cannam@167 1994 @html
cannam@167 1995 <center><img src="equation-idft.png" align="top">.</center>
cannam@167 1996 @end html
cannam@167 1997 The outputs @code{Y} of this transform can easily be seen to be purely
cannam@167 1998 real, and are stored as an array of real numbers.
cannam@167 1999
cannam@167 2000 @cindex normalization
cannam@167 2001 Like FFTW's complex DFT, these transforms are unnormalized. In other
cannam@167 2002 words, applying the real-to-complex (forward) and then the
cannam@167 2003 complex-to-real (backward) transform will multiply the input by
cannam@167 2004 @math{n}.
cannam@167 2005
cannam@167 2006 @c =========>
cannam@167 2007 @node 1d Real-even DFTs (DCTs), 1d Real-odd DFTs (DSTs), The 1d Real-data DFT, What FFTW Really Computes
cannam@167 2008 @subsection 1d Real-even DFTs (DCTs)
cannam@167 2009
cannam@167 2010 The Real-even symmetry DFTs in FFTW are exactly equivalent to the unnormalized
cannam@167 2011 forward (and backward) DFTs as defined above, where the input array
cannam@167 2012 @math{X} of length @math{N} is purely real and is also @dfn{even} symmetry. In
cannam@167 2013 this case, the output array is likewise real and even symmetry.
cannam@167 2014 @cindex real-even DFT
cannam@167 2015 @cindex REDFT
cannam@167 2016
cannam@167 2017
cannam@167 2018 @ctindex REDFT00
cannam@167 2019 For the case of @code{REDFT00}, this even symmetry means that
cannam@167 2020 @tex
cannam@167 2021 $X_j = X_{N-j}$,
cannam@167 2022 @end tex
cannam@167 2023 @ifinfo
cannam@167 2024 X[j] = X[N-j],
cannam@167 2025 @end ifinfo
cannam@167 2026 @html
cannam@167 2027 <i>X<sub>j</sub> = X<sub>N-j</sub></i>,
cannam@167 2028 @end html
cannam@167 2029 where we take @math{X} to be periodic so that
cannam@167 2030 @tex
cannam@167 2031 $X_N = X_0$.
cannam@167 2032 @end tex
cannam@167 2033 @ifinfo
cannam@167 2034 X[N] = X[0].
cannam@167 2035 @end ifinfo
cannam@167 2036 @html
cannam@167 2037 <i>X<sub>N</sub> = X</i><sub>0</sub>.
cannam@167 2038 @end html
cannam@167 2039 Because of this redundancy, only the first @math{n} real numbers are
cannam@167 2040 actually stored, where @math{N = 2(n-1)}.
cannam@167 2041
cannam@167 2042 The proper definition of even symmetry for @code{REDFT10},
cannam@167 2043 @code{REDFT01}, and @code{REDFT11} transforms is somewhat more intricate
cannam@167 2044 because of the shifts by @math{1/2} of the input and/or output, although
cannam@167 2045 the corresponding boundary conditions are given in @ref{Real even/odd
cannam@167 2046 DFTs (cosine/sine transforms)}. Because of the even symmetry, however,
cannam@167 2047 the sine terms in the DFT all cancel and the remaining cosine terms are
cannam@167 2048 written explicitly below. This formulation often leads people to call
cannam@167 2049 such a transform a @dfn{discrete cosine transform} (DCT), although it is
cannam@167 2050 really just a special case of the DFT.
cannam@167 2051 @cindex discrete cosine transform
cannam@167 2052 @cindex DCT
cannam@167 2053
cannam@167 2054
cannam@167 2055 In each of the definitions below, we transform a real array @math{X} of
cannam@167 2056 length @math{n} to a real array @math{Y} of length @math{n}:
cannam@167 2057
cannam@167 2058 @subsubheading REDFT00 (DCT-I)
cannam@167 2059 @ctindex REDFT00
cannam@167 2060 An @code{REDFT00} transform (type-I DCT) in FFTW is defined by:
cannam@167 2061 @tex
cannam@167 2062 $$
cannam@167 2063 Y_k = X_0 + (-1)^k X_{n-1}
cannam@167 2064 + 2 \sum_{j=1}^{n-2} X_j \cos [ \pi j k / (n-1)].
cannam@167 2065 $$
cannam@167 2066 @end tex
cannam@167 2067 @ifinfo
cannam@167 2068 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@167 2069 @end ifinfo
cannam@167 2070 @html
cannam@167 2071 <center><img src="equation-redft00.png" align="top">.</center>
cannam@167 2072 @end html
cannam@167 2073 Note that this transform is not defined for @math{n=1}. For @math{n=2},
cannam@167 2074 the summation term above is dropped as you might expect.
cannam@167 2075
cannam@167 2076 @subsubheading REDFT10 (DCT-II)
cannam@167 2077 @ctindex REDFT10
cannam@167 2078 An @code{REDFT10} transform (type-II DCT, sometimes called ``the'' DCT) in FFTW is defined by:
cannam@167 2079 @tex
cannam@167 2080 $$
cannam@167 2081 Y_k = 2 \sum_{j=0}^{n-1} X_j \cos [\pi (j+1/2) k / n].
cannam@167 2082 $$
cannam@167 2083 @end tex
cannam@167 2084 @ifinfo
cannam@167 2085 Y[k] = 2 (sum for j = 0 to n-1 of X[j] cos(pi (j+1/2) k / n)).
cannam@167 2086 @end ifinfo
cannam@167 2087 @html
cannam@167 2088 <center><img src="equation-redft10.png" align="top">.</center>
cannam@167 2089 @end html
cannam@167 2090
cannam@167 2091 @subsubheading REDFT01 (DCT-III)
cannam@167 2092 @ctindex REDFT01
cannam@167 2093 An @code{REDFT01} transform (type-III DCT) in FFTW is defined by:
cannam@167 2094 @tex
cannam@167 2095 $$
cannam@167 2096 Y_k = X_0 + 2 \sum_{j=1}^{n-1} X_j \cos [\pi j (k+1/2) / n].
cannam@167 2097 $$
cannam@167 2098 @end tex
cannam@167 2099 @ifinfo
cannam@167 2100 Y[k] = X[0] + 2 (sum for j = 1 to n-1 of X[j] cos(pi j (k+1/2) / n)).
cannam@167 2101 @end ifinfo
cannam@167 2102 @html
cannam@167 2103 <center><img src="equation-redft01.png" align="top">.</center>
cannam@167 2104 @end html
cannam@167 2105 In the case of @math{n=1}, this reduces to
cannam@167 2106 @tex
cannam@167 2107 $Y_0 = X_0$.
cannam@167 2108 @end tex
cannam@167 2109 @ifinfo
cannam@167 2110 Y[0] = X[0].
cannam@167 2111 @end ifinfo
cannam@167 2112 @html
cannam@167 2113 <i>Y</i><sub>0</sub> = <i>X</i><sub>0</sub>.
cannam@167 2114 @end html
cannam@167 2115 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@167 2116 @cindex IDCT
cannam@167 2117
cannam@167 2118 @subsubheading REDFT11 (DCT-IV)
cannam@167 2119 @ctindex REDFT11
cannam@167 2120 An @code{REDFT11} transform (type-IV DCT) in FFTW is defined by:
cannam@167 2121 @tex
cannam@167 2122 $$
cannam@167 2123 Y_k = 2 \sum_{j=0}^{n-1} X_j \cos [\pi (j+1/2) (k+1/2) / n].
cannam@167 2124 $$
cannam@167 2125 @end tex
cannam@167 2126 @ifinfo
cannam@167 2127 Y[k] = 2 (sum for j = 0 to n-1 of X[j] cos(pi (j+1/2) (k+1/2) / n)).
cannam@167 2128 @end ifinfo
cannam@167 2129 @html
cannam@167 2130 <center><img src="equation-redft11.png" align="top">.</center>
cannam@167 2131 @end html
cannam@167 2132
cannam@167 2133 @subsubheading Inverses and Normalization
cannam@167 2134
cannam@167 2135 These definitions correspond directly to the unnormalized DFTs used
cannam@167 2136 elsewhere in FFTW (hence the factors of @math{2} in front of the
cannam@167 2137 summations). The unnormalized inverse of @code{REDFT00} is
cannam@167 2138 @code{REDFT00}, of @code{REDFT10} is @code{REDFT01} and vice versa, and
cannam@167 2139 of @code{REDFT11} is @code{REDFT11}. Each unnormalized inverse results
cannam@167 2140 in the original array multiplied by @math{N}, where @math{N} is the
cannam@167 2141 @emph{logical} DFT size. For @code{REDFT00}, @math{N=2(n-1)} (note that
cannam@167 2142 @math{n=1} is not defined); otherwise, @math{N=2n}.
cannam@167 2143 @cindex normalization
cannam@167 2144
cannam@167 2145
cannam@167 2146 In defining the discrete cosine transform, some authors also include
cannam@167 2147 additional factors of
cannam@167 2148 @ifinfo
cannam@167 2149 sqrt(2)
cannam@167 2150 @end ifinfo
cannam@167 2151 @html
cannam@167 2152 &radic;2
cannam@167 2153 @end html
cannam@167 2154 @tex
cannam@167 2155 $\sqrt{2}$
cannam@167 2156 @end tex
cannam@167 2157 (or its inverse) multiplying selected inputs and/or outputs. This is a
cannam@167 2158 mostly cosmetic change that makes the transform orthogonal, but
cannam@167 2159 sacrifices the direct equivalence to a symmetric DFT.
cannam@167 2160
cannam@167 2161 @c =========>
cannam@167 2162 @node 1d Real-odd DFTs (DSTs), 1d Discrete Hartley Transforms (DHTs), 1d Real-even DFTs (DCTs), What FFTW Really Computes
cannam@167 2163 @subsection 1d Real-odd DFTs (DSTs)
cannam@167 2164
cannam@167 2165 The Real-odd symmetry DFTs in FFTW are exactly equivalent to the unnormalized
cannam@167 2166 forward (and backward) DFTs as defined above, where the input array
cannam@167 2167 @math{X} of length @math{N} is purely real and is also @dfn{odd} symmetry. In
cannam@167 2168 this case, the output is odd symmetry and purely imaginary.
cannam@167 2169 @cindex real-odd DFT
cannam@167 2170 @cindex RODFT
cannam@167 2171
cannam@167 2172
cannam@167 2173 @ctindex RODFT00
cannam@167 2174 For the case of @code{RODFT00}, this odd symmetry means that
cannam@167 2175 @tex
cannam@167 2176 $X_j = -X_{N-j}$,
cannam@167 2177 @end tex
cannam@167 2178 @ifinfo
cannam@167 2179 X[j] = -X[N-j],
cannam@167 2180 @end ifinfo
cannam@167 2181 @html
cannam@167 2182 <i>X<sub>j</sub> = -X<sub>N-j</sub></i>,
cannam@167 2183 @end html
cannam@167 2184 where we take @math{X} to be periodic so that
cannam@167 2185 @tex
cannam@167 2186 $X_N = X_0$.
cannam@167 2187 @end tex
cannam@167 2188 @ifinfo
cannam@167 2189 X[N] = X[0].
cannam@167 2190 @end ifinfo
cannam@167 2191 @html
cannam@167 2192 <i>X<sub>N</sub> = X</i><sub>0</sub>.
cannam@167 2193 @end html
cannam@167 2194 Because of this redundancy, only the first @math{n} real numbers
cannam@167 2195 starting at @math{j=1} are actually stored (the @math{j=0} element is
cannam@167 2196 zero), where @math{N = 2(n+1)}.
cannam@167 2197
cannam@167 2198 The proper definition of odd symmetry for @code{RODFT10},
cannam@167 2199 @code{RODFT01}, and @code{RODFT11} transforms is somewhat more intricate
cannam@167 2200 because of the shifts by @math{1/2} of the input and/or output, although
cannam@167 2201 the corresponding boundary conditions are given in @ref{Real even/odd
cannam@167 2202 DFTs (cosine/sine transforms)}. Because of the odd symmetry, however,
cannam@167 2203 the cosine terms in the DFT all cancel and the remaining sine terms are
cannam@167 2204 written explicitly below. This formulation often leads people to call
cannam@167 2205 such a transform a @dfn{discrete sine transform} (DST), although it is
cannam@167 2206 really just a special case of the DFT.
cannam@167 2207 @cindex discrete sine transform
cannam@167 2208 @cindex DST
cannam@167 2209
cannam@167 2210
cannam@167 2211 In each of the definitions below, we transform a real array @math{X} of
cannam@167 2212 length @math{n} to a real array @math{Y} of length @math{n}:
cannam@167 2213
cannam@167 2214 @subsubheading RODFT00 (DST-I)
cannam@167 2215 @ctindex RODFT00
cannam@167 2216 An @code{RODFT00} transform (type-I DST) in FFTW is defined by:
cannam@167 2217 @tex
cannam@167 2218 $$
cannam@167 2219 Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [ \pi (j+1) (k+1) / (n+1)].
cannam@167 2220 $$
cannam@167 2221 @end tex
cannam@167 2222 @ifinfo
cannam@167 2223 Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1)(k+1) / (n+1))).
cannam@167 2224 @end ifinfo
cannam@167 2225 @html
cannam@167 2226 <center><img src="equation-rodft00.png" align="top">.</center>
cannam@167 2227 @end html
cannam@167 2228
cannam@167 2229 @subsubheading RODFT10 (DST-II)
cannam@167 2230 @ctindex RODFT10
cannam@167 2231 An @code{RODFT10} transform (type-II DST) in FFTW is defined by:
cannam@167 2232 @tex
cannam@167 2233 $$
cannam@167 2234 Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [\pi (j+1/2) (k+1) / n].
cannam@167 2235 $$
cannam@167 2236 @end tex
cannam@167 2237 @ifinfo
cannam@167 2238 Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1/2) (k+1) / n)).
cannam@167 2239 @end ifinfo
cannam@167 2240 @html
cannam@167 2241 <center><img src="equation-rodft10.png" align="top">.</center>
cannam@167 2242 @end html
cannam@167 2243
cannam@167 2244 @subsubheading RODFT01 (DST-III)
cannam@167 2245 @ctindex RODFT01
cannam@167 2246 An @code{RODFT01} transform (type-III DST) in FFTW is defined by:
cannam@167 2247 @tex
cannam@167 2248 $$
cannam@167 2249 Y_k = (-1)^k X_{n-1} + 2 \sum_{j=0}^{n-2} X_j \sin [\pi (j+1) (k+1/2) / n].
cannam@167 2250 $$
cannam@167 2251 @end tex
cannam@167 2252 @ifinfo
cannam@167 2253 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@167 2254 @end ifinfo
cannam@167 2255 @html
cannam@167 2256 <center><img src="equation-rodft01.png" align="top">.</center>
cannam@167 2257 @end html
cannam@167 2258 In the case of @math{n=1}, this reduces to
cannam@167 2259 @tex
cannam@167 2260 $Y_0 = X_0$.
cannam@167 2261 @end tex
cannam@167 2262 @ifinfo
cannam@167 2263 Y[0] = X[0].
cannam@167 2264 @end ifinfo
cannam@167 2265 @html
cannam@167 2266 <i>Y</i><sub>0</sub> = <i>X</i><sub>0</sub>.
cannam@167 2267 @end html
cannam@167 2268
cannam@167 2269 @subsubheading RODFT11 (DST-IV)
cannam@167 2270 @ctindex RODFT11
cannam@167 2271 An @code{RODFT11} transform (type-IV DST) in FFTW is defined by:
cannam@167 2272 @tex
cannam@167 2273 $$
cannam@167 2274 Y_k = 2 \sum_{j=0}^{n-1} X_j \sin [\pi (j+1/2) (k+1/2) / n].
cannam@167 2275 $$
cannam@167 2276 @end tex
cannam@167 2277 @ifinfo
cannam@167 2278 Y[k] = 2 (sum for j = 0 to n-1 of X[j] sin(pi (j+1/2) (k+1/2) / n)).
cannam@167 2279 @end ifinfo
cannam@167 2280 @html
cannam@167 2281 <center><img src="equation-rodft11.png" align="top">.</center>
cannam@167 2282 @end html
cannam@167 2283
cannam@167 2284 @subsubheading Inverses and Normalization
cannam@167 2285
cannam@167 2286 These definitions correspond directly to the unnormalized DFTs used
cannam@167 2287 elsewhere in FFTW (hence the factors of @math{2} in front of the
cannam@167 2288 summations). The unnormalized inverse of @code{RODFT00} is
cannam@167 2289 @code{RODFT00}, of @code{RODFT10} is @code{RODFT01} and vice versa, and
cannam@167 2290 of @code{RODFT11} is @code{RODFT11}. Each unnormalized inverse results
cannam@167 2291 in the original array multiplied by @math{N}, where @math{N} is the
cannam@167 2292 @emph{logical} DFT size. For @code{RODFT00}, @math{N=2(n+1)};
cannam@167 2293 otherwise, @math{N=2n}.
cannam@167 2294 @cindex normalization
cannam@167 2295
cannam@167 2296
cannam@167 2297 In defining the discrete sine transform, some authors also include
cannam@167 2298 additional factors of
cannam@167 2299 @ifinfo
cannam@167 2300 sqrt(2)
cannam@167 2301 @end ifinfo
cannam@167 2302 @html
cannam@167 2303 &radic;2
cannam@167 2304 @end html
cannam@167 2305 @tex
cannam@167 2306 $\sqrt{2}$
cannam@167 2307 @end tex
cannam@167 2308 (or its inverse) multiplying selected inputs and/or outputs. This is a
cannam@167 2309 mostly cosmetic change that makes the transform orthogonal, but
cannam@167 2310 sacrifices the direct equivalence to an antisymmetric DFT.
cannam@167 2311
cannam@167 2312 @c =========>
cannam@167 2313 @node 1d Discrete Hartley Transforms (DHTs), Multi-dimensional Transforms, 1d Real-odd DFTs (DSTs), What FFTW Really Computes
cannam@167 2314 @subsection 1d Discrete Hartley Transforms (DHTs)
cannam@167 2315
cannam@167 2316 @cindex discrete Hartley transform
cannam@167 2317 @cindex DHT
cannam@167 2318 The discrete Hartley transform (DHT) of a 1d real array @math{X} of size
cannam@167 2319 @math{n} computes a real array @math{Y} of the same size, where:
cannam@167 2320 @tex
cannam@167 2321 $$
cannam@167 2322 Y_k = \sum_{j = 0}^{n - 1} X_j [ \cos(2\pi j k / n) + \sin(2\pi j k / n)].
cannam@167 2323 $$
cannam@167 2324 @end tex
cannam@167 2325 @ifinfo
cannam@167 2326 @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@167 2327 @end ifinfo
cannam@167 2328 @html
cannam@167 2329 <center><img src="equation-dht.png" align="top">.</center>
cannam@167 2330 @end html
cannam@167 2331
cannam@167 2332 @cindex normalization
cannam@167 2333 FFTW computes an unnormalized transform, in that there is no coefficient
cannam@167 2334 in front of the summation in the DHT. In other words, applying the
cannam@167 2335 transform twice (the DHT is its own inverse) will multiply the input by
cannam@167 2336 @math{n}.
cannam@167 2337
cannam@167 2338 @c =========>
cannam@167 2339 @node Multi-dimensional Transforms, , 1d Discrete Hartley Transforms (DHTs), What FFTW Really Computes
cannam@167 2340 @subsection Multi-dimensional Transforms
cannam@167 2341
cannam@167 2342 The multi-dimensional transforms of FFTW, in general, compute simply the
cannam@167 2343 separable product of the given 1d transform along each dimension of the
cannam@167 2344 array. Since each of these transforms is unnormalized, computing the
cannam@167 2345 forward followed by the backward/inverse multi-dimensional transform
cannam@167 2346 will result in the original array scaled by the product of the
cannam@167 2347 normalization factors for each dimension (e.g. the product of the
cannam@167 2348 dimension sizes, for a multi-dimensional DFT).
cannam@167 2349
cannam@167 2350 @tex
cannam@167 2351 As an explicit example, consider the following exact mathematical
cannam@167 2352 definition of our multi-dimensional DFT. Let $X$ be a $d$-dimensional
cannam@167 2353 complex array whose elements are $X[j_1, j_2, \ldots, j_d]$, where $0
cannam@167 2354 \leq j_s < n_s$ for all~$s \in \{ 1, 2, \ldots, d \}$. Let also
cannam@167 2355 $\omega_s = e^{2\pi \sqrt{-1}/n_s}$, for all ~$s \in \{ 1, 2, \ldots, d
cannam@167 2356 \}$.
cannam@167 2357
cannam@167 2358 The forward transform computes a complex array~$Y$, whose
cannam@167 2359 structure is the same as that of~$X$, defined by
cannam@167 2360
cannam@167 2361 $$
cannam@167 2362 Y[k_1, k_2, \ldots, k_d] =
cannam@167 2363 \sum_{j_1 = 0}^{n_1 - 1}
cannam@167 2364 \sum_{j_2 = 0}^{n_2 - 1}
cannam@167 2365 \cdots
cannam@167 2366 \sum_{j_d = 0}^{n_d - 1}
cannam@167 2367 X[j_1, j_2, \ldots, j_d]
cannam@167 2368 \omega_1^{-j_1 k_1}
cannam@167 2369 \omega_2^{-j_2 k_2}
cannam@167 2370 \cdots
cannam@167 2371 \omega_d^{-j_d k_d} \ .
cannam@167 2372 $$
cannam@167 2373
cannam@167 2374 The backward transform computes
cannam@167 2375 $$
cannam@167 2376 Y[k_1, k_2, \ldots, k_d] =
cannam@167 2377 \sum_{j_1 = 0}^{n_1 - 1}
cannam@167 2378 \sum_{j_2 = 0}^{n_2 - 1}
cannam@167 2379 \cdots
cannam@167 2380 \sum_{j_d = 0}^{n_d - 1}
cannam@167 2381 X[j_1, j_2, \ldots, j_d]
cannam@167 2382 \omega_1^{j_1 k_1}
cannam@167 2383 \omega_2^{j_2 k_2}
cannam@167 2384 \cdots
cannam@167 2385 \omega_d^{j_d k_d} \ .
cannam@167 2386 $$
cannam@167 2387
cannam@167 2388 Computing the forward transform followed by the backward transform
cannam@167 2389 will multiply the array by $\prod_{s=1}^{d} n_d$.
cannam@167 2390 @end tex
cannam@167 2391
cannam@167 2392 @cindex r2c
cannam@167 2393 The definition of FFTW's multi-dimensional DFT of real data (r2c)
cannam@167 2394 deserves special attention. In this case, we logically compute the full
cannam@167 2395 multi-dimensional DFT of the input data; since the input data are purely
cannam@167 2396 real, the output data have the Hermitian symmetry and therefore only one
cannam@167 2397 non-redundant half need be stored. More specifically, for an @ndims multi-dimensional real-input DFT, the full (logical) complex output array
cannam@167 2398 @tex
cannam@167 2399 $Y[k_0, k_1, \ldots, k_{d-1}]$
cannam@167 2400 @end tex
cannam@167 2401 @html
cannam@167 2402 <i>Y</i>[<i>k</i><sub>0</sub>, <i>k</i><sub>1</sub>, ...,
cannam@167 2403 <i>k</i><sub><i>d-1</i></sub>]
cannam@167 2404 @end html
cannam@167 2405 @ifinfo
cannam@167 2406 Y[k[0], k[1], ..., k[d-1]]
cannam@167 2407 @end ifinfo
cannam@167 2408 has the symmetry:
cannam@167 2409 @tex
cannam@167 2410 $$
cannam@167 2411 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@167 2412 $$
cannam@167 2413 @end tex
cannam@167 2414 @html
cannam@167 2415 <i>Y</i>[<i>k</i><sub>0</sub>, <i>k</i><sub>1</sub>, ...,
cannam@167 2416 <i>k</i><sub><i>d-1</i></sub>] = <i>Y</i>[<i>n</i><sub>0</sub> -
cannam@167 2417 <i>k</i><sub>0</sub>, <i>n</i><sub>1</sub> - <i>k</i><sub>1</sub>, ...,
cannam@167 2418 <i>n</i><sub><i>d-1</i></sub> - <i>k</i><sub><i>d-1</i></sub>]<sup>*</sup>
cannam@167 2419 @end html
cannam@167 2420 @ifinfo
cannam@167 2421 Y[k[0], k[1], ..., k[d-1]] = Y[n[0] - k[0], n[1] - k[1], ..., n[d-1] - k[d-1]]*
cannam@167 2422 @end ifinfo
cannam@167 2423 (where each dimension is periodic). Because of this symmetry, we only
cannam@167 2424 store the
cannam@167 2425 @tex
cannam@167 2426 $k_{d-1} = 0 \cdots n_{d-1}/2$
cannam@167 2427 @end tex
cannam@167 2428 @html
cannam@167 2429 <i>k</i><sub><i>d-1</i></sub> = 0...<i>n</i><sub><i>d-1</i></sub>/2+1
cannam@167 2430 @end html
cannam@167 2431 @ifinfo
cannam@167 2432 k[d-1] = 0...n[d-1]/2
cannam@167 2433 @end ifinfo
cannam@167 2434 elements of the @emph{last} dimension (division by @math{2} is rounded
cannam@167 2435 down). (We could instead have cut any other dimension in half, but the
cannam@167 2436 last dimension proved computationally convenient.) This results in the
cannam@167 2437 peculiar array format described in more detail by @ref{Real-data DFT
cannam@167 2438 Array Format}.
cannam@167 2439
cannam@167 2440 The multi-dimensional c2r transform is simply the unnormalized inverse
cannam@167 2441 of the r2c transform. i.e. it is the same as FFTW's complex backward
cannam@167 2442 multi-dimensional DFT, operating on a Hermitian input array in the
cannam@167 2443 peculiar format mentioned above and outputting a real array (since the
cannam@167 2444 DFT output is purely real).
cannam@167 2445
cannam@167 2446 We should remind the user that the separable product of 1d transforms
cannam@167 2447 along each dimension, as computed by FFTW, is not always the same thing
cannam@167 2448 as the usual multi-dimensional transform. A multi-dimensional
cannam@167 2449 @code{R2HC} (or @code{HC2R}) transform is not identical to the
cannam@167 2450 multi-dimensional DFT, requiring some post-processing to combine the
cannam@167 2451 requisite real and imaginary parts, as was described in @ref{The
cannam@167 2452 Halfcomplex-format DFT}. Likewise, FFTW's multidimensional
cannam@167 2453 @code{FFTW_DHT} r2r transform is not the same thing as the logical
cannam@167 2454 multi-dimensional discrete Hartley transform defined in the literature,
cannam@167 2455 as discussed in @ref{The Discrete Hartley Transform}.
cannam@167 2456