qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
sqrshc.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 sqrshc(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!> real Q(ldq,*)
32!> real R(ldr,*)
33!> real w(*)
34!> ..
35!> \endverbatim
36!>
37!> \par Purpose:
38! =============
39!> \verbatim
40!>
41!> SQRSHC 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, SQRSHC
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 REAL 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 REAL 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!> \endverbatim
100!>
101!> \param[in] j
102!> \verbatim
103!> j is INTEGER
104!> The second index determining the range (see above).
105!> \endverbatim
106!>
107!> \param[out] w
108!> \verbatim
109!> w is REAL array, dimension (*)
110!> A workspace vector of size 2*k.
111!> \endverbatim
112!>
113!> \ingroup qrdecomp
114subroutine sqrshc(m,n,k,Q,ldq,R,ldr,i,j,w)
115 use iso_fortran_env
117 integer, intent(in) :: m, n, k, ldq, ldr, i, j
118 real(real32), intent(inout) :: Q(ldq,*), R(ldr,*)
119 real(real32), intent(out) :: w(*)
120 external scopy,sqrtv1,sqrqh,sqhqr,sqrot
121 integer info,jj,kk,l
122 ! quick return if possible.
123 if (m == 0 .or. n == 1) return
124 info = 0
125 ! check arguments.
126 if (m < 0) then
127 info = 1
128 else if (n < 0) then
129 info = 2
130 else if (k /= m .and. (k /= n .or. n > m)) then
131 info = 3
132 else if (i < 1 .or. i > n) then
133 info = 6
134 else if (j < 1 .or. j > n) then
135 info = 7
136 end if
137 if (info /= 0) then
138 call qrupdate_xerror('SQRSHC',info)
139 return
140 end if
141 if (i < j) then
142 ! shift columns
143 call scopy(k,r(1,i),1,w,1)
144 do l = i,j-1
145 call scopy(k,r(1,l+1),1,r(1,l),1)
146 end do
147 call scopy(k,w,1,r(1,j),1)
148 ! retriangularize
149 if (i < k) then
150 kk = min(k,j)
151 call sqhqr(kk+1-i,n+1-i,r(i,i),ldr,w(k+1),w)
152 ! apply rotations to Q.
153 call sqrot('F',m,kk+1-i,q(1,i),ldq,w(k+1),w)
154 end if
155 else if (j < i) then
156 ! shift columns
157 call scopy(k,r(1,i),1,w,1)
158 do l = i,j+1,-1
159 call scopy(k,r(1,l-1),1,r(1,l),1)
160 end do
161 call scopy(k,w,1,r(1,j),1)
162 ! retriangularize
163 if (j < k) then
164 jj = min(j+1,n)
165 kk = min(k,i)
166 ! eliminate the introduced spike.
167 call sqrtv1(kk+1-j,r(j,j),w(k+1))
168 ! apply rotations to R
169 call sqrqh(kk+1-j,n-j,r(j,jj),ldr,w(k+1),r(j+1,j))
170 ! apply rotations to Q
171 call sqrot('B',m,kk+1-j,q(1,j),ldq,w(k+1),r(j+1,j))
172 ! zero spike.
173 do l = j+1,kk
174 r(l,j) = 0e0
175 end do
176 end if
177 end if
178end subroutine
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
subroutine sqrtv1(n, u, w)
Generates Givens rotations to eliminate all but the first element of a vector.
Definition sqrtv1.f90:74
subroutine sqrot(dir, m, n, q, ldq, c, s)
Applies a sequence of Givens rotations from the right to a matrix.
Definition sqrot.f90:101
subroutine sqhqr(m, n, r, ldr, c, s)
Reduces an upper Hessenberg matrix to upper trapezoidal form.
Definition sqhqr.f90:90
subroutine sqrshc(m, n, k, q, ldq, r, ldr, i, j, w)
Updates a QR factorization after a circular shift of columns.
Definition sqrshc.f90:115
subroutine sqrqh(m, n, r, ldr, c, s)
Converts an upper trapezoidal matrix to upper Hessenberg form.
Definition sqrqh.f90:86
Module for custom error handling.