Mercurial > octave
annotate src/DLD-FUNCTIONS/fftn.cc @ 7814:87865ed7405f
Second set of single precision test code and fix of resulting bugs
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 02 Jun 2008 16:57:45 +0200 |
parents | 82be108cc558 |
children | 4976f66d469b |
rev | line source |
---|---|
4773 | 1 /* |
2 | |
7017 | 3 Copyright (C) 2004, 2005, 2006, 2007 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 ()) | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
91 if (arg.is_single_type ()) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
92 return octave_value (FloatMatrix ()); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
93 else |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
94 return octave_value (Matrix ()); |
4773 | 95 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
96 if (arg.is_single_type ()) |
4773 | 97 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
98 if (arg.is_real_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
99 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
100 FloatNDArray nda = arg.float_array_value (); |
4773 | 101 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
102 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
103 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
104 nda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
105 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
106 } |
4773 | 107 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
108 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
109 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
110 FloatComplexNDArray cnda = arg.float_complex_array_value (); |
4773 | 111 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
112 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
113 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
114 cnda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
116 } |
4773 | 117 } |
118 } | |
119 else | |
120 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
121 if (arg.is_real_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
122 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 NDArray nda = arg.array_value (); |
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 if (! error_state) |
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 nda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
128 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
129 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
130 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
131 else if (arg.is_complex_type ()) |
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 ComplexNDArray cnda = arg.complex_array_value (); |
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 if (! error_state) |
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 cnda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
138 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ()); |
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 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
141 else |
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 gripe_wrong_type_arg (fcn, arg); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
144 } |
4773 | 145 } |
146 | |
147 return retval; | |
148 } | |
149 | |
150 DEFUN_DLD (fftn, args, , | |
151 "-*- texinfo -*-\n\ | |
4787 | 152 @deftypefn {Loadable Function} {} fftn (@var{a}, @var{size})\n\ |
4773 | 153 Compute the N dimensional FFT of @var{a} using subroutines from\n" |
154 FFTSRC | |
4787 | 155 ". The optional vector argument @var{size} may be used specify the\n\ |
156 dimensions of the array to be used. If an element of @var{size} is\n\ | |
4773 | 157 smaller than the corresponding dimension, then the dimension is\n\ |
158 truncated prior to performing the FFT. Otherwise if an element\n\ | |
4787 | 159 of @var{size} is larger than the corresponding dimension @var{a}\n\ |
4773 | 160 is resized and padded with zeros.\n\ |
6971 | 161 @seealso {ifftn, fft, fft2, fftw}\n\ |
5642 | 162 @end deftypefn") |
4773 | 163 { |
4782 | 164 return do_fftn (args, "fftn", 0); |
4773 | 165 } |
166 | |
167 DEFUN_DLD (ifftn, args, , | |
168 "-*- texinfo -*-\n\ | |
4787 | 169 @deftypefn {Loadable Function} {} ifftn (@var{a}, @var{size})\n\ |
7007 | 170 Compute the inverse N dimensional FFT of @var{a} using subroutines from\n" |
4773 | 171 FFTSRC |
4787 | 172 ". The optional vector argument @var{size} may be used specify the\n\ |
173 dimensions of the array to be used. If an element of @var{size} is\n\ | |
4773 | 174 smaller than the corresponding dimension, then the dimension is\n\ |
175 truncated prior to performing the inverse FFT. Otherwise if an element\n\ | |
4787 | 176 of @var{size} is larger than the corresponding dimension @var{a}\n\ |
4773 | 177 is resized and padded with zeros.\n\ |
6971 | 178 @seealso {fftn, ifft, ifft2, fftw}\n\ |
5642 | 179 @end deftypefn") |
4773 | 180 { |
4782 | 181 return do_fftn (args, "ifftn", 1); |
4773 | 182 } |
183 | |
184 /* | |
185 ;;; Local Variables: *** | |
186 ;;; mode: C++ *** | |
187 ;;; End: *** | |
188 */ |