qrupdate-ng
1.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
cgqvec.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 cgqvec(m,n,Q,ldq,u)
26
!>
27
!> .. Scalar Arguments ..
28
!> integer m, n, ldq
29
!> ..
30
!> .. Array Arguments ..
31
!> complex Q(ldq,*), u(*)
32
!> ..
33
!> \endverbatim
34
!>
35
!> \par Purpose:
36
! =============
37
!> \verbatim
38
!>
39
!> CGQVEC generates a vector u in the orthogonal complement of the
40
!> column space of a unitary matrix Q. Given an m-by-n unitary
41
!> matrix Q with n < m, CGQVEC generates a vector u of
42
!> length m such that Q'*u = 0 and norm(u) = 1, where Q' denotes
43
!> the conjugate 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 COMPLEX array, dimension (ldq,n)
66
!> The unitary 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 COMPLEX array, dimension (m)
78
!> The generated vector such that Q'*u = 0 and norm(u) = 1.
79
!> \endverbatim
80
!>
81
!> \ingroup qrdecomp
82
subroutine
cgqvec
(m,n,Q,ldq,u)
83
use
iso_fortran_env
84
use
qrupdate_blas
85
use
qrupdate_error
86
integer
,
intent(in)
:: m, n, ldq
87
complex(real32)
,
intent(in)
:: Q(ldq,*)
88
complex(real32)
,
intent(out)
:: u(*)
89
external
caxpy,scnrm2,csscal
90
real
(real32) scnrm2,r
91
complex(real32)
rc
92
integer
info,i,j
93
! quick return if possible.
94
if
(m == 0)
return
95
if
(n == 0)
then
96
u(1) = 1e0
97
do
i = 2,m
98
u(i) = 0e0
99
end do
100
return
101
end if
102
! check arguments.
103
info = 0
104
if
(m < 0)
then
105
info = 1
106
else
if
(n < 0)
then
107
info = 2
108
else
if
(ldq < m)
then
109
info = 4
110
end if
111
if
(info /= 0)
then
112
call
qrupdate_xerror
(
'CGQVEC'
,info)
113
return
114
end if
115
j = 1
116
r = 0e0
117
do
while
( r .eq. 0e0 )
118
! probe j-th canonical unit vector.
119
do
i = 1,m
120
u(i) = 0e0
121
end do
122
u(j) = 1e0
123
! form u - Q*Q'*u
124
do
i = 1,n
125
call
qrupdate_cdotc
(rc, m,q(1,i),1,u,1)
126
call
caxpy(m,-rc,q(1,i),1,u,1)
127
end do
128
r = scnrm2(m,u,1)
129
if
(r == 0e0)
then
130
j = j + 1
131
if
(j > n)
then
132
! this is fatal, and in theory, it can't happen.
133
stop
'fatal: impossible condition in CGQVEC'
134
end if
135
end if
136
end do
137
call
csscal(m,1e0/r,u,1)
138
end subroutine
qrupdate_error::qrupdate_xerror
subroutine qrupdate_xerror(srname, info)
Dispatches error reporting to the handler.
Definition
qrupdate_error.f90:89
cgqvec
subroutine cgqvec(m, n, q, ldq, u)
Generates a unit vector orthogonal to the column space of a unitary matrix.
Definition
cgqvec.f90:83
qrupdate_blas::qrupdate_cdotc
Definition
qrupdate_blas.f90:30
qrupdate_blas
Definition
qrupdate_blas.f90:25
qrupdate_error
Module for custom error handling.
Definition
qrupdate_error.f90:24
src
cgqvec.f90
Generated by
1.17.0