# HG changeset patch # User Rik # Date 1378501722 25200 # Node ID 6dbc866379e22072111a90063d5f477705a46e45 # Parent 5ca5aff90ffd6db20fd5e948929645cbca911068 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. diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/help/doc_cache_create.m --- a/scripts/help/doc_cache_create.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/help/doc_cache_create.m Fri Sep 06 14:08:42 2013 -0700 @@ -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 diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/image/imformats.m --- a/scripts/image/imformats.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/image/imformats.m Fri Sep 06 14:08:42 2013 -0700 @@ -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 diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/image/private/__imread__.m --- a/scripts/image/private/__imread__.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/image/private/__imread__.m Fri Sep 06 14:08:42 2013 -0700 @@ -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)) && diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/miscellaneous/what.m --- a/scripts/miscellaneous/what.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/miscellaneous/what.m Fri Sep 06 14:08:42 2013 -0700 @@ -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 diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/pkg/private/rebuild.m --- a/scripts/pkg/private/rebuild.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/pkg/private/rebuild.m Fri Sep 06 14:08:42 2013 -0700 @@ -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 diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/plot/axis.m --- a/scripts/plot/axis.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/plot/axis.m Fri Sep 06 14:08:42 2013 -0700 @@ -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]; diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/plot/pareto.m --- a/scripts/plot/pareto.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/plot/pareto.m Fri Sep 06 14:08:42 2013 -0700 @@ -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"); diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/plot/private/__gnuplot_print__.m --- a/scripts/plot/private/__gnuplot_print__.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/plot/private/__gnuplot_print__.m Fri Sep 06 14:08:42 2013 -0700 @@ -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 diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/plot/private/__line__.m --- a/scripts/plot/private/__line__.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/plot/private/__line__.m Fri Sep 06 14:08:42 2013 -0700 @@ -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); diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/plot/private/__patch__.m --- a/scripts/plot/private/__patch__.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/plot/private/__patch__.m Fri Sep 06 14:08:42 2013 -0700 @@ -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) diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/plot/struct2hdl.m --- a/scripts/plot/struct2hdl.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/plot/struct2hdl.m Fri Sep 06 14:08:42 2013 -0700 @@ -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)}; diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/polynomial/splinefit.m --- a/scripts/polynomial/splinefit.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/polynomial/splinefit.m Fri Sep 06 14:08:42 2013 -0700 @@ -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{:}); diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/special-matrix/gallery.m --- a/scripts/special-matrix/gallery.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/special-matrix/gallery.m Fri Sep 06 14:08:42 2013 -0700 @@ -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 diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/strings/strsplit.m --- a/scripts/strings/strsplit.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/strings/strsplit.m Fri Sep 06 14:08:42 2013 -0700 @@ -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 diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/strings/untabify.m --- a/scripts/strings/untabify.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/strings/untabify.m Fri Sep 06 14:08:42 2013 -0700 @@ -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) diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/testfun/__run_test_suite__.m --- a/scripts/testfun/__run_test_suite__.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/testfun/__run_test_suite__.m Fri Sep 06 14:08:42 2013 -0700 @@ -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) diff -r 5ca5aff90ffd -r 6dbc866379e2 scripts/ui/inputdlg.m --- a/scripts/ui/inputdlg.m Fri Sep 06 13:25:24 2013 -0700 +++ b/scripts/ui/inputdlg.m Fri Sep 06 14:08:42 2013 -0700 @@ -66,7 +66,7 @@ if (iscell (prompt)) ## Silently extract only char elements - prompt = prompt(cellfun ("ischar", prompt)); + prompt = prompt(cellfun ("isclass", prompt, "char")); elseif (ischar (prompt)) prompt = {prompt}; else