Mercurial > octave
annotate libinterp/dldfcn/chol.cc @ 21547:ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
* besselj.cc, bitfcns.cc, cellfun.cc, data.cc, debug.cc, error.cc,
file-io.cc, graphics.cc, input.cc, lu.cc, matrix_type.cc, nproc.cc,
pr-output.cc, quadcc.cc, regexp.cc, schur.cc, sparse.cc, strfind.cc, strfns.cc,
syscalls.cc, urlwrite.cc, variables.cc, __osmesa_print__.cc, audiodevinfo.cc,
audioread.cc, ccolamd.cc, chol.cc, colamd.cc, convhulln.cc, qr.cc, symbfact.cc,
ov-java.cc, ov-struct.cc, ov-usr-fcn.cc, pt-arg-list.cc:
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
author | Rik <rik@octave.org> |
---|---|
date | Sun, 27 Mar 2016 20:39:19 -0700 |
parents | 40de9f8f23a6 |
children | 3d60ed163b70 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19055
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
11523 | 4 Copyright (C) 2008-2009 Jaroslav Hajek |
5 Copyright (C) 2008-2009 VZLU Prague | |
2928 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
2928 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
2928 | 22 |
23 */ | |
24 | |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
25 |
2928 | 26 #ifdef 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 | 28 #endif |
29 | |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
30 #include "chol.h" |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
31 #include "sparse-chol.h" |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
32 #include "oct-spparms.h" |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
33 #include "sparse-util.h" |
2928 | 34 |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
35 #include "ov-re-sparse.h" |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
36 #include "ov-cx-sparse.h" |
2928 | 37 #include "defun-dld.h" |
38 #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
|
39 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
40 #include "ovl.h" |
2928 | 41 #include "utils.h" |
42 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
43 template <typename CHOLT> |
9715
9f27172fbd1e
auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9453
diff
changeset
|
44 static octave_value |
20462
5ce959c55cc0
Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
20163
diff
changeset
|
45 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
|
46 { |
5ce959c55cc0
Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
20163
diff
changeset
|
47 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
|
48 } |
5ce959c55cc0
Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
20163
diff
changeset
|
49 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
50 template <typename CHOLT> |
20462
5ce959c55cc0
Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
20163
diff
changeset
|
51 static octave_value |
9715
9f27172fbd1e
auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9453
diff
changeset
|
52 get_chol_r (const CHOLT& fact) |
9f27172fbd1e
auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9453
diff
changeset
|
53 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
54 return octave_value (fact.chol_matrix (), |
9715
9f27172fbd1e
auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9453
diff
changeset
|
55 MatrixType (MatrixType::Upper)); |
9f27172fbd1e
auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9453
diff
changeset
|
56 } |
9f27172fbd1e
auto-set MatrixType from certain functions
Jaroslav Hajek <highegg@gmail.com>
parents:
9453
diff
changeset
|
57 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
58 template <typename CHOLT> |
9862
c0aeedd8fb86
improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
59 static octave_value |
c0aeedd8fb86
improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
60 get_chol_l (const CHOLT& fact) |
c0aeedd8fb86
improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
61 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
62 return octave_value (fact.chol_matrix ().transpose (), |
9862
c0aeedd8fb86
improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
63 MatrixType (MatrixType::Lower)); |
c0aeedd8fb86
improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
64 } |
c0aeedd8fb86
improve chol Matlab compatibility
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
65 |
2928 | 66 DEFUN_DLD (chol, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
68 @deftypefn {} {@var{R} =} chol (@var{A})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
69 @deftypefnx {} {[@var{R}, @var{p}] =} chol (@var{A})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
70 @deftypefnx {} {[@var{R}, @var{p}, @var{Q}] =} chol (@var{S})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
71 @deftypefnx {} {[@var{R}, @var{p}, @var{Q}] =} chol (@var{S}, \"vector\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
72 @deftypefnx {} {[@var{L}, @dots{}] =} chol (@dots{}, \"lower\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
73 @deftypefnx {} {[@var{L}, @dots{}] =} chol (@dots{}, \"upper\")\n\ |
3372 | 74 @cindex Cholesky factorization\n\ |
21547
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
75 Compute the Cholesky@tie{}factor, @var{R}, of the symmetric positive\n\ |
ad0599a0acc6
doc: Wrap C++ docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
76 definite matrix @var{A}.\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
77 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
78 The Cholesky@tie{}factor is defined by\n\ |
3372 | 79 @tex\n\ |
80 $ R^T R = A $.\n\ | |
81 @end tex\n\ | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8421
diff
changeset
|
82 @ifnottex\n\ |
3372 | 83 \n\ |
84 @example\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
85 @var{R}' * @var{R} = @var{A}.\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
86 @end example\n\ |
10840 | 87 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8421
diff
changeset
|
88 @end ifnottex\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
89 \n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
90 Called with one output argument @code{chol} fails if @var{A} or @var{S} is\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8880
diff
changeset
|
91 not positive definite. With two or more output arguments @var{p} flags\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8880
diff
changeset
|
92 whether the matrix was positive definite and @code{chol} does not fail. A\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
93 zero value indicated that the matrix was positive definite and the @var{R}\n\ |
9065
8207b833557f
Cleanup documentation for arith.texi, linalg.texi, nonlin.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
94 gives the factorization, and @var{p} will have a positive value otherwise.\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
95 \n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
96 If called with 3 outputs then a sparsity preserving row/column permutation\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
97 is applied to @var{A} prior to the factorization. That is @var{R} is the\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
98 factorization of @code{@var{A}(@var{Q},@var{Q})} such that\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
99 @tex\n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
100 $ R^T R = Q^T A Q$.\n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
101 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8421
diff
changeset
|
102 @ifnottex\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
103 \n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
104 @example\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
105 @var{R}' * @var{R} = @var{Q}' * @var{A} * @var{Q}.\n\ |
3372 | 106 @end example\n\ |
10840 | 107 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8421
diff
changeset
|
108 @end ifnottex\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
109 \n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
110 The sparsity preserving permutation is generally returned as a matrix.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
111 However, given the flag @qcode{\"vector\"}, @var{Q} will be returned as a\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
112 vector such that\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
113 @tex\n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
114 $ R^T R = A (Q, Q)$.\n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
115 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8421
diff
changeset
|
116 @ifnottex\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
117 \n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
118 @example\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
119 @var{R}' * @var{R} = @var{A}(@var{Q}, @var{Q}).\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
120 @end example\n\ |
10840 | 121 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8421
diff
changeset
|
122 @end ifnottex\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
123 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
124 Called with either a sparse or full matrix and using the @qcode{\"lower\"}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
125 flag, @code{chol} returns the lower triangular factorization such that\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
126 @tex\n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
127 $ L L^T = A $.\n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
128 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8421
diff
changeset
|
129 @ifnottex\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
130 \n\ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
131 @example\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
132 @var{L} * @var{L}' = @var{A}.\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
133 @end example\n\ |
10840 | 134 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8421
diff
changeset
|
135 @end ifnottex\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
136 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
137 For full matrices, if the @qcode{\"lower\"} flag is set only the lower\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
138 triangular part of the matrix is used for the factorization, otherwise the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
139 upper triangular part is used.\n\ |
13953
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
140 \n\ |
9065
8207b833557f
Cleanup documentation for arith.texi, linalg.texi, nonlin.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
141 In general the lower triangular factorization is significantly faster for\n\ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
142 sparse matrices.\n\ |
19055
38937efbee21
Incorporate new functions ichol and ilu into Octave.
Rik <rik@octave.org>
parents:
18911
diff
changeset
|
143 @seealso{hess, lu, qr, qz, schur, svd, ichol, cholinv, chol2inv, cholupdate, cholinsert, choldelete, cholshift}\n\ |
3372 | 144 @end deftypefn") |
2928 | 145 { |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
146 int nargin = args.length (); |
2928 | 147 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
148 if (nargin < 1 || nargin > 3 || nargout > 3 |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 || (! args(0).is_sparse_type () && nargout > 2)) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
150 print_usage (); |
2928 | 151 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20863
diff
changeset
|
152 bool LLt = false; |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20863
diff
changeset
|
153 bool vecout = false; |
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20863
diff
changeset
|
154 |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
155 int n = 1; |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
156 while (n < nargin) |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
157 { |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
158 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
|
159 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
160 if (tmp == "vector") |
20579
10ec79b47808
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20559
diff
changeset
|
161 vecout = true; |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
162 else if (tmp == "lower") |
20579
10ec79b47808
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20559
diff
changeset
|
163 LLt = true; |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
164 else if (tmp == "upper") |
20579
10ec79b47808
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20559
diff
changeset
|
165 LLt = false; |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
166 else |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20700
diff
changeset
|
167 error ("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
|
168 } |
2928 | 169 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20863
diff
changeset
|
170 octave_value_list retval; |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
171 octave_value arg = args(0); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
172 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
173 octave_idx_type nr = arg.rows (); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
174 octave_idx_type nc = arg.columns (); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
175 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
176 int arg_is_empty = empty_arg ("chol", nr, nc); |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
177 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
178 if (arg_is_empty < 0) |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
179 return ovl (); |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
180 if (arg_is_empty > 0) |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21110
diff
changeset
|
181 return ovl (Matrix ()); |
2928 | 182 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
183 if (arg.is_sparse_type ()) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
184 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
185 octave_idx_type info; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
186 bool natural = (nargout != 3); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
187 bool force = nargout > 1; |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
188 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
189 if (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
190 { |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
191 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
|
192 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
193 sparse_chol<SparseMatrix> fact (m, info, natural, force); |
2928 | 194 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
195 if (nargout == 3) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
196 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
197 if (vecout) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
198 retval(2) = fact.perm (); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
199 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
200 retval(2) = fact.Q (); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
201 } |
2928 | 202 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20863
diff
changeset
|
203 if (nargout >= 2 || info == 0) |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
204 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
205 retval(1) = info; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
206 if (LLt) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
207 retval(0) = fact.L (); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
208 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
209 retval(0) = fact.R (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
210 } |
20559
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 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
|
213 } |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
214 else if (arg.is_complex_type ()) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
215 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
216 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
|
217 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
218 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
|
219 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
220 if (nargout == 3) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
221 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
222 if (vecout) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
223 retval(2) = fact.perm (); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
224 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
225 retval(2) = fact.Q (); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
226 } |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
227 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20863
diff
changeset
|
228 if (nargout >= 2 || info == 0) |
20559
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 retval(1) = info; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
231 if (LLt) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
232 retval(0) = fact.L (); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
233 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
234 retval(0) = fact.R (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
235 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
236 else |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
237 error ("chol: input matrix must be positive definite"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
238 } |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
239 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
240 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
|
241 } |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
242 else if (arg.is_single_type ()) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
243 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
244 if (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
245 { |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
246 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
|
247 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
248 octave_idx_type info; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7700
diff
changeset
|
249 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
250 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
|
251 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
252 if (nargout == 2 || info == 0) |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
253 retval = ovl (get_chol (fact), info); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
254 else |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
255 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
|
256 } |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
257 else if (arg.is_complex_type ()) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
258 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
259 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
|
260 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
261 octave_idx_type info; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
262 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
263 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
|
264 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
265 if (nargout == 2 || info == 0) |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
266 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
|
267 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
268 error ("chol: input matrix must be positive definite"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
269 } |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
270 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
271 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
|
272 } |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
273 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
274 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
275 if (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
276 { |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
277 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
|
278 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
279 octave_idx_type info; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
280 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
281 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
|
282 |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
283 if (nargout == 2 || info == 0) |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
284 retval = ovl (get_chol (fact), info); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
285 else |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
286 error ("chol: input matrix must be positive definite"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
287 } |
20559
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
288 else if (arg.is_complex_type ()) |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
289 { |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
290 ComplexMatrix m = arg.complex_matrix_value (); |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
291 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
292 octave_idx_type info; |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
293 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
294 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
|
295 |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
296 if (nargout == 2 || info == 0) |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
297 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
|
298 else |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
299 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
|
300 } |
0650b8431037
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20462
diff
changeset
|
301 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
302 err_wrong_type_arg ("chol", arg); |
2928 | 303 } |
304 | |
305 return retval; | |
306 } | |
307 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
308 /* |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
309 %!assert (chol ([2, 1; 1, 1]), [sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)], sqrt (eps)) |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
310 %!assert (chol (single ([2, 1; 1, 1])), single ([sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)]), sqrt (eps ("single"))) |
18886
534511deb10e
Use %!testif HAVE_CHOLMOD for sparse chol test added in cset 161b11e7da2d
Mike Miller <mtmiller@ieee.org>
parents:
18845
diff
changeset
|
311 %!testif HAVE_CHOLMOD |
18845
161b11e7da2d
Return error code from sparse chol factorization (bug #42587).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
312 %! ## Bug #42587 |
161b11e7da2d
Return error code from sparse chol factorization (bug #42587).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
313 %! 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
|
314 %! [Q, p] = chol (A); |
161b11e7da2d
Return error code from sparse chol factorization (bug #42587).
Rik <rik@octave.org>
parents:
17861
diff
changeset
|
315 %! 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
|
316 |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
317 %!error chol () |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
318 %!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
|
319 %!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
|
320 %!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
|
321 %!error <optional argument must be one of "vector", "lower"> chol (1, "foobar") |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
322 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
323 |
5760 | 324 DEFUN_DLD (cholinv, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
325 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
326 @deftypefn {} {} cholinv (@var{A})\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
327 Compute the inverse of the symmetric positive definite matrix @var{A} using\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
328 the Cholesky@tie{}factorization.\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
329 @seealso{chol, chol2inv, inv}\n\ |
5340 | 330 @end deftypefn") |
331 { | |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20816
diff
changeset
|
332 if (args.length () != 1) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
333 print_usage (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
334 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
335 octave_value retval; |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
336 octave_value arg = args(0); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
337 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
338 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
|
339 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
|
340 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
341 if (nr == 0 || nc == 0) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
342 retval = Matrix (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
343 else |
5340 | 344 { |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
345 if (arg.is_sparse_type ()) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
346 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
347 octave_idx_type info; |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
348 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
349 if (arg.is_real_type ()) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
350 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
351 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
|
352 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
353 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
|
354 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
355 if (info == 0) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
356 retval = chol.inverse (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
357 else |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
358 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
|
359 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
360 else if (arg.is_complex_type ()) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
361 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
362 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
|
363 |
21145
307096fb67e1
revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
364 sparse_chol<SparseComplexMatrix> chol (m, info); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
365 |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
366 if (info == 0) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
367 retval = chol.inverse (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
368 else |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
369 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
|
370 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
371 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
372 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
|
373 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
374 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
|
375 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
376 if (arg.is_real_type ()) |
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 FloatMatrix m = arg.float_matrix_value (); |
5340 | 379 |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
380 octave_idx_type info; |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
381 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
|
382 if (info == 0) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
383 retval = chol.inverse (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
384 else |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
385 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
|
386 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
387 else if (arg.is_complex_type ()) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
388 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
389 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
|
390 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
391 octave_idx_type info; |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
392 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
|
393 if (info == 0) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
394 retval = chol.inverse (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
395 else |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
396 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
|
397 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
398 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
399 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
|
400 } |
5340 | 401 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
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 (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
404 { |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
405 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
|
406 |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
407 octave_idx_type info; |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
408 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
|
409 if (info == 0) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
410 retval = chol.inverse (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
411 else |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
412 error ("cholinv: A must be positive definite"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
413 } |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
414 else if (arg.is_complex_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
415 { |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
416 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
|
417 |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
418 octave_idx_type info; |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
419 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
|
420 if (info == 0) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
421 retval = chol.inverse (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
422 else |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
423 error ("cholinv: A must be positive definite"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
424 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
425 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
426 err_wrong_type_arg ("chol", arg); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
427 } |
5340 | 428 } |
429 | |
430 return retval; | |
431 } | |
432 | |
8402
2176f2b4599e
Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents:
8284
diff
changeset
|
433 /* |
8871 | 434 %!shared A, Ainv |
8402
2176f2b4599e
Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents:
8284
diff
changeset
|
435 %! 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
|
436 %! Ainv = inv (A); |
8871 | 437 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
438 %! Ainv1 = cholinv (A); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
439 %! assert (norm (Ainv-Ainv1), 0, 1e-10); |
8871 | 440 %!testif HAVE_CHOLMOD |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
441 %! Ainv2 = inv (sparse (A)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
442 %! 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
|
443 %!testif HAVE_CHOLMOD |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
444 %! Ainv3 = cholinv (sparse (A)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
445 %! assert (norm (Ainv-Ainv3), 0, 1e-10); |
8402
2176f2b4599e
Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents:
8284
diff
changeset
|
446 */ |
2176f2b4599e
Fix sparse cholesky inversion
David Bateman <dbateman@free.fr>
parents:
8284
diff
changeset
|
447 |
5760 | 448 DEFUN_DLD (chol2inv, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
449 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
450 @deftypefn {} {} chol2inv (@var{U})\n\ |
5340 | 451 Invert a symmetric, positive definite square matrix from its Cholesky\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
452 decomposition, @var{U}.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
453 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
454 Note that @var{U} should be an upper-triangular matrix with positive\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
455 diagonal elements. @code{chol2inv (@var{U})} provides\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
456 @code{inv (@var{U}'*@var{U})} but it is much faster than using @code{inv}.\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
457 @seealso{chol, cholinv, inv}\n\ |
5340 | 458 @end deftypefn") |
459 { | |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20816
diff
changeset
|
460 if (args.length () != 1) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
461 print_usage (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
462 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
463 octave_value retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
464 |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
465 octave_value arg = args(0); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
466 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
467 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
|
468 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
|
469 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
470 if (nr == 0 || nc == 0) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
471 retval = Matrix (); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
472 else |
5340 | 473 { |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
474 if (arg.is_sparse_type ()) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
475 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
476 if (arg.is_real_type ()) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
477 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
478 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
|
479 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
480 retval = chol2inv (r); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
481 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
482 else if (arg.is_complex_type ()) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
483 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
484 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
|
485 |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
486 retval = chol2inv (r); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
487 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
488 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
489 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
|
490 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
491 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
|
492 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
493 if (arg.is_real_type ()) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
494 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
495 FloatMatrix r = arg.float_matrix_value (); |
5340 | 496 |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
497 retval = chol2inv (r); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
498 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
499 else if (arg.is_complex_type ()) |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
500 { |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
501 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
|
502 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
503 retval = chol2inv (r); |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
504 } |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
505 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
506 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
|
507 |
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
508 } |
5340 | 509 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
510 { |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
511 if (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
512 { |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
513 Matrix r = arg.matrix_value (); |
5340 | 514 |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
515 retval = chol2inv (r); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
516 } |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
517 else if (arg.is_complex_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
518 { |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
519 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
|
520 |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
521 retval = chol2inv (r); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
522 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
523 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20941
diff
changeset
|
524 err_wrong_type_arg ("chol2inv", arg); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9862
diff
changeset
|
525 } |
5340 | 526 } |
527 | |
528 return retval; | |
529 } | |
530 | |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
531 DEFUN_DLD (cholupdate, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
532 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
533 @deftypefn {} {[@var{R1}, @var{info}] =} cholupdate (@var{R}, @var{u}, @var{op})\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
534 Update or downdate a Cholesky@tie{}factorization.\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
535 \n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
536 Given an upper triangular matrix @var{R} and a column vector @var{u},\n\ |
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
537 attempt to determine another upper triangular matrix @var{R1} such that\n\ |
14620
cd375519eab0
doc: Periodic grammar check of documentation
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
538 \n\ |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
539 @itemize @bullet\n\ |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
540 @item\n\ |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
541 @var{R1}'*@var{R1} = @var{R}'*@var{R} + @var{u}*@var{u}'\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
542 if @var{op} is @qcode{\"+\"}\n\ |
10840 | 543 \n\ |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
544 @item\n\ |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
545 @var{R1}'*@var{R1} = @var{R}'*@var{R} - @var{u}*@var{u}'\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
546 if @var{op} is @qcode{\"-\"}\n\ |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
547 @end itemize\n\ |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
548 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16920
diff
changeset
|
549 If @var{op} is @qcode{\"-\"}, @var{info} is set to\n\ |
14620
cd375519eab0
doc: Periodic grammar check of documentation
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
550 \n\ |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
551 @itemize\n\ |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
552 @item 0 if the downdate was successful,\n\ |
10840 | 553 \n\ |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
554 @item 1 if @var{R}'*@var{R} - @var{u}*@var{u}' is not positive definite,\n\ |
10840 | 555 \n\ |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
556 @item 2 if @var{R} is singular.\n\ |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
557 @end itemize\n\ |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
558 \n\ |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
559 If @var{info} is not present, an error message is printed in cases 1 and 2.\n\ |
16920
53eaa83e4181
doc: Add seealso links between various factorization forms.
Rik <rik@octave.org>
parents:
15264
diff
changeset
|
560 @seealso{chol, cholinsert, choldelete, cholshift}\n\ |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
561 @end deftypefn") |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
562 { |
20816
b16bcd7a2a33
Use int rather than octave_idx_type for nargin data type.
Rik <rik@octave.org>
parents:
20812
diff
changeset
|
563 int nargin = args.length (); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
564 |
20898
8da80da1ac37
maint: Use ovl() more places in the code.
Rik <rik@octave.org>
parents:
20863
diff
changeset
|
565 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
|
566 print_usage (); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
567 |
7559
07522d7dcdf8
fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents:
7554
diff
changeset
|
568 octave_value argr = args(0); |
07522d7dcdf8
fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents:
7554
diff
changeset
|
569 octave_value argu = args(1); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
570 |
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
|
571 if (! argr.is_numeric_type () || ! argu.is_numeric_type () |
0828bf20d105
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
572 || (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
|
573 print_usage (); |
7559
07522d7dcdf8
fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents:
7554
diff
changeset
|
574 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
575 octave_value_list retval (nargout == 2 ? 2 : 1); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
576 |
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
|
577 octave_idx_type n = argr.rows (); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
578 |
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
|
579 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
|
580 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
581 bool down = (op == "-"); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
582 |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
583 if (! down && op != "+") |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
584 error ("cholupdate: OP must be \"+\" or \"-\""); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
585 |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
586 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
|
587 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
|
588 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
589 int err = 0; |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
590 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
|
591 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
592 if (argr.is_real_type () && argu.is_real_type ()) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
593 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
594 // real case |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
595 FloatMatrix R = argr.float_matrix_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
596 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
|
597 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
598 chol<FloatMatrix> fact; |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
599 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
|
600 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
601 if (down) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
602 err = fact.downdate (u); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
603 else |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
604 fact.update (u); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
605 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
606 retval = ovl (get_chol_r (fact)); |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
607 } |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
608 else |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
609 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
610 // complex case |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
611 FloatComplexMatrix R = argr.float_complex_matrix_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
612 FloatComplexColumnVector u = |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
613 argu.float_complex_column_vector_value (); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
614 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
615 chol<FloatComplexMatrix> fact; |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
616 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
|
617 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
618 if (down) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
619 err = fact.downdate (u); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
620 else |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
621 fact.update (u); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
622 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
623 retval = ovl (get_chol_r (fact)); |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
624 } |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
625 } |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
626 else |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
627 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
628 if (argr.is_real_type () && argu.is_real_type ()) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
629 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
630 // real case |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
631 Matrix R = argr.matrix_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
632 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
|
633 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
634 chol<Matrix> fact; |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
635 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
|
636 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
637 if (down) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
638 err = fact.downdate (u); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
639 else |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
640 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
|
641 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
642 retval = ovl (get_chol_r (fact)); |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
643 } |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
644 else |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
645 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
646 // complex case |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
647 ComplexMatrix R = argr.complex_matrix_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
648 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
|
649 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
650 chol<ComplexMatrix> fact; |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
651 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
|
652 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
653 if (down) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
654 err = fact.downdate (u); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
655 else |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
656 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
|
657 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
658 retval = ovl (get_chol_r (fact)); |
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 } |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
661 |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
662 if (nargout > 1) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
663 retval(1) = err; |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
664 else if (err == 1) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
665 error ("cholupdate: downdate violates positiveness"); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
666 else if (err == 2) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
667 error ("cholupdate: singular matrix"); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
668 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
669 return retval; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
670 } |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
671 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
672 /* |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
673 %!shared A, u, Ac, uc |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
674 %! A = [ 0.436997 -0.131721 0.124120 -0.061673 ; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
675 %! -0.131721 0.738529 0.019851 -0.140295 ; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
676 %! 0.124120 0.019851 0.354879 -0.059472 ; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
677 %! -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
|
678 %! |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
679 %! u = [ 0.98950 ; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
680 %! 0.39844 ; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
681 %! 0.63484 ; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
682 %! 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
|
683 %! 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
|
684 %! -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
|
685 %! 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
|
686 %! -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
|
687 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
688 %! 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
|
689 %! 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
|
690 %! 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
|
691 %! 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
|
692 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
693 %!test |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
694 %! R = chol (A); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
695 %! R1 = cholupdate (R, u); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
696 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
697 %! assert (norm (R1'*R1 - R'*R - u*u', Inf) < 1e1*eps); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
698 %! |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
699 %! R1 = cholupdate (R1, u, "-"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
700 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
701 %! assert (norm (R1 - R, Inf) < 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
|
702 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
703 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
704 %! R = chol (Ac); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
705 %! R1 = cholupdate (R, uc); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
706 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
707 %! assert (norm (R1'*R1 - R'*R - uc*uc', Inf) < 1e1*eps); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
708 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
709 %! R1 = cholupdate (R1, uc, "-"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
710 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
711 %! assert (norm (R1 - R, Inf) < 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
|
712 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
713 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
714 %! R = chol (single (A)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
715 %! 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
|
716 %! assert (norm (triu (R1)-R1, Inf), single (0)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
717 %! assert (norm (R1'*R1 - R'*R - single (u*u'), Inf) < 1e1*eps ("single")); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
718 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
719 %! 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
|
720 %! assert (norm (triu (R1)-R1, Inf), single (0)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
721 %! assert (norm (R1 - R, Inf) < 2e1*eps ("single")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
722 |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
723 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
724 %! R = chol (single (Ac)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
725 %! 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
|
726 %! assert (norm (triu (R1)-R1, Inf), single (0)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
727 %! assert (norm (R1'*R1 - R'*R - single (uc*uc'), Inf) < 1e1*eps ("single")); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
728 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
729 %! 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
|
730 %! assert (norm (triu (R1)-R1, Inf), single (0)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
731 %! assert (norm (R1 - R, Inf) < 2e1*eps ("single")); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
732 */ |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7515
diff
changeset
|
733 |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
734 DEFUN_DLD (cholinsert, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
735 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
736 @deftypefn {} {@var{R1} =} cholinsert (@var{R}, @var{j}, @var{u})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
737 @deftypefnx {} {[@var{R1}, @var{info}] =} cholinsert (@var{R}, @var{j}, @var{u})\n\ |
10840 | 738 Given a Cholesky@tie{}factorization of a real symmetric or complex Hermitian\n\ |
739 positive definite matrix @w{@var{A} = @var{R}'*@var{R}}, @var{R}@tie{}upper\n\ | |
740 triangular, return the Cholesky@tie{}factorization of\n\ | |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
741 @var{A1}, where @w{A1(p,p) = A}, @w{A1(:,j) = A1(j,:)' = u} and\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8880
diff
changeset
|
742 @w{p = [1:j-1,j+1:n+1]}. @w{u(j)} should be positive.\n\ |
20163
075a5e2e1ba5
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
743 \n\ |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
744 On return, @var{info} is set to\n\ |
14620
cd375519eab0
doc: Periodic grammar check of documentation
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
745 \n\ |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
746 @itemize\n\ |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
747 @item 0 if the insertion was successful,\n\ |
10840 | 748 \n\ |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
749 @item 1 if @var{A1} is not positive definite,\n\ |
10840 | 750 \n\ |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
751 @item 2 if @var{R} is singular.\n\ |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
752 @end itemize\n\ |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
753 \n\ |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
754 If @var{info} is not present, an error message is printed in cases 1 and 2.\n\ |
16920
53eaa83e4181
doc: Add seealso links between various factorization forms.
Rik <rik@octave.org>
parents:
15264
diff
changeset
|
755 @seealso{chol, cholupdate, choldelete, cholshift}\n\ |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
756 @end deftypefn") |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
757 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20816
diff
changeset
|
758 if (args.length () != 3) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
759 print_usage (); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
760 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
761 octave_value argr = args(0); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
762 octave_value argj = args(1); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
763 octave_value argu = args(2); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
764 |
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
|
765 if (! argr.is_numeric_type () || ! argu.is_numeric_type () |
0828bf20d105
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
766 || ! 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
|
767 print_usage (); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
768 |
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
|
769 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
|
770 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
|
771 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
772 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
|
773 error ("cholinsert: dimension mismatch between R and U"); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
774 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
775 if (j < 1 || j > n+1) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
776 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
|
777 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
778 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
|
779 |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
780 int err = 0; |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
781 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
|
782 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
783 if (argr.is_real_type () && argu.is_real_type ()) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
784 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
785 // real case |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
786 FloatMatrix R = argr.float_matrix_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
787 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
|
788 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
789 chol<FloatMatrix> fact; |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
790 fact.set (R); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
791 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
|
792 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
793 retval = ovl (get_chol_r (fact)); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
794 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
795 else |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
796 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
797 // complex case |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
798 FloatComplexMatrix R = argr.float_complex_matrix_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
799 FloatComplexColumnVector u = |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
800 argu.float_complex_column_vector_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
801 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
802 chol<FloatComplexMatrix> fact; |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
803 fact.set (R); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
804 err = fact.insert_sym (u, j-1); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
805 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
806 retval = ovl (get_chol_r (fact)); |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
807 } |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
808 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
809 else |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
810 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
811 if (argr.is_real_type () && argu.is_real_type ()) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
812 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
813 // real case |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
814 Matrix R = argr.matrix_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
815 ColumnVector u = argu.column_vector_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
816 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
817 chol<Matrix> fact; |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
818 fact.set (R); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
819 err = fact.insert_sym (u, j-1); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
820 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
821 retval = ovl (get_chol_r (fact)); |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
822 } |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
823 else |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
824 { |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
825 // complex case |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
826 ComplexMatrix R = argr.complex_matrix_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
827 ComplexColumnVector u = |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
828 argu.complex_column_vector_value (); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
829 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
830 chol<ComplexMatrix> fact; |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
831 fact.set (R); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
832 err = fact.insert_sym (u, j-1); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
833 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
834 retval = ovl (get_chol_r (fact)); |
20863
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
835 } |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
836 } |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
837 |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
838 if (nargout > 1) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
839 retval(1) = err; |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
840 else if (err == 1) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
841 error ("cholinsert: insertion violates positiveness"); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
842 else if (err == 2) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
843 error ("cholinsert: singular matrix"); |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
844 else if (err == 3) |
e81276e8f481
2015 Code Sprint: chol.cc: use ovl().
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
845 error ("cholinsert: diagonal element must be real"); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
846 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
847 return retval; |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
848 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
849 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
850 /* |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
851 %!test |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
852 %! 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
|
853 %! 0.63930 ; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
854 %! 3.31057 ; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
855 %! -0.13825 ; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
856 %! 0.45266 ]; |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
857 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
858 %! R = chol (A); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
859 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
860 %! 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
|
861 %! 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
|
862 %! A1 = R1'*R1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
863 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
864 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
865 %! assert (norm (A1(p,p) - A, Inf) < 1e1*eps); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
866 |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
867 %!test |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
868 %! 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
|
869 %! 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
|
870 %! 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
|
871 %! -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
|
872 %! 0.45266 + 0.50020i]; |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
873 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
874 %! R = chol (Ac); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
875 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
876 %! 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
|
877 %! 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
|
878 %! A1 = R1'*R1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
879 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
880 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
881 %! assert (norm (A1(p,p) - Ac, Inf) < 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
|
882 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
883 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
884 %! 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
|
885 %! 0.63930 ; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
886 %! 3.31057 ; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
887 %! -0.13825 ; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
888 %! 0.45266 ]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
889 %! |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
890 %! R = chol (single (A)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
891 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
892 %! 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
|
893 %! 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
|
894 %! A1 = R1'*R1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
895 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
896 %! assert (norm (triu (R1)-R1, Inf), single (0)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
897 %! assert (norm (A1(p,p) - A, Inf) < 1e1*eps ("single")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
898 |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
899 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
900 %! 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
|
901 %! 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
|
902 %! 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
|
903 %! -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
|
904 %! 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
|
905 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
906 %! R = chol (single (Ac)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
907 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
908 %! 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
|
909 %! 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
|
910 %! A1 = R1'*R1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
911 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
912 %! assert (norm (triu (R1)-R1, Inf), single (0)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
913 %! assert (norm (A1(p,p) - single (Ac), Inf) < 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
|
914 |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
915 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
916 %! 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
|
917 %! 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
|
918 %! assert (cu, cl', eps); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
919 |
13953
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
920 %!test |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
921 %! cca = chol (Ac); |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
922 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
923 %! ccal = chol (Ac, "lower"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
924 %! 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
|
925 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
926 %! ccau = chol (Ac, "upper"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
927 %! 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
|
928 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
929 %! 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
|
930 %! 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
|
931 %! 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
|
932 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
933 %! assert (cca, ccal', eps); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
934 %! assert (cca, ccau, eps); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
935 %! assert (cca, ccal2', eps); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
936 %! assert (cca, ccau2, eps); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
937 |
13953
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
938 %!test |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
939 %! cca = chol (single (Ac)); |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
940 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
941 %! 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
|
942 %! 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
|
943 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
944 %! 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
|
945 %! 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
|
946 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
947 %! 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
|
948 %! 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
|
949 %! 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
|
950 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
951 %! 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
|
952 %! 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
|
953 %! 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
|
954 %! 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
|
955 |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
956 %!test |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
957 %! 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
|
958 %! 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
|
959 %! 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
|
960 %! 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
|
961 %! |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
962 %! 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
|
963 %! -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
|
964 %! -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
|
965 %! -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
|
966 %! |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
967 %! ca = a + i*b; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
968 %! |
13953
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
969 %! cca = chol (ca); |
642e43164af6
fix behavior of chol (..., 'lower') to be compatible with matlab
Carlo de Falco <kingcrimson@tiscali.it>
parents:
13915
diff
changeset
|
970 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
971 %! ccal = chol (ca, "lower"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
972 %! 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
|
973 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
974 %! ccau = chol (ca, "upper"); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
975 %! 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
|
976 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
977 %! 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
|
978 %! 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
|
979 %! 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
|
980 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
981 %! 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
|
982 %! 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
|
983 %! 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
|
984 %! assert (cca, ccau2, 16*eps); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
985 */ |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
986 |
7924 | 987 DEFUN_DLD (choldelete, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
988 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
989 @deftypefn {} {@var{R1} =} choldelete (@var{R}, @var{j})\n\ |
10840 | 990 Given a Cholesky@tie{}factorization of a real symmetric or complex Hermitian\n\ |
991 positive definite matrix @w{@var{A} = @var{R}'*@var{R}}, @var{R}@tie{}upper\n\ | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
992 triangular, return the Cholesky@tie{}factorization of @w{A(p,p)}, where\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
993 @w{p = [1:j-1,j+1:n+1]}.\n\ |
16920
53eaa83e4181
doc: Add seealso links between various factorization forms.
Rik <rik@octave.org>
parents:
15264
diff
changeset
|
994 @seealso{chol, cholupdate, cholinsert, cholshift}\n\ |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
995 @end deftypefn") |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
996 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20816
diff
changeset
|
997 if (args.length () != 2) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
998 print_usage (); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
999 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1000 octave_value argr = args(0); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1001 octave_value argj = args(1); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1002 |
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
|
1003 if (! argr.is_numeric_type () || ! 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
|
1004 print_usage (); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1005 |
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
|
1006 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
|
1007 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
|
1008 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1009 if (argr.columns () != n) |
21110
3d0d84305600
Use err_square_matrix_required more widely.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1010 err_square_matrix_required ("choldelete", "R"); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1011 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1012 if (j < 0 && j > n) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1013 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
|
1014 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1015 octave_value_list retval; |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1016 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1017 if (argr.is_single_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1018 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1019 if (argr.is_real_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1020 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1021 // real case |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1022 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
|
1023 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1024 chol<FloatMatrix> fact; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1025 fact.set (R); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1026 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
|
1027 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1028 retval = ovl (get_chol_r (fact)); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1029 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1030 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1031 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1032 // complex case |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1033 FloatComplexMatrix R = argr.float_complex_matrix_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1034 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1035 chol<FloatComplexMatrix> fact; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1036 fact.set (R); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1037 fact.delete_sym (j-1); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1038 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1039 retval = ovl (get_chol_r (fact)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1040 } |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1041 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1042 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1043 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1044 if (argr.is_real_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1045 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1046 // real case |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1047 Matrix R = argr.matrix_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1048 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1049 chol<Matrix> fact; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1050 fact.set (R); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1051 fact.delete_sym (j-1); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1052 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1053 retval = ovl (get_chol_r (fact)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1054 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1055 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1056 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1057 // complex case |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1058 ComplexMatrix R = argr.complex_matrix_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1059 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1060 chol<ComplexMatrix> fact; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1061 fact.set (R); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1062 fact.delete_sym (j-1); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1063 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1064 retval = ovl (get_chol_r (fact)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1065 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1066 } |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1067 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1068 return retval; |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1069 } |
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 /* |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1072 %!test |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1073 %! R = chol (A); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1074 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1075 %! 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
|
1076 %! R1 = choldelete (R, j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1077 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1078 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1079 %! assert (norm (R1'*R1 - A(p,p), Inf) < 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
|
1080 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
1081 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1082 %! R = chol (Ac); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1083 %! |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1084 %! 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
|
1085 %! R1 = choldelete (R, j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1086 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1087 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1088 %! assert (norm (R1'*R1 - Ac(p,p), Inf) < 1e1*eps); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1089 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1090 %!test |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1091 %! R = chol (single (A)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1092 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1093 %! 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
|
1094 %! R1 = choldelete (R, j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1095 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1096 %! assert (norm (triu (R1)-R1, Inf), single (0)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1097 %! assert (norm (R1'*R1 - single (A(p,p)), Inf) < 1e1*eps ("single")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1098 |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
1099 %!test |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1100 %! R = chol (single (Ac)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1101 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1102 %! 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
|
1103 %! R1 = choldelete (R,j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1104 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1105 %! assert (norm (triu (R1)-R1, Inf), single (0)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1106 %! assert (norm (R1'*R1 - single (Ac(p,p)), Inf) < 1e1*eps ("single")); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1107 */ |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1108 |
7924 | 1109 DEFUN_DLD (cholshift, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1110 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20851
diff
changeset
|
1111 @deftypefn {} {@var{R1} =} cholshift (@var{R}, @var{i}, @var{j})\n\ |
10840 | 1112 Given a Cholesky@tie{}factorization of a real symmetric or complex Hermitian\n\ |
1113 positive definite matrix @w{@var{A} = @var{R}'*@var{R}}, @var{R}@tie{}upper\n\ | |
1114 triangular, return the Cholesky@tie{}factorization of\n\ | |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1115 @w{@var{A}(p,p)}, where @w{p} is the permutation @*\n\ |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1116 @code{p = [1:i-1, shift(i:j, 1), j+1:n]} if @w{@var{i} < @var{j}} @*\n\ |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1117 or @*\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8880
diff
changeset
|
1118 @code{p = [1:j-1, shift(j:i,-1), i+1:n]} if @w{@var{j} < @var{i}}. @*\n\ |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1119 \n\ |
16920
53eaa83e4181
doc: Add seealso links between various factorization forms.
Rik <rik@octave.org>
parents:
15264
diff
changeset
|
1120 @seealso{chol, cholupdate, cholinsert, choldelete}\n\ |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1121 @end deftypefn") |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1122 { |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20816
diff
changeset
|
1123 if (args.length () != 3) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20711
diff
changeset
|
1124 print_usage (); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1125 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1126 octave_value argr = args(0); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1127 octave_value argi = args(1); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1128 octave_value argj = args(2); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1129 |
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
|
1130 if (! argr.is_numeric_type () || ! argi.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
|
1131 || ! 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
|
1132 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
|
1133 |
0828bf20d105
maint: Refactor C++ calls to print_usage to resemble m-files (2015 code sprint)
Mike Miller <mtmiller@octave.org>
parents:
20818
diff
changeset
|
1134 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
|
1135 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
|
1136 octave_idx_type j = argj.scalar_value (); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1137 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1138 if (argr.columns () != n) |
21110
3d0d84305600
Use err_square_matrix_required more widely.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
1139 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
|
1140 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1141 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
|
1142 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
|
1143 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1144 octave_value_list retval; |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1145 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1146 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
|
1147 && argj.is_single_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1148 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1149 if (argr.is_real_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1150 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1151 // real case |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1152 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
|
1153 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1154 chol<FloatMatrix> fact; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1155 fact.set (R); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1156 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
|
1157 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1158 retval = ovl (get_chol_r (fact)); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1159 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1160 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1161 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1162 // complex case |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1163 FloatComplexMatrix R = argr.float_complex_matrix_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1164 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1165 chol<FloatComplexMatrix> fact; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1166 fact.set (R); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1167 fact.shift_sym (i-1, j-1); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1168 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1169 retval = ovl (get_chol_r (fact)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1170 } |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1171 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1172 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1173 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1174 if (argr.is_real_type ()) |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1175 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1176 // real case |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1177 Matrix R = argr.matrix_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1178 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1179 chol<Matrix> fact; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1180 fact.set (R); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1181 fact.shift_sym (i-1, j-1); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1182 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1183 retval = ovl (get_chol_r (fact)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1184 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1185 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1186 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1187 // complex case |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1188 ComplexMatrix R = argr.complex_matrix_value (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1189 |
21269
3c8a3d35661a
better use of templates for Cholesky factorization
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
1190 chol<ComplexMatrix> fact; |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1191 fact.set (R); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1192 fact.shift_sym (i-1, j-1); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1193 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1194 retval = ovl (get_chol_r (fact)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1195 } |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20898
diff
changeset
|
1196 } |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1197 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1198 return retval; |
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 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1201 /* |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1202 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1203 %! R = chol (A); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1204 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1205 %! i = 1; j = 3; p = [1:i-1, shift(i: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
|
1206 %! R1 = cholshift (R, i, j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1207 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1208 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1209 %! assert (norm (R1'*R1 - A(p,p), Inf) < 1e1*eps); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1210 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1211 %! j = 1; i = 3; p = [1:j-1, shift(j:i,+1), i+1:4]; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1212 %! R1 = cholshift (R, i, j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1213 %! |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1214 %! assert (norm (triu (R1) - R1, Inf), 0); |
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1215 %! assert (norm (R1'*R1 - A(p,p), Inf) < 1e1*eps); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1216 |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1217 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1218 %! R = chol (Ac); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1219 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1220 %! i = 1; j = 3; p = [1:i-1, shift(i: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
|
1221 %! R1 = cholshift (R, i, j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1222 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1223 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1224 %! assert (norm (R1'*R1 - Ac(p,p), Inf) < 1e1*eps); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1225 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1226 %! j = 1; i = 3; p = [1:j-1, shift(j:i,+1), i+1:4]; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1227 %! R1 = cholshift (R, i, j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1228 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1229 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1230 %! assert (norm (R1'*R1 - Ac(p,p), Inf) < 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
|
1231 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
1232 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1233 %! R = chol (single (A)); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1234 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1235 %! i = 1; j = 3; p = [1:i-1, shift(i: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
|
1236 %! 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
|
1237 %! |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1238 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1239 %! assert (norm (R1'*R1 - single (A(p,p)), Inf) < 1e1*eps ("single")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1240 %! |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1241 %! j = 1; i = 3; p = [1:j-1, shift(j:i,+1), i+1:4]; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1242 %! R1 = cholshift (R, i, j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1243 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1244 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1245 %! assert (norm (R1'*R1 - single (A(p,p)), Inf) < 1e1*eps ("single")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1246 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1247 %!test |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1248 %! R = chol (single (Ac)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1249 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1250 %! i = 1; j = 3; p = [1:i-1, shift(i: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
|
1251 %! 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
|
1252 %! |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1253 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1254 %! assert (norm (R1'*R1 - single (Ac(p,p)), Inf) < 1e1*eps ("single")); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1255 %! |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1256 %! j = 1; i = 3; p = [1:j-1, shift(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
|
1257 %! R1 = cholshift (R, i, j); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1258 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1259 %! assert (norm (triu (R1)-R1, Inf), 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1260 %! assert (norm (R1'*R1 - single (Ac(p,p)), Inf) < 1e1*eps ("single")); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7650
diff
changeset
|
1261 */ |