qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
zlup1up.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 zlup1up(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 complex L(ldl,*), R(ldr,*), u(*), v(*), w(*)
33!> ..
34!> \endverbatim
35!>
36!> \par Purpose:
37! =============
38!> \verbatim
39!>
40!> ZLUP1UP 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), ZLUP1UP
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 conjugate
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 COMPLEX*16 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 COMPLEX*16 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 COMPLEX*16 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 COMPLEX*16 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 COMPLEX*16 array, dimension (m)
112!> Workspace vector used during the update computation.
113!> \endverbatim
114!>
115!> \ingroup ludecomp
116subroutine zlup1up(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 complex(real64), intent(inout) :: L(ldl,*), R(ldr,*)
122 complex(real64), intent(in) :: u(*), v(*)
123 complex(real64), intent(out) :: w(*)
124 complex(real64) one,tmp
125 real(real64) tau
126 parameter(one = 1d0, tau = 1d-1)
127 integer k,info,i,j,itmp
128 external zcopy,zaxpy,ztrsv,zgeru,zgemv,zswap
129 ! quick return if possible.
130 k = min(m,n)
131 if (k == 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 (ldl < m) then
139 info = 4
140 else if (ldr < k) then
141 info = 6
142 endif
143 if (info /= 0) then
144 call qrupdate_xerror('ZLUP1UP',info)
145 return
146 end if
147 ! form L \ P*u.
148 do i = 1,m
149 w(i) = u(p(i))
150 end do
151 call ztrsv('L','N','U',k,l,ldl,w,1)
152 ! if m > k = n, subtract the trailing part.
153 if (m > k) then
154 call zgemv('N',m-k,k,-one,l(k+1,1),ldl,w,1,one,w(k+1),1)
155 end if
156 ! work from bottom to top
157 do j = k-1,1,-1
158 if (abs(w(j)) < tau * abs(l(j+1,j)*w(j) + w(j+1))) then
159 ! need pivoting. swap j and j+1
160 tmp = w(j)
161 w(j) = w(j+1)
162 w(j+1) = tmp
163 ! update p
164 itmp = p(j)
165 p(j) = p(j+1)
166 p(j+1) = itmp
167 ! update L
168 call zswap(m-j+1,l(j,j),1,l(j,j+1),1)
169 call zswap(j+1,l(j,1),ldl,l(j+1,1),ldl)
170 ! update R
171 call zswap(n-j+1,r(j,j),ldr,r(j+1,j),ldr)
172 ! make L lower triangular again
173 tmp = -l(j,j+1)
174 call zaxpy(m-j+1,tmp,l(j,j),1,l(j,j+1),1)
175 ! update R
176 call zaxpy(n-j+1,-tmp,r(j+1,j),ldr,r(j,j),ldr)
177 ! update w
178 w(j) = w(j) - tmp*w(j+1)
179 end if
180 ! eliminate w(j+1)
181 tmp = w(j+1)/w(j)
182 w(j+1) = 0
183 ! update R.
184 call zaxpy(n-j+1,-tmp,r(j,j),ldr,r(j+1,j),ldr)
185 ! update L.
186 call zaxpy(m-j,tmp,l(j+1,j+1),1,l(j+1,j),1)
187 end do
188 ! add a multiple of v to R
189 call zaxpy(n,w(1),v,1,r(1,1),ldr)
190 ! forward sweep
191 do j = 1,k-1
192 if (abs(r(j,j)) < tau * abs(l(j+1,j)*r(j,j) + r(j+1,j))) then
193 ! need pivoting. swap j and j+1
194 ! update p
195 itmp = p(j)
196 p(j) = p(j+1)
197 p(j+1) = itmp
198 ! update L
199 call zswap(m-j+1,l(j,j),1,l(j,j+1),1)
200 call zswap(j+1,l(j,1),ldl,l(j+1,1),ldl)
201 ! update R
202 call zswap(n-j+1,r(j,j),ldr,r(j+1,j),ldr)
203 ! make L lower triangular again
204 tmp = -l(j,j+1)
205 call zaxpy(m-j+1,tmp,l(j,j),1,l(j,j+1),1)
206 ! update R
207 call zaxpy(n-j+1,-tmp,r(j+1,j),ldr,r(j,j),ldr)
208 end if
209 ! eliminate R(j+1,j)
210 tmp = r(j+1,j)/r(j,j)
211 ! update R.
212 r(j+1,j) = 0d0
213 call zaxpy(n-j,-tmp,r(j,j+1),ldr,r(j+1,j+1),ldr)
214 ! update L.
215 call zaxpy(m-j,tmp,l(j+1,j+1),1,l(j+1,j),1)
216 end do
217 ! if m > k = n, complete the update by updating the lower part of L.
218 if (m > k) then
219 call zcopy(k,v,1,w,1)
220 call ztrsv('U','T','N',k,r,ldr,w,1)
221 call zgeru(m-k,k,one,w(k+1),1,w,1,l(k+1,1),ldl)
222 endif
223end subroutine
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
subroutine zlup1up(m, n, l, ldl, r, ldr, p, u, v, w)
Updates a row-pivoted LU factorization after rank-1 modification.
Definition zlup1up.f90:117
Module for custom error handling.