qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
dlup1up.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 row-pivoted LU factorization after rank-1 modification.
21!>
22!> \par Definition:
23! =============
24!> \verbatim
25!> subroutine dlup1up(m,n,L,ldl,R,ldr,p,u,v,w)
26!>
27!> .. Scalar Arguments ..
28!> integer m, n, ldl, ldr
29!> ..
30!> .. Array Arguments ..
31!> integer p(*)
32!> double precision L(ldl,*), R(ldr,*), u(*), v(*), w(*)
33!> ..
34!> \endverbatim
35!>
36!> \par Purpose:
37! =============
38!> \verbatim
39!>
40!> DLUP1UP updates a row-pivoted LU factorization after rank-1
41!> modification. Given an m-by-k lower-triangular matrix L with
42!> unit diagonal, a k-by-n upper-trapezoidal matrix R, and a
43!> permutation vector p, where k = min(m,n), DLUP1UP
44!> updates L -> L1, R -> R1 and p -> p1 so that L1 is again
45!> lower unit triangular, R1 upper trapezoidal, p1 a permutation,
46!> and P1.'*L1*R1 = P.'*L*R + u*v.', where v.' denotes the
47!> transpose of v and P is the permutation matrix corresponding
48!> to p.
49!> \endverbatim
50!>
51!> \param[in] m
52!> \verbatim
53!> m is INTEGER
54!> The number of rows of the matrix L. 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,out] L
64!> \verbatim
65!> L is DOUBLE PRECISION array, dimension (ldl,k)
66!> On entry, the unit lower triangular matrix L. On exit,
67!> the updated unit lower triangular matrix L1.
68!> \endverbatim
69!>
70!> \param[in] ldl
71!> \verbatim
72!> ldl is INTEGER
73!> The leading dimension of the array L. ldl >= m.
74!> \endverbatim
75!>
76!> \param[in,out] R
77!> \verbatim
78!> R is DOUBLE PRECISION array, dimension (ldr,n)
79!> On entry, the upper trapezoidal m-by-n matrix R.
80!> On exit, the updated upper trapezoidal matrix R1.
81!> \endverbatim
82!>
83!> \param[in] ldr
84!> \verbatim
85!> ldr is INTEGER
86!> The leading dimension of the array R. ldr >= k,
87!> where k = min(m,n).
88!> \endverbatim
89!>
90!> \param[in] p
91!> \verbatim
92!> p is INTEGER array, dimension (m)
93!> The permutation vector representing the row pivoting.
94!> On exit, p is updated to reflect the new pivoting.
95!> \endverbatim
96!>
97!> \param[in] u
98!> \verbatim
99!> u is DOUBLE PRECISION array, dimension (m)
100!> The left m-vector defining the rank-1 modification.
101!> \endverbatim
102!>
103!> \param[in] v
104!> \verbatim
105!> v is DOUBLE PRECISION array, dimension (n)
106!> The right n-vector defining the rank-1 modification.
107!> \endverbatim
108!>
109!> \param[out] w
110!> \verbatim
111!> w is DOUBLE PRECISION array, dimension (m)
112!> Workspace vector used during the update computation.
113!> \endverbatim
114!>
115!> \ingroup ludecomp
116subroutine dlup1up(m,n,L,ldl,R,ldr,p,u,v,w)
117 use iso_fortran_env
119 integer, intent(in) :: m, n, ldl, ldr
120 integer, intent(inout) :: p(*)
121 real(real64), intent(inout) :: L(ldl,*)
122 real(real64), intent(inout) :: R(ldr,*)
123 real(real64), intent(in) :: u(*)
124 real(real64), intent(in) :: v(*)
125 real(real64), intent(out) :: w(*)
126 real(real64) one,tau,tmp
127 parameter(one = 1d0, tau = 1d-1)
128 integer k,info,i,j,itmp
129 external dcopy,daxpy,dtrsv,dger,dgemv,dswap
130 ! quick return if possible.
131 k = min(m,n)
132 if (k == 0) return
133 ! check arguments.
134 info = 0
135 if (m < 0) then
136 info = 1
137 else if (n < 0) then
138 info = 2
139 else if (ldl < m) then
140 info = 4
141 else if (ldr < k) then
142 info = 6
143 endif
144 if (info /= 0) then
145 call qrupdate_xerror('DLUP1UP',info)
146 return
147 end if
148 ! form L \ P*u.
149 do i = 1,m
150 w(i) = u(p(i))
151 end do
152 call dtrsv('L','N','U',k,l,ldl,w,1)
153 ! if m > k = n, subtract the trailing part.
154 if (m > k) then
155 call dgemv('N',m-k,k,-one,l(k+1,1),ldl,w,1,one,w(k+1),1)
156 end if
157 ! work from bottom to top
158 do j = k-1,1,-1
159 if (abs(w(j)) < tau * abs(l(j+1,j)*w(j) + w(j+1))) then
160 ! need pivoting. swap j and j+1
161 tmp = w(j)
162 w(j) = w(j+1)
163 w(j+1) = tmp
164 ! update p
165 itmp = p(j)
166 p(j) = p(j+1)
167 p(j+1) = itmp
168 ! update L
169 call dswap(m-j+1,l(j,j),1,l(j,j+1),1)
170 call dswap(j+1,l(j,1),ldl,l(j+1,1),ldl)
171 ! update R
172 call dswap(n-j+1,r(j,j),ldr,r(j+1,j),ldr)
173 ! make L lower triangular again
174 tmp = -l(j,j+1)
175 call daxpy(m-j+1,tmp,l(j,j),1,l(j,j+1),1)
176 ! update R
177 call daxpy(n-j+1,-tmp,r(j+1,j),ldr,r(j,j),ldr)
178 ! update w
179 w(j) = w(j) - tmp*w(j+1)
180 end if
181 ! eliminate w(j+1)
182 tmp = w(j+1)/w(j)
183 w(j+1) = 0
184 ! update R.
185 call daxpy(n-j+1,-tmp,r(j,j),ldr,r(j+1,j),ldr)
186 ! update L.
187 call daxpy(m-j,tmp,l(j+1,j+1),1,l(j+1,j),1)
188 end do
189 ! add a multiple of v to R
190 call daxpy(n,w(1),v,1,r(1,1),ldr)
191 ! forward sweep
192 do j = 1,k-1
193 if (abs(r(j,j)) < tau * abs(l(j+1,j)*r(j,j) + r(j+1,j))) then
194 ! need pivoting. swap j and j+1
195 ! update p
196 itmp = p(j)
197 p(j) = p(j+1)
198 p(j+1) = itmp
199 ! update L
200 call dswap(m-j+1,l(j,j),1,l(j,j+1),1)
201 call dswap(j+1,l(j,1),ldl,l(j+1,1),ldl)
202 ! update R
203 call dswap(n-j+1,r(j,j),ldr,r(j+1,j),ldr)
204 ! make L lower triangular again
205 tmp = -l(j,j+1)
206 call daxpy(m-j+1,tmp,l(j,j),1,l(j,j+1),1)
207 ! update R
208 call daxpy(n-j+1,-tmp,r(j+1,j),ldr,r(j,j),ldr)
209 end if
210 ! eliminate R(j+1,j)
211 tmp = r(j+1,j)/r(j,j)
212 ! update R.
213 r(j+1,j) = 0d0
214 call daxpy(n-j,-tmp,r(j,j+1),ldr,r(j+1,j+1),ldr)
215 ! update L.
216 call daxpy(m-j,tmp,l(j+1,j+1),1,l(j+1,j),1)
217 end do
218 ! if m > k = n, complete the update by updating the lower part of L.
219 if (m > k) then
220 call dcopy(k,v,1,w,1)
221 call dtrsv('U','T','N',k,r,ldr,w,1)
222 call dger(m-k,k,one,w(k+1),1,w,1,l(k+1,1),ldl)
223 endif
224end subroutine
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
subroutine dlup1up(m, n, l, ldl, r, ldr, p, u, v, w)
Updates a row-pivoted LU factorization after rank-1 modification.
Definition dlup1up.f90:117
Module for custom error handling.