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