Mercurial > hg > octave-lyh
changeset 17394:6dbc866379e2
Replace cellfun() occurrences with faster code where possible.
* scripts/help/doc_cache_create.m: Use built-in "isclass" rather than ischar.
Use addpath and rmpath with multiple inputs rather than cellfun.
* scripts/image/imformats.m: Use isfield with cell string list rather
than cellfun.
* scripts/image/private/__imread__.m: Use ismember to replace cellfun/strcmpi
combo.
* scripts/miscellaneous/what.m: Re-order if/elseif tree.
* scripts/pkg/private/rebuild.m: Replace cellfun with strcat call.
* scripts/plot/axis.m: Use comma-separated lists to replace cellfun.
* scripts/plot/pareto.m: Use cellstr on char array to replace cellfun.
* scripts/plot/private/__gnuplot_print__.m: Use @times, rather than
anonymous function, in cellfun call.
* scripts/plot/private/__line__.m: White space cleanup.
* scripts/plot/private/__patch__.m: Use ismember to replace cellfun/strcmpi
combo. Use in-place '|=' operator for performance.
* scripts/plot/struct2hdl.m: Use ismember to replace cellfun/strcmp combo.
* scripts/polynomial/splinefit.m: Use built-in "isclass" rather than ischar.
* scripts/special-matrix/gallery.m: Remove anonymous functions inside cellfuns.
* scripts/strings/strsplit.m: Correct comment character to '#' from '%'.
* scripts/strings/untabify.m: Use multiple argument form of cellfun to get
rid of anonymous function.
* scripts/testfun/__run_test_suite__.m: Remove anonymous function from within
cellfun.
* scripts/ui/inputdlg.m: Use built-in "isclass" rather than ischar.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 06 Sep 2013 14:08:42 -0700 |
parents | 5ca5aff90ffd |
children | 2b4ed68be0d5 |
files | scripts/help/doc_cache_create.m scripts/image/imformats.m scripts/image/private/__imread__.m scripts/miscellaneous/what.m scripts/pkg/private/rebuild.m scripts/plot/axis.m scripts/plot/pareto.m scripts/plot/private/__gnuplot_print__.m scripts/plot/private/__line__.m scripts/plot/private/__patch__.m scripts/plot/struct2hdl.m scripts/polynomial/splinefit.m scripts/special-matrix/gallery.m scripts/strings/strsplit.m scripts/strings/untabify.m scripts/testfun/__run_test_suite__.m scripts/ui/inputdlg.m |
diffstat | 17 files changed, 36 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/help/doc_cache_create.m +++ b/scripts/help/doc_cache_create.m @@ -42,7 +42,7 @@ if (isempty (directory)) cache = gen_builtin_cache (); elseif (iscell (directory)) - if (all (cellfun (@ischar, directory))) + if (all (cellfun ("isclass", directory, "char"))) cache = gen_doc_cache_in_dir (directory); else error ("doc_cache_create: cell must contain only strings"); @@ -95,7 +95,7 @@ ## For each function: for n = 1:length (list) - f = list {n}; + f = list{n}; ## Get help text [text, format] = get_help_text (f); @@ -108,9 +108,9 @@ endif ## Store the help text - cache (1, end+1) = f; - cache (2, end) = text; - cache (3, end) = first_sentence; + cache(1, end+1) = f; + cache(2, end) = text; + cache(3, end) = first_sentence; endfor endfunction @@ -127,19 +127,19 @@ ## add them if (! isempty (dirs_notpath)) - cellfun (@addpath, dirs_notpath); + addpath (dirs_notpath{:}); endif ## create cache func = @(s_) create_cache (__list_functions__ (s_)); - cache = cellfun (func, directory, 'UniformOutput', false); + cache = cellfun (func, directory, "UniformOutput", false); ## concatenate results cache = [cache{:}]; ## remove dirs form path if (! isempty (dirs_notpath)) - cellfun (@rmpath, dirs_notpath); + rmpath (dirs_notpath{:}); endif endfunction
--- a/scripts/image/imformats.m +++ b/scripts/image/imformats.m @@ -260,7 +260,7 @@ ## the minimal list of fields required in the structure. We don't ## require multipage because it doesn't exist in matlab min_fields = {"ext", "read", "isa", "write", "info", "alpha", "description"}; - fields_mask = cellfun (@(x) isfield (format, x), min_fields); + fields_mask = isfield (format, min_fields); if (! all (fields_mask)) error ("imformats: structure has missing field `%s'.", min_fields(! fields_mask){1}); endif
--- a/scripts/image/private/__imread__.m +++ b/scripts/image/private/__imread__.m @@ -79,9 +79,9 @@ endif ## Check key/value options. - indexes = find (cellfun (@(x) ischar (x) ... - && any (strcmpi (x, {"frames", "index"})), - varargin)); + indexes = cellfun ("isclass", varargin, "char"); + indexes(indexes) &= ismember (varargin(indexes), {"frames", "index"}); + indexes = find (indexes); if (indexes) options.index = varargin{indexes+1}; if (! (is_valid_index_option (options.index)) &&
--- a/scripts/miscellaneous/what.m +++ b/scripts/miscellaneous/what.m @@ -63,13 +63,13 @@ [dummy, f, e] = fileparts (n); if (strcmp (e, ".m")) w.m{end+1} = n; - elseif (strcmp (e, mexext ())) - w.mex{end+1} = n; elseif (strcmp (e, ".oct")) w.oct{end+1} = n; + elseif (strcmp (e, mexext ())) + w.mex{end+1} = n; elseif (strcmp (e, ".mat")) w.mat{end+1} = n; - elseif(strcmp (n(1), "@")) + elseif (strcmp (n(1), "@")) w.classes{end+1} = n; endif endif
--- a/scripts/pkg/private/rebuild.m +++ b/scripts/pkg/private/rebuild.m @@ -35,7 +35,7 @@ wd = pwd (); unwind_protect cd (prefix); - dirlist = glob (cellfun(@(x) [x '-*'], files, 'uniformoutput', 0)); + dirlist = glob (strcat (files, '-*')); unwind_protect_cleanup cd (wd); end_unwind_protect
--- a/scripts/plot/axis.m +++ b/scripts/plot/axis.m @@ -339,8 +339,8 @@ data = cellfun (@(x) x(isfinite (x)), data, "uniformoutput", false); data = data(! cellfun ("isempty", data)); if (! isempty (data)) - lims_min = min (cellfun (@(x) min (x(:)), data(:))); - lims_max = max (cellfun (@(x) max (x(:)), data(:))); + lims_min = min ([data{:}](:)); + lims_max = max ([data{:}](:)); lims = [lims_min, lims_max]; else lims = [0, 1];
--- a/scripts/plot/pareto.m +++ b/scripts/plot/pareto.m @@ -70,19 +70,18 @@ print_usage (); endif - x = varargin {1}(:).'; + x = varargin{1}(:).'; if (nargin == 2) - y = varargin {2}(:).'; + y = varargin{2}(:).'; if (! iscell (y)) if (ischar (y)) y = cellstr (y); else - y = cellfun ("num2str", num2cell (y), "uniformoutput", false); + y = cellstr (num2str (y(:))); endif endif else - y = cellfun ("int2str", num2cell (1 : numel (x)), - "uniformoutput", false); + y = cellstr (int2str ([1:numel(x)]')); endif [x, idx] = sort (x, "descend");
--- a/scripts/plot/private/__gnuplot_print__.m +++ b/scripts/plot/private/__gnuplot_print__.m @@ -171,7 +171,7 @@ function eps_drawnow (opts, epsfile, gp_opts) [h, fontsize] = get_figure_text_objs (opts); unwind_protect - fontsize_2x = cellfun (@(x) 2*x, fontsize, "uniformoutput", false); + fontsize_2x = cellfun (@times, {2}, fontsize, "uniformoutput", false); set (h, {"fontsize"}, fontsize_2x); local_drawnow (["postscript eps " gp_opts], epsfile, opts); unwind_protect_cleanup
--- a/scripts/plot/private/__line__.m +++ b/scripts/plot/private/__line__.m @@ -113,7 +113,6 @@ || (nvecpts != 0 && any (nvecpts != cellfun ("size", tmp, 1)))) error ("line: data size_mismatch"); endif - data_args(mask) = cellfun (@(x) x(:,i), data(ismat), "uniformoutput", false);
--- a/scripts/plot/private/__patch__.m +++ b/scripts/plot/private/__patch__.m @@ -210,13 +210,14 @@ endfunction function args = delfields (args, flds) - idx = cellfun (@(x) any (strcmpi (x, flds)), args); + idx = cellfun ("isclass", args, "char"); + idx(idx) = ismember (args(idx), flds); if (rows (idx) == 1) - idx = idx | [false, idx(1:end-1)]; + idx |= [false, idx(1:end-1)]; else - idx = idx | [false; idx(1:end-1)]; + idx |= [false; idx(1:end-1)]; endif - args (idx) = []; + args(idx) = []; endfunction function args = setdata (args)
--- a/scripts/plot/struct2hdl.m +++ b/scripts/plot/struct2hdl.m @@ -93,7 +93,7 @@ p = p(1:2, 1:(tst(end)-1)); endif - ## Place the "*mode" properties as the end to avoid having the updaters + ## Place the "*mode" properties at the end to avoid having the updaters ## change the mode to "manual" when the value is "auto". names = fieldnames (s.properties); n = strncmp (cellfun (@fliplr, names, "uniformoutput", false), "edom", 4); @@ -630,7 +630,7 @@ hid = {"autopos_tag", "looseinset"}; oldfields = fieldnames (props); curfields = fieldnames (get (h)); - missing = cellfun (@(x) !any (strcmp (x, curfields)), oldfields); + missing = ! ismember (oldfields, curfields); idx = find (missing); for ii = 1:length (idx) prop = oldfields{idx(ii)};
--- a/scripts/polynomial/splinefit.m +++ b/scripts/polynomial/splinefit.m @@ -94,7 +94,7 @@ function pp = splinefit (x, y, breaks, varargin) if (nargin > 3) - n = cellfun (@ischar, varargin, "uniformoutput", true); + n = cellfun ("isclass", varargin, "char"); varargin(n) = lower (varargin(n)); try props = struct (varargin{:});
--- a/scripts/special-matrix/gallery.m +++ b/scripts/special-matrix/gallery.m @@ -2464,7 +2464,7 @@ error ("gallery: 1 to 6 arguments are required for toeppen matrix."); elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) error ("gallery: N must be a numeric integer for toeppen matrix."); - elseif (any (cellfun (@(x) ! isnumeric (x) || ! isscalar (x), {a b c d e}))) + elseif (any (! cellfun ("isnumeric", {a b c d e})) || any (cellfun ("numel", {a b c d e}) != 1)) error ("gallery: A, B, C, D and E must be numeric scalars for toeppen matrix."); endif
--- a/scripts/strings/strsplit.m +++ b/scripts/strings/strsplit.m @@ -187,7 +187,7 @@ else del = do_string_escapes (del); endif - % This is clumsy, but needed for multi-row strings + ## This is clumsy, but needed for multi-row strings del = regexprep (del, '([^\w])', '\\$1'); endif
--- a/scripts/strings/untabify.m +++ b/scripts/strings/untabify.m @@ -61,7 +61,7 @@ if (ischar (t)) s = replace_tabs (t, tw); else - s = cellfun (@(str) replace_tabs (str, tw), t, "uniformoutput", false); + s = cellfun (@replace_tabs, t, {tw}, "uniformoutput", false); endif if (dblank)
--- a/scripts/testfun/__run_test_suite__.m +++ b/scripts/testfun/__run_test_suite__.m @@ -257,7 +257,7 @@ endfunction function n = num_elts_matching_pattern (lst, pat) - n = sum (cellfun (@(x) !isempty (x), regexp (lst, pat, 'once'))); + n = sum (! cellfun ("isempty", regexp (lst, pat, 'once'))); endfunction function report_files_with_no_tests (with, without, typ)