qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
cch1dn.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 cch1dn(n,R,ldr,u,rw,info)
26!>
27!> .. Scalar Arguments ..
28!> integer n, ldr, info
29!> ..
30!> .. Array Arguments ..
31!> complex R(ldr,*), u(*)
32!> real rw(*)
33!> ..
34!> \endverbatim
35!>
36!> \par Purpose:
37! =============
38!> \verbatim
39!>
40!> CCH1DN 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!> CCH1DN 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 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 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 REAL 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 cch1dn(n,R,ldr,u,rw,info)
98 use iso_fortran_env
100 integer, intent(in) :: n, ldr
101 complex(real32), intent(inout) :: R(ldr,*)
102 complex(real32), intent(inout) :: u(*)
103 real(real32), intent(out) :: rw(*)
104 integer, intent(out) :: info
105 external ctrsv,clartg,scnrm2
106 complex(real32) crho,rr,ui,t
107 real(real32) scnrm2,rho
108 integer i,j
109 ! quick return if possible.
110 if (n == 0) return
111 ! check arguments.
112 info = 0
113 if (n < 0) then
114 info = -1
115 else if (ldr < n) then
116 info = -3
117 end if
118 if (info /= 0) then
119 call qrupdate_xerror('CCH1DN',-info)
120 return
121 end if
122 ! check for singularity of R.
123 do i = 1,n
124 if (r(i,i) == 0e0) goto 20
125 end do
126 ! form R' \ u
127 call ctrsv('U','C','N',n,r,ldr,u,1)
128 rho = scnrm2(n,u,1)
129 ! check positive definiteness
130 rho = 1 - rho**2
131 if (rho <= 0e0) goto 10
132 crho = sqrt(rho)
133 ! eliminate R' \ u
134 do i = n,1,-1
135 ui = u(i)
136 ! generate next rotation
137 call clartg(crho,ui,rw(i),u(i),rr)
138 crho = rr
139 end do
140 ! apply rotations
141 do i = n,1,-1
142 ui = 0e0
143 do j = i,1,-1
144 t = rw(j)*ui + u(j)*r(j,i)
145 r(j,i) = rw(j)*r(j,i) - conjg(u(j))*ui
146 ui = t
147 end do
148 end do
149 ! normal return
150 return
151 ! error returns
152 10 info = 1
153 return
154 20 info = 2
155 return
156end subroutine
subroutine cch1dn(n, r, ldr, u, rw, info)
Downdates a Cholesky factorization after a rank-1 modification.
Definition cch1dn.f90:98
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
Module for custom error handling.