fftw.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /* fftw/fftw.h. Generated by configure. */
  2. /* -*- C -*- */
  3. /*******************************************************************************
  4. ! Copyright (c) 2003 Matteo Frigo
  5. ! Copyright (c) 2003 Massachusetts Institute of Technology
  6. !
  7. ! This program is distributed with permission
  8. !
  9. !*******************************************************************************/
  10. /* fftw.h -- system-wide definitions */
  11. #ifndef FFTW_H
  12. #define FFTW_H
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif /* __cplusplus */
  18. /* Define for using single precision */
  19. /*
  20. * If you can, use configure --enable-float instead of changing this
  21. * flag directly
  22. */
  23. /* #define FFTW_ENABLE_FLOAT 1 */
  24. /* our real numbers */
  25. #ifdef FFTW_ENABLE_FLOAT
  26. typedef float fftw_real;
  27. #else
  28. typedef double fftw_real;
  29. #endif
  30. /*********************************************
  31. * Complex numbers and operations
  32. *********************************************/
  33. typedef struct {
  34. fftw_real re, im;
  35. } fftw_complex;
  36. #define c_re(c) ((c).re)
  37. #define c_im(c) ((c).im)
  38. typedef enum {
  39. FFTW_FORWARD = -1, FFTW_BACKWARD = 1
  40. } fftw_direction;
  41. /* backward compatibility with FFTW-1.3 */
  42. typedef fftw_complex FFTW_COMPLEX;
  43. typedef fftw_real FFTW_REAL;
  44. #ifndef FFTW_1_0_COMPATIBILITY
  45. #define FFTW_1_0_COMPATIBILITY 0
  46. #endif
  47. #if FFTW_1_0_COMPATIBILITY
  48. /* backward compatibility with FFTW-1.0 */
  49. #define REAL fftw_real
  50. #define COMPLEX fftw_complex
  51. #endif
  52. /*********************************************
  53. * Success or failure status
  54. *********************************************/
  55. typedef enum {
  56. FFTW_SUCCESS = 0, FFTW_FAILURE = -1
  57. } fftw_status;
  58. /*********************************************
  59. * Codelets
  60. *********************************************/
  61. typedef void (fftw_notw_codelet)
  62. (const fftw_complex *, fftw_complex *, int, int);
  63. typedef void (fftw_twiddle_codelet)
  64. (fftw_complex *, const fftw_complex *, int,
  65. int, int);
  66. typedef void (fftw_generic_codelet)
  67. (fftw_complex *, const fftw_complex *, int,
  68. int, int, int);
  69. typedef void (fftw_real2hc_codelet)
  70. (const fftw_real *, fftw_real *, fftw_real *,
  71. int, int, int);
  72. typedef void (fftw_hc2real_codelet)
  73. (const fftw_real *, const fftw_real *,
  74. fftw_real *, int, int, int);
  75. typedef void (fftw_hc2hc_codelet)
  76. (fftw_real *, const fftw_complex *,
  77. int, int, int);
  78. typedef void (fftw_rgeneric_codelet)
  79. (fftw_real *, const fftw_complex *, int,
  80. int, int, int);
  81. /*********************************************
  82. * Configurations
  83. *********************************************/
  84. /*
  85. * A configuration is a database of all known codelets
  86. */
  87. enum fftw_node_type {
  88. FFTW_NOTW, FFTW_TWIDDLE, FFTW_GENERIC, FFTW_RADER,
  89. FFTW_REAL2HC, FFTW_HC2REAL, FFTW_HC2HC, FFTW_RGENERIC
  90. };
  91. /* description of a codelet */
  92. typedef struct {
  93. const char *name; /* name of the codelet */
  94. void (*codelet)(void); /* pointer to the codelet itself */
  95. int size; /* size of the codelet */
  96. fftw_direction dir; /* direction */
  97. enum fftw_node_type type; /* TWIDDLE or NO_TWIDDLE */
  98. int signature; /* unique id */
  99. int ntwiddle; /* number of twiddle factors */
  100. const int *twiddle_order; /*
  101. * array that determines the order
  102. * in which the codelet expects
  103. * the twiddle factors
  104. */
  105. } fftw_codelet_desc;
  106. /* On Win32, you need to do funny things to access global variables
  107. in shared libraries. Thanks to Andrew Sterian for this hack. */
  108. #ifdef HAVE_WIN32
  109. # if defined(BUILD_FFTW_DLL)
  110. # define DL_IMPORT(type) __declspec(dllexport) type
  111. # elif defined(USE_FFTW_DLL)
  112. # define DL_IMPORT(type) __declspec(dllimport) type
  113. # else
  114. # define DL_IMPORT(type) type
  115. # endif
  116. #else
  117. # define DL_IMPORT(type) type
  118. #endif
  119. extern DL_IMPORT(const char *) fftw_version;
  120. /*****************************
  121. * Plans
  122. *****************************/
  123. /*
  124. * A plan is a sequence of reductions to compute a FFT of
  125. * a given size. At each step, the FFT algorithm can:
  126. *
  127. * 1) apply a notw codelet, or
  128. * 2) recurse and apply a twiddle codelet, or
  129. * 3) apply the generic codelet.
  130. */
  131. /* structure that contains twiddle factors */
  132. typedef struct fftw_twiddle_struct {
  133. int n;
  134. const fftw_codelet_desc *cdesc;
  135. fftw_complex *twarray;
  136. struct fftw_twiddle_struct *next;
  137. int refcnt;
  138. } fftw_twiddle;
  139. typedef struct fftw_rader_data_struct {
  140. struct fftw_plan_struct *plan;
  141. fftw_complex *omega;
  142. int g, ginv;
  143. int p, flags, refcount;
  144. struct fftw_rader_data_struct *next;
  145. fftw_codelet_desc *cdesc;
  146. } fftw_rader_data;
  147. typedef void (fftw_rader_codelet)
  148. (fftw_complex *, const fftw_complex *, int,
  149. int, int, fftw_rader_data *);
  150. /* structure that holds all the data needed for a given step */
  151. typedef struct fftw_plan_node_struct {
  152. enum fftw_node_type type;
  153. union {
  154. /* nodes of type FFTW_NOTW */
  155. struct {
  156. int size;
  157. fftw_notw_codelet *codelet;
  158. const fftw_codelet_desc *codelet_desc;
  159. } notw;
  160. /* nodes of type FFTW_TWIDDLE */
  161. struct {
  162. int size;
  163. fftw_twiddle_codelet *codelet;
  164. fftw_twiddle *tw;
  165. struct fftw_plan_node_struct *recurse;
  166. const fftw_codelet_desc *codelet_desc;
  167. } twiddle;
  168. /* nodes of type FFTW_GENERIC */
  169. struct {
  170. int size;
  171. fftw_generic_codelet *codelet;
  172. fftw_twiddle *tw;
  173. struct fftw_plan_node_struct *recurse;
  174. } generic;
  175. /* nodes of type FFTW_RADER */
  176. struct {
  177. int size;
  178. fftw_rader_codelet *codelet;
  179. fftw_rader_data *rader_data;
  180. fftw_twiddle *tw;
  181. struct fftw_plan_node_struct *recurse;
  182. } rader;
  183. /* nodes of type FFTW_REAL2HC */
  184. struct {
  185. int size;
  186. fftw_real2hc_codelet *codelet;
  187. const fftw_codelet_desc *codelet_desc;
  188. } real2hc;
  189. /* nodes of type FFTW_HC2REAL */
  190. struct {
  191. int size;
  192. fftw_hc2real_codelet *codelet;
  193. const fftw_codelet_desc *codelet_desc;
  194. } hc2real;
  195. /* nodes of type FFTW_HC2HC */
  196. struct {
  197. int size;
  198. fftw_direction dir;
  199. fftw_hc2hc_codelet *codelet;
  200. fftw_twiddle *tw;
  201. struct fftw_plan_node_struct *recurse;
  202. const fftw_codelet_desc *codelet_desc;
  203. } hc2hc;
  204. /* nodes of type FFTW_RGENERIC */
  205. struct {
  206. int size;
  207. fftw_direction dir;
  208. fftw_rgeneric_codelet *codelet;
  209. fftw_twiddle *tw;
  210. struct fftw_plan_node_struct *recurse;
  211. } rgeneric;
  212. } nodeu;
  213. int refcnt;
  214. } fftw_plan_node;
  215. typedef enum {
  216. FFTW_NORMAL_RECURSE = 0,
  217. FFTW_VECTOR_RECURSE = 1
  218. } fftw_recurse_kind;
  219. struct fftw_plan_struct {
  220. int n;
  221. int refcnt;
  222. fftw_direction dir;
  223. int flags;
  224. int wisdom_signature;
  225. enum fftw_node_type wisdom_type;
  226. struct fftw_plan_struct *next;
  227. fftw_plan_node *root;
  228. double cost;
  229. fftw_recurse_kind recurse_kind;
  230. int vector_size;
  231. };
  232. typedef struct fftw_plan_struct *fftw_plan;
  233. /* flags for the planner */
  234. #define FFTW_ESTIMATE (0)
  235. #define FFTW_MEASURE (1)
  236. #define FFTW_OUT_OF_PLACE (0)
  237. #define FFTW_IN_PLACE (8)
  238. #define FFTW_USE_WISDOM (16)
  239. #define FFTW_THREADSAFE (128) /* guarantee plan is read-only so that the
  240. same plan can be used in parallel by
  241. multiple threads */
  242. #define FFTWND_FORCE_BUFFERED (256) /* internal flag, forces buffering
  243. in fftwnd transforms */
  244. #define FFTW_NO_VECTOR_RECURSE (512) /* internal flag, prevents use
  245. of vector recursion */
  246. extern fftw_plan fftw_create_plan_specific(int n, fftw_direction dir,
  247. int flags,
  248. fftw_complex *in, int istride,
  249. fftw_complex *out, int ostride);
  250. #define FFTW_HAS_PLAN_SPECIFIC
  251. extern fftw_plan fftw_create_plan(int n, fftw_direction dir, int flags);
  252. extern void fftw_print_plan(fftw_plan plan);
  253. extern void fftw_destroy_plan(fftw_plan plan);
  254. extern void fftw(fftw_plan plan, int howmany, fftw_complex *in, int istride,
  255. int idist, fftw_complex *out, int ostride, int odist);
  256. extern void fftw_one(fftw_plan plan, fftw_complex *in, fftw_complex *out);
  257. extern void fftw_die(const char *s);
  258. extern void *fftw_malloc(size_t n);
  259. extern void fftw_free(void *p);
  260. extern void fftw_check_memory_leaks(void);
  261. extern void fftw_print_max_memory_usage(void);
  262. typedef void *(*fftw_malloc_type_function) (size_t n);
  263. typedef void (*fftw_free_type_function) (void *p);
  264. typedef void (*fftw_die_type_function) (const char *errString);
  265. extern DL_IMPORT(fftw_malloc_type_function) fftw_malloc_hook;
  266. extern DL_IMPORT(fftw_free_type_function) fftw_free_hook;
  267. extern DL_IMPORT(fftw_die_type_function) fftw_die_hook;
  268. extern size_t fftw_sizeof_fftw_real(void);
  269. /* Wisdom: */
  270. /*
  271. * define this symbol so that users know we are using a version of FFTW
  272. * with wisdom
  273. */
  274. #define FFTW_HAS_WISDOM
  275. extern void fftw_forget_wisdom(void);
  276. extern void fftw_export_wisdom(void (*emitter) (char c, void *), void *data);
  277. extern fftw_status fftw_import_wisdom(int (*g) (void *), void *data);
  278. extern void fftw_export_wisdom_to_file(FILE *output_file);
  279. extern fftw_status fftw_import_wisdom_from_file(FILE *input_file);
  280. extern char *fftw_export_wisdom_to_string(void);
  281. extern fftw_status fftw_import_wisdom_from_string(const char *input_string);
  282. /*
  283. * define symbol so we know this function is available (it is not in
  284. * older FFTWs)
  285. */
  286. #define FFTW_HAS_FPRINT_PLAN
  287. extern void fftw_fprint_plan(FILE *f, fftw_plan plan);
  288. /*****************************
  289. * N-dimensional code
  290. *****************************/
  291. typedef struct {
  292. int is_in_place; /* 1 if for in-place FFTs, 0 otherwise */
  293. int rank; /*
  294. * the rank (number of dimensions) of the
  295. * array to be FFTed
  296. */
  297. int *n; /*
  298. * the dimensions of the array to the
  299. * FFTed
  300. */
  301. fftw_direction dir;
  302. int *n_before; /*
  303. * n_before[i] = product of n[j] for j < i
  304. */
  305. int *n_after; /* n_after[i] = product of n[j] for j > i */
  306. fftw_plan *plans; /* 1d fftw plans for each dimension */
  307. int nbuffers, nwork;
  308. fftw_complex *work; /*
  309. * work array big enough to hold
  310. * nbuffers+1 of the largest dimension
  311. * (has nwork elements)
  312. */
  313. } fftwnd_data;
  314. typedef fftwnd_data *fftwnd_plan;
  315. /* Initializing the FFTWND plan: */
  316. extern fftwnd_plan fftw2d_create_plan(int nx, int ny, fftw_direction dir,
  317. int flags);
  318. extern fftwnd_plan fftw3d_create_plan(int nx, int ny, int nz,
  319. fftw_direction dir, int flags);
  320. extern fftwnd_plan fftwnd_create_plan(int rank, const int *n,
  321. fftw_direction dir,
  322. int flags);
  323. extern fftwnd_plan fftw2d_create_plan_specific(int nx, int ny,
  324. fftw_direction dir,
  325. int flags,
  326. fftw_complex *in, int istride,
  327. fftw_complex *out, int ostride);
  328. extern fftwnd_plan fftw3d_create_plan_specific(int nx, int ny, int nz,
  329. fftw_direction dir, int flags,
  330. fftw_complex *in, int istride,
  331. fftw_complex *out, int ostride);
  332. extern fftwnd_plan fftwnd_create_plan_specific(int rank, const int *n,
  333. fftw_direction dir,
  334. int flags,
  335. fftw_complex *in, int istride,
  336. fftw_complex *out, int ostride);
  337. /* Freeing the FFTWND plan: */
  338. extern void fftwnd_destroy_plan(fftwnd_plan plan);
  339. /* Printing the plan: */
  340. extern void fftwnd_fprint_plan(FILE *f, fftwnd_plan p);
  341. extern void fftwnd_print_plan(fftwnd_plan p);
  342. #define FFTWND_HAS_PRINT_PLAN
  343. /* Computing the N-Dimensional FFT */
  344. extern void fftwnd(fftwnd_plan plan, int howmany,
  345. fftw_complex *in, int istride, int idist,
  346. fftw_complex *out, int ostride, int odist);
  347. extern void fftwnd_one(fftwnd_plan p, fftw_complex *in, fftw_complex *out);
  348. #ifdef __cplusplus
  349. } /* extern "C" */
  350. #endif /* __cplusplus */
  351. #endif /* FFTW_H */