GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-fftw.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2001-2018 John W. Eaton
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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_oct_fftw_h)
24 #define octave_oct_fftw_h 1
25 
26 #include "octave-config.h"
27 
28 #include <cstddef>
29 
30 #include <string>
31 
32 #include "dim-vector.h"
33 #include "oct-cmplx.h"
34 
35 namespace octave
36 {
37  class
38  OCTAVE_API
40  {
41  protected:
42 
43  fftw_planner (void);
44 
45  public:
46 
47  // No copying!
48 
49  fftw_planner (const fftw_planner&) = delete;
50 
51  fftw_planner& operator = (const fftw_planner&) = delete;
52 
53  ~fftw_planner (void);
54 
56  {
57  UNKNOWN = -1,
62  HYBRID
63  };
64 
65  static bool instance_ok (void);
66 
67  static void *
68  create_plan (int dir, const int rank, const dim_vector& dims,
69  octave_idx_type howmany, octave_idx_type stride,
70  octave_idx_type dist, const Complex *in,
71  Complex *out)
72  {
73  return instance_ok ()
74  ? instance->do_create_plan (dir, rank, dims, howmany, stride,
75  dist, in, out)
76  : nullptr;
77  }
78 
79  static void *
80  create_plan (const int rank, const dim_vector& dims,
81  octave_idx_type howmany, octave_idx_type stride,
82  octave_idx_type dist, const double *in, Complex *out)
83  {
84  return instance_ok ()
85  ? instance->do_create_plan (rank, dims, howmany, stride, dist,
86  in, out)
87  : nullptr;
88  }
89 
90  static FftwMethod method (void)
91  {
92  static FftwMethod dummy;
93 
94  return instance_ok () ? instance->do_method () : dummy;
95  }
96 
97  static FftwMethod method (FftwMethod _meth)
98  {
99  static FftwMethod dummy;
100 
101  return instance_ok () ? instance->do_method (_meth) : dummy;
102  }
103 
104  static void threads (int nt);
105 
106  static int threads (void)
107  {
108  return instance_ok () ? instance->nthreads : 0;
109  }
110 
111  private:
112 
114 
115  static void cleanup_instance (void) { delete instance; instance = nullptr; }
116 
117  void *
118  do_create_plan (int dir, const int rank, const dim_vector& dims,
119  octave_idx_type howmany, octave_idx_type stride,
120  octave_idx_type dist, const Complex *in,
121  Complex *out);
122 
123  void *
124  do_create_plan (const int rank, const dim_vector& dims,
125  octave_idx_type howmany, octave_idx_type stride,
126  octave_idx_type dist, const double *in, Complex *out);
127 
128  FftwMethod do_method (void);
129 
130  FftwMethod do_method (FftwMethod _meth);
131 
133 
134  // FIXME: perhaps this should be split into two classes?
135 
136  // Plan for fft and ifft of complex values
137  void *plan[2];
138 
139  // dist
141 
142  // stride
144 
145  // rank
146  int r[2];
147 
148  // howmany
150 
151  // dims
153 
154  bool simd_align[2];
155  bool inplace[2];
156 
157  // Plan for fft of real values
158  void *rplan;
159 
160  // dist
162 
163  // stride
165 
166  // rank
167  int rr;
168 
169  // howmany
171 
172  // dims
174 
176 
177  // number of threads. Always 1 unless compiled with multi-threading
178  // support.
179  int nthreads;
180  };
181 
182  class
183  OCTAVE_API
185  {
186  protected:
187 
188  float_fftw_planner (void);
189 
190  public:
191 
192  // No copying!
193 
194  float_fftw_planner (const float_fftw_planner&) = delete;
195 
197  operator = (const float_fftw_planner&) = delete;
198 
199  ~float_fftw_planner (void);
200 
202  {
203  UNKNOWN = -1,
208  HYBRID
209  };
210 
211  static bool instance_ok (void);
212 
213  static void *
214  create_plan (int dir, const int rank, const dim_vector& dims,
215  octave_idx_type howmany, octave_idx_type stride,
216  octave_idx_type dist, const FloatComplex *in,
217  FloatComplex *out)
218  {
219  return instance_ok ()
220  ? instance->do_create_plan (dir, rank, dims, howmany, stride,
221  dist, in, out)
222  : nullptr;
223  }
224 
225  static void *
226  create_plan (const int rank, const dim_vector& dims,
227  octave_idx_type howmany, octave_idx_type stride,
228  octave_idx_type dist, const float *in, FloatComplex *out)
229  {
230  return instance_ok ()
231  ? instance->do_create_plan (rank, dims, howmany, stride, dist,
232  in, out)
233  : nullptr;
234  }
235 
236  static FftwMethod method (void)
237  {
238  static FftwMethod dummy;
239 
240  return instance_ok () ? instance->do_method () : dummy;
241  }
242 
243  static FftwMethod method (FftwMethod _meth)
244  {
245  static FftwMethod dummy;
246 
247  return instance_ok () ? instance->do_method (_meth) : dummy;
248  }
249 
250  static void threads (int nt);
251 
252  static int threads (void)
253  {
254  return instance_ok () ? instance->nthreads : 0;
255  }
256 
257  private:
258 
260 
261  static void cleanup_instance (void) { delete instance; instance = nullptr; }
262 
263  void *
264  do_create_plan (int dir, const int rank, const dim_vector& dims,
265  octave_idx_type howmany, octave_idx_type stride,
266  octave_idx_type dist, const FloatComplex *in,
267  FloatComplex *out);
268 
269  void *
270  do_create_plan (const int rank, const dim_vector& dims,
271  octave_idx_type howmany, octave_idx_type stride,
272  octave_idx_type dist, const float *in, FloatComplex *out);
273 
274  FftwMethod do_method (void);
275 
276  FftwMethod do_method (FftwMethod _meth);
277 
279 
280  // FIXME: perhaps this should be split into two classes?
281 
282  // Plan for fft and ifft of complex values
283  void *plan[2];
284 
285  // dist
287 
288  // stride
290 
291  // rank
292  int r[2];
293 
294  // howmany
296 
297  // dims
299 
300  bool simd_align[2];
301  bool inplace[2];
302 
303  // Plan for fft of real values
304  void *rplan;
305 
306  // dist
308 
309  // stride
311 
312  // rank
313  int rr;
314 
315  // howmany
317 
318  // dims
320 
322 
323  // number of threads. Always 1 unless compiled with multi-threading
324  // support.
325  int nthreads;
326  };
327 
328  class
329  OCTAVE_API
330  fftw
331  {
332  public:
333 
334  fftw (void) = delete;
335 
336  // No copying.
337 
338  fftw (const fftw&) = delete;
339 
340  fftw& operator = (const fftw&) = delete;
341 
342  static int fft (const double *in, Complex *out, size_t npts,
343  size_t nsamples = 1, octave_idx_type stride = 1,
344  octave_idx_type dist = -1);
345  static int fft (const Complex *in, Complex *out, size_t npts,
346  size_t nsamples = 1, octave_idx_type stride = 1,
347  octave_idx_type dist = -1);
348  static int ifft (const Complex *in, Complex *out, size_t npts,
349  size_t nsamples = 1, octave_idx_type stride = 1,
350  octave_idx_type dist = -1);
351 
352  static int fftNd (const double*, Complex*, const int, const dim_vector&);
353  static int fftNd (const Complex*, Complex*, const int,
354  const dim_vector&);
355  static int ifftNd (const Complex*, Complex*, const int,
356  const dim_vector&);
357 
358  static int fft (const float *in, FloatComplex *out, size_t npts,
359  size_t nsamples = 1, octave_idx_type stride = 1,
360  octave_idx_type dist = -1);
361  static int fft (const FloatComplex *in, FloatComplex *out, size_t npts,
362  size_t nsamples = 1, octave_idx_type stride = 1,
363  octave_idx_type dist = -1);
364  static int ifft (const FloatComplex *in, FloatComplex *out, size_t npts,
365  size_t nsamples = 1, octave_idx_type stride = 1,
366  octave_idx_type dist = -1);
367 
368  static int fftNd (const float*, FloatComplex*, const int, const dim_vector&);
369  static int fftNd (const FloatComplex*, FloatComplex*, const int,
370  const dim_vector&);
371  static int ifftNd (const FloatComplex*, FloatComplex*, const int,
372  const dim_vector&);
373  };
374 
375  extern OCTAVE_API std::string fftw_version (void);
376  extern OCTAVE_API std::string fftwf_version (void);
377 }
378 
379 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
380 
381 OCTAVE_DEPRECATED (4.4, "use 'octave::fftw_version' instead")
382 static inline std::string
383 octave_fftw_version (void)
384 {
385  return octave::fftw_version ();
386 }
387 
388 OCTAVE_DEPRECATED (4.4, "use 'octave::fftwf_version' instead")
389 static inline std::string
390 octave_fftwf_version (void)
391 {
392  return octave::fftwf_version ();
393 }
394 
395 OCTAVE_DEPRECATED (4.4, "use 'octave::fftw_planner' instead")
396 typedef octave::fftw_planner octave_fftw_planner;
397 
398 OCTAVE_DEPRECATED (4.4, "use 'octave::float_fftw_planner' instead")
399 typedef octave::float_fftw_planner octave_float_fftw_planner;
400 
401 OCTAVE_DEPRECATED (4.4, "use 'octave::fftw' instead")
402 typedef octave::fftw octave_fftw;
403 
404 #endif
405 
406 #endif
static int threads(void)
Definition: oct-fftw.h:106
static void * create_plan(int dir, const int rank, const dim_vector &dims, octave_idx_type howmany, octave_idx_type stride, octave_idx_type dist, const Complex *in, Complex *out)
Definition: oct-fftw.h:68
STL namespace.
s
Definition: file-io.cc:2729
static FftwMethod method(void)
Definition: oct-fftw.h:236
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
double h
Definition: graphics.cc:11808
static FftwMethod method(void)
Definition: oct-fftw.h:90
static void cleanup_instance(void)
Definition: oct-fftw.h:115
octave_idx_type rh
Definition: oct-fftw.h:316
static void * create_plan(const int rank, const dim_vector &dims, octave_idx_type howmany, octave_idx_type stride, octave_idx_type dist, const double *in, Complex *out)
Definition: oct-fftw.h:80
octave_idx_type rh
Definition: oct-fftw.h:170
std::string fftwf_version(void)
Definition: oct-fftw.cc:1138
std::string fftw_version(void)
Definition: oct-fftw.cc:1128
static fftw_planner * instance
Definition: oct-fftw.h:113
static float_fftw_planner * instance
Definition: oct-fftw.h:259
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
Definition: sub2ind.cc:255
static FftwMethod method(FftwMethod _meth)
Definition: oct-fftw.h:243
static void * create_plan(const int rank, const dim_vector &dims, octave_idx_type howmany, octave_idx_type stride, octave_idx_type dist, const float *in, FloatComplex *out)
Definition: oct-fftw.h:226
octave_idx_type rd
Definition: oct-fftw.h:161
octave_idx_type rd
Definition: oct-fftw.h:307
static void * create_plan(int dir, const int rank, const dim_vector &dims, octave_idx_type howmany, octave_idx_type stride, octave_idx_type dist, const FloatComplex *in, FloatComplex *out)
Definition: oct-fftw.h:214
static int threads(void)
Definition: oct-fftw.h:252
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
static void cleanup_instance(void)
Definition: oct-fftw.h:261
FftwMethod meth
Definition: oct-fftw.h:132
std::complex< double > Complex
Definition: oct-cmplx.h:31
static FftwMethod method(FftwMethod _meth)
Definition: oct-fftw.h:97
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
octave_idx_type rs
Definition: oct-fftw.h:310
octave_idx_type rs
Definition: oct-fftw.h:164
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888