qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
zqrshc.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 circular shift of columns.
21!>
22!> \par Definition:
23! =============
24!> \verbatim
25!> subroutine zqrshc(m,n,k,Q,ldq,R,ldr,i,j,w,rw)
26!>
27!> .. Scalar Arguments ..
28!> integer m, n, k, ldq, ldr, i, j
29!> ..
30!> .. Array Arguments ..
31!> double complex Q(ldq,*)
32!> double complex R(ldr,*)
33!> double complex w(*)
34!> double precision rw(*)
35!> ..
36!> \endverbatim
37!>
38!> \par Purpose:
39! =============
40!> \verbatim
41!>
42!> ZQRSHC updates a QR factorization after circular shift of columns.
43!> i.e., given an m-by-k unitary matrix Q, an k-by-n upper trapezoidal
44!> matrix R and index j in the range 1:n+1, ZQRSHC updates the
45!> matrix Q -> Q1 and R -> R1 so that Q1 is again unitary, R1 upper
46!> trapezoidal, and Q1*R1 = A(:,p), where A = Q*R and p is the
47!> permutation [1:i-1,shift(i:j,-1),j+1:n] if i < j or
48!> [1:j-1,shift(j:i,+1),i+1:n] if j < i. (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 Q1, and rows of R1. 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 original matrix R. On exit, the
87!> 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] i
97!> \verbatim
98!> i is INTEGER
99!> The first index determining the range (see above).
100!> \endverbatim
101!>
102!> \param[in] j
103!> \verbatim
104!> j is INTEGER
105!> The second index determining the range (see above).
106!> \endverbatim
107!>
108!> \param[out] w
109!> \verbatim
110!> w is COMPLEX*16 array, dimension (*)
111!> A workspace vector of size k.
112!> \endverbatim
113!>
114!> \param[out] rw
115!> \verbatim
116!> rw is DOUBLE PRECISION array, dimension (*)
117!> A real workspace vector of size k.
118!> \endverbatim
119!>
120!> \ingroup qrdecomp
121subroutine zqrshc(m,n,k,Q,ldq,R,ldr,i,j,w,rw)
122 use iso_fortran_env
124 integer, intent(in) :: m, n, k, ldq, ldr, i, j
125 complex(real64), intent(inout) :: Q(ldq,*), R(ldr,*)
126 complex(real64), intent(out) :: w(*)
127 real(real64), intent(out) :: rw(*)
128 external zcopy,zqrtv1,zqrqh,zqhqr,zqrot
129 integer info,jj,kk,l
130 ! quick return if possible.
131 if (m == 0 .or. n == 1) return
132 info = 0
133 ! check arguments.
134 if (m < 0) then
135 info = 1
136 else if (n < 0) then
137 info = 2
138 else if (k /= m .and. (k /= n .or. n > m)) then
139 info = 3
140 else if (i < 1 .or. i > n) then
141 info = 6
142 else if (j < 1 .or. j > n) then
143 info = 7
144 end if
145 if (info /= 0) then
146 call qrupdate_xerror('ZQRSHC',info)
147 return
148 end if
149 if (i < j) then
150 ! shift columns
151 call zcopy(k,r(1,i),1,w,1)
152 do l = i,j-1
153 call zcopy(k,r(1,l+1),1,r(1,l),1)
154 end do
155 call zcopy(k,w,1,r(1,j),1)
156 ! retriangularize
157 if (i < k) then
158 kk = min(k,j)
159 call zqhqr(kk+1-i,n+1-i,r(i,i),ldr,rw,w)
160 ! apply rotations to Q.
161 call zqrot('F',m,kk+1-i,q(1,i),ldq,rw,w)
162 end if
163 else if (j < i) then
164 ! shift columns
165 call zcopy(k,r(1,i),1,w,1)
166 do l = i,j+1,-1
167 call zcopy(k,r(1,l-1),1,r(1,l),1)
168 end do
169 call zcopy(k,w,1,r(1,j),1)
170 ! retriangularize
171 if (j < k) then
172 jj = min(j+1,n)
173 kk = min(k,i)
174 ! eliminate the introduced spike.
175 call zqrtv1(kk+1-j,r(j,j),rw)
176 ! apply rotations to R
177 call zqrqh(kk+1-j,n-j,r(j,jj),ldr,rw,r(j+1,j))
178 ! apply rotations to Q
179 call zqrot('B',m,kk+1-j,q(1,j),ldq,rw,r(j+1,j))
180 ! zero spike.
181 do l = j+1,kk
182 r(l,j) = 0d0
183 end do
184 end if
185 end if
186end subroutine
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 zqrqh(m, n, r, ldr, c, s)
Converts an upper trapezoidal matrix to upper Hessenberg form.
Definition zqrqh.f90:86
subroutine zqrshc(m, n, k, q, ldq, r, ldr, i, j, w, rw)
Updates a QR factorization after a circular shift of columns.
Definition zqrshc.f90:122
Module for custom error handling.