qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
cchinx.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 Cholesky factorization after inserting a row and column.
21!>
22!> \par Definition:
23! =============
24!> \verbatim
25!> subroutine cchinx(n,R,ldr,j,u,rw,info)
26!>
27!> .. Scalar Arguments ..
28!> integer n, j, ldr, info
29!> ..
30!> .. Array Arguments ..
31!> complex R(ldr,*), u(*), rw(*)
32!> ..
33!> \endverbatim
34!>
35!> \par Purpose:
36! =============
37!> \verbatim
38!>
39!> CCHINX updates the Cholesky factorization of a hermitian
40!> positive definite matrix A after inserting a row and column.
41!> Given an upper triangular matrix R that is a Cholesky factor of
42!> A, i.e., A = R'*R, where R' denotes the conjugate transpose of
43!> R, CCHINX updates R -> R1 so that R1'*R1 = A1, where
44!> A1(jj,jj) = A, A1(j,:) = u', A1(:,j) = u, and
45!> jj = [1:j-1, j+1:n+1].
46!>
47!> On exit, u is destroyed and R is extended by one row and column.
48!> The insertion is performed by first solving R'*u = v, checking
49!> positive definiteness, and then retriangularizing.
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 COMPLEX array, dimension (ldr,n+1)
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 A1.
64!> \endverbatim
65!>
66!> \param[in] ldr
67!> \verbatim
68!> ldr is INTEGER
69!> The leading dimension of the array R. ldr >= n+1.
70!> \endverbatim
71!>
72!> \param[in] j
73!> \verbatim
74!> j is INTEGER
75!> The position of the inserted row and column.
76!> 1 <= j <= n+1.
77!> \endverbatim
78!>
79!> \param[in,out] u
80!> \verbatim
81!> u is COMPLEX array, dimension (n+1)
82!> On entry, the vector defining the inserted row/column.
83!> On exit, u is destroyed.
84!> \endverbatim
85!>
86!> \param[out] rw
87!> \verbatim
88!> rw is REAL array, dimension (n+1)
89!> Workspace vector used to store rotation cosines during
90!> the retriangularization.
91!> \endverbatim
92!>
93!> \param[out] info
94!> \verbatim
95!> info is INTEGER
96!> = 0: successful exit
97!> = 1: the update would violate positive-definiteness
98!> = 2: R is singular
99!> = 3: the diagonal element of u is not real
100!> \endverbatim
101!>
102!> \ingroup choldecomp
103subroutine cchinx(n,R,ldr,j,u,rw,info)
104 use iso_fortran_env
106 integer, intent(in) :: n, j, ldr
107 integer, intent(out) :: info
108 complex(real32), intent(inout) :: R(ldr,*)
109 complex(real32), intent(inout) :: u(*)
110 real(real32), intent(out) :: rw(*)
111 external ccopy,scnrm2,ctrsv,cqrtv1,cqrqh
112 complex(real32) t
113 real(real32) scnrm2,rho
114 integer i
115 ! check arguments
116 info = 0
117 if (n < 0) then
118 info = -1
119 else if (j < 1 .or. j > n+1) then
120 info = -4
121 end if
122 if (info /= 0) then
123 call qrupdate_xerror('CCHINX',info)
124 return
125 end if
126 ! shift vector.
127 t = u(j)
128 do i = j,n
129 u(i) = u(i+1)
130 end do
131 ! the diagonal element must be real.
132 if (imag(t) /= 0e0) goto 30
133 ! check for singularity of R.
134 do i = 1,n
135 if (r(i,i) == 0e0) goto 20
136 end do
137 ! form R' \ u
138 call ctrsv('U','C','N',n,r,ldr,u,1)
139 rho = scnrm2(n,u,1)
140 ! check positive definiteness.
141 rho = real(t, real32) - rho**2
142 if (rho <= 0e0) goto 10
143 ! shift columns
144 do i = n,j,-1
145 call ccopy(i,r(1,i),1,r(1,i+1),1)
146 r(i+1,i+1) = 0e0
147 end do
148 call ccopy(n,u,1,r(1,j),1)
149 r(n+1,j) = sqrt(rho)
150 ! retriangularize
151 if (j < n+1) then
152 ! eliminate the introduced spike.
153 call cqrtv1(n+2-j,r(j,j),rw)
154 ! apply rotations to R
155 call cqrqh(n+2-j,n+1-j,r(j,j+1),ldr,rw,r(j+1,j))
156 ! zero spike.
157 do i = j+1,n+1
158 r(i,j) = 0e0
159 end do
160 end if
161 ! normal return.
162 return
163 ! error returns.
164 10 info = 1
165 return
166 20 info = 2
167 return
168 30 info = 3
169 return
170end subroutine
subroutine cchinx(n, r, ldr, j, u, rw, info)
Updates a Cholesky factorization after inserting a row and column.
Definition cchinx.f90:104
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
subroutine cqrtv1(n, u, w)
Generates Givens rotations to eliminate all but the first element of a vector.
Definition cqrtv1.f90:75
subroutine cqrqh(m, n, r, ldr, c, s)
Converts an upper trapezoidal matrix to upper Hessenberg form.
Definition cqrqh.f90:89
Module for custom error handling.