Mercurial > octave
annotate liboctave/numeric/oct-fftw.cc @ 23475:d691ed308237
maint: Clean up #includes in liboctave/numeric directory.
* build-aux/mk-opts.pl: Change Perl to generate "" around local include
libraries rather than <>. Include "lo-math.h" rather than <cmath>.
* CollocWt.cc, DAERTFunc.h, DASPK.cc, DASPK.h, DASRT.cc, DASRT.h, DASSL.cc,
DASSL.h, DET.h, EIG.cc, EIG.h, LSODE.cc, LSODE.h, ODE.h, ODES.cc, ODESFunc.h,
Quad.cc, aepbalance.cc, base-de.h, base-min.h, bsxfun-decl.h, bsxfun-defs.cc,
bsxfun.h, chol.cc, eigs-base.cc, fEIG.cc, fEIG.h, gepbalance.cc, gsvd.cc,
hess.cc, lo-blas-proto.h, lo-lapack-proto.h, lo-mappers.cc, lo-mappers.h,
lo-qrupdate-proto.h, lo-slatec-proto.h, lo-specfun.cc, lo-specfun.h, lu.cc,
lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc,
oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc,
randgamma.cc, randpoisson.cc, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h,
sparse-dmsolve.cc, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h,
svd.cc:
Rationalize #includes. Use forward declarations of just classes where
possible. Reformat some long lines < 80 characters. Reformat some comments
for readabliity.
* mx-inlines.cc: Rationalize #includes for this file in liboctave/operators
used by many in liboctave/numeric.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 09 May 2017 08:46:07 -0700 |
parents | 21baad6b35c4 |
children | 980f39c3ab90 |
rev | line source |
---|---|
3828 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 2001-2017 John W. Eaton |
7017 | 4 |
3828 | 5 This file is part of Octave. |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 (at your option) any later version. |
3828 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 GNU General Public License for more details. |
3828 | 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/>. | |
3828 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21688
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
24 # include "config.h" |
3828 | 25 #endif |
26 | |
21451
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
27 #if defined (HAVE_FFTW3_H) |
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
28 # include <fftw3.h> |
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
29 #endif |
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
30 |
4786 | 31 #include "lo-error.h" |
3828 | 32 #include "oct-fftw.h" |
23475
d691ed308237
maint: Clean up #includes in liboctave/numeric directory.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
33 #include "oct-locbuf.h" |
4786 | 34 #include "quit.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
35 #include "singleton-cleanup.h" |
3828 | 36 |
21520
e1c921322ba2
Fix configuration conditions in oct-fftw.cc
Mike Miller <mtmiller@octave.org>
parents:
21451
diff
changeset
|
37 #if defined (HAVE_FFTW3_THREADS) || defined (HAVE_FFTW3F_THREADS) |
21893
0a6f387d18d3
* nproc.cc, oct-fftw.cc: Use octave_num_processors_wrapper.
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
38 # include "nproc-wrapper.h" |
15960
bde7731b2b83
added FFTW multithreaded library support
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15271
diff
changeset
|
39 #endif |
bde7731b2b83
added FFTW multithreaded library support
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15271
diff
changeset
|
40 |
23062
9ca0829b160e
fix editing error in previous change to oct-fftw.cc (bug #50070)
John W. Eaton <jwe@octave.org>
parents:
23058
diff
changeset
|
41 namespace octave |
9ca0829b160e
fix editing error in previous change to oct-fftw.cc (bug #50070)
John W. Eaton <jwe@octave.org>
parents:
23058
diff
changeset
|
42 { |
21688
68ab693d16e4
* oct-fftw.cc: Allow compilation without FFTW.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
43 #if defined (HAVE_FFTW) |
68ab693d16e4
* oct-fftw.cc: Allow compilation without FFTW.
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
44 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23440
diff
changeset
|
45 fftw_planner *fftw_planner::instance = nullptr; |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
46 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
47 // Helper class to create and cache FFTW plans for both 1D and |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
48 // 2D. This implementation defaults to using FFTW_ESTIMATE to create |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
49 // the plans, which in theory is suboptimal, but provides quite |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
50 // reasonable performance in practice. |
4773 | 51 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
52 // Also note that if FFTW_ESTIMATE is not used then the planner in FFTW3 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
53 // will destroy the input and output arrays. We must, therefore, create a |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
54 // temporary input array with the same size and 16-byte alignment as |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
55 // the original array when using a different planner strategy. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
56 // Note that we also use any wisdom that is available, either in a |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
57 // FFTW3 system wide file or as supplied by the user. |
4773 | 58 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
59 // FIXME: if we can ensure 16 byte alignment in Array<T> |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
60 // (<T> *data) the FFTW3 can use SIMD instructions for further |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
61 // acceleration. |
4773 | 62 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
63 // Note that it is profitable to store the FFTW3 plans, for small FFTs. |
3828 | 64 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
65 fftw_planner::fftw_planner (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
66 : meth (ESTIMATE), rplan (0), rd (0), rs (0), rr (0), rh (0), rn (), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
67 rsimd_align (false), nthreads (1) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
68 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
69 plan[0] = plan[1] = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
70 d[0] = d[1] = s[0] = s[1] = r[0] = r[1] = h[0] = h[1] = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
71 simd_align[0] = simd_align[1] = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
72 inplace[0] = inplace[1] = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
73 n[0] = n[1] = dim_vector (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
74 |
15960
bde7731b2b83
added FFTW multithreaded library support
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15271
diff
changeset
|
75 #if defined (HAVE_FFTW3_THREADS) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
76 int init_ret = fftw_init_threads (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
77 if (! init_ret) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
78 (*current_liboctave_error_handler) ("Error initializing FFTW threads"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
79 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
80 // Use number of processors available to the current process |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
81 // This can be later changed with fftw ("threads", nthreads). |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
82 nthreads = octave_num_processors_wrapper (OCTAVE_NPROC_CURRENT); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
83 fftw_plan_with_nthreads (nthreads); |
15960
bde7731b2b83
added FFTW multithreaded library support
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15271
diff
changeset
|
84 #endif |
bde7731b2b83
added FFTW multithreaded library support
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15271
diff
changeset
|
85 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
86 // If we have a system wide wisdom file, import it. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
87 fftw_import_system_wisdom (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
88 } |
3828 | 89 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
90 fftw_planner::~fftw_planner (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
91 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
92 fftw_plan *plan_p; |
14078
941d19370065
Cleanup FFTW wisdom plans in class destructor and prevent a memory leak.
Rik <octave@nomad.inbox5.com>
parents:
13994
diff
changeset
|
93 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
94 plan_p = reinterpret_cast<fftw_plan *> (&rplan); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
95 if (*plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
96 fftw_destroy_plan (*plan_p); |
14078
941d19370065
Cleanup FFTW wisdom plans in class destructor and prevent a memory leak.
Rik <octave@nomad.inbox5.com>
parents:
13994
diff
changeset
|
97 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
98 plan_p = reinterpret_cast<fftw_plan *> (&plan[0]); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
99 if (*plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
100 fftw_destroy_plan (*plan_p); |
14078
941d19370065
Cleanup FFTW wisdom plans in class destructor and prevent a memory leak.
Rik <octave@nomad.inbox5.com>
parents:
13994
diff
changeset
|
101 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
102 plan_p = reinterpret_cast<fftw_plan *> (&plan[1]); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
103 if (*plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
104 fftw_destroy_plan (*plan_p); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
105 } |
14078
941d19370065
Cleanup FFTW wisdom plans in class destructor and prevent a memory leak.
Rik <octave@nomad.inbox5.com>
parents:
13994
diff
changeset
|
106 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
107 bool |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
108 fftw_planner::instance_ok (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
109 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
110 bool retval = true; |
6228 | 111 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
112 if (! instance) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
113 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
114 instance = new fftw_planner (); |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
115 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
116 if (instance) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
117 singleton_cleanup_list::add (cleanup_instance); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
118 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
119 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
120 if (! instance) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
121 (*current_liboctave_error_handler) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
122 ("unable to create fftw_planner object!"); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
123 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
124 return retval; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
125 } |
6228 | 126 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
127 void |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
128 fftw_planner::threads (int nt) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
129 { |
21520
e1c921322ba2
Fix configuration conditions in oct-fftw.cc
Mike Miller <mtmiller@octave.org>
parents:
21451
diff
changeset
|
130 #if defined (HAVE_FFTW3_THREADS) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
131 if (instance_ok () && nt != threads ()) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
132 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
133 instance->nthreads = nt; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
134 fftw_plan_with_nthreads (nt); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
135 // Clear the current plans. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
136 instance->rplan = instance->plan[0] = instance->plan[1] = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
137 } |
21451
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
138 #else |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
139 (*current_liboctave_warning_handler) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
140 ("unable to change number of threads without FFTW thread support"); |
21451
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
141 #endif |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
142 } |
21451
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
143 |
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
144 #define CHECK_SIMD_ALIGNMENT(x) \ |
6482 | 145 (((reinterpret_cast<ptrdiff_t> (x)) & 0xF) == 0) |
4808 | 146 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
147 void * |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
148 fftw_planner::do_create_plan (int dir, const int rank, |
23440
f15f0d8b78c8
pass dim_vector as const reference, not by value
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
149 const dim_vector& dims, |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
150 octave_idx_type howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
151 octave_idx_type stride, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
152 octave_idx_type dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
153 const Complex *in, Complex *out) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
154 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
155 int which = (dir == FFTW_FORWARD) ? 0 : 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
156 fftw_plan *cur_plan_p = reinterpret_cast<fftw_plan *> (&plan[which]); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
157 bool create_new_plan = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
158 bool ioalign = CHECK_SIMD_ALIGNMENT (in) && CHECK_SIMD_ALIGNMENT (out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
159 bool ioinplace = (in == out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
160 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
161 // Don't create a new plan if we have a non SIMD plan already but |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
162 // can do SIMD. This prevents endlessly recreating plans if we |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
163 // change the alignment. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
164 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
165 if (plan[which] == 0 || d[which] != dist || s[which] != stride |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
166 || r[which] != rank || h[which] != howmany |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
167 || ioinplace != inplace[which] |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
168 || ((ioalign != simd_align[which]) ? ! ioalign : false)) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
169 create_new_plan = true; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
170 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
171 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
172 // We still might not have the same shape of array. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
173 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
174 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
175 if (dims(i) != n[which](i)) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
176 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
177 create_new_plan = true; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
178 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
179 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
180 } |
3828 | 181 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
182 if (create_new_plan) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
183 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
184 d[which] = dist; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
185 s[which] = stride; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
186 r[which] = rank; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
187 h[which] = howmany; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
188 simd_align[which] = ioalign; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
189 inplace[which] = ioinplace; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
190 n[which] = dims; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
191 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
192 // Note reversal of dimensions for column major storage in FFTW. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
193 octave_idx_type nn = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
194 OCTAVE_LOCAL_BUFFER (int, tmp, rank); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
195 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
196 for (int i = 0, j = rank-1; i < rank; i++, j--) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
197 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
198 tmp[i] = dims(j); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
199 nn *= dims(j); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
200 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
201 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
202 int plan_flags = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
203 bool plan_destroys_in = true; |
4809 | 204 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
205 switch (meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
206 { |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
207 case UNKNOWN: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
208 case ESTIMATE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
209 plan_flags |= FFTW_ESTIMATE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
210 plan_destroys_in = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
211 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
212 case MEASURE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
213 plan_flags |= FFTW_MEASURE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
214 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
215 case PATIENT: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
216 plan_flags |= FFTW_PATIENT; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
217 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
218 case EXHAUSTIVE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
219 plan_flags |= FFTW_EXHAUSTIVE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
220 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
221 case HYBRID: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
222 if (nn < 8193) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
223 plan_flags |= FFTW_MEASURE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
224 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
225 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
226 plan_flags |= FFTW_ESTIMATE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
227 plan_destroys_in = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
228 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
229 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
230 } |
3828 | 231 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
232 if (ioalign) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
233 plan_flags &= ~FFTW_UNALIGNED; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
234 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
235 plan_flags |= FFTW_UNALIGNED; |
4773 | 236 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
237 if (*cur_plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
238 fftw_destroy_plan (*cur_plan_p); |
6228 | 239 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
240 if (plan_destroys_in) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
241 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
242 // Create matrix with the same size and 16-byte alignment as input |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
243 OCTAVE_LOCAL_BUFFER (Complex, itmp, nn * howmany + 32); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
244 itmp = reinterpret_cast<Complex *> |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
245 (((reinterpret_cast<ptrdiff_t>(itmp) + 15) & ~ 0xF) + |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
246 ((reinterpret_cast<ptrdiff_t> (in)) & 0xF)); |
6228 | 247 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
248 *cur_plan_p = |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
249 fftw_plan_many_dft (rank, tmp, howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
250 reinterpret_cast<fftw_complex *> (itmp), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
251 0, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
252 reinterpret_cast<fftw_complex *> (out), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
253 0, stride, dist, dir, plan_flags); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
254 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
255 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
256 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
257 *cur_plan_p = |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
258 fftw_plan_many_dft (rank, tmp, howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
259 reinterpret_cast<fftw_complex *> (const_cast<Complex *> (in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
260 0, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
261 reinterpret_cast<fftw_complex *> (out), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
262 0, stride, dist, dir, plan_flags); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
263 } |
6228 | 264 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
265 if (*cur_plan_p == 0) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
266 (*current_liboctave_error_handler) ("Error creating fftw plan"); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
267 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
268 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
269 return *cur_plan_p; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
270 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
271 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
272 void * |
23440
f15f0d8b78c8
pass dim_vector as const reference, not by value
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
273 fftw_planner::do_create_plan (const int rank, const dim_vector& dims, |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
274 octave_idx_type howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
275 octave_idx_type stride, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
276 octave_idx_type dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
277 const double *in, Complex *out) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
278 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
279 fftw_plan *cur_plan_p = reinterpret_cast<fftw_plan *> (&rplan); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
280 bool create_new_plan = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
281 bool ioalign = CHECK_SIMD_ALIGNMENT (in) && CHECK_SIMD_ALIGNMENT (out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
282 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
283 // Don't create a new plan if we have a non SIMD plan already but |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
284 // can do SIMD. This prevents endlessly recreating plans if we |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
285 // change the alignment. |
4808 | 286 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
287 if (rplan == 0 || rd != dist || rs != stride || rr != rank |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
288 || rh != howmany || ((ioalign != rsimd_align) ? ! ioalign : false)) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
289 create_new_plan = true; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
290 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
291 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
292 // We still might not have the same shape of array. |
4809 | 293 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
294 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
295 if (dims(i) != rn(i)) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
296 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
297 create_new_plan = true; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
298 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
299 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
300 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
301 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
302 if (create_new_plan) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
303 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
304 rd = dist; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
305 rs = stride; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
306 rr = rank; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
307 rh = howmany; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
308 rsimd_align = ioalign; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
309 rn = dims; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
310 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
311 // Note reversal of dimensions for column major storage in FFTW. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
312 octave_idx_type nn = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
313 OCTAVE_LOCAL_BUFFER (int, tmp, rank); |
3828 | 314 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
315 for (int i = 0, j = rank-1; i < rank; i++, j--) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
316 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
317 tmp[i] = dims(j); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
318 nn *= dims(j); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
319 } |
3828 | 320 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
321 int plan_flags = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
322 bool plan_destroys_in = true; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
323 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
324 switch (meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
325 { |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
326 case UNKNOWN: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
327 case ESTIMATE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
328 plan_flags |= FFTW_ESTIMATE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
329 plan_destroys_in = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
330 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
331 case MEASURE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
332 plan_flags |= FFTW_MEASURE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
333 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
334 case PATIENT: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
335 plan_flags |= FFTW_PATIENT; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
336 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
337 case EXHAUSTIVE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
338 plan_flags |= FFTW_EXHAUSTIVE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
339 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
340 case HYBRID: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
341 if (nn < 8193) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
342 plan_flags |= FFTW_MEASURE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
343 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
344 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
345 plan_flags |= FFTW_ESTIMATE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
346 plan_destroys_in = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
347 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
348 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
349 } |
3828 | 350 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
351 if (ioalign) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
352 plan_flags &= ~FFTW_UNALIGNED; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
353 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
354 plan_flags |= FFTW_UNALIGNED; |
4773 | 355 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
356 if (*cur_plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
357 fftw_destroy_plan (*cur_plan_p); |
6228 | 358 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
359 if (plan_destroys_in) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
360 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
361 // Create matrix with the same size and 16-byte alignment as input |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
362 OCTAVE_LOCAL_BUFFER (double, itmp, nn + 32); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
363 itmp = reinterpret_cast<double *> |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
364 (((reinterpret_cast<ptrdiff_t>(itmp) + 15) & ~ 0xF) + |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
365 ((reinterpret_cast<ptrdiff_t> (in)) & 0xF)); |
6228 | 366 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
367 *cur_plan_p = |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
368 fftw_plan_many_dft_r2c (rank, tmp, howmany, itmp, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
369 0, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
370 reinterpret_cast<fftw_complex *> (out), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
371 0, stride, dist, plan_flags); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
372 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
373 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
374 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
375 *cur_plan_p = |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
376 fftw_plan_many_dft_r2c (rank, tmp, howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
377 (const_cast<double *> (in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
378 0, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
379 reinterpret_cast<fftw_complex *> (out), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
380 0, stride, dist, plan_flags); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
381 } |
6228 | 382 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
383 if (*cur_plan_p == 0) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
384 (*current_liboctave_error_handler) ("Error creating fftw plan"); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
385 } |
4808 | 386 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
387 return *cur_plan_p; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
388 } |
3828 | 389 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
390 fftw_planner::FftwMethod |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
391 fftw_planner::do_method (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
392 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
393 return meth; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
394 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
395 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
396 fftw_planner::FftwMethod |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
397 fftw_planner::do_method (FftwMethod _meth) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
398 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
399 FftwMethod ret = meth; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
400 if (_meth == ESTIMATE || _meth == MEASURE |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
401 || _meth == PATIENT || _meth == EXHAUSTIVE |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
402 || _meth == HYBRID) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
403 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
404 if (meth != _meth) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
405 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
406 meth = _meth; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
407 if (rplan) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
408 fftw_destroy_plan (reinterpret_cast<fftw_plan> (rplan)); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
409 if (plan[0]) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
410 fftw_destroy_plan (reinterpret_cast<fftw_plan> (plan[0])); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
411 if (plan[1]) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
412 fftw_destroy_plan (reinterpret_cast<fftw_plan> (plan[1])); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
413 rplan = plan[0] = plan[1] = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
414 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
415 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
416 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
417 ret = UNKNOWN; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
418 return ret; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
419 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
420 |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23440
diff
changeset
|
421 float_fftw_planner *float_fftw_planner::instance = nullptr; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
422 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
423 float_fftw_planner::float_fftw_planner (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
424 : meth (ESTIMATE), rplan (0), rd (0), rs (0), rr (0), rh (0), rn (), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
425 rsimd_align (false), nthreads (1) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
426 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
427 plan[0] = plan[1] = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
428 d[0] = d[1] = s[0] = s[1] = r[0] = r[1] = h[0] = h[1] = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
429 simd_align[0] = simd_align[1] = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
430 inplace[0] = inplace[1] = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
431 n[0] = n[1] = dim_vector (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
432 |
15960
bde7731b2b83
added FFTW multithreaded library support
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15271
diff
changeset
|
433 #if defined (HAVE_FFTW3F_THREADS) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
434 int init_ret = fftwf_init_threads (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
435 if (! init_ret) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
436 (*current_liboctave_error_handler) ("Error initializing FFTW3F threads"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
437 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
438 // Use number of processors available to the current process |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
439 // This can be later changed with fftw ("threads", nthreads). |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
440 nthreads = octave_num_processors_wrapper (OCTAVE_NPROC_CURRENT); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
441 fftwf_plan_with_nthreads (nthreads); |
15960
bde7731b2b83
added FFTW multithreaded library support
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15271
diff
changeset
|
442 #endif |
bde7731b2b83
added FFTW multithreaded library support
Andreas Weber <andy.weber.aw@gmail.com>
parents:
15271
diff
changeset
|
443 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
444 // If we have a system wide wisdom file, import it. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
445 fftwf_import_system_wisdom (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
446 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
447 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
448 float_fftw_planner::~float_fftw_planner (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
449 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
450 fftwf_plan *plan_p; |
14078
941d19370065
Cleanup FFTW wisdom plans in class destructor and prevent a memory leak.
Rik <octave@nomad.inbox5.com>
parents:
13994
diff
changeset
|
451 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
452 plan_p = reinterpret_cast<fftwf_plan *> (&rplan); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
453 if (*plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
454 fftwf_destroy_plan (*plan_p); |
14078
941d19370065
Cleanup FFTW wisdom plans in class destructor and prevent a memory leak.
Rik <octave@nomad.inbox5.com>
parents:
13994
diff
changeset
|
455 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
456 plan_p = reinterpret_cast<fftwf_plan *> (&plan[0]); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
457 if (*plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
458 fftwf_destroy_plan (*plan_p); |
14078
941d19370065
Cleanup FFTW wisdom plans in class destructor and prevent a memory leak.
Rik <octave@nomad.inbox5.com>
parents:
13994
diff
changeset
|
459 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
460 plan_p = reinterpret_cast<fftwf_plan *> (&plan[1]); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
461 if (*plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
462 fftwf_destroy_plan (*plan_p); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
463 } |
14078
941d19370065
Cleanup FFTW wisdom plans in class destructor and prevent a memory leak.
Rik <octave@nomad.inbox5.com>
parents:
13994
diff
changeset
|
464 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
465 bool |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
466 float_fftw_planner::instance_ok (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
467 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
468 bool retval = true; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
469 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
470 if (! instance) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
471 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
472 instance = new float_fftw_planner (); |
13994
99f039289e95
also clean up float fftw planner
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
473 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
474 if (instance) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
475 singleton_cleanup_list::add (cleanup_instance); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
476 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
477 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
478 if (! instance) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
479 (*current_liboctave_error_handler) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
480 ("unable to create fftw_planner object!"); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
481 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
482 return retval; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
483 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
484 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
485 void |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
486 float_fftw_planner::threads (int nt) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
487 { |
21451
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
488 #if defined (HAVE_FFTW3F_THREADS) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
489 if (instance_ok () && nt != threads ()) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
490 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
491 instance->nthreads = nt; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
492 fftwf_plan_with_nthreads (nt); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
493 // Clear the current plans. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
494 instance->rplan = instance->plan[0] = instance->plan[1] = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
495 } |
21451
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
496 #else |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
497 (*current_liboctave_warning_handler) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
498 ("unable to change number of threads without FFTW thread support"); |
21451
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
499 #endif |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
500 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
501 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
502 void * |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
503 float_fftw_planner::do_create_plan (int dir, const int rank, |
23440
f15f0d8b78c8
pass dim_vector as const reference, not by value
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
504 const dim_vector& dims, |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
505 octave_idx_type howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
506 octave_idx_type stride, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
507 octave_idx_type dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
508 const FloatComplex *in, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
509 FloatComplex *out) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
510 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
511 int which = (dir == FFTW_FORWARD) ? 0 : 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
512 fftwf_plan *cur_plan_p = reinterpret_cast<fftwf_plan *> (&plan[which]); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
513 bool create_new_plan = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
514 bool ioalign = CHECK_SIMD_ALIGNMENT (in) && CHECK_SIMD_ALIGNMENT (out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
515 bool ioinplace = (in == out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
516 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
517 // Don't create a new plan if we have a non SIMD plan already but |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
518 // can do SIMD. This prevents endlessly recreating plans if we |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
519 // change the alignment. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
520 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
521 if (plan[which] == 0 || d[which] != dist || s[which] != stride |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
522 || r[which] != rank || h[which] != howmany |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
523 || ioinplace != inplace[which] |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
524 || ((ioalign != simd_align[which]) ? ! ioalign : false)) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
525 create_new_plan = true; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
526 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
527 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
528 // We still might not have the same shape of array. |
21451
763e30285935
eliminate configuration macros from oct-fftw.h (bug #41027)
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
529 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
530 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
531 if (dims(i) != n[which](i)) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
532 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
533 create_new_plan = true; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
534 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
535 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
536 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
537 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
538 if (create_new_plan) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
539 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
540 d[which] = dist; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
541 s[which] = stride; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
542 r[which] = rank; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
543 h[which] = howmany; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
544 simd_align[which] = ioalign; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
545 inplace[which] = ioinplace; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
546 n[which] = dims; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
547 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
548 // Note reversal of dimensions for column major storage in FFTW. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
549 octave_idx_type nn = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
550 OCTAVE_LOCAL_BUFFER (int, tmp, rank); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
551 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
552 for (int i = 0, j = rank-1; i < rank; i++, j--) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
553 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
554 tmp[i] = dims(j); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
555 nn *= dims(j); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
556 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
557 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
558 int plan_flags = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
559 bool plan_destroys_in = true; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
560 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
561 switch (meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
562 { |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
563 case UNKNOWN: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
564 case ESTIMATE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
565 plan_flags |= FFTW_ESTIMATE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
566 plan_destroys_in = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
567 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
568 case MEASURE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
569 plan_flags |= FFTW_MEASURE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
570 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
571 case PATIENT: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
572 plan_flags |= FFTW_PATIENT; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
573 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
574 case EXHAUSTIVE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
575 plan_flags |= FFTW_EXHAUSTIVE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
576 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
577 case HYBRID: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
578 if (nn < 8193) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
579 plan_flags |= FFTW_MEASURE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
580 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
581 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
582 plan_flags |= FFTW_ESTIMATE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
583 plan_destroys_in = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
584 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
585 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
586 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
587 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
588 if (ioalign) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
589 plan_flags &= ~FFTW_UNALIGNED; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
590 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
591 plan_flags |= FFTW_UNALIGNED; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
592 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
593 if (*cur_plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
594 fftwf_destroy_plan (*cur_plan_p); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
595 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
596 if (plan_destroys_in) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
597 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
598 // Create matrix with the same size and 16-byte alignment as input |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
599 OCTAVE_LOCAL_BUFFER (FloatComplex, itmp, nn * howmany + 32); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
600 itmp = reinterpret_cast<FloatComplex *> |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
601 (((reinterpret_cast<ptrdiff_t>(itmp) + 15) & ~ 0xF) + |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
602 ((reinterpret_cast<ptrdiff_t> (in)) & 0xF)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
603 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
604 *cur_plan_p = |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
605 fftwf_plan_many_dft (rank, tmp, howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
606 reinterpret_cast<fftwf_complex *> (itmp), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
607 0, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
608 reinterpret_cast<fftwf_complex *> (out), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
609 0, stride, dist, dir, plan_flags); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
610 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
611 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
612 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
613 *cur_plan_p = |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
614 fftwf_plan_many_dft (rank, tmp, howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
615 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *> (in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
616 0, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
617 reinterpret_cast<fftwf_complex *> (out), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
618 0, stride, dist, dir, plan_flags); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
619 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
620 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
621 if (*cur_plan_p == 0) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
622 (*current_liboctave_error_handler) ("Error creating fftw plan"); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
623 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
624 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
625 return *cur_plan_p; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
626 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
627 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
628 void * |
23440
f15f0d8b78c8
pass dim_vector as const reference, not by value
John W. Eaton <jwe@octave.org>
parents:
23433
diff
changeset
|
629 float_fftw_planner::do_create_plan (const int rank, const dim_vector& dims, |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
630 octave_idx_type howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
631 octave_idx_type stride, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
632 octave_idx_type dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
633 const float *in, FloatComplex *out) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
634 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
635 fftwf_plan *cur_plan_p = reinterpret_cast<fftwf_plan *> (&rplan); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
636 bool create_new_plan = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
637 bool ioalign = CHECK_SIMD_ALIGNMENT (in) && CHECK_SIMD_ALIGNMENT (out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
638 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
639 // Don't create a new plan if we have a non SIMD plan already but |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
640 // can do SIMD. This prevents endlessly recreating plans if we |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
641 // change the alignment. |
3828 | 642 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
643 if (rplan == 0 || rd != dist || rs != stride || rr != rank |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
644 || rh != howmany || ((ioalign != rsimd_align) ? ! ioalign : false)) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
645 create_new_plan = true; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
646 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
647 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
648 // We still might not have the same shape of array. |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
649 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
650 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
651 if (dims(i) != rn(i)) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
652 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
653 create_new_plan = true; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
654 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
655 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
656 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
657 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
658 if (create_new_plan) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
659 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
660 rd = dist; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
661 rs = stride; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
662 rr = rank; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
663 rh = howmany; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
664 rsimd_align = ioalign; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
665 rn = dims; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
666 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
667 // Note reversal of dimensions for column major storage in FFTW. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
668 octave_idx_type nn = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
669 OCTAVE_LOCAL_BUFFER (int, tmp, rank); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
670 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
671 for (int i = 0, j = rank-1; i < rank; i++, j--) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
672 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
673 tmp[i] = dims(j); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
674 nn *= dims(j); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
675 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
676 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
677 int plan_flags = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
678 bool plan_destroys_in = true; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
679 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
680 switch (meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
681 { |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
682 case UNKNOWN: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
683 case ESTIMATE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
684 plan_flags |= FFTW_ESTIMATE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
685 plan_destroys_in = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
686 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
687 case MEASURE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
688 plan_flags |= FFTW_MEASURE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
689 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
690 case PATIENT: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
691 plan_flags |= FFTW_PATIENT; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
692 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
693 case EXHAUSTIVE: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
694 plan_flags |= FFTW_EXHAUSTIVE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
695 break; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
696 case HYBRID: |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
697 if (nn < 8193) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
698 plan_flags |= FFTW_MEASURE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
699 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
700 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
701 plan_flags |= FFTW_ESTIMATE; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
702 plan_destroys_in = false; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
703 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
704 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
705 } |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
706 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
707 if (ioalign) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
708 plan_flags &= ~FFTW_UNALIGNED; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
709 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
710 plan_flags |= FFTW_UNALIGNED; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
711 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
712 if (*cur_plan_p) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
713 fftwf_destroy_plan (*cur_plan_p); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
714 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
715 if (plan_destroys_in) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
716 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
717 // Create matrix with the same size and 16-byte alignment as input |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
718 OCTAVE_LOCAL_BUFFER (float, itmp, nn + 32); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
719 itmp = reinterpret_cast<float *> |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
720 (((reinterpret_cast<ptrdiff_t>(itmp) + 15) & ~ 0xF) + |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
721 ((reinterpret_cast<ptrdiff_t> (in)) & 0xF)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
722 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
723 *cur_plan_p = |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
724 fftwf_plan_many_dft_r2c (rank, tmp, howmany, itmp, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
725 0, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
726 reinterpret_cast<fftwf_complex *> (out), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
727 0, stride, dist, plan_flags); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
728 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
729 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
730 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
731 *cur_plan_p = |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
732 fftwf_plan_many_dft_r2c (rank, tmp, howmany, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
733 (const_cast<float *> (in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
734 0, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
735 reinterpret_cast<fftwf_complex *> (out), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
736 0, stride, dist, plan_flags); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
737 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
738 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
739 if (*cur_plan_p == 0) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
740 (*current_liboctave_error_handler) ("Error creating fftw plan"); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
741 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
742 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
743 return *cur_plan_p; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
744 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
745 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
746 float_fftw_planner::FftwMethod |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
747 float_fftw_planner::do_method (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
748 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
749 return meth; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
750 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
751 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
752 float_fftw_planner::FftwMethod |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
753 float_fftw_planner::do_method (FftwMethod _meth) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
754 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
755 FftwMethod ret = meth; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
756 if (_meth == ESTIMATE || _meth == MEASURE |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
757 || _meth == PATIENT || _meth == EXHAUSTIVE |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
758 || _meth == HYBRID) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
759 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
760 if (meth != _meth) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
761 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
762 meth = _meth; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
763 if (rplan) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
764 fftwf_destroy_plan (reinterpret_cast<fftwf_plan> (rplan)); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
765 if (plan[0]) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
766 fftwf_destroy_plan (reinterpret_cast<fftwf_plan> (plan[0])); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
767 if (plan[1]) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
768 fftwf_destroy_plan (reinterpret_cast<fftwf_plan> (plan[1])); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
769 rplan = plan[0] = plan[1] = 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
770 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
771 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
772 else |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
773 ret = UNKNOWN; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
774 return ret; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
775 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
776 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
777 template <typename T> |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
778 static inline void |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
779 convert_packcomplex_1d (T *out, size_t nr, size_t nc, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
780 octave_idx_type stride, octave_idx_type dist) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
781 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
782 octave_quit (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
783 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
784 // Fill in the missing data. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
785 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
786 for (size_t i = 0; i < nr; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
787 for (size_t j = nc/2+1; j < nc; j++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
788 out[j*stride + i*dist] = conj (out[(nc - j)*stride + i*dist]); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
789 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
790 octave_quit (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
791 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
792 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
793 template <typename T> |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
794 static inline void |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
795 convert_packcomplex_Nd (T *out, const dim_vector& dv) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
796 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
797 size_t nc = dv(0); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
798 size_t nr = dv(1); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
799 size_t np = (dv.ndims () > 2 ? dv.numel () / nc / nr : 1); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
800 size_t nrp = nr * np; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
801 T *ptr1, *ptr2; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
802 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
803 octave_quit (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
804 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
805 // Create space for the missing elements. |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
806 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
807 for (size_t i = 0; i < nrp; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
808 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
809 ptr1 = out + i * (nc/2 + 1) + nrp*((nc-1)/2); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
810 ptr2 = out + i * nc; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
811 for (size_t j = 0; j < nc/2+1; j++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
812 *ptr2++ = *ptr1++; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
813 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
814 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
815 octave_quit (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
816 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
817 // Fill in the missing data for the rank = 2 case directly for speed. |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
818 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
819 for (size_t i = 0; i < np; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
820 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
821 for (size_t j = 1; j < nr; j++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
822 for (size_t k = nc/2+1; k < nc; k++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
823 out[k + (j + i*nr)*nc] = conj (out[nc - k + ((i+1)*nr - j)*nc]); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
824 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
825 for (size_t j = nc/2+1; j < nc; j++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
826 out[j + i*nr*nc] = conj (out[(i*nr+1)*nc - j]); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
827 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
828 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
829 octave_quit (); |
4785 | 830 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
831 // Now do the permutations needed for rank > 2 cases. |
4785 | 832 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
833 size_t jstart = dv(0) * dv(1); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
834 size_t kstep = dv(0); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
835 size_t nel = dv.numel (); |
4773 | 836 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
837 for (int inner = 2; inner < dv.ndims (); inner++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
838 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
839 size_t jmax = jstart * dv(inner); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
840 for (size_t i = 0; i < nel; i+=jmax) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
841 for (size_t j = jstart, jj = jmax-jstart; j < jj; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
842 j+=jstart, jj-=jstart) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
843 for (size_t k = 0; k < jstart; k+= kstep) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
844 for (size_t l = nc/2+1; l < nc; l++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
845 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
846 T tmp = out[i+ j + k + l]; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
847 out[i + j + k + l] = out[i + jj + k + l]; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
848 out[i + jj + k + l] = tmp; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
849 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
850 jstart = jmax; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
851 } |
4785 | 852 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
853 octave_quit (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
854 } |
4785 | 855 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
856 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
857 fftw::fft (const double *in, Complex *out, size_t npts, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
858 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
859 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
860 dist = (dist < 0 ? npts : dist); |
4773 | 861 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
862 dim_vector dv (npts, 1); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
863 void *vplan = fftw_planner::create_plan (1, dv, nsamples, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
864 stride, dist, in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
865 fftw_plan plan = reinterpret_cast<fftw_plan> (vplan); |
4785 | 866 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
867 fftw_execute_dft_r2c (plan, (const_cast<double *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
868 reinterpret_cast<fftw_complex *> (out)); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
869 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
870 // Need to create other half of the transform. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
871 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
872 convert_packcomplex_1d (out, nsamples, npts, stride, dist); |
4785 | 873 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
874 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
875 } |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
876 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
877 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
878 fftw::fft (const Complex *in, Complex *out, size_t npts, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
879 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
880 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
881 dist = (dist < 0 ? npts : dist); |
4773 | 882 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
883 dim_vector dv (npts, 1); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
884 void *vplan = fftw_planner::create_plan (FFTW_FORWARD, 1, dv, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
885 nsamples, stride, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
886 dist, in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
887 fftw_plan plan = reinterpret_cast<fftw_plan> (vplan); |
4773 | 888 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
889 fftw_execute_dft (plan, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
890 reinterpret_cast<fftw_complex *> (const_cast<Complex *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
891 reinterpret_cast<fftw_complex *> (out)); |
4773 | 892 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
893 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
894 } |
3828 | 895 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
896 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
897 fftw::ifft (const Complex *in, Complex *out, size_t npts, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
898 size_t nsamples, octave_idx_type stride, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
899 octave_idx_type dist) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
900 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
901 dist = (dist < 0 ? npts : dist); |
4773 | 902 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
903 dim_vector dv (npts, 1); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
904 void *vplan = fftw_planner::create_plan (FFTW_BACKWARD, 1, dv, nsamples, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
905 stride, dist, in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
906 fftw_plan plan = reinterpret_cast<fftw_plan> (vplan); |
4773 | 907 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
908 fftw_execute_dft (plan, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
909 reinterpret_cast<fftw_complex *> (const_cast<Complex *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
910 reinterpret_cast<fftw_complex *> (out)); |
4773 | 911 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
912 const Complex scale = npts; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
913 for (size_t j = 0; j < nsamples; j++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
914 for (size_t i = 0; i < npts; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
915 out[i*stride + j*dist] /= scale; |
4773 | 916 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
917 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
918 } |
4773 | 919 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
920 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
921 fftw::fftNd (const double *in, Complex *out, const int rank, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
922 const dim_vector& dv) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
923 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
924 octave_idx_type dist = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
925 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
926 dist *= dv(i); |
4773 | 927 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
928 // Fool with the position of the start of the output matrix, so that |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
929 // creating other half of the matrix won't cause cache problems. |
3828 | 930 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
931 octave_idx_type offset = (dv.numel () / dv(0)) * ((dv(0) - 1) / 2); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
932 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
933 void *vplan = fftw_planner::create_plan (rank, dv, 1, 1, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
934 in, out + offset); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
935 fftw_plan plan = reinterpret_cast<fftw_plan> (vplan); |
3828 | 936 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
937 fftw_execute_dft_r2c (plan, (const_cast<double *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
938 reinterpret_cast<fftw_complex *> (out+ offset)); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
939 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
940 // Need to create other half of the transform. |
3828 | 941 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
942 convert_packcomplex_Nd (out, dv); |
4773 | 943 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
944 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
945 } |
4809 | 946 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
947 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
948 fftw::fftNd (const Complex *in, Complex *out, const int rank, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
949 const dim_vector& dv) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
950 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
951 octave_idx_type dist = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
952 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
953 dist *= dv(i); |
4773 | 954 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
955 void *vplan = fftw_planner::create_plan (FFTW_FORWARD, rank, dv, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
956 1, 1, dist, in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
957 fftw_plan plan = reinterpret_cast<fftw_plan> (vplan); |
4809 | 958 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
959 fftw_execute_dft (plan, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
960 reinterpret_cast<fftw_complex *> (const_cast<Complex *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
961 reinterpret_cast<fftw_complex *> (out)); |
3828 | 962 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
963 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
964 } |
4773 | 965 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
966 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
967 fftw::ifftNd (const Complex *in, Complex *out, const int rank, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
968 const dim_vector& dv) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
969 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
970 octave_idx_type dist = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
971 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
972 dist *= dv(i); |
4773 | 973 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
974 void *vplan = fftw_planner::create_plan (FFTW_BACKWARD, rank, dv, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
975 1, 1, dist, in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
976 fftw_plan plan = reinterpret_cast<fftw_plan> (vplan); |
4773 | 977 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
978 fftw_execute_dft (plan, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
979 reinterpret_cast<fftw_complex *> (const_cast<Complex *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
980 reinterpret_cast<fftw_complex *> (out)); |
3828 | 981 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
982 const size_t npts = dv.numel (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
983 const Complex scale = npts; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
984 for (size_t i = 0; i < npts; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
985 out[i] /= scale; |
4773 | 986 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
987 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
988 } |
4773 | 989 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
990 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
991 fftw::fft (const float *in, FloatComplex *out, size_t npts, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
992 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
993 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
994 dist = (dist < 0 ? npts : dist); |
4773 | 995 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
996 dim_vector dv (npts, 1); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
997 void *vplan = float_fftw_planner::create_plan (1, dv, nsamples, stride, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
998 dist, in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
999 fftwf_plan plan = reinterpret_cast<fftwf_plan> (vplan); |
3828 | 1000 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1001 fftwf_execute_dft_r2c (plan, (const_cast<float *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1002 reinterpret_cast<fftwf_complex *> (out)); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1003 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1004 // Need to create other half of the transform. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1005 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1006 convert_packcomplex_1d (out, nsamples, npts, stride, dist); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1007 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1008 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1009 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1010 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1011 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1012 fftw::fft (const FloatComplex *in, FloatComplex *out, size_t npts, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1013 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1014 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1015 dist = (dist < 0 ? npts : dist); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1016 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1017 dim_vector dv (npts, 1); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1018 void *vplan = float_fftw_planner::create_plan (FFTW_FORWARD, 1, dv, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1019 nsamples, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1020 in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1021 fftwf_plan plan = reinterpret_cast<fftwf_plan> (vplan); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1022 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1023 fftwf_execute_dft (plan, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1024 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1025 reinterpret_cast<fftwf_complex *> (out)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1026 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1027 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1028 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1029 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1030 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1031 fftw::ifft (const FloatComplex *in, FloatComplex *out, size_t npts, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1032 size_t nsamples, octave_idx_type stride, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1033 octave_idx_type dist) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1034 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1035 dist = (dist < 0 ? npts : dist); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1036 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1037 dim_vector dv (npts, 1); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1038 void *vplan = float_fftw_planner::create_plan (FFTW_BACKWARD, 1, dv, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1039 nsamples, stride, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1040 in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1041 fftwf_plan plan = reinterpret_cast<fftwf_plan> (vplan); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1042 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1043 fftwf_execute_dft (plan, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1044 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1045 reinterpret_cast<fftwf_complex *> (out)); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1046 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1047 const FloatComplex scale = npts; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1048 for (size_t j = 0; j < nsamples; j++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1049 for (size_t i = 0; i < npts; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1050 out[i*stride + j*dist] /= scale; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1051 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1052 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1053 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1054 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1055 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1056 fftw::fftNd (const float *in, FloatComplex *out, const int rank, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1057 const dim_vector& dv) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1058 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1059 octave_idx_type dist = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1060 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1061 dist *= dv(i); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1062 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1063 // Fool with the position of the start of the output matrix, so that |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1064 // creating other half of the matrix won't cause cache problems. |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1065 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1066 octave_idx_type offset = (dv.numel () / dv(0)) * ((dv(0) - 1) / 2); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1067 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1068 void *vplan = float_fftw_planner::create_plan (rank, dv, 1, 1, dist, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1069 in, out + offset); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1070 fftwf_plan plan = reinterpret_cast<fftwf_plan> (vplan); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1071 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1072 fftwf_execute_dft_r2c (plan, (const_cast<float *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1073 reinterpret_cast<fftwf_complex *> (out+ offset)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1074 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1075 // Need to create other half of the transform. |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1076 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1077 convert_packcomplex_Nd (out, dv); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1078 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1079 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1080 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1081 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1082 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1083 fftw::fftNd (const FloatComplex *in, FloatComplex *out, const int rank, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1084 const dim_vector& dv) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1085 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1086 octave_idx_type dist = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1087 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1088 dist *= dv(i); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1089 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1090 void *vplan = float_fftw_planner::create_plan (FFTW_FORWARD, rank, dv, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1091 1, 1, dist, in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1092 fftwf_plan plan = reinterpret_cast<fftwf_plan> (vplan); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1093 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1094 fftwf_execute_dft (plan, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1095 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1096 reinterpret_cast<fftwf_complex *> (out)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1097 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1098 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1099 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1100 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1101 int |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1102 fftw::ifftNd (const FloatComplex *in, FloatComplex *out, const int rank, |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
1103 const dim_vector& dv) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1104 { |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1105 octave_idx_type dist = 1; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1106 for (int i = 0; i < rank; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1107 dist *= dv(i); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1108 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1109 void *vplan = float_fftw_planner::create_plan (FFTW_BACKWARD, rank, dv, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1110 1, 1, dist, in, out); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1111 fftwf_plan plan = reinterpret_cast<fftwf_plan> (vplan); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1112 |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1113 fftwf_execute_dft (plan, |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1114 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *>(in)), |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1115 reinterpret_cast<fftwf_complex *> (out)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1116 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1117 const size_t npts = dv.numel (); |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1118 const FloatComplex scale = npts; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1119 for (size_t i = 0; i < npts; i++) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1120 out[i] /= scale; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1121 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1122 return 0; |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1123 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1124 |
3828 | 1125 #endif |
21600
184b85b31e03
more updates for version function
mmuetzel <markus.muetzel@gmx.de>
parents:
21520
diff
changeset
|
1126 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1127 std::string |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1128 fftw_version (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1129 { |
21600
184b85b31e03
more updates for version function
mmuetzel <markus.muetzel@gmx.de>
parents:
21520
diff
changeset
|
1130 #if defined (HAVE_FFTW) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1131 return ::fftw_version; |
21600
184b85b31e03
more updates for version function
mmuetzel <markus.muetzel@gmx.de>
parents:
21520
diff
changeset
|
1132 #else |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1133 return "none"; |
21600
184b85b31e03
more updates for version function
mmuetzel <markus.muetzel@gmx.de>
parents:
21520
diff
changeset
|
1134 #endif |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1135 } |
21603
37cbdf7bffa9
Add fftwf_version (bug #45659)
mmuetzel <markus.muetzel@gmx.de>
parents:
21600
diff
changeset
|
1136 |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1137 std::string |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1138 fftwf_version (void) |
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1139 { |
21603
37cbdf7bffa9
Add fftwf_version (bug #45659)
mmuetzel <markus.muetzel@gmx.de>
parents:
21600
diff
changeset
|
1140 #if defined (HAVE_FFTW) |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1141 return ::fftwf_version; |
21603
37cbdf7bffa9
Add fftwf_version (bug #45659)
mmuetzel <markus.muetzel@gmx.de>
parents:
21600
diff
changeset
|
1142 #else |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1143 return "none"; |
21603
37cbdf7bffa9
Add fftwf_version (bug #45659)
mmuetzel <markus.muetzel@gmx.de>
parents:
21600
diff
changeset
|
1144 #endif |
23058
5839d16828cb
move fftw classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
1145 } |
21603
37cbdf7bffa9
Add fftwf_version (bug #45659)
mmuetzel <markus.muetzel@gmx.de>
parents:
21600
diff
changeset
|
1146 } |