annotate libinterp/dldfcn/chol.cc @ 23581:c3075ae020e1

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