// Compute the minimum-norm solution to a real linear least squares problem // minimize 2-norm (|b-A*x|) void MatB_Ax( Mat &A, Mat &B, Mat &X) { integer m = A.row; integer n = A.col; integer nrhs = B.col; integer lda = A.row; integer ldb = B.row; doublereal rcond = 1e-5; doublereal wkopt; doublereal *work; integer *iwork = new integer[3*m*0+11*m]; integer info, rank; doublereal S[3]; MatCopy( B, X); integer lwork = -1; dgelsd_( &m, &n, &nrhs, A.data, &lda, X.data, &ldb, S, &rcond, &rank, &wkopt, &lwork, iwork, &info); lwork = (integer)wkopt; work = new doublereal[lwork]; dgelsd_( &m, &n, &nrhs, A.data, &lda, X.data, &ldb, S, &rcond, &rank, work, &lwork, iwork, &info); /* Check for convergence */ if( info != 0 ) { printf( "The algorithm computing SVD failed to converge;\n" ); printf( "the least squares solution could not be computed.\n" ); system("pause"); } delete [] work; delete [] iwork; }
int ccdl::LeastSquaresSvdFit ( int const nobs, int const nparam, double const * A_obs_by_param, double * x_param, double const * b_obs, double TOL ) { // min (xt.At-bt).(A.x-b) std::vector<double> A( A_obs_by_param, A_obs_by_param + nparam*nobs ); int nmax = std::max( nparam, nobs ); std::vector<double> X( nmax, 0. ); std::copy( b_obs, b_obs + nobs, X.data() ); std::vector<double> S( nmax, 0. ); int LWORK = -1; std::vector<int> iwork(1,0); int INFO = 0; double twork = 0; int rank = 0; int nrhs=1; dgelsd_( &nobs, &nparam, &nrhs, A.data(), &nobs, X.data(), &nmax, S.data(), &TOL, &rank, &twork, &LWORK, iwork.data(), &INFO ); if ( INFO == 0 ) { LWORK = twork+1; std::vector<double> WORK( LWORK, 0. ); int LIWORK = iwork[0]; iwork.resize( LIWORK ); #ifdef PDBG std::printf("dgelsd_\n"); #endif dgelsd_( &nobs, &nparam, &nrhs, A.data(), &nobs, X.data(), &nmax, S.data(), &TOL, &rank, WORK.data(), &LWORK, iwork.data(), &INFO ); #ifdef PDBG std::printf("return %i\n",INFO); #endif std::copy( X.data(), X.data() + nparam, x_param ); } else { std::fill( x_param, x_param + nparam, 0. ); }; return INFO; }
int CLapack::gelsd(CFortranMatrix& a,CVector& rhs,double rcond,int& rank) { int m = a.GetNumberOfRows(); int n = a.GetNumberOfColumns(); int nrhs = 1; int lda = m; int ldb = std::max(m,n); CVector s; int ns = std::min(m,n); s.CreateVector(ns); int info = 0; // query work size int lwork = -1; double twork[1]; // printf("lwork = %d\n",lwork); CSimpleVector<int> iwork; int li = 3*std::min(m,n)*std::min(m,n) + 11*std::min(m,n); iwork.CreateVector(li); dgelsd_(&m,&n,&nrhs,a.GetRawDataField(),&lda,rhs.GetRawDataField(),&ldb,s.GetRawDataField(), &rcond,&rank,twork,&lwork,iwork.GetRawDataField(),&info); if( info != 0 ){ CSmallString error; error << "unable to determine lwork, info = " << info; INVALID_ARGUMENT(error); } lwork = static_cast<int>(twork[0]) + 1; // printf("lwork = %d\n",lwork); CSimpleVector<double> work; work.CreateVector(lwork); // run svd dgelsd_(&m,&n,&nrhs,a.GetRawDataField(),&lda,rhs.GetRawDataField(),&ldb,s.GetRawDataField(), &rcond,&rank,work.GetRawDataField(),&lwork,iwork.GetRawDataField(),&info); return(info); }
static long dgelsd(int m, int n, int nrhs, double *a, int lda, double *b, int ldb, double *s, double rcond, int *rank, double *work, int lwork, int *iwork) { extern void dgelsd_(const int *m, const int *n, const int *nrhs, double *a, const int *lda, double *b, const int *ldb, double *s, const double *rcond, int *rank, double *work, int *lwork, int *iwork, int *info); int info; dgelsd_(&m, &n, &nrhs, a, &lda, b, &ldb, s, &rcond, rank, work, &lwork, iwork, &info); return info; }
/** * @brief * checkPoints denote this term has not been checked. * limit it the least number of term in one surface * * @param subpoly * @param checkPoints * @param size * @param rePoints * @param limit * * @return */ int onSameSurf(const SubPoly* subpoly, const int* checkPoints, const int size, indice_t* rePoints, const int limit) { ASSERT(limit >= 1 && size >= limit, "candidate must greater or equal to limit"); indice_t* indices = subpoly->poly->indices; int dim = getvarNum(subpoly->poly->varId); int* loc = subpoly->locs; int i, j, m, k, maxSum, tempSum; int checkTime = dim * limit * size; int number = 0; int choose[limit]; long int numBound; int coefsNum[dim]; int coefsDen[dim]; double A[size * dim]; double dummy; int info; int DUM_DOMAIN = 1, bound = 1; for (i = 0; i < dim; i += 1) { for (j = 0; j < size; j += 1) { A[ijtok(j + 1, i + 1, size)] = indices[loc[checkPoints[j]] * dim + i]; } } double VT[dim * dim]; double eigenvector[dim]; info = lpca(A, size, dim, VT, TRUE); if (info != -1) { for (k = 0; k < dim; k += 1) { for (i = 0; i < dim; i += 1) { eigenvector[i] = VT[ijtok(k + 1, i + 1, dim)]; } DUM_DOMAIN = 0; for (m = 0; m < EIGN_CEF_BOUND; m += 1) { memset(rePoints, 0, size * sizeof(indice_t)); DUM_DOMAIN++; for (i = 0; i < dim; i += 1) { f2rat(eigenvector[i], DUM_DOMAIN, coefsDen + i, coefsNum + i); } bound = 1; for (i = 0; i < dim; i += 1) { if (coefsNum[i] != 0) { dummy = bound * coefsNum[i]; if (fabs(dummy) > LONG_MAX / 2) { bound = 0; break; } bound *= coefsNum[i]; } } ASSERT(0 != bound, ""); if (0 == bound) continue; for (i = 0; i < dim; i += 1) { if (coefsNum[i] != 0) { coefsDen[i] = (bound / coefsNum[i]); } else { coefsDen[i] = 0; } } number = 0; maxSum = 0; for (i = 0; i < dim; i += 1) { maxSum += coefsDen[i] * indices[loc[checkPoints[0]] * dim + i]; } number = 1; rePoints[0] = 1; for (i = 1; i < size; i += 1) { tempSum = 0; for (j = 0; j < dim; j += 1) { tempSum += coefsDen[j] * indices[loc[checkPoints[i]] * dim + j]; } if (tempSum > maxSum) { maxSum = tempSum; memset(rePoints, 0, i * sizeof(indice_t)); rePoints[i] = 1; number = 1; } else if (tempSum == maxSum) { number++; rePoints[i] = 1; } } if (number >= limit) { return number; } } } } int M = limit; int N = dim; int NRHS = 1; int LDA = limit; int LDB = dim > limit ? dim : limit; m = M; int n = N, nrhs = NRHS, lda = LDA, ldb = LDB, lwork, rank; /* Negative rcond means using default (machine precision) value */ double rcond = -1.0; double wkopt; double* work; /* Local arrays */ /* iwork dimension should be at least 3*min(m,n)*nlvl + 11*min(m,n), where nlvl = max( 0, int( log_2( min(m,n)/(smlsiz+1) ) )+1 ) and smlsiz = 25 */ int iwork[3 * M * 1 + 11 * M]; double s[M < N ? M : N]; double a[LDA * N]; // double dummy; double b[LDB * NRHS]; for (i = 0; i < checkTime; i += 1) { memset(rePoints, 0, size * sizeof(indice_t)); number = 0; j = 0; k = 0; while (1) { k++; if (k == size) k = 0; if (rePoints[k]) continue; if (rand() % size < limit) { rePoints[k] = 1; choose[number++] = k; if (number >= limit) break; } } numBound = dim * dim; for (k = 0; k < dim; k += 1) { numBound *= (indices[loc[checkPoints[choose[0]]] * dim + k] + 1); } for (j = 0; j < limit; j += 1) { b[j] = 1; for (k = 0; k < dim; k += 1) { a[k * limit + j] = indices[loc[checkPoints[choose[j]]] * dim + k]; } } /* Query and allocate the optimal workspace */ lwork = -1; dgelsd_(&m, &n, &nrhs, a, &lda, b, &ldb, s, &rcond, &rank, &wkopt, &lwork, iwork, &info); lwork = (int)wkopt; work = (double*)malloc(lwork * sizeof(double)); /* Solve the equations A*X = B */ dgelsd_(&m, &n, &nrhs, a, &lda, b, &ldb, s, &rcond, &rank, work, &lwork, iwork, &info); if (info == 0) { /* success */ for (k = 0; k < dim; k += 1) { f2rat(b[k], numBound, coefsDen + k, coefsNum + k); } numBound = 1; for (k = 0; k < dim; k += 1) { if (coefsNum[k] != 0) { dummy = numBound * coefsNum[k]; if (fabs(dummy) > LONG_MAX / 2) { numBound = 0; break; } numBound *= coefsNum[k]; } } if (0 == numBound) continue; for (k = 0; k < dim; k += 1) { if (coefsNum[k] != 0) { coefsDen[k] *= (numBound / coefsNum[k]); } else coefsDen[k] = 0; } for (k = 0; k < limit; k += 1) { tempSum = 0; for (j = 0; j < dim; j += 1) { tempSum += coefsDen[j] * indices[loc[checkPoints[choose[k]]] * dim + j]; } if (tempSum != numBound) break; } if (tempSum != numBound) continue; k = 0; number = limit; while (k < size) { while (1 == rePoints[k] && k < size) k++; if (k == size) return number; tempSum = 0; for (j = 0; j < dim; j += 1) { tempSum += coefsDen[j] * indices[loc[checkPoints[k]] * dim + j]; } k++; if (tempSum == numBound) { number++; rePoints[k - 1] = 1; } else break; } if (k == size) return number; if (tempSum > numBound) { for (; k < size; k += 1) { if (0 == rePoints[k]) { tempSum = 0; for (j = 0; j < dim; j += 1) { tempSum += coefsDen[j] * indices[loc[checkPoints[k]] * dim + j]; } if (tempSum < numBound) break; else if (tempSum == numBound) { rePoints[k] = 1; number++; } } } if (tempSum < numBound) continue; return number; } else if (tempSum < numBound) { for (; k < size; k += 1) { if (0 == rePoints[k]) { tempSum = 0; for (j = 0; j < dim; j += 1) { tempSum += coefsDen[j] * indices[loc[checkPoints[k]] * dim + j]; } if (tempSum > numBound) break; else if (tempSum == numBound) { rePoints[k] = 1; number++; } } } if (tempSum > numBound) continue; return number; } } free((void*)work); } return -1; }
int lls(const gsl_matrix *A, const gsl_vector *c, gsl_vector *x) { int m = (int) A->size1; int n = (int) A->size2; int nrhs = 1; int info; int lwork; gsl_matrix *aa, *bb; gsl_vector *s; gsl_vector *work; double q[1]; int ldb = GSL_MAX(m, n); int lda = m; double rcond = 1.0e-12; int rank; int *iwork = 0; gsl_vector_view v; gsl_vector *rhs; rhs = gsl_vector_alloc(c->size); aa = gsl_matrix_alloc(A->size2, A->size1); bb = gsl_matrix_alloc(nrhs, GSL_MAX(m, n)); s = gsl_vector_alloc(GSL_MIN(m, n)); gsl_matrix_transpose_memcpy(aa, A); gsl_vector_memcpy(rhs, c); v = gsl_matrix_subrow(bb, 0, 0, m); gsl_vector_memcpy(&v.vector, rhs); lwork = -1; dgelsd_(&m, &n, &nrhs, aa->data, &lda, bb->data, &ldb, s->data, &rcond, &rank, q, &lwork, iwork, &info); lwork = (int) q[0]; work = gsl_vector_alloc((size_t) lwork); iwork = malloc(sizeof(int) * m); dgelsd_(&m, &n, &nrhs, aa->data, &lda, bb->data, &ldb, s->data, &rcond, &rank, work->data, &lwork, iwork, &info); v = gsl_matrix_subrow(bb, 0, 0, n); gsl_vector_memcpy(x, &v.vector); gsl_matrix_free(aa); gsl_matrix_free(bb); gsl_vector_free(s); gsl_vector_free(rhs); gsl_vector_free(work); free(iwork); if (info) fprintf(stderr, "ERROR: lls: info = %d\n", info); return (info); } /* lls() */
/** * \brief get the corrected projection */ Projection ProjectionCorrector::corrected( const std::vector<Residual>& residuals) const { debug(LOG_DEBUG, DEBUG_LOG, 0, "correct projection: %s", centeredprojection.toString().c_str()); // allocate an array for the computation of the correction int n = 2 * residuals.size(); double a[8 * n]; double b[n]; debug(LOG_DEBUG, DEBUG_LOG, 0, "%d equations", n); // start filling in the arrays std::vector<Residual>::const_iterator r; unsigned int i; for (r = residuals.begin(), i = 0; r != residuals.end(); r++, i += 2) { b[i ] = r->offset().x(); b[i + 1] = r->offset().y(); } // display the right hand side if (debuglevel >= LOG_DEBUG) { std::string msg("b = [\n"); for (i = 0; i < 2 * residuals.size(); i++) { msg += stringprintf("%f;\n", b[i]); } msg += std::string("];\n"); std::cout << msg; } // build the matrix of derivatives double h = 0.01; for (int j = 0; j < 8; j++) { CenteredProjection pr = centeredprojection; pr[j] += h; for (r = residuals.begin(), i = 0; r != residuals.end(); r++, i += 2) { Point p1 = centeredprojection(r->from()); Point p2 = pr(r->from()); Point delta = (p2 - p1) * (1 / h); a[i + n * j] = delta.x(); a[i + 1 + n * j] = delta.y(); } } debug(LOG_DEBUG, DEBUG_LOG, 0, "derivative matrix computed"); // report the derivatives matrix for debugging if (debuglevel >= LOG_DEBUG) { std::string msg("A = [\n"); for (i = 0; i < 2 * residuals.size(); i++) { msg += stringprintf("/* %3d */ ", i); for (int j = 0; j < 8; j++) { if (j > 0) { msg += std::string(","); } msg += stringprintf(" %10.3g", a[i + n * j]); } msg += stringprintf(";\n"); } msg += std::string("];\n"); std::cout << msg; } // apply the weights for (r = residuals.begin(), i = 0; r != residuals.end(); r++, i++) { b[2 * i ] *= r->weight(); b[2 * i + 1] *= r->weight(); for (unsigned int j = 0; j < 8; j++) { a[2 * i + n * j] *= r->weight(); a[2 * i + 1 + n * j] *= r->weight(); } } // compute liwork (based on dgelsd documentation) int nlvl = 4; /* LOG_2(8 / SMLSIZ + 1) + 1 */ int liwork = (3 * nlvl + 11) * 8; // solve the system of equations, gives the correction int m = 8; int nrhs = 1; int lda = n; int ldb = n; double s[8]; double rcond = 0; int rank = 0; int lwork = -1; int iwork_length = liwork; int info = 0; double x; dgelsd_(&n, &m, &nrhs, a, &lda, b, &ldb, s, &rcond, &rank, &x, &lwork, &iwork_length, &info); if (info != 0) { std::string msg = stringprintf("dgels cannot determine " "work area size: %d", info); debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str()); throw std::runtime_error(msg); } lwork = x; debug(LOG_DEBUG, DEBUG_LOG, 0, "need work area of size %d, " "and iwork of size %d", lwork, iwork_length); // with the correct work array in place, the next call solves the // equations double work[lwork]; int iwork[iwork_length]; dgelsd_(&n, &m, &nrhs, a, &lda, b, &ldb, s, &rcond, &rank, work, &lwork, iwork, &info); if (info != 0) { std::string msg = stringprintf("dgels cannot solve " "equations: %d", info); debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str()); throw std::runtime_error(msg); } if (info == 0) { debug(LOG_DEBUG, DEBUG_LOG, 0, "reported iwork length: %d", iwork[0]); } debug(LOG_DEBUG, DEBUG_LOG, 0, "system of equations solved, rank = %d", rank); if (debuglevel >= LOG_DEBUG) { for (int j = 0; j < 8; j++) { debug(LOG_DEBUG, DEBUG_LOG, 0, "singular value[%d] = %f", j, s[j]); } } // copy result vector CenteredProjection pr = centeredprojection; for (int j = 0; j < 8; j++) { debug(LOG_DEBUG, DEBUG_LOG, 0, "correction[%d] = %g", j, b[j]); pr[j] += b[j]; } debug(LOG_DEBUG, DEBUG_LOG, 0, "original projection: %s", centeredprojection.toString().c_str()); debug(LOG_DEBUG, DEBUG_LOG, 0, "new projection: %s", pr.toString().c_str()); return pr; }
/* Subroutine */ int derrls_(char *path, integer *nunit) { /* Builtin functions */ integer s_wsle(cilist *), e_wsle(void); /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); /* Local variables */ doublereal a[4] /* was [2][2] */, b[4] /* was [2][2] */, s[2], w[2]; char c2[2]; integer ip[2], info, irnk; extern /* Subroutine */ int dgels_(char *, integer *, integer *, integer * , doublereal *, integer *, doublereal *, integer *, doublereal *, integer *, integer *); doublereal rcond; extern /* Subroutine */ int alaesm_(char *, logical *, integer *), dgelsd_(integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *, integer *, integer *); extern logical lsamen_(integer *, char *, char *); extern /* Subroutine */ int dgelss_(integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *, integer *), chkxer_(char *, integer *, integer *, logical *, logical *), dgelsx_(integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, integer *, doublereal *, integer *, doublereal *, integer *), dgelsy_(integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, integer *); /* Fortran I/O blocks */ static cilist io___1 = { 0, 0, 0, 0, 0 }; /* -- LAPACK test routine (version 3.1) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* DERRLS tests the error exits for the DOUBLE PRECISION least squares */ /* driver routines (DGELS, SGELSS, SGELSX, SGELSY, SGELSD). */ /* 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 .. */ /* .. */ /* .. 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); a[0] = 1.; a[2] = 2.; a[3] = 3.; a[1] = 4.; infoc_1.ok = TRUE_; if (lsamen_(&c__2, c2, "LS")) { /* Test error exits for the least squares driver routines. */ /* DGELS */ s_copy(srnamc_1.srnamt, "DGELS ", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; dgels_("/", &c__0, &c__0, &c__0, a, &c__1, b, &c__1, w, &c__1, &info); chkxer_("DGELS ", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; dgels_("N", &c_n1, &c__0, &c__0, a, &c__1, b, &c__1, w, &c__1, &info); chkxer_("DGELS ", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; dgels_("N", &c__0, &c_n1, &c__0, a, &c__1, b, &c__1, w, &c__1, &info); chkxer_("DGELS ", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 4; dgels_("N", &c__0, &c__0, &c_n1, a, &c__1, b, &c__1, w, &c__1, &info); chkxer_("DGELS ", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 6; dgels_("N", &c__2, &c__0, &c__0, a, &c__1, b, &c__2, w, &c__2, &info); chkxer_("DGELS ", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 8; dgels_("N", &c__2, &c__0, &c__0, a, &c__2, b, &c__1, w, &c__2, &info); chkxer_("DGELS ", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 10; dgels_("N", &c__1, &c__1, &c__0, a, &c__1, b, &c__1, w, &c__1, &info); chkxer_("DGELS ", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* DGELSS */ s_copy(srnamc_1.srnamt, "DGELSS", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; dgelss_(&c_n1, &c__0, &c__0, a, &c__1, b, &c__1, s, &rcond, &irnk, w, &c__1, &info); chkxer_("DGELSS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; dgelss_(&c__0, &c_n1, &c__0, a, &c__1, b, &c__1, s, &rcond, &irnk, w, &c__1, &info); chkxer_("DGELSS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; dgelss_(&c__0, &c__0, &c_n1, a, &c__1, b, &c__1, s, &rcond, &irnk, w, &c__1, &info); chkxer_("DGELSS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; dgelss_(&c__2, &c__0, &c__0, a, &c__1, b, &c__2, s, &rcond, &irnk, w, &c__2, &info); chkxer_("DGELSS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 7; dgelss_(&c__2, &c__0, &c__0, a, &c__2, b, &c__1, s, &rcond, &irnk, w, &c__2, &info); chkxer_("DGELSS", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* DGELSX */ s_copy(srnamc_1.srnamt, "DGELSX", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; dgelsx_(&c_n1, &c__0, &c__0, a, &c__1, b, &c__1, ip, &rcond, &irnk, w, &info); chkxer_("DGELSX", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; dgelsx_(&c__0, &c_n1, &c__0, a, &c__1, b, &c__1, ip, &rcond, &irnk, w, &info); chkxer_("DGELSX", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; dgelsx_(&c__0, &c__0, &c_n1, a, &c__1, b, &c__1, ip, &rcond, &irnk, w, &info); chkxer_("DGELSX", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; dgelsx_(&c__2, &c__0, &c__0, a, &c__1, b, &c__2, ip, &rcond, &irnk, w, &info); chkxer_("DGELSX", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 7; dgelsx_(&c__2, &c__0, &c__0, a, &c__2, b, &c__1, ip, &rcond, &irnk, w, &info); chkxer_("DGELSX", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* DGELSY */ s_copy(srnamc_1.srnamt, "DGELSY", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; dgelsy_(&c_n1, &c__0, &c__0, a, &c__1, b, &c__1, ip, &rcond, &irnk, w, &c__10, &info); chkxer_("DGELSY", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; dgelsy_(&c__0, &c_n1, &c__0, a, &c__1, b, &c__1, ip, &rcond, &irnk, w, &c__10, &info); chkxer_("DGELSY", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; dgelsy_(&c__0, &c__0, &c_n1, a, &c__1, b, &c__1, ip, &rcond, &irnk, w, &c__10, &info); chkxer_("DGELSY", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; dgelsy_(&c__2, &c__0, &c__0, a, &c__1, b, &c__2, ip, &rcond, &irnk, w, &c__10, &info); chkxer_("DGELSY", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 7; dgelsy_(&c__2, &c__0, &c__0, a, &c__2, b, &c__1, ip, &rcond, &irnk, w, &c__10, &info); chkxer_("DGELSY", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 12; dgelsy_(&c__2, &c__2, &c__1, a, &c__2, b, &c__2, ip, &rcond, &irnk, w, &c__1, &info); chkxer_("DGELSY", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); /* DGELSD */ s_copy(srnamc_1.srnamt, "DGELSD", (ftnlen)6, (ftnlen)6); infoc_1.infot = 1; dgelsd_(&c_n1, &c__0, &c__0, a, &c__1, b, &c__1, s, &rcond, &irnk, w, &c__10, ip, &info); chkxer_("DGELSD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 2; dgelsd_(&c__0, &c_n1, &c__0, a, &c__1, b, &c__1, s, &rcond, &irnk, w, &c__10, ip, &info); chkxer_("DGELSD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 3; dgelsd_(&c__0, &c__0, &c_n1, a, &c__1, b, &c__1, s, &rcond, &irnk, w, &c__10, ip, &info); chkxer_("DGELSD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 5; dgelsd_(&c__2, &c__0, &c__0, a, &c__1, b, &c__2, s, &rcond, &irnk, w, &c__10, ip, &info); chkxer_("DGELSD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 7; dgelsd_(&c__2, &c__0, &c__0, a, &c__2, b, &c__1, s, &rcond, &irnk, w, &c__10, ip, &info); chkxer_("DGELSD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); infoc_1.infot = 12; dgelsd_(&c__2, &c__2, &c__1, a, &c__2, b, &c__2, s, &rcond, &irnk, w, &c__1, ip, &info); chkxer_("DGELSD", &infoc_1.infot, &infoc_1.nout, &infoc_1.lerr, & infoc_1.ok); } /* Print a summary line. */ alaesm_(path, &infoc_1.ok, &infoc_1.nout); return 0; /* End of DERRLS */ } /* derrls_ */
/* Subroutine */ int ddrvls_(logical *dotype, integer *nm, integer *mval, integer *nn, integer *nval, integer *nns, integer *nsval, integer * nnb, integer *nbval, integer *nxval, doublereal *thresh, logical * tsterr, doublereal *a, doublereal *copya, doublereal *b, doublereal * copyb, doublereal *c__, doublereal *s, doublereal *copys, doublereal * work, integer *iwork, integer *nout) { /* Initialized data */ static integer iseedy[4] = { 1988,1989,1990,1991 }; /* Format strings */ static char fmt_9999[] = "(\002 TRANS='\002,a1,\002', M=\002,i5,\002, N" "=\002,i5,\002, NRHS=\002,i4,\002, NB=\002,i4,\002, type\002,i2" ",\002, test(\002,i2,\002)=\002,g12.5)"; static char fmt_9998[] = "(\002 M=\002,i5,\002, N=\002,i5,\002, NRHS=" "\002,i4,\002, NB=\002,i4,\002, type\002,i2,\002, test(\002,i2" ",\002)=\002,g12.5)"; /* System generated locals */ integer i__1, i__2, i__3, i__4, i__5, i__6; doublereal d__1, d__2; /* Builtin functions Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen); double sqrt(doublereal), log(doublereal); integer s_wsfe(cilist *), do_fio(integer *, char *, ftnlen), e_wsfe(void); /* Local variables */ static integer info; static char path[3]; static integer rank, nrhs, nlvl, nrun, i__, j, k; extern /* Subroutine */ int alahd_(integer *, char *); static integer m, n; extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, integer *); static integer nfail, iseed[4]; extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *); static integer crank; extern /* Subroutine */ int dgels_(char *, integer *, integer *, integer * , doublereal *, integer *, doublereal *, integer *, doublereal *, integer *, integer *); static integer irank; static doublereal rcond; extern doublereal dasum_(integer *, doublereal *, integer *); static integer itran, mnmin, ncols; static doublereal norma, normb; extern doublereal dqrt12_(integer *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *), dqrt14_(char *, integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, integer *), dqrt17_(char *, integer *, integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *); extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, integer *, doublereal *, integer *); static char trans[1]; static integer nerrs, itype; extern /* Subroutine */ int dqrt13_(integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *); static integer lwork; extern /* Subroutine */ int dqrt15_(integer *, integer *, integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *), dqrt16_(char *, integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *); static integer nrows, lwlsy, nb, im, in; extern doublereal dlamch_(char *); extern /* Subroutine */ int alaerh_(char *, char *, integer *, integer *, char *, integer *, integer *, integer *, integer *, integer *, integer *, integer *, integer *, integer *); static integer iscale; extern /* Subroutine */ int dgelsd_(integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *, integer *, integer *), dlacpy_(char *, integer *, integer *, doublereal *, integer *, doublereal *, integer *), dgelss_(integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *, integer *), alasvm_(char *, integer *, integer *, integer *, integer *), dgelsx_(integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, integer *, doublereal *, integer *, doublereal *, integer *), dgelsy_(integer *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, integer *, doublereal *, integer *, doublereal *, integer *, integer *), dlarnv_(integer *, integer *, integer *, doublereal *), derrls_(char *, integer *), xlaenv_(integer *, integer *); static integer ldwork; static doublereal result[18]; static integer lda, ldb, inb; static doublereal eps; static integer ins; /* Fortran I/O blocks */ static cilist io___35 = { 0, 0, 0, fmt_9999, 0 }; static cilist io___40 = { 0, 0, 0, fmt_9998, 0 }; static cilist io___42 = { 0, 0, 0, fmt_9998, 0 }; /* -- LAPACK test routine (version 3.0) -- Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University January 3, 2000 Purpose ======= DDRVLS tests the least squares driver routines DGELS, DGELSS, DGELSX, DGELSY and DGELSD. Arguments ========= DOTYPE (input) LOGICAL array, dimension (NTYPES) The matrix types to be used for testing. Matrices of type j (for 1 <= j <= NTYPES) are used for testing if DOTYPE(j) = .TRUE.; if DOTYPE(j) = .FALSE., then type j is not used. The matrix of type j is generated as follows: j=1: A = U*D*V where U and V are random orthogonal matrices and D has random entries (> 0.1) taken from a uniform distribution (0,1). A is full rank. j=2: The same of 1, but A is scaled up. j=3: The same of 1, but A is scaled down. j=4: A = U*D*V where U and V are random orthogonal matrices and D has 3*min(M,N)/4 random entries (> 0.1) taken from a uniform distribution (0,1) and the remaining entries set to 0. A is rank-deficient. j=5: The same of 4, but A is scaled up. j=6: The same of 5, but A is scaled down. NM (input) INTEGER The number of values of M contained in the vector MVAL. MVAL (input) INTEGER array, dimension (NM) The values of the matrix row dimension M. NN (input) INTEGER The number of values of N contained in the vector NVAL. NVAL (input) INTEGER array, dimension (NN) The values of the matrix column dimension N. NNS (input) INTEGER The number of values of NRHS contained in the vector NSVAL. NSVAL (input) INTEGER array, dimension (NNS) The values of the number of right hand sides NRHS. NNB (input) INTEGER The number of values of NB and NX contained in the vectors NBVAL and NXVAL. The blocking parameters are used in pairs (NB,NX). NBVAL (input) INTEGER array, dimension (NNB) The values of the blocksize NB. NXVAL (input) INTEGER array, dimension (NNB) The values of the crossover point NX. THRESH (input) DOUBLE PRECISION 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. TSTERR (input) LOGICAL Flag that indicates whether error exits are to be tested. A (workspace) DOUBLE PRECISION array, dimension (MMAX*NMAX) where MMAX is the maximum value of M in MVAL and NMAX is the maximum value of N in NVAL. COPYA (workspace) DOUBLE PRECISION array, dimension (MMAX*NMAX) B (workspace) DOUBLE PRECISION array, dimension (MMAX*NSMAX) where MMAX is the maximum value of M in MVAL and NSMAX is the maximum value of NRHS in NSVAL. COPYB (workspace) DOUBLE PRECISION array, dimension (MMAX*NSMAX) C (workspace) DOUBLE PRECISION array, dimension (MMAX*NSMAX) S (workspace) DOUBLE PRECISION array, dimension (min(MMAX,NMAX)) COPYS (workspace) DOUBLE PRECISION array, dimension (min(MMAX,NMAX)) WORK (workspace) DOUBLE PRECISION array, dimension (MMAX*NMAX + 4*NMAX + MMAX). IWORK (workspace) INTEGER array, dimension (15*NMAX) NOUT (input) INTEGER The unit number for output. ===================================================================== Parameter adjustments */ --iwork; --work; --copys; --s; --c__; --copyb; --b; --copya; --a; --nxval; --nbval; --nsval; --nval; --mval; --dotype; /* Function Body Initialize constants and the random number seed. */ s_copy(path, "Double precision", (ftnlen)1, (ftnlen)16); s_copy(path + 1, "LS", (ftnlen)2, (ftnlen)2); nrun = 0; nfail = 0; nerrs = 0; for (i__ = 1; i__ <= 4; ++i__) { iseed[i__ - 1] = iseedy[i__ - 1]; /* L10: */ } eps = dlamch_("Epsilon"); /* Threshold for rank estimation */ rcond = sqrt(eps) - (sqrt(eps) - eps) / 2; /* Test the error exits */ if (*tsterr) { derrls_(path, nout); } /* Print the header if NM = 0 or NN = 0 and THRESH = 0. */ if ((*nm == 0 || *nn == 0) && *thresh == 0.) { alahd_(nout, path); } infoc_1.infot = 0; xlaenv_(&c__2, &c__2); xlaenv_(&c__9, &c__25); i__1 = *nm; for (im = 1; im <= i__1; ++im) { m = mval[im]; lda = max(1,m); i__2 = *nn; for (in = 1; in <= i__2; ++in) { n = nval[in]; mnmin = min(m,n); /* Computing MAX */ i__3 = max(1,m); ldb = max(i__3,n); i__3 = *nns; for (ins = 1; ins <= i__3; ++ins) { nrhs = nsval[ins]; /* Computing MAX Computing MAX */ d__1 = 1., d__2 = (doublereal) mnmin; i__4 = (integer) (log(max(d__1,d__2) / 26.) / log(2.)) + 1; nlvl = max(i__4,0); /* Computing MAX */ i__4 = 1, i__5 = (m + nrhs) * (n + 2), i__4 = max(i__4,i__5), i__5 = (n + nrhs) * (m + 2), i__4 = max(i__4,i__5), i__5 = m * n + (mnmin << 2) + max(m,n), i__4 = max( i__4,i__5), i__5 = mnmin * 12 + mnmin * 50 + (mnmin << 3) * nlvl + mnmin * nrhs + 676; lwork = max(i__4,i__5); for (irank = 1; irank <= 2; ++irank) { for (iscale = 1; iscale <= 3; ++iscale) { itype = (irank - 1) * 3 + iscale; if (! dotype[itype]) { goto L110; } if (irank == 1) { /* Test DGELS Generate a matrix of scaling type ISCALE */ dqrt13_(&iscale, &m, &n, ©a[1], &lda, &norma, iseed); i__4 = *nnb; for (inb = 1; inb <= i__4; ++inb) { nb = nbval[inb]; xlaenv_(&c__1, &nb); xlaenv_(&c__3, &nxval[inb]); for (itran = 1; itran <= 2; ++itran) { if (itran == 1) { *(unsigned char *)trans = 'N'; nrows = m; ncols = n; } else { *(unsigned char *)trans = 'T'; nrows = n; ncols = m; } ldwork = max(1,ncols); /* Set up a consistent rhs */ if (ncols > 0) { i__5 = ncols * nrhs; dlarnv_(&c__2, iseed, &i__5, &work[1]) ; i__5 = ncols * nrhs; d__1 = 1. / (doublereal) ncols; dscal_(&i__5, &d__1, &work[1], &c__1); } dgemm_(trans, "No transpose", &nrows, & nrhs, &ncols, &c_b24, ©a[1], & lda, &work[1], &ldwork, &c_b25, & b[1], &ldb) ; dlacpy_("Full", &nrows, &nrhs, &b[1], & ldb, ©b[1], &ldb); /* Solve LS or overdetermined system */ if (m > 0 && n > 0) { dlacpy_("Full", &m, &n, ©a[1], & lda, &a[1], &lda); dlacpy_("Full", &nrows, &nrhs, ©b[ 1], &ldb, &b[1], &ldb); } s_copy(srnamc_1.srnamt, "DGELS ", (ftnlen) 6, (ftnlen)6); dgels_(trans, &m, &n, &nrhs, &a[1], &lda, &b[1], &ldb, &work[1], &lwork, & info); if (info != 0) { alaerh_(path, "DGELS ", &info, &c__0, trans, &m, &n, &nrhs, &c_n1, & nb, &itype, &nfail, &nerrs, nout); } /* Check correctness of results */ ldwork = max(1,nrows); if (nrows > 0 && nrhs > 0) { dlacpy_("Full", &nrows, &nrhs, ©b[ 1], &ldb, &c__[1], &ldb); } dqrt16_(trans, &m, &n, &nrhs, ©a[1], & lda, &b[1], &ldb, &c__[1], &ldb, & work[1], result); if (itran == 1 && m >= n || itran == 2 && m < n) { /* Solving LS system */ result[1] = dqrt17_(trans, &c__1, &m, &n, &nrhs, ©a[1], &lda, & b[1], &ldb, ©b[1], &ldb, & c__[1], &work[1], &lwork); } else { /* Solving overdetermined system */ result[1] = dqrt14_(trans, &m, &n, & nrhs, ©a[1], &lda, &b[1], &ldb, &work[1], &lwork); } /* Print information about the tests that did not pass the threshold. */ for (k = 1; k <= 2; ++k) { if (result[k - 1] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___35.ciunit = *nout; s_wsfe(&io___35); do_fio(&c__1, trans, (ftnlen)1); do_fio(&c__1, (char *)&m, (ftnlen) sizeof(integer)); do_fio(&c__1, (char *)&n, (ftnlen) sizeof(integer)); do_fio(&c__1, (char *)&nrhs, ( ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&nb, ( ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&itype, ( ftnlen)sizeof(integer)); do_fio(&c__1, (char *)&k, (ftnlen) sizeof(integer)); do_fio(&c__1, (char *)&result[k - 1], (ftnlen)sizeof( doublereal)); e_wsfe(); ++nfail; } /* L20: */ } nrun += 2; /* L30: */ } /* L40: */ } } /* Generate a matrix of scaling type ISCALE and rank type IRANK. */ dqrt15_(&iscale, &irank, &m, &n, &nrhs, ©a[1], & lda, ©b[1], &ldb, ©s[1], &rank, & norma, &normb, iseed, &work[1], &lwork); /* workspace used: MAX(M+MIN(M,N),NRHS*MIN(M,N),2*N+M) Initialize vector IWORK. */ i__4 = n; for (j = 1; j <= i__4; ++j) { iwork[j] = 0; /* L50: */ } ldwork = max(1,m); /* Test DGELSX DGELSX: Compute the minimum-norm solution X to min( norm( A * X - B ) ) using a complete orthogonal factorization. */ dlacpy_("Full", &m, &n, ©a[1], &lda, &a[1], &lda); dlacpy_("Full", &m, &nrhs, ©b[1], &ldb, &b[1], & ldb); s_copy(srnamc_1.srnamt, "DGELSX", (ftnlen)6, (ftnlen) 6); dgelsx_(&m, &n, &nrhs, &a[1], &lda, &b[1], &ldb, & iwork[1], &rcond, &crank, &work[1], &info); if (info != 0) { alaerh_(path, "DGELSX", &info, &c__0, " ", &m, &n, &nrhs, &c_n1, &nb, &itype, &nfail, & nerrs, nout); } /* workspace used: MAX( MNMIN+3*N, 2*MNMIN+NRHS ) Test 3: Compute relative error in svd workspace: M*N + 4*MIN(M,N) + MAX(M,N) */ result[2] = dqrt12_(&crank, &crank, &a[1], &lda, & copys[1], &work[1], &lwork); /* Test 4: Compute error in solution workspace: M*NRHS + M */ dlacpy_("Full", &m, &nrhs, ©b[1], &ldb, &work[1], &ldwork); dqrt16_("No transpose", &m, &n, &nrhs, ©a[1], & lda, &b[1], &ldb, &work[1], &ldwork, &work[m * nrhs + 1], &result[3]); /* Test 5: Check norm of r'*A workspace: NRHS*(M+N) */ result[4] = 0.; if (m > crank) { result[4] = dqrt17_("No transpose", &c__1, &m, &n, &nrhs, ©a[1], &lda, &b[1], &ldb, & copyb[1], &ldb, &c__[1], &work[1], &lwork); } /* Test 6: Check if x is in the rowspace of A workspace: (M+NRHS)*(N+2) */ result[5] = 0.; if (n > crank) { result[5] = dqrt14_("No transpose", &m, &n, &nrhs, ©a[1], &lda, &b[1], &ldb, &work[1], & lwork); } /* Print information about the tests that did not pass the threshold. */ for (k = 3; k <= 6; ++k) { if (result[k - 1] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___40.ciunit = *nout; s_wsfe(&io___40); do_fio(&c__1, (char *)&m, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&n, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&nrhs, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&nb, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&itype, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&k, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&result[k - 1], (ftnlen) sizeof(doublereal)); e_wsfe(); ++nfail; } /* L60: */ } nrun += 4; /* Loop for testing different block sizes. */ i__4 = *nnb; for (inb = 1; inb <= i__4; ++inb) { nb = nbval[inb]; xlaenv_(&c__1, &nb); xlaenv_(&c__3, &nxval[inb]); /* Test DGELSY DGELSY: Compute the minimum-norm solution X to min( norm( A * X - B ) ) using the rank-revealing orthogonal factorization. Initialize vector IWORK. */ i__5 = n; for (j = 1; j <= i__5; ++j) { iwork[j] = 0; /* L70: */ } /* Set LWLSY to the adequate value. Computing MAX */ i__5 = 1, i__6 = mnmin + (n << 1) + nb * (n + 1), i__5 = max(i__5,i__6), i__6 = (mnmin << 1) + nb * nrhs; lwlsy = max(i__5,i__6); dlacpy_("Full", &m, &n, ©a[1], &lda, &a[1], & lda); dlacpy_("Full", &m, &nrhs, ©b[1], &ldb, &b[1], &ldb); s_copy(srnamc_1.srnamt, "DGELSY", (ftnlen)6, ( ftnlen)6); dgelsy_(&m, &n, &nrhs, &a[1], &lda, &b[1], &ldb, & iwork[1], &rcond, &crank, &work[1], & lwlsy, &info); if (info != 0) { alaerh_(path, "DGELSY", &info, &c__0, " ", &m, &n, &nrhs, &c_n1, &nb, &itype, & nfail, &nerrs, nout); } /* Test 7: Compute relative error in svd workspace: M*N + 4*MIN(M,N) + MAX(M,N) */ result[6] = dqrt12_(&crank, &crank, &a[1], &lda, & copys[1], &work[1], &lwork); /* Test 8: Compute error in solution workspace: M*NRHS + M */ dlacpy_("Full", &m, &nrhs, ©b[1], &ldb, &work[ 1], &ldwork); dqrt16_("No transpose", &m, &n, &nrhs, ©a[1], &lda, &b[1], &ldb, &work[1], &ldwork, & work[m * nrhs + 1], &result[7]); /* Test 9: Check norm of r'*A workspace: NRHS*(M+N) */ result[8] = 0.; if (m > crank) { result[8] = dqrt17_("No transpose", &c__1, &m, &n, &nrhs, ©a[1], &lda, &b[1], & ldb, ©b[1], &ldb, &c__[1], &work[ 1], &lwork); } /* Test 10: Check if x is in the rowspace of A workspace: (M+NRHS)*(N+2) */ result[9] = 0.; if (n > crank) { result[9] = dqrt14_("No transpose", &m, &n, & nrhs, ©a[1], &lda, &b[1], &ldb, & work[1], &lwork); } /* Test DGELSS DGELSS: Compute the minimum-norm solution X to min( norm( A * X - B ) ) using the SVD. */ dlacpy_("Full", &m, &n, ©a[1], &lda, &a[1], & lda); dlacpy_("Full", &m, &nrhs, ©b[1], &ldb, &b[1], &ldb); s_copy(srnamc_1.srnamt, "DGELSS", (ftnlen)6, ( ftnlen)6); dgelss_(&m, &n, &nrhs, &a[1], &lda, &b[1], &ldb, & s[1], &rcond, &crank, &work[1], &lwork, & info); if (info != 0) { alaerh_(path, "DGELSS", &info, &c__0, " ", &m, &n, &nrhs, &c_n1, &nb, &itype, & nfail, &nerrs, nout); } /* workspace used: 3*min(m,n) + max(2*min(m,n),nrhs,max(m,n)) Test 11: Compute relative error in svd */ if (rank > 0) { daxpy_(&mnmin, &c_b92, ©s[1], &c__1, &s[1] , &c__1); result[10] = dasum_(&mnmin, &s[1], &c__1) / dasum_(&mnmin, ©s[1], &c__1) / ( eps * (doublereal) mnmin); } else { result[10] = 0.; } /* Test 12: Compute error in solution */ dlacpy_("Full", &m, &nrhs, ©b[1], &ldb, &work[ 1], &ldwork); dqrt16_("No transpose", &m, &n, &nrhs, ©a[1], &lda, &b[1], &ldb, &work[1], &ldwork, & work[m * nrhs + 1], &result[11]); /* Test 13: Check norm of r'*A */ result[12] = 0.; if (m > crank) { result[12] = dqrt17_("No transpose", &c__1, & m, &n, &nrhs, ©a[1], &lda, &b[1], &ldb, ©b[1], &ldb, &c__[1], &work[ 1], &lwork); } /* Test 14: Check if x is in the rowspace of A */ result[13] = 0.; if (n > crank) { result[13] = dqrt14_("No transpose", &m, &n, & nrhs, ©a[1], &lda, &b[1], &ldb, & work[1], &lwork); } /* Test DGELSD DGELSD: Compute the minimum-norm solution X to min( norm( A * X - B ) ) using a divide and conquer SVD. Initialize vector IWORK. */ i__5 = n; for (j = 1; j <= i__5; ++j) { iwork[j] = 0; /* L80: */ } dlacpy_("Full", &m, &n, ©a[1], &lda, &a[1], & lda); dlacpy_("Full", &m, &nrhs, ©b[1], &ldb, &b[1], &ldb); s_copy(srnamc_1.srnamt, "DGELSD", (ftnlen)6, ( ftnlen)6); dgelsd_(&m, &n, &nrhs, &a[1], &lda, &b[1], &ldb, & s[1], &rcond, &crank, &work[1], &lwork, & iwork[1], &info); if (info != 0) { alaerh_(path, "DGELSD", &info, &c__0, " ", &m, &n, &nrhs, &c_n1, &nb, &itype, & nfail, &nerrs, nout); } /* Test 15: Compute relative error in svd */ if (rank > 0) { daxpy_(&mnmin, &c_b92, ©s[1], &c__1, &s[1] , &c__1); result[14] = dasum_(&mnmin, &s[1], &c__1) / dasum_(&mnmin, ©s[1], &c__1) / ( eps * (doublereal) mnmin); } else { result[14] = 0.; } /* Test 16: Compute error in solution */ dlacpy_("Full", &m, &nrhs, ©b[1], &ldb, &work[ 1], &ldwork); dqrt16_("No transpose", &m, &n, &nrhs, ©a[1], &lda, &b[1], &ldb, &work[1], &ldwork, & work[m * nrhs + 1], &result[15]); /* Test 17: Check norm of r'*A */ result[16] = 0.; if (m > crank) { result[16] = dqrt17_("No transpose", &c__1, & m, &n, &nrhs, ©a[1], &lda, &b[1], &ldb, ©b[1], &ldb, &c__[1], &work[ 1], &lwork); } /* Test 18: Check if x is in the rowspace of A */ result[17] = 0.; if (n > crank) { result[17] = dqrt14_("No transpose", &m, &n, & nrhs, ©a[1], &lda, &b[1], &ldb, & work[1], &lwork); } /* Print information about the tests that did not pass the threshold. */ for (k = 7; k <= 18; ++k) { if (result[k - 1] >= *thresh) { if (nfail == 0 && nerrs == 0) { alahd_(nout, path); } io___42.ciunit = *nout; s_wsfe(&io___42); do_fio(&c__1, (char *)&m, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&n, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&nrhs, (ftnlen) sizeof(integer)); do_fio(&c__1, (char *)&nb, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&itype, (ftnlen) sizeof(integer)); do_fio(&c__1, (char *)&k, (ftnlen)sizeof( integer)); do_fio(&c__1, (char *)&result[k - 1], ( ftnlen)sizeof(doublereal)); e_wsfe(); ++nfail; } /* L90: */ } nrun += 12; /* L100: */ } L110: ; } /* L120: */ } /* L130: */ } /* L140: */ } /* L150: */ } /* Print a summary of the results. */ alasvm_(path, nout, &nfail, &nrun, &nerrs); return 0; /* End of DDRVLS */ } /* ddrvls_ */