changeset 30706:6fff5d9291ce stable

describe find's indexing behavior for dim > 2 and add BIST (bug #61986) * libinterp/corefcn/find.cc: add description of find returning column indexing of flattened multidimensional arrays to docstring, add a BIST to verify behavior.
author Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
date Thu, 03 Feb 2022 09:08:39 -0500
parents ec36fe975d2d
children ebda4b3a0482
files libinterp/corefcn/find.cc
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/find.cc	Wed Feb 02 18:41:03 2022 +0100
+++ b/libinterp/corefcn/find.cc	Thu Feb 03 09:08:39 2022 -0500
@@ -377,6 +377,10 @@
 @end group
 @end example
 
+If @var{x} is multidimensional array of size m x n x p x @dots{}, @var{j} is
+the column location as if @var{x} was flattened into a two-dimensional matrix
+of size m x (n + p + @dots{}).
+
 Note that this function is particularly useful for sparse matrices, as
 it extracts the nonzero elements as vectors, which can then be used to
 create the original matrix.  For example:
@@ -588,6 +592,15 @@
 %! assert (j, jfull);
 %! assert (all (v == 1));
 
+%!test <*61986>
+%! P = cat (3, eye(3), eye(3));
+%! loc = find (P);
+%! [i, j, v] = find(P);
+%! assert (loc, [1, 5, 9, 10, 14, 18]');
+%! assert (i, [1, 2, 3, 1, 2, 3]');
+%! assert (j, [1, 2, 3, 4, 5, 6]');
+%! assert (v, [1, 1, 1, 1, 1, 1]');
+
 %!assert <*53655> (find (false), zeros (0, 0))
 %!assert <*53655> (find ([false, false]), zeros (1, 0))
 %!assert <*53655> (find ([false; false]), zeros (0, 1))