qrupdate-ng
1.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
schinx.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 schinx(n,R,ldr,j,u,w,info)
26
!>
27
!> .. Scalar Arguments ..
28
!> integer n, j, ldr, info
29
!> ..
30
!> .. Array Arguments ..
31
!> real R(ldr,*), u(*), w(*)
32
!> ..
33
!> \endverbatim
34
!>
35
!> \par Purpose:
36
! =============
37
!> \verbatim
38
!>
39
!> SCHINX updates the Cholesky factorization of a symmetric
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 transpose of R, this
43
!> SCHINX 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 REAL 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 REAL 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] w
87
!> \verbatim
88
!> w is REAL array, dimension (n+1)
89
!> Workspace vector used during the retriangularization.
90
!> \endverbatim
91
!>
92
!> \param[out] info
93
!> \verbatim
94
!> info is INTEGER
95
!> = 0: successful exit
96
!> = 1: the update would violate positive-definiteness
97
!> = 2: R is singular
98
!> \endverbatim
99
!>
100
!> \ingroup choldecomp
101
subroutine
schinx
(n,R,ldr,j,u,w,info)
102
use
iso_fortran_env
103
use
qrupdate_error
104
integer
,
intent(in)
:: n, j, ldr
105
real
(real32),
intent(inout)
:: R(ldr,*)
106
real
(real32),
intent(inout)
:: u(*)
107
real
(real32),
intent(out)
:: w(*)
108
integer
,
intent(out)
:: info
109
external
scopy,snrm2,strsv,sqrtv1,sqrqh
110
real
(real32) snrm2,rho,t
111
integer
i
112
! check arguments
113
info = 0
114
if
(n < 0)
then
115
info = -1
116
else
if
(j < 1 .or. j > n+1)
then
117
info = -4
118
end if
119
if
(info /= 0)
then
120
call
qrupdate_xerror
(
'SCHINX'
,info)
121
return
122
end if
123
! shift vector.
124
t = u(j)
125
do
i = j,n
126
u(i) = u(i+1)
127
end do
128
! check for singularity of R.
129
do
i = 1,n
130
if
(r(i,i) == 0e0)
goto
20
131
end do
132
! form R' \ u
133
call
strsv(
'U'
,
'T'
,
'N'
,n,r,ldr,u,1)
134
rho = snrm2(n,u,1)
135
! check positive definiteness.
136
rho = t - rho**2
137
if
(rho <= 0e0)
goto
10
138
! shift columns
139
do
i = n,j,-1
140
call
scopy(i,r(1,i),1,r(1,i+1),1)
141
r(i+1,i+1) = 0e0
142
end do
143
call
scopy(n,u,1,r(1,j),1)
144
r(n+1,j) = sqrt(rho)
145
! retriangularize
146
if
(j < n+1)
then
147
! eliminate the introduced spike.
148
call
sqrtv1
(n+2-j,r(j,j),w)
149
! apply rotations to R
150
call
sqrqh
(n+2-j,n+1-j,r(j,j+1),ldr,w,r(j+1,j))
151
! zero spike.
152
do
i = j+1,n+1
153
r(i,j) = 0e0
154
end do
155
end if
156
! normal return.
157
return
158
! error returns.
159
10 info = 1
160
return
161
20 info = 2
162
return
163
end subroutine
schinx
subroutine schinx(n, r, ldr, j, u, w, info)
Updates a Cholesky factorization after inserting a row and column.
Definition
schinx.f90:102
qrupdate_error::qrupdate_xerror
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
Definition
qrupdate_error.f90:89
sqrtv1
subroutine sqrtv1(n, u, w)
Generates Givens rotations to eliminate all but the first element of a vector.
Definition
sqrtv1.f90:74
sqrqh
subroutine sqrqh(m, n, r, ldr, c, s)
Converts an upper trapezoidal matrix to upper Hessenberg form.
Definition
sqrqh.f90:86
qrupdate_error
Module for custom error handling.
Definition
qrupdate_error.f90:24
src
schinx.f90
Generated by
1.17.0