qrupdate-ng
1.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
sgqvec.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 Generates a unit vector orthogonal to the column space of a unitary matrix.
21
!>
22
!> \par Definition:
23
! =============
24
!> \verbatim
25
!> subroutine sgqvec(m,n,Q,ldq,u)
26
!>
27
!> .. Scalar Arguments ..
28
!> integer m, n, ldq
29
!> ..
30
!> .. Array Arguments ..
31
!> real Q(ldq,*), u(*)
32
!> ..
33
!> \endverbatim
34
!>
35
!> \par Purpose:
36
! =============
37
!> \verbatim
38
!>
39
!> SGQVEC generates a vector u in the orthogonal complement of the
40
!> column space of an orthogonal matrix Q. Given an m-by-n
41
!> orthogonal matrix Q with n < m, SGQVEC generates a
42
!> vector u of length m such that Q.'*u = 0 and norm(u) = 1, where
43
!> Q.' denotes the transpose of Q.
44
!>
45
!> The algorithm projects canonical unit vectors onto the orthogonal
46
!> complement of Q's column space until a nonzero result is found.
47
!> If n = 0, the first canonical unit vector is returned.
48
!> \endverbatim
49
!>
50
!> \param[in] m
51
!> \verbatim
52
!> m is INTEGER
53
!> The number of rows of the matrix Q. m >= 0.
54
!> \endverbatim
55
!>
56
!> \param[in] n
57
!> \verbatim
58
!> n is INTEGER
59
!> The number of columns of the matrix Q. n >= 0 and
60
!> n < m.
61
!> \endverbatim
62
!>
63
!> \param[in] Q
64
!> \verbatim
65
!> Q is REAL array, dimension (ldq,n)
66
!> The orthogonal m-by-n matrix Q.
67
!> \endverbatim
68
!>
69
!> \param[in] ldq
70
!> \verbatim
71
!> ldq is INTEGER
72
!> The leading dimension of the array Q. ldq >= m.
73
!> \endverbatim
74
!>
75
!> \param[out] u
76
!> \verbatim
77
!> u is REAL array, dimension (m)
78
!> The generated vector such that Q.'*u = 0 and norm(u) = 1.
79
!> \endverbatim
80
!>
81
!> \ingroup qrdecomp
82
subroutine
sgqvec
(m,n,Q,ldq,u)
83
use
iso_fortran_env
84
use
qrupdate_error
85
integer
,
intent(in)
:: m, n, ldq
86
real
(real32),
intent(in)
:: Q(ldq,*)
87
real
(real32),
intent(out)
:: u(*)
88
external
sdot,saxpy,snrm2,sscal
89
real
(real32) sdot,snrm2,r
90
integer
info,i,j
91
! quick return if possible.
92
if
(m == 0)
return
93
if
(n == 0)
then
94
u(1) = 1e0
95
do
i = 2,m
96
u(i) = 0e0
97
end do
98
return
99
end if
100
! check arguments.
101
info = 0
102
if
(m < 0)
then
103
info = 1
104
else
if
(n < 0)
then
105
info = 2
106
else
if
(ldq < m)
then
107
info = 4
108
end if
109
if
(info /= 0)
then
110
call
qrupdate_xerror
(
'SGQVEC'
,info)
111
return
112
end if
113
j = 1
114
r = 0e0
115
do
while
( r .eq. 0e0 )
116
! probe j-th canonical unit vector.
117
do
i = 1,m
118
u(i) = 0e0
119
end do
120
u(j) = 1e0
121
! form u - Q*Q'*u
122
do
i = 1,n
123
r = sdot(m,q(1,i),1,u,1)
124
call
saxpy(m,-r,q(1,i),1,u,1)
125
end do
126
r = snrm2(m,u,1)
127
if
(r == 0e0)
then
128
j = j + 1
129
if
(j > n)
then
130
! this is fatal, and in theory, it can't happen.
131
stop
'fatal: impossible condition in SGQVEC'
132
end if
133
end if
134
end do
135
call
sscal(m,1e0/r,u,1)
136
end subroutine
qrupdate_error::qrupdate_xerror
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
Definition
qrupdate_error.f90:89
sgqvec
subroutine sgqvec(m, n, q, ldq, u)
Generates a unit vector orthogonal to the column space of a unitary matrix.
Definition
sgqvec.f90:83
qrupdate_error
Module for custom error handling.
Definition
qrupdate_error.f90:24
src
sgqvec.f90
Generated by
1.17.0