changeset 31860:16a04c6bc7db

movfun.m: Use short-circuit code for all empty input data arrays. * movfun.m: Extend input validation to find any empty matrix and return immediately.
author Rik <rik@octave.org>
date Mon, 27 Feb 2023 09:50:59 -0800
parents 84805310d0d7
children 5943f65d06c4 e7f507e7d99c
files scripts/signal/movfun.m
diffstat 1 files changed, 12 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/signal/movfun.m	Sun Feb 26 20:09:35 2023 -0800
+++ b/scripts/signal/movfun.m	Mon Feb 27 09:50:59 2023 -0800
@@ -197,20 +197,20 @@
   clear parser
   ## End parse input arguments
 
+  if (isempty (x))
+    ## Nothing to do.  Return immediately with empty output same shape as input.
+    ## Technically, it would be best to return the correct class, rather than
+    ## always "double", but this seems like a lot of work for little gain.
+    y = zeros (size (x));
+    return;
+  endif
+
   ## If dim was not provided find the first non-singleton dimension.
   szx = size (x);
   if (isempty (dim))
     (dim = find (szx > 1, 1)) || (dim = 1);
   endif
-
   N = szx(dim);
-  if (N == 0)
-    ## Nothing to do.  Return immediately with empty output same shape as input.
-    ## Technically, it would be best to return the correct class, rather than
-    ## always "double", but this seems like a lot of work for little gain.
-    y = zeros (szx);
-    return;
-  endif
 
   ## Calculate slicing indices.  This call also validates WLEN input.
   [slc, C, Cpre, Cpos, win] = movslice (N, wlen);
@@ -306,7 +306,10 @@
 
   ## Process center of data
   try
-    y(C,:) = fcn (x(slcidx));
+    slcidx2 = int64 (slcidx);
+    tmp = x(slcidx2);
+    y(C,:) = fcn (tmp);
+    #y(C,:) = fcn (x(slcidx));
   catch err
     ## Operation failed, likely because of out-of-memory error for "x(slcidx)".
     if (! strcmp (err.identifier, "Octave:bad-alloc"))