Mercurial > hg > octave-lyh
annotate src/DLD-FUNCTIONS/fftw.cc @ 9583:8dc1531e2149
correctly save and restore LIBS and CPPFLAGS when checking for GraphicsMagick++
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 27 Aug 2009 15:49:51 -0400 |
parents | 0ce82753dd72 |
children | 40dfc0c99116 |
rev | line source |
---|---|
6228 | 1 /* |
2 | |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
9072
diff
changeset
|
3 Copyright (C) 2006, 2007, 2008, 2009 David Bateman |
6228 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
6228 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
6228 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <algorithm> | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9516
diff
changeset
|
28 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9516
diff
changeset
|
29 #include "oct-fftw.h" |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9516
diff
changeset
|
30 |
6228 | 31 #include "defun-dld.h" |
32 #include "error.h" | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9516
diff
changeset
|
33 #include "ov.h" |
6228 | 34 |
35 DEFUN_DLD (fftw, args, , | |
36 "-*- texinfo -*-\n\ | |
37 @deftypefn {Loadable Function} {@var{method} =} fftw ('planner')\n\ | |
38 @deftypefnx {Loadable Function} {} fftw ('planner', @var{method})\n\ | |
39 @deftypefnx {Loadable Function} {@var{wisdom} =} fftw ('dwisdom')\n\ | |
40 @deftypefnx {Loadable Function} {@var{wisdom} =} fftw ('dwisdom', @var{wisdom})\n\ | |
41 \n\ | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
42 Manage @sc{fftw} wisdom data. Wisdom data can be used to significantly\n\ |
7001 | 43 accelerate the calculation of the FFTs but implies an initial cost\n\ |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
44 in its calculation. When the @sc{fftw} libraries are initialized, they read\n\ |
8115
37c1bdb9805c
Clarify fftw documentation
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
45 a system wide wisdom file (typically in @file{/etc/fftw/wisdom}), allowing wisdom\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
46 to be shared between applications other than Octave. Alternatively, the\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
47 @code{fftw} function can be used to import wisdom. For example\n\ |
6228 | 48 \n\ |
49 @example\n\ | |
50 @var{wisdom} = fftw ('dwisdom')\n\ | |
51 @end example\n\ | |
52 \n\ | |
53 will save the existing wisdom used by Octave to the string @var{wisdom}.\n\ | |
8115
37c1bdb9805c
Clarify fftw documentation
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
54 This string can then be saved to a file and restored using the @code{save}\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
55 and @code{load} commands respectively. This existing wisdom can be reimported\n\ |
8115
37c1bdb9805c
Clarify fftw documentation
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
56 as follows\n\ |
6228 | 57 \n\ |
58 @example\n\ | |
59 fftw ('dwisdom', @var{wisdom})\n\ | |
60 @end example \n\ | |
61 \n\ | |
62 If @var{wisdom} is an empty matrix, then the wisdom used is cleared.\n\ | |
63 \n\ | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
64 During the calculation of Fourier transforms further wisdom is generated.\n\ |
6228 | 65 The fashion in which this wisdom is generated is equally controlled by\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
66 the @code{fftw} function. There are five different manners in which the\n\ |
6228 | 67 wisdom can be treated, these being\n\ |
68 \n\ | |
69 @table @asis\n\ | |
70 @item 'estimate'\n\ | |
71 This specifies that no run-time measurement of the optimal means of\n\ | |
72 calculating a particular is performed, and a simple heuristic is used\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
73 to pick a (probably sub-optimal) plan. The advantage of this method is\n\ |
6228 | 74 that there is little or no overhead in the generation of the plan, which\n\ |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
75 is appropriate for a Fourier transform that will be calculated once.\n\ |
6228 | 76 \n\ |
77 @item 'measure'\n\ | |
78 In this case a range of algorithms to perform the transform is considered\n\ | |
79 and the best is selected based on their execution time.\n\ | |
80 \n\ | |
81 @item 'patient'\n\ | |
82 This is like 'measure', but a wider range of algorithms is considered.\n\ | |
83 \n\ | |
7001 | 84 @item 'exhaustive'\n\ |
85 This is like 'measure', but all possible algorithms that may be used to\n\ | |
6228 | 86 treat the transform are considered.\n\ |
87 \n\ | |
88 @item 'hybrid'\n\ | |
89 As run-time measurement of the algorithm can be expensive, this is a\n\ | |
7001 | 90 compromise where 'measure' is used for transforms up to the size of 8192\n\ |
6228 | 91 and beyond that the 'estimate' method is used.\n\ |
92 @end table\n\ | |
93 \n\ | |
94 The default method is 'estimate', and the method currently being used can\n\ | |
95 be probed with\n\ | |
96 \n\ | |
97 @example\n\ | |
98 @var{method} = fftw ('planner')\n\ | |
99 @end example\n\ | |
100 \n\ | |
101 and the method used can be set using\n\ | |
102 \n\ | |
103 @example\n\ | |
104 fftw ('planner', @var{method})\n\ | |
105 @end example\n\ | |
106 \n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
107 Note that calculated wisdom will be lost when restarting Octave. However,\n\ |
6228 | 108 the wisdom data can be reloaded if it is saved to a file as described\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
109 above. Saved wisdom files should not be used on different platforms since\n\ |
8115
37c1bdb9805c
Clarify fftw documentation
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
110 they will not be efficient and the point of calculating the wisdom is lost.\n\ |
6228 | 111 @seealso{fft, ifft, fft2, ifft2, fftn, ifftn}\n\ |
112 @end deftypefn") | |
113 { | |
114 octave_value retval; | |
115 | |
116 int nargin = args.length(); | |
117 | |
118 if (nargin < 1 || nargin > 2) | |
119 { | |
120 print_usage (); | |
121 return retval; | |
122 } | |
123 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9516
diff
changeset
|
124 #if defined (HAVE_FFTW) |
6228 | 125 if (args(0).is_string ()) |
126 { | |
127 std::string arg0 = args(0).string_value (); | |
128 | |
129 if (!error_state) | |
130 { | |
131 // Use STL function to convert to lower case | |
132 std::transform (arg0.begin (), arg0.end (), arg0.begin (), tolower); | |
133 | |
134 if (nargin == 2) | |
135 { | |
136 std::string arg1 = args(1).string_value (); | |
137 if (!error_state) | |
138 { | |
139 if (arg0 == "planner") | |
140 { | |
141 std::transform (arg1.begin (), arg1.end (), | |
142 arg1.begin (), tolower); | |
6484 | 143 octave_fftw_planner::FftwMethod meth |
144 = octave_fftw_planner::UNKNOWN; | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
145 octave_float_fftw_planner::FftwMethod methf |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
146 = octave_float_fftw_planner::UNKNOWN; |
6228 | 147 |
148 if (arg1 == "estimate") | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
150 meth = octave_fftw_planner::ESTIMATE; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
151 methf = octave_float_fftw_planner::ESTIMATE; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
152 } |
6228 | 153 else if (arg1 == "measure") |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
154 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
155 meth = octave_fftw_planner::MEASURE; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
156 methf = octave_float_fftw_planner::MEASURE; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
157 } |
6228 | 158 else if (arg1 == "patient") |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
159 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
160 meth = octave_fftw_planner::PATIENT; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
161 methf = octave_float_fftw_planner::PATIENT; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
162 } |
6228 | 163 else if (arg1 == "exhaustive") |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
164 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
165 meth = octave_fftw_planner::EXHAUSTIVE; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
166 methf = octave_float_fftw_planner::EXHAUSTIVE; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
167 } |
6228 | 168 else if (arg1 == "hybrid") |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
169 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
170 meth = octave_fftw_planner::HYBRID; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
171 methf = octave_float_fftw_planner::HYBRID; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
172 } |
6228 | 173 else |
174 error ("unrecognized planner method"); | |
175 | |
176 if (!error_state) | |
177 { | |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
9072
diff
changeset
|
178 meth = octave_fftw_planner::method (meth); |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
9072
diff
changeset
|
179 octave_float_fftw_planner::method (methf); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
180 |
6228 | 181 if (meth == octave_fftw_planner::MEASURE) |
182 retval = octave_value ("measure"); | |
183 else if (meth == octave_fftw_planner::PATIENT) | |
184 retval = octave_value ("patient"); | |
185 else if (meth == octave_fftw_planner::EXHAUSTIVE) | |
186 retval = octave_value ("exhaustive"); | |
187 else if (meth == octave_fftw_planner::HYBRID) | |
188 retval = octave_value ("hybrid"); | |
189 else | |
190 retval = octave_value ("estimate"); | |
191 } | |
192 } | |
193 else if (arg0 == "dwisdom") | |
194 { | |
195 char *str = fftw_export_wisdom_to_string (); | |
196 | |
197 if (arg1.length() < 1) | |
198 fftw_forget_wisdom (); | |
199 else if (! fftw_import_wisdom_from_string (arg1.c_str())) | |
200 error ("could not import supplied wisdom"); | |
201 | |
202 if (!error_state) | |
203 retval = octave_value (std::string (str)); | |
204 | |
205 free (str); | |
206 } | |
207 else if (arg0 == "swisdom") | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
208 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
209 char *str = fftwf_export_wisdom_to_string (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
210 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
211 if (arg1.length() < 1) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
212 fftwf_forget_wisdom (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
213 else if (! fftwf_import_wisdom_from_string (arg1.c_str())) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
214 error ("could not import supplied wisdom"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
215 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
216 if (!error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
217 retval = octave_value (std::string (str)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
218 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
219 free (str); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
220 } |
6228 | 221 else |
222 error ("unrecognized argument"); | |
223 } | |
224 } | |
225 else | |
226 { | |
227 if (arg0 == "planner") | |
228 { | |
229 octave_fftw_planner::FftwMethod meth = | |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
9072
diff
changeset
|
230 octave_fftw_planner::method (); |
6228 | 231 |
232 if (meth == octave_fftw_planner::MEASURE) | |
233 retval = octave_value ("measure"); | |
234 else if (meth == octave_fftw_planner::PATIENT) | |
235 retval = octave_value ("patient"); | |
236 else if (meth == octave_fftw_planner::EXHAUSTIVE) | |
237 retval = octave_value ("exhaustive"); | |
238 else if (meth == octave_fftw_planner::HYBRID) | |
239 retval = octave_value ("hybrid"); | |
240 else | |
241 retval = octave_value ("estimate"); | |
242 } | |
243 else if (arg0 == "dwisdom") | |
244 { | |
245 char *str = fftw_export_wisdom_to_string (); | |
246 retval = octave_value (std::string (str)); | |
247 free (str); | |
248 } | |
249 else if (arg0 == "swisdom") | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
250 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
251 char *str = fftwf_export_wisdom_to_string (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
252 retval = octave_value (std::string (str)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
253 free (str); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
254 } |
6228 | 255 else |
256 error ("unrecognized argument"); | |
257 } | |
258 } | |
259 } | |
260 #else | |
261 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9516
diff
changeset
|
262 warning ("fftw: this copy of Octave was not configured to use the FFTW3 planner"); |
6228 | 263 |
264 #endif | |
265 | |
266 return retval; | |
267 } |