Mercurial > octave
changeset 33300:38860e27296b
assert.m: Recode ind2tuple subfunction for 20% performance boost.
* assert.m: Recode and remove for loop. Replace with combination of sprintf()
and ostrsplit().
author | Rik <rik@octave.org> |
---|---|
date | Tue, 02 Apr 2024 21:35:47 -0700 |
parents | e50806e3f370 |
children | 36918f99b189 |
files | scripts/testfun/assert.m |
diffstat | 1 files changed, 6 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/testfun/assert.m Tue Apr 02 16:13:21 2024 -0700 +++ b/scripts/testfun/assert.m Tue Apr 02 21:35:47 2024 -0700 @@ -765,17 +765,17 @@ ## Convert all error indices into tuple format function cout = ind2tuple (matsize, erridx) - cout = cell (numel (erridx), 1); tmp = cell (1, numel (matsize)); [tmp{:}] = ind2sub (matsize, erridx(:)); subs = [tmp{:}]; if (numel (matsize) == 2) - subs = subs(:, matsize != 1); + subs = subs(:, matsize != 1); # For vectors, use 1-D index endif - for i = 1:numel (erridx) - loc = sprintf ("%d,", subs(i,:)); - cout{i} = ["(" loc(1:end-1) ")"]; - endfor + fmt = repmat ('%d,', 1, columns (subs)); + fmt(end) = []; # delete final extra comma + cout = ostrsplit (sprintf (['(' fmt ')', '$'], subs'), '$'); + cout(end) = []; # delete extra cell from final '$' + cout = cout.'; # return column vector endfunction