Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.5/doc/html/Reversing-array-dimensions.html @ 127:7867fa7e1b6b
Current fftw source
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 18 Oct 2016 13:40:26 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
126:4a7071416412 | 127:7867fa7e1b6b |
---|---|
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
2 <html> | |
3 <!-- This manual is for FFTW | |
4 (version 3.3.5, 30 July 2016). | |
5 | |
6 Copyright (C) 2003 Matteo Frigo. | |
7 | |
8 Copyright (C) 2003 Massachusetts Institute of Technology. | |
9 | |
10 Permission is granted to make and distribute verbatim copies of this | |
11 manual provided the copyright notice and this permission notice are | |
12 preserved on all copies. | |
13 | |
14 Permission is granted to copy and distribute modified versions of this | |
15 manual under the conditions for verbatim copying, provided that the | |
16 entire resulting derived work is distributed under the terms of a | |
17 permission notice identical to this one. | |
18 | |
19 Permission is granted to copy and distribute translations of this manual | |
20 into another language, under the above conditions for modified versions, | |
21 except that this permission notice may be stated in a translation | |
22 approved by the Free Software Foundation. --> | |
23 <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ --> | |
24 <head> | |
25 <title>FFTW 3.3.5: Reversing array dimensions</title> | |
26 | |
27 <meta name="description" content="FFTW 3.3.5: Reversing array dimensions"> | |
28 <meta name="keywords" content="FFTW 3.3.5: Reversing array dimensions"> | |
29 <meta name="resource-type" content="document"> | |
30 <meta name="distribution" content="global"> | |
31 <meta name="Generator" content="makeinfo"> | |
32 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
33 <link href="index.html#Top" rel="start" title="Top"> | |
34 <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> | |
35 <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> | |
36 <link href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran" rel="up" title="Calling FFTW from Modern Fortran"> | |
37 <link href="FFTW-Fortran-type-reference.html#FFTW-Fortran-type-reference" rel="next" title="FFTW Fortran type reference"> | |
38 <link href="Extended-and-quadruple-precision-in-Fortran.html#Extended-and-quadruple-precision-in-Fortran" rel="prev" title="Extended and quadruple precision in Fortran"> | |
39 <style type="text/css"> | |
40 <!-- | |
41 a.summary-letter {text-decoration: none} | |
42 blockquote.smallquotation {font-size: smaller} | |
43 div.display {margin-left: 3.2em} | |
44 div.example {margin-left: 3.2em} | |
45 div.indentedblock {margin-left: 3.2em} | |
46 div.lisp {margin-left: 3.2em} | |
47 div.smalldisplay {margin-left: 3.2em} | |
48 div.smallexample {margin-left: 3.2em} | |
49 div.smallindentedblock {margin-left: 3.2em; font-size: smaller} | |
50 div.smalllisp {margin-left: 3.2em} | |
51 kbd {font-style:oblique} | |
52 pre.display {font-family: inherit} | |
53 pre.format {font-family: inherit} | |
54 pre.menu-comment {font-family: serif} | |
55 pre.menu-preformatted {font-family: serif} | |
56 pre.smalldisplay {font-family: inherit; font-size: smaller} | |
57 pre.smallexample {font-size: smaller} | |
58 pre.smallformat {font-family: inherit; font-size: smaller} | |
59 pre.smalllisp {font-size: smaller} | |
60 span.nocodebreak {white-space:nowrap} | |
61 span.nolinebreak {white-space:nowrap} | |
62 span.roman {font-family:serif; font-weight:normal} | |
63 span.sansserif {font-family:sans-serif; font-weight:normal} | |
64 ul.no-bullet {list-style: none} | |
65 --> | |
66 </style> | |
67 | |
68 | |
69 </head> | |
70 | |
71 <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> | |
72 <a name="Reversing-array-dimensions"></a> | |
73 <div class="header"> | |
74 <p> | |
75 Next: <a href="FFTW-Fortran-type-reference.html#FFTW-Fortran-type-reference" accesskey="n" rel="next">FFTW Fortran type reference</a>, Previous: <a href="Overview-of-Fortran-interface.html#Overview-of-Fortran-interface" accesskey="p" rel="prev">Overview of Fortran interface</a>, Up: <a href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran" accesskey="u" rel="up">Calling FFTW from Modern Fortran</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> | |
76 </div> | |
77 <hr> | |
78 <a name="Reversing-array-dimensions-1"></a> | |
79 <h3 class="section">7.2 Reversing array dimensions</h3> | |
80 | |
81 <a name="index-row_002dmajor-6"></a> | |
82 <a name="index-column_002dmajor-1"></a> | |
83 <p>A minor annoyance in calling FFTW from Fortran is that FFTW’s array | |
84 dimensions are defined in the C convention (row-major order), while | |
85 Fortran’s array dimensions are the opposite convention (column-major | |
86 order). See <a href="Multi_002ddimensional-Array-Format.html#Multi_002ddimensional-Array-Format">Multi-dimensional Array Format</a>. This is just a | |
87 bookkeeping difference, with no effect on performance. The only | |
88 consequence of this is that, whenever you create an FFTW plan for a | |
89 multi-dimensional transform, you must always <em>reverse the | |
90 ordering of the dimensions</em>. | |
91 </p> | |
92 <p>For example, consider the three-dimensional (L × M × N) arrays: | |
93 </p> | |
94 <div class="example"> | |
95 <pre class="example"> complex(C_DOUBLE_COMPLEX), dimension(L,M,N) :: in, out | |
96 </pre></div> | |
97 | |
98 <p>To plan a DFT for these arrays using <code>fftw_plan_dft_3d</code>, you could do: | |
99 </p> | |
100 <a name="index-fftw_005fplan_005fdft_005f3d-2"></a> | |
101 <div class="example"> | |
102 <pre class="example"> plan = fftw_plan_dft_3d(N,M,L, in,out, FFTW_FORWARD,FFTW_ESTIMATE) | |
103 </pre></div> | |
104 | |
105 <p>That is, from FFTW’s perspective this is a N × M × L array. | |
106 <em>No data transposition need occur</em>, as this is <em>only | |
107 notation</em>. Similarly, to use the more generic routine | |
108 <code>fftw_plan_dft</code> with the same arrays, you could do: | |
109 </p> | |
110 <div class="example"> | |
111 <pre class="example"> integer(C_INT), dimension(3) :: n = [N,M,L] | |
112 plan = fftw_plan_dft_3d(3, n, in,out, FFTW_FORWARD,FFTW_ESTIMATE) | |
113 </pre></div> | |
114 | |
115 <p>Note, by the way, that this is different from the legacy Fortran | |
116 interface (see <a href="Fortran_002dinterface-routines.html#Fortran_002dinterface-routines">Fortran-interface routines</a>), which automatically | |
117 reverses the order of the array dimension for you. Here, you are | |
118 calling the C interface directly, so there is no “translation” layer. | |
119 </p> | |
120 <a name="index-r2c_002fc2r-multi_002ddimensional-array-format-2"></a> | |
121 <p>An important thing to keep in mind is the implication of this for | |
122 multidimensional real-to-complex transforms (see <a href="Multi_002dDimensional-DFTs-of-Real-Data.html#Multi_002dDimensional-DFTs-of-Real-Data">Multi-Dimensional DFTs of Real Data</a>). In C, a multidimensional real-to-complex DFT | |
123 chops the last dimension roughly in half (N × M × L real input | |
124 goes to N × M × L/2+1 complex output). In Fortran, because | |
125 the array dimension notation is reversed, the <em>first</em> dimension of | |
126 the complex data is chopped roughly in half. For example consider the | |
127 ‘<samp>r2c</samp>’ transform of L × M × N real input in Fortran: | |
128 </p> | |
129 <a name="index-fftw_005fplan_005fdft_005fr2c_005f3d-2"></a> | |
130 <a name="index-fftw_005fexecute_005fdft_005fr2c-1"></a> | |
131 <div class="example"> | |
132 <pre class="example"> type(C_PTR) :: plan | |
133 real(C_DOUBLE), dimension(L,M,N) :: in | |
134 complex(C_DOUBLE_COMPLEX), dimension(L/2+1,M,N) :: out | |
135 plan = fftw_plan_dft_r2c_3d(N,M,L, in,out, FFTW_ESTIMATE) | |
136 ... | |
137 call fftw_execute_dft_r2c(plan, in, out) | |
138 </pre></div> | |
139 | |
140 <a name="index-in_002dplace-9"></a> | |
141 <a name="index-padding-5"></a> | |
142 <p>Alternatively, for an in-place r2c transform, as described in the C | |
143 documentation we must <em>pad</em> the <em>first</em> dimension of the | |
144 real input with an extra two entries (which are ignored by FFTW) so as | |
145 to leave enough space for the complex output. The input is | |
146 <em>allocated</em> as a 2[L/2+1] × M × N array, even though only | |
147 L × M × N of it is actually used. In this example, we will | |
148 allocate the array as a pointer type, using ‘<samp>fftw_alloc</samp>’ to | |
149 ensure aligned memory for maximum performance (see <a href="Allocating-aligned-memory-in-Fortran.html#Allocating-aligned-memory-in-Fortran">Allocating aligned memory in Fortran</a>); this also makes it easy to reference the | |
150 same memory as both a real array and a complex array. | |
151 </p> | |
152 <a name="index-fftw_005falloc_005fcomplex-4"></a> | |
153 <a name="index-c_005ff_005fpointer"></a> | |
154 <div class="example"> | |
155 <pre class="example"> real(C_DOUBLE), pointer :: in(:,:,:) | |
156 complex(C_DOUBLE_COMPLEX), pointer :: out(:,:,:) | |
157 type(C_PTR) :: plan, data | |
158 data = fftw_alloc_complex(int((L/2+1) * M * N, C_SIZE_T)) | |
159 call c_f_pointer(data, in, [2*(L/2+1),M,N]) | |
160 call c_f_pointer(data, out, [L/2+1,M,N]) | |
161 plan = fftw_plan_dft_r2c_3d(N,M,L, in,out, FFTW_ESTIMATE) | |
162 ... | |
163 call fftw_execute_dft_r2c(plan, in, out) | |
164 ... | |
165 call fftw_destroy_plan(plan) | |
166 call fftw_free(data) | |
167 </pre></div> | |
168 | |
169 <hr> | |
170 <div class="header"> | |
171 <p> | |
172 Next: <a href="FFTW-Fortran-type-reference.html#FFTW-Fortran-type-reference" accesskey="n" rel="next">FFTW Fortran type reference</a>, Previous: <a href="Overview-of-Fortran-interface.html#Overview-of-Fortran-interface" accesskey="p" rel="prev">Overview of Fortran interface</a>, Up: <a href="Calling-FFTW-from-Modern-Fortran.html#Calling-FFTW-from-Modern-Fortran" accesskey="u" rel="up">Calling FFTW from Modern Fortran</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> | |
173 </div> | |
174 | |
175 | |
176 | |
177 </body> | |
178 </html> |