annotate liboctave/numeric/oct-fftw.cc @ 27923:bd51beb6205e

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