Mercurial > octave-nkf
annotate libinterp/corefcn/fftn.cc @ 20645:395140e53656
Fix regression in svg output and simplify viewport handling (bug #44765)
* gl2ps-renderer.cc (glps-renderer::draw): remove check for GL2PS_NO_FEEDBACK, it it always true after EndViewport
* gl2ps-renderer.h (glps-renderer::draw_axes): call gl2psBegin(End)Viewport for every axes and check for GL2PS_NO_FEEDBACK after each axes.
* gl2ps-renderer.h (glps-renderer::draw_axes):remove unnecessary "naxes" attribute
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Mon, 12 Oct 2015 20:49:04 +0200 |
parents | f90c8372b7ba |
children |
rev | line source |
---|---|
4773 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3 Copyright (C) 2004-2015 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 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
29 #include "defun.h" |
4773 | 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 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9072
diff
changeset
|
37 #if defined (HAVE_FFTW) |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
38 #define FFTSRC "@sc{fftw}" |
4773 | 39 #else |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
40 #define FFTSRC "@sc{fftpack}" |
4773 | 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 (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
58 |
4773 | 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 ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
67 val = val.transpose (); |
4773 | 68 |
4849 | 69 if (error_state || val.columns () != dims.length () || val.rows () != 1) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
70 error ("%s: SIZE must be a vector of length dim", fcn); |
4773 | 71 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
72 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
73 for (int i = 0; i < dims.length (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
74 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
75 if (xisnan (val(i,0))) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
76 error ("%s: SIZE has invalid NaN entries", fcn); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
77 else if (NINTbig (val(i,0)) < 0) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 error ("%s: all dimensions in SIZE must be greater than zero", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
79 fcn); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
80 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
81 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
82 dims(i) = NINTbig(val(i,0)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
83 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
84 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
85 } |
4773 | 86 } |
87 | |
88 if (dims.all_zero ()) | |
7924 | 89 { |
90 if (arg.is_single_type ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
91 return octave_value (FloatMatrix ()); |
7924 | 92 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
93 return octave_value (Matrix ()); |
7924 | 94 } |
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 ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
99 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
100 FloatNDArray nda = arg.float_array_value (); |
4773 | 101 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20207
diff
changeset
|
102 nda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20207
diff
changeset
|
103 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
104 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
105 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
106 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
107 FloatComplexNDArray cnda = arg.float_complex_array_value (); |
4773 | 108 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20207
diff
changeset
|
109 cnda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20207
diff
changeset
|
110 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
111 } |
4773 | 112 } |
113 else | |
114 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 if (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
116 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
117 NDArray nda = arg.array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
118 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20207
diff
changeset
|
119 nda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20207
diff
changeset
|
120 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
121 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
122 else if (arg.is_complex_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
123 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
124 ComplexNDArray cnda = arg.complex_array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
125 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20207
diff
changeset
|
126 cnda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20207
diff
changeset
|
127 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ()); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
128 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
129 else |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20207
diff
changeset
|
130 gripe_wrong_type_arg (fcn, arg); |
4773 | 131 } |
132 | |
133 return retval; | |
134 } | |
135 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
136 DEFUN (fftn, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
137 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
138 @deftypefn {Built-in Function} {} fftn (@var{A})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
139 @deftypefnx {Built-in Function} {} fftn (@var{A}, @var{size})\n\ |
12160
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
140 Compute the N-dimensional discrete Fourier transform of @var{A} using\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
141 a Fast Fourier Transform (FFT) algorithm.\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
142 \n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
143 The optional vector argument @var{size} may be used specify the dimensions\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
144 of the array to be used. If an element of @var{size} is smaller than the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
145 corresponding dimension of @var{A}, then the dimension of @var{A} is\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
146 truncated prior to performing the FFT@. Otherwise, if an element of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
147 @var{size} is larger than the corresponding dimension then @var{A} is\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
148 resized and padded with zeros.\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
149 @seealso{ifftn, fft, fft2, fftw}\n\ |
5642 | 150 @end deftypefn") |
4773 | 151 { |
4782 | 152 return do_fftn (args, "fftn", 0); |
4773 | 153 } |
154 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
155 DEFUN (ifftn, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
156 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
157 @deftypefn {Built-in Function} {} ifftn (@var{A})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
158 @deftypefnx {Built-in Function} {} ifftn (@var{A}, @var{size})\n\ |
12160
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
159 Compute the inverse N-dimensional discrete Fourier transform of @var{A}\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
160 using a Fast Fourier Transform (FFT) algorithm.\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
161 \n\ |
20207
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
162 The optional vector argument @var{size} may be used specify the dimensions\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
163 of the array to be used. If an element of @var{size} is smaller than the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
164 corresponding dimension of @var{A}, then the dimension of @var{A} is\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
165 truncated prior to performing the inverse FFT@. Otherwise, if an element of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
166 @var{size} is larger than the corresponding dimension then @var{A} is\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
167 resized and padded with zeros.\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
168 @seealso{fftn, ifft, ifft2, fftw}\n\ |
5642 | 169 @end deftypefn") |
4773 | 170 { |
4782 | 171 return do_fftn (args, "ifftn", 1); |
4773 | 172 } |