qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
dch1dn.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 Downdates a Cholesky factorization after a rank-1 modification.
21!>
22!> \par Definition:
23! =============
24!> \verbatim
25!> subroutine dch1dn(n,R,ldr,u,w,info)
26!>
27!> .. Scalar Arguments ..
28!> integer n, ldr, info
29!> ..
30!> .. Array Arguments ..
31!> double precision R(ldr,*), u(*), w(*)
32!> ..
33!> \endverbatim
34!>
35!> \par Purpose:
36! =============
37!> \verbatim
38!>
39!> DCH1DN downdates the Cholesky factorization of a symmetric
40!> positive definite matrix A after a rank-1 modification. Given an
41!> upper triangular matrix R that is a Cholesky factor of A, i.e.,
42!> A = R.'*R, where R.' denotes the transpose of R, DCH1DN
43!> downdates R -> R1 so that R1.'*R1 = A - u*u.', where u is a
44!> given vector.
45!>
46!> The downdate is performed by applying a sequence of hyperbolic
47!> rotations to restore the upper triangular structure of R. On
48!> exit, u contains the rotation sines and w contains the rotation
49!> cosines used in the transformation.
50!> \endverbatim
51!>
52!> \param[in] n
53!> \verbatim
54!> n is INTEGER
55!> The order of matrix R. n >= 0.
56!> \endverbatim
57!>
58!> \param[in,out] R
59!> \verbatim
60!> R is DOUBLE PRECISION array, dimension (ldr,n)
61!> On entry, the upper triangular matrix R, the Cholesky
62!> factor of A. On exit, the updated upper triangular
63!> matrix R1, the Cholesky factor of A - u*u.'.
64!> \endverbatim
65!>
66!> \param[in] ldr
67!> \verbatim
68!> ldr is INTEGER
69!> The leading dimension of the array R. ldr >= n.
70!> \endverbatim
71!>
72!> \param[in,out] u
73!> \verbatim
74!> u is DOUBLE PRECISION array, dimension (n)
75!> On entry, the vector determining the rank-1 downdate.
76!> On exit, u contains the rotation sines used to
77!> transform R to R1.
78!> \endverbatim
79!>
80!> \param[out] w
81!> \verbatim
82!> w is DOUBLE PRECISION array, dimension (n)
83!> On exit, w contains the cosine parts of the
84!> rotations used to transform R to R1.
85!> \endverbatim
86!>
87!> \param[out] info
88!> \verbatim
89!> info is INTEGER
90!> = 0: successful exit
91!> = 1: the update would violate positive-definiteness
92!> = 2: R is singular
93!> \endverbatim
94!>
95!> \ingroup choldecomp
96subroutine dch1dn(n,R,ldr,u,w,info)
97 use iso_fortran_env
99 integer, intent(in) :: n, ldr
100 real(real64), intent(inout) :: R(ldr,*)
101 real(real64), intent(inout) :: u(*)
102 real(real64), intent(out) :: w(*)
103 integer, intent(out) :: info
104 external dtrsv,dlartg,dnrm2
105 real(real64) dnrm2,rho,rr,ui,t
106 integer i,j
107 ! quick return if possible.
108 if (n == 0) return
109 ! check arguments.
110 info = 0
111 if (n < 0) then
112 info = -1
113 else if (ldr < n) then
114 info = -3
115 end if
116 if (info /= 0) then
117 call qrupdate_xerror('DCH1DN',-info)
118 return
119 end if
120 ! check for singularity of R.
121 do i = 1,n
122 if (r(i,i) == 0d0) goto 20
123 end do
124 ! form R' \ u
125 call dtrsv('U','T','N',n,r,ldr,u,1)
126 rho = dnrm2(n,u,1)
127 ! check positive definiteness
128 rho = 1 - rho**2
129 if (rho <= 0d0) goto 10
130 rho = sqrt(rho)
131 ! eliminate R' \ u
132 do i = n,1,-1
133 ui = u(i)
134 ! generate next rotation
135 call dlartg(rho,ui,w(i),u(i),rr)
136 rho = rr
137 end do
138 ! apply rotations
139 do i = n,1,-1
140 ui = 0d0
141 do j = i,1,-1
142 t = w(j)*ui + u(j)*r(j,i)
143 r(j,i) = w(j)*r(j,i) - u(j)*ui
144 ui = t
145 end do
146 end do
147 ! normal return
148 return
149 ! error returns
150 10 info = 1
151 return
152 20 info = 2
153 return
154end subroutine
subroutine dch1dn(n, r, ldr, u, w, info)
Downdates a Cholesky factorization after a rank-1 modification.
Definition dch1dn.f90:97
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
Module for custom error handling.