annotate libinterp/corefcn/rcond.cc @ 29358:0a5b15007766 stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021.
author John W. Eaton <jwe@octave.org>
date Wed, 10 Feb 2021 09:52:15 -0500
parents bd51beb6205e
children 32c3a5805893
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 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
3 // Copyright (C) 2008-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
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/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
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 ////////////////////////////////////////////////////////////////////////
7788
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21317
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
7788
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
28 #endif
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
29
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
30 #include "defun.h"
7788
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
31 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20940
diff changeset
32 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
33 #include "ovl.h"
7788
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
34 #include "utils.h"
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
35
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
36 DEFUN (rcond, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
37 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
38 @deftypefn {} {@var{c} =} rcond (@var{A})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
39 Compute the 1-norm estimate of the reciprocal condition number as returned
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
40 by @sc{lapack}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
41
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
42 If the matrix is well-conditioned then @var{c} will be near 1 and if the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
43 matrix is poorly conditioned it will be close to 0.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
44
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
45 The matrix @var{A} must not be sparse. If the matrix is sparse then
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
46 @code{condest (@var{A})} or @code{rcond (full (@var{A}))} should be used
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
47 instead.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
48 @seealso{cond, condest}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
49 @end deftypefn */)
7788
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
50 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20802
diff changeset
51 if (args.length () != 1)
7788
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
52 print_usage ();
20802
8bb38ba1bad6 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20172
diff changeset
53
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
54 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
55
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23581
diff changeset
56 if (args(0).issparse ())
7788
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
57 error ("rcond: for sparse matrices use 'rcond (full (a))' or 'condest (a)' instead");
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
58
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
59 if (args(0).is_single_type ())
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7788
diff changeset
60 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23220
diff changeset
61 if (args(0).iscomplex ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
62 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
63 FloatComplexMatrix m = args(0).float_complex_matrix_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
64 MatrixType mattyp;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
65 retval = m.rcond (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
66 args(0).matrix_type (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
67 }
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7788
diff changeset
68 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
69 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
70 FloatMatrix m = args(0).float_matrix_value ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
71 MatrixType mattyp;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
72 retval = m.rcond (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
73 args(0).matrix_type (mattyp);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
74 }
7797
f42c6f8d6d8e Extend rcond function to single precision types
David Bateman <dbateman@free.fr>
parents: 7788
diff changeset
75 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23220
diff changeset
76 else if (args(0).iscomplex ())
7788
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
77 {
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
78 ComplexMatrix m = args(0).complex_matrix_value ();
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
79 MatrixType mattyp;
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
80 retval = m.rcond (mattyp);
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
81 args(0).matrix_type (mattyp);
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
82 }
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
83 else
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
84 {
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
85 Matrix m = args(0).matrix_value ();
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
86 MatrixType mattyp;
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
87 retval = m.rcond (mattyp);
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
88 args(0).matrix_type (mattyp);
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
89 }
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
90
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
91 return retval;
45f5faba05a2 Add the rcond function
David Bateman <dbateman@free.fr>
parents:
diff changeset
92 }
12791
610a4e780a19 codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11572
diff changeset
93
610a4e780a19 codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11572
diff changeset
94 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
95 %!assert (rcond (eye (2)), 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
96 %!assert (rcond (ones (2)), 0)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
97 %!assert (rcond ([1 1; 2 1]), 1/9)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
98 %!assert (rcond (magic (4)), 0, eps)
12791
610a4e780a19 codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11572
diff changeset
99
15382
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
100 %!shared x, sx
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
101 %! x = [-5.25, -2.25; -2.25, 1] * eps () + ones (2) / 2;
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
102 %! sx = [-5.25, -2.25; -2.25, 1] * eps ("single") + ones (2) / 2;
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
103 %!assert (rcond (x) < eps ())
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
104 %!assert (rcond (sx) < eps ('single'))
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
105 %!assert (rcond (x*i) < eps ())
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
106 %!assert (rcond (sx*i) < eps ('single'))
15382
197774b411ec rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
107
12791
610a4e780a19 codesprint: write 4 test for rcond
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 11572
diff changeset
108 */