changeset 25263:316b75b0d886 stable

restore find (false) to be compatible with Matlab again (bug #53655) * find.cc (Ffind): Keep the dimensions of an empty logical result, so that find (false) returns the correct size and shape. Add related BISTs.
author Mike Miller <mtmiller@octave.org>
date Sun, 15 Apr 2018 23:59:24 -0700
parents 32323f5e61d2
children 6f9d51536643 fa9993b55617
files libinterp/corefcn/find.cc
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/find.cc	Sun Apr 15 22:03:13 2018 -0700
+++ b/libinterp/corefcn/find.cc	Sun Apr 15 23:59:24 2018 -0700
@@ -446,7 +446,8 @@
 
           dim_vector dv = result.dims ();
 
-          retval(0) = (dv.isvector () ? result : result.reshape (dv.as_column ()));
+          retval(0) = (dv.all_zero () || dv.isvector ()
+                       ? result : result.reshape (dv.as_column ()));
         }
       else
         {
@@ -585,6 +586,11 @@
 %! assert (j, jfull);
 %! assert (all (v == 1));
 
+%!assert <*53655> (find (false), zeros (0, 0))
+%!assert <*53655> (find ([false, false]), zeros (1, 0))
+%!assert <*53655> (find ([false; false]), zeros (0, 1))
+%!assert <*53655> (find ([false, false; false, false]), zeros (0, 1))
+
 %!assert (find ([2 0 1 0 5 0], 1), 1)
 %!assert (find ([2 0 1 0 5 0], 2, "last"), [3, 5])