qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
dqrshc.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 dqrshc(m,n,k,Q,ldq,R,ldr,i,j,w)
26!>
27!> .. Scalar Arguments ..
28!> integer m, n, k, ldq, ldr, i, j
29!> ..
30!> .. Array Arguments ..
31!> double precision Q(ldq,*)
32!> double precision R(ldr,*)
33!> double precision w(*)
34!> ..
35!> \endverbatim
36!>
37!> \par Purpose:
38! =============
39!> \verbatim
40!>
41!> DQRSHC updates a QR factorization after circular shift of columns.
42!> i.e., given an m-by-k orthogonal matrix Q, an k-by-n upper
43!> trapezoidal matrix R and index j in the range 1:n+1, DQRSHC
44!> updates the matrix Q -> Q1 and R -> R1 so that Q1 is again
45!> orthogonal, R1 upper trapezoidal, and Q1*R1 = A(:,p), where A = Q*R
46!> and p is the permutation [1:i-1,shift(i:j,-1),j+1:n] if i < j or
47!> [1:j-1,shift(j:i,+1),i+1:n] if j < i. (real version)
48!> \endverbatim
49!>
50!> \param[in] m
51!> \verbatim
52!> m is INTEGER
53!> The number of rows of the matrix Q. m >= 0.
54!> \endverbatim
55!>
56!> \param[in] n
57!> \verbatim
58!> n is INTEGER
59!> The number of columns of the matrix R. n >= 0.
60!> \endverbatim
61!>
62!> \param[in] k
63!> \verbatim
64!> k is INTEGER
65!> The number of columns of Q1, and rows of R1. Must be
66!> either k = m (full Q) or k = n <= m (economical form).
67!> \endverbatim
68!>
69!> \param[in,out] Q
70!> \verbatim
71!> Q is DOUBLE PRECISION array, dimension (ldq,*)
72!> On entry, the orthogonal m-by-k matrix Q. On exit,
73!> the updated matrix Q1.
74!> \endverbatim
75!>
76!> \param[in] ldq
77!> \verbatim
78!> ldq is INTEGER
79!> The leading dimension of Q. ldq >= m.
80!> \endverbatim
81!>
82!> \param[in,out] R
83!> \verbatim
84!> R is DOUBLE PRECISION array, dimension (ldr,*)
85!> On entry, the original matrix R. On exit, the
86!> updated matrix R1.
87!> \endverbatim
88!>
89!> \param[in] ldr
90!> \verbatim
91!> ldr is INTEGER
92!> The leading dimension of R. ldr >= k.
93!> \endverbatim
94!>
95!> \param[in] i
96!> \verbatim
97!> i is INTEGER
98!> The first index determining the range (see above).
99!> 1 <= i <= n.
100!> \endverbatim
101!>
102!> \param[in] j
103!> \verbatim
104!> j is INTEGER
105!> The second index determining the range (see above).
106!> 1 <= j <= n.
107!> \endverbatim
108!>
109!> \param[out] w
110!> \verbatim
111!> w is DOUBLE PRECISION array, dimension (*)
112!> A workspace vector of size 2*k.
113!> \endverbatim
114!>
115!> \ingroup qrdecomp
116subroutine dqrshc(m,n,k,Q,ldq,R,ldr,i,j,w)
117 use iso_fortran_env
119 integer, intent(in) :: m, n, k, ldq, ldr, i, j
120 real(real64), intent(inout) :: Q(ldq,*)
121 real(real64), intent(inout) :: R(ldr,*)
122 real(real64), intent(out) :: w(*)
123 external dqrot,dcopy,dqrtv1,dqrqh,dqhqr
124 integer info,jj,kk,l
125 ! quick return if possible.
126 if (m == 0 .or. n == 1) return
127 info = 0
128 ! check arguments.
129 if (m < 0) then
130 info = 1
131 else if (n < 0) then
132 info = 2
133 else if (k /= m .and. (k /= n .or. n > m)) then
134 info = 3
135 else if (i < 1 .or. i > n) then
136 info = 6
137 else if (j < 1 .or. j > n) then
138 info = 7
139 end if
140 if (info /= 0) then
141 call qrupdate_xerror('DQRSHC',info)
142 return
143 end if
144 if (i < j) then
145 ! shift columns
146 call dcopy(k,r(1,i),1,w,1)
147 do l = i,j-1
148 call dcopy(k,r(1,l+1),1,r(1,l),1)
149 end do
150 call dcopy(k,w,1,r(1,j),1)
151 ! retriangularize
152 if (i < k) then
153 kk = min(k,j)
154 call dqhqr(kk+1-i,n+1-i,r(i,i),ldr,w(k+1),w)
155 ! apply rotations to Q.
156 call dqrot('F',m,kk+1-i,q(1,i),ldq,w(k+1),w)
157 end if
158 else if (j < i) then
159 ! shift columns
160 call dcopy(k,r(1,i),1,w,1)
161 do l = i,j+1,-1
162 call dcopy(k,r(1,l-1),1,r(1,l),1)
163 end do
164 call dcopy(k,w,1,r(1,j),1)
165 ! retriangularize
166 if (j < k) then
167 jj = min(j+1,n)
168 kk = min(k,i)
169 ! eliminate the introduced spike.
170 call dqrtv1(kk+1-j,r(j,j),w(k+1))
171 ! apply rotations to R
172 call dqrqh(kk+1-j,n-j,r(j,jj),ldr,w(k+1),r(j+1,j))
173 ! apply rotations to Q
174 call dqrot('B',m,kk+1-j,q(1,j),ldq,w(k+1),r(j+1,j))
175 ! zero spike.
176 do l = j+1,kk
177 r(l,j) = 0d0
178 end do
179 end if
180 end if
181end subroutine
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
subroutine dqrtv1(n, u, w)
Generates Givens rotations to eliminate all but the first element of a vector.
Definition dqrtv1.f90:74
subroutine dqrot(dir, m, n, q, ldq, c, s)
Applies a sequence of Givens rotations from the right to a matrix.
Definition dqrot.f90:101
subroutine dqrqh(m, n, r, ldr, c, s)
Converts an upper trapezoidal matrix to upper Hessenberg form.
Definition dqrqh.f90:86
subroutine dqrshc(m, n, k, q, ldq, r, ldr, i, j, w)
Updates a QR factorization after a circular shift of columns.
Definition dqrshc.f90:117
subroutine dqhqr(m, n, r, ldr, c, s)
Reduces an upper Hessenberg matrix to upper trapezoidal form.
Definition dqhqr.f90:90
Module for custom error handling.