/* Subroutine */ int cchkbd_(integer *nsizes, integer *mval, integer *nval, integer *ntypes, logical *dotype, integer *nrhs, integer *iseed, real *thresh, complex *a, integer *lda, real *bd, real *be, real *s1, real *s2, complex *x, integer *ldx, complex *y, complex *z__, complex *q, integer *ldq, complex *pt, integer *ldpt, complex *u, complex *vt, complex *work, integer *lwork, real *rwork, integer *nout, integer * info) { /* Initialized data */ static integer ktype[16] = { 1,2,4,4,4,4,4,6,6,6,6,6,9,9,9,10 }; static integer kmagn[16] = { 1,1,1,1,1,2,3,1,1,1,2,3,1,2,3,0 }; static integer kmode[16] = { 0,0,4,3,1,4,4,4,3,1,4,4,0,0,0,0 }; /* Format strings */ static char fmt_9998[] = "(\002 CCHKBD: \002,a,\002 returned INFO=\002,i" "6,\002.\002,/9x,\002M=\002,i6,\002, N=\002,i6,\002, JTYPE=\002,i" "6,\002, ISEED=(\002,3(i5,\002,\002),i5,\002)\002)"; static char fmt_9999[] = "(\002 M=\002,i5,\002, N=\002,i5,\002, type " "\002,i2,\002, seed=\002,4(i4,\002,\002),\002 test(\002,i2,\002)" "=\002,g11.4)"; /* System generated locals */ integer a_dim1, a_offset, pt_dim1, pt_offset, q_dim1, q_offset, u_dim1, u_offset, vt_dim1, vt_offset, x_dim1, x_offset, y_dim1, y_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5, i__6, i__7; real r__1, r__2, r__3, r__4, r__5, r__6, r__7; /* Builtin functions Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); double log(doublereal), sqrt(doublereal), exp(doublereal); integer s_wsfe(cilist *), do_fio(integer *, char *, ftnlen), e_wsfe(void); /* Local variables */ static real cond; static integer jcol; static char path[3]; static integer mmax, nmax; static real unfl, ovfl; static char uplo[1]; static real temp1, temp2; static integer i__, j, m, n; extern /* Subroutine */ int cbdt01_(integer *, integer *, integer *, complex *, integer *, complex *, integer *, real *, real *, complex *, integer *, complex *, real *, real *); static logical badmm, badnn; extern /* Subroutine */ int cbdt02_(integer *, integer *, complex *, integer *, complex *, integer *, complex *, integer *, complex *, real *, real *), cbdt03_(char *, integer *, integer *, real *, real *, complex *, integer *, real *, complex *, integer *, complex *, real *); static integer nfail, imode; extern /* Subroutine */ int cgemm_(char *, char *, integer *, integer *, integer *, complex *, complex *, integer *, complex *, integer *, complex *, complex *, integer *); static real dumma[1]; static integer iinfo; extern /* Subroutine */ int cunt01_(char *, integer *, integer *, complex *, integer *, complex *, integer *, real *, real *); static real anorm; static integer mnmin, mnmax, jsize, itype, jtype, iwork[1], ntest; extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, integer *), slahd2_(integer *, char *); static integer log2ui; static logical bidiag; extern /* Subroutine */ int cgebrd_(integer *, integer *, complex *, integer *, real *, real *, complex *, complex *, complex *, integer *, integer *), slabad_(real *, real *); static integer mq; extern doublereal slamch_(char *); extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex *, integer *, complex *, integer *), claset_(char *, integer *, integer *, complex *, complex *, complex *, integer *), xerbla_(char *, integer *); static integer ioldsd[4]; extern /* Subroutine */ int cbdsqr_(char *, integer *, integer *, integer *, integer *, real *, real *, complex *, integer *, complex *, integer *, complex *, integer *, real *, integer *), cungbr_(char *, integer *, integer *, integer *, complex *, integer *, complex *, complex *, integer *, integer *), alasum_(char *, integer *, integer *, integer *, integer *); extern doublereal slarnd_(integer *, integer *); extern /* Subroutine */ int clatmr_(integer *, integer *, char *, integer *, char *, complex *, integer *, real *, complex *, char *, char * , complex *, integer *, real *, complex *, integer *, real *, char *, integer *, integer *, integer *, real *, real *, char *, complex *, integer *, integer *, integer *), clatms_(integer *, integer *, char *, integer *, char *, real *, integer *, real *, real *, integer *, integer *, char *, complex *, integer *, complex *, integer *); static real amninv; extern /* Subroutine */ int ssvdch_(integer *, real *, real *, real *, real *, integer *); static integer minwrk; static real rtunfl, rtovfl, ulpinv, result[14]; static integer mtypes; static real ulp; /* Fortran I/O blocks */ static cilist io___40 = { 0, 0, 0, fmt_9998, 0 }; static cilist io___41 = { 0, 0, 0, fmt_9998, 0 }; static cilist io___43 = { 0, 0, 0, fmt_9998, 0 }; static cilist io___44 = { 0, 0, 0, fmt_9998, 0 }; static cilist io___45 = { 0, 0, 0, fmt_9998, 0 }; static cilist io___46 = { 0, 0, 0, fmt_9998, 0 }; static cilist io___50 = { 0, 0, 0, fmt_9999, 0 }; #define a_subscr(a_1,a_2) (a_2)*a_dim1 + a_1 #define a_ref(a_1,a_2) a[a_subscr(a_1,a_2)] /* -- LAPACK test routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University September 30, 1994 Purpose ======= CCHKBD checks the singular value decomposition (SVD) routines. CGEBRD reduces a complex general m by n matrix A to real upper or lower bidiagonal form by an orthogonal transformation: Q' * A * P = B (or A = Q * B * P'). The matrix B is upper bidiagonal if m >= n and lower bidiagonal if m < n. CUNGBR generates the orthogonal matrices Q and P' from CGEBRD. Note that Q and P are not necessarily square. CBDSQR computes the singular value decomposition of the bidiagonal matrix B as B = U S V'. It is called three times to compute 1) B = U S1 V', where S1 is the diagonal matrix of singular values and the columns of the matrices U and V are the left and right singular vectors, respectively, of B. 2) Same as 1), but the singular values are stored in S2 and the singular vectors are not computed. 3) A = (UQ) S (P'V'), the SVD of the original matrix A. In addition, CBDSQR has an option to apply the left orthogonal matrix U to a matrix X, useful in least squares applications. For each pair of matrix dimensions (M,N) and each selected matrix type, an M by N matrix A and an M by NRHS matrix X are generated. The problem dimensions are as follows A: M x N Q: M x min(M,N) (but M x M if NRHS > 0) P: min(M,N) x N B: min(M,N) x min(M,N) U, V: min(M,N) x min(M,N) S1, S2 diagonal, order min(M,N) X: M x NRHS For each generated matrix, 14 tests are performed: Test CGEBRD and CUNGBR (1) | A - Q B PT | / ( |A| max(M,N) ulp ), PT = P' (2) | I - Q' Q | / ( M ulp ) (3) | I - PT PT' | / ( N ulp ) Test CBDSQR on bidiagonal matrix B (4) | B - U S1 VT | / ( |B| min(M,N) ulp ), VT = V' (5) | Y - U Z | / ( |Y| max(min(M,N),k) ulp ), where Y = Q' X and Z = U' Y. (6) | I - U' U | / ( min(M,N) ulp ) (7) | I - VT VT' | / ( min(M,N) ulp ) (8) S1 contains min(M,N) nonnegative values in decreasing order. (Return 0 if true, 1/ULP if false.) (9) 0 if the true singular values of B are within THRESH of those in S1. 2*THRESH if they are not. (Tested using SSVDCH) (10) | S1 - S2 | / ( |S1| ulp ), where S2 is computed without computing U and V. Test CBDSQR on matrix A (11) | A - (QU) S (VT PT) | / ( |A| max(M,N) ulp ) (12) | X - (QU) Z | / ( |X| max(M,k) ulp ) (13) | I - (QU)'(QU) | / ( M ulp ) (14) | I - (VT PT) (PT'VT') | / ( N ulp ) The possible matrix types are (1) The zero matrix. (2) The identity matrix. (3) A diagonal matrix with evenly spaced entries 1, ..., ULP and random signs. (ULP = (first number larger than 1) - 1 ) (4) A diagonal matrix with geometrically spaced entries 1, ..., ULP and random signs. (5) A diagonal matrix with "clustered" entries 1, ULP, ..., ULP and random signs. (6) Same as (3), but multiplied by SQRT( overflow threshold ) (7) Same as (3), but multiplied by SQRT( underflow threshold ) (8) A matrix of the form U D V, where U and V are orthogonal and D has evenly spaced entries 1, ..., ULP with random signs on the diagonal. (9) A matrix of the form U D V, where U and V are orthogonal and D has geometrically spaced entries 1, ..., ULP with random signs on the diagonal. (10) A matrix of the form U D V, where U and V are orthogonal and D has "clustered" entries 1, ULP,..., ULP with random signs on the diagonal. (11) Same as (8), but multiplied by SQRT( overflow threshold ) (12) Same as (8), but multiplied by SQRT( underflow threshold ) (13) Rectangular matrix with random entries chosen from (-1,1). (14) Same as (13), but multiplied by SQRT( overflow threshold ) (15) Same as (13), but multiplied by SQRT( underflow threshold ) Special case: (16) A bidiagonal matrix with random entries chosen from a logarithmic distribution on [ulp^2,ulp^(-2)] (I.e., each entry is e^x, where x is chosen uniformly on [ 2 log(ulp), -2 log(ulp) ] .) For *this* type: (a) CGEBRD is not called to reduce it to bidiagonal form. (b) the bidiagonal is min(M,N) x min(M,N); if M<N, the matrix will be lower bidiagonal, otherwise upper. (c) only tests 5--8 and 14 are performed. A subset of the full set of matrix types may be selected through the logical array DOTYPE. Arguments ========== NSIZES (input) INTEGER The number of values of M and N contained in the vectors MVAL and NVAL. The matrix sizes are used in pairs (M,N). MVAL (input) INTEGER array, dimension (NM) The values of the matrix row dimension M. NVAL (input) INTEGER array, dimension (NM) The values of the matrix column dimension N. NTYPES (input) INTEGER The number of elements in DOTYPE. If it is zero, CCHKBD does nothing. It must be at least zero. If it is MAXTYP+1 and NSIZES is 1, then an additional type, MAXTYP+1 is defined, which is to use whatever matrices are in A and B. This is only useful if DOTYPE(1:MAXTYP) is .FALSE. and DOTYPE(MAXTYP+1) is .TRUE. . DOTYPE (input) LOGICAL array, dimension (NTYPES) If DOTYPE(j) is .TRUE., then for each size (m,n), a matrix of type j will be generated. If NTYPES is smaller than the maximum number of types defined (PARAMETER MAXTYP), then types NTYPES+1 through MAXTYP will not be generated. If NTYPES is larger than MAXTYP, DOTYPE(MAXTYP+1) through DOTYPE(NTYPES) will be ignored. NRHS (input) INTEGER The number of columns in the "right-hand side" matrices X, Y, and Z, used in testing CBDSQR. If NRHS = 0, then the operations on the right-hand side will not be tested. NRHS must be at least 0. ISEED (input/output) INTEGER array, dimension (4) On entry ISEED specifies the seed of the random number generator. The array elements should be between 0 and 4095; if not they will be reduced mod 4096. Also, ISEED(4) must be odd. The values of ISEED are changed on exit, and can be used in the next call to CCHKBD to continue the same random number sequence. THRESH (input) REAL The threshold value for the test ratios. A result is included in the output file if RESULT >= THRESH. To have every test ratio printed, use THRESH = 0. Note that the expected value of the test ratios is O(1), so THRESH should be a reasonably small multiple of 1, e.g., 10 or 100. A (workspace) COMPLEX array, dimension (LDA,NMAX) where NMAX is the maximum value of N in NVAL. LDA (input) INTEGER The leading dimension of the array A. LDA >= max(1,MMAX), where MMAX is the maximum value of M in MVAL. BD (workspace) REAL array, dimension (max(min(MVAL(j),NVAL(j)))) BE (workspace) REAL array, dimension (max(min(MVAL(j),NVAL(j)))) S1 (workspace) REAL array, dimension (max(min(MVAL(j),NVAL(j)))) S2 (workspace) REAL array, dimension (max(min(MVAL(j),NVAL(j)))) X (workspace) COMPLEX array, dimension (LDX,NRHS) LDX (input) INTEGER The leading dimension of the arrays X, Y, and Z. LDX >= max(1,MMAX). Y (workspace) COMPLEX array, dimension (LDX,NRHS) Z (workspace) COMPLEX array, dimension (LDX,NRHS) Q (workspace) COMPLEX array, dimension (LDQ,MMAX) LDQ (input) INTEGER The leading dimension of the array Q. LDQ >= max(1,MMAX). PT (workspace) COMPLEX array, dimension (LDPT,NMAX) LDPT (input) INTEGER The leading dimension of the arrays PT, U, and V. LDPT >= max(1, max(min(MVAL(j),NVAL(j)))). U (workspace) COMPLEX array, dimension (LDPT,max(min(MVAL(j),NVAL(j)))) V (workspace) COMPLEX array, dimension (LDPT,max(min(MVAL(j),NVAL(j)))) WORK (workspace) COMPLEX array, dimension (LWORK) LWORK (input) INTEGER The number of entries in WORK. This must be at least 3(M+N) and M(M + max(M,N,k) + 1) + N*min(M,N) for all pairs (M,N)=(MM(j),NN(j)) RWORK (workspace) REAL array, dimension (5*max(min(M,N))) NOUT (input) INTEGER The FORTRAN unit number for printing out error messages (e.g., if a routine returns IINFO not equal to 0.) INFO (output) INTEGER If 0, then everything ran OK. -1: NSIZES < 0 -2: Some MM(j) < 0 -3: Some NN(j) < 0 -4: NTYPES < 0 -6: NRHS < 0 -8: THRESH < 0 -11: LDA < 1 or LDA < MMAX, where MMAX is max( MM(j) ). -17: LDB < 1 or LDB < MMAX. -21: LDQ < 1 or LDQ < MMAX. -23: LDP < 1 or LDP < MNMAX. -27: LWORK too small. If CLATMR, CLATMS, CGEBRD, CUNGBR, or CBDSQR, returns an error code, the absolute value of it is returned. ----------------------------------------------------------------------- Some Local Variables and Parameters: ---- ----- --------- --- ---------- ZERO, ONE Real 0 and 1. MAXTYP The number of types defined. NTEST The number of tests performed, or which can be performed so far, for the current matrix. MMAX Largest value in NN. NMAX Largest value in NN. MNMIN min(MM(j), NN(j)) (the dimension of the bidiagonal matrix.) MNMAX The maximum value of MNMIN for j=1,...,NSIZES. NFAIL The number of tests which have exceeded THRESH COND, IMODE Values to be passed to the matrix generators. ANORM Norm of A; passed to matrix generators. OVFL, UNFL Overflow and underflow thresholds. RTOVFL, RTUNFL Square roots of the previous 2 values. ULP, ULPINV Finest relative precision and its inverse. The following four arrays decode JTYPE: KTYPE(j) The general type (1-10) for type "j". KMODE(j) The MODE value to be passed to the matrix generator for type "j". KMAGN(j) The order of magnitude ( O(1), O(overflow^(1/2) ), O(underflow^(1/2) ) ====================================================================== Parameter adjustments */ --mval; --nval; --dotype; --iseed; a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --bd; --be; --s1; --s2; z_dim1 = *ldx; z_offset = 1 + z_dim1 * 1; z__ -= z_offset; y_dim1 = *ldx; y_offset = 1 + y_dim1 * 1; y -= y_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1 * 1; x -= x_offset; q_dim1 = *ldq; q_offset = 1 + q_dim1 * 1; q -= q_offset; vt_dim1 = *ldpt; vt_offset = 1 + vt_dim1 * 1; vt -= vt_offset; u_dim1 = *ldpt; u_offset = 1 + u_dim1 * 1; u -= u_offset; pt_dim1 = *ldpt; pt_offset = 1 + pt_dim1 * 1; pt -= pt_offset; --work; --rwork; /* Function Body Check for errors */ *info = 0; badmm = FALSE_; badnn = FALSE_; mmax = 1; nmax = 1; mnmax = 1; minwrk = 1; i__1 = *nsizes; for (j = 1; j <= i__1; ++j) { /* Computing MAX */ i__2 = mmax, i__3 = mval[j]; mmax = max(i__2,i__3); if (mval[j] < 0) { badmm = TRUE_; } /* Computing MAX */ i__2 = nmax, i__3 = nval[j]; nmax = max(i__2,i__3); if (nval[j] < 0) { badnn = TRUE_; } /* Computing MAX Computing MIN */ i__4 = mval[j], i__5 = nval[j]; i__2 = mnmax, i__3 = min(i__4,i__5); mnmax = max(i__2,i__3); /* Computing MAX Computing MAX */ i__4 = mval[j], i__5 = nval[j], i__4 = max(i__4,i__5); /* Computing MIN */ i__6 = nval[j], i__7 = mval[j]; i__2 = minwrk, i__3 = (mval[j] + nval[j]) * 3, i__2 = max(i__2,i__3), i__3 = mval[j] * (mval[j] + max(i__4,*nrhs) + 1) + nval[j] * min(i__6,i__7); minwrk = max(i__2,i__3); /* L10: */ } /* Check for errors */ if (*nsizes < 0) { *info = -1; } else if (badmm) { *info = -2; } else if (badnn) { *info = -3; } else if (*ntypes < 0) { *info = -4; } else if (*nrhs < 0) { *info = -6; } else if (*lda < mmax) { *info = -11; } else if (*ldx < mmax) { *info = -17; } else if (*ldq < mmax) { *info = -21; } else if (*ldpt < mnmax) { *info = -23; } else if (minwrk > *lwork) { *info = -27; } if (*info != 0) { i__1 = -(*info); xerbla_("CCHKBD", &i__1); return 0; } /* Initialize constants */ s_copy(path, "Complex precision", (ftnlen)1, (ftnlen)17); s_copy(path + 1, "BD", (ftnlen)2, (ftnlen)2); nfail = 0; ntest = 0; unfl = slamch_("Safe minimum"); ovfl = slamch_("Overflow"); slabad_(&unfl, &ovfl); ulp = slamch_("Precision"); ulpinv = 1.f / ulp; log2ui = (integer) (log(ulpinv) / log(2.f)); rtunfl = sqrt(unfl); rtovfl = sqrt(ovfl); infoc_1.infot = 0; /* Loop over sizes, types */ i__1 = *nsizes; for (jsize = 1; jsize <= i__1; ++jsize) { m = mval[jsize]; n = nval[jsize]; mnmin = min(m,n); /* Computing MAX */ i__2 = max(m,n); amninv = 1.f / max(i__2,1); if (*nsizes != 1) { mtypes = min(16,*ntypes); } else { mtypes = min(17,*ntypes); } i__2 = mtypes; for (jtype = 1; jtype <= i__2; ++jtype) { if (! dotype[jtype]) { goto L170; } for (j = 1; j <= 4; ++j) { ioldsd[j - 1] = iseed[j]; /* L20: */ } for (j = 1; j <= 14; ++j) { result[j - 1] = -1.f; /* L30: */ } *(unsigned char *)uplo = ' '; /* Compute "A" Control parameters: KMAGN KMODE KTYPE =1 O(1) clustered 1 zero =2 large clustered 2 identity =3 small exponential (none) =4 arithmetic diagonal, (w/ eigenvalues) =5 random symmetric, w/ eigenvalues =6 nonsymmetric, w/ singular values =7 random diagonal =8 random symmetric =9 random nonsymmetric =10 random bidiagonal (log. distrib.) */ if (mtypes > 16) { goto L100; } itype = ktype[jtype - 1]; imode = kmode[jtype - 1]; /* Compute norm */ switch (kmagn[jtype - 1]) { case 1: goto L40; case 2: goto L50; case 3: goto L60; } L40: anorm = 1.f; goto L70; L50: anorm = rtovfl * ulp * amninv; goto L70; L60: anorm = rtunfl * max(m,n) * ulpinv; goto L70; L70: claset_("Full", lda, &n, &c_b1, &c_b1, &a[a_offset], lda); iinfo = 0; cond = ulpinv; bidiag = FALSE_; if (itype == 1) { /* Zero matrix */ iinfo = 0; } else if (itype == 2) { /* Identity */ i__3 = mnmin; for (jcol = 1; jcol <= i__3; ++jcol) { i__4 = a_subscr(jcol, jcol); a[i__4].r = anorm, a[i__4].i = 0.f; /* L80: */ } } else if (itype == 4) { /* Diagonal Matrix, [Eigen]values Specified */ clatms_(&mnmin, &mnmin, "S", &iseed[1], "N", &rwork[1], & imode, &cond, &anorm, &c__0, &c__0, "N", &a[a_offset], lda, &work[1], &iinfo); } else if (itype == 5) { /* Symmetric, eigenvalues specified */ clatms_(&mnmin, &mnmin, "S", &iseed[1], "S", &rwork[1], & imode, &cond, &anorm, &m, &n, "N", &a[a_offset], lda, &work[1], &iinfo); } else if (itype == 6) { /* Nonsymmetric, singular values specified */ clatms_(&m, &n, "S", &iseed[1], "N", &rwork[1], &imode, &cond, &anorm, &m, &n, "N", &a[a_offset], lda, &work[1], & iinfo); } else if (itype == 7) { /* Diagonal, random entries */ clatmr_(&mnmin, &mnmin, "S", &iseed[1], "N", &work[1], &c__6, &c_b37, &c_b2, "T", "N", &work[mnmin + 1], &c__1, & c_b37, &work[(mnmin << 1) + 1], &c__1, &c_b37, "N", iwork, &c__0, &c__0, &c_b47, &anorm, "NO", &a[ a_offset], lda, iwork, &iinfo); } else if (itype == 8) { /* Symmetric, random entries */ clatmr_(&mnmin, &mnmin, "S", &iseed[1], "S", &work[1], &c__6, &c_b37, &c_b2, "T", "N", &work[mnmin + 1], &c__1, & c_b37, &work[m + mnmin + 1], &c__1, &c_b37, "N", iwork, &m, &n, &c_b47, &anorm, "NO", &a[a_offset], lda, iwork, &iinfo); } else if (itype == 9) { /* Nonsymmetric, random entries */ clatmr_(&m, &n, "S", &iseed[1], "N", &work[1], &c__6, &c_b37, &c_b2, "T", "N", &work[mnmin + 1], &c__1, &c_b37, & work[m + mnmin + 1], &c__1, &c_b37, "N", iwork, &m, & n, &c_b47, &anorm, "NO", &a[a_offset], lda, iwork, & iinfo); } else if (itype == 10) { /* Bidiagonal, random entries */ temp1 = log(ulp) * -2.f; i__3 = mnmin; for (j = 1; j <= i__3; ++j) { bd[j] = exp(temp1 * slarnd_(&c__2, &iseed[1])); if (j < mnmin) { be[j] = exp(temp1 * slarnd_(&c__2, &iseed[1])); } /* L90: */ } iinfo = 0; bidiag = TRUE_; if (m >= n) { *(unsigned char *)uplo = 'U'; } else { *(unsigned char *)uplo = 'L'; } } else { iinfo = 1; } if (iinfo == 0) { /* Generate Right-Hand Side */ if (bidiag) { clatmr_(&mnmin, nrhs, "S", &iseed[1], "N", &work[1], & c__6, &c_b37, &c_b2, "T", "N", &work[mnmin + 1], & c__1, &c_b37, &work[(mnmin << 1) + 1], &c__1, & c_b37, "N", iwork, &mnmin, nrhs, &c_b47, &c_b37, "NO", &y[y_offset], ldx, iwork, &iinfo); } else { clatmr_(&m, nrhs, "S", &iseed[1], "N", &work[1], &c__6, & c_b37, &c_b2, "T", "N", &work[m + 1], &c__1, & c_b37, &work[(m << 1) + 1], &c__1, &c_b37, "N", iwork, &m, nrhs, &c_b47, &c_b37, "NO", &x[ x_offset], ldx, iwork, &iinfo); } } /* Error Exit */ if (iinfo != 0) { io___40.ciunit = *nout; s_wsfe(&io___40); do_fio(&c__1, "Generator", (ftnlen)9); do_fio(&c__1, (char *)&iinfo, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&m, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&jtype, (ftnlen)sizeof(integer)); do_fio(&c__4, (char *)&ioldsd[0], (ftnlen)sizeof(integer)); e_wsfe(); *info = abs(iinfo); return 0; } L100: /* Call CGEBRD and CUNGBR to compute B, Q, and P, do tests. */ if (! bidiag) { /* Compute transformations to reduce A to bidiagonal form: B := Q' * A * P. */ clacpy_(" ", &m, &n, &a[a_offset], lda, &q[q_offset], ldq); i__3 = *lwork - (mnmin << 1); cgebrd_(&m, &n, &q[q_offset], ldq, &bd[1], &be[1], &work[1], & work[mnmin + 1], &work[(mnmin << 1) + 1], &i__3, & iinfo); /* Check error code from CGEBRD. */ if (iinfo != 0) { io___41.ciunit = *nout; s_wsfe(&io___41); do_fio(&c__1, "CGEBRD", (ftnlen)6); do_fio(&c__1, (char *)&iinfo, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&m, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&jtype, (ftnlen)sizeof(integer)); do_fio(&c__4, (char *)&ioldsd[0], (ftnlen)sizeof(integer)) ; e_wsfe(); *info = abs(iinfo); return 0; } clacpy_(" ", &m, &n, &q[q_offset], ldq, &pt[pt_offset], ldpt); if (m >= n) { *(unsigned char *)uplo = 'U'; } else { *(unsigned char *)uplo = 'L'; } /* Generate Q */ mq = m; if (*nrhs <= 0) { mq = mnmin; } i__3 = *lwork - (mnmin << 1); cungbr_("Q", &m, &mq, &n, &q[q_offset], ldq, &work[1], &work[( mnmin << 1) + 1], &i__3, &iinfo); /* Check error code from CUNGBR. */ if (iinfo != 0) { io___43.ciunit = *nout; s_wsfe(&io___43); do_fio(&c__1, "CUNGBR(Q)", (ftnlen)9); do_fio(&c__1, (char *)&iinfo, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&m, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&jtype, (ftnlen)sizeof(integer)); do_fio(&c__4, (char *)&ioldsd[0], (ftnlen)sizeof(integer)) ; e_wsfe(); *info = abs(iinfo); return 0; } /* Generate P' */ i__3 = *lwork - (mnmin << 1); cungbr_("P", &mnmin, &n, &m, &pt[pt_offset], ldpt, &work[ mnmin + 1], &work[(mnmin << 1) + 1], &i__3, &iinfo); /* Check error code from CUNGBR. */ if (iinfo != 0) { io___44.ciunit = *nout; s_wsfe(&io___44); do_fio(&c__1, "CUNGBR(P)", (ftnlen)9); do_fio(&c__1, (char *)&iinfo, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&m, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&jtype, (ftnlen)sizeof(integer)); do_fio(&c__4, (char *)&ioldsd[0], (ftnlen)sizeof(integer)) ; e_wsfe(); *info = abs(iinfo); return 0; } /* Apply Q' to an M by NRHS matrix X: Y := Q' * X. */ cgemm_("Conjugate transpose", "No transpose", &m, nrhs, &m, & c_b2, &q[q_offset], ldq, &x[x_offset], ldx, &c_b1, &y[ y_offset], ldx); /* Test 1: Check the decomposition A := Q * B * PT 2: Check the orthogonality of Q 3: Check the orthogonality of PT */ cbdt01_(&m, &n, &c__1, &a[a_offset], lda, &q[q_offset], ldq, & bd[1], &be[1], &pt[pt_offset], ldpt, &work[1], &rwork[ 1], result); cunt01_("Columns", &m, &mq, &q[q_offset], ldq, &work[1], lwork, &rwork[1], &result[1]); cunt01_("Rows", &mnmin, &n, &pt[pt_offset], ldpt, &work[1], lwork, &rwork[1], &result[2]); } /* Use CBDSQR to form the SVD of the bidiagonal matrix B: B := U * S1 * VT, and compute Z = U' * Y. */ scopy_(&mnmin, &bd[1], &c__1, &s1[1], &c__1); if (mnmin > 0) { i__3 = mnmin - 1; scopy_(&i__3, &be[1], &c__1, &rwork[1], &c__1); } clacpy_(" ", &m, nrhs, &y[y_offset], ldx, &z__[z_offset], ldx); claset_("Full", &mnmin, &mnmin, &c_b1, &c_b2, &u[u_offset], ldpt); claset_("Full", &mnmin, &mnmin, &c_b1, &c_b2, &vt[vt_offset], ldpt); cbdsqr_(uplo, &mnmin, &mnmin, &mnmin, nrhs, &s1[1], &rwork[1], & vt[vt_offset], ldpt, &u[u_offset], ldpt, &z__[z_offset], ldx, &rwork[mnmin + 1], &iinfo); /* Check error code from CBDSQR. */ if (iinfo != 0) { io___45.ciunit = *nout; s_wsfe(&io___45); do_fio(&c__1, "CBDSQR(vects)", (ftnlen)13); do_fio(&c__1, (char *)&iinfo, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&m, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&jtype, (ftnlen)sizeof(integer)); do_fio(&c__4, (char *)&ioldsd[0], (ftnlen)sizeof(integer)); e_wsfe(); *info = abs(iinfo); if (iinfo < 0) { return 0; } else { result[3] = ulpinv; goto L150; } } /* Use CBDSQR to compute only the singular values of the bidiagonal matrix B; U, VT, and Z should not be modified. */ scopy_(&mnmin, &bd[1], &c__1, &s2[1], &c__1); if (mnmin > 0) { i__3 = mnmin - 1; scopy_(&i__3, &be[1], &c__1, &rwork[1], &c__1); } cbdsqr_(uplo, &mnmin, &c__0, &c__0, &c__0, &s2[1], &rwork[1], &vt[ vt_offset], ldpt, &u[u_offset], ldpt, &z__[z_offset], ldx, &rwork[mnmin + 1], &iinfo); /* Check error code from CBDSQR. */ if (iinfo != 0) { io___46.ciunit = *nout; s_wsfe(&io___46); do_fio(&c__1, "CBDSQR(values)", (ftnlen)14); do_fio(&c__1, (char *)&iinfo, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&m, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&jtype, (ftnlen)sizeof(integer)); do_fio(&c__4, (char *)&ioldsd[0], (ftnlen)sizeof(integer)); e_wsfe(); *info = abs(iinfo); if (iinfo < 0) { return 0; } else { result[8] = ulpinv; goto L150; } } /* Test 4: Check the decomposition B := U * S1 * VT 5: Check the computation Z := U' * Y 6: Check the orthogonality of U 7: Check the orthogonality of VT */ cbdt03_(uplo, &mnmin, &c__1, &bd[1], &be[1], &u[u_offset], ldpt, & s1[1], &vt[vt_offset], ldpt, &work[1], &result[3]); cbdt02_(&mnmin, nrhs, &y[y_offset], ldx, &z__[z_offset], ldx, &u[ u_offset], ldpt, &work[1], &rwork[1], &result[4]); cunt01_("Columns", &mnmin, &mnmin, &u[u_offset], ldpt, &work[1], lwork, &rwork[1], &result[5]); cunt01_("Rows", &mnmin, &mnmin, &vt[vt_offset], ldpt, &work[1], lwork, &rwork[1], &result[6]); /* Test 8: Check that the singular values are sorted in non-increasing order and are non-negative */ result[7] = 0.f; i__3 = mnmin - 1; for (i__ = 1; i__ <= i__3; ++i__) { if (s1[i__] < s1[i__ + 1]) { result[7] = ulpinv; } if (s1[i__] < 0.f) { result[7] = ulpinv; } /* L110: */ } if (mnmin >= 1) { if (s1[mnmin] < 0.f) { result[7] = ulpinv; } } /* Test 9: Compare CBDSQR with and without singular vectors */ temp2 = 0.f; i__3 = mnmin; for (j = 1; j <= i__3; ++j) { /* Computing MAX Computing MAX */ r__6 = (r__1 = s1[j], dabs(r__1)), r__7 = (r__2 = s2[j], dabs( r__2)); r__4 = sqrt(unfl) * dmax(s1[1],1.f), r__5 = ulp * dmax(r__6, r__7); temp1 = (r__3 = s1[j] - s2[j], dabs(r__3)) / dmax(r__4,r__5); temp2 = dmax(temp1,temp2); /* L120: */ } result[8] = temp2; /* Test 10: Sturm sequence test of singular values Go up by factors of two until it succeeds */ temp1 = *thresh * (.5f - ulp); i__3 = log2ui; for (j = 0; j <= i__3; ++j) { ssvdch_(&mnmin, &bd[1], &be[1], &s1[1], &temp1, &iinfo); if (iinfo == 0) { goto L140; } temp1 *= 2.f; /* L130: */ } L140: result[9] = temp1; /* Use CBDSQR to form the decomposition A := (QU) S (VT PT) from the bidiagonal form A := Q B PT. */ if (! bidiag) { scopy_(&mnmin, &bd[1], &c__1, &s2[1], &c__1); if (mnmin > 0) { i__3 = mnmin - 1; scopy_(&i__3, &be[1], &c__1, &rwork[1], &c__1); } cbdsqr_(uplo, &mnmin, &n, &m, nrhs, &s2[1], &rwork[1], &pt[ pt_offset], ldpt, &q[q_offset], ldq, &y[y_offset], ldx, &rwork[mnmin + 1], &iinfo); /* Test 11: Check the decomposition A := Q*U * S2 * VT*PT 12: Check the computation Z := U' * Q' * X 13: Check the orthogonality of Q*U 14: Check the orthogonality of VT*PT */ cbdt01_(&m, &n, &c__0, &a[a_offset], lda, &q[q_offset], ldq, & s2[1], dumma, &pt[pt_offset], ldpt, &work[1], &rwork[ 1], &result[10]); cbdt02_(&m, nrhs, &x[x_offset], ldx, &y[y_offset], ldx, &q[ q_offset], ldq, &work[1], &rwork[1], &result[11]); cunt01_("Columns", &m, &mq, &q[q_offset], ldq, &work[1], lwork, &rwork[1], &result[12]); cunt01_("Rows", &mnmin, &n, &pt[pt_offset], ldpt, &work[1], lwork, &rwork[1], &result[13]); } /* End of Loop -- Check for RESULT(j) > THRESH */ L150: for (j = 1; j <= 14; ++j) { if (result[j - 1] >= *thresh) { if (nfail == 0) { slahd2_(nout, path); } io___50.ciunit = *nout; s_wsfe(&io___50); do_fio(&c__1, (char *)&m, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&n, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&jtype, (ftnlen)sizeof(integer)); do_fio(&c__4, (char *)&ioldsd[0], (ftnlen)sizeof(integer)) ; do_fio(&c__1, (char *)&j, (ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&result[j - 1], (ftnlen)sizeof(real) ); e_wsfe(); ++nfail; } /* L160: */ } if (! bidiag) { ntest += 14; } else { ntest += 5; } L170: ; } /* L180: */ } /* Summary */ alasum_(path, nout, &nfail, &ntest, &c__0); return 0; /* End of CCHKBD */ } /* cchkbd_ */
/* Subroutine */ int cerrbd_(char *path, integer *nunit) { /* Format strings */ static char fmt_9999[] = "(1x,a3,\002 routines passed the tests of the e" "rror exits (\002,i3,\002 tests done)\002)"; static char fmt_9998[] = "(\002 *** \002,a3,\002 routines failed the tes" "ts of the error \002,\002exits ***\002)"; /* System generated locals */ integer i__1; real r__1; /* Local variables */ complex a[16] /* was [4][4] */; real d__[4], e[4]; integer i__, j; complex u[16] /* was [4][4] */, v[16] /* was [4][4] */, w[4]; char c2[2]; integer nt; complex tp[4], tq[4]; real rw[16]; integer info; extern /* Subroutine */ int cgebrd_(integer *, integer *, complex *, integer *, real *, real *, complex *, complex *, complex *, integer *, integer *), cbdsqr_(char *, integer *, integer *, integer *, integer *, real *, real *, complex *, integer *, complex *, integer *, complex *, integer *, real *, integer *); extern logical lsamen_(integer *, char *, char *); extern /* Subroutine */ int cungbr_(char *, integer *, integer *, integer *, complex *, integer *, complex *, complex *, integer *, integer *), chkxer_(char *, integer *, integer *, logical *, logical *), cunmbr_(char *, char *, char *, integer *, integer *, integer *, complex *, integer *, complex *, complex *, integer *, complex *, integer *, integer *); /* Fortran I/O blocks */ static cilist io___1 = { 0, 0, 0, 0, 0 }; static cilist io___16 = { 0, 0, 0, fmt_9999, 0 }; static cilist io___17 = { 0, 0, 0, fmt_9998, 0 }; /* -- LAPACK test routine (version 3.1.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* CERRBD tests the error exits for CGEBRD, CUNGBR, CUNMBR, and CBDSQR. */ /* Arguments */ /* ========= */ /* PATH (input) CHARACTER*3 */ /* The LAPACK path name for the routines to be tested. */ /* NUNIT (input) INTEGER */ /* The unit number for output. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Scalars in Common .. */ /* .. */ /* .. Common blocks .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ infoc_1.nout = *nunit; io___1.ciunit = infoc_1.nout; s_wsle(&io___1); e_wsle(); s_copy(c2, path + 1, (ftnlen)2, (ftnlen)2); /* Set the variables to innocuous values. */ for (j = 1; j <= 4; ++j) { for (i__ = 1; i__ <= 4; ++i__) { i__1 = i__ + (j << 2) - 5; r__1 = 1.f / (real) (i__ + j); a[i__1].r = r__1, a[i__1].i = 0.f; /* L10: */ } /* L20: */ } infoc_1.ok = TRUE_; nt = 0; /* Test error exits of the SVD routines. */ if (lsamen_(&c__2, c2, "BD")) { /* CGEBRD */ s_copy(srnamc_1.srnamt, "CGEBRD", (ftnlen)32, (ftnlen)6); infoc_1.infot = 1; cgebrd_(&c_n1, &c__0, a, &c__1, d__, e, tq, tp, w, &c__1, &info); chkxer_("CGEBRD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; cgebrd_(&c__0, &c_n1, a, &c__1, d__, e, tq, tp, w, &c__1, &info); chkxer_("CGEBRD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 4; cgebrd_(&c__2, &c__1, a, &c__1, d__, e, tq, tp, w, &c__2, &info); chkxer_("CGEBRD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 10; cgebrd_(&c__2, &c__1, a, &c__2, d__, e, tq, tp, w, &c__1, &info); chkxer_("CGEBRD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); nt += 4; /* CUNGBR */ s_copy(srnamc_1.srnamt, "CUNGBR", (ftnlen)32, (ftnlen)6); infoc_1.infot = 1; cungbr_("/", &c__0, &c__0, &c__0, a, &c__1, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; cungbr_("Q", &c_n1, &c__0, &c__0, a, &c__1, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; cungbr_("Q", &c__0, &c_n1, &c__0, a, &c__1, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; cungbr_("Q", &c__0, &c__1, &c__0, a, &c__1, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; cungbr_("Q", &c__1, &c__0, &c__1, a, &c__1, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; cungbr_("P", &c__1, &c__0, &c__0, a, &c__1, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; cungbr_("P", &c__0, &c__1, &c__1, a, &c__1, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 4; cungbr_("Q", &c__0, &c__0, &c_n1, a, &c__1, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 6; cungbr_("Q", &c__2, &c__1, &c__1, a, &c__1, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 9; cungbr_("Q", &c__2, &c__2, &c__1, a, &c__2, tq, w, &c__1, &info); chkxer_("CUNGBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); nt += 10; /* CUNMBR */ s_copy(srnamc_1.srnamt, "CUNMBR", (ftnlen)32, (ftnlen)6); infoc_1.infot = 1; cunmbr_("/", "L", "T", &c__0, &c__0, &c__0, a, &c__1, tq, u, &c__1, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; cunmbr_("Q", "/", "T", &c__0, &c__0, &c__0, a, &c__1, tq, u, &c__1, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; cunmbr_("Q", "L", "/", &c__0, &c__0, &c__0, a, &c__1, tq, u, &c__1, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 4; cunmbr_("Q", "L", "C", &c_n1, &c__0, &c__0, a, &c__1, tq, u, &c__1, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; cunmbr_("Q", "L", "C", &c__0, &c_n1, &c__0, a, &c__1, tq, u, &c__1, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 6; cunmbr_("Q", "L", "C", &c__0, &c__0, &c_n1, a, &c__1, tq, u, &c__1, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 8; cunmbr_("Q", "L", "C", &c__2, &c__0, &c__0, a, &c__1, tq, u, &c__2, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 8; cunmbr_("Q", "R", "C", &c__0, &c__2, &c__0, a, &c__1, tq, u, &c__1, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 8; cunmbr_("P", "L", "C", &c__2, &c__0, &c__2, a, &c__1, tq, u, &c__2, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 8; cunmbr_("P", "R", "C", &c__0, &c__2, &c__2, a, &c__1, tq, u, &c__1, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 11; cunmbr_("Q", "R", "C", &c__2, &c__0, &c__0, a, &c__1, tq, u, &c__1, w, &c__1, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 13; cunmbr_("Q", "L", "C", &c__0, &c__2, &c__0, a, &c__1, tq, u, &c__1, w, &c__0, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 13; cunmbr_("Q", "R", "C", &c__2, &c__0, &c__0, a, &c__1, tq, u, &c__2, w, &c__0, &info); chkxer_("CUNMBR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); nt += 13; /* CBDSQR */ s_copy(srnamc_1.srnamt, "CBDSQR", (ftnlen)32, (ftnlen)6); infoc_1.infot = 1; cbdsqr_("/", &c__0, &c__0, &c__0, &c__0, d__, e, v, &c__1, u, &c__1, a, &c__1, rw, &info); chkxer_("CBDSQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; cbdsqr_("U", &c_n1, &c__0, &c__0, &c__0, d__, e, v, &c__1, u, &c__1, a, &c__1, rw, &info); chkxer_("CBDSQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; cbdsqr_("U", &c__0, &c_n1, &c__0, &c__0, d__, e, v, &c__1, u, &c__1, a, &c__1, rw, &info); chkxer_("CBDSQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 4; cbdsqr_("U", &c__0, &c__0, &c_n1, &c__0, d__, e, v, &c__1, u, &c__1, a, &c__1, rw, &info); chkxer_("CBDSQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; cbdsqr_("U", &c__0, &c__0, &c__0, &c_n1, d__, e, v, &c__1, u, &c__1, a, &c__1, rw, &info); chkxer_("CBDSQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 9; cbdsqr_("U", &c__2, &c__1, &c__0, &c__0, d__, e, v, &c__1, u, &c__1, a, &c__1, rw, &info); chkxer_("CBDSQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 11; cbdsqr_("U", &c__0, &c__0, &c__2, &c__0, d__, e, v, &c__1, u, &c__1, a, &c__1, rw, &info); chkxer_("CBDSQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 13; cbdsqr_("U", &c__2, &c__0, &c__0, &c__1, d__, e, v, &c__1, u, &c__1, a, &c__1, rw, &info); chkxer_("CBDSQR", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); nt += 8; } /* Print a summary line. */ if (infoc_1.ok) { io___16.ciunit = infoc_1.nout; s_wsfe(&io___16); do_fio(&c__1, path, (ftnlen)3); do_fio(&c__1, (char *)&nt, (ftnlen)sizeof(integer)); e_wsfe(); } else { io___17.ciunit = infoc_1.nout; s_wsfe(&io___17); do_fio(&c__1, path, (ftnlen)3); e_wsfe(); } return 0; /* End of CERRBD */ } /* cerrbd_ */
/* Subroutine */ int cgelss_(integer *m, integer *n, integer *nrhs, complex * a, integer *lda, complex *b, integer *ldb, real *s, real *rcond, integer *rank, complex *work, integer *lwork, real *rwork, integer * info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3; real r__1; /* Local variables */ integer i__, bl, ie, il, mm; complex dum[1]; real eps, thr, anrm, bnrm; integer itau, lwork_cgebrd__, lwork_cgelqf__, lwork_cgeqrf__, lwork_cungbr__, lwork_cunmbr__, lwork_cunmlq__, lwork_cunmqr__; extern /* Subroutine */ int cgemm_(char *, char *, integer *, integer *, integer *, complex *, complex *, integer *, complex *, integer *, complex *, complex *, integer *); integer iascl, ibscl; extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex * , complex *, integer *, complex *, integer *, complex *, complex * , integer *); integer chunk; real sfmin; extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, complex *, integer *); integer minmn, maxmn, itaup, itauq, mnthr, iwork; extern /* Subroutine */ int cgebrd_(), slabad_(real *, real *); extern real clange_(char *, integer *, integer *, complex *, integer *, real *); extern /* Subroutine */ int cgelqf_(integer *, integer *, complex *, integer *, complex *, complex *, integer *, integer *), clascl_( char *, integer *, integer *, real *, real *, integer *, integer * , complex *, integer *, integer *), cgeqrf_(integer *, integer *, complex *, integer *, complex *, complex *, integer *, integer *); extern real slamch_(char *); extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex *, integer *, complex *, integer *), claset_(char *, integer *, integer *, complex *, complex *, complex *, integer *), xerbla_(char *, integer *), cbdsqr_(char *, integer *, integer *, integer *, integer *, real *, real *, complex *, integer *, complex *, integer *, complex *, integer *, real *, integer *); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *); real bignum; extern /* Subroutine */ int cungbr_(char *, integer *, integer *, integer *, complex *, integer *, complex *, complex *, integer *, integer *), slascl_(char *, integer *, integer *, real *, real *, integer *, integer *, real *, integer *, integer *), cunmbr_(char *, char *, char *, integer *, integer *, integer *, complex *, integer *, complex *, complex *, integer *, complex *, integer *, integer *), csrscl_(integer *, real *, complex *, integer *), slaset_(char *, integer *, integer *, real *, real *, real *, integer *), cunmlq_(char *, char *, integer *, integer *, integer *, complex *, integer *, complex *, complex *, integer *, complex *, integer *, integer *); integer ldwork; extern /* Subroutine */ int cunmqr_(char *, char *, integer *, integer *, integer *, complex *, integer *, complex *, complex *, integer *, complex *, integer *, integer *); integer minwrk, maxwrk; real smlnum; integer irwork; logical lquery; /* -- LAPACK driver routine (version 3.4.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* November 2011 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. Local Arrays .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* Test the input arguments */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1; b -= b_offset; --s; --work; --rwork; /* Function Body */ *info = 0; minmn = min(*m,*n); maxmn = max(*m,*n); lquery = *lwork == -1; if (*m < 0) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*lda < max(1,*m)) { *info = -5; } else if (*ldb < max(1,maxmn)) { *info = -7; } /* Compute workspace */ /* (Note: Comments in the code beginning "Workspace:" describe the */ /* minimal amount of workspace needed at that point in the code, */ /* as well as the preferred amount for good performance. */ /* CWorkspace refers to complex workspace, and RWorkspace refers */ /* to real workspace. NB refers to the optimal block size for the */ /* immediately following subroutine, as returned by ILAENV.) */ if (*info == 0) { minwrk = 1; maxwrk = 1; if (minmn > 0) { mm = *m; mnthr = ilaenv_(&c__6, "CGELSS", " ", m, n, nrhs, &c_n1); if (*m >= *n && *m >= mnthr) { /* Path 1a - overdetermined, with many more rows than */ /* columns */ /* Compute space needed for CGEQRF */ cgeqrf_(m, n, &a[a_offset], lda, dum, dum, &c_n1, info); lwork_cgeqrf__ = dum[0].r; /* Compute space needed for CUNMQR */ cunmqr_("L", "C", m, nrhs, n, &a[a_offset], lda, dum, &b[ b_offset], ldb, dum, &c_n1, info); lwork_cunmqr__ = dum[0].r; mm = *n; /* Computing MAX */ i__1 = maxwrk; i__2 = *n + *n * ilaenv_(&c__1, "CGEQRF", " ", m, n, &c_n1, &c_n1); // , expr subst maxwrk = max(i__1,i__2); /* Computing MAX */ i__1 = maxwrk; i__2 = *n + *nrhs * ilaenv_(&c__1, "CUNMQR", "LC", m, nrhs, n, &c_n1); // , expr subst maxwrk = max(i__1,i__2); } if (*m >= *n) { /* Path 1 - overdetermined or exactly determined */ /* Compute space needed for CGEBRD */ cgebrd_(&mm, n, &a[a_offset], lda, &s[1], dum, dum, dum, dum, &c_n1, info); lwork_cgebrd__ = dum[0].r; /* Compute space needed for CUNMBR */ cunmbr_("Q", "L", "C", &mm, nrhs, n, &a[a_offset], lda, dum, & b[b_offset], ldb, dum, &c_n1, info); lwork_cunmbr__ = dum[0].r; /* Compute space needed for CUNGBR */ cungbr_("P", n, n, n, &a[a_offset], lda, dum, dum, &c_n1, info); lwork_cungbr__ = dum[0].r; /* Compute total workspace needed */ /* Computing MAX */ i__1 = maxwrk; i__2 = (*n << 1) + lwork_cgebrd__; // , expr subst maxwrk = max(i__1,i__2); /* Computing MAX */ i__1 = maxwrk; i__2 = (*n << 1) + lwork_cunmbr__; // , expr subst maxwrk = max(i__1,i__2); /* Computing MAX */ i__1 = maxwrk; i__2 = (*n << 1) + lwork_cungbr__; // , expr subst maxwrk = max(i__1,i__2); /* Computing MAX */ i__1 = maxwrk; i__2 = *n * *nrhs; // , expr subst maxwrk = max(i__1,i__2); minwrk = (*n << 1) + max(*nrhs,*m); } if (*n > *m) { minwrk = (*m << 1) + max(*nrhs,*n); if (*n >= mnthr) { /* Path 2a - underdetermined, with many more columns */ /* than rows */ /* Compute space needed for CGELQF */ cgelqf_(m, n, &a[a_offset], lda, dum, dum, &c_n1, info); lwork_cgelqf__ = dum[0].r; /* Compute space needed for CGEBRD */ cgebrd_(m, m, &a[a_offset], lda, &s[1], dum, dum, dum, dum, &c_n1, info); lwork_cgebrd__ = dum[0].r; /* Compute space needed for CUNMBR */ cunmbr_("Q", "L", "C", m, nrhs, n, &a[a_offset], lda, dum, &b[b_offset], ldb, dum, &c_n1, info); lwork_cunmbr__ = dum[0].r; /* Compute space needed for CUNGBR */ cungbr_("P", m, m, m, &a[a_offset], lda, dum, dum, &c_n1, info); lwork_cungbr__ = dum[0].r; /* Compute space needed for CUNMLQ */ cunmlq_("L", "C", n, nrhs, m, &a[a_offset], lda, dum, &b[ b_offset], ldb, dum, &c_n1, info); lwork_cunmlq__ = dum[0].r; /* Compute total workspace needed */ maxwrk = *m + lwork_cgelqf__; /* Computing MAX */ i__1 = maxwrk; i__2 = *m * 3 + *m * *m + lwork_cgebrd__; // , expr subst maxwrk = max(i__1,i__2); /* Computing MAX */ i__1 = maxwrk; i__2 = *m * 3 + *m * *m + lwork_cunmbr__; // , expr subst maxwrk = max(i__1,i__2); /* Computing MAX */ i__1 = maxwrk; i__2 = *m * 3 + *m * *m + lwork_cungbr__; // , expr subst maxwrk = max(i__1,i__2); if (*nrhs > 1) { /* Computing MAX */ i__1 = maxwrk; i__2 = *m * *m + *m + *m * *nrhs; // , expr subst maxwrk = max(i__1,i__2); } else { /* Computing MAX */ i__1 = maxwrk; i__2 = *m * *m + (*m << 1); // , expr subst maxwrk = max(i__1,i__2); } /* Computing MAX */ i__1 = maxwrk; i__2 = *m + lwork_cunmlq__; // , expr subst maxwrk = max(i__1,i__2); } else { /* Path 2 - underdetermined */ /* Compute space needed for CGEBRD */ cgebrd_(m, n, &a[a_offset], lda, &s[1], dum, dum, dum, dum, &c_n1, info); lwork_cgebrd__ = dum[0].r; /* Compute space needed for CUNMBR */ cunmbr_("Q", "L", "C", m, nrhs, m, &a[a_offset], lda, dum, &b[b_offset], ldb, dum, &c_n1, info); lwork_cunmbr__ = dum[0].r; /* Compute space needed for CUNGBR */ cungbr_("P", m, n, m, &a[a_offset], lda, dum, dum, &c_n1, info); lwork_cungbr__ = dum[0].r; maxwrk = (*m << 1) + lwork_cgebrd__; /* Computing MAX */ i__1 = maxwrk; i__2 = (*m << 1) + lwork_cunmbr__; // , expr subst maxwrk = max(i__1,i__2); /* Computing MAX */ i__1 = maxwrk; i__2 = (*m << 1) + lwork_cungbr__; // , expr subst maxwrk = max(i__1,i__2); /* Computing MAX */ i__1 = maxwrk; i__2 = *n * *nrhs; // , expr subst maxwrk = max(i__1,i__2); } } maxwrk = max(minwrk,maxwrk); } work[1].r = (real) maxwrk; work[1].i = 0.f; // , expr subst if (*lwork < minwrk && ! lquery) { *info = -12; } } if (*info != 0) { i__1 = -(*info); xerbla_("CGELSS", &i__1); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ if (*m == 0 || *n == 0) { *rank = 0; return 0; } /* Get machine parameters */ eps = slamch_("P"); sfmin = slamch_("S"); smlnum = sfmin / eps; bignum = 1.f / smlnum; slabad_(&smlnum, &bignum); /* Scale A if max element outside range [SMLNUM,BIGNUM] */ anrm = clange_("M", m, n, &a[a_offset], lda, &rwork[1]); iascl = 0; if (anrm > 0.f && anrm < smlnum) { /* Scale matrix norm up to SMLNUM */ clascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda, info); iascl = 1; } else if (anrm > bignum) { /* Scale matrix norm down to BIGNUM */ clascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda, info); iascl = 2; } else if (anrm == 0.f) { /* Matrix all zero. Return zero solution. */ i__1 = max(*m,*n); claset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb); slaset_("F", &minmn, &c__1, &c_b59, &c_b59, &s[1], &minmn); *rank = 0; goto L70; } /* Scale B if max element outside range [SMLNUM,BIGNUM] */ bnrm = clange_("M", m, nrhs, &b[b_offset], ldb, &rwork[1]); ibscl = 0; if (bnrm > 0.f && bnrm < smlnum) { /* Scale matrix norm up to SMLNUM */ clascl_("G", &c__0, &c__0, &bnrm, &smlnum, m, nrhs, &b[b_offset], ldb, info); ibscl = 1; } else if (bnrm > bignum) { /* Scale matrix norm down to BIGNUM */ clascl_("G", &c__0, &c__0, &bnrm, &bignum, m, nrhs, &b[b_offset], ldb, info); ibscl = 2; } /* Overdetermined case */ if (*m >= *n) { /* Path 1 - overdetermined or exactly determined */ mm = *m; if (*m >= mnthr) { /* Path 1a - overdetermined, with many more rows than columns */ mm = *n; itau = 1; iwork = itau + *n; /* Compute A=Q*R */ /* (CWorkspace: need 2*N, prefer N+N*NB) */ /* (RWorkspace: none) */ i__1 = *lwork - iwork + 1; cgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[iwork], &i__1, info); /* Multiply B by transpose(Q) */ /* (CWorkspace: need N+NRHS, prefer N+NRHS*NB) */ /* (RWorkspace: none) */ i__1 = *lwork - iwork + 1; cunmqr_("L", "C", m, nrhs, n, &a[a_offset], lda, &work[itau], &b[ b_offset], ldb, &work[iwork], &i__1, info); /* Zero out below R */ if (*n > 1) { i__1 = *n - 1; i__2 = *n - 1; claset_("L", &i__1, &i__2, &c_b1, &c_b1, &a[a_dim1 + 2], lda); } } ie = 1; itauq = 1; itaup = itauq + *n; iwork = itaup + *n; /* Bidiagonalize R in A */ /* (CWorkspace: need 2*N+MM, prefer 2*N+(MM+N)*NB) */ /* (RWorkspace: need N) */ i__1 = *lwork - iwork + 1; cgebrd_(&mm, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq], & work[itaup], &work[iwork], &i__1, info); /* Multiply B by transpose of left bidiagonalizing vectors of R */ /* (CWorkspace: need 2*N+NRHS, prefer 2*N+NRHS*NB) */ /* (RWorkspace: none) */ i__1 = *lwork - iwork + 1; cunmbr_("Q", "L", "C", &mm, nrhs, n, &a[a_offset], lda, &work[itauq], &b[b_offset], ldb, &work[iwork], &i__1, info); /* Generate right bidiagonalizing vectors of R in A */ /* (CWorkspace: need 3*N-1, prefer 2*N+(N-1)*NB) */ /* (RWorkspace: none) */ i__1 = *lwork - iwork + 1; cungbr_("P", n, n, n, &a[a_offset], lda, &work[itaup], &work[iwork], & i__1, info); irwork = ie + *n; /* Perform bidiagonal QR iteration */ /* multiply B by transpose of left singular vectors */ /* compute right singular vectors in A */ /* (CWorkspace: none) */ /* (RWorkspace: need BDSPAC) */ cbdsqr_("U", n, n, &c__0, nrhs, &s[1], &rwork[ie], &a[a_offset], lda, dum, &c__1, &b[b_offset], ldb, &rwork[irwork], info); if (*info != 0) { goto L70; } /* Multiply B by reciprocals of singular values */ /* Computing MAX */ r__1 = *rcond * s[1]; thr = max(r__1,sfmin); if (*rcond < 0.f) { /* Computing MAX */ r__1 = eps * s[1]; thr = max(r__1,sfmin); } *rank = 0; i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { if (s[i__] > thr) { csrscl_(nrhs, &s[i__], &b[i__ + b_dim1], ldb); ++(*rank); } else { claset_("F", &c__1, nrhs, &c_b1, &c_b1, &b[i__ + b_dim1], ldb); } /* L10: */ } /* Multiply B by right singular vectors */ /* (CWorkspace: need N, prefer N*NRHS) */ /* (RWorkspace: none) */ if (*lwork >= *ldb * *nrhs && *nrhs > 1) { cgemm_("C", "N", n, nrhs, n, &c_b2, &a[a_offset], lda, &b[ b_offset], ldb, &c_b1, &work[1], ldb); clacpy_("G", n, nrhs, &work[1], ldb, &b[b_offset], ldb) ; } else if (*nrhs > 1) { chunk = *lwork / *n; i__1 = *nrhs; i__2 = chunk; for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) { /* Computing MIN */ i__3 = *nrhs - i__ + 1; bl = min(i__3,chunk); cgemm_("C", "N", n, &bl, n, &c_b2, &a[a_offset], lda, &b[i__ * b_dim1 + 1], ldb, &c_b1, &work[1], n); clacpy_("G", n, &bl, &work[1], n, &b[i__ * b_dim1 + 1], ldb); /* L20: */ } } else { cgemv_("C", n, n, &c_b2, &a[a_offset], lda, &b[b_offset], &c__1, & c_b1, &work[1], &c__1); ccopy_(n, &work[1], &c__1, &b[b_offset], &c__1); } } else /* if(complicated condition) */ { /* Computing MAX */ i__2 = max(*m,*nrhs); i__1 = *n - (*m << 1); // , expr subst if (*n >= mnthr && *lwork >= *m * 3 + *m * *m + max(i__2,i__1)) { /* Underdetermined case, M much less than N */ /* Path 2a - underdetermined, with many more columns than rows */ /* and sufficient workspace for an efficient algorithm */ ldwork = *m; /* Computing MAX */ i__2 = max(*m,*nrhs); i__1 = *n - (*m << 1); // , expr subst if (*lwork >= *m * 3 + *m * *lda + max(i__2,i__1)) { ldwork = *lda; } itau = 1; iwork = *m + 1; /* Compute A=L*Q */ /* (CWorkspace: need 2*M, prefer M+M*NB) */ /* (RWorkspace: none) */ i__2 = *lwork - iwork + 1; cgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[iwork], &i__2, info); il = iwork; /* Copy L to WORK(IL), zeroing out above it */ clacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwork); i__2 = *m - 1; i__1 = *m - 1; claset_("U", &i__2, &i__1, &c_b1, &c_b1, &work[il + ldwork], & ldwork); ie = 1; itauq = il + ldwork * *m; itaup = itauq + *m; iwork = itaup + *m; /* Bidiagonalize L in WORK(IL) */ /* (CWorkspace: need M*M+4*M, prefer M*M+3*M+2*M*NB) */ /* (RWorkspace: need M) */ i__2 = *lwork - iwork + 1; cgebrd_(m, m, &work[il], &ldwork, &s[1], &rwork[ie], &work[itauq], &work[itaup], &work[iwork], &i__2, info); /* Multiply B by transpose of left bidiagonalizing vectors of L */ /* (CWorkspace: need M*M+3*M+NRHS, prefer M*M+3*M+NRHS*NB) */ /* (RWorkspace: none) */ i__2 = *lwork - iwork + 1; cunmbr_("Q", "L", "C", m, nrhs, m, &work[il], &ldwork, &work[ itauq], &b[b_offset], ldb, &work[iwork], &i__2, info); /* Generate right bidiagonalizing vectors of R in WORK(IL) */ /* (CWorkspace: need M*M+4*M-1, prefer M*M+3*M+(M-1)*NB) */ /* (RWorkspace: none) */ i__2 = *lwork - iwork + 1; cungbr_("P", m, m, m, &work[il], &ldwork, &work[itaup], &work[ iwork], &i__2, info); irwork = ie + *m; /* Perform bidiagonal QR iteration, computing right singular */ /* vectors of L in WORK(IL) and multiplying B by transpose of */ /* left singular vectors */ /* (CWorkspace: need M*M) */ /* (RWorkspace: need BDSPAC) */ cbdsqr_("U", m, m, &c__0, nrhs, &s[1], &rwork[ie], &work[il], & ldwork, &a[a_offset], lda, &b[b_offset], ldb, &rwork[ irwork], info); if (*info != 0) { goto L70; } /* Multiply B by reciprocals of singular values */ /* Computing MAX */ r__1 = *rcond * s[1]; thr = max(r__1,sfmin); if (*rcond < 0.f) { /* Computing MAX */ r__1 = eps * s[1]; thr = max(r__1,sfmin); } *rank = 0; i__2 = *m; for (i__ = 1; i__ <= i__2; ++i__) { if (s[i__] > thr) { csrscl_(nrhs, &s[i__], &b[i__ + b_dim1], ldb); ++(*rank); } else { claset_("F", &c__1, nrhs, &c_b1, &c_b1, &b[i__ + b_dim1], ldb); } /* L30: */ } iwork = il + *m * ldwork; /* Multiply B by right singular vectors of L in WORK(IL) */ /* (CWorkspace: need M*M+2*M, prefer M*M+M+M*NRHS) */ /* (RWorkspace: none) */ if (*lwork >= *ldb * *nrhs + iwork - 1 && *nrhs > 1) { cgemm_("C", "N", m, nrhs, m, &c_b2, &work[il], &ldwork, &b[ b_offset], ldb, &c_b1, &work[iwork], ldb); clacpy_("G", m, nrhs, &work[iwork], ldb, &b[b_offset], ldb); } else if (*nrhs > 1) { chunk = (*lwork - iwork + 1) / *m; i__2 = *nrhs; i__1 = chunk; for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) { /* Computing MIN */ i__3 = *nrhs - i__ + 1; bl = min(i__3,chunk); cgemm_("C", "N", m, &bl, m, &c_b2, &work[il], &ldwork, &b[ i__ * b_dim1 + 1], ldb, &c_b1, &work[iwork], m); clacpy_("G", m, &bl, &work[iwork], m, &b[i__ * b_dim1 + 1] , ldb); /* L40: */ } } else { cgemv_("C", m, m, &c_b2, &work[il], &ldwork, &b[b_dim1 + 1], & c__1, &c_b1, &work[iwork], &c__1); ccopy_(m, &work[iwork], &c__1, &b[b_dim1 + 1], &c__1); } /* Zero out below first M rows of B */ i__1 = *n - *m; claset_("F", &i__1, nrhs, &c_b1, &c_b1, &b[*m + 1 + b_dim1], ldb); iwork = itau + *m; /* Multiply transpose(Q) by B */ /* (CWorkspace: need M+NRHS, prefer M+NHRS*NB) */ /* (RWorkspace: none) */ i__1 = *lwork - iwork + 1; cunmlq_("L", "C", n, nrhs, m, &a[a_offset], lda, &work[itau], &b[ b_offset], ldb, &work[iwork], &i__1, info); } else { /* Path 2 - remaining underdetermined cases */ ie = 1; itauq = 1; itaup = itauq + *m; iwork = itaup + *m; /* Bidiagonalize A */ /* (CWorkspace: need 3*M, prefer 2*M+(M+N)*NB) */ /* (RWorkspace: need N) */ i__1 = *lwork - iwork + 1; cgebrd_(m, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq], &work[itaup], &work[iwork], &i__1, info); /* Multiply B by transpose of left bidiagonalizing vectors */ /* (CWorkspace: need 2*M+NRHS, prefer 2*M+NRHS*NB) */ /* (RWorkspace: none) */ i__1 = *lwork - iwork + 1; cunmbr_("Q", "L", "C", m, nrhs, n, &a[a_offset], lda, &work[itauq] , &b[b_offset], ldb, &work[iwork], &i__1, info); /* Generate right bidiagonalizing vectors in A */ /* (CWorkspace: need 3*M, prefer 2*M+M*NB) */ /* (RWorkspace: none) */ i__1 = *lwork - iwork + 1; cungbr_("P", m, n, m, &a[a_offset], lda, &work[itaup], &work[ iwork], &i__1, info); irwork = ie + *m; /* Perform bidiagonal QR iteration, */ /* computing right singular vectors of A in A and */ /* multiplying B by transpose of left singular vectors */ /* (CWorkspace: none) */ /* (RWorkspace: need BDSPAC) */ cbdsqr_("L", m, n, &c__0, nrhs, &s[1], &rwork[ie], &a[a_offset], lda, dum, &c__1, &b[b_offset], ldb, &rwork[irwork], info); if (*info != 0) { goto L70; } /* Multiply B by reciprocals of singular values */ /* Computing MAX */ r__1 = *rcond * s[1]; thr = max(r__1,sfmin); if (*rcond < 0.f) { /* Computing MAX */ r__1 = eps * s[1]; thr = max(r__1,sfmin); } *rank = 0; i__1 = *m; for (i__ = 1; i__ <= i__1; ++i__) { if (s[i__] > thr) { csrscl_(nrhs, &s[i__], &b[i__ + b_dim1], ldb); ++(*rank); } else { claset_("F", &c__1, nrhs, &c_b1, &c_b1, &b[i__ + b_dim1], ldb); } /* L50: */ } /* Multiply B by right singular vectors of A */ /* (CWorkspace: need N, prefer N*NRHS) */ /* (RWorkspace: none) */ if (*lwork >= *ldb * *nrhs && *nrhs > 1) { cgemm_("C", "N", n, nrhs, m, &c_b2, &a[a_offset], lda, &b[ b_offset], ldb, &c_b1, &work[1], ldb); clacpy_("G", n, nrhs, &work[1], ldb, &b[b_offset], ldb); } else if (*nrhs > 1) { chunk = *lwork / *n; i__1 = *nrhs; i__2 = chunk; for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) { /* Computing MIN */ i__3 = *nrhs - i__ + 1; bl = min(i__3,chunk); cgemm_("C", "N", n, &bl, m, &c_b2, &a[a_offset], lda, &b[ i__ * b_dim1 + 1], ldb, &c_b1, &work[1], n); clacpy_("F", n, &bl, &work[1], n, &b[i__ * b_dim1 + 1], ldb); /* L60: */ } } else { cgemv_("C", m, n, &c_b2, &a[a_offset], lda, &b[b_offset], & c__1, &c_b1, &work[1], &c__1); ccopy_(n, &work[1], &c__1, &b[b_offset], &c__1); } } } /* Undo scaling */ if (iascl == 1) { clascl_("G", &c__0, &c__0, &anrm, &smlnum, n, nrhs, &b[b_offset], ldb, info); slascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], & minmn, info); } else if (iascl == 2) { clascl_("G", &c__0, &c__0, &anrm, &bignum, n, nrhs, &b[b_offset], ldb, info); slascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], & minmn, info); } if (ibscl == 1) { clascl_("G", &c__0, &c__0, &smlnum, &bnrm, n, nrhs, &b[b_offset], ldb, info); } else if (ibscl == 2) { clascl_("G", &c__0, &c__0, &bignum, &bnrm, n, nrhs, &b[b_offset], ldb, info); } L70: work[1].r = (real) maxwrk; work[1].i = 0.f; // , expr subst return 0; /* End of CGELSS */ }
int main(void) { /* Local scalars */ char vect, vect_i; lapack_int m, m_i; lapack_int n, n_i; lapack_int k, k_i; lapack_int lda, lda_i; lapack_int lda_r; lapack_int lwork, lwork_i; lapack_int info, info_i; lapack_int i; int failed; /* Local arrays */ lapack_complex_float *a = NULL, *a_i = NULL; lapack_complex_float *tau = NULL, *tau_i = NULL; lapack_complex_float *work = NULL, *work_i = NULL; lapack_complex_float *a_save = NULL; lapack_complex_float *a_r = NULL; /* Iniitialize the scalar parameters */ init_scalars_cungbr( &vect, &m, &n, &k, &lda, &lwork ); lda_r = n+2; vect_i = vect; m_i = m; n_i = n; k_i = k; lda_i = lda; lwork_i = lwork; /* Allocate memory for the LAPACK routine arrays */ a = (lapack_complex_float *) LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) ); tau = (lapack_complex_float *) LAPACKE_malloc( MIN(m,k) * sizeof(lapack_complex_float) ); work = (lapack_complex_float *) LAPACKE_malloc( lwork * sizeof(lapack_complex_float) ); /* Allocate memory for the C interface function arrays */ a_i = (lapack_complex_float *) LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) ); tau_i = (lapack_complex_float *) LAPACKE_malloc( MIN(m,k) * sizeof(lapack_complex_float) ); work_i = (lapack_complex_float *) LAPACKE_malloc( lwork * sizeof(lapack_complex_float) ); /* Allocate memory for the backup arrays */ a_save = (lapack_complex_float *) LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) ); /* Allocate memory for the row-major arrays */ a_r = (lapack_complex_float *) LAPACKE_malloc( m*(n+2) * sizeof(lapack_complex_float) ); /* Initialize input arrays */ init_a( lda*n, a ); init_tau( (MIN(m,k)), tau ); init_work( lwork, work ); /* Backup the ouptut arrays */ for( i = 0; i < lda*n; i++ ) { a_save[i] = a[i]; } /* Call the LAPACK routine */ cungbr_( &vect, &m, &n, &k, a, &lda, tau, work, &lwork, &info ); /* Initialize input data, call the column-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a_save[i]; } for( i = 0; i < (MIN(m,k)); i++ ) { tau_i[i] = tau[i]; } for( i = 0; i < lwork; i++ ) { work_i[i] = work[i]; } info_i = LAPACKE_cungbr_work( LAPACK_COL_MAJOR, vect_i, m_i, n_i, k_i, a_i, lda_i, tau_i, work_i, lwork_i ); failed = compare_cungbr( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: column-major middle-level interface to cungbr\n" ); } else { printf( "FAILED: column-major middle-level interface to cungbr\n" ); } /* Initialize input data, call the column-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a_save[i]; } for( i = 0; i < (MIN(m,k)); i++ ) { tau_i[i] = tau[i]; } for( i = 0; i < lwork; i++ ) { work_i[i] = work[i]; } info_i = LAPACKE_cungbr( LAPACK_COL_MAJOR, vect_i, m_i, n_i, k_i, a_i, lda_i, tau_i ); failed = compare_cungbr( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: column-major high-level interface to cungbr\n" ); } else { printf( "FAILED: column-major high-level interface to cungbr\n" ); } /* Initialize input data, call the row-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a_save[i]; } for( i = 0; i < (MIN(m,k)); i++ ) { tau_i[i] = tau[i]; } for( i = 0; i < lwork; i++ ) { work_i[i] = work[i]; } LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 ); info_i = LAPACKE_cungbr_work( LAPACK_ROW_MAJOR, vect_i, m_i, n_i, k_i, a_r, lda_r, tau_i, work_i, lwork_i ); LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda ); failed = compare_cungbr( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: row-major middle-level interface to cungbr\n" ); } else { printf( "FAILED: row-major middle-level interface to cungbr\n" ); } /* Initialize input data, call the row-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a_save[i]; } for( i = 0; i < (MIN(m,k)); i++ ) { tau_i[i] = tau[i]; } for( i = 0; i < lwork; i++ ) { work_i[i] = work[i]; } /* Init row_major arrays */ LAPACKE_cge_trans( LAPACK_COL_MAJOR, m, n, a_i, lda, a_r, n+2 ); info_i = LAPACKE_cungbr( LAPACK_ROW_MAJOR, vect_i, m_i, n_i, k_i, a_r, lda_r, tau_i ); LAPACKE_cge_trans( LAPACK_ROW_MAJOR, m, n, a_r, n+2, a_i, lda ); failed = compare_cungbr( a, a_i, info, info_i, lda, n ); if( failed == 0 ) { printf( "PASSED: row-major high-level interface to cungbr\n" ); } else { printf( "FAILED: row-major high-level interface to cungbr\n" ); } /* Release memory */ if( a != NULL ) { LAPACKE_free( a ); } if( a_i != NULL ) { LAPACKE_free( a_i ); } if( a_r != NULL ) { LAPACKE_free( a_r ); } if( a_save != NULL ) { LAPACKE_free( a_save ); } if( tau != NULL ) { LAPACKE_free( tau ); } if( tau_i != NULL ) { LAPACKE_free( tau_i ); } if( work != NULL ) { LAPACKE_free( work ); } if( work_i != NULL ) { LAPACKE_free( work_i ); } return 0; }