gesvdq(3)
π gesvdq(3) β Library Functions Manual
okay so bestie, you're reading gesvdq(3) out of the Library Functions Manual, and honestly? this one's a whole meal. it's the LAPACK squad that does your SVD and your QR with pivoting, and there are four flavors of it depending on whether your matrix is real or complex, single or double precision. no cap, it's giving "linear algebra final boss" energy π
β¨ NAME β¨
gesvdq β gesvdq: SVD, QR with pivoting π
π SYNOPSIS π
π«Ά Functions
so there's literally four of them, one per data type, and they all do the same iconic thing. here's the lineup:
subroutine cgesvdq(joba,jobp,jobr,jobu,jobv,m,n,a,lda,s,u,ldu,v,ldv,numrank,iwork,liwork,cwork,lcwork,rwork,lrwork,info) β CGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method for GE matrices πsubroutine dgesvdq(joba,jobp,jobr,jobu,jobv,m,n,a,lda,s,u,ldu,v,ldv,numrank,iwork,liwork,work,lwork,rwork,lrwork,info) β DGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method for GE matrices πsubroutine sgesvdq(joba,jobp,jobr,jobu,jobv,m,n,a,lda,s,u,ldu,v,ldv,numrank,iwork,liwork,work,lwork,rwork,lrwork,info) β SGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method for GE matrices πsubroutine zgesvdq(joba,jobp,jobr,jobu,jobv,m,n,a,lda,s,u,ldu,v,ldv,numrank,iwork,liwork,cwork,lcwork,rwork,lrwork,info) β ZGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method for GE matrices π
π¦ Detailed Description π¦
π§ Function Documentation
β subroutine cgesvdq β
subroutine cgesvdq (character joba, character jobp, character jobr,
character jobu, character jobv, integer m, integer n, complex,
dimension( lda, * ) a, integer lda, real, dimension( * ) s, complex,
dimension( ldu, * ) u, integer ldu, complex, dimension( ldv, * ) v,
integer ldv, integer numrank, integer, dimension( * ) iwork, integer
liwork, complex, dimension( * ) cwork, integer lcwork, real, dimension(
* ) rwork, integer lrwork, integer info)
CGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method for GE matrices π
πΈ Purpose πΈ
okay so, what does it actually do? here's the tea:
CGESVDQ computes the singular value decomposition (SVD) of a complex M-by-N matrix A, where M >= N. The SVD of A is written as
[++] [xx] [x0] [xx]
A = U * SIGMA * V^*, [++] = [xx] * [ox] * [xx]
[++] [xx]
where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal matrix, and V is an N-by-N unitary matrix. The diagonal elements of SIGMA are the singular values of A. The columns of U and V are the left and the right singular vectors of A, respectively.
periodt. that's the whole vibe π
π Parameters π
π JOBA
JOBA is CHARACTER*1 Specifies the level of accuracy in the computed SVD
'A'β the requested accuracy corresponds to having the backward error bounded by|| delta A ||_F <= f(m,n) * EPS * || A ||_F, whereEPS = SLAMCH('Epsilon'). This authorises CGESVDQ to truncate the computed triangular factor in a rank revealing QR factorization whenever the truncated part is below the threshold of the order ofEPS * ||A||_F. This is aggressive truncation level π₯'M'β similarly as with'A', but the truncation is more gentle: it is allowed only when there is a drop on the diagonal of the triangular factor in the QR factorization. This is medium truncation level π«'H'β high accuracy requested. No numerical rank determination based on the rank revealing QR factorization is attempted π―'E'β same as'H', and in addition the condition number of column scaled A is estimated and returned inRWORK(1).N^(-1/4)*RWORK(1) <= ||pinv(A_scaled)||_2 <= N^(1/4)*RWORK(1)β
π JOBP
JOBP is CHARACTER*1
'P'β the rows of A are ordered in decreasing order with respect to||A(i,:)||_\infty. This enhances numerical accuracy at the cost of extra data movement. Recommended for numerical robustness π‘οΈ'N'β no row pivoting π
π JOBR
JOBR is CHARACTER*1
'T'β after the initial pivoted QR factorization, CGESVD is applied to the adjointR**Hof the computed triangular factor R. This involves some extra data movement (matrix transpositions). Useful for experiments, research and development π§ͺ'N'β the triangular factor R is given as input to CGESVD. This may be preferred as it involves less data movement π
π JOBU
JOBU is CHARACTER*1
'A'β all M left singular vectors are computed and returned in the matrix U. See the description of U π'S'or'U'βN = min(M,N)left singular vectors are computed and returned in the matrix U. See the description of U π'R'β numerical rank NUMRANK is determined and only NUMRANK left singular vectors are computed and returned in the matrix U π―'F'β the N left singular vectors are returned in factored form as the product of the Q factor from the initial QR factorization and the N left singular vectors of(R**H , 0)**H. If row pivoting is used, then the necessary information on the row pivoting is stored inIWORK(N+1:N+M-1)π¦'N'β the left singular vectors are not computed π
π JOBV
JOBV is CHARACTER*1
'A','V'β all N right singular vectors are computed and returned in the matrix V π'R'β numerical rank NUMRANK is determined and only NUMRANK right singular vectors are computed and returned in the matrix V. This option is allowed only ifJOBU = 'R'orJOBU = 'N'; otherwise it is illegal π¨'N'β the right singular vectors are not computed π
π M
M isINTEGERThe number of rows of the input matrix A.M >= 0.π
π N
N isINTEGERThe number of columns of the input matrix A.M >= N >= 0.π
π A
A isCOMPLEXarray of dimensionsLDA x NOn entry, the input matrix A. On exit, ifJOBU .NE. 'N'orJOBV .NE. 'N', the lower triangle of A contains the Householder vectors as stored by CGEQP3. IfJOBU = 'F', these Householder vectors together withCWORK(1:N)can be used to restore the Q factors from the initial pivoted QR factorization of A. See the description of U. π
π LDA
LDA isINTEGER. The leading dimension of the array A.LDA >= max(1,M).π
π S
S isREALarray of dimension N. The singular values of A, ordered so thatS(i) >= S(i+1).π
π U
U is COMPLEX array, dimension
LDU x MifJOBU = 'A'; see the description of LDU. In this case, on exit, U contains the M left singular vectors πLDU x NifJOBU = 'S','U','R'; see the description of LDU. In this case, U contains the leading N or the leading NUMRANK left singular vectors πLDU x NifJOBU = 'F'; see the description of LDU. In this case U contains N x N unitary matrix that can be used to form the left singular vectors π
If JOBU = 'N', U is not referenced π
π LDU
LDU is INTEGER. The leading dimension of the array U.
- If
JOBU = 'A','S','U','R'βLDU >= max(1,M). - If
JOBU = 'F'βLDU >= max(1,N). - Otherwise β
LDU >= 1.
π V
V isCOMPLEXarray, dimensionLDV x NifJOBV = 'A','V','R'or ifJOBA = 'E'.
- If
JOBV = 'A', or'V', V contains the N-by-N unitary matrixV**Hπ - If
JOBV = 'R', V contains the first NUMRANK rows ofV**H(the right singular vectors, stored rowwise, of the NUMRANK largest singular values) π - If
JOBV = 'N'andJOBA = 'E', V is used as a workspace π οΈ - If
JOBV = 'N', andJOBA.NE.'E', V is not referenced π
π LDV
LDV is INTEGER The leading dimension of the array V.
- If
JOBV = 'A','V','R', orJOBA = 'E'βLDV >= max(1,N). - Otherwise β
LDV >= 1.
π NUMRANK
NUMRANK isINTEGERNUMRANK is the numerical rank first determined after the rank revealing QR factorization, following the strategy specified by the value of JOBA. IfJOBV = 'R'andJOBU = 'R', only NUMRANK leading singular values and vectors are then requested in the call of CGESVD. The final value of NUMRANK might be further reduced if some singular values are computed as zeros π
π IWORK
IWORK isINTEGERarray, dimension(max(1, LIWORK)).On exit,IWORK(1:N)contains column pivoting permutation of the rank revealing QR factorization. IfJOBP = 'P',IWORK(N+1:N+M-1)contains the indices of the sequence of row swaps used in row pivoting. These can be used to restore the left singular vectors in the caseJOBU = 'F'.
If LIWORK, LCWORK, or LRWORK =-1, then on exit, ifINFO = 0,IWORK(1)returns the minimal LIWORK π
π LIWORK
LIWORK is INTEGER The dimension of the array IWORK.
LIWORK >= N + M - 1,ifJOBP = 'P';LIWORK >= NifJOBP = 'N'.
If LIWORK = -1, then a workspace query is assumed; the routine only calculates and returns the optimal and minimal sizes for the CWORK, IWORK, and RWORK arrays, and no error message related to LCWORK is issued by XERBLA π¨
π CWORK
CWORK is a COMPLEX array, dimension (max(2, LCWORK)), and it's here to be your workspace bestie π
On exit, if β on entry β LCWORK.NE.-1, then CWORK(1:N) contains the parameters you need to recover the Q factor from the QR factorization that CGEQP3 computed. (iykyk π)
And if LIWORK, LCWORK, or LRWORK = -1, then on exit, if INFO = 0:
CWORK(1)returns the optimalLCWORKCWORK(2)returns the minimalLCWORK
LCWORK β the size math, bestie π₯
LCWORK is INTEGER. It's the dimension of the array CWORK, and it's determined as follows. First, let:
LWQP3 = N+1, LWCON = 2*N, and let
LWUNQ = { MAX( N, 1 ), if JOBU = 'R', 'S', or 'U'
{ MAX( M, 1 ), if JOBU = 'A'
LWSVD = MAX( 3*N, 1 )
LWLQF = MAX( N/2, 1 ), LWSVD2 = MAX( 3*(N/2), 1 ), LWUNLQ = MAX( N, 1 ),
LWQRF = MAX( N/2, 1 ), LWUNQ2 = MAX( N, 1 )
Then the minimal value of LCWORK is:
= MAX( N + LWQP3, LWSVD )β if only the singular values are needed= MAX( N + LWQP3, LWCON, LWSVD )β if only the singular values are needed, and a scaled condition estimate requested= N + MAX( LWQP3, LWSVD, LWUNQ )β if the singular values and the left singular vectors are requested= N + MAX( LWQP3, LWCON, LWSVD, LWUNQ )β if the singular values and the left singular vectors are requested, and also a scaled condition estimate requested= N + MAX( LWQP3, LWSVD )β if the singular values and the right singular vectors are requested= N + MAX( LWQP3, LWCON, LWSVD )β if the singular values and the right singular vectors are requested, and also a scaled condition etimate requested= N + MAX( LWQP3, LWSVD, LWUNQ )β if the full SVD is requested withJOBV = 'R'; independent ofJOBR= N + MAX( LWQP3, LWCON, LWSVD, LWUNQ )β if the full SVD is requested,JOBV = 'R'and, also a scaled condition estimate requested; independent ofJOBR= MAX( N + MAX( LWQP3, LWSVD, LWUNQ ), N + MAX( LWQP3, N/2+LWLQF, N/2+LWSVD2, N/2+LWUNLQ, LWUNQ) )β if the full SVD is requested withJOBV = 'A'or'V', andJOBR ='N'= MAX( N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ), N + MAX( LWQP3, LWCON, N/2+LWLQF, N/2+LWSVD2, N/2+LWUNLQ, LWUNQ ) )β if the full SVD is requested withJOBV = 'A'or'V', andJOBR ='N', and also a scaled condition number estimate requested.= MAX( N + MAX( LWQP3, LWSVD, LWUNQ ), N + MAX( LWQP3, N/2+LWQRF, N/2+LWSVD2, N/2+LWUNQ2, LWUNQ ) )β if the full SVD is requested withJOBV = 'A','V', andJOBR ='T'= MAX( N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ), N + MAX( LWQP3, LWCON, N/2+LWQRF, N/2+LWSVD2, N/2+LWUNQ2, LWUNQ ) )β if the full SVD is requested withJOBV = 'A','V'andJOBR ='T', and also a scaled condition number estimate requested.
Finally β and this is the floor, no negotiating β LCWORK must be at least two: LCWORK = MAX( 2, LCWORK ). π«Ά
IfLCWORK = -1, then a workspace query is assumed. The routine only calculates and returns the optimal and minimal sizes for theCWORK,IWORK, andRWORKarrays, and no error message related toLCWORKis issued byXERBLA. (So don't go looking for a drag, there isn't one π )
RWORK πΈ
RWORK is REAL array, dimension (max(1, LRWORK)).
On exit:
- If
JOBA = 'E',RWORK(1)contains an estimate of the condition number of column scaled A. IfA = C * DwhereDis diagonal andChas unit columns in the Euclidean norm, then, assuming full column rank,N^(-1/4) * RWORK(1) <= ||pinv(C)||_2 <= N^(1/4) * RWORK(1). Otherwise,RWORK(1) = -1. RWORK(2)contains the number of singular values computed as exact zeros inCGESVDapplied to the upper triangular or trapezoidalR(from the initial QR factorization). In case of early exit (no call toCGESVD, such as in the case of zero matrix)RWORK(2) = -1.
If LIWORK, LCWORK, or LRWORK = -1, then on exit, if INFO = 0, RWORK(1) returns the minimal LRWORK. β
LRWORK π¦
LRWORK is INTEGER. It's the dimension of the array RWORK.
- If
JOBP ='P', thenLRWORK >= MAX(2, M, 5*N) - Otherwise,
LRWORK >= MAX(2, 5*N)
IfLRWORK = -1, then a workspace query is assumed. The routine only calculates and returns the optimal and minimal sizes for theCWORK,IWORK, andRWORKarrays, and no error message related toLCWORKis issued byXERBLA. (Yes, it saysLCWORKhere β not a typo of mine, that's literally what the source says π)
INFO π
INFO is INTEGER:
= 0: successful exit. periodt. β¨< 0: ifINFO = -i, the i-th argument had an illegal value. π> 0: ifCBDSQRdid not converge,INFOspecifies how many superdiagonals of an intermediate bidiagonal formB(computed inCGESVD) did not converge to zero. π
Further Details (the behind-the-scenes tea β)
- The data movement (matrix transpose) is coded using simple nested DO-loops because BLAS and LAPACK do not provide corresponding subroutines. Those DO-loops are easily identified in this source code β by the
CONTINUEstatements labeled with11**. In an optimized version of this code, the nested DO loops should be replaced with calls to an optimized subroutine. - This code scales
Aby1/SQRT(M)if the largestABS(A(i,j))could cause column norm overflow. This is the minial precaution (yes, that's the spelling in the source, love that for them π«Ά) and it is left to the SVD routine (CGESVD) to do its own preemptive scaling if potential over- or underflows are detected. To avoid repeated scanning of the arrayA, an optimal implementation would do all necessary scaling before callingCGESVDand the scaling inCGESVDcan be switched off. - Other comments related to code optimization are given in comments in the code, enclosed in
[[double brackets]].
Bugs, examples and comments ππ¬
Please report all bugs and send interesting examples and/or comments to drmac@math.hr. Thank you. π«Ά
References π
- [1] Zlatko Drmac, Algorithm 977: A QR-Preconditioned QR SVD Method for Computing the SVD with High Accuracy. ACM Trans. Math. Softw. 44(1): 11:1-11:30 (2017)
- SIGMA library, xGESVDQ section updated February 2016.
- Developed and coded by Zlatko Drmac, Department of Mathematics University of Zagreb, Croatia,
drmac@math.hr
Contributors: π§
Developed and coded by Zlatko Drmac, Department of Mathematics University of Zagreb, Croatia, drmac@math.hr
Author π
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Definition at line 410 of file cgesvdq.f.
π and now, the DGESVDQ girlies π
subroutine dgesvdq (character joba, character jobp, character jobr,
character jobu, character jobv, integer m, integer n, double precision,
dimension( lda, * ) a, integer lda, double precision, dimension( * ) s,
double precision, dimension( ldu, * ) u, integer ldu, double precision,
dimension( ldv, * ) v, integer ldv, integer numrank, integer, dimension(
* ) iwork, integer liwork, double precision, dimension( * ) work,
integer lwork, double precision, dimension( * ) rwork, integer lrwork,
integer info)
DGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method for GE matrices. iconic behaviour, honestly.
Purpose: β¨
DGESVDQ computes the singular value decomposition (SVD) of a real M-by-N matrix A, where M >= N. The SVD of A is written as
[++] [xx] [x0] [xx]
A = U * SIGMA * V^*, [++] = [xx] * [ox] * [xx]
[++] [xx]
where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal matrix, and V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA are the singular values of A. The columns of U and V are the left and the right singular vectors of A, respectively. π
Parameters
JOBA π―
JOBA is CHARACTER*1. It specifies the level of accuracy in the computed SVD:
= 'A'β The requested accuracy corresponds to having the backward error bounded by|| delta A ||_F <= f(m,n) * EPS * || A ||_F, whereEPS = DLAMCH('Epsilon'). This authorisesDGESVDQto truncate the computed triangular factor in a rank revealing QR factorization whenever the truncated part is below the threshold of the order ofEPS * ||A||_F. This is aggressive truncation level. π₯= 'M'β Similarly as with'A', but the truncation is more gentle: it is allowed only when there is a drop on the diagonal of the triangular factor in the QR factorization. This is medium truncation level.= 'H'β High accuracy requested. No numerical rank determination based on the rank revealing QR factorization is attempted. π= 'E'β Same as'H', and in addition the condition number of column scaledAis estimated and returned inRWORK(1).N^(-1/4)*RWORK(1) <= ||pinv(A_scaled)||_2 <= N^(1/4)*RWORK(1)
JOBP π
JOBP is CHARACTER*1:
= 'P'β The rows ofAare ordered in decreasing order with respect to||A(i,:)||_\infty. This enhances numerical accuracy at the cost of extra data movement. Recommended for numerical robustness. π= 'N'β No row pivoting.
JOBR
JOBR
= 'T'β so after the initial pivoted QR factorization,DGESVDgets applied to the transposedR**Tof the computed triangular factorR. Heads up: that means some extra data movement (matrix transpositions, ugh). Lowkey only really useful for experiments, research and development. π§ͺ= 'N'β the triangular factorRgoes straight intoDGESVDas input. This one might be preferred fr, since it involves less data movement. β¨
JOBU
JOBU is CHARACTER*1:
= 'A'β allMleft singular vectors get computed and returned in the matrixU. Peep the description ofU. π= 'S'or'U'βN = min(M,N)left singular vectors get computed and returned in the matrixU. Again, see the description ofU.= 'R'β the numerical rankNUMRANKis determined, and onlyNUMRANKleft singular vectors are computed and returned in the matrixU.= 'F'β theNleft singular vectors come back in factored form, as the product of theQfactor from the initial QR factorization and theNleft singular vectors of(R**T , 0)**T. Not me explaining this twice: if row pivoting is used, then the necessary info on the row pivoting is stored inIWORK(N+1:N+M-1). π= 'N'β the left singular vectors are not computed. We're just not doing that today. π ββοΈ
JOBV
JOBV is CHARACTER*1:
= 'A', 'V'β allNright singular vectors are computed and returned in the matrixV.= 'R'β the numerical rankNUMRANKis determined, and onlyNUMRANKright singular vectors are computed and returned in the matrixV. β οΈ This option is allowed only ifJOBU = 'R'orJOBU = 'N'; otherwise it is illegal. Like, genuinely illegal, don't.= 'N'β the right singular vectors are not computed.
M
M is INTEGER
The number of rows of the input matrix A. M >= 0. π
N
N is INTEGER
The number of columns of the input matrix A. M >= N >= 0. (Yes bestie, M >= N β that's the vibe check and A has to pass it.) β
A
A is DOUBLE PRECISION array of dimensions LDA x N
On entry, the input matrix A. π«Ά
On exit, if JOBU .NE. 'N' or JOBV .NE. 'N', the lower triangle of A contains the Householder vectors as stored by DGEQP3. And if JOBU = 'F', those Householder vectors, together with WORK(1:N), can be used to restore the Q factors from the initial pivoted QR factorization of A. See the description of U. π
LDA
LDA is INTEGER.
The leading dimension of the array A. LDA >= max(1,M). π
S
S is DOUBLE PRECISION array of dimension N.
The singular values of A, ordered so that S(i) >= S(i+1). Descending order, the way we like it. π
U
U is DOUBLE PRECISION array, dimension
LDU x MifJOBU = 'A'; see the description ofLDU. In this case, on exit,Ucontains theMleft singular vectors.LDU x NifJOBU = 'S','U','R'; see the description ofLDU. In this case,Ucontains the leadingNor the leadingNUMRANKleft singular vectors.LDU x NifJOBU = 'F'; see the description ofLDU. In this caseUcontains anN x Northogonal matrix that can be used to form the left singular vectors.
If JOBU = 'N', U is not referenced. Iconic behaviour honestly, it's just not invited. π
LDU
LDU is INTEGER.
The leading dimension of the array U.
- If
JOBU = 'A','S','U','R', thenLDU >= max(1,M). - If
JOBU = 'F', thenLDU >= max(1,N). - Otherwise,
LDU >= 1.
V
V is DOUBLE PRECISION array, dimension
LDV x NifJOBV = 'A','V','R'or ifJOBA = 'E'.- If
JOBV = 'A', or'V',Vcontains theN-by-Northogonal matrixV**T. - If
JOBV = 'R',Vcontains the firstNUMRANKrows ofV**T(the right singular vectors, stored rowwise, of theNUMRANKlargest singular values). π§ - If
JOBV = 'N'andJOBA = 'E',Vis used as a workspace. - If
JOBV = 'N', andJOBA.NE.'E',Vis not referenced.
LDV
LDV is INTEGER
The leading dimension of the array V.
- If
JOBV = 'A','V','R', orJOBA = 'E', thenLDV >= max(1,N). - Otherwise,
LDV >= 1.
NUMRANK
NUMRANK is INTEGER
NUMRANK is the numerical rank first determined after the rank revealing QR factorization, following the strategy specified by the value of JOBA. π If JOBV = 'R' and JOBU = 'R', only NUMRANK leading singular values and vectors are then requested in the call of DGESVD. And heads up: the final value of NUMRANK might be further reduced if some singular values are computed as zeros. It can shrink, basically. π
IWORK
IWORK is INTEGER array, dimension (max(1, LIWORK)).
On exit, IWORK(1:N) contains the column pivoting permutation of the rank revealing QR factorization. π
If JOBP = 'P', IWORK(N+1:N+M-1) contains the indices of the sequence of row swaps used in row pivoting. These can be used to restore the left singular vectors in the case JOBU = 'F'. Keep them, you'll want them.
If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, IWORK(1) returns the minimal LIWORK. β¨
LIWORK
LIWORK is INTEGER
The dimension of the array IWORK. So:
LIWORK >= N + M - 1, if JOBP = 'P' and JOBA .NE. 'E';
LIWORK >= N if JOBP = 'N' and JOBA .NE. 'E';
LIWORK >= N + M - 1 + N, if JOBP = 'P' and JOBA = 'E';
LIWORK >= N + N if JOBP = 'N' and JOBA = 'E'.
If LIWORK = -1, then a workspace query is assumed; the routine only calculates and returns the optimal and minimal sizes for the WORK, IWORK, and RWORK arrays, and no error message related to LWORK is issued by XERBLA. π
WORK
WORK is DOUBLE PRECISION array, dimension (max(2, LWORK)), used as a workspace.
On exit, if, on entry, LWORK.NE.-1, WORK(1:N) contains parameters needed to recover the Q factor from the QR factorization computed by DGEQP3. π οΈ
If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0:
WORK(1)returns the optimalLWORK, andWORK(2)returns the minimalLWORK.
LWORK
LWORK is INTEGER
The dimension of the array WORK. It is determined as follows. Prepare yourself bestie, this is the whole formula sheet: π
Let LWQP3 = 3*N+1, LWCON = 3*N, and let
LWORQ = { MAX( N, 1 ), if JOBU = 'R', 'S', or 'U'
{ MAX( M, 1 ), if JOBU = 'A'
LWSVD = MAX( 5*N, 1 )
LWLQF = MAX( N/2, 1 ), LWSVD2 = MAX( 5*(N/2), 1 ), LWORLQ = MAX( N, 1 ),
LWQRF = MAX( N/2, 1 ), LWORQ2 = MAX( N, 1 )
Then the minimal value of LWORK is:
= MAX( N + LWQP3, LWSVD ) if only the singular values are needed;
= MAX( N + LWQP3, LWCON, LWSVD ) if only the singular values are needed,
and a scaled condition estimate requested;
= N + MAX( LWQP3, LWSVD, LWORQ ) if the singular values and the left
singular vectors are requested;
= N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the singular values and the left
singular vectors are requested, and also
a scaled condition estimate requested;
= N + MAX( LWQP3, LWSVD ) if the singular values and the right
singular vectors are requested;
= N + MAX( LWQP3, LWCON, LWSVD ) if the singular values and the right
singular vectors are requested, and also
a scaled condition etimate requested;
= N + MAX( LWQP3, LWSVD, LWORQ ) if the full SVD is requested with JOBV = 'R';
independent of JOBR;
= N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the full SVD is requested,
JOBV = 'R' and, also a scaled condition
estimate requested; independent of JOBR;
= MAX( N + MAX( LWQP3, LWSVD, LWORQ ),
N + MAX( LWQP3, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ) ) if the
full SVD is requested with JOBV = 'A' or 'V', and
JOBR ='N'
= MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ),
N + MAX( LWQP3, LWCON, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ ) )
if the full SVD is requested with JOBV = 'A' or 'V', and
JOBR ='N', and also a scaled condition number estimate
requested.
= MAX( N + MAX( LWQP3, LWSVD, LWORQ ),
N + MAX( LWQP3, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) ) if the
full SVD is requested with JOBV = 'A', 'V', and JOBR ='T'
= MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ),
N + MAX( LWQP3, LWCON, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) )
if the full SVD is requested with JOBV = 'A' or 'V', and
JOBR ='T', and also a scaled condition number estimate
requested.
Finally, LWORK must be at least two: LWORK = MAX( 2, LWORK ).
If LWORK = -1, then a workspace query is assumed; the routine only calculates and returns the optimal and minimal sizes for the WORK, IWORK, and RWORK arrays, and no error message related to LWORK is issued by XERBLA. No cap, that's a free pass on the error message. π¦
RWORK
(coming right up, keep scrolling bestie π)
RWORKβDOUBLE PRECISIONarray, dimension(max(1, LRWORK)). On exit, bestie:- If
JOBA = 'E',RWORK(1)contains an estimate of the condition number of column scaledA. IfA = C * DwhereDis diagonal andChas unit columns in the Euclidean norm, then, assuming full column rank,N^(-1/4) * RWORK(1) <= ||pinv(C)||_2 <= N^(1/4) * RWORK(1). Otherwise,RWORK(1) = -1. RWORK(2)contains the number of singular values computed as exact zeros inDGESVDapplied to the upper triangular or trapezoidalR(from the initial QR factorization). In case of early exit (no call toDGESVD, such as in the case of zero matrix)RWORK(2) = -1.
- If
If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, RWORK(1) returns the minimal LRWORK.
LRWORKβINTEGER. The dimension of the arrayRWORK. IfJOBP ='P', thenLRWORK >= MAX(2, M). Otherwise,LRWORK >= 2.
If LRWORK = -1, then a workspace query is assumed; the routine only calculates and returns the optimal and minimal sizes for the WORK, IWORK, and RWORK arrays, and no error message related to LWORK is issued by XERBLA.
INFOβINTEGER.= 0: successful exit.< 0: ifINFO = -i, the i-th argument had an illegal value.> 0: ifDBDSQRdid not converge,INFOspecifies how many superdiagonals of an intermediate bidiagonal formB(computed inDGESVD) did not converge to zero.
Further Details π
- The data movement (matrix transpose) is coded using simple nested
DO-loops becauseBLASandLAPACKdo not provide corresponding subroutines. ThoseDO-loops are easily identified in this source code β by theCONTINUEstatements labeled with11**. In an optimized version of this code, the nestedDOloops should be replaced with calls to an optimized subroutine. - This code scales
Aby1/SQRT(M)if the largestABS(A(i,j))could cause column norm overflow. This is the minial precaution and it is left to the SVD routine (CGESVD) to do its own preemptive scaling if potential over- or underflows are detected. To avoid repeated scanning of the arrayA, an optimal implementation would do all necessary scaling before callingCGESVDand the scaling inCGESVDcan be switched off. - Other comments related to code optimization are given in comments in the code, enclosed in
[[double brackets]].
Bugs, examples and comments ππ
Please report all bugs and send interesting examples and/or comments to drmac@math.hr. Thank you.
References π
- [1] Zlatko Drmac, Algorithm 977: A QR-Preconditioned QR SVD Method for Computing the SVD with High Accuracy. ACM Trans. Math. Softw. 44(1): 11:1-11:30 (2017)
- SIGMA library, xGESVDQ section updated February 2016. Developed and coded by Zlatko Drmac, Department of Mathematics University of Zagreb, Croatia,
drmac@math.hr
Contributors π«Ά
Developed and coded by Zlatko Drmac, Department of Mathematics University of Zagreb, Croatia, drmac@math.hr
Author π
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Definition at line 412 of file dgesvdq.f.
subroutine sgesvdq (character joba, character jobp, character jobr,
character jobu, character jobv, integer m, integer n, real, dimension(
lda, * ) a, integer lda, real, dimension( * ) s, real, dimension( ldu, *
) u, integer ldu, real, dimension( ldv, * ) v, integer ldv, integer
numrank, integer, dimension( * ) iwork, integer liwork, real, dimension(
* ) work, integer lwork, real, dimension( * ) rwork, integer lrwork,
integer info)
SGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method for GE matrices
Purpose π―
SGESVDQ computes the singular value decomposition (SVD) of a real M-by-N matrix A, where M >= N. The SVD of A is written as
[++] [xx] [x0] [xx]
A = U * SIGMA * V^*, [++] = [xx] * [ox] * [xx]
[++] [xx]
where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal matrix, and V is an N-by-N orthogonal matrix. The diagonal elements of SIGMA are the singular values of A. The columns of U and V are the left and the right singular vectors of A, respectively.
Parameters β¨
JOBAβCHARACTER*1. Specifies the level of accuracy in the computed SVD.= 'A': The requested accuracy corresponds to having the backward error bounded by|| delta A ||_F <= f(m,n) * EPS * || A ||_F, whereEPS = SLAMCH('Epsilon'). This authorisesCGESVDQto truncate the computed triangular factor in a rank revealing QR factorization whenever the truncated part is below the threshold of the order ofEPS * ||A||_F. This is aggressive truncation level.= 'M': Similarly as with'A', but the truncation is more gentle: it is allowed only when there is a drop on the diagonal of the triangular factor in the QR factorization. This is medium truncation level.= 'H': High accuracy requested. No numerical rank determination based on the rank revealing QR factorization is attempted.= 'E': Same as'H', and in addition the condition number of column scaledAis estimated and returned inRWORK(1).N^(-1/4)*RWORK(1) <= ||pinv(A_scaled)||_2 <= N^(1/4)*RWORK(1)
JOBPβCHARACTER*1.= 'P': The rows ofAare ordered in decreasing order with respect to||A(i,:)||_\infty. This enhances numerical accuracy at the cost of extra data movement. Recommended for numerical robustness.= 'N': No row pivoting.
JOBRβCHARACTER*1.= 'T': After the initial pivoted QR factorization,SGESVDis applied to the transposedR**Tof the computed triangular factorR. This involves some extra data movement (matrix transpositions). Useful for experiments, research and development.= 'N': The triangular factorRis given as input toSGESVD. This may be preferred as it involves less data movement.
JOBUβCHARACTER*1.= 'A': AllMleft singular vectors are computed and returned in the matrixU. See the description ofU.= 'S'or'U':N = min(M,N)left singular vectors are computed and returned in the matrixU. See the description ofU.= 'R': Numerical rankNUMRANKis determined and onlyNUMRANKleft singular vectors are computed and returned in the matrixU.= 'F': TheNleft singular vectors are returned in factored form as the product of theQfactor from the initial QR factorization and theNleft singular vectors of(R**T , 0)**T. If row pivoting is used, then the necessary information on the row pivoting is stored inIWORK(N+1:N+M-1).= 'N': The left singular vectors are not computed.
JOBVβCHARACTER*1.= 'A', 'V': AllNright singular vectors are computed and returned in the matrixV.= 'R': Numerical rankNUMRANKis determined and onlyNUMRANKright singular vectors are computed and returned in the matrixV. This option is allowed only ifJOBU = 'R'orJOBU = 'N'; otherwise it is illegal.= 'N': The right singular vectors are not computed.
MβINTEGER. The number of rows of the input matrixA.M >= 0.NβINTEGER. The number of columns of the input matrixA.M >= N >= 0.AβREALarray of dimensionsLDA x N. On entry, the input matrixA. On exit, ifJOBU .NE. 'N'orJOBV .NE. 'N', the lower triangle ofAcontains the Householder vectors as stored bySGEQP3. IfJOBU = 'F', these Householder vectors together withWORK(1:N)can be used to restore theQfactors from the initial pivoted QR factorization ofA. See the description ofU.LDAβINTEGER. The leading dimension of the arrayA.LDA >= max(1,M).SβREALarray of dimensionN. The singular values ofA, ordered so thatS(i) >= S(i+1).UβREALarray, dimensionLDU x MifJOBU = 'A'; see the description ofLDU. In this case, on exit,Ucontains theMleft singular vectors.LDU x NifJOBU = 'S', 'U', 'R'; see the description ofLDU. In this case,Ucontains the leadingNor the leadingNUMRANKleft singular vectors.LDU x NifJOBU = 'F'; see the description ofLDU. In this caseUcontainsN x Northogonal matrix that can be used to form the left singular vectors. IfJOBU = 'N',Uis not referenced.LDUβINTEGER. The leading dimension of the arrayU. IfJOBU = 'A', 'S', 'U', 'R',LDU >= max(1,M). IfJOBU = 'F',LDU >= max(1,N). Otherwise,LDU >= 1.VβVβ this one is a REAL array, dimensionLDV x NifJOBV = 'A','V','R'or ifJOBA = 'E'. IfJOBV = 'A', or'V',Vcontains the N-by-N orthogonal matrixV**T; ifJOBV = 'R',Vcontains the firstNUMRANKrows ofV**T(the right singular vectors, stored rowwise, of theNUMRANKlargest singular values). IfJOBV = 'N'andJOBA = 'E',Vis used as a workspace. IfJOBV = 'N', andJOBA.NE.'E',Vis not referenced.LDVβ INTEGER, bestie. It's the leading dimension of the arrayV. IfJOBV = 'A','V','R', orJOBA = 'E', thenLDV >= max(1,N). Otherwise,LDV >= 1.NUMRANKβ INTEGER.NUMRANKis the numerical rank first determined after the rank revealing QR factorization, following the strategy specified by the value ofJOBA. IfJOBV = 'R'andJOBU = 'R', onlyNUMRANKleading singular values and vectors are then requested in the call ofSGESVD. The final value ofNUMRANKmight be further reduced if some singular values are computed as zeros.IWORKβ INTEGER array, dimension(max(1, LIWORK)). On exit,IWORK(1:N)contains column pivoting permutation of the rank revealing QR factorization. IfJOBP = 'P',IWORK(N+1:N+M-1)contains the indices of the sequence of row swaps used in row pivoting. These can be used to restore the left singular vectors in the caseJOBU = 'F'. IfLIWORK,LWORK, orLRWORK = -1, then on exit, ifINFO = 0,IWORK(1)returns the minimalLIWORK.LIWORKβ INTEGER. The dimension of the arrayIWORK.LIWORK >= N + M - 1, ifJOBP = 'P'andJOBA .NE. 'E';LIWORK >= NifJOBP = 'N'andJOBA .NE. 'E';LIWORK >= N + M - 1 + N, ifJOBP = 'P'andJOBA = 'E';LIWORK >= N + NifJOBP = 'N'andJOBA = 'E'. IfLIWORK = -1, then a workspace query is assumed; the routine only calculates and returns the optimal and minimal sizes for theWORK,IWORK, andRWORKarrays, and no error message related toLWORKis issued byXERBLA.WORKβ REAL array, dimension(max(2, LWORK)), used as a workspace. On exit, if, on entry,LWORK.NE.-1,WORK(1:N)contains parameters needed to recover the Q factor from the QR factorization computed bySGEQP3. IfLIWORK,LWORK, orLRWORK = -1, then on exit, ifINFO = 0,WORK(1)returns the optimalLWORK, andWORK(2)returns the minimalLWORK.LWORKβ INTEGER. It's the dimension of the arrayWORK, and it is determined as follows β buckle up, because this is the formula drop:
Let LWQP3 = 3*N+1, LWCON = 3*N, and let
LWORQ = { MAX( N, 1 ), if JOBU = 'R', 'S', or 'U'
{ MAX( M, 1 ), if JOBU = 'A'
LWSVD = MAX( 5*N, 1 )
LWLQF = MAX( N/2, 1 ), LWSVD2 = MAX( 5*(N/2), 1 ), LWORLQ = MAX( N, 1 ),
LWQRF = MAX( N/2, 1 ), LWORQ2 = MAX( N, 1 )
Then the minimal value of LWORK is:
= MAX( N + LWQP3, LWSVD ) if only the singular values are needed;
= MAX( N + LWQP3, LWCON, LWSVD ) if only the singular values are needed,
and a scaled condition estimate requested;
= N + MAX( LWQP3, LWSVD, LWORQ ) if the singular values and the left
singular vectors are requested;
= N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the singular values and the left
singular vectors are requested, and also
a scaled condition estimate requested;
= N + MAX( LWQP3, LWSVD ) if the singular values and the right
singular vectors are requested;
= N + MAX( LWQP3, LWCON, LWSVD ) if the singular values and the right
singular vectors are requested, and also
a scaled condition etimate requested;
= N + MAX( LWQP3, LWSVD, LWORQ ) if the full SVD is requested with JOBV = 'R';
independent of JOBR;
= N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the full SVD is requested,
JOBV = 'R' and, also a scaled condition
estimate requested; independent of JOBR;
= MAX( N + MAX( LWQP3, LWSVD, LWORQ ),
N + MAX( LWQP3, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ) ) if the
full SVD is requested with JOBV = 'A' or 'V', and
JOBR ='N'
= MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ),
N + MAX( LWQP3, LWCON, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ ) )
if the full SVD is requested with JOBV = 'A' or 'V', and
JOBR ='N', and also a scaled condition number estimate
requested.
= MAX( N + MAX( LWQP3, LWSVD, LWORQ ),
N + MAX( LWQP3, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) ) if the
full SVD is requested with JOBV = 'A', 'V', and JOBR ='T'
= MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ),
N + MAX( LWQP3, LWCON, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) )
if the full SVD is requested with JOBV = 'A' or 'V', and
JOBR ='T', and also a scaled condition number estimate
requested.
Finally, LWORK must be at least two: LWORK = MAX( 2, LWORK ).
If LWORK = -1, then a workspace query is assumed; the routine
only calculates and returns the optimal and minimal sizes
for the WORK, IWORK, and RWORK arrays, and no error
message related to LWORK is issued by XERBLA.
RWORKβ REAL array, dimension(max(1, LRWORK)). On exit:- If
JOBA = 'E',RWORK(1)contains an estimate of the condition number of column scaledA. IfA = C * DwhereDis diagonal andChas unit columns in the Euclidean norm, then, assuming full column rank,N^(-1/4) * RWORK(1) <= ||pinv(C)||_2 <= N^(1/4) * RWORK(1). Otherwise,RWORK(1) = -1. RWORK(2)contains the number of singular values computed as exact zeros inSGESVDapplied to the upper triangular or trapezoidalR(from the initial QR factorization). In case of early exit (no call toSGESVD, such as in the case of zero matrix)RWORK(2) = -1. IfLIWORK,LWORK, orLRWORK = -1, then on exit, ifINFO = 0,RWORK(1)returns the minimalLRWORK.
- If
LRWORKβ INTEGER. The dimension of the arrayRWORK. IfJOBP ='P', thenLRWORK >= MAX(2, M). Otherwise,LRWORK >= 2. IfLRWORK = -1, then a workspace query is assumed; the routine only calculates and returns the optimal and minimal sizes for theWORK,IWORK, andRWORKarrays, and no error message related toLWORKis issued byXERBLA.INFOβ INTEGER.= 0: successful exit.< 0: ifINFO = -i, the i-th argument had an illegal value.> 0: ifSBDSQRdid not converge,INFOspecifies how many superdiagonals of an intermediate bidiagonal formB(computed inSGESVD) did not converge to zero.
π Further Details π
- The data movement (matrix transpose) is coded using simple nested DO-loops because BLAS and LAPACK do not provide corresponding subroutines. Those DO-loops are easily identified in this source code β by the CONTINUE statements labeled with
11**. In an optimized version of this code, the nested DO loops should be replaced with calls to an optimized subroutine. - This code scales
Aby1/SQRT(M)if the largestABS(A(i,j))could cause column norm overflow. This is the minial precaution and it is left to the SVD routine (CGESVD) to do its own preemptive scaling if potential over- or underflows are detected. To avoid repeated scanning of the arrayA, an optimal implementation would do all necessary scaling before callingCGESVDand the scaling inCGESVDcan be switched off. - Other comments related to code optimization are given in comments in the code, enclosed in
[[double brackets]].
π Bugs, examples and comments π
Please report all bugs and send interesting examples and/or comments to drmac@math.hr. Thank you. π
π References π
[1] Zlatko Drmac, Algorithm 977: A QR-Preconditioned QR SVD Method for Computing the SVD with High Accuracy. ACM Trans. Math. Softw. 44(1): 11:1-11:30 (2017)
SIGMA library, xGESVDQ section updated February 2016. Developed and coded by Zlatko Drmac, Department of Mathematics University of Zagreb, Croatia, drmac@math.hr
π«Ά Contributors π«Ά
Developed and coded by Zlatko Drmac, Department of Mathematics University of Zagreb, Croatia, drmac@math.hr
π Author π
- Univ. of Tennessee
- Univ. of California Berkeley
- Univ. of Colorado Denver
- NAG Ltd.
Definition at line 412 of file sgesvdq.f.
subroutine zgesvdq (character joba, character jobp, character jobr,
character jobu, character jobv, integer m, integer n, complex*16,
dimension( lda, * ) a, integer lda, double precision, dimension( * ) s,
complex*16, dimension( ldu, * ) u, integer ldu, complex*16, dimension(
ldv, * ) v, integer ldv, integer numrank, integer, dimension( * ) iwork,
integer liwork, complex*16, dimension( * ) cwork, integer lcwork, double
precision, dimension( * ) rwork, integer lrwork, integer info)
ZGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method for GE matrices
Purpose
okay bestie, the doc block literally says ZCGESVDQ computes the singular value decomposition (SVD) of a complex M-by-N matrix A, where M >= N. The SVD of A is written as
[++] [xx] [x0] [xx]
A = U * SIGMA * V^*, [++] = [xx] * [ox] * [xx]
[++] [xx]
where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal matrix, and V is an N-by-N unitary matrix. The diagonal elements of SIGMA are the singular values of A. The columns of U and V are the left and the right singular vectors of A, respectively. iconic math behavior π
Parameters
JOBAβJOBAisCHARACTER*1. It specifies the level of accuracy in the computed SVD.= 'A'The requested accuracy corresponds to having the backward error bounded by|| delta A ||_F <= f(m,n) * EPS * || A ||_F, whereEPS = DLAMCH('Epsilon'). This authorisesZGESVDQto truncate the computed triangular factor in a rank revealing QR factorization whenever the truncated part is below the threshold of the order ofEPS * ||A||_F. This is aggressive truncation level.= 'M'Similarly as with'A', but the truncation is more gentle: it is allowed only when there is a drop on the diagonal of the triangular factor in the QR factorization. This is medium truncation level.= 'H'High accuracy requested. No numerical rank determination based on the rank revealing QR factorization is attempted.= 'E'Same as'H', and in addition the condition number of column scaled A is estimated and returned inRWORK(1).N^(-1/4)*RWORK(1) <= ||pinv(A_scaled)||_2 <= N^(1/4)*RWORK(1)
JOBPβJOBPisCHARACTER*1.= 'P'The rows of A are ordered in decreasing order with respect to||A(i,:)||_\infty. This enhances numerical accuracy at the cost of extra data movement. Recommended for numerical robustness.= 'N'No row pivoting.
JOBRβJOBRisCHARACTER*1.= 'T'After the initial pivoted QR factorization,ZGESVDis applied to the adjointR**Hof the computed triangular factor R. This involves some extra data movement (matrix transpositions). Useful for experiments, research and development.= 'N'The triangular factor R is given as input toCGESVD. This may be preferred as it involves less data movement.
JOBUβJOBUisCHARACTER*1.= 'A'All M left singular vectors are computed and returned in the matrix U. See the description of U.= 'S'or'U'N = min(M,N)left singular vectors are computed and returned in the matrix U. See the description of U.= 'R'Numerical rankNUMRANKis determined and onlyNUMRANKleft singular vectors are computed and returned in the matrix U.= 'F'The N left singular vectors are returned in factored form as the product of the Q factor from the initial QR factorization and the N left singular vectors of(R**H , 0)**H. If row pivoting is used, then the necessary information on the row pivoting is stored inIWORK(N+1:N+M-1).= 'N'The left singular vectors are not computed.
JOBVβJOBVisCHARACTER*1.= 'A','V'All N right singular vectors are computed and returned in the matrix V.= 'R'Numerical rankNUMRANKis determined and onlyNUMRANKright singular vectors are computed and returned in the matrix V. This option is allowed only ifJOBU = 'R'orJOBU = 'N'; otherwise it is illegal.= 'N'The right singular vectors are not computed.
MβMis INTEGER. The number of rows of the input matrix A.M >= 0.NβNis INTEGER. The number of columns of the input matrix A.M >= N >= 0.AβAisCOMPLEX*16array of dimensionsLDA x N. On entry, the input matrix A. On exit, ifJOBU .NE. 'N'orJOBV .NE. 'N', the lower triangle of A contains the Householder vectors as stored byZGEQP3. IfJOBU = 'F', these Householder vectors together withCWORK(1:N)can be used to restore the Q factors from the initial pivoted QR factorization of A. See the description of U.LDAβLDAis INTEGER. The leading dimension of the array A.LDA >= max(1,M).SβSisDOUBLE PRECISIONarray of dimension N. The singular values of A, ordered so thatS(i) >= S(i+1).UβUisCOMPLEX*16array, dimension:LDU x MifJOBU = 'A'; see the description ofLDU. In this case, on exit, U contains the M left singular vectors.LDU x NifJOBU = 'S','U','R'; see the description ofLDU. In this case, U contains the leading N or the leadingNUMRANKleft singular vectors.LDU x NifJOBU = 'F'; see the description ofLDU. In this case U contains N x N unitary matrix that can be used to form the left singular vectors.- If
JOBU = 'N', U is not referenced.
LDUβLDUis INTEGER. The leading dimension of the array U.- If
JOBU = 'A','S','U','R',LDU >= max(1,M). - If
JOBU = 'F',LDU >= max(1,N). - Otherwise,
LDU >= 1.
- If
VβVisCOMPLEX*16array, dimension:LDV x NifJOBV = 'A','V','R'or ifJOBA = 'E'.- If
JOBV = 'A', or'V', V contains the N-by-N unitary matrixV**H; - If
JOBV = 'R', V contains the firstNUMRANKrows ofV**H(the right singular vectors, stored rowwise, of theNUMRANKlargest singular values). - If
JOBV = 'N'andJOBA = 'E', V is used as a workspace. - If
JOBV = 'N', andJOBA.NE.'E', V is not referenced.
LDVβLDVis INTEGER. The leading dimension of the array V.- If
JOBV = 'A','V','R', orJOBA = 'E',LDV >= max(1,N). - Otherwise,
LDV >= 1.
- If
NUMRANKβNUMRANKis INTEGER.NUMRANKis the numerical rank first determined after the rank revealing QR factorization, following the strategy specified by the value ofJOBA. IfJOBV = 'R'andJOBU = 'R', onlyNUMRANKleading singular values and vectors are then requested in the call ofCGESVD. The final value ofNUMRANKmight be further reduced if some singular values are computed as zeros.IWORKβIWORKis INTEGER array, dimension(max(1, LIWORK)). On exit,IWORK(1:N)contains column pivoting permutation of the rank revealing QR factorization. IfJOBP = 'P',IWORK(N+1:N+M-1)contains the indices of the sequence of row swaps used in row pivoting. These can be used to restore the left singular vectors in the caseJOBU = 'F'. IfLIWORK,LCWORK, orLRWORK = -1, then on exit, ifINFO = 0,IWORK(1)returns the minimalLIWORK.LIWORKβLIWORKis INTEGER. The dimension of the arrayIWORK.LIWORK >= N + M - 1, ifJOBP = 'P';LIWORK >= NifJOBP = 'N'. IfLIWORK = -1, then a workspace query is assumed; the routine only calculates and returns the optimal and minimal sizes for theCWORK,IWORK, andRWORKarrays, and no error message related toLCWORKis issued byXERBLA.
CWORKβCWORKisCOMPLEX*12array, dimension(max(2, LCWORK)), used as a workspace. On exit, if, on entry,LCWORK.NE.-1,CWORK(1:N)contains parameters needed to recover the Q factor from the QR factorization computed byZGEQP3. IfLIWORK,LCWORK, orLRWORK = -1, then on exit, ifINFO = 0,CWORK(1)returns the optimalLCWORK, andCWORK(2)returns the minimalLCWORK.LCWORK
LCWORK is INTEGER, and itβs literally the dimension of the array CWORK π
. It gets determined like this:
Let LWQP3 = N+1, LWCON = 2*N, and let
LWUNQ = { MAX( N, 1 ), if JOBU = 'R', 'S', or 'U'
{ MAX( M, 1 ), if JOBU = 'A'
LWSVD = MAX( 3*N, 1 )
LWLQF = MAX( N/2, 1 ), LWSVD2 = MAX( 3*(N/2), 1 ), LWUNLQ = MAX( N, 1 ),
LWQRF = MAX( N/2, 1 ), LWUNQ2 = MAX( N, 1 )
Then the minimal value of LCWORK is:
= MAX( N + LWQP3, LWSVD ) if only the singular values are needed;
= MAX( N + LWQP3, LWCON, LWSVD ) if only the singular values are needed,
and a scaled condition estimate requested;
= N + MAX( LWQP3, LWSVD, LWUNQ ) if the singular values and the left
singular vectors are requested;
= N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ) if the singular values and the left
singular vectors are requested, and also
a scaled condition estimate requested;
= N + MAX( LWQP3, LWSVD ) if the singular values and the right
singular vectors are requested;
= N + MAX( LWQP3, LWCON, LWSVD ) if the singular values and the right
singular vectors are requested, and also
a scaled condition estimate requested;
= N + MAX( LWQP3, LWSVD, LWUNQ ) if the full SVD is requested with JOBV = 'R';
independent of JOBR;
= N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ) if the full SVD is requested,
JOBV = 'R' and, also a scaled condition
estimate requested; independent of JOBR;
= MAX( N + MAX( LWQP3, LWSVD, LWUNQ ),
N + MAX( LWQP3, N/2+LWLQF, N/2+LWSVD2, N/2+LWUNLQ, LWUNQ) ) if the
full SVD is requested with JOBV = 'A' or 'V', and
JOBR ='N'
= MAX( N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ),
N + MAX( LWQP3, LWCON, N/2+LWLQF, N/2+LWSVD2, N/2+LWUNLQ, LWUNQ ) )
if the full SVD is requested with JOBV = 'A' or 'V', and
JOBR ='N', and also a scaled condition number estimate
requested.
= MAX( N + MAX( LWQP3, LWSVD, LWUNQ ),
N + MAX( LWQP3, N/2+LWQRF, N/2+LWSVD2, N/2+LWUNQ2, LWUNQ ) ) if the
full SVD is requested with JOBV = 'A', 'V', and JOBR ='T'
= MAX( N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ),
N + MAX( LWQP3, LWCON, N/2+LWQRF, N/2+LWSVD2, N/2+LWUNQ2, LWUNQ ) )
if the full SVD is requested with JOBV = 'A', 'V' and
JOBR ='T', and also a scaled condition number estimate
requested.
Finally, LCWORK must be at least two: LCWORK = MAX( 2, LCWORK ).
If LCWORK = -1, then a workspace query is assumed; the routine only calculates and returns the optimal and minimal sizes for the CWORK, IWORK, and RWORK arrays, and no error message related to LCWORK is issued by XERBLA.
RWORK π
RWORK is a DOUBLE PRECISION array, dimension (max(1, LRWORK)).
On exit:
- If
JOBA = 'E',RWORK(1)contains an estimate of the condition number of column scaledA. IfA = C * DwhereDis diagonal andChas unit columns in the Euclidean norm, then, assuming full column rank,N^(-1/4) * RWORK(1) <= ||pinv(C)||_2 <= N^(1/4) * RWORK(1). Otherwise,RWORK(1) = -1. RWORK(2)contains the number of singular values computed as exact zeros inZGESVDapplied to the upper triangular or trapezoidalR(from the initial QR factorization). In case of early exit (no call toZGESVD, such as in the case of zero matrix)RWORK(2) = -1.
If LIWORK, LCWORK, or LRWORK = -1, then on exit, if INFO = 0, RWORK(1) returns the minimal LRWORK.
LRWORK π¦
LRWORK is INTEGER. Itβs the dimension of the array RWORK.
If JOBP = 'P', then LRWORK >= MAX(2, M, 5*N); Otherwise, LRWORK >= MAX(2, 5*N).
If LRWORK = -1, then a workspace query is assumed; the routine only calculates and returns the optimal and minimal sizes for the CWORK, IWORK, and RWORK arrays, and no error message related to LCWORK is issued by XERBLA.
INFO π
INFO is INTEGER.
= 0: successful exit.< 0: ifINFO = -i, the i-th argument had an illegal value.> 0: ifZBDSQRdid not converge,INFOspecifies how many superdiagonals of an intermediate bidiagonal formB(computed inZGESVD) did not converge to zero.
Further Details π§ β¨
- The data movement (matrix transpose) is coded using simple nested
DO-loops becauseBLASandLAPACKdo not provide corresponding subroutines. ThoseDO-loops are easily identified in this source code β by theCONTINUEstatements labeled with11**. In an optimized version of this code, the nestedDOloops should be replaced with calls to an optimized subroutine. - This code scales
Aby1/SQRT(M)if the largestABS(A(i,j))could cause column norm overflow. This is the minimal precaution and it is left to the SVD routine (CGESVD) to do its own preemptive scaling if potential over- or underflows are detected. To avoid repeated scanning of the arrayA, an optimal implementation would do all necessary scaling before callingCGESVDand the scaling inCGESVDcan be switched off. - Other comments related to code optimization are given in comments in the code, enclosed in
[[double brackets]].
Bugs, examples and comments ππ
Please report all bugs and send interesting examples and/or comments to drmac@math.hr. Thank you.
References π
[1] Zlatko Drmac, Algorithm 977: A QR-Preconditioned QR SVD Method for Computing the SVD with High Accuracy. ACM Trans. Math. Softw. 44(1): 11:1-11:30 (2017)
SIGMA library, xGESVDQ section updated February 2016.
Developed and coded by Zlatko Drmac, Department of Mathematics University of Zagreb, Croatia, drmac@math.hr
Contributors π«Ά
Developed and coded by Zlatko Drmac, Department of Mathematics University of Zagreb, Croatia, drmac@math.hr
Author π
- Univ. of Tennessee
- Univ. of California Berkeley
- Univ. of Colorado Denver
- NAG Ltd.
Definition at line 410 of file zgesvdq.f.
Author πΈ
Generated automatically by Doxygen for LAPACK from the source code.
Final sign-off, bestie: this page is from LAPACK, version 3.12.0, manual page gesvdq(3) β and the footer doesnβt give a date, so Iβm not making one up ππ
π¦ where this page comes from
- arch rolling: lapack-doc 3.12.1-2 Β· custom
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms