annotate libinterp/corefcn/chol.cc @ 33617:ec2635a02328 bytecode-interpreter tip

maint: Merge default to bytecode-interpreter.
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 21 May 2024 18:29:03 +0200
parents 4b601ca024d5
children
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 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 32631
diff changeset
3 // Copyright (C) 1996-2024 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 ////////////////////////////////////////////////////////////////////////
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21683
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21269
diff changeset
27 # include "config.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
28 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
29
22217
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
30 #include <string>
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
31
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
32 #include "Matrix.h"
21269
3c8a3d35661a better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
33 #include "chol.h"
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
34 #include "oct-string.h"
21145
307096fb67e1 revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents: 21139
diff changeset
35 #include "sparse-chol.h"
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
36 #include "sparse-util.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
37
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
38 #include "defun.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
39 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
40 #include "errwarn.h"
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
41 #include "ov.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
42 #include "ovl.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
43
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30888
diff changeset
44 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
45
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21127
diff changeset
46 template <typename CHOLT>
9715
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9453
diff changeset
47 static octave_value
20462
5ce959c55cc0 Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 20163
diff changeset
48 get_chol (const CHOLT& fact)
5ce959c55cc0 Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 20163
diff changeset
49 {
5ce959c55cc0 Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 20163
diff changeset
50 return octave_value (fact.chol_matrix());
5ce959c55cc0 Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 20163
diff changeset
51 }
5ce959c55cc0 Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 20163
diff changeset
52
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21127
diff changeset
53 template <typename CHOLT>
20462
5ce959c55cc0 Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 20163
diff changeset
54 static octave_value
9715
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9453
diff changeset
55 get_chol_r (const CHOLT& fact)
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9453
diff changeset
56 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
57 return octave_value (fact.chol_matrix (),
9715
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9453
diff changeset
58 MatrixType (MatrixType::Upper));
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9453
diff changeset
59 }
9f27172fbd1e auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents: 9453
diff changeset
60
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21127
diff changeset
61 template <typename CHOLT>
9862
c0aeedd8fb86 improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
62 static octave_value
c0aeedd8fb86 improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
63 get_chol_l (const CHOLT& fact)
c0aeedd8fb86 improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
64 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
65 return octave_value (fact.chol_matrix ().transpose (),
9862
c0aeedd8fb86 improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
66 MatrixType (MatrixType::Lower));
c0aeedd8fb86 improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
67 }
c0aeedd8fb86 improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents: 9758
diff changeset
68
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
69 DEFUN (chol, args, nargout,
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
70 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
71 @deftypefn {} {@var{R} =} chol (@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
72 @deftypefnx {} {[@var{R}, @var{p}] =} chol (@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
73 @deftypefnx {} {[@var{R}, @var{p}, @var{Q}] =} chol (@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
74 @deftypefnx {} {[@var{R}, @var{p}, @var{Q}] =} chol (@var{A}, "vector")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
75 @deftypefnx {} {[@var{L}, @dots{}] =} chol (@dots{}, "lower")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
76 @deftypefnx {} {[@var{R}, @dots{}] =} chol (@dots{}, "upper")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
77 @cindex Cholesky factorization
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
78 Compute the upper Cholesky@tie{}factor, @var{R}, of the real symmetric
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
79 or complex Hermitian positive definite matrix @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
80
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
81 The upper Cholesky@tie{}factor @var{R} is computed by using the upper
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
82 triangular part of matrix @var{A} and is defined by
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
83 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
84 $ R^T R = A $.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
85 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
86 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
87
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
88 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
89 @var{R}' * @var{R} = @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
90 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
91
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
92 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
93
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
94 Calling @code{chol} using the optional @qcode{"upper"} flag has the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
95 same behavior. In contrast, using the optional @qcode{"lower"} flag,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
96 @code{chol} returns the lower triangular factorization, computed by using
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
97 the lower triangular part of matrix @var{A}, such that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
98 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
99 $ L L^T = A $.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
100 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
101 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
102
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
103 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
104 @var{L} * @var{L}' = @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
105 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
106
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
107 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
108
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
109 Called with one output argument @code{chol} fails if matrix @var{A} is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
110 not positive definite. Note that if matrix @var{A} is not real symmetric
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
111 or complex Hermitian then the lower triangular part is considered to be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
112 the (complex conjugate) transpose of the upper triangular part, or vice
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
113 versa, given the @qcode{"lower"} flag.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
114
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
115 Called with two or more output arguments @var{p} flags whether the matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
116 @var{A} was positive definite and @code{chol} does not fail. A zero value
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
117 of @var{p} indicates that matrix @var{A} is positive definite and @var{R}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
118 gives the factorization. Otherwise, @var{p} will have a positive value.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
119
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
120 If called with three output arguments matrix @var{A} must be sparse and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
121 a sparsity preserving row/column permutation is applied to matrix @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
122 prior to the factorization. That is @var{R} is the factorization of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
123 @code{@var{A}(@var{Q},@var{Q})} such that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
124 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
125 $ R^T R = Q^T A Q$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
126 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
127 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
128
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
129 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
130 @var{R}' * @var{R} = @var{Q}' * @var{A} * @var{Q}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
131 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
132
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
133 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
134
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
135 The sparsity preserving permutation is generally returned as a matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
136 However, given the optional flag @qcode{"vector"}, @var{Q} will be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
137 returned as a vector such that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
138 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
139 $ R^T R = A (Q, Q)$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
140 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
141 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
142
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
143 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
144 @var{R}' * @var{R} = @var{A}(@var{Q}, @var{Q}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
145 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
146
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
147 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
148
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
149 In general the lower triangular factorization is significantly faster for
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
150 sparse matrices.
30329
81d26e8481a6 maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
151 @seealso{hess, lu, qr, qz, schur, svd, ichol, cholinv, chol2inv, cholupdate,
81d26e8481a6 maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29961
diff changeset
152 cholinsert, choldelete, cholshift}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
153 @end deftypefn */)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
154 {
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
155 int nargin = args.length ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
156
21683
54fa4dcba730 chol.cc (chol): improving doc (bugs #44313, #45146), help for correct usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21568
diff changeset
157 if (nargin < 1 || nargin > 3 || nargout > 3)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
158 print_usage ();
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
159 if (nargout > 2 && ! args(0).issparse ())
21683
54fa4dcba730 chol.cc (chol): improving doc (bugs #44313, #45146), help for correct usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21568
diff changeset
160 error ("chol: using three output arguments, matrix A must be sparse");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
161
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20863
diff changeset
162 bool LLt = false;
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20863
diff changeset
163 bool vecout = false;
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20863
diff changeset
164
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
165 int n = 1;
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
166 while (n < nargin)
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
167 {
22280
26109cce022e New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents: 22270
diff changeset
168 std::string tmp = args(n++).xstring_value ("chol: optional arguments must be strings");
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
169
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
170 if (string::strcmpi (tmp, "vector"))
20579
10ec79b47808 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20559
diff changeset
171 vecout = true;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
172 else if (string::strcmpi (tmp, "lower"))
20579
10ec79b47808 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20559
diff changeset
173 LLt = true;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
174 else if (string::strcmpi (tmp, "upper"))
20579
10ec79b47808 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20559
diff changeset
175 LLt = false;
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
176 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23586
diff changeset
177 error (R"(chol: optional argument must be one of "vector", "lower", or "upper")");
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
178 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
179
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20863
diff changeset
180 octave_value_list retval;
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
181 octave_value arg = args(0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
182
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23573
diff changeset
183 if (arg.isempty ())
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21110
diff changeset
184 return ovl (Matrix ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
185
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
186 if (arg.issparse ())
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
187 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
188 octave_idx_type info;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
189 bool natural = (nargout != 3);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
190 bool force = nargout > 1;
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
191
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
192 if (arg.isreal ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
193 {
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
194 SparseMatrix m = arg.sparse_matrix_value ();
15264
94cdf82d4a0c don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
195
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
196 math::sparse_chol<SparseMatrix> fact (m, info, natural, force);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
197
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
198 if (nargout == 3)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
199 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
200 if (vecout)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
201 retval(2) = fact.perm ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
202 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
203 retval(2) = fact.Q ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
204 }
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
205
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20863
diff changeset
206 if (nargout >= 2 || info == 0)
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
207 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
208 retval(1) = info;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
209 if (LLt)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
210 retval(0) = fact.L ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
211 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
212 retval(0) = fact.R ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
213 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
214 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
215 error ("chol: input matrix must be positive definite");
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
216 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
217 else if (arg.iscomplex ())
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
218 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
219 SparseComplexMatrix m = arg.sparse_complex_matrix_value ();
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
220
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
221 math::sparse_chol<SparseComplexMatrix> fact (m, info, natural, force);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
222
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
223 if (nargout == 3)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
224 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
225 if (vecout)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
226 retval(2) = fact.perm ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
227 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
228 retval(2) = fact.Q ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
229 }
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
230
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20863
diff changeset
231 if (nargout >= 2 || info == 0)
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
232 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
233 retval(1) = info;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
234 if (LLt)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
235 retval(0) = fact.L ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
236 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
237 retval(0) = fact.R ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
238 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
239 else
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
240 error ("chol: input matrix must be positive definite");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
241 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
242 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
243 err_wrong_type_arg ("chol", arg);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
244 }
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
245 else if (arg.is_single_type ())
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
246 {
22229
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
247 if (vecout)
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23586
diff changeset
248 error (R"(chol: A must be sparse for the "vector" option)");
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
249 if (arg.isreal ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
250 {
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
251 FloatMatrix m = arg.float_matrix_value ();
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
252
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
253 octave_idx_type info;
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7700
diff changeset
254
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
255 math::chol<FloatMatrix> fact (m, info, LLt != true);
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
256
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
257 if (nargout == 2 || info == 0)
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
258 retval = ovl (get_chol (fact), info);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
259 else
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
260 error ("chol: input matrix must be positive definite");
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
261 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
262 else if (arg.iscomplex ())
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
263 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
264 FloatComplexMatrix m = arg.float_complex_matrix_value ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
265
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
266 octave_idx_type info;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
267
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
268 math::chol<FloatComplexMatrix> fact (m, info, LLt != true);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
269
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
270 if (nargout == 2 || info == 0)
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
271 retval = ovl (get_chol (fact), info);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
272 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
273 error ("chol: input matrix must be positive definite");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
274 }
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
275 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
276 err_wrong_type_arg ("chol", arg);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
277 }
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
278 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
279 {
22229
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
280 if (vecout)
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23586
diff changeset
281 error (R"(chol: A must be sparse for the "vector" option)");
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
282 if (arg.isreal ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
283 {
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
284 Matrix m = arg.matrix_value ();
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
285
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
286 octave_idx_type info;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
287
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
288 math::chol<Matrix> fact (m, info, LLt != true);
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
289
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
290 if (nargout == 2 || info == 0)
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
291 retval = ovl (get_chol (fact), info);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
292 else
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
293 error ("chol: input matrix must be positive definite");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
294 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
295 else if (arg.iscomplex ())
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
296 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
297 ComplexMatrix m = arg.complex_matrix_value ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
298
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
299 octave_idx_type info;
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
300
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
301 math::chol<ComplexMatrix> fact (m, info, LLt != true);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
302
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
303 if (nargout == 2 || info == 0)
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
304 retval = ovl (get_chol (fact), info);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
305 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
306 error ("chol: input matrix must be positive definite");
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
307 }
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20462
diff changeset
308 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
309 err_wrong_type_arg ("chol", arg);
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
310 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
311
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
312 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
313 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
314
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
315 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
316 %!assert (chol ([2, 1; 1, 1]), [sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)], sqrt (eps))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
317 %!assert (chol (single ([2, 1; 1, 1])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
318 %! single ([sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)]), sqrt (eps ("single")))
22217
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
319
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
320 %!assert (chol ([2, 1; 1, 1], "upper"), [sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)],
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
321 %! sqrt (eps))
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
322 %!assert (chol ([2, 1; 1, 1], "lower"), [sqrt(2), 0; 1/sqrt(2), 1/sqrt(2)],
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
323 %! sqrt (eps))
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
324
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
325 %!assert (chol ([2, 1; 1, 1], "lower"), chol ([2, 1; 1, 1], "LoweR"))
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
326 %!assert (chol ([2, 1; 1, 1], "upper"), chol ([2, 1; 1, 1], "Upper"))
22229
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
327
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
328 ## Check the "vector" option which only affects the 3rd argument and
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
329 ## is only valid for sparse input.
22270
2c7acd39e9b7 Conditionally disable tests that rely on optional features
Mike Miller <mtmiller@octave.org>
parents: 22241
diff changeset
330 %!testif HAVE_CHOLMOD
22229
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
331 %! a = sparse ([2 1; 1 1]);
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
332 %! r = sparse ([sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)]);
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
333 %! [rd, pd, qd] = chol (a);
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
334 %! [rv, pv, qv] = chol (a, "vector");
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
335 %! assert (r, rd, eps)
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
336 %! assert (r, rv, eps)
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
337 %! assert (pd, 0)
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
338 %! assert (pd, pv)
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
339 %! assert (qd, sparse (eye (2)))
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
340 %! assert (qv, [1 2])
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
341 %!
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
342 %! [rv, pv, qv] = chol (a, "Vector"); # check case sensitivity
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
343 %! assert (r, rv, eps)
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
344 %! assert (pd, pv)
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
345 %! assert (qv, [1 2])
22217
3ac380d46d54 chol: make option passed as string case insensitive.
Carnë Draug <carandraug@octave.org>
parents: 22022
diff changeset
346
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
347 %!testif HAVE_CHOLMOD <*42587>
18845
161b11e7da2d Return error code from sparse chol factorization (bug #42587).
Rik <rik@octave.org>
parents: 17861
diff changeset
348 %! A = sparse ([1 0 8;0 1 8;8 8 1]);
161b11e7da2d Return error code from sparse chol factorization (bug #42587).
Rik <rik@octave.org>
parents: 17861
diff changeset
349 %! [Q, p] = chol (A);
161b11e7da2d Return error code from sparse chol factorization (bug #42587).
Rik <rik@octave.org>
parents: 17861
diff changeset
350 %! assert (p != 0);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
351
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
352 %!error chol ()
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
353 %!error <matrix must be positive definite> chol ([1, 2; 3, 4])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
354 %!error <requires square matrix> chol ([1, 2; 3, 4; 5, 6])
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
355 %!error <optional arguments must be strings> chol (1, 2)
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20700
diff changeset
356 %!error <optional argument must be one of "vector", "lower"> chol (1, "foobar")
21683
54fa4dcba730 chol.cc (chol): improving doc (bugs #44313, #45146), help for correct usage.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21568
diff changeset
357 %!error <matrix A must be sparse> [L,p,Q] = chol ([1, 2; 3, 4])
22229
22c2bd440544 chol: return permutation vector as row vector instead of column vector.
Carnë Draug <carandraug@octave.org>
parents: 22217
diff changeset
358 %!error <A must be sparse> [L, p] = chol ([1, 2; 3, 4], "vector")
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
359 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
360
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
361 DEFUN (cholinv, args, ,
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
362 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
363 @deftypefn {} {@var{Ainv} =} cholinv (@var{A})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
364 Compute the inverse of the symmetric positive definite matrix @var{A} using
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
365 the Cholesky@tie{}factorization.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
366 @seealso{chol, chol2inv, inv}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
367 @end deftypefn */)
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
368 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
369 if (args.length () != 1)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
370 print_usage ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
371
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
372 octave_value retval;
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
373 octave_value arg = args(0);
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
374
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
375 octave_idx_type nr = arg.rows ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
376 octave_idx_type nc = arg.columns ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
377
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
378 if (nr == 0 || nc == 0)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
379 retval = Matrix ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
380 else
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
381 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
382 if (arg.issparse ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
383 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
384 octave_idx_type info;
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
385
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
386 if (arg.isreal ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
387 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
388 SparseMatrix m = arg.sparse_matrix_value ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
389
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
390 math::sparse_chol<SparseMatrix> chol (m, info);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
391
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
392 if (info == 0)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
393 retval = chol.inverse ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
394 else
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
395 error ("cholinv: A must be positive definite");
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
396 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
397 else if (arg.iscomplex ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
398 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
399 SparseComplexMatrix m = arg.sparse_complex_matrix_value ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
400
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
401 math::sparse_chol<SparseComplexMatrix> chol (m, info);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
402
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
403 if (info == 0)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
404 retval = chol.inverse ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
405 else
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
406 error ("cholinv: A must be positive definite");
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
407 }
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
408 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
409 err_wrong_type_arg ("cholinv", arg);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
410 }
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
411 else if (arg.is_single_type ())
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
412 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
413 if (arg.isreal ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
414 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
415 FloatMatrix m = arg.float_matrix_value ();
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
416
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
417 octave_idx_type info;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
418 math::chol<FloatMatrix> chol (m, info);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
419 if (info == 0)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
420 retval = chol.inverse ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
421 else
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
422 error ("cholinv: A must be positive definite");
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
423 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
424 else if (arg.iscomplex ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
425 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
426 FloatComplexMatrix m = arg.float_complex_matrix_value ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
427
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
428 octave_idx_type info;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
429 math::chol<FloatComplexMatrix> chol (m, info);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
430 if (info == 0)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
431 retval = chol.inverse ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
432 else
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
433 error ("cholinv: A must be positive definite");
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
434 }
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
435 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
436 err_wrong_type_arg ("chol", arg);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
437 }
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
438 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
439 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
440 if (arg.isreal ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
441 {
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
442 Matrix m = arg.matrix_value ();
15264
94cdf82d4a0c don't overload meaning of info in Sparse Cholesky factorization functions
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
443
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
444 octave_idx_type info;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
445 math::chol<Matrix> chol (m, info);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
446 if (info == 0)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
447 retval = chol.inverse ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
448 else
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
449 error ("cholinv: A must be positive definite");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
450 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
451 else if (arg.iscomplex ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
452 {
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
453 ComplexMatrix m = arg.complex_matrix_value ();
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
454
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
455 octave_idx_type info;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
456 math::chol<ComplexMatrix> chol (m, info);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
457 if (info == 0)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
458 retval = chol.inverse ();
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
459 else
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
460 error ("cholinv: A must be positive definite");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
461 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
462 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
463 err_wrong_type_arg ("chol", arg);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
464 }
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
465 }
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
466
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
467 return retval;
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
468 }
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
469
8402
2176f2b4599e Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents: 8284
diff changeset
470 /*
8871
fb1c929dbbb7 tests vs. 64-bit indexing
John W. Eaton <jwe@octave.org>
parents: 8562
diff changeset
471 %!shared A, Ainv
8402
2176f2b4599e Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents: 8284
diff changeset
472 %! A = [2,0.2;0.2,1];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
473 %! Ainv = inv (A);
8871
fb1c929dbbb7 tests vs. 64-bit indexing
John W. Eaton <jwe@octave.org>
parents: 8562
diff changeset
474 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
475 %! Ainv1 = cholinv (A);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
476 %! assert (norm (Ainv-Ainv1), 0, 1e-10);
8871
fb1c929dbbb7 tests vs. 64-bit indexing
John W. Eaton <jwe@octave.org>
parents: 8562
diff changeset
477 %!testif HAVE_CHOLMOD
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
478 %! Ainv2 = inv (sparse (A));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
479 %! assert (norm (Ainv-Ainv2), 0, 1e-10);
8880
078ca05e4ef8 chol.cc: correct spelling of CHOLMOD in tests
John W. Eaton <jwe@octave.org>
parents: 8872
diff changeset
480 %!testif HAVE_CHOLMOD
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
481 %! Ainv3 = cholinv (sparse (A));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
482 %! assert (norm (Ainv-Ainv3), 0, 1e-10);
8402
2176f2b4599e Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents: 8284
diff changeset
483 */
2176f2b4599e Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents: 8284
diff changeset
484
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
485 DEFUN (chol2inv, args, ,
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
486 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
487 @deftypefn {} {@var{Ainv} =} chol2inv (@var{R})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
488 Invert a symmetric, positive definite square matrix from its Cholesky
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
489 decomposition, @var{R}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
490
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
491 Note that @var{R} should be an upper-triangular matrix with positive diagonal
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
492 elements. @code{chol2inv (@var{U})} provides @code{inv (@var{R}'*@var{R})} but
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30565
diff changeset
493 is much faster than using @code{inv}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
494 @seealso{chol, cholinv, inv}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
495 @end deftypefn */)
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
496 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
497 if (args.length () != 1)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
498 print_usage ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
499
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
500 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
501
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
502 octave_value arg = args(0);
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
503
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
504 octave_idx_type nr = arg.rows ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
505 octave_idx_type nc = arg.columns ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
506
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
507 if (nr == 0 || nc == 0)
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
508 retval = Matrix ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
509 else
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
510 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
511 if (arg.issparse ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
512 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
513 if (arg.isreal ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
514 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
515 SparseMatrix r = arg.sparse_matrix_value ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
516
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
517 retval = math::chol2inv (r);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
518 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
519 else if (arg.iscomplex ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
520 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
521 SparseComplexMatrix r = arg.sparse_complex_matrix_value ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
522
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
523 retval = math::chol2inv (r);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
524 }
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
525 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
526 err_wrong_type_arg ("chol2inv", arg);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
527 }
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
528 else if (arg.is_single_type ())
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
529 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
530 if (arg.isreal ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
531 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
532 FloatMatrix r = arg.float_matrix_value ();
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
533
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
534 retval = math::chol2inv (r);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
535 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
536 else if (arg.iscomplex ())
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
537 {
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
538 FloatComplexMatrix r = arg.float_complex_matrix_value ();
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
539
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
540 retval = math::chol2inv (r);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
541 }
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
542 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
543 err_wrong_type_arg ("chol2inv", arg);
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
544
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
545 }
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
546 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
547 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
548 if (arg.isreal ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
549 {
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
550 Matrix r = arg.matrix_value ();
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
551
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
552 retval = math::chol2inv (r);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
553 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23577
diff changeset
554 else if (arg.iscomplex ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
555 {
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
556 ComplexMatrix r = arg.complex_matrix_value ();
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
557
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
558 retval = math::chol2inv (r);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
559 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
560 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20941
diff changeset
561 err_wrong_type_arg ("chol2inv", arg);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9862
diff changeset
562 }
5340
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
563 }
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
564
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
565 return retval;
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
566 }
15843d76156d [project @ 2005-05-06 16:26:58 by jwe]
jwe
parents: 5307
diff changeset
567
22241
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
568 /*
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
569
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
570 ## Test for bug #36437
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
571 %!function sparse_chol2inv (T, tol)
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
572 %! iT = inv (T);
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
573 %! ciT = chol2inv (chol (T));
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
574 %! assert (ciT, iT, tol);
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
575 %! assert (chol2inv (chol ( full (T))), ciT, tol*2);
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
576 %!endfunction
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
577
22270
2c7acd39e9b7 Conditionally disable tests that rely on optional features
Mike Miller <mtmiller@octave.org>
parents: 22241
diff changeset
578 %!testif HAVE_CHOLMOD
22241
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
579 %! A = gallery ("poisson", 3);
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
580 %! sparse_chol2inv (A, eps);
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
581
22270
2c7acd39e9b7 Conditionally disable tests that rely on optional features
Mike Miller <mtmiller@octave.org>
parents: 22241
diff changeset
582 %!testif HAVE_CHOLMOD
22241
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
583 %! n = 10;
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
584 %! B = spdiags (ones (n, 1) * [1 2 1], [-1 0 1], n, n);
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
585 %! sparse_chol2inv (B, eps*100);
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
586
22270
2c7acd39e9b7 Conditionally disable tests that rely on optional features
Mike Miller <mtmiller@octave.org>
parents: 22241
diff changeset
587 %!testif HAVE_CHOLMOD
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
588 %! C = gallery ("tridiag", 5);
22241
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
589 %! sparse_chol2inv (C, eps*10);
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
590
22270
2c7acd39e9b7 Conditionally disable tests that rely on optional features
Mike Miller <mtmiller@octave.org>
parents: 22241
diff changeset
591 %!testif HAVE_CHOLMOD
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
592 %! D = gallery ("wathen", 1, 1);
22241
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
593 %! sparse_chol2inv (D, eps*10^4);
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
594
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
595 */
71d86e88589f chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents: 22229
diff changeset
596
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
597 DEFUN (cholupdate, args, nargout,
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
598 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
599 @deftypefn {} {[@var{R1}, @var{info}] =} cholupdate (@var{R}, @var{u}, @var{op})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
600 Update or downdate a Cholesky@tie{}factorization.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
601
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
602 Given an upper triangular matrix @var{R} and a column vector @var{u},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
603 attempt to determine another upper triangular matrix @var{R1} such that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
604
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
605 @itemize @bullet
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
606 @item
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
607 @var{R1}'*@var{R1} = @var{R}'*@var{R} + @var{u}*@var{u}'
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
608 if @var{op} is @qcode{"+"}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
609
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
610 @item
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
611 @var{R1}'*@var{R1} = @var{R}'*@var{R} - @var{u}*@var{u}'
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
612 if @var{op} is @qcode{"-"}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
613 @end itemize
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
614
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
615 If @var{op} is @qcode{"-"}, @var{info} is set to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
616
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
617 @itemize
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
618 @item 0 if the downdate was successful,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
619
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
620 @item 1 if @var{R}'*@var{R} - @var{u}*@var{u}' is not positive definite,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
621
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
622 @item 2 if @var{R} is singular.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
623 @end itemize
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
624
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
625 If @var{info} is not present, an error message is printed in cases 1 and 2.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
626 @seealso{chol, cholinsert, choldelete, cholshift}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
627 @end deftypefn */)
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
628 {
20816
b16bcd7a2a33 Use int rather than octave_idx_type for nargin data type.
Rik <rik@octave.org>
parents: 20812
diff changeset
629 int nargin = args.length ();
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
630
20898
8da80da1ac37 maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents: 20863
diff changeset
631 if (nargin < 2 || nargin > 3)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
632 print_usage ();
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
633
7559
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
634 octave_value argr = args(0);
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
635 octave_value argu = args(1);
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
636
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23583
diff changeset
637 if (! argr.isnumeric () || ! argu.isnumeric ()
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
638 || (nargin > 2 && ! args(2).is_string ()))
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
639 print_usage ();
7559
07522d7dcdf8 fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents: 7554
diff changeset
640
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
641 octave_value_list retval (nargout == 2 ? 2 : 1);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
642
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
643 octave_idx_type n = argr.rows ();
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
644
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
645 std::string op = (nargin < 3) ? "+" : args(2).string_value ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
646
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
647 bool down = (op == "-");
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
648
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
649 if (! down && op != "+")
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23586
diff changeset
650 error (R"(cholupdate: OP must be "+" or "-")");
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
651
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
652 if (argr.columns () != n || argu.rows () != n || argu.columns () != 1)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
653 error ("cholupdate: dimension mismatch between R and U");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
654
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
655 int err = 0;
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
656 if (argr.is_single_type () || argu.is_single_type ())
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
657 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
658 if (argr.isreal () && argu.isreal ())
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
659 {
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
660 // real case
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
661 FloatMatrix R = argr.float_matrix_value ();
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
662 FloatColumnVector u = argu.float_column_vector_value ();
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
663
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
664 math::chol<FloatMatrix> fact;
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
665 fact.set (R);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
666
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
667 if (down)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
668 err = fact.downdate (u);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
669 else
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
670 fact.update (u);
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
671
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
672 retval = ovl (get_chol_r (fact));
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
673 }
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
674 else
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
675 {
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
676 // complex case
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
677 FloatComplexMatrix R = argr.float_complex_matrix_value ();
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
678 FloatComplexColumnVector u
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
679 = argu.float_complex_column_vector_value ();
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
680
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
681 math::chol<FloatComplexMatrix> fact;
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
682 fact.set (R);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
683
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
684 if (down)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
685 err = fact.downdate (u);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
686 else
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
687 fact.update (u);
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
688
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
689 retval = ovl (get_chol_r (fact));
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
690 }
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
691 }
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
692 else
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
693 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
694 if (argr.isreal () && argu.isreal ())
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
695 {
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
696 // real case
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
697 Matrix R = argr.matrix_value ();
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
698 ColumnVector u = argu.column_vector_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
699
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
700 math::chol<Matrix> fact;
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
701 fact.set (R);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
702
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
703 if (down)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
704 err = fact.downdate (u);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
705 else
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
706 fact.update (u);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
707
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
708 retval = ovl (get_chol_r (fact));
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
709 }
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
710 else
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
711 {
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
712 // complex case
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
713 ComplexMatrix R = argr.complex_matrix_value ();
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
714 ComplexColumnVector u = argu.complex_column_vector_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
715
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
716 math::chol<ComplexMatrix> fact;
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
717 fact.set (R);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
718
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
719 if (down)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
720 err = fact.downdate (u);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
721 else
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
722 fact.update (u);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
723
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
724 retval = ovl (get_chol_r (fact));
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
725 }
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
726 }
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
727
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
728 if (nargout > 1)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
729 retval(1) = err;
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
730 else if (err == 1)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
731 error ("cholupdate: downdate violates positiveness");
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
732 else if (err == 2)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
733 error ("cholupdate: singular matrix");
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
734
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
735 return retval;
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
736 }
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
737
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
738 /*
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
739 %!shared A, u, Ac, uc
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
740 %! A = [ 0.436997 -0.131721 0.124120 -0.061673 ;
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
741 %! -0.131721 0.738529 0.019851 -0.140295 ;
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
742 %! 0.124120 0.019851 0.354879 -0.059472 ;
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
743 %! -0.061673 -0.140295 -0.059472 0.600939 ];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
744 %!
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
745 %! u = [ 0.98950 ;
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
746 %! 0.39844 ;
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
747 %! 0.63484 ;
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
748 %! 0.13351 ];
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
749 %! Ac = [ 0.5585528 + 0.0000000i -0.1662088 - 0.0315341i 0.0107873 + 0.0236411i -0.0276775 - 0.0186073i ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
750 %! -0.1662088 + 0.0315341i 0.6760061 + 0.0000000i 0.0011452 - 0.0475528i 0.0145967 + 0.0247641i ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
751 %! 0.0107873 - 0.0236411i 0.0011452 + 0.0475528i 0.6263149 - 0.0000000i -0.1585837 - 0.0719763i ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
752 %! -0.0276775 + 0.0186073i 0.0145967 - 0.0247641i -0.1585837 + 0.0719763i 0.6034234 - 0.0000000i ];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
753 %!
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
754 %! uc = [ 0.54267 + 0.91519i ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
755 %! 0.99647 + 0.43141i ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
756 %! 0.83760 + 0.68977i ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
757 %! 0.39160 + 0.90378i ];
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
758
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
759 %!test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
760 %! R = chol (A);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
761 %! R1 = cholupdate (R, u);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
762 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
763 %! assert (norm (R1'*R1 - R'*R - u*u', Inf), 0, 1e1*eps);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
764 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
765 %! R1 = cholupdate (R1, u, "-");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
766 %! assert (norm (triu (R1)-R1, Inf), 0);
32450
1f77c3f61aea chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32400
diff changeset
767 %! assert (norm (R1 - R, Inf), 0, 1e1*eps);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
768
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
769 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
770 %! R = chol (Ac);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
771 %! R1 = cholupdate (R, uc);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
772 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
773 %! assert (norm (R1'*R1 - R'*R - uc*uc', Inf), 0, 1e1*eps);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
774 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
775 %! R1 = cholupdate (R1, uc, "-");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
776 %! assert (norm (triu (R1)-R1, Inf), 0);
32631
07affc3de044 norm: Increase tolerance in test by 1*eps.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32450
diff changeset
777 %! assert (norm (R1 - R, Inf), 0, 11*eps);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
778
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
779 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
780 %! R = chol (single (A));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
781 %! R1 = cholupdate (R, single (u));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
782 %! assert (norm (triu (R1)-R1, Inf), single (0));
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
783 %! assert (norm (R1'*R1 - R'*R - single (u*u'), Inf), 0, 1e1* eps ("single"));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
784 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
785 %! R1 = cholupdate (R1, single (u), "-");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
786 %! assert (norm (triu (R1)-R1, Inf), single (0));
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
787 %! assert (norm (R1 - R, Inf), 0, 2e1* eps ("single"));
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
788
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
789 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
790 %! R = chol (single (Ac));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
791 %! R1 = cholupdate (R, single (uc));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
792 %! assert (norm (triu (R1)-R1, Inf), single (0));
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
793 %! assert (norm (R1'*R1 - R'*R - single (uc*uc'), Inf), 0, 1e1* eps ("single"));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
794 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
795 %! R1 = cholupdate (R1, single (uc), "-");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
796 %! assert (norm (triu (R1)-R1, Inf), single (0));
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
797 %! assert (norm (R1 - R, Inf), 0, 2e1* eps ("single"));
7554
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
798 */
40574114c514 implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7515
diff changeset
799
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
800 DEFUN (cholinsert, args, nargout,
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
801 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
802 @deftypefn {} {@var{R1} =} cholinsert (@var{R}, @var{j}, @var{u})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
803 @deftypefnx {} {[@var{R1}, @var{info}] =} cholinsert (@var{R}, @var{j}, @var{u})
26046
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 25113
diff changeset
804 Update a Cholesky factorization given a row or column to insert in the
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 25113
diff changeset
805 original factored matrix.
25113
476fc012d09a doc: Shorten very long first sentences of docstrings (bug #53388).
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
806
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
807 Given a Cholesky@tie{}factorization of a real symmetric or complex Hermitian
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
808 positive definite matrix @w{@var{A} = @var{R}'*@var{R}}, @var{R}@tie{}upper
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
809 triangular, return the Cholesky@tie{}factorization of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
810 @var{A1}, where @w{A1(p,p) = A}, @w{A1(:,j) = A1(j,:)' = u} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
811 @w{p = [1:j-1,j+1:n+1]}. @w{u(j)} should be positive.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
812
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
813 On return, @var{info} is set to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
814
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
815 @itemize
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
816 @item 0 if the insertion was successful,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
817
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
818 @item 1 if @var{A1} is not positive definite,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
819
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
820 @item 2 if @var{R} is singular.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
821 @end itemize
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
822
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
823 If @var{info} is not present, an error message is printed in cases 1 and 2.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
824 @seealso{chol, cholupdate, choldelete, cholshift}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
825 @end deftypefn */)
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
826 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
827 if (args.length () != 3)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
828 print_usage ();
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
829
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
830 octave_value argr = args(0);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
831 octave_value argj = args(1);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
832 octave_value argu = args(2);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
833
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23583
diff changeset
834 if (! argr.isnumeric () || ! argu.isnumeric ()
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
835 || ! argj.is_real_scalar ())
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
836 print_usage ();
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
837
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
838 octave_idx_type n = argr.rows ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
839 octave_idx_type j = argj.scalar_value ();
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
840
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
841 if (argr.columns () != n || argu.rows () != n+1 || argu.columns () != 1)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
842 error ("cholinsert: dimension mismatch between R and U");
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
843
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
844 if (j < 1 || j > n+1)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
845 error ("cholinsert: index J out of range");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
846
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
847 octave_value_list retval (nargout == 2 ? 2 : 1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
848
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
849 int err = 0;
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
850 if (argr.is_single_type () || argu.is_single_type ())
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
851 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
852 if (argr.isreal () && argu.isreal ())
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
853 {
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
854 // real case
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
855 FloatMatrix R = argr.float_matrix_value ();
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
856 FloatColumnVector u = argu.float_column_vector_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
857
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
858 math::chol<FloatMatrix> fact;
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
859 fact.set (R);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
860 err = fact.insert_sym (u, j-1);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
861
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
862 retval = ovl (get_chol_r (fact));
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
863 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
864 else
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
865 {
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
866 // complex case
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
867 FloatComplexMatrix R = argr.float_complex_matrix_value ();
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
868 FloatComplexColumnVector u
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
869 = argu.float_complex_column_vector_value ();
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
870
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
871 math::chol<FloatComplexMatrix> fact;
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
872 fact.set (R);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
873 err = fact.insert_sym (u, j-1);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
874
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
875 retval = ovl (get_chol_r (fact));
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
876 }
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
877 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
878 else
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
879 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
880 if (argr.isreal () && argu.isreal ())
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
881 {
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
882 // real case
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
883 Matrix R = argr.matrix_value ();
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
884 ColumnVector u = argu.column_vector_value ();
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
885
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
886 math::chol<Matrix> fact;
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
887 fact.set (R);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
888 err = fact.insert_sym (u, j-1);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
889
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
890 retval = ovl (get_chol_r (fact));
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
891 }
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
892 else
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
893 {
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
894 // complex case
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
895 ComplexMatrix R = argr.complex_matrix_value ();
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
896 ComplexColumnVector u = argu.complex_column_vector_value ();
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
897
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
898 math::chol<ComplexMatrix> fact;
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
899 fact.set (R);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
900 err = fact.insert_sym (u, j-1);
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
901
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
902 retval = ovl (get_chol_r (fact));
20863
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
903 }
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
904 }
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
905
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
906 if (nargout > 1)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
907 retval(1) = err;
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
908 else if (err == 1)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
909 error ("cholinsert: insertion violates positiveness");
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
910 else if (err == 2)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
911 error ("cholinsert: singular matrix");
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
912 else if (err == 3)
e81276e8f481 2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents: 20853
diff changeset
913 error ("cholinsert: diagonal element must be real");
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
914
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
915 return retval;
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
916 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
917
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
918 /*
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
919 %!test
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
920 %! u2 = [ 0.35080 ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
921 %! 0.63930 ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
922 %! 3.31057 ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
923 %! -0.13825 ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
924 %! 0.45266 ];
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
925 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
926 %! R = chol (A);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
927 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
928 %! j = 3; p = [1:j-1, j+1:5];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
929 %! R1 = cholinsert (R, j, u2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
930 %! A1 = R1'*R1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
931 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
932 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
933 %! assert (norm (A1(p,p) - A, Inf), 0, 1e1*eps);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
934
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
935 %!test
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
936 %! u2 = [ 0.35080 + 0.04298i;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
937 %! 0.63930 + 0.23778i;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
938 %! 3.31057 + 0.00000i;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
939 %! -0.13825 + 0.19879i;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
940 %! 0.45266 + 0.50020i];
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
941 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
942 %! R = chol (Ac);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
943 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
944 %! j = 3; p = [1:j-1, j+1:5];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
945 %! R1 = cholinsert (R, j, u2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
946 %! A1 = R1'*R1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
947 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
948 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
949 %! assert (norm (A1(p,p) - Ac, Inf), 0, 1e1*eps);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
950
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
951 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
952 %! u2 = single ([ 0.35080 ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
953 %! 0.63930 ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
954 %! 3.31057 ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
955 %! -0.13825 ;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
956 %! 0.45266 ]);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
957 %!
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
958 %! R = chol (single (A));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
959 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
960 %! j = 3; p = [1:j-1, j+1:5];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
961 %! R1 = cholinsert (R, j, u2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
962 %! A1 = R1'*R1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
963 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
964 %! assert (norm (triu (R1)-R1, Inf), single (0));
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
965 %! assert (norm (A1(p,p) - A, Inf), 0, 1e1* eps ("single"));
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
966
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
967 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
968 %! u2 = single ([ 0.35080 + 0.04298i;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
969 %! 0.63930 + 0.23778i;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
970 %! 3.31057 + 0.00000i;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
971 %! -0.13825 + 0.19879i;
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
972 %! 0.45266 + 0.50020i]);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
973 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
974 %! R = chol (single (Ac));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
975 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
976 %! j = 3; p = [1:j-1, j+1:5];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
977 %! R1 = cholinsert (R, j, u2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
978 %! A1 = R1'*R1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
979 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
980 %! assert (norm (triu (R1)-R1, Inf), single (0));
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
981 %! assert (norm (A1(p,p) - single (Ac), Inf), 0, 2e1* eps ("single"));
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
982
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
983 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
984 %! cu = chol (triu (A), "upper");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
985 %! cl = chol (tril (A), "lower");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
986 %! assert (cu, cl', eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
987
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
988 %!test
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21547
diff changeset
989 %! cca = chol (Ac);
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
990 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
991 %! ccal = chol (Ac, "lower");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
992 %! ccal2 = chol (tril (Ac), "lower");
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
993 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
994 %! ccau = chol (Ac, "upper");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
995 %! ccau2 = chol (triu (Ac), "upper");
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
996 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
997 %! assert (cca'*cca, Ac, eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
998 %! assert (ccau'*ccau, Ac, eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
999 %! assert (ccau2'*ccau2, Ac, eps);
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1000 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1001 %! assert (cca, ccal', eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1002 %! assert (cca, ccau, eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1003 %! assert (cca, ccal2', eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1004 %! assert (cca, ccau2, eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1005
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1006 %!test
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21547
diff changeset
1007 %! cca = chol (single (Ac));
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1008 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1009 %! ccal = chol (single (Ac), "lower");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1010 %! ccal2 = chol (tril (single (Ac)), "lower");
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1011 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1012 %! ccau = chol (single (Ac), "upper");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1013 %! ccau2 = chol (triu (single (Ac)), "upper");
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1014 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1015 %! assert (cca'*cca, single (Ac), eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1016 %! assert (ccau'*ccau, single (Ac), eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1017 %! assert (ccau2'*ccau2, single (Ac), eps ("single"));
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1018 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1019 %! assert (cca, ccal', eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1020 %! assert (cca, ccau, eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1021 %! assert (cca, ccal2', eps ("single"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1022 %! assert (cca, ccau2, eps ("single"));
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1023
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1024 %!test
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1025 %! a = [12, 2, 3, 4;
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1026 %! 2, 14, 5, 3;
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1027 %! 3, 5, 16, 6;
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1028 %! 4, 3, 6, 16];
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1029 %!
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1030 %! b = [0, 1, 2, 3;
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1031 %! -1, 0, 1, 2;
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1032 %! -2, -1, 0, 1;
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1033 %! -3, -2, -1, 0];
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1034 %!
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1035 %! ca = a + i*b;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1036 %!
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21547
diff changeset
1037 %! cca = chol (ca);
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1038 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1039 %! ccal = chol (ca, "lower");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1040 %! ccal2 = chol (tril (ca), "lower");
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1041 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1042 %! ccau = chol (ca, "upper");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1043 %! ccau2 = chol (triu (ca), "upper");
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1044 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1045 %! assert (cca'*cca, ca, 16*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1046 %! assert (ccau'*ccau, ca, 16*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1047 %! assert (ccau2'*ccau2, ca, 16*eps);
13953
642e43164af6 fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents: 13915
diff changeset
1048 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1049 %! assert (cca, ccal', 16*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1050 %! assert (cca, ccau, 16*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1051 %! assert (cca, ccal2', 16*eps);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1052 %! assert (cca, ccau2, 16*eps);
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1053 */
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1054
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
1055 DEFUN (choldelete, args, ,
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
1056 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1057 @deftypefn {} {@var{R1} =} choldelete (@var{R}, @var{j})
26046
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 25113
diff changeset
1058 Update a Cholesky factorization given a row or column to delete from the
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 25113
diff changeset
1059 original factored matrix.
25113
476fc012d09a doc: Shorten very long first sentences of docstrings (bug #53388).
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
1060
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1061 Given a Cholesky@tie{}factorization of a real symmetric or complex Hermitian
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1062 positive definite matrix @w{@var{A} = @var{R}'*@var{R}}, @var{R}@tie{}upper
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1063 triangular, return the Cholesky@tie{}factorization of @w{A(p,p)}, where
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1064 @w{p = [1:j-1,j+1:n+1]}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1065 @seealso{chol, cholupdate, cholinsert, cholshift}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1066 @end deftypefn */)
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1067 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
1068 if (args.length () != 2)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
1069 print_usage ();
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1070
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1071 octave_value argr = args(0);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1072 octave_value argj = args(1);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1073
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23583
diff changeset
1074 if (! argr.isnumeric () || ! argj.is_real_scalar ())
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1075 print_usage ();
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1076
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1077 octave_idx_type n = argr.rows ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1078 octave_idx_type j = argj.scalar_value ();
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1079
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1080 if (argr.columns () != n)
21110
3d0d84305600 Use err_square_matrix_required more widely.
Rik <rik@octave.org>
parents: 21100
diff changeset
1081 err_square_matrix_required ("choldelete", "R");
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1082
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1083 if (j < 0 && j > n)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1084 error ("choldelete: index J out of range");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1085
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1086 octave_value_list retval;
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1087
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1088 if (argr.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1089 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
1090 if (argr.isreal ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1091 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1092 // real case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1093 FloatMatrix R = argr.float_matrix_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1094
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1095 math::chol<FloatMatrix> fact;
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1096 fact.set (R);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1097 fact.delete_sym (j-1);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1098
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1099 retval = ovl (get_chol_r (fact));
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1100 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1101 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1102 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1103 // complex case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1104 FloatComplexMatrix R = argr.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1105
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1106 math::chol<FloatComplexMatrix> fact;
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1107 fact.set (R);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1108 fact.delete_sym (j-1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1109
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1110 retval = ovl (get_chol_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1111 }
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1112 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1113 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1114 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
1115 if (argr.isreal ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1116 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1117 // real case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1118 Matrix R = argr.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1119
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1120 math::chol<Matrix> fact;
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1121 fact.set (R);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1122 fact.delete_sym (j-1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1123
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1124 retval = ovl (get_chol_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1125 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1126 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1127 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1128 // complex case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1129 ComplexMatrix R = argr.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1130
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1131 math::chol<ComplexMatrix> fact;
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1132 fact.set (R);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1133 fact.delete_sym (j-1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1134
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1135 retval = ovl (get_chol_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1136 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1137 }
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1138
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1139 return retval;
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1140 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1141
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1142 /*
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1143 %!test
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1144 %! R = chol (A);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1145 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1146 %! j = 3; p = [1:j-1,j+1:4];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1147 %! R1 = choldelete (R, j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1148 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1149 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1150 %! assert (norm (R1'*R1 - A(p,p), Inf), 0, 1e1*eps);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1151
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1152 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1153 %! R = chol (Ac);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1154 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1155 %! j = 3; p = [1:j-1,j+1:4];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1156 %! R1 = choldelete (R, j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1157 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1158 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1159 %! assert (norm (R1'*R1 - Ac(p,p), Inf), 0, 1e1*eps);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1160
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1161 %!test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1162 %! R = chol (single (A));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1163 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1164 %! j = 3; p = [1:j-1,j+1:4];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1165 %! R1 = choldelete (R, j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1166 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1167 %! assert (norm (triu (R1)-R1, Inf), single (0));
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1168 %! assert (norm (R1'*R1 - single (A(p,p)), Inf), 0, 1e1* eps ("single"));
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1169
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1170 %!test
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1171 %! R = chol (single (Ac));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1172 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1173 %! j = 3; p = [1:j-1,j+1:4];
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1174 %! R1 = choldelete (R,j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1175 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1176 %! assert (norm (triu (R1)-R1, Inf), single (0));
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1177 %! assert (norm (R1'*R1 - single (Ac(p,p)), Inf), 0, 1e1* eps ("single"));
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1178 */
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1179
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
1180 DEFUN (cholshift, args, ,
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
1181 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1182 @deftypefn {} {@var{R1} =} cholshift (@var{R}, @var{i}, @var{j})
26046
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 25113
diff changeset
1183 Update a Cholesky factorization given a range of columns to shift in the
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 25113
diff changeset
1184 original factored matrix.
25113
476fc012d09a doc: Shorten very long first sentences of docstrings (bug #53388).
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
1185
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1186 Given a Cholesky@tie{}factorization of a real symmetric or complex Hermitian
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1187 positive definite matrix @w{@var{A} = @var{R}'*@var{R}}, @var{R}@tie{}upper
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1188 triangular, return the Cholesky@tie{}factorization of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1189 @w{@var{A}(p,p)}, where @w{p} is the permutation @*
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1190 @code{p = [1:i-1, circshift(i:j, 1), j+1:n]} if @w{@var{i} < @var{j}} @*
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1191 or @*
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1192 @code{p = [1:j-1, circshift(j:i,-1), i+1:n]} if @w{@var{j} < @var{i}}. @*
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1193
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1194 @seealso{chol, cholupdate, cholinsert, choldelete}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1195 @end deftypefn */)
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1196 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
1197 if (args.length () != 3)
20790
c2d9556d51d0 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20711
diff changeset
1198 print_usage ();
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1199
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1200 octave_value argr = args(0);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1201 octave_value argi = args(1);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1202 octave_value argj = args(2);
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1203
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23583
diff changeset
1204 if (! argr.isnumeric () || ! argi.is_real_scalar ()
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1205 || ! argj.is_real_scalar ())
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1206 print_usage ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1207
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1208 octave_idx_type n = argr.rows ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1209 octave_idx_type i = argi.scalar_value ();
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1210 octave_idx_type j = argj.scalar_value ();
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1211
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1212 if (argr.columns () != n)
21110
3d0d84305600 Use err_square_matrix_required more widely.
Rik <rik@octave.org>
parents: 21100
diff changeset
1213 err_square_matrix_required ("cholshift", "R");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1214
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1215 if (j < 0 || j > n+1 || i < 0 || i > n+1)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1216 error ("cholshift: index I or J is out of range");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1217
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1218 octave_value_list retval;
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1219
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1220 if (argr.is_single_type () && argi.is_single_type ()
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1221 && argj.is_single_type ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1222 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
1223 if (argr.isreal ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1224 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1225 // real case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1226 FloatMatrix R = argr.float_matrix_value ();
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1227
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1228 math::chol<FloatMatrix> fact;
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1229 fact.set (R);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1230 fact.shift_sym (i-1, j-1);
20851
0828bf20d105 maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents: 20818
diff changeset
1231
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1232 retval = ovl (get_chol_r (fact));
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1233 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1234 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1235 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1236 // complex case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1237 FloatComplexMatrix R = argr.float_complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1238
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1239 math::chol<FloatComplexMatrix> fact;
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1240 fact.set (R);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1241 fact.shift_sym (i-1, j-1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1242
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1243 retval = ovl (get_chol_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1244 }
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1245 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1246 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1247 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
1248 if (argr.isreal ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1249 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1250 // real case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1251 Matrix R = argr.matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1252
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1253 math::chol<Matrix> fact;
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1254 fact.set (R);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1255 fact.shift_sym (i-1, j-1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1256
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1257 retval = ovl (get_chol_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1258 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1259 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1260 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1261 // complex case
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1262 ComplexMatrix R = argr.complex_matrix_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1263
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1264 math::chol<ComplexMatrix> fact;
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1265 fact.set (R);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1266 fact.shift_sym (i-1, j-1);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1267
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1268 retval = ovl (get_chol_r (fact));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1269 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20898
diff changeset
1270 }
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1271
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1272 return retval;
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1273 }
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1274
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1275 /*
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1276 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1277 %! R = chol (A);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1278 %!
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1279 %! i = 1; j = 3; p = [1:i-1, circshift(i:j,-1), j+1:4];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1280 %! R1 = cholshift (R, i, j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1281 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1282 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1283 %! assert (norm (R1'*R1 - A(p,p), Inf), 0, 1e1*eps);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1284 %!
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1285 %! j = 1; i = 3; p = [1:j-1, circshift(j:i,+1), i+1:4];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1286 %! R1 = cholshift (R, i, j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1287 %!
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1288 %! assert (norm (triu (R1) - R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1289 %! assert (norm (R1'*R1 - A(p,p), Inf), 0, 1e1*eps);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1290
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1291 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1292 %! R = chol (Ac);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1293 %!
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1294 %! i = 1; j = 3; p = [1:i-1, circshift(i:j,-1), j+1:4];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1295 %! R1 = cholshift (R, i, j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1296 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1297 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1298 %! assert (norm (R1'*R1 - Ac(p,p), Inf), 0, 1e1*eps);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1299 %!
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1300 %! j = 1; i = 3; p = [1:j-1, circshift(j:i,+1), i+1:4];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1301 %! R1 = cholshift (R, i, j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1302 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1303 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1304 %! assert (norm (R1'*R1 - Ac(p,p), Inf), 0, 1e1*eps);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1305
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
1306 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1307 %! R = chol (single (A));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1308 %!
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1309 %! i = 1; j = 3; p = [1:i-1, circshift(i:j,-1), j+1:4];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1310 %! R1 = cholshift (R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1311 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1312 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1313 %! assert (norm (R1'*R1 - single (A(p,p)), Inf), 0, 1e1* eps ("single"));
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1314 %!
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1315 %! j = 1; i = 3; p = [1:j-1, circshift(j:i,+1), i+1:4];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1316 %! R1 = cholshift (R, i, j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1317 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1318 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1319 %! assert (norm (R1'*R1 - single (A(p,p)), Inf), 0, 1e1* eps ("single"));
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1320
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1321 %!test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1322 %! R = chol (single (Ac));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1323 %!
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1324 %! i = 1; j = 3; p = [1:i-1, circshift(i:j,-1), j+1:4];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1325 %! R1 = cholshift (R, i, j);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1326 %!
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1327 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1328 %! assert (norm (R1'*R1 - single (Ac(p,p)), Inf), 0, 1e1* eps ("single"));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1329 %!
32485
22c90d779a24 Update deprecated `shift` to `circshift` in BISTs for chol() and qr()
Arun Giridhar <arungiridhar@gmail.com>
parents: 32450
diff changeset
1330 %! j = 1; i = 3; p = [1:j-1, circshift(j:i,+1), i+1:4];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1331 %! R1 = cholshift (R, i, j);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
1332 %!
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1333 %! assert (norm (triu (R1)-R1, Inf), 0);
32400
3f48081aa034 chol.cc: Use three arguments for assert in self tests.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
1334 %! assert (norm (R1'*R1 - single (Ac(p,p)), Inf), 0, 1e1* eps ("single"));
7700
efccca5f2ad7 more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents: 7650
diff changeset
1335 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1336
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30888
diff changeset
1337 OCTAVE_END_NAMESPACE(octave)