dggsvd.c
来自「InsightToolkit-1.4.0(有大量的优化算法程序)」· C语言 代码 · 共 278 行 · 第 1/2 页
C
278 行
/* See Purpose for details. */
/* */
/* LDA (input) INTEGER */
/* The leading dimension of the array A. LDA >= max(1,M). */
/* */
/* B (input/output) DOUBLE PRECISION array, dimension (LDB,N) */
/* On entry, the P-by-N matrix B. */
/* On exit, B contains the triangular matrix R if M-K-L < 0. */
/* See Purpose for details. */
/* */
/* LDB (input) INTEGER */
/* The leading dimension of the array B. LDA >= max(1,P). */
/* */
/* ALPHA (output) DOUBLE PRECISION array, dimension (N) */
/* BETA (output) DOUBLE PRECISION array, dimension (N) */
/* On exit, ALPHA and BETA contain the generalized singular */
/* value pairs of A and B; */
/* ALPHA(1:K) = 1, */
/* BETA(1:K) = 0, */
/* and if M-K-L >= 0, */
/* ALPHA(K+1:K+L) = C, */
/* BETA(K+1:K+L) = S, */
/* or if M-K-L < 0, */
/* ALPHA(K+1:M)=C, ALPHA(M+1:K+L)=0 */
/* BETA(K+1:M) =S, BETA(M+1:K+L) =1 */
/* and */
/* ALPHA(K+L+1:N) = 0 */
/* BETA(K+L+1:N) = 0 */
/* */
/* U (output) DOUBLE PRECISION array, dimension (LDU,M) */
/* If JOBU = 'U', U contains the M-by-M orthogonal matrix U. */
/* If JOBU = 'N', U is not referenced. */
/* */
/* LDU (input) INTEGER */
/* The leading dimension of the array U. LDU >= max(1,M) if */
/* JOBU = 'U'; LDU >= 1 otherwise. */
/* */
/* V (output) DOUBLE PRECISION array, dimension (LDV,P) */
/* If JOBV = 'V', V contains the P-by-P orthogonal matrix V. */
/* If JOBV = 'N', V is not referenced. */
/* */
/* LDV (input) INTEGER */
/* The leading dimension of the array V. LDV >= max(1,P) if */
/* JOBV = 'V'; LDV >= 1 otherwise. */
/* */
/* Q (output) DOUBLE PRECISION array, dimension (LDQ,N) */
/* If JOBQ = 'Q', Q contains the N-by-N orthogonal matrix Q. */
/* If JOBQ = 'N', Q is not referenced. */
/* */
/* LDQ (input) INTEGER */
/* The leading dimension of the array Q. LDQ >= max(1,N) if */
/* JOBQ = 'Q'; LDQ >= 1 otherwise. */
/* */
/* WORK (workspace) DOUBLE PRECISION array, */
/* dimension (max(3*N,M,P)+N) */
/* */
/* IWORK (workspace) INTEGER array, dimension (N) */
/* */
/* INFO (output)INTEGER */
/* = 0: successful exit */
/* < 0: if INFO = -i, the i-th argument had an illegal value. */
/* > 0: if INFO = 1, the Jacobi-type procedure failed to */
/* converge. For further details, see subroutine DTGSJA. */
/* */
/* Internal Parameters */
/* =================== */
/* */
/* TOLA DOUBLE PRECISION */
/* TOLB DOUBLE PRECISION */
/* TOLA and TOLB are the thresholds to determine the effective */
/* rank of (A',B')'. Generally, they are set to */
/* TOLA = MAX(M,N)*norm(A)*MACHEPS, */
/* TOLB = MAX(P,N)*norm(B)*MACHEPS. */
/* The size of TOLA and TOLB may affect the size of backward */
/* errors of the decomposition. */
/* */
/* ===================================================================== */
/* Test the input parameters */
wantu = lsame_(jobu, "U");
wantv = lsame_(jobv, "V");
wantq = lsame_(jobq, "Q");
*info = 0;
if (! (wantu || lsame_(jobu, "N"))) {
*info = -1;
} else if (! (wantv || lsame_(jobv, "N"))) {
*info = -2;
} else if (! (wantq || lsame_(jobq, "N"))) {
*info = -3;
} else if (*m < 0) {
*info = -4;
} else if (*n < 0) {
*info = -5;
} else if (*p < 0) {
*info = -6;
} else if (*lda < max(1,*m)) {
*info = -10;
} else if (*ldb < max(1,*p)) {
*info = -12;
} else if (*ldu < 1 || (wantu && *ldu < *m)) {
*info = -16;
} else if (*ldv < 1 || (wantv && *ldv < *p)) {
*info = -18;
} else if (*ldq < 1 || (wantq && *ldq < *n)) {
*info = -20;
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("DGGSVD", &i__1);
return;
}
/* Compute the Frobenius norm of matrices A and B */
anorm = dlange_("1", m, n, a, lda, work);
bnorm = dlange_("1", p, n, b, ldb, work);
/* Get machine precision and set up threshold for determining */
/* the effective numerical rank of the matrices A and B. */
ulp = dlamch_("Precision");
unfl = dlamch_("Safe Minimum");
tola = max(*m,*n) * max(anorm,unfl) * ulp;
tolb = max(*p,*n) * max(bnorm,unfl) * ulp;
/* Preprocessing */
dggsvp_(jobu, jobv, jobq, m, p, n, a, lda, b, ldb, &tola, &tolb, k, l,
u, ldu, v, ldv, q, ldq, iwork, work, &work[*n], info);
/* Compute the GSVD of two upper "triangular" matrices */
dtgsja_(jobu, jobv, jobq, m, p, n, k, l, a, lda, b, ldb, &tola, &tolb,
alpha, beta, u, ldu, v, ldv, q, ldq, work, &ncycle, info);
} /* dggsvd_ */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?