annotate liboctave/oct-fftw.cc @ 14078:941d19370065 stable

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