annotate liboctave/numeric/oct-fftw.cc @ 15960:bde7731b2b83

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