comparison libinterp/dldfcn/fftw.cc @ 19743:67f2c76f9f4d

Remove unnecessary checking of error_state after is_string validation. * data.cc (#NATIVE_REDUCTION, Fcumsum, Fprod, Fsum): Remove if (error_state) check. * debug.cc (Fdbstep): Remove if (error_state) check. * dlmread.cc (Fdlmread): Remove if (error_state) check. * graphics.cc (Fwaitfor): Remove if (error_state) check. * lu.cc (Flu): Remove if (error_state) check. * utils.cc (Ferrno): Remove if (error_state) check. * variables.cc (is_valid_function): Remove if (error_state) check. * fftw.cc (Ffftw): Remove if (error_state) check.
author Rik <rik@octave.org>
date Tue, 17 Feb 2015 17:34:48 -0800
parents 4197fc428c7d
children 075a5e2e1ba5
comparison
equal deleted inserted replaced
19742:55a4173f1624 19743:67f2c76f9f4d
142 142
143 #if defined (HAVE_FFTW) 143 #if defined (HAVE_FFTW)
144 if (args(0).is_string ()) 144 if (args(0).is_string ())
145 { 145 {
146 std::string arg0 = args(0).string_value (); 146 std::string arg0 = args(0).string_value ();
147 if (!error_state) 147
148 if (arg0 == "planner")
148 { 149 {
149 if (arg0 == "planner") 150 if (nargin == 2) //planner setter
150 { 151 {
151 if (nargin == 2) //planner setter 152 if (args(1).is_string ())
152 { 153 {
153 if (args(1).is_string ()) 154 // Use STL function to convert to lower case
155 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
156 tolower);
157 std::string arg1 = args(1).string_value ();
158 if (!error_state)
154 { 159 {
155 // Use STL function to convert to lower case 160 std::transform (arg1.begin (), arg1.end (),
156 std::transform (arg0.begin (), arg0.end (), arg0.begin (), 161 arg1.begin (), tolower);
157 tolower); 162 octave_fftw_planner::FftwMethod meth
158 std::string arg1 = args(1).string_value (); 163 = octave_fftw_planner::UNKNOWN;
164 octave_float_fftw_planner::FftwMethod methf
165 = octave_float_fftw_planner::UNKNOWN;
166
167 if (arg1 == "estimate")
168 {
169 meth = octave_fftw_planner::ESTIMATE;
170 methf = octave_float_fftw_planner::ESTIMATE;
171 }
172 else if (arg1 == "measure")
173 {
174 meth = octave_fftw_planner::MEASURE;
175 methf = octave_float_fftw_planner::MEASURE;
176 }
177 else if (arg1 == "patient")
178 {
179 meth = octave_fftw_planner::PATIENT;
180 methf = octave_float_fftw_planner::PATIENT;
181 }
182 else if (arg1 == "exhaustive")
183 {
184 meth = octave_fftw_planner::EXHAUSTIVE;
185 methf = octave_float_fftw_planner::EXHAUSTIVE;
186 }
187 else if (arg1 == "hybrid")
188 {
189 meth = octave_fftw_planner::HYBRID;
190 methf = octave_float_fftw_planner::HYBRID;
191 }
192 else
193 error ("fftw: unrecognized planner METHOD");
194
159 if (!error_state) 195 if (!error_state)
160 { 196 {
161 std::transform (arg1.begin (), arg1.end (), 197 meth = octave_fftw_planner::method (meth);
162 arg1.begin (), tolower); 198 octave_float_fftw_planner::method (methf);
163 octave_fftw_planner::FftwMethod meth 199
164 = octave_fftw_planner::UNKNOWN; 200 if (meth == octave_fftw_planner::MEASURE)
165 octave_float_fftw_planner::FftwMethod methf 201 retval = octave_value ("measure");
166 = octave_float_fftw_planner::UNKNOWN; 202 else if (meth == octave_fftw_planner::PATIENT)
167 203 retval = octave_value ("patient");
168 if (arg1 == "estimate") 204 else if (meth == octave_fftw_planner::EXHAUSTIVE)
169 { 205 retval = octave_value ("exhaustive");
170 meth = octave_fftw_planner::ESTIMATE; 206 else if (meth == octave_fftw_planner::HYBRID)
171 methf = octave_float_fftw_planner::ESTIMATE; 207 retval = octave_value ("hybrid");
172 }
173 else if (arg1 == "measure")
174 {
175 meth = octave_fftw_planner::MEASURE;
176 methf = octave_float_fftw_planner::MEASURE;
177 }
178 else if (arg1 == "patient")
179 {
180 meth = octave_fftw_planner::PATIENT;
181 methf = octave_float_fftw_planner::PATIENT;
182 }
183 else if (arg1 == "exhaustive")
184 {
185 meth = octave_fftw_planner::EXHAUSTIVE;
186 methf = octave_float_fftw_planner::EXHAUSTIVE;
187 }
188 else if (arg1 == "hybrid")
189 {
190 meth = octave_fftw_planner::HYBRID;
191 methf = octave_float_fftw_planner::HYBRID;
192 }
193 else 208 else
194 error ("fftw: unrecognized planner METHOD"); 209 retval = octave_value ("estimate");
195 210 }
196 if (!error_state) 211 }
197 { 212 }
198 meth = octave_fftw_planner::method (meth); 213 else
199 octave_float_fftw_planner::method (methf); 214 error ("fftw: planner expects a string value as METHOD");
200 215 }
201 if (meth == octave_fftw_planner::MEASURE) 216 else //planner getter
202 retval = octave_value ("measure"); 217 {
203 else if (meth == octave_fftw_planner::PATIENT) 218 octave_fftw_planner::FftwMethod meth =
204 retval = octave_value ("patient"); 219 octave_fftw_planner::method ();
205 else if (meth == octave_fftw_planner::EXHAUSTIVE) 220
206 retval = octave_value ("exhaustive"); 221 if (meth == octave_fftw_planner::MEASURE)
207 else if (meth == octave_fftw_planner::HYBRID) 222 retval = octave_value ("measure");
208 retval = octave_value ("hybrid"); 223 else if (meth == octave_fftw_planner::PATIENT)
209 else 224 retval = octave_value ("patient");
210 retval = octave_value ("estimate"); 225 else if (meth == octave_fftw_planner::EXHAUSTIVE)
211 } 226 retval = octave_value ("exhaustive");
212 } 227 else if (meth == octave_fftw_planner::HYBRID)
228 retval = octave_value ("hybrid");
229 else
230 retval = octave_value ("estimate");
231 }
232 }
233 else if (arg0 == "dwisdom")
234 {
235 if (nargin == 2) //dwisdom setter
236 {
237 if (args(1).is_string ())
238 {
239 // Use STL function to convert to lower case
240 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
241 tolower);
242 std::string arg1 = args(1).string_value ();
243 if (!error_state)
244 {
245 char *str = fftw_export_wisdom_to_string ();
246
247 if (arg1.length () < 1)
248 fftw_forget_wisdom ();
249 else if (! fftw_import_wisdom_from_string (arg1.c_str ()))
250 error ("fftw: could not import supplied WISDOM");
251
252 if (!error_state)
253 retval = octave_value (std::string (str));
254
255 free (str);
256 }
257 }
258 }
259 else //dwisdom getter
260 {
261 char *str = fftw_export_wisdom_to_string ();
262 retval = octave_value (std::string (str));
263 free (str);
264 }
265 }
266 else if (arg0 == "swisdom")
267 {
268 //swisdom uses fftwf_ functions (float), dwisdom fftw_ (real)
269 if (nargin == 2) //swisdom setter
270 {
271 if (args(1).is_string ())
272 {
273 // Use STL function to convert to lower case
274 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
275 tolower);
276 std::string arg1 = args(1).string_value ();
277 if (!error_state)
278 {
279 char *str = fftwf_export_wisdom_to_string ();
280
281 if (arg1.length () < 1)
282 fftwf_forget_wisdom ();
283 else if (! fftwf_import_wisdom_from_string (arg1.c_str ()))
284 error ("fftw: could not import supplied WISDOM");
285
286 if (!error_state)
287 retval = octave_value (std::string (str));
288
289 free (str);
290 }
291 }
292 }
293 else //swisdom getter
294 {
295 char *str = fftwf_export_wisdom_to_string ();
296 retval = octave_value (std::string (str));
297 free (str);
298 }
299 }
300 else if (arg0 == "threads")
301 {
302 if (nargin == 2) //threads setter
303 {
304 if (args(1).is_real_scalar ())
305 {
306 int nthreads = args(1).int_value();
307 if (nthreads >= 1)
308 {
309 #if defined (HAVE_FFTW3_THREADS)
310 octave_fftw_planner::threads (nthreads);
311 #else
312 gripe_disabled_feature ("fftw", "multithreaded FFTW");
313 #endif
314 #if defined (HAVE_FFTW3F_THREADS)
315 octave_float_fftw_planner::threads (nthreads);
316 #else
317 gripe_disabled_feature ("fftw", "multithreaded FFTW");
318 #endif
213 } 319 }
214 else 320 else
215 error ("fftw: planner expects a string value as METHOD"); 321 error ("fftw: number of threads must be >=1");
216 } 322 }
217 else //planner getter 323 else
218 { 324 error ("fftw: setting threads needs one integer argument");
219 octave_fftw_planner::FftwMethod meth = 325 }
220 octave_fftw_planner::method (); 326 else //threads getter
221
222 if (meth == octave_fftw_planner::MEASURE)
223 retval = octave_value ("measure");
224 else if (meth == octave_fftw_planner::PATIENT)
225 retval = octave_value ("patient");
226 else if (meth == octave_fftw_planner::EXHAUSTIVE)
227 retval = octave_value ("exhaustive");
228 else if (meth == octave_fftw_planner::HYBRID)
229 retval = octave_value ("hybrid");
230 else
231 retval = octave_value ("estimate");
232 }
233 }
234 else if (arg0 == "dwisdom")
235 {
236 if (nargin == 2) //dwisdom setter
237 {
238 if (args(1).is_string ())
239 {
240 // Use STL function to convert to lower case
241 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
242 tolower);
243 std::string arg1 = args(1).string_value ();
244 if (!error_state)
245 {
246 char *str = fftw_export_wisdom_to_string ();
247
248 if (arg1.length () < 1)
249 fftw_forget_wisdom ();
250 else if (! fftw_import_wisdom_from_string (arg1.c_str ()))
251 error ("fftw: could not import supplied WISDOM");
252
253 if (!error_state)
254 retval = octave_value (std::string (str));
255
256 free (str);
257 }
258 }
259 }
260 else //dwisdom getter
261 {
262 char *str = fftw_export_wisdom_to_string ();
263 retval = octave_value (std::string (str));
264 free (str);
265 }
266 }
267 else if (arg0 == "swisdom")
268 {
269 //swisdom uses fftwf_ functions (float), dwisdom fftw_ (real)
270 if (nargin == 2) //swisdom setter
271 {
272 if (args(1).is_string ())
273 {
274 // Use STL function to convert to lower case
275 std::transform (arg0.begin (), arg0.end (), arg0.begin (),
276 tolower);
277 std::string arg1 = args(1).string_value ();
278 if (!error_state)
279 {
280 char *str = fftwf_export_wisdom_to_string ();
281
282 if (arg1.length () < 1)
283 fftwf_forget_wisdom ();
284 else if (! fftwf_import_wisdom_from_string (arg1.c_str ()))
285 error ("fftw: could not import supplied WISDOM");
286
287 if (!error_state)
288 retval = octave_value (std::string (str));
289
290 free (str);
291 }
292 }
293 }
294 else //swisdom getter
295 {
296 char *str = fftwf_export_wisdom_to_string ();
297 retval = octave_value (std::string (str));
298 free (str);
299 }
300 }
301 else if (arg0 == "threads")
302 {
303 if (nargin == 2) //threads setter
304 {
305 if (args(1).is_real_scalar ())
306 {
307 int nthreads = args(1).int_value();
308 if (nthreads >= 1)
309 {
310 #if defined (HAVE_FFTW3_THREADS) 327 #if defined (HAVE_FFTW3_THREADS)
311 octave_fftw_planner::threads (nthreads); 328 retval = octave_value (octave_fftw_planner::threads());
312 #else 329 #else
313 gripe_disabled_feature ("fftw", "multithreaded FFTW"); 330 retval = 1;
314 #endif 331 #endif
315 #if defined (HAVE_FFTW3F_THREADS)
316 octave_float_fftw_planner::threads (nthreads);
317 #else
318 gripe_disabled_feature ("fftw", "multithreaded FFTW");
319 #endif
320 }
321 else
322 error ("fftw: number of threads must be >=1");
323 }
324 else
325 error ("fftw: setting threads needs one integer argument");
326 }
327 else //threads getter
328 #if defined (HAVE_FFTW3_THREADS)
329 retval = octave_value (octave_fftw_planner::threads());
330 #else
331 retval = 1;
332 #endif
333 }
334 else
335 error ("fftw: unrecognized argument");
336 } 332 }
333 else
334 error ("fftw: unrecognized argument");
337 } 335 }
338 else 336 else
339 error ("fftw: unrecognized argument"); 337 error ("fftw: unrecognized argument");
340 #else 338 #else
341 339