comparison libinterp/corefcn/find.cc @ 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 6652d3823428
children 316b75b0d886
comparison
equal deleted inserted replaced
25193:6f1fde568e46 25195:2f0c0c0652d5
437 { 437 {
438 // This case is equivalent to extracting indices from a logical 438 // This case is equivalent to extracting indices from a logical
439 // matrix. Try to reuse the possibly cached index vector. 439 // matrix. Try to reuse the possibly cached index vector.
440 440
441 // No need to catch index_exception, since arg is bool. 441 // No need to catch index_exception, since arg is bool.
442 // Out-of-range errors have already set pos, and will be caught later. 442 // Out-of-range errors have already set pos, and will be
443 retval(0) = arg.index_vector ().unmask (); 443 // caught later.
444
445 octave_value result = arg.index_vector ().unmask ();
446
447 dim_vector dv = result.dims ();
448
449 retval(0) = (dv.isvector () ? result : result.reshape (dv.as_column ()));
444 } 450 }
445 else 451 else
446 { 452 {
447 boolNDArray v = arg.bool_array_value (); 453 boolNDArray v = arg.bool_array_value ();
448 454
538 %!assert (find (char ([0, 97])), 2) 544 %!assert (find (char ([0, 97])), 2)
539 %!assert (find ([1, 0, 1, 0, 1]), [1, 3, 5]) 545 %!assert (find ([1, 0, 1, 0, 1]), [1, 3, 5])
540 %!assert (find ([1; 0; 3; 0; 1]), [1; 3; 5]) 546 %!assert (find ([1; 0; 3; 0; 1]), [1; 3; 5])
541 %!assert (find ([0, 0, 2; 0, 3, 0; -1, 0, 0]), [3; 5; 7]) 547 %!assert (find ([0, 0, 2; 0, 3, 0; -1, 0, 0]), [3; 5; 7])
542 548
549 %!assert <*53603> (find (ones (1,1,2) > 0), [1;2])
550 %!assert <*53603> (find (ones (1,1,1,3) > 0), [1;2;3])
551
543 %!test 552 %!test
544 %! [i, j, v] = find ([0, 0, 2; 0, 3, 0; -1, 0, 0]); 553 %! [i, j, v] = find ([0, 0, 2; 0, 3, 0; -1, 0, 0]);
545 %! 554 %!
546 %! assert (i, [3; 2; 1]); 555 %! assert (i, [3; 2; 1]);
547 %! assert (j, [1; 2; 3]); 556 %! assert (j, [1; 2; 3]);