changeset 27962:3b8d21ff0ca6

New validator functions implementation (bug #57627). - NEWS: Announce new functions. - scripts/help/__unimplemented__.m: Remove new functions from list. - scripts/micellaneous/module.mk: Add new functions to build system. - scripts/micellaneous/mustBe*.m: Add validator function.
author Andrew Janke <andrew@apjanke.net>
date Sun, 19 Jan 2020 10:07:30 +0900
parents 27a5cc0614f1
children bb214b62839a
files NEWS scripts/help/__unimplemented__.m scripts/miscellaneous/module.mk scripts/miscellaneous/mustBeFinite.m scripts/miscellaneous/mustBeGreaterThan.m scripts/miscellaneous/mustBeGreaterThanOrEqual.m scripts/miscellaneous/mustBeInteger.m scripts/miscellaneous/mustBeLessThan.m scripts/miscellaneous/mustBeLessThanOrEqual.m scripts/miscellaneous/mustBeMember.m scripts/miscellaneous/mustBeNegative.m scripts/miscellaneous/mustBeNonNan.m scripts/miscellaneous/mustBeNonempty.m scripts/miscellaneous/mustBeNonnegative.m scripts/miscellaneous/mustBeNonpositive.m scripts/miscellaneous/mustBeNonsparse.m scripts/miscellaneous/mustBeNonzero.m scripts/miscellaneous/mustBeNumeric.m scripts/miscellaneous/mustBeNumericOrLogical.m scripts/miscellaneous/mustBePositive.m scripts/miscellaneous/mustBeReal.m
diffstat 21 files changed, 972 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Sat Jan 18 05:38:18 2020 -0800
+++ b/NEWS	Sun Jan 19 10:07:30 2020 +0900
@@ -167,6 +167,9 @@
 - An undocumented function `gui_mainfcn` has been added, for compatibility
   with figures created with Matlab's GUIDE.
 
+- Several validator functions of type `mustBe*` have been added.  See
+  the list of new functions below.
+
 ### Alphabetical list of new functions added in Octave 6
 
 * `commandhistory`
@@ -174,6 +177,24 @@
 * `filebrowser`
 * `is_same_file`
 * `lightangle`
+* `mustBeFinite`
+* `mustBeGreaterThan`
+* `mustBeGreaterThanOrEqual`
+* `mustBeInteger`
+* `mustBeLessThan`
+* `mustBeLessThanOrEqual`
+* `mustBeMember`
+* `mustBeNegative`
+* `mustBeNonempty`
+* `mustBeNonNan`
+* `mustBeNonnegative`
+* `mustBeNonpositive`
+* `mustBeNonsparse`
+* `mustBeNonzero`
+* `mustBeNumeric`
+* `mustBeNumericOrLogical`
+* `mustBePositive`
+* `mustBeReal`
 * `namedargs2cell`
 * `newline`
 * `rescale`
--- a/scripts/help/__unimplemented__.m	Sat Jan 18 05:38:18 2020 -0800
+++ b/scripts/help/__unimplemented__.m	Sun Jan 19 10:07:30 2020 +0900
@@ -1013,24 +1013,6 @@
   "mput",
   "multibandread",
   "multibandwrite",
-  "mustBeFinite",
-  "mustBeGreaterThan",
-  "mustBeGreaterThanOrEqual",
-  "mustBeInteger",
-  "mustBeLessThan",
-  "mustBeLessThanOrEqual",
-  "mustBeMember",
-  "mustBeNegative",
-  "mustBeNonempty",
-  "mustBeNonNan",
-  "mustBeNonnegative",
-  "mustBeNonpositive",
-  "mustBeNonsparse",
-  "mustBeNonzero",
-  "mustBeNumeric",
-  "mustBeNumericOrLogical",
-  "mustBePositive",
-  "mustBeReal",
   "NaT",
   "nccreate",
   "ncdisp",
--- a/scripts/miscellaneous/module.mk	Sat Jan 18 05:38:18 2020 -0800
+++ b/scripts/miscellaneous/module.mk	Sun Jan 19 10:07:30 2020 +0900
@@ -52,6 +52,24 @@
   %reldir%/mkdir.m \
   %reldir%/mkoctfile.m \
   %reldir%/movefile.m \
+  %reldir%/mustBeFinite.m \
+  %reldir%/mustBeGreaterThan.m \
+  %reldir%/mustBeGreaterThanOrEqual.m \
+  %reldir%/mustBeInteger.m \
+  %reldir%/mustBeLessThan.m \
+  %reldir%/mustBeLessThanOrEqual.m \
+  %reldir%/mustBeMember.m \
+  %reldir%/mustBeNegative.m \
+  %reldir%/mustBeNonempty.m \
+  %reldir%/mustBeNonNan.m \
+  %reldir%/mustBeNonnegative.m \
+  %reldir%/mustBeNonpositive.m \
+  %reldir%/mustBeNonsparse.m \
+  %reldir%/mustBeNonzero.m \
+  %reldir%/mustBeNumeric.m \
+  %reldir%/mustBeNumericOrLogical.m \
+  %reldir%/mustBePositive.m \
+  %reldir%/mustBeReal.m \
   %reldir%/namedargs2cell.m \
   %reldir%/namelengthmax.m \
   %reldir%/nargchk.m \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeFinite.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,47 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeFinite (@var{x})
+##
+## Requires that input @var{x} is finite.
+##
+## Raises an error if any element of the input @var{x} is not finite, as
+## determined by @code{isfinite (x)}.
+##
+## @end deftypefn
+
+function x = mustBeFinite (x)
+  tf = isfinite (x);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (!tf);
+    error ("%s must be finite; got Infs in %d elements: indexes %s", ...
+      label, numel (ix_bad), mat2str (ix_bad));
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeGreaterThan.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,55 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeGreaterThan (@var{x}, @var{c})
+##
+## Requires that input @var{x} is greater than @var{c}.
+##
+## Raises an error if any element of the input @var{x} is not greater than
+## @var{c}, as determined by @code{@var{x} > @var{c}}.
+##
+## @end deftypefn
+
+function x = mustBeGreaterThan (x, c)
+  tf = x > c;
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    try
+      bad = x(ix_bad);
+      errmsg = sprintf ("%s must be greater than %f; got %d elements that were not: values %s", ...
+        label, c, numel (ix_bad), mat2str (bad));
+    catch err
+      errmsg = sprintf ("%s must be greater than %f; got %d elements that were not: indexes %s", ...
+        label, c, numel (ix_bad), mat2str (ix_bad));
+    end_try_catch
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeGreaterThanOrEqual.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,57 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeGreaterThanOrEqual (@var{x}, @var{c})
+##
+## Requires that input @var{x} is greater than or equal to @var{c}.
+##
+## Raises an error if any element of the input @var{x} is not greater than
+## or equal to @var{c}, as determined by @code{@var{x} >= @var{c}}.
+##
+## @end deftypefn
+
+function x = mustBeGreaterThanOrEqual (x, c)
+  tf = x >= c;
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    try
+      bad = x(ix_bad);
+      errmsg = sprintf ( ...
+        "%s must be greater than or equal to %f; got %d elements that were not: values %s", ...
+        label, c, numel (ix_bad), mat2str (bad));
+    catch err
+      errmsg = sprintf ( ...
+        "%s must be greater than or equal to %f; got %d elements that were not: indexes %s", ...
+        label, c, numel (ix_bad), mat2str (ix_bad));
+    end_try_catch
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeInteger.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,58 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeInteger (@var{x})
+##
+## Requires that input @var{x} is integer-valued (but not necessarily
+## integer-typed).
+##
+## Raises an error if any element of the input @var{x} is not a finite,
+## real, integer-valued numeric value, as determined by various checks.
+##
+## @end deftypefn
+
+function x = mustBeInteger (x)
+  if isinteger (x) || islogical (x)
+    return
+  endif
+  but = [];
+  if ! isnumeric (x)
+    but = sprintf ("it was non-numeric (got a %s)", class (x));
+  elseif any (! isfinite (x))
+    but = "there were Inf values";
+  elseif ! isreal (x)
+    but = "it was complex";
+  elseif ! all (floor (x) == x)
+    but = "it had fractional values in some elements";
+  end
+  if ! isempty (but)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    error ("%s must be integer-valued; but %s", label, but);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeLessThan.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,57 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeLessThan (@var{x}, @var{c})
+##
+## Requires that input @var{x} is less than @var{c}.
+##
+## Raises an error if any element of the input @var{x} is not less than
+## @var{c}, as determined by @code{@var{x} < @var{c}}.
+##
+## @end deftypefn
+
+function x = mustBeLessThan (x, c)
+  tf = x < c;
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    try
+      bad = x(ix_bad);
+      errmsg = sprintf ( ...
+        "%s must be less than %f; got %d elements that were not: values %s", ...
+        label, c, numel (ix_bad), mat2str (bad));
+    catch err
+      errmsg = sprintf ( ...
+        "%s must be less than %f; got %d elements that were not: indexes %s", ...
+        label, c, numel (ix_bad), mat2str (ix_bad));
+    end_try_catch
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeLessThanOrEqual.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,57 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeLessThanOrEqual (@var{x}, @var{c})
+##
+## Requires that input is less than or equal to a given value.
+##
+## Raises an error if any element of the input @var{x} is not less than
+## or equal to @var{c}, as determined by @code{@var{x} <= @var{c}}.
+##
+## @end deftypefn
+
+function x = mustBeLessThanOrEqual (x, c)
+  tf = x <= c;
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    try
+      bad = x(ix_bad);
+      errmsg = sprintf ( ...
+        "%s must be less than or equal to %f; got %d elements that were not: values %s", ...
+        label, c, numel (ix_bad), mat2str (bad));
+    catch err
+      errmsg = sprintf ( ...
+        "%s must be less than or equal to %f; got %d elements that were not: indexes %s", ...
+        label, c, numel (ix_bad), mat2str (ix_bad));
+    end_try_catch
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeMember.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,54 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeMember (@var{x}, @var{valid})
+##
+## Requires that input @var{x} is a member of a set of given valid values.
+##
+## Raises an error if any element of the input @var{x} is not a member
+## of @var{valid}, as determined by @code{ismember (@var{x})}.
+##
+## Note that char inputs may behave weirdly, because of the interaction
+## between chars and cellstrings when calling ismember() on them.  But it
+## will probably "do what you mean" if you just use it naturally.
+##
+## @end deftypefn
+
+function x = mustBeMember (x, valid)
+  tf = ismember (x, valid);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    n_bad = numel (find (! tf));
+    # TODO: Fancy inclusion of bad & valid values in the error message.
+    # Probably use mat2str() in a try/catch for that.
+    error ( ...
+      "%s must be one of the specified valid values; got %d elements that weren't", ...
+      label, n_bad);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeNegative.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,57 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeNegative (@var{x})
+##
+## Requires that input @var{x} is negative.
+##
+## Raises an error if any element of the input @var{x} is not negative, as
+## determined by @code{@var{x} < 0}.
+##
+## @end deftypefn
+
+function x = mustBeNegative (x)
+  tf = x < 0;
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    try
+      bad = x(ix_bad);
+      errmsg = sprintf ( ...
+        "%s must be negative; got %d elements that were not: values %s", ...
+        label, numel (ix_bad), mat2str (bad));
+    catch err
+      errmsg = sprintf ( ...
+        "%s must be negative; got %d elements that were not: indexes %s", ...
+        label, numel (ix_bad), mat2str (ix_bad));
+    end_try_catch
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeNonNan.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,50 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeNonNan (@var{x})
+##
+## Requires that input @var{x} is non-NaN.
+##
+## Raises an error if any element of the input @var{x} is NaN, as determined
+## by @code{isnan (@var{x})}.
+##
+## @end deftypefn
+
+function x = mustBeNonNan (x)
+  tf = ! isnan (x);
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    errmsg = sprintf ( ...
+      "%s must be non-NaN; got %d elements that were not: indexes %s", ...
+      label, numel (ix_bad), mat2str (ix_bad));
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeNonempty.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,44 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeNonempty (@var{x})
+##
+## Requires that input @var{x} is nonempty.
+##
+## Raises an error if the input @var{x} is not empty, as determined by
+## @code{! isempty (@var{x})}.
+##
+## @end deftypefn
+
+function x = mustBeNonempty (x)
+  if isempty (x)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    error ("%s must be nonempty; got an empty", label);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeNonnegative.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,57 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeNonnegative (@var{x})
+##
+## Requires that input @var{x} is not negative.
+##
+## Raises an error if any element of the input @var{x} is negative, as
+## determined by @code{@var{x} >= 0}.
+##
+## @end deftypefn
+
+function x = mustBeNonnegative (x)
+  tf = x >= 0;
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    try
+      bad = x(ix_bad);
+      errmsg = sprintf ( ...
+        "%s must be non-negative; got %d elements that were not: values %s", ...
+        label, numel (ix_bad), mat2str (bad));
+    catch err
+      errmsg = sprintf ( ...
+        "%s must be non-negative; got %d elements that were not: indexes %s", ...
+        label, numel (ix_bad), mat2str (ix_bad));
+    end_try_catch
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeNonpositive.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,57 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeNonpositive (@var{x})
+##
+## Requires that input @var{x} is not positive.
+##
+## Raises an error if any element of the input @var{x} is positive, as
+## determined by @code{@var{x} <= 0}.
+##
+## @end deftypefn
+
+function x = mustBeNonpositive (x)
+  tf = x <= 0;
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    try
+      bad = x(ix_bad);
+      errmsg = sprintf ( ...
+        "%s must be non-positive; got %d elements that were not: values %s", ...
+        label, numel (ix_bad), mat2str (bad));
+    catch err
+      errmsg = sprintf ( ...
+        "%s must be non-positive; got %d elements that were not: indexes %s", ...
+        label, numel (ix_bad), mat2str (ix_bad));
+    end_try_catch
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeNonsparse.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,44 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeNonsparse (@var{x})
+##
+## Requires that input @var{x} is not sparse.
+##
+## Raises an error if the input @var{x} is sparse, as determined by
+## @code{issparse (@var{x})}.
+##
+## @end deftypefn
+
+function x = mustBeNonsparse (x)
+  if issparse (x)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    error ("%s must be nonsparse; got a sparse array", label);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeNonzero.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,50 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeNonzero (@var{x})
+##
+## Requires that input @var{x} is not zero.
+##
+## Raises an error if any element of the input @var{x} is zero, as determined
+## by @code{@var{x} != 0}.
+##
+## @end deftypefn
+
+function x = mustBeNonzero (x)
+  tf = x != 0;
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    errmsg = sprintf ( ...
+      "%s must be non-zero; got %d elements that were zero: indexes %s", ...
+      label, numel (ix_bad), mat2str (ix_bad));
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeNumeric.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,44 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeNumeric (@var{x})
+##
+## Requires that input @var{x} is numeric.
+##
+## Raises an error if the input @var{x} is not numeric, as determined by
+## @code{isnumeric (@var{x})}.
+##
+## @end deftypefn
+
+function x = mustBeNumeric (x)
+  if ! isnumeric (x)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    error ("%s must be numeric; got a %s", label, class (x));
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeNumericOrLogical.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,44 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeNumericOrLogical (@var{x})
+##
+## Requires that input @var{x} is numeric or logical.
+##
+## Raises an error if the input @var{x} is not numeric or logical, as
+## determined by @code{isnumeric (@var{x}) || islogical (@var{x})}.
+##
+## @end deftypefn
+
+function x = mustBeNumericOrLogical (x)
+  if ! (isnumeric (x) || islogical (x))
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    error ("%s must be numeric or logical; got a %s", label, class (x));
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBePositive.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,57 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBePositive (@var{x})
+##
+## Requires that input @var{x} is positive.
+##
+## Raises an error if any element of the input @var{x} is not positive, as
+## determined by @code{@var{x} > 0}.
+##
+## @end deftypefn
+
+function x = mustBePositive (x)
+  tf = x > 0;
+  tf = tf(:);
+  if ! all (tf)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    ix_bad = find (! tf);
+    try
+      bad = x(ix_bad);
+      errmsg = sprintf ( ...
+        "%s must be positive; got %d elements that were not: values %s", ...
+        label, numel (ix_bad), mat2str (bad));
+    catch err
+      errmsg = sprintf ( ...
+        "%s must be positive; got %d elements that were not: indexes %s", ...
+        label, numel (ix_bad), mat2str (ix_bad));
+    end_try_catch
+    error (errmsg);
+  endif
+endfunction
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/miscellaneous/mustBeReal.m	Sun Jan 19 10:07:30 2020 +0900
@@ -0,0 +1,44 @@
+########################################################################
+##
+## Copyright (C) 2019-2020 The Octave Project Developers
+##
+## See the file COPYRIGHT.md in the top-level directory of this
+## distribution or <https://octave.org/copyright/>.
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+##
+########################################################################
+
+## -*- texinfo -*-
+## @deftypefn {} {@var{x} =} mustBeReal (@var{x})
+##
+## Requires that input @var{x} is real.
+##
+## Raises an error if the input @var{x} is not real, as determined by
+## @code{isreal (@var{x})}.
+##
+## @end deftypefn
+
+function x = mustBeReal (x)
+  if ! isreal (x)
+    label = inputname (1);
+    if isempty (label)
+      label = "input";
+    endif
+    error ("%s must be real; got a complex value", label);
+  endif
+endfunction