qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
zqr1up.f90
Go to the documentation of this file.
1! Copyright (C) 2008, 2009 VZLU Prague, a.s., Czech Republic, Jaroslav Hajek <highegg@gmail.com>
2! Copyright (C) 2026 Martin Köhler <koehlerm(AT)mpi-magdeburg.mpg.de>
3!
4! This file is part of qrupdate-ng.
5!
6! qrupdate is free software; you can redistribute it and/or modify
7! it under the terms of the GNU General Public License as published by
8! the Free Software Foundation; either version 3 of the License, or
9! (at your option) any later version.
10!
11! This program is distributed in the hope that it will be useful,
12! but WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14! GNU General Public License for more details.
15!
16! You should have received a copy of the GNU General Public License
17! along with this software; see the file COPYING. If not, see
18! <http://www.gnu.org/licenses/>.
19!
20!> \brief Updates a QR factorization after a rank-1 modification.
21!>
22!> \par Definition:
23! =============
24!> \verbatim
25!> subroutine zqr1up(m,n,k,Q,ldq,R,ldr,u,v,w,rw)
26!>
27!> .. Scalar Arguments ..
28!> integer m, n, k, ldq, ldr
29!> ..
30!> .. Array Arguments ..
31!> double complex Q(ldq,*)
32!> double complex R(ldr,*)
33!> double complex u(*)
34!> double complex v(*)
35!> double complex w(*)
36!> double precision rw(*)
37!> ..
38!> \endverbatim
39!>
40!> \par Purpose:
41! =============
42!> \verbatim
43!>
44!> ZQR1UP updates a QR factorization after rank-1 modification i.e.,
45!> given a m-by-k unitary Q and m-by-n upper trapezoidal R, an m-vector
46!> u and n-vector v, ZQR1UP updates Q -> Q1 and R -> R1 so that
47!> Q1*R1 = Q*R + u*v', and Q1 is again unitary and R1 upper trapezoidal.
48!> (complex version)
49!> \endverbatim
50!>
51!> \param[in] m
52!> \verbatim
53!> m is INTEGER
54!> The number of rows of the matrix Q. m >= 0.
55!> \endverbatim
56!>
57!> \param[in] n
58!> \verbatim
59!> n is INTEGER
60!> The number of columns of the matrix R. n >= 0.
61!> \endverbatim
62!>
63!> \param[in] k
64!> \verbatim
65!> k is INTEGER
66!> The number of columns of Q, and rows of R. Must be
67!> either k = m (full Q) or k = n < m (economical form).
68!> \endverbatim
69!>
70!> \param[in,out] Q
71!> \verbatim
72!> Q is COMPLEX*16 array, dimension (ldq,*)
73!> On entry, the unitary m-by-k matrix Q. On exit,
74!> the updated matrix Q1.
75!> \endverbatim
76!>
77!> \param[in] ldq
78!> \verbatim
79!> ldq is INTEGER
80!> The leading dimension of Q. ldq >= m.
81!> \endverbatim
82!>
83!> \param[in,out] R
84!> \verbatim
85!> R is COMPLEX*16 array, dimension (ldr,*)
86!> On entry, the upper trapezoidal m-by-n matrix R. On
87!> exit, the updated matrix R1.
88!> \endverbatim
89!>
90!> \param[in] ldr
91!> \verbatim
92!> ldr is INTEGER
93!> The leading dimension of R. ldr >= k.
94!> \endverbatim
95!>
96!> \param[in,out] u
97!> \verbatim
98!> u is COMPLEX*16 array, dimension (*)
99!> On entry, the left m-vector. On exit, if k < m,
100!> u is destroyed.
101!> \endverbatim
102!>
103!> \param[in,out] v
104!> \verbatim
105!> v is COMPLEX*16 array, dimension (*)
106!> On entry, the right n-vector. On exit, v is
107!> destroyed.
108!> \endverbatim
109!>
110!> \param[out] w
111!> \verbatim
112!> w is COMPLEX*16 array, dimension (*)
113!> A workspace vector of size k.
114!> \endverbatim
115!>
116!> \param[out] rw
117!> \verbatim
118!> rw is DOUBLE PRECISION array, dimension (*)
119!> A real workspace vector of size k.
120!> \endverbatim
121!>
122!> \ingroup qrdecomp
123subroutine zqr1up(m,n,k,Q,ldq,R,ldr,u,v,w,rw)
124 use iso_fortran_env
125 use qrupdate_blas
127 integer, intent(in) :: m, n, k, ldq, ldr
128 complex(real64), intent(inout) :: Q(ldq,*), R(ldr,*), u(*), v(*)
129 complex(real64), intent(out) :: w(*)
130 real(real64), intent(out) :: rw(*)
131 external zqrqh,zqhqr,zqrot,zqrtv1,zaxpy,zaxcpy, zch1up
132 external dznrm2,dlamch,zdscal,zrot
133 real(real64) dznrm2,dlamch,ru,ruu
134 integer info,i
135 logical full
136 ! quick return if possible.
137 if (k == 0 .or. n == 0) return
138 ! check arguments.
139 info = 0
140 if (m < 0) then
141 info = 1
142 else if (n < 0) then
143 info = 2
144 else if (k /= m .and. (k /= n .or. n > m)) then
145 info = 3
146 else if (ldq < m) then
147 info = 5
148 else if (ldr < k) then
149 info = 7
150 endif
151 if (info /= 0) then
152 call qrupdate_xerror('ZQR1UP',info)
153 return
154 end if
155 full = k == m
156 ru = 1.0d0
157 ! in the non-full case, we shall need the norm of u.
158 if (.not.full) ru = dznrm2(m,u,1)
159 ! form Q'*u. In the non-full case, form also u - Q*Q'u.
160 do i = 1,k
161 call qrupdate_zdotc(w(i), m,q(1,i),1,u,1)
162 if (.not.full) call zaxpy(m,-w(i),q(1,i),1,u,1)
163 end do
164 ! generate rotations to eliminate Q'*u.
165 call zqrtv1(k,w,rw)
166 ! apply rotations to R.
167 call zqrqh(k,n,r,ldr,rw,w(2))
168 ! apply rotations to Q.
169 call zqrot('B',m,k,q,ldq,rw,w(2))
170 ! update the first row of R.
171 call zaxcpy(n,w(1),v,1,r(1,1),ldr)
172 ! retriangularize R.
173 call zqhqr(k,n,r,ldr,rw,w)
174 ! apply rotations to Q.
175 call zqrot('F',m,min(k,n+1),q,ldq,rw,w)
176 ! in the full case, we're finished
177 if (full) return
178 ! compute relative residual norm
179 ruu = dznrm2(m,u,1)
180 ru = ru * dlamch('e')
181 if (ruu <= ru) return
182 ! update the orthogonal basis.
183 call zdscal(n,ruu,v,1)
184 call zdscal(m,1d0/ruu,u,1)
185 call zch1up(n,r,ldr,v,rw)
186 do i = 1,n
187 call zrot(m,q(1,i),1,u,1,rw(i),conjg(v(i)))
188 end do
189end subroutine
subroutine zaxcpy(n, a, x, incx, y, incy)
Performs scaled conjugate vector addition.
Definition zaxcpy.f90:97
subroutine zch1up(n, r, ldr, u, w)
Updates a Cholesky factorization after a rank-1 modification.
Definition zch1up.f90:90
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
subroutine zqrot(dir, m, n, q, ldq, c, s)
Applies a sequence of Givens rotations from the right to a matrix.
Definition zqrot.f90:101
subroutine zqrtv1(n, u, w)
Generates Givens rotations to eliminate all but the first element of a vector.
Definition zqrtv1.f90:75
subroutine zqhqr(m, n, r, ldr, c, s)
Reduces an upper Hessenberg matrix to upper trapezoidal form.
Definition zqhqr.f90:91
subroutine zqr1up(m, n, k, q, ldq, r, ldr, u, v, w, rw)
Updates a QR factorization after a rank-1 modification.
Definition zqr1up.f90:124
subroutine zqrqh(m, n, r, ldr, c, s)
Converts an upper trapezoidal matrix to upper Hessenberg form.
Definition zqrqh.f90:86
Module for custom error handling.