qrupdate-ng 1.2.0
Loading...
Searching...
No Matches
sqrdec.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 deleting a column.
21!>
22!> \par Definition:
23! =============
24!> \verbatim
25!> subroutine sqrdec(m,n,k,Q,ldq,R,ldr,j,w)
26!>
27!> .. Scalar Arguments ..
28!> integer m, n, k, ldq, ldr, j
29!> ..
30!> .. Array Arguments ..
31!> real Q(ldq,*)
32!> real R(ldr,*)
33!> real w(*)
34!> ..
35!> \endverbatim
36!>
37!> \par Purpose:
38! =============
39!> \verbatim
40!>
41!> SQRDEC updates a QR factorization after deleting a column. i.e.,
42!> given an m-by-k orthogonal matrix Q, an k-by-n upper trapezoidal
43!> matrix R and index j in the range 1:n+1, SQRDEC updates the
44!> matrix Q -> Q1 and R -> R1 so that Q1 remains orthogonal, R1 is upper
45!> trapezoidal, and Q1*R1 = [A(:,1:j-1) A(:,j+1:n)], where A = Q*R.
46!> (real 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] k
62!> \verbatim
63!> k is INTEGER
64!> The number of columns of Q, and rows of R. Must be
65!> either k = m (full Q) or k = n < m (economical form,
66!> basis dimension will decrease).
67!> \endverbatim
68!>
69!> \param[in,out] Q
70!> \verbatim
71!> Q is REAL array, dimension (ldq,*)
72!> On entry, the orthogonal m-by-k matrix Q. On exit,
73!> the updated matrix Q1.
74!> \endverbatim
75!>
76!> \param[in] ldq
77!> \verbatim
78!> ldq is INTEGER
79!> The leading dimension of Q. ldq >= m.
80!> \endverbatim
81!>
82!> \param[in,out] R
83!> \verbatim
84!> R is REAL array, dimension (ldr,*)
85!> On entry, the original matrix R. On exit, the
86!> updated matrix R1.
87!> \endverbatim
88!>
89!> \param[in] ldr
90!> \verbatim
91!> ldr is INTEGER
92!> The leading dimension of R. ldr >= k.
93!> \endverbatim
94!>
95!> \param[in] j
96!> \verbatim
97!> j is INTEGER
98!> The position of the deleted column in R. 1 <= j <= n.
99!> \endverbatim
100!>
101!> \param[out] w
102!> \verbatim
103!> w is REAL array, dimension (*)
104!> A workspace vector of size k-j.
105!> \endverbatim
106!>
107!> \ingroup qrdecomp
108subroutine sqrdec(m,n,k,Q,ldq,R,ldr,j,w)
109 use iso_fortran_env
111 integer, intent(in) :: m, n, k, ldq, ldr, j
112 real(real32), intent(inout) :: Q(ldq,*), R(ldr,*)
113 real(real32), intent(out) :: w(*)
114 external scopy,sqhqr,sqrot
115 integer info,i
116 ! quick return if possible.
117 if (m == 0 .or. n == 0 .or. j == n) return
118 ! check arguments.
119 info = 0
120 if (m < 0) then
121 info = 1
122 else if (n < 0) then
123 info = 2
124 else if (k /= m .and. (k /= n .or. n >= m)) then
125 info = 3
126 else if (ldq < m) then
127 info = 5
128 else if (ldr < k) then
129 info = 7
130 else if (j < 1 .or. j > n+1) then
131 info = 8
132 end if
133 if (info /= 0) then
134 call qrupdate_xerror('SQRDEC',info)
135 return
136 end if
137 ! delete the j-th column.
138 do i = j,n-1
139 call scopy(k,r(1,i+1),1,r(1,i),1)
140 end do
141 ! retriangularize.
142 if (j < k) then
143 call sqhqr(k+1-j,n-j,r(j,j),ldr,w,r(1,n))
144 ! apply rotations to Q.
145 call sqrot('F',m,min(k,n)+1-j,q(1,j),ldq,w,r(1,n))
146 end if
147end subroutine
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
subroutine sqrot(dir, m, n, q, ldq, c, s)
Applies a sequence of Givens rotations from the right to a matrix.
Definition sqrot.f90:101
subroutine sqhqr(m, n, r, ldr, c, s)
Reduces an upper Hessenberg matrix to upper trapezoidal form.
Definition sqhqr.f90:90
subroutine sqrdec(m, n, k, q, ldq, r, ldr, j, w)
Updates a QR factorization after deleting a column.
Definition sqrdec.f90:109
Module for custom error handling.