qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
dqr1up.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 dqr1up(m,n,k,Q,ldq,R,ldr,u,v,w)
26!>
27!> .. Scalar Arguments ..
28!> integer m, n, k, ldq, ldr
29!> ..
30!> .. Array Arguments ..
31!> double precision Q(ldq,*)
32!> double precision R(ldr,*)
33!> double precision u(*)
34!> double precision v(*)
35!> double precision w(*)
36!> ..
37!> \endverbatim
38!>
39!> \par Purpose:
40! =============
41!> \verbatim
42!>
43!> DQR1UP updates a QR factorization after rank-1 modification i.e.,
44!> given a m-by-k orthogonal Q and m-by-n upper trapezoidal R, an
45!> m-vector u and n-vector v, DQR1UP updates Q -> Q1 and R ->
46!> R1 so that Q1*R1 = Q*R + u*v', and Q1 is again orthonormal and R1
47!> upper trapezoidal. (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 Q, and rows of R. 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 upper trapezoidal m-by-n matrix R. On
86!> exit, the 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,out] u
96!> \verbatim
97!> u is DOUBLE PRECISION array, dimension (*)
98!> On entry, the left m-vector. On exit, if k < m,
99!> u is destroyed.
100!> \endverbatim
101!>
102!> \param[in,out] v
103!> \verbatim
104!> v is DOUBLE PRECISION array, dimension (*)
105!> On entry, the right n-vector. On exit, v is
106!> destroyed.
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 dqr1up(m,n,k,Q,ldq,R,ldr,u,v,w)
117 use iso_fortran_env
119 integer, intent(in) :: m, n, k, ldq, ldr
120 real(real64), intent(inout) :: Q(ldq,*)
121 real(real64), intent(inout) :: R(ldr,*)
122 real(real64), intent(inout) :: u(*)
123 real(real64), intent(inout) :: v(*)
124 real(real64), intent(out) :: w(*)
125 external dch1up, dqrqh,dqhqr,dqrot,dqrtv1
126 external daxpy,ddot,dnrm2,dlamch,dscal,drot
127 real(real64) ddot,dnrm2,dlamch,ru,ruu
128 integer info,i
129 logical full
130 ! quick return if possible.
131 if (k == 0 .or. n == 0) return
132 ! check arguments.
133 info = 0
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 (ldq < m) then
141 info = 5
142 else if (ldr < k) then
143 info = 7
144 endif
145 if (info /= 0) then
146 call qrupdate_xerror('DQR1UP',info)
147 return
148 end if
149 full = k == m
150 ru = 1.0d0
151 ! in the non-full case, we shall need the norm of u.
152 if (.not.full) ru = dnrm2(m,u,1)
153 ! form Q'*u. In the non-full case, form also u - Q*Q'u.
154 do i = 1,k
155 w(i) = ddot(m,q(1,i),1,u,1)
156 if (.not.full) call daxpy(m,-w(i),q(1,i),1,u,1)
157 end do
158 ! generate rotations to eliminate Q'*u.
159 call dqrtv1(k,w,w(k+1))
160 ! apply rotations to R.
161 call dqrqh(k,n,r,ldr,w(k+1),w(2))
162 ! apply rotations to Q.
163 call dqrot('B',m,k,q,ldq,w(k+1),w(2))
164 ! update the first row of R.
165 call daxpy(n,w(1),v,1,r(1,1),ldr)
166 ! retriangularize R.
167 call dqhqr(k,n,r,ldr,w(k+1),w)
168 ! apply rotations to Q.
169 call dqrot('F',m,min(k,n+1),q,ldq,w(k+1),w)
170 ! in the full case, we're finished
171 if (full) return
172 ! compute relative residual norm
173 ruu = dnrm2(m,u,1)
174 ru = ru * dlamch('e')
175 if (ruu <= ru) return
176 ! update the orthogonal basis.
177 call dscal(n,ruu,v,1)
178 call dscal(m,1d0/ruu,u,1)
179 call dch1up(n,r,ldr,v,w(k+1))
180 do i = 1,n
181 call drot(m,q(1,i),1,u,1,w(k+i),v(i))
182 end do
183end subroutine
subroutine dch1up(n, r, ldr, u, w)
Updates a Cholesky factorization after a rank-1 modification.
Definition dch1up.f90:89
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 dqr1up(m, n, k, q, ldq, r, ldr, u, v, w)
Updates a QR factorization after a rank-1 modification.
Definition dqr1up.f90:117
subroutine dqrqh(m, n, r, ldr, c, s)
Converts an upper trapezoidal matrix to upper Hessenberg form.
Definition dqrqh.f90:86
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.