changeset 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 a92f3c0c92d9
children bfcd1515cd40
files libinterp/corefcn/fft2.cc libinterp/corefcn/fftn.cc
diffstat 2 files changed, 43 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/fft2.cc	Mon Mar 04 12:39:32 2024 -0800
+++ b/libinterp/corefcn/fft2.cc	Mon Mar 04 20:31:58 2024 +0100
@@ -89,12 +89,12 @@
   else
     dims(1) = n_cols;
 
-  if (dims.all_zero () || n_rows == 0 || n_cols == 0)
+  if (dims.any_zero ())
     {
       if (arg.is_single_type ())
-        return octave_value (FloatMatrix ());
+        return octave_value (FloatNDArray (dims));
       else
-        return octave_value (Matrix ());
+        return octave_value (NDArray (dims));
     }
 
   if (arg.is_single_type ())
@@ -156,6 +156,15 @@
   return do_fft2 (args, "fft2", 0);
 }
 
+/*
+%!testif HAVE_FFTW <*65414>
+%! sz = size (fft2 (ones (2, 0, 3)));
+%! assert (sz, [2, 0, 3]);
+
+%!testif HAVE_FFTW <*65414>
+%! sz = size (fft2 (ones (5, 4, 3), 2, 0));
+%! assert (sz, [2, 0, 3]);
+*/
 
 DEFUN (ifft2, args, ,
        doc: /* -*- texinfo -*-
@@ -177,6 +186,14 @@
 }
 
 /*
+%!testif HAVE_FFTW <*65414>
+%! sz = size (ifft2 (ones (2, 0, 3)));
+%! assert (sz, [2, 0, 3]);
+
+%!testif HAVE_FFTW <*65414>
+%! sz = size (ifft2 (ones (5, 4, 3), 2, 0));
+%! assert (sz, [2, 0, 3]);
+
 ## Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
 ##         Comalco Research and Technology
 ##         02 May 2000
--- a/libinterp/corefcn/fftn.cc	Mon Mar 04 12:39:32 2024 -0800
+++ b/libinterp/corefcn/fftn.cc	Mon Mar 04 20:31:58 2024 +0100
@@ -76,12 +76,12 @@
         }
     }
 
-  if (dims.all_zero ())
+  if (dims.any_zero ())
     {
       if (arg.is_single_type ())
-        return octave_value (FloatMatrix ());
+        return octave_value (FloatNDArray (dims));
       else
-        return octave_value (Matrix ());
+        return octave_value (NDArray (dims));
     }
 
   if (arg.is_single_type ())
@@ -143,6 +143,16 @@
   return do_fftn (args, "fftn", 0);
 }
 
+/*
+%!testif HAVE_FFTW <*65414>
+%! sz = size (fftn (ones (2, 0, 3)));
+%! assert (sz, [2, 0, 3]);
+
+%!testif HAVE_FFTW <*65414>
+%! sz = size (fftn (ones (5, 4, 3), [2, 0, 3]));
+%! assert (sz, [2, 0, 3]);
+*/
+
 DEFUN (ifftn, args, ,
        doc: /* -*- texinfo -*-
 @deftypefn  {} {@var{A} =} ifftn (@var{B})
@@ -162,4 +172,14 @@
   return do_fftn (args, "ifftn", 1);
 }
 
+/*
+%!testif HAVE_FFTW <*65414>
+%! sz = size (ifftn (ones (2, 0, 3)));
+%! assert (sz, [2, 0, 3]);
+
+%!testif HAVE_FFTW <*65414>
+%! sz = size (ifftn (ones (5, 4, 3), [2, 0, 3]));
+%! assert (sz, [2, 0, 3]);
+*/
+
 OCTAVE_END_NAMESPACE(octave)