Mercurial > hg > octave-nkf
annotate liboctave/CmplxCHOL.cc @ 8377:25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 29 Oct 2008 16:52:10 +0100 |
parents | 7c9ba697a479 |
children | d66c9b6e506a |
rev | line source |
---|---|
457 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2007 |
4 John W. Eaton | |
457 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
457 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
457 | 21 |
22 */ | |
23 | |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
24 // updating/downdating by Jaroslav Hajek 2008 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
25 |
457 | 26 #ifdef HAVE_CONFIG_H |
1192 | 27 #include <config.h> |
457 | 28 #endif |
29 | |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
30 #include <vector> |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
31 |
6486 | 32 #include "dMatrix.h" |
33 #include "dRowVector.h" | |
457 | 34 #include "CmplxCHOL.h" |
1847 | 35 #include "f77-fcn.h" |
457 | 36 #include "lo-error.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7725
diff
changeset
|
37 #include "oct-locbuf.h" |
457 | 38 |
39 extern "C" | |
40 { | |
4552 | 41 F77_RET_T |
5340 | 42 F77_FUNC (zpotrf, ZPOTRF) (F77_CONST_CHAR_ARG_DECL, const octave_idx_type&, |
43 Complex*, const octave_idx_type&, octave_idx_type& | |
44 F77_CHAR_ARG_LEN_DECL); | |
45 F77_RET_T | |
46 F77_FUNC (zpotri, ZPOTRI) (F77_CONST_CHAR_ARG_DECL, const octave_idx_type&, | |
47 Complex*, const octave_idx_type&, octave_idx_type& | |
4552 | 48 F77_CHAR_ARG_LEN_DECL); |
6486 | 49 |
50 F77_RET_T | |
51 F77_FUNC (zpocon, ZPOCON) (F77_CONST_CHAR_ARG_DECL, const octave_idx_type&, | |
52 Complex*, const octave_idx_type&, const double&, | |
53 double&, Complex*, double*, | |
54 octave_idx_type& F77_CHAR_ARG_LEN_DECL); | |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
55 F77_RET_T |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
56 F77_FUNC (zch1up, ZCH1UP) (const octave_idx_type&, Complex*, Complex*, double*); |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
57 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
58 F77_RET_T |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
59 F77_FUNC (zch1dn, ZCH1DN) (const octave_idx_type&, Complex*, Complex*, double*, |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
60 octave_idx_type&); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
61 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
62 F77_RET_T |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
63 F77_FUNC (zqrshc, ZQRSHC) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&, |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
64 Complex*, Complex*, const octave_idx_type&, const octave_idx_type&); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
65 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
66 F77_RET_T |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
67 F77_FUNC (zchinx, ZCHINX) (const octave_idx_type&, const Complex*, Complex*, const octave_idx_type&, |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
68 const Complex*, octave_idx_type&); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
69 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
70 F77_RET_T |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
71 F77_FUNC (zchdex, ZCHDEX) (const octave_idx_type&, const Complex*, Complex*, const octave_idx_type&); |
457 | 72 } |
73 | |
5275 | 74 octave_idx_type |
6486 | 75 ComplexCHOL::init (const ComplexMatrix& a, bool calc_cond) |
457 | 76 { |
5275 | 77 octave_idx_type a_nr = a.rows (); |
78 octave_idx_type a_nc = a.cols (); | |
457 | 79 |
1944 | 80 if (a_nr != a_nc) |
81 { | |
82 (*current_liboctave_error_handler) | |
83 ("ComplexCHOL requires square matrix"); | |
84 return -1; | |
85 } | |
457 | 86 |
5275 | 87 octave_idx_type n = a_nc; |
88 octave_idx_type info; | |
1944 | 89 |
90 chol_mat = a; | |
91 Complex *h = chol_mat.fortran_vec (); | |
457 | 92 |
6486 | 93 // Calculate the norm of the matrix, for later use. |
94 double anorm = 0; | |
95 if (calc_cond) | |
96 anorm = chol_mat.abs().sum().row(static_cast<octave_idx_type>(0)).max(); | |
97 | |
4552 | 98 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 ("U", 1), n, h, n, info |
99 F77_CHAR_ARG_LEN (1))); | |
457 | 100 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
101 xrcond = 0.0; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
102 if (info != 0) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
103 info = -1; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
104 else if (calc_cond) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
105 { |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
106 octave_idx_type zpocon_info = 0; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
107 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
108 // Now calculate the condition number for non-singular matrix. |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
109 Array<Complex> z (2*n); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
110 Complex *pz = z.fortran_vec (); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
111 Array<double> rz (n); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
112 double *prz = rz.fortran_vec (); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
113 F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 ("U", 1), n, h, |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
114 n, anorm, xrcond, pz, prz, zpocon_info |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
115 F77_CHAR_ARG_LEN (1))); |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
116 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
117 if (zpocon_info != 0) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
118 info = -1; |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
119 } |
1944 | 120 else |
121 { | |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
122 // If someone thinks of a more graceful way of doing this (or |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
123 // faster for that matter :-)), please let me know! |
457 | 124 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
125 if (n > 1) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
126 for (octave_idx_type j = 0; j < a_nc; j++) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
127 for (octave_idx_type i = j+1; i < a_nr; i++) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
128 chol_mat.xelem (i, j) = 0.0; |
1944 | 129 } |
130 | |
131 return info; | |
457 | 132 } |
133 | |
5340 | 134 static ComplexMatrix |
135 chol2inv_internal (const ComplexMatrix& r) | |
136 { | |
137 ComplexMatrix retval; | |
138 | |
139 octave_idx_type r_nr = r.rows (); | |
140 octave_idx_type r_nc = r.cols (); | |
141 | |
142 if (r_nr == r_nc) | |
143 { | |
144 octave_idx_type n = r_nc; | |
145 octave_idx_type info; | |
146 | |
147 ComplexMatrix tmp = r; | |
148 | |
149 F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 ("U", 1), n, | |
150 tmp.fortran_vec (), n, info | |
151 F77_CHAR_ARG_LEN (1))); | |
152 | |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
153 // If someone thinks of a more graceful way of doing this (or |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
154 // faster for that matter :-)), please let me know! |
5340 | 155 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
156 if (n > 1) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
157 for (octave_idx_type j = 0; j < r_nc; j++) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
158 for (octave_idx_type i = j+1; i < r_nr; i++) |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
159 tmp.xelem (i, j) = std::conj (tmp.xelem (j, i)); |
5340 | 160 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
161 retval = tmp; |
5340 | 162 } |
163 else | |
164 (*current_liboctave_error_handler) ("chol2inv requires square matrix"); | |
165 | |
166 return retval; | |
167 } | |
168 | |
169 // Compute the inverse of a matrix using the Cholesky factorization. | |
170 ComplexMatrix | |
171 ComplexCHOL::inverse (void) const | |
172 { | |
173 return chol2inv_internal (chol_mat); | |
174 } | |
175 | |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
176 void |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
177 ComplexCHOL::set (const ComplexMatrix& R) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
178 { |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
179 if (R.is_square ()) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
180 chol_mat = R; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
181 else |
7559
07522d7dcdf8
fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents:
7554
diff
changeset
|
182 (*current_liboctave_error_handler) ("CHOL requires square matrix"); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
183 } |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
184 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
185 void |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
186 ComplexCHOL::update (const ComplexMatrix& u) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
187 { |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
188 octave_idx_type n = chol_mat.rows (); |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
189 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
190 if (u.length () == n) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
191 { |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
192 ComplexMatrix tmp = u; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
193 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
194 OCTAVE_LOCAL_BUFFER (double, w, n); |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
195 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
196 F77_XFCN (zch1up, ZCH1UP, (n, chol_mat.fortran_vec (), |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
197 tmp.fortran_vec (), w)); |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
198 } |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
199 else |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
200 (*current_liboctave_error_handler) ("CHOL update dimension mismatch"); |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
201 } |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
202 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
203 octave_idx_type |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
204 ComplexCHOL::downdate (const ComplexMatrix& u) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
205 { |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
206 octave_idx_type info = -1; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
207 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
208 octave_idx_type n = chol_mat.rows (); |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
209 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
210 if (u.length () == n) |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
211 { |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
212 ComplexMatrix tmp = u; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
213 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
214 OCTAVE_LOCAL_BUFFER (double, w, n); |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
215 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
216 F77_XFCN (zch1dn, ZCH1DN, (n, chol_mat.fortran_vec (), |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
217 tmp.fortran_vec (), w, info)); |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
218 } |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
219 else |
7559
07522d7dcdf8
fixes to QR and Cholesky updating code
Jaroslav Hajek <highegg@gmail.com>
parents:
7554
diff
changeset
|
220 (*current_liboctave_error_handler) ("CHOL downdate dimension mismatch"); |
7554
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
221 |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
222 return info; |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
223 } |
40574114c514
implement Cholesky factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents:
7482
diff
changeset
|
224 |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
225 octave_idx_type |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
226 ComplexCHOL::insert_sym (const ComplexMatrix& u, octave_idx_type j) |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
227 { |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
228 octave_idx_type info = -1; |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
229 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
230 octave_idx_type n = chol_mat.rows (); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
231 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
232 if (u.length () != n+1) |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
233 (*current_liboctave_error_handler) ("CHOL insert dimension mismatch"); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
234 else if (j < 0 || j > n) |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
235 (*current_liboctave_error_handler) ("CHOL insert index out of range"); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
236 else |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
237 { |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
238 ComplexMatrix chol_mat1 (n+1, n+1); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
239 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
240 F77_XFCN (zchinx, ZCHINX, (n, chol_mat.data (), chol_mat1.fortran_vec (), |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
241 j+1, u.data (), info)); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
242 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
243 chol_mat = chol_mat1; |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
244 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
245 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
246 return info; |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
247 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
248 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
249 void |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
250 ComplexCHOL::delete_sym (octave_idx_type j) |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
251 { |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
252 octave_idx_type n = chol_mat.rows (); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
253 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
254 if (j < 0 || j > n-1) |
7725
7c9ba697a479
cosmetic fixes in QR & Cholesky updating codes
Jaroslav Hajek <highegg@gmail.com>
parents:
7700
diff
changeset
|
255 (*current_liboctave_error_handler) ("CHOL delete index out of range"); |
7700
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
256 else |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
257 { |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
258 ComplexMatrix chol_mat1 (n-1, n-1); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
259 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
260 F77_XFCN (zchdex, ZCHDEX, (n, chol_mat.data (), chol_mat1.fortran_vec (), j+1)); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
261 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
262 chol_mat = chol_mat1; |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
263 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
264 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
265 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
266 void |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
267 ComplexCHOL::shift_sym (octave_idx_type i, octave_idx_type j) |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
268 { |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
269 octave_idx_type n = chol_mat.rows (); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
270 Complex dummy; |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
271 |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
272 if (i < 0 || i > n-1 || j < 0 || j > n-1) |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
273 (*current_liboctave_error_handler) ("CHOL shift index out of range"); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
274 else |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
275 F77_XFCN (zqrshc, ZQRSHC, (0, n, n, &dummy, chol_mat.fortran_vec (), i+1, j+1)); |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
276 } |
efccca5f2ad7
more QR & Cholesky updating functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7559
diff
changeset
|
277 |
5340 | 278 ComplexMatrix |
279 chol2inv (const ComplexMatrix& r) | |
280 { | |
281 return chol2inv_internal (r); | |
282 } | |
283 | |
457 | 284 /* |
285 ;;; Local Variables: *** | |
286 ;;; mode: C++ *** | |
287 ;;; End: *** | |
288 */ |