Mercurial > hg > octave-nkf
annotate src/DLD-FUNCTIONS/fftn.cc @ 9064:7c02ec148a3c
Check grammar on all .cc files
Same check as previously done on .m files
Attempt to enforce some conformity in documentation text for rules
such as two spaces after a period, commas around latin abbreviations, etc.
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sat, 28 Mar 2009 13:57:22 -0700 |
parents | eb63fbe60fab |
children | bd8e388043c4 |
rev | line source |
---|---|
4773 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 David Bateman |
4773 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
4773 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4773 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "lo-mappers.h" | |
28 | |
29 #include "defun-dld.h" | |
30 #include "error.h" | |
31 #include "gripes.h" | |
32 #include "oct-obj.h" | |
33 #include "utils.h" | |
34 | |
35 // This function should be merged with Fifft. | |
36 | |
37 #if defined (HAVE_FFTW3) | |
38 #define FFTSRC "@sc{Fftw}" | |
39 #else | |
40 #define FFTSRC "@sc{Fftpack}" | |
41 #endif | |
42 | |
43 static octave_value | |
44 do_fftn (const octave_value_list &args, const char *fcn, int type) | |
45 { | |
46 octave_value retval; | |
47 | |
48 int nargin = args.length (); | |
49 | |
50 if (nargin < 1 || nargin > 2) | |
51 { | |
5823 | 52 print_usage (); |
4773 | 53 return retval; |
54 } | |
55 | |
56 octave_value arg = args(0); | |
57 dim_vector dims = arg.dims (); | |
58 | |
59 for (int i = 0; i < dims.length (); i++) | |
60 if (dims(i) < 0) | |
61 return retval; | |
62 | |
63 if (nargin > 1) | |
64 { | |
65 Matrix val = args(1).matrix_value (); | |
66 if (val.rows () > val.columns ()) | |
4849 | 67 val = val.transpose (); |
4773 | 68 |
4849 | 69 if (error_state || val.columns () != dims.length () || val.rows () != 1) |
4773 | 70 error ("%s: second argument must be a vector of length dim", fcn); |
71 else | |
72 { | |
73 for (int i = 0; i < dims.length (); i++) | |
74 { | |
75 if (xisnan (val(i,0))) | |
76 error ("%s: NaN is invalid as a dimension", fcn); | |
5275 | 77 else if (NINTbig (val(i,0)) < 0) |
4773 | 78 error ("%s: all dimension must be greater than zero", fcn); |
79 else | |
80 { | |
5275 | 81 dims(i) = NINTbig(val(i,0)); |
4773 | 82 } |
83 } | |
84 } | |
85 } | |
86 | |
87 if (error_state) | |
88 return retval; | |
89 | |
90 if (dims.all_zero ()) | |
7924 | 91 { |
92 if (arg.is_single_type ()) | |
93 return octave_value (FloatMatrix ()); | |
94 else | |
95 return octave_value (Matrix ()); | |
96 } | |
4773 | 97 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
98 if (arg.is_single_type ()) |
4773 | 99 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
100 if (arg.is_real_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
101 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
102 FloatNDArray nda = arg.float_array_value (); |
4773 | 103 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
104 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
105 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
106 nda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
107 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
108 } |
4773 | 109 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
110 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
111 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
112 FloatComplexNDArray cnda = arg.float_complex_array_value (); |
4773 | 113 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
114 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
116 cnda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
117 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
118 } |
4773 | 119 } |
120 } | |
121 else | |
122 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 if (arg.is_real_type ()) |
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 NDArray nda = arg.array_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
126 |
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 nda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
130 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
131 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
132 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
133 else if (arg.is_complex_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
134 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
135 ComplexNDArray cnda = arg.complex_array_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
136 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
137 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
139 cnda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
140 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ()); |
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 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
143 else |
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 gripe_wrong_type_arg (fcn, arg); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
146 } |
4773 | 147 } |
148 | |
149 return retval; | |
150 } | |
151 | |
152 DEFUN_DLD (fftn, args, , | |
153 "-*- texinfo -*-\n\ | |
4787 | 154 @deftypefn {Loadable Function} {} fftn (@var{a}, @var{size})\n\ |
8496 | 155 Compute the N-dimensional FFT of @var{a} using subroutines from\n" |
4773 | 156 FFTSRC |
4787 | 157 ". The optional vector argument @var{size} may be used specify the\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
158 dimensions of the array to be used. If an element of @var{size} is\n\ |
4773 | 159 smaller than the corresponding dimension, then the dimension is\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
160 truncated prior to performing the FFT. Otherwise if an element\n\ |
4787 | 161 of @var{size} is larger than the corresponding dimension @var{a}\n\ |
4773 | 162 is resized and padded with zeros.\n\ |
6971 | 163 @seealso {ifftn, fft, fft2, fftw}\n\ |
5642 | 164 @end deftypefn") |
4773 | 165 { |
4782 | 166 return do_fftn (args, "fftn", 0); |
4773 | 167 } |
168 | |
169 DEFUN_DLD (ifftn, args, , | |
170 "-*- texinfo -*-\n\ | |
4787 | 171 @deftypefn {Loadable Function} {} ifftn (@var{a}, @var{size})\n\ |
8496 | 172 Compute the inverse N-dimensional FFT of @var{a} using subroutines from\n" |
4773 | 173 FFTSRC |
4787 | 174 ". The optional vector argument @var{size} may be used specify the\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
175 dimensions of the array to be used. If an element of @var{size} is\n\ |
4773 | 176 smaller than the corresponding dimension, then the dimension is\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
177 truncated prior to performing the inverse FFT. Otherwise if an element\n\ |
4787 | 178 of @var{size} is larger than the corresponding dimension @var{a}\n\ |
4773 | 179 is resized and padded with zeros.\n\ |
6971 | 180 @seealso {fftn, ifft, ifft2, fftw}\n\ |
5642 | 181 @end deftypefn") |
4773 | 182 { |
4782 | 183 return do_fftn (args, "ifftn", 1); |
4773 | 184 } |
185 | |
186 /* | |
187 ;;; Local Variables: *** | |
188 ;;; mode: C++ *** | |
189 ;;; End: *** | |
190 */ |