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