changeset 25195:2f0c0c0652d5 stable

find: return column vector for N-d logical arrays (bug #53603) * find.cc (Ffind): In special case for bool arrays, force return value to be column vector if it is not already a row or column vector.
author John W. Eaton <jwe@octave.org>
date Tue, 10 Apr 2018 12:19:02 -0400
parents 6f1fde568e46
children 6254e47f2c6c 8cff7eceee87
files libinterp/corefcn/find.cc
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/find.cc	Tue Apr 10 09:54:07 2018 -0400
+++ b/libinterp/corefcn/find.cc	Tue Apr 10 12:19:02 2018 -0400
@@ -439,8 +439,14 @@
           // matrix.  Try to reuse the possibly cached index vector.
 
           // No need to catch index_exception, since arg is bool.
-          // Out-of-range errors have already set pos, and will be caught later.
-          retval(0) = arg.index_vector ().unmask ();
+          // Out-of-range errors have already set pos, and will be
+          // caught later.
+
+          octave_value result = arg.index_vector ().unmask ();
+
+          dim_vector dv = result.dims ();
+
+          retval(0) = (dv.isvector () ? result : result.reshape (dv.as_column ()));
         }
       else
         {
@@ -540,6 +546,9 @@
 %!assert (find ([1; 0; 3; 0; 1]), [1; 3; 5])
 %!assert (find ([0, 0, 2; 0, 3, 0; -1, 0, 0]), [3; 5; 7])
 
+%!assert <*53603> (find (ones (1,1,2) > 0), [1;2])
+%!assert <*53603> (find (ones (1,1,1,3) > 0), [1;2;3])
+
 %!test
 %! [i, j, v] = find ([0, 0, 2; 0, 3, 0; -1, 0, 0]);
 %!