comparison libinterp/corefcn/fftn.cc @ 33146:6e67f10b4d33

Fix input validation for zero-dimensional input data to ifftn, ifft2, fftn, fft2 (bug #65414). Verify data is not empty before passing to FFTW to avoid obscure error in FFTW planner. * fftn.cc (do_fftn): Use dim_vector.any_zero() function to find empty inputs. Return an empty NDArray of the same size as the input data. * fftn.cc (Ffftn, Fifftn): Add BIST tests for bug #65414. * fft2.cc (do_fft2): Use dim_vector.any_zero() function to find empty inputs. Return an empty NDArray of the same size as the input data. Add BIST tests. * fft2.cc (Ffft2, Fifft2): Add BIST tests for bug #65414.
author Markus Meisinger <chloros2@gmx.de>
date Mon, 04 Mar 2024 20:31:58 +0100
parents 2e484f9f1f18
children
comparison
equal deleted inserted replaced
33145:a92f3c0c92d9 33146:6e67f10b4d33
74 else 74 else
75 dims(i) = math::nint_big(val(i, 0)); 75 dims(i) = math::nint_big(val(i, 0));
76 } 76 }
77 } 77 }
78 78
79 if (dims.all_zero ()) 79 if (dims.any_zero ())
80 { 80 {
81 if (arg.is_single_type ()) 81 if (arg.is_single_type ())
82 return octave_value (FloatMatrix ()); 82 return octave_value (FloatNDArray (dims));
83 else 83 else
84 return octave_value (Matrix ()); 84 return octave_value (NDArray (dims));
85 } 85 }
86 86
87 if (arg.is_single_type ()) 87 if (arg.is_single_type ())
88 { 88 {
89 if (arg.isreal ()) 89 if (arg.isreal ())
141 @end deftypefn */) 141 @end deftypefn */)
142 { 142 {
143 return do_fftn (args, "fftn", 0); 143 return do_fftn (args, "fftn", 0);
144 } 144 }
145 145
146 /*
147 %!testif HAVE_FFTW <*65414>
148 %! sz = size (fftn (ones (2, 0, 3)));
149 %! assert (sz, [2, 0, 3]);
150
151 %!testif HAVE_FFTW <*65414>
152 %! sz = size (fftn (ones (5, 4, 3), [2, 0, 3]));
153 %! assert (sz, [2, 0, 3]);
154 */
155
146 DEFUN (ifftn, args, , 156 DEFUN (ifftn, args, ,
147 doc: /* -*- texinfo -*- 157 doc: /* -*- texinfo -*-
148 @deftypefn {} {@var{A} =} ifftn (@var{B}) 158 @deftypefn {} {@var{A} =} ifftn (@var{B})
149 @deftypefnx {} {@var{A} =} ifftn (@var{B}, @var{size}) 159 @deftypefnx {} {@var{A} =} ifftn (@var{B}, @var{size})
150 Compute the inverse N-dimensional discrete Fourier transform of @var{B} 160 Compute the inverse N-dimensional discrete Fourier transform of @var{B}
160 @end deftypefn */) 170 @end deftypefn */)
161 { 171 {
162 return do_fftn (args, "ifftn", 1); 172 return do_fftn (args, "ifftn", 1);
163 } 173 }
164 174
175 /*
176 %!testif HAVE_FFTW <*65414>
177 %! sz = size (ifftn (ones (2, 0, 3)));
178 %! assert (sz, [2, 0, 3]);
179
180 %!testif HAVE_FFTW <*65414>
181 %! sz = size (ifftn (ones (5, 4, 3), [2, 0, 3]));
182 %! assert (sz, [2, 0, 3]);
183 */
184
165 OCTAVE_END_NAMESPACE(octave) 185 OCTAVE_END_NAMESPACE(octave)