Mercurial > octave-nkf
annotate liboctave/oct-fftw.cc @ 13994:99f039289e95
also clean up float fftw planner
* oct-fftw.h (octave_float_fftw_planner::cleanup_instance):
New function.
* oct-fftw.cc (octave_float_fftw_planner::instance_ok):
Add instance to singleton cleanup list.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 Dec 2011 00:30:51 -0500 |
parents | 7dd7cccf0757 |
children | 941d19370065 |
rev | line source |
---|---|
3828 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2001-2011 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 | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3828 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
3828 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9516
diff
changeset
|
27 #if defined (HAVE_FFTW) |
3828 | 28 |
4775 | 29 #include <iostream> |
30 #include <vector> | |
31 | |
4786 | 32 #include "lo-error.h" |
3828 | 33 #include "oct-fftw.h" |
4786 | 34 #include "quit.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
35 #include "oct-locbuf.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
36 #include "singleton-cleanup.h" |
3828 | 37 |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
38 octave_fftw_planner *octave_fftw_planner::instance = 0; |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
39 |
4809 | 40 // Helper class to create and cache fftw plans for both 1d and |
6228 | 41 // 2d. This implementation defaults to using FFTW_ESTIMATE to create |
42 // the plans, which in theory is suboptimal, but provides quit | |
43 // reasonable performance. | |
4773 | 44 |
45 // Also note that if FFTW_ESTIMATE is not used the planner in FFTW3 | |
6228 | 46 // destroys the input and output arrays. We must therefore create a |
47 // temporary input array with the same size and 16-byte alignment as | |
48 // the original array and use that for the planner. Note that we also | |
49 // use any wisdom that is available, either in a FFTW3 system wide file | |
50 // or as supplied by the user. | |
4773 | 51 |
5775 | 52 // FIXME -- if we can ensure 16 byte alignment in Array<T> |
4809 | 53 // (<T> *data) the FFTW3 can use SIMD instructions for further |
54 // acceleration. | |
4773 | 55 |
4809 | 56 // Note that it is profitable to store the FFTW3 plans, for small |
57 // ffts. | |
3828 | 58 |
4808 | 59 octave_fftw_planner::octave_fftw_planner (void) |
11509
fc35194006d6
oct-fftw.cc: more constructor tweaks
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
60 : meth (ESTIMATE), rplan (0), rd (0), rs (0), rr (0), rh (0), rn (), |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
61 rsimd_align (false) |
3828 | 62 { |
63 plan[0] = plan[1] = 0; | |
4773 | 64 d[0] = d[1] = s[0] = s[1] = r[0] = r[1] = h[0] = h[1] = 0; |
4808 | 65 simd_align[0] = simd_align[1] = false; |
5044 | 66 inplace[0] = inplace[1] = false; |
4808 | 67 n[0] = n[1] = dim_vector (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
68 |
4809 | 69 // If we have a system wide wisdom file, import it. |
4808 | 70 fftw_import_system_wisdom (); |
3828 | 71 } |
72 | |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
73 bool |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
74 octave_fftw_planner::instance_ok (void) |
6228 | 75 { |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
76 bool retval = true; |
6228 | 77 |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
78 if (! instance) |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
79 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
80 instance = new octave_fftw_planner (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
81 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
82 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
83 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
84 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
85 |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
86 if (! instance) |
6228 | 87 { |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
88 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
89 ("unable to create octave_fftw_planner object!"); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
90 |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
91 retval = false; |
6228 | 92 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
93 |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
94 return retval; |
6228 | 95 } |
96 | |
4808 | 97 #define CHECK_SIMD_ALIGNMENT(x) \ |
6482 | 98 (((reinterpret_cast<ptrdiff_t> (x)) & 0xF) == 0) |
4808 | 99 |
3828 | 100 fftw_plan |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
101 octave_fftw_planner::do_create_plan (int dir, const int rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 const dim_vector dims, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
103 octave_idx_type howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
104 octave_idx_type stride, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
105 octave_idx_type dist, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
106 const Complex *in, Complex *out) |
3828 | 107 { |
4773 | 108 int which = (dir == FFTW_FORWARD) ? 0 : 1; |
3828 | 109 fftw_plan *cur_plan_p = &plan[which]; |
110 bool create_new_plan = false; | |
4808 | 111 bool ioalign = CHECK_SIMD_ALIGNMENT (in) && CHECK_SIMD_ALIGNMENT (out); |
5044 | 112 bool ioinplace = (in == out); |
3828 | 113 |
4809 | 114 // Don't create a new plan if we have a non SIMD plan already but |
115 // can do SIMD. This prevents endlessly recreating plans if we | |
116 // change the alignment. | |
117 | |
4783 | 118 if (plan[which] == 0 || d[which] != dist || s[which] != stride |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
119 || r[which] != rank || h[which] != howmany |
5044 | 120 || ioinplace != inplace[which] |
4808 | 121 || ((ioalign != simd_align[which]) ? !ioalign : false)) |
4773 | 122 create_new_plan = true; |
123 else | |
4809 | 124 { |
125 // We still might not have the same shape of array. | |
126 | |
127 for (int i = 0; i < rank; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
128 if (dims(i) != n[which](i)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
129 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
130 create_new_plan = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
131 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
132 } |
4809 | 133 } |
3828 | 134 |
135 if (create_new_plan) | |
136 { | |
4773 | 137 d[which] = dist; |
138 s[which] = stride; | |
139 r[which] = rank; | |
140 h[which] = howmany; | |
4808 | 141 simd_align[which] = ioalign; |
5044 | 142 inplace[which] = ioinplace; |
4773 | 143 n[which] = dims; |
144 | |
6228 | 145 // Note reversal of dimensions for column major storage in FFTW. |
146 octave_idx_type nn = 1; | |
147 OCTAVE_LOCAL_BUFFER (int, tmp, rank); | |
148 | |
149 for (int i = 0, j = rank-1; i < rank; i++, j--) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
150 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
151 tmp[i] = dims(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
152 nn *= dims(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
153 } |
6228 | 154 |
155 int plan_flags = 0; | |
156 bool plan_destroys_in = true; | |
157 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
158 switch (meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
159 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
160 case UNKNOWN: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
161 case ESTIMATE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
162 plan_flags |= FFTW_ESTIMATE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
163 plan_destroys_in = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
164 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
165 case MEASURE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
166 plan_flags |= FFTW_MEASURE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
167 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
168 case PATIENT: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
169 plan_flags |= FFTW_PATIENT; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
170 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
171 case EXHAUSTIVE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
172 plan_flags |= FFTW_EXHAUSTIVE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
173 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
174 case HYBRID: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
175 if (nn < 8193) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
176 plan_flags |= FFTW_MEASURE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
177 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
178 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
179 plan_flags |= FFTW_ESTIMATE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
180 plan_destroys_in = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
181 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
182 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
183 } |
6228 | 184 |
4808 | 185 if (ioalign) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
186 plan_flags &= ~FFTW_UNALIGNED; |
4808 | 187 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
188 plan_flags |= FFTW_UNALIGNED; |
4808 | 189 |
3828 | 190 if (*cur_plan_p) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
191 fftw_destroy_plan (*cur_plan_p); |
3828 | 192 |
6228 | 193 if (plan_destroys_in) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
194 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
195 // Create matrix with the same size and 16-byte alignment as input |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
196 OCTAVE_LOCAL_BUFFER (Complex, itmp, nn * howmany + 32); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
197 itmp = reinterpret_cast<Complex *> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
198 (((reinterpret_cast<ptrdiff_t>(itmp) + 15) & ~ 0xF) + |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
199 ((reinterpret_cast<ptrdiff_t> (in)) & 0xF)); |
4809 | 200 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
201 *cur_plan_p = |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
202 fftw_plan_many_dft (rank, tmp, howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
203 reinterpret_cast<fftw_complex *> (itmp), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
204 0, stride, dist, reinterpret_cast<fftw_complex *> (out), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
205 0, stride, dist, dir, plan_flags); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
206 } |
6228 | 207 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
208 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
209 *cur_plan_p = |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
210 fftw_plan_many_dft (rank, tmp, howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
211 reinterpret_cast<fftw_complex *> (const_cast<Complex *> (in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
212 0, stride, dist, reinterpret_cast<fftw_complex *> (out), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
213 0, stride, dist, dir, plan_flags); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
214 } |
3828 | 215 |
216 if (*cur_plan_p == 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
217 (*current_liboctave_error_handler) ("Error creating fftw plan"); |
3828 | 218 } |
219 | |
220 return *cur_plan_p; | |
221 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
222 |
4773 | 223 fftw_plan |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
224 octave_fftw_planner::do_create_plan (const int rank, const dim_vector dims, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
225 octave_idx_type howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
226 octave_idx_type stride, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
227 octave_idx_type dist, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
228 const double *in, Complex *out) |
3828 | 229 { |
4773 | 230 fftw_plan *cur_plan_p = &rplan; |
3828 | 231 bool create_new_plan = false; |
4808 | 232 bool ioalign = CHECK_SIMD_ALIGNMENT (in) && CHECK_SIMD_ALIGNMENT (out); |
3828 | 233 |
4809 | 234 // Don't create a new plan if we have a non SIMD plan already but |
235 // can do SIMD. This prevents endlessly recreating plans if we | |
236 // change the alignment. | |
237 | |
4783 | 238 if (rplan == 0 || rd != dist || rs != stride || rr != rank |
4808 | 239 || rh != howmany || ((ioalign != rsimd_align) ? !ioalign : false)) |
4773 | 240 create_new_plan = true; |
241 else | |
4809 | 242 { |
243 // We still might not have the same shape of array. | |
244 | |
245 for (int i = 0; i < rank; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
246 if (dims(i) != rn(i)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
247 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
248 create_new_plan = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
249 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
250 } |
4809 | 251 } |
3828 | 252 |
253 if (create_new_plan) | |
254 { | |
4773 | 255 rd = dist; |
256 rs = stride; | |
257 rr = rank; | |
258 rh = howmany; | |
4808 | 259 rsimd_align = ioalign; |
4773 | 260 rn = dims; |
261 | |
6228 | 262 // Note reversal of dimensions for column major storage in FFTW. |
263 octave_idx_type nn = 1; | |
264 OCTAVE_LOCAL_BUFFER (int, tmp, rank); | |
265 | |
266 for (int i = 0, j = rank-1; i < rank; i++, j--) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
267 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
268 tmp[i] = dims(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
269 nn *= dims(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
270 } |
6228 | 271 |
272 int plan_flags = 0; | |
273 bool plan_destroys_in = true; | |
274 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
275 switch (meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
276 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
277 case UNKNOWN: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
278 case ESTIMATE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
279 plan_flags |= FFTW_ESTIMATE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
280 plan_destroys_in = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
281 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
282 case MEASURE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
283 plan_flags |= FFTW_MEASURE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
284 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
285 case PATIENT: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
286 plan_flags |= FFTW_PATIENT; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
287 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
288 case EXHAUSTIVE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
289 plan_flags |= FFTW_EXHAUSTIVE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
290 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
291 case HYBRID: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
292 if (nn < 8193) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
293 plan_flags |= FFTW_MEASURE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
294 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
295 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
296 plan_flags |= FFTW_ESTIMATE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
297 plan_destroys_in = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
298 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
299 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
300 } |
6228 | 301 |
4808 | 302 if (ioalign) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
303 plan_flags &= ~FFTW_UNALIGNED; |
4808 | 304 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
305 plan_flags |= FFTW_UNALIGNED; |
4808 | 306 |
3828 | 307 if (*cur_plan_p) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
308 fftw_destroy_plan (*cur_plan_p); |
3828 | 309 |
6228 | 310 if (plan_destroys_in) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
311 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
312 // Create matrix with the same size and 16-byte alignment as input |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
313 OCTAVE_LOCAL_BUFFER (double, itmp, nn + 32); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
314 itmp = reinterpret_cast<double *> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
315 (((reinterpret_cast<ptrdiff_t>(itmp) + 15) & ~ 0xF) + |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
316 ((reinterpret_cast<ptrdiff_t> (in)) & 0xF)); |
4809 | 317 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
318 *cur_plan_p = |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
319 fftw_plan_many_dft_r2c (rank, tmp, howmany, itmp, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
320 0, stride, dist, reinterpret_cast<fftw_complex *> (out), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
321 0, stride, dist, plan_flags); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
322 } |
6228 | 323 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
324 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
325 *cur_plan_p = |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
326 fftw_plan_many_dft_r2c (rank, tmp, howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
327 (const_cast<double *> (in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
328 0, stride, dist, reinterpret_cast<fftw_complex *> (out), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
329 0, stride, dist, plan_flags); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
330 } |
3828 | 331 |
332 if (*cur_plan_p == 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
333 (*current_liboctave_error_handler) ("Error creating fftw plan"); |
3828 | 334 } |
335 | |
336 return *cur_plan_p; | |
337 } | |
338 | |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
339 octave_fftw_planner::FftwMethod |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
340 octave_fftw_planner::do_method (void) |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
341 { |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
342 return meth; |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
343 } |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
344 |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
345 octave_fftw_planner::FftwMethod |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
346 octave_fftw_planner::do_method (FftwMethod _meth) |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
347 { |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
348 FftwMethod ret = meth; |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
349 if (_meth == ESTIMATE || _meth == MEASURE |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
350 || _meth == PATIENT || _meth == EXHAUSTIVE |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
351 || _meth == HYBRID) |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
352 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
353 if (meth != _meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
354 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
355 meth = _meth; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
356 if (rplan) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
357 fftw_destroy_plan (rplan); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
358 if (plan[0]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
359 fftw_destroy_plan (plan[0]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
360 if (plan[1]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
361 fftw_destroy_plan (plan[1]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
362 rplan = plan[0] = plan[1] = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
363 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
364 } |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
365 else |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
366 ret = UNKNOWN; |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
367 return ret; |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
368 } |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
369 |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
370 octave_float_fftw_planner *octave_float_fftw_planner::instance = 0; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
371 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
372 octave_float_fftw_planner::octave_float_fftw_planner (void) |
11509
fc35194006d6
oct-fftw.cc: more constructor tweaks
John W. Eaton <jwe@octave.org>
parents:
11501
diff
changeset
|
373 : meth (ESTIMATE), rplan (0), rd (0), rs (0), rr (0), rh (0), rn (), |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10350
diff
changeset
|
374 rsimd_align (false) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
375 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
376 plan[0] = plan[1] = 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
377 d[0] = d[1] = s[0] = s[1] = r[0] = r[1] = h[0] = h[1] = 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
378 simd_align[0] = simd_align[1] = false; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
379 inplace[0] = inplace[1] = false; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
380 n[0] = n[1] = dim_vector (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
381 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
382 // If we have a system wide wisdom file, import it. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
383 fftwf_import_system_wisdom (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
384 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
385 |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
386 bool |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
387 octave_float_fftw_planner::instance_ok (void) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
388 { |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
389 bool retval = true; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
390 |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
391 if (! instance) |
13994
99f039289e95
also clean up float fftw planner
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
392 { |
99f039289e95
also clean up float fftw planner
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
393 instance = new octave_float_fftw_planner (); |
99f039289e95
also clean up float fftw planner
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
394 |
99f039289e95
also clean up float fftw planner
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
395 if (instance) |
99f039289e95
also clean up float fftw planner
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
396 singleton_cleanup_list::add (cleanup_instance); |
99f039289e95
also clean up float fftw planner
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
397 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
398 |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
399 if (! instance) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
400 { |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
401 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
402 ("unable to create octave_fftw_planner object!"); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
403 |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
404 retval = false; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
405 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
406 |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
407 return retval; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
408 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
409 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
410 fftwf_plan |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
411 octave_float_fftw_planner::do_create_plan (int dir, const int rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
412 const dim_vector dims, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
413 octave_idx_type howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
414 octave_idx_type stride, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
415 octave_idx_type dist, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
416 const FloatComplex *in, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
417 FloatComplex *out) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
418 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
419 int which = (dir == FFTW_FORWARD) ? 0 : 1; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
420 fftwf_plan *cur_plan_p = &plan[which]; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
421 bool create_new_plan = false; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
422 bool ioalign = CHECK_SIMD_ALIGNMENT (in) && CHECK_SIMD_ALIGNMENT (out); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
423 bool ioinplace = (in == out); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
424 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
425 // Don't create a new plan if we have a non SIMD plan already but |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
426 // can do SIMD. This prevents endlessly recreating plans if we |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
427 // change the alignment. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
428 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
429 if (plan[which] == 0 || d[which] != dist || s[which] != stride |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
430 || r[which] != rank || h[which] != howmany |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
431 || ioinplace != inplace[which] |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
432 || ((ioalign != simd_align[which]) ? !ioalign : false)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
433 create_new_plan = true; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
434 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
435 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
436 // We still might not have the same shape of array. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
437 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
438 for (int i = 0; i < rank; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
439 if (dims(i) != n[which](i)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
440 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
441 create_new_plan = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
442 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
443 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
444 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
445 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
446 if (create_new_plan) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
447 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
448 d[which] = dist; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
449 s[which] = stride; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
450 r[which] = rank; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
451 h[which] = howmany; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
452 simd_align[which] = ioalign; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
453 inplace[which] = ioinplace; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
454 n[which] = dims; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
455 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
456 // Note reversal of dimensions for column major storage in FFTW. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
457 octave_idx_type nn = 1; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
458 OCTAVE_LOCAL_BUFFER (int, tmp, rank); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
459 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
460 for (int i = 0, j = rank-1; i < rank; i++, j--) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
461 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
462 tmp[i] = dims(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
463 nn *= dims(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
464 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
465 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
466 int plan_flags = 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
467 bool plan_destroys_in = true; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
468 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
469 switch (meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
470 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
471 case UNKNOWN: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 case ESTIMATE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
473 plan_flags |= FFTW_ESTIMATE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
474 plan_destroys_in = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
475 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
476 case MEASURE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
477 plan_flags |= FFTW_MEASURE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
478 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
479 case PATIENT: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
480 plan_flags |= FFTW_PATIENT; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
481 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
482 case EXHAUSTIVE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
483 plan_flags |= FFTW_EXHAUSTIVE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
484 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
485 case HYBRID: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
486 if (nn < 8193) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
487 plan_flags |= FFTW_MEASURE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
488 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
489 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
490 plan_flags |= FFTW_ESTIMATE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
491 plan_destroys_in = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
492 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
493 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
494 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
495 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
496 if (ioalign) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
497 plan_flags &= ~FFTW_UNALIGNED; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
498 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
499 plan_flags |= FFTW_UNALIGNED; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
500 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
501 if (*cur_plan_p) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
502 fftwf_destroy_plan (*cur_plan_p); |
3828 | 503 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
504 if (plan_destroys_in) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
505 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
506 // Create matrix with the same size and 16-byte alignment as input |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
507 OCTAVE_LOCAL_BUFFER (FloatComplex, itmp, nn * howmany + 32); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
508 itmp = reinterpret_cast<FloatComplex *> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
509 (((reinterpret_cast<ptrdiff_t>(itmp) + 15) & ~ 0xF) + |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
510 ((reinterpret_cast<ptrdiff_t> (in)) & 0xF)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
511 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
512 *cur_plan_p = |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
513 fftwf_plan_many_dft (rank, tmp, howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
514 reinterpret_cast<fftwf_complex *> (itmp), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
515 0, stride, dist, reinterpret_cast<fftwf_complex *> (out), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
516 0, stride, dist, dir, plan_flags); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
517 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
518 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
519 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
520 *cur_plan_p = |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
521 fftwf_plan_many_dft (rank, tmp, howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
522 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *> (in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
523 0, stride, dist, reinterpret_cast<fftwf_complex *> (out), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
524 0, stride, dist, dir, plan_flags); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
525 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
526 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
527 if (*cur_plan_p == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
528 (*current_liboctave_error_handler) ("Error creating fftw plan"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
529 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
530 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
531 return *cur_plan_p; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
532 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
533 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
534 fftwf_plan |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
535 octave_float_fftw_planner::do_create_plan (const int rank, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
536 const dim_vector dims, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
537 octave_idx_type howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
538 octave_idx_type stride, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
539 octave_idx_type dist, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
540 const float *in, FloatComplex *out) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
541 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
542 fftwf_plan *cur_plan_p = &rplan; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
543 bool create_new_plan = false; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
544 bool ioalign = CHECK_SIMD_ALIGNMENT (in) && CHECK_SIMD_ALIGNMENT (out); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
545 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
546 // Don't create a new plan if we have a non SIMD plan already but |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
547 // can do SIMD. This prevents endlessly recreating plans if we |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
548 // change the alignment. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
549 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
550 if (rplan == 0 || rd != dist || rs != stride || rr != rank |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
551 || rh != howmany || ((ioalign != rsimd_align) ? !ioalign : false)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
552 create_new_plan = true; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
553 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
554 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
555 // We still might not have the same shape of array. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
556 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
557 for (int i = 0; i < rank; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
558 if (dims(i) != rn(i)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
559 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
560 create_new_plan = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
561 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
562 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
563 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
564 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
565 if (create_new_plan) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
566 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
567 rd = dist; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
568 rs = stride; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
569 rr = rank; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
570 rh = howmany; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
571 rsimd_align = ioalign; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
572 rn = dims; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
573 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
574 // Note reversal of dimensions for column major storage in FFTW. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
575 octave_idx_type nn = 1; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
576 OCTAVE_LOCAL_BUFFER (int, tmp, rank); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
577 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
578 for (int i = 0, j = rank-1; i < rank; i++, j--) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
579 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
580 tmp[i] = dims(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
581 nn *= dims(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
582 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
583 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
584 int plan_flags = 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
585 bool plan_destroys_in = true; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
586 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
587 switch (meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
588 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
589 case UNKNOWN: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
590 case ESTIMATE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
591 plan_flags |= FFTW_ESTIMATE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
592 plan_destroys_in = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
593 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
594 case MEASURE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
595 plan_flags |= FFTW_MEASURE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
596 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
597 case PATIENT: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
598 plan_flags |= FFTW_PATIENT; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
599 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
600 case EXHAUSTIVE: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
601 plan_flags |= FFTW_EXHAUSTIVE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
602 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
603 case HYBRID: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
604 if (nn < 8193) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
605 plan_flags |= FFTW_MEASURE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
606 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
607 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
608 plan_flags |= FFTW_ESTIMATE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
609 plan_destroys_in = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
610 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
611 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
612 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
613 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
614 if (ioalign) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
615 plan_flags &= ~FFTW_UNALIGNED; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
616 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
617 plan_flags |= FFTW_UNALIGNED; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
618 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
619 if (*cur_plan_p) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
620 fftwf_destroy_plan (*cur_plan_p); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
621 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
622 if (plan_destroys_in) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
623 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
624 // Create matrix with the same size and 16-byte alignment as input |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
625 OCTAVE_LOCAL_BUFFER (float, itmp, nn + 32); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
626 itmp = reinterpret_cast<float *> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
627 (((reinterpret_cast<ptrdiff_t>(itmp) + 15) & ~ 0xF) + |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
628 ((reinterpret_cast<ptrdiff_t> (in)) & 0xF)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
629 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
630 *cur_plan_p = |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
631 fftwf_plan_many_dft_r2c (rank, tmp, howmany, itmp, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
632 0, stride, dist, reinterpret_cast<fftwf_complex *> (out), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
633 0, stride, dist, plan_flags); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
634 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
635 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
636 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
637 *cur_plan_p = |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
638 fftwf_plan_many_dft_r2c (rank, tmp, howmany, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
639 (const_cast<float *> (in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
640 0, stride, dist, reinterpret_cast<fftwf_complex *> (out), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
641 0, stride, dist, plan_flags); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
642 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
643 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
644 if (*cur_plan_p == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
645 (*current_liboctave_error_handler) ("Error creating fftw plan"); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
646 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
647 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
648 return *cur_plan_p; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
649 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
650 |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
651 octave_float_fftw_planner::FftwMethod |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
652 octave_float_fftw_planner::do_method (void) |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
653 { |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
654 return meth; |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
655 } |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
656 |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
657 octave_float_fftw_planner::FftwMethod |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
658 octave_float_fftw_planner::do_method (FftwMethod _meth) |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
659 { |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
660 FftwMethod ret = meth; |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
661 if (_meth == ESTIMATE || _meth == MEASURE |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
662 || _meth == PATIENT || _meth == EXHAUSTIVE |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
663 || _meth == HYBRID) |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
664 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
665 if (meth != _meth) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
666 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
667 meth = _meth; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
668 if (rplan) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
669 fftwf_destroy_plan (rplan); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
670 if (plan[0]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
671 fftwf_destroy_plan (plan[0]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
672 if (plan[1]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
673 fftwf_destroy_plan (plan[1]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
674 rplan = plan[0] = plan[1] = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
675 } |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
676 } |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
677 else |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
678 ret = UNKNOWN; |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
679 return ret; |
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
680 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
681 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
682 template <class T> |
4775 | 683 static inline void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
684 convert_packcomplex_1d (T *out, size_t nr, size_t nc, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
685 octave_idx_type stride, octave_idx_type dist) |
4773 | 686 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
687 octave_quit (); |
4785 | 688 |
689 // Fill in the missing data. | |
690 | |
4773 | 691 for (size_t i = 0; i < nr; i++) |
692 for (size_t j = nc/2+1; j < nc; j++) | |
693 out[j*stride + i*dist] = conj(out[(nc - j)*stride + i*dist]); | |
4785 | 694 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
695 octave_quit (); |
4773 | 696 } |
697 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
698 template <class T> |
4775 | 699 static inline void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
700 convert_packcomplex_Nd (T *out, const dim_vector &dv) |
3828 | 701 { |
4773 | 702 size_t nc = dv(0); |
703 size_t nr = dv(1); | |
4808 | 704 size_t np = (dv.length () > 2 ? dv.numel () / nc / nr : 1); |
4773 | 705 size_t nrp = nr * np; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
706 T *ptr1, *ptr2; |
4773 | 707 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
708 octave_quit (); |
4785 | 709 |
710 // Create space for the missing elements. | |
711 | |
4773 | 712 for (size_t i = 0; i < nrp; i++) |
713 { | |
714 ptr1 = out + i * (nc/2 + 1) + nrp*((nc-1)/2); | |
715 ptr2 = out + i * nc; | |
716 for (size_t j = 0; j < nc/2+1; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
717 *ptr2++ = *ptr1++; |
4773 | 718 } |
719 | |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
720 octave_quit (); |
4785 | 721 |
722 // Fill in the missing data for the rank = 2 case directly for speed. | |
723 | |
4773 | 724 for (size_t i = 0; i < np; i++) |
725 { | |
726 for (size_t j = 1; j < nr; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
727 for (size_t k = nc/2+1; k < nc; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
728 out[k + (j + i*nr)*nc] = conj(out[nc - k + ((i+1)*nr - j)*nc]); |
4773 | 729 |
730 for (size_t j = nc/2+1; j < nc; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
731 out[j + i*nr*nc] = conj(out[(i*nr+1)*nc - j]); |
4773 | 732 } |
733 | |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
734 octave_quit (); |
4785 | 735 |
736 // Now do the permutations needed for rank > 2 cases. | |
737 | |
4773 | 738 size_t jstart = dv(0) * dv(1); |
739 size_t kstep = dv(0); | |
740 size_t nel = dv.numel (); | |
4785 | 741 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
742 for (int inner = 2; inner < dv.length (); inner++) |
4773 | 743 { |
744 size_t jmax = jstart * dv(inner); | |
745 for (size_t i = 0; i < nel; i+=jmax) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
746 for (size_t j = jstart, jj = jmax-jstart; j < jj; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
747 j+=jstart, jj-=jstart) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
748 for (size_t k = 0; k < jstart; k+= kstep) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
749 for (size_t l = nc/2+1; l < nc; l++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
750 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
751 T tmp = out[i+ j + k + l]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
752 out[i + j + k + l] = out[i + jj + k + l]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
753 out[i + jj + k + l] = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
754 } |
4773 | 755 jstart = jmax; |
756 } | |
4785 | 757 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
758 octave_quit (); |
4773 | 759 } |
760 | |
761 int | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
762 octave_fftw::fft (const double *in, Complex *out, size_t npts, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
763 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
4773 | 764 { |
765 dist = (dist < 0 ? npts : dist); | |
766 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
767 dim_vector dv (npts, 1); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
768 fftw_plan plan = octave_fftw_planner::create_plan (1, dv, nsamples, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
769 stride, dist, in, out); |
4773 | 770 |
771 fftw_execute_dft_r2c (plan, (const_cast<double *>(in)), | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
772 reinterpret_cast<fftw_complex *> (out)); |
4773 | 773 |
4809 | 774 // Need to create other half of the transform. |
775 | |
4773 | 776 convert_packcomplex_1d (out, nsamples, npts, stride, dist); |
3828 | 777 |
778 return 0; | |
779 } | |
780 | |
781 int | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
782 octave_fftw::fft (const Complex *in, Complex *out, size_t npts, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
783 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
3828 | 784 { |
4773 | 785 dist = (dist < 0 ? npts : dist); |
786 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
787 dim_vector dv (npts, 1); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
788 fftw_plan plan = octave_fftw_planner::create_plan (FFTW_FORWARD, 1, dv, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
789 nsamples, stride, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
790 dist, in, out); |
4773 | 791 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
792 fftw_execute_dft (plan, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
793 reinterpret_cast<fftw_complex *> (const_cast<Complex *>(in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
794 reinterpret_cast<fftw_complex *> (out)); |
4773 | 795 |
796 return 0; | |
797 } | |
798 | |
799 int | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
800 octave_fftw::ifft (const Complex *in, Complex *out, size_t npts, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
801 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
4773 | 802 { |
803 dist = (dist < 0 ? npts : dist); | |
804 | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
805 dim_vector dv (npts, 1); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
806 fftw_plan plan = octave_fftw_planner::create_plan (FFTW_BACKWARD, 1, dv, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
807 nsamples, stride, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
808 dist, in, out); |
4773 | 809 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
810 fftw_execute_dft (plan, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
811 reinterpret_cast<fftw_complex *> (const_cast<Complex *>(in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
812 reinterpret_cast<fftw_complex *> (out)); |
3828 | 813 |
814 const Complex scale = npts; | |
4773 | 815 for (size_t j = 0; j < nsamples; j++) |
816 for (size_t i = 0; i < npts; i++) | |
817 out[i*stride + j*dist] /= scale; | |
3828 | 818 |
819 return 0; | |
820 } | |
821 | |
822 int | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
823 octave_fftw::fftNd (const double *in, Complex *out, const int rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
824 const dim_vector &dv) |
3828 | 825 { |
5275 | 826 octave_idx_type dist = 1; |
4773 | 827 for (int i = 0; i < rank; i++) |
828 dist *= dv(i); | |
829 | |
830 // Fool with the position of the start of the output matrix, so that | |
4809 | 831 // creating other half of the matrix won't cause cache problems. |
832 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
833 octave_idx_type offset = (dv.numel () / dv(0)) * ((dv(0) - 1) / 2); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
834 |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
835 fftw_plan plan = octave_fftw_planner::create_plan (rank, dv, 1, 1, dist, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
836 in, out + offset); |
4773 | 837 |
838 fftw_execute_dft_r2c (plan, (const_cast<double *>(in)), | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
839 reinterpret_cast<fftw_complex *> (out+ offset)); |
4773 | 840 |
4809 | 841 // Need to create other half of the transform. |
842 | |
4773 | 843 convert_packcomplex_Nd (out, dv); |
3828 | 844 |
845 return 0; | |
846 } | |
847 | |
848 int | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
849 octave_fftw::fftNd (const Complex *in, Complex *out, const int rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
850 const dim_vector &dv) |
3828 | 851 { |
5275 | 852 octave_idx_type dist = 1; |
4773 | 853 for (int i = 0; i < rank; i++) |
854 dist *= dv(i); | |
855 | |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
856 fftw_plan plan = octave_fftw_planner::create_plan (FFTW_FORWARD, rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
857 dv, 1, 1, dist, in, out); |
4773 | 858 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
859 fftw_execute_dft (plan, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
860 reinterpret_cast<fftw_complex *> (const_cast<Complex *>(in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
861 reinterpret_cast<fftw_complex *> (out)); |
4773 | 862 |
863 return 0; | |
864 } | |
3828 | 865 |
4773 | 866 int |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
867 octave_fftw::ifftNd (const Complex *in, Complex *out, const int rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
868 const dim_vector &dv) |
4773 | 869 { |
5275 | 870 octave_idx_type dist = 1; |
4773 | 871 for (int i = 0; i < rank; i++) |
872 dist *= dv(i); | |
873 | |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
874 fftw_plan plan = octave_fftw_planner::create_plan (FFTW_BACKWARD, rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
875 dv, 1, 1, dist, in, out); |
4773 | 876 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
877 fftw_execute_dft (plan, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
878 reinterpret_cast<fftw_complex *> (const_cast<Complex *>(in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
879 reinterpret_cast<fftw_complex *> (out)); |
4773 | 880 |
881 const size_t npts = dv.numel (); | |
3828 | 882 const Complex scale = npts; |
883 for (size_t i = 0; i < npts; i++) | |
4773 | 884 out[i] /= scale; |
3828 | 885 |
886 return 0; | |
887 } | |
888 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
889 int |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
890 octave_fftw::fft (const float *in, FloatComplex *out, size_t npts, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
891 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
892 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
893 dist = (dist < 0 ? npts : dist); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
894 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
895 dim_vector dv (npts, 1); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
896 fftwf_plan plan = octave_float_fftw_planner::create_plan (1, dv, nsamples, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
897 stride, dist, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
898 in, out); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
899 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
900 fftwf_execute_dft_r2c (plan, (const_cast<float *>(in)), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
901 reinterpret_cast<fftwf_complex *> (out)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
902 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
903 // Need to create other half of the transform. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
904 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
905 convert_packcomplex_1d (out, nsamples, npts, stride, dist); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
906 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
907 return 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
908 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
909 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
910 int |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
911 octave_fftw::fft (const FloatComplex *in, FloatComplex *out, size_t npts, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
912 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
913 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
914 dist = (dist < 0 ? npts : dist); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
915 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
916 dim_vector dv (npts, 1); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
917 fftwf_plan plan = octave_float_fftw_planner::create_plan (FFTW_FORWARD, 1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
918 dv, nsamples, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
919 stride, dist, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
920 in, out); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
921 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
922 fftwf_execute_dft (plan, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
923 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *>(in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
924 reinterpret_cast<fftwf_complex *> (out)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
925 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
926 return 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
927 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
928 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
929 int |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
930 octave_fftw::ifft (const FloatComplex *in, FloatComplex *out, size_t npts, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
931 size_t nsamples, octave_idx_type stride, octave_idx_type dist) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
932 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
933 dist = (dist < 0 ? npts : dist); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
934 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
935 dim_vector dv (npts, 1); |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
936 fftwf_plan plan = octave_float_fftw_planner::create_plan (FFTW_BACKWARD, 1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
937 dv, nsamples, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
938 stride, dist, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
939 in, out); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
940 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
941 fftwf_execute_dft (plan, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
942 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *>(in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
943 reinterpret_cast<fftwf_complex *> (out)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
944 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
945 const FloatComplex scale = npts; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
946 for (size_t j = 0; j < nsamples; j++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
947 for (size_t i = 0; i < npts; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
948 out[i*stride + j*dist] /= scale; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
949 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
950 return 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
951 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
952 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
953 int |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
954 octave_fftw::fftNd (const float *in, FloatComplex *out, const int rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
955 const dim_vector &dv) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
956 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
957 octave_idx_type dist = 1; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
958 for (int i = 0; i < rank; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
959 dist *= dv(i); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
960 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
961 // Fool with the position of the start of the output matrix, so that |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
962 // creating other half of the matrix won't cause cache problems. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
963 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
964 octave_idx_type offset = (dv.numel () / dv(0)) * ((dv(0) - 1) / 2); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
965 |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
966 fftwf_plan plan = octave_float_fftw_planner::create_plan (rank, dv, 1, 1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
967 dist, in, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
968 out + offset); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
969 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
970 fftwf_execute_dft_r2c (plan, (const_cast<float *>(in)), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
971 reinterpret_cast<fftwf_complex *> (out+ offset)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
972 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
973 // Need to create other half of the transform. |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
974 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
975 convert_packcomplex_Nd (out, dv); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
976 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
977 return 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
978 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
979 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
980 int |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
981 octave_fftw::fftNd (const FloatComplex *in, FloatComplex *out, const int rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
982 const dim_vector &dv) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
983 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
984 octave_idx_type dist = 1; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
985 for (int i = 0; i < rank; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
986 dist *= dv(i); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
987 |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
988 fftwf_plan plan = octave_float_fftw_planner::create_plan (FFTW_FORWARD, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
989 rank, dv, 1, 1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
990 dist, in, out); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
991 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
992 fftwf_execute_dft (plan, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
993 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *>(in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
994 reinterpret_cast<fftwf_complex *> (out)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
995 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
996 return 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
997 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
998 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
999 int |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1000 octave_fftw::ifftNd (const FloatComplex *in, FloatComplex *out, const int rank, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1001 const dim_vector &dv) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1002 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1003 octave_idx_type dist = 1; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1004 for (int i = 0; i < rank; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1005 dist *= dv(i); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1006 |
9516
fb933db0c517
convert fftw planner classes to singleton objects
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
1007 fftwf_plan plan = octave_float_fftw_planner::create_plan (FFTW_BACKWARD, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1008 rank, dv, 1, 1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1009 dist, in, out); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1010 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1011 fftwf_execute_dft (plan, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1012 reinterpret_cast<fftwf_complex *> (const_cast<FloatComplex *>(in)), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1013 reinterpret_cast<fftwf_complex *> (out)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1014 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1015 const size_t npts = dv.numel (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1016 const FloatComplex scale = npts; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1017 for (size_t i = 0; i < npts; i++) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1018 out[i] /= scale; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1019 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1020 return 0; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1021 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1022 |
3828 | 1023 #endif |