qrupdate-ng
1.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
cqrinr.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 QR factorization after inserting a new row.
21
!>
22
!> \par Definition:
23
! =============
24
!> \verbatim
25
!> subroutine cqrinr(m,n,Q,ldq,R,ldr,j,x,rw)
26
!>
27
!> .. Scalar Arguments ..
28
!> integer m, n, ldq, ldr, j
29
!> ..
30
!> .. Array Arguments ..
31
!> complex Q(ldq,*)
32
!> complex R(ldr,*)
33
!> complex x(*)
34
!> real rw(*)
35
!> ..
36
!> \endverbatim
37
!>
38
!> \par Purpose:
39
! =============
40
!> \verbatim
41
!>
42
!> CQRINR updates a QR factorization after inserting a new row. i.e.,
43
!> given an m-by-m unitary matrix Q, an m-by-n upper trapezoidal matrix
44
!> R and index j in the range 1:m+1, CQRINR updates Q -> Q1 and
45
!> R -> R1 so that Q1 is again unitary, R1 upper trapezoidal, and Q1*R1
46
!> = [A(1:j-1,:); x; A(j:m,:)], where A = Q*R. (complex version)
47
!> \endverbatim
48
!>
49
!> \param[in] m
50
!> \verbatim
51
!> m is INTEGER
52
!> The number of rows of the matrix Q. m >= 0.
53
!> \endverbatim
54
!>
55
!> \param[in] n
56
!> \verbatim
57
!> n is INTEGER
58
!> The number of columns of the matrix R. n >= 0.
59
!> \endverbatim
60
!>
61
!> \param[in,out] Q
62
!> \verbatim
63
!> Q is COMPLEX array, dimension (ldq,*)
64
!> On entry, the unitary matrix Q. On exit, the
65
!> updated matrix Q1.
66
!> \endverbatim
67
!>
68
!> \param[in] ldq
69
!> \verbatim
70
!> ldq is INTEGER
71
!> The leading dimension of Q. ldq >= m+1.
72
!> \endverbatim
73
!>
74
!> \param[in,out] R
75
!> \verbatim
76
!> R is COMPLEX array, dimension (ldr,*)
77
!> On entry, the original matrix R. On exit, the
78
!> updated matrix R1.
79
!> \endverbatim
80
!>
81
!> \param[in] ldr
82
!> \verbatim
83
!> ldr is INTEGER
84
!> The leading dimension of R. ldr >= m+1.
85
!> \endverbatim
86
!>
87
!> \param[in] j
88
!> \verbatim
89
!> j is INTEGER
90
!> The position of the new row in R1. 1 <= j <= m+1.
91
!> \endverbatim
92
!>
93
!> \param[in,out] x
94
!> \verbatim
95
!> x is COMPLEX array, dimension (*)
96
!> On entry, the row being added. On exit, x is
97
!> destroyed.
98
!> \endverbatim
99
!>
100
!> \param[out] rw
101
!> \verbatim
102
!> rw is REAL array, dimension (*)
103
!> A real workspace vector of size min(m,n).
104
!> \endverbatim
105
!>
106
!> \ingroup qrdecomp
107
subroutine
cqrinr
(m,n,Q,ldq,R,ldr,j,x,rw)
108
use
iso_fortran_env
109
use
qrupdate_error
110
integer
,
intent(in)
:: m, n, j, ldq, ldr
111
complex(real32)
,
intent(inout)
:: Q(ldq,*)
112
complex(real32)
,
intent(inout)
:: R(ldr,*)
113
complex(real32)
,
intent(inout)
:: x(*)
114
real
(real32),
intent(out)
:: rw(*)
115
external
ccopy,cqhqr,cqrot
116
integer
info,i,k
117
! check arguments
118
info = 0
119
if
(n < 0)
then
120
info = 2
121
else
if
(j < 1 .or. j > m+1)
then
122
info = 7
123
end if
124
if
(info /= 0)
then
125
call
qrupdate_xerror
(
'CQRINR'
,info)
126
return
127
end if
128
! permute the columns of Q1 and rows of R1 so that c the new row ends
129
! up being the topmost row of R1.
130
do
i = m,1,-1
131
if
(j > 1)
then
132
call
ccopy(j-1,q(1,i),1,q(1,i+1),1)
133
end if
134
q(j,i+1) = 0e0
135
if
(j <= m)
then
136
call
ccopy(m+1-j,q(j,i),1,q(j+1,i+1),1)
137
end if
138
end do
139
! set up the 1st column
140
do
i = 1,j-1
141
q(i,1) = 0e0
142
end do
143
q(j,1) = 1e0
144
do
i = j+1,m+1
145
q(i,1) = 0e0
146
end do
147
! set up the new matrix R1
148
do
k = 1,n
149
if
(k < m) r(m+1,k) = 0e0
150
do
i = min(m,k),1,-1
151
r(i+1,k) = r(i,k)
152
end do
153
r(1,k) = x(k)
154
end do
155
! retriangularize R
156
call
cqhqr
(m+1,n,r,ldr,rw,x)
157
! apply rotations to Q
158
call
cqrot
(
'F'
,m+1,min(m,n)+1,q,ldq,rw,x)
159
end subroutine
qrupdate_error::qrupdate_xerror
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
Definition
qrupdate_error.f90:89
cqrot
subroutine cqrot(dir, m, n, q, ldq, c, s)
Applies a sequence of Givens rotations from the right to a matrix.
Definition
cqrot.f90:101
cqhqr
subroutine cqhqr(m, n, r, ldr, c, s)
Reduces an upper Hessenberg matrix to upper trapezoidal form.
Definition
cqhqr.f90:91
cqrinr
subroutine cqrinr(m, n, q, ldq, r, ldr, j, x, rw)
Updates a QR factorization after inserting a new row.
Definition
cqrinr.f90:108
qrupdate_error
Module for custom error handling.
Definition
qrupdate_error.f90:24
src
cqrinr.f90
Generated by
1.17.0