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