# HG changeset patch # User Rik # Date 1608256670 28800 # Node ID 3332f1964e598d3595de02c86d5373ad9bd647c9 # Parent 01e5c00a860985fd4a5617745fdc606419b99103# Parent 900246a8bb37ba1b08c3fbcbdf07bedb1fe0aed1 maint: merge stable to default. diff -r 01e5c00a8609 -r 3332f1964e59 scripts/general/repelem.m --- a/scripts/general/repelem.m Thu Dec 17 15:58:23 2020 -0800 +++ b/scripts/general/repelem.m Thu Dec 17 17:57:50 2020 -0800 @@ -226,7 +226,7 @@ vector_r = ! (cellfun (@numel, varargin) == 1); ## 1. Check that all varargin are either scalars or vectors, not arrays. - ## isvector gives true for scalars. + ## isvector returns true for scalars so one test captures both inputs. if (! (isvector (varargin{1}) && (isvector (varargin{2})))) error ("repelem: R1 and R2 must be scalars or vectors"); @@ -237,13 +237,17 @@ endif ## Create index arrays to pass to element. - ## (It is no slower passing to prepareIdx - ## than checking and doing scalars directly.) + ## (It is no slower to call prepareIdx than to check and do scalars + ## directly.) idx1 = prepareIdx (varargin{1}, xsz(1)); idx2 = prepareIdx (varargin{2}, xsz(2)); - ## The ":" at the end takes care of any x dimensions > 2. - retval = x(idx1, idx2, :); + if (issparse (x)) + retval = x(idx1, idx2); + else + ## The ":" at the end takes care of any x dimensions > 2. + retval = x(idx1, idx2, :); + endif else # (nargin > 3) @@ -437,6 +441,11 @@ %!test <*54275> %! assert (repelem (11:13, [1 3 0]), [11 12 12 12]); +%!test <*59705> +%! xs = sparse (magic (3)); +%! assert (repelem (xs, 1, 2), ... +%! sparse ([8,8,1,1,6,6; 3,3,5,5,7,7; 4,4,9,9,2,2])); + ## nargin <= 1 error tests %!error repelem () %!error repelem (1)