Mercurial > octave
changeset 30379:363fb10055df stable
maint: Style check m-files ahead of 7.1 release.
* Map.m, integral3.m, logspace.m, quad2d.m, quadgk.m, quadl.m, tsearchn.m,
get_first_help_sentence.m, print_usage.m, getframe.m, imformats.m,
javaclasspath.m, condest.m, null.m, ordeig.m, inputParser.m, license.m,
memory.m, methods.m, __publish_html_output__.m, __publish_latex_output__.m,
publish.m, ode15s.m, fminbnd.m, fzero.m, configure_make.m, get_description.m,
get_forge_pkg.m, annotation.m, camlookat.m, legend.m, __gnuplot_legend__.m,
bar.m, colorbar.m, fill3.m, isosurface.m, plotyy.m, polar.m, __bar__.m,
__ezplot__.m, __patch__.m, __pie__.m, __plt__.m, __scatter__.m, smooth3.m,
stemleaf.m, __gnuplot_drawnow__.m, print.m, printd.m, __add_default_menu__.m,
__gnuplot_draw_axes__.m, __gnuplot_print__.m, __print_parse_opts__.m,
struct2hdl.m, profexport.m, profile.m, movfun.m, sprandsym.m, betaincinv.m,
factor.m, nchoosek.m, gallery.m, hadamard.m, iqr.m, ranks.m,
__run_test_suite__.m, test.m, datevec.m, weboptions.m:
Style check m-files ahead of 7.1 release.
line wrap: on
line diff
--- a/scripts/+containers/Map.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/+containers/Map.m Fri Nov 26 20:53:22 2021 -0800 @@ -109,6 +109,7 @@ methods (Access = public) function this = Map (varargin) + if (nargin == 0) ## Empty object with "char" key type and "any" value type. elseif (nargin == 2 || (nargin == 4 @@ -294,7 +295,7 @@ tf = false (size (keySet)); in = cellfun ("isnumeric", keySet) | cellfun ("islogical", keySet); if (! this.numeric_keys) - in = !in; + in = ! in; endif keySet = encode_keys (this, keySet(in)); tf(in) = isfield (this.map, keySet); @@ -320,7 +321,7 @@ endif in = cellfun ("isnumeric", keySet) | cellfun ("islogical", keySet); if (! this.numeric_keys) - in = !in; + in = ! in; endif keySet = encode_keys (this, keySet(in)); in = isfield (this.map, keySet); @@ -378,6 +379,7 @@ endfunction function sref = subsref (this, s) + switch (s(1).type) case "." switch (s(1).subs) @@ -390,7 +392,7 @@ s(1) = []; else sref = values (this); - end + endif case "size" sref = size (this); case "length" @@ -437,9 +439,11 @@ if (numel (s) > 1) sref = subsref (sref, s(2:end)); endif + endfunction function this = subsasgn (this, s, val) + if (numel (s) > 1) error ("containers.Map: only one level of indexing is supported"); endif @@ -472,6 +476,7 @@ case "{}" error ("containers.Map: only '()' indexing is supported for assigning values"); endswitch + endfunction function newobj = horzcat (varargin) @@ -481,6 +486,7 @@ endfunction function newobj = vertcat (varargin) + ## When concatenating maps, the data type of all values must be ## consistent with the ValueType of the leftmost map. keySet = cell (1, 0); @@ -500,6 +506,7 @@ valueSet = [valueSet, values(varargin{i})]; endfor newobj = containers.Map (keySet, valueSet); + endfunction function disp (this) @@ -517,6 +524,7 @@ ## All keys are encoded as strings. ## For numeric keys, this requires conversion. function keys = encode_keys (this, keys) + if (iscellstr (keys) || ischar (keys)) return; endif @@ -536,6 +544,7 @@ if (cell_input) keys = reshape (cellstr (keys), orig_sz); endif + endfunction function keys = decode_keys (this, keys) @@ -547,6 +556,7 @@ endfunction function this = sort_keys (this) + keySet = keys (this); if (this.numeric_keys) [~, p] = sort (cell2mat (keySet)); @@ -554,9 +564,11 @@ [~, p] = sort (keySet); endif this.map = orderfields (this.map, p); + endfunction function check_types (this) + switch (this.KeyType) case {"char"} this.numeric_keys = false; @@ -573,6 +585,7 @@ "int64"; "uint64"}))) error ("containers.Map: unsupported ValueType"); endif + endfunction endmethods
--- a/scripts/general/integral3.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/general/integral3.m Fri Nov 26 20:53:22 2021 -0800 @@ -256,6 +256,7 @@ endfunction function q = inner (x, f, ya, yb, za, zb, vectorized, method, abstol, reltol) + q = zeros (size (x)); for i = 1 : length (x) za2 = @(y) za(x(i), y); @@ -272,6 +273,7 @@ "AbsTol", abstol, "RelTol", reltol); endif endfor + endfunction function q = inner_iterated (y, f2, za2, zb2, abstol, reltol)
--- a/scripts/general/logspace.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/general/logspace.m Fri Nov 26 20:53:22 2021 -0800 @@ -92,6 +92,7 @@ endfunction + %!test %! x1 = logspace (1, 2); %! x2 = logspace (1, 2, 10.1);
--- a/scripts/general/quad2d.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/general/quad2d.m Fri Nov 26 20:53:22 2021 -0800 @@ -357,6 +357,7 @@ endfunction function [q, qerr] = tensorproduct (f, ya, yb, tile, xtrans, ytrans, ztrans, singular) + ## The Shampine TwoD paper proposes using a G3,K7 rule in a tensor product. ## I couldn't find a tabulated abscissas and weights of a G3,K7 rule publicly ## available, so use a G7,K15 rule from Octave's implementation of quadgk.
--- a/scripts/general/quadgk.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/general/quadgk.m Fri Nov 26 20:53:22 2021 -0800 @@ -409,6 +409,7 @@ ## FIXME: too_close output is never used in function that calls this one. function [q, err, too_close] = __quadgk_eval__ (f, subs, eps1, trans) + ## A (15,7) point pair of Gauss-Kronrod quadrature rules. ## The abscissa and weights are copied directly from dqk15w.f from quadpack.
--- a/scripts/general/quadl.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/general/quadl.m Fri Nov 26 20:53:22 2021 -0800 @@ -119,6 +119,7 @@ function [q, nfun, hmin] = adaptlobstp (f, a, b, fa, fb, q0, nfun, hmin, tol, trace, varargin) + persistent alpha = sqrt (2/3); persistent beta = 1 / sqrt (5);
--- a/scripts/geometry/tsearchn.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/geometry/tsearchn.m Fri Nov 26 20:53:22 2021 -0800 @@ -68,6 +68,7 @@ endfunction function Beta = cart2bary (T, P) + ## Conversion of Cartesian to Barycentric coordinates. ## Given a reference simplex in N dimensions represented by an ## N+1-by-N matrix, an arbitrary point P in Cartesian coordinates,
--- a/scripts/help/get_first_help_sentence.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/help/get_first_help_sentence.m Fri Nov 26 20:53:22 2021 -0800 @@ -91,6 +91,7 @@ ## This function extracts the first sentence from a plain text help text function [text, status] = first_sentence_plain_text (help_text, max_len) + ## Extract first line by searching for a period followed by whitespace ## followed by a capital letter (Nearly the same rule as Texinfo). period_idx = regexp (help_text, '\.\s+(?:[A-Z]|\n)', "once"); @@ -119,6 +120,7 @@ ## render the text to plain text using makeinfo, and then extract the first ## line. function [text, status] = first_sentence_texinfo (help_text, max_len) + ## Lines ending with "@\n" are continuation lines, so they should be ## concatenated with the following line. help_text = strrep (help_text, "@\n", " "); @@ -169,11 +171,13 @@ ## This function extracts the first sentence from a html help text. ## The function simply removes the tags and treats the text as plain text. function [text, status] = first_sentence_html (help_text, max_len) + ## Strip tags [help_text, status] = strip_html_tags (help_text); ## Extract first line with plain text method. text = first_sentence_plain_text (help_text, max_len); + endfunction
--- a/scripts/help/print_usage.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/help/print_usage.m Fri Nov 26 20:53:22 2021 -0800 @@ -148,11 +148,13 @@ endfunction function [retval, status] = get_usage_html (help_text, max_len) + ## Strip tags [help_text, status] = strip_html_tags (help_text); ## Extract first line with plain text method. retval = get_usage_plain_text (help_text, max_len); + endfunction
--- a/scripts/image/getframe.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/image/getframe.m Fri Nov 26 20:53:22 2021 -0800 @@ -52,6 +52,7 @@ ## @end deftypefn function frame = getframe (h = [], rect = []) + hf = hax = []; if (isempty (h)) hf = get (0, "currentfigure");
--- a/scripts/image/imformats.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/image/imformats.m Fri Nov 26 20:53:22 2021 -0800 @@ -295,6 +295,7 @@ endfunction function pretty_print_formats (formats) + ## define header names (none should be shorter than 3 characters) headers = {"Extension", "isa", "Info", "Read", "Write", "Alpha", "Description"}; cols_length = cellfun (@numel, headers);
--- a/scripts/java/javaclasspath.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/java/javaclasspath.m Fri Nov 26 20:53:22 2021 -0800 @@ -115,10 +115,12 @@ ## Display cell array of paths function disp_path_list (what, path_list) + printf (" %s JAVA PATH\n\n", what); if (numel (path_list) > 0) printf (" %s\n", path_list{:}); else printf (" - empty -\n"); endif + endfunction
--- a/scripts/linear-algebra/condest.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/linear-algebra/condest.m Fri Nov 26 20:53:22 2021 -0800 @@ -248,6 +248,7 @@ endfunction function retval = inv_sparse_fcn (flag, x, varargin) + ## FIXME: Sparse algorithm is less accurate than full matrix version. ## See BIST test for asymmetric matrix where relative tolerance ## of 1e-12 is used for sparse, but 4e-16 for full matrix.
--- a/scripts/linear-algebra/null.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/linear-algebra/null.m Fri Nov 26 20:53:22 2021 -0800 @@ -60,7 +60,7 @@ s = diag (S); else s = S(1); - end + endif if (nargin == 1) tol = max (size (A)) * s(1) * eps (out_cls); endif
--- a/scripts/linear-algebra/ordeig.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/linear-algebra/ordeig.m Fri Nov 26 20:53:22 2021 -0800 @@ -107,12 +107,14 @@ ## Check whether a matrix is quasi-triangular function retval = is_quasitri (A) + if (length (A) <= 2) retval = true; else v = diag (A, -1) != 0; retval = (all (tril (A, -2)(:) == 0) && all (v(1:end-1) + v(2:end) < 2)); endif + endfunction
--- a/scripts/miscellaneous/inputParser.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/miscellaneous/inputParser.m Fri Nov 26 20:53:22 2021 -0800 @@ -506,6 +506,7 @@ endfunction function disp (this) + if (nargin != 1) print_usage (); endif @@ -519,6 +520,7 @@ b2s (this.StructExpand)); printf ("Defined parameters:\n\n {%s}\n", strjoin (this.Parameters, ", ")); + endfunction endmethods @@ -526,6 +528,7 @@ methods (Access = private) function validate_name (this, type, name) + if (! isvarname (name)) error ("inputParser.add%s: NAME is an invalid identifier", method); elseif (any (strcmpi (this.Parameters, name))) @@ -535,17 +538,21 @@ type, name); endif this.Parameters{end+1} = name; + endfunction function validate_arg (this, name, val, in) - if (! val (in)) - this.error (sprintf ("failed validation of %s with %s", - toupper (name), func2str (val))); - endif - this.Results.(name) = in; + + if (! val (in)) + this.error (sprintf ("failed validation of %s with %s", + toupper (name), func2str (val))); + endif + this.Results.(name) = in; + endfunction function r = is_argname (this, type, name) + r = ischar (name) && isrow (name); if (r) if (this.CaseSensitive) @@ -562,23 +569,28 @@ endif endif endif + endfunction function add_missing (this, type) + unmatched = setdiff (fieldnames (this.(type)), fieldnames (this.Results)); for namec = unmatched(:)' name = namec{1}; this.UsingDefaults{end+1} = name; this.Results.(name) = this.(type).(name).def; endfor + endfunction function error (this, msg) + where = ""; if (this.FunctionName) where = [this.FunctionName ": "]; endif error ("%s%s", where, msg); + endfunction endmethods
--- a/scripts/miscellaneous/license.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/miscellaneous/license.m Fri Nov 26 20:53:22 2021 -0800 @@ -130,12 +130,14 @@ endfunction function username = get_username () + pw = getpwuid (getuid ()); if (isstruct (pw)) username = pw.name; else username = "octave_user"; endif + endfunction function [features, loaded] = get_all_features ()
--- a/scripts/miscellaneous/memory.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/miscellaneous/memory.m Fri Nov 26 20:53:22 2021 -0800 @@ -232,6 +232,7 @@ endfunction function [status, meminfo] = lmemory () + ## Read pseudo files to gather memory information on Linux ## Read the proc/self/status pseudofile.
--- a/scripts/miscellaneous/methods.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/miscellaneous/methods.m Fri Nov 26 20:53:22 2021 -0800 @@ -44,7 +44,7 @@ ## @seealso{ismethod, properties, fieldnames} ## @end deftypefn -function mtds = methods (obj, opt) +function mtds = methods (obj, fullopt) if (nargin < 1) print_usage (); @@ -53,7 +53,7 @@ havesigs = false; showsigs = false; if (nargin == 2) - if (! strcmp (opt, "-full")) + if (! strcmp (fullopt, "-full")) error ("methods: invalid option"); endif showsigs = true;
--- a/scripts/miscellaneous/private/__publish_html_output__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/miscellaneous/private/__publish_html_output__.m Fri Nov 26 20:53:22 2021 -0800 @@ -115,6 +115,7 @@ endfunction function outstr = do_header (title_str, intro_str, toc_cstr) + mathjax_str = sprintf ("%s\n", '<script type="text/x-mathjax-config">', "MathJax.Hub.Config({", @@ -198,6 +199,7 @@ endfunction function outstr = do_footer (m_source_str) + outstr = sprintf ("%s\n", "", "<footer>", @@ -211,6 +213,7 @@ "-->", "</body>", "</html>"); + endfunction function outstr = do_code (str) @@ -249,19 +252,23 @@ endfunction function outstr = do_bulleted_list (cstr) + outstr = "\n<ul>\n"; for i = 1:numel (cstr) outstr = [outstr, "<li>" cstr{i} "</li>\n"]; endfor outstr = [outstr, "</ul>\n"]; + endfunction function outstr = do_numbered_list (cstr) + outstr = "\n<ol>\n"; for i = 1:numel (cstr) outstr = [outstr, "<li>" cstr{i} "</li>\n"]; endfor outstr = [outstr, "</ol>\n"]; + endfunction function outstr = do_graphic (str) @@ -322,6 +329,7 @@ ## SYNTAX_HIGHLIGHT: A primitive parser to highlight syntax via <span> tags. ## FIXME: Needs to be replaced by a better solution. function outstr = syntax_highlight (str) + str = do_escape_special_chars (str); outstr = ""; placeholder_cstr = {};
--- a/scripts/miscellaneous/private/__publish_latex_output__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/miscellaneous/private/__publish_latex_output__.m Fri Nov 26 20:53:22 2021 -0800 @@ -115,6 +115,7 @@ endfunction function outstr = do_header (title_str, intro_str, toc_cstr) + publish_comment = sprintf ("%s\n", "", "", @@ -137,15 +138,15 @@ '\usepackage[T1]{fontenc}', '\usepackage{lmodern}'); - # "lstlisting" doesn't support multi-byte UTF-8 characters. - # Add substitution rules for some characters (commonly used in languages with - # Latin-based script). - # Set of substitions taken from: - # https://en.wikibooks.org/w/index.php?title=LaTeX/Source_Code_Listings&oldid=3815132#Encoding_issue - # FIXME: Any multi-byte UTF-8 character in a non-section comment without a - # substitution rule will still cause an error. This should be fixed - # more generally, or a way how to work around this limitation should - # be documented. + ## "lstlisting" doesn't support multi-byte UTF-8 characters. + ## Add substitution rules for some characters (commonly used in languages with + ## Latin-based script). + ## Set of substitions taken from: + ## https://en.wikibooks.org/w/index.php?title=LaTeX/Source_Code_Listings&oldid=3815132#Encoding_issue + ## FIXME: Any multi-byte UTF-8 character in a non-section comment without a + ## substitution rule will still cause an error. This should be fixed + ## more generally, or a way how to work around this limitation should + ## be documented. listings_option = sprintf ("%s\n", "", "", @@ -236,19 +237,23 @@ endfunction function outstr = do_bulleted_list (cstr) + outstr = ["\n" '\begin{itemize}' "\n"]; for i = 1:numel (cstr) outstr = [outstr, '\item ' cstr{i} "\n"]; endfor outstr = [outstr, '\end{itemize}' "\n"]; + endfunction function outstr = do_numbered_list (cstr) + outstr = ["\n" '\begin{enumerate}' "\n"]; for i = 1:numel (cstr) outstr = [outstr, '\item ' cstr{i} "\n"]; endfor outstr = [outstr, "\\end{enumerate}\n"]; + endfunction function outstr = do_graphic (str) @@ -303,6 +308,7 @@ endfunction function str = do_escape_special_chars (str) + ## Escape \, {, }, &, %, #, _, ~, ^, <, > str = regexprep (str, '\\', "\\ensuremath{\\backslash}"); str = regexprep (str, '(?<!\\)(\{|\}|&|%|#|_)', '\\$1'); @@ -312,4 +318,5 @@ str = regexprep (str, '(?<!\\)\^', "\\^{}"); str = regexprep (str, '(?<!\\)<', "\\ensuremath{<}"); str = regexprep (str, '(?<!\\)>', "\\ensuremath{>}"); + endfunction
--- a/scripts/miscellaneous/publish.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/miscellaneous/publish.m Fri Nov 26 20:53:22 2021 -0800 @@ -409,6 +409,7 @@ function doc = parse_m_source (doc) + ## PARSE_M_SOURCE First parsing level ## This function extracts the overall structure (paragraphs and code ## sections) given in doc.m_source. @@ -434,6 +435,7 @@ ## Checks line to have N "%" or "#" lines ## followed either by a space or end of string function r = is_publish_markup (cstr, N) + str = char (cstr); r = any (strncmp (str, {"%%%", "##"}, N)); @@ -571,6 +573,7 @@ function p_content = parse_paragraph_content (content) + ## PARSE_PARAGRAPH_CONTENT second parsing level ## ## Parses the content of a paragraph (without potential title) and @@ -715,8 +718,8 @@ function m_source = read_file_to_cellstr (file) + ## READ_FILE_TO_CELLSTR reads a given file line by line into a cellstring - fid = fopen (file, "r"); i = 0; do @@ -729,8 +732,8 @@ function ofile = create_output (doc, options) + ## CREATE_OUTPUT creates the desired output file - formatter = []; switch (options.format) case "html" @@ -778,9 +781,9 @@ function toc_cstr = get_toc (cstr, formatter) + ## GET_TOC extracts the table of contents from a cellstring (e.g., doc.body) ## with each section headline as a cell in a returned cellstring. - toc_cstr = cell (); for i = 1:numel (cstr) if (strcmp (cstr{i}.type, "section")) @@ -792,13 +795,13 @@ function str = format_output (cstr, formatter, options) + ## FORMAT_OUTPUT steps through all blocks (doc.intro or doc.body) in cstr and ## produces a single result string with the source code in the desired output ## format. ## ## formatter has the only knowledge how to enforce the target format ## and produces for each block the necessary target format source string. - str = ""; for i = 1:numel (cstr) switch (cstr{i}.type) @@ -825,6 +828,7 @@ function str = format_text (str, formatter) + ## FORMAT_TEXT formats inline formats in strings. ## These are: links, block/inline math, bold, italic, monospaced, (TM), (R) @@ -957,6 +961,7 @@ function doc = eval_code (doc, options) + ## EVAL_CODE Third level parsing ## ## Generates the output of the script code and takes care of generated @@ -1060,6 +1065,7 @@ function cstr = eval_code_helper (__code__) + ## EVAL_CODE_HELPER evaluates a given string with Octave code in an extra ## temporary context and returns a cellstring with the eval output. @@ -1077,6 +1083,7 @@ function cstr = eval_context (op) + ## EVAL_CONTEXT temporary evaluation context. persistent ctext
--- a/scripts/ode/ode15s.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/ode/ode15s.m Fri Nov 26 20:53:22 2021 -0800 @@ -368,6 +368,7 @@ function [jac, jact] = wrapjacfun (t, y, yp, Jac, Mass, havetimedep, havejacfun) + if (havejacfun) jac = - Jac (t, y); else
--- a/scripts/optimization/fminbnd.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/optimization/fminbnd.m Fri Nov 26 20:53:22 2021 -0800 @@ -276,6 +276,7 @@ ## A helper function that evaluates a function and checks for bad results. function fx = guarded_eval (fun, x) + fx = fun (x); fx = fx(1); if (! isreal (fx)) @@ -283,6 +284,7 @@ elseif (isnan (fx)) error ("Octave:fmindbnd:isnan", "fminbnd: NaN value encountered"); endif + endfunction ## A hack for printing a formatted table @@ -298,6 +300,7 @@ ## Print either a success termination message or bad news function print_exit_msg (info, opt=struct ()) + printf (""); switch (info) case 1 @@ -313,6 +316,7 @@ error ("fminbnd: internal error, info return code was %d", info); endswitch printf ("\n"); + endfunction
--- a/scripts/optimization/fzero.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/optimization/fzero.m Fri Nov 26 20:53:22 2021 -0800 @@ -439,6 +439,7 @@ ## A helper function that evaluates a function and checks for bad results. function fx = guarded_eval (fun, x) + fx = fun (x); fx = fx(1); if (! isreal (fx)) @@ -446,6 +447,7 @@ elseif (isnan (fx)) error ("Octave:fzero:isnan", "fzero: NaN value encountered"); endif + endfunction
--- a/scripts/pkg/private/configure_make.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/pkg/private/configure_make.m Fri Nov 26 20:53:22 2021 -0800 @@ -187,6 +187,7 @@ endfunction function body = __extract_test_code__ (nm) + ## Collect all BIST lines starting %! from the file named nm ## and return them as a single \n-delimited string. fid = fopen (nm, "rt"); @@ -199,4 +200,5 @@ endwhile fclose (fid); endif + endfunction
--- a/scripts/pkg/private/get_description.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/pkg/private/get_description.m Fri Nov 26 20:53:22 2021 -0800 @@ -144,6 +144,7 @@ endfunction function valid = is_valid_pkg_version_string (str) + ## We are limiting ourselves to this set of characters because the ## version will appear on the filepath. The portable character, according to ## http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_278 @@ -162,4 +163,5 @@ ## able to co-exist in the same directory, e.g., during package install or ## in a flat level package repository. valid = numel (regexp (str, '[^0-9a-zA-Z\.\+\-\~]')) == 0; + endfunction
--- a/scripts/pkg/private/get_forge_pkg.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/pkg/private/get_forge_pkg.m Fri Nov 26 20:53:22 2021 -0800 @@ -77,6 +77,7 @@ endif ## Try a simplistic method to determine similar names. function d = fdist (x) + len1 = length (name); len2 = length (x); if (len1 <= len2) @@ -86,7 +87,9 @@ d = sum (abs (tolower (name(1:len2)) - tolower (x(1:len2)))) ... + (len1 - len2)*23; endif + endfunction + dist = cellfun ("fdist", t); [~, i] = min (dist); error ("get_forge_pkg: package not found: ""%s"". Did you mean ""%s""?", ...
--- a/scripts/plot/appearance/annotation.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/appearance/annotation.m Fri Nov 26 20:53:22 2021 -0800 @@ -1132,6 +1132,7 @@ endfunction function XY = textcoordinates (hte, pos) + ## Get the "tight" extent of the text object in points units textpos = get (hte, "position"); rot = get (hte, "rotation"); @@ -1207,6 +1208,7 @@ endfunction function pos = convertposition (h, from, to) + ## FIXME: handle "characters" units pos = get (h, "position");
--- a/scripts/plot/appearance/camlookat.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/appearance/camlookat.m Fri Nov 26 20:53:22 2021 -0800 @@ -52,17 +52,17 @@ ## @end deftypefn -function camlookat (hh) +function camlookat (h) if (nargin == 0) hax = gca (); - hh = get (hax, "children"); + h = get (hax, "children"); elseif (nargin == 1) - if (isaxes (hh)) - hax = hh; - hh = get (hax, "children"); - elseif (all (ishghandle (hh))) - hax = ancestor (hh, "axes"); + if (isaxes (h)) + hax = h; + h = get (hax, "children"); + elseif (all (ishghandle (h))) + hax = ancestor (h, "axes"); if (numel (hax) > 1) hax = unique ([hax{:}]); endif @@ -72,24 +72,24 @@ endif endif - if (isempty (hh)) + if (isempty (h)) return; endif x0 = x1 = y0 = y1 = z0 = z1 = []; - for i = 1:numel (hh) - h = hh(i); + for i = 1:numel (h) + hi = h(i); - if (! ishghandle (h)) + if (! ishghandle (hi)) error ("camlookat: Inputs must be handles"); endif - x0_ = min (get (h, "xdata")(:)); - x1_ = max (get (h, "xdata")(:)); - y0_ = min (get (h, "ydata")(:)); - y1_ = max (get (h, "ydata")(:)); - z0_ = min (get (h, "zdata")(:)); - z1_ = max (get (h, "zdata")(:)); + x0_ = min (get (hi, "xdata")(:)); + x1_ = max (get (hi, "xdata")(:)); + y0_ = min (get (hi, "ydata")(:)); + y1_ = max (get (hi, "ydata")(:)); + z0_ = min (get (hi, "zdata")(:)); + z1_ = max (get (hi, "zdata")(:)); if (i == 1) x0 = x0_; x1 = x1_;
--- a/scripts/plot/appearance/legend.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/appearance/legend.m Fri Nov 26 20:53:22 2021 -0800 @@ -898,6 +898,7 @@ endfunction function update_layout_cb (hl, ~, update_item = false) + updating = getappdata (hl, "__updating_layout__"); if (! isempty (updating) && updating) return; @@ -1184,12 +1185,14 @@ endfunction function safe_property_link (h1, h2, props) + for ii = 1:numel (props) prop = props{ii}; lsn = {h1, prop, @(h, ~) set (h2, prop, get (h, prop))}; addlistener (lsn{:}); addlistener (h2, "beingdeleted", @(~, ~) dellistener (lsn{:})); endfor + endfunction function update_displayname_cb (h, ~, hl) @@ -1368,6 +1371,7 @@ endfunction function update_icon_position (hicon, xdata, ydata) + creator = getappdata (hicon, "__creator__"); switch (creator) case "line"
--- a/scripts/plot/appearance/private/__gnuplot_legend__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/appearance/private/__gnuplot_legend__.m Fri Nov 26 20:53:22 2021 -0800 @@ -1253,6 +1253,7 @@ ## Axes to which legend was attached is being deleted/reset. Delete legend. function cb_axes_deleted (~, ~, ca, hlegend) + if (isaxes (hlegend)) if (strcmp (get (ca(1), "beingdeleted"), "on")) ## Axes are being deleted. Disable call to cb_restore_axes. @@ -1260,6 +1261,7 @@ endif delete (hlegend); endif + endfunction ## Restore position of axes object when legend is deleted.
--- a/scripts/plot/draw/bar.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/bar.m Fri Nov 26 20:53:22 2021 -0800 @@ -117,6 +117,7 @@ [varargout{:}] = __bar__ ("bar", true, varargin{:}); endfunction + %!demo %! clf; %! y = rand (11, 1);
--- a/scripts/plot/draw/colorbar.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/colorbar.m Fri Nov 26 20:53:22 2021 -0800 @@ -394,6 +394,7 @@ ## Axes to which colorbar was attached is being deleted/reset. Delete colorbar. function cb_axes_deleted (~, ~, hax, hcb) + if (isaxes (hcb)) if (strcmp (get (hax, "beingdeleted"), "on")) ## Axes are being deleted. Disable call to cb_restore_axes. @@ -401,6 +402,7 @@ endif delete (hcb); endif + endfunction ## Error on attempt to set logscale on colorbar axes
--- a/scripts/plot/draw/fill3.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/fill3.m Fri Nov 26 20:53:22 2021 -0800 @@ -118,13 +118,13 @@ num_cols = max ([columns(x), columns(y), columns(z)]); if (iscolumn (x)) x = repmat (x, [1, num_cols]); - end + endif if (iscolumn (y)) y = repmat (y, [1, num_cols]); - end + endif if (iscolumn (z)) z = repmat (z, [1, num_cols]); - end + endif endif if (isrow (x))
--- a/scripts/plot/draw/isosurface.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/isosurface.m Fri Nov 26 20:53:22 2021 -0800 @@ -226,6 +226,7 @@ endfunction function [x, y, z, v, isoval, colors, noshare, verbose] = __get_check_isosurface_args__ (nout, varargin) + ## get arguments from input and check values x = y = z = []; v = [];
--- a/scripts/plot/draw/plotyy.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/plotyy.m Fri Nov 26 20:53:22 2021 -0800 @@ -76,7 +76,7 @@ ## Check if first argument is axes handle(s). hax = []; - if numel (varargin) > 0 + if (numel (varargin) > 0) if (isscalar (varargin{1})) [hax, varargin] = __plt_get_axis_arg__ ("plotyy", varargin{:}); elseif (numel (varargin{1}) == 2 && all (isaxes (varargin{1}))) @@ -251,6 +251,7 @@ function update_prop (h, ~, ax2, prop) persistent recursion = false; + ## Don't allow recursion if (! recursion && all (ishghandle ([h, ax2]))) unwind_protect
--- a/scripts/plot/draw/polar.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/polar.m Fri Nov 26 20:53:22 2021 -0800 @@ -165,6 +165,7 @@ endfunction function rtick = __calc_rtick__ (hax, maxr) + ## FIXME: workaround: calculate r(ho)tick from xtick ## It would be better to just calculate the values, ## but that code is deep in the C++ for the plot engines.
--- a/scripts/plot/draw/private/__bar__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/private/__bar__.m Fri Nov 26 20:53:22 2021 -0800 @@ -412,6 +412,7 @@ endfunction function update_basevalue_logscale (hax, ~, hg) + if (strcmp (get (hax, "yscale"), "log")) warning ("off", "Octave:negative-data-log-axis", "local"); if (get (hg, "basevalue") == 0) @@ -422,6 +423,7 @@ set (hg, "basevalue", 0); endif endif + endfunction function update_baseline (h, ~)
--- a/scripts/plot/draw/private/__ezplot__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/private/__ezplot__.m Fri Nov 26 20:53:22 2021 -0800 @@ -478,6 +478,7 @@ ## Eliminate bad data (complex values, infinities, singularities) function x = __eliminate_sing__ (x) + if (iscomplex (x)) x(imag (x) != 0) = NaN; endif @@ -485,6 +486,7 @@ ## High rates of curvature are treated as singularities threshold = 0.2 * (max (x(:)) - min (x(:))); x(abs (del2 (x)) > threshold) = NaN; + endfunction ## Find: 1) range of function where there are not NaN values,
--- a/scripts/plot/draw/private/__patch__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/private/__patch__.m Fri Nov 26 20:53:22 2021 -0800 @@ -183,6 +183,7 @@ endfunction function retval = iscolorspec (arg) + retval = false; if (ischar (arg)) persistent colors = {"y", "yellow", "r", "red", "m", "magenta", ... @@ -192,4 +193,5 @@ retval = true; endif endif + endfunction
--- a/scripts/plot/draw/private/__pie__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/private/__pie__.m Fri Nov 26 20:53:22 2021 -0800 @@ -163,6 +163,7 @@ endfunction function update_text_pos (all_handles) + ## Text objects in the foreground should be at the base level. ## Text objects in the background should be at the top level. ## Text objects on the right side should be aligned to the right
--- a/scripts/plot/draw/private/__plt__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/private/__plt__.m Fri Nov 26 20:53:22 2021 -0800 @@ -157,6 +157,7 @@ function [hlgnd, tlgnd, setlgnd] = __plt_key__ (hp, options, hlgnd, tlgnd, setlgnd) + n = numel (hp); if (numel (options) == 1) options = repmat (options(:), n, 1);
--- a/scripts/plot/draw/private/__scatter__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/private/__scatter__.m Fri Nov 26 20:53:22 2021 -0800 @@ -199,9 +199,9 @@ endfunction - +## Convert a color code to the corresponding RGB values function rgb = str2rgb (str) - ## Convert a color code to the corresponding RGB values + rgb = []; switch (str) @@ -221,6 +221,6 @@ rgb = [0, 1, 1]; case 'w' rgb = [1, 1, 1]; -endswitch + endswitch endfunction
--- a/scripts/plot/draw/smooth3.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/smooth3.m Fri Nov 26 20:53:22 2021 -0800 @@ -142,8 +142,8 @@ endfunction function gaussian3 = __smooth3_gaussian3__ (sz, std_dev) + ## trivariate non-correlated Gaussian distribution function - x = (-(sz(2)-1)/2:(sz(2)-1)/2) / std_dev(2); y = (-(sz(1)-1)/2:(sz(1)-1)/2) / std_dev(1); z = (-(sz(3)-1)/2:(sz(3)-1)/2) / std_dev(3);
--- a/scripts/plot/draw/stemleaf.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/draw/stemleaf.m Fri Nov 26 20:53:22 2021 -0800 @@ -81,6 +81,7 @@ ## @end deftypefn function plotstr = stemleaf (x, caption, stem_sz) + ## Compute and display a stem and leaf plot of the vector x. The x ## vector is converted to integer by x = fix(x). If an output argument ## is provided, the plot is returned as an array of strings. The
--- a/scripts/plot/util/__gnuplot_drawnow__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/util/__gnuplot_drawnow__.m Fri Nov 26 20:53:22 2021 -0800 @@ -112,6 +112,7 @@ endfunction function enhanced = gnuplot_set_term (plot_stream, new_stream, h, term, file) + ## Generate the gnuplot "set terminal <term> ..." command. ## When "term" originates from print.m, it may include other options. if (nargin < 4) @@ -363,15 +364,18 @@ endfunction function [term, opts] = gnuplot_trim_term (string) + ## Extract the terminal type and terminal options (from print.m) string = strtrim (string); [term, opts] = strtok (string, ' '); if (! isempty (opts)) opts(1) = ""; # trim extra space from strtok endif + endfunction function have_enhanced = gnuplot_is_enhanced_term (plot_stream, term) + ## Don't include pstex, pslatex or epslatex here as the TeX commands ## should not be interpreted in that case. persistent enhanced_terminals = {"aqua", "canvas", "dumb", "emf", "gif", ... @@ -384,6 +388,7 @@ term = gnuplot_default_term (plot_stream); endif have_enhanced = any (strcmp (term, enhanced_terminals)); + endfunction function ret = output_to_screen (term)
--- a/scripts/plot/util/print.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/util/print.m Fri Nov 26 20:53:22 2021 -0800 @@ -808,6 +808,7 @@ endfunction + %!error <a graphics handle> %! hf = figure ("visible", "off"); %! unwind_protect @@ -821,6 +822,7 @@ %! end_unwind_protect function cmd = epstool (opts, filein, fileout) + ## As epstool does not work with pipes, a subshell is used to ## permit piping. Since this solution does not work with the DOS ## command shell, the -tight and -preview options are disabled if
--- a/scripts/plot/util/printd.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/util/printd.m Fri Nov 26 20:53:22 2021 -0800 @@ -39,6 +39,7 @@ ## @end deftypefn function pr_out = printd (obj, filename) + ## Convert any object acceptable to disp() into various display formats. ## obj is the input object. ## filename is the output file (with required suffix).
--- a/scripts/plot/util/private/__add_default_menu__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/util/private/__add_default_menu__.m Fri Nov 26 20:53:22 2021 -0800 @@ -165,6 +165,7 @@ endfunction function toggle_visibility_cb (hf, ~, hmenu, htb) + menu_state = ifelse (strcmp (get (hf, "menubar"), "figure"), "on", "off"); toolbar_state = "on"; if (strcmp (get (hf, "toolbar"), "auto")) @@ -175,6 +176,7 @@ set (hmenu, "visible", menu_state); set (htb, "visible", toolbar_state); + endfunction function open_cb (~, ~) @@ -187,6 +189,7 @@ endfunction function save_cb (h, ~, action) + hfig = gcbf (); fname = get (hfig, "filename"); @@ -199,9 +202,11 @@ elseif (strcmp (action, "saveas")) __save_as__ (hfig, fname); endif + endfunction function __save_as__ (hf, fname = "") + if (! isempty (fname)) def = fname; else @@ -387,6 +392,7 @@ endfunction function axes_cb (h, ~) + hax = get (gcbf (), "currentaxes"); if (! isempty (hax)) if (strcmp (get (hax, "visible"), "on")) @@ -395,9 +401,11 @@ set (hax, "visible", "on"); endif endif + endfunction function grid_cb (h, ~) + hax = get (gcbf (), "currentaxes"); if (! isempty (hax)) if (strcmp (get (hax, "xgrid"), "on") && strcmp (get (hax, "ygrid"), "on")) @@ -406,6 +414,7 @@ grid (hax, "on"); endif endif + endfunction function auto_cb (h, ~)
--- a/scripts/plot/util/private/__gnuplot_draw_axes__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/util/private/__gnuplot_draw_axes__.m Fri Nov 26 20:53:22 2021 -0800 @@ -1779,6 +1779,7 @@ endfunction function spacing_spec = create_spacingspec (f, s, gp_term) + ## The gnuplot default font size is 10, and default spacing is 1.25. ## gnuplot has a concept of a figure global font, and sizes everything ## appropriate to that, including the legend spacing. @@ -1863,6 +1864,7 @@ tick ('z', obj.zcolor, obj.tickdir, mirrorstr); function tick (axischar, color, tickdir, mirrorstr) + if (isnumeric (color)) if (length (color) == 3) colorspec = sprintf ('rgb "#%02x%02x%02x"', round (255*color)); @@ -1874,12 +1876,14 @@ endif fprintf (plot_stream, "set %ctics %s %s textcolor %s\n", axischar, tickdir, mirrorstr, colorspec); + endfunction endfunction function [style, ltidx] = do_linestyle_command (obj, linecolor, idx, plot_stream) + idx = idx + 8; style = {}; ltidx = []; @@ -2141,6 +2145,7 @@ endfunction function __gnuplot_write_data__ (plot_stream, data, nd, parametric, cdata) + ## DATA is already transposed. ## Convert NA elements to normal NaN values because fprintf writes
--- a/scripts/plot/util/private/__gnuplot_print__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/util/private/__gnuplot_print__.m Fri Nov 26 20:53:22 2021 -0800 @@ -244,6 +244,7 @@ function f = font_spec (opts, varargin) + for n = 1:2:numel (varargin) opts.(varargin{n}) = varargin{n+1}; endfor
--- a/scripts/plot/util/private/__print_parse_opts__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/util/private/__print_parse_opts__.m Fri Nov 26 20:53:22 2021 -0800 @@ -763,6 +763,7 @@ endfunction function device_list = gs_device_list () + ## Graphics formats/languages, not printers. device_list = {"bmp16"; "bmp16m"; "bmp256"; "bmp32b"; "bmpgray"; ... "epswrite"; "eps2write"; "jpeg"; "jpegcymk"; "jpeggray";
--- a/scripts/plot/util/struct2hdl.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/plot/util/struct2hdl.m Fri Nov 26 20:53:22 2021 -0800 @@ -439,6 +439,7 @@ endfunction function [h, sout, pout] = createhg (s, p, par, hilev) + ## Here we infer from properties the type of hggroup we should build ## an call corresponding high level functions ## We manually set "hold on" to avoid next hggroup be deleted
--- a/scripts/profiler/profexport.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/profiler/profexport.m Fri Nov 26 20:53:22 2021 -0800 @@ -276,12 +276,14 @@ ## General helper functions. function __writeToFile (file, str) + fid = fopen (file, "w"); if (fid < 0) error ("profexport: failed to open '%s' for writing", file); endif fputs (fid, str); fclose (fid); + endfunction function fn = __dataFilename (name)
--- a/scripts/profiler/profile.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/profiler/profile.m Fri Nov 26 20:53:22 2021 -0800 @@ -65,14 +65,13 @@ ## @end table ## @end deftypefn -## Built-in profiler. -function retval = profile (option) +function retval = profile (arg) if (nargin < 1) print_usage (); endif - switch (option) + switch (arg) case "on" __profiler_enable__ (true); @@ -99,7 +98,7 @@ retval = struct ("FunctionTable", flat, "Hierarchical", tree); otherwise - warning ("profile: Unrecognized option '%s'", option); + warning ("profile: Unrecognized option '%s'", arg); print_usage (); endswitch
--- a/scripts/signal/movfun.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/signal/movfun.m Fri Nov 26 20:53:22 2021 -0800 @@ -362,17 +362,20 @@ ## 'y' values outside window are replaced by value of 'x' at the window ## boundary. function y = same_bc (fcn, x, idxp, win, ~, ~) + idx = idxp + win; idx(idx < 1) = 1; N = length (x); idx(idx > N) = N; y = fcn (x(idx)); + endfunction ## Apply "periodic" boundary conditions ## Window wraps around. Window values outside data array are replaced with ## data from the other end of the array. function y = periodic_bc (fcn, x, idxp, win, ~, ~) + N = length (x); idx = idxp + win; tf = idx < 1; @@ -380,6 +383,7 @@ tf = idx > N; idx(tf) = idx(tf) - N; y = fcn (x(idx)); + endfunction
--- a/scripts/sparse/sprandsym.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/sparse/sprandsym.m Fri Nov 26 20:53:22 2021 -0800 @@ -91,6 +91,7 @@ endfunction function r = pick_rand_diag (n, k) + ## Pick a random number R of entries for the diagonal of a sparse NxN ## symmetric square matrix with exactly K nonzero entries, ensuring ## that this R is chosen uniformly over all such matrices.
--- a/scripts/specfun/betaincinv.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/specfun/betaincinv.m Fri Nov 26 20:53:22 2021 -0800 @@ -149,7 +149,7 @@ if (! isempty (idx)) x_i(idx) = (a(idx) - 1) ./ (a(idx) + b(idx) - 2); y_i(idx) = betainc (x_i(idx), a(idx), b(idx)); - end + endif ## Converge outwards tmpidx = find (a(idx) > 1);
--- a/scripts/specfun/factor.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/specfun/factor.m Fri Nov 26 20:53:22 2021 -0800 @@ -136,7 +136,7 @@ ## ## are relevant and slow down significantly for large values of q. else - # For sufficiently large q, go up to the 5th root of q for now. + ## For sufficiently large q, go up to the 5th root of q for now. smallprimes = primes (feval (cls, q^0.2)); endif @@ -181,6 +181,7 @@ endfunction function [pf, q] = reducefactors (qin, pfin, divisors) + pf = pfin; q = qin; ## The following line is a few milliseconds faster than @@ -198,6 +199,7 @@ q /= pp; endwhile endfor + endfunction
--- a/scripts/specfun/nchoosek.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/specfun/nchoosek.m Fri Nov 26 20:53:22 2021 -0800 @@ -128,7 +128,7 @@ denom = (1:k/2) .* (k:-1:k/2+1) / 2; endif - # Remove common factors from numerator and denominator + ## Remove common factors from numerator and denominator do for i = numel (denom):-1:1 factors = gcd (denom(i), numer); @@ -180,7 +180,7 @@ %!assert (nchoosek (1:5, 3), %! [1:3;1,2,4;1,2,5;1,3,4;1,3,5;1,4,5;2:4;2,3,5;2,4,5;3:5]) -# Test basic behavior for various input types +## Test basic behavior for various input types %!assert (nchoosek ('a':'b', 2), 'ab') %!assert (nchoosek ("a":"b", 2), "ab") %!assert (nchoosek ({1,2}, 2), {1,2}) @@ -190,7 +190,7 @@ %! assert (nchoosek (s, 1), s(:)); %! assert (nchoosek (s, 2), s); -# Verify Matlab compatibility of return sizes & types +## Verify Matlab compatibility of return sizes & types %!test %! x = nchoosek (1:2, 0); %! assert (size (x), [1, 0]);
--- a/scripts/special-matrix/gallery.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/special-matrix/gallery.m Fri Nov 26 20:53:22 2021 -0800 @@ -511,6 +511,7 @@ endfunction function C = cauchy (x, y) + ## CAUCHY Cauchy matrix. ## C = CAUCHY(X, Y), where X, Y are N-vectors, is the N-by-N matrix ## with C(i,j) = 1/(X(i)+Y(j)). By default, Y = X. @@ -563,9 +564,11 @@ endif C = 1 ./ (x + y.'); + endfunction function C = chebspec (n, k = 0) + ## CHEBSPEC Chebyshev spectral differentiation matrix. ## C = CHEBSPEC(N, K) is a Chebyshev spectral differentiation ## matrix of order N. K = 0 (the default) or 1. @@ -630,9 +633,11 @@ if (k == 1) C = C(2:n+1,2:n+1); endif + endfunction function C = chebvand (m, p) + ## CHEBVAND Vandermonde-like matrix for the Chebyshev polynomials. ## C = CHEBVAND(P), where P is a vector, produces the (primal) ## Chebyshev Vandermonde matrix based on the points P, @@ -682,9 +687,11 @@ C(i,:) = 2.*p.*C(i-1,:) - C(i-2,:); endfor endif + endfunction function A = chow (n, alpha = 1, delta = 0) + ## CHOW Chow matrix - a singular Toeplitz lower Hessenberg matrix. ## A = CHOW(N, ALPHA, DELTA) is a Toeplitz lower Hessenberg matrix ## A = H(ALPHA) + DELTA*EYE, where H(i,j) = ALPHA^(i-j+1). @@ -709,9 +716,11 @@ endif A = toeplitz (alpha.^(1:n), [alpha 1 zeros(1, n-2)]) + delta * eye (n); + endfunction function C = circul (v) + ## CIRCUL Circulant matrix. ## C = CIRCUL(V) is the circulant matrix whose first row is V. ## (A circulant matrix has the property that each row is obtained @@ -744,9 +753,11 @@ v = v(:).'; # Make sure v is a row vector C = toeplitz ([v(1) v(n:-1:2)], v); + endfunction function A = clement (n, k = 0) + ## CLEMENT Clement matrix - tridiagonal with zero diagonal entries. ## CLEMENT(N, K) is a tridiagonal matrix with zero diagonal entries ## and known eigenvalues. It is singular if N is odd. About 64 @@ -791,9 +802,11 @@ else error ("gallery: K must have a value of 0 or 1 for clement matrix"); endif + endfunction function C = compar (A, k = 0) + ## COMP Comparison matrices. ## COMP(A) is DIAG(B) - TRIL(B,-1) - TRIU(B,1), where B = ABS(A). ## COMP(A, 1) is A with each diagonal element replaced by its @@ -846,6 +859,7 @@ endfunction function A = condex (n, k = 4, theta = 100) + ## CONDEX 'Counterexamples' to matrix condition number estimators. ## CONDEX(N, K, THETA) is a 'counterexample' matrix to a condition ## estimator. It has order N and scalar parameter THETA (default 100). @@ -915,9 +929,11 @@ A(i,i) = 1; endfor endif + endfunction function A = cycol (n, k = max (round (n(end)/4), 1)) + ## CYCOL Matrix whose columns repeat cyclically. ## A = CYCOL([M N], K) is an M-by-N matrix of the form A = B(1:M,1:N) ## where B = [C C C...] and C = RANDN(M, K). Thus A's columns repeat @@ -945,9 +961,11 @@ A = [A A(:,1:k)]; endfor A = A(:,1:n); + endfunction function [c, d, e] = dorr (n, theta = 0.01) + ## DORR Dorr matrix - diagonally dominant, ill conditioned, tridiagonal. ## [C, D, E] = DORR(N, THETA) returns the vectors defining a row diagonally ## dominant, tridiagonal M-matrix that is ill conditioned for small @@ -996,9 +1014,11 @@ if (nargout <= 1) c = tridiag (c, d, e); endif + endfunction function A = dramadah (n, k = 1) + ## DRAMADAH A (0,1) matrix whose inverse has large integer entries. ## An anti-Hadamard matrix A is a matrix with elements 0 or 1 for ## which MU(A) := NORM(INV(A),'FRO') is maximal. @@ -1063,9 +1083,11 @@ otherwise error ("gallery: unknown K '%d' for dramadah matrix", k); endswitch + endfunction function A = fiedler (c) + ## FIEDLER Fiedler matrix - symmetric. ## FIEDLER(C), where C is an n-vector, is the n-by-n symmetric ## matrix with elements ABS(C(i)-C(j)). @@ -1104,9 +1126,11 @@ c = c(:).'; # Ensure c is a row vector. A = abs (c - c.'); + endfunction function A = forsythe (n, alpha = sqrt (eps), lambda = 0) + ## FORSYTHE Forsythe matrix - a perturbed Jordan block. ## FORSYTHE(N, ALPHA, LAMBDA) is the N-by-N matrix equal to ## JORDBLOC(N, LAMBDA) except it has an ALPHA in the (N,1) position. @@ -1126,9 +1150,11 @@ A = jordbloc (n, lambda); A(n,1) = alpha; + endfunction function F = frank (n, k = 0) + ## FRANK Frank matrix---ill conditioned eigenvalues. ## F = FRANK(N, K) is the Frank matrix of order N. It is upper ## Hessenberg with determinant 1. K = 0 is the default; if K = 1 the @@ -1183,6 +1209,7 @@ otherwise error ("gallery: K must have a value of 0 or 1 for frank matrix"); endswitch + endfunction function c = gcdmat (n) @@ -1192,9 +1219,11 @@ error ("gallery: N must be an integer for gcdmat matrix"); endif c = gcd (repmat ((1:n)', [1 n]), repmat (1:n, [n 1])); + endfunction function A = gearmat (n, i = n, j = -n) + ## NOTE: this function was named gearm in the original Test Matrix Toolbox ## GEARMAT Gear matrix. ## A = GEARMAT(N,I,J) is the N-by-N matrix with ones on the sub- and @@ -1225,9 +1254,11 @@ A = diag (ones (n-1, 1), -1) + diag (ones (n-1, 1), 1); A(1, abs (i)) = sign (i); A(n, n+1 - abs (j)) = sign (j); + endfunction function G = grcar (n, k = 3) + ## GRCAR Grcar matrix - a Toeplitz matrix with sensitive eigenvalues. ## GRCAR(N, K) is an N-by-N matrix with -1s on the ## subdiagonal, 1s on the diagonal, and K superdiagonals of 1s. @@ -1251,9 +1282,11 @@ endif G = tril (triu (ones (n)), k) - diag (ones (n-1, 1), -1); + endfunction function A = hanowa (n, d = -1) + ## HANOWA A matrix whose eigenvalues lie on a vertical line in the complex plane. ## HANOWA(N, d) is the N-by-N block 2x2 matrix (thus N = 2M must be even) ## [d*EYE(M) -DIAG(1:M) @@ -1279,9 +1312,11 @@ m = n/2; A = [ d*eye(m) -diag(1:m) diag(1:m) d*eye(m) ]; + endfunction function [v, beta] = house (x) + ## HOUSE Householder matrix. ## If [v, beta] = HOUSE(x) then H = EYE - beta*v*v' is a Householder ## matrix such that Hx = -sign(x(1))*norm(x)*e_1. @@ -1326,6 +1361,7 @@ ## beta = 1/(abs (s) * (abs (s) +abs(x(1)) would guarantee beta real. ## But beta as above can be non-real (due to rounding) only when x is complex. endif + endfunction function A = integerdata (varargin) @@ -1371,6 +1407,7 @@ endfunction function A = invhess (x, y) + ## INVHESS Inverse of an upper Hessenberg matrix. ## INVHESS(X, Y), where X is an N-vector and Y an N-1 vector, ## is the matrix whose lower triangle agrees with that of @@ -1422,9 +1459,11 @@ for j = 2:n A(1:j-1,j) = y(1:j-1); endfor + endfunction function A = invol (n) + ## INVOL An involutory matrix. ## A = INVOL(N) is an N-by-N involutory (A*A = EYE(N)) and ## ill-conditioned matrix. @@ -1451,9 +1490,11 @@ d = -(n+i)*(n-i)*d/(i*i); A(i+1,:) = d * A(i+1,:); endfor + endfunction function [A, detA] = ipjfact (n, k = 0) + ## IPJFACT A Hankel matrix with factorial elements. ## A = IPJFACT(N, K) is the matrix with ## A(i,j) = (i+j)! (K = 0, default) @@ -1512,9 +1553,11 @@ detA = d; endif + endfunction function J = jordbloc (n, lambda = 1) + ## JORDBLOC Jordan block. ## JORDBLOC(N, LAMBDA) is the N-by-N Jordan block with eigenvalue ## LAMBDA. LAMBDA = 1 is the default. @@ -1528,9 +1571,11 @@ endif J = lambda * eye (n) + diag (ones (n-1, 1), 1); + endfunction function U = kahan (n, theta = 1.2, pert = 25) + ## KAHAN Kahan matrix - upper trapezoidal. ## KAHAN(N, THETA) is an upper trapezoidal matrix ## that has some interesting properties regarding estimation of @@ -1581,9 +1626,11 @@ else U = U(1:r,:); # Reduce to an r-by-n matrix endif + endfunction function A = kms (n, rho = 0.5) + ## KMS Kac-Murdock-Szego Toeplitz matrix. ## A = KMS(N, RHO) is the N-by-N Kac-Murdock-Szego Toeplitz matrix with ## A(i,j) = RHO^(ABS((i-j))) (for real RHO). @@ -1616,9 +1663,11 @@ if (imag (rho)) A = conj (tril (A,-1)) + triu (A); endif + endfunction function B = krylov (A, x, j) + ## KRYLOV Krylov matrix. ## KRYLOV(A, x, j) is the Krylov matrix ## [x, Ax, A^2x, ..., A^(j-1)x], @@ -1659,9 +1708,11 @@ for i = 2:j B(:,i) = A*B(:,i-1); endfor + endfunction function A = lauchli (n, mu = sqrt (eps)) + ## LAUCHLI Lauchli matrix - rectangular. ## LAUCHLI(N, MU) is the (N+1)-by-N matrix [ONES(1,N); MU*EYE(N))]. ## It is a well-known example in least squares and other problems @@ -1682,9 +1733,11 @@ A = [ones(1, n) mu*eye(n) ]; + endfunction function A = lehmer (n) + ## LEHMER Lehmer matrix - symmetric positive definite. ## A = LEHMER(N) is the symmetric positive definite N-by-N matrix with ## A(i,j) = i/j for j >= i. @@ -1709,9 +1762,11 @@ A = ones (n, 1) * (1:n); A = A./A'; A = tril (A) + tril (A, -1)'; + endfunction function T = lesp (n) + ## LESP A tridiagonal matrix with real, sensitive eigenvalues. ## LESP(N) is an N-by-N matrix whose eigenvalues are real and smoothly ## distributed in the interval approximately [-2*N-3.5, -4.5]. @@ -1739,9 +1794,11 @@ x = 2:n; T = full (tridiag (ones (size (x)) ./x, -(2*[x n+1]+1), x)); + endfunction function A = lotkin (n) + ## LOTKIN Lotkin matrix. ## A = LOTKIN(N) is the Hilbert matrix with its first row altered to ## all ones. A is unsymmetric, ill-conditioned, and has many negative @@ -1759,9 +1816,11 @@ A = hilb (n); A(1,:) = ones (1, n); + endfunction function A = minij (n) + ## MINIJ Symmetric positive definite matrix MIN(i,j). ## A = MINIJ(N) is the N-by-N symmetric positive definite matrix with ## A(i,j) = MIN(i,j). @@ -1786,9 +1845,11 @@ endif A = bsxfun (@min, 1:n, (1:n)'); + endfunction function A = moler (n, alpha = -1) + ## MOLER Moler matrix - symmetric positive definite. ## A = MOLER(N, ALPHA) is the symmetric positive definite N-by-N matrix ## U'*U where U = TRIW(N, ALPHA). @@ -1811,9 +1872,11 @@ endif A = triw (n, alpha)' * triw (n, alpha); + endfunction function [A, T] = neumann (n) + ## NEUMANN Singular matrix from the discrete Neumann problem (sparse). ## NEUMANN(N) is the singular, row diagonally dominant matrix resulting ## from discretizing the Neumann problem with the usual five point @@ -1846,6 +1909,7 @@ T(n(1),n(1)-1) = -2; A = kron (T, eye (n(2))) + kron (eye (n(2)), T); + endfunction function A = normaldata (varargin) @@ -1890,6 +1954,7 @@ endfunction function Q = orthog (n, k = 1) + ## ORTHOG Orthogonal and nearly orthogonal matrices. ## Q = ORTHOG(N, K) selects the K'th type of matrix of order N. ## K > 0 for exactly orthogonal matrices, K < 0 for diagonal scalings of @@ -1973,9 +2038,11 @@ otherwise error ("gallery: unknown K '%d' for orthog matrix", k); endswitch + endfunction function A = parter (n) + ## PARTER Parter matrix - a Toeplitz matrix with singular values near PI. ## PARTER(N) is the matrix with (i,j) element 1/(i-j+0.5). ## It is a Cauchy matrix and a Toeplitz matrix. @@ -1999,9 +2066,11 @@ endif A = cauchy ((1:n) + 0.5, -(1:n)); + endfunction function P = pei (n, alpha = 1) + ## PEI Pei matrix. ## PEI(N, ALPHA), where ALPHA is a scalar, is the symmetric matrix ## ALPHA*EYE(N) + ONES(N). @@ -2021,9 +2090,11 @@ endif P = alpha * eye (n) + ones (n); + endfunction function A = poisson (n) + ## POISSON Block tridiagonal matrix from Poisson's equation (sparse). ## POISSON(N) is the block tridiagonal matrix of order N^2 ## resulting from discretizing Poisson's equation with the @@ -2043,9 +2114,11 @@ S = tridiag (n, -1, 2, -1); I = speye (n); A = kron (I, S) + kron (S, I); + endfunction function A = prolate (n, w = 0.25) + ## PROLATE Prolate matrix - symmetric, ill-conditioned Toeplitz matrix. ## A = PROLATE(N, W) is the N-by-N prolate matrix with parameter W. ## It is a symmetric Toeplitz matrix. @@ -2072,9 +2145,11 @@ a(2:n) = sin (2*pi*w*(1:n-1)) ./ (pi*(1:n-1)); A = toeplitz (a); + endfunction function H = randhess (x) + ## NOTE: this function was named ohess in the original Test Matrix Toolbox ## RANDHESS Random, orthogonal upper Hessenberg matrix. ## H = RANDHESS(N) is an N-by-N real, random, orthogonal @@ -2122,9 +2197,11 @@ H([i-1 i], :) = [ c*H(i-1,:)+s*H(i,:) -s*H(i-1,:)+c*H(i,:) ]; endfor + endfunction function A = rando (n, k = 1) + ## RANDO Random matrix with elements -1, 0 or 1. ## A = RANDO(N, K) is a random N-by-N matrix with elements from ## one of the following discrete distributions (default K = 1): @@ -2157,6 +2234,7 @@ function A = randsvd (n, kappa = sqrt (1/eps), mode = 3, kl = max (n) -1, ku = kl) + ## RANDSVD Random matrix with pre-assigned singular values. ## RANDSVD(N, KAPPA, MODE, KL, KU) is a (banded) random matrix of order N ## with COND(A) = KAPPA and singular values from the distribution MODE. @@ -2278,9 +2356,11 @@ A = bandred (A, kl, ku); endif endif + endfunction function A = redheff (n) + ## REDHEFF A (0,1) matrix of Redheffer associated with the Riemann hypothesis. ## A = REDHEFF(N) is an N-by-N matrix of 0s and 1s defined by ## A(i,j) = 1 if j = 1 or if i divides j, @@ -2314,9 +2394,11 @@ i = (1:n)' * ones (1, n); A = ! rem (i', i); A(:,1) = ones (n, 1); + endfunction function A = riemann (n) + ## RIEMANN A matrix associated with the Riemann hypothesis. ## A = RIEMANN(N) is an N-by-N matrix for which the ## Riemann hypothesis is true if and only if @@ -2345,9 +2427,11 @@ i = (2:n)' * ones (1, n-1); j = i'; A = i .* (! rem (j, i)) - ones (n-1); + endfunction function A = ris (n) + ## NOTE: this function was named dingdong in the original Test Matrix Toolbox ## RIS Dingdong matrix - a symmetric Hankel matrix. ## A = RIS(N) is the symmetric N-by-N Hankel matrix with @@ -2369,9 +2453,11 @@ p = -2*(1:n) + (n+1.5); A = cauchy (p); + endfunction function A = smoke (n, k = 0) + ## SMOKE Smoke matrix - complex, with a 'smoke ring' pseudospectrum. ## SMOKE(N) is an N-by-N matrix with 1s on the ## superdiagonal, 1 in the (N,1) position, and powers of @@ -2405,9 +2491,11 @@ otherwise, error ("gallery: K must have a value of 0 or 1 for smoke matrix"); endswitch + endfunction function T = toeppd (n, m = n, w = rand (m,1), theta = rand (m,1)) + ## NOTE: this function was named pdtoep in the original Test Matrix Toolbox ## TOEPPD Symmetric positive definite Toeplitz matrix. ## TOEPPD(N, M, W, THETA) is an N-by-N symmetric positive (semi-) @@ -2439,9 +2527,11 @@ for i = 1:m T += w(i) * cos (theta(i)*E); endfor + endfunction function P = toeppen (n, a = 1, b = -10, c = 0, d = 10, e = 1) + ## NOTE: this function was named pentoep in the original Test Matrix Toolbox ## TOEPPEN Pentadiagonal Toeplitz matrix (sparse). ## P = TOEPPEN(N, A, B, C, D, E) is the N-by-N pentadiagonal @@ -2475,9 +2565,11 @@ P = spdiags ([a*ones(n,1) b*ones(n,1) c*ones(n,1) d*ones(n,1) e*ones(n,1)], -2:2, n, n); + endfunction function T = tridiag (n, x = -1, y = 2, z = -1) + ## TRIDIAG Tridiagonal matrix (sparse). ## TRIDIAG(X, Y, Z) is the tridiagonal matrix with subdiagonal X, ## diagonal Y, and superdiagonal Z. @@ -2523,9 +2615,11 @@ ## T = diag (x, -1) + diag (y) + diag (z, 1); # For non-sparse matrix. n = numel (y); T = spdiags ([[x;0] y [0;z]], -1:1, n, n); + endfunction function t = triw (n, alpha = -1, k = n(end) - 1) + ## TRIW Upper triangular matrix discussed by Wilkinson and others. ## TRIW(N, ALPHA, K) is the upper triangular matrix with ones on ## the diagonal and ALPHAs on the first K >= 0 superdiagonals. @@ -2569,6 +2663,7 @@ n = n(end); t = tril (eye (m, n) + alpha * triu (ones (m, n), 1), k); + endfunction function A = uniformdata (varargin) @@ -2613,6 +2708,7 @@ endfunction function A = wathen (nx, ny, k = 0) + ## WATHEN returns the Wathen matrix. ## ## Discussion: @@ -2745,9 +2841,11 @@ if (k) A = diag (diag (A)) \ A; endif + endfunction function [A, b] = wilk (n) + ## WILK Various specific matrices devised/discussed by Wilkinson. ## [A, b] = WILK(N) is the matrix or system of order N. ## N = 3: upper triangular system Ux=b illustrating inaccurate solution. @@ -2805,10 +2903,12 @@ else error ("gallery: unknown N '%d' for wilk matrix", n); endif + endfunction ## NOTE: bandred is part of the Test Matrix Toolbox and is used by randsvd() function A = bandred (A, kl, ku) + ## BANDRED Band reduction by two-sided unitary transformations. ## B = BANDRED(A, KL, KU) is a matrix unitarily equivalent to A ## with lower bandwidth KL and upper bandwidth KU @@ -2856,10 +2956,12 @@ if (flip) A = A'; endif + endfunction ## NOTE: qmult is part of the Test Matrix Toolbox and is used by randsvd() function B = qmult (A) + ## QMULT Pre-multiply by random orthogonal matrix. ## QMULT(A) is Q*A where Q is a random real orthogonal matrix from ## the Haar distribution, of dimension the number of rows in A. @@ -2904,6 +3006,7 @@ endfor A(n,:) = A(n,:) * sign (randn); B = A; + endfunction
--- a/scripts/special-matrix/hadamard.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/special-matrix/hadamard.m Fri Nov 26 20:53:22 2021 -0800 @@ -134,6 +134,7 @@ endfunction function h = h28 () + ## Williamson matrix construction from ## http://www.research.att.com/~njas/hadamard/had.28.will.txt ## Normalized so that each row and column starts with +1
--- a/scripts/statistics/iqr.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/statistics/iqr.m Fri Nov 26 20:53:22 2021 -0800 @@ -82,7 +82,7 @@ nd = ndims (x); sz = size (x); - if isempty (dim) + if (isempty (dim)) ## Find first non-singleton dimension. if (max (sz) == 1) dim = 2; @@ -174,6 +174,7 @@ endfunction + %!assert (iqr (17), 0) %!assert (iqr (17, 1), 0) %!assert (iqr (17, 4), 0)
--- a/scripts/statistics/ranks.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/statistics/ranks.m Fri Nov 26 20:53:22 2021 -0800 @@ -132,21 +132,25 @@ endfunction function linnew = _competition (lin, sx, sz) + ## Stop increasing lin when sx does not increase. Otherwise, same as before. infvec = -Inf ([1, sz(2:end)]); fnewp = find (diff ([infvec; sx])); linnew = zeros (size (lin)); linnew(fnewp) = lin(fnewp); linnew = cummax (linnew, 1); + endfunction function linnew = _modified (lin, sx, sz) + ## Traverse lin backwards. Stop decreasing it when sx doesn't decrease. infvec = Inf ([1, sz(2:end)]); fnewp = find (diff ([sx; infvec])); linnew = Inf (size (lin)); linnew(fnewp) = lin(fnewp); linnew = flip (cummin (flip (linnew, 1)), 1); + endfunction
--- a/scripts/testfun/__run_test_suite__.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/testfun/__run_test_suite__.m Fri Nov 26 20:53:22 2021 -0800 @@ -246,12 +246,14 @@ endfunction function print_test_file_name (nm) + nmlen = numel (nm); filler = repmat (".", 1, 63-nmlen); if (nmlen > 63) nm = ["..", nm(nmlen-60:end)]; endif printf (" %s %s", nm, filler); + endfunction function fail_info = print_pass_fail (p, n, xf, xb, sk, rtsk, rgrs) @@ -355,11 +357,13 @@ endfunction function report_files_with_no_tests (with, without, typ) + pat = ['\' typ "$"]; n_with = num_elts_matching_pattern (with, pat); n_without = num_elts_matching_pattern (without, pat); n_tot = n_with + n_without; printf ("\n%d (of %d) %s files have no tests.\n", n_without, n_tot, typ); + endfunction
--- a/scripts/testfun/test.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/testfun/test.m Fri Nov 26 20:53:22 2021 -0800 @@ -913,11 +913,13 @@ ## Strip '.*prefix:' from '.*prefix: msg\n' and strip trailing blanks. function msg = trimerr (msg, prefix) + idx = index (msg, [prefix ":"]); if (idx > 0) msg(1:idx+length (prefix)) = []; endif msg = strtrim (msg); + endfunction ## Strip leading blanks from string. @@ -927,10 +929,11 @@ endfunction function body = __extract_test_code (nm) + filedir = fileparts (nm); if (is_same_file (filedir, pwd ())) - # The canonical current directory is not added as key to the load path. - # So it doesn't work as key for "dir_encoding". Use "." instead. + ## The canonical current directory is not added as key to the load path. + ## So it doesn't work as key for "dir_encoding". Use "." instead. filedir = "."; endif fid = fopen (nm, "rt", "n", dir_encoding (filedir)); @@ -943,6 +946,7 @@ endwhile fclose (fid); endif + endfunction
--- a/scripts/time/datevec.m Fri Nov 26 18:13:08 2021 -0800 +++ b/scripts/time/datevec.m Fri Nov 26 20:53:22 2021 -0800 @@ -205,6 +205,7 @@ endfunction function [f, rY, ry, fy, fm, fd, fh, fmi, fs] = __date_vfmt2sfmt__ (f) + original_f = f; # Store for error messages. ## Play safe with percent signs.