Mercurial > octave
changeset 31817:90ce081eb281
Fix mat2cell for N-D array input with only one output dimension (bug #63682)
* cellfun.cc (do_mat2cell_nd): If only one output dimension is specified (rows)
then set the column field of the dimension vector to 1 (All arrays in Octave
are at least 2-D).
* cellfun.cc (Fmat2cell): Clarify output is C in docstring. Add BIST test for
bug #63682.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 04 Feb 2023 17:49:58 -0800 |
parents | 60c072f42338 |
children | 758de955caca |
files | libinterp/corefcn/cellfun.cc |
diffstat | 1 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/cellfun.cc Sat Feb 04 17:38:52 2023 -0800 +++ b/libinterp/corefcn/cellfun.cc Sat Feb 04 17:49:58 2023 -0800 @@ -2061,6 +2061,8 @@ idxtot += nidx[i]; } + if (nd == 1) + rdv(1) = 1; retval.clear (rdv); OCTAVE_LOCAL_BUFFER (idx_vector, xidx, idxtot); @@ -2161,7 +2163,7 @@ doc: /* -*- texinfo -*- @deftypefn {} {@var{C} =} mat2cell (@var{A}, @var{dim1}, @var{dim2}, @dots{}, @var{dimi}, @dots{}, @var{dimn}) @deftypefnx {} {@var{C} =} mat2cell (@var{A}, @var{rowdim}) -Convert the matrix @var{A} to a cell array. +Convert the matrix @var{A} to a cell array @var{C}. Each dimension argument (@var{dim1}, @var{dim2}, etc.@:) is a vector of integers which specifies how to divide that dimension's elements amongst the @@ -2332,6 +2334,15 @@ %! c = mat2cell (x, 1, [0,4,2,0,4,0]); %! empty1by0str = resize ("", 1, 0); %! assert (c, {empty1by0str,"abcd","ef",empty1by0str,"ghij",empty1by0str}); + +## Omitted input for trailing dimensions means not splitting on them. +%!test <*63682> +%! x = reshape (1:16, 4, 2, 2); +%! c1 = mat2cell (x, [2, 2], 2, 2); +%! c2 = mat2cell (x, [2, 2]); +%! assert (c1, c2); +%! assert (c1, {cat(3, [1,5;2,6], [9,13;10,14]); ... +%! cat(3, [3,7;4,8], [11,15;12,16])}); */ // FIXME: it would be nice to allow ranges being handled without a conversion.