annotate scripts/linear-algebra/ishermitian.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 7854d5752dd2
children 83f9f8bda883
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 1996-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26592
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 ##
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 ## This file is part of Octave.
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 ##
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 ##
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20160
diff changeset
27 ## @deftypefn {} {} ishermitian (@var{A})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20160
diff changeset
28 ## @deftypefnx {} {} ishermitian (@var{A}, @var{tol})
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
29 ## @deftypefnx {} {} ishermitian (@var{A}, @qcode{"skew"})
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
30 ## @deftypefnx {} {} ishermitian (@var{A}, @qcode{"skew"}, @var{tol})
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
31 ## Return true if @var{A} is a Hermitian or skew-Hermitian matrix within the
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
32 ## tolerance specified by @var{tol}.
18921
d0d0858cfab1 doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
33 ##
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
34 ## The default tolerance is zero (uses faster code).
20160
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
35 ##
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
36 ## The type of symmetry to check may be specified with the additional input
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
37 ## @qcode{"nonskew"} (default) for regular Hermitian or @qcode{"skew"} for
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
38 ## skew-Hermitian.
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
39 ##
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
40 ## Background: A matrix is Hermitian if the complex conjugate transpose of the
25228
581d3a13d7e2 ishermitian.m, issymmetric.m: Use @tcode macro in docstring (bug #53556).
Rik <rik@octave.org>
parents: 25227
diff changeset
41 ## matrix is equal to the original matrix: @w{@tcode{@var{A} == @var{A}'}}. If
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
42 ## a tolerance is given then the calculation is
18921
d0d0858cfab1 doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
43 ## @code{norm (@var{A} - @var{A}', Inf) / norm (@var{A}, Inf) < @var{tol}}.
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
44 ##
26043
5cef57130cb9 doc: grammar check m-files in scripts/ directory.
Rik <rik@octave.org>
parents: 25228
diff changeset
45 ## A matrix is skew-Hermitian if the complex conjugate transpose of the matrix
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
46 ## is equal to the negative of the original matrix:
25228
581d3a13d7e2 ishermitian.m, issymmetric.m: Use @tcode macro in docstring (bug #53556).
Rik <rik@octave.org>
parents: 25227
diff changeset
47 ## @w{@tcode{@var{A} == -@var{A}'}}. If a
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
48 ## tolerance is given then the calculation is
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
49 ## @code{norm (@var{A} + @var{A}', Inf) / norm (@var{A}, Inf) < @var{tol}}.
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
50 ## @seealso{issymmetric, isdefinite}
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 ## @end deftypefn
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
53 function retval = ishermitian (A, skewopt = "nonskew", tol = 0)
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27985
diff changeset
55 if (nargin < 1)
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56 print_usage ();
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 endif
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
59 if (nargin == 2)
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
60 ## Decode whether second argument is skewopt or tol
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
61 if (isnumeric (skewopt))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
62 tol = skewopt;
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
63 skewopt = "nonskew";
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
64 elseif (! ischar (skewopt))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
65 error ("ishermitian: second argument must be a non-negative scalar TOL, or one of the strings: 'skew' / 'nonskew'");
25227
a937ffe7dfd9 fix typo in previous change
John W. Eaton <jwe@octave.org>
parents: 25225
diff changeset
66 endif
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
67 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
68
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
69 ## Validate inputs
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
70 retval = (isnumeric (A) || islogical (A)) && issquare (A);
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
71 if (! retval)
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
72 return;
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
73 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
74
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
75 if (! (strcmp (skewopt, "skew") || strcmp (skewopt, "nonskew")))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
76 error ("ishermitian: SKEWOPT must be 'skew' or 'nonskew'");
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
77 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
78
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
79 if (! (isnumeric (tol) && isscalar (tol) && tol >= 0))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
80 error ("ishermitian: TOL must be a scalar >= 0");
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
81 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
82
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
83 ## Calculate Hermitian-ness
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
84 if (strcmp (skewopt, "nonskew"))
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
85 if (tol == 0)
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
86 ## check for exact symmetry
26592
c0fa4a9eef95 Ensure boolean value when checking sparse matrices for symmetry/hermiticity.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 26376
diff changeset
87 retval = full (! any ((A != A')(:)));
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
88 else
26289
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
89 if (islogical (A))
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
90 ## Hack to allow norm to work. Choose single to minimize memory.
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
91 A = single (A);
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
92 endif
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
93 norm_x = norm (A, Inf);
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
94 retval = norm_x == 0 || norm (A - A', Inf) / norm_x <= tol;
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
95 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
96 else
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
97 ## skew-Hermitian
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
98 if (tol == 0)
26592
c0fa4a9eef95 Ensure boolean value when checking sparse matrices for symmetry/hermiticity.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 26376
diff changeset
99 retval = full (! any ((A != -A')(:)));
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
100 else
26289
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
101 if (islogical (A))
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
102 ## Hack to allow norm to work. Choose single to minimize memory.
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
103 A = single (A);
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
104 endif
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
105 norm_x = norm (A, Inf);
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
106 retval = norm_x == 0 || norm (A + A', Inf) / norm_x <= tol;
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
107 endif
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
108 endif
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
109
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
110 endfunction
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
111
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
112
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
113 %!assert (ishermitian (1))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
114 %!assert (! ishermitian ([1, 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
115 %!assert (ishermitian ([]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
116 %!assert (ishermitian ([1, 2; 2, 1]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
117 %!assert (ishermitian ([1, 2.1; 2, 1.1], 0.2))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
118 %!assert (ishermitian ([1, -2i; 2i, 1]))
26592
c0fa4a9eef95 Ensure boolean value when checking sparse matrices for symmetry/hermiticity.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 26376
diff changeset
119 %!assert (ishermitian (speye (100)), true) # Return full logical value.
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
120 %!assert (ishermitian (logical (eye (2))))
26289
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
121 %!assert (! ishermitian (logical ([1 1; 0 1])))
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
122 %!assert (ishermitian (logical ([1 1; 0 1]), 0.5))
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
123 %!assert (ishermitian ([0, 2i; 2i, 0], "skew"))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
124 %!assert (! ishermitian ([0, 2; -2, eps], "skew"))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
125 %!assert (ishermitian ([0, 2; -2, eps], "skew", eps))
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
126
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
127 %!assert (! (ishermitian ("test")))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
128 %!assert (! (ishermitian ("t")))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
129 %!assert (! (ishermitian (["te"; "et"])))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
130 %!assert (! ishermitian ({1}))
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131 %!test
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132 %! s.a = 1;
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
133 %! assert (! ishermitian (s));
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
134
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
135 ## Test input validation
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
136 %!error <Invalid call> ishermitian ()
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
137 %!error <second argument must be> ishermitian (1, {"skew"})
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
138 %!error <SKEWOPT must be 'skew' or 'nonskew'> ishermitian (1, "foobar")
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
139 %!error <SKEWOPT must be 'skew' or 'nonskew'> ishermitian (1, "foobar")
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
140 %!error <TOL must be a scalar .= 0> ishermitian (1, "skew", {1})
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
141 %!error <TOL must be a scalar .= 0> ishermitian (1, "skew", [1 1])
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
142 %!error <TOL must be a scalar .= 0> ishermitian (1, -1)