Mercurial > octave
annotate src/DLD-FUNCTIONS/fft2.cc @ 7789:82be108cc558
First attempt at single precision tyeps
* * *
corrections to qrupdate single precision routines
* * *
prefer demotion to single over promotion to double
* * *
Add single precision support to log2 function
* * *
Trivial PROJECT file update
* * *
Cache optimized hermitian/transpose methods
* * *
Add tests for tranpose/hermitian and ChangeLog entry for new transpose code
author | David Bateman <dbateman@free.fr> |
---|---|
date | Sun, 27 Apr 2008 22:34:17 +0200 |
parents | a1dbe9d80eee |
children | 87865ed7405f |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1997, 1999, 2002, 2004, 2005, 2006, 2007 David Bateman |
2928 | 4 Copyright (C) 1996, 1997 John W. Eaton |
5 | |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2928 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2928 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "lo-mappers.h" | |
29 | |
30 #include "defun-dld.h" | |
31 #include "error.h" | |
32 #include "gripes.h" | |
33 #include "oct-obj.h" | |
34 #include "utils.h" | |
35 | |
4773 | 36 // This function should be merged with Fifft. |
2928 | 37 |
4773 | 38 #if defined (HAVE_FFTW3) |
39 #define FFTSRC "@sc{Fftw}" | |
40 #else | |
41 #define FFTSRC "@sc{Fftpack}" | |
42 #endif | |
43 | |
44 static octave_value | |
45 do_fft2 (const octave_value_list &args, const char *fcn, int type) | |
2928 | 46 { |
4233 | 47 octave_value retval; |
2928 | 48 |
49 int nargin = args.length (); | |
50 | |
51 if (nargin < 1 || nargin > 3) | |
52 { | |
5823 | 53 print_usage (); |
2928 | 54 return retval; |
55 } | |
56 | |
57 octave_value arg = args(0); | |
4773 | 58 dim_vector dims = arg.dims (); |
5275 | 59 octave_idx_type n_rows = -1; |
4773 | 60 |
2928 | 61 if (nargin > 1) |
62 { | |
63 double dval = args(1).double_value (); | |
64 if (xisnan (dval)) | |
4773 | 65 error ("%s: NaN is invalid as the N_ROWS", fcn); |
2928 | 66 else |
4773 | 67 { |
5275 | 68 n_rows = NINTbig (dval); |
4773 | 69 if (n_rows < 0) |
70 error ("%s: number of rows must be greater than zero", fcn); | |
71 } | |
2928 | 72 } |
73 | |
74 if (error_state) | |
75 return retval; | |
76 | |
5275 | 77 octave_idx_type n_cols = -1; |
2928 | 78 if (nargin > 2) |
79 { | |
80 double dval = args(2).double_value (); | |
81 if (xisnan (dval)) | |
4773 | 82 error ("%s: NaN is invalid as the N_COLS", fcn); |
2928 | 83 else |
4773 | 84 { |
5275 | 85 n_cols = NINTbig (dval); |
4773 | 86 if (n_cols < 0) |
87 error ("%s: number of columns must be greater than zero", fcn); | |
88 } | |
2928 | 89 } |
90 | |
91 if (error_state) | |
92 return retval; | |
93 | |
4773 | 94 for (int i = 0; i < dims.length (); i++) |
95 if (dims(i) < 0) | |
2928 | 96 return retval; |
97 | |
4773 | 98 if (n_rows < 0) |
99 n_rows = dims (0); | |
100 else | |
101 dims (0) = n_rows; | |
2928 | 102 |
4773 | 103 if (n_cols < 0) |
104 n_cols = dims (1); | |
105 else | |
106 dims (1) = n_cols; | |
107 | |
108 if (dims.all_zero () || n_rows == 0 || n_cols == 0) | |
4233 | 109 return octave_value (Matrix ()); |
2928 | 110 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
111 if (arg.is_single_type ()) |
2928 | 112 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
113 if (arg.is_real_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
114 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 FloatNDArray nda = arg.float_array_value (); |
2928 | 116 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
117 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
118 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
119 nda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
120 retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
121 } |
2928 | 122 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
124 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
125 FloatComplexNDArray cnda = arg.float_complex_array_value (); |
2928 | 126 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
127 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
128 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
129 cnda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
130 retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
131 } |
2928 | 132 } |
133 } | |
134 else | |
135 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
136 if (arg.is_real_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
137 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 NDArray nda = arg.array_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
139 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
140 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
141 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
142 nda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
143 retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
144 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
145 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
146 else if (arg.is_complex_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
147 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
148 ComplexNDArray cnda = arg.complex_array_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
150 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
151 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
152 cnda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
153 retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
154 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
155 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
156 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
157 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
158 gripe_wrong_type_arg (fcn, arg); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
159 } |
2928 | 160 } |
161 | |
162 return retval; | |
163 } | |
164 | |
4773 | 165 DEFUN_DLD (fft2, args, , |
166 "-*- texinfo -*-\n\ | |
167 @deftypefn {Loadable Function} {} fft2 (@var{a}, @var{n}, @var{m})\n\ | |
168 Compute the two dimensional FFT of @var{a} using subroutines from\n" | |
169 FFTSRC | |
170 ". The optional arguments @var{n} and @var{m} may be used specify the\n\ | |
171 number of rows and columns of @var{a} to use. If either of these is\n\ | |
172 larger than the size of @var{a}, @var{a} is resized and padded with\n\ | |
173 zeros.\n\ | |
174 \n\ | |
175 If @var{a} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\ | |
7001 | 176 of @var{a} is treated separately\n\ |
6971 | 177 @seealso {ifft2, fft, fftn, fftw}\n\ |
5642 | 178 @end deftypefn") |
4773 | 179 { |
4782 | 180 return do_fft2 (args, "fft2", 0); |
4773 | 181 } |
182 | |
183 | |
184 DEFUN_DLD (ifft2, args, , | |
185 "-*- texinfo -*-\n\ | |
186 @deftypefn {Loadable Function} {} fft2 (@var{a}, @var{n}, @var{m})\n\ | |
187 Compute the inverse two dimensional FFT of @var{a} using subroutines from\n" | |
188 FFTSRC | |
189 ". The optional arguments @var{n} and @var{m} may be used specify the\n\ | |
190 number of rows and columns of @var{a} to use. If either of these is\n\ | |
191 larger than the size of @var{a}, @var{a} is resized and padded with\n\ | |
192 zeros.\n\ | |
193 \n\ | |
194 If @var{a} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\ | |
7001 | 195 of @var{a} is treated separately\n\ |
6971 | 196 @seealso {fft2, ifft, ifftn, fftw}\n\ |
5642 | 197 @end deftypefn") |
4773 | 198 { |
4782 | 199 return do_fft2 (args, "ifft2", 1); |
4773 | 200 } |
201 | |
2928 | 202 /* |
203 ;;; Local Variables: *** | |
204 ;;; mode: C++ *** | |
205 ;;; End: *** | |
206 */ |