annotate liboctave/CmplxQR.cc @ 7553:56be6f31dd4e

implementation of QR factorization updating
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 04 Mar 2008 21:47:11 -0500
parents 29980c6b8604
children 40574114c514
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
1 /*
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1994, 1995, 1996, 1997, 2002, 2003, 2004, 2005, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 John W. Eaton
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
5
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
7
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
11 option) any later version.
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
12
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
16 for more details.
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
17
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
18 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: 5307
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5307
diff changeset
20 <http://www.gnu.org/licenses/>.
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
21
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
22 */
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
23
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
24 // updating/downdating by Jaroslav Hajek 2008
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
25
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1011
diff changeset
27 #include <config.h>
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
28 #endif
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
29
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
30 #include "CmplxQR.h"
1847
2ffe49eb95a5 [project @ 1996-02-03 12:47:55 by jwe]
jwe
parents: 1368
diff changeset
31 #include "f77-fcn.h"
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
32 #include "lo-error.h"
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
33 #include "Range.h"
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
34 #include "idx-vector.h"
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
35
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
36 extern "C"
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
37 {
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
38 F77_RET_T
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
39 F77_FUNC (zgeqrf, ZGEQRF) (const octave_idx_type&, const octave_idx_type&, Complex*,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
40 const octave_idx_type&, Complex*, Complex*,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
41 const octave_idx_type&, octave_idx_type&);
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
42
4552
6f3382e08a52 [project @ 2003-10-27 20:38:02 by jwe]
jwe
parents: 4192
diff changeset
43 F77_RET_T
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
44 F77_FUNC (zungqr, ZUNGQR) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
45 Complex*, const octave_idx_type&, Complex*,
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
46 Complex*, const octave_idx_type&, octave_idx_type&);
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
47
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
48 // these come from qrupdate
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
49
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
50 F77_RET_T
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
51 F77_FUNC (zqr1up, ZQR1UP) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
52 Complex*, Complex*, const Complex*, const Complex*);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
53
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
54 F77_RET_T
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
55 F77_FUNC (zqrinc, ZQRINC) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
56 Complex*, const Complex*, Complex*, const octave_idx_type&, const Complex*);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
57
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
58 F77_RET_T
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
59 F77_FUNC (zqrdec, ZQRDEC) (const octave_idx_type&, const octave_idx_type&, const octave_idx_type&,
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
60 Complex*, const Complex*, Complex*, const octave_idx_type&);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
61
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
62 F77_RET_T
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
63 F77_FUNC (zqrinr, ZQRINR) (const octave_idx_type&, const octave_idx_type&,
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
64 const Complex*, Complex*, const Complex*, Complex*,
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
65 const octave_idx_type&, const Complex*);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
66
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
67 F77_RET_T
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
68 F77_FUNC (zqrder, ZQRDER) (const octave_idx_type&, const octave_idx_type&,
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
69 const Complex*, Complex*, const Complex*, Complex *,
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
70 const octave_idx_type&);
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
71 }
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
72
539
5ec10a984241 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents: 457
diff changeset
73 ComplexQR::ComplexQR (const ComplexMatrix& a, QR::type qr_type)
2763
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2244
diff changeset
74 : q (), r ()
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2244
diff changeset
75 {
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2244
diff changeset
76 init (a, qr_type);
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2244
diff changeset
77 }
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2244
diff changeset
78
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2244
diff changeset
79 void
d9d00d7e271e [project @ 1997-03-01 02:14:33 by jwe]
jwe
parents: 2244
diff changeset
80 ComplexQR::init (const ComplexMatrix& a, QR::type qr_type)
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
81 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
82 octave_idx_type m = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
83 octave_idx_type n = a.cols ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
84
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
85 if (m == 0 || n == 0)
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
86 {
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
87 (*current_liboctave_error_handler)
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
88 ("ComplexQR must have non-empty matrix");
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
89 return;
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
90 }
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
91
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
92 octave_idx_type min_mn = m < n ? m : n;
1927
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
93
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
94 Array<Complex> tau (min_mn);
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
95 Complex *ptau = tau.fortran_vec ();
1921
ce0db0ca0729 [project @ 1996-02-11 02:31:58 by jwe]
jwe
parents: 1882
diff changeset
96
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
97 octave_idx_type lwork = 32*n;
1927
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
98 Array<Complex> work (lwork);
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
99 Complex *pwork = work.fortran_vec ();
1921
ce0db0ca0729 [project @ 1996-02-11 02:31:58 by jwe]
jwe
parents: 1882
diff changeset
100
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
101 octave_idx_type info = 0;
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
102
1927
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
103 ComplexMatrix A_fact;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3069
diff changeset
104 if (m > n && qr_type != QR::economy)
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
105 {
1927
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
106 A_fact.resize (m, m);
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
107 A_fact.insert (a, 0, 0);
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
108 }
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
109 else
1927
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
110 A_fact = a;
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
111
1927
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
112 Complex *tmp_data = A_fact.fortran_vec ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
113
1927
e379c781ae7e [project @ 1996-02-11 21:39:27 by jwe]
jwe
parents: 1921
diff changeset
114 F77_XFCN (zgeqrf, ZGEQRF, (m, n, tmp_data, m, ptau, pwork, lwork, info));
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
115
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
116 if (qr_type == QR::raw)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
117 {
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
118 for (octave_idx_type j = 0; j < min_mn; j++)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
119 {
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
120 octave_idx_type limit = j < min_mn - 1 ? j : min_mn - 1;
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
121 for (octave_idx_type i = limit + 1; i < m; i++)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
122 A_fact.elem (i, j) *= tau.elem (j);
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
123 }
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
124
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
125 r = A_fact;
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
126
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
127 if (m > n)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
128 r.resize (m, n);
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
129 }
539
5ec10a984241 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents: 457
diff changeset
130 else
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
131 {
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
132 octave_idx_type n2 = (qr_type == QR::economy) ? min_mn : m;
3069
db6d57d718f7 [project @ 1997-07-10 23:34:03 by jwe]
jwe
parents: 3068
diff changeset
133
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
134 if (qr_type == QR::economy && m > n)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
135 r.resize (n, n, 0.0);
539
5ec10a984241 [project @ 1994-07-21 22:40:04 by jwe]
jwe
parents: 457
diff changeset
136 else
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
137 r.resize (m, n, 0.0);
1921
ce0db0ca0729 [project @ 1996-02-11 02:31:58 by jwe]
jwe
parents: 1882
diff changeset
138
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
139 for (octave_idx_type j = 0; j < n; j++)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
140 {
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
141 octave_idx_type limit = j < min_mn-1 ? j : min_mn-1;
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
142 for (octave_idx_type i = 0; i <= limit; i++)
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
143 r.elem (i, j) = A_fact.elem (i, j);
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
144 }
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
145
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
146 lwork = 32 * n2;
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
147 work.resize (lwork);
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
148 Complex *pwork2 = work.fortran_vec ();
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
149
7482
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
150 F77_XFCN (zungqr, ZUNGQR, (m, n2, min_mn, tmp_data, m, ptau,
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
151 pwork2, lwork, info));
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
152
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
153 q = A_fact;
29980c6b8604 don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
154 q.resize (m, n2);
1921
ce0db0ca0729 [project @ 1996-02-11 02:31:58 by jwe]
jwe
parents: 1882
diff changeset
155 }
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
156 }
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
157
7553
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
158
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
159 ComplexQR::ComplexQR (const ComplexMatrix &q, const ComplexMatrix& r)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
160 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
161 if (q.columns () != r.rows ())
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
162 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
163 (*current_liboctave_error_handler) ("QR dimensions mismatch");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
164 return;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
165 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
166
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
167 this->q = q;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
168 this->r = r;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
169 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
170
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
171 void
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
172 ComplexQR::update (const ComplexMatrix& u, const ComplexMatrix& v)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
173 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
174 octave_idx_type m = q.rows ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
175 octave_idx_type n = r.columns ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
176 octave_idx_type k = q.columns ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
177
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
178 if (u.length () != m || v.length () != n)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
179 (*current_liboctave_error_handler) ("QR update dimensions mismatch");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
180 else
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
181 F77_XFCN (zqr1up, ZQR1UP, (m, n, k, q.fortran_vec (), r.fortran_vec (),
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
182 u.data (), v.data ()));
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
183 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
184
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
185 void
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
186 ComplexQR::insert_col (const ComplexMatrix& u, octave_idx_type j)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
187 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
188 octave_idx_type m = q.rows ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
189 octave_idx_type n = r.columns ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
190 octave_idx_type k = q.columns ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
191
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
192 if (u.length () != m)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
193 (*current_liboctave_error_handler) ("QR insert dimensions mismatch");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
194 else if (j < 1 || j > n+1)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
195 (*current_liboctave_error_handler) ("QR insert index out of range");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
196 else
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
197 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
198 ComplexMatrix r1 (m,n+1);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
199
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
200 F77_XFCN (zqrinc, ZQRINC, (m, n, k, q.fortran_vec (), r.data (),
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
201 r1.fortran_vec (), j, u.data ()));
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
202
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
203 r = r1;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
204 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
205 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
206
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
207 void
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
208 ComplexQR::delete_col (octave_idx_type j)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
209 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
210 octave_idx_type m = q.rows ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
211 octave_idx_type k = r.rows ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
212 octave_idx_type n = r.columns ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
213
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
214 if (k < m && k < n)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
215 (*current_liboctave_error_handler) ("QR delete dimensions mismatch");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
216 else if (j < 1 || j > n)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
217 (*current_liboctave_error_handler) ("QR delete index out of range");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
218 else
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
219 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
220 ComplexMatrix r1 (k, n-1);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
221
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
222 F77_XFCN (zqrdec, ZQRDEC, (m, n, k, q.fortran_vec (), r.data (),
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
223 r1.fortran_vec (), j));
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
224
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
225 r = r1;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
226 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
227 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
228
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
229 void
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
230 ComplexQR::insert_row (const ComplexMatrix& u, octave_idx_type j)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
231 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
232 octave_idx_type m = r.rows ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
233 octave_idx_type n = r.columns ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
234
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
235 if (! q.is_square () || u.length () != n)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
236 (*current_liboctave_error_handler) ("QR insert dimensions mismatch");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
237 else if (j < 1 || j > m+1)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
238 (*current_liboctave_error_handler) ("QR insert index out of range");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
239 else
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
240 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
241 ComplexMatrix q1 (m+1, m+1);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
242 ComplexMatrix r1 (m+1, n);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
243
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
244 F77_XFCN (zqrinr, ZQRINR, (m, n, q.data (), q1.fortran_vec (),
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
245 r.data (), r1.fortran_vec (), j, u.data ()));
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
246
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
247 q = q1;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
248 r = r1;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
249 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
250 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
251
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
252 void
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
253 ComplexQR::delete_row (octave_idx_type j)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
254 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
255 octave_idx_type m = r.rows ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
256 octave_idx_type n = r.columns ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
257
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
258 if (! q.is_square ())
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
259 (*current_liboctave_error_handler) ("QR insert dimensions mismatch");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
260 else if (j < 1 || j > n)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
261 (*current_liboctave_error_handler) ("QR delete index out of range");
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
262 else
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
263 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
264 ComplexMatrix q1 (m-1, m-1);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
265 ComplexMatrix r1 (m-1, n);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
266
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
267 F77_XFCN (zqrder, ZQRDER, (m, n, q.data (), q1.fortran_vec (),
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
268 r.data (), r1.fortran_vec (), j ));
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
269
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
270 q = q1;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
271 r = r1;
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
272 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
273 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
274
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
275 void
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
276 ComplexQR::economize (void)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
277 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
278 idx_vector c (':'), i (Range (1, r.columns ()));
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
279 q = ComplexMatrix (q.index (c, i));
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
280 r = ComplexMatrix (r.index (i, c));
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
281 #if 0
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
282 octave_idx_type r_nc = r.columns ();
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
283
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
284 if (r.rows () > r_nc)
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
285 {
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
286 q.resize (q.rows (), r_nc);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
287 r.resize (r_nc, r_nc);
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
288 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
289 #endif
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
290 }
56be6f31dd4e implementation of QR factorization updating
Jaroslav Hajek <highegg@gmail.com>
parents: 7482
diff changeset
291
457
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
292 /*
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
293 ;;; Local Variables: ***
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
294 ;;; mode: C++ ***
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
295 ;;; End: ***
3d4b4f0fa5ba [project @ 1994-06-06 00:33:33 by jwe]
jwe
parents:
diff changeset
296 */