| 1 |
#include "clapack.h" |
| 2 |
#include "f2cP.h" |
| 3 |
|
| 4 |
/* Subroutine */ int dsbev_(const char *jobz, const char *uplo, integer *n, integer *kd, |
| 5 |
double *ab, integer *ldab, double *w, double *z__, |
| 6 |
integer *ldz, double *work, integer *info) |
| 7 |
{ |
| 8 |
/* Table of constant values */ |
| 9 |
static double c_b11 = 1.; |
| 10 |
static integer c__1 = 1; |
| 11 |
|
| 12 |
/* System generated locals */ |
| 13 |
integer ab_dim1, ab_offset, z_dim1, z_offset, i__1; |
| 14 |
double d__1; |
| 15 |
|
| 16 |
/* Local variables */ |
| 17 |
double eps; |
| 18 |
integer inde; |
| 19 |
double anrm; |
| 20 |
integer imax; |
| 21 |
double rmin, rmax; |
| 22 |
double sigma; |
| 23 |
integer iinfo; |
| 24 |
bool lower, wantz; |
| 25 |
integer iscale; |
| 26 |
double safmin; |
| 27 |
double bignum; |
| 28 |
integer indwrk; |
| 29 |
double smlnum; |
| 30 |
|
| 31 |
|
| 32 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 33 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 34 |
/* November 2006 */ |
| 35 |
|
| 36 |
/* .. Scalar Arguments .. */ |
| 37 |
/* .. */ |
| 38 |
/* .. Array Arguments .. */ |
| 39 |
/* .. */ |
| 40 |
|
| 41 |
/* Purpose */ |
| 42 |
/* ======= */ |
| 43 |
|
| 44 |
/* DSBEV computes all the eigenvalues and, optionally, eigenvectors of */ |
| 45 |
/* a real symmetric band matrix A. */ |
| 46 |
|
| 47 |
/* Arguments */ |
| 48 |
/* ========= */ |
| 49 |
|
| 50 |
/* JOBZ (input) CHARACTER*1 */ |
| 51 |
/* = 'N': Compute eigenvalues only; */ |
| 52 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 53 |
|
| 54 |
/* UPLO (input) CHARACTER*1 */ |
| 55 |
/* = 'U': Upper triangle of A is stored; */ |
| 56 |
/* = 'L': Lower triangle of A is stored. */ |
| 57 |
|
| 58 |
/* N (input) INTEGER */ |
| 59 |
/* The order of the matrix A. N >= 0. */ |
| 60 |
|
| 61 |
/* KD (input) INTEGER */ |
| 62 |
/* The number of superdiagonals of the matrix A if UPLO = 'U', */ |
| 63 |
/* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */ |
| 64 |
|
| 65 |
/* AB (input/output) DOUBLE PRECISION array, dimension (LDAB, N) */ |
| 66 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 67 |
/* matrix A, stored in the first KD+1 rows of the array. The */ |
| 68 |
/* j-th column of A is stored in the j-th column of the array AB */ |
| 69 |
/* as follows: */ |
| 70 |
/* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */ |
| 71 |
/* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */ |
| 72 |
|
| 73 |
/* On exit, AB is overwritten by values generated during the */ |
| 74 |
/* reduction to tridiagonal form. If UPLO = 'U', the first */ |
| 75 |
/* superdiagonal and the diagonal of the tridiagonal matrix T */ |
| 76 |
/* are returned in rows KD and KD+1 of AB, and if UPLO = 'L', */ |
| 77 |
/* the diagonal and first subdiagonal of T are returned in the */ |
| 78 |
/* first two rows of AB. */ |
| 79 |
|
| 80 |
/* LDAB (input) INTEGER */ |
| 81 |
/* The leading dimension of the array AB. LDAB >= KD + 1. */ |
| 82 |
|
| 83 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 84 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 85 |
|
| 86 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 87 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */ |
| 88 |
/* eigenvectors of the matrix A, with the i-th column of Z */ |
| 89 |
/* holding the eigenvector associated with W(i). */ |
| 90 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 91 |
|
| 92 |
/* LDZ (input) INTEGER */ |
| 93 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 94 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 95 |
|
| 96 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (max(1,3*N-2)) */ |
| 97 |
|
| 98 |
/* INFO (output) INTEGER */ |
| 99 |
/* = 0: successful exit */ |
| 100 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 101 |
/* > 0: if INFO = i, the algorithm failed to converge; i */ |
| 102 |
/* off-diagonal elements of an intermediate tridiagonal */ |
| 103 |
/* form did not converge to zero. */ |
| 104 |
|
| 105 |
/* ===================================================================== */ |
| 106 |
|
| 107 |
/* .. Parameters .. */ |
| 108 |
/* .. */ |
| 109 |
/* .. Local Scalars .. */ |
| 110 |
/* .. */ |
| 111 |
/* .. External Functions .. */ |
| 112 |
/* .. */ |
| 113 |
/* .. External Subroutines .. */ |
| 114 |
/* .. */ |
| 115 |
/* .. Intrinsic Functions .. */ |
| 116 |
/* .. */ |
| 117 |
/* .. Executable Statements .. */ |
| 118 |
|
| 119 |
/* Test the input parameters. */ |
| 120 |
|
| 121 |
/* Parameter adjustments */ |
| 122 |
ab_dim1 = *ldab; |
| 123 |
ab_offset = 1 + ab_dim1; |
| 124 |
ab -= ab_offset; |
| 125 |
--w; |
| 126 |
z_dim1 = *ldz; |
| 127 |
z_offset = 1 + z_dim1; |
| 128 |
z__ -= z_offset; |
| 129 |
--work; |
| 130 |
|
| 131 |
/* Function Body */ |
| 132 |
wantz = lsame_(jobz, "V"); |
| 133 |
lower = lsame_(uplo, "L"); |
| 134 |
|
| 135 |
*info = 0; |
| 136 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 137 |
*info = -1; |
| 138 |
} else if (! (lower || lsame_(uplo, "U"))) { |
| 139 |
*info = -2; |
| 140 |
} else if (*n < 0) { |
| 141 |
*info = -3; |
| 142 |
} else if (*kd < 0) { |
| 143 |
*info = -4; |
| 144 |
} else if (*ldab < *kd + 1) { |
| 145 |
*info = -6; |
| 146 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 147 |
*info = -9; |
| 148 |
} |
| 149 |
|
| 150 |
if (*info != 0) { |
| 151 |
i__1 = -(*info); |
| 152 |
xerbla_("DSBEV ", &i__1); |
| 153 |
return 0; |
| 154 |
} |
| 155 |
|
| 156 |
/* Quick return if possible */ |
| 157 |
|
| 158 |
if (*n == 0) { |
| 159 |
return 0; |
| 160 |
} |
| 161 |
|
| 162 |
if (*n == 1) { |
| 163 |
if (lower) { |
| 164 |
w[1] = ab[ab_dim1 + 1]; |
| 165 |
} else { |
| 166 |
w[1] = ab[*kd + 1 + ab_dim1]; |
| 167 |
} |
| 168 |
if (wantz) { |
| 169 |
z__[z_dim1 + 1] = 1.; |
| 170 |
} |
| 171 |
return 0; |
| 172 |
} |
| 173 |
|
| 174 |
/* Get machine constants. */ |
| 175 |
|
| 176 |
safmin = dlamch_("Safe minimum"); |
| 177 |
eps = dlamch_("Precision"); |
| 178 |
smlnum = safmin / eps; |
| 179 |
bignum = 1. / smlnum; |
| 180 |
rmin = sqrt(smlnum); |
| 181 |
rmax = sqrt(bignum); |
| 182 |
|
| 183 |
/* Scale matrix to allowable range, if necessary. */ |
| 184 |
|
| 185 |
anrm = dlansb_("M", uplo, n, kd, &ab[ab_offset], ldab, &work[1]); |
| 186 |
iscale = 0; |
| 187 |
if (anrm > 0. && anrm < rmin) { |
| 188 |
iscale = 1; |
| 189 |
sigma = rmin / anrm; |
| 190 |
} else if (anrm > rmax) { |
| 191 |
iscale = 1; |
| 192 |
sigma = rmax / anrm; |
| 193 |
} |
| 194 |
if (iscale == 1) { |
| 195 |
if (lower) { |
| 196 |
dlascl_("B", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab, |
| 197 |
info); |
| 198 |
} else { |
| 199 |
dlascl_("Q", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab, |
| 200 |
info); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
/* Call DSBTRD to reduce symmetric band matrix to tridiagonal form. */ |
| 205 |
|
| 206 |
inde = 1; |
| 207 |
indwrk = inde + *n; |
| 208 |
dsbtrd_(jobz, uplo, n, kd, &ab[ab_offset], ldab, &w[1], &work[inde], &z__[ |
| 209 |
z_offset], ldz, &work[indwrk], &iinfo); |
| 210 |
|
| 211 |
/* For eigenvalues only, call DSTERF. For eigenvectors, call SSTEQR. */ |
| 212 |
|
| 213 |
if (! wantz) { |
| 214 |
dsterf_(n, &w[1], &work[inde], info); |
| 215 |
} else { |
| 216 |
dsteqr_(jobz, n, &w[1], &work[inde], &z__[z_offset], ldz, &work[ |
| 217 |
indwrk], info); |
| 218 |
} |
| 219 |
|
| 220 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 221 |
|
| 222 |
if (iscale == 1) { |
| 223 |
if (*info == 0) { |
| 224 |
imax = *n; |
| 225 |
} else { |
| 226 |
imax = *info - 1; |
| 227 |
} |
| 228 |
d__1 = 1. / sigma; |
| 229 |
dscal_(&imax, &d__1, &w[1], &c__1); |
| 230 |
} |
| 231 |
|
| 232 |
return 0; |
| 233 |
|
| 234 |
/* End of DSBEV */ |
| 235 |
|
| 236 |
} /* dsbev_ */ |
| 237 |
|
| 238 |
/* Subroutine */ int dsbevd_(const char *jobz, const char *uplo, integer *n, integer *kd, |
| 239 |
double *ab, integer *ldab, double *w, double *z__, |
| 240 |
integer *ldz, double *work, integer *lwork, integer *iwork, |
| 241 |
integer *liwork, integer *info) |
| 242 |
{ |
| 243 |
/* Table of constant values */ |
| 244 |
static double c_b11 = 1.; |
| 245 |
static double c_b18 = 0.; |
| 246 |
static integer c__1 = 1; |
| 247 |
|
| 248 |
/* System generated locals */ |
| 249 |
integer ab_dim1, ab_offset, z_dim1, z_offset, i__1; |
| 250 |
double d__1; |
| 251 |
|
| 252 |
/* Local variables */ |
| 253 |
double eps; |
| 254 |
integer inde; |
| 255 |
double anrm, rmin, rmax; |
| 256 |
double sigma; |
| 257 |
integer iinfo, lwmin; |
| 258 |
bool lower, wantz; |
| 259 |
integer indwk2, llwrk2; |
| 260 |
integer iscale; |
| 261 |
double safmin; |
| 262 |
double bignum; |
| 263 |
integer indwrk, liwmin; |
| 264 |
double smlnum; |
| 265 |
bool lquery; |
| 266 |
|
| 267 |
|
| 268 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 269 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 270 |
/* November 2006 */ |
| 271 |
|
| 272 |
/* .. Scalar Arguments .. */ |
| 273 |
/* .. */ |
| 274 |
/* .. Array Arguments .. */ |
| 275 |
/* .. */ |
| 276 |
|
| 277 |
/* Purpose */ |
| 278 |
/* ======= */ |
| 279 |
|
| 280 |
/* DSBEVD computes all the eigenvalues and, optionally, eigenvectors of */ |
| 281 |
/* a real symmetric band matrix A. If eigenvectors are desired, it uses */ |
| 282 |
/* a divide and conquer algorithm. */ |
| 283 |
|
| 284 |
/* The divide and conquer algorithm makes very mild assumptions about */ |
| 285 |
/* floating point arithmetic. It will work on machines with a guard */ |
| 286 |
/* digit in add/subtract, or on those binary machines without guard */ |
| 287 |
/* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ |
| 288 |
/* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ |
| 289 |
/* without guard digits, but we know of none. */ |
| 290 |
|
| 291 |
/* Arguments */ |
| 292 |
/* ========= */ |
| 293 |
|
| 294 |
/* JOBZ (input) CHARACTER*1 */ |
| 295 |
/* = 'N': Compute eigenvalues only; */ |
| 296 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 297 |
|
| 298 |
/* UPLO (input) CHARACTER*1 */ |
| 299 |
/* = 'U': Upper triangle of A is stored; */ |
| 300 |
/* = 'L': Lower triangle of A is stored. */ |
| 301 |
|
| 302 |
/* N (input) INTEGER */ |
| 303 |
/* The order of the matrix A. N >= 0. */ |
| 304 |
|
| 305 |
/* KD (input) INTEGER */ |
| 306 |
/* The number of superdiagonals of the matrix A if UPLO = 'U', */ |
| 307 |
/* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */ |
| 308 |
|
| 309 |
/* AB (input/output) DOUBLE PRECISION array, dimension (LDAB, N) */ |
| 310 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 311 |
/* matrix A, stored in the first KD+1 rows of the array. The */ |
| 312 |
/* j-th column of A is stored in the j-th column of the array AB */ |
| 313 |
/* as follows: */ |
| 314 |
/* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */ |
| 315 |
/* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */ |
| 316 |
|
| 317 |
/* On exit, AB is overwritten by values generated during the */ |
| 318 |
/* reduction to tridiagonal form. If UPLO = 'U', the first */ |
| 319 |
/* superdiagonal and the diagonal of the tridiagonal matrix T */ |
| 320 |
/* are returned in rows KD and KD+1 of AB, and if UPLO = 'L', */ |
| 321 |
/* the diagonal and first subdiagonal of T are returned in the */ |
| 322 |
/* first two rows of AB. */ |
| 323 |
|
| 324 |
/* LDAB (input) INTEGER */ |
| 325 |
/* The leading dimension of the array AB. LDAB >= KD + 1. */ |
| 326 |
|
| 327 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 328 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 329 |
|
| 330 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 331 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */ |
| 332 |
/* eigenvectors of the matrix A, with the i-th column of Z */ |
| 333 |
/* holding the eigenvector associated with W(i). */ |
| 334 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 335 |
|
| 336 |
/* LDZ (input) INTEGER */ |
| 337 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 338 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 339 |
|
| 340 |
/* WORK (workspace/output) DOUBLE PRECISION array, */ |
| 341 |
/* dimension (LWORK) */ |
| 342 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 343 |
|
| 344 |
/* LWORK (input) INTEGER */ |
| 345 |
/* The dimension of the array WORK. */ |
| 346 |
/* IF N <= 1, LWORK must be at least 1. */ |
| 347 |
/* If JOBZ = 'N' and N > 2, LWORK must be at least 2*N. */ |
| 348 |
/* If JOBZ = 'V' and N > 2, LWORK must be at least */ |
| 349 |
/* ( 1 + 5*N + 2*N**2 ). */ |
| 350 |
|
| 351 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 352 |
/* only calculates the optimal sizes of the WORK and IWORK */ |
| 353 |
/* arrays, returns these values as the first entries of the WORK */ |
| 354 |
/* and IWORK arrays, and no error message related to LWORK or */ |
| 355 |
/* LIWORK is issued by XERBLA. */ |
| 356 |
|
| 357 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 358 |
/* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ |
| 359 |
|
| 360 |
/* LIWORK (input) INTEGER */ |
| 361 |
/* The dimension of the array LIWORK. */ |
| 362 |
/* If JOBZ = 'N' or N <= 1, LIWORK must be at least 1. */ |
| 363 |
/* If JOBZ = 'V' and N > 2, LIWORK must be at least 3 + 5*N. */ |
| 364 |
|
| 365 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 366 |
/* routine only calculates the optimal sizes of the WORK and */ |
| 367 |
/* IWORK arrays, returns these values as the first entries of */ |
| 368 |
/* the WORK and IWORK arrays, and no error message related to */ |
| 369 |
/* LWORK or LIWORK is issued by XERBLA. */ |
| 370 |
|
| 371 |
/* INFO (output) INTEGER */ |
| 372 |
/* = 0: successful exit */ |
| 373 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 374 |
/* > 0: if INFO = i, the algorithm failed to converge; i */ |
| 375 |
/* off-diagonal elements of an intermediate tridiagonal */ |
| 376 |
/* form did not converge to zero. */ |
| 377 |
|
| 378 |
/* ===================================================================== */ |
| 379 |
|
| 380 |
/* .. Parameters .. */ |
| 381 |
/* .. */ |
| 382 |
/* .. Local Scalars .. */ |
| 383 |
/* .. */ |
| 384 |
/* .. External Functions .. */ |
| 385 |
/* .. */ |
| 386 |
/* .. External Subroutines .. */ |
| 387 |
/* .. */ |
| 388 |
/* .. Intrinsic Functions .. */ |
| 389 |
/* .. */ |
| 390 |
/* .. Executable Statements .. */ |
| 391 |
|
| 392 |
/* Test the input parameters. */ |
| 393 |
|
| 394 |
/* Parameter adjustments */ |
| 395 |
ab_dim1 = *ldab; |
| 396 |
ab_offset = 1 + ab_dim1; |
| 397 |
ab -= ab_offset; |
| 398 |
--w; |
| 399 |
z_dim1 = *ldz; |
| 400 |
z_offset = 1 + z_dim1; |
| 401 |
z__ -= z_offset; |
| 402 |
--work; |
| 403 |
--iwork; |
| 404 |
|
| 405 |
/* Function Body */ |
| 406 |
wantz = lsame_(jobz, "V"); |
| 407 |
lower = lsame_(uplo, "L"); |
| 408 |
lquery = *lwork == -1 || *liwork == -1; |
| 409 |
|
| 410 |
*info = 0; |
| 411 |
if (*n <= 1) { |
| 412 |
liwmin = 1; |
| 413 |
lwmin = 1; |
| 414 |
} else { |
| 415 |
if (wantz) { |
| 416 |
liwmin = *n * 5 + 3; |
| 417 |
/* Computing 2nd power */ |
| 418 |
i__1 = *n; |
| 419 |
lwmin = *n * 5 + 1 + (i__1 * i__1 << 1); |
| 420 |
} else { |
| 421 |
liwmin = 1; |
| 422 |
lwmin = *n << 1; |
| 423 |
} |
| 424 |
} |
| 425 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 426 |
*info = -1; |
| 427 |
} else if (! (lower || lsame_(uplo, "U"))) { |
| 428 |
*info = -2; |
| 429 |
} else if (*n < 0) { |
| 430 |
*info = -3; |
| 431 |
} else if (*kd < 0) { |
| 432 |
*info = -4; |
| 433 |
} else if (*ldab < *kd + 1) { |
| 434 |
*info = -6; |
| 435 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 436 |
*info = -9; |
| 437 |
} |
| 438 |
|
| 439 |
if (*info == 0) { |
| 440 |
work[1] = (double) lwmin; |
| 441 |
iwork[1] = liwmin; |
| 442 |
|
| 443 |
if (*lwork < lwmin && ! lquery) { |
| 444 |
*info = -11; |
| 445 |
} else if (*liwork < liwmin && ! lquery) { |
| 446 |
*info = -13; |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
if (*info != 0) { |
| 451 |
i__1 = -(*info); |
| 452 |
xerbla_("DSBEVD", &i__1); |
| 453 |
return 0; |
| 454 |
} else if (lquery) { |
| 455 |
return 0; |
| 456 |
} |
| 457 |
|
| 458 |
/* Quick return if possible */ |
| 459 |
|
| 460 |
if (*n == 0) { |
| 461 |
return 0; |
| 462 |
} |
| 463 |
|
| 464 |
if (*n == 1) { |
| 465 |
w[1] = ab[ab_dim1 + 1]; |
| 466 |
if (wantz) { |
| 467 |
z__[z_dim1 + 1] = 1.; |
| 468 |
} |
| 469 |
return 0; |
| 470 |
} |
| 471 |
|
| 472 |
/* Get machine constants. */ |
| 473 |
|
| 474 |
safmin = dlamch_("Safe minimum"); |
| 475 |
eps = dlamch_("Precision"); |
| 476 |
smlnum = safmin / eps; |
| 477 |
bignum = 1. / smlnum; |
| 478 |
rmin = sqrt(smlnum); |
| 479 |
rmax = sqrt(bignum); |
| 480 |
|
| 481 |
/* Scale matrix to allowable range, if necessary. */ |
| 482 |
|
| 483 |
anrm = dlansb_("M", uplo, n, kd, &ab[ab_offset], ldab, &work[1]); |
| 484 |
iscale = 0; |
| 485 |
if (anrm > 0. && anrm < rmin) { |
| 486 |
iscale = 1; |
| 487 |
sigma = rmin / anrm; |
| 488 |
} else if (anrm > rmax) { |
| 489 |
iscale = 1; |
| 490 |
sigma = rmax / anrm; |
| 491 |
} |
| 492 |
if (iscale == 1) { |
| 493 |
if (lower) { |
| 494 |
dlascl_("B", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab, |
| 495 |
info); |
| 496 |
} else { |
| 497 |
dlascl_("Q", kd, kd, &c_b11, &sigma, n, n, &ab[ab_offset], ldab, |
| 498 |
info); |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
/* Call DSBTRD to reduce symmetric band matrix to tridiagonal form. */ |
| 503 |
|
| 504 |
inde = 1; |
| 505 |
indwrk = inde + *n; |
| 506 |
indwk2 = indwrk + *n * *n; |
| 507 |
llwrk2 = *lwork - indwk2 + 1; |
| 508 |
dsbtrd_(jobz, uplo, n, kd, &ab[ab_offset], ldab, &w[1], &work[inde], &z__[ |
| 509 |
z_offset], ldz, &work[indwrk], &iinfo); |
| 510 |
|
| 511 |
/* For eigenvalues only, call DSTERF. For eigenvectors, call SSTEDC. */ |
| 512 |
|
| 513 |
if (! wantz) { |
| 514 |
dsterf_(n, &w[1], &work[inde], info); |
| 515 |
} else { |
| 516 |
dstedc_("I", n, &w[1], &work[inde], &work[indwrk], n, &work[indwk2], & |
| 517 |
llwrk2, &iwork[1], liwork, info); |
| 518 |
dgemm_("N", "N", n, n, n, &c_b11, &z__[z_offset], ldz, &work[indwrk], |
| 519 |
n, &c_b18, &work[indwk2], n); |
| 520 |
dlacpy_("A", n, n, &work[indwk2], n, &z__[z_offset], ldz); |
| 521 |
} |
| 522 |
|
| 523 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 524 |
|
| 525 |
if (iscale == 1) { |
| 526 |
d__1 = 1. / sigma; |
| 527 |
dscal_(n, &d__1, &w[1], &c__1); |
| 528 |
} |
| 529 |
|
| 530 |
work[1] = (double) lwmin; |
| 531 |
iwork[1] = liwmin; |
| 532 |
return 0; |
| 533 |
|
| 534 |
/* End of DSBEVD */ |
| 535 |
|
| 536 |
} /* dsbevd_ */ |
| 537 |
|
| 538 |
/* Subroutine */ int dsbevx_(const char *jobz, const char *range, const char *uplo, integer *n, |
| 539 |
integer *kd, double *ab, integer *ldab, double *q, integer * |
| 540 |
ldq, double *vl, double *vu, integer *il, integer *iu, |
| 541 |
double *abstol, integer *m, double *w, double *z__, |
| 542 |
integer *ldz, double *work, integer *iwork, integer *ifail, |
| 543 |
integer *info) |
| 544 |
{ |
| 545 |
/* Table of constant values */ |
| 546 |
static double c_b14 = 1.; |
| 547 |
static integer c__1 = 1; |
| 548 |
static double c_b34 = 0.; |
| 549 |
|
| 550 |
/* System generated locals */ |
| 551 |
integer ab_dim1, ab_offset, q_dim1, q_offset, z_dim1, z_offset, i__1, |
| 552 |
i__2; |
| 553 |
double d__1, d__2; |
| 554 |
|
| 555 |
/* Local variables */ |
| 556 |
integer i__, j, jj; |
| 557 |
double eps, vll, vuu, tmp1; |
| 558 |
integer indd, inde; |
| 559 |
double anrm; |
| 560 |
integer imax; |
| 561 |
double rmin, rmax; |
| 562 |
bool test; |
| 563 |
integer itmp1, indee; |
| 564 |
double sigma; |
| 565 |
integer iinfo; |
| 566 |
char order[1]; |
| 567 |
bool lower, wantz; |
| 568 |
bool alleig, indeig; |
| 569 |
integer iscale, indibl; |
| 570 |
bool valeig; |
| 571 |
double safmin; |
| 572 |
double abstll, bignum; |
| 573 |
integer indisp; |
| 574 |
integer indiwo; |
| 575 |
integer indwrk; |
| 576 |
integer nsplit; |
| 577 |
double smlnum; |
| 578 |
|
| 579 |
|
| 580 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 581 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 582 |
/* November 2006 */ |
| 583 |
|
| 584 |
/* .. Scalar Arguments .. */ |
| 585 |
/* .. */ |
| 586 |
/* .. Array Arguments .. */ |
| 587 |
/* .. */ |
| 588 |
|
| 589 |
/* Purpose */ |
| 590 |
/* ======= */ |
| 591 |
|
| 592 |
/* DSBEVX computes selected eigenvalues and, optionally, eigenvectors */ |
| 593 |
/* of a real symmetric band matrix A. Eigenvalues and eigenvectors can */ |
| 594 |
/* be selected by specifying either a range of values or a range of */ |
| 595 |
/* indices for the desired eigenvalues. */ |
| 596 |
|
| 597 |
/* Arguments */ |
| 598 |
/* ========= */ |
| 599 |
|
| 600 |
/* JOBZ (input) CHARACTER*1 */ |
| 601 |
/* = 'N': Compute eigenvalues only; */ |
| 602 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 603 |
|
| 604 |
/* RANGE (input) CHARACTER*1 */ |
| 605 |
/* = 'A': all eigenvalues will be found; */ |
| 606 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 607 |
/* will be found; */ |
| 608 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 609 |
|
| 610 |
/* UPLO (input) CHARACTER*1 */ |
| 611 |
/* = 'U': Upper triangle of A is stored; */ |
| 612 |
/* = 'L': Lower triangle of A is stored. */ |
| 613 |
|
| 614 |
/* N (input) INTEGER */ |
| 615 |
/* The order of the matrix A. N >= 0. */ |
| 616 |
|
| 617 |
/* KD (input) INTEGER */ |
| 618 |
/* The number of superdiagonals of the matrix A if UPLO = 'U', */ |
| 619 |
/* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */ |
| 620 |
|
| 621 |
/* AB (input/output) DOUBLE PRECISION array, dimension (LDAB, N) */ |
| 622 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 623 |
/* matrix A, stored in the first KD+1 rows of the array. The */ |
| 624 |
/* j-th column of A is stored in the j-th column of the array AB */ |
| 625 |
/* as follows: */ |
| 626 |
/* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */ |
| 627 |
/* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */ |
| 628 |
|
| 629 |
/* On exit, AB is overwritten by values generated during the */ |
| 630 |
/* reduction to tridiagonal form. If UPLO = 'U', the first */ |
| 631 |
/* superdiagonal and the diagonal of the tridiagonal matrix T */ |
| 632 |
/* are returned in rows KD and KD+1 of AB, and if UPLO = 'L', */ |
| 633 |
/* the diagonal and first subdiagonal of T are returned in the */ |
| 634 |
/* first two rows of AB. */ |
| 635 |
|
| 636 |
/* LDAB (input) INTEGER */ |
| 637 |
/* The leading dimension of the array AB. LDAB >= KD + 1. */ |
| 638 |
|
| 639 |
/* Q (output) DOUBLE PRECISION array, dimension (LDQ, N) */ |
| 640 |
/* If JOBZ = 'V', the N-by-N orthogonal matrix used in the */ |
| 641 |
/* reduction to tridiagonal form. */ |
| 642 |
/* If JOBZ = 'N', the array Q is not referenced. */ |
| 643 |
|
| 644 |
/* LDQ (input) INTEGER */ |
| 645 |
/* The leading dimension of the array Q. If JOBZ = 'V', then */ |
| 646 |
/* LDQ >= max(1,N). */ |
| 647 |
|
| 648 |
/* VL (input) DOUBLE PRECISION */ |
| 649 |
/* VU (input) DOUBLE PRECISION */ |
| 650 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 651 |
/* be searched for eigenvalues. VL < VU. */ |
| 652 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 653 |
|
| 654 |
/* IL (input) INTEGER */ |
| 655 |
/* IU (input) INTEGER */ |
| 656 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 657 |
/* smallest and largest eigenvalues to be returned. */ |
| 658 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 659 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 660 |
|
| 661 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 662 |
/* The absolute error tolerance for the eigenvalues. */ |
| 663 |
/* An approximate eigenvalue is accepted as converged */ |
| 664 |
/* when it is determined to lie in an interval [a,b] */ |
| 665 |
/* of width less than or equal to */ |
| 666 |
|
| 667 |
/* ABSTOL + EPS * max( |a|,|b| ) , */ |
| 668 |
|
| 669 |
/* where EPS is the machine precision. If ABSTOL is less than */ |
| 670 |
/* or equal to zero, then EPS*|T| will be used in its place, */ |
| 671 |
/* where |T| is the 1-norm of the tridiagonal matrix obtained */ |
| 672 |
/* by reducing AB to tridiagonal form. */ |
| 673 |
|
| 674 |
/* Eigenvalues will be computed most accurately when ABSTOL is */ |
| 675 |
/* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */ |
| 676 |
/* If this routine returns with INFO>0, indicating that some */ |
| 677 |
/* eigenvectors did not converge, try setting ABSTOL to */ |
| 678 |
/* 2*DLAMCH('S'). */ |
| 679 |
|
| 680 |
/* See "Computing Small Singular Values of Bidiagonal Matrices */ |
| 681 |
/* with Guaranteed High Relative Accuracy," by Demmel and */ |
| 682 |
/* Kahan, LAPACK Working Note #3. */ |
| 683 |
|
| 684 |
/* M (output) INTEGER */ |
| 685 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 686 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 687 |
|
| 688 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 689 |
/* The first M elements contain the selected eigenvalues in */ |
| 690 |
/* ascending order. */ |
| 691 |
|
| 692 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */ |
| 693 |
/* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ |
| 694 |
/* contain the orthonormal eigenvectors of the matrix A */ |
| 695 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 696 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 697 |
/* If an eigenvector fails to converge, then that column of Z */ |
| 698 |
/* contains the latest approximation to the eigenvector, and the */ |
| 699 |
/* index of the eigenvector is returned in IFAIL. */ |
| 700 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 701 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 702 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 703 |
/* is not known in advance and an upper bound must be used. */ |
| 704 |
|
| 705 |
/* LDZ (input) INTEGER */ |
| 706 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 707 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 708 |
|
| 709 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (7*N) */ |
| 710 |
|
| 711 |
/* IWORK (workspace) INTEGER array, dimension (5*N) */ |
| 712 |
|
| 713 |
/* IFAIL (output) INTEGER array, dimension (N) */ |
| 714 |
/* If JOBZ = 'V', then if INFO = 0, the first M elements of */ |
| 715 |
/* IFAIL are zero. If INFO > 0, then IFAIL contains the */ |
| 716 |
/* indices of the eigenvectors that failed to converge. */ |
| 717 |
/* If JOBZ = 'N', then IFAIL is not referenced. */ |
| 718 |
|
| 719 |
/* INFO (output) INTEGER */ |
| 720 |
/* = 0: successful exit. */ |
| 721 |
/* < 0: if INFO = -i, the i-th argument had an illegal value. */ |
| 722 |
/* > 0: if INFO = i, then i eigenvectors failed to converge. */ |
| 723 |
/* Their indices are stored in array IFAIL. */ |
| 724 |
|
| 725 |
/* ===================================================================== */ |
| 726 |
|
| 727 |
/* .. Parameters .. */ |
| 728 |
/* .. */ |
| 729 |
/* .. Local Scalars .. */ |
| 730 |
/* .. */ |
| 731 |
/* .. External Functions .. */ |
| 732 |
/* .. */ |
| 733 |
/* .. External Subroutines .. */ |
| 734 |
/* .. */ |
| 735 |
/* .. Intrinsic Functions .. */ |
| 736 |
/* .. */ |
| 737 |
/* .. Executable Statements .. */ |
| 738 |
|
| 739 |
/* Test the input parameters. */ |
| 740 |
|
| 741 |
/* Parameter adjustments */ |
| 742 |
ab_dim1 = *ldab; |
| 743 |
ab_offset = 1 + ab_dim1; |
| 744 |
ab -= ab_offset; |
| 745 |
q_dim1 = *ldq; |
| 746 |
q_offset = 1 + q_dim1; |
| 747 |
q -= q_offset; |
| 748 |
--w; |
| 749 |
z_dim1 = *ldz; |
| 750 |
z_offset = 1 + z_dim1; |
| 751 |
z__ -= z_offset; |
| 752 |
--work; |
| 753 |
--iwork; |
| 754 |
--ifail; |
| 755 |
|
| 756 |
/* Function Body */ |
| 757 |
wantz = lsame_(jobz, "V"); |
| 758 |
alleig = lsame_(range, "A"); |
| 759 |
valeig = lsame_(range, "V"); |
| 760 |
indeig = lsame_(range, "I"); |
| 761 |
lower = lsame_(uplo, "L"); |
| 762 |
|
| 763 |
*info = 0; |
| 764 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 765 |
*info = -1; |
| 766 |
} else if (! (alleig || valeig || indeig)) { |
| 767 |
*info = -2; |
| 768 |
} else if (! (lower || lsame_(uplo, "U"))) { |
| 769 |
*info = -3; |
| 770 |
} else if (*n < 0) { |
| 771 |
*info = -4; |
| 772 |
} else if (*kd < 0) { |
| 773 |
*info = -5; |
| 774 |
} else if (*ldab < *kd + 1) { |
| 775 |
*info = -7; |
| 776 |
} else if (wantz && *ldq < std::max(1_integer,*n)) { |
| 777 |
*info = -9; |
| 778 |
} else { |
| 779 |
if (valeig) { |
| 780 |
if (*n > 0 && *vu <= *vl) { |
| 781 |
*info = -11; |
| 782 |
} |
| 783 |
} else if (indeig) { |
| 784 |
if (*il < 1 || *il > std::max(1_integer,*n)) { |
| 785 |
*info = -12; |
| 786 |
} else if (*iu < std::min(*n,*il) || *iu > *n) { |
| 787 |
*info = -13; |
| 788 |
} |
| 789 |
} |
| 790 |
} |
| 791 |
if (*info == 0) { |
| 792 |
if (*ldz < 1 || wantz && *ldz < *n) { |
| 793 |
*info = -18; |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
if (*info != 0) { |
| 798 |
i__1 = -(*info); |
| 799 |
xerbla_("DSBEVX", &i__1); |
| 800 |
return 0; |
| 801 |
} |
| 802 |
|
| 803 |
/* Quick return if possible */ |
| 804 |
|
| 805 |
*m = 0; |
| 806 |
if (*n == 0) { |
| 807 |
return 0; |
| 808 |
} |
| 809 |
|
| 810 |
if (*n == 1) { |
| 811 |
*m = 1; |
| 812 |
if (lower) { |
| 813 |
tmp1 = ab[ab_dim1 + 1]; |
| 814 |
} else { |
| 815 |
tmp1 = ab[*kd + 1 + ab_dim1]; |
| 816 |
} |
| 817 |
if (valeig) { |
| 818 |
if (! (*vl < tmp1 && *vu >= tmp1)) { |
| 819 |
*m = 0; |
| 820 |
} |
| 821 |
} |
| 822 |
if (*m == 1) { |
| 823 |
w[1] = tmp1; |
| 824 |
if (wantz) { |
| 825 |
z__[z_dim1 + 1] = 1.; |
| 826 |
} |
| 827 |
} |
| 828 |
return 0; |
| 829 |
} |
| 830 |
|
| 831 |
/* Get machine constants. */ |
| 832 |
|
| 833 |
safmin = dlamch_("Safe minimum"); |
| 834 |
eps = dlamch_("Precision"); |
| 835 |
smlnum = safmin / eps; |
| 836 |
bignum = 1. / smlnum; |
| 837 |
rmin = sqrt(smlnum); |
| 838 |
/* Computing MIN */ |
| 839 |
d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin)); |
| 840 |
rmax = std::min(d__1,d__2); |
| 841 |
|
| 842 |
/* Scale matrix to allowable range, if necessary. */ |
| 843 |
|
| 844 |
iscale = 0; |
| 845 |
abstll = *abstol; |
| 846 |
if (valeig) { |
| 847 |
vll = *vl; |
| 848 |
vuu = *vu; |
| 849 |
} else { |
| 850 |
vll = 0.; |
| 851 |
vuu = 0.; |
| 852 |
} |
| 853 |
anrm = dlansb_("M", uplo, n, kd, &ab[ab_offset], ldab, &work[1]); |
| 854 |
if (anrm > 0. && anrm < rmin) { |
| 855 |
iscale = 1; |
| 856 |
sigma = rmin / anrm; |
| 857 |
} else if (anrm > rmax) { |
| 858 |
iscale = 1; |
| 859 |
sigma = rmax / anrm; |
| 860 |
} |
| 861 |
if (iscale == 1) { |
| 862 |
if (lower) { |
| 863 |
dlascl_("B", kd, kd, &c_b14, &sigma, n, n, &ab[ab_offset], ldab, |
| 864 |
info); |
| 865 |
} else { |
| 866 |
dlascl_("Q", kd, kd, &c_b14, &sigma, n, n, &ab[ab_offset], ldab, |
| 867 |
info); |
| 868 |
} |
| 869 |
if (*abstol > 0.) { |
| 870 |
abstll = *abstol * sigma; |
| 871 |
} |
| 872 |
if (valeig) { |
| 873 |
vll = *vl * sigma; |
| 874 |
vuu = *vu * sigma; |
| 875 |
} |
| 876 |
} |
| 877 |
|
| 878 |
/* Call DSBTRD to reduce symmetric band matrix to tridiagonal form. */ |
| 879 |
|
| 880 |
indd = 1; |
| 881 |
inde = indd + *n; |
| 882 |
indwrk = inde + *n; |
| 883 |
dsbtrd_(jobz, uplo, n, kd, &ab[ab_offset], ldab, &work[indd], &work[inde], |
| 884 |
&q[q_offset], ldq, &work[indwrk], &iinfo); |
| 885 |
|
| 886 |
/* If all eigenvalues are desired and ABSTOL is less than or equal */ |
| 887 |
/* to zero, then call DSTERF or SSTEQR. If this fails for some */ |
| 888 |
/* eigenvalue, then try DSTEBZ. */ |
| 889 |
|
| 890 |
test = false; |
| 891 |
if (indeig) { |
| 892 |
if (*il == 1 && *iu == *n) { |
| 893 |
test = true; |
| 894 |
} |
| 895 |
} |
| 896 |
if ((alleig || test) && *abstol <= 0.) { |
| 897 |
dcopy_(n, &work[indd], &c__1, &w[1], &c__1); |
| 898 |
indee = indwrk + (*n << 1); |
| 899 |
if (! wantz) { |
| 900 |
i__1 = *n - 1; |
| 901 |
dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); |
| 902 |
dsterf_(n, &w[1], &work[indee], info); |
| 903 |
} else { |
| 904 |
dlacpy_("A", n, n, &q[q_offset], ldq, &z__[z_offset], ldz); |
| 905 |
i__1 = *n - 1; |
| 906 |
dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); |
| 907 |
dsteqr_(jobz, n, &w[1], &work[indee], &z__[z_offset], ldz, &work[ |
| 908 |
indwrk], info); |
| 909 |
if (*info == 0) { |
| 910 |
i__1 = *n; |
| 911 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 912 |
ifail[i__] = 0; |
| 913 |
/* L10: */ |
| 914 |
} |
| 915 |
} |
| 916 |
} |
| 917 |
if (*info == 0) { |
| 918 |
*m = *n; |
| 919 |
goto L30; |
| 920 |
} |
| 921 |
*info = 0; |
| 922 |
} |
| 923 |
|
| 924 |
/* Otherwise, call DSTEBZ and, if eigenvectors are desired, SSTEIN. */ |
| 925 |
|
| 926 |
if (wantz) { |
| 927 |
*(unsigned char *)order = 'B'; |
| 928 |
} else { |
| 929 |
*(unsigned char *)order = 'E'; |
| 930 |
} |
| 931 |
indibl = 1; |
| 932 |
indisp = indibl + *n; |
| 933 |
indiwo = indisp + *n; |
| 934 |
dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[ |
| 935 |
inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[ |
| 936 |
indwrk], &iwork[indiwo], info); |
| 937 |
|
| 938 |
if (wantz) { |
| 939 |
dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[ |
| 940 |
indisp], &z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], & |
| 941 |
ifail[1], info); |
| 942 |
|
| 943 |
/* Apply orthogonal matrix used in reduction to tridiagonal */ |
| 944 |
/* form to eigenvectors returned by DSTEIN. */ |
| 945 |
|
| 946 |
i__1 = *m; |
| 947 |
for (j = 1; j <= i__1; ++j) { |
| 948 |
dcopy_(n, &z__[j * z_dim1 + 1], &c__1, &work[1], &c__1); |
| 949 |
dgemv_("N", n, n, &c_b14, &q[q_offset], ldq, &work[1], &c__1, & |
| 950 |
c_b34, &z__[j * z_dim1 + 1], &c__1); |
| 951 |
/* L20: */ |
| 952 |
} |
| 953 |
} |
| 954 |
|
| 955 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 956 |
|
| 957 |
L30: |
| 958 |
if (iscale == 1) { |
| 959 |
if (*info == 0) { |
| 960 |
imax = *m; |
| 961 |
} else { |
| 962 |
imax = *info - 1; |
| 963 |
} |
| 964 |
d__1 = 1. / sigma; |
| 965 |
dscal_(&imax, &d__1, &w[1], &c__1); |
| 966 |
} |
| 967 |
|
| 968 |
/* If eigenvalues are not in order, then sort them, along with */ |
| 969 |
/* eigenvectors. */ |
| 970 |
|
| 971 |
if (wantz) { |
| 972 |
i__1 = *m - 1; |
| 973 |
for (j = 1; j <= i__1; ++j) { |
| 974 |
i__ = 0; |
| 975 |
tmp1 = w[j]; |
| 976 |
i__2 = *m; |
| 977 |
for (jj = j + 1; jj <= i__2; ++jj) { |
| 978 |
if (w[jj] < tmp1) { |
| 979 |
i__ = jj; |
| 980 |
tmp1 = w[jj]; |
| 981 |
} |
| 982 |
/* L40: */ |
| 983 |
} |
| 984 |
|
| 985 |
if (i__ != 0) { |
| 986 |
itmp1 = iwork[indibl + i__ - 1]; |
| 987 |
w[i__] = w[j]; |
| 988 |
iwork[indibl + i__ - 1] = iwork[indibl + j - 1]; |
| 989 |
w[j] = tmp1; |
| 990 |
iwork[indibl + j - 1] = itmp1; |
| 991 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], |
| 992 |
&c__1); |
| 993 |
if (*info != 0) { |
| 994 |
itmp1 = ifail[i__]; |
| 995 |
ifail[i__] = ifail[j]; |
| 996 |
ifail[j] = itmp1; |
| 997 |
} |
| 998 |
} |
| 999 |
/* L50: */ |
| 1000 |
} |
| 1001 |
} |
| 1002 |
|
| 1003 |
return 0; |
| 1004 |
|
| 1005 |
/* End of DSBEVX */ |
| 1006 |
|
| 1007 |
} /* dsbevx_ */ |
| 1008 |
|
| 1009 |
/* Subroutine */ int dsbgst_(const char *vect, const char *uplo, integer *n, integer *ka, |
| 1010 |
integer *kb, double *ab, integer *ldab, double *bb, integer * |
| 1011 |
ldbb, double *x, integer *ldx, double *work, integer *info) |
| 1012 |
{ |
| 1013 |
/* Table of constant values */ |
| 1014 |
static double c_b8 = 0.; |
| 1015 |
static double c_b9 = 1.; |
| 1016 |
static integer c__1 = 1; |
| 1017 |
static double c_b20 = -1.; |
| 1018 |
|
| 1019 |
/* System generated locals */ |
| 1020 |
integer ab_dim1, ab_offset, bb_dim1, bb_offset, x_dim1, x_offset, i__1, |
| 1021 |
i__2, i__3, i__4; |
| 1022 |
double d__1; |
| 1023 |
|
| 1024 |
/* Local variables */ |
| 1025 |
integer i__, j, k, l, m; |
| 1026 |
double t; |
| 1027 |
integer i0, i1, i2, j1, j2; |
| 1028 |
double ra; |
| 1029 |
integer nr, nx, ka1, kb1; |
| 1030 |
double ra1; |
| 1031 |
integer j1t, j2t; |
| 1032 |
double bii; |
| 1033 |
integer kbt, nrt, inca; |
| 1034 |
bool upper, wantx; |
| 1035 |
bool update; |
| 1036 |
|
| 1037 |
|
| 1038 |
/* -- LAPACK routine (version 3.1) -- */ |
| 1039 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 1040 |
/* November 2006 */ |
| 1041 |
|
| 1042 |
/* .. Scalar Arguments .. */ |
| 1043 |
/* .. */ |
| 1044 |
/* .. Array Arguments .. */ |
| 1045 |
/* .. */ |
| 1046 |
|
| 1047 |
/* Purpose */ |
| 1048 |
/* ======= */ |
| 1049 |
|
| 1050 |
/* DSBGST reduces a real symmetric-definite banded generalized */ |
| 1051 |
/* eigenproblem A*x = lambda*B*x to standard form C*y = lambda*y, */ |
| 1052 |
/* such that C has the same bandwidth as A. */ |
| 1053 |
|
| 1054 |
/* B must have been previously factorized as S**T*S by DPBSTF, using a */ |
| 1055 |
/* split Cholesky factorization. A is overwritten by C = X**T*A*X, where */ |
| 1056 |
/* X = S**(-1)*Q and Q is an orthogonal matrix chosen to preserve the */ |
| 1057 |
/* bandwidth of A. */ |
| 1058 |
|
| 1059 |
/* Arguments */ |
| 1060 |
/* ========= */ |
| 1061 |
|
| 1062 |
/* VECT (input) CHARACTER*1 */ |
| 1063 |
/* = 'N': do not form the transformation matrix X; */ |
| 1064 |
/* = 'V': form X. */ |
| 1065 |
|
| 1066 |
/* UPLO (input) CHARACTER*1 */ |
| 1067 |
/* = 'U': Upper triangle of A is stored; */ |
| 1068 |
/* = 'L': Lower triangle of A is stored. */ |
| 1069 |
|
| 1070 |
/* N (input) INTEGER */ |
| 1071 |
/* The order of the matrices A and B. N >= 0. */ |
| 1072 |
|
| 1073 |
/* KA (input) INTEGER */ |
| 1074 |
/* The number of superdiagonals of the matrix A if UPLO = 'U', */ |
| 1075 |
/* or the number of subdiagonals if UPLO = 'L'. KA >= 0. */ |
| 1076 |
|
| 1077 |
/* KB (input) INTEGER */ |
| 1078 |
/* The number of superdiagonals of the matrix B if UPLO = 'U', */ |
| 1079 |
/* or the number of subdiagonals if UPLO = 'L'. KA >= KB >= 0. */ |
| 1080 |
|
| 1081 |
/* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */ |
| 1082 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 1083 |
/* matrix A, stored in the first ka+1 rows of the array. The */ |
| 1084 |
/* j-th column of A is stored in the j-th column of the array AB */ |
| 1085 |
/* as follows: */ |
| 1086 |
/* if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; */ |
| 1087 |
/* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+ka). */ |
| 1088 |
|
| 1089 |
/* On exit, the transformed matrix X**T*A*X, stored in the same */ |
| 1090 |
/* format as A. */ |
| 1091 |
|
| 1092 |
/* LDAB (input) INTEGER */ |
| 1093 |
/* The leading dimension of the array AB. LDAB >= KA+1. */ |
| 1094 |
|
| 1095 |
/* BB (input) DOUBLE PRECISION array, dimension (LDBB,N) */ |
| 1096 |
/* The banded factor S from the split Cholesky factorization of */ |
| 1097 |
/* B, as returned by DPBSTF, stored in the first KB+1 rows of */ |
| 1098 |
/* the array. */ |
| 1099 |
|
| 1100 |
/* LDBB (input) INTEGER */ |
| 1101 |
/* The leading dimension of the array BB. LDBB >= KB+1. */ |
| 1102 |
|
| 1103 |
/* X (output) DOUBLE PRECISION array, dimension (LDX,N) */ |
| 1104 |
/* If VECT = 'V', the n-by-n matrix X. */ |
| 1105 |
/* If VECT = 'N', the array X is not referenced. */ |
| 1106 |
|
| 1107 |
/* LDX (input) INTEGER */ |
| 1108 |
/* The leading dimension of the array X. */ |
| 1109 |
/* LDX >= max(1,N) if VECT = 'V'; LDX >= 1 otherwise. */ |
| 1110 |
|
| 1111 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */ |
| 1112 |
|
| 1113 |
/* INFO (output) INTEGER */ |
| 1114 |
/* = 0: successful exit */ |
| 1115 |
/* < 0: if INFO = -i, the i-th argument had an illegal value. */ |
| 1116 |
|
| 1117 |
/* ===================================================================== */ |
| 1118 |
|
| 1119 |
/* .. Parameters .. */ |
| 1120 |
/* .. */ |
| 1121 |
/* .. Local Scalars .. */ |
| 1122 |
/* .. */ |
| 1123 |
/* .. External Functions .. */ |
| 1124 |
/* .. */ |
| 1125 |
/* .. External Subroutines .. */ |
| 1126 |
/* .. */ |
| 1127 |
/* .. Intrinsic Functions .. */ |
| 1128 |
/* .. */ |
| 1129 |
/* .. Executable Statements .. */ |
| 1130 |
|
| 1131 |
/* Test the input parameters */ |
| 1132 |
|
| 1133 |
/* Parameter adjustments */ |
| 1134 |
ab_dim1 = *ldab; |
| 1135 |
ab_offset = 1 + ab_dim1; |
| 1136 |
ab -= ab_offset; |
| 1137 |
bb_dim1 = *ldbb; |
| 1138 |
bb_offset = 1 + bb_dim1; |
| 1139 |
bb -= bb_offset; |
| 1140 |
x_dim1 = *ldx; |
| 1141 |
x_offset = 1 + x_dim1; |
| 1142 |
x -= x_offset; |
| 1143 |
--work; |
| 1144 |
|
| 1145 |
/* Function Body */ |
| 1146 |
wantx = lsame_(vect, "V"); |
| 1147 |
upper = lsame_(uplo, "U"); |
| 1148 |
ka1 = *ka + 1; |
| 1149 |
kb1 = *kb + 1; |
| 1150 |
*info = 0; |
| 1151 |
if (! wantx && ! lsame_(vect, "N")) { |
| 1152 |
*info = -1; |
| 1153 |
} else if (! upper && ! lsame_(uplo, "L")) { |
| 1154 |
*info = -2; |
| 1155 |
} else if (*n < 0) { |
| 1156 |
*info = -3; |
| 1157 |
} else if (*ka < 0) { |
| 1158 |
*info = -4; |
| 1159 |
} else if (*kb < 0 || *kb > *ka) { |
| 1160 |
*info = -5; |
| 1161 |
} else if (*ldab < *ka + 1) { |
| 1162 |
*info = -7; |
| 1163 |
} else if (*ldbb < *kb + 1) { |
| 1164 |
*info = -9; |
| 1165 |
} else if (*ldx < 1 || wantx && *ldx < std::max(1_integer,*n)) { |
| 1166 |
*info = -11; |
| 1167 |
} |
| 1168 |
if (*info != 0) { |
| 1169 |
i__1 = -(*info); |
| 1170 |
xerbla_("DSBGST", &i__1); |
| 1171 |
return 0; |
| 1172 |
} |
| 1173 |
|
| 1174 |
/* Quick return if possible */ |
| 1175 |
|
| 1176 |
if (*n == 0) { |
| 1177 |
return 0; |
| 1178 |
} |
| 1179 |
|
| 1180 |
inca = *ldab * ka1; |
| 1181 |
|
| 1182 |
/* Initialize X to the unit matrix, if needed */ |
| 1183 |
|
| 1184 |
if (wantx) { |
| 1185 |
dlaset_("Full", n, n, &c_b8, &c_b9, &x[x_offset], ldx); |
| 1186 |
} |
| 1187 |
|
| 1188 |
/* Set M to the splitting point m. It must be the same value as is */ |
| 1189 |
/* used in DPBSTF. The chosen value allows the arrays WORK and RWORK */ |
| 1190 |
/* to be of dimension (N). */ |
| 1191 |
|
| 1192 |
m = (*n + *kb) / 2; |
| 1193 |
|
| 1194 |
/* The routine works in two phases, corresponding to the two halves */ |
| 1195 |
/* of the split Cholesky factorization of B as S**T*S where */ |
| 1196 |
|
| 1197 |
/* S = ( U ) */ |
| 1198 |
/* ( M L ) */ |
| 1199 |
|
| 1200 |
/* with U upper triangular of order m, and L lower triangular of */ |
| 1201 |
/* order n-m. S has the same bandwidth as B. */ |
| 1202 |
|
| 1203 |
/* S is treated as a product of elementary matrices: */ |
| 1204 |
|
| 1205 |
/* S = S(m)*S(m-1)*...*S(2)*S(1)*S(m+1)*S(m+2)*...*S(n-1)*S(n) */ |
| 1206 |
|
| 1207 |
/* where S(i) is determined by the i-th row of S. */ |
| 1208 |
|
| 1209 |
/* In phase 1, the index i takes the values n, n-1, ... , m+1; */ |
| 1210 |
/* in phase 2, it takes the values 1, 2, ... , m. */ |
| 1211 |
|
| 1212 |
/* For each value of i, the current matrix A is updated by forming */ |
| 1213 |
/* inv(S(i))**T*A*inv(S(i)). This creates a triangular bulge outside */ |
| 1214 |
/* the band of A. The bulge is then pushed down toward the bottom of */ |
| 1215 |
/* A in phase 1, and up toward the top of A in phase 2, by applying */ |
| 1216 |
/* plane rotations. */ |
| 1217 |
|
| 1218 |
/* There are kb*(kb+1)/2 elements in the bulge, but at most 2*kb-1 */ |
| 1219 |
/* of them are linearly independent, so annihilating a bulge requires */ |
| 1220 |
/* only 2*kb-1 plane rotations. The rotations are divided into a 1st */ |
| 1221 |
/* set of kb-1 rotations, and a 2nd set of kb rotations. */ |
| 1222 |
|
| 1223 |
/* Wherever possible, rotations are generated and applied in vector */ |
| 1224 |
/* operations of length NR between the indices J1 and J2 (sometimes */ |
| 1225 |
/* replaced by modified values NRT, J1T or J2T). */ |
| 1226 |
|
| 1227 |
/* The cosines and sines of the rotations are stored in the array */ |
| 1228 |
/* WORK. The cosines of the 1st set of rotations are stored in */ |
| 1229 |
/* elements n+2:n+m-kb-1 and the sines of the 1st set in elements */ |
| 1230 |
/* 2:m-kb-1; the cosines of the 2nd set are stored in elements */ |
| 1231 |
/* n+m-kb+1:2*n and the sines of the second set in elements m-kb+1:n. */ |
| 1232 |
|
| 1233 |
/* The bulges are not formed explicitly; nonzero elements outside the */ |
| 1234 |
/* band are created only when they are required for generating new */ |
| 1235 |
/* rotations; they are stored in the array WORK, in positions where */ |
| 1236 |
/* they are later overwritten by the sines of the rotations which */ |
| 1237 |
/* annihilate them. */ |
| 1238 |
|
| 1239 |
/* **************************** Phase 1 ***************************** */ |
| 1240 |
|
| 1241 |
/* The logical structure of this phase is: */ |
| 1242 |
|
| 1243 |
/* UPDATE = .TRUE. */ |
| 1244 |
/* DO I = N, M + 1, -1 */ |
| 1245 |
/* use S(i) to update A and create a new bulge */ |
| 1246 |
/* apply rotations to push all bulges KA positions downward */ |
| 1247 |
/* END DO */ |
| 1248 |
/* UPDATE = .FALSE. */ |
| 1249 |
/* DO I = M + KA + 1, N - 1 */ |
| 1250 |
/* apply rotations to push all bulges KA positions downward */ |
| 1251 |
/* END DO */ |
| 1252 |
|
| 1253 |
/* To avoid duplicating code, the two loops are merged. */ |
| 1254 |
|
| 1255 |
update = true; |
| 1256 |
i__ = *n + 1; |
| 1257 |
L10: |
| 1258 |
if (update) { |
| 1259 |
--i__; |
| 1260 |
/* Computing MIN */ |
| 1261 |
i__1 = *kb, i__2 = i__ - 1; |
| 1262 |
kbt = std::min(i__1,i__2); |
| 1263 |
i0 = i__ - 1; |
| 1264 |
/* Computing MIN */ |
| 1265 |
i__1 = *n, i__2 = i__ + *ka; |
| 1266 |
i1 = std::min(i__1,i__2); |
| 1267 |
i2 = i__ - kbt + ka1; |
| 1268 |
if (i__ < m + 1) { |
| 1269 |
update = false; |
| 1270 |
++i__; |
| 1271 |
i0 = m; |
| 1272 |
if (*ka == 0) { |
| 1273 |
goto L480; |
| 1274 |
} |
| 1275 |
goto L10; |
| 1276 |
} |
| 1277 |
} else { |
| 1278 |
i__ += *ka; |
| 1279 |
if (i__ > *n - 1) { |
| 1280 |
goto L480; |
| 1281 |
} |
| 1282 |
} |
| 1283 |
|
| 1284 |
if (upper) { |
| 1285 |
|
| 1286 |
/* Transform A, working with the upper triangle */ |
| 1287 |
|
| 1288 |
if (update) { |
| 1289 |
|
| 1290 |
/* Form inv(S(i))**T * A * inv(S(i)) */ |
| 1291 |
|
| 1292 |
bii = bb[kb1 + i__ * bb_dim1]; |
| 1293 |
i__1 = i1; |
| 1294 |
for (j = i__; j <= i__1; ++j) { |
| 1295 |
ab[i__ - j + ka1 + j * ab_dim1] /= bii; |
| 1296 |
/* L20: */ |
| 1297 |
} |
| 1298 |
/* Computing MAX */ |
| 1299 |
i__1 = 1, i__2 = i__ - *ka; |
| 1300 |
i__3 = i__; |
| 1301 |
for (j = std::max(i__1,i__2); j <= i__3; ++j) { |
| 1302 |
ab[j - i__ + ka1 + i__ * ab_dim1] /= bii; |
| 1303 |
/* L30: */ |
| 1304 |
} |
| 1305 |
i__3 = i__ - 1; |
| 1306 |
for (k = i__ - kbt; k <= i__3; ++k) { |
| 1307 |
i__1 = k; |
| 1308 |
for (j = i__ - kbt; j <= i__1; ++j) { |
| 1309 |
ab[j - k + ka1 + k * ab_dim1] = ab[j - k + ka1 + k * |
| 1310 |
ab_dim1] - bb[j - i__ + kb1 + i__ * bb_dim1] * ab[ |
| 1311 |
k - i__ + ka1 + i__ * ab_dim1] - bb[k - i__ + kb1 |
| 1312 |
+ i__ * bb_dim1] * ab[j - i__ + ka1 + i__ * |
| 1313 |
ab_dim1] + ab[ka1 + i__ * ab_dim1] * bb[j - i__ + |
| 1314 |
kb1 + i__ * bb_dim1] * bb[k - i__ + kb1 + i__ * |
| 1315 |
bb_dim1]; |
| 1316 |
/* L40: */ |
| 1317 |
} |
| 1318 |
/* Computing MAX */ |
| 1319 |
i__1 = 1, i__2 = i__ - *ka; |
| 1320 |
i__4 = i__ - kbt - 1; |
| 1321 |
for (j = std::max(i__1,i__2); j <= i__4; ++j) { |
| 1322 |
ab[j - k + ka1 + k * ab_dim1] -= bb[k - i__ + kb1 + i__ * |
| 1323 |
bb_dim1] * ab[j - i__ + ka1 + i__ * ab_dim1]; |
| 1324 |
/* L50: */ |
| 1325 |
} |
| 1326 |
/* L60: */ |
| 1327 |
} |
| 1328 |
i__3 = i1; |
| 1329 |
for (j = i__; j <= i__3; ++j) { |
| 1330 |
/* Computing MAX */ |
| 1331 |
i__4 = j - *ka, i__1 = i__ - kbt; |
| 1332 |
i__2 = i__ - 1; |
| 1333 |
for (k = std::max(i__4,i__1); k <= i__2; ++k) { |
| 1334 |
ab[k - j + ka1 + j * ab_dim1] -= bb[k - i__ + kb1 + i__ * |
| 1335 |
bb_dim1] * ab[i__ - j + ka1 + j * ab_dim1]; |
| 1336 |
/* L70: */ |
| 1337 |
} |
| 1338 |
/* L80: */ |
| 1339 |
} |
| 1340 |
|
| 1341 |
if (wantx) { |
| 1342 |
|
| 1343 |
/* post-multiply X by inv(S(i)) */ |
| 1344 |
|
| 1345 |
i__3 = *n - m; |
| 1346 |
d__1 = 1. / bii; |
| 1347 |
dscal_(&i__3, &d__1, &x[m + 1 + i__ * x_dim1], &c__1); |
| 1348 |
if (kbt > 0) { |
| 1349 |
i__3 = *n - m; |
| 1350 |
dger_(&i__3, &kbt, &c_b20, &x[m + 1 + i__ * x_dim1], & |
| 1351 |
c__1, &bb[kb1 - kbt + i__ * bb_dim1], &c__1, &x[m |
| 1352 |
+ 1 + (i__ - kbt) * x_dim1], ldx); |
| 1353 |
} |
| 1354 |
} |
| 1355 |
|
| 1356 |
/* store a(i,i1) in RA1 for use in next loop over K */ |
| 1357 |
|
| 1358 |
ra1 = ab[i__ - i1 + ka1 + i1 * ab_dim1]; |
| 1359 |
} |
| 1360 |
|
| 1361 |
/* Generate and apply vectors of rotations to chase all the */ |
| 1362 |
/* existing bulges KA positions down toward the bottom of the */ |
| 1363 |
/* band */ |
| 1364 |
|
| 1365 |
i__3 = *kb - 1; |
| 1366 |
for (k = 1; k <= i__3; ++k) { |
| 1367 |
if (update) { |
| 1368 |
|
| 1369 |
/* Determine the rotations which would annihilate the bulge */ |
| 1370 |
/* which has in theory just been created */ |
| 1371 |
|
| 1372 |
if (i__ - k + *ka < *n && i__ - k > 1) { |
| 1373 |
|
| 1374 |
/* generate rotation to annihilate a(i,i-k+ka+1) */ |
| 1375 |
|
| 1376 |
dlartg_(&ab[k + 1 + (i__ - k + *ka) * ab_dim1], &ra1, & |
| 1377 |
work[*n + i__ - k + *ka - m], &work[i__ - k + *ka |
| 1378 |
- m], &ra); |
| 1379 |
|
| 1380 |
/* create nonzero element a(i-k,i-k+ka+1) outside the */ |
| 1381 |
/* band and store it in WORK(i-k) */ |
| 1382 |
|
| 1383 |
t = -bb[kb1 - k + i__ * bb_dim1] * ra1; |
| 1384 |
work[i__ - k] = work[*n + i__ - k + *ka - m] * t - work[ |
| 1385 |
i__ - k + *ka - m] * ab[(i__ - k + *ka) * ab_dim1 |
| 1386 |
+ 1]; |
| 1387 |
ab[(i__ - k + *ka) * ab_dim1 + 1] = work[i__ - k + *ka - |
| 1388 |
m] * t + work[*n + i__ - k + *ka - m] * ab[(i__ - |
| 1389 |
k + *ka) * ab_dim1 + 1]; |
| 1390 |
ra1 = ra; |
| 1391 |
} |
| 1392 |
} |
| 1393 |
/* Computing MAX */ |
| 1394 |
i__2 = 1, i__4 = k - i0 + 2; |
| 1395 |
j2 = i__ - k - 1 + std::max(i__2,i__4) * ka1; |
| 1396 |
nr = (*n - j2 + *ka) / ka1; |
| 1397 |
j1 = j2 + (nr - 1) * ka1; |
| 1398 |
if (update) { |
| 1399 |
/* Computing MAX */ |
| 1400 |
i__2 = j2, i__4 = i__ + (*ka << 1) - k + 1; |
| 1401 |
j2t = std::max(i__2,i__4); |
| 1402 |
} else { |
| 1403 |
j2t = j2; |
| 1404 |
} |
| 1405 |
nrt = (*n - j2t + *ka) / ka1; |
| 1406 |
i__2 = j1; |
| 1407 |
i__4 = ka1; |
| 1408 |
for (j = j2t; i__4 < 0 ? j >= i__2 : j <= i__2; j += i__4) { |
| 1409 |
|
| 1410 |
/* create nonzero element a(j-ka,j+1) outside the band */ |
| 1411 |
/* and store it in WORK(j-m) */ |
| 1412 |
|
| 1413 |
work[j - m] *= ab[(j + 1) * ab_dim1 + 1]; |
| 1414 |
ab[(j + 1) * ab_dim1 + 1] = work[*n + j - m] * ab[(j + 1) * |
| 1415 |
ab_dim1 + 1]; |
| 1416 |
/* L90: */ |
| 1417 |
} |
| 1418 |
|
| 1419 |
/* generate rotations in 1st set to annihilate elements which */ |
| 1420 |
/* have been created outside the band */ |
| 1421 |
|
| 1422 |
if (nrt > 0) { |
| 1423 |
dlargv_(&nrt, &ab[j2t * ab_dim1 + 1], &inca, &work[j2t - m], & |
| 1424 |
ka1, &work[*n + j2t - m], &ka1); |
| 1425 |
} |
| 1426 |
if (nr > 0) { |
| 1427 |
|
| 1428 |
/* apply rotations in 1st set from the right */ |
| 1429 |
|
| 1430 |
i__4 = *ka - 1; |
| 1431 |
for (l = 1; l <= i__4; ++l) { |
| 1432 |
dlartv_(&nr, &ab[ka1 - l + j2 * ab_dim1], &inca, &ab[*ka |
| 1433 |
- l + (j2 + 1) * ab_dim1], &inca, &work[*n + j2 - |
| 1434 |
m], &work[j2 - m], &ka1); |
| 1435 |
/* L100: */ |
| 1436 |
} |
| 1437 |
|
| 1438 |
/* apply rotations in 1st set from both sides to diagonal */ |
| 1439 |
/* blocks */ |
| 1440 |
|
| 1441 |
dlar2v_(&nr, &ab[ka1 + j2 * ab_dim1], &ab[ka1 + (j2 + 1) * |
| 1442 |
ab_dim1], &ab[*ka + (j2 + 1) * ab_dim1], &inca, &work[ |
| 1443 |
*n + j2 - m], &work[j2 - m], &ka1); |
| 1444 |
|
| 1445 |
} |
| 1446 |
|
| 1447 |
/* start applying rotations in 1st set from the left */ |
| 1448 |
|
| 1449 |
i__4 = *kb - k + 1; |
| 1450 |
for (l = *ka - 1; l >= i__4; --l) { |
| 1451 |
nrt = (*n - j2 + l) / ka1; |
| 1452 |
if (nrt > 0) { |
| 1453 |
dlartv_(&nrt, &ab[l + (j2 + ka1 - l) * ab_dim1], &inca, & |
| 1454 |
ab[l + 1 + (j2 + ka1 - l) * ab_dim1], &inca, & |
| 1455 |
work[*n + j2 - m], &work[j2 - m], &ka1); |
| 1456 |
} |
| 1457 |
/* L110: */ |
| 1458 |
} |
| 1459 |
|
| 1460 |
if (wantx) { |
| 1461 |
|
| 1462 |
/* post-multiply X by product of rotations in 1st set */ |
| 1463 |
|
| 1464 |
i__4 = j1; |
| 1465 |
i__2 = ka1; |
| 1466 |
for (j = j2; i__2 < 0 ? j >= i__4 : j <= i__4; j += i__2) { |
| 1467 |
i__1 = *n - m; |
| 1468 |
drot_(&i__1, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j |
| 1469 |
+ 1) * x_dim1], &c__1, &work[*n + j - m], &work[j |
| 1470 |
- m]); |
| 1471 |
/* L120: */ |
| 1472 |
} |
| 1473 |
} |
| 1474 |
/* L130: */ |
| 1475 |
} |
| 1476 |
|
| 1477 |
if (update) { |
| 1478 |
if (i2 <= *n && kbt > 0) { |
| 1479 |
|
| 1480 |
/* create nonzero element a(i-kbt,i-kbt+ka+1) outside the */ |
| 1481 |
/* band and store it in WORK(i-kbt) */ |
| 1482 |
|
| 1483 |
work[i__ - kbt] = -bb[kb1 - kbt + i__ * bb_dim1] * ra1; |
| 1484 |
} |
| 1485 |
} |
| 1486 |
|
| 1487 |
for (k = *kb; k >= 1; --k) { |
| 1488 |
if (update) { |
| 1489 |
/* Computing MAX */ |
| 1490 |
i__3 = 2, i__2 = k - i0 + 1; |
| 1491 |
j2 = i__ - k - 1 + std::max(i__3,i__2) * ka1; |
| 1492 |
} else { |
| 1493 |
/* Computing MAX */ |
| 1494 |
i__3 = 1, i__2 = k - i0 + 1; |
| 1495 |
j2 = i__ - k - 1 + std::max(i__3,i__2) * ka1; |
| 1496 |
} |
| 1497 |
|
| 1498 |
/* finish applying rotations in 2nd set from the left */ |
| 1499 |
|
| 1500 |
for (l = *kb - k; l >= 1; --l) { |
| 1501 |
nrt = (*n - j2 + *ka + l) / ka1; |
| 1502 |
if (nrt > 0) { |
| 1503 |
dlartv_(&nrt, &ab[l + (j2 - l + 1) * ab_dim1], &inca, &ab[ |
| 1504 |
l + 1 + (j2 - l + 1) * ab_dim1], &inca, &work[*n |
| 1505 |
+ j2 - *ka], &work[j2 - *ka], &ka1); |
| 1506 |
} |
| 1507 |
/* L140: */ |
| 1508 |
} |
| 1509 |
nr = (*n - j2 + *ka) / ka1; |
| 1510 |
j1 = j2 + (nr - 1) * ka1; |
| 1511 |
i__3 = j2; |
| 1512 |
i__2 = -ka1; |
| 1513 |
for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j += i__2) { |
| 1514 |
work[j] = work[j - *ka]; |
| 1515 |
work[*n + j] = work[*n + j - *ka]; |
| 1516 |
/* L150: */ |
| 1517 |
} |
| 1518 |
i__2 = j1; |
| 1519 |
i__3 = ka1; |
| 1520 |
for (j = j2; i__3 < 0 ? j >= i__2 : j <= i__2; j += i__3) { |
| 1521 |
|
| 1522 |
/* create nonzero element a(j-ka,j+1) outside the band */ |
| 1523 |
/* and store it in WORK(j) */ |
| 1524 |
|
| 1525 |
work[j] *= ab[(j + 1) * ab_dim1 + 1]; |
| 1526 |
ab[(j + 1) * ab_dim1 + 1] = work[*n + j] * ab[(j + 1) * |
| 1527 |
ab_dim1 + 1]; |
| 1528 |
/* L160: */ |
| 1529 |
} |
| 1530 |
if (update) { |
| 1531 |
if (i__ - k < *n - *ka && k <= kbt) { |
| 1532 |
work[i__ - k + *ka] = work[i__ - k]; |
| 1533 |
} |
| 1534 |
} |
| 1535 |
/* L170: */ |
| 1536 |
} |
| 1537 |
|
| 1538 |
for (k = *kb; k >= 1; --k) { |
| 1539 |
/* Computing MAX */ |
| 1540 |
i__3 = 1, i__2 = k - i0 + 1; |
| 1541 |
j2 = i__ - k - 1 + std::max(i__3,i__2) * ka1; |
| 1542 |
nr = (*n - j2 + *ka) / ka1; |
| 1543 |
j1 = j2 + (nr - 1) * ka1; |
| 1544 |
if (nr > 0) { |
| 1545 |
|
| 1546 |
/* generate rotations in 2nd set to annihilate elements */ |
| 1547 |
/* which have been created outside the band */ |
| 1548 |
|
| 1549 |
dlargv_(&nr, &ab[j2 * ab_dim1 + 1], &inca, &work[j2], &ka1, & |
| 1550 |
work[*n + j2], &ka1); |
| 1551 |
|
| 1552 |
/* apply rotations in 2nd set from the right */ |
| 1553 |
|
| 1554 |
i__3 = *ka - 1; |
| 1555 |
for (l = 1; l <= i__3; ++l) { |
| 1556 |
dlartv_(&nr, &ab[ka1 - l + j2 * ab_dim1], &inca, &ab[*ka |
| 1557 |
- l + (j2 + 1) * ab_dim1], &inca, &work[*n + j2], |
| 1558 |
&work[j2], &ka1); |
| 1559 |
/* L180: */ |
| 1560 |
} |
| 1561 |
|
| 1562 |
/* apply rotations in 2nd set from both sides to diagonal */ |
| 1563 |
/* blocks */ |
| 1564 |
|
| 1565 |
dlar2v_(&nr, &ab[ka1 + j2 * ab_dim1], &ab[ka1 + (j2 + 1) * |
| 1566 |
ab_dim1], &ab[*ka + (j2 + 1) * ab_dim1], &inca, &work[ |
| 1567 |
*n + j2], &work[j2], &ka1); |
| 1568 |
|
| 1569 |
} |
| 1570 |
|
| 1571 |
/* start applying rotations in 2nd set from the left */ |
| 1572 |
|
| 1573 |
i__3 = *kb - k + 1; |
| 1574 |
for (l = *ka - 1; l >= i__3; --l) { |
| 1575 |
nrt = (*n - j2 + l) / ka1; |
| 1576 |
if (nrt > 0) { |
| 1577 |
dlartv_(&nrt, &ab[l + (j2 + ka1 - l) * ab_dim1], &inca, & |
| 1578 |
ab[l + 1 + (j2 + ka1 - l) * ab_dim1], &inca, & |
| 1579 |
work[*n + j2], &work[j2], &ka1); |
| 1580 |
} |
| 1581 |
/* L190: */ |
| 1582 |
} |
| 1583 |
|
| 1584 |
if (wantx) { |
| 1585 |
|
| 1586 |
/* post-multiply X by product of rotations in 2nd set */ |
| 1587 |
|
| 1588 |
i__3 = j1; |
| 1589 |
i__2 = ka1; |
| 1590 |
for (j = j2; i__2 < 0 ? j >= i__3 : j <= i__3; j += i__2) { |
| 1591 |
i__4 = *n - m; |
| 1592 |
drot_(&i__4, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j |
| 1593 |
+ 1) * x_dim1], &c__1, &work[*n + j], &work[j]); |
| 1594 |
/* L200: */ |
| 1595 |
} |
| 1596 |
} |
| 1597 |
/* L210: */ |
| 1598 |
} |
| 1599 |
|
| 1600 |
i__2 = *kb - 1; |
| 1601 |
for (k = 1; k <= i__2; ++k) { |
| 1602 |
/* Computing MAX */ |
| 1603 |
i__3 = 1, i__4 = k - i0 + 2; |
| 1604 |
j2 = i__ - k - 1 + std::max(i__3,i__4) * ka1; |
| 1605 |
|
| 1606 |
/* finish applying rotations in 1st set from the left */ |
| 1607 |
|
| 1608 |
for (l = *kb - k; l >= 1; --l) { |
| 1609 |
nrt = (*n - j2 + l) / ka1; |
| 1610 |
if (nrt > 0) { |
| 1611 |
dlartv_(&nrt, &ab[l + (j2 + ka1 - l) * ab_dim1], &inca, & |
| 1612 |
ab[l + 1 + (j2 + ka1 - l) * ab_dim1], &inca, & |
| 1613 |
work[*n + j2 - m], &work[j2 - m], &ka1); |
| 1614 |
} |
| 1615 |
/* L220: */ |
| 1616 |
} |
| 1617 |
/* L230: */ |
| 1618 |
} |
| 1619 |
|
| 1620 |
if (*kb > 1) { |
| 1621 |
i__2 = i__ - *kb + (*ka << 1) + 1; |
| 1622 |
for (j = *n - 1; j >= i__2; --j) { |
| 1623 |
work[*n + j - m] = work[*n + j - *ka - m]; |
| 1624 |
work[j - m] = work[j - *ka - m]; |
| 1625 |
/* L240: */ |
| 1626 |
} |
| 1627 |
} |
| 1628 |
|
| 1629 |
} else { |
| 1630 |
|
| 1631 |
/* Transform A, working with the lower triangle */ |
| 1632 |
|
| 1633 |
if (update) { |
| 1634 |
|
| 1635 |
/* Form inv(S(i))**T * A * inv(S(i)) */ |
| 1636 |
|
| 1637 |
bii = bb[i__ * bb_dim1 + 1]; |
| 1638 |
i__2 = i1; |
| 1639 |
for (j = i__; j <= i__2; ++j) { |
| 1640 |
ab[j - i__ + 1 + i__ * ab_dim1] /= bii; |
| 1641 |
/* L250: */ |
| 1642 |
} |
| 1643 |
/* Computing MAX */ |
| 1644 |
i__2 = 1, i__3 = i__ - *ka; |
| 1645 |
i__4 = i__; |
| 1646 |
for (j = std::max(i__2,i__3); j <= i__4; ++j) { |
| 1647 |
ab[i__ - j + 1 + j * ab_dim1] /= bii; |
| 1648 |
/* L260: */ |
| 1649 |
} |
| 1650 |
i__4 = i__ - 1; |
| 1651 |
for (k = i__ - kbt; k <= i__4; ++k) { |
| 1652 |
i__2 = k; |
| 1653 |
for (j = i__ - kbt; j <= i__2; ++j) { |
| 1654 |
ab[k - j + 1 + j * ab_dim1] = ab[k - j + 1 + j * ab_dim1] |
| 1655 |
- bb[i__ - j + 1 + j * bb_dim1] * ab[i__ - k + 1 |
| 1656 |
+ k * ab_dim1] - bb[i__ - k + 1 + k * bb_dim1] * |
| 1657 |
ab[i__ - j + 1 + j * ab_dim1] + ab[i__ * ab_dim1 |
| 1658 |
+ 1] * bb[i__ - j + 1 + j * bb_dim1] * bb[i__ - k |
| 1659 |
+ 1 + k * bb_dim1]; |
| 1660 |
/* L270: */ |
| 1661 |
} |
| 1662 |
/* Computing MAX */ |
| 1663 |
i__2 = 1, i__3 = i__ - *ka; |
| 1664 |
i__1 = i__ - kbt - 1; |
| 1665 |
for (j = std::max(i__2,i__3); j <= i__1; ++j) { |
| 1666 |
ab[k - j + 1 + j * ab_dim1] -= bb[i__ - k + 1 + k * |
| 1667 |
bb_dim1] * ab[i__ - j + 1 + j * ab_dim1]; |
| 1668 |
/* L280: */ |
| 1669 |
} |
| 1670 |
/* L290: */ |
| 1671 |
} |
| 1672 |
i__4 = i1; |
| 1673 |
for (j = i__; j <= i__4; ++j) { |
| 1674 |
/* Computing MAX */ |
| 1675 |
i__1 = j - *ka, i__2 = i__ - kbt; |
| 1676 |
i__3 = i__ - 1; |
| 1677 |
for (k = std::max(i__1,i__2); k <= i__3; ++k) { |
| 1678 |
ab[j - k + 1 + k * ab_dim1] -= bb[i__ - k + 1 + k * |
| 1679 |
bb_dim1] * ab[j - i__ + 1 + i__ * ab_dim1]; |
| 1680 |
/* L300: */ |
| 1681 |
} |
| 1682 |
/* L310: */ |
| 1683 |
} |
| 1684 |
|
| 1685 |
if (wantx) { |
| 1686 |
|
| 1687 |
/* post-multiply X by inv(S(i)) */ |
| 1688 |
|
| 1689 |
i__4 = *n - m; |
| 1690 |
d__1 = 1. / bii; |
| 1691 |
dscal_(&i__4, &d__1, &x[m + 1 + i__ * x_dim1], &c__1); |
| 1692 |
if (kbt > 0) { |
| 1693 |
i__4 = *n - m; |
| 1694 |
i__3 = *ldbb - 1; |
| 1695 |
dger_(&i__4, &kbt, &c_b20, &x[m + 1 + i__ * x_dim1], & |
| 1696 |
c__1, &bb[kbt + 1 + (i__ - kbt) * bb_dim1], &i__3, |
| 1697 |
&x[m + 1 + (i__ - kbt) * x_dim1], ldx); |
| 1698 |
} |
| 1699 |
} |
| 1700 |
|
| 1701 |
/* store a(i1,i) in RA1 for use in next loop over K */ |
| 1702 |
|
| 1703 |
ra1 = ab[i1 - i__ + 1 + i__ * ab_dim1]; |
| 1704 |
} |
| 1705 |
|
| 1706 |
/* Generate and apply vectors of rotations to chase all the */ |
| 1707 |
/* existing bulges KA positions down toward the bottom of the */ |
| 1708 |
/* band */ |
| 1709 |
|
| 1710 |
i__4 = *kb - 1; |
| 1711 |
for (k = 1; k <= i__4; ++k) { |
| 1712 |
if (update) { |
| 1713 |
|
| 1714 |
/* Determine the rotations which would annihilate the bulge */ |
| 1715 |
/* which has in theory just been created */ |
| 1716 |
|
| 1717 |
if (i__ - k + *ka < *n && i__ - k > 1) { |
| 1718 |
|
| 1719 |
/* generate rotation to annihilate a(i-k+ka+1,i) */ |
| 1720 |
|
| 1721 |
dlartg_(&ab[ka1 - k + i__ * ab_dim1], &ra1, &work[*n + |
| 1722 |
i__ - k + *ka - m], &work[i__ - k + *ka - m], &ra) |
| 1723 |
; |
| 1724 |
|
| 1725 |
/* create nonzero element a(i-k+ka+1,i-k) outside the */ |
| 1726 |
/* band and store it in WORK(i-k) */ |
| 1727 |
|
| 1728 |
t = -bb[k + 1 + (i__ - k) * bb_dim1] * ra1; |
| 1729 |
work[i__ - k] = work[*n + i__ - k + *ka - m] * t - work[ |
| 1730 |
i__ - k + *ka - m] * ab[ka1 + (i__ - k) * ab_dim1] |
| 1731 |
; |
| 1732 |
ab[ka1 + (i__ - k) * ab_dim1] = work[i__ - k + *ka - m] * |
| 1733 |
t + work[*n + i__ - k + *ka - m] * ab[ka1 + (i__ |
| 1734 |
- k) * ab_dim1]; |
| 1735 |
ra1 = ra; |
| 1736 |
} |
| 1737 |
} |
| 1738 |
/* Computing MAX */ |
| 1739 |
i__3 = 1, i__1 = k - i0 + 2; |
| 1740 |
j2 = i__ - k - 1 + std::max(i__3,i__1) * ka1; |
| 1741 |
nr = (*n - j2 + *ka) / ka1; |
| 1742 |
j1 = j2 + (nr - 1) * ka1; |
| 1743 |
if (update) { |
| 1744 |
/* Computing MAX */ |
| 1745 |
i__3 = j2, i__1 = i__ + (*ka << 1) - k + 1; |
| 1746 |
j2t = std::max(i__3,i__1); |
| 1747 |
} else { |
| 1748 |
j2t = j2; |
| 1749 |
} |
| 1750 |
nrt = (*n - j2t + *ka) / ka1; |
| 1751 |
i__3 = j1; |
| 1752 |
i__1 = ka1; |
| 1753 |
for (j = j2t; i__1 < 0 ? j >= i__3 : j <= i__3; j += i__1) { |
| 1754 |
|
| 1755 |
/* create nonzero element a(j+1,j-ka) outside the band */ |
| 1756 |
/* and store it in WORK(j-m) */ |
| 1757 |
|
| 1758 |
work[j - m] *= ab[ka1 + (j - *ka + 1) * ab_dim1]; |
| 1759 |
ab[ka1 + (j - *ka + 1) * ab_dim1] = work[*n + j - m] * ab[ka1 |
| 1760 |
+ (j - *ka + 1) * ab_dim1]; |
| 1761 |
/* L320: */ |
| 1762 |
} |
| 1763 |
|
| 1764 |
/* generate rotations in 1st set to annihilate elements which */ |
| 1765 |
/* have been created outside the band */ |
| 1766 |
|
| 1767 |
if (nrt > 0) { |
| 1768 |
dlargv_(&nrt, &ab[ka1 + (j2t - *ka) * ab_dim1], &inca, &work[ |
| 1769 |
j2t - m], &ka1, &work[*n + j2t - m], &ka1); |
| 1770 |
} |
| 1771 |
if (nr > 0) { |
| 1772 |
|
| 1773 |
/* apply rotations in 1st set from the left */ |
| 1774 |
|
| 1775 |
i__1 = *ka - 1; |
| 1776 |
for (l = 1; l <= i__1; ++l) { |
| 1777 |
dlartv_(&nr, &ab[l + 1 + (j2 - l) * ab_dim1], &inca, &ab[ |
| 1778 |
l + 2 + (j2 - l) * ab_dim1], &inca, &work[*n + j2 |
| 1779 |
- m], &work[j2 - m], &ka1); |
| 1780 |
/* L330: */ |
| 1781 |
} |
| 1782 |
|
| 1783 |
/* apply rotations in 1st set from both sides to diagonal */ |
| 1784 |
/* blocks */ |
| 1785 |
|
| 1786 |
dlar2v_(&nr, &ab[j2 * ab_dim1 + 1], &ab[(j2 + 1) * ab_dim1 + |
| 1787 |
1], &ab[j2 * ab_dim1 + 2], &inca, &work[*n + j2 - m], |
| 1788 |
&work[j2 - m], &ka1); |
| 1789 |
|
| 1790 |
} |
| 1791 |
|
| 1792 |
/* start applying rotations in 1st set from the right */ |
| 1793 |
|
| 1794 |
i__1 = *kb - k + 1; |
| 1795 |
for (l = *ka - 1; l >= i__1; --l) { |
| 1796 |
nrt = (*n - j2 + l) / ka1; |
| 1797 |
if (nrt > 0) { |
| 1798 |
dlartv_(&nrt, &ab[ka1 - l + 1 + j2 * ab_dim1], &inca, &ab[ |
| 1799 |
ka1 - l + (j2 + 1) * ab_dim1], &inca, &work[*n + |
| 1800 |
j2 - m], &work[j2 - m], &ka1); |
| 1801 |
} |
| 1802 |
/* L340: */ |
| 1803 |
} |
| 1804 |
|
| 1805 |
if (wantx) { |
| 1806 |
|
| 1807 |
/* post-multiply X by product of rotations in 1st set */ |
| 1808 |
|
| 1809 |
i__1 = j1; |
| 1810 |
i__3 = ka1; |
| 1811 |
for (j = j2; i__3 < 0 ? j >= i__1 : j <= i__1; j += i__3) { |
| 1812 |
i__2 = *n - m; |
| 1813 |
drot_(&i__2, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j |
| 1814 |
+ 1) * x_dim1], &c__1, &work[*n + j - m], &work[j |
| 1815 |
- m]); |
| 1816 |
/* L350: */ |
| 1817 |
} |
| 1818 |
} |
| 1819 |
/* L360: */ |
| 1820 |
} |
| 1821 |
|
| 1822 |
if (update) { |
| 1823 |
if (i2 <= *n && kbt > 0) { |
| 1824 |
|
| 1825 |
/* create nonzero element a(i-kbt+ka+1,i-kbt) outside the */ |
| 1826 |
/* band and store it in WORK(i-kbt) */ |
| 1827 |
|
| 1828 |
work[i__ - kbt] = -bb[kbt + 1 + (i__ - kbt) * bb_dim1] * ra1; |
| 1829 |
} |
| 1830 |
} |
| 1831 |
|
| 1832 |
for (k = *kb; k >= 1; --k) { |
| 1833 |
if (update) { |
| 1834 |
/* Computing MAX */ |
| 1835 |
i__4 = 2, i__3 = k - i0 + 1; |
| 1836 |
j2 = i__ - k - 1 + std::max(i__4,i__3) * ka1; |
| 1837 |
} else { |
| 1838 |
/* Computing MAX */ |
| 1839 |
i__4 = 1, i__3 = k - i0 + 1; |
| 1840 |
j2 = i__ - k - 1 + std::max(i__4,i__3) * ka1; |
| 1841 |
} |
| 1842 |
|
| 1843 |
/* finish applying rotations in 2nd set from the right */ |
| 1844 |
|
| 1845 |
for (l = *kb - k; l >= 1; --l) { |
| 1846 |
nrt = (*n - j2 + *ka + l) / ka1; |
| 1847 |
if (nrt > 0) { |
| 1848 |
dlartv_(&nrt, &ab[ka1 - l + 1 + (j2 - *ka) * ab_dim1], & |
| 1849 |
inca, &ab[ka1 - l + (j2 - *ka + 1) * ab_dim1], & |
| 1850 |
inca, &work[*n + j2 - *ka], &work[j2 - *ka], &ka1) |
| 1851 |
; |
| 1852 |
} |
| 1853 |
/* L370: */ |
| 1854 |
} |
| 1855 |
nr = (*n - j2 + *ka) / ka1; |
| 1856 |
j1 = j2 + (nr - 1) * ka1; |
| 1857 |
i__4 = j2; |
| 1858 |
i__3 = -ka1; |
| 1859 |
for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) { |
| 1860 |
work[j] = work[j - *ka]; |
| 1861 |
work[*n + j] = work[*n + j - *ka]; |
| 1862 |
/* L380: */ |
| 1863 |
} |
| 1864 |
i__3 = j1; |
| 1865 |
i__4 = ka1; |
| 1866 |
for (j = j2; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) { |
| 1867 |
|
| 1868 |
/* create nonzero element a(j+1,j-ka) outside the band */ |
| 1869 |
/* and store it in WORK(j) */ |
| 1870 |
|
| 1871 |
work[j] *= ab[ka1 + (j - *ka + 1) * ab_dim1]; |
| 1872 |
ab[ka1 + (j - *ka + 1) * ab_dim1] = work[*n + j] * ab[ka1 + ( |
| 1873 |
j - *ka + 1) * ab_dim1]; |
| 1874 |
/* L390: */ |
| 1875 |
} |
| 1876 |
if (update) { |
| 1877 |
if (i__ - k < *n - *ka && k <= kbt) { |
| 1878 |
work[i__ - k + *ka] = work[i__ - k]; |
| 1879 |
} |
| 1880 |
} |
| 1881 |
/* L400: */ |
| 1882 |
} |
| 1883 |
|
| 1884 |
for (k = *kb; k >= 1; --k) { |
| 1885 |
/* Computing MAX */ |
| 1886 |
i__4 = 1, i__3 = k - i0 + 1; |
| 1887 |
j2 = i__ - k - 1 + std::max(i__4,i__3) * ka1; |
| 1888 |
nr = (*n - j2 + *ka) / ka1; |
| 1889 |
j1 = j2 + (nr - 1) * ka1; |
| 1890 |
if (nr > 0) { |
| 1891 |
|
| 1892 |
/* generate rotations in 2nd set to annihilate elements */ |
| 1893 |
/* which have been created outside the band */ |
| 1894 |
|
| 1895 |
dlargv_(&nr, &ab[ka1 + (j2 - *ka) * ab_dim1], &inca, &work[j2] |
| 1896 |
, &ka1, &work[*n + j2], &ka1); |
| 1897 |
|
| 1898 |
/* apply rotations in 2nd set from the left */ |
| 1899 |
|
| 1900 |
i__4 = *ka - 1; |
| 1901 |
for (l = 1; l <= i__4; ++l) { |
| 1902 |
dlartv_(&nr, &ab[l + 1 + (j2 - l) * ab_dim1], &inca, &ab[ |
| 1903 |
l + 2 + (j2 - l) * ab_dim1], &inca, &work[*n + j2] |
| 1904 |
, &work[j2], &ka1); |
| 1905 |
/* L410: */ |
| 1906 |
} |
| 1907 |
|
| 1908 |
/* apply rotations in 2nd set from both sides to diagonal */ |
| 1909 |
/* blocks */ |
| 1910 |
|
| 1911 |
dlar2v_(&nr, &ab[j2 * ab_dim1 + 1], &ab[(j2 + 1) * ab_dim1 + |
| 1912 |
1], &ab[j2 * ab_dim1 + 2], &inca, &work[*n + j2], & |
| 1913 |
work[j2], &ka1); |
| 1914 |
|
| 1915 |
} |
| 1916 |
|
| 1917 |
/* start applying rotations in 2nd set from the right */ |
| 1918 |
|
| 1919 |
i__4 = *kb - k + 1; |
| 1920 |
for (l = *ka - 1; l >= i__4; --l) { |
| 1921 |
nrt = (*n - j2 + l) / ka1; |
| 1922 |
if (nrt > 0) { |
| 1923 |
dlartv_(&nrt, &ab[ka1 - l + 1 + j2 * ab_dim1], &inca, &ab[ |
| 1924 |
ka1 - l + (j2 + 1) * ab_dim1], &inca, &work[*n + |
| 1925 |
j2], &work[j2], &ka1); |
| 1926 |
} |
| 1927 |
/* L420: */ |
| 1928 |
} |
| 1929 |
|
| 1930 |
if (wantx) { |
| 1931 |
|
| 1932 |
/* post-multiply X by product of rotations in 2nd set */ |
| 1933 |
|
| 1934 |
i__4 = j1; |
| 1935 |
i__3 = ka1; |
| 1936 |
for (j = j2; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) { |
| 1937 |
i__1 = *n - m; |
| 1938 |
drot_(&i__1, &x[m + 1 + j * x_dim1], &c__1, &x[m + 1 + (j |
| 1939 |
+ 1) * x_dim1], &c__1, &work[*n + j], &work[j]); |
| 1940 |
/* L430: */ |
| 1941 |
} |
| 1942 |
} |
| 1943 |
/* L440: */ |
| 1944 |
} |
| 1945 |
|
| 1946 |
i__3 = *kb - 1; |
| 1947 |
for (k = 1; k <= i__3; ++k) { |
| 1948 |
/* Computing MAX */ |
| 1949 |
i__4 = 1, i__1 = k - i0 + 2; |
| 1950 |
j2 = i__ - k - 1 + std::max(i__4,i__1) * ka1; |
| 1951 |
|
| 1952 |
/* finish applying rotations in 1st set from the right */ |
| 1953 |
|
| 1954 |
for (l = *kb - k; l >= 1; --l) { |
| 1955 |
nrt = (*n - j2 + l) / ka1; |
| 1956 |
if (nrt > 0) { |
| 1957 |
dlartv_(&nrt, &ab[ka1 - l + 1 + j2 * ab_dim1], &inca, &ab[ |
| 1958 |
ka1 - l + (j2 + 1) * ab_dim1], &inca, &work[*n + |
| 1959 |
j2 - m], &work[j2 - m], &ka1); |
| 1960 |
} |
| 1961 |
/* L450: */ |
| 1962 |
} |
| 1963 |
/* L460: */ |
| 1964 |
} |
| 1965 |
|
| 1966 |
if (*kb > 1) { |
| 1967 |
i__3 = i__ - *kb + (*ka << 1) + 1; |
| 1968 |
for (j = *n - 1; j >= i__3; --j) { |
| 1969 |
work[*n + j - m] = work[*n + j - *ka - m]; |
| 1970 |
work[j - m] = work[j - *ka - m]; |
| 1971 |
/* L470: */ |
| 1972 |
} |
| 1973 |
} |
| 1974 |
|
| 1975 |
} |
| 1976 |
|
| 1977 |
goto L10; |
| 1978 |
|
| 1979 |
L480: |
| 1980 |
|
| 1981 |
/* **************************** Phase 2 ***************************** */ |
| 1982 |
|
| 1983 |
/* The logical structure of this phase is: */ |
| 1984 |
|
| 1985 |
/* UPDATE = .TRUE. */ |
| 1986 |
/* DO I = 1, M */ |
| 1987 |
/* use S(i) to update A and create a new bulge */ |
| 1988 |
/* apply rotations to push all bulges KA positions upward */ |
| 1989 |
/* END DO */ |
| 1990 |
/* UPDATE = .FALSE. */ |
| 1991 |
/* DO I = M - KA - 1, 2, -1 */ |
| 1992 |
/* apply rotations to push all bulges KA positions upward */ |
| 1993 |
/* END DO */ |
| 1994 |
|
| 1995 |
/* To avoid duplicating code, the two loops are merged. */ |
| 1996 |
|
| 1997 |
update = true; |
| 1998 |
i__ = 0; |
| 1999 |
L490: |
| 2000 |
if (update) { |
| 2001 |
++i__; |
| 2002 |
/* Computing MIN */ |
| 2003 |
i__3 = *kb, i__4 = m - i__; |
| 2004 |
kbt = std::min(i__3,i__4); |
| 2005 |
i0 = i__ + 1; |
| 2006 |
/* Computing MAX */ |
| 2007 |
i__3 = 1, i__4 = i__ - *ka; |
| 2008 |
i1 = std::max(i__3,i__4); |
| 2009 |
i2 = i__ + kbt - ka1; |
| 2010 |
if (i__ > m) { |
| 2011 |
update = false; |
| 2012 |
--i__; |
| 2013 |
i0 = m + 1; |
| 2014 |
if (*ka == 0) { |
| 2015 |
return 0; |
| 2016 |
} |
| 2017 |
goto L490; |
| 2018 |
} |
| 2019 |
} else { |
| 2020 |
i__ -= *ka; |
| 2021 |
if (i__ < 2) { |
| 2022 |
return 0; |
| 2023 |
} |
| 2024 |
} |
| 2025 |
|
| 2026 |
if (i__ < m - kbt) { |
| 2027 |
nx = m; |
| 2028 |
} else { |
| 2029 |
nx = *n; |
| 2030 |
} |
| 2031 |
|
| 2032 |
if (upper) { |
| 2033 |
|
| 2034 |
/* Transform A, working with the upper triangle */ |
| 2035 |
|
| 2036 |
if (update) { |
| 2037 |
|
| 2038 |
/* Form inv(S(i))**T * A * inv(S(i)) */ |
| 2039 |
|
| 2040 |
bii = bb[kb1 + i__ * bb_dim1]; |
| 2041 |
i__3 = i__; |
| 2042 |
for (j = i1; j <= i__3; ++j) { |
| 2043 |
ab[j - i__ + ka1 + i__ * ab_dim1] /= bii; |
| 2044 |
/* L500: */ |
| 2045 |
} |
| 2046 |
/* Computing MIN */ |
| 2047 |
i__4 = *n, i__1 = i__ + *ka; |
| 2048 |
i__3 = std::min(i__4,i__1); |
| 2049 |
for (j = i__; j <= i__3; ++j) { |
| 2050 |
ab[i__ - j + ka1 + j * ab_dim1] /= bii; |
| 2051 |
/* L510: */ |
| 2052 |
} |
| 2053 |
i__3 = i__ + kbt; |
| 2054 |
for (k = i__ + 1; k <= i__3; ++k) { |
| 2055 |
i__4 = i__ + kbt; |
| 2056 |
for (j = k; j <= i__4; ++j) { |
| 2057 |
ab[k - j + ka1 + j * ab_dim1] = ab[k - j + ka1 + j * |
| 2058 |
ab_dim1] - bb[i__ - j + kb1 + j * bb_dim1] * ab[ |
| 2059 |
i__ - k + ka1 + k * ab_dim1] - bb[i__ - k + kb1 + |
| 2060 |
k * bb_dim1] * ab[i__ - j + ka1 + j * ab_dim1] + |
| 2061 |
ab[ka1 + i__ * ab_dim1] * bb[i__ - j + kb1 + j * |
| 2062 |
bb_dim1] * bb[i__ - k + kb1 + k * bb_dim1]; |
| 2063 |
/* L520: */ |
| 2064 |
} |
| 2065 |
/* Computing MIN */ |
| 2066 |
i__1 = *n, i__2 = i__ + *ka; |
| 2067 |
i__4 = std::min(i__1,i__2); |
| 2068 |
for (j = i__ + kbt + 1; j <= i__4; ++j) { |
| 2069 |
ab[k - j + ka1 + j * ab_dim1] -= bb[i__ - k + kb1 + k * |
| 2070 |
bb_dim1] * ab[i__ - j + ka1 + j * ab_dim1]; |
| 2071 |
/* L530: */ |
| 2072 |
} |
| 2073 |
/* L540: */ |
| 2074 |
} |
| 2075 |
i__3 = i__; |
| 2076 |
for (j = i1; j <= i__3; ++j) { |
| 2077 |
/* Computing MIN */ |
| 2078 |
i__1 = j + *ka, i__2 = i__ + kbt; |
| 2079 |
i__4 = std::min(i__1,i__2); |
| 2080 |
for (k = i__ + 1; k <= i__4; ++k) { |
| 2081 |
ab[j - k + ka1 + k * ab_dim1] -= bb[i__ - k + kb1 + k * |
| 2082 |
bb_dim1] * ab[j - i__ + ka1 + i__ * ab_dim1]; |
| 2083 |
/* L550: */ |
| 2084 |
} |
| 2085 |
/* L560: */ |
| 2086 |
} |
| 2087 |
|
| 2088 |
if (wantx) { |
| 2089 |
|
| 2090 |
/* post-multiply X by inv(S(i)) */ |
| 2091 |
|
| 2092 |
d__1 = 1. / bii; |
| 2093 |
dscal_(&nx, &d__1, &x[i__ * x_dim1 + 1], &c__1); |
| 2094 |
if (kbt > 0) { |
| 2095 |
i__3 = *ldbb - 1; |
| 2096 |
dger_(&nx, &kbt, &c_b20, &x[i__ * x_dim1 + 1], &c__1, &bb[ |
| 2097 |
*kb + (i__ + 1) * bb_dim1], &i__3, &x[(i__ + 1) * |
| 2098 |
x_dim1 + 1], ldx); |
| 2099 |
} |
| 2100 |
} |
| 2101 |
|
| 2102 |
/* store a(i1,i) in RA1 for use in next loop over K */ |
| 2103 |
|
| 2104 |
ra1 = ab[i1 - i__ + ka1 + i__ * ab_dim1]; |
| 2105 |
} |
| 2106 |
|
| 2107 |
/* Generate and apply vectors of rotations to chase all the */ |
| 2108 |
/* existing bulges KA positions up toward the top of the band */ |
| 2109 |
|
| 2110 |
i__3 = *kb - 1; |
| 2111 |
for (k = 1; k <= i__3; ++k) { |
| 2112 |
if (update) { |
| 2113 |
|
| 2114 |
/* Determine the rotations which would annihilate the bulge */ |
| 2115 |
/* which has in theory just been created */ |
| 2116 |
|
| 2117 |
if (i__ + k - ka1 > 0 && i__ + k < m) { |
| 2118 |
|
| 2119 |
/* generate rotation to annihilate a(i+k-ka-1,i) */ |
| 2120 |
|
| 2121 |
dlartg_(&ab[k + 1 + i__ * ab_dim1], &ra1, &work[*n + i__ |
| 2122 |
+ k - *ka], &work[i__ + k - *ka], &ra); |
| 2123 |
|
| 2124 |
/* create nonzero element a(i+k-ka-1,i+k) outside the */ |
| 2125 |
/* band and store it in WORK(m-kb+i+k) */ |
| 2126 |
|
| 2127 |
t = -bb[kb1 - k + (i__ + k) * bb_dim1] * ra1; |
| 2128 |
work[m - *kb + i__ + k] = work[*n + i__ + k - *ka] * t - |
| 2129 |
work[i__ + k - *ka] * ab[(i__ + k) * ab_dim1 + 1]; |
| 2130 |
ab[(i__ + k) * ab_dim1 + 1] = work[i__ + k - *ka] * t + |
| 2131 |
work[*n + i__ + k - *ka] * ab[(i__ + k) * ab_dim1 |
| 2132 |
+ 1]; |
| 2133 |
ra1 = ra; |
| 2134 |
} |
| 2135 |
} |
| 2136 |
/* Computing MAX */ |
| 2137 |
i__4 = 1, i__1 = k + i0 - m + 1; |
| 2138 |
j2 = i__ + k + 1 - std::max(i__4,i__1) * ka1; |
| 2139 |
nr = (j2 + *ka - 1) / ka1; |
| 2140 |
j1 = j2 - (nr - 1) * ka1; |
| 2141 |
if (update) { |
| 2142 |
/* Computing MIN */ |
| 2143 |
i__4 = j2, i__1 = i__ - (*ka << 1) + k - 1; |
| 2144 |
j2t = std::min(i__4,i__1); |
| 2145 |
} else { |
| 2146 |
j2t = j2; |
| 2147 |
} |
| 2148 |
nrt = (j2t + *ka - 1) / ka1; |
| 2149 |
i__4 = j2t; |
| 2150 |
i__1 = ka1; |
| 2151 |
for (j = j1; i__1 < 0 ? j >= i__4 : j <= i__4; j += i__1) { |
| 2152 |
|
| 2153 |
/* create nonzero element a(j-1,j+ka) outside the band */ |
| 2154 |
/* and store it in WORK(j) */ |
| 2155 |
|
| 2156 |
work[j] *= ab[(j + *ka - 1) * ab_dim1 + 1]; |
| 2157 |
ab[(j + *ka - 1) * ab_dim1 + 1] = work[*n + j] * ab[(j + *ka |
| 2158 |
- 1) * ab_dim1 + 1]; |
| 2159 |
/* L570: */ |
| 2160 |
} |
| 2161 |
|
| 2162 |
/* generate rotations in 1st set to annihilate elements which */ |
| 2163 |
/* have been created outside the band */ |
| 2164 |
|
| 2165 |
if (nrt > 0) { |
| 2166 |
dlargv_(&nrt, &ab[(j1 + *ka) * ab_dim1 + 1], &inca, &work[j1], |
| 2167 |
&ka1, &work[*n + j1], &ka1); |
| 2168 |
} |
| 2169 |
if (nr > 0) { |
| 2170 |
|
| 2171 |
/* apply rotations in 1st set from the left */ |
| 2172 |
|
| 2173 |
i__1 = *ka - 1; |
| 2174 |
for (l = 1; l <= i__1; ++l) { |
| 2175 |
dlartv_(&nr, &ab[ka1 - l + (j1 + l) * ab_dim1], &inca, & |
| 2176 |
ab[*ka - l + (j1 + l) * ab_dim1], &inca, &work[*n |
| 2177 |
+ j1], &work[j1], &ka1); |
| 2178 |
/* L580: */ |
| 2179 |
} |
| 2180 |
|
| 2181 |
/* apply rotations in 1st set from both sides to diagonal */ |
| 2182 |
/* blocks */ |
| 2183 |
|
| 2184 |
dlar2v_(&nr, &ab[ka1 + j1 * ab_dim1], &ab[ka1 + (j1 - 1) * |
| 2185 |
ab_dim1], &ab[*ka + j1 * ab_dim1], &inca, &work[*n + |
| 2186 |
j1], &work[j1], &ka1); |
| 2187 |
|
| 2188 |
} |
| 2189 |
|
| 2190 |
/* start applying rotations in 1st set from the right */ |
| 2191 |
|
| 2192 |
i__1 = *kb - k + 1; |
| 2193 |
for (l = *ka - 1; l >= i__1; --l) { |
| 2194 |
nrt = (j2 + l - 1) / ka1; |
| 2195 |
j1t = j2 - (nrt - 1) * ka1; |
| 2196 |
if (nrt > 0) { |
| 2197 |
dlartv_(&nrt, &ab[l + j1t * ab_dim1], &inca, &ab[l + 1 + ( |
| 2198 |
j1t - 1) * ab_dim1], &inca, &work[*n + j1t], & |
| 2199 |
work[j1t], &ka1); |
| 2200 |
} |
| 2201 |
/* L590: */ |
| 2202 |
} |
| 2203 |
|
| 2204 |
if (wantx) { |
| 2205 |
|
| 2206 |
/* post-multiply X by product of rotations in 1st set */ |
| 2207 |
|
| 2208 |
i__1 = j2; |
| 2209 |
i__4 = ka1; |
| 2210 |
for (j = j1; i__4 < 0 ? j >= i__1 : j <= i__1; j += i__4) { |
| 2211 |
drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1 |
| 2212 |
+ 1], &c__1, &work[*n + j], &work[j]); |
| 2213 |
/* L600: */ |
| 2214 |
} |
| 2215 |
} |
| 2216 |
/* L610: */ |
| 2217 |
} |
| 2218 |
|
| 2219 |
if (update) { |
| 2220 |
if (i2 > 0 && kbt > 0) { |
| 2221 |
|
| 2222 |
/* create nonzero element a(i+kbt-ka-1,i+kbt) outside the */ |
| 2223 |
/* band and store it in WORK(m-kb+i+kbt) */ |
| 2224 |
|
| 2225 |
work[m - *kb + i__ + kbt] = -bb[kb1 - kbt + (i__ + kbt) * |
| 2226 |
bb_dim1] * ra1; |
| 2227 |
} |
| 2228 |
} |
| 2229 |
|
| 2230 |
for (k = *kb; k >= 1; --k) { |
| 2231 |
if (update) { |
| 2232 |
/* Computing MAX */ |
| 2233 |
i__3 = 2, i__4 = k + i0 - m; |
| 2234 |
j2 = i__ + k + 1 - std::max(i__3,i__4) * ka1; |
| 2235 |
} else { |
| 2236 |
/* Computing MAX */ |
| 2237 |
i__3 = 1, i__4 = k + i0 - m; |
| 2238 |
j2 = i__ + k + 1 - std::max(i__3,i__4) * ka1; |
| 2239 |
} |
| 2240 |
|
| 2241 |
/* finish applying rotations in 2nd set from the right */ |
| 2242 |
|
| 2243 |
for (l = *kb - k; l >= 1; --l) { |
| 2244 |
nrt = (j2 + *ka + l - 1) / ka1; |
| 2245 |
j1t = j2 - (nrt - 1) * ka1; |
| 2246 |
if (nrt > 0) { |
| 2247 |
dlartv_(&nrt, &ab[l + (j1t + *ka) * ab_dim1], &inca, &ab[ |
| 2248 |
l + 1 + (j1t + *ka - 1) * ab_dim1], &inca, &work[* |
| 2249 |
n + m - *kb + j1t + *ka], &work[m - *kb + j1t + * |
| 2250 |
ka], &ka1); |
| 2251 |
} |
| 2252 |
/* L620: */ |
| 2253 |
} |
| 2254 |
nr = (j2 + *ka - 1) / ka1; |
| 2255 |
j1 = j2 - (nr - 1) * ka1; |
| 2256 |
i__3 = j2; |
| 2257 |
i__4 = ka1; |
| 2258 |
for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) { |
| 2259 |
work[m - *kb + j] = work[m - *kb + j + *ka]; |
| 2260 |
work[*n + m - *kb + j] = work[*n + m - *kb + j + *ka]; |
| 2261 |
/* L630: */ |
| 2262 |
} |
| 2263 |
i__4 = j2; |
| 2264 |
i__3 = ka1; |
| 2265 |
for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) { |
| 2266 |
|
| 2267 |
/* create nonzero element a(j-1,j+ka) outside the band */ |
| 2268 |
/* and store it in WORK(m-kb+j) */ |
| 2269 |
|
| 2270 |
work[m - *kb + j] *= ab[(j + *ka - 1) * ab_dim1 + 1]; |
| 2271 |
ab[(j + *ka - 1) * ab_dim1 + 1] = work[*n + m - *kb + j] * ab[ |
| 2272 |
(j + *ka - 1) * ab_dim1 + 1]; |
| 2273 |
/* L640: */ |
| 2274 |
} |
| 2275 |
if (update) { |
| 2276 |
if (i__ + k > ka1 && k <= kbt) { |
| 2277 |
work[m - *kb + i__ + k - *ka] = work[m - *kb + i__ + k]; |
| 2278 |
} |
| 2279 |
} |
| 2280 |
/* L650: */ |
| 2281 |
} |
| 2282 |
|
| 2283 |
for (k = *kb; k >= 1; --k) { |
| 2284 |
/* Computing MAX */ |
| 2285 |
i__3 = 1, i__4 = k + i0 - m; |
| 2286 |
j2 = i__ + k + 1 - std::max(i__3,i__4) * ka1; |
| 2287 |
nr = (j2 + *ka - 1) / ka1; |
| 2288 |
j1 = j2 - (nr - 1) * ka1; |
| 2289 |
if (nr > 0) { |
| 2290 |
|
| 2291 |
/* generate rotations in 2nd set to annihilate elements */ |
| 2292 |
/* which have been created outside the band */ |
| 2293 |
|
| 2294 |
dlargv_(&nr, &ab[(j1 + *ka) * ab_dim1 + 1], &inca, &work[m - * |
| 2295 |
kb + j1], &ka1, &work[*n + m - *kb + j1], &ka1); |
| 2296 |
|
| 2297 |
/* apply rotations in 2nd set from the left */ |
| 2298 |
|
| 2299 |
i__3 = *ka - 1; |
| 2300 |
for (l = 1; l <= i__3; ++l) { |
| 2301 |
dlartv_(&nr, &ab[ka1 - l + (j1 + l) * ab_dim1], &inca, & |
| 2302 |
ab[*ka - l + (j1 + l) * ab_dim1], &inca, &work[*n |
| 2303 |
+ m - *kb + j1], &work[m - *kb + j1], &ka1); |
| 2304 |
/* L660: */ |
| 2305 |
} |
| 2306 |
|
| 2307 |
/* apply rotations in 2nd set from both sides to diagonal */ |
| 2308 |
/* blocks */ |
| 2309 |
|
| 2310 |
dlar2v_(&nr, &ab[ka1 + j1 * ab_dim1], &ab[ka1 + (j1 - 1) * |
| 2311 |
ab_dim1], &ab[*ka + j1 * ab_dim1], &inca, &work[*n + |
| 2312 |
m - *kb + j1], &work[m - *kb + j1], &ka1); |
| 2313 |
|
| 2314 |
} |
| 2315 |
|
| 2316 |
/* start applying rotations in 2nd set from the right */ |
| 2317 |
|
| 2318 |
i__3 = *kb - k + 1; |
| 2319 |
for (l = *ka - 1; l >= i__3; --l) { |
| 2320 |
nrt = (j2 + l - 1) / ka1; |
| 2321 |
j1t = j2 - (nrt - 1) * ka1; |
| 2322 |
if (nrt > 0) { |
| 2323 |
dlartv_(&nrt, &ab[l + j1t * ab_dim1], &inca, &ab[l + 1 + ( |
| 2324 |
j1t - 1) * ab_dim1], &inca, &work[*n + m - *kb + |
| 2325 |
j1t], &work[m - *kb + j1t], &ka1); |
| 2326 |
} |
| 2327 |
/* L670: */ |
| 2328 |
} |
| 2329 |
|
| 2330 |
if (wantx) { |
| 2331 |
|
| 2332 |
/* post-multiply X by product of rotations in 2nd set */ |
| 2333 |
|
| 2334 |
i__3 = j2; |
| 2335 |
i__4 = ka1; |
| 2336 |
for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) { |
| 2337 |
drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1 |
| 2338 |
+ 1], &c__1, &work[*n + m - *kb + j], &work[m - * |
| 2339 |
kb + j]); |
| 2340 |
/* L680: */ |
| 2341 |
} |
| 2342 |
} |
| 2343 |
/* L690: */ |
| 2344 |
} |
| 2345 |
|
| 2346 |
i__4 = *kb - 1; |
| 2347 |
for (k = 1; k <= i__4; ++k) { |
| 2348 |
/* Computing MAX */ |
| 2349 |
i__3 = 1, i__1 = k + i0 - m + 1; |
| 2350 |
j2 = i__ + k + 1 - std::max(i__3,i__1) * ka1; |
| 2351 |
|
| 2352 |
/* finish applying rotations in 1st set from the right */ |
| 2353 |
|
| 2354 |
for (l = *kb - k; l >= 1; --l) { |
| 2355 |
nrt = (j2 + l - 1) / ka1; |
| 2356 |
j1t = j2 - (nrt - 1) * ka1; |
| 2357 |
if (nrt > 0) { |
| 2358 |
dlartv_(&nrt, &ab[l + j1t * ab_dim1], &inca, &ab[l + 1 + ( |
| 2359 |
j1t - 1) * ab_dim1], &inca, &work[*n + j1t], & |
| 2360 |
work[j1t], &ka1); |
| 2361 |
} |
| 2362 |
/* L700: */ |
| 2363 |
} |
| 2364 |
/* L710: */ |
| 2365 |
} |
| 2366 |
|
| 2367 |
if (*kb > 1) { |
| 2368 |
/* Computing MIN */ |
| 2369 |
i__3 = i__ + *kb; |
| 2370 |
i__4 = std::min(i__3,m) - (*ka << 1) - 1; |
| 2371 |
for (j = 2; j <= i__4; ++j) { |
| 2372 |
work[*n + j] = work[*n + j + *ka]; |
| 2373 |
work[j] = work[j + *ka]; |
| 2374 |
/* L720: */ |
| 2375 |
} |
| 2376 |
} |
| 2377 |
|
| 2378 |
} else { |
| 2379 |
|
| 2380 |
/* Transform A, working with the lower triangle */ |
| 2381 |
|
| 2382 |
if (update) { |
| 2383 |
|
| 2384 |
/* Form inv(S(i))**T * A * inv(S(i)) */ |
| 2385 |
|
| 2386 |
bii = bb[i__ * bb_dim1 + 1]; |
| 2387 |
i__4 = i__; |
| 2388 |
for (j = i1; j <= i__4; ++j) { |
| 2389 |
ab[i__ - j + 1 + j * ab_dim1] /= bii; |
| 2390 |
/* L730: */ |
| 2391 |
} |
| 2392 |
/* Computing MIN */ |
| 2393 |
i__3 = *n, i__1 = i__ + *ka; |
| 2394 |
i__4 = std::min(i__3,i__1); |
| 2395 |
for (j = i__; j <= i__4; ++j) { |
| 2396 |
ab[j - i__ + 1 + i__ * ab_dim1] /= bii; |
| 2397 |
/* L740: */ |
| 2398 |
} |
| 2399 |
i__4 = i__ + kbt; |
| 2400 |
for (k = i__ + 1; k <= i__4; ++k) { |
| 2401 |
i__3 = i__ + kbt; |
| 2402 |
for (j = k; j <= i__3; ++j) { |
| 2403 |
ab[j - k + 1 + k * ab_dim1] = ab[j - k + 1 + k * ab_dim1] |
| 2404 |
- bb[j - i__ + 1 + i__ * bb_dim1] * ab[k - i__ + |
| 2405 |
1 + i__ * ab_dim1] - bb[k - i__ + 1 + i__ * |
| 2406 |
bb_dim1] * ab[j - i__ + 1 + i__ * ab_dim1] + ab[ |
| 2407 |
i__ * ab_dim1 + 1] * bb[j - i__ + 1 + i__ * |
| 2408 |
bb_dim1] * bb[k - i__ + 1 + i__ * bb_dim1]; |
| 2409 |
/* L750: */ |
| 2410 |
} |
| 2411 |
/* Computing MIN */ |
| 2412 |
i__1 = *n, i__2 = i__ + *ka; |
| 2413 |
i__3 = std::min(i__1,i__2); |
| 2414 |
for (j = i__ + kbt + 1; j <= i__3; ++j) { |
| 2415 |
ab[j - k + 1 + k * ab_dim1] -= bb[k - i__ + 1 + i__ * |
| 2416 |
bb_dim1] * ab[j - i__ + 1 + i__ * ab_dim1]; |
| 2417 |
/* L760: */ |
| 2418 |
} |
| 2419 |
/* L770: */ |
| 2420 |
} |
| 2421 |
i__4 = i__; |
| 2422 |
for (j = i1; j <= i__4; ++j) { |
| 2423 |
/* Computing MIN */ |
| 2424 |
i__1 = j + *ka, i__2 = i__ + kbt; |
| 2425 |
i__3 = std::min(i__1,i__2); |
| 2426 |
for (k = i__ + 1; k <= i__3; ++k) { |
| 2427 |
ab[k - j + 1 + j * ab_dim1] -= bb[k - i__ + 1 + i__ * |
| 2428 |
bb_dim1] * ab[i__ - j + 1 + j * ab_dim1]; |
| 2429 |
/* L780: */ |
| 2430 |
} |
| 2431 |
/* L790: */ |
| 2432 |
} |
| 2433 |
|
| 2434 |
if (wantx) { |
| 2435 |
|
| 2436 |
/* post-multiply X by inv(S(i)) */ |
| 2437 |
|
| 2438 |
d__1 = 1. / bii; |
| 2439 |
dscal_(&nx, &d__1, &x[i__ * x_dim1 + 1], &c__1); |
| 2440 |
if (kbt > 0) { |
| 2441 |
dger_(&nx, &kbt, &c_b20, &x[i__ * x_dim1 + 1], &c__1, &bb[ |
| 2442 |
i__ * bb_dim1 + 2], &c__1, &x[(i__ + 1) * x_dim1 |
| 2443 |
+ 1], ldx); |
| 2444 |
} |
| 2445 |
} |
| 2446 |
|
| 2447 |
/* store a(i,i1) in RA1 for use in next loop over K */ |
| 2448 |
|
| 2449 |
ra1 = ab[i__ - i1 + 1 + i1 * ab_dim1]; |
| 2450 |
} |
| 2451 |
|
| 2452 |
/* Generate and apply vectors of rotations to chase all the */ |
| 2453 |
/* existing bulges KA positions up toward the top of the band */ |
| 2454 |
|
| 2455 |
i__4 = *kb - 1; |
| 2456 |
for (k = 1; k <= i__4; ++k) { |
| 2457 |
if (update) { |
| 2458 |
|
| 2459 |
/* Determine the rotations which would annihilate the bulge */ |
| 2460 |
/* which has in theory just been created */ |
| 2461 |
|
| 2462 |
if (i__ + k - ka1 > 0 && i__ + k < m) { |
| 2463 |
|
| 2464 |
/* generate rotation to annihilate a(i,i+k-ka-1) */ |
| 2465 |
|
| 2466 |
dlartg_(&ab[ka1 - k + (i__ + k - *ka) * ab_dim1], &ra1, & |
| 2467 |
work[*n + i__ + k - *ka], &work[i__ + k - *ka], & |
| 2468 |
ra); |
| 2469 |
|
| 2470 |
/* create nonzero element a(i+k,i+k-ka-1) outside the */ |
| 2471 |
/* band and store it in WORK(m-kb+i+k) */ |
| 2472 |
|
| 2473 |
t = -bb[k + 1 + i__ * bb_dim1] * ra1; |
| 2474 |
work[m - *kb + i__ + k] = work[*n + i__ + k - *ka] * t - |
| 2475 |
work[i__ + k - *ka] * ab[ka1 + (i__ + k - *ka) * |
| 2476 |
ab_dim1]; |
| 2477 |
ab[ka1 + (i__ + k - *ka) * ab_dim1] = work[i__ + k - *ka] |
| 2478 |
* t + work[*n + i__ + k - *ka] * ab[ka1 + (i__ + |
| 2479 |
k - *ka) * ab_dim1]; |
| 2480 |
ra1 = ra; |
| 2481 |
} |
| 2482 |
} |
| 2483 |
/* Computing MAX */ |
| 2484 |
i__3 = 1, i__1 = k + i0 - m + 1; |
| 2485 |
j2 = i__ + k + 1 - std::max(i__3,i__1) * ka1; |
| 2486 |
nr = (j2 + *ka - 1) / ka1; |
| 2487 |
j1 = j2 - (nr - 1) * ka1; |
| 2488 |
if (update) { |
| 2489 |
/* Computing MIN */ |
| 2490 |
i__3 = j2, i__1 = i__ - (*ka << 1) + k - 1; |
| 2491 |
j2t = std::min(i__3,i__1); |
| 2492 |
} else { |
| 2493 |
j2t = j2; |
| 2494 |
} |
| 2495 |
nrt = (j2t + *ka - 1) / ka1; |
| 2496 |
i__3 = j2t; |
| 2497 |
i__1 = ka1; |
| 2498 |
for (j = j1; i__1 < 0 ? j >= i__3 : j <= i__3; j += i__1) { |
| 2499 |
|
| 2500 |
/* create nonzero element a(j+ka,j-1) outside the band */ |
| 2501 |
/* and store it in WORK(j) */ |
| 2502 |
|
| 2503 |
work[j] *= ab[ka1 + (j - 1) * ab_dim1]; |
| 2504 |
ab[ka1 + (j - 1) * ab_dim1] = work[*n + j] * ab[ka1 + (j - 1) |
| 2505 |
* ab_dim1]; |
| 2506 |
/* L800: */ |
| 2507 |
} |
| 2508 |
|
| 2509 |
/* generate rotations in 1st set to annihilate elements which */ |
| 2510 |
/* have been created outside the band */ |
| 2511 |
|
| 2512 |
if (nrt > 0) { |
| 2513 |
dlargv_(&nrt, &ab[ka1 + j1 * ab_dim1], &inca, &work[j1], &ka1, |
| 2514 |
&work[*n + j1], &ka1); |
| 2515 |
} |
| 2516 |
if (nr > 0) { |
| 2517 |
|
| 2518 |
/* apply rotations in 1st set from the right */ |
| 2519 |
|
| 2520 |
i__1 = *ka - 1; |
| 2521 |
for (l = 1; l <= i__1; ++l) { |
| 2522 |
dlartv_(&nr, &ab[l + 1 + j1 * ab_dim1], &inca, &ab[l + 2 |
| 2523 |
+ (j1 - 1) * ab_dim1], &inca, &work[*n + j1], & |
| 2524 |
work[j1], &ka1); |
| 2525 |
/* L810: */ |
| 2526 |
} |
| 2527 |
|
| 2528 |
/* apply rotations in 1st set from both sides to diagonal */ |
| 2529 |
/* blocks */ |
| 2530 |
|
| 2531 |
dlar2v_(&nr, &ab[j1 * ab_dim1 + 1], &ab[(j1 - 1) * ab_dim1 + |
| 2532 |
1], &ab[(j1 - 1) * ab_dim1 + 2], &inca, &work[*n + j1] |
| 2533 |
, &work[j1], &ka1); |
| 2534 |
|
| 2535 |
} |
| 2536 |
|
| 2537 |
/* start applying rotations in 1st set from the left */ |
| 2538 |
|
| 2539 |
i__1 = *kb - k + 1; |
| 2540 |
for (l = *ka - 1; l >= i__1; --l) { |
| 2541 |
nrt = (j2 + l - 1) / ka1; |
| 2542 |
j1t = j2 - (nrt - 1) * ka1; |
| 2543 |
if (nrt > 0) { |
| 2544 |
dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t - ka1 + l) * ab_dim1] |
| 2545 |
, &inca, &ab[ka1 - l + (j1t - ka1 + l) * ab_dim1], |
| 2546 |
&inca, &work[*n + j1t], &work[j1t], &ka1); |
| 2547 |
} |
| 2548 |
/* L820: */ |
| 2549 |
} |
| 2550 |
|
| 2551 |
if (wantx) { |
| 2552 |
|
| 2553 |
/* post-multiply X by product of rotations in 1st set */ |
| 2554 |
|
| 2555 |
i__1 = j2; |
| 2556 |
i__3 = ka1; |
| 2557 |
for (j = j1; i__3 < 0 ? j >= i__1 : j <= i__1; j += i__3) { |
| 2558 |
drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1 |
| 2559 |
+ 1], &c__1, &work[*n + j], &work[j]); |
| 2560 |
/* L830: */ |
| 2561 |
} |
| 2562 |
} |
| 2563 |
/* L840: */ |
| 2564 |
} |
| 2565 |
|
| 2566 |
if (update) { |
| 2567 |
if (i2 > 0 && kbt > 0) { |
| 2568 |
|
| 2569 |
/* create nonzero element a(i+kbt,i+kbt-ka-1) outside the */ |
| 2570 |
/* band and store it in WORK(m-kb+i+kbt) */ |
| 2571 |
|
| 2572 |
work[m - *kb + i__ + kbt] = -bb[kbt + 1 + i__ * bb_dim1] * |
| 2573 |
ra1; |
| 2574 |
} |
| 2575 |
} |
| 2576 |
|
| 2577 |
for (k = *kb; k >= 1; --k) { |
| 2578 |
if (update) { |
| 2579 |
/* Computing MAX */ |
| 2580 |
i__4 = 2, i__3 = k + i0 - m; |
| 2581 |
j2 = i__ + k + 1 - std::max(i__4,i__3) * ka1; |
| 2582 |
} else { |
| 2583 |
/* Computing MAX */ |
| 2584 |
i__4 = 1, i__3 = k + i0 - m; |
| 2585 |
j2 = i__ + k + 1 - std::max(i__4,i__3) * ka1; |
| 2586 |
} |
| 2587 |
|
| 2588 |
/* finish applying rotations in 2nd set from the left */ |
| 2589 |
|
| 2590 |
for (l = *kb - k; l >= 1; --l) { |
| 2591 |
nrt = (j2 + *ka + l - 1) / ka1; |
| 2592 |
j1t = j2 - (nrt - 1) * ka1; |
| 2593 |
if (nrt > 0) { |
| 2594 |
dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t + l - 1) * ab_dim1], |
| 2595 |
&inca, &ab[ka1 - l + (j1t + l - 1) * ab_dim1], & |
| 2596 |
inca, &work[*n + m - *kb + j1t + *ka], &work[m - * |
| 2597 |
kb + j1t + *ka], &ka1); |
| 2598 |
} |
| 2599 |
/* L850: */ |
| 2600 |
} |
| 2601 |
nr = (j2 + *ka - 1) / ka1; |
| 2602 |
j1 = j2 - (nr - 1) * ka1; |
| 2603 |
i__4 = j2; |
| 2604 |
i__3 = ka1; |
| 2605 |
for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) { |
| 2606 |
work[m - *kb + j] = work[m - *kb + j + *ka]; |
| 2607 |
work[*n + m - *kb + j] = work[*n + m - *kb + j + *ka]; |
| 2608 |
/* L860: */ |
| 2609 |
} |
| 2610 |
i__3 = j2; |
| 2611 |
i__4 = ka1; |
| 2612 |
for (j = j1; i__4 < 0 ? j >= i__3 : j <= i__3; j += i__4) { |
| 2613 |
|
| 2614 |
/* create nonzero element a(j+ka,j-1) outside the band */ |
| 2615 |
/* and store it in WORK(m-kb+j) */ |
| 2616 |
|
| 2617 |
work[m - *kb + j] *= ab[ka1 + (j - 1) * ab_dim1]; |
| 2618 |
ab[ka1 + (j - 1) * ab_dim1] = work[*n + m - *kb + j] * ab[ka1 |
| 2619 |
+ (j - 1) * ab_dim1]; |
| 2620 |
/* L870: */ |
| 2621 |
} |
| 2622 |
if (update) { |
| 2623 |
if (i__ + k > ka1 && k <= kbt) { |
| 2624 |
work[m - *kb + i__ + k - *ka] = work[m - *kb + i__ + k]; |
| 2625 |
} |
| 2626 |
} |
| 2627 |
/* L880: */ |
| 2628 |
} |
| 2629 |
|
| 2630 |
for (k = *kb; k >= 1; --k) { |
| 2631 |
/* Computing MAX */ |
| 2632 |
i__4 = 1, i__3 = k + i0 - m; |
| 2633 |
j2 = i__ + k + 1 - std::max(i__4,i__3) * ka1; |
| 2634 |
nr = (j2 + *ka - 1) / ka1; |
| 2635 |
j1 = j2 - (nr - 1) * ka1; |
| 2636 |
if (nr > 0) { |
| 2637 |
|
| 2638 |
/* generate rotations in 2nd set to annihilate elements */ |
| 2639 |
/* which have been created outside the band */ |
| 2640 |
|
| 2641 |
dlargv_(&nr, &ab[ka1 + j1 * ab_dim1], &inca, &work[m - *kb + |
| 2642 |
j1], &ka1, &work[*n + m - *kb + j1], &ka1); |
| 2643 |
|
| 2644 |
/* apply rotations in 2nd set from the right */ |
| 2645 |
|
| 2646 |
i__4 = *ka - 1; |
| 2647 |
for (l = 1; l <= i__4; ++l) { |
| 2648 |
dlartv_(&nr, &ab[l + 1 + j1 * ab_dim1], &inca, &ab[l + 2 |
| 2649 |
+ (j1 - 1) * ab_dim1], &inca, &work[*n + m - *kb |
| 2650 |
+ j1], &work[m - *kb + j1], &ka1); |
| 2651 |
/* L890: */ |
| 2652 |
} |
| 2653 |
|
| 2654 |
/* apply rotations in 2nd set from both sides to diagonal */ |
| 2655 |
/* blocks */ |
| 2656 |
|
| 2657 |
dlar2v_(&nr, &ab[j1 * ab_dim1 + 1], &ab[(j1 - 1) * ab_dim1 + |
| 2658 |
1], &ab[(j1 - 1) * ab_dim1 + 2], &inca, &work[*n + m |
| 2659 |
- *kb + j1], &work[m - *kb + j1], &ka1); |
| 2660 |
|
| 2661 |
} |
| 2662 |
|
| 2663 |
/* start applying rotations in 2nd set from the left */ |
| 2664 |
|
| 2665 |
i__4 = *kb - k + 1; |
| 2666 |
for (l = *ka - 1; l >= i__4; --l) { |
| 2667 |
nrt = (j2 + l - 1) / ka1; |
| 2668 |
j1t = j2 - (nrt - 1) * ka1; |
| 2669 |
if (nrt > 0) { |
| 2670 |
dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t - ka1 + l) * ab_dim1] |
| 2671 |
, &inca, &ab[ka1 - l + (j1t - ka1 + l) * ab_dim1], |
| 2672 |
&inca, &work[*n + m - *kb + j1t], &work[m - *kb |
| 2673 |
+ j1t], &ka1); |
| 2674 |
} |
| 2675 |
/* L900: */ |
| 2676 |
} |
| 2677 |
|
| 2678 |
if (wantx) { |
| 2679 |
|
| 2680 |
/* post-multiply X by product of rotations in 2nd set */ |
| 2681 |
|
| 2682 |
i__4 = j2; |
| 2683 |
i__3 = ka1; |
| 2684 |
for (j = j1; i__3 < 0 ? j >= i__4 : j <= i__4; j += i__3) { |
| 2685 |
drot_(&nx, &x[j * x_dim1 + 1], &c__1, &x[(j - 1) * x_dim1 |
| 2686 |
+ 1], &c__1, &work[*n + m - *kb + j], &work[m - * |
| 2687 |
kb + j]); |
| 2688 |
/* L910: */ |
| 2689 |
} |
| 2690 |
} |
| 2691 |
/* L920: */ |
| 2692 |
} |
| 2693 |
|
| 2694 |
i__3 = *kb - 1; |
| 2695 |
for (k = 1; k <= i__3; ++k) { |
| 2696 |
/* Computing MAX */ |
| 2697 |
i__4 = 1, i__1 = k + i0 - m + 1; |
| 2698 |
j2 = i__ + k + 1 - std::max(i__4,i__1) * ka1; |
| 2699 |
|
| 2700 |
/* finish applying rotations in 1st set from the left */ |
| 2701 |
|
| 2702 |
for (l = *kb - k; l >= 1; --l) { |
| 2703 |
nrt = (j2 + l - 1) / ka1; |
| 2704 |
j1t = j2 - (nrt - 1) * ka1; |
| 2705 |
if (nrt > 0) { |
| 2706 |
dlartv_(&nrt, &ab[ka1 - l + 1 + (j1t - ka1 + l) * ab_dim1] |
| 2707 |
, &inca, &ab[ka1 - l + (j1t - ka1 + l) * ab_dim1], |
| 2708 |
&inca, &work[*n + j1t], &work[j1t], &ka1); |
| 2709 |
} |
| 2710 |
/* L930: */ |
| 2711 |
} |
| 2712 |
/* L940: */ |
| 2713 |
} |
| 2714 |
|
| 2715 |
if (*kb > 1) { |
| 2716 |
/* Computing MIN */ |
| 2717 |
i__4 = i__ + *kb; |
| 2718 |
i__3 = std::min(i__4,m) - (*ka << 1) - 1; |
| 2719 |
for (j = 2; j <= i__3; ++j) { |
| 2720 |
work[*n + j] = work[*n + j + *ka]; |
| 2721 |
work[j] = work[j + *ka]; |
| 2722 |
/* L950: */ |
| 2723 |
} |
| 2724 |
} |
| 2725 |
|
| 2726 |
} |
| 2727 |
|
| 2728 |
goto L490; |
| 2729 |
|
| 2730 |
/* End of DSBGST */ |
| 2731 |
|
| 2732 |
} /* dsbgst_ */ |
| 2733 |
|
| 2734 |
/* Subroutine */ int dsbgv_(const char *jobz, const char *uplo, integer *n, integer *ka, |
| 2735 |
integer *kb, double *ab, integer *ldab, double *bb, integer * |
| 2736 |
ldbb, double *w, double *z__, integer *ldz, double *work, |
| 2737 |
integer *info) |
| 2738 |
{ |
| 2739 |
/* System generated locals */ |
| 2740 |
integer ab_dim1, ab_offset, bb_dim1, bb_offset, z_dim1, z_offset, i__1; |
| 2741 |
|
| 2742 |
/* Local variables */ |
| 2743 |
integer inde; |
| 2744 |
char vect[1]; |
| 2745 |
integer iinfo; |
| 2746 |
bool upper, wantz; |
| 2747 |
integer indwrk; |
| 2748 |
|
| 2749 |
|
| 2750 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 2751 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 2752 |
/* November 2006 */ |
| 2753 |
|
| 2754 |
/* .. Scalar Arguments .. */ |
| 2755 |
/* .. */ |
| 2756 |
/* .. Array Arguments .. */ |
| 2757 |
/* .. */ |
| 2758 |
|
| 2759 |
/* Purpose */ |
| 2760 |
/* ======= */ |
| 2761 |
|
| 2762 |
/* DSBGV computes all the eigenvalues, and optionally, the eigenvectors */ |
| 2763 |
/* of a real generalized symmetric-definite banded eigenproblem, of */ |
| 2764 |
/* the form A*x=(lambda)*B*x. Here A and B are assumed to be symmetric */ |
| 2765 |
/* and banded, and B is also positive definite. */ |
| 2766 |
|
| 2767 |
/* Arguments */ |
| 2768 |
/* ========= */ |
| 2769 |
|
| 2770 |
/* JOBZ (input) CHARACTER*1 */ |
| 2771 |
/* = 'N': Compute eigenvalues only; */ |
| 2772 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 2773 |
|
| 2774 |
/* UPLO (input) CHARACTER*1 */ |
| 2775 |
/* = 'U': Upper triangles of A and B are stored; */ |
| 2776 |
/* = 'L': Lower triangles of A and B are stored. */ |
| 2777 |
|
| 2778 |
/* N (input) INTEGER */ |
| 2779 |
/* The order of the matrices A and B. N >= 0. */ |
| 2780 |
|
| 2781 |
/* KA (input) INTEGER */ |
| 2782 |
/* The number of superdiagonals of the matrix A if UPLO = 'U', */ |
| 2783 |
/* or the number of subdiagonals if UPLO = 'L'. KA >= 0. */ |
| 2784 |
|
| 2785 |
/* KB (input) INTEGER */ |
| 2786 |
/* The number of superdiagonals of the matrix B if UPLO = 'U', */ |
| 2787 |
/* or the number of subdiagonals if UPLO = 'L'. KB >= 0. */ |
| 2788 |
|
| 2789 |
/* AB (input/output) DOUBLE PRECISION array, dimension (LDAB, N) */ |
| 2790 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 2791 |
/* matrix A, stored in the first ka+1 rows of the array. The */ |
| 2792 |
/* j-th column of A is stored in the j-th column of the array AB */ |
| 2793 |
/* as follows: */ |
| 2794 |
/* if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; */ |
| 2795 |
/* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+ka). */ |
| 2796 |
|
| 2797 |
/* On exit, the contents of AB are destroyed. */ |
| 2798 |
|
| 2799 |
/* LDAB (input) INTEGER */ |
| 2800 |
/* The leading dimension of the array AB. LDAB >= KA+1. */ |
| 2801 |
|
| 2802 |
/* BB (input/output) DOUBLE PRECISION array, dimension (LDBB, N) */ |
| 2803 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 2804 |
/* matrix B, stored in the first kb+1 rows of the array. The */ |
| 2805 |
/* j-th column of B is stored in the j-th column of the array BB */ |
| 2806 |
/* as follows: */ |
| 2807 |
/* if UPLO = 'U', BB(kb+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j; */ |
| 2808 |
/* if UPLO = 'L', BB(1+i-j,j) = B(i,j) for j<=i<=min(n,j+kb). */ |
| 2809 |
|
| 2810 |
/* On exit, the factor S from the split Cholesky factorization */ |
| 2811 |
/* B = S**T*S, as returned by DPBSTF. */ |
| 2812 |
|
| 2813 |
/* LDBB (input) INTEGER */ |
| 2814 |
/* The leading dimension of the array BB. LDBB >= KB+1. */ |
| 2815 |
|
| 2816 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 2817 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 2818 |
|
| 2819 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 2820 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */ |
| 2821 |
/* eigenvectors, with the i-th column of Z holding the */ |
| 2822 |
/* eigenvector associated with W(i). The eigenvectors are */ |
| 2823 |
/* normalized so that Z**T*B*Z = I. */ |
| 2824 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 2825 |
|
| 2826 |
/* LDZ (input) INTEGER */ |
| 2827 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 2828 |
/* JOBZ = 'V', LDZ >= N. */ |
| 2829 |
|
| 2830 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */ |
| 2831 |
|
| 2832 |
/* INFO (output) INTEGER */ |
| 2833 |
/* = 0: successful exit */ |
| 2834 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 2835 |
/* > 0: if INFO = i, and i is: */ |
| 2836 |
/* <= N: the algorithm failed to converge: */ |
| 2837 |
/* i off-diagonal elements of an intermediate */ |
| 2838 |
/* tridiagonal form did not converge to zero; */ |
| 2839 |
/* > N: if INFO = N + i, for 1 <= i <= N, then DPBSTF */ |
| 2840 |
/* returned INFO = i: B is not positive definite. */ |
| 2841 |
/* The factorization of B could not be completed and */ |
| 2842 |
/* no eigenvalues or eigenvectors were computed. */ |
| 2843 |
|
| 2844 |
/* ===================================================================== */ |
| 2845 |
|
| 2846 |
/* .. Local Scalars .. */ |
| 2847 |
/* .. */ |
| 2848 |
/* .. External Functions .. */ |
| 2849 |
/* .. */ |
| 2850 |
/* .. External Subroutines .. */ |
| 2851 |
/* .. */ |
| 2852 |
/* .. Executable Statements .. */ |
| 2853 |
|
| 2854 |
/* Test the input parameters. */ |
| 2855 |
|
| 2856 |
/* Parameter adjustments */ |
| 2857 |
ab_dim1 = *ldab; |
| 2858 |
ab_offset = 1 + ab_dim1; |
| 2859 |
ab -= ab_offset; |
| 2860 |
bb_dim1 = *ldbb; |
| 2861 |
bb_offset = 1 + bb_dim1; |
| 2862 |
bb -= bb_offset; |
| 2863 |
--w; |
| 2864 |
z_dim1 = *ldz; |
| 2865 |
z_offset = 1 + z_dim1; |
| 2866 |
z__ -= z_offset; |
| 2867 |
--work; |
| 2868 |
|
| 2869 |
/* Function Body */ |
| 2870 |
wantz = lsame_(jobz, "V"); |
| 2871 |
upper = lsame_(uplo, "U"); |
| 2872 |
|
| 2873 |
*info = 0; |
| 2874 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 2875 |
*info = -1; |
| 2876 |
} else if (! (upper || lsame_(uplo, "L"))) { |
| 2877 |
*info = -2; |
| 2878 |
} else if (*n < 0) { |
| 2879 |
*info = -3; |
| 2880 |
} else if (*ka < 0) { |
| 2881 |
*info = -4; |
| 2882 |
} else if (*kb < 0 || *kb > *ka) { |
| 2883 |
*info = -5; |
| 2884 |
} else if (*ldab < *ka + 1) { |
| 2885 |
*info = -7; |
| 2886 |
} else if (*ldbb < *kb + 1) { |
| 2887 |
*info = -9; |
| 2888 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 2889 |
*info = -12; |
| 2890 |
} |
| 2891 |
if (*info != 0) { |
| 2892 |
i__1 = -(*info); |
| 2893 |
xerbla_("DSBGV ", &i__1); |
| 2894 |
return 0; |
| 2895 |
} |
| 2896 |
|
| 2897 |
/* Quick return if possible */ |
| 2898 |
|
| 2899 |
if (*n == 0) { |
| 2900 |
return 0; |
| 2901 |
} |
| 2902 |
|
| 2903 |
/* Form a split Cholesky factorization of B. */ |
| 2904 |
|
| 2905 |
dpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info); |
| 2906 |
if (*info != 0) { |
| 2907 |
*info = *n + *info; |
| 2908 |
return 0; |
| 2909 |
} |
| 2910 |
|
| 2911 |
/* Transform problem to standard eigenvalue problem. */ |
| 2912 |
|
| 2913 |
inde = 1; |
| 2914 |
indwrk = inde + *n; |
| 2915 |
dsbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb, |
| 2916 |
&z__[z_offset], ldz, &work[indwrk], &iinfo) |
| 2917 |
; |
| 2918 |
|
| 2919 |
/* Reduce to tridiagonal form. */ |
| 2920 |
|
| 2921 |
if (wantz) { |
| 2922 |
*(unsigned char *)vect = 'U'; |
| 2923 |
} else { |
| 2924 |
*(unsigned char *)vect = 'N'; |
| 2925 |
} |
| 2926 |
dsbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &w[1], &work[inde], &z__[ |
| 2927 |
z_offset], ldz, &work[indwrk], &iinfo); |
| 2928 |
|
| 2929 |
/* For eigenvalues only, call DSTERF. For eigenvectors, call SSTEQR. */ |
| 2930 |
|
| 2931 |
if (! wantz) { |
| 2932 |
dsterf_(n, &w[1], &work[inde], info); |
| 2933 |
} else { |
| 2934 |
dsteqr_(jobz, n, &w[1], &work[inde], &z__[z_offset], ldz, &work[ |
| 2935 |
indwrk], info); |
| 2936 |
} |
| 2937 |
return 0; |
| 2938 |
|
| 2939 |
/* End of DSBGV */ |
| 2940 |
|
| 2941 |
} /* dsbgv_ */ |
| 2942 |
|
| 2943 |
/* Subroutine */ int dsbgvd_(const char *jobz, const char *uplo, integer *n, integer *ka, |
| 2944 |
integer *kb, double *ab, integer *ldab, double *bb, integer * |
| 2945 |
ldbb, double *w, double *z__, integer *ldz, double *work, |
| 2946 |
integer *lwork, integer *iwork, integer *liwork, integer *info) |
| 2947 |
{ |
| 2948 |
/* Table of constant values */ |
| 2949 |
static double c_b12 = 1.; |
| 2950 |
static double c_b13 = 0.; |
| 2951 |
|
| 2952 |
/* System generated locals */ |
| 2953 |
integer ab_dim1, ab_offset, bb_dim1, bb_offset, z_dim1, z_offset, i__1; |
| 2954 |
|
| 2955 |
/* Local variables */ |
| 2956 |
integer inde; |
| 2957 |
char vect[1]; |
| 2958 |
integer iinfo, lwmin; |
| 2959 |
bool upper, wantz; |
| 2960 |
integer indwk2, llwrk2; |
| 2961 |
integer indwrk, liwmin; |
| 2962 |
bool lquery; |
| 2963 |
|
| 2964 |
|
| 2965 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 2966 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 2967 |
/* November 2006 */ |
| 2968 |
|
| 2969 |
/* .. Scalar Arguments .. */ |
| 2970 |
/* .. */ |
| 2971 |
/* .. Array Arguments .. */ |
| 2972 |
/* .. */ |
| 2973 |
|
| 2974 |
/* Purpose */ |
| 2975 |
/* ======= */ |
| 2976 |
|
| 2977 |
/* DSBGVD computes all the eigenvalues, and optionally, the eigenvectors */ |
| 2978 |
/* of a real generalized symmetric-definite banded eigenproblem, of the */ |
| 2979 |
/* form A*x=(lambda)*B*x. Here A and B are assumed to be symmetric and */ |
| 2980 |
/* banded, and B is also positive definite. If eigenvectors are */ |
| 2981 |
/* desired, it uses a divide and conquer algorithm. */ |
| 2982 |
|
| 2983 |
/* The divide and conquer algorithm makes very mild assumptions about */ |
| 2984 |
/* floating point arithmetic. It will work on machines with a guard */ |
| 2985 |
/* digit in add/subtract, or on those binary machines without guard */ |
| 2986 |
/* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ |
| 2987 |
/* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ |
| 2988 |
/* without guard digits, but we know of none. */ |
| 2989 |
|
| 2990 |
/* Arguments */ |
| 2991 |
/* ========= */ |
| 2992 |
|
| 2993 |
/* JOBZ (input) CHARACTER*1 */ |
| 2994 |
/* = 'N': Compute eigenvalues only; */ |
| 2995 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 2996 |
|
| 2997 |
/* UPLO (input) CHARACTER*1 */ |
| 2998 |
/* = 'U': Upper triangles of A and B are stored; */ |
| 2999 |
/* = 'L': Lower triangles of A and B are stored. */ |
| 3000 |
|
| 3001 |
/* N (input) INTEGER */ |
| 3002 |
/* The order of the matrices A and B. N >= 0. */ |
| 3003 |
|
| 3004 |
/* KA (input) INTEGER */ |
| 3005 |
/* The number of superdiagonals of the matrix A if UPLO = 'U', */ |
| 3006 |
/* or the number of subdiagonals if UPLO = 'L'. KA >= 0. */ |
| 3007 |
|
| 3008 |
/* KB (input) INTEGER */ |
| 3009 |
/* The number of superdiagonals of the matrix B if UPLO = 'U', */ |
| 3010 |
/* or the number of subdiagonals if UPLO = 'L'. KB >= 0. */ |
| 3011 |
|
| 3012 |
/* AB (input/output) DOUBLE PRECISION array, dimension (LDAB, N) */ |
| 3013 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 3014 |
/* matrix A, stored in the first ka+1 rows of the array. The */ |
| 3015 |
/* j-th column of A is stored in the j-th column of the array AB */ |
| 3016 |
/* as follows: */ |
| 3017 |
/* if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; */ |
| 3018 |
/* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+ka). */ |
| 3019 |
|
| 3020 |
/* On exit, the contents of AB are destroyed. */ |
| 3021 |
|
| 3022 |
/* LDAB (input) INTEGER */ |
| 3023 |
/* The leading dimension of the array AB. LDAB >= KA+1. */ |
| 3024 |
|
| 3025 |
/* BB (input/output) DOUBLE PRECISION array, dimension (LDBB, N) */ |
| 3026 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 3027 |
/* matrix B, stored in the first kb+1 rows of the array. The */ |
| 3028 |
/* j-th column of B is stored in the j-th column of the array BB */ |
| 3029 |
/* as follows: */ |
| 3030 |
/* if UPLO = 'U', BB(ka+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j; */ |
| 3031 |
/* if UPLO = 'L', BB(1+i-j,j) = B(i,j) for j<=i<=min(n,j+kb). */ |
| 3032 |
|
| 3033 |
/* On exit, the factor S from the split Cholesky factorization */ |
| 3034 |
/* B = S**T*S, as returned by DPBSTF. */ |
| 3035 |
|
| 3036 |
/* LDBB (input) INTEGER */ |
| 3037 |
/* The leading dimension of the array BB. LDBB >= KB+1. */ |
| 3038 |
|
| 3039 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 3040 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 3041 |
|
| 3042 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 3043 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */ |
| 3044 |
/* eigenvectors, with the i-th column of Z holding the */ |
| 3045 |
/* eigenvector associated with W(i). The eigenvectors are */ |
| 3046 |
/* normalized so Z**T*B*Z = I. */ |
| 3047 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 3048 |
|
| 3049 |
/* LDZ (input) INTEGER */ |
| 3050 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 3051 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 3052 |
|
| 3053 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 3054 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 3055 |
|
| 3056 |
/* LWORK (input) INTEGER */ |
| 3057 |
/* The dimension of the array WORK. */ |
| 3058 |
/* If N <= 1, LWORK >= 1. */ |
| 3059 |
/* If JOBZ = 'N' and N > 1, LWORK >= 3*N. */ |
| 3060 |
/* If JOBZ = 'V' and N > 1, LWORK >= 1 + 5*N + 2*N**2. */ |
| 3061 |
|
| 3062 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 3063 |
/* only calculates the optimal sizes of the WORK and IWORK */ |
| 3064 |
/* arrays, returns these values as the first entries of the WORK */ |
| 3065 |
/* and IWORK arrays, and no error message related to LWORK or */ |
| 3066 |
/* LIWORK is issued by XERBLA. */ |
| 3067 |
|
| 3068 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 3069 |
/* On exit, if LIWORK > 0, IWORK(1) returns the optimal LIWORK. */ |
| 3070 |
|
| 3071 |
/* LIWORK (input) INTEGER */ |
| 3072 |
/* The dimension of the array IWORK. */ |
| 3073 |
/* If JOBZ = 'N' or N <= 1, LIWORK >= 1. */ |
| 3074 |
/* If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N. */ |
| 3075 |
|
| 3076 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 3077 |
/* routine only calculates the optimal sizes of the WORK and */ |
| 3078 |
/* IWORK arrays, returns these values as the first entries of */ |
| 3079 |
/* the WORK and IWORK arrays, and no error message related to */ |
| 3080 |
/* LWORK or LIWORK is issued by XERBLA. */ |
| 3081 |
|
| 3082 |
/* INFO (output) INTEGER */ |
| 3083 |
/* = 0: successful exit */ |
| 3084 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 3085 |
/* > 0: if INFO = i, and i is: */ |
| 3086 |
/* <= N: the algorithm failed to converge: */ |
| 3087 |
/* i off-diagonal elements of an intermediate */ |
| 3088 |
/* tridiagonal form did not converge to zero; */ |
| 3089 |
/* > N: if INFO = N + i, for 1 <= i <= N, then DPBSTF */ |
| 3090 |
/* returned INFO = i: B is not positive definite. */ |
| 3091 |
/* The factorization of B could not be completed and */ |
| 3092 |
/* no eigenvalues or eigenvectors were computed. */ |
| 3093 |
|
| 3094 |
/* Further Details */ |
| 3095 |
/* =============== */ |
| 3096 |
|
| 3097 |
/* Based on contributions by */ |
| 3098 |
/* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */ |
| 3099 |
|
| 3100 |
/* ===================================================================== */ |
| 3101 |
|
| 3102 |
/* .. Parameters .. */ |
| 3103 |
/* .. */ |
| 3104 |
/* .. Local Scalars .. */ |
| 3105 |
/* .. */ |
| 3106 |
/* .. External Functions .. */ |
| 3107 |
/* .. */ |
| 3108 |
/* .. External Subroutines .. */ |
| 3109 |
/* .. */ |
| 3110 |
/* .. Executable Statements .. */ |
| 3111 |
|
| 3112 |
/* Test the input parameters. */ |
| 3113 |
|
| 3114 |
/* Parameter adjustments */ |
| 3115 |
ab_dim1 = *ldab; |
| 3116 |
ab_offset = 1 + ab_dim1; |
| 3117 |
ab -= ab_offset; |
| 3118 |
bb_dim1 = *ldbb; |
| 3119 |
bb_offset = 1 + bb_dim1; |
| 3120 |
bb -= bb_offset; |
| 3121 |
--w; |
| 3122 |
z_dim1 = *ldz; |
| 3123 |
z_offset = 1 + z_dim1; |
| 3124 |
z__ -= z_offset; |
| 3125 |
--work; |
| 3126 |
--iwork; |
| 3127 |
|
| 3128 |
/* Function Body */ |
| 3129 |
wantz = lsame_(jobz, "V"); |
| 3130 |
upper = lsame_(uplo, "U"); |
| 3131 |
lquery = *lwork == -1 || *liwork == -1; |
| 3132 |
|
| 3133 |
*info = 0; |
| 3134 |
if (*n <= 1) { |
| 3135 |
liwmin = 1; |
| 3136 |
lwmin = 1; |
| 3137 |
} else if (wantz) { |
| 3138 |
liwmin = *n * 5 + 3; |
| 3139 |
/* Computing 2nd power */ |
| 3140 |
i__1 = *n; |
| 3141 |
lwmin = *n * 5 + 1 + (i__1 * i__1 << 1); |
| 3142 |
} else { |
| 3143 |
liwmin = 1; |
| 3144 |
lwmin = *n << 1; |
| 3145 |
} |
| 3146 |
|
| 3147 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 3148 |
*info = -1; |
| 3149 |
} else if (! (upper || lsame_(uplo, "L"))) { |
| 3150 |
*info = -2; |
| 3151 |
} else if (*n < 0) { |
| 3152 |
*info = -3; |
| 3153 |
} else if (*ka < 0) { |
| 3154 |
*info = -4; |
| 3155 |
} else if (*kb < 0 || *kb > *ka) { |
| 3156 |
*info = -5; |
| 3157 |
} else if (*ldab < *ka + 1) { |
| 3158 |
*info = -7; |
| 3159 |
} else if (*ldbb < *kb + 1) { |
| 3160 |
*info = -9; |
| 3161 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 3162 |
*info = -12; |
| 3163 |
} |
| 3164 |
|
| 3165 |
if (*info == 0) { |
| 3166 |
work[1] = (double) lwmin; |
| 3167 |
iwork[1] = liwmin; |
| 3168 |
|
| 3169 |
if (*lwork < lwmin && ! lquery) { |
| 3170 |
*info = -14; |
| 3171 |
} else if (*liwork < liwmin && ! lquery) { |
| 3172 |
*info = -16; |
| 3173 |
} |
| 3174 |
} |
| 3175 |
|
| 3176 |
if (*info != 0) { |
| 3177 |
i__1 = -(*info); |
| 3178 |
xerbla_("DSBGVD", &i__1); |
| 3179 |
return 0; |
| 3180 |
} else if (lquery) { |
| 3181 |
return 0; |
| 3182 |
} |
| 3183 |
|
| 3184 |
/* Quick return if possible */ |
| 3185 |
|
| 3186 |
if (*n == 0) { |
| 3187 |
return 0; |
| 3188 |
} |
| 3189 |
|
| 3190 |
/* Form a split Cholesky factorization of B. */ |
| 3191 |
|
| 3192 |
dpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info); |
| 3193 |
if (*info != 0) { |
| 3194 |
*info = *n + *info; |
| 3195 |
return 0; |
| 3196 |
} |
| 3197 |
|
| 3198 |
/* Transform problem to standard eigenvalue problem. */ |
| 3199 |
|
| 3200 |
inde = 1; |
| 3201 |
indwrk = inde + *n; |
| 3202 |
indwk2 = indwrk + *n * *n; |
| 3203 |
llwrk2 = *lwork - indwk2 + 1; |
| 3204 |
dsbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb, |
| 3205 |
&z__[z_offset], ldz, &work[indwrk], &iinfo) |
| 3206 |
; |
| 3207 |
|
| 3208 |
/* Reduce to tridiagonal form. */ |
| 3209 |
|
| 3210 |
if (wantz) { |
| 3211 |
*(unsigned char *)vect = 'U'; |
| 3212 |
} else { |
| 3213 |
*(unsigned char *)vect = 'N'; |
| 3214 |
} |
| 3215 |
dsbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &w[1], &work[inde], &z__[ |
| 3216 |
z_offset], ldz, &work[indwrk], &iinfo); |
| 3217 |
|
| 3218 |
/* For eigenvalues only, call DSTERF. For eigenvectors, call SSTEDC. */ |
| 3219 |
|
| 3220 |
if (! wantz) { |
| 3221 |
dsterf_(n, &w[1], &work[inde], info); |
| 3222 |
} else { |
| 3223 |
dstedc_("I", n, &w[1], &work[inde], &work[indwrk], n, &work[indwk2], & |
| 3224 |
llwrk2, &iwork[1], liwork, info); |
| 3225 |
dgemm_("N", "N", n, n, n, &c_b12, &z__[z_offset], ldz, &work[indwrk], |
| 3226 |
n, &c_b13, &work[indwk2], n); |
| 3227 |
dlacpy_("A", n, n, &work[indwk2], n, &z__[z_offset], ldz); |
| 3228 |
} |
| 3229 |
|
| 3230 |
work[1] = (double) lwmin; |
| 3231 |
iwork[1] = liwmin; |
| 3232 |
|
| 3233 |
return 0; |
| 3234 |
|
| 3235 |
/* End of DSBGVD */ |
| 3236 |
|
| 3237 |
} /* dsbgvd_ */ |
| 3238 |
|
| 3239 |
/* Subroutine */ int dsbgvx_(const char *jobz, const char *range, const char *uplo, integer *n, |
| 3240 |
integer *ka, integer *kb, double *ab, integer *ldab, double * |
| 3241 |
bb, integer *ldbb, double *q, integer *ldq, double *vl, |
| 3242 |
double *vu, integer *il, integer *iu, double *abstol, integer |
| 3243 |
*m, double *w, double *z__, integer *ldz, double *work, |
| 3244 |
integer *iwork, integer *ifail, integer *info) |
| 3245 |
{ |
| 3246 |
/* Table of constant values */ |
| 3247 |
static integer c__1 = 1; |
| 3248 |
static double c_b25 = 1.; |
| 3249 |
static double c_b27 = 0.; |
| 3250 |
|
| 3251 |
/* System generated locals */ |
| 3252 |
integer ab_dim1, ab_offset, bb_dim1, bb_offset, q_dim1, q_offset, z_dim1, |
| 3253 |
z_offset, i__1, i__2; |
| 3254 |
|
| 3255 |
/* Local variables */ |
| 3256 |
integer i__, j, jj; |
| 3257 |
double tmp1; |
| 3258 |
integer indd, inde; |
| 3259 |
char vect[1]; |
| 3260 |
bool test; |
| 3261 |
integer itmp1, indee; |
| 3262 |
integer iinfo; |
| 3263 |
char order[1]; |
| 3264 |
bool upper, wantz, alleig, indeig; |
| 3265 |
integer indibl; |
| 3266 |
bool valeig; |
| 3267 |
integer indisp; |
| 3268 |
integer indiwo; |
| 3269 |
integer indwrk; |
| 3270 |
integer nsplit; |
| 3271 |
|
| 3272 |
|
| 3273 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 3274 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 3275 |
/* November 2006 */ |
| 3276 |
|
| 3277 |
/* .. Scalar Arguments .. */ |
| 3278 |
/* .. */ |
| 3279 |
/* .. Array Arguments .. */ |
| 3280 |
/* .. */ |
| 3281 |
|
| 3282 |
/* Purpose */ |
| 3283 |
/* ======= */ |
| 3284 |
|
| 3285 |
/* DSBGVX computes selected eigenvalues, and optionally, eigenvectors */ |
| 3286 |
/* of a real generalized symmetric-definite banded eigenproblem, of */ |
| 3287 |
/* the form A*x=(lambda)*B*x. Here A and B are assumed to be symmetric */ |
| 3288 |
/* and banded, and B is also positive definite. Eigenvalues and */ |
| 3289 |
/* eigenvectors can be selected by specifying either all eigenvalues, */ |
| 3290 |
/* a range of values or a range of indices for the desired eigenvalues. */ |
| 3291 |
|
| 3292 |
/* Arguments */ |
| 3293 |
/* ========= */ |
| 3294 |
|
| 3295 |
/* JOBZ (input) CHARACTER*1 */ |
| 3296 |
/* = 'N': Compute eigenvalues only; */ |
| 3297 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 3298 |
|
| 3299 |
/* RANGE (input) CHARACTER*1 */ |
| 3300 |
/* = 'A': all eigenvalues will be found. */ |
| 3301 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 3302 |
/* will be found. */ |
| 3303 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 3304 |
|
| 3305 |
/* UPLO (input) CHARACTER*1 */ |
| 3306 |
/* = 'U': Upper triangles of A and B are stored; */ |
| 3307 |
/* = 'L': Lower triangles of A and B are stored. */ |
| 3308 |
|
| 3309 |
/* N (input) INTEGER */ |
| 3310 |
/* The order of the matrices A and B. N >= 0. */ |
| 3311 |
|
| 3312 |
/* KA (input) INTEGER */ |
| 3313 |
/* The number of superdiagonals of the matrix A if UPLO = 'U', */ |
| 3314 |
/* or the number of subdiagonals if UPLO = 'L'. KA >= 0. */ |
| 3315 |
|
| 3316 |
/* KB (input) INTEGER */ |
| 3317 |
/* The number of superdiagonals of the matrix B if UPLO = 'U', */ |
| 3318 |
/* or the number of subdiagonals if UPLO = 'L'. KB >= 0. */ |
| 3319 |
|
| 3320 |
/* AB (input/output) DOUBLE PRECISION array, dimension (LDAB, N) */ |
| 3321 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 3322 |
/* matrix A, stored in the first ka+1 rows of the array. The */ |
| 3323 |
/* j-th column of A is stored in the j-th column of the array AB */ |
| 3324 |
/* as follows: */ |
| 3325 |
/* if UPLO = 'U', AB(ka+1+i-j,j) = A(i,j) for max(1,j-ka)<=i<=j; */ |
| 3326 |
/* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+ka). */ |
| 3327 |
|
| 3328 |
/* On exit, the contents of AB are destroyed. */ |
| 3329 |
|
| 3330 |
/* LDAB (input) INTEGER */ |
| 3331 |
/* The leading dimension of the array AB. LDAB >= KA+1. */ |
| 3332 |
|
| 3333 |
/* BB (input/output) DOUBLE PRECISION array, dimension (LDBB, N) */ |
| 3334 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 3335 |
/* matrix B, stored in the first kb+1 rows of the array. The */ |
| 3336 |
/* j-th column of B is stored in the j-th column of the array BB */ |
| 3337 |
/* as follows: */ |
| 3338 |
/* if UPLO = 'U', BB(ka+1+i-j,j) = B(i,j) for max(1,j-kb)<=i<=j; */ |
| 3339 |
/* if UPLO = 'L', BB(1+i-j,j) = B(i,j) for j<=i<=min(n,j+kb). */ |
| 3340 |
|
| 3341 |
/* On exit, the factor S from the split Cholesky factorization */ |
| 3342 |
/* B = S**T*S, as returned by DPBSTF. */ |
| 3343 |
|
| 3344 |
/* LDBB (input) INTEGER */ |
| 3345 |
/* The leading dimension of the array BB. LDBB >= KB+1. */ |
| 3346 |
|
| 3347 |
/* Q (output) DOUBLE PRECISION array, dimension (LDQ, N) */ |
| 3348 |
/* If JOBZ = 'V', the n-by-n matrix used in the reduction of */ |
| 3349 |
/* A*x = (lambda)*B*x to standard form, i.e. C*x = (lambda)*x, */ |
| 3350 |
/* and consequently C to tridiagonal form. */ |
| 3351 |
/* If JOBZ = 'N', the array Q is not referenced. */ |
| 3352 |
|
| 3353 |
/* LDQ (input) INTEGER */ |
| 3354 |
/* The leading dimension of the array Q. If JOBZ = 'N', */ |
| 3355 |
/* LDQ >= 1. If JOBZ = 'V', LDQ >= max(1,N). */ |
| 3356 |
|
| 3357 |
/* VL (input) DOUBLE PRECISION */ |
| 3358 |
/* VU (input) DOUBLE PRECISION */ |
| 3359 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 3360 |
/* be searched for eigenvalues. VL < VU. */ |
| 3361 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 3362 |
|
| 3363 |
/* IL (input) INTEGER */ |
| 3364 |
/* IU (input) INTEGER */ |
| 3365 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 3366 |
/* smallest and largest eigenvalues to be returned. */ |
| 3367 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 3368 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 3369 |
|
| 3370 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 3371 |
/* The absolute error tolerance for the eigenvalues. */ |
| 3372 |
/* An approximate eigenvalue is accepted as converged */ |
| 3373 |
/* when it is determined to lie in an interval [a,b] */ |
| 3374 |
/* of width less than or equal to */ |
| 3375 |
|
| 3376 |
/* ABSTOL + EPS * max( |a|,|b| ) , */ |
| 3377 |
|
| 3378 |
/* where EPS is the machine precision. If ABSTOL is less than */ |
| 3379 |
/* or equal to zero, then EPS*|T| will be used in its place, */ |
| 3380 |
/* where |T| is the 1-norm of the tridiagonal matrix obtained */ |
| 3381 |
/* by reducing A to tridiagonal form. */ |
| 3382 |
|
| 3383 |
/* Eigenvalues will be computed most accurately when ABSTOL is */ |
| 3384 |
/* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */ |
| 3385 |
/* If this routine returns with INFO>0, indicating that some */ |
| 3386 |
/* eigenvectors did not converge, try setting ABSTOL to */ |
| 3387 |
/* 2*DLAMCH('S'). */ |
| 3388 |
|
| 3389 |
/* M (output) INTEGER */ |
| 3390 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 3391 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 3392 |
|
| 3393 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 3394 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 3395 |
|
| 3396 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 3397 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */ |
| 3398 |
/* eigenvectors, with the i-th column of Z holding the */ |
| 3399 |
/* eigenvector associated with W(i). The eigenvectors are */ |
| 3400 |
/* normalized so Z**T*B*Z = I. */ |
| 3401 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 3402 |
|
| 3403 |
/* LDZ (input) INTEGER */ |
| 3404 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 3405 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 3406 |
|
| 3407 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (7*N) */ |
| 3408 |
|
| 3409 |
/* IWORK (workspace/output) INTEGER array, dimension (5*N) */ |
| 3410 |
|
| 3411 |
/* IFAIL (output) INTEGER array, dimension (M) */ |
| 3412 |
/* If JOBZ = 'V', then if INFO = 0, the first M elements of */ |
| 3413 |
/* IFAIL are zero. If INFO > 0, then IFAIL contains the */ |
| 3414 |
/* indices of the eigenvalues that failed to converge. */ |
| 3415 |
/* If JOBZ = 'N', then IFAIL is not referenced. */ |
| 3416 |
|
| 3417 |
/* INFO (output) INTEGER */ |
| 3418 |
/* = 0 : successful exit */ |
| 3419 |
/* < 0 : if INFO = -i, the i-th argument had an illegal value */ |
| 3420 |
/* <= N: if INFO = i, then i eigenvectors failed to converge. */ |
| 3421 |
/* Their indices are stored in IFAIL. */ |
| 3422 |
/* > N : DPBSTF returned an error code; i.e., */ |
| 3423 |
/* if INFO = N + i, for 1 <= i <= N, then the leading */ |
| 3424 |
/* minor of order i of B is not positive definite. */ |
| 3425 |
/* The factorization of B could not be completed and */ |
| 3426 |
/* no eigenvalues or eigenvectors were computed. */ |
| 3427 |
|
| 3428 |
/* Further Details */ |
| 3429 |
/* =============== */ |
| 3430 |
|
| 3431 |
/* Based on contributions by */ |
| 3432 |
/* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */ |
| 3433 |
|
| 3434 |
/* ===================================================================== */ |
| 3435 |
|
| 3436 |
/* .. Parameters .. */ |
| 3437 |
/* .. */ |
| 3438 |
/* .. Local Scalars .. */ |
| 3439 |
/* .. */ |
| 3440 |
/* .. External Functions .. */ |
| 3441 |
/* .. */ |
| 3442 |
/* .. External Subroutines .. */ |
| 3443 |
/* .. */ |
| 3444 |
/* .. Intrinsic Functions .. */ |
| 3445 |
/* .. */ |
| 3446 |
/* .. Executable Statements .. */ |
| 3447 |
|
| 3448 |
/* Test the input parameters. */ |
| 3449 |
|
| 3450 |
/* Parameter adjustments */ |
| 3451 |
ab_dim1 = *ldab; |
| 3452 |
ab_offset = 1 + ab_dim1; |
| 3453 |
ab -= ab_offset; |
| 3454 |
bb_dim1 = *ldbb; |
| 3455 |
bb_offset = 1 + bb_dim1; |
| 3456 |
bb -= bb_offset; |
| 3457 |
q_dim1 = *ldq; |
| 3458 |
q_offset = 1 + q_dim1; |
| 3459 |
q -= q_offset; |
| 3460 |
--w; |
| 3461 |
z_dim1 = *ldz; |
| 3462 |
z_offset = 1 + z_dim1; |
| 3463 |
z__ -= z_offset; |
| 3464 |
--work; |
| 3465 |
--iwork; |
| 3466 |
--ifail; |
| 3467 |
|
| 3468 |
/* Function Body */ |
| 3469 |
wantz = lsame_(jobz, "V"); |
| 3470 |
upper = lsame_(uplo, "U"); |
| 3471 |
alleig = lsame_(range, "A"); |
| 3472 |
valeig = lsame_(range, "V"); |
| 3473 |
indeig = lsame_(range, "I"); |
| 3474 |
|
| 3475 |
*info = 0; |
| 3476 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 3477 |
*info = -1; |
| 3478 |
} else if (! (alleig || valeig || indeig)) { |
| 3479 |
*info = -2; |
| 3480 |
} else if (! (upper || lsame_(uplo, "L"))) { |
| 3481 |
*info = -3; |
| 3482 |
} else if (*n < 0) { |
| 3483 |
*info = -4; |
| 3484 |
} else if (*ka < 0) { |
| 3485 |
*info = -5; |
| 3486 |
} else if (*kb < 0 || *kb > *ka) { |
| 3487 |
*info = -6; |
| 3488 |
} else if (*ldab < *ka + 1) { |
| 3489 |
*info = -8; |
| 3490 |
} else if (*ldbb < *kb + 1) { |
| 3491 |
*info = -10; |
| 3492 |
} else if (*ldq < 1 || wantz && *ldq < *n) { |
| 3493 |
*info = -12; |
| 3494 |
} else { |
| 3495 |
if (valeig) { |
| 3496 |
if (*n > 0 && *vu <= *vl) { |
| 3497 |
*info = -14; |
| 3498 |
} |
| 3499 |
} else if (indeig) { |
| 3500 |
if (*il < 1 || *il > std::max(1_integer,*n)) { |
| 3501 |
*info = -15; |
| 3502 |
} else if (*iu < std::min(*n,*il) || *iu > *n) { |
| 3503 |
*info = -16; |
| 3504 |
} |
| 3505 |
} |
| 3506 |
} |
| 3507 |
if (*info == 0) { |
| 3508 |
if (*ldz < 1 || wantz && *ldz < *n) { |
| 3509 |
*info = -21; |
| 3510 |
} |
| 3511 |
} |
| 3512 |
|
| 3513 |
if (*info != 0) { |
| 3514 |
i__1 = -(*info); |
| 3515 |
xerbla_("DSBGVX", &i__1); |
| 3516 |
return 0; |
| 3517 |
} |
| 3518 |
|
| 3519 |
/* Quick return if possible */ |
| 3520 |
|
| 3521 |
*m = 0; |
| 3522 |
if (*n == 0) { |
| 3523 |
return 0; |
| 3524 |
} |
| 3525 |
|
| 3526 |
/* Form a split Cholesky factorization of B. */ |
| 3527 |
|
| 3528 |
dpbstf_(uplo, n, kb, &bb[bb_offset], ldbb, info); |
| 3529 |
if (*info != 0) { |
| 3530 |
*info = *n + *info; |
| 3531 |
return 0; |
| 3532 |
} |
| 3533 |
|
| 3534 |
/* Transform problem to standard eigenvalue problem. */ |
| 3535 |
|
| 3536 |
dsbgst_(jobz, uplo, n, ka, kb, &ab[ab_offset], ldab, &bb[bb_offset], ldbb, |
| 3537 |
&q[q_offset], ldq, &work[1], &iinfo); |
| 3538 |
|
| 3539 |
/* Reduce symmetric band matrix to tridiagonal form. */ |
| 3540 |
|
| 3541 |
indd = 1; |
| 3542 |
inde = indd + *n; |
| 3543 |
indwrk = inde + *n; |
| 3544 |
if (wantz) { |
| 3545 |
*(unsigned char *)vect = 'U'; |
| 3546 |
} else { |
| 3547 |
*(unsigned char *)vect = 'N'; |
| 3548 |
} |
| 3549 |
dsbtrd_(vect, uplo, n, ka, &ab[ab_offset], ldab, &work[indd], &work[inde], |
| 3550 |
&q[q_offset], ldq, &work[indwrk], &iinfo); |
| 3551 |
|
| 3552 |
/* If all eigenvalues are desired and ABSTOL is less than or equal */ |
| 3553 |
/* to zero, then call DSTERF or SSTEQR. If this fails for some */ |
| 3554 |
/* eigenvalue, then try DSTEBZ. */ |
| 3555 |
|
| 3556 |
test = false; |
| 3557 |
if (indeig) { |
| 3558 |
if (*il == 1 && *iu == *n) { |
| 3559 |
test = true; |
| 3560 |
} |
| 3561 |
} |
| 3562 |
if ((alleig || test) && *abstol <= 0.) { |
| 3563 |
dcopy_(n, &work[indd], &c__1, &w[1], &c__1); |
| 3564 |
indee = indwrk + (*n << 1); |
| 3565 |
i__1 = *n - 1; |
| 3566 |
dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); |
| 3567 |
if (! wantz) { |
| 3568 |
dsterf_(n, &w[1], &work[indee], info); |
| 3569 |
} else { |
| 3570 |
dlacpy_("A", n, n, &q[q_offset], ldq, &z__[z_offset], ldz); |
| 3571 |
dsteqr_(jobz, n, &w[1], &work[indee], &z__[z_offset], ldz, &work[ |
| 3572 |
indwrk], info); |
| 3573 |
if (*info == 0) { |
| 3574 |
i__1 = *n; |
| 3575 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 3576 |
ifail[i__] = 0; |
| 3577 |
/* L10: */ |
| 3578 |
} |
| 3579 |
} |
| 3580 |
} |
| 3581 |
if (*info == 0) { |
| 3582 |
*m = *n; |
| 3583 |
goto L30; |
| 3584 |
} |
| 3585 |
*info = 0; |
| 3586 |
} |
| 3587 |
|
| 3588 |
/* Otherwise, call DSTEBZ and, if eigenvectors are desired, */ |
| 3589 |
/* call DSTEIN. */ |
| 3590 |
|
| 3591 |
if (wantz) { |
| 3592 |
*(unsigned char *)order = 'B'; |
| 3593 |
} else { |
| 3594 |
*(unsigned char *)order = 'E'; |
| 3595 |
} |
| 3596 |
indibl = 1; |
| 3597 |
indisp = indibl + *n; |
| 3598 |
indiwo = indisp + *n; |
| 3599 |
dstebz_(range, order, n, vl, vu, il, iu, abstol, &work[indd], &work[inde], |
| 3600 |
m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[indwrk], |
| 3601 |
&iwork[indiwo], info); |
| 3602 |
|
| 3603 |
if (wantz) { |
| 3604 |
dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[ |
| 3605 |
indisp], &z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], & |
| 3606 |
ifail[1], info); |
| 3607 |
|
| 3608 |
/* Apply transformation matrix used in reduction to tridiagonal */ |
| 3609 |
/* form to eigenvectors returned by DSTEIN. */ |
| 3610 |
|
| 3611 |
i__1 = *m; |
| 3612 |
for (j = 1; j <= i__1; ++j) { |
| 3613 |
dcopy_(n, &z__[j * z_dim1 + 1], &c__1, &work[1], &c__1); |
| 3614 |
dgemv_("N", n, n, &c_b25, &q[q_offset], ldq, &work[1], &c__1, & |
| 3615 |
c_b27, &z__[j * z_dim1 + 1], &c__1); |
| 3616 |
/* L20: */ |
| 3617 |
} |
| 3618 |
} |
| 3619 |
|
| 3620 |
L30: |
| 3621 |
|
| 3622 |
/* If eigenvalues are not in order, then sort them, along with */ |
| 3623 |
/* eigenvectors. */ |
| 3624 |
|
| 3625 |
if (wantz) { |
| 3626 |
i__1 = *m - 1; |
| 3627 |
for (j = 1; j <= i__1; ++j) { |
| 3628 |
i__ = 0; |
| 3629 |
tmp1 = w[j]; |
| 3630 |
i__2 = *m; |
| 3631 |
for (jj = j + 1; jj <= i__2; ++jj) { |
| 3632 |
if (w[jj] < tmp1) { |
| 3633 |
i__ = jj; |
| 3634 |
tmp1 = w[jj]; |
| 3635 |
} |
| 3636 |
/* L40: */ |
| 3637 |
} |
| 3638 |
|
| 3639 |
if (i__ != 0) { |
| 3640 |
itmp1 = iwork[indibl + i__ - 1]; |
| 3641 |
w[i__] = w[j]; |
| 3642 |
iwork[indibl + i__ - 1] = iwork[indibl + j - 1]; |
| 3643 |
w[j] = tmp1; |
| 3644 |
iwork[indibl + j - 1] = itmp1; |
| 3645 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], |
| 3646 |
&c__1); |
| 3647 |
if (*info != 0) { |
| 3648 |
itmp1 = ifail[i__]; |
| 3649 |
ifail[i__] = ifail[j]; |
| 3650 |
ifail[j] = itmp1; |
| 3651 |
} |
| 3652 |
} |
| 3653 |
/* L50: */ |
| 3654 |
} |
| 3655 |
} |
| 3656 |
|
| 3657 |
return 0; |
| 3658 |
|
| 3659 |
/* End of DSBGVX */ |
| 3660 |
|
| 3661 |
} /* dsbgvx_ */ |
| 3662 |
|
| 3663 |
/* Subroutine */ int dsbtrd_(const char *vect, const char *uplo, integer *n, integer *kd, |
| 3664 |
double *ab, integer *ldab, double *d__, double *e, |
| 3665 |
double *q, integer *ldq, double *work, integer *info) |
| 3666 |
{ |
| 3667 |
/* Table of constant values */ |
| 3668 |
static double c_b9 = 0.; |
| 3669 |
static double c_b10 = 1.; |
| 3670 |
static integer c__1 = 1; |
| 3671 |
|
| 3672 |
/* System generated locals */ |
| 3673 |
integer ab_dim1, ab_offset, q_dim1, q_offset, i__1, i__2, i__3, i__4, |
| 3674 |
i__5; |
| 3675 |
|
| 3676 |
/* Local variables */ |
| 3677 |
integer i__, j, k, l, i2, j1, j2, nq, nr, kd1, ibl, iqb, kdn, jin, nrt, |
| 3678 |
kdm1, inca, jend, lend, jinc, incx, last; |
| 3679 |
double temp; |
| 3680 |
integer j1end, j1inc, iqend; |
| 3681 |
bool initq, wantq, upper; |
| 3682 |
integer iqaend; |
| 3683 |
|
| 3684 |
/* -- LAPACK routine (version 3.1) -- */ |
| 3685 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 3686 |
/* November 2006 */ |
| 3687 |
|
| 3688 |
/* .. Scalar Arguments .. */ |
| 3689 |
/* .. */ |
| 3690 |
/* .. Array Arguments .. */ |
| 3691 |
/* .. */ |
| 3692 |
|
| 3693 |
/* Purpose */ |
| 3694 |
/* ======= */ |
| 3695 |
|
| 3696 |
/* DSBTRD reduces a real symmetric band matrix A to symmetric */ |
| 3697 |
/* tridiagonal form T by an orthogonal similarity transformation: */ |
| 3698 |
/* Q**T * A * Q = T. */ |
| 3699 |
|
| 3700 |
/* Arguments */ |
| 3701 |
/* ========= */ |
| 3702 |
|
| 3703 |
/* VECT (input) CHARACTER*1 */ |
| 3704 |
/* = 'N': do not form Q; */ |
| 3705 |
/* = 'V': form Q; */ |
| 3706 |
/* = 'U': update a matrix X, by forming X*Q. */ |
| 3707 |
|
| 3708 |
/* UPLO (input) CHARACTER*1 */ |
| 3709 |
/* = 'U': Upper triangle of A is stored; */ |
| 3710 |
/* = 'L': Lower triangle of A is stored. */ |
| 3711 |
|
| 3712 |
/* N (input) INTEGER */ |
| 3713 |
/* The order of the matrix A. N >= 0. */ |
| 3714 |
|
| 3715 |
/* KD (input) INTEGER */ |
| 3716 |
/* The number of superdiagonals of the matrix A if UPLO = 'U', */ |
| 3717 |
/* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */ |
| 3718 |
|
| 3719 |
/* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */ |
| 3720 |
/* On entry, the upper or lower triangle of the symmetric band */ |
| 3721 |
/* matrix A, stored in the first KD+1 rows of the array. The */ |
| 3722 |
/* j-th column of A is stored in the j-th column of the array AB */ |
| 3723 |
/* as follows: */ |
| 3724 |
/* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */ |
| 3725 |
/* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */ |
| 3726 |
/* On exit, the diagonal elements of AB are overwritten by the */ |
| 3727 |
/* diagonal elements of the tridiagonal matrix T; if KD > 0, the */ |
| 3728 |
/* elements on the first superdiagonal (if UPLO = 'U') or the */ |
| 3729 |
/* first subdiagonal (if UPLO = 'L') are overwritten by the */ |
| 3730 |
/* off-diagonal elements of T; the rest of AB is overwritten by */ |
| 3731 |
/* values generated during the reduction. */ |
| 3732 |
|
| 3733 |
/* LDAB (input) INTEGER */ |
| 3734 |
/* The leading dimension of the array AB. LDAB >= KD+1. */ |
| 3735 |
|
| 3736 |
/* D (output) DOUBLE PRECISION array, dimension (N) */ |
| 3737 |
/* The diagonal elements of the tridiagonal matrix T. */ |
| 3738 |
|
| 3739 |
/* E (output) DOUBLE PRECISION array, dimension (N-1) */ |
| 3740 |
/* The off-diagonal elements of the tridiagonal matrix T: */ |
| 3741 |
/* E(i) = T(i,i+1) if UPLO = 'U'; E(i) = T(i+1,i) if UPLO = 'L'. */ |
| 3742 |
|
| 3743 |
/* Q (input/output) DOUBLE PRECISION array, dimension (LDQ,N) */ |
| 3744 |
/* On entry, if VECT = 'U', then Q must contain an N-by-N */ |
| 3745 |
/* matrix X; if VECT = 'N' or 'V', then Q need not be set. */ |
| 3746 |
|
| 3747 |
/* On exit: */ |
| 3748 |
/* if VECT = 'V', Q contains the N-by-N orthogonal matrix Q; */ |
| 3749 |
/* if VECT = 'U', Q contains the product X*Q; */ |
| 3750 |
/* if VECT = 'N', the array Q is not referenced. */ |
| 3751 |
|
| 3752 |
/* LDQ (input) INTEGER */ |
| 3753 |
/* The leading dimension of the array Q. */ |
| 3754 |
/* LDQ >= 1, and LDQ >= N if VECT = 'V' or 'U'. */ |
| 3755 |
|
| 3756 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (N) */ |
| 3757 |
|
| 3758 |
/* INFO (output) INTEGER */ |
| 3759 |
/* = 0: successful exit */ |
| 3760 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 3761 |
|
| 3762 |
/* Further Details */ |
| 3763 |
/* =============== */ |
| 3764 |
|
| 3765 |
/* Modified by Linda Kaufman, Bell Labs. */ |
| 3766 |
|
| 3767 |
/* ===================================================================== */ |
| 3768 |
|
| 3769 |
/* .. Parameters .. */ |
| 3770 |
/* .. */ |
| 3771 |
/* .. Local Scalars .. */ |
| 3772 |
/* .. */ |
| 3773 |
/* .. External Subroutines .. */ |
| 3774 |
/* .. */ |
| 3775 |
/* .. Intrinsic Functions .. */ |
| 3776 |
/* .. */ |
| 3777 |
/* .. External Functions .. */ |
| 3778 |
/* .. */ |
| 3779 |
/* .. Executable Statements .. */ |
| 3780 |
|
| 3781 |
/* Test the input parameters */ |
| 3782 |
|
| 3783 |
/* Parameter adjustments */ |
| 3784 |
ab_dim1 = *ldab; |
| 3785 |
ab_offset = 1 + ab_dim1; |
| 3786 |
ab -= ab_offset; |
| 3787 |
--d__; |
| 3788 |
--e; |
| 3789 |
q_dim1 = *ldq; |
| 3790 |
q_offset = 1 + q_dim1; |
| 3791 |
q -= q_offset; |
| 3792 |
--work; |
| 3793 |
|
| 3794 |
/* Function Body */ |
| 3795 |
initq = lsame_(vect, "V"); |
| 3796 |
wantq = initq || lsame_(vect, "U"); |
| 3797 |
upper = lsame_(uplo, "U"); |
| 3798 |
kd1 = *kd + 1; |
| 3799 |
kdm1 = *kd - 1; |
| 3800 |
incx = *ldab - 1; |
| 3801 |
iqend = 1; |
| 3802 |
|
| 3803 |
*info = 0; |
| 3804 |
if (! wantq && ! lsame_(vect, "N")) { |
| 3805 |
*info = -1; |
| 3806 |
} else if (! upper && ! lsame_(uplo, "L")) { |
| 3807 |
*info = -2; |
| 3808 |
} else if (*n < 0) { |
| 3809 |
*info = -3; |
| 3810 |
} else if (*kd < 0) { |
| 3811 |
*info = -4; |
| 3812 |
} else if (*ldab < kd1) { |
| 3813 |
*info = -6; |
| 3814 |
} else if (*ldq < std::max(1_integer,*n) && wantq) { |
| 3815 |
*info = -10; |
| 3816 |
} |
| 3817 |
if (*info != 0) { |
| 3818 |
i__1 = -(*info); |
| 3819 |
xerbla_("DSBTRD", &i__1); |
| 3820 |
return 0; |
| 3821 |
} |
| 3822 |
|
| 3823 |
/* Quick return if possible */ |
| 3824 |
|
| 3825 |
if (*n == 0) { |
| 3826 |
return 0; |
| 3827 |
} |
| 3828 |
|
| 3829 |
/* Initialize Q to the unit matrix, if needed */ |
| 3830 |
|
| 3831 |
if (initq) { |
| 3832 |
dlaset_("Full", n, n, &c_b9, &c_b10, &q[q_offset], ldq); |
| 3833 |
} |
| 3834 |
|
| 3835 |
/* Wherever possible, plane rotations are generated and applied in */ |
| 3836 |
/* vector operations of length NR over the index set J1:J2:KD1. */ |
| 3837 |
|
| 3838 |
/* The cosines and sines of the plane rotations are stored in the */ |
| 3839 |
/* arrays D and WORK. */ |
| 3840 |
|
| 3841 |
inca = kd1 * *ldab; |
| 3842 |
/* Computing MIN */ |
| 3843 |
i__1 = *n - 1; |
| 3844 |
kdn = std::min(i__1,*kd); |
| 3845 |
if (upper) { |
| 3846 |
|
| 3847 |
if (*kd > 1) { |
| 3848 |
|
| 3849 |
/* Reduce to tridiagonal form, working with upper triangle */ |
| 3850 |
|
| 3851 |
nr = 0; |
| 3852 |
j1 = kdn + 2; |
| 3853 |
j2 = 1; |
| 3854 |
|
| 3855 |
i__1 = *n - 2; |
| 3856 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 3857 |
|
| 3858 |
/* Reduce i-th row of matrix to tridiagonal form */ |
| 3859 |
|
| 3860 |
for (k = kdn + 1; k >= 2; --k) { |
| 3861 |
j1 += kdn; |
| 3862 |
j2 += kdn; |
| 3863 |
|
| 3864 |
if (nr > 0) { |
| 3865 |
|
| 3866 |
/* generate plane rotations to annihilate nonzero */ |
| 3867 |
/* elements which have been created outside the band */ |
| 3868 |
|
| 3869 |
dlargv_(&nr, &ab[(j1 - 1) * ab_dim1 + 1], &inca, & |
| 3870 |
work[j1], &kd1, &d__[j1], &kd1); |
| 3871 |
|
| 3872 |
/* apply rotations from the right */ |
| 3873 |
|
| 3874 |
|
| 3875 |
/* Dependent on the the number of diagonals either */ |
| 3876 |
/* DLARTV or DROT is used */ |
| 3877 |
|
| 3878 |
if (nr >= (*kd << 1) - 1) { |
| 3879 |
i__2 = *kd - 1; |
| 3880 |
for (l = 1; l <= i__2; ++l) { |
| 3881 |
dlartv_(&nr, &ab[l + 1 + (j1 - 1) * ab_dim1], |
| 3882 |
&inca, &ab[l + j1 * ab_dim1], &inca, & |
| 3883 |
d__[j1], &work[j1], &kd1); |
| 3884 |
/* L10: */ |
| 3885 |
} |
| 3886 |
|
| 3887 |
} else { |
| 3888 |
jend = j1 + (nr - 1) * kd1; |
| 3889 |
i__2 = jend; |
| 3890 |
i__3 = kd1; |
| 3891 |
for (jinc = j1; i__3 < 0 ? jinc >= i__2 : jinc <= |
| 3892 |
i__2; jinc += i__3) { |
| 3893 |
drot_(&kdm1, &ab[(jinc - 1) * ab_dim1 + 2], & |
| 3894 |
c__1, &ab[jinc * ab_dim1 + 1], &c__1, |
| 3895 |
&d__[jinc], &work[jinc]); |
| 3896 |
/* L20: */ |
| 3897 |
} |
| 3898 |
} |
| 3899 |
} |
| 3900 |
|
| 3901 |
|
| 3902 |
if (k > 2) { |
| 3903 |
if (k <= *n - i__ + 1) { |
| 3904 |
|
| 3905 |
/* generate plane rotation to annihilate a(i,i+k-1) */ |
| 3906 |
/* within the band */ |
| 3907 |
|
| 3908 |
dlartg_(&ab[*kd - k + 3 + (i__ + k - 2) * ab_dim1] |
| 3909 |
, &ab[*kd - k + 2 + (i__ + k - 1) * |
| 3910 |
ab_dim1], &d__[i__ + k - 1], &work[i__ + |
| 3911 |
k - 1], &temp); |
| 3912 |
ab[*kd - k + 3 + (i__ + k - 2) * ab_dim1] = temp; |
| 3913 |
|
| 3914 |
/* apply rotation from the right */ |
| 3915 |
|
| 3916 |
i__3 = k - 3; |
| 3917 |
drot_(&i__3, &ab[*kd - k + 4 + (i__ + k - 2) * |
| 3918 |
ab_dim1], &c__1, &ab[*kd - k + 3 + (i__ + |
| 3919 |
k - 1) * ab_dim1], &c__1, &d__[i__ + k - |
| 3920 |
1], &work[i__ + k - 1]); |
| 3921 |
} |
| 3922 |
++nr; |
| 3923 |
j1 = j1 - kdn - 1; |
| 3924 |
} |
| 3925 |
|
| 3926 |
/* apply plane rotations from both sides to diagonal */ |
| 3927 |
/* blocks */ |
| 3928 |
|
| 3929 |
if (nr > 0) { |
| 3930 |
dlar2v_(&nr, &ab[kd1 + (j1 - 1) * ab_dim1], &ab[kd1 + |
| 3931 |
j1 * ab_dim1], &ab[*kd + j1 * ab_dim1], &inca, |
| 3932 |
&d__[j1], &work[j1], &kd1); |
| 3933 |
} |
| 3934 |
|
| 3935 |
/* apply plane rotations from the left */ |
| 3936 |
|
| 3937 |
if (nr > 0) { |
| 3938 |
if ((*kd << 1) - 1 < nr) { |
| 3939 |
|
| 3940 |
/* Dependent on the the number of diagonals either */ |
| 3941 |
/* DLARTV or DROT is used */ |
| 3942 |
|
| 3943 |
i__3 = *kd - 1; |
| 3944 |
for (l = 1; l <= i__3; ++l) { |
| 3945 |
if (j2 + l > *n) { |
| 3946 |
nrt = nr - 1; |
| 3947 |
} else { |
| 3948 |
nrt = nr; |
| 3949 |
} |
| 3950 |
if (nrt > 0) { |
| 3951 |
dlartv_(&nrt, &ab[*kd - l + (j1 + l) * |
| 3952 |
ab_dim1], &inca, &ab[*kd - l + 1 |
| 3953 |
+ (j1 + l) * ab_dim1], &inca, & |
| 3954 |
d__[j1], &work[j1], &kd1); |
| 3955 |
} |
| 3956 |
/* L30: */ |
| 3957 |
} |
| 3958 |
} else { |
| 3959 |
j1end = j1 + kd1 * (nr - 2); |
| 3960 |
if (j1end >= j1) { |
| 3961 |
i__3 = j1end; |
| 3962 |
i__2 = kd1; |
| 3963 |
for (jin = j1; i__2 < 0 ? jin >= i__3 : jin <= |
| 3964 |
i__3; jin += i__2) { |
| 3965 |
i__4 = *kd - 1; |
| 3966 |
drot_(&i__4, &ab[*kd - 1 + (jin + 1) * |
| 3967 |
ab_dim1], &incx, &ab[*kd + (jin + |
| 3968 |
1) * ab_dim1], &incx, &d__[jin], & |
| 3969 |
work[jin]); |
| 3970 |
/* L40: */ |
| 3971 |
} |
| 3972 |
} |
| 3973 |
/* Computing MIN */ |
| 3974 |
i__2 = kdm1, i__3 = *n - j2; |
| 3975 |
lend = std::min(i__2,i__3); |
| 3976 |
last = j1end + kd1; |
| 3977 |
if (lend > 0) { |
| 3978 |
drot_(&lend, &ab[*kd - 1 + (last + 1) * |
| 3979 |
ab_dim1], &incx, &ab[*kd + (last + 1) |
| 3980 |
* ab_dim1], &incx, &d__[last], &work[ |
| 3981 |
last]); |
| 3982 |
} |
| 3983 |
} |
| 3984 |
} |
| 3985 |
|
| 3986 |
if (wantq) { |
| 3987 |
|
| 3988 |
/* accumulate product of plane rotations in Q */ |
| 3989 |
|
| 3990 |
if (initq) { |
| 3991 |
|
| 3992 |
/* take advantage of the fact that Q was */ |
| 3993 |
/* initially the Identity matrix */ |
| 3994 |
|
| 3995 |
iqend = std::max(iqend,j2); |
| 3996 |
/* Computing MAX */ |
| 3997 |
i__2 = 0, i__3 = k - 3; |
| 3998 |
i2 = std::max(i__2,i__3); |
| 3999 |
iqaend = i__ * *kd + 1; |
| 4000 |
if (k == 2) { |
| 4001 |
iqaend += *kd; |
| 4002 |
} |
| 4003 |
iqaend = std::min(iqaend,iqend); |
| 4004 |
i__2 = j2; |
| 4005 |
i__3 = kd1; |
| 4006 |
for (j = j1; i__3 < 0 ? j >= i__2 : j <= i__2; j |
| 4007 |
+= i__3) { |
| 4008 |
ibl = i__ - i2 / kdm1; |
| 4009 |
++i2; |
| 4010 |
/* Computing MAX */ |
| 4011 |
i__4 = 1, i__5 = j - ibl; |
| 4012 |
iqb = std::max(i__4,i__5); |
| 4013 |
nq = iqaend + 1 - iqb; |
| 4014 |
/* Computing MIN */ |
| 4015 |
i__4 = iqaend + *kd; |
| 4016 |
iqaend = std::min(i__4,iqend); |
| 4017 |
drot_(&nq, &q[iqb + (j - 1) * q_dim1], &c__1, |
| 4018 |
&q[iqb + j * q_dim1], &c__1, &d__[j], |
| 4019 |
&work[j]); |
| 4020 |
/* L50: */ |
| 4021 |
} |
| 4022 |
} else { |
| 4023 |
|
| 4024 |
i__3 = j2; |
| 4025 |
i__2 = kd1; |
| 4026 |
for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j |
| 4027 |
+= i__2) { |
| 4028 |
drot_(n, &q[(j - 1) * q_dim1 + 1], &c__1, &q[ |
| 4029 |
j * q_dim1 + 1], &c__1, &d__[j], & |
| 4030 |
work[j]); |
| 4031 |
/* L60: */ |
| 4032 |
} |
| 4033 |
} |
| 4034 |
|
| 4035 |
} |
| 4036 |
|
| 4037 |
if (j2 + kdn > *n) { |
| 4038 |
|
| 4039 |
/* adjust J2 to keep within the bounds of the matrix */ |
| 4040 |
|
| 4041 |
--nr; |
| 4042 |
j2 = j2 - kdn - 1; |
| 4043 |
} |
| 4044 |
|
| 4045 |
i__2 = j2; |
| 4046 |
i__3 = kd1; |
| 4047 |
for (j = j1; i__3 < 0 ? j >= i__2 : j <= i__2; j += i__3) |
| 4048 |
{ |
| 4049 |
|
| 4050 |
/* create nonzero element a(j-1,j+kd) outside the band */ |
| 4051 |
/* and store it in WORK */ |
| 4052 |
|
| 4053 |
work[j + *kd] = work[j] * ab[(j + *kd) * ab_dim1 + 1]; |
| 4054 |
ab[(j + *kd) * ab_dim1 + 1] = d__[j] * ab[(j + *kd) * |
| 4055 |
ab_dim1 + 1]; |
| 4056 |
/* L70: */ |
| 4057 |
} |
| 4058 |
/* L80: */ |
| 4059 |
} |
| 4060 |
/* L90: */ |
| 4061 |
} |
| 4062 |
} |
| 4063 |
|
| 4064 |
if (*kd > 0) { |
| 4065 |
|
| 4066 |
/* copy off-diagonal elements to E */ |
| 4067 |
|
| 4068 |
i__1 = *n - 1; |
| 4069 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 4070 |
e[i__] = ab[*kd + (i__ + 1) * ab_dim1]; |
| 4071 |
/* L100: */ |
| 4072 |
} |
| 4073 |
} else { |
| 4074 |
|
| 4075 |
/* set E to zero if original matrix was diagonal */ |
| 4076 |
|
| 4077 |
i__1 = *n - 1; |
| 4078 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 4079 |
e[i__] = 0.; |
| 4080 |
/* L110: */ |
| 4081 |
} |
| 4082 |
} |
| 4083 |
|
| 4084 |
/* copy diagonal elements to D */ |
| 4085 |
|
| 4086 |
i__1 = *n; |
| 4087 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 4088 |
d__[i__] = ab[kd1 + i__ * ab_dim1]; |
| 4089 |
/* L120: */ |
| 4090 |
} |
| 4091 |
|
| 4092 |
} else { |
| 4093 |
|
| 4094 |
if (*kd > 1) { |
| 4095 |
|
| 4096 |
/* Reduce to tridiagonal form, working with lower triangle */ |
| 4097 |
|
| 4098 |
nr = 0; |
| 4099 |
j1 = kdn + 2; |
| 4100 |
j2 = 1; |
| 4101 |
|
| 4102 |
i__1 = *n - 2; |
| 4103 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 4104 |
|
| 4105 |
/* Reduce i-th column of matrix to tridiagonal form */ |
| 4106 |
|
| 4107 |
for (k = kdn + 1; k >= 2; --k) { |
| 4108 |
j1 += kdn; |
| 4109 |
j2 += kdn; |
| 4110 |
|
| 4111 |
if (nr > 0) { |
| 4112 |
|
| 4113 |
/* generate plane rotations to annihilate nonzero */ |
| 4114 |
/* elements which have been created outside the band */ |
| 4115 |
|
| 4116 |
dlargv_(&nr, &ab[kd1 + (j1 - kd1) * ab_dim1], &inca, & |
| 4117 |
work[j1], &kd1, &d__[j1], &kd1); |
| 4118 |
|
| 4119 |
/* apply plane rotations from one side */ |
| 4120 |
|
| 4121 |
|
| 4122 |
/* Dependent on the the number of diagonals either */ |
| 4123 |
/* DLARTV or DROT is used */ |
| 4124 |
|
| 4125 |
if (nr > (*kd << 1) - 1) { |
| 4126 |
i__3 = *kd - 1; |
| 4127 |
for (l = 1; l <= i__3; ++l) { |
| 4128 |
dlartv_(&nr, &ab[kd1 - l + (j1 - kd1 + l) * |
| 4129 |
ab_dim1], &inca, &ab[kd1 - l + 1 + ( |
| 4130 |
j1 - kd1 + l) * ab_dim1], &inca, &d__[ |
| 4131 |
j1], &work[j1], &kd1); |
| 4132 |
/* L130: */ |
| 4133 |
} |
| 4134 |
} else { |
| 4135 |
jend = j1 + kd1 * (nr - 1); |
| 4136 |
i__3 = jend; |
| 4137 |
i__2 = kd1; |
| 4138 |
for (jinc = j1; i__2 < 0 ? jinc >= i__3 : jinc <= |
| 4139 |
i__3; jinc += i__2) { |
| 4140 |
drot_(&kdm1, &ab[*kd + (jinc - *kd) * ab_dim1] |
| 4141 |
, &incx, &ab[kd1 + (jinc - *kd) * |
| 4142 |
ab_dim1], &incx, &d__[jinc], &work[ |
| 4143 |
jinc]); |
| 4144 |
/* L140: */ |
| 4145 |
} |
| 4146 |
} |
| 4147 |
|
| 4148 |
} |
| 4149 |
|
| 4150 |
if (k > 2) { |
| 4151 |
if (k <= *n - i__ + 1) { |
| 4152 |
|
| 4153 |
/* generate plane rotation to annihilate a(i+k-1,i) */ |
| 4154 |
/* within the band */ |
| 4155 |
|
| 4156 |
dlartg_(&ab[k - 1 + i__ * ab_dim1], &ab[k + i__ * |
| 4157 |
ab_dim1], &d__[i__ + k - 1], &work[i__ + |
| 4158 |
k - 1], &temp); |
| 4159 |
ab[k - 1 + i__ * ab_dim1] = temp; |
| 4160 |
|
| 4161 |
/* apply rotation from the left */ |
| 4162 |
|
| 4163 |
i__2 = k - 3; |
| 4164 |
i__3 = *ldab - 1; |
| 4165 |
i__4 = *ldab - 1; |
| 4166 |
drot_(&i__2, &ab[k - 2 + (i__ + 1) * ab_dim1], & |
| 4167 |
i__3, &ab[k - 1 + (i__ + 1) * ab_dim1], & |
| 4168 |
i__4, &d__[i__ + k - 1], &work[i__ + k - |
| 4169 |
1]); |
| 4170 |
} |
| 4171 |
++nr; |
| 4172 |
j1 = j1 - kdn - 1; |
| 4173 |
} |
| 4174 |
|
| 4175 |
/* apply plane rotations from both sides to diagonal */ |
| 4176 |
/* blocks */ |
| 4177 |
|
| 4178 |
if (nr > 0) { |
| 4179 |
dlar2v_(&nr, &ab[(j1 - 1) * ab_dim1 + 1], &ab[j1 * |
| 4180 |
ab_dim1 + 1], &ab[(j1 - 1) * ab_dim1 + 2], & |
| 4181 |
inca, &d__[j1], &work[j1], &kd1); |
| 4182 |
} |
| 4183 |
|
| 4184 |
/* apply plane rotations from the right */ |
| 4185 |
|
| 4186 |
|
| 4187 |
/* Dependent on the the number of diagonals either */ |
| 4188 |
/* DLARTV or DROT is used */ |
| 4189 |
|
| 4190 |
if (nr > 0) { |
| 4191 |
if (nr > (*kd << 1) - 1) { |
| 4192 |
i__2 = *kd - 1; |
| 4193 |
for (l = 1; l <= i__2; ++l) { |
| 4194 |
if (j2 + l > *n) { |
| 4195 |
nrt = nr - 1; |
| 4196 |
} else { |
| 4197 |
nrt = nr; |
| 4198 |
} |
| 4199 |
if (nrt > 0) { |
| 4200 |
dlartv_(&nrt, &ab[l + 2 + (j1 - 1) * |
| 4201 |
ab_dim1], &inca, &ab[l + 1 + j1 * |
| 4202 |
ab_dim1], &inca, &d__[j1], &work[ |
| 4203 |
j1], &kd1); |
| 4204 |
} |
| 4205 |
/* L150: */ |
| 4206 |
} |
| 4207 |
} else { |
| 4208 |
j1end = j1 + kd1 * (nr - 2); |
| 4209 |
if (j1end >= j1) { |
| 4210 |
i__2 = j1end; |
| 4211 |
i__3 = kd1; |
| 4212 |
for (j1inc = j1; i__3 < 0 ? j1inc >= i__2 : |
| 4213 |
j1inc <= i__2; j1inc += i__3) { |
| 4214 |
drot_(&kdm1, &ab[(j1inc - 1) * ab_dim1 + |
| 4215 |
3], &c__1, &ab[j1inc * ab_dim1 + |
| 4216 |
2], &c__1, &d__[j1inc], &work[ |
| 4217 |
j1inc]); |
| 4218 |
/* L160: */ |
| 4219 |
} |
| 4220 |
} |
| 4221 |
/* Computing MIN */ |
| 4222 |
i__3 = kdm1, i__2 = *n - j2; |
| 4223 |
lend = std::min(i__3,i__2); |
| 4224 |
last = j1end + kd1; |
| 4225 |
if (lend > 0) { |
| 4226 |
drot_(&lend, &ab[(last - 1) * ab_dim1 + 3], & |
| 4227 |
c__1, &ab[last * ab_dim1 + 2], &c__1, |
| 4228 |
&d__[last], &work[last]); |
| 4229 |
} |
| 4230 |
} |
| 4231 |
} |
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
if (wantq) { |
| 4236 |
|
| 4237 |
/* accumulate product of plane rotations in Q */ |
| 4238 |
|
| 4239 |
if (initq) { |
| 4240 |
|
| 4241 |
/* take advantage of the fact that Q was */ |
| 4242 |
/* initially the Identity matrix */ |
| 4243 |
|
| 4244 |
iqend = std::max(iqend,j2); |
| 4245 |
/* Computing MAX */ |
| 4246 |
i__3 = 0, i__2 = k - 3; |
| 4247 |
i2 = std::max(i__3,i__2); |
| 4248 |
iqaend = i__ * *kd + 1; |
| 4249 |
if (k == 2) { |
| 4250 |
iqaend += *kd; |
| 4251 |
} |
| 4252 |
iqaend = std::min(iqaend,iqend); |
| 4253 |
i__3 = j2; |
| 4254 |
i__2 = kd1; |
| 4255 |
for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j |
| 4256 |
+= i__2) { |
| 4257 |
ibl = i__ - i2 / kdm1; |
| 4258 |
++i2; |
| 4259 |
/* Computing MAX */ |
| 4260 |
i__4 = 1, i__5 = j - ibl; |
| 4261 |
iqb = std::max(i__4,i__5); |
| 4262 |
nq = iqaend + 1 - iqb; |
| 4263 |
/* Computing MIN */ |
| 4264 |
i__4 = iqaend + *kd; |
| 4265 |
iqaend = std::min(i__4,iqend); |
| 4266 |
drot_(&nq, &q[iqb + (j - 1) * q_dim1], &c__1, |
| 4267 |
&q[iqb + j * q_dim1], &c__1, &d__[j], |
| 4268 |
&work[j]); |
| 4269 |
/* L170: */ |
| 4270 |
} |
| 4271 |
} else { |
| 4272 |
|
| 4273 |
i__2 = j2; |
| 4274 |
i__3 = kd1; |
| 4275 |
for (j = j1; i__3 < 0 ? j >= i__2 : j <= i__2; j |
| 4276 |
+= i__3) { |
| 4277 |
drot_(n, &q[(j - 1) * q_dim1 + 1], &c__1, &q[ |
| 4278 |
j * q_dim1 + 1], &c__1, &d__[j], & |
| 4279 |
work[j]); |
| 4280 |
/* L180: */ |
| 4281 |
} |
| 4282 |
} |
| 4283 |
} |
| 4284 |
|
| 4285 |
if (j2 + kdn > *n) { |
| 4286 |
|
| 4287 |
/* adjust J2 to keep within the bounds of the matrix */ |
| 4288 |
|
| 4289 |
--nr; |
| 4290 |
j2 = j2 - kdn - 1; |
| 4291 |
} |
| 4292 |
|
| 4293 |
i__3 = j2; |
| 4294 |
i__2 = kd1; |
| 4295 |
for (j = j1; i__2 < 0 ? j >= i__3 : j <= i__3; j += i__2) |
| 4296 |
{ |
| 4297 |
|
| 4298 |
/* create nonzero element a(j+kd,j-1) outside the */ |
| 4299 |
/* band and store it in WORK */ |
| 4300 |
|
| 4301 |
work[j + *kd] = work[j] * ab[kd1 + j * ab_dim1]; |
| 4302 |
ab[kd1 + j * ab_dim1] = d__[j] * ab[kd1 + j * ab_dim1] |
| 4303 |
; |
| 4304 |
/* L190: */ |
| 4305 |
} |
| 4306 |
/* L200: */ |
| 4307 |
} |
| 4308 |
/* L210: */ |
| 4309 |
} |
| 4310 |
} |
| 4311 |
|
| 4312 |
if (*kd > 0) { |
| 4313 |
|
| 4314 |
/* copy off-diagonal elements to E */ |
| 4315 |
|
| 4316 |
i__1 = *n - 1; |
| 4317 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 4318 |
e[i__] = ab[i__ * ab_dim1 + 2]; |
| 4319 |
/* L220: */ |
| 4320 |
} |
| 4321 |
} else { |
| 4322 |
|
| 4323 |
/* set E to zero if original matrix was diagonal */ |
| 4324 |
|
| 4325 |
i__1 = *n - 1; |
| 4326 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 4327 |
e[i__] = 0.; |
| 4328 |
/* L230: */ |
| 4329 |
} |
| 4330 |
} |
| 4331 |
|
| 4332 |
/* copy diagonal elements to D */ |
| 4333 |
|
| 4334 |
i__1 = *n; |
| 4335 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 4336 |
d__[i__] = ab[i__ * ab_dim1 + 1]; |
| 4337 |
/* L240: */ |
| 4338 |
} |
| 4339 |
} |
| 4340 |
|
| 4341 |
return 0; |
| 4342 |
|
| 4343 |
/* End of DSBTRD */ |
| 4344 |
|
| 4345 |
} /* dsbtrd_ */ |
| 4346 |
|
| 4347 |
int dsfrk_(const char *transr, const char *uplo, const char *trans, integer *n, |
| 4348 |
integer *k, double *alpha, double *a, integer *lda, |
| 4349 |
double *beta, double *c__) |
| 4350 |
{ |
| 4351 |
/* System generated locals */ |
| 4352 |
integer a_dim1, a_offset, i__1; |
| 4353 |
|
| 4354 |
/* Local variables */ |
| 4355 |
integer j, n1, n2, nk, info; |
| 4356 |
bool normaltransr; |
| 4357 |
integer nrowa; |
| 4358 |
bool lower, nisodd, notrans; |
| 4359 |
|
| 4360 |
|
| 4361 |
/* -- LAPACK routine (version 3.2) -- */ |
| 4362 |
|
| 4363 |
/* -- Contributed by Julien Langou of the Univ. of Colorado Denver -- */ |
| 4364 |
/* -- November 2008 -- */ |
| 4365 |
|
| 4366 |
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ |
| 4367 |
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ |
| 4368 |
|
| 4369 |
/* .. */ |
| 4370 |
/* .. Scalar Arguments .. */ |
| 4371 |
/* .. */ |
| 4372 |
/* .. Array Arguments .. */ |
| 4373 |
/* .. */ |
| 4374 |
|
| 4375 |
/* Purpose */ |
| 4376 |
/* ======= */ |
| 4377 |
|
| 4378 |
/* Level 3 BLAS like routine for C in RFP Format. */ |
| 4379 |
|
| 4380 |
/* DSFRK performs one of the symmetric rank--k operations */ |
| 4381 |
|
| 4382 |
/* C := alpha*A*A' + beta*C, */ |
| 4383 |
|
| 4384 |
/* or */ |
| 4385 |
|
| 4386 |
/* C := alpha*A'*A + beta*C, */ |
| 4387 |
|
| 4388 |
/* where alpha and beta are real scalars, C is an n--by--n symmetric */ |
| 4389 |
/* matrix and A is an n--by--k matrix in the first case and a k--by--n */ |
| 4390 |
/* matrix in the second case. */ |
| 4391 |
|
| 4392 |
/* Arguments */ |
| 4393 |
/* ========== */ |
| 4394 |
|
| 4395 |
/* TRANSR (input) CHARACTER */ |
| 4396 |
/* = 'N': The Normal Form of RFP A is stored; */ |
| 4397 |
/* = 'T': The Transpose Form of RFP A is stored. */ |
| 4398 |
|
| 4399 |
/* UPLO - (input) CHARACTER */ |
| 4400 |
/* On entry, UPLO specifies whether the upper or lower */ |
| 4401 |
/* triangular part of the array C is to be referenced as */ |
| 4402 |
/* follows: */ |
| 4403 |
|
| 4404 |
/* UPLO = 'U' or 'u' Only the upper triangular part of C */ |
| 4405 |
/* is to be referenced. */ |
| 4406 |
|
| 4407 |
/* UPLO = 'L' or 'l' Only the lower triangular part of C */ |
| 4408 |
/* is to be referenced. */ |
| 4409 |
|
| 4410 |
/* Unchanged on exit. */ |
| 4411 |
|
| 4412 |
/* TRANS - (input) CHARACTER */ |
| 4413 |
/* On entry, TRANS specifies the operation to be performed as */ |
| 4414 |
/* follows: */ |
| 4415 |
|
| 4416 |
/* TRANS = 'N' or 'n' C := alpha*A*A' + beta*C. */ |
| 4417 |
|
| 4418 |
/* TRANS = 'T' or 't' C := alpha*A'*A + beta*C. */ |
| 4419 |
|
| 4420 |
/* Unchanged on exit. */ |
| 4421 |
|
| 4422 |
/* N - (input) INTEGER. */ |
| 4423 |
/* On entry, N specifies the order of the matrix C. N must be */ |
| 4424 |
/* at least zero. */ |
| 4425 |
/* Unchanged on exit. */ |
| 4426 |
|
| 4427 |
/* K - (input) INTEGER. */ |
| 4428 |
/* On entry with TRANS = 'N' or 'n', K specifies the number */ |
| 4429 |
/* of columns of the matrix A, and on entry with TRANS = 'T' */ |
| 4430 |
/* or 't', K specifies the number of rows of the matrix A. K */ |
| 4431 |
/* must be at least zero. */ |
| 4432 |
/* Unchanged on exit. */ |
| 4433 |
|
| 4434 |
/* ALPHA - (input) DOUBLE PRECISION. */ |
| 4435 |
/* On entry, ALPHA specifies the scalar alpha. */ |
| 4436 |
/* Unchanged on exit. */ |
| 4437 |
|
| 4438 |
/* A - (input) DOUBLE PRECISION array of DIMENSION ( LDA, ka ), where KA */ |
| 4439 |
/* is K when TRANS = 'N' or 'n', and is N otherwise. Before */ |
| 4440 |
/* entry with TRANS = 'N' or 'n', the leading N--by--K part of */ |
| 4441 |
/* the array A must contain the matrix A, otherwise the leading */ |
| 4442 |
/* K--by--N part of the array A must contain the matrix A. */ |
| 4443 |
/* Unchanged on exit. */ |
| 4444 |
|
| 4445 |
/* LDA - (input) INTEGER. */ |
| 4446 |
/* On entry, LDA specifies the first dimension of A as declared */ |
| 4447 |
/* in the calling (sub) program. When TRANS = 'N' or 'n' */ |
| 4448 |
/* then LDA must be at least max( 1, n ), otherwise LDA must */ |
| 4449 |
/* be at least max( 1, k ). */ |
| 4450 |
/* Unchanged on exit. */ |
| 4451 |
|
| 4452 |
/* BETA - (input) DOUBLE PRECISION. */ |
| 4453 |
/* On entry, BETA specifies the scalar beta. */ |
| 4454 |
/* Unchanged on exit. */ |
| 4455 |
|
| 4456 |
|
| 4457 |
/* C - (input/output) DOUBLE PRECISION array, dimension ( NT ); */ |
| 4458 |
/* NT = N*(N+1)/2. On entry, the symmetric matrix C in RFP */ |
| 4459 |
/* Format. RFP Format is described by TRANSR, UPLO and N. */ |
| 4460 |
|
| 4461 |
/* Arguments */ |
| 4462 |
/* ========== */ |
| 4463 |
|
| 4464 |
/* .. */ |
| 4465 |
/* .. Parameters .. */ |
| 4466 |
/* .. */ |
| 4467 |
/* .. Local Scalars .. */ |
| 4468 |
/* .. */ |
| 4469 |
/* .. External Functions .. */ |
| 4470 |
/* .. */ |
| 4471 |
/* .. External Subroutines .. */ |
| 4472 |
/* .. */ |
| 4473 |
/* .. Intrinsic Functions .. */ |
| 4474 |
/* .. */ |
| 4475 |
/* .. Executable Statements .. */ |
| 4476 |
|
| 4477 |
/* Test the input parameters. */ |
| 4478 |
|
| 4479 |
/* Parameter adjustments */ |
| 4480 |
a_dim1 = *lda; |
| 4481 |
a_offset = 1 + a_dim1; |
| 4482 |
a -= a_offset; |
| 4483 |
--c__; |
| 4484 |
|
| 4485 |
/* Function Body */ |
| 4486 |
info = 0; |
| 4487 |
normaltransr = lsame_(transr, "N"); |
| 4488 |
lower = lsame_(uplo, "L"); |
| 4489 |
notrans = lsame_(trans, "N"); |
| 4490 |
|
| 4491 |
if (notrans) { |
| 4492 |
nrowa = *n; |
| 4493 |
} else { |
| 4494 |
nrowa = *k; |
| 4495 |
} |
| 4496 |
|
| 4497 |
if (! normaltransr && ! lsame_(transr, "T")) { |
| 4498 |
info = -1; |
| 4499 |
} else if (! lower && ! lsame_(uplo, "U")) { |
| 4500 |
info = -2; |
| 4501 |
} else if (! notrans && ! lsame_(trans, "T")) { |
| 4502 |
info = -3; |
| 4503 |
} else if (*n < 0) { |
| 4504 |
info = -4; |
| 4505 |
} else if (*k < 0) { |
| 4506 |
info = -5; |
| 4507 |
} else if (*lda < std::max(1_integer,nrowa)) { |
| 4508 |
info = -8; |
| 4509 |
} |
| 4510 |
if (info != 0) { |
| 4511 |
i__1 = -info; |
| 4512 |
xerbla_("DSFRK ", &i__1); |
| 4513 |
return 0; |
| 4514 |
} |
| 4515 |
|
| 4516 |
/* Quick return if possible. */ |
| 4517 |
|
| 4518 |
/* The quick return case: ((ALPHA.EQ.0).AND.(BETA.NE.ZERO)) is not */ |
| 4519 |
/* done (it is in DSYRK for example) and left in the general case. */ |
| 4520 |
|
| 4521 |
if (*n == 0 || (*alpha == 0. || *k == 0) && *beta == 1.) { |
| 4522 |
return 0; |
| 4523 |
} |
| 4524 |
|
| 4525 |
if (*alpha == 0. && *beta == 0.) { |
| 4526 |
i__1 = *n * (*n + 1) / 2; |
| 4527 |
for (j = 1; j <= i__1; ++j) { |
| 4528 |
c__[j] = 0.; |
| 4529 |
} |
| 4530 |
return 0; |
| 4531 |
} |
| 4532 |
|
| 4533 |
/* C is N-by-N. */ |
| 4534 |
/* If N is odd, set NISODD = .TRUE., and N1 and N2. */ |
| 4535 |
/* If N is even, NISODD = .FALSE., and NK. */ |
| 4536 |
|
| 4537 |
if (*n % 2 == 0) { |
| 4538 |
nisodd = false; |
| 4539 |
nk = *n / 2; |
| 4540 |
} else { |
| 4541 |
nisodd = true; |
| 4542 |
if (lower) { |
| 4543 |
n2 = *n / 2; |
| 4544 |
n1 = *n - n2; |
| 4545 |
} else { |
| 4546 |
n1 = *n / 2; |
| 4547 |
n2 = *n - n1; |
| 4548 |
} |
| 4549 |
} |
| 4550 |
|
| 4551 |
if (nisodd) { |
| 4552 |
|
| 4553 |
/* N is odd */ |
| 4554 |
|
| 4555 |
if (normaltransr) { |
| 4556 |
|
| 4557 |
/* N is odd and TRANSR = 'N' */ |
| 4558 |
|
| 4559 |
if (lower) { |
| 4560 |
|
| 4561 |
/* N is odd, TRANSR = 'N', and UPLO = 'L' */ |
| 4562 |
|
| 4563 |
if (notrans) { |
| 4564 |
|
| 4565 |
/* N is odd, TRANSR = 'N', UPLO = 'L', and TRANS = 'N' */ |
| 4566 |
|
| 4567 |
dsyrk_("L", "N", &n1, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4568 |
&c__[1], n); |
| 4569 |
dsyrk_("U", "N", &n2, k, alpha, &a[n1 + 1 + a_dim1], lda, |
| 4570 |
beta, &c__[*n + 1], n); |
| 4571 |
dgemm_("N", "T", &n2, &n1, k, alpha, &a[n1 + 1 + a_dim1], |
| 4572 |
lda, &a[a_dim1 + 1], lda, beta, &c__[n1 + 1], n); |
| 4573 |
|
| 4574 |
} else { |
| 4575 |
|
| 4576 |
/* N is odd, TRANSR = 'N', UPLO = 'L', and TRANS = 'T' */ |
| 4577 |
|
| 4578 |
dsyrk_("L", "T", &n1, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4579 |
&c__[1], n); |
| 4580 |
dsyrk_("U", "T", &n2, k, alpha, &a[(n1 + 1) * a_dim1 + 1], |
| 4581 |
lda, beta, &c__[*n + 1], n) |
| 4582 |
; |
| 4583 |
dgemm_("T", "N", &n2, &n1, k, alpha, &a[(n1 + 1) * a_dim1 |
| 4584 |
+ 1], lda, &a[a_dim1 + 1], lda, beta, &c__[n1 + 1], n); |
| 4585 |
|
| 4586 |
} |
| 4587 |
|
| 4588 |
} else { |
| 4589 |
|
| 4590 |
/* N is odd, TRANSR = 'N', and UPLO = 'U' */ |
| 4591 |
|
| 4592 |
if (notrans) { |
| 4593 |
|
| 4594 |
/* N is odd, TRANSR = 'N', UPLO = 'U', and TRANS = 'N' */ |
| 4595 |
|
| 4596 |
dsyrk_("L", "N", &n1, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4597 |
&c__[n2 + 1], n); |
| 4598 |
dsyrk_("U", "N", &n2, k, alpha, &a[n2 + a_dim1], lda, |
| 4599 |
beta, &c__[n1 + 1], n); |
| 4600 |
dgemm_("N", "T", &n1, &n2, k, alpha, &a[a_dim1 + 1], lda, |
| 4601 |
&a[n2 + a_dim1], lda, beta, &c__[1], n); |
| 4602 |
|
| 4603 |
} else { |
| 4604 |
|
| 4605 |
/* N is odd, TRANSR = 'N', UPLO = 'U', and TRANS = 'T' */ |
| 4606 |
|
| 4607 |
dsyrk_("L", "T", &n1, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4608 |
&c__[n2 + 1], n); |
| 4609 |
dsyrk_("U", "T", &n2, k, alpha, &a[n2 * a_dim1 + 1], lda, |
| 4610 |
beta, &c__[n1 + 1], n); |
| 4611 |
dgemm_("T", "N", &n1, &n2, k, alpha, &a[a_dim1 + 1], lda, |
| 4612 |
&a[n2 * a_dim1 + 1], lda, beta, &c__[1], n); |
| 4613 |
|
| 4614 |
} |
| 4615 |
|
| 4616 |
} |
| 4617 |
|
| 4618 |
} else { |
| 4619 |
|
| 4620 |
/* N is odd, and TRANSR = 'T' */ |
| 4621 |
|
| 4622 |
if (lower) { |
| 4623 |
|
| 4624 |
/* N is odd, TRANSR = 'T', and UPLO = 'L' */ |
| 4625 |
|
| 4626 |
if (notrans) { |
| 4627 |
|
| 4628 |
/* N is odd, TRANSR = 'T', UPLO = 'L', and TRANS = 'N' */ |
| 4629 |
|
| 4630 |
dsyrk_("U", "N", &n1, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4631 |
&c__[1], &n1); |
| 4632 |
dsyrk_("L", "N", &n2, k, alpha, &a[n1 + 1 + a_dim1], lda, |
| 4633 |
beta, &c__[2], &n1); |
| 4634 |
dgemm_("N", "T", &n1, &n2, k, alpha, &a[a_dim1 + 1], lda, |
| 4635 |
&a[n1 + 1 + a_dim1], lda, beta, &c__[n1 * n1 + 1], |
| 4636 |
&n1); |
| 4637 |
|
| 4638 |
} else { |
| 4639 |
|
| 4640 |
/* N is odd, TRANSR = 'T', UPLO = 'L', and TRANS = 'T' */ |
| 4641 |
|
| 4642 |
dsyrk_("U", "T", &n1, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4643 |
&c__[1], &n1); |
| 4644 |
dsyrk_("L", "T", &n2, k, alpha, &a[(n1 + 1) * a_dim1 + 1], |
| 4645 |
lda, beta, &c__[2], &n1); |
| 4646 |
dgemm_("T", "N", &n1, &n2, k, alpha, &a[a_dim1 + 1], lda, |
| 4647 |
&a[(n1 + 1) * a_dim1 + 1], lda, beta, &c__[n1 * |
| 4648 |
n1 + 1], &n1); |
| 4649 |
|
| 4650 |
} |
| 4651 |
|
| 4652 |
} else { |
| 4653 |
|
| 4654 |
/* N is odd, TRANSR = 'T', and UPLO = 'U' */ |
| 4655 |
|
| 4656 |
if (notrans) { |
| 4657 |
|
| 4658 |
/* N is odd, TRANSR = 'T', UPLO = 'U', and TRANS = 'N' */ |
| 4659 |
|
| 4660 |
dsyrk_("U", "N", &n1, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4661 |
&c__[n2 * n2 + 1], &n2); |
| 4662 |
dsyrk_("L", "N", &n2, k, alpha, &a[n1 + 1 + a_dim1], lda, |
| 4663 |
beta, &c__[n1 * n2 + 1], &n2); |
| 4664 |
dgemm_("N", "T", &n2, &n1, k, alpha, &a[n1 + 1 + a_dim1], |
| 4665 |
lda, &a[a_dim1 + 1], lda, beta, &c__[1], &n2); |
| 4666 |
|
| 4667 |
} else { |
| 4668 |
|
| 4669 |
/* N is odd, TRANSR = 'T', UPLO = 'U', and TRANS = 'T' */ |
| 4670 |
|
| 4671 |
dsyrk_("U", "T", &n1, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4672 |
&c__[n2 * n2 + 1], &n2); |
| 4673 |
dsyrk_("L", "T", &n2, k, alpha, &a[(n1 + 1) * a_dim1 + 1], |
| 4674 |
lda, beta, &c__[n1 * n2 + 1], &n2); |
| 4675 |
dgemm_("T", "N", &n2, &n1, k, alpha, &a[(n1 + 1) * a_dim1 |
| 4676 |
+ 1], lda, &a[a_dim1 + 1], lda, beta, &c__[1], & |
| 4677 |
n2); |
| 4678 |
|
| 4679 |
} |
| 4680 |
|
| 4681 |
} |
| 4682 |
|
| 4683 |
} |
| 4684 |
|
| 4685 |
} else { |
| 4686 |
|
| 4687 |
/* N is even */ |
| 4688 |
|
| 4689 |
if (normaltransr) { |
| 4690 |
|
| 4691 |
/* N is even and TRANSR = 'N' */ |
| 4692 |
|
| 4693 |
if (lower) { |
| 4694 |
|
| 4695 |
/* N is even, TRANSR = 'N', and UPLO = 'L' */ |
| 4696 |
|
| 4697 |
if (notrans) { |
| 4698 |
|
| 4699 |
/* N is even, TRANSR = 'N', UPLO = 'L', and TRANS = 'N' */ |
| 4700 |
|
| 4701 |
i__1 = *n + 1; |
| 4702 |
dsyrk_("L", "N", &nk, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4703 |
&c__[2], &i__1); |
| 4704 |
i__1 = *n + 1; |
| 4705 |
dsyrk_("U", "N", &nk, k, alpha, &a[nk + 1 + a_dim1], lda, |
| 4706 |
beta, &c__[1], &i__1); |
| 4707 |
i__1 = *n + 1; |
| 4708 |
dgemm_("N", "T", &nk, &nk, k, alpha, &a[nk + 1 + a_dim1], |
| 4709 |
lda, &a[a_dim1 + 1], lda, beta, &c__[nk + 2], & |
| 4710 |
i__1); |
| 4711 |
|
| 4712 |
} else { |
| 4713 |
|
| 4714 |
/* N is even, TRANSR = 'N', UPLO = 'L', and TRANS = 'T' */ |
| 4715 |
|
| 4716 |
i__1 = *n + 1; |
| 4717 |
dsyrk_("L", "T", &nk, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4718 |
&c__[2], &i__1); |
| 4719 |
i__1 = *n + 1; |
| 4720 |
dsyrk_("U", "T", &nk, k, alpha, &a[(nk + 1) * a_dim1 + 1], |
| 4721 |
lda, beta, &c__[1], &i__1); |
| 4722 |
i__1 = *n + 1; |
| 4723 |
dgemm_("T", "N", &nk, &nk, k, alpha, &a[(nk + 1) * a_dim1 |
| 4724 |
+ 1], lda, &a[a_dim1 + 1], lda, beta, &c__[nk + 2], &i__1); |
| 4725 |
|
| 4726 |
} |
| 4727 |
|
| 4728 |
} else { |
| 4729 |
|
| 4730 |
/* N is even, TRANSR = 'N', and UPLO = 'U' */ |
| 4731 |
|
| 4732 |
if (notrans) { |
| 4733 |
|
| 4734 |
/* N is even, TRANSR = 'N', UPLO = 'U', and TRANS = 'N' */ |
| 4735 |
|
| 4736 |
i__1 = *n + 1; |
| 4737 |
dsyrk_("L", "N", &nk, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4738 |
&c__[nk + 2], &i__1); |
| 4739 |
i__1 = *n + 1; |
| 4740 |
dsyrk_("U", "N", &nk, k, alpha, &a[nk + 1 + a_dim1], lda, |
| 4741 |
beta, &c__[nk + 1], &i__1); |
| 4742 |
i__1 = *n + 1; |
| 4743 |
dgemm_("N", "T", &nk, &nk, k, alpha, &a[a_dim1 + 1], lda, |
| 4744 |
&a[nk + 1 + a_dim1], lda, beta, &c__[1], &i__1); |
| 4745 |
|
| 4746 |
} else { |
| 4747 |
|
| 4748 |
/* N is even, TRANSR = 'N', UPLO = 'U', and TRANS = 'T' */ |
| 4749 |
|
| 4750 |
i__1 = *n + 1; |
| 4751 |
dsyrk_("L", "T", &nk, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4752 |
&c__[nk + 2], &i__1); |
| 4753 |
i__1 = *n + 1; |
| 4754 |
dsyrk_("U", "T", &nk, k, alpha, &a[(nk + 1) * a_dim1 + 1], |
| 4755 |
lda, beta, &c__[nk + 1], &i__1); |
| 4756 |
i__1 = *n + 1; |
| 4757 |
dgemm_("T", "N", &nk, &nk, k, alpha, &a[a_dim1 + 1], lda, |
| 4758 |
&a[(nk + 1) * a_dim1 + 1], lda, beta, &c__[1], &i__1); |
| 4759 |
|
| 4760 |
} |
| 4761 |
|
| 4762 |
} |
| 4763 |
|
| 4764 |
} else { |
| 4765 |
|
| 4766 |
/* N is even, and TRANSR = 'T' */ |
| 4767 |
|
| 4768 |
if (lower) { |
| 4769 |
|
| 4770 |
/* N is even, TRANSR = 'T', and UPLO = 'L' */ |
| 4771 |
|
| 4772 |
if (notrans) { |
| 4773 |
|
| 4774 |
/* N is even, TRANSR = 'T', UPLO = 'L', and TRANS = 'N' */ |
| 4775 |
|
| 4776 |
dsyrk_("U", "N", &nk, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4777 |
&c__[nk + 1], &nk); |
| 4778 |
dsyrk_("L", "N", &nk, k, alpha, &a[nk + 1 + a_dim1], lda, |
| 4779 |
beta, &c__[1], &nk); |
| 4780 |
dgemm_("N", "T", &nk, &nk, k, alpha, &a[a_dim1 + 1], lda, |
| 4781 |
&a[nk + 1 + a_dim1], lda, beta, &c__[(nk + 1) * |
| 4782 |
nk + 1], &nk); |
| 4783 |
|
| 4784 |
} else { |
| 4785 |
|
| 4786 |
/* N is even, TRANSR = 'T', UPLO = 'L', and TRANS = 'T' */ |
| 4787 |
|
| 4788 |
dsyrk_("U", "T", &nk, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4789 |
&c__[nk + 1], &nk); |
| 4790 |
dsyrk_("L", "T", &nk, k, alpha, &a[(nk + 1) * a_dim1 + 1], |
| 4791 |
lda, beta, &c__[1], &nk); |
| 4792 |
dgemm_("T", "N", &nk, &nk, k, alpha, &a[a_dim1 + 1], lda, |
| 4793 |
&a[(nk + 1) * a_dim1 + 1], lda, beta, &c__[(nk + 1) * nk + 1], &nk); |
| 4794 |
|
| 4795 |
} |
| 4796 |
|
| 4797 |
} else { |
| 4798 |
|
| 4799 |
/* N is even, TRANSR = 'T', and UPLO = 'U' */ |
| 4800 |
|
| 4801 |
if (notrans) { |
| 4802 |
|
| 4803 |
/* N is even, TRANSR = 'T', UPLO = 'U', and TRANS = 'N' */ |
| 4804 |
|
| 4805 |
dsyrk_("U", "N", &nk, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4806 |
&c__[nk * (nk + 1) + 1], &nk); |
| 4807 |
dsyrk_("L", "N", &nk, k, alpha, &a[nk + 1 + a_dim1], lda, |
| 4808 |
beta, &c__[nk * nk + 1], &nk); |
| 4809 |
dgemm_("N", "T", &nk, &nk, k, alpha, &a[nk + 1 + a_dim1], |
| 4810 |
lda, &a[a_dim1 + 1], lda, beta, &c__[1], &nk); |
| 4811 |
|
| 4812 |
} else { |
| 4813 |
|
| 4814 |
/* N is even, TRANSR = 'T', UPLO = 'U', and TRANS = 'T' */ |
| 4815 |
|
| 4816 |
dsyrk_("U", "T", &nk, k, alpha, &a[a_dim1 + 1], lda, beta, |
| 4817 |
&c__[nk * (nk + 1) + 1], &nk); |
| 4818 |
dsyrk_("L", "T", &nk, k, alpha, &a[(nk + 1) * a_dim1 + 1], |
| 4819 |
lda, beta, &c__[nk * nk + 1], &nk); |
| 4820 |
dgemm_("T", "N", &nk, &nk, k, alpha, &a[(nk + 1) * a_dim1 |
| 4821 |
+ 1], lda, &a[a_dim1 + 1], lda, beta, &c__[1], & |
| 4822 |
nk); |
| 4823 |
|
| 4824 |
} |
| 4825 |
|
| 4826 |
} |
| 4827 |
|
| 4828 |
} |
| 4829 |
|
| 4830 |
} |
| 4831 |
|
| 4832 |
return 0; |
| 4833 |
|
| 4834 |
/* End of DSFRK */ |
| 4835 |
|
| 4836 |
} /* dsfrk_ */ |
| 4837 |
|
| 4838 |
#if 0 |
| 4839 |
/* Subroutine */ int dsgesv_(integer *n, integer *nrhs, double *a, integer *lda, integer *ipiv, double *b, integer *ldb, |
| 4840 |
double *x, integer *ldx, double *work, float *swork, integer *iter, integer *info) |
| 4841 |
{ |
| 4842 |
/* Table of constant values */ |
| 4843 |
static double c_b10 = -1.; |
| 4844 |
static double c_b11 = 1.; |
| 4845 |
static integer c__1 = 1; |
| 4846 |
|
| 4847 |
/* System generated locals */ |
| 4848 |
integer a_dim1, a_offset, b_dim1, b_offset, work_dim1, work_offset, x_dim1, x_offset, i__1; |
| 4849 |
double d__1; |
| 4850 |
|
| 4851 |
|
| 4852 |
/* Local variables */ |
| 4853 |
double cte, eps, anrm, rnrm, xnrm; |
| 4854 |
integer i__, ptsa, ptsx, iiter; |
| 4855 |
|
| 4856 |
/* -- LAPACK PROTOTYPE driver routine (version 3.2) -- */ |
| 4857 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 4858 |
/* February 2007 */ |
| 4859 |
|
| 4860 |
/* .. */ |
| 4861 |
/* .. Scalar Arguments .. */ |
| 4862 |
/* .. */ |
| 4863 |
/* .. Array Arguments .. */ |
| 4864 |
/* .. */ |
| 4865 |
|
| 4866 |
/* Purpose */ |
| 4867 |
/* ======= */ |
| 4868 |
|
| 4869 |
/* DSGESV computes the solution to a real system of linear equations */ |
| 4870 |
/* A * X = B, */ |
| 4871 |
/* where A is an N-by-N matrix and X and B are N-by-NRHS matrices. */ |
| 4872 |
|
| 4873 |
/* DSGESV first attempts to factorize the matrix in SINGLE PRECISION */ |
| 4874 |
/* and use this factorization within an iterative refinement procedure */ |
| 4875 |
/* to produce a solution with DOUBLE PRECISION normwise backward error */ |
| 4876 |
/* quality (see below). If the approach fails the method switches to a */ |
| 4877 |
/* DOUBLE PRECISION factorization and solve. */ |
| 4878 |
|
| 4879 |
/* The iterative refinement is not going to be a winning strategy if */ |
| 4880 |
/* the ratio SINGLE PRECISION performance over DOUBLE PRECISION */ |
| 4881 |
/* performance is too small. A reasonable strategy should take the */ |
| 4882 |
/* number of right-hand sides and the size of the matrix into account. */ |
| 4883 |
/* This might be done with a call to ILAENV in the future. Up to now, we */ |
| 4884 |
/* always try iterative refinement. */ |
| 4885 |
|
| 4886 |
/* The iterative refinement process is stopped if */ |
| 4887 |
/* ITER > ITERMAX */ |
| 4888 |
/* or for all the RHS we have: */ |
| 4889 |
/* RNRM < SQRT(N)*XNRM*ANRM*EPS*BWDMAX */ |
| 4890 |
/* where */ |
| 4891 |
/* o ITER is the number of the current iteration in the iterative */ |
| 4892 |
/* refinement process */ |
| 4893 |
/* o RNRM is the infinity-norm of the residual */ |
| 4894 |
/* o XNRM is the infinity-norm of the solution */ |
| 4895 |
/* o ANRM is the infinity-operator-norm of the matrix A */ |
| 4896 |
/* o EPS is the machine epsilon returned by DLAMCH('Epsilon') */ |
| 4897 |
/* The value ITERMAX and BWDMAX are fixed to 30 and 1.0D+00 */ |
| 4898 |
/* respectively. */ |
| 4899 |
|
| 4900 |
/* Arguments */ |
| 4901 |
/* ========= */ |
| 4902 |
|
| 4903 |
/* N (input) INTEGER */ |
| 4904 |
/* The number of linear equations, i.e., the order of the */ |
| 4905 |
/* matrix A. N >= 0. */ |
| 4906 |
|
| 4907 |
/* NRHS (input) INTEGER */ |
| 4908 |
/* The number of right hand sides, i.e., the number of columns */ |
| 4909 |
/* of the matrix B. NRHS >= 0. */ |
| 4910 |
|
| 4911 |
/* A (input or input/ouptut) DOUBLE PRECISION array, */ |
| 4912 |
/* dimension (LDA,N) */ |
| 4913 |
/* On entry, the N-by-N coefficient matrix A. */ |
| 4914 |
/* On exit, if iterative refinement has been successfully used */ |
| 4915 |
/* (INFO.EQ.0 and ITER.GE.0, see description below), then A is */ |
| 4916 |
/* unchanged, if double precision factorization has been used */ |
| 4917 |
/* (INFO.EQ.0 and ITER.LT.0, see description below), then the */ |
| 4918 |
/* array A contains the factors L and U from the factorization */ |
| 4919 |
/* A = P*L*U; the unit diagonal elements of L are not stored. */ |
| 4920 |
|
| 4921 |
/* LDA (input) INTEGER */ |
| 4922 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 4923 |
|
| 4924 |
/* IPIV (output) INTEGER array, dimension (N) */ |
| 4925 |
/* The pivot indices that define the permutation matrix P; */ |
| 4926 |
/* row i of the matrix was interchanged with row IPIV(i). */ |
| 4927 |
/* Corresponds either to the single precision factorization */ |
| 4928 |
/* (if INFO.EQ.0 and ITER.GE.0) or the double precision */ |
| 4929 |
/* factorization (if INFO.EQ.0 and ITER.LT.0). */ |
| 4930 |
|
| 4931 |
/* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 4932 |
/* The N-by-NRHS right hand side matrix B. */ |
| 4933 |
|
| 4934 |
/* LDB (input) INTEGER */ |
| 4935 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 4936 |
|
| 4937 |
/* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */ |
| 4938 |
/* If INFO = 0, the N-by-NRHS solution matrix X. */ |
| 4939 |
|
| 4940 |
/* LDX (input) INTEGER */ |
| 4941 |
/* The leading dimension of the array X. LDX >= max(1,N). */ |
| 4942 |
|
| 4943 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (N*NRHS) */ |
| 4944 |
/* This array is used to hold the residual vectors. */ |
| 4945 |
|
| 4946 |
/* SWORK (workspace) REAL array, dimension (N*(N+NRHS)) */ |
| 4947 |
/* This array is used to use the single precision matrix and the */ |
| 4948 |
/* right-hand sides or solutions in single precision. */ |
| 4949 |
|
| 4950 |
/* ITER (output) INTEGER */ |
| 4951 |
/* < 0: iterative refinement has failed, double precision */ |
| 4952 |
/* factorization has been performed */ |
| 4953 |
/* -1 : the routine fell back to full precision for */ |
| 4954 |
/* implementation- or machine-specific reasons */ |
| 4955 |
/* -2 : narrowing the precision induced an overflow, */ |
| 4956 |
/* the routine fell back to full precision */ |
| 4957 |
/* -3 : failure of SGETRF */ |
| 4958 |
/* -31: stop the iterative refinement after the 30th */ |
| 4959 |
/* iterations */ |
| 4960 |
/* > 0: iterative refinement has been sucessfully used. */ |
| 4961 |
/* Returns the number of iterations */ |
| 4962 |
|
| 4963 |
/* INFO (output) INTEGER */ |
| 4964 |
/* = 0: successful exit */ |
| 4965 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 4966 |
/* > 0: if INFO = i, U(i,i) computed in DOUBLE PRECISION is */ |
| 4967 |
/* exactly zero. The factorization has been completed, */ |
| 4968 |
/* but the factor U is exactly singular, so the solution */ |
| 4969 |
/* could not be computed. */ |
| 4970 |
|
| 4971 |
/* ========= */ |
| 4972 |
|
| 4973 |
/* .. Parameters .. */ |
| 4974 |
|
| 4975 |
|
| 4976 |
|
| 4977 |
|
| 4978 |
/* .. Local Scalars .. */ |
| 4979 |
|
| 4980 |
/* .. External Subroutines .. */ |
| 4981 |
/* .. */ |
| 4982 |
/* .. External Functions .. */ |
| 4983 |
/* .. */ |
| 4984 |
/* .. Intrinsic Functions .. */ |
| 4985 |
/* .. */ |
| 4986 |
/* .. Executable Statements .. */ |
| 4987 |
|
| 4988 |
/* Parameter adjustments */ |
| 4989 |
work_dim1 = *n; |
| 4990 |
work_offset = 1 + work_dim1; |
| 4991 |
work -= work_offset; |
| 4992 |
a_dim1 = *lda; |
| 4993 |
a_offset = 1 + a_dim1; |
| 4994 |
a -= a_offset; |
| 4995 |
--ipiv; |
| 4996 |
b_dim1 = *ldb; |
| 4997 |
b_offset = 1 + b_dim1; |
| 4998 |
b -= b_offset; |
| 4999 |
x_dim1 = *ldx; |
| 5000 |
x_offset = 1 + x_dim1; |
| 5001 |
x -= x_offset; |
| 5002 |
--swork; |
| 5003 |
|
| 5004 |
/* Function Body */ |
| 5005 |
*info = 0; |
| 5006 |
*iter = 0; |
| 5007 |
|
| 5008 |
/* Test the input parameters. */ |
| 5009 |
|
| 5010 |
if (*n < 0) { |
| 5011 |
*info = -1; |
| 5012 |
} else if (*nrhs < 0) { |
| 5013 |
*info = -2; |
| 5014 |
} else if (*lda < std::max(1_integer,*n)) { |
| 5015 |
*info = -4; |
| 5016 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 5017 |
*info = -7; |
| 5018 |
} else if (*ldx < std::max(1_integer,*n)) { |
| 5019 |
*info = -9; |
| 5020 |
} |
| 5021 |
if (*info != 0) { |
| 5022 |
i__1 = -(*info); |
| 5023 |
xerbla_("DSGESV", &i__1); |
| 5024 |
return 0; |
| 5025 |
} |
| 5026 |
|
| 5027 |
/* Quick return if (N.EQ.0). */ |
| 5028 |
|
| 5029 |
if (*n == 0) { |
| 5030 |
return 0; |
| 5031 |
} |
| 5032 |
|
| 5033 |
/* Skip single precision iterative refinement if a priori slower */ |
| 5034 |
/* than double precision factorization. */ |
| 5035 |
|
| 5036 |
if (false) { |
| 5037 |
*iter = -1; |
| 5038 |
goto L40; |
| 5039 |
} |
| 5040 |
|
| 5041 |
/* Compute some constants. */ |
| 5042 |
|
| 5043 |
anrm = dlange_("I", n, n, &a[a_offset], lda, &work[work_offset]); |
| 5044 |
eps = dlamch_("Epsilon"); |
| 5045 |
cte = anrm * eps * sqrt((double) (*n)) * 1.; |
| 5046 |
|
| 5047 |
/* Set the indices PTSA, PTSX for referencing SA and SX in SWORK. */ |
| 5048 |
|
| 5049 |
ptsa = 1; |
| 5050 |
ptsx = ptsa + *n * *n; |
| 5051 |
|
| 5052 |
/* Convert B from double precision to single precision and store the */ |
| 5053 |
/* result in SX. */ |
| 5054 |
|
| 5055 |
dlag2s_(n, nrhs, &b[b_offset], ldb, &swork[ptsx], n, info); |
| 5056 |
|
| 5057 |
if (*info != 0) { |
| 5058 |
*iter = -2; |
| 5059 |
goto L40; |
| 5060 |
} |
| 5061 |
|
| 5062 |
/* Convert A from double precision to single precision and store the */ |
| 5063 |
/* result in SA. */ |
| 5064 |
|
| 5065 |
dlag2s_(n, n, &a[a_offset], lda, &swork[ptsa], n, info); |
| 5066 |
|
| 5067 |
if (*info != 0) { |
| 5068 |
*iter = -2; |
| 5069 |
goto L40; |
| 5070 |
} |
| 5071 |
|
| 5072 |
/* Compute the LU factorization of SA. */ |
| 5073 |
|
| 5074 |
sgetrf_(n, n, &swork[ptsa], n, &ipiv[1], info); |
| 5075 |
|
| 5076 |
if (*info != 0) { |
| 5077 |
*iter = -3; |
| 5078 |
goto L40; |
| 5079 |
} |
| 5080 |
|
| 5081 |
/* Solve the system SA*SX = SB. */ |
| 5082 |
|
| 5083 |
sgetrs_("No transpose", n, nrhs, &swork[ptsa], n, &ipiv[1], &swork[ptsx], |
| 5084 |
n, info); |
| 5085 |
|
| 5086 |
/* Convert SX back to double precision */ |
| 5087 |
|
| 5088 |
slag2d_(n, nrhs, &swork[ptsx], n, &x[x_offset], ldx, info); |
| 5089 |
|
| 5090 |
/* Compute R = B - AX (R is WORK). */ |
| 5091 |
|
| 5092 |
dlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n); |
| 5093 |
|
| 5094 |
dgemm_("No Transpose", "No Transpose", n, nrhs, n, &c_b10, &a[a_offset], |
| 5095 |
lda, &x[x_offset], ldx, &c_b11, &work[work_offset], n); |
| 5096 |
|
| 5097 |
/* Check whether the NRHS normwise backward errors satisfy the */ |
| 5098 |
/* stopping criterion. If yes, set ITER=0 and return. */ |
| 5099 |
|
| 5100 |
i__1 = *nrhs; |
| 5101 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 5102 |
xnrm = (d__1 = x[idamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ * |
| 5103 |
x_dim1], abs(d__1)); |
| 5104 |
rnrm = (d__1 = work[idamax_(n, &work[i__ * work_dim1 + 1], &c__1) + |
| 5105 |
i__ * work_dim1], abs(d__1)); |
| 5106 |
if (rnrm > xnrm * cte) { |
| 5107 |
goto L10; |
| 5108 |
} |
| 5109 |
} |
| 5110 |
|
| 5111 |
/* If we are here, the NRHS normwise backward errors satisfy the */ |
| 5112 |
/* stopping criterion. We are good to exit. */ |
| 5113 |
|
| 5114 |
*iter = 0; |
| 5115 |
return 0; |
| 5116 |
|
| 5117 |
L10: |
| 5118 |
|
| 5119 |
for (iiter = 1; iiter <= 30; ++iiter) { |
| 5120 |
|
| 5121 |
/* Convert R (in WORK) from double precision to single precision */ |
| 5122 |
/* and store the result in SX. */ |
| 5123 |
|
| 5124 |
dlag2s_(n, nrhs, &work[work_offset], n, &swork[ptsx], n, info); |
| 5125 |
|
| 5126 |
if (*info != 0) { |
| 5127 |
*iter = -2; |
| 5128 |
goto L40; |
| 5129 |
} |
| 5130 |
|
| 5131 |
/* Solve the system SA*SX = SR. */ |
| 5132 |
|
| 5133 |
sgetrs_("No transpose", n, nrhs, &swork[ptsa], n, &ipiv[1], &swork[ |
| 5134 |
ptsx], n, info); |
| 5135 |
|
| 5136 |
/* Convert SX back to double precision and update the current */ |
| 5137 |
/* iterate. */ |
| 5138 |
|
| 5139 |
slag2d_(n, nrhs, &swork[ptsx], n, &work[work_offset], n, info); |
| 5140 |
|
| 5141 |
i__1 = *nrhs; |
| 5142 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 5143 |
daxpy_(n, &c_b11, &work[i__ * work_dim1 + 1], &c__1, &x[i__ * |
| 5144 |
x_dim1 + 1], &c__1); |
| 5145 |
} |
| 5146 |
|
| 5147 |
/* Compute R = B - AX (R is WORK). */ |
| 5148 |
|
| 5149 |
dlacpy_("All", n, nrhs, &b[b_offset], ldb, &work[work_offset], n); |
| 5150 |
|
| 5151 |
dgemm_("No Transpose", "No Transpose", n, nrhs, n, &c_b10, &a[ |
| 5152 |
a_offset], lda, &x[x_offset], ldx, &c_b11, &work[work_offset], |
| 5153 |
n); |
| 5154 |
|
| 5155 |
/* Check whether the NRHS normwise backward errors satisfy the */ |
| 5156 |
/* stopping criterion. If yes, set ITER=IITER>0 and return. */ |
| 5157 |
|
| 5158 |
i__1 = *nrhs; |
| 5159 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 5160 |
xnrm = (d__1 = x[idamax_(n, &x[i__ * x_dim1 + 1], &c__1) + i__ * |
| 5161 |
x_dim1], abs(d__1)); |
| 5162 |
rnrm = (d__1 = work[idamax_(n, &work[i__ * work_dim1 + 1], &c__1) |
| 5163 |
+ i__ * work_dim1], abs(d__1)); |
| 5164 |
if (rnrm > xnrm * cte) { |
| 5165 |
goto L20; |
| 5166 |
} |
| 5167 |
} |
| 5168 |
|
| 5169 |
/* If we are here, the NRHS normwise backward errors satisfy the */ |
| 5170 |
/* stopping criterion, we are good to exit. */ |
| 5171 |
|
| 5172 |
*iter = iiter; |
| 5173 |
|
| 5174 |
return 0; |
| 5175 |
|
| 5176 |
L20: |
| 5177 |
|
| 5178 |
/* L30: */ |
| 5179 |
; |
| 5180 |
} |
| 5181 |
|
| 5182 |
/* If we are at this place of the code, this is because we have */ |
| 5183 |
/* performed ITER=ITERMAX iterations and never satisified the */ |
| 5184 |
/* stopping criterion, set up the ITER flag accordingly and follow up */ |
| 5185 |
/* on double precision routine. */ |
| 5186 |
|
| 5187 |
*iter = -31; |
| 5188 |
|
| 5189 |
L40: |
| 5190 |
|
| 5191 |
/* Single-precision iterative refinement failed to converge to a */ |
| 5192 |
/* satisfactory solution, so we resort to double precision. */ |
| 5193 |
|
| 5194 |
dgetrf_(n, n, &a[a_offset], lda, &ipiv[1], info); |
| 5195 |
|
| 5196 |
if (*info != 0) { |
| 5197 |
return 0; |
| 5198 |
} |
| 5199 |
|
| 5200 |
dlacpy_("All", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx); |
| 5201 |
dgetrs_("No transpose", n, nrhs, &a[a_offset], lda, &ipiv[1], &x[x_offset] |
| 5202 |
, ldx, info); |
| 5203 |
|
| 5204 |
return 0; |
| 5205 |
|
| 5206 |
/* End of DSGESV. */ |
| 5207 |
|
| 5208 |
} /* dsgesv_ */ |
| 5209 |
#endif |
| 5210 |
|
| 5211 |
/* Subroutine */ int dspcon_(const char *uplo, integer *n, double *ap, integer * |
| 5212 |
ipiv, double *anorm, double *rcond, double *work, integer |
| 5213 |
*iwork, integer *info) |
| 5214 |
{ |
| 5215 |
/* Table of constant values */ |
| 5216 |
static integer c__1 = 1; |
| 5217 |
|
| 5218 |
/* System generated locals */ |
| 5219 |
integer i__1; |
| 5220 |
|
| 5221 |
/* Local variables */ |
| 5222 |
integer i__, ip, kase; |
| 5223 |
integer isave[3]; |
| 5224 |
bool upper; |
| 5225 |
double ainvnm; |
| 5226 |
|
| 5227 |
/* -- LAPACK routine (version 3.1) -- */ |
| 5228 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 5229 |
/* November 2006 */ |
| 5230 |
|
| 5231 |
/* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */ |
| 5232 |
|
| 5233 |
/* .. Scalar Arguments .. */ |
| 5234 |
/* .. */ |
| 5235 |
/* .. Array Arguments .. */ |
| 5236 |
/* .. */ |
| 5237 |
|
| 5238 |
/* Purpose */ |
| 5239 |
/* ======= */ |
| 5240 |
|
| 5241 |
/* DSPCON estimates the reciprocal of the condition number (in the */ |
| 5242 |
/* 1-norm) of a real symmetric packed matrix A using the factorization */ |
| 5243 |
/* A = U*D*U**T or A = L*D*L**T computed by DSPTRF. */ |
| 5244 |
|
| 5245 |
/* An estimate is obtained for norm(inv(A)), and the reciprocal of the */ |
| 5246 |
/* condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). */ |
| 5247 |
|
| 5248 |
/* Arguments */ |
| 5249 |
/* ========= */ |
| 5250 |
|
| 5251 |
/* UPLO (input) CHARACTER*1 */ |
| 5252 |
/* Specifies whether the details of the factorization are stored */ |
| 5253 |
/* as an upper or lower triangular matrix. */ |
| 5254 |
/* = 'U': Upper triangular, form is A = U*D*U**T; */ |
| 5255 |
/* = 'L': Lower triangular, form is A = L*D*L**T. */ |
| 5256 |
|
| 5257 |
/* N (input) INTEGER */ |
| 5258 |
/* The order of the matrix A. N >= 0. */ |
| 5259 |
|
| 5260 |
/* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 5261 |
/* The block diagonal matrix D and the multipliers used to */ |
| 5262 |
/* obtain the factor U or L as computed by DSPTRF, stored as a */ |
| 5263 |
/* packed triangular matrix. */ |
| 5264 |
|
| 5265 |
/* IPIV (input) INTEGER array, dimension (N) */ |
| 5266 |
/* Details of the interchanges and the block structure of D */ |
| 5267 |
/* as determined by DSPTRF. */ |
| 5268 |
|
| 5269 |
/* ANORM (input) DOUBLE PRECISION */ |
| 5270 |
/* The 1-norm of the original matrix A. */ |
| 5271 |
|
| 5272 |
/* RCOND (output) DOUBLE PRECISION */ |
| 5273 |
/* The reciprocal of the condition number of the matrix A, */ |
| 5274 |
/* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an */ |
| 5275 |
/* estimate of the 1-norm of inv(A) computed in this routine. */ |
| 5276 |
|
| 5277 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */ |
| 5278 |
|
| 5279 |
/* IWORK (workspace) INTEGER array, dimension (N) */ |
| 5280 |
|
| 5281 |
/* INFO (output) INTEGER */ |
| 5282 |
/* = 0: successful exit */ |
| 5283 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 5284 |
|
| 5285 |
/* ===================================================================== */ |
| 5286 |
|
| 5287 |
/* .. Parameters .. */ |
| 5288 |
/* .. */ |
| 5289 |
/* .. Local Scalars .. */ |
| 5290 |
/* .. */ |
| 5291 |
/* .. Local Arrays .. */ |
| 5292 |
/* .. */ |
| 5293 |
/* .. External Functions .. */ |
| 5294 |
/* .. */ |
| 5295 |
/* .. External Subroutines .. */ |
| 5296 |
/* .. */ |
| 5297 |
/* .. Executable Statements .. */ |
| 5298 |
|
| 5299 |
/* Test the input parameters. */ |
| 5300 |
|
| 5301 |
/* Parameter adjustments */ |
| 5302 |
--iwork; |
| 5303 |
--work; |
| 5304 |
--ipiv; |
| 5305 |
--ap; |
| 5306 |
|
| 5307 |
/* Function Body */ |
| 5308 |
*info = 0; |
| 5309 |
upper = lsame_(uplo, "U"); |
| 5310 |
if (! upper && ! lsame_(uplo, "L")) { |
| 5311 |
*info = -1; |
| 5312 |
} else if (*n < 0) { |
| 5313 |
*info = -2; |
| 5314 |
} else if (*anorm < 0.) { |
| 5315 |
*info = -5; |
| 5316 |
} |
| 5317 |
if (*info != 0) { |
| 5318 |
i__1 = -(*info); |
| 5319 |
xerbla_("DSPCON", &i__1); |
| 5320 |
return 0; |
| 5321 |
} |
| 5322 |
|
| 5323 |
/* Quick return if possible */ |
| 5324 |
|
| 5325 |
*rcond = 0.; |
| 5326 |
if (*n == 0) { |
| 5327 |
*rcond = 1.; |
| 5328 |
return 0; |
| 5329 |
} else if (*anorm <= 0.) { |
| 5330 |
return 0; |
| 5331 |
} |
| 5332 |
|
| 5333 |
/* Check that the diagonal matrix D is nonsingular. */ |
| 5334 |
|
| 5335 |
if (upper) { |
| 5336 |
|
| 5337 |
/* Upper triangular storage: examine D from bottom to top */ |
| 5338 |
|
| 5339 |
ip = *n * (*n + 1) / 2; |
| 5340 |
for (i__ = *n; i__ >= 1; --i__) { |
| 5341 |
if (ipiv[i__] > 0 && ap[ip] == 0.) { |
| 5342 |
return 0; |
| 5343 |
} |
| 5344 |
ip -= i__; |
| 5345 |
/* L10: */ |
| 5346 |
} |
| 5347 |
} else { |
| 5348 |
|
| 5349 |
/* Lower triangular storage: examine D from top to bottom. */ |
| 5350 |
|
| 5351 |
ip = 1; |
| 5352 |
i__1 = *n; |
| 5353 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 5354 |
if (ipiv[i__] > 0 && ap[ip] == 0.) { |
| 5355 |
return 0; |
| 5356 |
} |
| 5357 |
ip = ip + *n - i__ + 1; |
| 5358 |
/* L20: */ |
| 5359 |
} |
| 5360 |
} |
| 5361 |
|
| 5362 |
/* Estimate the 1-norm of the inverse. */ |
| 5363 |
|
| 5364 |
kase = 0; |
| 5365 |
L30: |
| 5366 |
dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave); |
| 5367 |
if (kase != 0) { |
| 5368 |
|
| 5369 |
/* Multiply by inv(L*D*L') or inv(U*D*U'). */ |
| 5370 |
|
| 5371 |
dsptrs_(uplo, n, &c__1, &ap[1], &ipiv[1], &work[1], n, info); |
| 5372 |
goto L30; |
| 5373 |
} |
| 5374 |
|
| 5375 |
/* Compute the estimate of the reciprocal condition number. */ |
| 5376 |
|
| 5377 |
if (ainvnm != 0.) { |
| 5378 |
*rcond = 1. / ainvnm / *anorm; |
| 5379 |
} |
| 5380 |
|
| 5381 |
return 0; |
| 5382 |
|
| 5383 |
/* End of DSPCON */ |
| 5384 |
|
| 5385 |
} /* dspcon_ */ |
| 5386 |
|
| 5387 |
/* Subroutine */ int dspev_(const char *jobz, const char *uplo, integer *n, double * |
| 5388 |
ap, double *w, double *z__, integer *ldz, double *work, |
| 5389 |
integer *info) |
| 5390 |
{ |
| 5391 |
/* Table of constant values */ |
| 5392 |
static integer c__1 = 1; |
| 5393 |
|
| 5394 |
/* System generated locals */ |
| 5395 |
integer z_dim1, z_offset, i__1; |
| 5396 |
double d__1; |
| 5397 |
|
| 5398 |
/* Local variables */ |
| 5399 |
double eps; |
| 5400 |
integer inde; |
| 5401 |
double anrm; |
| 5402 |
integer imax; |
| 5403 |
double rmin, rmax; |
| 5404 |
double sigma; |
| 5405 |
integer iinfo; |
| 5406 |
bool wantz; |
| 5407 |
integer iscale; |
| 5408 |
double safmin; |
| 5409 |
double bignum; |
| 5410 |
integer indtau; |
| 5411 |
integer indwrk; |
| 5412 |
double smlnum; |
| 5413 |
|
| 5414 |
|
| 5415 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 5416 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 5417 |
/* November 2006 */ |
| 5418 |
|
| 5419 |
/* .. Scalar Arguments .. */ |
| 5420 |
/* .. */ |
| 5421 |
/* .. Array Arguments .. */ |
| 5422 |
/* .. */ |
| 5423 |
|
| 5424 |
/* Purpose */ |
| 5425 |
/* ======= */ |
| 5426 |
|
| 5427 |
/* DSPEV computes all the eigenvalues and, optionally, eigenvectors of a */ |
| 5428 |
/* real symmetric matrix A in packed storage. */ |
| 5429 |
|
| 5430 |
/* Arguments */ |
| 5431 |
/* ========= */ |
| 5432 |
|
| 5433 |
/* JOBZ (input) CHARACTER*1 */ |
| 5434 |
/* = 'N': Compute eigenvalues only; */ |
| 5435 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 5436 |
|
| 5437 |
/* UPLO (input) CHARACTER*1 */ |
| 5438 |
/* = 'U': Upper triangle of A is stored; */ |
| 5439 |
/* = 'L': Lower triangle of A is stored. */ |
| 5440 |
|
| 5441 |
/* N (input) INTEGER */ |
| 5442 |
/* The order of the matrix A. N >= 0. */ |
| 5443 |
|
| 5444 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 5445 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 5446 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 5447 |
/* is stored in the array AP as follows: */ |
| 5448 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 5449 |
/* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ |
| 5450 |
|
| 5451 |
/* On exit, AP is overwritten by values generated during the */ |
| 5452 |
/* reduction to tridiagonal form. If UPLO = 'U', the diagonal */ |
| 5453 |
/* and first superdiagonal of the tridiagonal matrix T overwrite */ |
| 5454 |
/* the corresponding elements of A, and if UPLO = 'L', the */ |
| 5455 |
/* diagonal and first subdiagonal of T overwrite the */ |
| 5456 |
/* corresponding elements of A. */ |
| 5457 |
|
| 5458 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 5459 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 5460 |
|
| 5461 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 5462 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */ |
| 5463 |
/* eigenvectors of the matrix A, with the i-th column of Z */ |
| 5464 |
/* holding the eigenvector associated with W(i). */ |
| 5465 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 5466 |
|
| 5467 |
/* LDZ (input) INTEGER */ |
| 5468 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 5469 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 5470 |
|
| 5471 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */ |
| 5472 |
|
| 5473 |
/* INFO (output) INTEGER */ |
| 5474 |
/* = 0: successful exit. */ |
| 5475 |
/* < 0: if INFO = -i, the i-th argument had an illegal value. */ |
| 5476 |
/* > 0: if INFO = i, the algorithm failed to converge; i */ |
| 5477 |
/* off-diagonal elements of an intermediate tridiagonal */ |
| 5478 |
/* form did not converge to zero. */ |
| 5479 |
|
| 5480 |
/* ===================================================================== */ |
| 5481 |
|
| 5482 |
/* .. Parameters .. */ |
| 5483 |
/* .. */ |
| 5484 |
/* .. Local Scalars .. */ |
| 5485 |
/* .. */ |
| 5486 |
/* .. External Functions .. */ |
| 5487 |
/* .. */ |
| 5488 |
/* .. External Subroutines .. */ |
| 5489 |
/* .. */ |
| 5490 |
/* .. Intrinsic Functions .. */ |
| 5491 |
/* .. */ |
| 5492 |
/* .. Executable Statements .. */ |
| 5493 |
|
| 5494 |
/* Test the input parameters. */ |
| 5495 |
|
| 5496 |
/* Parameter adjustments */ |
| 5497 |
--ap; |
| 5498 |
--w; |
| 5499 |
z_dim1 = *ldz; |
| 5500 |
z_offset = 1 + z_dim1; |
| 5501 |
z__ -= z_offset; |
| 5502 |
--work; |
| 5503 |
|
| 5504 |
/* Function Body */ |
| 5505 |
wantz = lsame_(jobz, "V"); |
| 5506 |
|
| 5507 |
*info = 0; |
| 5508 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 5509 |
*info = -1; |
| 5510 |
} else if (! (lsame_(uplo, "U") || lsame_(uplo, |
| 5511 |
"L"))) { |
| 5512 |
*info = -2; |
| 5513 |
} else if (*n < 0) { |
| 5514 |
*info = -3; |
| 5515 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 5516 |
*info = -7; |
| 5517 |
} |
| 5518 |
|
| 5519 |
if (*info != 0) { |
| 5520 |
i__1 = -(*info); |
| 5521 |
xerbla_("DSPEV ", &i__1); |
| 5522 |
return 0; |
| 5523 |
} |
| 5524 |
|
| 5525 |
/* Quick return if possible */ |
| 5526 |
|
| 5527 |
if (*n == 0) { |
| 5528 |
return 0; |
| 5529 |
} |
| 5530 |
|
| 5531 |
if (*n == 1) { |
| 5532 |
w[1] = ap[1]; |
| 5533 |
if (wantz) { |
| 5534 |
z__[z_dim1 + 1] = 1.; |
| 5535 |
} |
| 5536 |
return 0; |
| 5537 |
} |
| 5538 |
|
| 5539 |
/* Get machine constants. */ |
| 5540 |
|
| 5541 |
safmin = dlamch_("Safe minimum"); |
| 5542 |
eps = dlamch_("Precision"); |
| 5543 |
smlnum = safmin / eps; |
| 5544 |
bignum = 1. / smlnum; |
| 5545 |
rmin = sqrt(smlnum); |
| 5546 |
rmax = sqrt(bignum); |
| 5547 |
|
| 5548 |
/* Scale matrix to allowable range, if necessary. */ |
| 5549 |
|
| 5550 |
anrm = dlansp_("M", uplo, n, &ap[1], &work[1]); |
| 5551 |
iscale = 0; |
| 5552 |
if (anrm > 0. && anrm < rmin) { |
| 5553 |
iscale = 1; |
| 5554 |
sigma = rmin / anrm; |
| 5555 |
} else if (anrm > rmax) { |
| 5556 |
iscale = 1; |
| 5557 |
sigma = rmax / anrm; |
| 5558 |
} |
| 5559 |
if (iscale == 1) { |
| 5560 |
i__1 = *n * (*n + 1) / 2; |
| 5561 |
dscal_(&i__1, &sigma, &ap[1], &c__1); |
| 5562 |
} |
| 5563 |
|
| 5564 |
/* Call DSPTRD to reduce symmetric packed matrix to tridiagonal form. */ |
| 5565 |
|
| 5566 |
inde = 1; |
| 5567 |
indtau = inde + *n; |
| 5568 |
dsptrd_(uplo, n, &ap[1], &w[1], &work[inde], &work[indtau], &iinfo); |
| 5569 |
|
| 5570 |
/* For eigenvalues only, call DSTERF. For eigenvectors, first call */ |
| 5571 |
/* DOPGTR to generate the orthogonal matrix, then call DSTEQR. */ |
| 5572 |
|
| 5573 |
if (! wantz) { |
| 5574 |
dsterf_(n, &w[1], &work[inde], info); |
| 5575 |
} else { |
| 5576 |
indwrk = indtau + *n; |
| 5577 |
dopgtr_(uplo, n, &ap[1], &work[indtau], &z__[z_offset], ldz, &work[ |
| 5578 |
indwrk], &iinfo); |
| 5579 |
dsteqr_(jobz, n, &w[1], &work[inde], &z__[z_offset], ldz, &work[ |
| 5580 |
indtau], info); |
| 5581 |
} |
| 5582 |
|
| 5583 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 5584 |
|
| 5585 |
if (iscale == 1) { |
| 5586 |
if (*info == 0) { |
| 5587 |
imax = *n; |
| 5588 |
} else { |
| 5589 |
imax = *info - 1; |
| 5590 |
} |
| 5591 |
d__1 = 1. / sigma; |
| 5592 |
dscal_(&imax, &d__1, &w[1], &c__1); |
| 5593 |
} |
| 5594 |
|
| 5595 |
return 0; |
| 5596 |
|
| 5597 |
/* End of DSPEV */ |
| 5598 |
|
| 5599 |
} /* dspev_ */ |
| 5600 |
|
| 5601 |
/* Subroutine */ int dspevd_(const char *jobz, const char *uplo, integer *n, double * |
| 5602 |
ap, double *w, double *z__, integer *ldz, double *work, |
| 5603 |
integer *lwork, integer *iwork, integer *liwork, integer *info) |
| 5604 |
{ |
| 5605 |
/* Table of constant values */ |
| 5606 |
static integer c__1 = 1; |
| 5607 |
|
| 5608 |
/* System generated locals */ |
| 5609 |
integer z_dim1, z_offset, i__1; |
| 5610 |
double d__1; |
| 5611 |
|
| 5612 |
/* Local variables */ |
| 5613 |
double eps; |
| 5614 |
integer inde; |
| 5615 |
double anrm, rmin, rmax; |
| 5616 |
double sigma; |
| 5617 |
integer iinfo, lwmin; |
| 5618 |
bool wantz; |
| 5619 |
integer iscale; |
| 5620 |
double safmin; |
| 5621 |
double bignum; |
| 5622 |
integer indtau; |
| 5623 |
integer indwrk, liwmin; |
| 5624 |
integer llwork; |
| 5625 |
double smlnum; |
| 5626 |
bool lquery; |
| 5627 |
|
| 5628 |
|
| 5629 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 5630 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 5631 |
/* November 2006 */ |
| 5632 |
|
| 5633 |
/* .. Scalar Arguments .. */ |
| 5634 |
/* .. */ |
| 5635 |
/* .. Array Arguments .. */ |
| 5636 |
/* .. */ |
| 5637 |
|
| 5638 |
/* Purpose */ |
| 5639 |
/* ======= */ |
| 5640 |
|
| 5641 |
/* DSPEVD computes all the eigenvalues and, optionally, eigenvectors */ |
| 5642 |
/* of a real symmetric matrix A in packed storage. If eigenvectors are */ |
| 5643 |
/* desired, it uses a divide and conquer algorithm. */ |
| 5644 |
|
| 5645 |
/* The divide and conquer algorithm makes very mild assumptions about */ |
| 5646 |
/* floating point arithmetic. It will work on machines with a guard */ |
| 5647 |
/* digit in add/subtract, or on those binary machines without guard */ |
| 5648 |
/* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ |
| 5649 |
/* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ |
| 5650 |
/* without guard digits, but we know of none. */ |
| 5651 |
|
| 5652 |
/* Arguments */ |
| 5653 |
/* ========= */ |
| 5654 |
|
| 5655 |
/* JOBZ (input) CHARACTER*1 */ |
| 5656 |
/* = 'N': Compute eigenvalues only; */ |
| 5657 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 5658 |
|
| 5659 |
/* UPLO (input) CHARACTER*1 */ |
| 5660 |
/* = 'U': Upper triangle of A is stored; */ |
| 5661 |
/* = 'L': Lower triangle of A is stored. */ |
| 5662 |
|
| 5663 |
/* N (input) INTEGER */ |
| 5664 |
/* The order of the matrix A. N >= 0. */ |
| 5665 |
|
| 5666 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 5667 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 5668 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 5669 |
/* is stored in the array AP as follows: */ |
| 5670 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 5671 |
/* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ |
| 5672 |
|
| 5673 |
/* On exit, AP is overwritten by values generated during the */ |
| 5674 |
/* reduction to tridiagonal form. If UPLO = 'U', the diagonal */ |
| 5675 |
/* and first superdiagonal of the tridiagonal matrix T overwrite */ |
| 5676 |
/* the corresponding elements of A, and if UPLO = 'L', the */ |
| 5677 |
/* diagonal and first subdiagonal of T overwrite the */ |
| 5678 |
/* corresponding elements of A. */ |
| 5679 |
|
| 5680 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 5681 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 5682 |
|
| 5683 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 5684 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */ |
| 5685 |
/* eigenvectors of the matrix A, with the i-th column of Z */ |
| 5686 |
/* holding the eigenvector associated with W(i). */ |
| 5687 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 5688 |
|
| 5689 |
/* LDZ (input) INTEGER */ |
| 5690 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 5691 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 5692 |
|
| 5693 |
/* WORK (workspace/output) DOUBLE PRECISION array, */ |
| 5694 |
/* dimension (LWORK) */ |
| 5695 |
/* On exit, if INFO = 0, WORK(1) returns the required LWORK. */ |
| 5696 |
|
| 5697 |
/* LWORK (input) INTEGER */ |
| 5698 |
/* The dimension of the array WORK. */ |
| 5699 |
/* If N <= 1, LWORK must be at least 1. */ |
| 5700 |
/* If JOBZ = 'N' and N > 1, LWORK must be at least 2*N. */ |
| 5701 |
/* If JOBZ = 'V' and N > 1, LWORK must be at least */ |
| 5702 |
/* 1 + 6*N + N**2. */ |
| 5703 |
|
| 5704 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 5705 |
/* only calculates the required sizes of the WORK and IWORK */ |
| 5706 |
/* arrays, returns these values as the first entries of the WORK */ |
| 5707 |
/* and IWORK arrays, and no error message related to LWORK or */ |
| 5708 |
/* LIWORK is issued by XERBLA. */ |
| 5709 |
|
| 5710 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 5711 |
/* On exit, if INFO = 0, IWORK(1) returns the required LIWORK. */ |
| 5712 |
|
| 5713 |
/* LIWORK (input) INTEGER */ |
| 5714 |
/* The dimension of the array IWORK. */ |
| 5715 |
/* If JOBZ = 'N' or N <= 1, LIWORK must be at least 1. */ |
| 5716 |
/* If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N. */ |
| 5717 |
|
| 5718 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 5719 |
/* routine only calculates the required sizes of the WORK and */ |
| 5720 |
/* IWORK arrays, returns these values as the first entries of */ |
| 5721 |
/* the WORK and IWORK arrays, and no error message related to */ |
| 5722 |
/* LWORK or LIWORK is issued by XERBLA. */ |
| 5723 |
|
| 5724 |
/* INFO (output) INTEGER */ |
| 5725 |
/* = 0: successful exit */ |
| 5726 |
/* < 0: if INFO = -i, the i-th argument had an illegal value. */ |
| 5727 |
/* > 0: if INFO = i, the algorithm failed to converge; i */ |
| 5728 |
/* off-diagonal elements of an intermediate tridiagonal */ |
| 5729 |
/* form did not converge to zero. */ |
| 5730 |
|
| 5731 |
/* ===================================================================== */ |
| 5732 |
|
| 5733 |
/* .. Parameters .. */ |
| 5734 |
/* .. */ |
| 5735 |
/* .. Local Scalars .. */ |
| 5736 |
/* .. */ |
| 5737 |
/* .. External Functions .. */ |
| 5738 |
/* .. */ |
| 5739 |
/* .. External Subroutines .. */ |
| 5740 |
/* .. */ |
| 5741 |
/* .. Intrinsic Functions .. */ |
| 5742 |
/* .. */ |
| 5743 |
/* .. Executable Statements .. */ |
| 5744 |
|
| 5745 |
/* Test the input parameters. */ |
| 5746 |
|
| 5747 |
/* Parameter adjustments */ |
| 5748 |
--ap; |
| 5749 |
--w; |
| 5750 |
z_dim1 = *ldz; |
| 5751 |
z_offset = 1 + z_dim1; |
| 5752 |
z__ -= z_offset; |
| 5753 |
--work; |
| 5754 |
--iwork; |
| 5755 |
|
| 5756 |
/* Function Body */ |
| 5757 |
wantz = lsame_(jobz, "V"); |
| 5758 |
lquery = *lwork == -1 || *liwork == -1; |
| 5759 |
|
| 5760 |
*info = 0; |
| 5761 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 5762 |
*info = -1; |
| 5763 |
} else if (! (lsame_(uplo, "U") || lsame_(uplo, |
| 5764 |
"L"))) { |
| 5765 |
*info = -2; |
| 5766 |
} else if (*n < 0) { |
| 5767 |
*info = -3; |
| 5768 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 5769 |
*info = -7; |
| 5770 |
} |
| 5771 |
|
| 5772 |
if (*info == 0) { |
| 5773 |
if (*n <= 1) { |
| 5774 |
liwmin = 1; |
| 5775 |
lwmin = 1; |
| 5776 |
} else { |
| 5777 |
if (wantz) { |
| 5778 |
liwmin = *n * 5 + 3; |
| 5779 |
/* Computing 2nd power */ |
| 5780 |
i__1 = *n; |
| 5781 |
lwmin = *n * 6 + 1 + i__1 * i__1; |
| 5782 |
} else { |
| 5783 |
liwmin = 1; |
| 5784 |
lwmin = *n << 1; |
| 5785 |
} |
| 5786 |
} |
| 5787 |
iwork[1] = liwmin; |
| 5788 |
work[1] = (double) lwmin; |
| 5789 |
|
| 5790 |
if (*lwork < lwmin && ! lquery) { |
| 5791 |
*info = -9; |
| 5792 |
} else if (*liwork < liwmin && ! lquery) { |
| 5793 |
*info = -11; |
| 5794 |
} |
| 5795 |
} |
| 5796 |
|
| 5797 |
if (*info != 0) { |
| 5798 |
i__1 = -(*info); |
| 5799 |
xerbla_("DSPEVD", &i__1); |
| 5800 |
return 0; |
| 5801 |
} else if (lquery) { |
| 5802 |
return 0; |
| 5803 |
} |
| 5804 |
|
| 5805 |
/* Quick return if possible */ |
| 5806 |
|
| 5807 |
if (*n == 0) { |
| 5808 |
return 0; |
| 5809 |
} |
| 5810 |
|
| 5811 |
if (*n == 1) { |
| 5812 |
w[1] = ap[1]; |
| 5813 |
if (wantz) { |
| 5814 |
z__[z_dim1 + 1] = 1.; |
| 5815 |
} |
| 5816 |
return 0; |
| 5817 |
} |
| 5818 |
|
| 5819 |
/* Get machine constants. */ |
| 5820 |
|
| 5821 |
safmin = dlamch_("Safe minimum"); |
| 5822 |
eps = dlamch_("Precision"); |
| 5823 |
smlnum = safmin / eps; |
| 5824 |
bignum = 1. / smlnum; |
| 5825 |
rmin = sqrt(smlnum); |
| 5826 |
rmax = sqrt(bignum); |
| 5827 |
|
| 5828 |
/* Scale matrix to allowable range, if necessary. */ |
| 5829 |
|
| 5830 |
anrm = dlansp_("M", uplo, n, &ap[1], &work[1]); |
| 5831 |
iscale = 0; |
| 5832 |
if (anrm > 0. && anrm < rmin) { |
| 5833 |
iscale = 1; |
| 5834 |
sigma = rmin / anrm; |
| 5835 |
} else if (anrm > rmax) { |
| 5836 |
iscale = 1; |
| 5837 |
sigma = rmax / anrm; |
| 5838 |
} |
| 5839 |
if (iscale == 1) { |
| 5840 |
i__1 = *n * (*n + 1) / 2; |
| 5841 |
dscal_(&i__1, &sigma, &ap[1], &c__1); |
| 5842 |
} |
| 5843 |
|
| 5844 |
/* Call DSPTRD to reduce symmetric packed matrix to tridiagonal form. */ |
| 5845 |
|
| 5846 |
inde = 1; |
| 5847 |
indtau = inde + *n; |
| 5848 |
dsptrd_(uplo, n, &ap[1], &w[1], &work[inde], &work[indtau], &iinfo); |
| 5849 |
|
| 5850 |
/* For eigenvalues only, call DSTERF. For eigenvectors, first call */ |
| 5851 |
/* DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the */ |
| 5852 |
/* tridiagonal matrix, then call DOPMTR to multiply it by the */ |
| 5853 |
/* Householder transformations represented in AP. */ |
| 5854 |
|
| 5855 |
if (! wantz) { |
| 5856 |
dsterf_(n, &w[1], &work[inde], info); |
| 5857 |
} else { |
| 5858 |
indwrk = indtau + *n; |
| 5859 |
llwork = *lwork - indwrk + 1; |
| 5860 |
dstedc_("I", n, &w[1], &work[inde], &z__[z_offset], ldz, &work[indwrk] |
| 5861 |
, &llwork, &iwork[1], liwork, info); |
| 5862 |
dopmtr_("L", uplo, "N", n, n, &ap[1], &work[indtau], &z__[z_offset], |
| 5863 |
ldz, &work[indwrk], &iinfo); |
| 5864 |
} |
| 5865 |
|
| 5866 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 5867 |
|
| 5868 |
if (iscale == 1) { |
| 5869 |
d__1 = 1. / sigma; |
| 5870 |
dscal_(n, &d__1, &w[1], &c__1); |
| 5871 |
} |
| 5872 |
|
| 5873 |
work[1] = (double) lwmin; |
| 5874 |
iwork[1] = liwmin; |
| 5875 |
return 0; |
| 5876 |
|
| 5877 |
/* End of DSPEVD */ |
| 5878 |
|
| 5879 |
} /* dspevd_ */ |
| 5880 |
|
| 5881 |
/* Subroutine */ int dspevx_(const char *jobz, const char *range, const char *uplo, integer *n, |
| 5882 |
double *ap, double *vl, double *vu, integer *il, integer * |
| 5883 |
iu, double *abstol, integer *m, double *w, double *z__, |
| 5884 |
integer *ldz, double *work, integer *iwork, integer *ifail, |
| 5885 |
integer *info) |
| 5886 |
{ |
| 5887 |
/* Table of constant values */ |
| 5888 |
static integer c__1 = 1; |
| 5889 |
|
| 5890 |
/* System generated locals */ |
| 5891 |
integer z_dim1, z_offset, i__1, i__2; |
| 5892 |
double d__1, d__2; |
| 5893 |
|
| 5894 |
/* Local variables */ |
| 5895 |
integer i__, j, jj; |
| 5896 |
double eps, vll, vuu, tmp1; |
| 5897 |
integer indd, inde; |
| 5898 |
double anrm; |
| 5899 |
integer imax; |
| 5900 |
double rmin, rmax; |
| 5901 |
bool test; |
| 5902 |
integer itmp1, indee; |
| 5903 |
double sigma; |
| 5904 |
integer iinfo; |
| 5905 |
char order[1]; |
| 5906 |
bool wantz; |
| 5907 |
bool alleig, indeig; |
| 5908 |
integer iscale, indibl; |
| 5909 |
bool valeig; |
| 5910 |
double safmin; |
| 5911 |
double abstll, bignum; |
| 5912 |
integer indtau, indisp; |
| 5913 |
integer indiwo; |
| 5914 |
integer indwrk; |
| 5915 |
integer nsplit; |
| 5916 |
double smlnum; |
| 5917 |
|
| 5918 |
|
| 5919 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 5920 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 5921 |
/* November 2006 */ |
| 5922 |
|
| 5923 |
/* .. Scalar Arguments .. */ |
| 5924 |
/* .. */ |
| 5925 |
/* .. Array Arguments .. */ |
| 5926 |
/* .. */ |
| 5927 |
|
| 5928 |
/* Purpose */ |
| 5929 |
/* ======= */ |
| 5930 |
|
| 5931 |
/* DSPEVX computes selected eigenvalues and, optionally, eigenvectors */ |
| 5932 |
/* of a real symmetric matrix A in packed storage. Eigenvalues/vectors */ |
| 5933 |
/* can be selected by specifying either a range of values or a range of */ |
| 5934 |
/* indices for the desired eigenvalues. */ |
| 5935 |
|
| 5936 |
/* Arguments */ |
| 5937 |
/* ========= */ |
| 5938 |
|
| 5939 |
/* JOBZ (input) CHARACTER*1 */ |
| 5940 |
/* = 'N': Compute eigenvalues only; */ |
| 5941 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 5942 |
|
| 5943 |
/* RANGE (input) CHARACTER*1 */ |
| 5944 |
/* = 'A': all eigenvalues will be found; */ |
| 5945 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 5946 |
/* will be found; */ |
| 5947 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 5948 |
|
| 5949 |
/* UPLO (input) CHARACTER*1 */ |
| 5950 |
/* = 'U': Upper triangle of A is stored; */ |
| 5951 |
/* = 'L': Lower triangle of A is stored. */ |
| 5952 |
|
| 5953 |
/* N (input) INTEGER */ |
| 5954 |
/* The order of the matrix A. N >= 0. */ |
| 5955 |
|
| 5956 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 5957 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 5958 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 5959 |
/* is stored in the array AP as follows: */ |
| 5960 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 5961 |
/* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ |
| 5962 |
|
| 5963 |
/* On exit, AP is overwritten by values generated during the */ |
| 5964 |
/* reduction to tridiagonal form. If UPLO = 'U', the diagonal */ |
| 5965 |
/* and first superdiagonal of the tridiagonal matrix T overwrite */ |
| 5966 |
/* the corresponding elements of A, and if UPLO = 'L', the */ |
| 5967 |
/* diagonal and first subdiagonal of T overwrite the */ |
| 5968 |
/* corresponding elements of A. */ |
| 5969 |
|
| 5970 |
/* VL (input) DOUBLE PRECISION */ |
| 5971 |
/* VU (input) DOUBLE PRECISION */ |
| 5972 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 5973 |
/* be searched for eigenvalues. VL < VU. */ |
| 5974 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 5975 |
|
| 5976 |
/* IL (input) INTEGER */ |
| 5977 |
/* IU (input) INTEGER */ |
| 5978 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 5979 |
/* smallest and largest eigenvalues to be returned. */ |
| 5980 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 5981 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 5982 |
|
| 5983 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 5984 |
/* The absolute error tolerance for the eigenvalues. */ |
| 5985 |
/* An approximate eigenvalue is accepted as converged */ |
| 5986 |
/* when it is determined to lie in an interval [a,b] */ |
| 5987 |
/* of width less than or equal to */ |
| 5988 |
|
| 5989 |
/* ABSTOL + EPS * max( |a|,|b| ) , */ |
| 5990 |
|
| 5991 |
/* where EPS is the machine precision. If ABSTOL is less than */ |
| 5992 |
/* or equal to zero, then EPS*|T| will be used in its place, */ |
| 5993 |
/* where |T| is the 1-norm of the tridiagonal matrix obtained */ |
| 5994 |
/* by reducing AP to tridiagonal form. */ |
| 5995 |
|
| 5996 |
/* Eigenvalues will be computed most accurately when ABSTOL is */ |
| 5997 |
/* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */ |
| 5998 |
/* If this routine returns with INFO>0, indicating that some */ |
| 5999 |
/* eigenvectors did not converge, try setting ABSTOL to */ |
| 6000 |
/* 2*DLAMCH('S'). */ |
| 6001 |
|
| 6002 |
/* See "Computing Small Singular Values of Bidiagonal Matrices */ |
| 6003 |
/* with Guaranteed High Relative Accuracy," by Demmel and */ |
| 6004 |
/* Kahan, LAPACK Working Note #3. */ |
| 6005 |
|
| 6006 |
/* M (output) INTEGER */ |
| 6007 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 6008 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 6009 |
|
| 6010 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 6011 |
/* If INFO = 0, the selected eigenvalues in ascending order. */ |
| 6012 |
|
| 6013 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */ |
| 6014 |
/* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ |
| 6015 |
/* contain the orthonormal eigenvectors of the matrix A */ |
| 6016 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 6017 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 6018 |
/* If an eigenvector fails to converge, then that column of Z */ |
| 6019 |
/* contains the latest approximation to the eigenvector, and the */ |
| 6020 |
/* index of the eigenvector is returned in IFAIL. */ |
| 6021 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 6022 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 6023 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 6024 |
/* is not known in advance and an upper bound must be used. */ |
| 6025 |
|
| 6026 |
/* LDZ (input) INTEGER */ |
| 6027 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 6028 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 6029 |
|
| 6030 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (8*N) */ |
| 6031 |
|
| 6032 |
/* IWORK (workspace) INTEGER array, dimension (5*N) */ |
| 6033 |
|
| 6034 |
/* IFAIL (output) INTEGER array, dimension (N) */ |
| 6035 |
/* If JOBZ = 'V', then if INFO = 0, the first M elements of */ |
| 6036 |
/* IFAIL are zero. If INFO > 0, then IFAIL contains the */ |
| 6037 |
/* indices of the eigenvectors that failed to converge. */ |
| 6038 |
/* If JOBZ = 'N', then IFAIL is not referenced. */ |
| 6039 |
|
| 6040 |
/* INFO (output) INTEGER */ |
| 6041 |
/* = 0: successful exit */ |
| 6042 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 6043 |
/* > 0: if INFO = i, then i eigenvectors failed to converge. */ |
| 6044 |
/* Their indices are stored in array IFAIL. */ |
| 6045 |
|
| 6046 |
/* ===================================================================== */ |
| 6047 |
|
| 6048 |
/* .. Parameters .. */ |
| 6049 |
/* .. */ |
| 6050 |
/* .. Local Scalars .. */ |
| 6051 |
/* .. */ |
| 6052 |
/* .. External Functions .. */ |
| 6053 |
/* .. */ |
| 6054 |
/* .. External Subroutines .. */ |
| 6055 |
/* .. */ |
| 6056 |
/* .. Intrinsic Functions .. */ |
| 6057 |
/* .. */ |
| 6058 |
/* .. Executable Statements .. */ |
| 6059 |
|
| 6060 |
/* Test the input parameters. */ |
| 6061 |
|
| 6062 |
/* Parameter adjustments */ |
| 6063 |
--ap; |
| 6064 |
--w; |
| 6065 |
z_dim1 = *ldz; |
| 6066 |
z_offset = 1 + z_dim1; |
| 6067 |
z__ -= z_offset; |
| 6068 |
--work; |
| 6069 |
--iwork; |
| 6070 |
--ifail; |
| 6071 |
|
| 6072 |
/* Function Body */ |
| 6073 |
wantz = lsame_(jobz, "V"); |
| 6074 |
alleig = lsame_(range, "A"); |
| 6075 |
valeig = lsame_(range, "V"); |
| 6076 |
indeig = lsame_(range, "I"); |
| 6077 |
|
| 6078 |
*info = 0; |
| 6079 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 6080 |
*info = -1; |
| 6081 |
} else if (! (alleig || valeig || indeig)) { |
| 6082 |
*info = -2; |
| 6083 |
} else if (! (lsame_(uplo, "L") || lsame_(uplo, |
| 6084 |
"U"))) { |
| 6085 |
*info = -3; |
| 6086 |
} else if (*n < 0) { |
| 6087 |
*info = -4; |
| 6088 |
} else { |
| 6089 |
if (valeig) { |
| 6090 |
if (*n > 0 && *vu <= *vl) { |
| 6091 |
*info = -7; |
| 6092 |
} |
| 6093 |
} else if (indeig) { |
| 6094 |
if (*il < 1 || *il > std::max(1_integer,*n)) { |
| 6095 |
*info = -8; |
| 6096 |
} else if (*iu < std::min(*n,*il) || *iu > *n) { |
| 6097 |
*info = -9; |
| 6098 |
} |
| 6099 |
} |
| 6100 |
} |
| 6101 |
if (*info == 0) { |
| 6102 |
if (*ldz < 1 || wantz && *ldz < *n) { |
| 6103 |
*info = -14; |
| 6104 |
} |
| 6105 |
} |
| 6106 |
|
| 6107 |
if (*info != 0) { |
| 6108 |
i__1 = -(*info); |
| 6109 |
xerbla_("DSPEVX", &i__1); |
| 6110 |
return 0; |
| 6111 |
} |
| 6112 |
|
| 6113 |
/* Quick return if possible */ |
| 6114 |
|
| 6115 |
*m = 0; |
| 6116 |
if (*n == 0) { |
| 6117 |
return 0; |
| 6118 |
} |
| 6119 |
|
| 6120 |
if (*n == 1) { |
| 6121 |
if (alleig || indeig) { |
| 6122 |
*m = 1; |
| 6123 |
w[1] = ap[1]; |
| 6124 |
} else { |
| 6125 |
if (*vl < ap[1] && *vu >= ap[1]) { |
| 6126 |
*m = 1; |
| 6127 |
w[1] = ap[1]; |
| 6128 |
} |
| 6129 |
} |
| 6130 |
if (wantz) { |
| 6131 |
z__[z_dim1 + 1] = 1.; |
| 6132 |
} |
| 6133 |
return 0; |
| 6134 |
} |
| 6135 |
|
| 6136 |
/* Get machine constants. */ |
| 6137 |
|
| 6138 |
safmin = dlamch_("Safe minimum"); |
| 6139 |
eps = dlamch_("Precision"); |
| 6140 |
smlnum = safmin / eps; |
| 6141 |
bignum = 1. / smlnum; |
| 6142 |
rmin = sqrt(smlnum); |
| 6143 |
/* Computing MIN */ |
| 6144 |
d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin)); |
| 6145 |
rmax = std::min(d__1,d__2); |
| 6146 |
|
| 6147 |
/* Scale matrix to allowable range, if necessary. */ |
| 6148 |
|
| 6149 |
iscale = 0; |
| 6150 |
abstll = *abstol; |
| 6151 |
if (valeig) { |
| 6152 |
vll = *vl; |
| 6153 |
vuu = *vu; |
| 6154 |
} else { |
| 6155 |
vll = 0.; |
| 6156 |
vuu = 0.; |
| 6157 |
} |
| 6158 |
anrm = dlansp_("M", uplo, n, &ap[1], &work[1]); |
| 6159 |
if (anrm > 0. && anrm < rmin) { |
| 6160 |
iscale = 1; |
| 6161 |
sigma = rmin / anrm; |
| 6162 |
} else if (anrm > rmax) { |
| 6163 |
iscale = 1; |
| 6164 |
sigma = rmax / anrm; |
| 6165 |
} |
| 6166 |
if (iscale == 1) { |
| 6167 |
i__1 = *n * (*n + 1) / 2; |
| 6168 |
dscal_(&i__1, &sigma, &ap[1], &c__1); |
| 6169 |
if (*abstol > 0.) { |
| 6170 |
abstll = *abstol * sigma; |
| 6171 |
} |
| 6172 |
if (valeig) { |
| 6173 |
vll = *vl * sigma; |
| 6174 |
vuu = *vu * sigma; |
| 6175 |
} |
| 6176 |
} |
| 6177 |
|
| 6178 |
/* Call DSPTRD to reduce symmetric packed matrix to tridiagonal form. */ |
| 6179 |
|
| 6180 |
indtau = 1; |
| 6181 |
inde = indtau + *n; |
| 6182 |
indd = inde + *n; |
| 6183 |
indwrk = indd + *n; |
| 6184 |
dsptrd_(uplo, n, &ap[1], &work[indd], &work[inde], &work[indtau], &iinfo); |
| 6185 |
|
| 6186 |
/* If all eigenvalues are desired and ABSTOL is less than or equal */ |
| 6187 |
/* to zero, then call DSTERF or DOPGTR and SSTEQR. If this fails */ |
| 6188 |
/* for some eigenvalue, then try DSTEBZ. */ |
| 6189 |
|
| 6190 |
test = false; |
| 6191 |
if (indeig) { |
| 6192 |
if (*il == 1 && *iu == *n) { |
| 6193 |
test = true; |
| 6194 |
} |
| 6195 |
} |
| 6196 |
if ((alleig || test) && *abstol <= 0.) { |
| 6197 |
dcopy_(n, &work[indd], &c__1, &w[1], &c__1); |
| 6198 |
indee = indwrk + (*n << 1); |
| 6199 |
if (! wantz) { |
| 6200 |
i__1 = *n - 1; |
| 6201 |
dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); |
| 6202 |
dsterf_(n, &w[1], &work[indee], info); |
| 6203 |
} else { |
| 6204 |
dopgtr_(uplo, n, &ap[1], &work[indtau], &z__[z_offset], ldz, & |
| 6205 |
work[indwrk], &iinfo); |
| 6206 |
i__1 = *n - 1; |
| 6207 |
dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); |
| 6208 |
dsteqr_(jobz, n, &w[1], &work[indee], &z__[z_offset], ldz, &work[ |
| 6209 |
indwrk], info); |
| 6210 |
if (*info == 0) { |
| 6211 |
i__1 = *n; |
| 6212 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 6213 |
ifail[i__] = 0; |
| 6214 |
/* L10: */ |
| 6215 |
} |
| 6216 |
} |
| 6217 |
} |
| 6218 |
if (*info == 0) { |
| 6219 |
*m = *n; |
| 6220 |
goto L20; |
| 6221 |
} |
| 6222 |
*info = 0; |
| 6223 |
} |
| 6224 |
|
| 6225 |
/* Otherwise, call DSTEBZ and, if eigenvectors are desired, SSTEIN. */ |
| 6226 |
|
| 6227 |
if (wantz) { |
| 6228 |
*(unsigned char *)order = 'B'; |
| 6229 |
} else { |
| 6230 |
*(unsigned char *)order = 'E'; |
| 6231 |
} |
| 6232 |
indibl = 1; |
| 6233 |
indisp = indibl + *n; |
| 6234 |
indiwo = indisp + *n; |
| 6235 |
dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[ |
| 6236 |
inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[ |
| 6237 |
indwrk], &iwork[indiwo], info); |
| 6238 |
|
| 6239 |
if (wantz) { |
| 6240 |
dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[ |
| 6241 |
indisp], &z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], & |
| 6242 |
ifail[1], info); |
| 6243 |
|
| 6244 |
/* Apply orthogonal matrix used in reduction to tridiagonal */ |
| 6245 |
/* form to eigenvectors returned by DSTEIN. */ |
| 6246 |
|
| 6247 |
dopmtr_("L", uplo, "N", n, m, &ap[1], &work[indtau], &z__[z_offset], |
| 6248 |
ldz, &work[indwrk], info); |
| 6249 |
} |
| 6250 |
|
| 6251 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 6252 |
|
| 6253 |
L20: |
| 6254 |
if (iscale == 1) { |
| 6255 |
if (*info == 0) { |
| 6256 |
imax = *m; |
| 6257 |
} else { |
| 6258 |
imax = *info - 1; |
| 6259 |
} |
| 6260 |
d__1 = 1. / sigma; |
| 6261 |
dscal_(&imax, &d__1, &w[1], &c__1); |
| 6262 |
} |
| 6263 |
|
| 6264 |
/* If eigenvalues are not in order, then sort them, along with */ |
| 6265 |
/* eigenvectors. */ |
| 6266 |
|
| 6267 |
if (wantz) { |
| 6268 |
i__1 = *m - 1; |
| 6269 |
for (j = 1; j <= i__1; ++j) { |
| 6270 |
i__ = 0; |
| 6271 |
tmp1 = w[j]; |
| 6272 |
i__2 = *m; |
| 6273 |
for (jj = j + 1; jj <= i__2; ++jj) { |
| 6274 |
if (w[jj] < tmp1) { |
| 6275 |
i__ = jj; |
| 6276 |
tmp1 = w[jj]; |
| 6277 |
} |
| 6278 |
/* L30: */ |
| 6279 |
} |
| 6280 |
|
| 6281 |
if (i__ != 0) { |
| 6282 |
itmp1 = iwork[indibl + i__ - 1]; |
| 6283 |
w[i__] = w[j]; |
| 6284 |
iwork[indibl + i__ - 1] = iwork[indibl + j - 1]; |
| 6285 |
w[j] = tmp1; |
| 6286 |
iwork[indibl + j - 1] = itmp1; |
| 6287 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], |
| 6288 |
&c__1); |
| 6289 |
if (*info != 0) { |
| 6290 |
itmp1 = ifail[i__]; |
| 6291 |
ifail[i__] = ifail[j]; |
| 6292 |
ifail[j] = itmp1; |
| 6293 |
} |
| 6294 |
} |
| 6295 |
/* L40: */ |
| 6296 |
} |
| 6297 |
} |
| 6298 |
|
| 6299 |
return 0; |
| 6300 |
|
| 6301 |
/* End of DSPEVX */ |
| 6302 |
|
| 6303 |
} /* dspevx_ */ |
| 6304 |
|
| 6305 |
/* Subroutine */ int dspgst_(integer *itype, const char *uplo, integer *n, |
| 6306 |
double *ap, double *bp, integer *info) |
| 6307 |
{ |
| 6308 |
/* Table of constant values */ |
| 6309 |
static integer c__1 = 1; |
| 6310 |
static double c_b9 = -1.; |
| 6311 |
static double c_b11 = 1.; |
| 6312 |
|
| 6313 |
/* System generated locals */ |
| 6314 |
integer i__1, i__2; |
| 6315 |
double d__1; |
| 6316 |
|
| 6317 |
/* Local variables */ |
| 6318 |
integer j, k, j1, k1, jj, kk; |
| 6319 |
double ct, ajj; |
| 6320 |
integer j1j1; |
| 6321 |
double akk; |
| 6322 |
integer k1k1; |
| 6323 |
double bjj, bkk; |
| 6324 |
bool upper; |
| 6325 |
|
| 6326 |
|
| 6327 |
/* -- LAPACK routine (version 3.1) -- */ |
| 6328 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 6329 |
/* November 2006 */ |
| 6330 |
|
| 6331 |
/* .. Scalar Arguments .. */ |
| 6332 |
/* .. */ |
| 6333 |
/* .. Array Arguments .. */ |
| 6334 |
/* .. */ |
| 6335 |
|
| 6336 |
/* Purpose */ |
| 6337 |
/* ======= */ |
| 6338 |
|
| 6339 |
/* DSPGST reduces a real symmetric-definite generalized eigenproblem */ |
| 6340 |
/* to standard form, using packed storage. */ |
| 6341 |
|
| 6342 |
/* If ITYPE = 1, the problem is A*x = lambda*B*x, */ |
| 6343 |
/* and A is overwritten by inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T) */ |
| 6344 |
|
| 6345 |
/* If ITYPE = 2 or 3, the problem is A*B*x = lambda*x or */ |
| 6346 |
/* B*A*x = lambda*x, and A is overwritten by U*A*U**T or L**T*A*L. */ |
| 6347 |
|
| 6348 |
/* B must have been previously factorized as U**T*U or L*L**T by DPPTRF. */ |
| 6349 |
|
| 6350 |
/* Arguments */ |
| 6351 |
/* ========= */ |
| 6352 |
|
| 6353 |
/* ITYPE (input) INTEGER */ |
| 6354 |
/* = 1: compute inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T); */ |
| 6355 |
/* = 2 or 3: compute U*A*U**T or L**T*A*L. */ |
| 6356 |
|
| 6357 |
/* UPLO (input) CHARACTER*1 */ |
| 6358 |
/* = 'U': Upper triangle of A is stored and B is factored as */ |
| 6359 |
/* U**T*U; */ |
| 6360 |
/* = 'L': Lower triangle of A is stored and B is factored as */ |
| 6361 |
/* L*L**T. */ |
| 6362 |
|
| 6363 |
/* N (input) INTEGER */ |
| 6364 |
/* The order of the matrices A and B. N >= 0. */ |
| 6365 |
|
| 6366 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 6367 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 6368 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 6369 |
/* is stored in the array AP as follows: */ |
| 6370 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 6371 |
/* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */ |
| 6372 |
|
| 6373 |
/* On exit, if INFO = 0, the transformed matrix, stored in the */ |
| 6374 |
/* same format as A. */ |
| 6375 |
|
| 6376 |
/* BP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 6377 |
/* The triangular factor from the Cholesky factorization of B, */ |
| 6378 |
/* stored in the same format as A, as returned by DPPTRF. */ |
| 6379 |
|
| 6380 |
/* INFO (output) INTEGER */ |
| 6381 |
/* = 0: successful exit */ |
| 6382 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 6383 |
|
| 6384 |
/* ===================================================================== */ |
| 6385 |
|
| 6386 |
/* .. Parameters .. */ |
| 6387 |
/* .. */ |
| 6388 |
/* .. Local Scalars .. */ |
| 6389 |
/* .. */ |
| 6390 |
/* .. External Subroutines .. */ |
| 6391 |
/* .. */ |
| 6392 |
/* .. External Functions .. */ |
| 6393 |
/* .. */ |
| 6394 |
/* .. Executable Statements .. */ |
| 6395 |
|
| 6396 |
/* Test the input parameters. */ |
| 6397 |
|
| 6398 |
/* Parameter adjustments */ |
| 6399 |
--bp; |
| 6400 |
--ap; |
| 6401 |
|
| 6402 |
/* Function Body */ |
| 6403 |
*info = 0; |
| 6404 |
upper = lsame_(uplo, "U"); |
| 6405 |
if (*itype < 1 || *itype > 3) { |
| 6406 |
*info = -1; |
| 6407 |
} else if (! upper && ! lsame_(uplo, "L")) { |
| 6408 |
*info = -2; |
| 6409 |
} else if (*n < 0) { |
| 6410 |
*info = -3; |
| 6411 |
} |
| 6412 |
if (*info != 0) { |
| 6413 |
i__1 = -(*info); |
| 6414 |
xerbla_("DSPGST", &i__1); |
| 6415 |
return 0; |
| 6416 |
} |
| 6417 |
|
| 6418 |
if (*itype == 1) { |
| 6419 |
if (upper) { |
| 6420 |
|
| 6421 |
/* Compute inv(U')*A*inv(U) */ |
| 6422 |
|
| 6423 |
/* J1 and JJ are the indices of A(1,j) and A(j,j) */ |
| 6424 |
|
| 6425 |
jj = 0; |
| 6426 |
i__1 = *n; |
| 6427 |
for (j = 1; j <= i__1; ++j) { |
| 6428 |
j1 = jj + 1; |
| 6429 |
jj += j; |
| 6430 |
|
| 6431 |
/* Compute the j-th column of the upper triangle of A */ |
| 6432 |
|
| 6433 |
bjj = bp[jj]; |
| 6434 |
dtpsv_(uplo, "Transpose", "Nonunit", &j, &bp[1], &ap[j1], & |
| 6435 |
c__1); |
| 6436 |
i__2 = j - 1; |
| 6437 |
dspmv_(uplo, &i__2, &c_b9, &ap[1], &bp[j1], &c__1, &c_b11, & |
| 6438 |
ap[j1], &c__1); |
| 6439 |
i__2 = j - 1; |
| 6440 |
d__1 = 1. / bjj; |
| 6441 |
dscal_(&i__2, &d__1, &ap[j1], &c__1); |
| 6442 |
i__2 = j - 1; |
| 6443 |
ap[jj] = (ap[jj] - ddot_(&i__2, &ap[j1], &c__1, &bp[j1], & |
| 6444 |
c__1)) / bjj; |
| 6445 |
/* L10: */ |
| 6446 |
} |
| 6447 |
} else { |
| 6448 |
|
| 6449 |
/* Compute inv(L)*A*inv(L') */ |
| 6450 |
|
| 6451 |
/* KK and K1K1 are the indices of A(k,k) and A(k+1,k+1) */ |
| 6452 |
|
| 6453 |
kk = 1; |
| 6454 |
i__1 = *n; |
| 6455 |
for (k = 1; k <= i__1; ++k) { |
| 6456 |
k1k1 = kk + *n - k + 1; |
| 6457 |
|
| 6458 |
/* Update the lower triangle of A(k:n,k:n) */ |
| 6459 |
|
| 6460 |
akk = ap[kk]; |
| 6461 |
bkk = bp[kk]; |
| 6462 |
/* Computing 2nd power */ |
| 6463 |
d__1 = bkk; |
| 6464 |
akk /= d__1 * d__1; |
| 6465 |
ap[kk] = akk; |
| 6466 |
if (k < *n) { |
| 6467 |
i__2 = *n - k; |
| 6468 |
d__1 = 1. / bkk; |
| 6469 |
dscal_(&i__2, &d__1, &ap[kk + 1], &c__1); |
| 6470 |
ct = akk * -.5; |
| 6471 |
i__2 = *n - k; |
| 6472 |
daxpy_(&i__2, &ct, &bp[kk + 1], &c__1, &ap[kk + 1], &c__1) |
| 6473 |
; |
| 6474 |
i__2 = *n - k; |
| 6475 |
dspr2_(uplo, &i__2, &c_b9, &ap[kk + 1], &c__1, &bp[kk + 1] |
| 6476 |
, &c__1, &ap[k1k1]); |
| 6477 |
i__2 = *n - k; |
| 6478 |
daxpy_(&i__2, &ct, &bp[kk + 1], &c__1, &ap[kk + 1], &c__1) |
| 6479 |
; |
| 6480 |
i__2 = *n - k; |
| 6481 |
dtpsv_(uplo, "No transpose", "Non-unit", &i__2, &bp[k1k1], |
| 6482 |
&ap[kk + 1], &c__1); |
| 6483 |
} |
| 6484 |
kk = k1k1; |
| 6485 |
/* L20: */ |
| 6486 |
} |
| 6487 |
} |
| 6488 |
} else { |
| 6489 |
if (upper) { |
| 6490 |
|
| 6491 |
/* Compute U*A*U' */ |
| 6492 |
|
| 6493 |
/* K1 and KK are the indices of A(1,k) and A(k,k) */ |
| 6494 |
|
| 6495 |
kk = 0; |
| 6496 |
i__1 = *n; |
| 6497 |
for (k = 1; k <= i__1; ++k) { |
| 6498 |
k1 = kk + 1; |
| 6499 |
kk += k; |
| 6500 |
|
| 6501 |
/* Update the upper triangle of A(1:k,1:k) */ |
| 6502 |
|
| 6503 |
akk = ap[kk]; |
| 6504 |
bkk = bp[kk]; |
| 6505 |
i__2 = k - 1; |
| 6506 |
dtpmv_(uplo, "No transpose", "Non-unit", &i__2, &bp[1], &ap[ |
| 6507 |
k1], &c__1); |
| 6508 |
ct = akk * .5; |
| 6509 |
i__2 = k - 1; |
| 6510 |
daxpy_(&i__2, &ct, &bp[k1], &c__1, &ap[k1], &c__1); |
| 6511 |
i__2 = k - 1; |
| 6512 |
dspr2_(uplo, &i__2, &c_b11, &ap[k1], &c__1, &bp[k1], &c__1, & |
| 6513 |
ap[1]); |
| 6514 |
i__2 = k - 1; |
| 6515 |
daxpy_(&i__2, &ct, &bp[k1], &c__1, &ap[k1], &c__1); |
| 6516 |
i__2 = k - 1; |
| 6517 |
dscal_(&i__2, &bkk, &ap[k1], &c__1); |
| 6518 |
/* Computing 2nd power */ |
| 6519 |
d__1 = bkk; |
| 6520 |
ap[kk] = akk * (d__1 * d__1); |
| 6521 |
/* L30: */ |
| 6522 |
} |
| 6523 |
} else { |
| 6524 |
|
| 6525 |
/* Compute L'*A*L */ |
| 6526 |
|
| 6527 |
/* JJ and J1J1 are the indices of A(j,j) and A(j+1,j+1) */ |
| 6528 |
|
| 6529 |
jj = 1; |
| 6530 |
i__1 = *n; |
| 6531 |
for (j = 1; j <= i__1; ++j) { |
| 6532 |
j1j1 = jj + *n - j + 1; |
| 6533 |
|
| 6534 |
/* Compute the j-th column of the lower triangle of A */ |
| 6535 |
|
| 6536 |
ajj = ap[jj]; |
| 6537 |
bjj = bp[jj]; |
| 6538 |
i__2 = *n - j; |
| 6539 |
ap[jj] = ajj * bjj + ddot_(&i__2, &ap[jj + 1], &c__1, &bp[jj |
| 6540 |
+ 1], &c__1); |
| 6541 |
i__2 = *n - j; |
| 6542 |
dscal_(&i__2, &bjj, &ap[jj + 1], &c__1); |
| 6543 |
i__2 = *n - j; |
| 6544 |
dspmv_(uplo, &i__2, &c_b11, &ap[j1j1], &bp[jj + 1], &c__1, & |
| 6545 |
c_b11, &ap[jj + 1], &c__1); |
| 6546 |
i__2 = *n - j + 1; |
| 6547 |
dtpmv_(uplo, "Transpose", "Non-unit", &i__2, &bp[jj], &ap[jj], |
| 6548 |
&c__1); |
| 6549 |
jj = j1j1; |
| 6550 |
/* L40: */ |
| 6551 |
} |
| 6552 |
} |
| 6553 |
} |
| 6554 |
return 0; |
| 6555 |
|
| 6556 |
/* End of DSPGST */ |
| 6557 |
|
| 6558 |
} /* dspgst_ */ |
| 6559 |
|
| 6560 |
/* Subroutine */ int dspgv_(integer *itype, const char *jobz, const char *uplo, integer * |
| 6561 |
n, double *ap, double *bp, double *w, double *z__, |
| 6562 |
integer *ldz, double *work, integer *info) |
| 6563 |
{ |
| 6564 |
/* Table of constant values */ |
| 6565 |
static integer c__1 = 1; |
| 6566 |
|
| 6567 |
/* System generated locals */ |
| 6568 |
integer z_dim1, z_offset, i__1; |
| 6569 |
|
| 6570 |
/* Local variables */ |
| 6571 |
integer j, neig; |
| 6572 |
char trans[1]; |
| 6573 |
bool upper; |
| 6574 |
bool wantz; |
| 6575 |
|
| 6576 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 6577 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 6578 |
/* November 2006 */ |
| 6579 |
|
| 6580 |
/* .. Scalar Arguments .. */ |
| 6581 |
/* .. */ |
| 6582 |
/* .. Array Arguments .. */ |
| 6583 |
/* .. */ |
| 6584 |
|
| 6585 |
/* Purpose */ |
| 6586 |
/* ======= */ |
| 6587 |
|
| 6588 |
/* DSPGV computes all the eigenvalues and, optionally, the eigenvectors */ |
| 6589 |
/* of a real generalized symmetric-definite eigenproblem, of the form */ |
| 6590 |
/* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. */ |
| 6591 |
/* Here A and B are assumed to be symmetric, stored in packed format, */ |
| 6592 |
/* and B is also positive definite. */ |
| 6593 |
|
| 6594 |
/* Arguments */ |
| 6595 |
/* ========= */ |
| 6596 |
|
| 6597 |
/* ITYPE (input) INTEGER */ |
| 6598 |
/* Specifies the problem type to be solved: */ |
| 6599 |
/* = 1: A*x = (lambda)*B*x */ |
| 6600 |
/* = 2: A*B*x = (lambda)*x */ |
| 6601 |
/* = 3: B*A*x = (lambda)*x */ |
| 6602 |
|
| 6603 |
/* JOBZ (input) CHARACTER*1 */ |
| 6604 |
/* = 'N': Compute eigenvalues only; */ |
| 6605 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 6606 |
|
| 6607 |
/* UPLO (input) CHARACTER*1 */ |
| 6608 |
/* = 'U': Upper triangles of A and B are stored; */ |
| 6609 |
/* = 'L': Lower triangles of A and B are stored. */ |
| 6610 |
|
| 6611 |
/* N (input) INTEGER */ |
| 6612 |
/* The order of the matrices A and B. N >= 0. */ |
| 6613 |
|
| 6614 |
/* AP (input/output) DOUBLE PRECISION array, dimension */ |
| 6615 |
/* (N*(N+1)/2) */ |
| 6616 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 6617 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 6618 |
/* is stored in the array AP as follows: */ |
| 6619 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 6620 |
/* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ |
| 6621 |
|
| 6622 |
/* On exit, the contents of AP are destroyed. */ |
| 6623 |
|
| 6624 |
/* BP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 6625 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 6626 |
/* B, packed columnwise in a linear array. The j-th column of B */ |
| 6627 |
/* is stored in the array BP as follows: */ |
| 6628 |
/* if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */ |
| 6629 |
/* if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */ |
| 6630 |
|
| 6631 |
/* On exit, the triangular factor U or L from the Cholesky */ |
| 6632 |
/* factorization B = U**T*U or B = L*L**T, in the same storage */ |
| 6633 |
/* format as B. */ |
| 6634 |
|
| 6635 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 6636 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 6637 |
|
| 6638 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 6639 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */ |
| 6640 |
/* eigenvectors. The eigenvectors are normalized as follows: */ |
| 6641 |
/* if ITYPE = 1 or 2, Z**T*B*Z = I; */ |
| 6642 |
/* if ITYPE = 3, Z**T*inv(B)*Z = I. */ |
| 6643 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 6644 |
|
| 6645 |
/* LDZ (input) INTEGER */ |
| 6646 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 6647 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 6648 |
|
| 6649 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */ |
| 6650 |
|
| 6651 |
/* INFO (output) INTEGER */ |
| 6652 |
/* = 0: successful exit */ |
| 6653 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 6654 |
/* > 0: DPPTRF or DSPEV returned an error code: */ |
| 6655 |
/* <= N: if INFO = i, DSPEV failed to converge; */ |
| 6656 |
/* i off-diagonal elements of an intermediate */ |
| 6657 |
/* tridiagonal form did not converge to zero. */ |
| 6658 |
/* > N: if INFO = n + i, for 1 <= i <= n, then the leading */ |
| 6659 |
/* minor of order i of B is not positive definite. */ |
| 6660 |
/* The factorization of B could not be completed and */ |
| 6661 |
/* no eigenvalues or eigenvectors were computed. */ |
| 6662 |
|
| 6663 |
/* ===================================================================== */ |
| 6664 |
|
| 6665 |
/* .. Local Scalars .. */ |
| 6666 |
/* .. */ |
| 6667 |
/* .. External Functions .. */ |
| 6668 |
/* .. */ |
| 6669 |
/* .. External Subroutines .. */ |
| 6670 |
/* .. */ |
| 6671 |
/* .. Executable Statements .. */ |
| 6672 |
|
| 6673 |
/* Test the input parameters. */ |
| 6674 |
|
| 6675 |
/* Parameter adjustments */ |
| 6676 |
--ap; |
| 6677 |
--bp; |
| 6678 |
--w; |
| 6679 |
z_dim1 = *ldz; |
| 6680 |
z_offset = 1 + z_dim1; |
| 6681 |
z__ -= z_offset; |
| 6682 |
--work; |
| 6683 |
|
| 6684 |
/* Function Body */ |
| 6685 |
wantz = lsame_(jobz, "V"); |
| 6686 |
upper = lsame_(uplo, "U"); |
| 6687 |
|
| 6688 |
*info = 0; |
| 6689 |
if (*itype < 1 || *itype > 3) { |
| 6690 |
*info = -1; |
| 6691 |
} else if (! (wantz || lsame_(jobz, "N"))) { |
| 6692 |
*info = -2; |
| 6693 |
} else if (! (upper || lsame_(uplo, "L"))) { |
| 6694 |
*info = -3; |
| 6695 |
} else if (*n < 0) { |
| 6696 |
*info = -4; |
| 6697 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 6698 |
*info = -9; |
| 6699 |
} |
| 6700 |
if (*info != 0) { |
| 6701 |
i__1 = -(*info); |
| 6702 |
xerbla_("DSPGV ", &i__1); |
| 6703 |
return 0; |
| 6704 |
} |
| 6705 |
|
| 6706 |
/* Quick return if possible */ |
| 6707 |
|
| 6708 |
if (*n == 0) { |
| 6709 |
return 0; |
| 6710 |
} |
| 6711 |
|
| 6712 |
/* Form a Cholesky factorization of B. */ |
| 6713 |
|
| 6714 |
dpptrf_(uplo, n, &bp[1], info); |
| 6715 |
if (*info != 0) { |
| 6716 |
*info = *n + *info; |
| 6717 |
return 0; |
| 6718 |
} |
| 6719 |
|
| 6720 |
/* Transform problem to standard eigenvalue problem and solve. */ |
| 6721 |
|
| 6722 |
dspgst_(itype, uplo, n, &ap[1], &bp[1], info); |
| 6723 |
dspev_(jobz, uplo, n, &ap[1], &w[1], &z__[z_offset], ldz, &work[1], info); |
| 6724 |
|
| 6725 |
if (wantz) { |
| 6726 |
|
| 6727 |
/* Backtransform eigenvectors to the original problem. */ |
| 6728 |
|
| 6729 |
neig = *n; |
| 6730 |
if (*info > 0) { |
| 6731 |
neig = *info - 1; |
| 6732 |
} |
| 6733 |
if (*itype == 1 || *itype == 2) { |
| 6734 |
|
| 6735 |
/* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */ |
| 6736 |
/* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */ |
| 6737 |
|
| 6738 |
if (upper) { |
| 6739 |
*(unsigned char *)trans = 'N'; |
| 6740 |
} else { |
| 6741 |
*(unsigned char *)trans = 'T'; |
| 6742 |
} |
| 6743 |
|
| 6744 |
i__1 = neig; |
| 6745 |
for (j = 1; j <= i__1; ++j) { |
| 6746 |
dtpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + |
| 6747 |
1], &c__1); |
| 6748 |
/* L10: */ |
| 6749 |
} |
| 6750 |
|
| 6751 |
} else if (*itype == 3) { |
| 6752 |
|
| 6753 |
/* For B*A*x=(lambda)*x; */ |
| 6754 |
/* backtransform eigenvectors: x = L*y or U'*y */ |
| 6755 |
|
| 6756 |
if (upper) { |
| 6757 |
*(unsigned char *)trans = 'T'; |
| 6758 |
} else { |
| 6759 |
*(unsigned char *)trans = 'N'; |
| 6760 |
} |
| 6761 |
|
| 6762 |
i__1 = neig; |
| 6763 |
for (j = 1; j <= i__1; ++j) { |
| 6764 |
dtpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + |
| 6765 |
1], &c__1); |
| 6766 |
/* L20: */ |
| 6767 |
} |
| 6768 |
} |
| 6769 |
} |
| 6770 |
return 0; |
| 6771 |
|
| 6772 |
/* End of DSPGV */ |
| 6773 |
|
| 6774 |
} /* dspgv_ */ |
| 6775 |
|
| 6776 |
/* Subroutine */ int dspgvd_(integer *itype, const char *jobz, const char *uplo, integer * |
| 6777 |
n, double *ap, double *bp, double *w, double *z__, |
| 6778 |
integer *ldz, double *work, integer *lwork, integer *iwork, |
| 6779 |
integer *liwork, integer *info) |
| 6780 |
{ |
| 6781 |
/* Table of constant values */ |
| 6782 |
static integer c__1 = 1; |
| 6783 |
|
| 6784 |
/* System generated locals */ |
| 6785 |
integer z_dim1, z_offset, i__1; |
| 6786 |
double d__1, d__2; |
| 6787 |
|
| 6788 |
/* Local variables */ |
| 6789 |
integer j, neig; |
| 6790 |
integer lwmin; |
| 6791 |
char trans[1]; |
| 6792 |
bool upper; |
| 6793 |
bool wantz; |
| 6794 |
integer liwmin; |
| 6795 |
bool lquery; |
| 6796 |
|
| 6797 |
|
| 6798 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 6799 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 6800 |
/* November 2006 */ |
| 6801 |
|
| 6802 |
/* .. Scalar Arguments .. */ |
| 6803 |
/* .. */ |
| 6804 |
/* .. Array Arguments .. */ |
| 6805 |
/* .. */ |
| 6806 |
|
| 6807 |
/* Purpose */ |
| 6808 |
/* ======= */ |
| 6809 |
|
| 6810 |
/* DSPGVD computes all the eigenvalues, and optionally, the eigenvectors */ |
| 6811 |
/* of a real generalized symmetric-definite eigenproblem, of the form */ |
| 6812 |
/* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A and */ |
| 6813 |
/* B are assumed to be symmetric, stored in packed format, and B is also */ |
| 6814 |
/* positive definite. */ |
| 6815 |
/* If eigenvectors are desired, it uses a divide and conquer algorithm. */ |
| 6816 |
|
| 6817 |
/* The divide and conquer algorithm makes very mild assumptions about */ |
| 6818 |
/* floating point arithmetic. It will work on machines with a guard */ |
| 6819 |
/* digit in add/subtract, or on those binary machines without guard */ |
| 6820 |
/* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ |
| 6821 |
/* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ |
| 6822 |
/* without guard digits, but we know of none. */ |
| 6823 |
|
| 6824 |
/* Arguments */ |
| 6825 |
/* ========= */ |
| 6826 |
|
| 6827 |
/* ITYPE (input) INTEGER */ |
| 6828 |
/* Specifies the problem type to be solved: */ |
| 6829 |
/* = 1: A*x = (lambda)*B*x */ |
| 6830 |
/* = 2: A*B*x = (lambda)*x */ |
| 6831 |
/* = 3: B*A*x = (lambda)*x */ |
| 6832 |
|
| 6833 |
/* JOBZ (input) CHARACTER*1 */ |
| 6834 |
/* = 'N': Compute eigenvalues only; */ |
| 6835 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 6836 |
|
| 6837 |
/* UPLO (input) CHARACTER*1 */ |
| 6838 |
/* = 'U': Upper triangles of A and B are stored; */ |
| 6839 |
/* = 'L': Lower triangles of A and B are stored. */ |
| 6840 |
|
| 6841 |
/* N (input) INTEGER */ |
| 6842 |
/* The order of the matrices A and B. N >= 0. */ |
| 6843 |
|
| 6844 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 6845 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 6846 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 6847 |
/* is stored in the array AP as follows: */ |
| 6848 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 6849 |
/* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ |
| 6850 |
|
| 6851 |
/* On exit, the contents of AP are destroyed. */ |
| 6852 |
|
| 6853 |
/* BP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 6854 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 6855 |
/* B, packed columnwise in a linear array. The j-th column of B */ |
| 6856 |
/* is stored in the array BP as follows: */ |
| 6857 |
/* if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */ |
| 6858 |
/* if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */ |
| 6859 |
|
| 6860 |
/* On exit, the triangular factor U or L from the Cholesky */ |
| 6861 |
/* factorization B = U**T*U or B = L*L**T, in the same storage */ |
| 6862 |
/* format as B. */ |
| 6863 |
|
| 6864 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 6865 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 6866 |
|
| 6867 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 6868 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */ |
| 6869 |
/* eigenvectors. The eigenvectors are normalized as follows: */ |
| 6870 |
/* if ITYPE = 1 or 2, Z**T*B*Z = I; */ |
| 6871 |
/* if ITYPE = 3, Z**T*inv(B)*Z = I. */ |
| 6872 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 6873 |
|
| 6874 |
/* LDZ (input) INTEGER */ |
| 6875 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 6876 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 6877 |
|
| 6878 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 6879 |
/* On exit, if INFO = 0, WORK(1) returns the required LWORK. */ |
| 6880 |
|
| 6881 |
/* LWORK (input) INTEGER */ |
| 6882 |
/* The dimension of the array WORK. */ |
| 6883 |
/* If N <= 1, LWORK >= 1. */ |
| 6884 |
/* If JOBZ = 'N' and N > 1, LWORK >= 2*N. */ |
| 6885 |
/* If JOBZ = 'V' and N > 1, LWORK >= 1 + 6*N + 2*N**2. */ |
| 6886 |
|
| 6887 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 6888 |
/* only calculates the required sizes of the WORK and IWORK */ |
| 6889 |
/* arrays, returns these values as the first entries of the WORK */ |
| 6890 |
/* and IWORK arrays, and no error message related to LWORK or */ |
| 6891 |
/* LIWORK is issued by XERBLA. */ |
| 6892 |
|
| 6893 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 6894 |
/* On exit, if INFO = 0, IWORK(1) returns the required LIWORK. */ |
| 6895 |
|
| 6896 |
/* LIWORK (input) INTEGER */ |
| 6897 |
/* The dimension of the array IWORK. */ |
| 6898 |
/* If JOBZ = 'N' or N <= 1, LIWORK >= 1. */ |
| 6899 |
/* If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N. */ |
| 6900 |
|
| 6901 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 6902 |
/* routine only calculates the required sizes of the WORK and */ |
| 6903 |
/* IWORK arrays, returns these values as the first entries of */ |
| 6904 |
/* the WORK and IWORK arrays, and no error message related to */ |
| 6905 |
/* LWORK or LIWORK is issued by XERBLA. */ |
| 6906 |
|
| 6907 |
/* INFO (output) INTEGER */ |
| 6908 |
/* = 0: successful exit */ |
| 6909 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 6910 |
/* > 0: DPPTRF or DSPEVD returned an error code: */ |
| 6911 |
/* <= N: if INFO = i, DSPEVD failed to converge; */ |
| 6912 |
/* i off-diagonal elements of an intermediate */ |
| 6913 |
/* tridiagonal form did not converge to zero; */ |
| 6914 |
/* > N: if INFO = N + i, for 1 <= i <= N, then the leading */ |
| 6915 |
/* minor of order i of B is not positive definite. */ |
| 6916 |
/* The factorization of B could not be completed and */ |
| 6917 |
/* no eigenvalues or eigenvectors were computed. */ |
| 6918 |
|
| 6919 |
/* Further Details */ |
| 6920 |
/* =============== */ |
| 6921 |
|
| 6922 |
/* Based on contributions by */ |
| 6923 |
/* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */ |
| 6924 |
|
| 6925 |
/* ===================================================================== */ |
| 6926 |
|
| 6927 |
/* .. Parameters .. */ |
| 6928 |
/* .. */ |
| 6929 |
/* .. Local Scalars .. */ |
| 6930 |
/* .. */ |
| 6931 |
/* .. External Functions .. */ |
| 6932 |
/* .. */ |
| 6933 |
/* .. External Subroutines .. */ |
| 6934 |
/* .. */ |
| 6935 |
/* .. Intrinsic Functions .. */ |
| 6936 |
/* .. */ |
| 6937 |
/* .. Executable Statements .. */ |
| 6938 |
|
| 6939 |
/* Test the input parameters. */ |
| 6940 |
|
| 6941 |
/* Parameter adjustments */ |
| 6942 |
--ap; |
| 6943 |
--bp; |
| 6944 |
--w; |
| 6945 |
z_dim1 = *ldz; |
| 6946 |
z_offset = 1 + z_dim1; |
| 6947 |
z__ -= z_offset; |
| 6948 |
--work; |
| 6949 |
--iwork; |
| 6950 |
|
| 6951 |
/* Function Body */ |
| 6952 |
wantz = lsame_(jobz, "V"); |
| 6953 |
upper = lsame_(uplo, "U"); |
| 6954 |
lquery = *lwork == -1 || *liwork == -1; |
| 6955 |
|
| 6956 |
*info = 0; |
| 6957 |
if (*itype < 1 || *itype > 3) { |
| 6958 |
*info = -1; |
| 6959 |
} else if (! (wantz || lsame_(jobz, "N"))) { |
| 6960 |
*info = -2; |
| 6961 |
} else if (! (upper || lsame_(uplo, "L"))) { |
| 6962 |
*info = -3; |
| 6963 |
} else if (*n < 0) { |
| 6964 |
*info = -4; |
| 6965 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 6966 |
*info = -9; |
| 6967 |
} |
| 6968 |
|
| 6969 |
if (*info == 0) { |
| 6970 |
if (*n <= 1) { |
| 6971 |
liwmin = 1; |
| 6972 |
lwmin = 1; |
| 6973 |
} else { |
| 6974 |
if (wantz) { |
| 6975 |
liwmin = *n * 5 + 3; |
| 6976 |
/* Computing 2nd power */ |
| 6977 |
i__1 = *n; |
| 6978 |
lwmin = *n * 6 + 1 + (i__1 * i__1 << 1); |
| 6979 |
} else { |
| 6980 |
liwmin = 1; |
| 6981 |
lwmin = *n << 1; |
| 6982 |
} |
| 6983 |
} |
| 6984 |
work[1] = (double) lwmin; |
| 6985 |
iwork[1] = liwmin; |
| 6986 |
|
| 6987 |
if (*lwork < lwmin && ! lquery) { |
| 6988 |
*info = -11; |
| 6989 |
} else if (*liwork < liwmin && ! lquery) { |
| 6990 |
*info = -13; |
| 6991 |
} |
| 6992 |
} |
| 6993 |
|
| 6994 |
if (*info != 0) { |
| 6995 |
i__1 = -(*info); |
| 6996 |
xerbla_("DSPGVD", &i__1); |
| 6997 |
return 0; |
| 6998 |
} else if (lquery) { |
| 6999 |
return 0; |
| 7000 |
} |
| 7001 |
|
| 7002 |
/* Quick return if possible */ |
| 7003 |
|
| 7004 |
if (*n == 0) { |
| 7005 |
return 0; |
| 7006 |
} |
| 7007 |
|
| 7008 |
/* Form a Cholesky factorization of BP. */ |
| 7009 |
|
| 7010 |
dpptrf_(uplo, n, &bp[1], info); |
| 7011 |
if (*info != 0) { |
| 7012 |
*info = *n + *info; |
| 7013 |
return 0; |
| 7014 |
} |
| 7015 |
|
| 7016 |
/* Transform problem to standard eigenvalue problem and solve. */ |
| 7017 |
|
| 7018 |
dspgst_(itype, uplo, n, &ap[1], &bp[1], info); |
| 7019 |
dspevd_(jobz, uplo, n, &ap[1], &w[1], &z__[z_offset], ldz, &work[1], |
| 7020 |
lwork, &iwork[1], liwork, info); |
| 7021 |
/* Computing MAX */ |
| 7022 |
d__1 = (double) lwmin; |
| 7023 |
lwmin = (integer) std::max(d__1,work[1]); |
| 7024 |
/* Computing MAX */ |
| 7025 |
d__1 = (double) liwmin, d__2 = (double) iwork[1]; |
| 7026 |
liwmin = (integer) std::max(d__1,d__2); |
| 7027 |
|
| 7028 |
if (wantz) { |
| 7029 |
|
| 7030 |
/* Backtransform eigenvectors to the original problem. */ |
| 7031 |
|
| 7032 |
neig = *n; |
| 7033 |
if (*info > 0) { |
| 7034 |
neig = *info - 1; |
| 7035 |
} |
| 7036 |
if (*itype == 1 || *itype == 2) { |
| 7037 |
|
| 7038 |
/* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */ |
| 7039 |
/* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */ |
| 7040 |
|
| 7041 |
if (upper) { |
| 7042 |
*(unsigned char *)trans = 'N'; |
| 7043 |
} else { |
| 7044 |
*(unsigned char *)trans = 'T'; |
| 7045 |
} |
| 7046 |
|
| 7047 |
i__1 = neig; |
| 7048 |
for (j = 1; j <= i__1; ++j) { |
| 7049 |
dtpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + |
| 7050 |
1], &c__1); |
| 7051 |
/* L10: */ |
| 7052 |
} |
| 7053 |
|
| 7054 |
} else if (*itype == 3) { |
| 7055 |
|
| 7056 |
/* For B*A*x=(lambda)*x; */ |
| 7057 |
/* backtransform eigenvectors: x = L*y or U'*y */ |
| 7058 |
|
| 7059 |
if (upper) { |
| 7060 |
*(unsigned char *)trans = 'T'; |
| 7061 |
} else { |
| 7062 |
*(unsigned char *)trans = 'N'; |
| 7063 |
} |
| 7064 |
|
| 7065 |
i__1 = neig; |
| 7066 |
for (j = 1; j <= i__1; ++j) { |
| 7067 |
dtpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + |
| 7068 |
1], &c__1); |
| 7069 |
/* L20: */ |
| 7070 |
} |
| 7071 |
} |
| 7072 |
} |
| 7073 |
|
| 7074 |
work[1] = (double) lwmin; |
| 7075 |
iwork[1] = liwmin; |
| 7076 |
|
| 7077 |
return 0; |
| 7078 |
|
| 7079 |
/* End of DSPGVD */ |
| 7080 |
|
| 7081 |
} /* dspgvd_ */ |
| 7082 |
|
| 7083 |
/* Subroutine */ int dspgvx_(integer *itype, const char *jobz, const char *range, const char * |
| 7084 |
uplo, integer *n, double *ap, double *bp, double *vl, |
| 7085 |
double *vu, integer *il, integer *iu, double *abstol, integer |
| 7086 |
*m, double *w, double *z__, integer *ldz, double *work, |
| 7087 |
integer *iwork, integer *ifail, integer *info) |
| 7088 |
{ |
| 7089 |
/* Table of constant values */ |
| 7090 |
static integer c__1 = 1; |
| 7091 |
|
| 7092 |
/* System generated locals */ |
| 7093 |
integer z_dim1, z_offset, i__1; |
| 7094 |
|
| 7095 |
/* Local variables */ |
| 7096 |
integer j; |
| 7097 |
char trans[1]; |
| 7098 |
bool upper; |
| 7099 |
bool wantz, alleig, indeig, valeig; |
| 7100 |
|
| 7101 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 7102 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 7103 |
/* November 2006 */ |
| 7104 |
|
| 7105 |
/* .. Scalar Arguments .. */ |
| 7106 |
/* .. */ |
| 7107 |
/* .. Array Arguments .. */ |
| 7108 |
/* .. */ |
| 7109 |
|
| 7110 |
/* Purpose */ |
| 7111 |
/* ======= */ |
| 7112 |
|
| 7113 |
/* DSPGVX computes selected eigenvalues, and optionally, eigenvectors */ |
| 7114 |
/* of a real generalized symmetric-definite eigenproblem, of the form */ |
| 7115 |
/* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A */ |
| 7116 |
/* and B are assumed to be symmetric, stored in packed storage, and B */ |
| 7117 |
/* is also positive definite. Eigenvalues and eigenvectors can be */ |
| 7118 |
/* selected by specifying either a range of values or a range of indices */ |
| 7119 |
/* for the desired eigenvalues. */ |
| 7120 |
|
| 7121 |
/* Arguments */ |
| 7122 |
/* ========= */ |
| 7123 |
|
| 7124 |
/* ITYPE (input) INTEGER */ |
| 7125 |
/* Specifies the problem type to be solved: */ |
| 7126 |
/* = 1: A*x = (lambda)*B*x */ |
| 7127 |
/* = 2: A*B*x = (lambda)*x */ |
| 7128 |
/* = 3: B*A*x = (lambda)*x */ |
| 7129 |
|
| 7130 |
/* JOBZ (input) CHARACTER*1 */ |
| 7131 |
/* = 'N': Compute eigenvalues only; */ |
| 7132 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 7133 |
|
| 7134 |
/* RANGE (input) CHARACTER*1 */ |
| 7135 |
/* = 'A': all eigenvalues will be found. */ |
| 7136 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 7137 |
/* will be found. */ |
| 7138 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 7139 |
|
| 7140 |
/* UPLO (input) CHARACTER*1 */ |
| 7141 |
/* = 'U': Upper triangle of A and B are stored; */ |
| 7142 |
/* = 'L': Lower triangle of A and B are stored. */ |
| 7143 |
|
| 7144 |
/* N (input) INTEGER */ |
| 7145 |
/* The order of the matrix pencil (A,B). N >= 0. */ |
| 7146 |
|
| 7147 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 7148 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 7149 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 7150 |
/* is stored in the array AP as follows: */ |
| 7151 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 7152 |
/* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ |
| 7153 |
|
| 7154 |
/* On exit, the contents of AP are destroyed. */ |
| 7155 |
|
| 7156 |
/* BP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 7157 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 7158 |
/* B, packed columnwise in a linear array. The j-th column of B */ |
| 7159 |
/* is stored in the array BP as follows: */ |
| 7160 |
/* if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */ |
| 7161 |
/* if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */ |
| 7162 |
|
| 7163 |
/* On exit, the triangular factor U or L from the Cholesky */ |
| 7164 |
/* factorization B = U**T*U or B = L*L**T, in the same storage */ |
| 7165 |
/* format as B. */ |
| 7166 |
|
| 7167 |
/* VL (input) DOUBLE PRECISION */ |
| 7168 |
/* VU (input) DOUBLE PRECISION */ |
| 7169 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 7170 |
/* be searched for eigenvalues. VL < VU. */ |
| 7171 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 7172 |
|
| 7173 |
/* IL (input) INTEGER */ |
| 7174 |
/* IU (input) INTEGER */ |
| 7175 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 7176 |
/* smallest and largest eigenvalues to be returned. */ |
| 7177 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 7178 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 7179 |
|
| 7180 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 7181 |
/* The absolute error tolerance for the eigenvalues. */ |
| 7182 |
/* An approximate eigenvalue is accepted as converged */ |
| 7183 |
/* when it is determined to lie in an interval [a,b] */ |
| 7184 |
/* of width less than or equal to */ |
| 7185 |
|
| 7186 |
/* ABSTOL + EPS * max( |a|,|b| ) , */ |
| 7187 |
|
| 7188 |
/* where EPS is the machine precision. If ABSTOL is less than */ |
| 7189 |
/* or equal to zero, then EPS*|T| will be used in its place, */ |
| 7190 |
/* where |T| is the 1-norm of the tridiagonal matrix obtained */ |
| 7191 |
/* by reducing A to tridiagonal form. */ |
| 7192 |
|
| 7193 |
/* Eigenvalues will be computed most accurately when ABSTOL is */ |
| 7194 |
/* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */ |
| 7195 |
/* If this routine returns with INFO>0, indicating that some */ |
| 7196 |
/* eigenvectors did not converge, try setting ABSTOL to */ |
| 7197 |
/* 2*DLAMCH('S'). */ |
| 7198 |
|
| 7199 |
/* M (output) INTEGER */ |
| 7200 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 7201 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 7202 |
|
| 7203 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 7204 |
/* On normal exit, the first M elements contain the selected */ |
| 7205 |
/* eigenvalues in ascending order. */ |
| 7206 |
|
| 7207 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */ |
| 7208 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 7209 |
/* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ |
| 7210 |
/* contain the orthonormal eigenvectors of the matrix A */ |
| 7211 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 7212 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 7213 |
/* The eigenvectors are normalized as follows: */ |
| 7214 |
/* if ITYPE = 1 or 2, Z**T*B*Z = I; */ |
| 7215 |
/* if ITYPE = 3, Z**T*inv(B)*Z = I. */ |
| 7216 |
|
| 7217 |
/* If an eigenvector fails to converge, then that column of Z */ |
| 7218 |
/* contains the latest approximation to the eigenvector, and the */ |
| 7219 |
/* index of the eigenvector is returned in IFAIL. */ |
| 7220 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 7221 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 7222 |
/* is not known in advance and an upper bound must be used. */ |
| 7223 |
|
| 7224 |
/* LDZ (input) INTEGER */ |
| 7225 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 7226 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 7227 |
|
| 7228 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (8*N) */ |
| 7229 |
|
| 7230 |
/* IWORK (workspace) INTEGER array, dimension (5*N) */ |
| 7231 |
|
| 7232 |
/* IFAIL (output) INTEGER array, dimension (N) */ |
| 7233 |
/* If JOBZ = 'V', then if INFO = 0, the first M elements of */ |
| 7234 |
/* IFAIL are zero. If INFO > 0, then IFAIL contains the */ |
| 7235 |
/* indices of the eigenvectors that failed to converge. */ |
| 7236 |
/* If JOBZ = 'N', then IFAIL is not referenced. */ |
| 7237 |
|
| 7238 |
/* INFO (output) INTEGER */ |
| 7239 |
/* = 0: successful exit */ |
| 7240 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 7241 |
/* > 0: DPPTRF or DSPEVX returned an error code: */ |
| 7242 |
/* <= N: if INFO = i, DSPEVX failed to converge; */ |
| 7243 |
/* i eigenvectors failed to converge. Their indices */ |
| 7244 |
/* are stored in array IFAIL. */ |
| 7245 |
/* > N: if INFO = N + i, for 1 <= i <= N, then the leading */ |
| 7246 |
/* minor of order i of B is not positive definite. */ |
| 7247 |
/* The factorization of B could not be completed and */ |
| 7248 |
/* no eigenvalues or eigenvectors were computed. */ |
| 7249 |
|
| 7250 |
/* Further Details */ |
| 7251 |
/* =============== */ |
| 7252 |
|
| 7253 |
/* Based on contributions by */ |
| 7254 |
/* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */ |
| 7255 |
|
| 7256 |
/* ===================================================================== */ |
| 7257 |
|
| 7258 |
/* .. Local Scalars .. */ |
| 7259 |
/* .. */ |
| 7260 |
/* .. External Functions .. */ |
| 7261 |
/* .. */ |
| 7262 |
/* .. External Subroutines .. */ |
| 7263 |
/* .. */ |
| 7264 |
/* .. Intrinsic Functions .. */ |
| 7265 |
/* .. */ |
| 7266 |
/* .. Executable Statements .. */ |
| 7267 |
|
| 7268 |
/* Test the input parameters. */ |
| 7269 |
|
| 7270 |
/* Parameter adjustments */ |
| 7271 |
--ap; |
| 7272 |
--bp; |
| 7273 |
--w; |
| 7274 |
z_dim1 = *ldz; |
| 7275 |
z_offset = 1 + z_dim1; |
| 7276 |
z__ -= z_offset; |
| 7277 |
--work; |
| 7278 |
--iwork; |
| 7279 |
--ifail; |
| 7280 |
|
| 7281 |
/* Function Body */ |
| 7282 |
upper = lsame_(uplo, "U"); |
| 7283 |
wantz = lsame_(jobz, "V"); |
| 7284 |
alleig = lsame_(range, "A"); |
| 7285 |
valeig = lsame_(range, "V"); |
| 7286 |
indeig = lsame_(range, "I"); |
| 7287 |
|
| 7288 |
*info = 0; |
| 7289 |
if (*itype < 1 || *itype > 3) { |
| 7290 |
*info = -1; |
| 7291 |
} else if (! (wantz || lsame_(jobz, "N"))) { |
| 7292 |
*info = -2; |
| 7293 |
} else if (! (alleig || valeig || indeig)) { |
| 7294 |
*info = -3; |
| 7295 |
} else if (! (upper || lsame_(uplo, "L"))) { |
| 7296 |
*info = -4; |
| 7297 |
} else if (*n < 0) { |
| 7298 |
*info = -5; |
| 7299 |
} else { |
| 7300 |
if (valeig) { |
| 7301 |
if (*n > 0 && *vu <= *vl) { |
| 7302 |
*info = -9; |
| 7303 |
} |
| 7304 |
} else if (indeig) { |
| 7305 |
if (*il < 1) { |
| 7306 |
*info = -10; |
| 7307 |
} else if (*iu < std::min(*n,*il) || *iu > *n) { |
| 7308 |
*info = -11; |
| 7309 |
} |
| 7310 |
} |
| 7311 |
} |
| 7312 |
if (*info == 0) { |
| 7313 |
if (*ldz < 1 || wantz && *ldz < *n) { |
| 7314 |
*info = -16; |
| 7315 |
} |
| 7316 |
} |
| 7317 |
|
| 7318 |
if (*info != 0) { |
| 7319 |
i__1 = -(*info); |
| 7320 |
xerbla_("DSPGVX", &i__1); |
| 7321 |
return 0; |
| 7322 |
} |
| 7323 |
|
| 7324 |
/* Quick return if possible */ |
| 7325 |
|
| 7326 |
*m = 0; |
| 7327 |
if (*n == 0) { |
| 7328 |
return 0; |
| 7329 |
} |
| 7330 |
|
| 7331 |
/* Form a Cholesky factorization of B. */ |
| 7332 |
|
| 7333 |
dpptrf_(uplo, n, &bp[1], info); |
| 7334 |
if (*info != 0) { |
| 7335 |
*info = *n + *info; |
| 7336 |
return 0; |
| 7337 |
} |
| 7338 |
|
| 7339 |
/* Transform problem to standard eigenvalue problem and solve. */ |
| 7340 |
|
| 7341 |
dspgst_(itype, uplo, n, &ap[1], &bp[1], info); |
| 7342 |
dspevx_(jobz, range, uplo, n, &ap[1], vl, vu, il, iu, abstol, m, &w[1], & |
| 7343 |
z__[z_offset], ldz, &work[1], &iwork[1], &ifail[1], info); |
| 7344 |
|
| 7345 |
if (wantz) { |
| 7346 |
|
| 7347 |
/* Backtransform eigenvectors to the original problem. */ |
| 7348 |
|
| 7349 |
if (*info > 0) { |
| 7350 |
*m = *info - 1; |
| 7351 |
} |
| 7352 |
if (*itype == 1 || *itype == 2) { |
| 7353 |
|
| 7354 |
/* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */ |
| 7355 |
/* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */ |
| 7356 |
|
| 7357 |
if (upper) { |
| 7358 |
*(unsigned char *)trans = 'N'; |
| 7359 |
} else { |
| 7360 |
*(unsigned char *)trans = 'T'; |
| 7361 |
} |
| 7362 |
|
| 7363 |
i__1 = *m; |
| 7364 |
for (j = 1; j <= i__1; ++j) { |
| 7365 |
dtpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + |
| 7366 |
1], &c__1); |
| 7367 |
/* L10: */ |
| 7368 |
} |
| 7369 |
|
| 7370 |
} else if (*itype == 3) { |
| 7371 |
|
| 7372 |
/* For B*A*x=(lambda)*x; */ |
| 7373 |
/* backtransform eigenvectors: x = L*y or U'*y */ |
| 7374 |
|
| 7375 |
if (upper) { |
| 7376 |
*(unsigned char *)trans = 'T'; |
| 7377 |
} else { |
| 7378 |
*(unsigned char *)trans = 'N'; |
| 7379 |
} |
| 7380 |
|
| 7381 |
i__1 = *m; |
| 7382 |
for (j = 1; j <= i__1; ++j) { |
| 7383 |
dtpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 + |
| 7384 |
1], &c__1); |
| 7385 |
/* L20: */ |
| 7386 |
} |
| 7387 |
} |
| 7388 |
} |
| 7389 |
|
| 7390 |
return 0; |
| 7391 |
|
| 7392 |
/* End of DSPGVX */ |
| 7393 |
|
| 7394 |
} /* dspgvx_ */ |
| 7395 |
|
| 7396 |
/* Subroutine */ int dsprfs_(const char *uplo, integer *n, integer *nrhs, |
| 7397 |
double *ap, double *afp, integer *ipiv, double *b, |
| 7398 |
integer *ldb, double *x, integer *ldx, double *ferr, |
| 7399 |
double *berr, double *work, integer *iwork, integer *info) |
| 7400 |
{ |
| 7401 |
/* Table of constant values */ |
| 7402 |
static integer c__1 = 1; |
| 7403 |
static double c_b12 = -1.; |
| 7404 |
static double c_b14 = 1.; |
| 7405 |
|
| 7406 |
/* System generated locals */ |
| 7407 |
integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3; |
| 7408 |
double d__1, d__2, d__3; |
| 7409 |
|
| 7410 |
/* Local variables */ |
| 7411 |
integer i__, j, k; |
| 7412 |
double s; |
| 7413 |
integer ik, kk; |
| 7414 |
double xk; |
| 7415 |
integer nz; |
| 7416 |
double eps; |
| 7417 |
integer kase; |
| 7418 |
double safe1, safe2; |
| 7419 |
integer isave[3]; |
| 7420 |
integer count; |
| 7421 |
bool upper; |
| 7422 |
double safmin; |
| 7423 |
double lstres; |
| 7424 |
|
| 7425 |
/* -- LAPACK routine (version 3.1) -- */ |
| 7426 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 7427 |
/* November 2006 */ |
| 7428 |
|
| 7429 |
/* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */ |
| 7430 |
|
| 7431 |
/* .. Scalar Arguments .. */ |
| 7432 |
/* .. */ |
| 7433 |
/* .. Array Arguments .. */ |
| 7434 |
/* .. */ |
| 7435 |
|
| 7436 |
/* Purpose */ |
| 7437 |
/* ======= */ |
| 7438 |
|
| 7439 |
/* DSPRFS improves the computed solution to a system of linear */ |
| 7440 |
/* equations when the coefficient matrix is symmetric indefinite */ |
| 7441 |
/* and packed, and provides error bounds and backward error estimates */ |
| 7442 |
/* for the solution. */ |
| 7443 |
|
| 7444 |
/* Arguments */ |
| 7445 |
/* ========= */ |
| 7446 |
|
| 7447 |
/* UPLO (input) CHARACTER*1 */ |
| 7448 |
/* = 'U': Upper triangle of A is stored; */ |
| 7449 |
/* = 'L': Lower triangle of A is stored. */ |
| 7450 |
|
| 7451 |
/* N (input) INTEGER */ |
| 7452 |
/* The order of the matrix A. N >= 0. */ |
| 7453 |
|
| 7454 |
/* NRHS (input) INTEGER */ |
| 7455 |
/* The number of right hand sides, i.e., the number of columns */ |
| 7456 |
/* of the matrices B and X. NRHS >= 0. */ |
| 7457 |
|
| 7458 |
/* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 7459 |
/* The upper or lower triangle of the symmetric matrix A, packed */ |
| 7460 |
/* columnwise in a linear array. The j-th column of A is stored */ |
| 7461 |
/* in the array AP as follows: */ |
| 7462 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 7463 |
/* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ |
| 7464 |
|
| 7465 |
/* AFP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 7466 |
/* The factored form of the matrix A. AFP contains the block */ |
| 7467 |
/* diagonal matrix D and the multipliers used to obtain the */ |
| 7468 |
/* factor U or L from the factorization A = U*D*U**T or */ |
| 7469 |
/* A = L*D*L**T as computed by DSPTRF, stored as a packed */ |
| 7470 |
/* triangular matrix. */ |
| 7471 |
|
| 7472 |
/* IPIV (input) INTEGER array, dimension (N) */ |
| 7473 |
/* Details of the interchanges and the block structure of D */ |
| 7474 |
/* as determined by DSPTRF. */ |
| 7475 |
|
| 7476 |
/* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 7477 |
/* The right hand side matrix B. */ |
| 7478 |
|
| 7479 |
/* LDB (input) INTEGER */ |
| 7480 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 7481 |
|
| 7482 |
/* X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */ |
| 7483 |
/* On entry, the solution matrix X, as computed by DSPTRS. */ |
| 7484 |
/* On exit, the improved solution matrix X. */ |
| 7485 |
|
| 7486 |
/* LDX (input) INTEGER */ |
| 7487 |
/* The leading dimension of the array X. LDX >= max(1,N). */ |
| 7488 |
|
| 7489 |
/* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 7490 |
/* The estimated forward error bound for each solution vector */ |
| 7491 |
/* X(j) (the j-th column of the solution matrix X). */ |
| 7492 |
/* If XTRUE is the true solution corresponding to X(j), FERR(j) */ |
| 7493 |
/* is an estimated upper bound for the magnitude of the largest */ |
| 7494 |
/* element in (X(j) - XTRUE) divided by the magnitude of the */ |
| 7495 |
/* largest element in X(j). The estimate is as reliable as */ |
| 7496 |
/* the estimate for RCOND, and is almost always a slight */ |
| 7497 |
/* overestimate of the true error. */ |
| 7498 |
|
| 7499 |
/* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 7500 |
/* The componentwise relative backward error of each solution */ |
| 7501 |
/* vector X(j) (i.e., the smallest relative change in */ |
| 7502 |
/* any element of A or B that makes X(j) an exact solution). */ |
| 7503 |
|
| 7504 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */ |
| 7505 |
|
| 7506 |
/* IWORK (workspace) INTEGER array, dimension (N) */ |
| 7507 |
|
| 7508 |
/* INFO (output) INTEGER */ |
| 7509 |
/* = 0: successful exit */ |
| 7510 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 7511 |
|
| 7512 |
/* Internal Parameters */ |
| 7513 |
/* =================== */ |
| 7514 |
|
| 7515 |
/* ITMAX is the maximum number of steps of iterative refinement. */ |
| 7516 |
|
| 7517 |
/* ===================================================================== */ |
| 7518 |
|
| 7519 |
/* .. Parameters .. */ |
| 7520 |
/* .. */ |
| 7521 |
/* .. Local Scalars .. */ |
| 7522 |
/* .. */ |
| 7523 |
/* .. Local Arrays .. */ |
| 7524 |
/* .. */ |
| 7525 |
/* .. External Subroutines .. */ |
| 7526 |
/* .. */ |
| 7527 |
/* .. Intrinsic Functions .. */ |
| 7528 |
/* .. */ |
| 7529 |
/* .. External Functions .. */ |
| 7530 |
/* .. */ |
| 7531 |
/* .. Executable Statements .. */ |
| 7532 |
|
| 7533 |
/* Test the input parameters. */ |
| 7534 |
|
| 7535 |
/* Parameter adjustments */ |
| 7536 |
--ap; |
| 7537 |
--afp; |
| 7538 |
--ipiv; |
| 7539 |
b_dim1 = *ldb; |
| 7540 |
b_offset = 1 + b_dim1; |
| 7541 |
b -= b_offset; |
| 7542 |
x_dim1 = *ldx; |
| 7543 |
x_offset = 1 + x_dim1; |
| 7544 |
x -= x_offset; |
| 7545 |
--ferr; |
| 7546 |
--berr; |
| 7547 |
--work; |
| 7548 |
--iwork; |
| 7549 |
|
| 7550 |
/* Function Body */ |
| 7551 |
*info = 0; |
| 7552 |
upper = lsame_(uplo, "U"); |
| 7553 |
if (! upper && ! lsame_(uplo, "L")) { |
| 7554 |
*info = -1; |
| 7555 |
} else if (*n < 0) { |
| 7556 |
*info = -2; |
| 7557 |
} else if (*nrhs < 0) { |
| 7558 |
*info = -3; |
| 7559 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 7560 |
*info = -8; |
| 7561 |
} else if (*ldx < std::max(1_integer,*n)) { |
| 7562 |
*info = -10; |
| 7563 |
} |
| 7564 |
if (*info != 0) { |
| 7565 |
i__1 = -(*info); |
| 7566 |
xerbla_("DSPRFS", &i__1); |
| 7567 |
return 0; |
| 7568 |
} |
| 7569 |
|
| 7570 |
/* Quick return if possible */ |
| 7571 |
|
| 7572 |
if (*n == 0 || *nrhs == 0) { |
| 7573 |
i__1 = *nrhs; |
| 7574 |
for (j = 1; j <= i__1; ++j) { |
| 7575 |
ferr[j] = 0.; |
| 7576 |
berr[j] = 0.; |
| 7577 |
/* L10: */ |
| 7578 |
} |
| 7579 |
return 0; |
| 7580 |
} |
| 7581 |
|
| 7582 |
/* NZ = maximum number of nonzero elements in each row of A, plus 1 */ |
| 7583 |
|
| 7584 |
nz = *n + 1; |
| 7585 |
eps = dlamch_("Epsilon"); |
| 7586 |
safmin = dlamch_("Safe minimum"); |
| 7587 |
safe1 = nz * safmin; |
| 7588 |
safe2 = safe1 / eps; |
| 7589 |
|
| 7590 |
/* Do for each right hand side */ |
| 7591 |
|
| 7592 |
i__1 = *nrhs; |
| 7593 |
for (j = 1; j <= i__1; ++j) { |
| 7594 |
|
| 7595 |
count = 1; |
| 7596 |
lstres = 3.; |
| 7597 |
L20: |
| 7598 |
|
| 7599 |
/* Loop until stopping criterion is satisfied. */ |
| 7600 |
|
| 7601 |
/* Compute residual R = B - A * X */ |
| 7602 |
|
| 7603 |
dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1); |
| 7604 |
dspmv_(uplo, n, &c_b12, &ap[1], &x[j * x_dim1 + 1], &c__1, &c_b14, & |
| 7605 |
work[*n + 1], &c__1); |
| 7606 |
|
| 7607 |
/* Compute componentwise relative backward error from formula */ |
| 7608 |
|
| 7609 |
/* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */ |
| 7610 |
|
| 7611 |
/* where abs(Z) is the componentwise absolute value of the matrix */ |
| 7612 |
/* or vector Z. If the i-th component of the denominator is less */ |
| 7613 |
/* than SAFE2, then SAFE1 is added to the i-th components of the */ |
| 7614 |
/* numerator and denominator before dividing. */ |
| 7615 |
|
| 7616 |
i__2 = *n; |
| 7617 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 7618 |
work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1)); |
| 7619 |
/* L30: */ |
| 7620 |
} |
| 7621 |
|
| 7622 |
/* Compute abs(A)*abs(X) + abs(B). */ |
| 7623 |
|
| 7624 |
kk = 1; |
| 7625 |
if (upper) { |
| 7626 |
i__2 = *n; |
| 7627 |
for (k = 1; k <= i__2; ++k) { |
| 7628 |
s = 0.; |
| 7629 |
xk = (d__1 = x[k + j * x_dim1], abs(d__1)); |
| 7630 |
ik = kk; |
| 7631 |
i__3 = k - 1; |
| 7632 |
for (i__ = 1; i__ <= i__3; ++i__) { |
| 7633 |
work[i__] += (d__1 = ap[ik], abs(d__1)) * xk; |
| 7634 |
s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j * |
| 7635 |
x_dim1], abs(d__2)); |
| 7636 |
++ik; |
| 7637 |
/* L40: */ |
| 7638 |
} |
| 7639 |
work[k] = work[k] + (d__1 = ap[kk + k - 1], abs(d__1)) * xk + |
| 7640 |
s; |
| 7641 |
kk += k; |
| 7642 |
/* L50: */ |
| 7643 |
} |
| 7644 |
} else { |
| 7645 |
i__2 = *n; |
| 7646 |
for (k = 1; k <= i__2; ++k) { |
| 7647 |
s = 0.; |
| 7648 |
xk = (d__1 = x[k + j * x_dim1], abs(d__1)); |
| 7649 |
work[k] += (d__1 = ap[kk], abs(d__1)) * xk; |
| 7650 |
ik = kk + 1; |
| 7651 |
i__3 = *n; |
| 7652 |
for (i__ = k + 1; i__ <= i__3; ++i__) { |
| 7653 |
work[i__] += (d__1 = ap[ik], abs(d__1)) * xk; |
| 7654 |
s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j * |
| 7655 |
x_dim1], abs(d__2)); |
| 7656 |
++ik; |
| 7657 |
/* L60: */ |
| 7658 |
} |
| 7659 |
work[k] += s; |
| 7660 |
kk += *n - k + 1; |
| 7661 |
/* L70: */ |
| 7662 |
} |
| 7663 |
} |
| 7664 |
s = 0.; |
| 7665 |
i__2 = *n; |
| 7666 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 7667 |
if (work[i__] > safe2) { |
| 7668 |
/* Computing MAX */ |
| 7669 |
d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[ |
| 7670 |
i__]; |
| 7671 |
s = std::max(d__2,d__3); |
| 7672 |
} else { |
| 7673 |
/* Computing MAX */ |
| 7674 |
d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1) |
| 7675 |
/ (work[i__] + safe1); |
| 7676 |
s = std::max(d__2,d__3); |
| 7677 |
} |
| 7678 |
/* L80: */ |
| 7679 |
} |
| 7680 |
berr[j] = s; |
| 7681 |
|
| 7682 |
/* Test stopping criterion. Continue iterating if */ |
| 7683 |
/* 1) The residual BERR(J) is larger than machine epsilon, and */ |
| 7684 |
/* 2) BERR(J) decreased by at least a factor of 2 during the */ |
| 7685 |
/* last iteration, and */ |
| 7686 |
/* 3) At most ITMAX iterations tried. */ |
| 7687 |
|
| 7688 |
if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) { |
| 7689 |
|
| 7690 |
/* Update solution and try again. */ |
| 7691 |
|
| 7692 |
dsptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[*n + 1], n, info); |
| 7693 |
daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1) |
| 7694 |
; |
| 7695 |
lstres = berr[j]; |
| 7696 |
++count; |
| 7697 |
goto L20; |
| 7698 |
} |
| 7699 |
|
| 7700 |
/* Bound error from formula */ |
| 7701 |
|
| 7702 |
/* norm(X - XTRUE) / norm(X) .le. FERR = */ |
| 7703 |
/* norm( abs(inv(A))* */ |
| 7704 |
/* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */ |
| 7705 |
|
| 7706 |
/* where */ |
| 7707 |
/* norm(Z) is the magnitude of the largest component of Z */ |
| 7708 |
/* inv(A) is the inverse of A */ |
| 7709 |
/* abs(Z) is the componentwise absolute value of the matrix or */ |
| 7710 |
/* vector Z */ |
| 7711 |
/* NZ is the maximum number of nonzeros in any row of A, plus 1 */ |
| 7712 |
/* EPS is machine epsilon */ |
| 7713 |
|
| 7714 |
/* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */ |
| 7715 |
/* is incremented by SAFE1 if the i-th component of */ |
| 7716 |
/* abs(A)*abs(X) + abs(B) is less than SAFE2. */ |
| 7717 |
|
| 7718 |
/* Use DLACN2 to estimate the infinity-norm of the matrix */ |
| 7719 |
/* inv(A) * diag(W), */ |
| 7720 |
/* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */ |
| 7721 |
|
| 7722 |
i__2 = *n; |
| 7723 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 7724 |
if (work[i__] > safe2) { |
| 7725 |
work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * |
| 7726 |
work[i__]; |
| 7727 |
} else { |
| 7728 |
work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * |
| 7729 |
work[i__] + safe1; |
| 7730 |
} |
| 7731 |
/* L90: */ |
| 7732 |
} |
| 7733 |
|
| 7734 |
kase = 0; |
| 7735 |
L100: |
| 7736 |
dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], & |
| 7737 |
kase, isave); |
| 7738 |
if (kase != 0) { |
| 7739 |
if (kase == 1) { |
| 7740 |
|
| 7741 |
/* Multiply by diag(W)*inv(A'). */ |
| 7742 |
|
| 7743 |
dsptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[*n + 1], n, |
| 7744 |
info); |
| 7745 |
i__2 = *n; |
| 7746 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 7747 |
work[*n + i__] = work[i__] * work[*n + i__]; |
| 7748 |
/* L110: */ |
| 7749 |
} |
| 7750 |
} else if (kase == 2) { |
| 7751 |
|
| 7752 |
/* Multiply by inv(A)*diag(W). */ |
| 7753 |
|
| 7754 |
i__2 = *n; |
| 7755 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 7756 |
work[*n + i__] = work[i__] * work[*n + i__]; |
| 7757 |
/* L120: */ |
| 7758 |
} |
| 7759 |
dsptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[*n + 1], n, |
| 7760 |
info); |
| 7761 |
} |
| 7762 |
goto L100; |
| 7763 |
} |
| 7764 |
|
| 7765 |
/* Normalize error. */ |
| 7766 |
|
| 7767 |
lstres = 0.; |
| 7768 |
i__2 = *n; |
| 7769 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 7770 |
/* Computing MAX */ |
| 7771 |
d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1)); |
| 7772 |
lstres = std::max(d__2,d__3); |
| 7773 |
/* L130: */ |
| 7774 |
} |
| 7775 |
if (lstres != 0.) { |
| 7776 |
ferr[j] /= lstres; |
| 7777 |
} |
| 7778 |
|
| 7779 |
/* L140: */ |
| 7780 |
} |
| 7781 |
|
| 7782 |
return 0; |
| 7783 |
|
| 7784 |
/* End of DSPRFS */ |
| 7785 |
|
| 7786 |
} /* dsprfs_ */ |
| 7787 |
|
| 7788 |
/* Subroutine */ int dspsv_(const char *uplo, integer *n, integer *nrhs, double |
| 7789 |
*ap, integer *ipiv, double *b, integer *ldb, integer *info) |
| 7790 |
{ |
| 7791 |
/* System generated locals */ |
| 7792 |
integer b_dim1, b_offset, i__1; |
| 7793 |
|
| 7794 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 7795 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 7796 |
/* November 2006 */ |
| 7797 |
|
| 7798 |
/* .. Scalar Arguments .. */ |
| 7799 |
/* .. */ |
| 7800 |
/* .. Array Arguments .. */ |
| 7801 |
/* .. */ |
| 7802 |
|
| 7803 |
/* Purpose */ |
| 7804 |
/* ======= */ |
| 7805 |
|
| 7806 |
/* DSPSV computes the solution to a real system of linear equations */ |
| 7807 |
/* A * X = B, */ |
| 7808 |
/* where A is an N-by-N symmetric matrix stored in packed format and X */ |
| 7809 |
/* and B are N-by-NRHS matrices. */ |
| 7810 |
|
| 7811 |
/* The diagonal pivoting method is used to factor A as */ |
| 7812 |
/* A = U * D * U**T, if UPLO = 'U', or */ |
| 7813 |
/* A = L * D * L**T, if UPLO = 'L', */ |
| 7814 |
/* where U (or L) is a product of permutation and unit upper (lower) */ |
| 7815 |
/* triangular matrices, D is symmetric and block diagonal with 1-by-1 */ |
| 7816 |
/* and 2-by-2 diagonal blocks. The factored form of A is then used to */ |
| 7817 |
/* solve the system of equations A * X = B. */ |
| 7818 |
|
| 7819 |
/* Arguments */ |
| 7820 |
/* ========= */ |
| 7821 |
|
| 7822 |
/* UPLO (input) CHARACTER*1 */ |
| 7823 |
/* = 'U': Upper triangle of A is stored; */ |
| 7824 |
/* = 'L': Lower triangle of A is stored. */ |
| 7825 |
|
| 7826 |
/* N (input) INTEGER */ |
| 7827 |
/* The number of linear equations, i.e., the order of the */ |
| 7828 |
/* matrix A. N >= 0. */ |
| 7829 |
|
| 7830 |
/* NRHS (input) INTEGER */ |
| 7831 |
/* The number of right hand sides, i.e., the number of columns */ |
| 7832 |
/* of the matrix B. NRHS >= 0. */ |
| 7833 |
|
| 7834 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 7835 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 7836 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 7837 |
/* is stored in the array AP as follows: */ |
| 7838 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 7839 |
/* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */ |
| 7840 |
/* See below for further details. */ |
| 7841 |
|
| 7842 |
/* On exit, the block diagonal matrix D and the multipliers used */ |
| 7843 |
/* to obtain the factor U or L from the factorization */ |
| 7844 |
/* A = U*D*U**T or A = L*D*L**T as computed by DSPTRF, stored as */ |
| 7845 |
/* a packed triangular matrix in the same storage format as A. */ |
| 7846 |
|
| 7847 |
/* IPIV (output) INTEGER array, dimension (N) */ |
| 7848 |
/* Details of the interchanges and the block structure of D, as */ |
| 7849 |
/* determined by DSPTRF. If IPIV(k) > 0, then rows and columns */ |
| 7850 |
/* k and IPIV(k) were interchanged, and D(k,k) is a 1-by-1 */ |
| 7851 |
/* diagonal block. If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, */ |
| 7852 |
/* then rows and columns k-1 and -IPIV(k) were interchanged and */ |
| 7853 |
/* D(k-1:k,k-1:k) is a 2-by-2 diagonal block. If UPLO = 'L' and */ |
| 7854 |
/* IPIV(k) = IPIV(k+1) < 0, then rows and columns k+1 and */ |
| 7855 |
/* -IPIV(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2 */ |
| 7856 |
/* diagonal block. */ |
| 7857 |
|
| 7858 |
/* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 7859 |
/* On entry, the N-by-NRHS right hand side matrix B. */ |
| 7860 |
/* On exit, if INFO = 0, the N-by-NRHS solution matrix X. */ |
| 7861 |
|
| 7862 |
/* LDB (input) INTEGER */ |
| 7863 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 7864 |
|
| 7865 |
/* INFO (output) INTEGER */ |
| 7866 |
/* = 0: successful exit */ |
| 7867 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 7868 |
/* > 0: if INFO = i, D(i,i) is exactly zero. The factorization */ |
| 7869 |
/* has been completed, but the block diagonal matrix D is */ |
| 7870 |
/* exactly singular, so the solution could not be */ |
| 7871 |
/* computed. */ |
| 7872 |
|
| 7873 |
/* Further Details */ |
| 7874 |
/* =============== */ |
| 7875 |
|
| 7876 |
/* The packed storage scheme is illustrated by the following example */ |
| 7877 |
/* when N = 4, UPLO = 'U': */ |
| 7878 |
|
| 7879 |
/* Two-dimensional storage of the symmetric matrix A: */ |
| 7880 |
|
| 7881 |
/* a11 a12 a13 a14 */ |
| 7882 |
/* a22 a23 a24 */ |
| 7883 |
/* a33 a34 (aij = aji) */ |
| 7884 |
/* a44 */ |
| 7885 |
|
| 7886 |
/* Packed storage of the upper triangle of A: */ |
| 7887 |
|
| 7888 |
/* AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] */ |
| 7889 |
|
| 7890 |
/* ===================================================================== */ |
| 7891 |
|
| 7892 |
/* .. External Functions .. */ |
| 7893 |
/* .. */ |
| 7894 |
/* .. External Subroutines .. */ |
| 7895 |
/* .. */ |
| 7896 |
/* .. Intrinsic Functions .. */ |
| 7897 |
/* .. */ |
| 7898 |
/* .. Executable Statements .. */ |
| 7899 |
|
| 7900 |
/* Test the input parameters. */ |
| 7901 |
|
| 7902 |
/* Parameter adjustments */ |
| 7903 |
--ap; |
| 7904 |
--ipiv; |
| 7905 |
b_dim1 = *ldb; |
| 7906 |
b_offset = 1 + b_dim1; |
| 7907 |
b -= b_offset; |
| 7908 |
|
| 7909 |
/* Function Body */ |
| 7910 |
*info = 0; |
| 7911 |
if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { |
| 7912 |
*info = -1; |
| 7913 |
} else if (*n < 0) { |
| 7914 |
*info = -2; |
| 7915 |
} else if (*nrhs < 0) { |
| 7916 |
*info = -3; |
| 7917 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 7918 |
*info = -7; |
| 7919 |
} |
| 7920 |
if (*info != 0) { |
| 7921 |
i__1 = -(*info); |
| 7922 |
xerbla_("DSPSV ", &i__1); |
| 7923 |
return 0; |
| 7924 |
} |
| 7925 |
|
| 7926 |
/* Compute the factorization A = U*D*U' or A = L*D*L'. */ |
| 7927 |
|
| 7928 |
dsptrf_(uplo, n, &ap[1], &ipiv[1], info); |
| 7929 |
if (*info == 0) { |
| 7930 |
|
| 7931 |
/* Solve the system A*X = B, overwriting B with X. */ |
| 7932 |
|
| 7933 |
dsptrs_(uplo, n, nrhs, &ap[1], &ipiv[1], &b[b_offset], ldb, info); |
| 7934 |
|
| 7935 |
} |
| 7936 |
return 0; |
| 7937 |
|
| 7938 |
/* End of DSPSV */ |
| 7939 |
|
| 7940 |
} /* dspsv_ */ |
| 7941 |
|
| 7942 |
/* Subroutine */ int dspsvx_(const char *fact, const char *uplo, integer *n, integer * |
| 7943 |
nrhs, double *ap, double *afp, integer *ipiv, double *b, |
| 7944 |
integer *ldb, double *x, integer *ldx, double *rcond, |
| 7945 |
double *ferr, double *berr, double *work, integer *iwork, |
| 7946 |
integer *info) |
| 7947 |
{ |
| 7948 |
/* Table of constant values */ |
| 7949 |
static integer c__1 = 1; |
| 7950 |
|
| 7951 |
/* System generated locals */ |
| 7952 |
integer b_dim1, b_offset, x_dim1, x_offset, i__1; |
| 7953 |
|
| 7954 |
/* Local variables */ |
| 7955 |
double anorm; |
| 7956 |
bool nofact; |
| 7957 |
|
| 7958 |
|
| 7959 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 7960 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 7961 |
/* November 2006 */ |
| 7962 |
|
| 7963 |
/* .. Scalar Arguments .. */ |
| 7964 |
/* .. */ |
| 7965 |
/* .. Array Arguments .. */ |
| 7966 |
/* .. */ |
| 7967 |
|
| 7968 |
/* Purpose */ |
| 7969 |
/* ======= */ |
| 7970 |
|
| 7971 |
/* DSPSVX uses the diagonal pivoting factorization A = U*D*U**T or */ |
| 7972 |
/* A = L*D*L**T to compute the solution to a real system of linear */ |
| 7973 |
/* equations A * X = B, where A is an N-by-N symmetric matrix stored */ |
| 7974 |
/* in packed format and X and B are N-by-NRHS matrices. */ |
| 7975 |
|
| 7976 |
/* Error bounds on the solution and a condition estimate are also */ |
| 7977 |
/* provided. */ |
| 7978 |
|
| 7979 |
/* Description */ |
| 7980 |
/* =========== */ |
| 7981 |
|
| 7982 |
/* The following steps are performed: */ |
| 7983 |
|
| 7984 |
/* 1. If FACT = 'N', the diagonal pivoting method is used to factor A as */ |
| 7985 |
/* A = U * D * U**T, if UPLO = 'U', or */ |
| 7986 |
/* A = L * D * L**T, if UPLO = 'L', */ |
| 7987 |
/* where U (or L) is a product of permutation and unit upper (lower) */ |
| 7988 |
/* triangular matrices and D is symmetric and block diagonal with */ |
| 7989 |
/* 1-by-1 and 2-by-2 diagonal blocks. */ |
| 7990 |
|
| 7991 |
/* 2. If some D(i,i)=0, so that D is exactly singular, then the routine */ |
| 7992 |
/* returns with INFO = i. Otherwise, the factored form of A is used */ |
| 7993 |
/* to estimate the condition number of the matrix A. If the */ |
| 7994 |
/* reciprocal of the condition number is less than machine precision, */ |
| 7995 |
/* INFO = N+1 is returned as a warning, but the routine still goes on */ |
| 7996 |
/* to solve for X and compute error bounds as described below. */ |
| 7997 |
|
| 7998 |
/* 3. The system of equations is solved for X using the factored form */ |
| 7999 |
/* of A. */ |
| 8000 |
|
| 8001 |
/* 4. Iterative refinement is applied to improve the computed solution */ |
| 8002 |
/* matrix and calculate error bounds and backward error estimates */ |
| 8003 |
/* for it. */ |
| 8004 |
|
| 8005 |
/* Arguments */ |
| 8006 |
/* ========= */ |
| 8007 |
|
| 8008 |
/* FACT (input) CHARACTER*1 */ |
| 8009 |
/* Specifies whether or not the factored form of A has been */ |
| 8010 |
/* supplied on entry. */ |
| 8011 |
/* = 'F': On entry, AFP and IPIV contain the factored form of */ |
| 8012 |
/* A. AP, AFP and IPIV will not be modified. */ |
| 8013 |
/* = 'N': The matrix A will be copied to AFP and factored. */ |
| 8014 |
|
| 8015 |
/* UPLO (input) CHARACTER*1 */ |
| 8016 |
/* = 'U': Upper triangle of A is stored; */ |
| 8017 |
/* = 'L': Lower triangle of A is stored. */ |
| 8018 |
|
| 8019 |
/* N (input) INTEGER */ |
| 8020 |
/* The number of linear equations, i.e., the order of the */ |
| 8021 |
/* matrix A. N >= 0. */ |
| 8022 |
|
| 8023 |
/* NRHS (input) INTEGER */ |
| 8024 |
/* The number of right hand sides, i.e., the number of columns */ |
| 8025 |
/* of the matrices B and X. NRHS >= 0. */ |
| 8026 |
|
| 8027 |
/* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 8028 |
/* The upper or lower triangle of the symmetric matrix A, packed */ |
| 8029 |
/* columnwise in a linear array. The j-th column of A is stored */ |
| 8030 |
/* in the array AP as follows: */ |
| 8031 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 8032 |
/* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ |
| 8033 |
/* See below for further details. */ |
| 8034 |
|
| 8035 |
/* AFP (input or output) DOUBLE PRECISION array, dimension */ |
| 8036 |
/* (N*(N+1)/2) */ |
| 8037 |
/* If FACT = 'F', then AFP is an input argument and on entry */ |
| 8038 |
/* contains the block diagonal matrix D and the multipliers used */ |
| 8039 |
/* to obtain the factor U or L from the factorization */ |
| 8040 |
/* A = U*D*U**T or A = L*D*L**T as computed by DSPTRF, stored as */ |
| 8041 |
/* a packed triangular matrix in the same storage format as A. */ |
| 8042 |
|
| 8043 |
/* If FACT = 'N', then AFP is an output argument and on exit */ |
| 8044 |
/* contains the block diagonal matrix D and the multipliers used */ |
| 8045 |
/* to obtain the factor U or L from the factorization */ |
| 8046 |
/* A = U*D*U**T or A = L*D*L**T as computed by DSPTRF, stored as */ |
| 8047 |
/* a packed triangular matrix in the same storage format as A. */ |
| 8048 |
|
| 8049 |
/* IPIV (input or output) INTEGER array, dimension (N) */ |
| 8050 |
/* If FACT = 'F', then IPIV is an input argument and on entry */ |
| 8051 |
/* contains details of the interchanges and the block structure */ |
| 8052 |
/* of D, as determined by DSPTRF. */ |
| 8053 |
/* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */ |
| 8054 |
/* interchanged and D(k,k) is a 1-by-1 diagonal block. */ |
| 8055 |
/* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */ |
| 8056 |
/* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */ |
| 8057 |
/* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */ |
| 8058 |
/* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */ |
| 8059 |
/* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */ |
| 8060 |
|
| 8061 |
/* If FACT = 'N', then IPIV is an output argument and on exit */ |
| 8062 |
/* contains details of the interchanges and the block structure */ |
| 8063 |
/* of D, as determined by DSPTRF. */ |
| 8064 |
|
| 8065 |
/* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 8066 |
/* The N-by-NRHS right hand side matrix B. */ |
| 8067 |
|
| 8068 |
/* LDB (input) INTEGER */ |
| 8069 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 8070 |
|
| 8071 |
/* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */ |
| 8072 |
/* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X. */ |
| 8073 |
|
| 8074 |
/* LDX (input) INTEGER */ |
| 8075 |
/* The leading dimension of the array X. LDX >= max(1,N). */ |
| 8076 |
|
| 8077 |
/* RCOND (output) DOUBLE PRECISION */ |
| 8078 |
/* The estimate of the reciprocal condition number of the matrix */ |
| 8079 |
/* A. If RCOND is less than the machine precision (in */ |
| 8080 |
/* particular, if RCOND = 0), the matrix is singular to working */ |
| 8081 |
/* precision. This condition is indicated by a return code of */ |
| 8082 |
/* INFO > 0. */ |
| 8083 |
|
| 8084 |
/* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 8085 |
/* The estimated forward error bound for each solution vector */ |
| 8086 |
/* X(j) (the j-th column of the solution matrix X). */ |
| 8087 |
/* If XTRUE is the true solution corresponding to X(j), FERR(j) */ |
| 8088 |
/* is an estimated upper bound for the magnitude of the largest */ |
| 8089 |
/* element in (X(j) - XTRUE) divided by the magnitude of the */ |
| 8090 |
/* largest element in X(j). The estimate is as reliable as */ |
| 8091 |
/* the estimate for RCOND, and is almost always a slight */ |
| 8092 |
/* overestimate of the true error. */ |
| 8093 |
|
| 8094 |
/* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 8095 |
/* The componentwise relative backward error of each solution */ |
| 8096 |
/* vector X(j) (i.e., the smallest relative change in */ |
| 8097 |
/* any element of A or B that makes X(j) an exact solution). */ |
| 8098 |
|
| 8099 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */ |
| 8100 |
|
| 8101 |
/* IWORK (workspace) INTEGER array, dimension (N) */ |
| 8102 |
|
| 8103 |
/* INFO (output) INTEGER */ |
| 8104 |
/* = 0: successful exit */ |
| 8105 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 8106 |
/* > 0: if INFO = i, and i is */ |
| 8107 |
/* <= N: D(i,i) is exactly zero. The factorization */ |
| 8108 |
/* has been completed but the factor D is exactly */ |
| 8109 |
/* singular, so the solution and error bounds could */ |
| 8110 |
/* not be computed. RCOND = 0 is returned. */ |
| 8111 |
/* = N+1: D is nonsingular, but RCOND is less than machine */ |
| 8112 |
/* precision, meaning that the matrix is singular */ |
| 8113 |
/* to working precision. Nevertheless, the */ |
| 8114 |
/* solution and error bounds are computed because */ |
| 8115 |
/* there are a number of situations where the */ |
| 8116 |
/* computed solution can be more accurate than the */ |
| 8117 |
/* value of RCOND would suggest. */ |
| 8118 |
|
| 8119 |
/* Further Details */ |
| 8120 |
/* =============== */ |
| 8121 |
|
| 8122 |
/* The packed storage scheme is illustrated by the following example */ |
| 8123 |
/* when N = 4, UPLO = 'U': */ |
| 8124 |
|
| 8125 |
/* Two-dimensional storage of the symmetric matrix A: */ |
| 8126 |
|
| 8127 |
/* a11 a12 a13 a14 */ |
| 8128 |
/* a22 a23 a24 */ |
| 8129 |
/* a33 a34 (aij = aji) */ |
| 8130 |
/* a44 */ |
| 8131 |
|
| 8132 |
/* Packed storage of the upper triangle of A: */ |
| 8133 |
|
| 8134 |
/* AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] */ |
| 8135 |
|
| 8136 |
/* ===================================================================== */ |
| 8137 |
|
| 8138 |
/* .. Parameters .. */ |
| 8139 |
/* .. */ |
| 8140 |
/* .. Local Scalars .. */ |
| 8141 |
/* .. */ |
| 8142 |
/* .. External Functions .. */ |
| 8143 |
/* .. */ |
| 8144 |
/* .. External Subroutines .. */ |
| 8145 |
/* .. */ |
| 8146 |
/* .. Intrinsic Functions .. */ |
| 8147 |
/* .. */ |
| 8148 |
/* .. Executable Statements .. */ |
| 8149 |
|
| 8150 |
/* Test the input parameters. */ |
| 8151 |
|
| 8152 |
/* Parameter adjustments */ |
| 8153 |
--ap; |
| 8154 |
--afp; |
| 8155 |
--ipiv; |
| 8156 |
b_dim1 = *ldb; |
| 8157 |
b_offset = 1 + b_dim1; |
| 8158 |
b -= b_offset; |
| 8159 |
x_dim1 = *ldx; |
| 8160 |
x_offset = 1 + x_dim1; |
| 8161 |
x -= x_offset; |
| 8162 |
--ferr; |
| 8163 |
--berr; |
| 8164 |
--work; |
| 8165 |
--iwork; |
| 8166 |
|
| 8167 |
/* Function Body */ |
| 8168 |
*info = 0; |
| 8169 |
nofact = lsame_(fact, "N"); |
| 8170 |
if (! nofact && ! lsame_(fact, "F")) { |
| 8171 |
*info = -1; |
| 8172 |
} else if (! lsame_(uplo, "U") && ! lsame_(uplo, |
| 8173 |
"L")) { |
| 8174 |
*info = -2; |
| 8175 |
} else if (*n < 0) { |
| 8176 |
*info = -3; |
| 8177 |
} else if (*nrhs < 0) { |
| 8178 |
*info = -4; |
| 8179 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 8180 |
*info = -9; |
| 8181 |
} else if (*ldx < std::max(1_integer,*n)) { |
| 8182 |
*info = -11; |
| 8183 |
} |
| 8184 |
if (*info != 0) { |
| 8185 |
i__1 = -(*info); |
| 8186 |
xerbla_("DSPSVX", &i__1); |
| 8187 |
return 0; |
| 8188 |
} |
| 8189 |
|
| 8190 |
if (nofact) { |
| 8191 |
|
| 8192 |
/* Compute the factorization A = U*D*U' or A = L*D*L'. */ |
| 8193 |
|
| 8194 |
i__1 = *n * (*n + 1) / 2; |
| 8195 |
dcopy_(&i__1, &ap[1], &c__1, &afp[1], &c__1); |
| 8196 |
dsptrf_(uplo, n, &afp[1], &ipiv[1], info); |
| 8197 |
|
| 8198 |
/* Return if INFO is non-zero. */ |
| 8199 |
|
| 8200 |
if (*info > 0) { |
| 8201 |
*rcond = 0.; |
| 8202 |
return 0; |
| 8203 |
} |
| 8204 |
} |
| 8205 |
|
| 8206 |
/* Compute the norm of the matrix A. */ |
| 8207 |
|
| 8208 |
anorm = dlansp_("I", uplo, n, &ap[1], &work[1]); |
| 8209 |
|
| 8210 |
/* Compute the reciprocal of the condition number of A. */ |
| 8211 |
|
| 8212 |
dspcon_(uplo, n, &afp[1], &ipiv[1], &anorm, rcond, &work[1], &iwork[1], |
| 8213 |
info); |
| 8214 |
|
| 8215 |
/* Compute the solution vectors X. */ |
| 8216 |
|
| 8217 |
dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx); |
| 8218 |
dsptrs_(uplo, n, nrhs, &afp[1], &ipiv[1], &x[x_offset], ldx, info); |
| 8219 |
|
| 8220 |
/* Use iterative refinement to improve the computed solutions and */ |
| 8221 |
/* compute error bounds and backward error estimates for them. */ |
| 8222 |
|
| 8223 |
dsprfs_(uplo, n, nrhs, &ap[1], &afp[1], &ipiv[1], &b[b_offset], ldb, &x[ |
| 8224 |
x_offset], ldx, &ferr[1], &berr[1], &work[1], &iwork[1], info); |
| 8225 |
|
| 8226 |
/* Set INFO = N+1 if the matrix is singular to working precision. */ |
| 8227 |
|
| 8228 |
if (*rcond < dlamch_("Epsilon")) { |
| 8229 |
*info = *n + 1; |
| 8230 |
} |
| 8231 |
|
| 8232 |
return 0; |
| 8233 |
|
| 8234 |
/* End of DSPSVX */ |
| 8235 |
|
| 8236 |
} /* dspsvx_ */ |
| 8237 |
|
| 8238 |
/* Subroutine */ int dsptrd_(const char *uplo, integer *n, double *ap, |
| 8239 |
double *d__, double *e, double *tau, integer *info) |
| 8240 |
{ |
| 8241 |
/* Table of constant values */ |
| 8242 |
static integer c__1 = 1; |
| 8243 |
static double c_b8 = 0.; |
| 8244 |
static double c_b14 = -1.; |
| 8245 |
|
| 8246 |
/* System generated locals */ |
| 8247 |
integer i__1, i__2; |
| 8248 |
|
| 8249 |
/* Local variables */ |
| 8250 |
integer i__, i1, ii, i1i1; |
| 8251 |
double taui; |
| 8252 |
double alpha; |
| 8253 |
bool upper; |
| 8254 |
|
| 8255 |
|
| 8256 |
/* -- LAPACK routine (version 3.1) -- */ |
| 8257 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 8258 |
/* November 2006 */ |
| 8259 |
|
| 8260 |
/* .. Scalar Arguments .. */ |
| 8261 |
/* .. */ |
| 8262 |
/* .. Array Arguments .. */ |
| 8263 |
/* .. */ |
| 8264 |
|
| 8265 |
/* Purpose */ |
| 8266 |
/* ======= */ |
| 8267 |
|
| 8268 |
/* DSPTRD reduces a real symmetric matrix A stored in packed form to */ |
| 8269 |
/* symmetric tridiagonal form T by an orthogonal similarity */ |
| 8270 |
/* transformation: Q**T * A * Q = T. */ |
| 8271 |
|
| 8272 |
/* Arguments */ |
| 8273 |
/* ========= */ |
| 8274 |
|
| 8275 |
/* UPLO (input) CHARACTER*1 */ |
| 8276 |
/* = 'U': Upper triangle of A is stored; */ |
| 8277 |
/* = 'L': Lower triangle of A is stored. */ |
| 8278 |
|
| 8279 |
/* N (input) INTEGER */ |
| 8280 |
/* The order of the matrix A. N >= 0. */ |
| 8281 |
|
| 8282 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 8283 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 8284 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 8285 |
/* is stored in the array AP as follows: */ |
| 8286 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 8287 |
/* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ |
| 8288 |
/* On exit, if UPLO = 'U', the diagonal and first superdiagonal */ |
| 8289 |
/* of A are overwritten by the corresponding elements of the */ |
| 8290 |
/* tridiagonal matrix T, and the elements above the first */ |
| 8291 |
/* superdiagonal, with the array TAU, represent the orthogonal */ |
| 8292 |
/* matrix Q as a product of elementary reflectors; if UPLO */ |
| 8293 |
/* = 'L', the diagonal and first subdiagonal of A are over- */ |
| 8294 |
/* written by the corresponding elements of the tridiagonal */ |
| 8295 |
/* matrix T, and the elements below the first subdiagonal, with */ |
| 8296 |
/* the array TAU, represent the orthogonal matrix Q as a product */ |
| 8297 |
/* of elementary reflectors. See Further Details. */ |
| 8298 |
|
| 8299 |
/* D (output) DOUBLE PRECISION array, dimension (N) */ |
| 8300 |
/* The diagonal elements of the tridiagonal matrix T: */ |
| 8301 |
/* D(i) = A(i,i). */ |
| 8302 |
|
| 8303 |
/* E (output) DOUBLE PRECISION array, dimension (N-1) */ |
| 8304 |
/* The off-diagonal elements of the tridiagonal matrix T: */ |
| 8305 |
/* E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */ |
| 8306 |
|
| 8307 |
/* TAU (output) DOUBLE PRECISION array, dimension (N-1) */ |
| 8308 |
/* The scalar factors of the elementary reflectors (see Further */ |
| 8309 |
/* Details). */ |
| 8310 |
|
| 8311 |
/* INFO (output) INTEGER */ |
| 8312 |
/* = 0: successful exit */ |
| 8313 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 8314 |
|
| 8315 |
/* Further Details */ |
| 8316 |
/* =============== */ |
| 8317 |
|
| 8318 |
/* If UPLO = 'U', the matrix Q is represented as a product of elementary */ |
| 8319 |
/* reflectors */ |
| 8320 |
|
| 8321 |
/* Q = H(n-1) . . . H(2) H(1). */ |
| 8322 |
|
| 8323 |
/* Each H(i) has the form */ |
| 8324 |
|
| 8325 |
/* H(i) = I - tau * v * v' */ |
| 8326 |
|
| 8327 |
/* where tau is a real scalar, and v is a real vector with */ |
| 8328 |
/* v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in AP, */ |
| 8329 |
/* overwriting A(1:i-1,i+1), and tau is stored in TAU(i). */ |
| 8330 |
|
| 8331 |
/* If UPLO = 'L', the matrix Q is represented as a product of elementary */ |
| 8332 |
/* reflectors */ |
| 8333 |
|
| 8334 |
/* Q = H(1) H(2) . . . H(n-1). */ |
| 8335 |
|
| 8336 |
/* Each H(i) has the form */ |
| 8337 |
|
| 8338 |
/* H(i) = I - tau * v * v' */ |
| 8339 |
|
| 8340 |
/* where tau is a real scalar, and v is a real vector with */ |
| 8341 |
/* v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in AP, */ |
| 8342 |
/* overwriting A(i+2:n,i), and tau is stored in TAU(i). */ |
| 8343 |
|
| 8344 |
/* ===================================================================== */ |
| 8345 |
|
| 8346 |
/* .. Parameters .. */ |
| 8347 |
/* .. */ |
| 8348 |
/* .. Local Scalars .. */ |
| 8349 |
/* .. */ |
| 8350 |
/* .. External Subroutines .. */ |
| 8351 |
/* .. */ |
| 8352 |
/* .. External Functions .. */ |
| 8353 |
/* .. */ |
| 8354 |
/* .. Executable Statements .. */ |
| 8355 |
|
| 8356 |
/* Test the input parameters */ |
| 8357 |
|
| 8358 |
/* Parameter adjustments */ |
| 8359 |
--tau; |
| 8360 |
--e; |
| 8361 |
--d__; |
| 8362 |
--ap; |
| 8363 |
|
| 8364 |
/* Function Body */ |
| 8365 |
*info = 0; |
| 8366 |
upper = lsame_(uplo, "U"); |
| 8367 |
if (! upper && ! lsame_(uplo, "L")) { |
| 8368 |
*info = -1; |
| 8369 |
} else if (*n < 0) { |
| 8370 |
*info = -2; |
| 8371 |
} |
| 8372 |
if (*info != 0) { |
| 8373 |
i__1 = -(*info); |
| 8374 |
xerbla_("DSPTRD", &i__1); |
| 8375 |
return 0; |
| 8376 |
} |
| 8377 |
|
| 8378 |
/* Quick return if possible */ |
| 8379 |
|
| 8380 |
if (*n <= 0) { |
| 8381 |
return 0; |
| 8382 |
} |
| 8383 |
|
| 8384 |
if (upper) { |
| 8385 |
|
| 8386 |
/* Reduce the upper triangle of A. */ |
| 8387 |
/* I1 is the index in AP of A(1,I+1). */ |
| 8388 |
|
| 8389 |
i1 = *n * (*n - 1) / 2 + 1; |
| 8390 |
for (i__ = *n - 1; i__ >= 1; --i__) { |
| 8391 |
|
| 8392 |
/* Generate elementary reflector H(i) = I - tau * v * v' */ |
| 8393 |
/* to annihilate A(1:i-1,i+1) */ |
| 8394 |
|
| 8395 |
dlarfg_(&i__, &ap[i1 + i__ - 1], &ap[i1], &c__1, &taui); |
| 8396 |
e[i__] = ap[i1 + i__ - 1]; |
| 8397 |
|
| 8398 |
if (taui != 0.) { |
| 8399 |
|
| 8400 |
/* Apply H(i) from both sides to A(1:i,1:i) */ |
| 8401 |
|
| 8402 |
ap[i1 + i__ - 1] = 1.; |
| 8403 |
|
| 8404 |
/* Compute y := tau * A * v storing y in TAU(1:i) */ |
| 8405 |
|
| 8406 |
dspmv_(uplo, &i__, &taui, &ap[1], &ap[i1], &c__1, &c_b8, &tau[ |
| 8407 |
1], &c__1); |
| 8408 |
|
| 8409 |
/* Compute w := y - 1/2 * tau * (y'*v) * v */ |
| 8410 |
|
| 8411 |
alpha = taui * -.5 * ddot_(&i__, &tau[1], &c__1, &ap[i1], & |
| 8412 |
c__1); |
| 8413 |
daxpy_(&i__, &alpha, &ap[i1], &c__1, &tau[1], &c__1); |
| 8414 |
|
| 8415 |
/* Apply the transformation as a rank-2 update: */ |
| 8416 |
/* A := A - v * w' - w * v' */ |
| 8417 |
|
| 8418 |
dspr2_(uplo, &i__, &c_b14, &ap[i1], &c__1, &tau[1], &c__1, & |
| 8419 |
ap[1]); |
| 8420 |
|
| 8421 |
ap[i1 + i__ - 1] = e[i__]; |
| 8422 |
} |
| 8423 |
d__[i__ + 1] = ap[i1 + i__]; |
| 8424 |
tau[i__] = taui; |
| 8425 |
i1 -= i__; |
| 8426 |
/* L10: */ |
| 8427 |
} |
| 8428 |
d__[1] = ap[1]; |
| 8429 |
} else { |
| 8430 |
|
| 8431 |
/* Reduce the lower triangle of A. II is the index in AP of */ |
| 8432 |
/* A(i,i) and I1I1 is the index of A(i+1,i+1). */ |
| 8433 |
|
| 8434 |
ii = 1; |
| 8435 |
i__1 = *n - 1; |
| 8436 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 8437 |
i1i1 = ii + *n - i__ + 1; |
| 8438 |
|
| 8439 |
/* Generate elementary reflector H(i) = I - tau * v * v' */ |
| 8440 |
/* to annihilate A(i+2:n,i) */ |
| 8441 |
|
| 8442 |
i__2 = *n - i__; |
| 8443 |
dlarfg_(&i__2, &ap[ii + 1], &ap[ii + 2], &c__1, &taui); |
| 8444 |
e[i__] = ap[ii + 1]; |
| 8445 |
|
| 8446 |
if (taui != 0.) { |
| 8447 |
|
| 8448 |
/* Apply H(i) from both sides to A(i+1:n,i+1:n) */ |
| 8449 |
|
| 8450 |
ap[ii + 1] = 1.; |
| 8451 |
|
| 8452 |
/* Compute y := tau * A * v storing y in TAU(i:n-1) */ |
| 8453 |
|
| 8454 |
i__2 = *n - i__; |
| 8455 |
dspmv_(uplo, &i__2, &taui, &ap[i1i1], &ap[ii + 1], &c__1, & |
| 8456 |
c_b8, &tau[i__], &c__1); |
| 8457 |
|
| 8458 |
/* Compute w := y - 1/2 * tau * (y'*v) * v */ |
| 8459 |
|
| 8460 |
i__2 = *n - i__; |
| 8461 |
alpha = taui * -.5 * ddot_(&i__2, &tau[i__], &c__1, &ap[ii + |
| 8462 |
1], &c__1); |
| 8463 |
i__2 = *n - i__; |
| 8464 |
daxpy_(&i__2, &alpha, &ap[ii + 1], &c__1, &tau[i__], &c__1); |
| 8465 |
|
| 8466 |
/* Apply the transformation as a rank-2 update: */ |
| 8467 |
/* A := A - v * w' - w * v' */ |
| 8468 |
|
| 8469 |
i__2 = *n - i__; |
| 8470 |
dspr2_(uplo, &i__2, &c_b14, &ap[ii + 1], &c__1, &tau[i__], & |
| 8471 |
c__1, &ap[i1i1]); |
| 8472 |
|
| 8473 |
ap[ii + 1] = e[i__]; |
| 8474 |
} |
| 8475 |
d__[i__] = ap[ii]; |
| 8476 |
tau[i__] = taui; |
| 8477 |
ii = i1i1; |
| 8478 |
/* L20: */ |
| 8479 |
} |
| 8480 |
d__[*n] = ap[ii]; |
| 8481 |
} |
| 8482 |
|
| 8483 |
return 0; |
| 8484 |
|
| 8485 |
/* End of DSPTRD */ |
| 8486 |
|
| 8487 |
} /* dsptrd_ */ |
| 8488 |
|
| 8489 |
/* Subroutine */ int dsptrf_(const char *uplo, integer *n, double *ap, integer * |
| 8490 |
ipiv, integer *info) |
| 8491 |
{ |
| 8492 |
/* Table of constant values */ |
| 8493 |
static integer c__1 = 1; |
| 8494 |
|
| 8495 |
/* System generated locals */ |
| 8496 |
integer i__1, i__2; |
| 8497 |
double d__1, d__2, d__3; |
| 8498 |
|
| 8499 |
/* Local variables */ |
| 8500 |
integer i__, j, k; |
| 8501 |
double t, r1, d11, d12, d21, d22; |
| 8502 |
integer kc, kk, kp; |
| 8503 |
double wk; |
| 8504 |
integer kx, knc, kpc, npp; |
| 8505 |
double wkm1, wkp1; |
| 8506 |
integer imax, jmax; |
| 8507 |
double alpha; |
| 8508 |
integer kstep; |
| 8509 |
bool upper; |
| 8510 |
double absakk; |
| 8511 |
double colmax, rowmax; |
| 8512 |
|
| 8513 |
|
| 8514 |
/* -- LAPACK routine (version 3.1) -- */ |
| 8515 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 8516 |
/* November 2006 */ |
| 8517 |
|
| 8518 |
/* .. Scalar Arguments .. */ |
| 8519 |
/* .. */ |
| 8520 |
/* .. Array Arguments .. */ |
| 8521 |
/* .. */ |
| 8522 |
|
| 8523 |
/* Purpose */ |
| 8524 |
/* ======= */ |
| 8525 |
|
| 8526 |
/* DSPTRF computes the factorization of a real symmetric matrix A stored */ |
| 8527 |
/* in packed format using the Bunch-Kaufman diagonal pivoting method: */ |
| 8528 |
|
| 8529 |
/* A = U*D*U**T or A = L*D*L**T */ |
| 8530 |
|
| 8531 |
/* where U (or L) is a product of permutation and unit upper (lower) */ |
| 8532 |
/* triangular matrices, and D is symmetric and block diagonal with */ |
| 8533 |
/* 1-by-1 and 2-by-2 diagonal blocks. */ |
| 8534 |
|
| 8535 |
/* Arguments */ |
| 8536 |
/* ========= */ |
| 8537 |
|
| 8538 |
/* UPLO (input) CHARACTER*1 */ |
| 8539 |
/* = 'U': Upper triangle of A is stored; */ |
| 8540 |
/* = 'L': Lower triangle of A is stored. */ |
| 8541 |
|
| 8542 |
/* N (input) INTEGER */ |
| 8543 |
/* The order of the matrix A. N >= 0. */ |
| 8544 |
|
| 8545 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 8546 |
/* On entry, the upper or lower triangle of the symmetric matrix */ |
| 8547 |
/* A, packed columnwise in a linear array. The j-th column of A */ |
| 8548 |
/* is stored in the array AP as follows: */ |
| 8549 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ |
| 8550 |
/* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */ |
| 8551 |
|
| 8552 |
/* On exit, the block diagonal matrix D and the multipliers used */ |
| 8553 |
/* to obtain the factor U or L, stored as a packed triangular */ |
| 8554 |
/* matrix overwriting A (see below for further details). */ |
| 8555 |
|
| 8556 |
/* IPIV (output) INTEGER array, dimension (N) */ |
| 8557 |
/* Details of the interchanges and the block structure of D. */ |
| 8558 |
/* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */ |
| 8559 |
/* interchanged and D(k,k) is a 1-by-1 diagonal block. */ |
| 8560 |
/* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */ |
| 8561 |
/* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */ |
| 8562 |
/* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */ |
| 8563 |
/* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */ |
| 8564 |
/* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */ |
| 8565 |
|
| 8566 |
/* INFO (output) INTEGER */ |
| 8567 |
/* = 0: successful exit */ |
| 8568 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 8569 |
/* > 0: if INFO = i, D(i,i) is exactly zero. The factorization */ |
| 8570 |
/* has been completed, but the block diagonal matrix D is */ |
| 8571 |
/* exactly singular, and division by zero will occur if it */ |
| 8572 |
/* is used to solve a system of equations. */ |
| 8573 |
|
| 8574 |
/* Further Details */ |
| 8575 |
/* =============== */ |
| 8576 |
|
| 8577 |
/* 5-96 - Based on modifications by J. Lewis, Boeing Computer Services */ |
| 8578 |
/* Company */ |
| 8579 |
|
| 8580 |
/* If UPLO = 'U', then A = U*D*U', where */ |
| 8581 |
/* U = P(n)*U(n)* ... *P(k)U(k)* ..., */ |
| 8582 |
/* i.e., U is a product of terms P(k)*U(k), where k decreases from n to */ |
| 8583 |
/* 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */ |
| 8584 |
/* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */ |
| 8585 |
/* defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */ |
| 8586 |
/* that if the diagonal block D(k) is of order s (s = 1 or 2), then */ |
| 8587 |
|
| 8588 |
/* ( I v 0 ) k-s */ |
| 8589 |
/* U(k) = ( 0 I 0 ) s */ |
| 8590 |
/* ( 0 0 I ) n-k */ |
| 8591 |
/* k-s s n-k */ |
| 8592 |
|
| 8593 |
/* If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */ |
| 8594 |
/* If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */ |
| 8595 |
/* and A(k,k), and v overwrites A(1:k-2,k-1:k). */ |
| 8596 |
|
| 8597 |
/* If UPLO = 'L', then A = L*D*L', where */ |
| 8598 |
/* L = P(1)*L(1)* ... *P(k)*L(k)* ..., */ |
| 8599 |
/* i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */ |
| 8600 |
/* n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */ |
| 8601 |
/* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */ |
| 8602 |
/* defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */ |
| 8603 |
/* that if the diagonal block D(k) is of order s (s = 1 or 2), then */ |
| 8604 |
|
| 8605 |
/* ( I 0 0 ) k-1 */ |
| 8606 |
/* L(k) = ( 0 I 0 ) s */ |
| 8607 |
/* ( 0 v I ) n-k-s+1 */ |
| 8608 |
/* k-1 s n-k-s+1 */ |
| 8609 |
|
| 8610 |
/* If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */ |
| 8611 |
/* If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */ |
| 8612 |
/* and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */ |
| 8613 |
|
| 8614 |
/* ===================================================================== */ |
| 8615 |
|
| 8616 |
/* .. Parameters .. */ |
| 8617 |
/* .. */ |
| 8618 |
/* .. Local Scalars .. */ |
| 8619 |
/* .. */ |
| 8620 |
/* .. External Functions .. */ |
| 8621 |
/* .. */ |
| 8622 |
/* .. External Subroutines .. */ |
| 8623 |
/* .. */ |
| 8624 |
/* .. Intrinsic Functions .. */ |
| 8625 |
/* .. */ |
| 8626 |
/* .. Executable Statements .. */ |
| 8627 |
|
| 8628 |
/* Test the input parameters. */ |
| 8629 |
|
| 8630 |
/* Parameter adjustments */ |
| 8631 |
--ipiv; |
| 8632 |
--ap; |
| 8633 |
|
| 8634 |
/* Function Body */ |
| 8635 |
*info = 0; |
| 8636 |
upper = lsame_(uplo, "U"); |
| 8637 |
if (! upper && ! lsame_(uplo, "L")) { |
| 8638 |
*info = -1; |
| 8639 |
} else if (*n < 0) { |
| 8640 |
*info = -2; |
| 8641 |
} |
| 8642 |
if (*info != 0) { |
| 8643 |
i__1 = -(*info); |
| 8644 |
xerbla_("DSPTRF", &i__1); |
| 8645 |
return 0; |
| 8646 |
} |
| 8647 |
|
| 8648 |
/* Initialize ALPHA for use in choosing pivot block size. */ |
| 8649 |
|
| 8650 |
alpha = (sqrt(17.) + 1.) / 8.; |
| 8651 |
|
| 8652 |
if (upper) { |
| 8653 |
|
| 8654 |
/* Factorize A as U*D*U' using the upper triangle of A */ |
| 8655 |
|
| 8656 |
/* K is the main loop index, decreasing from N to 1 in steps of */ |
| 8657 |
/* 1 or 2 */ |
| 8658 |
|
| 8659 |
k = *n; |
| 8660 |
kc = (*n - 1) * *n / 2 + 1; |
| 8661 |
L10: |
| 8662 |
knc = kc; |
| 8663 |
|
| 8664 |
/* If K < 1, exit from loop */ |
| 8665 |
|
| 8666 |
if (k < 1) { |
| 8667 |
goto L110; |
| 8668 |
} |
| 8669 |
kstep = 1; |
| 8670 |
|
| 8671 |
/* Determine rows and columns to be interchanged and whether */ |
| 8672 |
/* a 1-by-1 or 2-by-2 pivot block will be used */ |
| 8673 |
|
| 8674 |
absakk = (d__1 = ap[kc + k - 1], abs(d__1)); |
| 8675 |
|
| 8676 |
/* IMAX is the row-index of the largest off-diagonal element in */ |
| 8677 |
/* column K, and COLMAX is its absolute value */ |
| 8678 |
|
| 8679 |
if (k > 1) { |
| 8680 |
i__1 = k - 1; |
| 8681 |
imax = idamax_(&i__1, &ap[kc], &c__1); |
| 8682 |
colmax = (d__1 = ap[kc + imax - 1], abs(d__1)); |
| 8683 |
} else { |
| 8684 |
colmax = 0.; |
| 8685 |
} |
| 8686 |
|
| 8687 |
if (std::max(absakk,colmax) == 0.) { |
| 8688 |
|
| 8689 |
/* Column K is zero: set INFO and continue */ |
| 8690 |
|
| 8691 |
if (*info == 0) { |
| 8692 |
*info = k; |
| 8693 |
} |
| 8694 |
kp = k; |
| 8695 |
} else { |
| 8696 |
if (absakk >= alpha * colmax) { |
| 8697 |
|
| 8698 |
/* no interchange, use 1-by-1 pivot block */ |
| 8699 |
|
| 8700 |
kp = k; |
| 8701 |
} else { |
| 8702 |
|
| 8703 |
/* JMAX is the column-index of the largest off-diagonal */ |
| 8704 |
/* element in row IMAX, and ROWMAX is its absolute value */ |
| 8705 |
|
| 8706 |
rowmax = 0.; |
| 8707 |
jmax = imax; |
| 8708 |
kx = imax * (imax + 1) / 2 + imax; |
| 8709 |
i__1 = k; |
| 8710 |
for (j = imax + 1; j <= i__1; ++j) { |
| 8711 |
if ((d__1 = ap[kx], abs(d__1)) > rowmax) { |
| 8712 |
rowmax = (d__1 = ap[kx], abs(d__1)); |
| 8713 |
jmax = j; |
| 8714 |
} |
| 8715 |
kx += j; |
| 8716 |
/* L20: */ |
| 8717 |
} |
| 8718 |
kpc = (imax - 1) * imax / 2 + 1; |
| 8719 |
if (imax > 1) { |
| 8720 |
i__1 = imax - 1; |
| 8721 |
jmax = idamax_(&i__1, &ap[kpc], &c__1); |
| 8722 |
/* Computing MAX */ |
| 8723 |
d__2 = rowmax, d__3 = (d__1 = ap[kpc + jmax - 1], abs( |
| 8724 |
d__1)); |
| 8725 |
rowmax = std::max(d__2,d__3); |
| 8726 |
} |
| 8727 |
|
| 8728 |
if (absakk >= alpha * colmax * (colmax / rowmax)) { |
| 8729 |
|
| 8730 |
/* no interchange, use 1-by-1 pivot block */ |
| 8731 |
|
| 8732 |
kp = k; |
| 8733 |
} else if ((d__1 = ap[kpc + imax - 1], abs(d__1)) >= alpha * |
| 8734 |
rowmax) { |
| 8735 |
|
| 8736 |
/* interchange rows and columns K and IMAX, use 1-by-1 */ |
| 8737 |
/* pivot block */ |
| 8738 |
|
| 8739 |
kp = imax; |
| 8740 |
} else { |
| 8741 |
|
| 8742 |
/* interchange rows and columns K-1 and IMAX, use 2-by-2 */ |
| 8743 |
/* pivot block */ |
| 8744 |
|
| 8745 |
kp = imax; |
| 8746 |
kstep = 2; |
| 8747 |
} |
| 8748 |
} |
| 8749 |
|
| 8750 |
kk = k - kstep + 1; |
| 8751 |
if (kstep == 2) { |
| 8752 |
knc = knc - k + 1; |
| 8753 |
} |
| 8754 |
if (kp != kk) { |
| 8755 |
|
| 8756 |
/* Interchange rows and columns KK and KP in the leading */ |
| 8757 |
/* submatrix A(1:k,1:k) */ |
| 8758 |
|
| 8759 |
i__1 = kp - 1; |
| 8760 |
dswap_(&i__1, &ap[knc], &c__1, &ap[kpc], &c__1); |
| 8761 |
kx = kpc + kp - 1; |
| 8762 |
i__1 = kk - 1; |
| 8763 |
for (j = kp + 1; j <= i__1; ++j) { |
| 8764 |
kx = kx + j - 1; |
| 8765 |
t = ap[knc + j - 1]; |
| 8766 |
ap[knc + j - 1] = ap[kx]; |
| 8767 |
ap[kx] = t; |
| 8768 |
/* L30: */ |
| 8769 |
} |
| 8770 |
t = ap[knc + kk - 1]; |
| 8771 |
ap[knc + kk - 1] = ap[kpc + kp - 1]; |
| 8772 |
ap[kpc + kp - 1] = t; |
| 8773 |
if (kstep == 2) { |
| 8774 |
t = ap[kc + k - 2]; |
| 8775 |
ap[kc + k - 2] = ap[kc + kp - 1]; |
| 8776 |
ap[kc + kp - 1] = t; |
| 8777 |
} |
| 8778 |
} |
| 8779 |
|
| 8780 |
/* Update the leading submatrix */ |
| 8781 |
|
| 8782 |
if (kstep == 1) { |
| 8783 |
|
| 8784 |
/* 1-by-1 pivot block D(k): column k now holds */ |
| 8785 |
|
| 8786 |
/* W(k) = U(k)*D(k) */ |
| 8787 |
|
| 8788 |
/* where U(k) is the k-th column of U */ |
| 8789 |
|
| 8790 |
/* Perform a rank-1 update of A(1:k-1,1:k-1) as */ |
| 8791 |
|
| 8792 |
/* A := A - U(k)*D(k)*U(k)' = A - W(k)*1/D(k)*W(k)' */ |
| 8793 |
|
| 8794 |
r1 = 1. / ap[kc + k - 1]; |
| 8795 |
i__1 = k - 1; |
| 8796 |
d__1 = -r1; |
| 8797 |
dspr_(uplo, &i__1, &d__1, &ap[kc], &c__1, &ap[1]); |
| 8798 |
|
| 8799 |
/* Store U(k) in column k */ |
| 8800 |
|
| 8801 |
i__1 = k - 1; |
| 8802 |
dscal_(&i__1, &r1, &ap[kc], &c__1); |
| 8803 |
} else { |
| 8804 |
|
| 8805 |
/* 2-by-2 pivot block D(k): columns k and k-1 now hold */ |
| 8806 |
|
| 8807 |
/* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */ |
| 8808 |
|
| 8809 |
/* where U(k) and U(k-1) are the k-th and (k-1)-th columns */ |
| 8810 |
/* of U */ |
| 8811 |
|
| 8812 |
/* Perform a rank-2 update of A(1:k-2,1:k-2) as */ |
| 8813 |
|
| 8814 |
/* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )' */ |
| 8815 |
/* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )' */ |
| 8816 |
|
| 8817 |
if (k > 2) { |
| 8818 |
|
| 8819 |
d12 = ap[k - 1 + (k - 1) * k / 2]; |
| 8820 |
d22 = ap[k - 1 + (k - 2) * (k - 1) / 2] / d12; |
| 8821 |
d11 = ap[k + (k - 1) * k / 2] / d12; |
| 8822 |
t = 1. / (d11 * d22 - 1.); |
| 8823 |
d12 = t / d12; |
| 8824 |
|
| 8825 |
for (j = k - 2; j >= 1; --j) { |
| 8826 |
wkm1 = d12 * (d11 * ap[j + (k - 2) * (k - 1) / 2] - |
| 8827 |
ap[j + (k - 1) * k / 2]); |
| 8828 |
wk = d12 * (d22 * ap[j + (k - 1) * k / 2] - ap[j + (k |
| 8829 |
- 2) * (k - 1) / 2]); |
| 8830 |
for (i__ = j; i__ >= 1; --i__) { |
| 8831 |
ap[i__ + (j - 1) * j / 2] = ap[i__ + (j - 1) * j / |
| 8832 |
2] - ap[i__ + (k - 1) * k / 2] * wk - ap[ |
| 8833 |
i__ + (k - 2) * (k - 1) / 2] * wkm1; |
| 8834 |
/* L40: */ |
| 8835 |
} |
| 8836 |
ap[j + (k - 1) * k / 2] = wk; |
| 8837 |
ap[j + (k - 2) * (k - 1) / 2] = wkm1; |
| 8838 |
/* L50: */ |
| 8839 |
} |
| 8840 |
|
| 8841 |
} |
| 8842 |
|
| 8843 |
} |
| 8844 |
} |
| 8845 |
|
| 8846 |
/* Store details of the interchanges in IPIV */ |
| 8847 |
|
| 8848 |
if (kstep == 1) { |
| 8849 |
ipiv[k] = kp; |
| 8850 |
} else { |
| 8851 |
ipiv[k] = -kp; |
| 8852 |
ipiv[k - 1] = -kp; |
| 8853 |
} |
| 8854 |
|
| 8855 |
/* Decrease K and return to the start of the main loop */ |
| 8856 |
|
| 8857 |
k -= kstep; |
| 8858 |
kc = knc - k; |
| 8859 |
goto L10; |
| 8860 |
|
| 8861 |
} else { |
| 8862 |
|
| 8863 |
/* Factorize A as L*D*L' using the lower triangle of A */ |
| 8864 |
|
| 8865 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 8866 |
/* 1 or 2 */ |
| 8867 |
|
| 8868 |
k = 1; |
| 8869 |
kc = 1; |
| 8870 |
npp = *n * (*n + 1) / 2; |
| 8871 |
L60: |
| 8872 |
knc = kc; |
| 8873 |
|
| 8874 |
/* If K > N, exit from loop */ |
| 8875 |
|
| 8876 |
if (k > *n) { |
| 8877 |
goto L110; |
| 8878 |
} |
| 8879 |
kstep = 1; |
| 8880 |
|
| 8881 |
/* Determine rows and columns to be interchanged and whether */ |
| 8882 |
/* a 1-by-1 or 2-by-2 pivot block will be used */ |
| 8883 |
|
| 8884 |
absakk = (d__1 = ap[kc], abs(d__1)); |
| 8885 |
|
| 8886 |
/* IMAX is the row-index of the largest off-diagonal element in */ |
| 8887 |
/* column K, and COLMAX is its absolute value */ |
| 8888 |
|
| 8889 |
if (k < *n) { |
| 8890 |
i__1 = *n - k; |
| 8891 |
imax = k + idamax_(&i__1, &ap[kc + 1], &c__1); |
| 8892 |
colmax = (d__1 = ap[kc + imax - k], abs(d__1)); |
| 8893 |
} else { |
| 8894 |
colmax = 0.; |
| 8895 |
} |
| 8896 |
|
| 8897 |
if (std::max(absakk,colmax) == 0.) { |
| 8898 |
|
| 8899 |
/* Column K is zero: set INFO and continue */ |
| 8900 |
|
| 8901 |
if (*info == 0) { |
| 8902 |
*info = k; |
| 8903 |
} |
| 8904 |
kp = k; |
| 8905 |
} else { |
| 8906 |
if (absakk >= alpha * colmax) { |
| 8907 |
|
| 8908 |
/* no interchange, use 1-by-1 pivot block */ |
| 8909 |
|
| 8910 |
kp = k; |
| 8911 |
} else { |
| 8912 |
|
| 8913 |
/* JMAX is the column-index of the largest off-diagonal */ |
| 8914 |
/* element in row IMAX, and ROWMAX is its absolute value */ |
| 8915 |
|
| 8916 |
rowmax = 0.; |
| 8917 |
kx = kc + imax - k; |
| 8918 |
i__1 = imax - 1; |
| 8919 |
for (j = k; j <= i__1; ++j) { |
| 8920 |
if ((d__1 = ap[kx], abs(d__1)) > rowmax) { |
| 8921 |
rowmax = (d__1 = ap[kx], abs(d__1)); |
| 8922 |
jmax = j; |
| 8923 |
} |
| 8924 |
kx = kx + *n - j; |
| 8925 |
/* L70: */ |
| 8926 |
} |
| 8927 |
kpc = npp - (*n - imax + 1) * (*n - imax + 2) / 2 + 1; |
| 8928 |
if (imax < *n) { |
| 8929 |
i__1 = *n - imax; |
| 8930 |
jmax = imax + idamax_(&i__1, &ap[kpc + 1], &c__1); |
| 8931 |
/* Computing MAX */ |
| 8932 |
d__2 = rowmax, d__3 = (d__1 = ap[kpc + jmax - imax], abs( |
| 8933 |
d__1)); |
| 8934 |
rowmax = std::max(d__2,d__3); |
| 8935 |
} |
| 8936 |
|
| 8937 |
if (absakk >= alpha * colmax * (colmax / rowmax)) { |
| 8938 |
|
| 8939 |
/* no interchange, use 1-by-1 pivot block */ |
| 8940 |
|
| 8941 |
kp = k; |
| 8942 |
} else if ((d__1 = ap[kpc], abs(d__1)) >= alpha * rowmax) { |
| 8943 |
|
| 8944 |
/* interchange rows and columns K and IMAX, use 1-by-1 */ |
| 8945 |
/* pivot block */ |
| 8946 |
|
| 8947 |
kp = imax; |
| 8948 |
} else { |
| 8949 |
|
| 8950 |
/* interchange rows and columns K+1 and IMAX, use 2-by-2 */ |
| 8951 |
/* pivot block */ |
| 8952 |
|
| 8953 |
kp = imax; |
| 8954 |
kstep = 2; |
| 8955 |
} |
| 8956 |
} |
| 8957 |
|
| 8958 |
kk = k + kstep - 1; |
| 8959 |
if (kstep == 2) { |
| 8960 |
knc = knc + *n - k + 1; |
| 8961 |
} |
| 8962 |
if (kp != kk) { |
| 8963 |
|
| 8964 |
/* Interchange rows and columns KK and KP in the trailing */ |
| 8965 |
/* submatrix A(k:n,k:n) */ |
| 8966 |
|
| 8967 |
if (kp < *n) { |
| 8968 |
i__1 = *n - kp; |
| 8969 |
dswap_(&i__1, &ap[knc + kp - kk + 1], &c__1, &ap[kpc + 1], |
| 8970 |
&c__1); |
| 8971 |
} |
| 8972 |
kx = knc + kp - kk; |
| 8973 |
i__1 = kp - 1; |
| 8974 |
for (j = kk + 1; j <= i__1; ++j) { |
| 8975 |
kx = kx + *n - j + 1; |
| 8976 |
t = ap[knc + j - kk]; |
| 8977 |
ap[knc + j - kk] = ap[kx]; |
| 8978 |
ap[kx] = t; |
| 8979 |
/* L80: */ |
| 8980 |
} |
| 8981 |
t = ap[knc]; |
| 8982 |
ap[knc] = ap[kpc]; |
| 8983 |
ap[kpc] = t; |
| 8984 |
if (kstep == 2) { |
| 8985 |
t = ap[kc + 1]; |
| 8986 |
ap[kc + 1] = ap[kc + kp - k]; |
| 8987 |
ap[kc + kp - k] = t; |
| 8988 |
} |
| 8989 |
} |
| 8990 |
|
| 8991 |
/* Update the trailing submatrix */ |
| 8992 |
|
| 8993 |
if (kstep == 1) { |
| 8994 |
|
| 8995 |
/* 1-by-1 pivot block D(k): column k now holds */ |
| 8996 |
|
| 8997 |
/* W(k) = L(k)*D(k) */ |
| 8998 |
|
| 8999 |
/* where L(k) is the k-th column of L */ |
| 9000 |
|
| 9001 |
if (k < *n) { |
| 9002 |
|
| 9003 |
/* Perform a rank-1 update of A(k+1:n,k+1:n) as */ |
| 9004 |
|
| 9005 |
/* A := A - L(k)*D(k)*L(k)' = A - W(k)*(1/D(k))*W(k)' */ |
| 9006 |
|
| 9007 |
r1 = 1. / ap[kc]; |
| 9008 |
i__1 = *n - k; |
| 9009 |
d__1 = -r1; |
| 9010 |
dspr_(uplo, &i__1, &d__1, &ap[kc + 1], &c__1, &ap[kc + *n |
| 9011 |
- k + 1]); |
| 9012 |
|
| 9013 |
/* Store L(k) in column K */ |
| 9014 |
|
| 9015 |
i__1 = *n - k; |
| 9016 |
dscal_(&i__1, &r1, &ap[kc + 1], &c__1); |
| 9017 |
} |
| 9018 |
} else { |
| 9019 |
|
| 9020 |
/* 2-by-2 pivot block D(k): columns K and K+1 now hold */ |
| 9021 |
|
| 9022 |
/* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */ |
| 9023 |
|
| 9024 |
/* where L(k) and L(k+1) are the k-th and (k+1)-th columns */ |
| 9025 |
/* of L */ |
| 9026 |
|
| 9027 |
if (k < *n - 1) { |
| 9028 |
|
| 9029 |
/* Perform a rank-2 update of A(k+2:n,k+2:n) as */ |
| 9030 |
|
| 9031 |
/* A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )' */ |
| 9032 |
/* = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )' */ |
| 9033 |
|
| 9034 |
d21 = ap[k + 1 + (k - 1) * ((*n << 1) - k) / 2]; |
| 9035 |
d11 = ap[k + 1 + k * ((*n << 1) - k - 1) / 2] / d21; |
| 9036 |
d22 = ap[k + (k - 1) * ((*n << 1) - k) / 2] / d21; |
| 9037 |
t = 1. / (d11 * d22 - 1.); |
| 9038 |
d21 = t / d21; |
| 9039 |
|
| 9040 |
i__1 = *n; |
| 9041 |
for (j = k + 2; j <= i__1; ++j) { |
| 9042 |
wk = d21 * (d11 * ap[j + (k - 1) * ((*n << 1) - k) / |
| 9043 |
2] - ap[j + k * ((*n << 1) - k - 1) / 2]); |
| 9044 |
wkp1 = d21 * (d22 * ap[j + k * ((*n << 1) - k - 1) / |
| 9045 |
2] - ap[j + (k - 1) * ((*n << 1) - k) / 2]); |
| 9046 |
|
| 9047 |
i__2 = *n; |
| 9048 |
for (i__ = j; i__ <= i__2; ++i__) { |
| 9049 |
ap[i__ + (j - 1) * ((*n << 1) - j) / 2] = ap[i__ |
| 9050 |
+ (j - 1) * ((*n << 1) - j) / 2] - ap[i__ |
| 9051 |
+ (k - 1) * ((*n << 1) - k) / 2] * wk - |
| 9052 |
ap[i__ + k * ((*n << 1) - k - 1) / 2] * |
| 9053 |
wkp1; |
| 9054 |
/* L90: */ |
| 9055 |
} |
| 9056 |
|
| 9057 |
ap[j + (k - 1) * ((*n << 1) - k) / 2] = wk; |
| 9058 |
ap[j + k * ((*n << 1) - k - 1) / 2] = wkp1; |
| 9059 |
|
| 9060 |
/* L100: */ |
| 9061 |
} |
| 9062 |
} |
| 9063 |
} |
| 9064 |
} |
| 9065 |
|
| 9066 |
/* Store details of the interchanges in IPIV */ |
| 9067 |
|
| 9068 |
if (kstep == 1) { |
| 9069 |
ipiv[k] = kp; |
| 9070 |
} else { |
| 9071 |
ipiv[k] = -kp; |
| 9072 |
ipiv[k + 1] = -kp; |
| 9073 |
} |
| 9074 |
|
| 9075 |
/* Increase K and return to the start of the main loop */ |
| 9076 |
|
| 9077 |
k += kstep; |
| 9078 |
kc = knc + *n - k + 2; |
| 9079 |
goto L60; |
| 9080 |
|
| 9081 |
} |
| 9082 |
|
| 9083 |
L110: |
| 9084 |
return 0; |
| 9085 |
|
| 9086 |
/* End of DSPTRF */ |
| 9087 |
|
| 9088 |
} /* dsptrf_ */ |
| 9089 |
|
| 9090 |
/* Subroutine */ int dsptri_(const char *uplo, integer *n, double *ap, integer * |
| 9091 |
ipiv, double *work, integer *info) |
| 9092 |
{ |
| 9093 |
/* Table of constant values */ |
| 9094 |
static integer c__1 = 1; |
| 9095 |
static double c_b11 = -1.; |
| 9096 |
static double c_b13 = 0.; |
| 9097 |
|
| 9098 |
/* System generated locals */ |
| 9099 |
integer i__1; |
| 9100 |
double d__1; |
| 9101 |
|
| 9102 |
/* Local variables */ |
| 9103 |
double d__; |
| 9104 |
integer j, k; |
| 9105 |
double t, ak; |
| 9106 |
integer kc, kp, kx, kpc, npp; |
| 9107 |
double akp1; |
| 9108 |
double temp, akkp1; |
| 9109 |
integer kstep; |
| 9110 |
bool upper; |
| 9111 |
integer kcnext; |
| 9112 |
|
| 9113 |
|
| 9114 |
/* -- LAPACK routine (version 3.1) -- */ |
| 9115 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 9116 |
/* November 2006 */ |
| 9117 |
|
| 9118 |
/* .. Scalar Arguments .. */ |
| 9119 |
/* .. */ |
| 9120 |
/* .. Array Arguments .. */ |
| 9121 |
/* .. */ |
| 9122 |
|
| 9123 |
/* Purpose */ |
| 9124 |
/* ======= */ |
| 9125 |
|
| 9126 |
/* DSPTRI computes the inverse of a real symmetric indefinite matrix */ |
| 9127 |
/* A in packed storage using the factorization A = U*D*U**T or */ |
| 9128 |
/* A = L*D*L**T computed by DSPTRF. */ |
| 9129 |
|
| 9130 |
/* Arguments */ |
| 9131 |
/* ========= */ |
| 9132 |
|
| 9133 |
/* UPLO (input) CHARACTER*1 */ |
| 9134 |
/* Specifies whether the details of the factorization are stored */ |
| 9135 |
/* as an upper or lower triangular matrix. */ |
| 9136 |
/* = 'U': Upper triangular, form is A = U*D*U**T; */ |
| 9137 |
/* = 'L': Lower triangular, form is A = L*D*L**T. */ |
| 9138 |
|
| 9139 |
/* N (input) INTEGER */ |
| 9140 |
/* The order of the matrix A. N >= 0. */ |
| 9141 |
|
| 9142 |
/* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 9143 |
/* On entry, the block diagonal matrix D and the multipliers */ |
| 9144 |
/* used to obtain the factor U or L as computed by DSPTRF, */ |
| 9145 |
/* stored as a packed triangular matrix. */ |
| 9146 |
|
| 9147 |
/* On exit, if INFO = 0, the (symmetric) inverse of the original */ |
| 9148 |
/* matrix, stored as a packed triangular matrix. The j-th column */ |
| 9149 |
/* of inv(A) is stored in the array AP as follows: */ |
| 9150 |
/* if UPLO = 'U', AP(i + (j-1)*j/2) = inv(A)(i,j) for 1<=i<=j; */ |
| 9151 |
/* if UPLO = 'L', */ |
| 9152 |
/* AP(i + (j-1)*(2n-j)/2) = inv(A)(i,j) for j<=i<=n. */ |
| 9153 |
|
| 9154 |
/* IPIV (input) INTEGER array, dimension (N) */ |
| 9155 |
/* Details of the interchanges and the block structure of D */ |
| 9156 |
/* as determined by DSPTRF. */ |
| 9157 |
|
| 9158 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (N) */ |
| 9159 |
|
| 9160 |
/* INFO (output) INTEGER */ |
| 9161 |
/* = 0: successful exit */ |
| 9162 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 9163 |
/* > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its */ |
| 9164 |
/* inverse could not be computed. */ |
| 9165 |
|
| 9166 |
/* ===================================================================== */ |
| 9167 |
|
| 9168 |
/* .. Parameters .. */ |
| 9169 |
/* .. */ |
| 9170 |
/* .. Local Scalars .. */ |
| 9171 |
/* .. */ |
| 9172 |
/* .. External Functions .. */ |
| 9173 |
/* .. */ |
| 9174 |
/* .. External Subroutines .. */ |
| 9175 |
/* .. */ |
| 9176 |
/* .. Intrinsic Functions .. */ |
| 9177 |
/* .. */ |
| 9178 |
/* .. Executable Statements .. */ |
| 9179 |
|
| 9180 |
/* Test the input parameters. */ |
| 9181 |
|
| 9182 |
/* Parameter adjustments */ |
| 9183 |
--work; |
| 9184 |
--ipiv; |
| 9185 |
--ap; |
| 9186 |
|
| 9187 |
/* Function Body */ |
| 9188 |
*info = 0; |
| 9189 |
upper = lsame_(uplo, "U"); |
| 9190 |
if (! upper && ! lsame_(uplo, "L")) { |
| 9191 |
*info = -1; |
| 9192 |
} else if (*n < 0) { |
| 9193 |
*info = -2; |
| 9194 |
} |
| 9195 |
if (*info != 0) { |
| 9196 |
i__1 = -(*info); |
| 9197 |
xerbla_("DSPTRI", &i__1); |
| 9198 |
return 0; |
| 9199 |
} |
| 9200 |
|
| 9201 |
/* Quick return if possible */ |
| 9202 |
|
| 9203 |
if (*n == 0) { |
| 9204 |
return 0; |
| 9205 |
} |
| 9206 |
|
| 9207 |
/* Check that the diagonal matrix D is nonsingular. */ |
| 9208 |
|
| 9209 |
if (upper) { |
| 9210 |
|
| 9211 |
/* Upper triangular storage: examine D from bottom to top */ |
| 9212 |
|
| 9213 |
kp = *n * (*n + 1) / 2; |
| 9214 |
for (*info = *n; *info >= 1; --(*info)) { |
| 9215 |
if (ipiv[*info] > 0 && ap[kp] == 0.) { |
| 9216 |
return 0; |
| 9217 |
} |
| 9218 |
kp -= *info; |
| 9219 |
/* L10: */ |
| 9220 |
} |
| 9221 |
} else { |
| 9222 |
|
| 9223 |
/* Lower triangular storage: examine D from top to bottom. */ |
| 9224 |
|
| 9225 |
kp = 1; |
| 9226 |
i__1 = *n; |
| 9227 |
for (*info = 1; *info <= i__1; ++(*info)) { |
| 9228 |
if (ipiv[*info] > 0 && ap[kp] == 0.) { |
| 9229 |
return 0; |
| 9230 |
} |
| 9231 |
kp = kp + *n - *info + 1; |
| 9232 |
/* L20: */ |
| 9233 |
} |
| 9234 |
} |
| 9235 |
*info = 0; |
| 9236 |
|
| 9237 |
if (upper) { |
| 9238 |
|
| 9239 |
/* Compute inv(A) from the factorization A = U*D*U'. */ |
| 9240 |
|
| 9241 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 9242 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 9243 |
|
| 9244 |
k = 1; |
| 9245 |
kc = 1; |
| 9246 |
L30: |
| 9247 |
|
| 9248 |
/* If K > N, exit from loop. */ |
| 9249 |
|
| 9250 |
if (k > *n) { |
| 9251 |
goto L50; |
| 9252 |
} |
| 9253 |
|
| 9254 |
kcnext = kc + k; |
| 9255 |
if (ipiv[k] > 0) { |
| 9256 |
|
| 9257 |
/* 1 x 1 diagonal block */ |
| 9258 |
|
| 9259 |
/* Invert the diagonal block. */ |
| 9260 |
|
| 9261 |
ap[kc + k - 1] = 1. / ap[kc + k - 1]; |
| 9262 |
|
| 9263 |
/* Compute column K of the inverse. */ |
| 9264 |
|
| 9265 |
if (k > 1) { |
| 9266 |
i__1 = k - 1; |
| 9267 |
dcopy_(&i__1, &ap[kc], &c__1, &work[1], &c__1); |
| 9268 |
i__1 = k - 1; |
| 9269 |
dspmv_(uplo, &i__1, &c_b11, &ap[1], &work[1], &c__1, &c_b13, & |
| 9270 |
ap[kc], &c__1); |
| 9271 |
i__1 = k - 1; |
| 9272 |
ap[kc + k - 1] -= ddot_(&i__1, &work[1], &c__1, &ap[kc], & |
| 9273 |
c__1); |
| 9274 |
} |
| 9275 |
kstep = 1; |
| 9276 |
} else { |
| 9277 |
|
| 9278 |
/* 2 x 2 diagonal block */ |
| 9279 |
|
| 9280 |
/* Invert the diagonal block. */ |
| 9281 |
|
| 9282 |
t = (d__1 = ap[kcnext + k - 1], abs(d__1)); |
| 9283 |
ak = ap[kc + k - 1] / t; |
| 9284 |
akp1 = ap[kcnext + k] / t; |
| 9285 |
akkp1 = ap[kcnext + k - 1] / t; |
| 9286 |
d__ = t * (ak * akp1 - 1.); |
| 9287 |
ap[kc + k - 1] = akp1 / d__; |
| 9288 |
ap[kcnext + k] = ak / d__; |
| 9289 |
ap[kcnext + k - 1] = -akkp1 / d__; |
| 9290 |
|
| 9291 |
/* Compute columns K and K+1 of the inverse. */ |
| 9292 |
|
| 9293 |
if (k > 1) { |
| 9294 |
i__1 = k - 1; |
| 9295 |
dcopy_(&i__1, &ap[kc], &c__1, &work[1], &c__1); |
| 9296 |
i__1 = k - 1; |
| 9297 |
dspmv_(uplo, &i__1, &c_b11, &ap[1], &work[1], &c__1, &c_b13, & |
| 9298 |
ap[kc], &c__1); |
| 9299 |
i__1 = k - 1; |
| 9300 |
ap[kc + k - 1] -= ddot_(&i__1, &work[1], &c__1, &ap[kc], & |
| 9301 |
c__1); |
| 9302 |
i__1 = k - 1; |
| 9303 |
ap[kcnext + k - 1] -= ddot_(&i__1, &ap[kc], &c__1, &ap[kcnext] |
| 9304 |
, &c__1); |
| 9305 |
i__1 = k - 1; |
| 9306 |
dcopy_(&i__1, &ap[kcnext], &c__1, &work[1], &c__1); |
| 9307 |
i__1 = k - 1; |
| 9308 |
dspmv_(uplo, &i__1, &c_b11, &ap[1], &work[1], &c__1, &c_b13, & |
| 9309 |
ap[kcnext], &c__1); |
| 9310 |
i__1 = k - 1; |
| 9311 |
ap[kcnext + k] -= ddot_(&i__1, &work[1], &c__1, &ap[kcnext], & |
| 9312 |
c__1); |
| 9313 |
} |
| 9314 |
kstep = 2; |
| 9315 |
kcnext = kcnext + k + 1; |
| 9316 |
} |
| 9317 |
|
| 9318 |
kp = (i__1 = ipiv[k], abs(i__1)); |
| 9319 |
if (kp != k) { |
| 9320 |
|
| 9321 |
/* Interchange rows and columns K and KP in the leading */ |
| 9322 |
/* submatrix A(1:k+1,1:k+1) */ |
| 9323 |
|
| 9324 |
kpc = (kp - 1) * kp / 2 + 1; |
| 9325 |
i__1 = kp - 1; |
| 9326 |
dswap_(&i__1, &ap[kc], &c__1, &ap[kpc], &c__1); |
| 9327 |
kx = kpc + kp - 1; |
| 9328 |
i__1 = k - 1; |
| 9329 |
for (j = kp + 1; j <= i__1; ++j) { |
| 9330 |
kx = kx + j - 1; |
| 9331 |
temp = ap[kc + j - 1]; |
| 9332 |
ap[kc + j - 1] = ap[kx]; |
| 9333 |
ap[kx] = temp; |
| 9334 |
/* L40: */ |
| 9335 |
} |
| 9336 |
temp = ap[kc + k - 1]; |
| 9337 |
ap[kc + k - 1] = ap[kpc + kp - 1]; |
| 9338 |
ap[kpc + kp - 1] = temp; |
| 9339 |
if (kstep == 2) { |
| 9340 |
temp = ap[kc + k + k - 1]; |
| 9341 |
ap[kc + k + k - 1] = ap[kc + k + kp - 1]; |
| 9342 |
ap[kc + k + kp - 1] = temp; |
| 9343 |
} |
| 9344 |
} |
| 9345 |
|
| 9346 |
k += kstep; |
| 9347 |
kc = kcnext; |
| 9348 |
goto L30; |
| 9349 |
L50: |
| 9350 |
|
| 9351 |
; |
| 9352 |
} else { |
| 9353 |
|
| 9354 |
/* Compute inv(A) from the factorization A = L*D*L'. */ |
| 9355 |
|
| 9356 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 9357 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 9358 |
|
| 9359 |
npp = *n * (*n + 1) / 2; |
| 9360 |
k = *n; |
| 9361 |
kc = npp; |
| 9362 |
L60: |
| 9363 |
|
| 9364 |
/* If K < 1, exit from loop. */ |
| 9365 |
|
| 9366 |
if (k < 1) { |
| 9367 |
goto L80; |
| 9368 |
} |
| 9369 |
|
| 9370 |
kcnext = kc - (*n - k + 2); |
| 9371 |
if (ipiv[k] > 0) { |
| 9372 |
|
| 9373 |
/* 1 x 1 diagonal block */ |
| 9374 |
|
| 9375 |
/* Invert the diagonal block. */ |
| 9376 |
|
| 9377 |
ap[kc] = 1. / ap[kc]; |
| 9378 |
|
| 9379 |
/* Compute column K of the inverse. */ |
| 9380 |
|
| 9381 |
if (k < *n) { |
| 9382 |
i__1 = *n - k; |
| 9383 |
dcopy_(&i__1, &ap[kc + 1], &c__1, &work[1], &c__1); |
| 9384 |
i__1 = *n - k; |
| 9385 |
dspmv_(uplo, &i__1, &c_b11, &ap[kc + *n - k + 1], &work[1], & |
| 9386 |
c__1, &c_b13, &ap[kc + 1], &c__1); |
| 9387 |
i__1 = *n - k; |
| 9388 |
ap[kc] -= ddot_(&i__1, &work[1], &c__1, &ap[kc + 1], &c__1); |
| 9389 |
} |
| 9390 |
kstep = 1; |
| 9391 |
} else { |
| 9392 |
|
| 9393 |
/* 2 x 2 diagonal block */ |
| 9394 |
|
| 9395 |
/* Invert the diagonal block. */ |
| 9396 |
|
| 9397 |
t = (d__1 = ap[kcnext + 1], abs(d__1)); |
| 9398 |
ak = ap[kcnext] / t; |
| 9399 |
akp1 = ap[kc] / t; |
| 9400 |
akkp1 = ap[kcnext + 1] / t; |
| 9401 |
d__ = t * (ak * akp1 - 1.); |
| 9402 |
ap[kcnext] = akp1 / d__; |
| 9403 |
ap[kc] = ak / d__; |
| 9404 |
ap[kcnext + 1] = -akkp1 / d__; |
| 9405 |
|
| 9406 |
/* Compute columns K-1 and K of the inverse. */ |
| 9407 |
|
| 9408 |
if (k < *n) { |
| 9409 |
i__1 = *n - k; |
| 9410 |
dcopy_(&i__1, &ap[kc + 1], &c__1, &work[1], &c__1); |
| 9411 |
i__1 = *n - k; |
| 9412 |
dspmv_(uplo, &i__1, &c_b11, &ap[kc + (*n - k + 1)], &work[1], |
| 9413 |
&c__1, &c_b13, &ap[kc + 1], &c__1); |
| 9414 |
i__1 = *n - k; |
| 9415 |
ap[kc] -= ddot_(&i__1, &work[1], &c__1, &ap[kc + 1], &c__1); |
| 9416 |
i__1 = *n - k; |
| 9417 |
ap[kcnext + 1] -= ddot_(&i__1, &ap[kc + 1], &c__1, &ap[kcnext |
| 9418 |
+ 2], &c__1); |
| 9419 |
i__1 = *n - k; |
| 9420 |
dcopy_(&i__1, &ap[kcnext + 2], &c__1, &work[1], &c__1); |
| 9421 |
i__1 = *n - k; |
| 9422 |
dspmv_(uplo, &i__1, &c_b11, &ap[kc + (*n - k + 1)], &work[1], |
| 9423 |
&c__1, &c_b13, &ap[kcnext + 2], &c__1); |
| 9424 |
i__1 = *n - k; |
| 9425 |
ap[kcnext] -= ddot_(&i__1, &work[1], &c__1, &ap[kcnext + 2], & |
| 9426 |
c__1); |
| 9427 |
} |
| 9428 |
kstep = 2; |
| 9429 |
kcnext -= *n - k + 3; |
| 9430 |
} |
| 9431 |
|
| 9432 |
kp = (i__1 = ipiv[k], abs(i__1)); |
| 9433 |
if (kp != k) { |
| 9434 |
|
| 9435 |
/* Interchange rows and columns K and KP in the trailing */ |
| 9436 |
/* submatrix A(k-1:n,k-1:n) */ |
| 9437 |
|
| 9438 |
kpc = npp - (*n - kp + 1) * (*n - kp + 2) / 2 + 1; |
| 9439 |
if (kp < *n) { |
| 9440 |
i__1 = *n - kp; |
| 9441 |
dswap_(&i__1, &ap[kc + kp - k + 1], &c__1, &ap[kpc + 1], & |
| 9442 |
c__1); |
| 9443 |
} |
| 9444 |
kx = kc + kp - k; |
| 9445 |
i__1 = kp - 1; |
| 9446 |
for (j = k + 1; j <= i__1; ++j) { |
| 9447 |
kx = kx + *n - j + 1; |
| 9448 |
temp = ap[kc + j - k]; |
| 9449 |
ap[kc + j - k] = ap[kx]; |
| 9450 |
ap[kx] = temp; |
| 9451 |
/* L70: */ |
| 9452 |
} |
| 9453 |
temp = ap[kc]; |
| 9454 |
ap[kc] = ap[kpc]; |
| 9455 |
ap[kpc] = temp; |
| 9456 |
if (kstep == 2) { |
| 9457 |
temp = ap[kc - *n + k - 1]; |
| 9458 |
ap[kc - *n + k - 1] = ap[kc - *n + kp - 1]; |
| 9459 |
ap[kc - *n + kp - 1] = temp; |
| 9460 |
} |
| 9461 |
} |
| 9462 |
|
| 9463 |
k -= kstep; |
| 9464 |
kc = kcnext; |
| 9465 |
goto L60; |
| 9466 |
L80: |
| 9467 |
; |
| 9468 |
} |
| 9469 |
|
| 9470 |
return 0; |
| 9471 |
|
| 9472 |
/* End of DSPTRI */ |
| 9473 |
|
| 9474 |
} /* dsptri_ */ |
| 9475 |
|
| 9476 |
/* Subroutine */ int dsptrs_(const char *uplo, integer *n, integer *nrhs, |
| 9477 |
double *ap, integer *ipiv, double *b, integer *ldb, integer * |
| 9478 |
info) |
| 9479 |
{ |
| 9480 |
/* Table of constant values */ |
| 9481 |
static double c_b7 = -1.; |
| 9482 |
static integer c__1 = 1; |
| 9483 |
static double c_b19 = 1.; |
| 9484 |
|
| 9485 |
/* System generated locals */ |
| 9486 |
integer b_dim1, b_offset, i__1; |
| 9487 |
double d__1; |
| 9488 |
|
| 9489 |
/* Local variables */ |
| 9490 |
integer j, k; |
| 9491 |
double ak, bk; |
| 9492 |
integer kc, kp; |
| 9493 |
double akm1, bkm1; |
| 9494 |
double akm1k; |
| 9495 |
double denom; |
| 9496 |
bool upper; |
| 9497 |
|
| 9498 |
|
| 9499 |
/* -- LAPACK routine (version 3.1) -- */ |
| 9500 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 9501 |
/* November 2006 */ |
| 9502 |
|
| 9503 |
/* .. Scalar Arguments .. */ |
| 9504 |
/* .. */ |
| 9505 |
/* .. Array Arguments .. */ |
| 9506 |
/* .. */ |
| 9507 |
|
| 9508 |
/* Purpose */ |
| 9509 |
/* ======= */ |
| 9510 |
|
| 9511 |
/* DSPTRS solves a system of linear equations A*X = B with a real */ |
| 9512 |
/* symmetric matrix A stored in packed format using the factorization */ |
| 9513 |
/* A = U*D*U**T or A = L*D*L**T computed by DSPTRF. */ |
| 9514 |
|
| 9515 |
/* Arguments */ |
| 9516 |
/* ========= */ |
| 9517 |
|
| 9518 |
/* UPLO (input) CHARACTER*1 */ |
| 9519 |
/* Specifies whether the details of the factorization are stored */ |
| 9520 |
/* as an upper or lower triangular matrix. */ |
| 9521 |
/* = 'U': Upper triangular, form is A = U*D*U**T; */ |
| 9522 |
/* = 'L': Lower triangular, form is A = L*D*L**T. */ |
| 9523 |
|
| 9524 |
/* N (input) INTEGER */ |
| 9525 |
/* The order of the matrix A. N >= 0. */ |
| 9526 |
|
| 9527 |
/* NRHS (input) INTEGER */ |
| 9528 |
/* The number of right hand sides, i.e., the number of columns */ |
| 9529 |
/* of the matrix B. NRHS >= 0. */ |
| 9530 |
|
| 9531 |
/* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */ |
| 9532 |
/* The block diagonal matrix D and the multipliers used to */ |
| 9533 |
/* obtain the factor U or L as computed by DSPTRF, stored as a */ |
| 9534 |
/* packed triangular matrix. */ |
| 9535 |
|
| 9536 |
/* IPIV (input) INTEGER array, dimension (N) */ |
| 9537 |
/* Details of the interchanges and the block structure of D */ |
| 9538 |
/* as determined by DSPTRF. */ |
| 9539 |
|
| 9540 |
/* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 9541 |
/* On entry, the right hand side matrix B. */ |
| 9542 |
/* On exit, the solution matrix X. */ |
| 9543 |
|
| 9544 |
/* LDB (input) INTEGER */ |
| 9545 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 9546 |
|
| 9547 |
/* INFO (output) INTEGER */ |
| 9548 |
/* = 0: successful exit */ |
| 9549 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 9550 |
|
| 9551 |
/* ===================================================================== */ |
| 9552 |
|
| 9553 |
/* .. Parameters .. */ |
| 9554 |
/* .. */ |
| 9555 |
/* .. Local Scalars .. */ |
| 9556 |
/* .. */ |
| 9557 |
/* .. External Functions .. */ |
| 9558 |
/* .. */ |
| 9559 |
/* .. External Subroutines .. */ |
| 9560 |
/* .. */ |
| 9561 |
/* .. Intrinsic Functions .. */ |
| 9562 |
/* .. */ |
| 9563 |
/* .. Executable Statements .. */ |
| 9564 |
|
| 9565 |
/* Parameter adjustments */ |
| 9566 |
--ap; |
| 9567 |
--ipiv; |
| 9568 |
b_dim1 = *ldb; |
| 9569 |
b_offset = 1 + b_dim1; |
| 9570 |
b -= b_offset; |
| 9571 |
|
| 9572 |
/* Function Body */ |
| 9573 |
*info = 0; |
| 9574 |
upper = lsame_(uplo, "U"); |
| 9575 |
if (! upper && ! lsame_(uplo, "L")) { |
| 9576 |
*info = -1; |
| 9577 |
} else if (*n < 0) { |
| 9578 |
*info = -2; |
| 9579 |
} else if (*nrhs < 0) { |
| 9580 |
*info = -3; |
| 9581 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 9582 |
*info = -7; |
| 9583 |
} |
| 9584 |
if (*info != 0) { |
| 9585 |
i__1 = -(*info); |
| 9586 |
xerbla_("DSPTRS", &i__1); |
| 9587 |
return 0; |
| 9588 |
} |
| 9589 |
|
| 9590 |
/* Quick return if possible */ |
| 9591 |
|
| 9592 |
if (*n == 0 || *nrhs == 0) { |
| 9593 |
return 0; |
| 9594 |
} |
| 9595 |
|
| 9596 |
if (upper) { |
| 9597 |
|
| 9598 |
/* Solve A*X = B, where A = U*D*U'. */ |
| 9599 |
|
| 9600 |
/* First solve U*D*X = B, overwriting B with X. */ |
| 9601 |
|
| 9602 |
/* K is the main loop index, decreasing from N to 1 in steps of */ |
| 9603 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 9604 |
|
| 9605 |
k = *n; |
| 9606 |
kc = *n * (*n + 1) / 2 + 1; |
| 9607 |
L10: |
| 9608 |
|
| 9609 |
/* If K < 1, exit from loop. */ |
| 9610 |
|
| 9611 |
if (k < 1) { |
| 9612 |
goto L30; |
| 9613 |
} |
| 9614 |
|
| 9615 |
kc -= k; |
| 9616 |
if (ipiv[k] > 0) { |
| 9617 |
|
| 9618 |
/* 1 x 1 diagonal block */ |
| 9619 |
|
| 9620 |
/* Interchange rows K and IPIV(K). */ |
| 9621 |
|
| 9622 |
kp = ipiv[k]; |
| 9623 |
if (kp != k) { |
| 9624 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 9625 |
} |
| 9626 |
|
| 9627 |
/* Multiply by inv(U(K)), where U(K) is the transformation */ |
| 9628 |
/* stored in column K of A. */ |
| 9629 |
|
| 9630 |
i__1 = k - 1; |
| 9631 |
dger_(&i__1, nrhs, &c_b7, &ap[kc], &c__1, &b[k + b_dim1], ldb, &b[ |
| 9632 |
b_dim1 + 1], ldb); |
| 9633 |
|
| 9634 |
/* Multiply by the inverse of the diagonal block. */ |
| 9635 |
|
| 9636 |
d__1 = 1. / ap[kc + k - 1]; |
| 9637 |
dscal_(nrhs, &d__1, &b[k + b_dim1], ldb); |
| 9638 |
--k; |
| 9639 |
} else { |
| 9640 |
|
| 9641 |
/* 2 x 2 diagonal block */ |
| 9642 |
|
| 9643 |
/* Interchange rows K-1 and -IPIV(K). */ |
| 9644 |
|
| 9645 |
kp = -ipiv[k]; |
| 9646 |
if (kp != k - 1) { |
| 9647 |
dswap_(nrhs, &b[k - 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 9648 |
} |
| 9649 |
|
| 9650 |
/* Multiply by inv(U(K)), where U(K) is the transformation */ |
| 9651 |
/* stored in columns K-1 and K of A. */ |
| 9652 |
|
| 9653 |
i__1 = k - 2; |
| 9654 |
dger_(&i__1, nrhs, &c_b7, &ap[kc], &c__1, &b[k + b_dim1], ldb, &b[ |
| 9655 |
b_dim1 + 1], ldb); |
| 9656 |
i__1 = k - 2; |
| 9657 |
dger_(&i__1, nrhs, &c_b7, &ap[kc - (k - 1)], &c__1, &b[k - 1 + |
| 9658 |
b_dim1], ldb, &b[b_dim1 + 1], ldb); |
| 9659 |
|
| 9660 |
/* Multiply by the inverse of the diagonal block. */ |
| 9661 |
|
| 9662 |
akm1k = ap[kc + k - 2]; |
| 9663 |
akm1 = ap[kc - 1] / akm1k; |
| 9664 |
ak = ap[kc + k - 1] / akm1k; |
| 9665 |
denom = akm1 * ak - 1.; |
| 9666 |
i__1 = *nrhs; |
| 9667 |
for (j = 1; j <= i__1; ++j) { |
| 9668 |
bkm1 = b[k - 1 + j * b_dim1] / akm1k; |
| 9669 |
bk = b[k + j * b_dim1] / akm1k; |
| 9670 |
b[k - 1 + j * b_dim1] = (ak * bkm1 - bk) / denom; |
| 9671 |
b[k + j * b_dim1] = (akm1 * bk - bkm1) / denom; |
| 9672 |
/* L20: */ |
| 9673 |
} |
| 9674 |
kc = kc - k + 1; |
| 9675 |
k += -2; |
| 9676 |
} |
| 9677 |
|
| 9678 |
goto L10; |
| 9679 |
L30: |
| 9680 |
|
| 9681 |
/* Next solve U'*X = B, overwriting B with X. */ |
| 9682 |
|
| 9683 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 9684 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 9685 |
|
| 9686 |
k = 1; |
| 9687 |
kc = 1; |
| 9688 |
L40: |
| 9689 |
|
| 9690 |
/* If K > N, exit from loop. */ |
| 9691 |
|
| 9692 |
if (k > *n) { |
| 9693 |
goto L50; |
| 9694 |
} |
| 9695 |
|
| 9696 |
if (ipiv[k] > 0) { |
| 9697 |
|
| 9698 |
/* 1 x 1 diagonal block */ |
| 9699 |
|
| 9700 |
/* Multiply by inv(U'(K)), where U(K) is the transformation */ |
| 9701 |
/* stored in column K of A. */ |
| 9702 |
|
| 9703 |
i__1 = k - 1; |
| 9704 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[b_offset], ldb, &ap[kc] |
| 9705 |
, &c__1, &c_b19, &b[k + b_dim1], ldb); |
| 9706 |
|
| 9707 |
/* Interchange rows K and IPIV(K). */ |
| 9708 |
|
| 9709 |
kp = ipiv[k]; |
| 9710 |
if (kp != k) { |
| 9711 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 9712 |
} |
| 9713 |
kc += k; |
| 9714 |
++k; |
| 9715 |
} else { |
| 9716 |
|
| 9717 |
/* 2 x 2 diagonal block */ |
| 9718 |
|
| 9719 |
/* Multiply by inv(U'(K+1)), where U(K+1) is the transformation */ |
| 9720 |
/* stored in columns K and K+1 of A. */ |
| 9721 |
|
| 9722 |
i__1 = k - 1; |
| 9723 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[b_offset], ldb, &ap[kc] |
| 9724 |
, &c__1, &c_b19, &b[k + b_dim1], ldb); |
| 9725 |
i__1 = k - 1; |
| 9726 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[b_offset], ldb, &ap[kc |
| 9727 |
+ k], &c__1, &c_b19, &b[k + 1 + b_dim1], ldb); |
| 9728 |
|
| 9729 |
/* Interchange rows K and -IPIV(K). */ |
| 9730 |
|
| 9731 |
kp = -ipiv[k]; |
| 9732 |
if (kp != k) { |
| 9733 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 9734 |
} |
| 9735 |
kc = kc + (k << 1) + 1; |
| 9736 |
k += 2; |
| 9737 |
} |
| 9738 |
|
| 9739 |
goto L40; |
| 9740 |
L50: |
| 9741 |
|
| 9742 |
; |
| 9743 |
} else { |
| 9744 |
|
| 9745 |
/* Solve A*X = B, where A = L*D*L'. */ |
| 9746 |
|
| 9747 |
/* First solve L*D*X = B, overwriting B with X. */ |
| 9748 |
|
| 9749 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 9750 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 9751 |
|
| 9752 |
k = 1; |
| 9753 |
kc = 1; |
| 9754 |
L60: |
| 9755 |
|
| 9756 |
/* If K > N, exit from loop. */ |
| 9757 |
|
| 9758 |
if (k > *n) { |
| 9759 |
goto L80; |
| 9760 |
} |
| 9761 |
|
| 9762 |
if (ipiv[k] > 0) { |
| 9763 |
|
| 9764 |
/* 1 x 1 diagonal block */ |
| 9765 |
|
| 9766 |
/* Interchange rows K and IPIV(K). */ |
| 9767 |
|
| 9768 |
kp = ipiv[k]; |
| 9769 |
if (kp != k) { |
| 9770 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 9771 |
} |
| 9772 |
|
| 9773 |
/* Multiply by inv(L(K)), where L(K) is the transformation */ |
| 9774 |
/* stored in column K of A. */ |
| 9775 |
|
| 9776 |
if (k < *n) { |
| 9777 |
i__1 = *n - k; |
| 9778 |
dger_(&i__1, nrhs, &c_b7, &ap[kc + 1], &c__1, &b[k + b_dim1], |
| 9779 |
ldb, &b[k + 1 + b_dim1], ldb); |
| 9780 |
} |
| 9781 |
|
| 9782 |
/* Multiply by the inverse of the diagonal block. */ |
| 9783 |
|
| 9784 |
d__1 = 1. / ap[kc]; |
| 9785 |
dscal_(nrhs, &d__1, &b[k + b_dim1], ldb); |
| 9786 |
kc = kc + *n - k + 1; |
| 9787 |
++k; |
| 9788 |
} else { |
| 9789 |
|
| 9790 |
/* 2 x 2 diagonal block */ |
| 9791 |
|
| 9792 |
/* Interchange rows K+1 and -IPIV(K). */ |
| 9793 |
|
| 9794 |
kp = -ipiv[k]; |
| 9795 |
if (kp != k + 1) { |
| 9796 |
dswap_(nrhs, &b[k + 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 9797 |
} |
| 9798 |
|
| 9799 |
/* Multiply by inv(L(K)), where L(K) is the transformation */ |
| 9800 |
/* stored in columns K and K+1 of A. */ |
| 9801 |
|
| 9802 |
if (k < *n - 1) { |
| 9803 |
i__1 = *n - k - 1; |
| 9804 |
dger_(&i__1, nrhs, &c_b7, &ap[kc + 2], &c__1, &b[k + b_dim1], |
| 9805 |
ldb, &b[k + 2 + b_dim1], ldb); |
| 9806 |
i__1 = *n - k - 1; |
| 9807 |
dger_(&i__1, nrhs, &c_b7, &ap[kc + *n - k + 2], &c__1, &b[k + |
| 9808 |
1 + b_dim1], ldb, &b[k + 2 + b_dim1], ldb); |
| 9809 |
} |
| 9810 |
|
| 9811 |
/* Multiply by the inverse of the diagonal block. */ |
| 9812 |
|
| 9813 |
akm1k = ap[kc + 1]; |
| 9814 |
akm1 = ap[kc] / akm1k; |
| 9815 |
ak = ap[kc + *n - k + 1] / akm1k; |
| 9816 |
denom = akm1 * ak - 1.; |
| 9817 |
i__1 = *nrhs; |
| 9818 |
for (j = 1; j <= i__1; ++j) { |
| 9819 |
bkm1 = b[k + j * b_dim1] / akm1k; |
| 9820 |
bk = b[k + 1 + j * b_dim1] / akm1k; |
| 9821 |
b[k + j * b_dim1] = (ak * bkm1 - bk) / denom; |
| 9822 |
b[k + 1 + j * b_dim1] = (akm1 * bk - bkm1) / denom; |
| 9823 |
/* L70: */ |
| 9824 |
} |
| 9825 |
kc = kc + (*n - k << 1) + 1; |
| 9826 |
k += 2; |
| 9827 |
} |
| 9828 |
|
| 9829 |
goto L60; |
| 9830 |
L80: |
| 9831 |
|
| 9832 |
/* Next solve L'*X = B, overwriting B with X. */ |
| 9833 |
|
| 9834 |
/* K is the main loop index, decreasing from N to 1 in steps of */ |
| 9835 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 9836 |
|
| 9837 |
k = *n; |
| 9838 |
kc = *n * (*n + 1) / 2 + 1; |
| 9839 |
L90: |
| 9840 |
|
| 9841 |
/* If K < 1, exit from loop. */ |
| 9842 |
|
| 9843 |
if (k < 1) { |
| 9844 |
goto L100; |
| 9845 |
} |
| 9846 |
|
| 9847 |
kc -= *n - k + 1; |
| 9848 |
if (ipiv[k] > 0) { |
| 9849 |
|
| 9850 |
/* 1 x 1 diagonal block */ |
| 9851 |
|
| 9852 |
/* Multiply by inv(L'(K)), where L(K) is the transformation */ |
| 9853 |
/* stored in column K of A. */ |
| 9854 |
|
| 9855 |
if (k < *n) { |
| 9856 |
i__1 = *n - k; |
| 9857 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[k + 1 + b_dim1], |
| 9858 |
ldb, &ap[kc + 1], &c__1, &c_b19, &b[k + b_dim1], ldb); |
| 9859 |
} |
| 9860 |
|
| 9861 |
/* Interchange rows K and IPIV(K). */ |
| 9862 |
|
| 9863 |
kp = ipiv[k]; |
| 9864 |
if (kp != k) { |
| 9865 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 9866 |
} |
| 9867 |
--k; |
| 9868 |
} else { |
| 9869 |
|
| 9870 |
/* 2 x 2 diagonal block */ |
| 9871 |
|
| 9872 |
/* Multiply by inv(L'(K-1)), where L(K-1) is the transformation */ |
| 9873 |
/* stored in columns K-1 and K of A. */ |
| 9874 |
|
| 9875 |
if (k < *n) { |
| 9876 |
i__1 = *n - k; |
| 9877 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[k + 1 + b_dim1], |
| 9878 |
ldb, &ap[kc + 1], &c__1, &c_b19, &b[k + b_dim1], ldb); |
| 9879 |
i__1 = *n - k; |
| 9880 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[k + 1 + b_dim1], |
| 9881 |
ldb, &ap[kc - (*n - k)], &c__1, &c_b19, &b[k - 1 + |
| 9882 |
b_dim1], ldb); |
| 9883 |
} |
| 9884 |
|
| 9885 |
/* Interchange rows K and -IPIV(K). */ |
| 9886 |
|
| 9887 |
kp = -ipiv[k]; |
| 9888 |
if (kp != k) { |
| 9889 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 9890 |
} |
| 9891 |
kc -= *n - k + 2; |
| 9892 |
k += -2; |
| 9893 |
} |
| 9894 |
|
| 9895 |
goto L90; |
| 9896 |
L100: |
| 9897 |
; |
| 9898 |
} |
| 9899 |
|
| 9900 |
return 0; |
| 9901 |
|
| 9902 |
/* End of DSPTRS */ |
| 9903 |
|
| 9904 |
} /* dsptrs_ */ |
| 9905 |
|
| 9906 |
/* Subroutine */ int dstebz_(const char *range, const char *order, integer *n, double |
| 9907 |
*vl, double *vu, integer *il, integer *iu, double *abstol, |
| 9908 |
double *d__, double *e, integer *m, integer *nsplit, |
| 9909 |
double *w, integer *iblock, integer *isplit, double *work, |
| 9910 |
integer *iwork, integer *info) |
| 9911 |
{ |
| 9912 |
/* Table of constant values */ |
| 9913 |
static integer c__1 = 1; |
| 9914 |
static integer c_n1 = -1; |
| 9915 |
static integer c__3 = 3; |
| 9916 |
static integer c__2 = 2; |
| 9917 |
static integer c__0 = 0; |
| 9918 |
|
| 9919 |
/* System generated locals */ |
| 9920 |
integer i__1, i__2, i__3; |
| 9921 |
double d__1, d__2, d__3, d__4, d__5; |
| 9922 |
|
| 9923 |
/* Local variables */ |
| 9924 |
integer j, ib, jb, ie, je, nb; |
| 9925 |
double gl; |
| 9926 |
integer im, in; |
| 9927 |
double gu; |
| 9928 |
integer iw; |
| 9929 |
double wl, wu; |
| 9930 |
integer nwl; |
| 9931 |
double ulp, wlu, wul; |
| 9932 |
integer nwu; |
| 9933 |
double tmp1, tmp2; |
| 9934 |
integer iend, ioff, iout, itmp1, jdisc; |
| 9935 |
integer iinfo; |
| 9936 |
double atoli; |
| 9937 |
integer iwoff; |
| 9938 |
double bnorm; |
| 9939 |
integer itmax; |
| 9940 |
double wkill, rtoli, tnorm; |
| 9941 |
integer ibegin; |
| 9942 |
integer irange, idiscl; |
| 9943 |
double safemn; |
| 9944 |
integer idumma[1]; |
| 9945 |
integer idiscu, iorder; |
| 9946 |
bool ncnvrg; |
| 9947 |
double pivmin; |
| 9948 |
bool toofew; |
| 9949 |
|
| 9950 |
|
| 9951 |
/* -- LAPACK routine (version 3.1) -- */ |
| 9952 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 9953 |
/* November 2006 */ |
| 9954 |
/* 8-18-00: Increase FUDGE factor for T3E (eca) */ |
| 9955 |
|
| 9956 |
/* .. Scalar Arguments .. */ |
| 9957 |
/* .. */ |
| 9958 |
/* .. Array Arguments .. */ |
| 9959 |
/* .. */ |
| 9960 |
|
| 9961 |
/* Purpose */ |
| 9962 |
/* ======= */ |
| 9963 |
|
| 9964 |
/* DSTEBZ computes the eigenvalues of a symmetric tridiagonal */ |
| 9965 |
/* matrix T. The user may ask for all eigenvalues, all eigenvalues */ |
| 9966 |
/* in the half-open interval (VL, VU], or the IL-th through IU-th */ |
| 9967 |
/* eigenvalues. */ |
| 9968 |
|
| 9969 |
/* To avoid overflow, the matrix must be scaled so that its */ |
| 9970 |
/* largest element is no greater than overflow**(1/2) * */ |
| 9971 |
/* underflow**(1/4) in absolute value, and for greatest */ |
| 9972 |
/* accuracy, it should not be much smaller than that. */ |
| 9973 |
|
| 9974 |
/* See W. Kahan "Accurate Eigenvalues of a Symmetric Tridiagonal */ |
| 9975 |
/* Matrix", Report CS41, Computer Science Dept., Stanford */ |
| 9976 |
/* University, July 21, 1966. */ |
| 9977 |
|
| 9978 |
/* Arguments */ |
| 9979 |
/* ========= */ |
| 9980 |
|
| 9981 |
/* RANGE (input) CHARACTER*1 */ |
| 9982 |
/* = 'A': ("All") all eigenvalues will be found. */ |
| 9983 |
/* = 'V': ("Value") all eigenvalues in the half-open interval */ |
| 9984 |
/* (VL, VU] will be found. */ |
| 9985 |
/* = 'I': ("Index") the IL-th through IU-th eigenvalues (of the */ |
| 9986 |
/* entire matrix) will be found. */ |
| 9987 |
|
| 9988 |
/* ORDER (input) CHARACTER*1 */ |
| 9989 |
/* = 'B': ("By Block") the eigenvalues will be grouped by */ |
| 9990 |
/* split-off block (see IBLOCK, ISPLIT) and */ |
| 9991 |
/* ordered from smallest to largest within */ |
| 9992 |
/* the block. */ |
| 9993 |
/* = 'E': ("Entire matrix") */ |
| 9994 |
/* the eigenvalues for the entire matrix */ |
| 9995 |
/* will be ordered from smallest to */ |
| 9996 |
/* largest. */ |
| 9997 |
|
| 9998 |
/* N (input) INTEGER */ |
| 9999 |
/* The order of the tridiagonal matrix T. N >= 0. */ |
| 10000 |
|
| 10001 |
/* VL (input) DOUBLE PRECISION */ |
| 10002 |
/* VU (input) DOUBLE PRECISION */ |
| 10003 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 10004 |
/* be searched for eigenvalues. Eigenvalues less than or equal */ |
| 10005 |
/* to VL, or greater than VU, will not be returned. VL < VU. */ |
| 10006 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 10007 |
|
| 10008 |
/* IL (input) INTEGER */ |
| 10009 |
/* IU (input) INTEGER */ |
| 10010 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 10011 |
/* smallest and largest eigenvalues to be returned. */ |
| 10012 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 10013 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 10014 |
|
| 10015 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 10016 |
/* The absolute tolerance for the eigenvalues. An eigenvalue */ |
| 10017 |
/* (or cluster) is considered to be located if it has been */ |
| 10018 |
/* determined to lie in an interval whose width is ABSTOL or */ |
| 10019 |
/* less. If ABSTOL is less than or equal to zero, then ULP*|T| */ |
| 10020 |
/* will be used, where |T| means the 1-norm of T. */ |
| 10021 |
|
| 10022 |
/* Eigenvalues will be computed most accurately when ABSTOL is */ |
| 10023 |
/* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */ |
| 10024 |
|
| 10025 |
/* D (input) DOUBLE PRECISION array, dimension (N) */ |
| 10026 |
/* The n diagonal elements of the tridiagonal matrix T. */ |
| 10027 |
|
| 10028 |
/* E (input) DOUBLE PRECISION array, dimension (N-1) */ |
| 10029 |
/* The (n-1) off-diagonal elements of the tridiagonal matrix T. */ |
| 10030 |
|
| 10031 |
/* M (output) INTEGER */ |
| 10032 |
/* The actual number of eigenvalues found. 0 <= M <= N. */ |
| 10033 |
/* (See also the description of INFO=2,3.) */ |
| 10034 |
|
| 10035 |
/* NSPLIT (output) INTEGER */ |
| 10036 |
/* The number of diagonal blocks in the matrix T. */ |
| 10037 |
/* 1 <= NSPLIT <= N. */ |
| 10038 |
|
| 10039 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 10040 |
/* On exit, the first M elements of W will contain the */ |
| 10041 |
/* eigenvalues. (DSTEBZ may use the remaining N-M elements as */ |
| 10042 |
/* workspace.) */ |
| 10043 |
|
| 10044 |
/* IBLOCK (output) INTEGER array, dimension (N) */ |
| 10045 |
/* At each row/column j where E(j) is zero or small, the */ |
| 10046 |
/* matrix T is considered to split into a block diagonal */ |
| 10047 |
/* matrix. On exit, if INFO = 0, IBLOCK(i) specifies to which */ |
| 10048 |
/* block (from 1 to the number of blocks) the eigenvalue W(i) */ |
| 10049 |
/* belongs. (DSTEBZ may use the remaining N-M elements as */ |
| 10050 |
/* workspace.) */ |
| 10051 |
|
| 10052 |
/* ISPLIT (output) INTEGER array, dimension (N) */ |
| 10053 |
/* The splitting points, at which T breaks up into submatrices. */ |
| 10054 |
/* The first submatrix consists of rows/columns 1 to ISPLIT(1), */ |
| 10055 |
/* the second of rows/columns ISPLIT(1)+1 through ISPLIT(2), */ |
| 10056 |
/* etc., and the NSPLIT-th consists of rows/columns */ |
| 10057 |
/* ISPLIT(NSPLIT-1)+1 through ISPLIT(NSPLIT)=N. */ |
| 10058 |
/* (Only the first NSPLIT elements will actually be used, but */ |
| 10059 |
/* since the user cannot know a priori what value NSPLIT will */ |
| 10060 |
/* have, N words must be reserved for ISPLIT.) */ |
| 10061 |
|
| 10062 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (4*N) */ |
| 10063 |
|
| 10064 |
/* IWORK (workspace) INTEGER array, dimension (3*N) */ |
| 10065 |
|
| 10066 |
/* INFO (output) INTEGER */ |
| 10067 |
/* = 0: successful exit */ |
| 10068 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 10069 |
/* > 0: some or all of the eigenvalues failed to converge or */ |
| 10070 |
/* were not computed: */ |
| 10071 |
/* =1 or 3: Bisection failed to converge for some */ |
| 10072 |
/* eigenvalues; these eigenvalues are flagged by a */ |
| 10073 |
/* negative block number. The effect is that the */ |
| 10074 |
/* eigenvalues may not be as accurate as the */ |
| 10075 |
/* absolute and relative tolerances. This is */ |
| 10076 |
/* generally caused by unexpectedly inaccurate */ |
| 10077 |
/* arithmetic. */ |
| 10078 |
/* =2 or 3: RANGE='I' only: Not all of the eigenvalues */ |
| 10079 |
/* IL:IU were found. */ |
| 10080 |
/* Effect: M < IU+1-IL */ |
| 10081 |
/* Cause: non-monotonic arithmetic, causing the */ |
| 10082 |
/* Sturm sequence to be non-monotonic. */ |
| 10083 |
/* Cure: recalculate, using RANGE='A', and pick */ |
| 10084 |
/* out eigenvalues IL:IU. In some cases, */ |
| 10085 |
/* increasing the PARAMETER "FUDGE" may */ |
| 10086 |
/* make things work. */ |
| 10087 |
/* = 4: RANGE='I', and the Gershgorin interval */ |
| 10088 |
/* initially used was too small. No eigenvalues */ |
| 10089 |
/* were computed. */ |
| 10090 |
/* Probable cause: your machine has sloppy */ |
| 10091 |
/* floating-point arithmetic. */ |
| 10092 |
/* Cure: Increase the PARAMETER "FUDGE", */ |
| 10093 |
/* recompile, and try again. */ |
| 10094 |
|
| 10095 |
/* Internal Parameters */ |
| 10096 |
/* =================== */ |
| 10097 |
|
| 10098 |
/* RELFAC DOUBLE PRECISION, default = 2.0e0 */ |
| 10099 |
/* The relative tolerance. An interval (a,b] lies within */ |
| 10100 |
/* "relative tolerance" if b-a < RELFAC*ulp*max(|a|,|b|), */ |
| 10101 |
/* where "ulp" is the machine precision (distance from 1 to */ |
| 10102 |
/* the next larger floating point number.) */ |
| 10103 |
|
| 10104 |
/* FUDGE DOUBLE PRECISION, default = 2 */ |
| 10105 |
/* A "fudge factor" to widen the Gershgorin intervals. Ideally, */ |
| 10106 |
/* a value of 1 should work, but on machines with sloppy */ |
| 10107 |
/* arithmetic, this needs to be larger. The default for */ |
| 10108 |
/* publicly released versions should be large enough to handle */ |
| 10109 |
/* the worst machine around. Note that this has no effect */ |
| 10110 |
/* on accuracy of the solution. */ |
| 10111 |
|
| 10112 |
/* ===================================================================== */ |
| 10113 |
|
| 10114 |
/* .. Parameters .. */ |
| 10115 |
/* .. */ |
| 10116 |
/* .. Local Scalars .. */ |
| 10117 |
/* .. */ |
| 10118 |
/* .. Local Arrays .. */ |
| 10119 |
/* .. */ |
| 10120 |
/* .. External Functions .. */ |
| 10121 |
/* .. */ |
| 10122 |
/* .. External Subroutines .. */ |
| 10123 |
/* .. */ |
| 10124 |
/* .. Intrinsic Functions .. */ |
| 10125 |
/* .. */ |
| 10126 |
/* .. Executable Statements .. */ |
| 10127 |
|
| 10128 |
/* Parameter adjustments */ |
| 10129 |
--iwork; |
| 10130 |
--work; |
| 10131 |
--isplit; |
| 10132 |
--iblock; |
| 10133 |
--w; |
| 10134 |
--e; |
| 10135 |
--d__; |
| 10136 |
|
| 10137 |
/* Function Body */ |
| 10138 |
*info = 0; |
| 10139 |
|
| 10140 |
/* Decode RANGE */ |
| 10141 |
|
| 10142 |
if (lsame_(range, "A")) { |
| 10143 |
irange = 1; |
| 10144 |
} else if (lsame_(range, "V")) { |
| 10145 |
irange = 2; |
| 10146 |
} else if (lsame_(range, "I")) { |
| 10147 |
irange = 3; |
| 10148 |
} else { |
| 10149 |
irange = 0; |
| 10150 |
} |
| 10151 |
|
| 10152 |
/* Decode ORDER */ |
| 10153 |
|
| 10154 |
if (lsame_(order, "B")) { |
| 10155 |
iorder = 2; |
| 10156 |
} else if (lsame_(order, "E")) { |
| 10157 |
iorder = 1; |
| 10158 |
} else { |
| 10159 |
iorder = 0; |
| 10160 |
} |
| 10161 |
|
| 10162 |
/* Check for Errors */ |
| 10163 |
|
| 10164 |
if (irange <= 0) { |
| 10165 |
*info = -1; |
| 10166 |
} else if (iorder <= 0) { |
| 10167 |
*info = -2; |
| 10168 |
} else if (*n < 0) { |
| 10169 |
*info = -3; |
| 10170 |
} else if (irange == 2) { |
| 10171 |
if (*vl >= *vu) { |
| 10172 |
*info = -5; |
| 10173 |
} |
| 10174 |
} else if (irange == 3 && (*il < 1 || *il > std::max(1_integer,*n))) { |
| 10175 |
*info = -6; |
| 10176 |
} else if (irange == 3 && (*iu < std::min(*n,*il) || *iu > *n)) { |
| 10177 |
*info = -7; |
| 10178 |
} |
| 10179 |
|
| 10180 |
if (*info != 0) { |
| 10181 |
i__1 = -(*info); |
| 10182 |
xerbla_("DSTEBZ", &i__1); |
| 10183 |
return 0; |
| 10184 |
} |
| 10185 |
|
| 10186 |
/* Initialize error flags */ |
| 10187 |
|
| 10188 |
*info = 0; |
| 10189 |
ncnvrg = false; |
| 10190 |
toofew = false; |
| 10191 |
|
| 10192 |
/* Quick return if possible */ |
| 10193 |
|
| 10194 |
*m = 0; |
| 10195 |
if (*n == 0) { |
| 10196 |
return 0; |
| 10197 |
} |
| 10198 |
|
| 10199 |
/* Simplifications: */ |
| 10200 |
|
| 10201 |
if (irange == 3 && *il == 1 && *iu == *n) { |
| 10202 |
irange = 1; |
| 10203 |
} |
| 10204 |
|
| 10205 |
/* Get machine constants */ |
| 10206 |
/* NB is the minimum vector length for vector bisection, or 0 */ |
| 10207 |
/* if only scalar is to be done. */ |
| 10208 |
|
| 10209 |
safemn = dlamch_("S"); |
| 10210 |
ulp = dlamch_("P"); |
| 10211 |
rtoli = ulp * 2.; |
| 10212 |
nb = ilaenv_(&c__1, "DSTEBZ", " ", n, &c_n1, &c_n1, &c_n1); |
| 10213 |
if (nb <= 1) { |
| 10214 |
nb = 0; |
| 10215 |
} |
| 10216 |
|
| 10217 |
/* Special Case when N=1 */ |
| 10218 |
|
| 10219 |
if (*n == 1) { |
| 10220 |
*nsplit = 1; |
| 10221 |
isplit[1] = 1; |
| 10222 |
if (irange == 2 && (*vl >= d__[1] || *vu < d__[1])) { |
| 10223 |
*m = 0; |
| 10224 |
} else { |
| 10225 |
w[1] = d__[1]; |
| 10226 |
iblock[1] = 1; |
| 10227 |
*m = 1; |
| 10228 |
} |
| 10229 |
return 0; |
| 10230 |
} |
| 10231 |
|
| 10232 |
/* Compute Splitting Points */ |
| 10233 |
|
| 10234 |
*nsplit = 1; |
| 10235 |
work[*n] = 0.; |
| 10236 |
pivmin = 1.; |
| 10237 |
|
| 10238 |
/* DIR$ NOVECTOR */ |
| 10239 |
i__1 = *n; |
| 10240 |
for (j = 2; j <= i__1; ++j) { |
| 10241 |
/* Computing 2nd power */ |
| 10242 |
d__1 = e[j - 1]; |
| 10243 |
tmp1 = d__1 * d__1; |
| 10244 |
/* Computing 2nd power */ |
| 10245 |
d__2 = ulp; |
| 10246 |
if ((d__1 = d__[j] * d__[j - 1], abs(d__1)) * (d__2 * d__2) + safemn |
| 10247 |
> tmp1) { |
| 10248 |
isplit[*nsplit] = j - 1; |
| 10249 |
++(*nsplit); |
| 10250 |
work[j - 1] = 0.; |
| 10251 |
} else { |
| 10252 |
work[j - 1] = tmp1; |
| 10253 |
pivmin = std::max(pivmin,tmp1); |
| 10254 |
} |
| 10255 |
/* L10: */ |
| 10256 |
} |
| 10257 |
isplit[*nsplit] = *n; |
| 10258 |
pivmin *= safemn; |
| 10259 |
|
| 10260 |
/* Compute Interval and ATOLI */ |
| 10261 |
|
| 10262 |
if (irange == 3) { |
| 10263 |
|
| 10264 |
/* RANGE='I': Compute the interval containing eigenvalues */ |
| 10265 |
/* IL through IU. */ |
| 10266 |
|
| 10267 |
/* Compute Gershgorin interval for entire (split) matrix */ |
| 10268 |
/* and use it as the initial interval */ |
| 10269 |
|
| 10270 |
gu = d__[1]; |
| 10271 |
gl = d__[1]; |
| 10272 |
tmp1 = 0.; |
| 10273 |
|
| 10274 |
i__1 = *n - 1; |
| 10275 |
for (j = 1; j <= i__1; ++j) { |
| 10276 |
tmp2 = sqrt(work[j]); |
| 10277 |
/* Computing MAX */ |
| 10278 |
d__1 = gu, d__2 = d__[j] + tmp1 + tmp2; |
| 10279 |
gu = std::max(d__1,d__2); |
| 10280 |
/* Computing MIN */ |
| 10281 |
d__1 = gl, d__2 = d__[j] - tmp1 - tmp2; |
| 10282 |
gl = std::min(d__1,d__2); |
| 10283 |
tmp1 = tmp2; |
| 10284 |
/* L20: */ |
| 10285 |
} |
| 10286 |
|
| 10287 |
/* Computing MAX */ |
| 10288 |
d__1 = gu, d__2 = d__[*n] + tmp1; |
| 10289 |
gu = std::max(d__1,d__2); |
| 10290 |
/* Computing MIN */ |
| 10291 |
d__1 = gl, d__2 = d__[*n] - tmp1; |
| 10292 |
gl = std::min(d__1,d__2); |
| 10293 |
/* Computing MAX */ |
| 10294 |
d__1 = abs(gl), d__2 = abs(gu); |
| 10295 |
tnorm = std::max(d__1,d__2); |
| 10296 |
gl = gl - tnorm * 2.1 * ulp * *n - pivmin * 4.2000000000000002; |
| 10297 |
gu = gu + tnorm * 2.1 * ulp * *n + pivmin * 2.1; |
| 10298 |
|
| 10299 |
/* Compute Iteration parameters */ |
| 10300 |
|
| 10301 |
itmax = (integer) ((log(tnorm + pivmin) - log(pivmin)) / log(2.)) + 2; |
| 10302 |
if (*abstol <= 0.) { |
| 10303 |
atoli = ulp * tnorm; |
| 10304 |
} else { |
| 10305 |
atoli = *abstol; |
| 10306 |
} |
| 10307 |
|
| 10308 |
work[*n + 1] = gl; |
| 10309 |
work[*n + 2] = gl; |
| 10310 |
work[*n + 3] = gu; |
| 10311 |
work[*n + 4] = gu; |
| 10312 |
work[*n + 5] = gl; |
| 10313 |
work[*n + 6] = gu; |
| 10314 |
iwork[1] = -1; |
| 10315 |
iwork[2] = -1; |
| 10316 |
iwork[3] = *n + 1; |
| 10317 |
iwork[4] = *n + 1; |
| 10318 |
iwork[5] = *il - 1; |
| 10319 |
iwork[6] = *iu; |
| 10320 |
|
| 10321 |
dlaebz_(&c__3, &itmax, n, &c__2, &c__2, &nb, &atoli, &rtoli, &pivmin, |
| 10322 |
&d__[1], &e[1], &work[1], &iwork[5], &work[*n + 1], &work[*n |
| 10323 |
+ 5], &iout, &iwork[1], &w[1], &iblock[1], &iinfo); |
| 10324 |
|
| 10325 |
if (iwork[6] == *iu) { |
| 10326 |
wl = work[*n + 1]; |
| 10327 |
wlu = work[*n + 3]; |
| 10328 |
nwl = iwork[1]; |
| 10329 |
wu = work[*n + 4]; |
| 10330 |
wul = work[*n + 2]; |
| 10331 |
nwu = iwork[4]; |
| 10332 |
} else { |
| 10333 |
wl = work[*n + 2]; |
| 10334 |
wlu = work[*n + 4]; |
| 10335 |
nwl = iwork[2]; |
| 10336 |
wu = work[*n + 3]; |
| 10337 |
wul = work[*n + 1]; |
| 10338 |
nwu = iwork[3]; |
| 10339 |
} |
| 10340 |
|
| 10341 |
if (nwl < 0 || nwl >= *n || nwu < 1 || nwu > *n) { |
| 10342 |
*info = 4; |
| 10343 |
return 0; |
| 10344 |
} |
| 10345 |
} else { |
| 10346 |
|
| 10347 |
/* RANGE='A' or 'V' -- Set ATOLI */ |
| 10348 |
|
| 10349 |
/* Computing MAX */ |
| 10350 |
d__3 = abs(d__[1]) + abs(e[1]), d__4 = (d__1 = d__[*n], abs(d__1)) + ( |
| 10351 |
d__2 = e[*n - 1], abs(d__2)); |
| 10352 |
tnorm = std::max(d__3,d__4); |
| 10353 |
|
| 10354 |
i__1 = *n - 1; |
| 10355 |
for (j = 2; j <= i__1; ++j) { |
| 10356 |
/* Computing MAX */ |
| 10357 |
d__4 = tnorm, d__5 = (d__1 = d__[j], abs(d__1)) + (d__2 = e[j - 1] |
| 10358 |
, abs(d__2)) + (d__3 = e[j], abs(d__3)); |
| 10359 |
tnorm = std::max(d__4,d__5); |
| 10360 |
/* L30: */ |
| 10361 |
} |
| 10362 |
|
| 10363 |
if (*abstol <= 0.) { |
| 10364 |
atoli = ulp * tnorm; |
| 10365 |
} else { |
| 10366 |
atoli = *abstol; |
| 10367 |
} |
| 10368 |
|
| 10369 |
if (irange == 2) { |
| 10370 |
wl = *vl; |
| 10371 |
wu = *vu; |
| 10372 |
} else { |
| 10373 |
wl = 0.; |
| 10374 |
wu = 0.; |
| 10375 |
} |
| 10376 |
} |
| 10377 |
|
| 10378 |
/* Find Eigenvalues -- Loop Over Blocks and recompute NWL and NWU. */ |
| 10379 |
/* NWL accumulates the number of eigenvalues .le. WL, */ |
| 10380 |
/* NWU accumulates the number of eigenvalues .le. WU */ |
| 10381 |
|
| 10382 |
*m = 0; |
| 10383 |
iend = 0; |
| 10384 |
*info = 0; |
| 10385 |
nwl = 0; |
| 10386 |
nwu = 0; |
| 10387 |
|
| 10388 |
i__1 = *nsplit; |
| 10389 |
for (jb = 1; jb <= i__1; ++jb) { |
| 10390 |
ioff = iend; |
| 10391 |
ibegin = ioff + 1; |
| 10392 |
iend = isplit[jb]; |
| 10393 |
in = iend - ioff; |
| 10394 |
|
| 10395 |
if (in == 1) { |
| 10396 |
|
| 10397 |
/* Special Case -- IN=1 */ |
| 10398 |
|
| 10399 |
if (irange == 1 || wl >= d__[ibegin] - pivmin) { |
| 10400 |
++nwl; |
| 10401 |
} |
| 10402 |
if (irange == 1 || wu >= d__[ibegin] - pivmin) { |
| 10403 |
++nwu; |
| 10404 |
} |
| 10405 |
if (irange == 1 || wl < d__[ibegin] - pivmin && wu >= d__[ibegin] |
| 10406 |
- pivmin) { |
| 10407 |
++(*m); |
| 10408 |
w[*m] = d__[ibegin]; |
| 10409 |
iblock[*m] = jb; |
| 10410 |
} |
| 10411 |
} else { |
| 10412 |
|
| 10413 |
/* General Case -- IN > 1 */ |
| 10414 |
|
| 10415 |
/* Compute Gershgorin Interval */ |
| 10416 |
/* and use it as the initial interval */ |
| 10417 |
|
| 10418 |
gu = d__[ibegin]; |
| 10419 |
gl = d__[ibegin]; |
| 10420 |
tmp1 = 0.; |
| 10421 |
|
| 10422 |
i__2 = iend - 1; |
| 10423 |
for (j = ibegin; j <= i__2; ++j) { |
| 10424 |
tmp2 = (d__1 = e[j], abs(d__1)); |
| 10425 |
/* Computing MAX */ |
| 10426 |
d__1 = gu, d__2 = d__[j] + tmp1 + tmp2; |
| 10427 |
gu = std::max(d__1,d__2); |
| 10428 |
/* Computing MIN */ |
| 10429 |
d__1 = gl, d__2 = d__[j] - tmp1 - tmp2; |
| 10430 |
gl = std::min(d__1,d__2); |
| 10431 |
tmp1 = tmp2; |
| 10432 |
/* L40: */ |
| 10433 |
} |
| 10434 |
|
| 10435 |
/* Computing MAX */ |
| 10436 |
d__1 = gu, d__2 = d__[iend] + tmp1; |
| 10437 |
gu = std::max(d__1,d__2); |
| 10438 |
/* Computing MIN */ |
| 10439 |
d__1 = gl, d__2 = d__[iend] - tmp1; |
| 10440 |
gl = std::min(d__1,d__2); |
| 10441 |
/* Computing MAX */ |
| 10442 |
d__1 = abs(gl), d__2 = abs(gu); |
| 10443 |
bnorm = std::max(d__1,d__2); |
| 10444 |
gl = gl - bnorm * 2.1 * ulp * in - pivmin * 2.1; |
| 10445 |
gu = gu + bnorm * 2.1 * ulp * in + pivmin * 2.1; |
| 10446 |
|
| 10447 |
/* Compute ATOLI for the current submatrix */ |
| 10448 |
|
| 10449 |
if (*abstol <= 0.) { |
| 10450 |
/* Computing MAX */ |
| 10451 |
d__1 = abs(gl), d__2 = abs(gu); |
| 10452 |
atoli = ulp * std::max(d__1,d__2); |
| 10453 |
} else { |
| 10454 |
atoli = *abstol; |
| 10455 |
} |
| 10456 |
|
| 10457 |
if (irange > 1) { |
| 10458 |
if (gu < wl) { |
| 10459 |
nwl += in; |
| 10460 |
nwu += in; |
| 10461 |
goto L70; |
| 10462 |
} |
| 10463 |
gl = std::max(gl,wl); |
| 10464 |
gu = std::min(gu,wu); |
| 10465 |
if (gl >= gu) { |
| 10466 |
goto L70; |
| 10467 |
} |
| 10468 |
} |
| 10469 |
|
| 10470 |
/* Set Up Initial Interval */ |
| 10471 |
|
| 10472 |
work[*n + 1] = gl; |
| 10473 |
work[*n + in + 1] = gu; |
| 10474 |
dlaebz_(&c__1, &c__0, &in, &in, &c__1, &nb, &atoli, &rtoli, & |
| 10475 |
pivmin, &d__[ibegin], &e[ibegin], &work[ibegin], idumma, & |
| 10476 |
work[*n + 1], &work[*n + (in << 1) + 1], &im, &iwork[1], & |
| 10477 |
w[*m + 1], &iblock[*m + 1], &iinfo); |
| 10478 |
|
| 10479 |
nwl += iwork[1]; |
| 10480 |
nwu += iwork[in + 1]; |
| 10481 |
iwoff = *m - iwork[1]; |
| 10482 |
|
| 10483 |
/* Compute Eigenvalues */ |
| 10484 |
|
| 10485 |
itmax = (integer) ((log(gu - gl + pivmin) - log(pivmin)) / log(2.) |
| 10486 |
) + 2; |
| 10487 |
dlaebz_(&c__2, &itmax, &in, &in, &c__1, &nb, &atoli, &rtoli, & |
| 10488 |
pivmin, &d__[ibegin], &e[ibegin], &work[ibegin], idumma, & |
| 10489 |
work[*n + 1], &work[*n + (in << 1) + 1], &iout, &iwork[1], |
| 10490 |
&w[*m + 1], &iblock[*m + 1], &iinfo); |
| 10491 |
|
| 10492 |
/* Copy Eigenvalues Into W and IBLOCK */ |
| 10493 |
/* Use -JB for block number for unconverged eigenvalues. */ |
| 10494 |
|
| 10495 |
i__2 = iout; |
| 10496 |
for (j = 1; j <= i__2; ++j) { |
| 10497 |
tmp1 = (work[j + *n] + work[j + in + *n]) * .5; |
| 10498 |
|
| 10499 |
/* Flag non-convergence. */ |
| 10500 |
|
| 10501 |
if (j > iout - iinfo) { |
| 10502 |
ncnvrg = true; |
| 10503 |
ib = -jb; |
| 10504 |
} else { |
| 10505 |
ib = jb; |
| 10506 |
} |
| 10507 |
i__3 = iwork[j + in] + iwoff; |
| 10508 |
for (je = iwork[j] + 1 + iwoff; je <= i__3; ++je) { |
| 10509 |
w[je] = tmp1; |
| 10510 |
iblock[je] = ib; |
| 10511 |
/* L50: */ |
| 10512 |
} |
| 10513 |
/* L60: */ |
| 10514 |
} |
| 10515 |
|
| 10516 |
*m += im; |
| 10517 |
} |
| 10518 |
L70: |
| 10519 |
; |
| 10520 |
} |
| 10521 |
|
| 10522 |
/* If RANGE='I', then (WL,WU) contains eigenvalues NWL+1,...,NWU */ |
| 10523 |
/* If NWL+1 < IL or NWU > IU, discard extra eigenvalues. */ |
| 10524 |
|
| 10525 |
if (irange == 3) { |
| 10526 |
im = 0; |
| 10527 |
idiscl = *il - 1 - nwl; |
| 10528 |
idiscu = nwu - *iu; |
| 10529 |
|
| 10530 |
if (idiscl > 0 || idiscu > 0) { |
| 10531 |
i__1 = *m; |
| 10532 |
for (je = 1; je <= i__1; ++je) { |
| 10533 |
if (w[je] <= wlu && idiscl > 0) { |
| 10534 |
--idiscl; |
| 10535 |
} else if (w[je] >= wul && idiscu > 0) { |
| 10536 |
--idiscu; |
| 10537 |
} else { |
| 10538 |
++im; |
| 10539 |
w[im] = w[je]; |
| 10540 |
iblock[im] = iblock[je]; |
| 10541 |
} |
| 10542 |
/* L80: */ |
| 10543 |
} |
| 10544 |
*m = im; |
| 10545 |
} |
| 10546 |
if (idiscl > 0 || idiscu > 0) { |
| 10547 |
|
| 10548 |
/* Code to deal with effects of bad arithmetic: */ |
| 10549 |
/* Some low eigenvalues to be discarded are not in (WL,WLU], */ |
| 10550 |
/* or high eigenvalues to be discarded are not in (WUL,WU] */ |
| 10551 |
/* so just kill off the smallest IDISCL/largest IDISCU */ |
| 10552 |
/* eigenvalues, by simply finding the smallest/largest */ |
| 10553 |
/* eigenvalue(s). */ |
| 10554 |
|
| 10555 |
/* (If N(w) is monotone non-decreasing, this should never */ |
| 10556 |
/* happen.) */ |
| 10557 |
|
| 10558 |
if (idiscl > 0) { |
| 10559 |
wkill = wu; |
| 10560 |
i__1 = idiscl; |
| 10561 |
for (jdisc = 1; jdisc <= i__1; ++jdisc) { |
| 10562 |
iw = 0; |
| 10563 |
i__2 = *m; |
| 10564 |
for (je = 1; je <= i__2; ++je) { |
| 10565 |
if (iblock[je] != 0 && (w[je] < wkill || iw == 0)) { |
| 10566 |
iw = je; |
| 10567 |
wkill = w[je]; |
| 10568 |
} |
| 10569 |
/* L90: */ |
| 10570 |
} |
| 10571 |
iblock[iw] = 0; |
| 10572 |
/* L100: */ |
| 10573 |
} |
| 10574 |
} |
| 10575 |
if (idiscu > 0) { |
| 10576 |
|
| 10577 |
wkill = wl; |
| 10578 |
i__1 = idiscu; |
| 10579 |
for (jdisc = 1; jdisc <= i__1; ++jdisc) { |
| 10580 |
iw = 0; |
| 10581 |
i__2 = *m; |
| 10582 |
for (je = 1; je <= i__2; ++je) { |
| 10583 |
if (iblock[je] != 0 && (w[je] > wkill || iw == 0)) { |
| 10584 |
iw = je; |
| 10585 |
wkill = w[je]; |
| 10586 |
} |
| 10587 |
/* L110: */ |
| 10588 |
} |
| 10589 |
iblock[iw] = 0; |
| 10590 |
/* L120: */ |
| 10591 |
} |
| 10592 |
} |
| 10593 |
im = 0; |
| 10594 |
i__1 = *m; |
| 10595 |
for (je = 1; je <= i__1; ++je) { |
| 10596 |
if (iblock[je] != 0) { |
| 10597 |
++im; |
| 10598 |
w[im] = w[je]; |
| 10599 |
iblock[im] = iblock[je]; |
| 10600 |
} |
| 10601 |
/* L130: */ |
| 10602 |
} |
| 10603 |
*m = im; |
| 10604 |
} |
| 10605 |
if (idiscl < 0 || idiscu < 0) { |
| 10606 |
toofew = true; |
| 10607 |
} |
| 10608 |
} |
| 10609 |
|
| 10610 |
/* If ORDER='B', do nothing -- the eigenvalues are already sorted */ |
| 10611 |
/* by block. */ |
| 10612 |
/* If ORDER='E', sort the eigenvalues from smallest to largest */ |
| 10613 |
|
| 10614 |
if (iorder == 1 && *nsplit > 1) { |
| 10615 |
i__1 = *m - 1; |
| 10616 |
for (je = 1; je <= i__1; ++je) { |
| 10617 |
ie = 0; |
| 10618 |
tmp1 = w[je]; |
| 10619 |
i__2 = *m; |
| 10620 |
for (j = je + 1; j <= i__2; ++j) { |
| 10621 |
if (w[j] < tmp1) { |
| 10622 |
ie = j; |
| 10623 |
tmp1 = w[j]; |
| 10624 |
} |
| 10625 |
/* L140: */ |
| 10626 |
} |
| 10627 |
|
| 10628 |
if (ie != 0) { |
| 10629 |
itmp1 = iblock[ie]; |
| 10630 |
w[ie] = w[je]; |
| 10631 |
iblock[ie] = iblock[je]; |
| 10632 |
w[je] = tmp1; |
| 10633 |
iblock[je] = itmp1; |
| 10634 |
} |
| 10635 |
/* L150: */ |
| 10636 |
} |
| 10637 |
} |
| 10638 |
|
| 10639 |
*info = 0; |
| 10640 |
if (ncnvrg) { |
| 10641 |
++(*info); |
| 10642 |
} |
| 10643 |
if (toofew) { |
| 10644 |
*info += 2; |
| 10645 |
} |
| 10646 |
return 0; |
| 10647 |
|
| 10648 |
/* End of DSTEBZ */ |
| 10649 |
|
| 10650 |
} /* dstebz_ */ |
| 10651 |
|
| 10652 |
/* Subroutine */ int dstedc_(const char *compz, integer *n, double *d__, |
| 10653 |
double *e, double *z__, integer *ldz, double *work, |
| 10654 |
integer *lwork, integer *iwork, integer *liwork, integer *info) |
| 10655 |
{ |
| 10656 |
/* Table of constant values */ |
| 10657 |
static integer c__9 = 9; |
| 10658 |
static integer c__0 = 0; |
| 10659 |
static integer c__2 = 2; |
| 10660 |
static double c_b17 = 0.; |
| 10661 |
static double c_b18 = 1.; |
| 10662 |
static integer c__1 = 1; |
| 10663 |
|
| 10664 |
/* System generated locals */ |
| 10665 |
integer z_dim1, z_offset, i__1, i__2; |
| 10666 |
double d__1, d__2; |
| 10667 |
|
| 10668 |
/* Local variables */ |
| 10669 |
integer i__, j, k, m; |
| 10670 |
double p; |
| 10671 |
integer ii, lgn; |
| 10672 |
double eps, tiny; |
| 10673 |
integer lwmin; |
| 10674 |
integer start; |
| 10675 |
integer finish; |
| 10676 |
integer liwmin, icompz; |
| 10677 |
double orgnrm; |
| 10678 |
bool lquery; |
| 10679 |
integer smlsiz, storez, strtrw; |
| 10680 |
|
| 10681 |
|
| 10682 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 10683 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 10684 |
/* November 2006 */ |
| 10685 |
|
| 10686 |
/* .. Scalar Arguments .. */ |
| 10687 |
/* .. */ |
| 10688 |
/* .. Array Arguments .. */ |
| 10689 |
/* .. */ |
| 10690 |
|
| 10691 |
/* Purpose */ |
| 10692 |
/* ======= */ |
| 10693 |
|
| 10694 |
/* DSTEDC computes all eigenvalues and, optionally, eigenvectors of a */ |
| 10695 |
/* symmetric tridiagonal matrix using the divide and conquer method. */ |
| 10696 |
/* The eigenvectors of a full or band real symmetric matrix can also be */ |
| 10697 |
/* found if DSYTRD or DSPTRD or DSBTRD has been used to reduce this */ |
| 10698 |
/* matrix to tridiagonal form. */ |
| 10699 |
|
| 10700 |
/* This code makes very mild assumptions about floating point */ |
| 10701 |
/* arithmetic. It will work on machines with a guard digit in */ |
| 10702 |
/* add/subtract, or on those binary machines without guard digits */ |
| 10703 |
/* which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2. */ |
| 10704 |
/* It could conceivably fail on hexadecimal or decimal machines */ |
| 10705 |
/* without guard digits, but we know of none. See DLAED3 for details. */ |
| 10706 |
|
| 10707 |
/* Arguments */ |
| 10708 |
/* ========= */ |
| 10709 |
|
| 10710 |
/* COMPZ (input) CHARACTER*1 */ |
| 10711 |
/* = 'N': Compute eigenvalues only. */ |
| 10712 |
/* = 'I': Compute eigenvectors of tridiagonal matrix also. */ |
| 10713 |
/* = 'V': Compute eigenvectors of original dense symmetric */ |
| 10714 |
/* matrix also. On entry, Z contains the orthogonal */ |
| 10715 |
/* matrix used to reduce the original matrix to */ |
| 10716 |
/* tridiagonal form. */ |
| 10717 |
|
| 10718 |
/* N (input) INTEGER */ |
| 10719 |
/* The dimension of the symmetric tridiagonal matrix. N >= 0. */ |
| 10720 |
|
| 10721 |
/* D (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 10722 |
/* On entry, the diagonal elements of the tridiagonal matrix. */ |
| 10723 |
/* On exit, if INFO = 0, the eigenvalues in ascending order. */ |
| 10724 |
|
| 10725 |
/* E (input/output) DOUBLE PRECISION array, dimension (N-1) */ |
| 10726 |
/* On entry, the subdiagonal elements of the tridiagonal matrix. */ |
| 10727 |
/* On exit, E has been destroyed. */ |
| 10728 |
|
| 10729 |
/* Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N) */ |
| 10730 |
/* On entry, if COMPZ = 'V', then Z contains the orthogonal */ |
| 10731 |
/* matrix used in the reduction to tridiagonal form. */ |
| 10732 |
/* On exit, if INFO = 0, then if COMPZ = 'V', Z contains the */ |
| 10733 |
/* orthonormal eigenvectors of the original symmetric matrix, */ |
| 10734 |
/* and if COMPZ = 'I', Z contains the orthonormal eigenvectors */ |
| 10735 |
/* of the symmetric tridiagonal matrix. */ |
| 10736 |
/* If COMPZ = 'N', then Z is not referenced. */ |
| 10737 |
|
| 10738 |
/* LDZ (input) INTEGER */ |
| 10739 |
/* The leading dimension of the array Z. LDZ >= 1. */ |
| 10740 |
/* If eigenvectors are desired, then LDZ >= max(1,N). */ |
| 10741 |
|
| 10742 |
/* WORK (workspace/output) DOUBLE PRECISION array, */ |
| 10743 |
/* dimension (LWORK) */ |
| 10744 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 10745 |
|
| 10746 |
/* LWORK (input) INTEGER */ |
| 10747 |
/* The dimension of the array WORK. */ |
| 10748 |
/* If COMPZ = 'N' or N <= 1 then LWORK must be at least 1. */ |
| 10749 |
/* If COMPZ = 'V' and N > 1 then LWORK must be at least */ |
| 10750 |
/* ( 1 + 3*N + 2*N*lg N + 3*N**2 ), */ |
| 10751 |
/* where lg( N ) = smallest integer k such */ |
| 10752 |
/* that 2**k >= N. */ |
| 10753 |
/* If COMPZ = 'I' and N > 1 then LWORK must be at least */ |
| 10754 |
/* ( 1 + 4*N + N**2 ). */ |
| 10755 |
/* Note that for COMPZ = 'I' or 'V', then if N is less than or */ |
| 10756 |
/* equal to the minimum divide size, usually 25, then LWORK need */ |
| 10757 |
/* only be max(1,2*(N-1)). */ |
| 10758 |
|
| 10759 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 10760 |
/* only calculates the optimal size of the WORK array, returns */ |
| 10761 |
/* this value as the first entry of the WORK array, and no error */ |
| 10762 |
/* message related to LWORK is issued by XERBLA. */ |
| 10763 |
|
| 10764 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 10765 |
/* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ |
| 10766 |
|
| 10767 |
/* LIWORK (input) INTEGER */ |
| 10768 |
/* The dimension of the array IWORK. */ |
| 10769 |
/* If COMPZ = 'N' or N <= 1 then LIWORK must be at least 1. */ |
| 10770 |
/* If COMPZ = 'V' and N > 1 then LIWORK must be at least */ |
| 10771 |
/* ( 6 + 6*N + 5*N*lg N ). */ |
| 10772 |
/* If COMPZ = 'I' and N > 1 then LIWORK must be at least */ |
| 10773 |
/* ( 3 + 5*N ). */ |
| 10774 |
/* Note that for COMPZ = 'I' or 'V', then if N is less than or */ |
| 10775 |
/* equal to the minimum divide size, usually 25, then LIWORK */ |
| 10776 |
/* need only be 1. */ |
| 10777 |
|
| 10778 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 10779 |
/* routine only calculates the optimal size of the IWORK array, */ |
| 10780 |
/* returns this value as the first entry of the IWORK array, and */ |
| 10781 |
/* no error message related to LIWORK is issued by XERBLA. */ |
| 10782 |
|
| 10783 |
/* INFO (output) INTEGER */ |
| 10784 |
/* = 0: successful exit. */ |
| 10785 |
/* < 0: if INFO = -i, the i-th argument had an illegal value. */ |
| 10786 |
/* > 0: The algorithm failed to compute an eigenvalue while */ |
| 10787 |
/* working on the submatrix lying in rows and columns */ |
| 10788 |
/* INFO/(N+1) through mod(INFO,N+1). */ |
| 10789 |
|
| 10790 |
/* Further Details */ |
| 10791 |
/* =============== */ |
| 10792 |
|
| 10793 |
/* Based on contributions by */ |
| 10794 |
/* Jeff Rutter, Computer Science Division, University of California */ |
| 10795 |
/* at Berkeley, USA */ |
| 10796 |
/* Modified by Francoise Tisseur, University of Tennessee. */ |
| 10797 |
|
| 10798 |
/* ===================================================================== */ |
| 10799 |
|
| 10800 |
/* .. Parameters .. */ |
| 10801 |
/* .. */ |
| 10802 |
/* .. Local Scalars .. */ |
| 10803 |
/* .. */ |
| 10804 |
/* .. External Functions .. */ |
| 10805 |
/* .. */ |
| 10806 |
/* .. External Subroutines .. */ |
| 10807 |
/* .. */ |
| 10808 |
/* .. Intrinsic Functions .. */ |
| 10809 |
/* .. */ |
| 10810 |
/* .. Executable Statements .. */ |
| 10811 |
|
| 10812 |
/* Test the input parameters. */ |
| 10813 |
|
| 10814 |
/* Parameter adjustments */ |
| 10815 |
--d__; |
| 10816 |
--e; |
| 10817 |
z_dim1 = *ldz; |
| 10818 |
z_offset = 1 + z_dim1; |
| 10819 |
z__ -= z_offset; |
| 10820 |
--work; |
| 10821 |
--iwork; |
| 10822 |
|
| 10823 |
/* Function Body */ |
| 10824 |
*info = 0; |
| 10825 |
lquery = *lwork == -1 || *liwork == -1; |
| 10826 |
|
| 10827 |
if (lsame_(compz, "N")) { |
| 10828 |
icompz = 0; |
| 10829 |
} else if (lsame_(compz, "V")) { |
| 10830 |
icompz = 1; |
| 10831 |
} else if (lsame_(compz, "I")) { |
| 10832 |
icompz = 2; |
| 10833 |
} else { |
| 10834 |
icompz = -1; |
| 10835 |
} |
| 10836 |
if (icompz < 0) { |
| 10837 |
*info = -1; |
| 10838 |
} else if (*n < 0) { |
| 10839 |
*info = -2; |
| 10840 |
} else if (*ldz < 1 || icompz > 0 && *ldz < std::max(1_integer,*n)) { |
| 10841 |
*info = -6; |
| 10842 |
} |
| 10843 |
|
| 10844 |
if (*info == 0) { |
| 10845 |
|
| 10846 |
/* Compute the workspace requirements */ |
| 10847 |
|
| 10848 |
smlsiz = ilaenv_(&c__9, "DSTEDC", " ", &c__0, &c__0, &c__0, &c__0); |
| 10849 |
if (*n <= 1 || icompz == 0) { |
| 10850 |
liwmin = 1; |
| 10851 |
lwmin = 1; |
| 10852 |
} else if (*n <= smlsiz) { |
| 10853 |
liwmin = 1; |
| 10854 |
lwmin = *n - 1 << 1; |
| 10855 |
} else { |
| 10856 |
lgn = (integer) (log((double) (*n)) / log(2.)); |
| 10857 |
if (pow_ii(&c__2, &lgn) < *n) { |
| 10858 |
++lgn; |
| 10859 |
} |
| 10860 |
if (pow_ii(&c__2, &lgn) < *n) { |
| 10861 |
++lgn; |
| 10862 |
} |
| 10863 |
if (icompz == 1) { |
| 10864 |
/* Computing 2nd power */ |
| 10865 |
i__1 = *n; |
| 10866 |
lwmin = *n * 3 + 1 + (*n << 1) * lgn + i__1 * i__1 * 3; |
| 10867 |
liwmin = *n * 6 + 6 + *n * 5 * lgn; |
| 10868 |
} else if (icompz == 2) { |
| 10869 |
/* Computing 2nd power */ |
| 10870 |
i__1 = *n; |
| 10871 |
lwmin = (*n << 2) + 1 + i__1 * i__1; |
| 10872 |
liwmin = *n * 5 + 3; |
| 10873 |
} |
| 10874 |
} |
| 10875 |
work[1] = (double) lwmin; |
| 10876 |
iwork[1] = liwmin; |
| 10877 |
|
| 10878 |
if (*lwork < lwmin && ! lquery) { |
| 10879 |
*info = -8; |
| 10880 |
} else if (*liwork < liwmin && ! lquery) { |
| 10881 |
*info = -10; |
| 10882 |
} |
| 10883 |
} |
| 10884 |
|
| 10885 |
if (*info != 0) { |
| 10886 |
i__1 = -(*info); |
| 10887 |
xerbla_("DSTEDC", &i__1); |
| 10888 |
return 0; |
| 10889 |
} else if (lquery) { |
| 10890 |
return 0; |
| 10891 |
} |
| 10892 |
|
| 10893 |
/* Quick return if possible */ |
| 10894 |
|
| 10895 |
if (*n == 0) { |
| 10896 |
return 0; |
| 10897 |
} |
| 10898 |
if (*n == 1) { |
| 10899 |
if (icompz != 0) { |
| 10900 |
z__[z_dim1 + 1] = 1.; |
| 10901 |
} |
| 10902 |
return 0; |
| 10903 |
} |
| 10904 |
|
| 10905 |
/* If the following conditional clause is removed, then the routine */ |
| 10906 |
/* will use the Divide and Conquer routine to compute only the */ |
| 10907 |
/* eigenvalues, which requires (3N + 3N**2) real workspace and */ |
| 10908 |
/* (2 + 5N + 2N lg(N)) integer workspace. */ |
| 10909 |
/* Since on many architectures DSTERF is much faster than any other */ |
| 10910 |
/* algorithm for finding eigenvalues only, it is used here */ |
| 10911 |
/* as the default. If the conditional clause is removed, then */ |
| 10912 |
/* information on the size of workspace needs to be changed. */ |
| 10913 |
|
| 10914 |
/* If COMPZ = 'N', use DSTERF to compute the eigenvalues. */ |
| 10915 |
|
| 10916 |
if (icompz == 0) { |
| 10917 |
dsterf_(n, &d__[1], &e[1], info); |
| 10918 |
goto L50; |
| 10919 |
} |
| 10920 |
|
| 10921 |
/* If N is smaller than the minimum divide size (SMLSIZ+1), then */ |
| 10922 |
/* solve the problem with another solver. */ |
| 10923 |
|
| 10924 |
if (*n <= smlsiz) { |
| 10925 |
|
| 10926 |
dsteqr_(compz, n, &d__[1], &e[1], &z__[z_offset], ldz, &work[1], info); |
| 10927 |
|
| 10928 |
} else { |
| 10929 |
|
| 10930 |
/* If COMPZ = 'V', the Z matrix must be stored elsewhere for later */ |
| 10931 |
/* use. */ |
| 10932 |
|
| 10933 |
if (icompz == 1) { |
| 10934 |
storez = *n * *n + 1; |
| 10935 |
} else { |
| 10936 |
storez = 1; |
| 10937 |
} |
| 10938 |
|
| 10939 |
if (icompz == 2) { |
| 10940 |
dlaset_("Full", n, n, &c_b17, &c_b18, &z__[z_offset], ldz); |
| 10941 |
} |
| 10942 |
|
| 10943 |
/* Scale. */ |
| 10944 |
|
| 10945 |
orgnrm = dlanst_("M", n, &d__[1], &e[1]); |
| 10946 |
if (orgnrm == 0.) { |
| 10947 |
goto L50; |
| 10948 |
} |
| 10949 |
|
| 10950 |
eps = dlamch_("Epsilon"); |
| 10951 |
|
| 10952 |
start = 1; |
| 10953 |
|
| 10954 |
/* while ( START <= N ) */ |
| 10955 |
|
| 10956 |
L10: |
| 10957 |
if (start <= *n) { |
| 10958 |
|
| 10959 |
/* Let FINISH be the position of the next subdiagonal entry */ |
| 10960 |
/* such that E( FINISH ) <= TINY or FINISH = N if no such */ |
| 10961 |
/* subdiagonal exists. The matrix identified by the elements */ |
| 10962 |
/* between START and FINISH constitutes an independent */ |
| 10963 |
/* sub-problem. */ |
| 10964 |
|
| 10965 |
finish = start; |
| 10966 |
L20: |
| 10967 |
if (finish < *n) { |
| 10968 |
tiny = eps * sqrt((d__1 = d__[finish], abs(d__1))) * sqrt(( |
| 10969 |
d__2 = d__[finish + 1], abs(d__2))); |
| 10970 |
if ((d__1 = e[finish], abs(d__1)) > tiny) { |
| 10971 |
++finish; |
| 10972 |
goto L20; |
| 10973 |
} |
| 10974 |
} |
| 10975 |
|
| 10976 |
/* (Sub) Problem determined. Compute its size and solve it. */ |
| 10977 |
|
| 10978 |
m = finish - start + 1; |
| 10979 |
if (m == 1) { |
| 10980 |
start = finish + 1; |
| 10981 |
goto L10; |
| 10982 |
} |
| 10983 |
if (m > smlsiz) { |
| 10984 |
|
| 10985 |
/* Scale. */ |
| 10986 |
|
| 10987 |
orgnrm = dlanst_("M", &m, &d__[start], &e[start]); |
| 10988 |
dlascl_("G", &c__0, &c__0, &orgnrm, &c_b18, &m, &c__1, &d__[ |
| 10989 |
start], &m, info); |
| 10990 |
i__1 = m - 1; |
| 10991 |
i__2 = m - 1; |
| 10992 |
dlascl_("G", &c__0, &c__0, &orgnrm, &c_b18, &i__1, &c__1, &e[ |
| 10993 |
start], &i__2, info); |
| 10994 |
|
| 10995 |
if (icompz == 1) { |
| 10996 |
strtrw = 1; |
| 10997 |
} else { |
| 10998 |
strtrw = start; |
| 10999 |
} |
| 11000 |
dlaed0_(&icompz, n, &m, &d__[start], &e[start], &z__[strtrw + |
| 11001 |
start * z_dim1], ldz, &work[1], n, &work[storez], & |
| 11002 |
iwork[1], info); |
| 11003 |
if (*info != 0) { |
| 11004 |
*info = (*info / (m + 1) + start - 1) * (*n + 1) + *info % |
| 11005 |
(m + 1) + start - 1; |
| 11006 |
goto L50; |
| 11007 |
} |
| 11008 |
|
| 11009 |
/* Scale back. */ |
| 11010 |
|
| 11011 |
dlascl_("G", &c__0, &c__0, &c_b18, &orgnrm, &m, &c__1, &d__[ |
| 11012 |
start], &m, info); |
| 11013 |
|
| 11014 |
} else { |
| 11015 |
if (icompz == 1) { |
| 11016 |
|
| 11017 |
/* Since QR won't update a Z matrix which is larger than */ |
| 11018 |
/* the length of D, we must solve the sub-problem in a */ |
| 11019 |
/* workspace and then multiply back into Z. */ |
| 11020 |
|
| 11021 |
dsteqr_("I", &m, &d__[start], &e[start], &work[1], &m, & |
| 11022 |
work[m * m + 1], info); |
| 11023 |
dlacpy_("A", n, &m, &z__[start * z_dim1 + 1], ldz, &work[ |
| 11024 |
storez], n); |
| 11025 |
dgemm_("N", "N", n, &m, &m, &c_b18, &work[storez], n, & |
| 11026 |
work[1], &m, &c_b17, &z__[start * z_dim1 + 1], |
| 11027 |
ldz); |
| 11028 |
} else if (icompz == 2) { |
| 11029 |
dsteqr_("I", &m, &d__[start], &e[start], &z__[start + |
| 11030 |
start * z_dim1], ldz, &work[1], info); |
| 11031 |
} else { |
| 11032 |
dsterf_(&m, &d__[start], &e[start], info); |
| 11033 |
} |
| 11034 |
if (*info != 0) { |
| 11035 |
*info = start * (*n + 1) + finish; |
| 11036 |
goto L50; |
| 11037 |
} |
| 11038 |
} |
| 11039 |
|
| 11040 |
start = finish + 1; |
| 11041 |
goto L10; |
| 11042 |
} |
| 11043 |
|
| 11044 |
/* endwhile */ |
| 11045 |
|
| 11046 |
/* If the problem split any number of times, then the eigenvalues */ |
| 11047 |
/* will not be properly ordered. Here we permute the eigenvalues */ |
| 11048 |
/* (and the associated eigenvectors) into ascending order. */ |
| 11049 |
|
| 11050 |
if (m != *n) { |
| 11051 |
if (icompz == 0) { |
| 11052 |
|
| 11053 |
/* Use Quick Sort */ |
| 11054 |
|
| 11055 |
dlasrt_("I", n, &d__[1], info); |
| 11056 |
|
| 11057 |
} else { |
| 11058 |
|
| 11059 |
/* Use Selection Sort to minimize swaps of eigenvectors */ |
| 11060 |
|
| 11061 |
i__1 = *n; |
| 11062 |
for (ii = 2; ii <= i__1; ++ii) { |
| 11063 |
i__ = ii - 1; |
| 11064 |
k = i__; |
| 11065 |
p = d__[i__]; |
| 11066 |
i__2 = *n; |
| 11067 |
for (j = ii; j <= i__2; ++j) { |
| 11068 |
if (d__[j] < p) { |
| 11069 |
k = j; |
| 11070 |
p = d__[j]; |
| 11071 |
} |
| 11072 |
/* L30: */ |
| 11073 |
} |
| 11074 |
if (k != i__) { |
| 11075 |
d__[k] = d__[i__]; |
| 11076 |
d__[i__] = p; |
| 11077 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[k * |
| 11078 |
z_dim1 + 1], &c__1); |
| 11079 |
} |
| 11080 |
/* L40: */ |
| 11081 |
} |
| 11082 |
} |
| 11083 |
} |
| 11084 |
} |
| 11085 |
|
| 11086 |
L50: |
| 11087 |
work[1] = (double) lwmin; |
| 11088 |
iwork[1] = liwmin; |
| 11089 |
|
| 11090 |
return 0; |
| 11091 |
|
| 11092 |
/* End of DSTEDC */ |
| 11093 |
|
| 11094 |
} /* dstedc_ */ |
| 11095 |
|
| 11096 |
/* Subroutine */ int dstegr_(const char *jobz, const char *range, integer *n, double * |
| 11097 |
d__, double *e, double *vl, double *vu, integer *il, |
| 11098 |
integer *iu, double *abstol, integer *m, double *w, |
| 11099 |
double *z__, integer *ldz, integer *isuppz, double *work, |
| 11100 |
integer *lwork, integer *iwork, integer *liwork, integer *info) |
| 11101 |
{ |
| 11102 |
/* System generated locals */ |
| 11103 |
integer z_dim1, z_offset; |
| 11104 |
|
| 11105 |
/* Local variables */ |
| 11106 |
bool tryrac; |
| 11107 |
|
| 11108 |
|
| 11109 |
/* -- LAPACK computational routine (version 3.1) -- */ |
| 11110 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 11111 |
/* November 2006 */ |
| 11112 |
|
| 11113 |
/* .. Scalar Arguments .. */ |
| 11114 |
/* .. */ |
| 11115 |
/* .. Array Arguments .. */ |
| 11116 |
/* .. */ |
| 11117 |
|
| 11118 |
/* Purpose */ |
| 11119 |
/* ======= */ |
| 11120 |
|
| 11121 |
/* DSTEGR computes selected eigenvalues and, optionally, eigenvectors */ |
| 11122 |
/* of a real symmetric tridiagonal matrix T. Any such unreduced matrix has */ |
| 11123 |
/* a well defined set of pairwise different real eigenvalues, the corresponding */ |
| 11124 |
/* real eigenvectors are pairwise orthogonal. */ |
| 11125 |
|
| 11126 |
/* The spectrum may be computed either completely or partially by specifying */ |
| 11127 |
/* either an interval (VL,VU] or a range of indices IL:IU for the desired */ |
| 11128 |
/* eigenvalues. */ |
| 11129 |
|
| 11130 |
/* DSTEGR is a compatability wrapper around the improved DSTEMR routine. */ |
| 11131 |
/* See DSTEMR for further details. */ |
| 11132 |
|
| 11133 |
/* One important change is that the ABSTOL parameter no longer provides any */ |
| 11134 |
/* benefit and hence is no longer used. */ |
| 11135 |
|
| 11136 |
/* Note : DSTEGR and DSTEMR work only on machines which follow */ |
| 11137 |
/* IEEE-754 floating-point standard in their handling of infinities and */ |
| 11138 |
/* NaNs. Normal execution may create these exceptiona values and hence */ |
| 11139 |
/* may abort due to a floating point exception in environments which */ |
| 11140 |
/* do not conform to the IEEE-754 standard. */ |
| 11141 |
|
| 11142 |
/* Arguments */ |
| 11143 |
/* ========= */ |
| 11144 |
|
| 11145 |
/* JOBZ (input) CHARACTER*1 */ |
| 11146 |
/* = 'N': Compute eigenvalues only; */ |
| 11147 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 11148 |
|
| 11149 |
/* RANGE (input) CHARACTER*1 */ |
| 11150 |
/* = 'A': all eigenvalues will be found. */ |
| 11151 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 11152 |
/* will be found. */ |
| 11153 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 11154 |
|
| 11155 |
/* N (input) INTEGER */ |
| 11156 |
/* The order of the matrix. N >= 0. */ |
| 11157 |
|
| 11158 |
/* D (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 11159 |
/* On entry, the N diagonal elements of the tridiagonal matrix */ |
| 11160 |
/* T. On exit, D is overwritten. */ |
| 11161 |
|
| 11162 |
/* E (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 11163 |
/* On entry, the (N-1) subdiagonal elements of the tridiagonal */ |
| 11164 |
/* matrix T in elements 1 to N-1 of E. E(N) need not be set on */ |
| 11165 |
/* input, but is used internally as workspace. */ |
| 11166 |
/* On exit, E is overwritten. */ |
| 11167 |
|
| 11168 |
/* VL (input) DOUBLE PRECISION */ |
| 11169 |
/* VU (input) DOUBLE PRECISION */ |
| 11170 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 11171 |
/* be searched for eigenvalues. VL < VU. */ |
| 11172 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 11173 |
|
| 11174 |
/* IL (input) INTEGER */ |
| 11175 |
/* IU (input) INTEGER */ |
| 11176 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 11177 |
/* smallest and largest eigenvalues to be returned. */ |
| 11178 |
/* 1 <= IL <= IU <= N, if N > 0. */ |
| 11179 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 11180 |
|
| 11181 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 11182 |
/* Unused. Was the absolute error tolerance for the */ |
| 11183 |
/* eigenvalues/eigenvectors in previous versions. */ |
| 11184 |
|
| 11185 |
/* M (output) INTEGER */ |
| 11186 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 11187 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 11188 |
|
| 11189 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 11190 |
/* The first M elements contain the selected eigenvalues in */ |
| 11191 |
/* ascending order. */ |
| 11192 |
|
| 11193 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */ |
| 11194 |
/* If JOBZ = 'V', and if INFO = 0, then the first M columns of Z */ |
| 11195 |
/* contain the orthonormal eigenvectors of the matrix T */ |
| 11196 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 11197 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 11198 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 11199 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 11200 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 11201 |
/* is not known in advance and an upper bound must be used. */ |
| 11202 |
/* Supplying N columns is always safe. */ |
| 11203 |
|
| 11204 |
/* LDZ (input) INTEGER */ |
| 11205 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 11206 |
/* JOBZ = 'V', then LDZ >= max(1,N). */ |
| 11207 |
|
| 11208 |
/* ISUPPZ (output) INTEGER ARRAY, dimension ( 2*max(1,M) ) */ |
| 11209 |
/* The support of the eigenvectors in Z, i.e., the indices */ |
| 11210 |
/* indicating the nonzero elements in Z. The i-th computed eigenvector */ |
| 11211 |
/* is nonzero only in elements ISUPPZ( 2*i-1 ) through */ |
| 11212 |
/* ISUPPZ( 2*i ). This is relevant in the case when the matrix */ |
| 11213 |
/* is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */ |
| 11214 |
|
| 11215 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) */ |
| 11216 |
/* On exit, if INFO = 0, WORK(1) returns the optimal */ |
| 11217 |
/* (and minimal) LWORK. */ |
| 11218 |
|
| 11219 |
/* LWORK (input) INTEGER */ |
| 11220 |
/* The dimension of the array WORK. LWORK >= max(1,18*N) */ |
| 11221 |
/* if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'. */ |
| 11222 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 11223 |
/* only calculates the optimal size of the WORK array, returns */ |
| 11224 |
/* this value as the first entry of the WORK array, and no error */ |
| 11225 |
/* message related to LWORK is issued by XERBLA. */ |
| 11226 |
|
| 11227 |
/* IWORK (workspace/output) INTEGER array, dimension (LIWORK) */ |
| 11228 |
/* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ |
| 11229 |
|
| 11230 |
/* LIWORK (input) INTEGER */ |
| 11231 |
/* The dimension of the array IWORK. LIWORK >= max(1,10*N) */ |
| 11232 |
/* if the eigenvectors are desired, and LIWORK >= max(1,8*N) */ |
| 11233 |
/* if only the eigenvalues are to be computed. */ |
| 11234 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 11235 |
/* routine only calculates the optimal size of the IWORK array, */ |
| 11236 |
/* returns this value as the first entry of the IWORK array, and */ |
| 11237 |
/* no error message related to LIWORK is issued by XERBLA. */ |
| 11238 |
|
| 11239 |
/* INFO (output) INTEGER */ |
| 11240 |
/* On exit, INFO */ |
| 11241 |
/* = 0: successful exit */ |
| 11242 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 11243 |
/* > 0: if INFO = 1X, internal error in DLARRE, */ |
| 11244 |
/* if INFO = 2X, internal error in DLARRV. */ |
| 11245 |
/* Here, the digit X = ABS( IINFO ) < 10, where IINFO is */ |
| 11246 |
/* the nonzero error code returned by DLARRE or */ |
| 11247 |
/* DLARRV, respectively. */ |
| 11248 |
|
| 11249 |
/* Further Details */ |
| 11250 |
/* =============== */ |
| 11251 |
|
| 11252 |
/* Based on contributions by */ |
| 11253 |
/* Inderjit Dhillon, IBM Almaden, USA */ |
| 11254 |
/* Osni Marques, LBNL/NERSC, USA */ |
| 11255 |
/* Christof Voemel, LBNL/NERSC, USA */ |
| 11256 |
|
| 11257 |
/* ===================================================================== */ |
| 11258 |
|
| 11259 |
/* .. Local Scalars .. */ |
| 11260 |
/* .. */ |
| 11261 |
/* .. External Subroutines .. */ |
| 11262 |
/* .. */ |
| 11263 |
/* .. Executable Statements .. */ |
| 11264 |
/* Parameter adjustments */ |
| 11265 |
--d__; |
| 11266 |
--e; |
| 11267 |
--w; |
| 11268 |
z_dim1 = *ldz; |
| 11269 |
z_offset = 1 + z_dim1; |
| 11270 |
z__ -= z_offset; |
| 11271 |
--isuppz; |
| 11272 |
--work; |
| 11273 |
--iwork; |
| 11274 |
|
| 11275 |
/* Function Body */ |
| 11276 |
*info = 0; |
| 11277 |
tryrac = false; |
| 11278 |
dstemr_(jobz, range, n, &d__[1], &e[1], vl, vu, il, iu, m, &w[1], &z__[ |
| 11279 |
z_offset], ldz, n, &isuppz[1], &tryrac, &work[1], lwork, &iwork[1] |
| 11280 |
, liwork, info); |
| 11281 |
|
| 11282 |
/* End of DSTEGR */ |
| 11283 |
|
| 11284 |
return 0; |
| 11285 |
} /* dstegr_ */ |
| 11286 |
|
| 11287 |
/* Subroutine */ int dstein_(integer *n, double *d__, double *e, |
| 11288 |
integer *m, double *w, integer *iblock, integer *isplit, |
| 11289 |
double *z__, integer *ldz, double *work, integer *iwork, |
| 11290 |
integer *ifail, integer *info) |
| 11291 |
{ |
| 11292 |
/* Table of constant values */ |
| 11293 |
static integer c__2 = 2; |
| 11294 |
static integer c__1 = 1; |
| 11295 |
static integer c_n1 = -1; |
| 11296 |
|
| 11297 |
/* System generated locals */ |
| 11298 |
integer z_dim1, z_offset, i__1, i__2, i__3; |
| 11299 |
double d__1, d__2, d__3, d__4, d__5; |
| 11300 |
|
| 11301 |
/* Local variables */ |
| 11302 |
integer i__, j, b1, j1, bn; |
| 11303 |
double xj, scl, eps, sep, nrm, tol; |
| 11304 |
integer its; |
| 11305 |
double xjm, ztr, eps1; |
| 11306 |
integer jblk, nblk; |
| 11307 |
integer jmax; |
| 11308 |
integer iseed[4], gpind, iinfo; |
| 11309 |
double ortol; |
| 11310 |
integer indrv1, indrv2, indrv3, indrv4, indrv5; |
| 11311 |
integer nrmchk; |
| 11312 |
integer blksiz; |
| 11313 |
double onenrm, dtpcrt, pertol; |
| 11314 |
|
| 11315 |
|
| 11316 |
/* -- LAPACK routine (version 3.1) -- */ |
| 11317 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 11318 |
/* November 2006 */ |
| 11319 |
|
| 11320 |
/* .. Scalar Arguments .. */ |
| 11321 |
/* .. */ |
| 11322 |
/* .. Array Arguments .. */ |
| 11323 |
/* .. */ |
| 11324 |
|
| 11325 |
/* Purpose */ |
| 11326 |
/* ======= */ |
| 11327 |
|
| 11328 |
/* DSTEIN computes the eigenvectors of a real symmetric tridiagonal */ |
| 11329 |
/* matrix T corresponding to specified eigenvalues, using inverse */ |
| 11330 |
/* iteration. */ |
| 11331 |
|
| 11332 |
/* The maximum number of iterations allowed for each eigenvector is */ |
| 11333 |
/* specified by an internal parameter MAXITS (currently set to 5). */ |
| 11334 |
|
| 11335 |
/* Arguments */ |
| 11336 |
/* ========= */ |
| 11337 |
|
| 11338 |
/* N (input) INTEGER */ |
| 11339 |
/* The order of the matrix. N >= 0. */ |
| 11340 |
|
| 11341 |
/* D (input) DOUBLE PRECISION array, dimension (N) */ |
| 11342 |
/* The n diagonal elements of the tridiagonal matrix T. */ |
| 11343 |
|
| 11344 |
/* E (input) DOUBLE PRECISION array, dimension (N-1) */ |
| 11345 |
/* The (n-1) subdiagonal elements of the tridiagonal matrix */ |
| 11346 |
/* T, in elements 1 to N-1. */ |
| 11347 |
|
| 11348 |
/* M (input) INTEGER */ |
| 11349 |
/* The number of eigenvectors to be found. 0 <= M <= N. */ |
| 11350 |
|
| 11351 |
/* W (input) DOUBLE PRECISION array, dimension (N) */ |
| 11352 |
/* The first M elements of W contain the eigenvalues for */ |
| 11353 |
/* which eigenvectors are to be computed. The eigenvalues */ |
| 11354 |
/* should be grouped by split-off block and ordered from */ |
| 11355 |
/* smallest to largest within the block. ( The output array */ |
| 11356 |
/* W from DSTEBZ with ORDER = 'B' is expected here. ) */ |
| 11357 |
|
| 11358 |
/* IBLOCK (input) INTEGER array, dimension (N) */ |
| 11359 |
/* The submatrix indices associated with the corresponding */ |
| 11360 |
/* eigenvalues in W; IBLOCK(i)=1 if eigenvalue W(i) belongs to */ |
| 11361 |
/* the first submatrix from the top, =2 if W(i) belongs to */ |
| 11362 |
/* the second submatrix, etc. ( The output array IBLOCK */ |
| 11363 |
/* from DSTEBZ is expected here. ) */ |
| 11364 |
|
| 11365 |
/* ISPLIT (input) INTEGER array, dimension (N) */ |
| 11366 |
/* The splitting points, at which T breaks up into submatrices. */ |
| 11367 |
/* The first submatrix consists of rows/columns 1 to */ |
| 11368 |
/* ISPLIT( 1 ), the second of rows/columns ISPLIT( 1 )+1 */ |
| 11369 |
/* through ISPLIT( 2 ), etc. */ |
| 11370 |
/* ( The output array ISPLIT from DSTEBZ is expected here. ) */ |
| 11371 |
|
| 11372 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, M) */ |
| 11373 |
/* The computed eigenvectors. The eigenvector associated */ |
| 11374 |
/* with the eigenvalue W(i) is stored in the i-th column of */ |
| 11375 |
/* Z. Any vector which fails to converge is set to its current */ |
| 11376 |
/* iterate after MAXITS iterations. */ |
| 11377 |
|
| 11378 |
/* LDZ (input) INTEGER */ |
| 11379 |
/* The leading dimension of the array Z. LDZ >= max(1,N). */ |
| 11380 |
|
| 11381 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (5*N) */ |
| 11382 |
|
| 11383 |
/* IWORK (workspace) INTEGER array, dimension (N) */ |
| 11384 |
|
| 11385 |
/* IFAIL (output) INTEGER array, dimension (M) */ |
| 11386 |
/* On normal exit, all elements of IFAIL are zero. */ |
| 11387 |
/* If one or more eigenvectors fail to converge after */ |
| 11388 |
/* MAXITS iterations, then their indices are stored in */ |
| 11389 |
/* array IFAIL. */ |
| 11390 |
|
| 11391 |
/* INFO (output) INTEGER */ |
| 11392 |
/* = 0: successful exit. */ |
| 11393 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 11394 |
/* > 0: if INFO = i, then i eigenvectors failed to converge */ |
| 11395 |
/* in MAXITS iterations. Their indices are stored in */ |
| 11396 |
/* array IFAIL. */ |
| 11397 |
|
| 11398 |
/* Internal Parameters */ |
| 11399 |
/* =================== */ |
| 11400 |
|
| 11401 |
/* MAXITS INTEGER, default = 5 */ |
| 11402 |
/* The maximum number of iterations performed. */ |
| 11403 |
|
| 11404 |
/* EXTRA INTEGER, default = 2 */ |
| 11405 |
/* The number of iterations performed after norm growth */ |
| 11406 |
/* criterion is satisfied, should be at least 1. */ |
| 11407 |
|
| 11408 |
/* ===================================================================== */ |
| 11409 |
|
| 11410 |
/* .. Parameters .. */ |
| 11411 |
/* .. */ |
| 11412 |
/* .. Local Scalars .. */ |
| 11413 |
/* .. */ |
| 11414 |
/* .. Local Arrays .. */ |
| 11415 |
/* .. */ |
| 11416 |
/* .. External Functions .. */ |
| 11417 |
/* .. */ |
| 11418 |
/* .. External Subroutines .. */ |
| 11419 |
/* .. */ |
| 11420 |
/* .. Intrinsic Functions .. */ |
| 11421 |
/* .. */ |
| 11422 |
/* .. Executable Statements .. */ |
| 11423 |
|
| 11424 |
/* Test the input parameters. */ |
| 11425 |
|
| 11426 |
/* Parameter adjustments */ |
| 11427 |
--d__; |
| 11428 |
--e; |
| 11429 |
--w; |
| 11430 |
--iblock; |
| 11431 |
--isplit; |
| 11432 |
z_dim1 = *ldz; |
| 11433 |
z_offset = 1 + z_dim1; |
| 11434 |
z__ -= z_offset; |
| 11435 |
--work; |
| 11436 |
--iwork; |
| 11437 |
--ifail; |
| 11438 |
|
| 11439 |
/* Function Body */ |
| 11440 |
*info = 0; |
| 11441 |
i__1 = *m; |
| 11442 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 11443 |
ifail[i__] = 0; |
| 11444 |
/* L10: */ |
| 11445 |
} |
| 11446 |
|
| 11447 |
if (*n < 0) { |
| 11448 |
*info = -1; |
| 11449 |
} else if (*m < 0 || *m > *n) { |
| 11450 |
*info = -4; |
| 11451 |
} else if (*ldz < std::max(1_integer,*n)) { |
| 11452 |
*info = -9; |
| 11453 |
} else { |
| 11454 |
i__1 = *m; |
| 11455 |
for (j = 2; j <= i__1; ++j) { |
| 11456 |
if (iblock[j] < iblock[j - 1]) { |
| 11457 |
*info = -6; |
| 11458 |
goto L30; |
| 11459 |
} |
| 11460 |
if (iblock[j] == iblock[j - 1] && w[j] < w[j - 1]) { |
| 11461 |
*info = -5; |
| 11462 |
goto L30; |
| 11463 |
} |
| 11464 |
/* L20: */ |
| 11465 |
} |
| 11466 |
L30: |
| 11467 |
; |
| 11468 |
} |
| 11469 |
|
| 11470 |
if (*info != 0) { |
| 11471 |
i__1 = -(*info); |
| 11472 |
xerbla_("DSTEIN", &i__1); |
| 11473 |
return 0; |
| 11474 |
} |
| 11475 |
|
| 11476 |
/* Quick return if possible */ |
| 11477 |
|
| 11478 |
if (*n == 0 || *m == 0) { |
| 11479 |
return 0; |
| 11480 |
} else if (*n == 1) { |
| 11481 |
z__[z_dim1 + 1] = 1.; |
| 11482 |
return 0; |
| 11483 |
} |
| 11484 |
|
| 11485 |
/* Get machine constants. */ |
| 11486 |
|
| 11487 |
eps = dlamch_("Precision"); |
| 11488 |
|
| 11489 |
/* Initialize seed for random number generator DLARNV. */ |
| 11490 |
|
| 11491 |
for (i__ = 1; i__ <= 4; ++i__) { |
| 11492 |
iseed[i__ - 1] = 1; |
| 11493 |
/* L40: */ |
| 11494 |
} |
| 11495 |
|
| 11496 |
/* Initialize pointers. */ |
| 11497 |
|
| 11498 |
indrv1 = 0; |
| 11499 |
indrv2 = indrv1 + *n; |
| 11500 |
indrv3 = indrv2 + *n; |
| 11501 |
indrv4 = indrv3 + *n; |
| 11502 |
indrv5 = indrv4 + *n; |
| 11503 |
|
| 11504 |
/* Compute eigenvectors of matrix blocks. */ |
| 11505 |
|
| 11506 |
j1 = 1; |
| 11507 |
i__1 = iblock[*m]; |
| 11508 |
for (nblk = 1; nblk <= i__1; ++nblk) { |
| 11509 |
|
| 11510 |
/* Find starting and ending indices of block nblk. */ |
| 11511 |
|
| 11512 |
if (nblk == 1) { |
| 11513 |
b1 = 1; |
| 11514 |
} else { |
| 11515 |
b1 = isplit[nblk - 1] + 1; |
| 11516 |
} |
| 11517 |
bn = isplit[nblk]; |
| 11518 |
blksiz = bn - b1 + 1; |
| 11519 |
if (blksiz == 1) { |
| 11520 |
goto L60; |
| 11521 |
} |
| 11522 |
gpind = b1; |
| 11523 |
|
| 11524 |
/* Compute reorthogonalization criterion and stopping criterion. */ |
| 11525 |
|
| 11526 |
onenrm = (d__1 = d__[b1], abs(d__1)) + (d__2 = e[b1], abs(d__2)); |
| 11527 |
/* Computing MAX */ |
| 11528 |
d__3 = onenrm, d__4 = (d__1 = d__[bn], abs(d__1)) + (d__2 = e[bn - 1], |
| 11529 |
abs(d__2)); |
| 11530 |
onenrm = std::max(d__3,d__4); |
| 11531 |
i__2 = bn - 1; |
| 11532 |
for (i__ = b1 + 1; i__ <= i__2; ++i__) { |
| 11533 |
/* Computing MAX */ |
| 11534 |
d__4 = onenrm, d__5 = (d__1 = d__[i__], abs(d__1)) + (d__2 = e[ |
| 11535 |
i__ - 1], abs(d__2)) + (d__3 = e[i__], abs(d__3)); |
| 11536 |
onenrm = std::max(d__4,d__5); |
| 11537 |
/* L50: */ |
| 11538 |
} |
| 11539 |
ortol = onenrm * .001; |
| 11540 |
|
| 11541 |
dtpcrt = sqrt(.1 / blksiz); |
| 11542 |
|
| 11543 |
/* Loop through eigenvalues of block nblk. */ |
| 11544 |
|
| 11545 |
L60: |
| 11546 |
jblk = 0; |
| 11547 |
i__2 = *m; |
| 11548 |
for (j = j1; j <= i__2; ++j) { |
| 11549 |
if (iblock[j] != nblk) { |
| 11550 |
j1 = j; |
| 11551 |
goto L160; |
| 11552 |
} |
| 11553 |
++jblk; |
| 11554 |
xj = w[j]; |
| 11555 |
|
| 11556 |
/* Skip all the work if the block size is one. */ |
| 11557 |
|
| 11558 |
if (blksiz == 1) { |
| 11559 |
work[indrv1 + 1] = 1.; |
| 11560 |
goto L120; |
| 11561 |
} |
| 11562 |
|
| 11563 |
/* If eigenvalues j and j-1 are too close, add a relatively */ |
| 11564 |
/* small perturbation. */ |
| 11565 |
|
| 11566 |
if (jblk > 1) { |
| 11567 |
eps1 = (d__1 = eps * xj, abs(d__1)); |
| 11568 |
pertol = eps1 * 10.; |
| 11569 |
sep = xj - xjm; |
| 11570 |
if (sep < pertol) { |
| 11571 |
xj = xjm + pertol; |
| 11572 |
} |
| 11573 |
} |
| 11574 |
|
| 11575 |
its = 0; |
| 11576 |
nrmchk = 0; |
| 11577 |
|
| 11578 |
/* Get random starting vector. */ |
| 11579 |
|
| 11580 |
dlarnv_(&c__2, iseed, &blksiz, &work[indrv1 + 1]); |
| 11581 |
|
| 11582 |
/* Copy the matrix T so it won't be destroyed in factorization. */ |
| 11583 |
|
| 11584 |
dcopy_(&blksiz, &d__[b1], &c__1, &work[indrv4 + 1], &c__1); |
| 11585 |
i__3 = blksiz - 1; |
| 11586 |
dcopy_(&i__3, &e[b1], &c__1, &work[indrv2 + 2], &c__1); |
| 11587 |
i__3 = blksiz - 1; |
| 11588 |
dcopy_(&i__3, &e[b1], &c__1, &work[indrv3 + 1], &c__1); |
| 11589 |
|
| 11590 |
/* Compute LU factors with partial pivoting ( PT = LU ) */ |
| 11591 |
|
| 11592 |
tol = 0.; |
| 11593 |
dlagtf_(&blksiz, &work[indrv4 + 1], &xj, &work[indrv2 + 2], &work[ |
| 11594 |
indrv3 + 1], &tol, &work[indrv5 + 1], &iwork[1], &iinfo); |
| 11595 |
|
| 11596 |
/* Update iteration count. */ |
| 11597 |
|
| 11598 |
L70: |
| 11599 |
++its; |
| 11600 |
if (its > 5) { |
| 11601 |
goto L100; |
| 11602 |
} |
| 11603 |
|
| 11604 |
/* Normalize and scale the righthand side vector Pb. */ |
| 11605 |
|
| 11606 |
/* Computing MAX */ |
| 11607 |
d__2 = eps, d__3 = (d__1 = work[indrv4 + blksiz], abs(d__1)); |
| 11608 |
scl = blksiz * onenrm * std::max(d__2,d__3) / dasum_(&blksiz, &work[ |
| 11609 |
indrv1 + 1], &c__1); |
| 11610 |
dscal_(&blksiz, &scl, &work[indrv1 + 1], &c__1); |
| 11611 |
|
| 11612 |
/* Solve the system LU = Pb. */ |
| 11613 |
|
| 11614 |
dlagts_(&c_n1, &blksiz, &work[indrv4 + 1], &work[indrv2 + 2], & |
| 11615 |
work[indrv3 + 1], &work[indrv5 + 1], &iwork[1], &work[ |
| 11616 |
indrv1 + 1], &tol, &iinfo); |
| 11617 |
|
| 11618 |
/* Reorthogonalize by modified Gram-Schmidt if eigenvalues are */ |
| 11619 |
/* close enough. */ |
| 11620 |
|
| 11621 |
if (jblk == 1) { |
| 11622 |
goto L90; |
| 11623 |
} |
| 11624 |
if ((d__1 = xj - xjm, abs(d__1)) > ortol) { |
| 11625 |
gpind = j; |
| 11626 |
} |
| 11627 |
if (gpind != j) { |
| 11628 |
i__3 = j - 1; |
| 11629 |
for (i__ = gpind; i__ <= i__3; ++i__) { |
| 11630 |
ztr = -ddot_(&blksiz, &work[indrv1 + 1], &c__1, &z__[b1 + |
| 11631 |
i__ * z_dim1], &c__1); |
| 11632 |
daxpy_(&blksiz, &ztr, &z__[b1 + i__ * z_dim1], &c__1, & |
| 11633 |
work[indrv1 + 1], &c__1); |
| 11634 |
/* L80: */ |
| 11635 |
} |
| 11636 |
} |
| 11637 |
|
| 11638 |
/* Check the infinity norm of the iterate. */ |
| 11639 |
|
| 11640 |
L90: |
| 11641 |
jmax = idamax_(&blksiz, &work[indrv1 + 1], &c__1); |
| 11642 |
nrm = (d__1 = work[indrv1 + jmax], abs(d__1)); |
| 11643 |
|
| 11644 |
/* Continue for additional iterations after norm reaches */ |
| 11645 |
/* stopping criterion. */ |
| 11646 |
|
| 11647 |
if (nrm < dtpcrt) { |
| 11648 |
goto L70; |
| 11649 |
} |
| 11650 |
++nrmchk; |
| 11651 |
if (nrmchk < 3) { |
| 11652 |
goto L70; |
| 11653 |
} |
| 11654 |
|
| 11655 |
goto L110; |
| 11656 |
|
| 11657 |
/* If stopping criterion was not satisfied, update info and */ |
| 11658 |
/* store eigenvector number in array ifail. */ |
| 11659 |
|
| 11660 |
L100: |
| 11661 |
++(*info); |
| 11662 |
ifail[*info] = j; |
| 11663 |
|
| 11664 |
/* Accept iterate as jth eigenvector. */ |
| 11665 |
|
| 11666 |
L110: |
| 11667 |
scl = 1. / dnrm2_(&blksiz, &work[indrv1 + 1], &c__1); |
| 11668 |
jmax = idamax_(&blksiz, &work[indrv1 + 1], &c__1); |
| 11669 |
if (work[indrv1 + jmax] < 0.) { |
| 11670 |
scl = -scl; |
| 11671 |
} |
| 11672 |
dscal_(&blksiz, &scl, &work[indrv1 + 1], &c__1); |
| 11673 |
L120: |
| 11674 |
i__3 = *n; |
| 11675 |
for (i__ = 1; i__ <= i__3; ++i__) { |
| 11676 |
z__[i__ + j * z_dim1] = 0.; |
| 11677 |
/* L130: */ |
| 11678 |
} |
| 11679 |
i__3 = blksiz; |
| 11680 |
for (i__ = 1; i__ <= i__3; ++i__) { |
| 11681 |
z__[b1 + i__ - 1 + j * z_dim1] = work[indrv1 + i__]; |
| 11682 |
/* L140: */ |
| 11683 |
} |
| 11684 |
|
| 11685 |
/* Save the shift to check eigenvalue spacing at next */ |
| 11686 |
/* iteration. */ |
| 11687 |
|
| 11688 |
xjm = xj; |
| 11689 |
|
| 11690 |
/* L150: */ |
| 11691 |
} |
| 11692 |
L160: |
| 11693 |
; |
| 11694 |
} |
| 11695 |
|
| 11696 |
return 0; |
| 11697 |
|
| 11698 |
/* End of DSTEIN */ |
| 11699 |
|
| 11700 |
} /* dstein_ */ |
| 11701 |
|
| 11702 |
/* Subroutine */ int dstemr_(const char *jobz, const char *range, integer *n, double * |
| 11703 |
d__, double *e, double *vl, double *vu, integer *il, |
| 11704 |
integer *iu, integer *m, double *w, double *z__, integer *ldz, |
| 11705 |
integer *nzc, integer *isuppz, bool *tryrac, double *work, |
| 11706 |
integer *lwork, integer *iwork, integer *liwork, integer *info) |
| 11707 |
{ |
| 11708 |
/* Table of constant values */ |
| 11709 |
static integer c__1 = 1; |
| 11710 |
static double c_b18 = .001; |
| 11711 |
|
| 11712 |
/* System generated locals */ |
| 11713 |
integer z_dim1, z_offset, i__1, i__2; |
| 11714 |
double d__1, d__2; |
| 11715 |
|
| 11716 |
/* Local variables */ |
| 11717 |
integer i__, j; |
| 11718 |
double r1, r2; |
| 11719 |
integer jj; |
| 11720 |
double cs; |
| 11721 |
integer in; |
| 11722 |
double sn, wl, wu; |
| 11723 |
integer iil, iiu; |
| 11724 |
double eps, tmp; |
| 11725 |
integer indd, iend, jblk, wend; |
| 11726 |
double rmin, rmax; |
| 11727 |
integer itmp; |
| 11728 |
double tnrm; |
| 11729 |
integer inde2, itmp2; |
| 11730 |
double rtol1, rtol2; |
| 11731 |
double scale; |
| 11732 |
integer indgp; |
| 11733 |
integer iinfo, iindw, ilast; |
| 11734 |
integer lwmin; |
| 11735 |
bool wantz; |
| 11736 |
bool alleig; |
| 11737 |
integer ibegin; |
| 11738 |
bool indeig; |
| 11739 |
integer iindbl; |
| 11740 |
bool valeig; |
| 11741 |
integer wbegin; |
| 11742 |
double safmin; |
| 11743 |
double bignum; |
| 11744 |
integer inderr, iindwk, indgrs, offset; |
| 11745 |
double thresh; |
| 11746 |
integer iinspl, ifirst, indwrk, liwmin, nzcmin; |
| 11747 |
double pivmin; |
| 11748 |
integer nsplit; |
| 11749 |
double smlnum; |
| 11750 |
bool lquery, zquery; |
| 11751 |
|
| 11752 |
|
| 11753 |
/* -- LAPACK computational routine (version 3.1) -- */ |
| 11754 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 11755 |
/* November 2006 */ |
| 11756 |
|
| 11757 |
/* .. Scalar Arguments .. */ |
| 11758 |
/* .. */ |
| 11759 |
/* .. Array Arguments .. */ |
| 11760 |
/* .. */ |
| 11761 |
|
| 11762 |
/* Purpose */ |
| 11763 |
/* ======= */ |
| 11764 |
|
| 11765 |
/* DSTEMR computes selected eigenvalues and, optionally, eigenvectors */ |
| 11766 |
/* of a real symmetric tridiagonal matrix T. Any such unreduced matrix has */ |
| 11767 |
/* a well defined set of pairwise different real eigenvalues, the corresponding */ |
| 11768 |
/* real eigenvectors are pairwise orthogonal. */ |
| 11769 |
|
| 11770 |
/* The spectrum may be computed either completely or partially by specifying */ |
| 11771 |
/* either an interval (VL,VU] or a range of indices IL:IU for the desired */ |
| 11772 |
/* eigenvalues. */ |
| 11773 |
|
| 11774 |
/* Depending on the number of desired eigenvalues, these are computed either */ |
| 11775 |
/* by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are */ |
| 11776 |
/* computed by the use of various suitable L D L^T factorizations near clusters */ |
| 11777 |
/* of close eigenvalues (referred to as RRRs, Relatively Robust */ |
| 11778 |
/* Representations). An informal sketch of the algorithm follows. */ |
| 11779 |
|
| 11780 |
/* For each unreduced block (submatrix) of T, */ |
| 11781 |
/* (a) Compute T - sigma I = L D L^T, so that L and D */ |
| 11782 |
/* define all the wanted eigenvalues to high relative accuracy. */ |
| 11783 |
/* This means that small relative changes in the entries of D and L */ |
| 11784 |
/* cause only small relative changes in the eigenvalues and */ |
| 11785 |
/* eigenvectors. The standard (unfactored) representation of the */ |
| 11786 |
/* tridiagonal matrix T does not have this property in general. */ |
| 11787 |
/* (b) Compute the eigenvalues to suitable accuracy. */ |
| 11788 |
/* If the eigenvectors are desired, the algorithm attains full */ |
| 11789 |
/* accuracy of the computed eigenvalues only right before */ |
| 11790 |
/* the corresponding vectors have to be computed, see steps c) and d). */ |
| 11791 |
/* (c) For each cluster of close eigenvalues, select a new */ |
| 11792 |
/* shift close to the cluster, find a new factorization, and refine */ |
| 11793 |
/* the shifted eigenvalues to suitable accuracy. */ |
| 11794 |
/* (d) For each eigenvalue with a large enough relative separation compute */ |
| 11795 |
/* the corresponding eigenvector by forming a rank revealing twisted */ |
| 11796 |
/* factorization. Go back to (c) for any clusters that remain. */ |
| 11797 |
|
| 11798 |
/* For more details, see: */ |
| 11799 |
/* - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */ |
| 11800 |
/* to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */ |
| 11801 |
/* Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */ |
| 11802 |
/* - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */ |
| 11803 |
/* Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */ |
| 11804 |
/* 2004. Also LAPACK Working Note 154. */ |
| 11805 |
/* - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */ |
| 11806 |
/* tridiagonal eigenvalue/eigenvector problem", */ |
| 11807 |
/* Computer Science Division Technical Report No. UCB/CSD-97-971, */ |
| 11808 |
/* UC Berkeley, May 1997. */ |
| 11809 |
|
| 11810 |
/* Notes: */ |
| 11811 |
/* 1.DSTEMR works only on machines which follow IEEE-754 */ |
| 11812 |
/* floating-point standard in their handling of infinities and NaNs. */ |
| 11813 |
/* This permits the use of efficient inner loops avoiding a check for */ |
| 11814 |
/* zero divisors. */ |
| 11815 |
|
| 11816 |
/* Arguments */ |
| 11817 |
/* ========= */ |
| 11818 |
|
| 11819 |
/* JOBZ (input) CHARACTER*1 */ |
| 11820 |
/* = 'N': Compute eigenvalues only; */ |
| 11821 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 11822 |
|
| 11823 |
/* RANGE (input) CHARACTER*1 */ |
| 11824 |
/* = 'A': all eigenvalues will be found. */ |
| 11825 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 11826 |
/* will be found. */ |
| 11827 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 11828 |
|
| 11829 |
/* N (input) INTEGER */ |
| 11830 |
/* The order of the matrix. N >= 0. */ |
| 11831 |
|
| 11832 |
/* D (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 11833 |
/* On entry, the N diagonal elements of the tridiagonal matrix */ |
| 11834 |
/* T. On exit, D is overwritten. */ |
| 11835 |
|
| 11836 |
/* E (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 11837 |
/* On entry, the (N-1) subdiagonal elements of the tridiagonal */ |
| 11838 |
/* matrix T in elements 1 to N-1 of E. E(N) need not be set on */ |
| 11839 |
/* input, but is used internally as workspace. */ |
| 11840 |
/* On exit, E is overwritten. */ |
| 11841 |
|
| 11842 |
/* VL (input) DOUBLE PRECISION */ |
| 11843 |
/* VU (input) DOUBLE PRECISION */ |
| 11844 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 11845 |
/* be searched for eigenvalues. VL < VU. */ |
| 11846 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 11847 |
|
| 11848 |
/* IL (input) INTEGER */ |
| 11849 |
/* IU (input) INTEGER */ |
| 11850 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 11851 |
/* smallest and largest eigenvalues to be returned. */ |
| 11852 |
/* 1 <= IL <= IU <= N, if N > 0. */ |
| 11853 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 11854 |
|
| 11855 |
/* M (output) INTEGER */ |
| 11856 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 11857 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 11858 |
|
| 11859 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 11860 |
/* The first M elements contain the selected eigenvalues in */ |
| 11861 |
/* ascending order. */ |
| 11862 |
|
| 11863 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */ |
| 11864 |
/* If JOBZ = 'V', and if INFO = 0, then the first M columns of Z */ |
| 11865 |
/* contain the orthonormal eigenvectors of the matrix T */ |
| 11866 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 11867 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 11868 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 11869 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 11870 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 11871 |
/* is not known in advance and can be computed with a workspace */ |
| 11872 |
/* query by setting NZC = -1, see below. */ |
| 11873 |
|
| 11874 |
/* LDZ (input) INTEGER */ |
| 11875 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 11876 |
/* JOBZ = 'V', then LDZ >= max(1,N). */ |
| 11877 |
|
| 11878 |
/* NZC (input) INTEGER */ |
| 11879 |
/* The number of eigenvectors to be held in the array Z. */ |
| 11880 |
/* If RANGE = 'A', then NZC >= max(1,N). */ |
| 11881 |
/* If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU]. */ |
| 11882 |
/* If RANGE = 'I', then NZC >= IU-IL+1. */ |
| 11883 |
/* If NZC = -1, then a workspace query is assumed; the */ |
| 11884 |
/* routine calculates the number of columns of the array Z that */ |
| 11885 |
/* are needed to hold the eigenvectors. */ |
| 11886 |
/* This value is returned as the first entry of the Z array, and */ |
| 11887 |
/* no error message related to NZC is issued by XERBLA. */ |
| 11888 |
|
| 11889 |
/* ISUPPZ (output) INTEGER ARRAY, dimension ( 2*max(1,M) ) */ |
| 11890 |
/* The support of the eigenvectors in Z, i.e., the indices */ |
| 11891 |
/* indicating the nonzero elements in Z. The i-th computed eigenvector */ |
| 11892 |
/* is nonzero only in elements ISUPPZ( 2*i-1 ) through */ |
| 11893 |
/* ISUPPZ( 2*i ). This is relevant in the case when the matrix */ |
| 11894 |
/* is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */ |
| 11895 |
|
| 11896 |
/* TRYRAC (input/output) LOGICAL */ |
| 11897 |
/* If TRYRAC.EQ..TRUE., indicates that the code should check whether */ |
| 11898 |
/* the tridiagonal matrix defines its eigenvalues to high relative */ |
| 11899 |
/* accuracy. If so, the code uses relative-accuracy preserving */ |
| 11900 |
/* algorithms that might be (a bit) slower depending on the matrix. */ |
| 11901 |
/* If the matrix does not define its eigenvalues to high relative */ |
| 11902 |
/* accuracy, the code can uses possibly faster algorithms. */ |
| 11903 |
/* If TRYRAC.EQ..FALSE., the code is not required to guarantee */ |
| 11904 |
/* relatively accurate eigenvalues and can use the fastest possible */ |
| 11905 |
/* techniques. */ |
| 11906 |
/* On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix */ |
| 11907 |
/* does not define its eigenvalues to high relative accuracy. */ |
| 11908 |
|
| 11909 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) */ |
| 11910 |
/* On exit, if INFO = 0, WORK(1) returns the optimal */ |
| 11911 |
/* (and minimal) LWORK. */ |
| 11912 |
|
| 11913 |
/* LWORK (input) INTEGER */ |
| 11914 |
/* The dimension of the array WORK. LWORK >= max(1,18*N) */ |
| 11915 |
/* if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'. */ |
| 11916 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 11917 |
/* only calculates the optimal size of the WORK array, returns */ |
| 11918 |
/* this value as the first entry of the WORK array, and no error */ |
| 11919 |
/* message related to LWORK is issued by XERBLA. */ |
| 11920 |
|
| 11921 |
/* IWORK (workspace/output) INTEGER array, dimension (LIWORK) */ |
| 11922 |
/* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ |
| 11923 |
|
| 11924 |
/* LIWORK (input) INTEGER */ |
| 11925 |
/* The dimension of the array IWORK. LIWORK >= max(1,10*N) */ |
| 11926 |
/* if the eigenvectors are desired, and LIWORK >= max(1,8*N) */ |
| 11927 |
/* if only the eigenvalues are to be computed. */ |
| 11928 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 11929 |
/* routine only calculates the optimal size of the IWORK array, */ |
| 11930 |
/* returns this value as the first entry of the IWORK array, and */ |
| 11931 |
/* no error message related to LIWORK is issued by XERBLA. */ |
| 11932 |
|
| 11933 |
/* INFO (output) INTEGER */ |
| 11934 |
/* On exit, INFO */ |
| 11935 |
/* = 0: successful exit */ |
| 11936 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 11937 |
/* > 0: if INFO = 1X, internal error in DLARRE, */ |
| 11938 |
/* if INFO = 2X, internal error in DLARRV. */ |
| 11939 |
/* Here, the digit X = ABS( IINFO ) < 10, where IINFO is */ |
| 11940 |
/* the nonzero error code returned by DLARRE or */ |
| 11941 |
/* DLARRV, respectively. */ |
| 11942 |
|
| 11943 |
|
| 11944 |
/* Further Details */ |
| 11945 |
/* =============== */ |
| 11946 |
|
| 11947 |
/* Based on contributions by */ |
| 11948 |
/* Beresford Parlett, University of California, Berkeley, USA */ |
| 11949 |
/* Jim Demmel, University of California, Berkeley, USA */ |
| 11950 |
/* Inderjit Dhillon, University of Texas, Austin, USA */ |
| 11951 |
/* Osni Marques, LBNL/NERSC, USA */ |
| 11952 |
/* Christof Voemel, University of California, Berkeley, USA */ |
| 11953 |
|
| 11954 |
/* ===================================================================== */ |
| 11955 |
|
| 11956 |
/* .. Parameters .. */ |
| 11957 |
/* .. */ |
| 11958 |
/* .. Local Scalars .. */ |
| 11959 |
/* .. */ |
| 11960 |
/* .. */ |
| 11961 |
/* .. External Functions .. */ |
| 11962 |
/* .. */ |
| 11963 |
/* .. External Subroutines .. */ |
| 11964 |
/* .. */ |
| 11965 |
/* .. Intrinsic Functions .. */ |
| 11966 |
/* .. */ |
| 11967 |
/* .. Executable Statements .. */ |
| 11968 |
|
| 11969 |
/* Test the input parameters. */ |
| 11970 |
|
| 11971 |
/* Parameter adjustments */ |
| 11972 |
--d__; |
| 11973 |
--e; |
| 11974 |
--w; |
| 11975 |
z_dim1 = *ldz; |
| 11976 |
z_offset = 1 + z_dim1; |
| 11977 |
z__ -= z_offset; |
| 11978 |
--isuppz; |
| 11979 |
--work; |
| 11980 |
--iwork; |
| 11981 |
|
| 11982 |
/* Function Body */ |
| 11983 |
wantz = lsame_(jobz, "V"); |
| 11984 |
alleig = lsame_(range, "A"); |
| 11985 |
valeig = lsame_(range, "V"); |
| 11986 |
indeig = lsame_(range, "I"); |
| 11987 |
|
| 11988 |
lquery = *lwork == -1 || *liwork == -1; |
| 11989 |
zquery = *nzc == -1; |
| 11990 |
*tryrac = *info != 0; |
| 11991 |
/* DSTEMR needs WORK of size 6*N, IWORK of size 3*N. */ |
| 11992 |
/* In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N. */ |
| 11993 |
/* Furthermore, DLARRV needs WORK of size 12*N, IWORK of size 7*N. */ |
| 11994 |
if (wantz) { |
| 11995 |
lwmin = *n * 18; |
| 11996 |
liwmin = *n * 10; |
| 11997 |
} else { |
| 11998 |
/* need less workspace if only the eigenvalues are wanted */ |
| 11999 |
lwmin = *n * 12; |
| 12000 |
liwmin = *n << 3; |
| 12001 |
} |
| 12002 |
wl = 0.; |
| 12003 |
wu = 0.; |
| 12004 |
iil = 0; |
| 12005 |
iiu = 0; |
| 12006 |
if (valeig) { |
| 12007 |
/* We do not reference VL, VU in the cases RANGE = 'I','A' */ |
| 12008 |
/* The interval (WL, WU] contains all the wanted eigenvalues. */ |
| 12009 |
/* It is either given by the user or computed in DLARRE. */ |
| 12010 |
wl = *vl; |
| 12011 |
wu = *vu; |
| 12012 |
} else if (indeig) { |
| 12013 |
/* We do not reference IL, IU in the cases RANGE = 'V','A' */ |
| 12014 |
iil = *il; |
| 12015 |
iiu = *iu; |
| 12016 |
} |
| 12017 |
|
| 12018 |
*info = 0; |
| 12019 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 12020 |
*info = -1; |
| 12021 |
} else if (! (alleig || valeig || indeig)) { |
| 12022 |
*info = -2; |
| 12023 |
} else if (*n < 0) { |
| 12024 |
*info = -3; |
| 12025 |
} else if (valeig && *n > 0 && wu <= wl) { |
| 12026 |
*info = -7; |
| 12027 |
} else if (indeig && (iil < 1 || iil > *n)) { |
| 12028 |
*info = -8; |
| 12029 |
} else if (indeig && (iiu < iil || iiu > *n)) { |
| 12030 |
*info = -9; |
| 12031 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 12032 |
*info = -13; |
| 12033 |
} else if (*lwork < lwmin && ! lquery) { |
| 12034 |
*info = -17; |
| 12035 |
} else if (*liwork < liwmin && ! lquery) { |
| 12036 |
*info = -19; |
| 12037 |
} |
| 12038 |
|
| 12039 |
/* Get machine constants. */ |
| 12040 |
|
| 12041 |
safmin = dlamch_("Safe minimum"); |
| 12042 |
eps = dlamch_("Precision"); |
| 12043 |
smlnum = safmin / eps; |
| 12044 |
bignum = 1. / smlnum; |
| 12045 |
rmin = sqrt(smlnum); |
| 12046 |
/* Computing MIN */ |
| 12047 |
d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin)); |
| 12048 |
rmax = std::min(d__1,d__2); |
| 12049 |
|
| 12050 |
if (*info == 0) { |
| 12051 |
work[1] = (double) lwmin; |
| 12052 |
iwork[1] = liwmin; |
| 12053 |
|
| 12054 |
if (wantz && alleig) { |
| 12055 |
nzcmin = *n; |
| 12056 |
} else if (wantz && valeig) { |
| 12057 |
dlarrc_("T", n, vl, vu, &d__[1], &e[1], &safmin, &nzcmin, &itmp, & |
| 12058 |
itmp2, info); |
| 12059 |
} else if (wantz && indeig) { |
| 12060 |
nzcmin = iiu - iil + 1; |
| 12061 |
} else { |
| 12062 |
/* WANTZ .EQ. FALSE. */ |
| 12063 |
nzcmin = 0; |
| 12064 |
} |
| 12065 |
if (zquery && *info == 0) { |
| 12066 |
z__[z_dim1 + 1] = (double) nzcmin; |
| 12067 |
} else if (*nzc < nzcmin && ! zquery) { |
| 12068 |
*info = -14; |
| 12069 |
} |
| 12070 |
} |
| 12071 |
if (*info != 0) { |
| 12072 |
|
| 12073 |
i__1 = -(*info); |
| 12074 |
xerbla_("DSTEMR", &i__1); |
| 12075 |
|
| 12076 |
return 0; |
| 12077 |
} else if (lquery || zquery) { |
| 12078 |
return 0; |
| 12079 |
} |
| 12080 |
|
| 12081 |
/* Handle N = 0, 1, and 2 cases immediately */ |
| 12082 |
|
| 12083 |
*m = 0; |
| 12084 |
if (*n == 0) { |
| 12085 |
return 0; |
| 12086 |
} |
| 12087 |
|
| 12088 |
if (*n == 1) { |
| 12089 |
if (alleig || indeig) { |
| 12090 |
*m = 1; |
| 12091 |
w[1] = d__[1]; |
| 12092 |
} else { |
| 12093 |
if (wl < d__[1] && wu >= d__[1]) { |
| 12094 |
*m = 1; |
| 12095 |
w[1] = d__[1]; |
| 12096 |
} |
| 12097 |
} |
| 12098 |
if (wantz && ! zquery) { |
| 12099 |
z__[z_dim1 + 1] = 1.; |
| 12100 |
isuppz[1] = 1; |
| 12101 |
isuppz[2] = 1; |
| 12102 |
} |
| 12103 |
return 0; |
| 12104 |
} |
| 12105 |
|
| 12106 |
if (*n == 2) { |
| 12107 |
if (! wantz) { |
| 12108 |
dlae2_(&d__[1], &e[1], &d__[2], &r1, &r2); |
| 12109 |
} else if (wantz && ! zquery) { |
| 12110 |
dlaev2_(&d__[1], &e[1], &d__[2], &r1, &r2, &cs, &sn); |
| 12111 |
} |
| 12112 |
if (alleig || valeig && r2 > wl && r2 <= wu || indeig && iil == 1) { |
| 12113 |
++(*m); |
| 12114 |
w[*m] = r2; |
| 12115 |
if (wantz && ! zquery) { |
| 12116 |
z__[*m * z_dim1 + 1] = -sn; |
| 12117 |
z__[*m * z_dim1 + 2] = cs; |
| 12118 |
/* Note: At most one of SN and CS can be zero. */ |
| 12119 |
if (sn != 0.) { |
| 12120 |
if (cs != 0.) { |
| 12121 |
isuppz[(*m << 1) - 1] = 1; |
| 12122 |
isuppz[(*m << 1) - 1] = 2; |
| 12123 |
} else { |
| 12124 |
isuppz[(*m << 1) - 1] = 1; |
| 12125 |
isuppz[(*m << 1) - 1] = 1; |
| 12126 |
} |
| 12127 |
} else { |
| 12128 |
isuppz[(*m << 1) - 1] = 2; |
| 12129 |
isuppz[*m * 2] = 2; |
| 12130 |
} |
| 12131 |
} |
| 12132 |
} |
| 12133 |
if (alleig || valeig && r1 > wl && r1 <= wu || indeig && iiu == 2) { |
| 12134 |
++(*m); |
| 12135 |
w[*m] = r1; |
| 12136 |
if (wantz && ! zquery) { |
| 12137 |
z__[*m * z_dim1 + 1] = cs; |
| 12138 |
z__[*m * z_dim1 + 2] = sn; |
| 12139 |
/* Note: At most one of SN and CS can be zero. */ |
| 12140 |
if (sn != 0.) { |
| 12141 |
if (cs != 0.) { |
| 12142 |
isuppz[(*m << 1) - 1] = 1; |
| 12143 |
isuppz[(*m << 1) - 1] = 2; |
| 12144 |
} else { |
| 12145 |
isuppz[(*m << 1) - 1] = 1; |
| 12146 |
isuppz[(*m << 1) - 1] = 1; |
| 12147 |
} |
| 12148 |
} else { |
| 12149 |
isuppz[(*m << 1) - 1] = 2; |
| 12150 |
isuppz[*m * 2] = 2; |
| 12151 |
} |
| 12152 |
} |
| 12153 |
} |
| 12154 |
return 0; |
| 12155 |
} |
| 12156 |
/* Continue with general N */ |
| 12157 |
indgrs = 1; |
| 12158 |
inderr = (*n << 1) + 1; |
| 12159 |
indgp = *n * 3 + 1; |
| 12160 |
indd = (*n << 2) + 1; |
| 12161 |
inde2 = *n * 5 + 1; |
| 12162 |
indwrk = *n * 6 + 1; |
| 12163 |
|
| 12164 |
iinspl = 1; |
| 12165 |
iindbl = *n + 1; |
| 12166 |
iindw = (*n << 1) + 1; |
| 12167 |
iindwk = *n * 3 + 1; |
| 12168 |
|
| 12169 |
/* Scale matrix to allowable range, if necessary. */ |
| 12170 |
/* The allowable range is related to the PIVMIN parameter; see the */ |
| 12171 |
/* comments in DLARRD. The preference for scaling small values */ |
| 12172 |
/* up is heuristic; we expect users' matrices not to be close to the */ |
| 12173 |
/* RMAX threshold. */ |
| 12174 |
|
| 12175 |
scale = 1.; |
| 12176 |
tnrm = dlanst_("M", n, &d__[1], &e[1]); |
| 12177 |
if (tnrm > 0. && tnrm < rmin) { |
| 12178 |
scale = rmin / tnrm; |
| 12179 |
} else if (tnrm > rmax) { |
| 12180 |
scale = rmax / tnrm; |
| 12181 |
} |
| 12182 |
if (scale != 1.) { |
| 12183 |
dscal_(n, &scale, &d__[1], &c__1); |
| 12184 |
i__1 = *n - 1; |
| 12185 |
dscal_(&i__1, &scale, &e[1], &c__1); |
| 12186 |
tnrm *= scale; |
| 12187 |
if (valeig) { |
| 12188 |
/* If eigenvalues in interval have to be found, */ |
| 12189 |
/* scale (WL, WU] accordingly */ |
| 12190 |
wl *= scale; |
| 12191 |
wu *= scale; |
| 12192 |
} |
| 12193 |
} |
| 12194 |
|
| 12195 |
/* Compute the desired eigenvalues of the tridiagonal after splitting */ |
| 12196 |
/* into smaller subblocks if the corresponding off-diagonal elements */ |
| 12197 |
/* are small */ |
| 12198 |
/* THRESH is the splitting parameter for DLARRE */ |
| 12199 |
/* A negative THRESH forces the old splitting criterion based on the */ |
| 12200 |
/* size of the off-diagonal. A positive THRESH switches to splitting */ |
| 12201 |
/* which preserves relative accuracy. */ |
| 12202 |
|
| 12203 |
if (*tryrac) { |
| 12204 |
/* Test whether the matrix warrants the more expensive relative approach. */ |
| 12205 |
dlarrr_(n, &d__[1], &e[1], &iinfo); |
| 12206 |
} else { |
| 12207 |
/* The user does not care about relative accurately eigenvalues */ |
| 12208 |
iinfo = -1; |
| 12209 |
} |
| 12210 |
/* Set the splitting criterion */ |
| 12211 |
if (iinfo == 0) { |
| 12212 |
thresh = eps; |
| 12213 |
} else { |
| 12214 |
thresh = -eps; |
| 12215 |
/* relative accuracy is desired but T does not guarantee it */ |
| 12216 |
*tryrac = false; |
| 12217 |
} |
| 12218 |
|
| 12219 |
if (*tryrac) { |
| 12220 |
/* Copy original diagonal, needed to guarantee relative accuracy */ |
| 12221 |
dcopy_(n, &d__[1], &c__1, &work[indd], &c__1); |
| 12222 |
} |
| 12223 |
/* Store the squares of the offdiagonal values of T */ |
| 12224 |
i__1 = *n - 1; |
| 12225 |
for (j = 1; j <= i__1; ++j) { |
| 12226 |
/* Computing 2nd power */ |
| 12227 |
d__1 = e[j]; |
| 12228 |
work[inde2 + j - 1] = d__1 * d__1; |
| 12229 |
/* L5: */ |
| 12230 |
} |
| 12231 |
/* Set the tolerance parameters for bisection */ |
| 12232 |
if (! wantz) { |
| 12233 |
/* DLARRE computes the eigenvalues to full precision. */ |
| 12234 |
rtol1 = eps * 4.; |
| 12235 |
rtol2 = eps * 4.; |
| 12236 |
} else { |
| 12237 |
/* DLARRE computes the eigenvalues to less than full precision. */ |
| 12238 |
/* DLARRV will refine the eigenvalue approximations, and we can */ |
| 12239 |
/* need less accurate initial bisection in DLARRE. */ |
| 12240 |
/* Note: these settings do only affect the subset case and DLARRE */ |
| 12241 |
rtol1 = sqrt(eps); |
| 12242 |
/* Computing MAX */ |
| 12243 |
d__1 = sqrt(eps) * .005, d__2 = eps * 4.; |
| 12244 |
rtol2 = std::max(d__1,d__2); |
| 12245 |
} |
| 12246 |
dlarre_(range, n, &wl, &wu, &iil, &iiu, &d__[1], &e[1], &work[inde2], & |
| 12247 |
rtol1, &rtol2, &thresh, &nsplit, &iwork[iinspl], m, &w[1], &work[ |
| 12248 |
inderr], &work[indgp], &iwork[iindbl], &iwork[iindw], &work[ |
| 12249 |
indgrs], &pivmin, &work[indwrk], &iwork[iindwk], &iinfo); |
| 12250 |
if (iinfo != 0) { |
| 12251 |
*info = abs(iinfo) + 10; |
| 12252 |
return 0; |
| 12253 |
} |
| 12254 |
/* Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired */ |
| 12255 |
/* part of the spectrum. All desired eigenvalues are contained in */ |
| 12256 |
/* (WL,WU] */ |
| 12257 |
if (wantz) { |
| 12258 |
|
| 12259 |
/* Compute the desired eigenvectors corresponding to the computed */ |
| 12260 |
/* eigenvalues */ |
| 12261 |
|
| 12262 |
dlarrv_(n, &wl, &wu, &d__[1], &e[1], &pivmin, &iwork[iinspl], m, & |
| 12263 |
c__1, m, &c_b18, &rtol1, &rtol2, &w[1], &work[inderr], &work[ |
| 12264 |
indgp], &iwork[iindbl], &iwork[iindw], &work[indgrs], &z__[ |
| 12265 |
z_offset], ldz, &isuppz[1], &work[indwrk], &iwork[iindwk], & |
| 12266 |
iinfo); |
| 12267 |
if (iinfo != 0) { |
| 12268 |
*info = abs(iinfo) + 20; |
| 12269 |
return 0; |
| 12270 |
} |
| 12271 |
} else { |
| 12272 |
/* DLARRE computes eigenvalues of the (shifted) root representation */ |
| 12273 |
/* DLARRV returns the eigenvalues of the unshifted matrix. */ |
| 12274 |
/* However, if the eigenvectors are not desired by the user, we need */ |
| 12275 |
/* to apply the corresponding shifts from DLARRE to obtain the */ |
| 12276 |
/* eigenvalues of the original matrix. */ |
| 12277 |
i__1 = *m; |
| 12278 |
for (j = 1; j <= i__1; ++j) { |
| 12279 |
itmp = iwork[iindbl + j - 1]; |
| 12280 |
w[j] += e[iwork[iinspl + itmp - 1]]; |
| 12281 |
/* L20: */ |
| 12282 |
} |
| 12283 |
} |
| 12284 |
|
| 12285 |
if (*tryrac) { |
| 12286 |
/* Refine computed eigenvalues so that they are relatively accurate */ |
| 12287 |
/* with respect to the original matrix T. */ |
| 12288 |
ibegin = 1; |
| 12289 |
wbegin = 1; |
| 12290 |
i__1 = iwork[iindbl + *m - 1]; |
| 12291 |
for (jblk = 1; jblk <= i__1; ++jblk) { |
| 12292 |
iend = iwork[iinspl + jblk - 1]; |
| 12293 |
in = iend - ibegin + 1; |
| 12294 |
wend = wbegin - 1; |
| 12295 |
/* check if any eigenvalues have to be refined in this block */ |
| 12296 |
L36: |
| 12297 |
if (wend < *m) { |
| 12298 |
if (iwork[iindbl + wend] == jblk) { |
| 12299 |
++wend; |
| 12300 |
goto L36; |
| 12301 |
} |
| 12302 |
} |
| 12303 |
if (wend < wbegin) { |
| 12304 |
ibegin = iend + 1; |
| 12305 |
goto L39; |
| 12306 |
} |
| 12307 |
offset = iwork[iindw + wbegin - 1] - 1; |
| 12308 |
ifirst = iwork[iindw + wbegin - 1]; |
| 12309 |
ilast = iwork[iindw + wend - 1]; |
| 12310 |
rtol2 = eps * 4.; |
| 12311 |
dlarrj_(&in, &work[indd + ibegin - 1], &work[inde2 + ibegin - 1], |
| 12312 |
&ifirst, &ilast, &rtol2, &offset, &w[wbegin], &work[ |
| 12313 |
inderr + wbegin - 1], &work[indwrk], &iwork[iindwk], & |
| 12314 |
pivmin, &tnrm, &iinfo); |
| 12315 |
ibegin = iend + 1; |
| 12316 |
wbegin = wend + 1; |
| 12317 |
L39: |
| 12318 |
; |
| 12319 |
} |
| 12320 |
} |
| 12321 |
|
| 12322 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 12323 |
|
| 12324 |
if (scale != 1.) { |
| 12325 |
d__1 = 1. / scale; |
| 12326 |
dscal_(m, &d__1, &w[1], &c__1); |
| 12327 |
} |
| 12328 |
|
| 12329 |
/* If eigenvalues are not in increasing order, then sort them, */ |
| 12330 |
/* possibly along with eigenvectors. */ |
| 12331 |
|
| 12332 |
if (nsplit > 1) { |
| 12333 |
if (! wantz) { |
| 12334 |
dlasrt_("I", m, &w[1], &iinfo); |
| 12335 |
if (iinfo != 0) { |
| 12336 |
*info = 3; |
| 12337 |
return 0; |
| 12338 |
} |
| 12339 |
} else { |
| 12340 |
i__1 = *m - 1; |
| 12341 |
for (j = 1; j <= i__1; ++j) { |
| 12342 |
i__ = 0; |
| 12343 |
tmp = w[j]; |
| 12344 |
i__2 = *m; |
| 12345 |
for (jj = j + 1; jj <= i__2; ++jj) { |
| 12346 |
if (w[jj] < tmp) { |
| 12347 |
i__ = jj; |
| 12348 |
tmp = w[jj]; |
| 12349 |
} |
| 12350 |
/* L50: */ |
| 12351 |
} |
| 12352 |
if (i__ != 0) { |
| 12353 |
w[i__] = w[j]; |
| 12354 |
w[j] = tmp; |
| 12355 |
if (wantz) { |
| 12356 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * |
| 12357 |
z_dim1 + 1], &c__1); |
| 12358 |
itmp = isuppz[(i__ << 1) - 1]; |
| 12359 |
isuppz[(i__ << 1) - 1] = isuppz[(j << 1) - 1]; |
| 12360 |
isuppz[(j << 1) - 1] = itmp; |
| 12361 |
itmp = isuppz[i__ * 2]; |
| 12362 |
isuppz[i__ * 2] = isuppz[j * 2]; |
| 12363 |
isuppz[j * 2] = itmp; |
| 12364 |
} |
| 12365 |
} |
| 12366 |
/* L60: */ |
| 12367 |
} |
| 12368 |
} |
| 12369 |
} |
| 12370 |
|
| 12371 |
|
| 12372 |
work[1] = (double) lwmin; |
| 12373 |
iwork[1] = liwmin; |
| 12374 |
return 0; |
| 12375 |
|
| 12376 |
/* End of DSTEMR */ |
| 12377 |
|
| 12378 |
} /* dstemr_ */ |
| 12379 |
|
| 12380 |
/* Subroutine */ int dsteqr_(const char *compz, integer *n, double *d__, |
| 12381 |
double *e, double *z__, integer *ldz, double *work, |
| 12382 |
integer *info) |
| 12383 |
{ |
| 12384 |
/* Table of constant values */ |
| 12385 |
static double c_b9 = 0.; |
| 12386 |
static double c_b10 = 1.; |
| 12387 |
static integer c__0 = 0; |
| 12388 |
static integer c__1 = 1; |
| 12389 |
static integer c__2 = 2; |
| 12390 |
|
| 12391 |
/* System generated locals */ |
| 12392 |
integer z_dim1, z_offset, i__1, i__2; |
| 12393 |
double d__1, d__2; |
| 12394 |
|
| 12395 |
/* Local variables */ |
| 12396 |
double b, c__, f, g; |
| 12397 |
integer i__, j, k, l, m; |
| 12398 |
double p, r__, s; |
| 12399 |
integer l1, ii, mm, lm1, mm1, nm1; |
| 12400 |
double rt1, rt2, eps; |
| 12401 |
integer lsv; |
| 12402 |
double tst, eps2; |
| 12403 |
integer lend, jtot; |
| 12404 |
double anorm; |
| 12405 |
integer lendm1, lendp1; |
| 12406 |
integer iscale; |
| 12407 |
double safmin; |
| 12408 |
double safmax; |
| 12409 |
integer lendsv; |
| 12410 |
double ssfmin; |
| 12411 |
integer nmaxit, icompz; |
| 12412 |
double ssfmax; |
| 12413 |
|
| 12414 |
|
| 12415 |
/* -- LAPACK routine (version 3.1) -- */ |
| 12416 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 12417 |
/* November 2006 */ |
| 12418 |
|
| 12419 |
/* .. Scalar Arguments .. */ |
| 12420 |
/* .. */ |
| 12421 |
/* .. Array Arguments .. */ |
| 12422 |
/* .. */ |
| 12423 |
|
| 12424 |
/* Purpose */ |
| 12425 |
/* ======= */ |
| 12426 |
|
| 12427 |
/* DSTEQR computes all eigenvalues and, optionally, eigenvectors of a */ |
| 12428 |
/* symmetric tridiagonal matrix using the implicit QL or QR method. */ |
| 12429 |
/* The eigenvectors of a full or band symmetric matrix can also be found */ |
| 12430 |
/* if DSYTRD or DSPTRD or DSBTRD has been used to reduce this matrix to */ |
| 12431 |
/* tridiagonal form. */ |
| 12432 |
|
| 12433 |
/* Arguments */ |
| 12434 |
/* ========= */ |
| 12435 |
|
| 12436 |
/* COMPZ (input) CHARACTER*1 */ |
| 12437 |
/* = 'N': Compute eigenvalues only. */ |
| 12438 |
/* = 'V': Compute eigenvalues and eigenvectors of the original */ |
| 12439 |
/* symmetric matrix. On entry, Z must contain the */ |
| 12440 |
/* orthogonal matrix used to reduce the original matrix */ |
| 12441 |
/* to tridiagonal form. */ |
| 12442 |
/* = 'I': Compute eigenvalues and eigenvectors of the */ |
| 12443 |
/* tridiagonal matrix. Z is initialized to the identity */ |
| 12444 |
/* matrix. */ |
| 12445 |
|
| 12446 |
/* N (input) INTEGER */ |
| 12447 |
/* The order of the matrix. N >= 0. */ |
| 12448 |
|
| 12449 |
/* D (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 12450 |
/* On entry, the diagonal elements of the tridiagonal matrix. */ |
| 12451 |
/* On exit, if INFO = 0, the eigenvalues in ascending order. */ |
| 12452 |
|
| 12453 |
/* E (input/output) DOUBLE PRECISION array, dimension (N-1) */ |
| 12454 |
/* On entry, the (n-1) subdiagonal elements of the tridiagonal */ |
| 12455 |
/* matrix. */ |
| 12456 |
/* On exit, E has been destroyed. */ |
| 12457 |
|
| 12458 |
/* Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 12459 |
/* On entry, if COMPZ = 'V', then Z contains the orthogonal */ |
| 12460 |
/* matrix used in the reduction to tridiagonal form. */ |
| 12461 |
/* On exit, if INFO = 0, then if COMPZ = 'V', Z contains the */ |
| 12462 |
/* orthonormal eigenvectors of the original symmetric matrix, */ |
| 12463 |
/* and if COMPZ = 'I', Z contains the orthonormal eigenvectors */ |
| 12464 |
/* of the symmetric tridiagonal matrix. */ |
| 12465 |
/* If COMPZ = 'N', then Z is not referenced. */ |
| 12466 |
|
| 12467 |
/* LDZ (input) INTEGER */ |
| 12468 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 12469 |
/* eigenvectors are desired, then LDZ >= max(1,N). */ |
| 12470 |
|
| 12471 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (max(1,2*N-2)) */ |
| 12472 |
/* If COMPZ = 'N', then WORK is not referenced. */ |
| 12473 |
|
| 12474 |
/* INFO (output) INTEGER */ |
| 12475 |
/* = 0: successful exit */ |
| 12476 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 12477 |
/* > 0: the algorithm has failed to find all the eigenvalues in */ |
| 12478 |
/* a total of 30*N iterations; if INFO = i, then i */ |
| 12479 |
/* elements of E have not converged to zero; on exit, D */ |
| 12480 |
/* and E contain the elements of a symmetric tridiagonal */ |
| 12481 |
/* matrix which is orthogonally similar to the original */ |
| 12482 |
/* matrix. */ |
| 12483 |
|
| 12484 |
/* ===================================================================== */ |
| 12485 |
|
| 12486 |
/* .. Parameters .. */ |
| 12487 |
/* .. */ |
| 12488 |
/* .. Local Scalars .. */ |
| 12489 |
/* .. */ |
| 12490 |
/* .. External Functions .. */ |
| 12491 |
/* .. */ |
| 12492 |
/* .. External Subroutines .. */ |
| 12493 |
/* .. */ |
| 12494 |
/* .. Intrinsic Functions .. */ |
| 12495 |
/* .. */ |
| 12496 |
/* .. Executable Statements .. */ |
| 12497 |
|
| 12498 |
/* Test the input parameters. */ |
| 12499 |
|
| 12500 |
/* Parameter adjustments */ |
| 12501 |
--d__; |
| 12502 |
--e; |
| 12503 |
z_dim1 = *ldz; |
| 12504 |
z_offset = 1 + z_dim1; |
| 12505 |
z__ -= z_offset; |
| 12506 |
--work; |
| 12507 |
|
| 12508 |
/* Function Body */ |
| 12509 |
*info = 0; |
| 12510 |
|
| 12511 |
if (lsame_(compz, "N")) { |
| 12512 |
icompz = 0; |
| 12513 |
} else if (lsame_(compz, "V")) { |
| 12514 |
icompz = 1; |
| 12515 |
} else if (lsame_(compz, "I")) { |
| 12516 |
icompz = 2; |
| 12517 |
} else { |
| 12518 |
icompz = -1; |
| 12519 |
} |
| 12520 |
if (icompz < 0) { |
| 12521 |
*info = -1; |
| 12522 |
} else if (*n < 0) { |
| 12523 |
*info = -2; |
| 12524 |
} else if (*ldz < 1 || icompz > 0 && *ldz < std::max(1_integer,*n)) { |
| 12525 |
*info = -6; |
| 12526 |
} |
| 12527 |
if (*info != 0) { |
| 12528 |
i__1 = -(*info); |
| 12529 |
xerbla_("DSTEQR", &i__1); |
| 12530 |
return 0; |
| 12531 |
} |
| 12532 |
|
| 12533 |
/* Quick return if possible */ |
| 12534 |
|
| 12535 |
if (*n == 0) { |
| 12536 |
return 0; |
| 12537 |
} |
| 12538 |
|
| 12539 |
if (*n == 1) { |
| 12540 |
if (icompz == 2) { |
| 12541 |
z__[z_dim1 + 1] = 1.; |
| 12542 |
} |
| 12543 |
return 0; |
| 12544 |
} |
| 12545 |
|
| 12546 |
/* Determine the unit roundoff and over/underflow thresholds. */ |
| 12547 |
|
| 12548 |
eps = dlamch_("E"); |
| 12549 |
/* Computing 2nd power */ |
| 12550 |
d__1 = eps; |
| 12551 |
eps2 = d__1 * d__1; |
| 12552 |
safmin = dlamch_("S"); |
| 12553 |
safmax = 1. / safmin; |
| 12554 |
ssfmax = sqrt(safmax) / 3.; |
| 12555 |
ssfmin = sqrt(safmin) / eps2; |
| 12556 |
|
| 12557 |
/* Compute the eigenvalues and eigenvectors of the tridiagonal */ |
| 12558 |
/* matrix. */ |
| 12559 |
|
| 12560 |
if (icompz == 2) { |
| 12561 |
dlaset_("Full", n, n, &c_b9, &c_b10, &z__[z_offset], ldz); |
| 12562 |
} |
| 12563 |
|
| 12564 |
nmaxit = *n * 30; |
| 12565 |
jtot = 0; |
| 12566 |
|
| 12567 |
/* Determine where the matrix splits and choose QL or QR iteration */ |
| 12568 |
/* for each block, according to whether top or bottom diagonal */ |
| 12569 |
/* element is smaller. */ |
| 12570 |
|
| 12571 |
l1 = 1; |
| 12572 |
nm1 = *n - 1; |
| 12573 |
|
| 12574 |
L10: |
| 12575 |
if (l1 > *n) { |
| 12576 |
goto L160; |
| 12577 |
} |
| 12578 |
if (l1 > 1) { |
| 12579 |
e[l1 - 1] = 0.; |
| 12580 |
} |
| 12581 |
if (l1 <= nm1) { |
| 12582 |
i__1 = nm1; |
| 12583 |
for (m = l1; m <= i__1; ++m) { |
| 12584 |
tst = (d__1 = e[m], abs(d__1)); |
| 12585 |
if (tst == 0.) { |
| 12586 |
goto L30; |
| 12587 |
} |
| 12588 |
if (tst <= sqrt((d__1 = d__[m], abs(d__1))) * sqrt((d__2 = d__[m |
| 12589 |
+ 1], abs(d__2))) * eps) { |
| 12590 |
e[m] = 0.; |
| 12591 |
goto L30; |
| 12592 |
} |
| 12593 |
/* L20: */ |
| 12594 |
} |
| 12595 |
} |
| 12596 |
m = *n; |
| 12597 |
|
| 12598 |
L30: |
| 12599 |
l = l1; |
| 12600 |
lsv = l; |
| 12601 |
lend = m; |
| 12602 |
lendsv = lend; |
| 12603 |
l1 = m + 1; |
| 12604 |
if (lend == l) { |
| 12605 |
goto L10; |
| 12606 |
} |
| 12607 |
|
| 12608 |
/* Scale submatrix in rows and columns L to LEND */ |
| 12609 |
|
| 12610 |
i__1 = lend - l + 1; |
| 12611 |
anorm = dlanst_("I", &i__1, &d__[l], &e[l]); |
| 12612 |
iscale = 0; |
| 12613 |
if (anorm == 0.) { |
| 12614 |
goto L10; |
| 12615 |
} |
| 12616 |
if (anorm > ssfmax) { |
| 12617 |
iscale = 1; |
| 12618 |
i__1 = lend - l + 1; |
| 12619 |
dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &d__[l], n, |
| 12620 |
info); |
| 12621 |
i__1 = lend - l; |
| 12622 |
dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &e[l], n, |
| 12623 |
info); |
| 12624 |
} else if (anorm < ssfmin) { |
| 12625 |
iscale = 2; |
| 12626 |
i__1 = lend - l + 1; |
| 12627 |
dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &d__[l], n, |
| 12628 |
info); |
| 12629 |
i__1 = lend - l; |
| 12630 |
dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &e[l], n, |
| 12631 |
info); |
| 12632 |
} |
| 12633 |
|
| 12634 |
/* Choose between QL and QR iteration */ |
| 12635 |
|
| 12636 |
if ((d__1 = d__[lend], abs(d__1)) < (d__2 = d__[l], abs(d__2))) { |
| 12637 |
lend = lsv; |
| 12638 |
l = lendsv; |
| 12639 |
} |
| 12640 |
|
| 12641 |
if (lend > l) { |
| 12642 |
|
| 12643 |
/* QL Iteration */ |
| 12644 |
|
| 12645 |
/* Look for small subdiagonal element. */ |
| 12646 |
|
| 12647 |
L40: |
| 12648 |
if (l != lend) { |
| 12649 |
lendm1 = lend - 1; |
| 12650 |
i__1 = lendm1; |
| 12651 |
for (m = l; m <= i__1; ++m) { |
| 12652 |
/* Computing 2nd power */ |
| 12653 |
d__2 = (d__1 = e[m], abs(d__1)); |
| 12654 |
tst = d__2 * d__2; |
| 12655 |
if (tst <= eps2 * (d__1 = d__[m], abs(d__1)) * (d__2 = d__[m |
| 12656 |
+ 1], abs(d__2)) + safmin) { |
| 12657 |
goto L60; |
| 12658 |
} |
| 12659 |
/* L50: */ |
| 12660 |
} |
| 12661 |
} |
| 12662 |
|
| 12663 |
m = lend; |
| 12664 |
|
| 12665 |
L60: |
| 12666 |
if (m < lend) { |
| 12667 |
e[m] = 0.; |
| 12668 |
} |
| 12669 |
p = d__[l]; |
| 12670 |
if (m == l) { |
| 12671 |
goto L80; |
| 12672 |
} |
| 12673 |
|
| 12674 |
/* If remaining matrix is 2-by-2, use DLAE2 or SLAEV2 */ |
| 12675 |
/* to compute its eigensystem. */ |
| 12676 |
|
| 12677 |
if (m == l + 1) { |
| 12678 |
if (icompz > 0) { |
| 12679 |
dlaev2_(&d__[l], &e[l], &d__[l + 1], &rt1, &rt2, &c__, &s); |
| 12680 |
work[l] = c__; |
| 12681 |
work[*n - 1 + l] = s; |
| 12682 |
dlasr_("R", "V", "B", n, &c__2, &work[l], &work[*n - 1 + l], & |
| 12683 |
z__[l * z_dim1 + 1], ldz); |
| 12684 |
} else { |
| 12685 |
dlae2_(&d__[l], &e[l], &d__[l + 1], &rt1, &rt2); |
| 12686 |
} |
| 12687 |
d__[l] = rt1; |
| 12688 |
d__[l + 1] = rt2; |
| 12689 |
e[l] = 0.; |
| 12690 |
l += 2; |
| 12691 |
if (l <= lend) { |
| 12692 |
goto L40; |
| 12693 |
} |
| 12694 |
goto L140; |
| 12695 |
} |
| 12696 |
|
| 12697 |
if (jtot == nmaxit) { |
| 12698 |
goto L140; |
| 12699 |
} |
| 12700 |
++jtot; |
| 12701 |
|
| 12702 |
/* Form shift. */ |
| 12703 |
|
| 12704 |
g = (d__[l + 1] - p) / (e[l] * 2.); |
| 12705 |
r__ = dlapy2_(&g, &c_b10); |
| 12706 |
g = d__[m] - p + e[l] / (g + d_sign(&r__, &g)); |
| 12707 |
|
| 12708 |
s = 1.; |
| 12709 |
c__ = 1.; |
| 12710 |
p = 0.; |
| 12711 |
|
| 12712 |
/* Inner loop */ |
| 12713 |
|
| 12714 |
mm1 = m - 1; |
| 12715 |
i__1 = l; |
| 12716 |
for (i__ = mm1; i__ >= i__1; --i__) { |
| 12717 |
f = s * e[i__]; |
| 12718 |
b = c__ * e[i__]; |
| 12719 |
dlartg_(&g, &f, &c__, &s, &r__); |
| 12720 |
if (i__ != m - 1) { |
| 12721 |
e[i__ + 1] = r__; |
| 12722 |
} |
| 12723 |
g = d__[i__ + 1] - p; |
| 12724 |
r__ = (d__[i__] - g) * s + c__ * 2. * b; |
| 12725 |
p = s * r__; |
| 12726 |
d__[i__ + 1] = g + p; |
| 12727 |
g = c__ * r__ - b; |
| 12728 |
|
| 12729 |
/* If eigenvectors are desired, then save rotations. */ |
| 12730 |
|
| 12731 |
if (icompz > 0) { |
| 12732 |
work[i__] = c__; |
| 12733 |
work[*n - 1 + i__] = -s; |
| 12734 |
} |
| 12735 |
|
| 12736 |
/* L70: */ |
| 12737 |
} |
| 12738 |
|
| 12739 |
/* If eigenvectors are desired, then apply saved rotations. */ |
| 12740 |
|
| 12741 |
if (icompz > 0) { |
| 12742 |
mm = m - l + 1; |
| 12743 |
dlasr_("R", "V", "B", n, &mm, &work[l], &work[*n - 1 + l], &z__[l |
| 12744 |
* z_dim1 + 1], ldz); |
| 12745 |
} |
| 12746 |
|
| 12747 |
d__[l] -= p; |
| 12748 |
e[l] = g; |
| 12749 |
goto L40; |
| 12750 |
|
| 12751 |
/* Eigenvalue found. */ |
| 12752 |
|
| 12753 |
L80: |
| 12754 |
d__[l] = p; |
| 12755 |
|
| 12756 |
++l; |
| 12757 |
if (l <= lend) { |
| 12758 |
goto L40; |
| 12759 |
} |
| 12760 |
goto L140; |
| 12761 |
|
| 12762 |
} else { |
| 12763 |
|
| 12764 |
/* QR Iteration */ |
| 12765 |
|
| 12766 |
/* Look for small superdiagonal element. */ |
| 12767 |
|
| 12768 |
L90: |
| 12769 |
if (l != lend) { |
| 12770 |
lendp1 = lend + 1; |
| 12771 |
i__1 = lendp1; |
| 12772 |
for (m = l; m >= i__1; --m) { |
| 12773 |
/* Computing 2nd power */ |
| 12774 |
d__2 = (d__1 = e[m - 1], abs(d__1)); |
| 12775 |
tst = d__2 * d__2; |
| 12776 |
if (tst <= eps2 * (d__1 = d__[m], abs(d__1)) * (d__2 = d__[m |
| 12777 |
- 1], abs(d__2)) + safmin) { |
| 12778 |
goto L110; |
| 12779 |
} |
| 12780 |
/* L100: */ |
| 12781 |
} |
| 12782 |
} |
| 12783 |
|
| 12784 |
m = lend; |
| 12785 |
|
| 12786 |
L110: |
| 12787 |
if (m > lend) { |
| 12788 |
e[m - 1] = 0.; |
| 12789 |
} |
| 12790 |
p = d__[l]; |
| 12791 |
if (m == l) { |
| 12792 |
goto L130; |
| 12793 |
} |
| 12794 |
|
| 12795 |
/* If remaining matrix is 2-by-2, use DLAE2 or SLAEV2 */ |
| 12796 |
/* to compute its eigensystem. */ |
| 12797 |
|
| 12798 |
if (m == l - 1) { |
| 12799 |
if (icompz > 0) { |
| 12800 |
dlaev2_(&d__[l - 1], &e[l - 1], &d__[l], &rt1, &rt2, &c__, &s) |
| 12801 |
; |
| 12802 |
work[m] = c__; |
| 12803 |
work[*n - 1 + m] = s; |
| 12804 |
dlasr_("R", "V", "F", n, &c__2, &work[m], &work[*n - 1 + m], & |
| 12805 |
z__[(l - 1) * z_dim1 + 1], ldz); |
| 12806 |
} else { |
| 12807 |
dlae2_(&d__[l - 1], &e[l - 1], &d__[l], &rt1, &rt2); |
| 12808 |
} |
| 12809 |
d__[l - 1] = rt1; |
| 12810 |
d__[l] = rt2; |
| 12811 |
e[l - 1] = 0.; |
| 12812 |
l += -2; |
| 12813 |
if (l >= lend) { |
| 12814 |
goto L90; |
| 12815 |
} |
| 12816 |
goto L140; |
| 12817 |
} |
| 12818 |
|
| 12819 |
if (jtot == nmaxit) { |
| 12820 |
goto L140; |
| 12821 |
} |
| 12822 |
++jtot; |
| 12823 |
|
| 12824 |
/* Form shift. */ |
| 12825 |
|
| 12826 |
g = (d__[l - 1] - p) / (e[l - 1] * 2.); |
| 12827 |
r__ = dlapy2_(&g, &c_b10); |
| 12828 |
g = d__[m] - p + e[l - 1] / (g + d_sign(&r__, &g)); |
| 12829 |
|
| 12830 |
s = 1.; |
| 12831 |
c__ = 1.; |
| 12832 |
p = 0.; |
| 12833 |
|
| 12834 |
/* Inner loop */ |
| 12835 |
|
| 12836 |
lm1 = l - 1; |
| 12837 |
i__1 = lm1; |
| 12838 |
for (i__ = m; i__ <= i__1; ++i__) { |
| 12839 |
f = s * e[i__]; |
| 12840 |
b = c__ * e[i__]; |
| 12841 |
dlartg_(&g, &f, &c__, &s, &r__); |
| 12842 |
if (i__ != m) { |
| 12843 |
e[i__ - 1] = r__; |
| 12844 |
} |
| 12845 |
g = d__[i__] - p; |
| 12846 |
r__ = (d__[i__ + 1] - g) * s + c__ * 2. * b; |
| 12847 |
p = s * r__; |
| 12848 |
d__[i__] = g + p; |
| 12849 |
g = c__ * r__ - b; |
| 12850 |
|
| 12851 |
/* If eigenvectors are desired, then save rotations. */ |
| 12852 |
|
| 12853 |
if (icompz > 0) { |
| 12854 |
work[i__] = c__; |
| 12855 |
work[*n - 1 + i__] = s; |
| 12856 |
} |
| 12857 |
|
| 12858 |
/* L120: */ |
| 12859 |
} |
| 12860 |
|
| 12861 |
/* If eigenvectors are desired, then apply saved rotations. */ |
| 12862 |
|
| 12863 |
if (icompz > 0) { |
| 12864 |
mm = l - m + 1; |
| 12865 |
dlasr_("R", "V", "F", n, &mm, &work[m], &work[*n - 1 + m], &z__[m |
| 12866 |
* z_dim1 + 1], ldz); |
| 12867 |
} |
| 12868 |
|
| 12869 |
d__[l] -= p; |
| 12870 |
e[lm1] = g; |
| 12871 |
goto L90; |
| 12872 |
|
| 12873 |
/* Eigenvalue found. */ |
| 12874 |
|
| 12875 |
L130: |
| 12876 |
d__[l] = p; |
| 12877 |
|
| 12878 |
--l; |
| 12879 |
if (l >= lend) { |
| 12880 |
goto L90; |
| 12881 |
} |
| 12882 |
goto L140; |
| 12883 |
|
| 12884 |
} |
| 12885 |
|
| 12886 |
/* Undo scaling if necessary */ |
| 12887 |
|
| 12888 |
L140: |
| 12889 |
if (iscale == 1) { |
| 12890 |
i__1 = lendsv - lsv + 1; |
| 12891 |
dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &d__[lsv], |
| 12892 |
n, info); |
| 12893 |
i__1 = lendsv - lsv; |
| 12894 |
dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &e[lsv], n, |
| 12895 |
info); |
| 12896 |
} else if (iscale == 2) { |
| 12897 |
i__1 = lendsv - lsv + 1; |
| 12898 |
dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &d__[lsv], |
| 12899 |
n, info); |
| 12900 |
i__1 = lendsv - lsv; |
| 12901 |
dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &e[lsv], n, |
| 12902 |
info); |
| 12903 |
} |
| 12904 |
|
| 12905 |
/* Check for no convergence to an eigenvalue after a total */ |
| 12906 |
/* of N*MAXIT iterations. */ |
| 12907 |
|
| 12908 |
if (jtot < nmaxit) { |
| 12909 |
goto L10; |
| 12910 |
} |
| 12911 |
i__1 = *n - 1; |
| 12912 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 12913 |
if (e[i__] != 0.) { |
| 12914 |
++(*info); |
| 12915 |
} |
| 12916 |
/* L150: */ |
| 12917 |
} |
| 12918 |
goto L190; |
| 12919 |
|
| 12920 |
/* Order eigenvalues and eigenvectors. */ |
| 12921 |
|
| 12922 |
L160: |
| 12923 |
if (icompz == 0) { |
| 12924 |
|
| 12925 |
/* Use Quick Sort */ |
| 12926 |
|
| 12927 |
dlasrt_("I", n, &d__[1], info); |
| 12928 |
|
| 12929 |
} else { |
| 12930 |
|
| 12931 |
/* Use Selection Sort to minimize swaps of eigenvectors */ |
| 12932 |
|
| 12933 |
i__1 = *n; |
| 12934 |
for (ii = 2; ii <= i__1; ++ii) { |
| 12935 |
i__ = ii - 1; |
| 12936 |
k = i__; |
| 12937 |
p = d__[i__]; |
| 12938 |
i__2 = *n; |
| 12939 |
for (j = ii; j <= i__2; ++j) { |
| 12940 |
if (d__[j] < p) { |
| 12941 |
k = j; |
| 12942 |
p = d__[j]; |
| 12943 |
} |
| 12944 |
/* L170: */ |
| 12945 |
} |
| 12946 |
if (k != i__) { |
| 12947 |
d__[k] = d__[i__]; |
| 12948 |
d__[i__] = p; |
| 12949 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[k * z_dim1 + 1], |
| 12950 |
&c__1); |
| 12951 |
} |
| 12952 |
/* L180: */ |
| 12953 |
} |
| 12954 |
} |
| 12955 |
|
| 12956 |
L190: |
| 12957 |
return 0; |
| 12958 |
|
| 12959 |
/* End of DSTEQR */ |
| 12960 |
|
| 12961 |
} /* dsteqr_ */ |
| 12962 |
|
| 12963 |
/* Subroutine */ int dsterf_(integer *n, double *d__, double *e, |
| 12964 |
integer *info) |
| 12965 |
{ |
| 12966 |
/* Table of constant values */ |
| 12967 |
static integer c__0 = 0; |
| 12968 |
static integer c__1 = 1; |
| 12969 |
static double c_b32 = 1.; |
| 12970 |
|
| 12971 |
/* System generated locals */ |
| 12972 |
integer i__1; |
| 12973 |
double d__1, d__2, d__3; |
| 12974 |
|
| 12975 |
/* Local variables */ |
| 12976 |
double c__; |
| 12977 |
integer i__, l, m; |
| 12978 |
double p, r__, s; |
| 12979 |
integer l1; |
| 12980 |
double bb, rt1, rt2, eps, rte; |
| 12981 |
integer lsv; |
| 12982 |
double eps2, oldc; |
| 12983 |
integer lend, jtot; |
| 12984 |
double gamma, alpha, sigma, anorm; |
| 12985 |
integer iscale; |
| 12986 |
double oldgam, safmin; |
| 12987 |
double safmax; |
| 12988 |
integer lendsv; |
| 12989 |
double ssfmin; |
| 12990 |
integer nmaxit; |
| 12991 |
double ssfmax; |
| 12992 |
|
| 12993 |
|
| 12994 |
/* -- LAPACK routine (version 3.1) -- */ |
| 12995 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 12996 |
/* November 2006 */ |
| 12997 |
|
| 12998 |
/* .. Scalar Arguments .. */ |
| 12999 |
/* .. */ |
| 13000 |
/* .. Array Arguments .. */ |
| 13001 |
/* .. */ |
| 13002 |
|
| 13003 |
/* Purpose */ |
| 13004 |
/* ======= */ |
| 13005 |
|
| 13006 |
/* DSTERF computes all eigenvalues of a symmetric tridiagonal matrix */ |
| 13007 |
/* using the Pal-Walker-Kahan variant of the QL or QR algorithm. */ |
| 13008 |
|
| 13009 |
/* Arguments */ |
| 13010 |
/* ========= */ |
| 13011 |
|
| 13012 |
/* N (input) INTEGER */ |
| 13013 |
/* The order of the matrix. N >= 0. */ |
| 13014 |
|
| 13015 |
/* D (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 13016 |
/* On entry, the n diagonal elements of the tridiagonal matrix. */ |
| 13017 |
/* On exit, if INFO = 0, the eigenvalues in ascending order. */ |
| 13018 |
|
| 13019 |
/* E (input/output) DOUBLE PRECISION array, dimension (N-1) */ |
| 13020 |
/* On entry, the (n-1) subdiagonal elements of the tridiagonal */ |
| 13021 |
/* matrix. */ |
| 13022 |
/* On exit, E has been destroyed. */ |
| 13023 |
|
| 13024 |
/* INFO (output) INTEGER */ |
| 13025 |
/* = 0: successful exit */ |
| 13026 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 13027 |
/* > 0: the algorithm failed to find all of the eigenvalues in */ |
| 13028 |
/* a total of 30*N iterations; if INFO = i, then i */ |
| 13029 |
/* elements of E have not converged to zero. */ |
| 13030 |
|
| 13031 |
/* ===================================================================== */ |
| 13032 |
|
| 13033 |
/* .. Parameters .. */ |
| 13034 |
/* .. */ |
| 13035 |
/* .. Local Scalars .. */ |
| 13036 |
/* .. */ |
| 13037 |
/* .. External Functions .. */ |
| 13038 |
/* .. */ |
| 13039 |
/* .. External Subroutines .. */ |
| 13040 |
/* .. */ |
| 13041 |
/* .. Intrinsic Functions .. */ |
| 13042 |
/* .. */ |
| 13043 |
/* .. Executable Statements .. */ |
| 13044 |
|
| 13045 |
/* Test the input parameters. */ |
| 13046 |
|
| 13047 |
/* Parameter adjustments */ |
| 13048 |
--e; |
| 13049 |
--d__; |
| 13050 |
|
| 13051 |
/* Function Body */ |
| 13052 |
*info = 0; |
| 13053 |
|
| 13054 |
/* Quick return if possible */ |
| 13055 |
|
| 13056 |
if (*n < 0) { |
| 13057 |
*info = -1; |
| 13058 |
i__1 = -(*info); |
| 13059 |
xerbla_("DSTERF", &i__1); |
| 13060 |
return 0; |
| 13061 |
} |
| 13062 |
if (*n <= 1) { |
| 13063 |
return 0; |
| 13064 |
} |
| 13065 |
|
| 13066 |
/* Determine the unit roundoff for this environment. */ |
| 13067 |
|
| 13068 |
eps = dlamch_("E"); |
| 13069 |
/* Computing 2nd power */ |
| 13070 |
d__1 = eps; |
| 13071 |
eps2 = d__1 * d__1; |
| 13072 |
safmin = dlamch_("S"); |
| 13073 |
safmax = 1. / safmin; |
| 13074 |
ssfmax = sqrt(safmax) / 3.; |
| 13075 |
ssfmin = sqrt(safmin) / eps2; |
| 13076 |
|
| 13077 |
/* Compute the eigenvalues of the tridiagonal matrix. */ |
| 13078 |
|
| 13079 |
nmaxit = *n * 30; |
| 13080 |
sigma = 0.; |
| 13081 |
jtot = 0; |
| 13082 |
|
| 13083 |
/* Determine where the matrix splits and choose QL or QR iteration */ |
| 13084 |
/* for each block, according to whether top or bottom diagonal */ |
| 13085 |
/* element is smaller. */ |
| 13086 |
|
| 13087 |
l1 = 1; |
| 13088 |
|
| 13089 |
L10: |
| 13090 |
if (l1 > *n) { |
| 13091 |
goto L170; |
| 13092 |
} |
| 13093 |
if (l1 > 1) { |
| 13094 |
e[l1 - 1] = 0.; |
| 13095 |
} |
| 13096 |
i__1 = *n - 1; |
| 13097 |
for (m = l1; m <= i__1; ++m) { |
| 13098 |
if ((d__3 = e[m], abs(d__3)) <= sqrt((d__1 = d__[m], abs(d__1))) * |
| 13099 |
sqrt((d__2 = d__[m + 1], abs(d__2))) * eps) { |
| 13100 |
e[m] = 0.; |
| 13101 |
goto L30; |
| 13102 |
} |
| 13103 |
/* L20: */ |
| 13104 |
} |
| 13105 |
m = *n; |
| 13106 |
|
| 13107 |
L30: |
| 13108 |
l = l1; |
| 13109 |
lsv = l; |
| 13110 |
lend = m; |
| 13111 |
lendsv = lend; |
| 13112 |
l1 = m + 1; |
| 13113 |
if (lend == l) { |
| 13114 |
goto L10; |
| 13115 |
} |
| 13116 |
|
| 13117 |
/* Scale submatrix in rows and columns L to LEND */ |
| 13118 |
|
| 13119 |
i__1 = lend - l + 1; |
| 13120 |
anorm = dlanst_("I", &i__1, &d__[l], &e[l]); |
| 13121 |
iscale = 0; |
| 13122 |
if (anorm > ssfmax) { |
| 13123 |
iscale = 1; |
| 13124 |
i__1 = lend - l + 1; |
| 13125 |
dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &d__[l], n, |
| 13126 |
info); |
| 13127 |
i__1 = lend - l; |
| 13128 |
dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &e[l], n, |
| 13129 |
info); |
| 13130 |
} else if (anorm < ssfmin) { |
| 13131 |
iscale = 2; |
| 13132 |
i__1 = lend - l + 1; |
| 13133 |
dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &d__[l], n, |
| 13134 |
info); |
| 13135 |
i__1 = lend - l; |
| 13136 |
dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &e[l], n, |
| 13137 |
info); |
| 13138 |
} |
| 13139 |
|
| 13140 |
i__1 = lend - 1; |
| 13141 |
for (i__ = l; i__ <= i__1; ++i__) { |
| 13142 |
/* Computing 2nd power */ |
| 13143 |
d__1 = e[i__]; |
| 13144 |
e[i__] = d__1 * d__1; |
| 13145 |
/* L40: */ |
| 13146 |
} |
| 13147 |
|
| 13148 |
/* Choose between QL and QR iteration */ |
| 13149 |
|
| 13150 |
if ((d__1 = d__[lend], abs(d__1)) < (d__2 = d__[l], abs(d__2))) { |
| 13151 |
lend = lsv; |
| 13152 |
l = lendsv; |
| 13153 |
} |
| 13154 |
|
| 13155 |
if (lend >= l) { |
| 13156 |
|
| 13157 |
/* QL Iteration */ |
| 13158 |
|
| 13159 |
/* Look for small subdiagonal element. */ |
| 13160 |
|
| 13161 |
L50: |
| 13162 |
if (l != lend) { |
| 13163 |
i__1 = lend - 1; |
| 13164 |
for (m = l; m <= i__1; ++m) { |
| 13165 |
if ((d__2 = e[m], abs(d__2)) <= eps2 * (d__1 = d__[m] * d__[m |
| 13166 |
+ 1], abs(d__1))) { |
| 13167 |
goto L70; |
| 13168 |
} |
| 13169 |
/* L60: */ |
| 13170 |
} |
| 13171 |
} |
| 13172 |
m = lend; |
| 13173 |
|
| 13174 |
L70: |
| 13175 |
if (m < lend) { |
| 13176 |
e[m] = 0.; |
| 13177 |
} |
| 13178 |
p = d__[l]; |
| 13179 |
if (m == l) { |
| 13180 |
goto L90; |
| 13181 |
} |
| 13182 |
|
| 13183 |
/* If remaining matrix is 2 by 2, use DLAE2 to compute its */ |
| 13184 |
/* eigenvalues. */ |
| 13185 |
|
| 13186 |
if (m == l + 1) { |
| 13187 |
rte = sqrt(e[l]); |
| 13188 |
dlae2_(&d__[l], &rte, &d__[l + 1], &rt1, &rt2); |
| 13189 |
d__[l] = rt1; |
| 13190 |
d__[l + 1] = rt2; |
| 13191 |
e[l] = 0.; |
| 13192 |
l += 2; |
| 13193 |
if (l <= lend) { |
| 13194 |
goto L50; |
| 13195 |
} |
| 13196 |
goto L150; |
| 13197 |
} |
| 13198 |
|
| 13199 |
if (jtot == nmaxit) { |
| 13200 |
goto L150; |
| 13201 |
} |
| 13202 |
++jtot; |
| 13203 |
|
| 13204 |
/* Form shift. */ |
| 13205 |
|
| 13206 |
rte = sqrt(e[l]); |
| 13207 |
sigma = (d__[l + 1] - p) / (rte * 2.); |
| 13208 |
r__ = dlapy2_(&sigma, &c_b32); |
| 13209 |
sigma = p - rte / (sigma + d_sign(&r__, &sigma)); |
| 13210 |
|
| 13211 |
c__ = 1.; |
| 13212 |
s = 0.; |
| 13213 |
gamma = d__[m] - sigma; |
| 13214 |
p = gamma * gamma; |
| 13215 |
|
| 13216 |
/* Inner loop */ |
| 13217 |
|
| 13218 |
i__1 = l; |
| 13219 |
for (i__ = m - 1; i__ >= i__1; --i__) { |
| 13220 |
bb = e[i__]; |
| 13221 |
r__ = p + bb; |
| 13222 |
if (i__ != m - 1) { |
| 13223 |
e[i__ + 1] = s * r__; |
| 13224 |
} |
| 13225 |
oldc = c__; |
| 13226 |
c__ = p / r__; |
| 13227 |
s = bb / r__; |
| 13228 |
oldgam = gamma; |
| 13229 |
alpha = d__[i__]; |
| 13230 |
gamma = c__ * (alpha - sigma) - s * oldgam; |
| 13231 |
d__[i__ + 1] = oldgam + (alpha - gamma); |
| 13232 |
if (c__ != 0.) { |
| 13233 |
p = gamma * gamma / c__; |
| 13234 |
} else { |
| 13235 |
p = oldc * bb; |
| 13236 |
} |
| 13237 |
/* L80: */ |
| 13238 |
} |
| 13239 |
|
| 13240 |
e[l] = s * p; |
| 13241 |
d__[l] = sigma + gamma; |
| 13242 |
goto L50; |
| 13243 |
|
| 13244 |
/* Eigenvalue found. */ |
| 13245 |
|
| 13246 |
L90: |
| 13247 |
d__[l] = p; |
| 13248 |
|
| 13249 |
++l; |
| 13250 |
if (l <= lend) { |
| 13251 |
goto L50; |
| 13252 |
} |
| 13253 |
goto L150; |
| 13254 |
|
| 13255 |
} else { |
| 13256 |
|
| 13257 |
/* QR Iteration */ |
| 13258 |
|
| 13259 |
/* Look for small superdiagonal element. */ |
| 13260 |
|
| 13261 |
L100: |
| 13262 |
i__1 = lend + 1; |
| 13263 |
for (m = l; m >= i__1; --m) { |
| 13264 |
if ((d__2 = e[m - 1], abs(d__2)) <= eps2 * (d__1 = d__[m] * d__[m |
| 13265 |
- 1], abs(d__1))) { |
| 13266 |
goto L120; |
| 13267 |
} |
| 13268 |
/* L110: */ |
| 13269 |
} |
| 13270 |
m = lend; |
| 13271 |
|
| 13272 |
L120: |
| 13273 |
if (m > lend) { |
| 13274 |
e[m - 1] = 0.; |
| 13275 |
} |
| 13276 |
p = d__[l]; |
| 13277 |
if (m == l) { |
| 13278 |
goto L140; |
| 13279 |
} |
| 13280 |
|
| 13281 |
/* If remaining matrix is 2 by 2, use DLAE2 to compute its */ |
| 13282 |
/* eigenvalues. */ |
| 13283 |
|
| 13284 |
if (m == l - 1) { |
| 13285 |
rte = sqrt(e[l - 1]); |
| 13286 |
dlae2_(&d__[l], &rte, &d__[l - 1], &rt1, &rt2); |
| 13287 |
d__[l] = rt1; |
| 13288 |
d__[l - 1] = rt2; |
| 13289 |
e[l - 1] = 0.; |
| 13290 |
l += -2; |
| 13291 |
if (l >= lend) { |
| 13292 |
goto L100; |
| 13293 |
} |
| 13294 |
goto L150; |
| 13295 |
} |
| 13296 |
|
| 13297 |
if (jtot == nmaxit) { |
| 13298 |
goto L150; |
| 13299 |
} |
| 13300 |
++jtot; |
| 13301 |
|
| 13302 |
/* Form shift. */ |
| 13303 |
|
| 13304 |
rte = sqrt(e[l - 1]); |
| 13305 |
sigma = (d__[l - 1] - p) / (rte * 2.); |
| 13306 |
r__ = dlapy2_(&sigma, &c_b32); |
| 13307 |
sigma = p - rte / (sigma + d_sign(&r__, &sigma)); |
| 13308 |
|
| 13309 |
c__ = 1.; |
| 13310 |
s = 0.; |
| 13311 |
gamma = d__[m] - sigma; |
| 13312 |
p = gamma * gamma; |
| 13313 |
|
| 13314 |
/* Inner loop */ |
| 13315 |
|
| 13316 |
i__1 = l - 1; |
| 13317 |
for (i__ = m; i__ <= i__1; ++i__) { |
| 13318 |
bb = e[i__]; |
| 13319 |
r__ = p + bb; |
| 13320 |
if (i__ != m) { |
| 13321 |
e[i__ - 1] = s * r__; |
| 13322 |
} |
| 13323 |
oldc = c__; |
| 13324 |
c__ = p / r__; |
| 13325 |
s = bb / r__; |
| 13326 |
oldgam = gamma; |
| 13327 |
alpha = d__[i__ + 1]; |
| 13328 |
gamma = c__ * (alpha - sigma) - s * oldgam; |
| 13329 |
d__[i__] = oldgam + (alpha - gamma); |
| 13330 |
if (c__ != 0.) { |
| 13331 |
p = gamma * gamma / c__; |
| 13332 |
} else { |
| 13333 |
p = oldc * bb; |
| 13334 |
} |
| 13335 |
/* L130: */ |
| 13336 |
} |
| 13337 |
|
| 13338 |
e[l - 1] = s * p; |
| 13339 |
d__[l] = sigma + gamma; |
| 13340 |
goto L100; |
| 13341 |
|
| 13342 |
/* Eigenvalue found. */ |
| 13343 |
|
| 13344 |
L140: |
| 13345 |
d__[l] = p; |
| 13346 |
|
| 13347 |
--l; |
| 13348 |
if (l >= lend) { |
| 13349 |
goto L100; |
| 13350 |
} |
| 13351 |
goto L150; |
| 13352 |
|
| 13353 |
} |
| 13354 |
|
| 13355 |
/* Undo scaling if necessary */ |
| 13356 |
|
| 13357 |
L150: |
| 13358 |
if (iscale == 1) { |
| 13359 |
i__1 = lendsv - lsv + 1; |
| 13360 |
dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &d__[lsv], |
| 13361 |
n, info); |
| 13362 |
} |
| 13363 |
if (iscale == 2) { |
| 13364 |
i__1 = lendsv - lsv + 1; |
| 13365 |
dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &d__[lsv], |
| 13366 |
n, info); |
| 13367 |
} |
| 13368 |
|
| 13369 |
/* Check for no convergence to an eigenvalue after a total */ |
| 13370 |
/* of N*MAXIT iterations. */ |
| 13371 |
|
| 13372 |
if (jtot < nmaxit) { |
| 13373 |
goto L10; |
| 13374 |
} |
| 13375 |
i__1 = *n - 1; |
| 13376 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 13377 |
if (e[i__] != 0.) { |
| 13378 |
++(*info); |
| 13379 |
} |
| 13380 |
/* L160: */ |
| 13381 |
} |
| 13382 |
goto L180; |
| 13383 |
|
| 13384 |
/* Sort eigenvalues in increasing order. */ |
| 13385 |
|
| 13386 |
L170: |
| 13387 |
dlasrt_("I", n, &d__[1], info); |
| 13388 |
|
| 13389 |
L180: |
| 13390 |
return 0; |
| 13391 |
|
| 13392 |
/* End of DSTERF */ |
| 13393 |
|
| 13394 |
} /* dsterf_ */ |
| 13395 |
|
| 13396 |
/* Subroutine */ int dstev_(const char *jobz, integer *n, double *d__, |
| 13397 |
double *e, double *z__, integer *ldz, double *work, |
| 13398 |
integer *info) |
| 13399 |
{ |
| 13400 |
/* Table of constant values */ |
| 13401 |
static integer c__1 = 1; |
| 13402 |
|
| 13403 |
/* System generated locals */ |
| 13404 |
integer z_dim1, z_offset, i__1; |
| 13405 |
double d__1; |
| 13406 |
|
| 13407 |
/* Local variables */ |
| 13408 |
double eps; |
| 13409 |
integer imax; |
| 13410 |
double rmin, rmax, tnrm; |
| 13411 |
double sigma; |
| 13412 |
bool wantz; |
| 13413 |
integer iscale; |
| 13414 |
double safmin; |
| 13415 |
double bignum; |
| 13416 |
double smlnum; |
| 13417 |
|
| 13418 |
|
| 13419 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 13420 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 13421 |
/* November 2006 */ |
| 13422 |
|
| 13423 |
/* .. Scalar Arguments .. */ |
| 13424 |
/* .. */ |
| 13425 |
/* .. Array Arguments .. */ |
| 13426 |
/* .. */ |
| 13427 |
|
| 13428 |
/* Purpose */ |
| 13429 |
/* ======= */ |
| 13430 |
|
| 13431 |
/* DSTEV computes all eigenvalues and, optionally, eigenvectors of a */ |
| 13432 |
/* real symmetric tridiagonal matrix A. */ |
| 13433 |
|
| 13434 |
/* Arguments */ |
| 13435 |
/* ========= */ |
| 13436 |
|
| 13437 |
/* JOBZ (input) CHARACTER*1 */ |
| 13438 |
/* = 'N': Compute eigenvalues only; */ |
| 13439 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 13440 |
|
| 13441 |
/* N (input) INTEGER */ |
| 13442 |
/* The order of the matrix. N >= 0. */ |
| 13443 |
|
| 13444 |
/* D (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 13445 |
/* On entry, the n diagonal elements of the tridiagonal matrix */ |
| 13446 |
/* A. */ |
| 13447 |
/* On exit, if INFO = 0, the eigenvalues in ascending order. */ |
| 13448 |
|
| 13449 |
/* E (input/output) DOUBLE PRECISION array, dimension (N-1) */ |
| 13450 |
/* On entry, the (n-1) subdiagonal elements of the tridiagonal */ |
| 13451 |
/* matrix A, stored in elements 1 to N-1 of E. */ |
| 13452 |
/* On exit, the contents of E are destroyed. */ |
| 13453 |
|
| 13454 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 13455 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */ |
| 13456 |
/* eigenvectors of the matrix A, with the i-th column of Z */ |
| 13457 |
/* holding the eigenvector associated with D(i). */ |
| 13458 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 13459 |
|
| 13460 |
/* LDZ (input) INTEGER */ |
| 13461 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 13462 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 13463 |
|
| 13464 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (max(1,2*N-2)) */ |
| 13465 |
/* If JOBZ = 'N', WORK is not referenced. */ |
| 13466 |
|
| 13467 |
/* INFO (output) INTEGER */ |
| 13468 |
/* = 0: successful exit */ |
| 13469 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 13470 |
/* > 0: if INFO = i, the algorithm failed to converge; i */ |
| 13471 |
/* off-diagonal elements of E did not converge to zero. */ |
| 13472 |
|
| 13473 |
/* ===================================================================== */ |
| 13474 |
|
| 13475 |
/* .. Parameters .. */ |
| 13476 |
/* .. */ |
| 13477 |
/* .. Local Scalars .. */ |
| 13478 |
/* .. */ |
| 13479 |
/* .. External Functions .. */ |
| 13480 |
/* .. */ |
| 13481 |
/* .. External Subroutines .. */ |
| 13482 |
/* .. */ |
| 13483 |
/* .. Intrinsic Functions .. */ |
| 13484 |
/* .. */ |
| 13485 |
/* .. Executable Statements .. */ |
| 13486 |
|
| 13487 |
/* Test the input parameters. */ |
| 13488 |
|
| 13489 |
/* Parameter adjustments */ |
| 13490 |
--d__; |
| 13491 |
--e; |
| 13492 |
z_dim1 = *ldz; |
| 13493 |
z_offset = 1 + z_dim1; |
| 13494 |
z__ -= z_offset; |
| 13495 |
--work; |
| 13496 |
|
| 13497 |
/* Function Body */ |
| 13498 |
wantz = lsame_(jobz, "V"); |
| 13499 |
|
| 13500 |
*info = 0; |
| 13501 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 13502 |
*info = -1; |
| 13503 |
} else if (*n < 0) { |
| 13504 |
*info = -2; |
| 13505 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 13506 |
*info = -6; |
| 13507 |
} |
| 13508 |
|
| 13509 |
if (*info != 0) { |
| 13510 |
i__1 = -(*info); |
| 13511 |
xerbla_("DSTEV ", &i__1); |
| 13512 |
return 0; |
| 13513 |
} |
| 13514 |
|
| 13515 |
/* Quick return if possible */ |
| 13516 |
|
| 13517 |
if (*n == 0) { |
| 13518 |
return 0; |
| 13519 |
} |
| 13520 |
|
| 13521 |
if (*n == 1) { |
| 13522 |
if (wantz) { |
| 13523 |
z__[z_dim1 + 1] = 1.; |
| 13524 |
} |
| 13525 |
return 0; |
| 13526 |
} |
| 13527 |
|
| 13528 |
/* Get machine constants. */ |
| 13529 |
|
| 13530 |
safmin = dlamch_("Safe minimum"); |
| 13531 |
eps = dlamch_("Precision"); |
| 13532 |
smlnum = safmin / eps; |
| 13533 |
bignum = 1. / smlnum; |
| 13534 |
rmin = sqrt(smlnum); |
| 13535 |
rmax = sqrt(bignum); |
| 13536 |
|
| 13537 |
/* Scale matrix to allowable range, if necessary. */ |
| 13538 |
|
| 13539 |
iscale = 0; |
| 13540 |
tnrm = dlanst_("M", n, &d__[1], &e[1]); |
| 13541 |
if (tnrm > 0. && tnrm < rmin) { |
| 13542 |
iscale = 1; |
| 13543 |
sigma = rmin / tnrm; |
| 13544 |
} else if (tnrm > rmax) { |
| 13545 |
iscale = 1; |
| 13546 |
sigma = rmax / tnrm; |
| 13547 |
} |
| 13548 |
if (iscale == 1) { |
| 13549 |
dscal_(n, &sigma, &d__[1], &c__1); |
| 13550 |
i__1 = *n - 1; |
| 13551 |
dscal_(&i__1, &sigma, &e[1], &c__1); |
| 13552 |
} |
| 13553 |
|
| 13554 |
/* For eigenvalues only, call DSTERF. For eigenvalues and */ |
| 13555 |
/* eigenvectors, call DSTEQR. */ |
| 13556 |
|
| 13557 |
if (! wantz) { |
| 13558 |
dsterf_(n, &d__[1], &e[1], info); |
| 13559 |
} else { |
| 13560 |
dsteqr_("I", n, &d__[1], &e[1], &z__[z_offset], ldz, &work[1], info); |
| 13561 |
} |
| 13562 |
|
| 13563 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 13564 |
|
| 13565 |
if (iscale == 1) { |
| 13566 |
if (*info == 0) { |
| 13567 |
imax = *n; |
| 13568 |
} else { |
| 13569 |
imax = *info - 1; |
| 13570 |
} |
| 13571 |
d__1 = 1. / sigma; |
| 13572 |
dscal_(&imax, &d__1, &d__[1], &c__1); |
| 13573 |
} |
| 13574 |
|
| 13575 |
return 0; |
| 13576 |
|
| 13577 |
/* End of DSTEV */ |
| 13578 |
|
| 13579 |
} /* dstev_ */ |
| 13580 |
|
| 13581 |
/* Subroutine */ int dstevd_(const char *jobz, integer *n, double *d__, |
| 13582 |
double *e, double *z__, integer *ldz, double *work, |
| 13583 |
integer *lwork, integer *iwork, integer *liwork, integer *info) |
| 13584 |
{ |
| 13585 |
/* Table of constant values */ |
| 13586 |
static integer c__1 = 1; |
| 13587 |
|
| 13588 |
/* System generated locals */ |
| 13589 |
integer z_dim1, z_offset, i__1; |
| 13590 |
double d__1; |
| 13591 |
|
| 13592 |
/* Local variables */ |
| 13593 |
double eps, rmin, rmax, tnrm; |
| 13594 |
double sigma; |
| 13595 |
integer lwmin; |
| 13596 |
bool wantz; |
| 13597 |
integer iscale; |
| 13598 |
double safmin; |
| 13599 |
double bignum; |
| 13600 |
integer liwmin; |
| 13601 |
double smlnum; |
| 13602 |
bool lquery; |
| 13603 |
|
| 13604 |
|
| 13605 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 13606 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 13607 |
/* November 2006 */ |
| 13608 |
|
| 13609 |
/* .. Scalar Arguments .. */ |
| 13610 |
/* .. */ |
| 13611 |
/* .. Array Arguments .. */ |
| 13612 |
/* .. */ |
| 13613 |
|
| 13614 |
/* Purpose */ |
| 13615 |
/* ======= */ |
| 13616 |
|
| 13617 |
/* DSTEVD computes all eigenvalues and, optionally, eigenvectors of a */ |
| 13618 |
/* real symmetric tridiagonal matrix. If eigenvectors are desired, it */ |
| 13619 |
/* uses a divide and conquer algorithm. */ |
| 13620 |
|
| 13621 |
/* The divide and conquer algorithm makes very mild assumptions about */ |
| 13622 |
/* floating point arithmetic. It will work on machines with a guard */ |
| 13623 |
/* digit in add/subtract, or on those binary machines without guard */ |
| 13624 |
/* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ |
| 13625 |
/* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ |
| 13626 |
/* without guard digits, but we know of none. */ |
| 13627 |
|
| 13628 |
/* Arguments */ |
| 13629 |
/* ========= */ |
| 13630 |
|
| 13631 |
/* JOBZ (input) CHARACTER*1 */ |
| 13632 |
/* = 'N': Compute eigenvalues only; */ |
| 13633 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 13634 |
|
| 13635 |
/* N (input) INTEGER */ |
| 13636 |
/* The order of the matrix. N >= 0. */ |
| 13637 |
|
| 13638 |
/* D (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 13639 |
/* On entry, the n diagonal elements of the tridiagonal matrix */ |
| 13640 |
/* A. */ |
| 13641 |
/* On exit, if INFO = 0, the eigenvalues in ascending order. */ |
| 13642 |
|
| 13643 |
/* E (input/output) DOUBLE PRECISION array, dimension (N-1) */ |
| 13644 |
/* On entry, the (n-1) subdiagonal elements of the tridiagonal */ |
| 13645 |
/* matrix A, stored in elements 1 to N-1 of E. */ |
| 13646 |
/* On exit, the contents of E are destroyed. */ |
| 13647 |
|
| 13648 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */ |
| 13649 |
/* If JOBZ = 'V', then if INFO = 0, Z contains the orthonormal */ |
| 13650 |
/* eigenvectors of the matrix A, with the i-th column of Z */ |
| 13651 |
/* holding the eigenvector associated with D(i). */ |
| 13652 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 13653 |
|
| 13654 |
/* LDZ (input) INTEGER */ |
| 13655 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 13656 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 13657 |
|
| 13658 |
/* WORK (workspace/output) DOUBLE PRECISION array, */ |
| 13659 |
/* dimension (LWORK) */ |
| 13660 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 13661 |
|
| 13662 |
/* LWORK (input) INTEGER */ |
| 13663 |
/* The dimension of the array WORK. */ |
| 13664 |
/* If JOBZ = 'N' or N <= 1 then LWORK must be at least 1. */ |
| 13665 |
/* If JOBZ = 'V' and N > 1 then LWORK must be at least */ |
| 13666 |
/* ( 1 + 4*N + N**2 ). */ |
| 13667 |
|
| 13668 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 13669 |
/* only calculates the optimal sizes of the WORK and IWORK */ |
| 13670 |
/* arrays, returns these values as the first entries of the WORK */ |
| 13671 |
/* and IWORK arrays, and no error message related to LWORK or */ |
| 13672 |
/* LIWORK is issued by XERBLA. */ |
| 13673 |
|
| 13674 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 13675 |
/* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ |
| 13676 |
|
| 13677 |
/* LIWORK (input) INTEGER */ |
| 13678 |
/* The dimension of the array IWORK. */ |
| 13679 |
/* If JOBZ = 'N' or N <= 1 then LIWORK must be at least 1. */ |
| 13680 |
/* If JOBZ = 'V' and N > 1 then LIWORK must be at least 3+5*N. */ |
| 13681 |
|
| 13682 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 13683 |
/* routine only calculates the optimal sizes of the WORK and */ |
| 13684 |
/* IWORK arrays, returns these values as the first entries of */ |
| 13685 |
/* the WORK and IWORK arrays, and no error message related to */ |
| 13686 |
/* LWORK or LIWORK is issued by XERBLA. */ |
| 13687 |
|
| 13688 |
/* INFO (output) INTEGER */ |
| 13689 |
/* = 0: successful exit */ |
| 13690 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 13691 |
/* > 0: if INFO = i, the algorithm failed to converge; i */ |
| 13692 |
/* off-diagonal elements of E did not converge to zero. */ |
| 13693 |
|
| 13694 |
/* ===================================================================== */ |
| 13695 |
|
| 13696 |
/* .. Parameters .. */ |
| 13697 |
/* .. */ |
| 13698 |
/* .. Local Scalars .. */ |
| 13699 |
/* .. */ |
| 13700 |
/* .. External Functions .. */ |
| 13701 |
/* .. */ |
| 13702 |
/* .. External Subroutines .. */ |
| 13703 |
/* .. */ |
| 13704 |
/* .. Intrinsic Functions .. */ |
| 13705 |
/* .. */ |
| 13706 |
/* .. Executable Statements .. */ |
| 13707 |
|
| 13708 |
/* Test the input parameters. */ |
| 13709 |
|
| 13710 |
/* Parameter adjustments */ |
| 13711 |
--d__; |
| 13712 |
--e; |
| 13713 |
z_dim1 = *ldz; |
| 13714 |
z_offset = 1 + z_dim1; |
| 13715 |
z__ -= z_offset; |
| 13716 |
--work; |
| 13717 |
--iwork; |
| 13718 |
|
| 13719 |
/* Function Body */ |
| 13720 |
wantz = lsame_(jobz, "V"); |
| 13721 |
lquery = *lwork == -1 || *liwork == -1; |
| 13722 |
|
| 13723 |
*info = 0; |
| 13724 |
liwmin = 1; |
| 13725 |
lwmin = 1; |
| 13726 |
if (*n > 1 && wantz) { |
| 13727 |
/* Computing 2nd power */ |
| 13728 |
i__1 = *n; |
| 13729 |
lwmin = (*n << 2) + 1 + i__1 * i__1; |
| 13730 |
liwmin = *n * 5 + 3; |
| 13731 |
} |
| 13732 |
|
| 13733 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 13734 |
*info = -1; |
| 13735 |
} else if (*n < 0) { |
| 13736 |
*info = -2; |
| 13737 |
} else if (*ldz < 1 || wantz && *ldz < *n) { |
| 13738 |
*info = -6; |
| 13739 |
} |
| 13740 |
|
| 13741 |
if (*info == 0) { |
| 13742 |
work[1] = (double) lwmin; |
| 13743 |
iwork[1] = liwmin; |
| 13744 |
|
| 13745 |
if (*lwork < lwmin && ! lquery) { |
| 13746 |
*info = -8; |
| 13747 |
} else if (*liwork < liwmin && ! lquery) { |
| 13748 |
*info = -10; |
| 13749 |
} |
| 13750 |
} |
| 13751 |
|
| 13752 |
if (*info != 0) { |
| 13753 |
i__1 = -(*info); |
| 13754 |
xerbla_("DSTEVD", &i__1); |
| 13755 |
return 0; |
| 13756 |
} else if (lquery) { |
| 13757 |
return 0; |
| 13758 |
} |
| 13759 |
|
| 13760 |
/* Quick return if possible */ |
| 13761 |
|
| 13762 |
if (*n == 0) { |
| 13763 |
return 0; |
| 13764 |
} |
| 13765 |
|
| 13766 |
if (*n == 1) { |
| 13767 |
if (wantz) { |
| 13768 |
z__[z_dim1 + 1] = 1.; |
| 13769 |
} |
| 13770 |
return 0; |
| 13771 |
} |
| 13772 |
|
| 13773 |
/* Get machine constants. */ |
| 13774 |
|
| 13775 |
safmin = dlamch_("Safe minimum"); |
| 13776 |
eps = dlamch_("Precision"); |
| 13777 |
smlnum = safmin / eps; |
| 13778 |
bignum = 1. / smlnum; |
| 13779 |
rmin = sqrt(smlnum); |
| 13780 |
rmax = sqrt(bignum); |
| 13781 |
|
| 13782 |
/* Scale matrix to allowable range, if necessary. */ |
| 13783 |
|
| 13784 |
iscale = 0; |
| 13785 |
tnrm = dlanst_("M", n, &d__[1], &e[1]); |
| 13786 |
if (tnrm > 0. && tnrm < rmin) { |
| 13787 |
iscale = 1; |
| 13788 |
sigma = rmin / tnrm; |
| 13789 |
} else if (tnrm > rmax) { |
| 13790 |
iscale = 1; |
| 13791 |
sigma = rmax / tnrm; |
| 13792 |
} |
| 13793 |
if (iscale == 1) { |
| 13794 |
dscal_(n, &sigma, &d__[1], &c__1); |
| 13795 |
i__1 = *n - 1; |
| 13796 |
dscal_(&i__1, &sigma, &e[1], &c__1); |
| 13797 |
} |
| 13798 |
|
| 13799 |
/* For eigenvalues only, call DSTERF. For eigenvalues and */ |
| 13800 |
/* eigenvectors, call DSTEDC. */ |
| 13801 |
|
| 13802 |
if (! wantz) { |
| 13803 |
dsterf_(n, &d__[1], &e[1], info); |
| 13804 |
} else { |
| 13805 |
dstedc_("I", n, &d__[1], &e[1], &z__[z_offset], ldz, &work[1], lwork, |
| 13806 |
&iwork[1], liwork, info); |
| 13807 |
} |
| 13808 |
|
| 13809 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 13810 |
|
| 13811 |
if (iscale == 1) { |
| 13812 |
d__1 = 1. / sigma; |
| 13813 |
dscal_(n, &d__1, &d__[1], &c__1); |
| 13814 |
} |
| 13815 |
|
| 13816 |
work[1] = (double) lwmin; |
| 13817 |
iwork[1] = liwmin; |
| 13818 |
|
| 13819 |
return 0; |
| 13820 |
|
| 13821 |
/* End of DSTEVD */ |
| 13822 |
|
| 13823 |
} /* dstevd_ */ |
| 13824 |
|
| 13825 |
/* Subroutine */ int dstevr_(const char *jobz, const char *range, integer *n, double * |
| 13826 |
d__, double *e, double *vl, double *vu, integer *il, |
| 13827 |
integer *iu, double *abstol, integer *m, double *w, |
| 13828 |
double *z__, integer *ldz, integer *isuppz, double *work, |
| 13829 |
integer *lwork, integer *iwork, integer *liwork, integer *info) |
| 13830 |
{ |
| 13831 |
/* Table of constant values */ |
| 13832 |
static integer c__10 = 10; |
| 13833 |
static integer c__1 = 1; |
| 13834 |
static integer c__2 = 2; |
| 13835 |
static integer c__3 = 3; |
| 13836 |
static integer c__4 = 4; |
| 13837 |
|
| 13838 |
/* System generated locals */ |
| 13839 |
integer z_dim1, z_offset, i__1, i__2; |
| 13840 |
double d__1, d__2; |
| 13841 |
|
| 13842 |
/* Local variables */ |
| 13843 |
integer i__, j, jj; |
| 13844 |
double eps, vll, vuu, tmp1; |
| 13845 |
integer imax; |
| 13846 |
double rmin, rmax; |
| 13847 |
bool test; |
| 13848 |
double tnrm; |
| 13849 |
integer itmp1; |
| 13850 |
double sigma; |
| 13851 |
char order[1]; |
| 13852 |
integer lwmin; |
| 13853 |
bool wantz; |
| 13854 |
bool alleig, indeig; |
| 13855 |
integer iscale, ieeeok, indibl, indifl; |
| 13856 |
bool valeig; |
| 13857 |
double safmin; |
| 13858 |
double bignum; |
| 13859 |
integer indisp; |
| 13860 |
integer indiwo; |
| 13861 |
integer liwmin; |
| 13862 |
bool tryrac; |
| 13863 |
integer nsplit; |
| 13864 |
double smlnum; |
| 13865 |
bool lquery; |
| 13866 |
|
| 13867 |
|
| 13868 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 13869 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 13870 |
/* November 2006 */ |
| 13871 |
|
| 13872 |
/* .. Scalar Arguments .. */ |
| 13873 |
/* .. */ |
| 13874 |
/* .. Array Arguments .. */ |
| 13875 |
/* .. */ |
| 13876 |
|
| 13877 |
/* Purpose */ |
| 13878 |
/* ======= */ |
| 13879 |
|
| 13880 |
/* DSTEVR computes selected eigenvalues and, optionally, eigenvectors */ |
| 13881 |
/* of a real symmetric tridiagonal matrix T. Eigenvalues and */ |
| 13882 |
/* eigenvectors can be selected by specifying either a range of values */ |
| 13883 |
/* or a range of indices for the desired eigenvalues. */ |
| 13884 |
|
| 13885 |
/* Whenever possible, DSTEVR calls DSTEMR to compute the */ |
| 13886 |
/* eigenspectrum using Relatively Robust Representations. DSTEMR */ |
| 13887 |
/* computes eigenvalues by the dqds algorithm, while orthogonal */ |
| 13888 |
/* eigenvectors are computed from various "good" L D L^T representations */ |
| 13889 |
/* (also known as Relatively Robust Representations). Gram-Schmidt */ |
| 13890 |
/* orthogonalization is avoided as far as possible. More specifically, */ |
| 13891 |
/* the various steps of the algorithm are as follows. For the i-th */ |
| 13892 |
/* unreduced block of T, */ |
| 13893 |
/* (a) Compute T - sigma_i = L_i D_i L_i^T, such that L_i D_i L_i^T */ |
| 13894 |
/* is a relatively robust representation, */ |
| 13895 |
/* (b) Compute the eigenvalues, lambda_j, of L_i D_i L_i^T to high */ |
| 13896 |
/* relative accuracy by the dqds algorithm, */ |
| 13897 |
/* (c) If there is a cluster of close eigenvalues, "choose" sigma_i */ |
| 13898 |
/* close to the cluster, and go to step (a), */ |
| 13899 |
/* (d) Given the approximate eigenvalue lambda_j of L_i D_i L_i^T, */ |
| 13900 |
/* compute the corresponding eigenvector by forming a */ |
| 13901 |
/* rank-revealing twisted factorization. */ |
| 13902 |
/* The desired accuracy of the output can be specified by the input */ |
| 13903 |
/* parameter ABSTOL. */ |
| 13904 |
|
| 13905 |
/* For more details, see "A new O(n^2) algorithm for the symmetric */ |
| 13906 |
/* tridiagonal eigenvalue/eigenvector problem", by Inderjit Dhillon, */ |
| 13907 |
/* Computer Science Division Technical Report No. UCB//CSD-97-971, */ |
| 13908 |
/* UC Berkeley, May 1997. */ |
| 13909 |
|
| 13910 |
|
| 13911 |
/* Note 1 : DSTEVR calls DSTEMR when the full spectrum is requested */ |
| 13912 |
/* on machines which conform to the ieee-754 floating point standard. */ |
| 13913 |
/* DSTEVR calls DSTEBZ and DSTEIN on non-ieee machines and */ |
| 13914 |
/* when partial spectrum requests are made. */ |
| 13915 |
|
| 13916 |
/* Normal execution of DSTEMR may create NaNs and infinities and */ |
| 13917 |
/* hence may abort due to a floating point exception in environments */ |
| 13918 |
/* which do not handle NaNs and infinities in the ieee standard default */ |
| 13919 |
/* manner. */ |
| 13920 |
|
| 13921 |
/* Arguments */ |
| 13922 |
/* ========= */ |
| 13923 |
|
| 13924 |
/* JOBZ (input) CHARACTER*1 */ |
| 13925 |
/* = 'N': Compute eigenvalues only; */ |
| 13926 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 13927 |
|
| 13928 |
/* RANGE (input) CHARACTER*1 */ |
| 13929 |
/* = 'A': all eigenvalues will be found. */ |
| 13930 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 13931 |
/* will be found. */ |
| 13932 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 13933 |
/* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and */ |
| 13934 |
/* ********* DSTEIN are called */ |
| 13935 |
|
| 13936 |
/* N (input) INTEGER */ |
| 13937 |
/* The order of the matrix. N >= 0. */ |
| 13938 |
|
| 13939 |
/* D (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 13940 |
/* On entry, the n diagonal elements of the tridiagonal matrix */ |
| 13941 |
/* A. */ |
| 13942 |
/* On exit, D may be multiplied by a constant factor chosen */ |
| 13943 |
/* to avoid over/underflow in computing the eigenvalues. */ |
| 13944 |
|
| 13945 |
/* E (input/output) DOUBLE PRECISION array, dimension (max(1,N-1)) */ |
| 13946 |
/* On entry, the (n-1) subdiagonal elements of the tridiagonal */ |
| 13947 |
/* matrix A in elements 1 to N-1 of E. */ |
| 13948 |
/* On exit, E may be multiplied by a constant factor chosen */ |
| 13949 |
/* to avoid over/underflow in computing the eigenvalues. */ |
| 13950 |
|
| 13951 |
/* VL (input) DOUBLE PRECISION */ |
| 13952 |
/* VU (input) DOUBLE PRECISION */ |
| 13953 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 13954 |
/* be searched for eigenvalues. VL < VU. */ |
| 13955 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 13956 |
|
| 13957 |
/* IL (input) INTEGER */ |
| 13958 |
/* IU (input) INTEGER */ |
| 13959 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 13960 |
/* smallest and largest eigenvalues to be returned. */ |
| 13961 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 13962 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 13963 |
|
| 13964 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 13965 |
/* The absolute error tolerance for the eigenvalues. */ |
| 13966 |
/* An approximate eigenvalue is accepted as converged */ |
| 13967 |
/* when it is determined to lie in an interval [a,b] */ |
| 13968 |
/* of width less than or equal to */ |
| 13969 |
|
| 13970 |
/* ABSTOL + EPS * max( |a|,|b| ) , */ |
| 13971 |
|
| 13972 |
/* where EPS is the machine precision. If ABSTOL is less than */ |
| 13973 |
/* or equal to zero, then EPS*|T| will be used in its place, */ |
| 13974 |
/* where |T| is the 1-norm of the tridiagonal matrix obtained */ |
| 13975 |
/* by reducing A to tridiagonal form. */ |
| 13976 |
|
| 13977 |
/* See "Computing Small Singular Values of Bidiagonal Matrices */ |
| 13978 |
/* with Guaranteed High Relative Accuracy," by Demmel and */ |
| 13979 |
/* Kahan, LAPACK Working Note #3. */ |
| 13980 |
|
| 13981 |
/* If high relative accuracy is important, set ABSTOL to */ |
| 13982 |
/* DLAMCH( 'Safe minimum' ). Doing so will guarantee that */ |
| 13983 |
/* eigenvalues are computed to high relative accuracy when */ |
| 13984 |
/* possible in future releases. The current code does not */ |
| 13985 |
/* make any guarantees about high relative accuracy, but */ |
| 13986 |
/* future releases will. See J. Barlow and J. Demmel, */ |
| 13987 |
/* "Computing Accurate Eigensystems of Scaled Diagonally */ |
| 13988 |
/* Dominant Matrices", LAPACK Working Note #7, for a discussion */ |
| 13989 |
/* of which matrices define their eigenvalues to high relative */ |
| 13990 |
/* accuracy. */ |
| 13991 |
|
| 13992 |
/* M (output) INTEGER */ |
| 13993 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 13994 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 13995 |
|
| 13996 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 13997 |
/* The first M elements contain the selected eigenvalues in */ |
| 13998 |
/* ascending order. */ |
| 13999 |
|
| 14000 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */ |
| 14001 |
/* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ |
| 14002 |
/* contain the orthonormal eigenvectors of the matrix A */ |
| 14003 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 14004 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 14005 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 14006 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 14007 |
/* is not known in advance and an upper bound must be used. */ |
| 14008 |
|
| 14009 |
/* LDZ (input) INTEGER */ |
| 14010 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 14011 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 14012 |
|
| 14013 |
/* ISUPPZ (output) INTEGER array, dimension ( 2*max(1,M) ) */ |
| 14014 |
/* The support of the eigenvectors in Z, i.e., the indices */ |
| 14015 |
/* indicating the nonzero elements in Z. The i-th eigenvector */ |
| 14016 |
/* is nonzero only in elements ISUPPZ( 2*i-1 ) through */ |
| 14017 |
/* ISUPPZ( 2*i ). */ |
| 14018 |
/* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */ |
| 14019 |
|
| 14020 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 14021 |
/* On exit, if INFO = 0, WORK(1) returns the optimal (and */ |
| 14022 |
/* minimal) LWORK. */ |
| 14023 |
|
| 14024 |
/* LWORK (input) INTEGER */ |
| 14025 |
/* The dimension of the array WORK. LWORK >= max(1,20*N). */ |
| 14026 |
|
| 14027 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 14028 |
/* only calculates the optimal sizes of the WORK and IWORK */ |
| 14029 |
/* arrays, returns these values as the first entries of the WORK */ |
| 14030 |
/* and IWORK arrays, and no error message related to LWORK or */ |
| 14031 |
/* LIWORK is issued by XERBLA. */ |
| 14032 |
|
| 14033 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 14034 |
/* On exit, if INFO = 0, IWORK(1) returns the optimal (and */ |
| 14035 |
/* minimal) LIWORK. */ |
| 14036 |
|
| 14037 |
/* LIWORK (input) INTEGER */ |
| 14038 |
/* The dimension of the array IWORK. LIWORK >= max(1,10*N). */ |
| 14039 |
|
| 14040 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 14041 |
/* routine only calculates the optimal sizes of the WORK and */ |
| 14042 |
/* IWORK arrays, returns these values as the first entries of */ |
| 14043 |
/* the WORK and IWORK arrays, and no error message related to */ |
| 14044 |
/* LWORK or LIWORK is issued by XERBLA. */ |
| 14045 |
|
| 14046 |
/* INFO (output) INTEGER */ |
| 14047 |
/* = 0: successful exit */ |
| 14048 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 14049 |
/* > 0: Internal error */ |
| 14050 |
|
| 14051 |
/* Further Details */ |
| 14052 |
/* =============== */ |
| 14053 |
|
| 14054 |
/* Based on contributions by */ |
| 14055 |
/* Inderjit Dhillon, IBM Almaden, USA */ |
| 14056 |
/* Osni Marques, LBNL/NERSC, USA */ |
| 14057 |
/* Ken Stanley, Computer Science Division, University of */ |
| 14058 |
/* California at Berkeley, USA */ |
| 14059 |
|
| 14060 |
/* ===================================================================== */ |
| 14061 |
|
| 14062 |
/* .. Parameters .. */ |
| 14063 |
/* .. */ |
| 14064 |
/* .. Local Scalars .. */ |
| 14065 |
/* .. */ |
| 14066 |
/* .. External Functions .. */ |
| 14067 |
/* .. */ |
| 14068 |
/* .. External Subroutines .. */ |
| 14069 |
/* .. */ |
| 14070 |
/* .. Intrinsic Functions .. */ |
| 14071 |
/* .. */ |
| 14072 |
/* .. Executable Statements .. */ |
| 14073 |
|
| 14074 |
|
| 14075 |
/* Test the input parameters. */ |
| 14076 |
|
| 14077 |
/* Parameter adjustments */ |
| 14078 |
--d__; |
| 14079 |
--e; |
| 14080 |
--w; |
| 14081 |
z_dim1 = *ldz; |
| 14082 |
z_offset = 1 + z_dim1; |
| 14083 |
z__ -= z_offset; |
| 14084 |
--isuppz; |
| 14085 |
--work; |
| 14086 |
--iwork; |
| 14087 |
|
| 14088 |
/* Function Body */ |
| 14089 |
ieeeok = ilaenv_(&c__10, "DSTEVR", "N", &c__1, &c__2, &c__3, &c__4); |
| 14090 |
|
| 14091 |
wantz = lsame_(jobz, "V"); |
| 14092 |
alleig = lsame_(range, "A"); |
| 14093 |
valeig = lsame_(range, "V"); |
| 14094 |
indeig = lsame_(range, "I"); |
| 14095 |
|
| 14096 |
lquery = *lwork == -1 || *liwork == -1; |
| 14097 |
/* Computing MAX */ |
| 14098 |
i__1 = 1, i__2 = *n * 20; |
| 14099 |
lwmin = std::max(i__1,i__2); |
| 14100 |
/* Computing MAX */ |
| 14101 |
i__1 = 1, i__2 = *n * 10; |
| 14102 |
liwmin = std::max(i__1,i__2); |
| 14103 |
|
| 14104 |
|
| 14105 |
*info = 0; |
| 14106 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 14107 |
*info = -1; |
| 14108 |
} else if (! (alleig || valeig || indeig)) { |
| 14109 |
*info = -2; |
| 14110 |
} else if (*n < 0) { |
| 14111 |
*info = -3; |
| 14112 |
} else { |
| 14113 |
if (valeig) { |
| 14114 |
if (*n > 0 && *vu <= *vl) { |
| 14115 |
*info = -7; |
| 14116 |
} |
| 14117 |
} else if (indeig) { |
| 14118 |
if (*il < 1 || *il > std::max(1_integer,*n)) { |
| 14119 |
*info = -8; |
| 14120 |
} else if (*iu < std::min(*n,*il) || *iu > *n) { |
| 14121 |
*info = -9; |
| 14122 |
} |
| 14123 |
} |
| 14124 |
} |
| 14125 |
if (*info == 0) { |
| 14126 |
if (*ldz < 1 || wantz && *ldz < *n) { |
| 14127 |
*info = -14; |
| 14128 |
} |
| 14129 |
} |
| 14130 |
|
| 14131 |
if (*info == 0) { |
| 14132 |
work[1] = (double) lwmin; |
| 14133 |
iwork[1] = liwmin; |
| 14134 |
|
| 14135 |
if (*lwork < lwmin && ! lquery) { |
| 14136 |
*info = -17; |
| 14137 |
} else if (*liwork < liwmin && ! lquery) { |
| 14138 |
*info = -19; |
| 14139 |
} |
| 14140 |
} |
| 14141 |
|
| 14142 |
if (*info != 0) { |
| 14143 |
i__1 = -(*info); |
| 14144 |
xerbla_("DSTEVR", &i__1); |
| 14145 |
return 0; |
| 14146 |
} else if (lquery) { |
| 14147 |
return 0; |
| 14148 |
} |
| 14149 |
|
| 14150 |
/* Quick return if possible */ |
| 14151 |
|
| 14152 |
*m = 0; |
| 14153 |
if (*n == 0) { |
| 14154 |
return 0; |
| 14155 |
} |
| 14156 |
|
| 14157 |
if (*n == 1) { |
| 14158 |
if (alleig || indeig) { |
| 14159 |
*m = 1; |
| 14160 |
w[1] = d__[1]; |
| 14161 |
} else { |
| 14162 |
if (*vl < d__[1] && *vu >= d__[1]) { |
| 14163 |
*m = 1; |
| 14164 |
w[1] = d__[1]; |
| 14165 |
} |
| 14166 |
} |
| 14167 |
if (wantz) { |
| 14168 |
z__[z_dim1 + 1] = 1.; |
| 14169 |
} |
| 14170 |
return 0; |
| 14171 |
} |
| 14172 |
|
| 14173 |
/* Get machine constants. */ |
| 14174 |
|
| 14175 |
safmin = dlamch_("Safe minimum"); |
| 14176 |
eps = dlamch_("Precision"); |
| 14177 |
smlnum = safmin / eps; |
| 14178 |
bignum = 1. / smlnum; |
| 14179 |
rmin = sqrt(smlnum); |
| 14180 |
/* Computing MIN */ |
| 14181 |
d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin)); |
| 14182 |
rmax = std::min(d__1,d__2); |
| 14183 |
|
| 14184 |
|
| 14185 |
/* Scale matrix to allowable range, if necessary. */ |
| 14186 |
|
| 14187 |
iscale = 0; |
| 14188 |
vll = *vl; |
| 14189 |
vuu = *vu; |
| 14190 |
|
| 14191 |
tnrm = dlanst_("M", n, &d__[1], &e[1]); |
| 14192 |
if (tnrm > 0. && tnrm < rmin) { |
| 14193 |
iscale = 1; |
| 14194 |
sigma = rmin / tnrm; |
| 14195 |
} else if (tnrm > rmax) { |
| 14196 |
iscale = 1; |
| 14197 |
sigma = rmax / tnrm; |
| 14198 |
} |
| 14199 |
if (iscale == 1) { |
| 14200 |
dscal_(n, &sigma, &d__[1], &c__1); |
| 14201 |
i__1 = *n - 1; |
| 14202 |
dscal_(&i__1, &sigma, &e[1], &c__1); |
| 14203 |
if (valeig) { |
| 14204 |
vll = *vl * sigma; |
| 14205 |
vuu = *vu * sigma; |
| 14206 |
} |
| 14207 |
} |
| 14208 |
/* Initialize indices into workspaces. Note: These indices are used only */ |
| 14209 |
/* if DSTERF or DSTEMR fail. */ |
| 14210 |
/* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and */ |
| 14211 |
/* stores the block indices of each of the M<=N eigenvalues. */ |
| 14212 |
indibl = 1; |
| 14213 |
/* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and */ |
| 14214 |
/* stores the starting and finishing indices of each block. */ |
| 14215 |
indisp = indibl + *n; |
| 14216 |
/* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */ |
| 14217 |
/* that corresponding to eigenvectors that fail to converge in */ |
| 14218 |
/* DSTEIN. This information is discarded; if any fail, the driver */ |
| 14219 |
/* returns INFO > 0. */ |
| 14220 |
indifl = indisp + *n; |
| 14221 |
/* INDIWO is the offset of the remaining integer workspace. */ |
| 14222 |
indiwo = indisp + *n; |
| 14223 |
|
| 14224 |
/* If all eigenvalues are desired, then */ |
| 14225 |
/* call DSTERF or DSTEMR. If this fails for some eigenvalue, then */ |
| 14226 |
/* try DSTEBZ. */ |
| 14227 |
|
| 14228 |
|
| 14229 |
test = false; |
| 14230 |
if (indeig) { |
| 14231 |
if (*il == 1 && *iu == *n) { |
| 14232 |
test = true; |
| 14233 |
} |
| 14234 |
} |
| 14235 |
if ((alleig || test) && ieeeok == 1) { |
| 14236 |
i__1 = *n - 1; |
| 14237 |
dcopy_(&i__1, &e[1], &c__1, &work[1], &c__1); |
| 14238 |
if (! wantz) { |
| 14239 |
dcopy_(n, &d__[1], &c__1, &w[1], &c__1); |
| 14240 |
dsterf_(n, &w[1], &work[1], info); |
| 14241 |
} else { |
| 14242 |
dcopy_(n, &d__[1], &c__1, &work[*n + 1], &c__1); |
| 14243 |
if (*abstol <= *n * 2. * eps) { |
| 14244 |
tryrac = true; |
| 14245 |
} else { |
| 14246 |
tryrac = false; |
| 14247 |
} |
| 14248 |
i__1 = *lwork - (*n << 1); |
| 14249 |
dstemr_(jobz, "A", n, &work[*n + 1], &work[1], vl, vu, il, iu, m, |
| 14250 |
&w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, &work[ |
| 14251 |
(*n << 1) + 1], &i__1, &iwork[1], liwork, info); |
| 14252 |
|
| 14253 |
} |
| 14254 |
if (*info == 0) { |
| 14255 |
*m = *n; |
| 14256 |
goto L10; |
| 14257 |
} |
| 14258 |
*info = 0; |
| 14259 |
} |
| 14260 |
|
| 14261 |
/* Otherwise, call DSTEBZ and, if eigenvectors are desired, DSTEIN. */ |
| 14262 |
|
| 14263 |
if (wantz) { |
| 14264 |
*(unsigned char *)order = 'B'; |
| 14265 |
} else { |
| 14266 |
*(unsigned char *)order = 'E'; |
| 14267 |
} |
| 14268 |
dstebz_(range, order, n, &vll, &vuu, il, iu, abstol, &d__[1], &e[1], m, & |
| 14269 |
nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[1], &iwork[ |
| 14270 |
indiwo], info); |
| 14271 |
|
| 14272 |
if (wantz) { |
| 14273 |
dstein_(n, &d__[1], &e[1], m, &w[1], &iwork[indibl], &iwork[indisp], & |
| 14274 |
z__[z_offset], ldz, &work[1], &iwork[indiwo], &iwork[indifl], |
| 14275 |
info); |
| 14276 |
} |
| 14277 |
|
| 14278 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 14279 |
|
| 14280 |
L10: |
| 14281 |
if (iscale == 1) { |
| 14282 |
if (*info == 0) { |
| 14283 |
imax = *m; |
| 14284 |
} else { |
| 14285 |
imax = *info - 1; |
| 14286 |
} |
| 14287 |
d__1 = 1. / sigma; |
| 14288 |
dscal_(&imax, &d__1, &w[1], &c__1); |
| 14289 |
} |
| 14290 |
|
| 14291 |
/* If eigenvalues are not in order, then sort them, along with */ |
| 14292 |
/* eigenvectors. */ |
| 14293 |
|
| 14294 |
if (wantz) { |
| 14295 |
i__1 = *m - 1; |
| 14296 |
for (j = 1; j <= i__1; ++j) { |
| 14297 |
i__ = 0; |
| 14298 |
tmp1 = w[j]; |
| 14299 |
i__2 = *m; |
| 14300 |
for (jj = j + 1; jj <= i__2; ++jj) { |
| 14301 |
if (w[jj] < tmp1) { |
| 14302 |
i__ = jj; |
| 14303 |
tmp1 = w[jj]; |
| 14304 |
} |
| 14305 |
/* L20: */ |
| 14306 |
} |
| 14307 |
|
| 14308 |
if (i__ != 0) { |
| 14309 |
itmp1 = iwork[i__]; |
| 14310 |
w[i__] = w[j]; |
| 14311 |
iwork[i__] = iwork[j]; |
| 14312 |
w[j] = tmp1; |
| 14313 |
iwork[j] = itmp1; |
| 14314 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], |
| 14315 |
&c__1); |
| 14316 |
} |
| 14317 |
/* L30: */ |
| 14318 |
} |
| 14319 |
} |
| 14320 |
|
| 14321 |
/* Causes problems with tests 19 & 20: */ |
| 14322 |
/* IF (wantz .and. INDEIG ) Z( 1,1) = Z(1,1) / 1.002 + .002 */ |
| 14323 |
|
| 14324 |
|
| 14325 |
work[1] = (double) lwmin; |
| 14326 |
iwork[1] = liwmin; |
| 14327 |
return 0; |
| 14328 |
|
| 14329 |
/* End of DSTEVR */ |
| 14330 |
|
| 14331 |
} /* dstevr_ */ |
| 14332 |
|
| 14333 |
/* Subroutine */ int dstevx_(const char *jobz, const char *range, integer *n, double * |
| 14334 |
d__, double *e, double *vl, double *vu, integer *il, |
| 14335 |
integer *iu, double *abstol, integer *m, double *w, |
| 14336 |
double *z__, integer *ldz, double *work, integer *iwork, |
| 14337 |
integer *ifail, integer *info) |
| 14338 |
{ |
| 14339 |
/* Table of constant values */ |
| 14340 |
static integer c__1 = 1; |
| 14341 |
|
| 14342 |
/* System generated locals */ |
| 14343 |
integer z_dim1, z_offset, i__1, i__2; |
| 14344 |
double d__1, d__2; |
| 14345 |
|
| 14346 |
/* Local variables */ |
| 14347 |
integer i__, j, jj; |
| 14348 |
double eps, vll, vuu, tmp1; |
| 14349 |
integer imax; |
| 14350 |
double rmin, rmax; |
| 14351 |
bool test; |
| 14352 |
double tnrm; |
| 14353 |
integer itmp1; |
| 14354 |
double sigma; |
| 14355 |
char order[1]; |
| 14356 |
bool wantz; |
| 14357 |
bool alleig, indeig; |
| 14358 |
integer iscale, indibl; |
| 14359 |
bool valeig; |
| 14360 |
double safmin; |
| 14361 |
double bignum; |
| 14362 |
integer indisp; |
| 14363 |
integer indiwo; |
| 14364 |
integer indwrk; |
| 14365 |
integer nsplit; |
| 14366 |
double smlnum; |
| 14367 |
|
| 14368 |
|
| 14369 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 14370 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 14371 |
/* November 2006 */ |
| 14372 |
|
| 14373 |
/* .. Scalar Arguments .. */ |
| 14374 |
/* .. */ |
| 14375 |
/* .. Array Arguments .. */ |
| 14376 |
/* .. */ |
| 14377 |
|
| 14378 |
/* Purpose */ |
| 14379 |
/* ======= */ |
| 14380 |
|
| 14381 |
/* DSTEVX computes selected eigenvalues and, optionally, eigenvectors */ |
| 14382 |
/* of a real symmetric tridiagonal matrix A. Eigenvalues and */ |
| 14383 |
/* eigenvectors can be selected by specifying either a range of values */ |
| 14384 |
/* or a range of indices for the desired eigenvalues. */ |
| 14385 |
|
| 14386 |
/* Arguments */ |
| 14387 |
/* ========= */ |
| 14388 |
|
| 14389 |
/* JOBZ (input) CHARACTER*1 */ |
| 14390 |
/* = 'N': Compute eigenvalues only; */ |
| 14391 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 14392 |
|
| 14393 |
/* RANGE (input) CHARACTER*1 */ |
| 14394 |
/* = 'A': all eigenvalues will be found. */ |
| 14395 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 14396 |
/* will be found. */ |
| 14397 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 14398 |
|
| 14399 |
/* N (input) INTEGER */ |
| 14400 |
/* The order of the matrix. N >= 0. */ |
| 14401 |
|
| 14402 |
/* D (input/output) DOUBLE PRECISION array, dimension (N) */ |
| 14403 |
/* On entry, the n diagonal elements of the tridiagonal matrix */ |
| 14404 |
/* A. */ |
| 14405 |
/* On exit, D may be multiplied by a constant factor chosen */ |
| 14406 |
/* to avoid over/underflow in computing the eigenvalues. */ |
| 14407 |
|
| 14408 |
/* E (input/output) DOUBLE PRECISION array, dimension (max(1,N-1)) */ |
| 14409 |
/* On entry, the (n-1) subdiagonal elements of the tridiagonal */ |
| 14410 |
/* matrix A in elements 1 to N-1 of E. */ |
| 14411 |
/* On exit, E may be multiplied by a constant factor chosen */ |
| 14412 |
/* to avoid over/underflow in computing the eigenvalues. */ |
| 14413 |
|
| 14414 |
/* VL (input) DOUBLE PRECISION */ |
| 14415 |
/* VU (input) DOUBLE PRECISION */ |
| 14416 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 14417 |
/* be searched for eigenvalues. VL < VU. */ |
| 14418 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 14419 |
|
| 14420 |
/* IL (input) INTEGER */ |
| 14421 |
/* IU (input) INTEGER */ |
| 14422 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 14423 |
/* smallest and largest eigenvalues to be returned. */ |
| 14424 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 14425 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 14426 |
|
| 14427 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 14428 |
/* The absolute error tolerance for the eigenvalues. */ |
| 14429 |
/* An approximate eigenvalue is accepted as converged */ |
| 14430 |
/* when it is determined to lie in an interval [a,b] */ |
| 14431 |
/* of width less than or equal to */ |
| 14432 |
|
| 14433 |
/* ABSTOL + EPS * max( |a|,|b| ) , */ |
| 14434 |
|
| 14435 |
/* where EPS is the machine precision. If ABSTOL is less */ |
| 14436 |
/* than or equal to zero, then EPS*|T| will be used in */ |
| 14437 |
/* its place, where |T| is the 1-norm of the tridiagonal */ |
| 14438 |
/* matrix. */ |
| 14439 |
|
| 14440 |
/* Eigenvalues will be computed most accurately when ABSTOL is */ |
| 14441 |
/* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */ |
| 14442 |
/* If this routine returns with INFO>0, indicating that some */ |
| 14443 |
/* eigenvectors did not converge, try setting ABSTOL to */ |
| 14444 |
/* 2*DLAMCH('S'). */ |
| 14445 |
|
| 14446 |
/* See "Computing Small Singular Values of Bidiagonal Matrices */ |
| 14447 |
/* with Guaranteed High Relative Accuracy," by Demmel and */ |
| 14448 |
/* Kahan, LAPACK Working Note #3. */ |
| 14449 |
|
| 14450 |
/* M (output) INTEGER */ |
| 14451 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 14452 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 14453 |
|
| 14454 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 14455 |
/* The first M elements contain the selected eigenvalues in */ |
| 14456 |
/* ascending order. */ |
| 14457 |
|
| 14458 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */ |
| 14459 |
/* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ |
| 14460 |
/* contain the orthonormal eigenvectors of the matrix A */ |
| 14461 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 14462 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 14463 |
/* If an eigenvector fails to converge (INFO > 0), then that */ |
| 14464 |
/* column of Z contains the latest approximation to the */ |
| 14465 |
/* eigenvector, and the index of the eigenvector is returned */ |
| 14466 |
/* in IFAIL. If JOBZ = 'N', then Z is not referenced. */ |
| 14467 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 14468 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 14469 |
/* is not known in advance and an upper bound must be used. */ |
| 14470 |
|
| 14471 |
/* LDZ (input) INTEGER */ |
| 14472 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 14473 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 14474 |
|
| 14475 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (5*N) */ |
| 14476 |
|
| 14477 |
/* IWORK (workspace) INTEGER array, dimension (5*N) */ |
| 14478 |
|
| 14479 |
/* IFAIL (output) INTEGER array, dimension (N) */ |
| 14480 |
/* If JOBZ = 'V', then if INFO = 0, the first M elements of */ |
| 14481 |
/* IFAIL are zero. If INFO > 0, then IFAIL contains the */ |
| 14482 |
/* indices of the eigenvectors that failed to converge. */ |
| 14483 |
/* If JOBZ = 'N', then IFAIL is not referenced. */ |
| 14484 |
|
| 14485 |
/* INFO (output) INTEGER */ |
| 14486 |
/* = 0: successful exit */ |
| 14487 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 14488 |
/* > 0: if INFO = i, then i eigenvectors failed to converge. */ |
| 14489 |
/* Their indices are stored in array IFAIL. */ |
| 14490 |
|
| 14491 |
/* ===================================================================== */ |
| 14492 |
|
| 14493 |
/* .. Parameters .. */ |
| 14494 |
/* .. */ |
| 14495 |
/* .. Local Scalars .. */ |
| 14496 |
/* .. */ |
| 14497 |
/* .. External Functions .. */ |
| 14498 |
/* .. */ |
| 14499 |
/* .. External Subroutines .. */ |
| 14500 |
/* .. */ |
| 14501 |
/* .. Intrinsic Functions .. */ |
| 14502 |
/* .. */ |
| 14503 |
/* .. Executable Statements .. */ |
| 14504 |
|
| 14505 |
/* Test the input parameters. */ |
| 14506 |
|
| 14507 |
/* Parameter adjustments */ |
| 14508 |
--d__; |
| 14509 |
--e; |
| 14510 |
--w; |
| 14511 |
z_dim1 = *ldz; |
| 14512 |
z_offset = 1 + z_dim1; |
| 14513 |
z__ -= z_offset; |
| 14514 |
--work; |
| 14515 |
--iwork; |
| 14516 |
--ifail; |
| 14517 |
|
| 14518 |
/* Function Body */ |
| 14519 |
wantz = lsame_(jobz, "V"); |
| 14520 |
alleig = lsame_(range, "A"); |
| 14521 |
valeig = lsame_(range, "V"); |
| 14522 |
indeig = lsame_(range, "I"); |
| 14523 |
|
| 14524 |
*info = 0; |
| 14525 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 14526 |
*info = -1; |
| 14527 |
} else if (! (alleig || valeig || indeig)) { |
| 14528 |
*info = -2; |
| 14529 |
} else if (*n < 0) { |
| 14530 |
*info = -3; |
| 14531 |
} else { |
| 14532 |
if (valeig) { |
| 14533 |
if (*n > 0 && *vu <= *vl) { |
| 14534 |
*info = -7; |
| 14535 |
} |
| 14536 |
} else if (indeig) { |
| 14537 |
if (*il < 1 || *il > std::max(1_integer,*n)) { |
| 14538 |
*info = -8; |
| 14539 |
} else if (*iu < std::min(*n,*il) || *iu > *n) { |
| 14540 |
*info = -9; |
| 14541 |
} |
| 14542 |
} |
| 14543 |
} |
| 14544 |
if (*info == 0) { |
| 14545 |
if (*ldz < 1 || wantz && *ldz < *n) { |
| 14546 |
*info = -14; |
| 14547 |
} |
| 14548 |
} |
| 14549 |
|
| 14550 |
if (*info != 0) { |
| 14551 |
i__1 = -(*info); |
| 14552 |
xerbla_("DSTEVX", &i__1); |
| 14553 |
return 0; |
| 14554 |
} |
| 14555 |
|
| 14556 |
/* Quick return if possible */ |
| 14557 |
|
| 14558 |
*m = 0; |
| 14559 |
if (*n == 0) { |
| 14560 |
return 0; |
| 14561 |
} |
| 14562 |
|
| 14563 |
if (*n == 1) { |
| 14564 |
if (alleig || indeig) { |
| 14565 |
*m = 1; |
| 14566 |
w[1] = d__[1]; |
| 14567 |
} else { |
| 14568 |
if (*vl < d__[1] && *vu >= d__[1]) { |
| 14569 |
*m = 1; |
| 14570 |
w[1] = d__[1]; |
| 14571 |
} |
| 14572 |
} |
| 14573 |
if (wantz) { |
| 14574 |
z__[z_dim1 + 1] = 1.; |
| 14575 |
} |
| 14576 |
return 0; |
| 14577 |
} |
| 14578 |
|
| 14579 |
/* Get machine constants. */ |
| 14580 |
|
| 14581 |
safmin = dlamch_("Safe minimum"); |
| 14582 |
eps = dlamch_("Precision"); |
| 14583 |
smlnum = safmin / eps; |
| 14584 |
bignum = 1. / smlnum; |
| 14585 |
rmin = sqrt(smlnum); |
| 14586 |
/* Computing MIN */ |
| 14587 |
d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin)); |
| 14588 |
rmax = std::min(d__1,d__2); |
| 14589 |
|
| 14590 |
/* Scale matrix to allowable range, if necessary. */ |
| 14591 |
|
| 14592 |
iscale = 0; |
| 14593 |
if (valeig) { |
| 14594 |
vll = *vl; |
| 14595 |
vuu = *vu; |
| 14596 |
} else { |
| 14597 |
vll = 0.; |
| 14598 |
vuu = 0.; |
| 14599 |
} |
| 14600 |
tnrm = dlanst_("M", n, &d__[1], &e[1]); |
| 14601 |
if (tnrm > 0. && tnrm < rmin) { |
| 14602 |
iscale = 1; |
| 14603 |
sigma = rmin / tnrm; |
| 14604 |
} else if (tnrm > rmax) { |
| 14605 |
iscale = 1; |
| 14606 |
sigma = rmax / tnrm; |
| 14607 |
} |
| 14608 |
if (iscale == 1) { |
| 14609 |
dscal_(n, &sigma, &d__[1], &c__1); |
| 14610 |
i__1 = *n - 1; |
| 14611 |
dscal_(&i__1, &sigma, &e[1], &c__1); |
| 14612 |
if (valeig) { |
| 14613 |
vll = *vl * sigma; |
| 14614 |
vuu = *vu * sigma; |
| 14615 |
} |
| 14616 |
} |
| 14617 |
|
| 14618 |
/* If all eigenvalues are desired and ABSTOL is less than zero, then */ |
| 14619 |
/* call DSTERF or SSTEQR. If this fails for some eigenvalue, then */ |
| 14620 |
/* try DSTEBZ. */ |
| 14621 |
|
| 14622 |
test = false; |
| 14623 |
if (indeig) { |
| 14624 |
if (*il == 1 && *iu == *n) { |
| 14625 |
test = true; |
| 14626 |
} |
| 14627 |
} |
| 14628 |
if ((alleig || test) && *abstol <= 0.) { |
| 14629 |
dcopy_(n, &d__[1], &c__1, &w[1], &c__1); |
| 14630 |
i__1 = *n - 1; |
| 14631 |
dcopy_(&i__1, &e[1], &c__1, &work[1], &c__1); |
| 14632 |
indwrk = *n + 1; |
| 14633 |
if (! wantz) { |
| 14634 |
dsterf_(n, &w[1], &work[1], info); |
| 14635 |
} else { |
| 14636 |
dsteqr_("I", n, &w[1], &work[1], &z__[z_offset], ldz, &work[ |
| 14637 |
indwrk], info); |
| 14638 |
if (*info == 0) { |
| 14639 |
i__1 = *n; |
| 14640 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 14641 |
ifail[i__] = 0; |
| 14642 |
/* L10: */ |
| 14643 |
} |
| 14644 |
} |
| 14645 |
} |
| 14646 |
if (*info == 0) { |
| 14647 |
*m = *n; |
| 14648 |
goto L20; |
| 14649 |
} |
| 14650 |
*info = 0; |
| 14651 |
} |
| 14652 |
|
| 14653 |
/* Otherwise, call DSTEBZ and, if eigenvectors are desired, SSTEIN. */ |
| 14654 |
|
| 14655 |
if (wantz) { |
| 14656 |
*(unsigned char *)order = 'B'; |
| 14657 |
} else { |
| 14658 |
*(unsigned char *)order = 'E'; |
| 14659 |
} |
| 14660 |
indwrk = 1; |
| 14661 |
indibl = 1; |
| 14662 |
indisp = indibl + *n; |
| 14663 |
indiwo = indisp + *n; |
| 14664 |
dstebz_(range, order, n, &vll, &vuu, il, iu, abstol, &d__[1], &e[1], m, & |
| 14665 |
nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[indwrk], & |
| 14666 |
iwork[indiwo], info); |
| 14667 |
|
| 14668 |
if (wantz) { |
| 14669 |
dstein_(n, &d__[1], &e[1], m, &w[1], &iwork[indibl], &iwork[indisp], & |
| 14670 |
z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], &ifail[1], |
| 14671 |
info); |
| 14672 |
} |
| 14673 |
|
| 14674 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 14675 |
|
| 14676 |
L20: |
| 14677 |
if (iscale == 1) { |
| 14678 |
if (*info == 0) { |
| 14679 |
imax = *m; |
| 14680 |
} else { |
| 14681 |
imax = *info - 1; |
| 14682 |
} |
| 14683 |
d__1 = 1. / sigma; |
| 14684 |
dscal_(&imax, &d__1, &w[1], &c__1); |
| 14685 |
} |
| 14686 |
|
| 14687 |
/* If eigenvalues are not in order, then sort them, along with */ |
| 14688 |
/* eigenvectors. */ |
| 14689 |
|
| 14690 |
if (wantz) { |
| 14691 |
i__1 = *m - 1; |
| 14692 |
for (j = 1; j <= i__1; ++j) { |
| 14693 |
i__ = 0; |
| 14694 |
tmp1 = w[j]; |
| 14695 |
i__2 = *m; |
| 14696 |
for (jj = j + 1; jj <= i__2; ++jj) { |
| 14697 |
if (w[jj] < tmp1) { |
| 14698 |
i__ = jj; |
| 14699 |
tmp1 = w[jj]; |
| 14700 |
} |
| 14701 |
/* L30: */ |
| 14702 |
} |
| 14703 |
|
| 14704 |
if (i__ != 0) { |
| 14705 |
itmp1 = iwork[indibl + i__ - 1]; |
| 14706 |
w[i__] = w[j]; |
| 14707 |
iwork[indibl + i__ - 1] = iwork[indibl + j - 1]; |
| 14708 |
w[j] = tmp1; |
| 14709 |
iwork[indibl + j - 1] = itmp1; |
| 14710 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], |
| 14711 |
&c__1); |
| 14712 |
if (*info != 0) { |
| 14713 |
itmp1 = ifail[i__]; |
| 14714 |
ifail[i__] = ifail[j]; |
| 14715 |
ifail[j] = itmp1; |
| 14716 |
} |
| 14717 |
} |
| 14718 |
/* L40: */ |
| 14719 |
} |
| 14720 |
} |
| 14721 |
|
| 14722 |
return 0; |
| 14723 |
|
| 14724 |
/* End of DSTEVX */ |
| 14725 |
|
| 14726 |
} /* dstevx_ */ |
| 14727 |
|
| 14728 |
/* Subroutine */ int dsycon_(const char *uplo, integer *n, double *a, integer * |
| 14729 |
lda, integer *ipiv, double *anorm, double *rcond, double * |
| 14730 |
work, integer *iwork, integer *info) |
| 14731 |
{ |
| 14732 |
/* Table of constant values */ |
| 14733 |
static integer c__1 = 1; |
| 14734 |
|
| 14735 |
/* System generated locals */ |
| 14736 |
integer a_dim1, a_offset, i__1; |
| 14737 |
|
| 14738 |
/* Local variables */ |
| 14739 |
integer i__, kase; |
| 14740 |
integer isave[3]; |
| 14741 |
bool upper; |
| 14742 |
double ainvnm; |
| 14743 |
|
| 14744 |
/* -- LAPACK routine (version 3.1) -- */ |
| 14745 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 14746 |
/* November 2006 */ |
| 14747 |
|
| 14748 |
/* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */ |
| 14749 |
|
| 14750 |
/* .. Scalar Arguments .. */ |
| 14751 |
/* .. */ |
| 14752 |
/* .. Array Arguments .. */ |
| 14753 |
/* .. */ |
| 14754 |
|
| 14755 |
/* Purpose */ |
| 14756 |
/* ======= */ |
| 14757 |
|
| 14758 |
/* DSYCON estimates the reciprocal of the condition number (in the */ |
| 14759 |
/* 1-norm) of a real symmetric matrix A using the factorization */ |
| 14760 |
/* A = U*D*U**T or A = L*D*L**T computed by DSYTRF. */ |
| 14761 |
|
| 14762 |
/* An estimate is obtained for norm(inv(A)), and the reciprocal of the */ |
| 14763 |
/* condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). */ |
| 14764 |
|
| 14765 |
/* Arguments */ |
| 14766 |
/* ========= */ |
| 14767 |
|
| 14768 |
/* UPLO (input) CHARACTER*1 */ |
| 14769 |
/* Specifies whether the details of the factorization are stored */ |
| 14770 |
/* as an upper or lower triangular matrix. */ |
| 14771 |
/* = 'U': Upper triangular, form is A = U*D*U**T; */ |
| 14772 |
/* = 'L': Lower triangular, form is A = L*D*L**T. */ |
| 14773 |
|
| 14774 |
/* N (input) INTEGER */ |
| 14775 |
/* The order of the matrix A. N >= 0. */ |
| 14776 |
|
| 14777 |
/* A (input) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 14778 |
/* The block diagonal matrix D and the multipliers used to */ |
| 14779 |
/* obtain the factor U or L as computed by DSYTRF. */ |
| 14780 |
|
| 14781 |
/* LDA (input) INTEGER */ |
| 14782 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 14783 |
|
| 14784 |
/* IPIV (input) INTEGER array, dimension (N) */ |
| 14785 |
/* Details of the interchanges and the block structure of D */ |
| 14786 |
/* as determined by DSYTRF. */ |
| 14787 |
|
| 14788 |
/* ANORM (input) DOUBLE PRECISION */ |
| 14789 |
/* The 1-norm of the original matrix A. */ |
| 14790 |
|
| 14791 |
/* RCOND (output) DOUBLE PRECISION */ |
| 14792 |
/* The reciprocal of the condition number of the matrix A, */ |
| 14793 |
/* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an */ |
| 14794 |
/* estimate of the 1-norm of inv(A) computed in this routine. */ |
| 14795 |
|
| 14796 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */ |
| 14797 |
|
| 14798 |
/* IWORK (workspace) INTEGER array, dimension (N) */ |
| 14799 |
|
| 14800 |
/* INFO (output) INTEGER */ |
| 14801 |
/* = 0: successful exit */ |
| 14802 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 14803 |
|
| 14804 |
/* ===================================================================== */ |
| 14805 |
|
| 14806 |
/* .. Parameters .. */ |
| 14807 |
/* .. */ |
| 14808 |
/* .. Local Scalars .. */ |
| 14809 |
/* .. */ |
| 14810 |
/* .. Local Arrays .. */ |
| 14811 |
/* .. */ |
| 14812 |
/* .. External Functions .. */ |
| 14813 |
/* .. */ |
| 14814 |
/* .. External Subroutines .. */ |
| 14815 |
/* .. */ |
| 14816 |
/* .. Intrinsic Functions .. */ |
| 14817 |
/* .. */ |
| 14818 |
/* .. Executable Statements .. */ |
| 14819 |
|
| 14820 |
/* Test the input parameters. */ |
| 14821 |
|
| 14822 |
/* Parameter adjustments */ |
| 14823 |
a_dim1 = *lda; |
| 14824 |
a_offset = 1 + a_dim1; |
| 14825 |
a -= a_offset; |
| 14826 |
--ipiv; |
| 14827 |
--work; |
| 14828 |
--iwork; |
| 14829 |
|
| 14830 |
/* Function Body */ |
| 14831 |
*info = 0; |
| 14832 |
upper = lsame_(uplo, "U"); |
| 14833 |
if (! upper && ! lsame_(uplo, "L")) { |
| 14834 |
*info = -1; |
| 14835 |
} else if (*n < 0) { |
| 14836 |
*info = -2; |
| 14837 |
} else if (*lda < std::max(1_integer,*n)) { |
| 14838 |
*info = -4; |
| 14839 |
} else if (*anorm < 0.) { |
| 14840 |
*info = -6; |
| 14841 |
} |
| 14842 |
if (*info != 0) { |
| 14843 |
i__1 = -(*info); |
| 14844 |
xerbla_("DSYCON", &i__1); |
| 14845 |
return 0; |
| 14846 |
} |
| 14847 |
|
| 14848 |
/* Quick return if possible */ |
| 14849 |
|
| 14850 |
*rcond = 0.; |
| 14851 |
if (*n == 0) { |
| 14852 |
*rcond = 1.; |
| 14853 |
return 0; |
| 14854 |
} else if (*anorm <= 0.) { |
| 14855 |
return 0; |
| 14856 |
} |
| 14857 |
|
| 14858 |
/* Check that the diagonal matrix D is nonsingular. */ |
| 14859 |
|
| 14860 |
if (upper) { |
| 14861 |
|
| 14862 |
/* Upper triangular storage: examine D from bottom to top */ |
| 14863 |
|
| 14864 |
for (i__ = *n; i__ >= 1; --i__) { |
| 14865 |
if (ipiv[i__] > 0 && a[i__ + i__ * a_dim1] == 0.) { |
| 14866 |
return 0; |
| 14867 |
} |
| 14868 |
/* L10: */ |
| 14869 |
} |
| 14870 |
} else { |
| 14871 |
|
| 14872 |
/* Lower triangular storage: examine D from top to bottom. */ |
| 14873 |
|
| 14874 |
i__1 = *n; |
| 14875 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 14876 |
if (ipiv[i__] > 0 && a[i__ + i__ * a_dim1] == 0.) { |
| 14877 |
return 0; |
| 14878 |
} |
| 14879 |
/* L20: */ |
| 14880 |
} |
| 14881 |
} |
| 14882 |
|
| 14883 |
/* Estimate the 1-norm of the inverse. */ |
| 14884 |
|
| 14885 |
kase = 0; |
| 14886 |
L30: |
| 14887 |
dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave); |
| 14888 |
if (kase != 0) { |
| 14889 |
|
| 14890 |
/* Multiply by inv(L*D*L') or inv(U*D*U'). */ |
| 14891 |
|
| 14892 |
dsytrs_(uplo, n, &c__1, &a[a_offset], lda, &ipiv[1], &work[1], n, |
| 14893 |
info); |
| 14894 |
goto L30; |
| 14895 |
} |
| 14896 |
|
| 14897 |
/* Compute the estimate of the reciprocal condition number. */ |
| 14898 |
|
| 14899 |
if (ainvnm != 0.) { |
| 14900 |
*rcond = 1. / ainvnm / *anorm; |
| 14901 |
} |
| 14902 |
|
| 14903 |
return 0; |
| 14904 |
|
| 14905 |
/* End of DSYCON */ |
| 14906 |
|
| 14907 |
} /* dsycon_ */ |
| 14908 |
|
| 14909 |
int dsyequb_(const char *uplo, integer *n, double *a, integer *lda, double *s, double *scond, |
| 14910 |
double *amax, double *work, integer *info) |
| 14911 |
{ |
| 14912 |
/* Table of constant values */ |
| 14913 |
static integer c__1 = 1; |
| 14914 |
|
| 14915 |
/* System generated locals */ |
| 14916 |
integer a_dim1, a_offset, i__1, i__2; |
| 14917 |
double d__1, d__2, d__3; |
| 14918 |
|
| 14919 |
/* Local variables */ |
| 14920 |
double d__; |
| 14921 |
integer i__, j; |
| 14922 |
double t, u, c0, c1, c2, si; |
| 14923 |
bool up; |
| 14924 |
double avg, std, tol, base; |
| 14925 |
integer iter; |
| 14926 |
double smin, smax, scale, sumsq, bignum, smlnum; |
| 14927 |
|
| 14928 |
|
| 14929 |
/* -- LAPACK routine (version 3.2) -- */ |
| 14930 |
/* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */ |
| 14931 |
/* -- Jason Riedy of Univ. of California Berkeley. -- */ |
| 14932 |
/* -- November 2008 -- */ |
| 14933 |
|
| 14934 |
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ |
| 14935 |
/* -- Univ. of California Berkeley and NAG Ltd. -- */ |
| 14936 |
|
| 14937 |
/* .. */ |
| 14938 |
/* .. Scalar Arguments .. */ |
| 14939 |
/* .. */ |
| 14940 |
/* .. Array Arguments .. */ |
| 14941 |
/* .. */ |
| 14942 |
|
| 14943 |
/* Purpose */ |
| 14944 |
/* ======= */ |
| 14945 |
|
| 14946 |
/* DSYEQUB computes row and column scalings intended to equilibrate a */ |
| 14947 |
/* symmetric matrix A and reduce its condition number */ |
| 14948 |
/* (with respect to the two-norm). S contains the scale factors, */ |
| 14949 |
/* S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with */ |
| 14950 |
/* elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This */ |
| 14951 |
/* choice of S puts the condition number of B within a factor N of the */ |
| 14952 |
/* smallest possible condition number over all possible diagonal */ |
| 14953 |
/* scalings. */ |
| 14954 |
|
| 14955 |
/* Arguments */ |
| 14956 |
/* ========= */ |
| 14957 |
|
| 14958 |
/* N (input) INTEGER */ |
| 14959 |
/* The order of the matrix A. N >= 0. */ |
| 14960 |
|
| 14961 |
/* A (input) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 14962 |
/* The N-by-N symmetric matrix whose scaling */ |
| 14963 |
/* factors are to be computed. Only the diagonal elements of A */ |
| 14964 |
/* are referenced. */ |
| 14965 |
|
| 14966 |
/* LDA (input) INTEGER */ |
| 14967 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 14968 |
|
| 14969 |
/* S (output) DOUBLE PRECISION array, dimension (N) */ |
| 14970 |
/* If INFO = 0, S contains the scale factors for A. */ |
| 14971 |
|
| 14972 |
/* SCOND (output) DOUBLE PRECISION */ |
| 14973 |
/* If INFO = 0, S contains the ratio of the smallest S(i) to */ |
| 14974 |
/* the largest S(i). If SCOND >= 0.1 and AMAX is neither too */ |
| 14975 |
/* large nor too small, it is not worth scaling by S. */ |
| 14976 |
|
| 14977 |
/* AMAX (output) DOUBLE PRECISION */ |
| 14978 |
/* Absolute value of largest matrix element. If AMAX is very */ |
| 14979 |
/* close to overflow or very close to underflow, the matrix */ |
| 14980 |
/* should be scaled. */ |
| 14981 |
/* INFO (output) INTEGER */ |
| 14982 |
/* = 0: successful exit */ |
| 14983 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 14984 |
/* > 0: if INFO = i, the i-th diagonal element is nonpositive. */ |
| 14985 |
|
| 14986 |
/* Further Details */ |
| 14987 |
/* ======= ======= */ |
| 14988 |
|
| 14989 |
/* Reference: Livne, O.E. and Golub, G.H., "Scaling by Binormalization", */ |
| 14990 |
/* Numerical Algorithms, vol. 35, no. 1, pp. 97-120, January 2004. */ |
| 14991 |
/* DOI 10.1023/B:NUMA.0000016606.32820.69 */ |
| 14992 |
/* Tech report version: http://ruready.utah.edu/archive/papers/bin.pdf */ |
| 14993 |
|
| 14994 |
/* ===================================================================== */ |
| 14995 |
|
| 14996 |
/* .. Parameters .. */ |
| 14997 |
/* .. */ |
| 14998 |
/* .. Local Scalars .. */ |
| 14999 |
/* .. */ |
| 15000 |
/* .. External Functions .. */ |
| 15001 |
/* .. */ |
| 15002 |
/* .. External Subroutines .. */ |
| 15003 |
/* .. */ |
| 15004 |
/* .. Executable Statements .. */ |
| 15005 |
|
| 15006 |
/* Test input parameters. */ |
| 15007 |
|
| 15008 |
/* Parameter adjustments */ |
| 15009 |
a_dim1 = *lda; |
| 15010 |
a_offset = 1 + a_dim1; |
| 15011 |
a -= a_offset; |
| 15012 |
--s; |
| 15013 |
--work; |
| 15014 |
|
| 15015 |
/* Function Body */ |
| 15016 |
*info = 0; |
| 15017 |
if (! (lsame_(uplo, "U") || lsame_(uplo, "L"))) { |
| 15018 |
*info = -1; |
| 15019 |
} else if (*n < 0) { |
| 15020 |
*info = -2; |
| 15021 |
} else if (*lda < std::max(1_integer,*n)) { |
| 15022 |
*info = -4; |
| 15023 |
} |
| 15024 |
if (*info != 0) { |
| 15025 |
i__1 = -(*info); |
| 15026 |
xerbla_("DSYEQUB", &i__1); |
| 15027 |
return 0; |
| 15028 |
} |
| 15029 |
up = lsame_(uplo, "U"); |
| 15030 |
*amax = 0.; |
| 15031 |
|
| 15032 |
/* Quick return if possible. */ |
| 15033 |
|
| 15034 |
if (*n == 0) { |
| 15035 |
*scond = 1.; |
| 15036 |
return 0; |
| 15037 |
} |
| 15038 |
i__1 = *n; |
| 15039 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 15040 |
s[i__] = 0.; |
| 15041 |
} |
| 15042 |
*amax = 0.; |
| 15043 |
if (up) { |
| 15044 |
i__1 = *n; |
| 15045 |
for (j = 1; j <= i__1; ++j) { |
| 15046 |
i__2 = j - 1; |
| 15047 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 15048 |
/* Computing MAX */ |
| 15049 |
d__2 = s[i__], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15050 |
s[i__] = std::max(d__2,d__3); |
| 15051 |
/* Computing MAX */ |
| 15052 |
d__2 = s[j], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15053 |
s[j] = std::max(d__2,d__3); |
| 15054 |
/* Computing MAX */ |
| 15055 |
d__2 = *amax, d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15056 |
*amax = std::max(d__2,d__3); |
| 15057 |
} |
| 15058 |
/* Computing MAX */ |
| 15059 |
d__2 = s[j], d__3 = (d__1 = a[j + j * a_dim1], abs(d__1)); |
| 15060 |
s[j] = std::max(d__2,d__3); |
| 15061 |
/* Computing MAX */ |
| 15062 |
d__2 = *amax, d__3 = (d__1 = a[j + j * a_dim1], abs(d__1)); |
| 15063 |
*amax = std::max(d__2,d__3); |
| 15064 |
} |
| 15065 |
} else { |
| 15066 |
i__1 = *n; |
| 15067 |
for (j = 1; j <= i__1; ++j) { |
| 15068 |
/* Computing MAX */ |
| 15069 |
d__2 = s[j], d__3 = (d__1 = a[j + j * a_dim1], abs(d__1)); |
| 15070 |
s[j] = std::max(d__2,d__3); |
| 15071 |
/* Computing MAX */ |
| 15072 |
d__2 = *amax, d__3 = (d__1 = a[j + j * a_dim1], abs(d__1)); |
| 15073 |
*amax = std::max(d__2,d__3); |
| 15074 |
i__2 = *n; |
| 15075 |
for (i__ = j + 1; i__ <= i__2; ++i__) { |
| 15076 |
/* Computing MAX */ |
| 15077 |
d__2 = s[i__], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15078 |
s[i__] = std::max(d__2,d__3); |
| 15079 |
/* Computing MAX */ |
| 15080 |
d__2 = s[j], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15081 |
s[j] = std::max(d__2,d__3); |
| 15082 |
/* Computing MAX */ |
| 15083 |
d__2 = *amax, d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15084 |
*amax = std::max(d__2,d__3); |
| 15085 |
} |
| 15086 |
} |
| 15087 |
} |
| 15088 |
i__1 = *n; |
| 15089 |
for (j = 1; j <= i__1; ++j) { |
| 15090 |
s[j] = 1. / s[j]; |
| 15091 |
} |
| 15092 |
tol = 1. / sqrt(*n * 2.); |
| 15093 |
for (iter = 1; iter <= 100; ++iter) { |
| 15094 |
scale = 0.; |
| 15095 |
sumsq = 0.; |
| 15096 |
/* BETA = |A|S */ |
| 15097 |
i__1 = *n; |
| 15098 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 15099 |
work[i__] = 0.; |
| 15100 |
} |
| 15101 |
if (up) { |
| 15102 |
i__1 = *n; |
| 15103 |
for (j = 1; j <= i__1; ++j) { |
| 15104 |
i__2 = j - 1; |
| 15105 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 15106 |
t = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15107 |
work[i__] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[ |
| 15108 |
j]; |
| 15109 |
work[j] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[ |
| 15110 |
i__]; |
| 15111 |
} |
| 15112 |
work[j] += (d__1 = a[j + j * a_dim1], abs(d__1)) * s[j]; |
| 15113 |
} |
| 15114 |
} else { |
| 15115 |
i__1 = *n; |
| 15116 |
for (j = 1; j <= i__1; ++j) { |
| 15117 |
work[j] += (d__1 = a[j + j * a_dim1], abs(d__1)) * s[j]; |
| 15118 |
i__2 = *n; |
| 15119 |
for (i__ = j + 1; i__ <= i__2; ++i__) { |
| 15120 |
t = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15121 |
work[i__] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[ |
| 15122 |
j]; |
| 15123 |
work[j] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[ |
| 15124 |
i__]; |
| 15125 |
} |
| 15126 |
} |
| 15127 |
} |
| 15128 |
/* avg = s^T beta / n */ |
| 15129 |
avg = 0.; |
| 15130 |
i__1 = *n; |
| 15131 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 15132 |
avg += s[i__] * work[i__]; |
| 15133 |
} |
| 15134 |
avg /= *n; |
| 15135 |
std = 0.; |
| 15136 |
i__1 = *n * 3; |
| 15137 |
for (i__ = (*n << 1) + 1; i__ <= i__1; ++i__) { |
| 15138 |
work[i__] = s[i__ - (*n << 1)] * work[i__ - (*n << 1)] - avg; |
| 15139 |
} |
| 15140 |
dlassq_(n, &work[(*n << 1) + 1], &c__1, &scale, &sumsq); |
| 15141 |
std = scale * sqrt(sumsq / *n); |
| 15142 |
if (std < tol * avg) { |
| 15143 |
goto L999; |
| 15144 |
} |
| 15145 |
i__1 = *n; |
| 15146 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 15147 |
t = (d__1 = a[i__ + i__ * a_dim1], abs(d__1)); |
| 15148 |
si = s[i__]; |
| 15149 |
c2 = (*n - 1) * t; |
| 15150 |
c1 = (*n - 2) * (work[i__] - t * si); |
| 15151 |
c0 = -(t * si) * si + work[i__] * 2 * si - *n * avg; |
| 15152 |
d__ = c1 * c1 - c0 * 4 * c2; |
| 15153 |
if (d__ <= 0.) { |
| 15154 |
*info = -1; |
| 15155 |
return 0; |
| 15156 |
} |
| 15157 |
si = c0 * -2 / (c1 + sqrt(d__)); |
| 15158 |
d__ = si - s[i__]; |
| 15159 |
u = 0.; |
| 15160 |
if (up) { |
| 15161 |
i__2 = i__; |
| 15162 |
for (j = 1; j <= i__2; ++j) { |
| 15163 |
t = (d__1 = a[j + i__ * a_dim1], abs(d__1)); |
| 15164 |
u += s[j] * t; |
| 15165 |
work[j] += d__ * t; |
| 15166 |
} |
| 15167 |
i__2 = *n; |
| 15168 |
for (j = i__ + 1; j <= i__2; ++j) { |
| 15169 |
t = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15170 |
u += s[j] * t; |
| 15171 |
work[j] += d__ * t; |
| 15172 |
} |
| 15173 |
} else { |
| 15174 |
i__2 = i__; |
| 15175 |
for (j = 1; j <= i__2; ++j) { |
| 15176 |
t = (d__1 = a[i__ + j * a_dim1], abs(d__1)); |
| 15177 |
u += s[j] * t; |
| 15178 |
work[j] += d__ * t; |
| 15179 |
} |
| 15180 |
i__2 = *n; |
| 15181 |
for (j = i__ + 1; j <= i__2; ++j) { |
| 15182 |
t = (d__1 = a[j + i__ * a_dim1], abs(d__1)); |
| 15183 |
u += s[j] * t; |
| 15184 |
work[j] += d__ * t; |
| 15185 |
} |
| 15186 |
} |
| 15187 |
avg += (u + work[i__]) * d__ / *n; |
| 15188 |
s[i__] = si; |
| 15189 |
} |
| 15190 |
} |
| 15191 |
L999: |
| 15192 |
smlnum = dlamch_("SAFEMIN"); |
| 15193 |
bignum = 1. / smlnum; |
| 15194 |
smin = bignum; |
| 15195 |
smax = 0.; |
| 15196 |
t = 1. / sqrt(avg); |
| 15197 |
base = dlamch_("B"); |
| 15198 |
u = 1. / log(base); |
| 15199 |
i__1 = *n; |
| 15200 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 15201 |
i__2 = (integer) (u * log(s[i__] * t)); |
| 15202 |
s[i__] = pow_di(&base, &i__2); |
| 15203 |
/* Computing MIN */ |
| 15204 |
d__1 = smin, d__2 = s[i__]; |
| 15205 |
smin = std::min(d__1,d__2); |
| 15206 |
/* Computing MAX */ |
| 15207 |
d__1 = smax, d__2 = s[i__]; |
| 15208 |
smax = std::max(d__1,d__2); |
| 15209 |
} |
| 15210 |
*scond = std::max(smin,smlnum) / std::min(smax,bignum); |
| 15211 |
|
| 15212 |
return 0; |
| 15213 |
} /* dsyequb_ */ |
| 15214 |
|
| 15215 |
/* Subroutine */ int dsyev_(const char *jobz, const char *uplo, integer *n, double *a, |
| 15216 |
integer *lda, double *w, double *work, integer *lwork, |
| 15217 |
integer *info) |
| 15218 |
{ |
| 15219 |
/* Table of constant values */ |
| 15220 |
static integer c__1 = 1; |
| 15221 |
static integer c_n1 = -1; |
| 15222 |
static integer c__0 = 0; |
| 15223 |
static double c_b17 = 1.; |
| 15224 |
|
| 15225 |
/* System generated locals */ |
| 15226 |
integer a_dim1, a_offset, i__1, i__2; |
| 15227 |
double d__1; |
| 15228 |
|
| 15229 |
/* Local variables */ |
| 15230 |
integer nb; |
| 15231 |
double eps; |
| 15232 |
integer inde; |
| 15233 |
double anrm; |
| 15234 |
integer imax; |
| 15235 |
double rmin, rmax; |
| 15236 |
double sigma; |
| 15237 |
integer iinfo; |
| 15238 |
bool lower, wantz; |
| 15239 |
integer iscale; |
| 15240 |
double safmin; |
| 15241 |
double bignum; |
| 15242 |
integer indtau; |
| 15243 |
integer indwrk; |
| 15244 |
integer llwork; |
| 15245 |
double smlnum; |
| 15246 |
integer lwkopt; |
| 15247 |
bool lquery; |
| 15248 |
|
| 15249 |
|
| 15250 |
/* -- LAPACK driver routine (version 3.2) -- */ |
| 15251 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 15252 |
/* November 2006 */ |
| 15253 |
|
| 15254 |
/* .. Scalar Arguments .. */ |
| 15255 |
/* .. */ |
| 15256 |
/* .. Array Arguments .. */ |
| 15257 |
/* .. */ |
| 15258 |
|
| 15259 |
/* Purpose */ |
| 15260 |
/* ======= */ |
| 15261 |
|
| 15262 |
/* DSYEV computes all eigenvalues and, optionally, eigenvectors of a */ |
| 15263 |
/* real symmetric matrix A. */ |
| 15264 |
|
| 15265 |
/* Arguments */ |
| 15266 |
/* ========= */ |
| 15267 |
|
| 15268 |
/* JOBZ (input) CHARACTER*1 */ |
| 15269 |
/* = 'N': Compute eigenvalues only; */ |
| 15270 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 15271 |
|
| 15272 |
/* UPLO (input) CHARACTER*1 */ |
| 15273 |
/* = 'U': Upper triangle of A is stored; */ |
| 15274 |
/* = 'L': Lower triangle of A is stored. */ |
| 15275 |
|
| 15276 |
/* N (input) INTEGER */ |
| 15277 |
/* The order of the matrix A. N >= 0. */ |
| 15278 |
|
| 15279 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */ |
| 15280 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the */ |
| 15281 |
/* leading N-by-N upper triangular part of A contains the */ |
| 15282 |
/* upper triangular part of the matrix A. If UPLO = 'L', */ |
| 15283 |
/* the leading N-by-N lower triangular part of A contains */ |
| 15284 |
/* the lower triangular part of the matrix A. */ |
| 15285 |
/* On exit, if JOBZ = 'V', then if INFO = 0, A contains the */ |
| 15286 |
/* orthonormal eigenvectors of the matrix A. */ |
| 15287 |
/* If JOBZ = 'N', then on exit the lower triangle (if UPLO='L') */ |
| 15288 |
/* or the upper triangle (if UPLO='U') of A, including the */ |
| 15289 |
/* diagonal, is destroyed. */ |
| 15290 |
|
| 15291 |
/* LDA (input) INTEGER */ |
| 15292 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 15293 |
|
| 15294 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 15295 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 15296 |
|
| 15297 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 15298 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 15299 |
|
| 15300 |
/* LWORK (input) INTEGER */ |
| 15301 |
/* The length of the array WORK. LWORK >= max(1,3*N-1). */ |
| 15302 |
/* For optimal efficiency, LWORK >= (NB+2)*N, */ |
| 15303 |
/* where NB is the blocksize for DSYTRD returned by ILAENV. */ |
| 15304 |
|
| 15305 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 15306 |
/* only calculates the optimal size of the WORK array, returns */ |
| 15307 |
/* this value as the first entry of the WORK array, and no error */ |
| 15308 |
/* message related to LWORK is issued by XERBLA. */ |
| 15309 |
|
| 15310 |
/* INFO (output) INTEGER */ |
| 15311 |
/* = 0: successful exit */ |
| 15312 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 15313 |
/* > 0: if INFO = i, the algorithm failed to converge; i */ |
| 15314 |
/* off-diagonal elements of an intermediate tridiagonal */ |
| 15315 |
/* form did not converge to zero. */ |
| 15316 |
|
| 15317 |
/* ===================================================================== */ |
| 15318 |
|
| 15319 |
/* .. Parameters .. */ |
| 15320 |
/* .. */ |
| 15321 |
/* .. Local Scalars .. */ |
| 15322 |
/* .. */ |
| 15323 |
/* .. External Functions .. */ |
| 15324 |
/* .. */ |
| 15325 |
/* .. External Subroutines .. */ |
| 15326 |
/* .. */ |
| 15327 |
/* .. Intrinsic Functions .. */ |
| 15328 |
/* .. */ |
| 15329 |
/* .. Executable Statements .. */ |
| 15330 |
|
| 15331 |
/* Test the input parameters. */ |
| 15332 |
|
| 15333 |
/* Parameter adjustments */ |
| 15334 |
a_dim1 = *lda; |
| 15335 |
a_offset = 1 + a_dim1; |
| 15336 |
a -= a_offset; |
| 15337 |
--w; |
| 15338 |
--work; |
| 15339 |
|
| 15340 |
/* Function Body */ |
| 15341 |
wantz = lsame_(jobz, "V"); |
| 15342 |
lower = lsame_(uplo, "L"); |
| 15343 |
lquery = *lwork == -1; |
| 15344 |
|
| 15345 |
*info = 0; |
| 15346 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 15347 |
*info = -1; |
| 15348 |
} else if (! (lower || lsame_(uplo, "U"))) { |
| 15349 |
*info = -2; |
| 15350 |
} else if (*n < 0) { |
| 15351 |
*info = -3; |
| 15352 |
} else if (*lda < std::max(1_integer,*n)) { |
| 15353 |
*info = -5; |
| 15354 |
} |
| 15355 |
|
| 15356 |
if (*info == 0) { |
| 15357 |
nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1); |
| 15358 |
/* Computing MAX */ |
| 15359 |
i__1 = 1, i__2 = (nb + 2) * *n; |
| 15360 |
lwkopt = std::max(i__1,i__2); |
| 15361 |
work[1] = (double) lwkopt; |
| 15362 |
|
| 15363 |
/* Computing MAX */ |
| 15364 |
i__1 = 1, i__2 = *n * 3 - 1; |
| 15365 |
if (*lwork < std::max(i__1,i__2) && ! lquery) { |
| 15366 |
*info = -8; |
| 15367 |
} |
| 15368 |
} |
| 15369 |
|
| 15370 |
if (*info != 0) { |
| 15371 |
i__1 = -(*info); |
| 15372 |
xerbla_("DSYEV ", &i__1); |
| 15373 |
return 0; |
| 15374 |
} else if (lquery) { |
| 15375 |
return 0; |
| 15376 |
} |
| 15377 |
|
| 15378 |
/* Quick return if possible */ |
| 15379 |
|
| 15380 |
if (*n == 0) { |
| 15381 |
return 0; |
| 15382 |
} |
| 15383 |
|
| 15384 |
if (*n == 1) { |
| 15385 |
w[1] = a[a_dim1 + 1]; |
| 15386 |
work[1] = 2.; |
| 15387 |
if (wantz) { |
| 15388 |
a[a_dim1 + 1] = 1.; |
| 15389 |
} |
| 15390 |
return 0; |
| 15391 |
} |
| 15392 |
|
| 15393 |
/* Get machine constants. */ |
| 15394 |
|
| 15395 |
safmin = dlamch_("Safe minimum"); |
| 15396 |
eps = dlamch_("Precision"); |
| 15397 |
smlnum = safmin / eps; |
| 15398 |
bignum = 1. / smlnum; |
| 15399 |
rmin = sqrt(smlnum); |
| 15400 |
rmax = sqrt(bignum); |
| 15401 |
|
| 15402 |
/* Scale matrix to allowable range, if necessary. */ |
| 15403 |
|
| 15404 |
anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]); |
| 15405 |
iscale = 0; |
| 15406 |
if (anrm > 0. && anrm < rmin) { |
| 15407 |
iscale = 1; |
| 15408 |
sigma = rmin / anrm; |
| 15409 |
} else if (anrm > rmax) { |
| 15410 |
iscale = 1; |
| 15411 |
sigma = rmax / anrm; |
| 15412 |
} |
| 15413 |
if (iscale == 1) { |
| 15414 |
dlascl_(uplo, &c__0, &c__0, &c_b17, &sigma, n, n, &a[a_offset], lda, |
| 15415 |
info); |
| 15416 |
} |
| 15417 |
|
| 15418 |
/* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */ |
| 15419 |
|
| 15420 |
inde = 1; |
| 15421 |
indtau = inde + *n; |
| 15422 |
indwrk = indtau + *n; |
| 15423 |
llwork = *lwork - indwrk + 1; |
| 15424 |
dsytrd_(uplo, n, &a[a_offset], lda, &w[1], &work[inde], &work[indtau], & |
| 15425 |
work[indwrk], &llwork, &iinfo); |
| 15426 |
|
| 15427 |
/* For eigenvalues only, call DSTERF. For eigenvectors, first call */ |
| 15428 |
/* DORGTR to generate the orthogonal matrix, then call DSTEQR. */ |
| 15429 |
|
| 15430 |
if (! wantz) { |
| 15431 |
dsterf_(n, &w[1], &work[inde], info); |
| 15432 |
} else { |
| 15433 |
dorgtr_(uplo, n, &a[a_offset], lda, &work[indtau], &work[indwrk], & |
| 15434 |
llwork, &iinfo); |
| 15435 |
dsteqr_(jobz, n, &w[1], &work[inde], &a[a_offset], lda, &work[indtau], |
| 15436 |
info); |
| 15437 |
} |
| 15438 |
|
| 15439 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 15440 |
|
| 15441 |
if (iscale == 1) { |
| 15442 |
if (*info == 0) { |
| 15443 |
imax = *n; |
| 15444 |
} else { |
| 15445 |
imax = *info - 1; |
| 15446 |
} |
| 15447 |
d__1 = 1. / sigma; |
| 15448 |
dscal_(&imax, &d__1, &w[1], &c__1); |
| 15449 |
} |
| 15450 |
|
| 15451 |
/* Set WORK(1) to optimal workspace size. */ |
| 15452 |
|
| 15453 |
work[1] = (double) lwkopt; |
| 15454 |
|
| 15455 |
return 0; |
| 15456 |
|
| 15457 |
/* End of DSYEV */ |
| 15458 |
|
| 15459 |
} /* dsyev_ */ |
| 15460 |
|
| 15461 |
/* Subroutine */ int dsyevd_(const char *jobz, const char *uplo, integer *n, double * |
| 15462 |
a, integer *lda, double *w, double *work, integer *lwork, |
| 15463 |
integer *iwork, integer *liwork, integer *info) |
| 15464 |
{ |
| 15465 |
/* Table of constant values */ |
| 15466 |
static integer c__1 = 1; |
| 15467 |
static integer c_n1 = -1; |
| 15468 |
static integer c__0 = 0; |
| 15469 |
static double c_b17 = 1.; |
| 15470 |
|
| 15471 |
/* System generated locals */ |
| 15472 |
integer a_dim1, a_offset, i__1, i__2, i__3; |
| 15473 |
double d__1; |
| 15474 |
|
| 15475 |
/* Local variables */ |
| 15476 |
double eps; |
| 15477 |
integer inde; |
| 15478 |
double anrm, rmin, rmax; |
| 15479 |
integer lopt; |
| 15480 |
double sigma; |
| 15481 |
integer iinfo, lwmin, liopt; |
| 15482 |
bool lower, wantz; |
| 15483 |
integer indwk2, llwrk2; |
| 15484 |
integer iscale; |
| 15485 |
double safmin; |
| 15486 |
double bignum; |
| 15487 |
integer indtau; |
| 15488 |
integer indwrk, liwmin; |
| 15489 |
integer llwork; |
| 15490 |
double smlnum; |
| 15491 |
bool lquery; |
| 15492 |
|
| 15493 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 15494 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 15495 |
/* November 2006 */ |
| 15496 |
|
| 15497 |
/* .. Scalar Arguments .. */ |
| 15498 |
/* .. */ |
| 15499 |
/* .. Array Arguments .. */ |
| 15500 |
/* .. */ |
| 15501 |
|
| 15502 |
/* Purpose */ |
| 15503 |
/* ======= */ |
| 15504 |
|
| 15505 |
/* DSYEVD computes all eigenvalues and, optionally, eigenvectors of a */ |
| 15506 |
/* real symmetric matrix A. If eigenvectors are desired, it uses a */ |
| 15507 |
/* divide and conquer algorithm. */ |
| 15508 |
|
| 15509 |
/* The divide and conquer algorithm makes very mild assumptions about */ |
| 15510 |
/* floating point arithmetic. It will work on machines with a guard */ |
| 15511 |
/* digit in add/subtract, or on those binary machines without guard */ |
| 15512 |
/* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ |
| 15513 |
/* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ |
| 15514 |
/* without guard digits, but we know of none. */ |
| 15515 |
|
| 15516 |
/* Because of large use of BLAS of level 3, DSYEVD needs N**2 more */ |
| 15517 |
/* workspace than DSYEVX. */ |
| 15518 |
|
| 15519 |
/* Arguments */ |
| 15520 |
/* ========= */ |
| 15521 |
|
| 15522 |
/* JOBZ (input) CHARACTER*1 */ |
| 15523 |
/* = 'N': Compute eigenvalues only; */ |
| 15524 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 15525 |
|
| 15526 |
/* UPLO (input) CHARACTER*1 */ |
| 15527 |
/* = 'U': Upper triangle of A is stored; */ |
| 15528 |
/* = 'L': Lower triangle of A is stored. */ |
| 15529 |
|
| 15530 |
/* N (input) INTEGER */ |
| 15531 |
/* The order of the matrix A. N >= 0. */ |
| 15532 |
|
| 15533 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */ |
| 15534 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the */ |
| 15535 |
/* leading N-by-N upper triangular part of A contains the */ |
| 15536 |
/* upper triangular part of the matrix A. If UPLO = 'L', */ |
| 15537 |
/* the leading N-by-N lower triangular part of A contains */ |
| 15538 |
/* the lower triangular part of the matrix A. */ |
| 15539 |
/* On exit, if JOBZ = 'V', then if INFO = 0, A contains the */ |
| 15540 |
/* orthonormal eigenvectors of the matrix A. */ |
| 15541 |
/* If JOBZ = 'N', then on exit the lower triangle (if UPLO='L') */ |
| 15542 |
/* or the upper triangle (if UPLO='U') of A, including the */ |
| 15543 |
/* diagonal, is destroyed. */ |
| 15544 |
|
| 15545 |
/* LDA (input) INTEGER */ |
| 15546 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 15547 |
|
| 15548 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 15549 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 15550 |
|
| 15551 |
/* WORK (workspace/output) DOUBLE PRECISION array, */ |
| 15552 |
/* dimension (LWORK) */ |
| 15553 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 15554 |
|
| 15555 |
/* LWORK (input) INTEGER */ |
| 15556 |
/* The dimension of the array WORK. */ |
| 15557 |
/* If N <= 1, LWORK must be at least 1. */ |
| 15558 |
/* If JOBZ = 'N' and N > 1, LWORK must be at least 2*N+1. */ |
| 15559 |
/* If JOBZ = 'V' and N > 1, LWORK must be at least */ |
| 15560 |
/* 1 + 6*N + 2*N**2. */ |
| 15561 |
|
| 15562 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 15563 |
/* only calculates the optimal sizes of the WORK and IWORK */ |
| 15564 |
/* arrays, returns these values as the first entries of the WORK */ |
| 15565 |
/* and IWORK arrays, and no error message related to LWORK or */ |
| 15566 |
/* LIWORK is issued by XERBLA. */ |
| 15567 |
|
| 15568 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 15569 |
/* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ |
| 15570 |
|
| 15571 |
/* LIWORK (input) INTEGER */ |
| 15572 |
/* The dimension of the array IWORK. */ |
| 15573 |
/* If N <= 1, LIWORK must be at least 1. */ |
| 15574 |
/* If JOBZ = 'N' and N > 1, LIWORK must be at least 1. */ |
| 15575 |
/* If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N. */ |
| 15576 |
|
| 15577 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 15578 |
/* routine only calculates the optimal sizes of the WORK and */ |
| 15579 |
/* IWORK arrays, returns these values as the first entries of */ |
| 15580 |
/* the WORK and IWORK arrays, and no error message related to */ |
| 15581 |
/* LWORK or LIWORK is issued by XERBLA. */ |
| 15582 |
|
| 15583 |
/* INFO (output) INTEGER */ |
| 15584 |
/* = 0: successful exit */ |
| 15585 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 15586 |
/* > 0: if INFO = i and JOBZ = 'N', then the algorithm failed */ |
| 15587 |
/* to converge; i off-diagonal elements of an intermediate */ |
| 15588 |
/* tridiagonal form did not converge to zero; */ |
| 15589 |
/* if INFO = i and JOBZ = 'V', then the algorithm failed */ |
| 15590 |
/* to compute an eigenvalue while working on the submatrix */ |
| 15591 |
/* lying in rows and columns INFO/(N+1) through */ |
| 15592 |
/* mod(INFO,N+1). */ |
| 15593 |
|
| 15594 |
/* Further Details */ |
| 15595 |
/* =============== */ |
| 15596 |
|
| 15597 |
/* Based on contributions by */ |
| 15598 |
/* Jeff Rutter, Computer Science Division, University of California */ |
| 15599 |
/* at Berkeley, USA */ |
| 15600 |
/* Modified by Francoise Tisseur, University of Tennessee. */ |
| 15601 |
|
| 15602 |
/* Modified description of INFO. Sven, 16 Feb 05. */ |
| 15603 |
/* ===================================================================== */ |
| 15604 |
|
| 15605 |
/* .. Parameters .. */ |
| 15606 |
/* .. */ |
| 15607 |
/* .. Local Scalars .. */ |
| 15608 |
|
| 15609 |
/* .. */ |
| 15610 |
/* .. External Functions .. */ |
| 15611 |
/* .. */ |
| 15612 |
/* .. External Subroutines .. */ |
| 15613 |
/* .. */ |
| 15614 |
/* .. Intrinsic Functions .. */ |
| 15615 |
/* .. */ |
| 15616 |
/* .. Executable Statements .. */ |
| 15617 |
|
| 15618 |
/* Test the input parameters. */ |
| 15619 |
|
| 15620 |
/* Parameter adjustments */ |
| 15621 |
a_dim1 = *lda; |
| 15622 |
a_offset = 1 + a_dim1; |
| 15623 |
a -= a_offset; |
| 15624 |
--w; |
| 15625 |
--work; |
| 15626 |
--iwork; |
| 15627 |
|
| 15628 |
/* Function Body */ |
| 15629 |
wantz = lsame_(jobz, "V"); |
| 15630 |
lower = lsame_(uplo, "L"); |
| 15631 |
lquery = *lwork == -1 || *liwork == -1; |
| 15632 |
|
| 15633 |
*info = 0; |
| 15634 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 15635 |
*info = -1; |
| 15636 |
} else if (! (lower || lsame_(uplo, "U"))) { |
| 15637 |
*info = -2; |
| 15638 |
} else if (*n < 0) { |
| 15639 |
*info = -3; |
| 15640 |
} else if (*lda < std::max(1_integer,*n)) { |
| 15641 |
*info = -5; |
| 15642 |
} |
| 15643 |
|
| 15644 |
if (*info == 0) { |
| 15645 |
if (*n <= 1) { |
| 15646 |
liwmin = 1; |
| 15647 |
lwmin = 1; |
| 15648 |
lopt = lwmin; |
| 15649 |
liopt = liwmin; |
| 15650 |
} else { |
| 15651 |
if (wantz) { |
| 15652 |
liwmin = *n * 5 + 3; |
| 15653 |
/* Computing 2nd power */ |
| 15654 |
i__1 = *n; |
| 15655 |
lwmin = *n * 6 + 1 + (i__1 * i__1 << 1); |
| 15656 |
} else { |
| 15657 |
liwmin = 1; |
| 15658 |
lwmin = (*n << 1) + 1; |
| 15659 |
} |
| 15660 |
/* Computing MAX */ |
| 15661 |
i__1 = lwmin, i__2 = (*n << 1) + ilaenv_(&c__1, "DSYTRD", uplo, n, |
| 15662 |
&c_n1, &c_n1, &c_n1); |
| 15663 |
lopt = std::max(i__1,i__2); |
| 15664 |
liopt = liwmin; |
| 15665 |
} |
| 15666 |
work[1] = (double) lopt; |
| 15667 |
iwork[1] = liopt; |
| 15668 |
|
| 15669 |
if (*lwork < lwmin && ! lquery) { |
| 15670 |
*info = -8; |
| 15671 |
} else if (*liwork < liwmin && ! lquery) { |
| 15672 |
*info = -10; |
| 15673 |
} |
| 15674 |
} |
| 15675 |
|
| 15676 |
if (*info != 0) { |
| 15677 |
i__1 = -(*info); |
| 15678 |
xerbla_("DSYEVD", &i__1); |
| 15679 |
return 0; |
| 15680 |
} else if (lquery) { |
| 15681 |
return 0; |
| 15682 |
} |
| 15683 |
|
| 15684 |
/* Quick return if possible */ |
| 15685 |
|
| 15686 |
if (*n == 0) { |
| 15687 |
return 0; |
| 15688 |
} |
| 15689 |
|
| 15690 |
if (*n == 1) { |
| 15691 |
w[1] = a[a_dim1 + 1]; |
| 15692 |
if (wantz) { |
| 15693 |
a[a_dim1 + 1] = 1.; |
| 15694 |
} |
| 15695 |
return 0; |
| 15696 |
} |
| 15697 |
|
| 15698 |
/* Get machine constants. */ |
| 15699 |
|
| 15700 |
safmin = dlamch_("Safe minimum"); |
| 15701 |
eps = dlamch_("Precision"); |
| 15702 |
smlnum = safmin / eps; |
| 15703 |
bignum = 1. / smlnum; |
| 15704 |
rmin = sqrt(smlnum); |
| 15705 |
rmax = sqrt(bignum); |
| 15706 |
|
| 15707 |
/* Scale matrix to allowable range, if necessary. */ |
| 15708 |
|
| 15709 |
anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]); |
| 15710 |
iscale = 0; |
| 15711 |
if (anrm > 0. && anrm < rmin) { |
| 15712 |
iscale = 1; |
| 15713 |
sigma = rmin / anrm; |
| 15714 |
} else if (anrm > rmax) { |
| 15715 |
iscale = 1; |
| 15716 |
sigma = rmax / anrm; |
| 15717 |
} |
| 15718 |
if (iscale == 1) { |
| 15719 |
dlascl_(uplo, &c__0, &c__0, &c_b17, &sigma, n, n, &a[a_offset], lda, |
| 15720 |
info); |
| 15721 |
} |
| 15722 |
|
| 15723 |
/* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */ |
| 15724 |
|
| 15725 |
inde = 1; |
| 15726 |
indtau = inde + *n; |
| 15727 |
indwrk = indtau + *n; |
| 15728 |
llwork = *lwork - indwrk + 1; |
| 15729 |
indwk2 = indwrk + *n * *n; |
| 15730 |
llwrk2 = *lwork - indwk2 + 1; |
| 15731 |
|
| 15732 |
dsytrd_(uplo, n, &a[a_offset], lda, &w[1], &work[inde], &work[indtau], & |
| 15733 |
work[indwrk], &llwork, &iinfo); |
| 15734 |
lopt = (integer) ((*n << 1) + work[indwrk]); |
| 15735 |
|
| 15736 |
/* For eigenvalues only, call DSTERF. For eigenvectors, first call */ |
| 15737 |
/* DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the */ |
| 15738 |
/* tridiagonal matrix, then call DORMTR to multiply it by the */ |
| 15739 |
/* Householder transformations stored in A. */ |
| 15740 |
|
| 15741 |
if (! wantz) { |
| 15742 |
dsterf_(n, &w[1], &work[inde], info); |
| 15743 |
} else { |
| 15744 |
dstedc_("I", n, &w[1], &work[inde], &work[indwrk], n, &work[indwk2], & |
| 15745 |
llwrk2, &iwork[1], liwork, info); |
| 15746 |
dormtr_("L", uplo, "N", n, n, &a[a_offset], lda, &work[indtau], &work[ |
| 15747 |
indwrk], n, &work[indwk2], &llwrk2, &iinfo); |
| 15748 |
dlacpy_("A", n, n, &work[indwrk], n, &a[a_offset], lda); |
| 15749 |
/* Computing MAX */ |
| 15750 |
/* Computing 2nd power */ |
| 15751 |
i__3 = *n; |
| 15752 |
i__1 = lopt, i__2 = *n * 6 + 1 + (i__3 * i__3 << 1); |
| 15753 |
lopt = std::max(i__1,i__2); |
| 15754 |
} |
| 15755 |
|
| 15756 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 15757 |
|
| 15758 |
if (iscale == 1) { |
| 15759 |
d__1 = 1. / sigma; |
| 15760 |
dscal_(n, &d__1, &w[1], &c__1); |
| 15761 |
} |
| 15762 |
|
| 15763 |
work[1] = (double) lopt; |
| 15764 |
iwork[1] = liopt; |
| 15765 |
|
| 15766 |
return 0; |
| 15767 |
|
| 15768 |
/* End of DSYEVD */ |
| 15769 |
|
| 15770 |
} /* dsyevd_ */ |
| 15771 |
|
| 15772 |
/* Subroutine */ int dsyevr_(const char *jobz, const char *range, const char *uplo, integer *n, |
| 15773 |
double *a, integer *lda, double *vl, double *vu, integer * |
| 15774 |
il, integer *iu, double *abstol, integer *m, double *w, |
| 15775 |
double *z__, integer *ldz, integer *isuppz, double *work, |
| 15776 |
integer *lwork, integer *iwork, integer *liwork, integer *info) |
| 15777 |
{ |
| 15778 |
/* Table of constant values */ |
| 15779 |
static integer c__10 = 10; |
| 15780 |
static integer c__1 = 1; |
| 15781 |
static integer c__2 = 2; |
| 15782 |
static integer c__3 = 3; |
| 15783 |
static integer c__4 = 4; |
| 15784 |
static integer c_n1 = -1; |
| 15785 |
|
| 15786 |
/* System generated locals */ |
| 15787 |
integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2; |
| 15788 |
double d__1, d__2; |
| 15789 |
|
| 15790 |
/* Local variables */ |
| 15791 |
integer i__, j, nb, jj; |
| 15792 |
double eps, vll, vuu, tmp1; |
| 15793 |
integer indd, inde; |
| 15794 |
double anrm; |
| 15795 |
integer imax; |
| 15796 |
double rmin, rmax; |
| 15797 |
integer inddd, indee; |
| 15798 |
double sigma; |
| 15799 |
integer iinfo; |
| 15800 |
char order[1]; |
| 15801 |
integer indwk; |
| 15802 |
integer lwmin; |
| 15803 |
bool lower, wantz; |
| 15804 |
bool alleig, indeig; |
| 15805 |
integer iscale, ieeeok, indibl, indifl; |
| 15806 |
bool valeig; |
| 15807 |
double safmin; |
| 15808 |
double abstll, bignum; |
| 15809 |
integer indtau, indisp; |
| 15810 |
integer indiwo, indwkn; |
| 15811 |
integer liwmin; |
| 15812 |
bool tryrac; |
| 15813 |
integer llwrkn, llwork, nsplit; |
| 15814 |
double smlnum; |
| 15815 |
integer lwkopt; |
| 15816 |
bool lquery; |
| 15817 |
|
| 15818 |
|
| 15819 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 15820 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 15821 |
/* November 2006 */ |
| 15822 |
|
| 15823 |
/* .. Scalar Arguments .. */ |
| 15824 |
/* .. */ |
| 15825 |
/* .. Array Arguments .. */ |
| 15826 |
/* .. */ |
| 15827 |
|
| 15828 |
/* Purpose */ |
| 15829 |
/* ======= */ |
| 15830 |
|
| 15831 |
/* DSYEVR computes selected eigenvalues and, optionally, eigenvectors */ |
| 15832 |
/* of a real symmetric matrix A. Eigenvalues and eigenvectors can be */ |
| 15833 |
/* selected by specifying either a range of values or a range of */ |
| 15834 |
/* indices for the desired eigenvalues. */ |
| 15835 |
|
| 15836 |
/* DSYEVR first reduces the matrix A to tridiagonal form T with a call */ |
| 15837 |
/* to DSYTRD. Then, whenever possible, DSYEVR calls DSTEMR to compute */ |
| 15838 |
/* the eigenspectrum using Relatively Robust Representations. DSTEMR */ |
| 15839 |
/* computes eigenvalues by the dqds algorithm, while orthogonal */ |
| 15840 |
/* eigenvectors are computed from various "good" L D L^T representations */ |
| 15841 |
/* (also known as Relatively Robust Representations). Gram-Schmidt */ |
| 15842 |
/* orthogonalization is avoided as far as possible. More specifically, */ |
| 15843 |
/* the various steps of the algorithm are as follows. */ |
| 15844 |
|
| 15845 |
/* For each unreduced block (submatrix) of T, */ |
| 15846 |
/* (a) Compute T - sigma I = L D L^T, so that L and D */ |
| 15847 |
/* define all the wanted eigenvalues to high relative accuracy. */ |
| 15848 |
/* This means that small relative changes in the entries of D and L */ |
| 15849 |
/* cause only small relative changes in the eigenvalues and */ |
| 15850 |
/* eigenvectors. The standard (unfactored) representation of the */ |
| 15851 |
/* tridiagonal matrix T does not have this property in general. */ |
| 15852 |
/* (b) Compute the eigenvalues to suitable accuracy. */ |
| 15853 |
/* If the eigenvectors are desired, the algorithm attains full */ |
| 15854 |
/* accuracy of the computed eigenvalues only right before */ |
| 15855 |
/* the corresponding vectors have to be computed, see steps c) and d). */ |
| 15856 |
/* (c) For each cluster of close eigenvalues, select a new */ |
| 15857 |
/* shift close to the cluster, find a new factorization, and refine */ |
| 15858 |
/* the shifted eigenvalues to suitable accuracy. */ |
| 15859 |
/* (d) For each eigenvalue with a large enough relative separation compute */ |
| 15860 |
/* the corresponding eigenvector by forming a rank revealing twisted */ |
| 15861 |
/* factorization. Go back to (c) for any clusters that remain. */ |
| 15862 |
|
| 15863 |
/* The desired accuracy of the output can be specified by the input */ |
| 15864 |
/* parameter ABSTOL. */ |
| 15865 |
|
| 15866 |
/* For more details, see DSTEMR's documentation and: */ |
| 15867 |
/* - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */ |
| 15868 |
/* to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */ |
| 15869 |
/* Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */ |
| 15870 |
/* - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */ |
| 15871 |
/* Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */ |
| 15872 |
/* 2004. Also LAPACK Working Note 154. */ |
| 15873 |
/* - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */ |
| 15874 |
/* tridiagonal eigenvalue/eigenvector problem", */ |
| 15875 |
/* Computer Science Division Technical Report No. UCB/CSD-97-971, */ |
| 15876 |
/* UC Berkeley, May 1997. */ |
| 15877 |
|
| 15878 |
|
| 15879 |
/* Note 1 : DSYEVR calls DSTEMR when the full spectrum is requested */ |
| 15880 |
/* on machines which conform to the ieee-754 floating point standard. */ |
| 15881 |
/* DSYEVR calls DSTEBZ and SSTEIN on non-ieee machines and */ |
| 15882 |
/* when partial spectrum requests are made. */ |
| 15883 |
|
| 15884 |
/* Normal execution of DSTEMR may create NaNs and infinities and */ |
| 15885 |
/* hence may abort due to a floating point exception in environments */ |
| 15886 |
/* which do not handle NaNs and infinities in the ieee standard default */ |
| 15887 |
/* manner. */ |
| 15888 |
|
| 15889 |
/* Arguments */ |
| 15890 |
/* ========= */ |
| 15891 |
|
| 15892 |
/* JOBZ (input) CHARACTER*1 */ |
| 15893 |
/* = 'N': Compute eigenvalues only; */ |
| 15894 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 15895 |
|
| 15896 |
/* RANGE (input) CHARACTER*1 */ |
| 15897 |
/* = 'A': all eigenvalues will be found. */ |
| 15898 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 15899 |
/* will be found. */ |
| 15900 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 15901 |
/* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and */ |
| 15902 |
/* ********* DSTEIN are called */ |
| 15903 |
|
| 15904 |
/* UPLO (input) CHARACTER*1 */ |
| 15905 |
/* = 'U': Upper triangle of A is stored; */ |
| 15906 |
/* = 'L': Lower triangle of A is stored. */ |
| 15907 |
|
| 15908 |
/* N (input) INTEGER */ |
| 15909 |
/* The order of the matrix A. N >= 0. */ |
| 15910 |
|
| 15911 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */ |
| 15912 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the */ |
| 15913 |
/* leading N-by-N upper triangular part of A contains the */ |
| 15914 |
/* upper triangular part of the matrix A. If UPLO = 'L', */ |
| 15915 |
/* the leading N-by-N lower triangular part of A contains */ |
| 15916 |
/* the lower triangular part of the matrix A. */ |
| 15917 |
/* On exit, the lower triangle (if UPLO='L') or the upper */ |
| 15918 |
/* triangle (if UPLO='U') of A, including the diagonal, is */ |
| 15919 |
/* destroyed. */ |
| 15920 |
|
| 15921 |
/* LDA (input) INTEGER */ |
| 15922 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 15923 |
|
| 15924 |
/* VL (input) DOUBLE PRECISION */ |
| 15925 |
/* VU (input) DOUBLE PRECISION */ |
| 15926 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 15927 |
/* be searched for eigenvalues. VL < VU. */ |
| 15928 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 15929 |
|
| 15930 |
/* IL (input) INTEGER */ |
| 15931 |
/* IU (input) INTEGER */ |
| 15932 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 15933 |
/* smallest and largest eigenvalues to be returned. */ |
| 15934 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 15935 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 15936 |
|
| 15937 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 15938 |
/* The absolute error tolerance for the eigenvalues. */ |
| 15939 |
/* An approximate eigenvalue is accepted as converged */ |
| 15940 |
/* when it is determined to lie in an interval [a,b] */ |
| 15941 |
/* of width less than or equal to */ |
| 15942 |
|
| 15943 |
/* ABSTOL + EPS * max( |a|,|b| ) , */ |
| 15944 |
|
| 15945 |
/* where EPS is the machine precision. If ABSTOL is less than */ |
| 15946 |
/* or equal to zero, then EPS*|T| will be used in its place, */ |
| 15947 |
/* where |T| is the 1-norm of the tridiagonal matrix obtained */ |
| 15948 |
/* by reducing A to tridiagonal form. */ |
| 15949 |
|
| 15950 |
/* See "Computing Small Singular Values of Bidiagonal Matrices */ |
| 15951 |
/* with Guaranteed High Relative Accuracy," by Demmel and */ |
| 15952 |
/* Kahan, LAPACK Working Note #3. */ |
| 15953 |
|
| 15954 |
/* If high relative accuracy is important, set ABSTOL to */ |
| 15955 |
/* DLAMCH( 'Safe minimum' ). Doing so will guarantee that */ |
| 15956 |
/* eigenvalues are computed to high relative accuracy when */ |
| 15957 |
/* possible in future releases. The current code does not */ |
| 15958 |
/* make any guarantees about high relative accuracy, but */ |
| 15959 |
/* future releases will. See J. Barlow and J. Demmel, */ |
| 15960 |
/* "Computing Accurate Eigensystems of Scaled Diagonally */ |
| 15961 |
/* Dominant Matrices", LAPACK Working Note #7, for a discussion */ |
| 15962 |
/* of which matrices define their eigenvalues to high relative */ |
| 15963 |
/* accuracy. */ |
| 15964 |
|
| 15965 |
/* M (output) INTEGER */ |
| 15966 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 15967 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 15968 |
|
| 15969 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 15970 |
/* The first M elements contain the selected eigenvalues in */ |
| 15971 |
/* ascending order. */ |
| 15972 |
|
| 15973 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */ |
| 15974 |
/* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ |
| 15975 |
/* contain the orthonormal eigenvectors of the matrix A */ |
| 15976 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 15977 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 15978 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 15979 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 15980 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 15981 |
/* is not known in advance and an upper bound must be used. */ |
| 15982 |
/* Supplying N columns is always safe. */ |
| 15983 |
|
| 15984 |
/* LDZ (input) INTEGER */ |
| 15985 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 15986 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 15987 |
|
| 15988 |
/* ISUPPZ (output) INTEGER array, dimension ( 2*max(1,M) ) */ |
| 15989 |
/* The support of the eigenvectors in Z, i.e., the indices */ |
| 15990 |
/* indicating the nonzero elements in Z. The i-th eigenvector */ |
| 15991 |
/* is nonzero only in elements ISUPPZ( 2*i-1 ) through */ |
| 15992 |
/* ISUPPZ( 2*i ). */ |
| 15993 |
/* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */ |
| 15994 |
|
| 15995 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 15996 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 15997 |
|
| 15998 |
/* LWORK (input) INTEGER */ |
| 15999 |
/* The dimension of the array WORK. LWORK >= max(1,26*N). */ |
| 16000 |
/* For optimal efficiency, LWORK >= (NB+6)*N, */ |
| 16001 |
/* where NB is the max of the blocksize for DSYTRD and DORMTR */ |
| 16002 |
/* returned by ILAENV. */ |
| 16003 |
|
| 16004 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 16005 |
/* only calculates the optimal size of the WORK array, returns */ |
| 16006 |
/* this value as the first entry of the WORK array, and no error */ |
| 16007 |
/* message related to LWORK is issued by XERBLA. */ |
| 16008 |
|
| 16009 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 16010 |
/* On exit, if INFO = 0, IWORK(1) returns the optimal LWORK. */ |
| 16011 |
|
| 16012 |
/* LIWORK (input) INTEGER */ |
| 16013 |
/* The dimension of the array IWORK. LIWORK >= max(1,10*N). */ |
| 16014 |
|
| 16015 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 16016 |
/* routine only calculates the optimal size of the IWORK array, */ |
| 16017 |
/* returns this value as the first entry of the IWORK array, and */ |
| 16018 |
/* no error message related to LIWORK is issued by XERBLA. */ |
| 16019 |
|
| 16020 |
/* INFO (output) INTEGER */ |
| 16021 |
/* = 0: successful exit */ |
| 16022 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 16023 |
/* > 0: Internal error */ |
| 16024 |
|
| 16025 |
/* Further Details */ |
| 16026 |
/* =============== */ |
| 16027 |
|
| 16028 |
/* Based on contributions by */ |
| 16029 |
/* Inderjit Dhillon, IBM Almaden, USA */ |
| 16030 |
/* Osni Marques, LBNL/NERSC, USA */ |
| 16031 |
/* Ken Stanley, Computer Science Division, University of */ |
| 16032 |
/* California at Berkeley, USA */ |
| 16033 |
/* Jason Riedy, Computer Science Division, University of */ |
| 16034 |
/* California at Berkeley, USA */ |
| 16035 |
|
| 16036 |
/* ===================================================================== */ |
| 16037 |
|
| 16038 |
/* .. Parameters .. */ |
| 16039 |
/* .. */ |
| 16040 |
/* .. Local Scalars .. */ |
| 16041 |
/* .. */ |
| 16042 |
/* .. External Functions .. */ |
| 16043 |
/* .. */ |
| 16044 |
/* .. External Subroutines .. */ |
| 16045 |
/* .. */ |
| 16046 |
/* .. Intrinsic Functions .. */ |
| 16047 |
/* .. */ |
| 16048 |
/* .. Executable Statements .. */ |
| 16049 |
|
| 16050 |
/* Test the input parameters. */ |
| 16051 |
|
| 16052 |
/* Parameter adjustments */ |
| 16053 |
a_dim1 = *lda; |
| 16054 |
a_offset = 1 + a_dim1; |
| 16055 |
a -= a_offset; |
| 16056 |
--w; |
| 16057 |
z_dim1 = *ldz; |
| 16058 |
z_offset = 1 + z_dim1; |
| 16059 |
z__ -= z_offset; |
| 16060 |
--isuppz; |
| 16061 |
--work; |
| 16062 |
--iwork; |
| 16063 |
|
| 16064 |
/* Function Body */ |
| 16065 |
ieeeok = ilaenv_(&c__10, "DSYEVR", "N", &c__1, &c__2, &c__3, &c__4); |
| 16066 |
|
| 16067 |
lower = lsame_(uplo, "L"); |
| 16068 |
wantz = lsame_(jobz, "V"); |
| 16069 |
alleig = lsame_(range, "A"); |
| 16070 |
valeig = lsame_(range, "V"); |
| 16071 |
indeig = lsame_(range, "I"); |
| 16072 |
|
| 16073 |
lquery = *lwork == -1 || *liwork == -1; |
| 16074 |
|
| 16075 |
/* Computing MAX */ |
| 16076 |
i__1 = 1, i__2 = *n * 26; |
| 16077 |
lwmin = std::max(i__1,i__2); |
| 16078 |
/* Computing MAX */ |
| 16079 |
i__1 = 1, i__2 = *n * 10; |
| 16080 |
liwmin = std::max(i__1,i__2); |
| 16081 |
|
| 16082 |
*info = 0; |
| 16083 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 16084 |
*info = -1; |
| 16085 |
} else if (! (alleig || valeig || indeig)) { |
| 16086 |
*info = -2; |
| 16087 |
} else if (! (lower || lsame_(uplo, "U"))) { |
| 16088 |
*info = -3; |
| 16089 |
} else if (*n < 0) { |
| 16090 |
*info = -4; |
| 16091 |
} else if (*lda < std::max(1_integer,*n)) { |
| 16092 |
*info = -6; |
| 16093 |
} else { |
| 16094 |
if (valeig) { |
| 16095 |
if (*n > 0 && *vu <= *vl) { |
| 16096 |
*info = -8; |
| 16097 |
} |
| 16098 |
} else if (indeig) { |
| 16099 |
if (*il < 1 || *il > std::max(1_integer,*n)) { |
| 16100 |
*info = -9; |
| 16101 |
} else if (*iu < std::min(*n,*il) || *iu > *n) { |
| 16102 |
*info = -10; |
| 16103 |
} |
| 16104 |
} |
| 16105 |
} |
| 16106 |
if (*info == 0) { |
| 16107 |
if (*ldz < 1 || wantz && *ldz < *n) { |
| 16108 |
*info = -15; |
| 16109 |
} else if (*lwork < lwmin && ! lquery) { |
| 16110 |
*info = -18; |
| 16111 |
} else if (*liwork < liwmin && ! lquery) { |
| 16112 |
*info = -20; |
| 16113 |
} |
| 16114 |
} |
| 16115 |
|
| 16116 |
if (*info == 0) { |
| 16117 |
nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1); |
| 16118 |
/* Computing MAX */ |
| 16119 |
i__1 = nb, i__2 = ilaenv_(&c__1, "DORMTR", uplo, n, &c_n1, &c_n1, & |
| 16120 |
c_n1); |
| 16121 |
nb = std::max(i__1,i__2); |
| 16122 |
/* Computing MAX */ |
| 16123 |
i__1 = (nb + 1) * *n; |
| 16124 |
lwkopt = std::max(i__1,lwmin); |
| 16125 |
work[1] = (double) lwkopt; |
| 16126 |
iwork[1] = liwmin; |
| 16127 |
} |
| 16128 |
|
| 16129 |
if (*info != 0) { |
| 16130 |
i__1 = -(*info); |
| 16131 |
xerbla_("DSYEVR", &i__1); |
| 16132 |
return 0; |
| 16133 |
} else if (lquery) { |
| 16134 |
return 0; |
| 16135 |
} |
| 16136 |
|
| 16137 |
/* Quick return if possible */ |
| 16138 |
|
| 16139 |
*m = 0; |
| 16140 |
if (*n == 0) { |
| 16141 |
work[1] = 1.; |
| 16142 |
return 0; |
| 16143 |
} |
| 16144 |
|
| 16145 |
if (*n == 1) { |
| 16146 |
work[1] = 7.; |
| 16147 |
if (alleig || indeig) { |
| 16148 |
*m = 1; |
| 16149 |
w[1] = a[a_dim1 + 1]; |
| 16150 |
} else { |
| 16151 |
if (*vl < a[a_dim1 + 1] && *vu >= a[a_dim1 + 1]) { |
| 16152 |
*m = 1; |
| 16153 |
w[1] = a[a_dim1 + 1]; |
| 16154 |
} |
| 16155 |
} |
| 16156 |
if (wantz) { |
| 16157 |
z__[z_dim1 + 1] = 1.; |
| 16158 |
} |
| 16159 |
return 0; |
| 16160 |
} |
| 16161 |
|
| 16162 |
/* Get machine constants. */ |
| 16163 |
|
| 16164 |
safmin = dlamch_("Safe minimum"); |
| 16165 |
eps = dlamch_("Precision"); |
| 16166 |
smlnum = safmin / eps; |
| 16167 |
bignum = 1. / smlnum; |
| 16168 |
rmin = sqrt(smlnum); |
| 16169 |
/* Computing MIN */ |
| 16170 |
d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin)); |
| 16171 |
rmax = std::min(d__1,d__2); |
| 16172 |
|
| 16173 |
/* Scale matrix to allowable range, if necessary. */ |
| 16174 |
|
| 16175 |
iscale = 0; |
| 16176 |
abstll = *abstol; |
| 16177 |
vll = *vl; |
| 16178 |
vuu = *vu; |
| 16179 |
anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]); |
| 16180 |
if (anrm > 0. && anrm < rmin) { |
| 16181 |
iscale = 1; |
| 16182 |
sigma = rmin / anrm; |
| 16183 |
} else if (anrm > rmax) { |
| 16184 |
iscale = 1; |
| 16185 |
sigma = rmax / anrm; |
| 16186 |
} |
| 16187 |
if (iscale == 1) { |
| 16188 |
if (lower) { |
| 16189 |
i__1 = *n; |
| 16190 |
for (j = 1; j <= i__1; ++j) { |
| 16191 |
i__2 = *n - j + 1; |
| 16192 |
dscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1); |
| 16193 |
/* L10: */ |
| 16194 |
} |
| 16195 |
} else { |
| 16196 |
i__1 = *n; |
| 16197 |
for (j = 1; j <= i__1; ++j) { |
| 16198 |
dscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1); |
| 16199 |
/* L20: */ |
| 16200 |
} |
| 16201 |
} |
| 16202 |
if (*abstol > 0.) { |
| 16203 |
abstll = *abstol * sigma; |
| 16204 |
} |
| 16205 |
if (valeig) { |
| 16206 |
vll = *vl * sigma; |
| 16207 |
vuu = *vu * sigma; |
| 16208 |
} |
| 16209 |
} |
| 16210 |
/* Initialize indices into workspaces. Note: The IWORK indices are */ |
| 16211 |
/* used only if DSTERF or DSTEMR fail. */ |
| 16212 |
/* WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the */ |
| 16213 |
/* elementary reflectors used in DSYTRD. */ |
| 16214 |
indtau = 1; |
| 16215 |
/* WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries. */ |
| 16216 |
indd = indtau + *n; |
| 16217 |
/* WORK(INDE:INDE+N-1) stores the off-diagonal entries of the */ |
| 16218 |
/* tridiagonal matrix from DSYTRD. */ |
| 16219 |
inde = indd + *n; |
| 16220 |
/* WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over */ |
| 16221 |
/* -written by DSTEMR (the DSTERF path copies the diagonal to W). */ |
| 16222 |
inddd = inde + *n; |
| 16223 |
/* WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over */ |
| 16224 |
/* -written while computing the eigenvalues in DSTERF and DSTEMR. */ |
| 16225 |
indee = inddd + *n; |
| 16226 |
/* INDWK is the starting offset of the left-over workspace, and */ |
| 16227 |
/* LLWORK is the remaining workspace size. */ |
| 16228 |
indwk = indee + *n; |
| 16229 |
llwork = *lwork - indwk + 1; |
| 16230 |
/* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and */ |
| 16231 |
/* stores the block indices of each of the M<=N eigenvalues. */ |
| 16232 |
indibl = 1; |
| 16233 |
/* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and */ |
| 16234 |
/* stores the starting and finishing indices of each block. */ |
| 16235 |
indisp = indibl + *n; |
| 16236 |
/* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */ |
| 16237 |
/* that corresponding to eigenvectors that fail to converge in */ |
| 16238 |
/* DSTEIN. This information is discarded; if any fail, the driver */ |
| 16239 |
/* returns INFO > 0. */ |
| 16240 |
indifl = indisp + *n; |
| 16241 |
/* INDIWO is the offset of the remaining integer workspace. */ |
| 16242 |
indiwo = indisp + *n; |
| 16243 |
|
| 16244 |
/* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */ |
| 16245 |
|
| 16246 |
dsytrd_(uplo, n, &a[a_offset], lda, &work[indd], &work[inde], &work[ |
| 16247 |
indtau], &work[indwk], &llwork, &iinfo); |
| 16248 |
|
| 16249 |
/* If all eigenvalues are desired */ |
| 16250 |
/* then call DSTERF or DSTEMR and DORMTR. */ |
| 16251 |
|
| 16252 |
if ((alleig || indeig && *il == 1 && *iu == *n) && ieeeok == 1) { |
| 16253 |
if (! wantz) { |
| 16254 |
dcopy_(n, &work[indd], &c__1, &w[1], &c__1); |
| 16255 |
i__1 = *n - 1; |
| 16256 |
dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); |
| 16257 |
dsterf_(n, &w[1], &work[indee], info); |
| 16258 |
} else { |
| 16259 |
i__1 = *n - 1; |
| 16260 |
dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); |
| 16261 |
dcopy_(n, &work[indd], &c__1, &work[inddd], &c__1); |
| 16262 |
|
| 16263 |
if (*abstol <= *n * 0. * eps) { |
| 16264 |
tryrac = true; |
| 16265 |
} else { |
| 16266 |
tryrac = false; |
| 16267 |
} |
| 16268 |
dstemr_(jobz, "A", n, &work[inddd], &work[indee], vl, vu, il, iu, |
| 16269 |
m, &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, & |
| 16270 |
work[indwk], lwork, &iwork[1], liwork, info); |
| 16271 |
|
| 16272 |
|
| 16273 |
|
| 16274 |
/* Apply orthogonal matrix used in reduction to tridiagonal */ |
| 16275 |
/* form to eigenvectors returned by DSTEIN. */ |
| 16276 |
|
| 16277 |
if (wantz && *info == 0) { |
| 16278 |
indwkn = inde; |
| 16279 |
llwrkn = *lwork - indwkn + 1; |
| 16280 |
dormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau] |
| 16281 |
, &z__[z_offset], ldz, &work[indwkn], &llwrkn, &iinfo); |
| 16282 |
} |
| 16283 |
} |
| 16284 |
|
| 16285 |
|
| 16286 |
if (*info == 0) { |
| 16287 |
/* Everything worked. Skip DSTEBZ/DSTEIN. IWORK(:) are */ |
| 16288 |
/* undefined. */ |
| 16289 |
*m = *n; |
| 16290 |
goto L30; |
| 16291 |
} |
| 16292 |
*info = 0; |
| 16293 |
} |
| 16294 |
|
| 16295 |
/* Otherwise, call DSTEBZ and, if eigenvectors are desired, DSTEIN. */ |
| 16296 |
/* Also call DSTEBZ and DSTEIN if DSTEMR fails. */ |
| 16297 |
|
| 16298 |
if (wantz) { |
| 16299 |
*(unsigned char *)order = 'B'; |
| 16300 |
} else { |
| 16301 |
*(unsigned char *)order = 'E'; |
| 16302 |
} |
| 16303 |
dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[ |
| 16304 |
inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[ |
| 16305 |
indwk], &iwork[indiwo], info); |
| 16306 |
|
| 16307 |
if (wantz) { |
| 16308 |
dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[ |
| 16309 |
indisp], &z__[z_offset], ldz, &work[indwk], &iwork[indiwo], & |
| 16310 |
iwork[indifl], info); |
| 16311 |
|
| 16312 |
/* Apply orthogonal matrix used in reduction to tridiagonal */ |
| 16313 |
/* form to eigenvectors returned by DSTEIN. */ |
| 16314 |
|
| 16315 |
indwkn = inde; |
| 16316 |
llwrkn = *lwork - indwkn + 1; |
| 16317 |
dormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[ |
| 16318 |
z_offset], ldz, &work[indwkn], &llwrkn, &iinfo); |
| 16319 |
} |
| 16320 |
|
| 16321 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 16322 |
|
| 16323 |
/* Jump here if DSTEMR/DSTEIN succeeded. */ |
| 16324 |
L30: |
| 16325 |
if (iscale == 1) { |
| 16326 |
if (*info == 0) { |
| 16327 |
imax = *m; |
| 16328 |
} else { |
| 16329 |
imax = *info - 1; |
| 16330 |
} |
| 16331 |
d__1 = 1. / sigma; |
| 16332 |
dscal_(&imax, &d__1, &w[1], &c__1); |
| 16333 |
} |
| 16334 |
|
| 16335 |
/* If eigenvalues are not in order, then sort them, along with */ |
| 16336 |
/* eigenvectors. Note: We do not sort the IFAIL portion of IWORK. */ |
| 16337 |
/* It may not be initialized (if DSTEMR/DSTEIN succeeded), and we do */ |
| 16338 |
/* not return this detailed information to the user. */ |
| 16339 |
|
| 16340 |
if (wantz) { |
| 16341 |
i__1 = *m - 1; |
| 16342 |
for (j = 1; j <= i__1; ++j) { |
| 16343 |
i__ = 0; |
| 16344 |
tmp1 = w[j]; |
| 16345 |
i__2 = *m; |
| 16346 |
for (jj = j + 1; jj <= i__2; ++jj) { |
| 16347 |
if (w[jj] < tmp1) { |
| 16348 |
i__ = jj; |
| 16349 |
tmp1 = w[jj]; |
| 16350 |
} |
| 16351 |
/* L40: */ |
| 16352 |
} |
| 16353 |
|
| 16354 |
if (i__ != 0) { |
| 16355 |
w[i__] = w[j]; |
| 16356 |
w[j] = tmp1; |
| 16357 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], |
| 16358 |
&c__1); |
| 16359 |
} |
| 16360 |
/* L50: */ |
| 16361 |
} |
| 16362 |
} |
| 16363 |
|
| 16364 |
/* Set WORK(1) to optimal workspace size. */ |
| 16365 |
|
| 16366 |
work[1] = (double) lwkopt; |
| 16367 |
iwork[1] = liwmin; |
| 16368 |
|
| 16369 |
return 0; |
| 16370 |
|
| 16371 |
/* End of DSYEVR */ |
| 16372 |
|
| 16373 |
} /* dsyevr_ */ |
| 16374 |
|
| 16375 |
/* Subroutine */ int dsyevx_(const char *jobz, const char *range, const char *uplo, integer *n, |
| 16376 |
double *a, integer *lda, double *vl, double *vu, integer * |
| 16377 |
il, integer *iu, double *abstol, integer *m, double *w, |
| 16378 |
double *z__, integer *ldz, double *work, integer *lwork, |
| 16379 |
integer *iwork, integer *ifail, integer *info) |
| 16380 |
{ |
| 16381 |
/* Table of constant values */ |
| 16382 |
static integer c__1 = 1; |
| 16383 |
static integer c_n1 = -1; |
| 16384 |
|
| 16385 |
/* System generated locals */ |
| 16386 |
integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2; |
| 16387 |
double d__1, d__2; |
| 16388 |
|
| 16389 |
/* Local variables */ |
| 16390 |
integer i__, j, nb, jj; |
| 16391 |
double eps, vll, vuu, tmp1; |
| 16392 |
integer indd, inde; |
| 16393 |
double anrm; |
| 16394 |
integer imax; |
| 16395 |
double rmin, rmax; |
| 16396 |
bool test; |
| 16397 |
integer itmp1, indee; |
| 16398 |
double sigma; |
| 16399 |
integer iinfo; |
| 16400 |
char order[1]; |
| 16401 |
bool lower, wantz; |
| 16402 |
bool alleig, indeig; |
| 16403 |
integer iscale, indibl; |
| 16404 |
bool valeig; |
| 16405 |
double safmin; |
| 16406 |
double abstll, bignum; |
| 16407 |
integer indtau, indisp; |
| 16408 |
integer indiwo, indwkn; |
| 16409 |
integer indwrk, lwkmin; |
| 16410 |
integer llwrkn, llwork, nsplit; |
| 16411 |
double smlnum; |
| 16412 |
integer lwkopt; |
| 16413 |
bool lquery; |
| 16414 |
|
| 16415 |
|
| 16416 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 16417 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 16418 |
/* November 2006 */ |
| 16419 |
|
| 16420 |
/* .. Scalar Arguments .. */ |
| 16421 |
/* .. */ |
| 16422 |
/* .. Array Arguments .. */ |
| 16423 |
/* .. */ |
| 16424 |
|
| 16425 |
/* Purpose */ |
| 16426 |
/* ======= */ |
| 16427 |
|
| 16428 |
/* DSYEVX computes selected eigenvalues and, optionally, eigenvectors */ |
| 16429 |
/* of a real symmetric matrix A. Eigenvalues and eigenvectors can be */ |
| 16430 |
/* selected by specifying either a range of values or a range of indices */ |
| 16431 |
/* for the desired eigenvalues. */ |
| 16432 |
|
| 16433 |
/* Arguments */ |
| 16434 |
/* ========= */ |
| 16435 |
|
| 16436 |
/* JOBZ (input) CHARACTER*1 */ |
| 16437 |
/* = 'N': Compute eigenvalues only; */ |
| 16438 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 16439 |
|
| 16440 |
/* RANGE (input) CHARACTER*1 */ |
| 16441 |
/* = 'A': all eigenvalues will be found. */ |
| 16442 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 16443 |
/* will be found. */ |
| 16444 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 16445 |
|
| 16446 |
/* UPLO (input) CHARACTER*1 */ |
| 16447 |
/* = 'U': Upper triangle of A is stored; */ |
| 16448 |
/* = 'L': Lower triangle of A is stored. */ |
| 16449 |
|
| 16450 |
/* N (input) INTEGER */ |
| 16451 |
/* The order of the matrix A. N >= 0. */ |
| 16452 |
|
| 16453 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */ |
| 16454 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the */ |
| 16455 |
/* leading N-by-N upper triangular part of A contains the */ |
| 16456 |
/* upper triangular part of the matrix A. If UPLO = 'L', */ |
| 16457 |
/* the leading N-by-N lower triangular part of A contains */ |
| 16458 |
/* the lower triangular part of the matrix A. */ |
| 16459 |
/* On exit, the lower triangle (if UPLO='L') or the upper */ |
| 16460 |
/* triangle (if UPLO='U') of A, including the diagonal, is */ |
| 16461 |
/* destroyed. */ |
| 16462 |
|
| 16463 |
/* LDA (input) INTEGER */ |
| 16464 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 16465 |
|
| 16466 |
/* VL (input) DOUBLE PRECISION */ |
| 16467 |
/* VU (input) DOUBLE PRECISION */ |
| 16468 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 16469 |
/* be searched for eigenvalues. VL < VU. */ |
| 16470 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 16471 |
|
| 16472 |
/* IL (input) INTEGER */ |
| 16473 |
/* IU (input) INTEGER */ |
| 16474 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 16475 |
/* smallest and largest eigenvalues to be returned. */ |
| 16476 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 16477 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 16478 |
|
| 16479 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 16480 |
/* The absolute error tolerance for the eigenvalues. */ |
| 16481 |
/* An approximate eigenvalue is accepted as converged */ |
| 16482 |
/* when it is determined to lie in an interval [a,b] */ |
| 16483 |
/* of width less than or equal to */ |
| 16484 |
|
| 16485 |
/* ABSTOL + EPS * max( |a|,|b| ) , */ |
| 16486 |
|
| 16487 |
/* where EPS is the machine precision. If ABSTOL is less than */ |
| 16488 |
/* or equal to zero, then EPS*|T| will be used in its place, */ |
| 16489 |
/* where |T| is the 1-norm of the tridiagonal matrix obtained */ |
| 16490 |
/* by reducing A to tridiagonal form. */ |
| 16491 |
|
| 16492 |
/* Eigenvalues will be computed most accurately when ABSTOL is */ |
| 16493 |
/* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */ |
| 16494 |
/* If this routine returns with INFO>0, indicating that some */ |
| 16495 |
/* eigenvectors did not converge, try setting ABSTOL to */ |
| 16496 |
/* 2*DLAMCH('S'). */ |
| 16497 |
|
| 16498 |
/* See "Computing Small Singular Values of Bidiagonal Matrices */ |
| 16499 |
/* with Guaranteed High Relative Accuracy," by Demmel and */ |
| 16500 |
/* Kahan, LAPACK Working Note #3. */ |
| 16501 |
|
| 16502 |
/* M (output) INTEGER */ |
| 16503 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 16504 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 16505 |
|
| 16506 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 16507 |
/* On normal exit, the first M elements contain the selected */ |
| 16508 |
/* eigenvalues in ascending order. */ |
| 16509 |
|
| 16510 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */ |
| 16511 |
/* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ |
| 16512 |
/* contain the orthonormal eigenvectors of the matrix A */ |
| 16513 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 16514 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 16515 |
/* If an eigenvector fails to converge, then that column of Z */ |
| 16516 |
/* contains the latest approximation to the eigenvector, and the */ |
| 16517 |
/* index of the eigenvector is returned in IFAIL. */ |
| 16518 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 16519 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 16520 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 16521 |
/* is not known in advance and an upper bound must be used. */ |
| 16522 |
|
| 16523 |
/* LDZ (input) INTEGER */ |
| 16524 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 16525 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 16526 |
|
| 16527 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 16528 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 16529 |
|
| 16530 |
/* LWORK (input) INTEGER */ |
| 16531 |
/* The length of the array WORK. LWORK >= 1, when N <= 1; */ |
| 16532 |
/* otherwise 8*N. */ |
| 16533 |
/* For optimal efficiency, LWORK >= (NB+3)*N, */ |
| 16534 |
/* where NB is the max of the blocksize for DSYTRD and DORMTR */ |
| 16535 |
/* returned by ILAENV. */ |
| 16536 |
|
| 16537 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 16538 |
/* only calculates the optimal size of the WORK array, returns */ |
| 16539 |
/* this value as the first entry of the WORK array, and no error */ |
| 16540 |
/* message related to LWORK is issued by XERBLA. */ |
| 16541 |
|
| 16542 |
/* IWORK (workspace) INTEGER array, dimension (5*N) */ |
| 16543 |
|
| 16544 |
/* IFAIL (output) INTEGER array, dimension (N) */ |
| 16545 |
/* If JOBZ = 'V', then if INFO = 0, the first M elements of */ |
| 16546 |
/* IFAIL are zero. If INFO > 0, then IFAIL contains the */ |
| 16547 |
/* indices of the eigenvectors that failed to converge. */ |
| 16548 |
/* If JOBZ = 'N', then IFAIL is not referenced. */ |
| 16549 |
|
| 16550 |
/* INFO (output) INTEGER */ |
| 16551 |
/* = 0: successful exit */ |
| 16552 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 16553 |
/* > 0: if INFO = i, then i eigenvectors failed to converge. */ |
| 16554 |
/* Their indices are stored in array IFAIL. */ |
| 16555 |
|
| 16556 |
/* ===================================================================== */ |
| 16557 |
|
| 16558 |
/* .. Parameters .. */ |
| 16559 |
/* .. */ |
| 16560 |
/* .. Local Scalars .. */ |
| 16561 |
/* .. */ |
| 16562 |
/* .. External Functions .. */ |
| 16563 |
/* .. */ |
| 16564 |
/* .. External Subroutines .. */ |
| 16565 |
/* .. */ |
| 16566 |
/* .. Intrinsic Functions .. */ |
| 16567 |
/* .. */ |
| 16568 |
/* .. Executable Statements .. */ |
| 16569 |
|
| 16570 |
/* Test the input parameters. */ |
| 16571 |
|
| 16572 |
/* Parameter adjustments */ |
| 16573 |
a_dim1 = *lda; |
| 16574 |
a_offset = 1 + a_dim1; |
| 16575 |
a -= a_offset; |
| 16576 |
--w; |
| 16577 |
z_dim1 = *ldz; |
| 16578 |
z_offset = 1 + z_dim1; |
| 16579 |
z__ -= z_offset; |
| 16580 |
--work; |
| 16581 |
--iwork; |
| 16582 |
--ifail; |
| 16583 |
|
| 16584 |
/* Function Body */ |
| 16585 |
lower = lsame_(uplo, "L"); |
| 16586 |
wantz = lsame_(jobz, "V"); |
| 16587 |
alleig = lsame_(range, "A"); |
| 16588 |
valeig = lsame_(range, "V"); |
| 16589 |
indeig = lsame_(range, "I"); |
| 16590 |
lquery = *lwork == -1; |
| 16591 |
|
| 16592 |
*info = 0; |
| 16593 |
if (! (wantz || lsame_(jobz, "N"))) { |
| 16594 |
*info = -1; |
| 16595 |
} else if (! (alleig || valeig || indeig)) { |
| 16596 |
*info = -2; |
| 16597 |
} else if (! (lower || lsame_(uplo, "U"))) { |
| 16598 |
*info = -3; |
| 16599 |
} else if (*n < 0) { |
| 16600 |
*info = -4; |
| 16601 |
} else if (*lda < std::max(1_integer,*n)) { |
| 16602 |
*info = -6; |
| 16603 |
} else { |
| 16604 |
if (valeig) { |
| 16605 |
if (*n > 0 && *vu <= *vl) { |
| 16606 |
*info = -8; |
| 16607 |
} |
| 16608 |
} else if (indeig) { |
| 16609 |
if (*il < 1 || *il > std::max(1_integer,*n)) { |
| 16610 |
*info = -9; |
| 16611 |
} else if (*iu < std::min(*n,*il) || *iu > *n) { |
| 16612 |
*info = -10; |
| 16613 |
} |
| 16614 |
} |
| 16615 |
} |
| 16616 |
if (*info == 0) { |
| 16617 |
if (*ldz < 1 || wantz && *ldz < *n) { |
| 16618 |
*info = -15; |
| 16619 |
} |
| 16620 |
} |
| 16621 |
|
| 16622 |
if (*info == 0) { |
| 16623 |
if (*n <= 1) { |
| 16624 |
lwkmin = 1; |
| 16625 |
work[1] = (double) lwkmin; |
| 16626 |
} else { |
| 16627 |
lwkmin = *n << 3; |
| 16628 |
nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1); |
| 16629 |
/* Computing MAX */ |
| 16630 |
i__1 = nb, i__2 = ilaenv_(&c__1, "DORMTR", uplo, n, &c_n1, &c_n1, |
| 16631 |
&c_n1); |
| 16632 |
nb = std::max(i__1,i__2); |
| 16633 |
/* Computing MAX */ |
| 16634 |
i__1 = lwkmin, i__2 = (nb + 3) * *n; |
| 16635 |
lwkopt = std::max(i__1,i__2); |
| 16636 |
work[1] = (double) lwkopt; |
| 16637 |
} |
| 16638 |
|
| 16639 |
if (*lwork < lwkmin && ! lquery) { |
| 16640 |
*info = -17; |
| 16641 |
} |
| 16642 |
} |
| 16643 |
|
| 16644 |
if (*info != 0) { |
| 16645 |
i__1 = -(*info); |
| 16646 |
xerbla_("DSYEVX", &i__1); |
| 16647 |
return 0; |
| 16648 |
} else if (lquery) { |
| 16649 |
return 0; |
| 16650 |
} |
| 16651 |
|
| 16652 |
/* Quick return if possible */ |
| 16653 |
|
| 16654 |
*m = 0; |
| 16655 |
if (*n == 0) { |
| 16656 |
return 0; |
| 16657 |
} |
| 16658 |
|
| 16659 |
if (*n == 1) { |
| 16660 |
if (alleig || indeig) { |
| 16661 |
*m = 1; |
| 16662 |
w[1] = a[a_dim1 + 1]; |
| 16663 |
} else { |
| 16664 |
if (*vl < a[a_dim1 + 1] && *vu >= a[a_dim1 + 1]) { |
| 16665 |
*m = 1; |
| 16666 |
w[1] = a[a_dim1 + 1]; |
| 16667 |
} |
| 16668 |
} |
| 16669 |
if (wantz) { |
| 16670 |
z__[z_dim1 + 1] = 1.; |
| 16671 |
} |
| 16672 |
return 0; |
| 16673 |
} |
| 16674 |
|
| 16675 |
/* Get machine constants. */ |
| 16676 |
|
| 16677 |
safmin = dlamch_("Safe minimum"); |
| 16678 |
eps = dlamch_("Precision"); |
| 16679 |
smlnum = safmin / eps; |
| 16680 |
bignum = 1. / smlnum; |
| 16681 |
rmin = sqrt(smlnum); |
| 16682 |
/* Computing MIN */ |
| 16683 |
d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin)); |
| 16684 |
rmax = std::min(d__1,d__2); |
| 16685 |
|
| 16686 |
/* Scale matrix to allowable range, if necessary. */ |
| 16687 |
|
| 16688 |
iscale = 0; |
| 16689 |
abstll = *abstol; |
| 16690 |
if (valeig) { |
| 16691 |
vll = *vl; |
| 16692 |
vuu = *vu; |
| 16693 |
} |
| 16694 |
anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]); |
| 16695 |
if (anrm > 0. && anrm < rmin) { |
| 16696 |
iscale = 1; |
| 16697 |
sigma = rmin / anrm; |
| 16698 |
} else if (anrm > rmax) { |
| 16699 |
iscale = 1; |
| 16700 |
sigma = rmax / anrm; |
| 16701 |
} |
| 16702 |
if (iscale == 1) { |
| 16703 |
if (lower) { |
| 16704 |
i__1 = *n; |
| 16705 |
for (j = 1; j <= i__1; ++j) { |
| 16706 |
i__2 = *n - j + 1; |
| 16707 |
dscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1); |
| 16708 |
/* L10: */ |
| 16709 |
} |
| 16710 |
} else { |
| 16711 |
i__1 = *n; |
| 16712 |
for (j = 1; j <= i__1; ++j) { |
| 16713 |
dscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1); |
| 16714 |
/* L20: */ |
| 16715 |
} |
| 16716 |
} |
| 16717 |
if (*abstol > 0.) { |
| 16718 |
abstll = *abstol * sigma; |
| 16719 |
} |
| 16720 |
if (valeig) { |
| 16721 |
vll = *vl * sigma; |
| 16722 |
vuu = *vu * sigma; |
| 16723 |
} |
| 16724 |
} |
| 16725 |
|
| 16726 |
/* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */ |
| 16727 |
|
| 16728 |
indtau = 1; |
| 16729 |
inde = indtau + *n; |
| 16730 |
indd = inde + *n; |
| 16731 |
indwrk = indd + *n; |
| 16732 |
llwork = *lwork - indwrk + 1; |
| 16733 |
dsytrd_(uplo, n, &a[a_offset], lda, &work[indd], &work[inde], &work[ |
| 16734 |
indtau], &work[indwrk], &llwork, &iinfo); |
| 16735 |
|
| 16736 |
/* If all eigenvalues are desired and ABSTOL is less than or equal to */ |
| 16737 |
/* zero, then call DSTERF or DORGTR and SSTEQR. If this fails for */ |
| 16738 |
/* some eigenvalue, then try DSTEBZ. */ |
| 16739 |
|
| 16740 |
test = false; |
| 16741 |
if (indeig) { |
| 16742 |
if (*il == 1 && *iu == *n) { |
| 16743 |
test = true; |
| 16744 |
} |
| 16745 |
} |
| 16746 |
if ((alleig || test) && *abstol <= 0.) { |
| 16747 |
dcopy_(n, &work[indd], &c__1, &w[1], &c__1); |
| 16748 |
indee = indwrk + (*n << 1); |
| 16749 |
if (! wantz) { |
| 16750 |
i__1 = *n - 1; |
| 16751 |
dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); |
| 16752 |
dsterf_(n, &w[1], &work[indee], info); |
| 16753 |
} else { |
| 16754 |
dlacpy_("A", n, n, &a[a_offset], lda, &z__[z_offset], ldz); |
| 16755 |
dorgtr_(uplo, n, &z__[z_offset], ldz, &work[indtau], &work[indwrk] |
| 16756 |
, &llwork, &iinfo); |
| 16757 |
i__1 = *n - 1; |
| 16758 |
dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1); |
| 16759 |
dsteqr_(jobz, n, &w[1], &work[indee], &z__[z_offset], ldz, &work[ |
| 16760 |
indwrk], info); |
| 16761 |
if (*info == 0) { |
| 16762 |
i__1 = *n; |
| 16763 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 16764 |
ifail[i__] = 0; |
| 16765 |
/* L30: */ |
| 16766 |
} |
| 16767 |
} |
| 16768 |
} |
| 16769 |
if (*info == 0) { |
| 16770 |
*m = *n; |
| 16771 |
goto L40; |
| 16772 |
} |
| 16773 |
*info = 0; |
| 16774 |
} |
| 16775 |
|
| 16776 |
/* Otherwise, call DSTEBZ and, if eigenvectors are desired, SSTEIN. */ |
| 16777 |
|
| 16778 |
if (wantz) { |
| 16779 |
*(unsigned char *)order = 'B'; |
| 16780 |
} else { |
| 16781 |
*(unsigned char *)order = 'E'; |
| 16782 |
} |
| 16783 |
indibl = 1; |
| 16784 |
indisp = indibl + *n; |
| 16785 |
indiwo = indisp + *n; |
| 16786 |
dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[ |
| 16787 |
inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[ |
| 16788 |
indwrk], &iwork[indiwo], info); |
| 16789 |
|
| 16790 |
if (wantz) { |
| 16791 |
dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[ |
| 16792 |
indisp], &z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], & |
| 16793 |
ifail[1], info); |
| 16794 |
|
| 16795 |
/* Apply orthogonal matrix used in reduction to tridiagonal */ |
| 16796 |
/* form to eigenvectors returned by DSTEIN. */ |
| 16797 |
|
| 16798 |
indwkn = inde; |
| 16799 |
llwrkn = *lwork - indwkn + 1; |
| 16800 |
dormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[ |
| 16801 |
z_offset], ldz, &work[indwkn], &llwrkn, &iinfo); |
| 16802 |
} |
| 16803 |
|
| 16804 |
/* If matrix was scaled, then rescale eigenvalues appropriately. */ |
| 16805 |
|
| 16806 |
L40: |
| 16807 |
if (iscale == 1) { |
| 16808 |
if (*info == 0) { |
| 16809 |
imax = *m; |
| 16810 |
} else { |
| 16811 |
imax = *info - 1; |
| 16812 |
} |
| 16813 |
d__1 = 1. / sigma; |
| 16814 |
dscal_(&imax, &d__1, &w[1], &c__1); |
| 16815 |
} |
| 16816 |
|
| 16817 |
/* If eigenvalues are not in order, then sort them, along with */ |
| 16818 |
/* eigenvectors. */ |
| 16819 |
|
| 16820 |
if (wantz) { |
| 16821 |
i__1 = *m - 1; |
| 16822 |
for (j = 1; j <= i__1; ++j) { |
| 16823 |
i__ = 0; |
| 16824 |
tmp1 = w[j]; |
| 16825 |
i__2 = *m; |
| 16826 |
for (jj = j + 1; jj <= i__2; ++jj) { |
| 16827 |
if (w[jj] < tmp1) { |
| 16828 |
i__ = jj; |
| 16829 |
tmp1 = w[jj]; |
| 16830 |
} |
| 16831 |
/* L50: */ |
| 16832 |
} |
| 16833 |
|
| 16834 |
if (i__ != 0) { |
| 16835 |
itmp1 = iwork[indibl + i__ - 1]; |
| 16836 |
w[i__] = w[j]; |
| 16837 |
iwork[indibl + i__ - 1] = iwork[indibl + j - 1]; |
| 16838 |
w[j] = tmp1; |
| 16839 |
iwork[indibl + j - 1] = itmp1; |
| 16840 |
dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], |
| 16841 |
&c__1); |
| 16842 |
if (*info != 0) { |
| 16843 |
itmp1 = ifail[i__]; |
| 16844 |
ifail[i__] = ifail[j]; |
| 16845 |
ifail[j] = itmp1; |
| 16846 |
} |
| 16847 |
} |
| 16848 |
/* L60: */ |
| 16849 |
} |
| 16850 |
} |
| 16851 |
|
| 16852 |
/* Set WORK(1) to optimal workspace size. */ |
| 16853 |
|
| 16854 |
work[1] = (double) lwkopt; |
| 16855 |
|
| 16856 |
return 0; |
| 16857 |
|
| 16858 |
/* End of DSYEVX */ |
| 16859 |
|
| 16860 |
} /* dsyevx_ */ |
| 16861 |
|
| 16862 |
/* Subroutine */ int dsygs2_(integer *itype, const char *uplo, integer *n, |
| 16863 |
double *a, integer *lda, double *b, integer *ldb, integer * |
| 16864 |
info) |
| 16865 |
{ |
| 16866 |
/* Table of constant values */ |
| 16867 |
static double c_b6 = -1.; |
| 16868 |
static integer c__1 = 1; |
| 16869 |
static double c_b27 = 1.; |
| 16870 |
|
| 16871 |
/* System generated locals */ |
| 16872 |
integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2; |
| 16873 |
double d__1; |
| 16874 |
|
| 16875 |
/* Local variables */ |
| 16876 |
integer k; |
| 16877 |
double ct, akk, bkk; |
| 16878 |
bool upper; |
| 16879 |
|
| 16880 |
|
| 16881 |
/* -- LAPACK routine (version 3.1) -- */ |
| 16882 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 16883 |
/* November 2006 */ |
| 16884 |
|
| 16885 |
/* .. Scalar Arguments .. */ |
| 16886 |
/* .. */ |
| 16887 |
/* .. Array Arguments .. */ |
| 16888 |
/* .. */ |
| 16889 |
|
| 16890 |
/* Purpose */ |
| 16891 |
/* ======= */ |
| 16892 |
|
| 16893 |
/* DSYGS2 reduces a real symmetric-definite generalized eigenproblem */ |
| 16894 |
/* to standard form. */ |
| 16895 |
|
| 16896 |
/* If ITYPE = 1, the problem is A*x = lambda*B*x, */ |
| 16897 |
/* and A is overwritten by inv(U')*A*inv(U) or inv(L)*A*inv(L') */ |
| 16898 |
|
| 16899 |
/* If ITYPE = 2 or 3, the problem is A*B*x = lambda*x or */ |
| 16900 |
/* B*A*x = lambda*x, and A is overwritten by U*A*U` or L'*A*L. */ |
| 16901 |
|
| 16902 |
/* B must have been previously factorized as U'*U or L*L' by DPOTRF. */ |
| 16903 |
|
| 16904 |
/* Arguments */ |
| 16905 |
/* ========= */ |
| 16906 |
|
| 16907 |
/* ITYPE (input) INTEGER */ |
| 16908 |
/* = 1: compute inv(U')*A*inv(U) or inv(L)*A*inv(L'); */ |
| 16909 |
/* = 2 or 3: compute U*A*U' or L'*A*L. */ |
| 16910 |
|
| 16911 |
/* UPLO (input) CHARACTER*1 */ |
| 16912 |
/* Specifies whether the upper or lower triangular part of the */ |
| 16913 |
/* symmetric matrix A is stored, and how B has been factorized. */ |
| 16914 |
/* = 'U': Upper triangular */ |
| 16915 |
/* = 'L': Lower triangular */ |
| 16916 |
|
| 16917 |
/* N (input) INTEGER */ |
| 16918 |
/* The order of the matrices A and B. N >= 0. */ |
| 16919 |
|
| 16920 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 16921 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the leading */ |
| 16922 |
/* n by n upper triangular part of A contains the upper */ |
| 16923 |
/* triangular part of the matrix A, and the strictly lower */ |
| 16924 |
/* triangular part of A is not referenced. If UPLO = 'L', the */ |
| 16925 |
/* leading n by n lower triangular part of A contains the lower */ |
| 16926 |
/* triangular part of the matrix A, and the strictly upper */ |
| 16927 |
/* triangular part of A is not referenced. */ |
| 16928 |
|
| 16929 |
/* On exit, if INFO = 0, the transformed matrix, stored in the */ |
| 16930 |
/* same format as A. */ |
| 16931 |
|
| 16932 |
/* LDA (input) INTEGER */ |
| 16933 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 16934 |
|
| 16935 |
/* B (input) DOUBLE PRECISION array, dimension (LDB,N) */ |
| 16936 |
/* The triangular factor from the Cholesky factorization of B, */ |
| 16937 |
/* as returned by DPOTRF. */ |
| 16938 |
|
| 16939 |
/* LDB (input) INTEGER */ |
| 16940 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 16941 |
|
| 16942 |
/* INFO (output) INTEGER */ |
| 16943 |
/* = 0: successful exit. */ |
| 16944 |
/* < 0: if INFO = -i, the i-th argument had an illegal value. */ |
| 16945 |
|
| 16946 |
/* ===================================================================== */ |
| 16947 |
|
| 16948 |
/* .. Parameters .. */ |
| 16949 |
/* .. */ |
| 16950 |
/* .. Local Scalars .. */ |
| 16951 |
/* .. */ |
| 16952 |
/* .. External Subroutines .. */ |
| 16953 |
/* .. */ |
| 16954 |
/* .. Intrinsic Functions .. */ |
| 16955 |
/* .. */ |
| 16956 |
/* .. External Functions .. */ |
| 16957 |
/* .. */ |
| 16958 |
/* .. Executable Statements .. */ |
| 16959 |
|
| 16960 |
/* Test the input parameters. */ |
| 16961 |
|
| 16962 |
/* Parameter adjustments */ |
| 16963 |
a_dim1 = *lda; |
| 16964 |
a_offset = 1 + a_dim1; |
| 16965 |
a -= a_offset; |
| 16966 |
b_dim1 = *ldb; |
| 16967 |
b_offset = 1 + b_dim1; |
| 16968 |
b -= b_offset; |
| 16969 |
|
| 16970 |
/* Function Body */ |
| 16971 |
*info = 0; |
| 16972 |
upper = lsame_(uplo, "U"); |
| 16973 |
if (*itype < 1 || *itype > 3) { |
| 16974 |
*info = -1; |
| 16975 |
} else if (! upper && ! lsame_(uplo, "L")) { |
| 16976 |
*info = -2; |
| 16977 |
} else if (*n < 0) { |
| 16978 |
*info = -3; |
| 16979 |
} else if (*lda < std::max(1_integer,*n)) { |
| 16980 |
*info = -5; |
| 16981 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 16982 |
*info = -7; |
| 16983 |
} |
| 16984 |
if (*info != 0) { |
| 16985 |
i__1 = -(*info); |
| 16986 |
xerbla_("DSYGS2", &i__1); |
| 16987 |
return 0; |
| 16988 |
} |
| 16989 |
|
| 16990 |
if (*itype == 1) { |
| 16991 |
if (upper) { |
| 16992 |
|
| 16993 |
/* Compute inv(U')*A*inv(U) */ |
| 16994 |
|
| 16995 |
i__1 = *n; |
| 16996 |
for (k = 1; k <= i__1; ++k) { |
| 16997 |
|
| 16998 |
/* Update the upper triangle of A(k:n,k:n) */ |
| 16999 |
|
| 17000 |
akk = a[k + k * a_dim1]; |
| 17001 |
bkk = b[k + k * b_dim1]; |
| 17002 |
/* Computing 2nd power */ |
| 17003 |
d__1 = bkk; |
| 17004 |
akk /= d__1 * d__1; |
| 17005 |
a[k + k * a_dim1] = akk; |
| 17006 |
if (k < *n) { |
| 17007 |
i__2 = *n - k; |
| 17008 |
d__1 = 1. / bkk; |
| 17009 |
dscal_(&i__2, &d__1, &a[k + (k + 1) * a_dim1], lda); |
| 17010 |
ct = akk * -.5; |
| 17011 |
i__2 = *n - k; |
| 17012 |
daxpy_(&i__2, &ct, &b[k + (k + 1) * b_dim1], ldb, &a[k + ( |
| 17013 |
k + 1) * a_dim1], lda); |
| 17014 |
i__2 = *n - k; |
| 17015 |
dsyr2_(uplo, &i__2, &c_b6, &a[k + (k + 1) * a_dim1], lda, |
| 17016 |
&b[k + (k + 1) * b_dim1], ldb, &a[k + 1 + (k + 1) |
| 17017 |
* a_dim1], lda); |
| 17018 |
i__2 = *n - k; |
| 17019 |
daxpy_(&i__2, &ct, &b[k + (k + 1) * b_dim1], ldb, &a[k + ( |
| 17020 |
k + 1) * a_dim1], lda); |
| 17021 |
i__2 = *n - k; |
| 17022 |
dtrsv_(uplo, "Transpose", "Non-unit", &i__2, &b[k + 1 + ( |
| 17023 |
k + 1) * b_dim1], ldb, &a[k + (k + 1) * a_dim1], |
| 17024 |
lda); |
| 17025 |
} |
| 17026 |
/* L10: */ |
| 17027 |
} |
| 17028 |
} else { |
| 17029 |
|
| 17030 |
/* Compute inv(L)*A*inv(L') */ |
| 17031 |
|
| 17032 |
i__1 = *n; |
| 17033 |
for (k = 1; k <= i__1; ++k) { |
| 17034 |
|
| 17035 |
/* Update the lower triangle of A(k:n,k:n) */ |
| 17036 |
|
| 17037 |
akk = a[k + k * a_dim1]; |
| 17038 |
bkk = b[k + k * b_dim1]; |
| 17039 |
/* Computing 2nd power */ |
| 17040 |
d__1 = bkk; |
| 17041 |
akk /= d__1 * d__1; |
| 17042 |
a[k + k * a_dim1] = akk; |
| 17043 |
if (k < *n) { |
| 17044 |
i__2 = *n - k; |
| 17045 |
d__1 = 1. / bkk; |
| 17046 |
dscal_(&i__2, &d__1, &a[k + 1 + k * a_dim1], &c__1); |
| 17047 |
ct = akk * -.5; |
| 17048 |
i__2 = *n - k; |
| 17049 |
daxpy_(&i__2, &ct, &b[k + 1 + k * b_dim1], &c__1, &a[k + |
| 17050 |
1 + k * a_dim1], &c__1); |
| 17051 |
i__2 = *n - k; |
| 17052 |
dsyr2_(uplo, &i__2, &c_b6, &a[k + 1 + k * a_dim1], &c__1, |
| 17053 |
&b[k + 1 + k * b_dim1], &c__1, &a[k + 1 + (k + 1) |
| 17054 |
* a_dim1], lda); |
| 17055 |
i__2 = *n - k; |
| 17056 |
daxpy_(&i__2, &ct, &b[k + 1 + k * b_dim1], &c__1, &a[k + |
| 17057 |
1 + k * a_dim1], &c__1); |
| 17058 |
i__2 = *n - k; |
| 17059 |
dtrsv_(uplo, "No transpose", "Non-unit", &i__2, &b[k + 1 |
| 17060 |
+ (k + 1) * b_dim1], ldb, &a[k + 1 + k * a_dim1], |
| 17061 |
&c__1); |
| 17062 |
} |
| 17063 |
/* L20: */ |
| 17064 |
} |
| 17065 |
} |
| 17066 |
} else { |
| 17067 |
if (upper) { |
| 17068 |
|
| 17069 |
/* Compute U*A*U' */ |
| 17070 |
|
| 17071 |
i__1 = *n; |
| 17072 |
for (k = 1; k <= i__1; ++k) { |
| 17073 |
|
| 17074 |
/* Update the upper triangle of A(1:k,1:k) */ |
| 17075 |
|
| 17076 |
akk = a[k + k * a_dim1]; |
| 17077 |
bkk = b[k + k * b_dim1]; |
| 17078 |
i__2 = k - 1; |
| 17079 |
dtrmv_(uplo, "No transpose", "Non-unit", &i__2, &b[b_offset], |
| 17080 |
ldb, &a[k * a_dim1 + 1], &c__1); |
| 17081 |
ct = akk * .5; |
| 17082 |
i__2 = k - 1; |
| 17083 |
daxpy_(&i__2, &ct, &b[k * b_dim1 + 1], &c__1, &a[k * a_dim1 + |
| 17084 |
1], &c__1); |
| 17085 |
i__2 = k - 1; |
| 17086 |
dsyr2_(uplo, &i__2, &c_b27, &a[k * a_dim1 + 1], &c__1, &b[k * |
| 17087 |
b_dim1 + 1], &c__1, &a[a_offset], lda); |
| 17088 |
i__2 = k - 1; |
| 17089 |
daxpy_(&i__2, &ct, &b[k * b_dim1 + 1], &c__1, &a[k * a_dim1 + |
| 17090 |
1], &c__1); |
| 17091 |
i__2 = k - 1; |
| 17092 |
dscal_(&i__2, &bkk, &a[k * a_dim1 + 1], &c__1); |
| 17093 |
/* Computing 2nd power */ |
| 17094 |
d__1 = bkk; |
| 17095 |
a[k + k * a_dim1] = akk * (d__1 * d__1); |
| 17096 |
/* L30: */ |
| 17097 |
} |
| 17098 |
} else { |
| 17099 |
|
| 17100 |
/* Compute L'*A*L */ |
| 17101 |
|
| 17102 |
i__1 = *n; |
| 17103 |
for (k = 1; k <= i__1; ++k) { |
| 17104 |
|
| 17105 |
/* Update the lower triangle of A(1:k,1:k) */ |
| 17106 |
|
| 17107 |
akk = a[k + k * a_dim1]; |
| 17108 |
bkk = b[k + k * b_dim1]; |
| 17109 |
i__2 = k - 1; |
| 17110 |
dtrmv_(uplo, "Transpose", "Non-unit", &i__2, &b[b_offset], |
| 17111 |
ldb, &a[k + a_dim1], lda); |
| 17112 |
ct = akk * .5; |
| 17113 |
i__2 = k - 1; |
| 17114 |
daxpy_(&i__2, &ct, &b[k + b_dim1], ldb, &a[k + a_dim1], lda); |
| 17115 |
i__2 = k - 1; |
| 17116 |
dsyr2_(uplo, &i__2, &c_b27, &a[k + a_dim1], lda, &b[k + |
| 17117 |
b_dim1], ldb, &a[a_offset], lda); |
| 17118 |
i__2 = k - 1; |
| 17119 |
daxpy_(&i__2, &ct, &b[k + b_dim1], ldb, &a[k + a_dim1], lda); |
| 17120 |
i__2 = k - 1; |
| 17121 |
dscal_(&i__2, &bkk, &a[k + a_dim1], lda); |
| 17122 |
/* Computing 2nd power */ |
| 17123 |
d__1 = bkk; |
| 17124 |
a[k + k * a_dim1] = akk * (d__1 * d__1); |
| 17125 |
/* L40: */ |
| 17126 |
} |
| 17127 |
} |
| 17128 |
} |
| 17129 |
return 0; |
| 17130 |
|
| 17131 |
/* End of DSYGS2 */ |
| 17132 |
|
| 17133 |
} /* dsygs2_ */ |
| 17134 |
|
| 17135 |
/* Subroutine */ int dsygst_(integer *itype, const char *uplo, integer *n, |
| 17136 |
double *a, integer *lda, double *b, integer *ldb, integer * |
| 17137 |
info) |
| 17138 |
{ |
| 17139 |
/* Table of constant values */ |
| 17140 |
static integer c__1 = 1; |
| 17141 |
static integer c_n1 = -1; |
| 17142 |
static double c_b14 = 1.; |
| 17143 |
static double c_b16 = -.5; |
| 17144 |
static double c_b19 = -1.; |
| 17145 |
static double c_b52 = .5; |
| 17146 |
|
| 17147 |
/* System generated locals */ |
| 17148 |
integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3; |
| 17149 |
|
| 17150 |
/* Local variables */ |
| 17151 |
integer k, kb, nb; |
| 17152 |
bool upper; |
| 17153 |
|
| 17154 |
|
| 17155 |
/* -- LAPACK routine (version 3.1) -- */ |
| 17156 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 17157 |
/* November 2006 */ |
| 17158 |
|
| 17159 |
/* .. Scalar Arguments .. */ |
| 17160 |
/* .. */ |
| 17161 |
/* .. Array Arguments .. */ |
| 17162 |
/* .. */ |
| 17163 |
|
| 17164 |
/* Purpose */ |
| 17165 |
/* ======= */ |
| 17166 |
|
| 17167 |
/* DSYGST reduces a real symmetric-definite generalized eigenproblem */ |
| 17168 |
/* to standard form. */ |
| 17169 |
|
| 17170 |
/* If ITYPE = 1, the problem is A*x = lambda*B*x, */ |
| 17171 |
/* and A is overwritten by inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T) */ |
| 17172 |
|
| 17173 |
/* If ITYPE = 2 or 3, the problem is A*B*x = lambda*x or */ |
| 17174 |
/* B*A*x = lambda*x, and A is overwritten by U*A*U**T or L**T*A*L. */ |
| 17175 |
|
| 17176 |
/* B must have been previously factorized as U**T*U or L*L**T by DPOTRF. */ |
| 17177 |
|
| 17178 |
/* Arguments */ |
| 17179 |
/* ========= */ |
| 17180 |
|
| 17181 |
/* ITYPE (input) INTEGER */ |
| 17182 |
/* = 1: compute inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T); */ |
| 17183 |
/* = 2 or 3: compute U*A*U**T or L**T*A*L. */ |
| 17184 |
|
| 17185 |
/* UPLO (input) CHARACTER*1 */ |
| 17186 |
/* = 'U': Upper triangle of A is stored and B is factored as */ |
| 17187 |
/* U**T*U; */ |
| 17188 |
/* = 'L': Lower triangle of A is stored and B is factored as */ |
| 17189 |
/* L*L**T. */ |
| 17190 |
|
| 17191 |
/* N (input) INTEGER */ |
| 17192 |
/* The order of the matrices A and B. N >= 0. */ |
| 17193 |
|
| 17194 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 17195 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the leading */ |
| 17196 |
/* N-by-N upper triangular part of A contains the upper */ |
| 17197 |
/* triangular part of the matrix A, and the strictly lower */ |
| 17198 |
/* triangular part of A is not referenced. If UPLO = 'L', the */ |
| 17199 |
/* leading N-by-N lower triangular part of A contains the lower */ |
| 17200 |
/* triangular part of the matrix A, and the strictly upper */ |
| 17201 |
/* triangular part of A is not referenced. */ |
| 17202 |
|
| 17203 |
/* On exit, if INFO = 0, the transformed matrix, stored in the */ |
| 17204 |
/* same format as A. */ |
| 17205 |
|
| 17206 |
/* LDA (input) INTEGER */ |
| 17207 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 17208 |
|
| 17209 |
/* B (input) DOUBLE PRECISION array, dimension (LDB,N) */ |
| 17210 |
/* The triangular factor from the Cholesky factorization of B, */ |
| 17211 |
/* as returned by DPOTRF. */ |
| 17212 |
|
| 17213 |
/* LDB (input) INTEGER */ |
| 17214 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 17215 |
|
| 17216 |
/* INFO (output) INTEGER */ |
| 17217 |
/* = 0: successful exit */ |
| 17218 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 17219 |
|
| 17220 |
/* ===================================================================== */ |
| 17221 |
|
| 17222 |
/* .. Parameters .. */ |
| 17223 |
/* .. */ |
| 17224 |
/* .. Local Scalars .. */ |
| 17225 |
/* .. */ |
| 17226 |
/* .. External Subroutines .. */ |
| 17227 |
/* .. */ |
| 17228 |
/* .. Intrinsic Functions .. */ |
| 17229 |
/* .. */ |
| 17230 |
/* .. External Functions .. */ |
| 17231 |
/* .. */ |
| 17232 |
/* .. Executable Statements .. */ |
| 17233 |
|
| 17234 |
/* Test the input parameters. */ |
| 17235 |
|
| 17236 |
/* Parameter adjustments */ |
| 17237 |
a_dim1 = *lda; |
| 17238 |
a_offset = 1 + a_dim1; |
| 17239 |
a -= a_offset; |
| 17240 |
b_dim1 = *ldb; |
| 17241 |
b_offset = 1 + b_dim1; |
| 17242 |
b -= b_offset; |
| 17243 |
|
| 17244 |
/* Function Body */ |
| 17245 |
*info = 0; |
| 17246 |
upper = lsame_(uplo, "U"); |
| 17247 |
if (*itype < 1 || *itype > 3) { |
| 17248 |
*info = -1; |
| 17249 |
} else if (! upper && ! lsame_(uplo, "L")) { |
| 17250 |
*info = -2; |
| 17251 |
} else if (*n < 0) { |
| 17252 |
*info = -3; |
| 17253 |
} else if (*lda < std::max(1_integer,*n)) { |
| 17254 |
*info = -5; |
| 17255 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 17256 |
*info = -7; |
| 17257 |
} |
| 17258 |
if (*info != 0) { |
| 17259 |
i__1 = -(*info); |
| 17260 |
xerbla_("DSYGST", &i__1); |
| 17261 |
return 0; |
| 17262 |
} |
| 17263 |
|
| 17264 |
/* Quick return if possible */ |
| 17265 |
|
| 17266 |
if (*n == 0) { |
| 17267 |
return 0; |
| 17268 |
} |
| 17269 |
|
| 17270 |
/* Determine the block size for this environment. */ |
| 17271 |
|
| 17272 |
nb = ilaenv_(&c__1, "DSYGST", uplo, n, &c_n1, &c_n1, &c_n1); |
| 17273 |
|
| 17274 |
if (nb <= 1 || nb >= *n) { |
| 17275 |
|
| 17276 |
/* Use unblocked code */ |
| 17277 |
|
| 17278 |
dsygs2_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info); |
| 17279 |
} else { |
| 17280 |
|
| 17281 |
/* Use blocked code */ |
| 17282 |
|
| 17283 |
if (*itype == 1) { |
| 17284 |
if (upper) { |
| 17285 |
|
| 17286 |
/* Compute inv(U')*A*inv(U) */ |
| 17287 |
|
| 17288 |
i__1 = *n; |
| 17289 |
i__2 = nb; |
| 17290 |
for (k = 1; i__2 < 0 ? k >= i__1 : k <= i__1; k += i__2) { |
| 17291 |
/* Computing MIN */ |
| 17292 |
i__3 = *n - k + 1; |
| 17293 |
kb = std::min(i__3,nb); |
| 17294 |
|
| 17295 |
/* Update the upper triangle of A(k:n,k:n) */ |
| 17296 |
|
| 17297 |
dsygs2_(itype, uplo, &kb, &a[k + k * a_dim1], lda, &b[k + |
| 17298 |
k * b_dim1], ldb, info); |
| 17299 |
if (k + kb <= *n) { |
| 17300 |
i__3 = *n - k - kb + 1; |
| 17301 |
dtrsm_("Left", uplo, "Transpose", "Non-unit", &kb, & |
| 17302 |
i__3, &c_b14, &b[k + k * b_dim1], ldb, &a[k + |
| 17303 |
(k + kb) * a_dim1], lda); |
| 17304 |
i__3 = *n - k - kb + 1; |
| 17305 |
dsymm_("Left", uplo, &kb, &i__3, &c_b16, &a[k + k * |
| 17306 |
a_dim1], lda, &b[k + (k + kb) * b_dim1], ldb, |
| 17307 |
&c_b14, &a[k + (k + kb) * a_dim1], lda); |
| 17308 |
i__3 = *n - k - kb + 1; |
| 17309 |
dsyr2k_(uplo, "Transpose", &i__3, &kb, &c_b19, &a[k + |
| 17310 |
(k + kb) * a_dim1], lda, &b[k + (k + kb) * |
| 17311 |
b_dim1], ldb, &c_b14, &a[k + kb + (k + kb) * |
| 17312 |
a_dim1], lda); |
| 17313 |
i__3 = *n - k - kb + 1; |
| 17314 |
dsymm_("Left", uplo, &kb, &i__3, &c_b16, &a[k + k * |
| 17315 |
a_dim1], lda, &b[k + (k + kb) * b_dim1], ldb, |
| 17316 |
&c_b14, &a[k + (k + kb) * a_dim1], lda); |
| 17317 |
i__3 = *n - k - kb + 1; |
| 17318 |
dtrsm_("Right", uplo, "No transpose", "Non-unit", &kb, |
| 17319 |
&i__3, &c_b14, &b[k + kb + (k + kb) * b_dim1] |
| 17320 |
, ldb, &a[k + (k + kb) * a_dim1], lda); |
| 17321 |
} |
| 17322 |
/* L10: */ |
| 17323 |
} |
| 17324 |
} else { |
| 17325 |
|
| 17326 |
/* Compute inv(L)*A*inv(L') */ |
| 17327 |
|
| 17328 |
i__2 = *n; |
| 17329 |
i__1 = nb; |
| 17330 |
for (k = 1; i__1 < 0 ? k >= i__2 : k <= i__2; k += i__1) { |
| 17331 |
/* Computing MIN */ |
| 17332 |
i__3 = *n - k + 1; |
| 17333 |
kb = std::min(i__3,nb); |
| 17334 |
|
| 17335 |
/* Update the lower triangle of A(k:n,k:n) */ |
| 17336 |
|
| 17337 |
dsygs2_(itype, uplo, &kb, &a[k + k * a_dim1], lda, &b[k + |
| 17338 |
k * b_dim1], ldb, info); |
| 17339 |
if (k + kb <= *n) { |
| 17340 |
i__3 = *n - k - kb + 1; |
| 17341 |
dtrsm_("Right", uplo, "Transpose", "Non-unit", &i__3, |
| 17342 |
&kb, &c_b14, &b[k + k * b_dim1], ldb, &a[k + |
| 17343 |
kb + k * a_dim1], lda); |
| 17344 |
i__3 = *n - k - kb + 1; |
| 17345 |
dsymm_("Right", uplo, &i__3, &kb, &c_b16, &a[k + k * |
| 17346 |
a_dim1], lda, &b[k + kb + k * b_dim1], ldb, & |
| 17347 |
c_b14, &a[k + kb + k * a_dim1], lda); |
| 17348 |
i__3 = *n - k - kb + 1; |
| 17349 |
dsyr2k_(uplo, "No transpose", &i__3, &kb, &c_b19, &a[ |
| 17350 |
k + kb + k * a_dim1], lda, &b[k + kb + k * |
| 17351 |
b_dim1], ldb, &c_b14, &a[k + kb + (k + kb) * |
| 17352 |
a_dim1], lda); |
| 17353 |
i__3 = *n - k - kb + 1; |
| 17354 |
dsymm_("Right", uplo, &i__3, &kb, &c_b16, &a[k + k * |
| 17355 |
a_dim1], lda, &b[k + kb + k * b_dim1], ldb, & |
| 17356 |
c_b14, &a[k + kb + k * a_dim1], lda); |
| 17357 |
i__3 = *n - k - kb + 1; |
| 17358 |
dtrsm_("Left", uplo, "No transpose", "Non-unit", & |
| 17359 |
i__3, &kb, &c_b14, &b[k + kb + (k + kb) * |
| 17360 |
b_dim1], ldb, &a[k + kb + k * a_dim1], lda); |
| 17361 |
} |
| 17362 |
/* L20: */ |
| 17363 |
} |
| 17364 |
} |
| 17365 |
} else { |
| 17366 |
if (upper) { |
| 17367 |
|
| 17368 |
/* Compute U*A*U' */ |
| 17369 |
|
| 17370 |
i__1 = *n; |
| 17371 |
i__2 = nb; |
| 17372 |
for (k = 1; i__2 < 0 ? k >= i__1 : k <= i__1; k += i__2) { |
| 17373 |
/* Computing MIN */ |
| 17374 |
i__3 = *n - k + 1; |
| 17375 |
kb = std::min(i__3,nb); |
| 17376 |
|
| 17377 |
/* Update the upper triangle of A(1:k+kb-1,1:k+kb-1) */ |
| 17378 |
|
| 17379 |
i__3 = k - 1; |
| 17380 |
dtrmm_("Left", uplo, "No transpose", "Non-unit", &i__3, & |
| 17381 |
kb, &c_b14, &b[b_offset], ldb, &a[k * a_dim1 + 1], |
| 17382 |
lda) |
| 17383 |
; |
| 17384 |
i__3 = k - 1; |
| 17385 |
dsymm_("Right", uplo, &i__3, &kb, &c_b52, &a[k + k * |
| 17386 |
a_dim1], lda, &b[k * b_dim1 + 1], ldb, &c_b14, &a[ |
| 17387 |
k * a_dim1 + 1], lda); |
| 17388 |
i__3 = k - 1; |
| 17389 |
dsyr2k_(uplo, "No transpose", &i__3, &kb, &c_b14, &a[k * |
| 17390 |
a_dim1 + 1], lda, &b[k * b_dim1 + 1], ldb, &c_b14, |
| 17391 |
&a[a_offset], lda); |
| 17392 |
i__3 = k - 1; |
| 17393 |
dsymm_("Right", uplo, &i__3, &kb, &c_b52, &a[k + k * |
| 17394 |
a_dim1], lda, &b[k * b_dim1 + 1], ldb, &c_b14, &a[ |
| 17395 |
k * a_dim1 + 1], lda); |
| 17396 |
i__3 = k - 1; |
| 17397 |
dtrmm_("Right", uplo, "Transpose", "Non-unit", &i__3, &kb, |
| 17398 |
&c_b14, &b[k + k * b_dim1], ldb, &a[k * a_dim1 + |
| 17399 |
1], lda); |
| 17400 |
dsygs2_(itype, uplo, &kb, &a[k + k * a_dim1], lda, &b[k + |
| 17401 |
k * b_dim1], ldb, info); |
| 17402 |
/* L30: */ |
| 17403 |
} |
| 17404 |
} else { |
| 17405 |
|
| 17406 |
/* Compute L'*A*L */ |
| 17407 |
|
| 17408 |
i__2 = *n; |
| 17409 |
i__1 = nb; |
| 17410 |
for (k = 1; i__1 < 0 ? k >= i__2 : k <= i__2; k += i__1) { |
| 17411 |
/* Computing MIN */ |
| 17412 |
i__3 = *n - k + 1; |
| 17413 |
kb = std::min(i__3,nb); |
| 17414 |
|
| 17415 |
/* Update the lower triangle of A(1:k+kb-1,1:k+kb-1) */ |
| 17416 |
|
| 17417 |
i__3 = k - 1; |
| 17418 |
dtrmm_("Right", uplo, "No transpose", "Non-unit", &kb, & |
| 17419 |
i__3, &c_b14, &b[b_offset], ldb, &a[k + a_dim1], |
| 17420 |
lda); |
| 17421 |
i__3 = k - 1; |
| 17422 |
dsymm_("Left", uplo, &kb, &i__3, &c_b52, &a[k + k * |
| 17423 |
a_dim1], lda, &b[k + b_dim1], ldb, &c_b14, &a[k + |
| 17424 |
a_dim1], lda); |
| 17425 |
i__3 = k - 1; |
| 17426 |
dsyr2k_(uplo, "Transpose", &i__3, &kb, &c_b14, &a[k + |
| 17427 |
a_dim1], lda, &b[k + b_dim1], ldb, &c_b14, &a[ |
| 17428 |
a_offset], lda); |
| 17429 |
i__3 = k - 1; |
| 17430 |
dsymm_("Left", uplo, &kb, &i__3, &c_b52, &a[k + k * |
| 17431 |
a_dim1], lda, &b[k + b_dim1], ldb, &c_b14, &a[k + |
| 17432 |
a_dim1], lda); |
| 17433 |
i__3 = k - 1; |
| 17434 |
dtrmm_("Left", uplo, "Transpose", "Non-unit", &kb, &i__3, |
| 17435 |
&c_b14, &b[k + k * b_dim1], ldb, &a[k + a_dim1], |
| 17436 |
lda); |
| 17437 |
dsygs2_(itype, uplo, &kb, &a[k + k * a_dim1], lda, &b[k + |
| 17438 |
k * b_dim1], ldb, info); |
| 17439 |
/* L40: */ |
| 17440 |
} |
| 17441 |
} |
| 17442 |
} |
| 17443 |
} |
| 17444 |
return 0; |
| 17445 |
|
| 17446 |
/* End of DSYGST */ |
| 17447 |
|
| 17448 |
} /* dsygst_ */ |
| 17449 |
|
| 17450 |
/* Subroutine */ int dsygv_(integer *itype, const char *jobz, const char *uplo, integer * |
| 17451 |
n, double *a, integer *lda, double *b, integer *ldb, |
| 17452 |
double *w, double *work, integer *lwork, integer *info) |
| 17453 |
{ |
| 17454 |
/* Table of constant values */ |
| 17455 |
static integer c__1 = 1; |
| 17456 |
static integer c_n1 = -1; |
| 17457 |
static double c_b16 = 1.; |
| 17458 |
|
| 17459 |
/* System generated locals */ |
| 17460 |
integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2; |
| 17461 |
|
| 17462 |
/* Local variables */ |
| 17463 |
integer nb, neig; |
| 17464 |
char trans[1]; |
| 17465 |
bool upper; |
| 17466 |
bool wantz; |
| 17467 |
integer lwkmin; |
| 17468 |
integer lwkopt; |
| 17469 |
bool lquery; |
| 17470 |
|
| 17471 |
|
| 17472 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 17473 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 17474 |
/* November 2006 */ |
| 17475 |
|
| 17476 |
/* .. Scalar Arguments .. */ |
| 17477 |
/* .. */ |
| 17478 |
/* .. Array Arguments .. */ |
| 17479 |
/* .. */ |
| 17480 |
|
| 17481 |
/* Purpose */ |
| 17482 |
/* ======= */ |
| 17483 |
|
| 17484 |
/* DSYGV computes all the eigenvalues, and optionally, the eigenvectors */ |
| 17485 |
/* of a real generalized symmetric-definite eigenproblem, of the form */ |
| 17486 |
/* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. */ |
| 17487 |
/* Here A and B are assumed to be symmetric and B is also */ |
| 17488 |
/* positive definite. */ |
| 17489 |
|
| 17490 |
/* Arguments */ |
| 17491 |
/* ========= */ |
| 17492 |
|
| 17493 |
/* ITYPE (input) INTEGER */ |
| 17494 |
/* Specifies the problem type to be solved: */ |
| 17495 |
/* = 1: A*x = (lambda)*B*x */ |
| 17496 |
/* = 2: A*B*x = (lambda)*x */ |
| 17497 |
/* = 3: B*A*x = (lambda)*x */ |
| 17498 |
|
| 17499 |
/* JOBZ (input) CHARACTER*1 */ |
| 17500 |
/* = 'N': Compute eigenvalues only; */ |
| 17501 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 17502 |
|
| 17503 |
/* UPLO (input) CHARACTER*1 */ |
| 17504 |
/* = 'U': Upper triangles of A and B are stored; */ |
| 17505 |
/* = 'L': Lower triangles of A and B are stored. */ |
| 17506 |
|
| 17507 |
/* N (input) INTEGER */ |
| 17508 |
/* The order of the matrices A and B. N >= 0. */ |
| 17509 |
|
| 17510 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */ |
| 17511 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the */ |
| 17512 |
/* leading N-by-N upper triangular part of A contains the */ |
| 17513 |
/* upper triangular part of the matrix A. If UPLO = 'L', */ |
| 17514 |
/* the leading N-by-N lower triangular part of A contains */ |
| 17515 |
/* the lower triangular part of the matrix A. */ |
| 17516 |
|
| 17517 |
/* On exit, if JOBZ = 'V', then if INFO = 0, A contains the */ |
| 17518 |
/* matrix Z of eigenvectors. The eigenvectors are normalized */ |
| 17519 |
/* as follows: */ |
| 17520 |
/* if ITYPE = 1 or 2, Z**T*B*Z = I; */ |
| 17521 |
/* if ITYPE = 3, Z**T*inv(B)*Z = I. */ |
| 17522 |
/* If JOBZ = 'N', then on exit the upper triangle (if UPLO='U') */ |
| 17523 |
/* or the lower triangle (if UPLO='L') of A, including the */ |
| 17524 |
/* diagonal, is destroyed. */ |
| 17525 |
|
| 17526 |
/* LDA (input) INTEGER */ |
| 17527 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 17528 |
|
| 17529 |
/* B (input/output) DOUBLE PRECISION array, dimension (LDB, N) */ |
| 17530 |
/* On entry, the symmetric positive definite matrix B. */ |
| 17531 |
/* If UPLO = 'U', the leading N-by-N upper triangular part of B */ |
| 17532 |
/* contains the upper triangular part of the matrix B. */ |
| 17533 |
/* If UPLO = 'L', the leading N-by-N lower triangular part of B */ |
| 17534 |
/* contains the lower triangular part of the matrix B. */ |
| 17535 |
|
| 17536 |
/* On exit, if INFO <= N, the part of B containing the matrix is */ |
| 17537 |
/* overwritten by the triangular factor U or L from the Cholesky */ |
| 17538 |
/* factorization B = U**T*U or B = L*L**T. */ |
| 17539 |
|
| 17540 |
/* LDB (input) INTEGER */ |
| 17541 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 17542 |
|
| 17543 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 17544 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 17545 |
|
| 17546 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 17547 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 17548 |
|
| 17549 |
/* LWORK (input) INTEGER */ |
| 17550 |
/* The length of the array WORK. LWORK >= max(1,3*N-1). */ |
| 17551 |
/* For optimal efficiency, LWORK >= (NB+2)*N, */ |
| 17552 |
/* where NB is the blocksize for DSYTRD returned by ILAENV. */ |
| 17553 |
|
| 17554 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 17555 |
/* only calculates the optimal size of the WORK array, returns */ |
| 17556 |
/* this value as the first entry of the WORK array, and no error */ |
| 17557 |
/* message related to LWORK is issued by XERBLA. */ |
| 17558 |
|
| 17559 |
/* INFO (output) INTEGER */ |
| 17560 |
/* = 0: successful exit */ |
| 17561 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 17562 |
/* > 0: DPOTRF or DSYEV returned an error code: */ |
| 17563 |
/* <= N: if INFO = i, DSYEV failed to converge; */ |
| 17564 |
/* i off-diagonal elements of an intermediate */ |
| 17565 |
/* tridiagonal form did not converge to zero; */ |
| 17566 |
/* > N: if INFO = N + i, for 1 <= i <= N, then the leading */ |
| 17567 |
/* minor of order i of B is not positive definite. */ |
| 17568 |
/* The factorization of B could not be completed and */ |
| 17569 |
/* no eigenvalues or eigenvectors were computed. */ |
| 17570 |
|
| 17571 |
/* ===================================================================== */ |
| 17572 |
|
| 17573 |
/* .. Parameters .. */ |
| 17574 |
/* .. */ |
| 17575 |
/* .. Local Scalars .. */ |
| 17576 |
/* .. */ |
| 17577 |
/* .. External Functions .. */ |
| 17578 |
/* .. */ |
| 17579 |
/* .. External Subroutines .. */ |
| 17580 |
/* .. */ |
| 17581 |
/* .. Intrinsic Functions .. */ |
| 17582 |
/* .. */ |
| 17583 |
/* .. Executable Statements .. */ |
| 17584 |
|
| 17585 |
/* Test the input parameters. */ |
| 17586 |
|
| 17587 |
/* Parameter adjustments */ |
| 17588 |
a_dim1 = *lda; |
| 17589 |
a_offset = 1 + a_dim1; |
| 17590 |
a -= a_offset; |
| 17591 |
b_dim1 = *ldb; |
| 17592 |
b_offset = 1 + b_dim1; |
| 17593 |
b -= b_offset; |
| 17594 |
--w; |
| 17595 |
--work; |
| 17596 |
|
| 17597 |
/* Function Body */ |
| 17598 |
wantz = lsame_(jobz, "V"); |
| 17599 |
upper = lsame_(uplo, "U"); |
| 17600 |
lquery = *lwork == -1; |
| 17601 |
|
| 17602 |
*info = 0; |
| 17603 |
if (*itype < 1 || *itype > 3) { |
| 17604 |
*info = -1; |
| 17605 |
} else if (! (wantz || lsame_(jobz, "N"))) { |
| 17606 |
*info = -2; |
| 17607 |
} else if (! (upper || lsame_(uplo, "L"))) { |
| 17608 |
*info = -3; |
| 17609 |
} else if (*n < 0) { |
| 17610 |
*info = -4; |
| 17611 |
} else if (*lda < std::max(1_integer,*n)) { |
| 17612 |
*info = -6; |
| 17613 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 17614 |
*info = -8; |
| 17615 |
} |
| 17616 |
|
| 17617 |
if (*info == 0) { |
| 17618 |
/* Computing MAX */ |
| 17619 |
i__1 = 1, i__2 = *n * 3 - 1; |
| 17620 |
lwkmin = std::max(i__1,i__2); |
| 17621 |
nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1); |
| 17622 |
/* Computing MAX */ |
| 17623 |
i__1 = lwkmin, i__2 = (nb + 2) * *n; |
| 17624 |
lwkopt = std::max(i__1,i__2); |
| 17625 |
work[1] = (double) lwkopt; |
| 17626 |
|
| 17627 |
if (*lwork < lwkmin && ! lquery) { |
| 17628 |
*info = -11; |
| 17629 |
} |
| 17630 |
} |
| 17631 |
|
| 17632 |
if (*info != 0) { |
| 17633 |
i__1 = -(*info); |
| 17634 |
xerbla_("DSYGV ", &i__1); |
| 17635 |
return 0; |
| 17636 |
} else if (lquery) { |
| 17637 |
return 0; |
| 17638 |
} |
| 17639 |
|
| 17640 |
/* Quick return if possible */ |
| 17641 |
|
| 17642 |
if (*n == 0) { |
| 17643 |
return 0; |
| 17644 |
} |
| 17645 |
|
| 17646 |
/* Form a Cholesky factorization of B. */ |
| 17647 |
|
| 17648 |
dpotrf_(uplo, n, &b[b_offset], ldb, info); |
| 17649 |
if (*info != 0) { |
| 17650 |
*info = *n + *info; |
| 17651 |
return 0; |
| 17652 |
} |
| 17653 |
|
| 17654 |
/* Transform problem to standard eigenvalue problem and solve. */ |
| 17655 |
|
| 17656 |
dsygst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info); |
| 17657 |
dsyev_(jobz, uplo, n, &a[a_offset], lda, &w[1], &work[1], lwork, info); |
| 17658 |
|
| 17659 |
if (wantz) { |
| 17660 |
|
| 17661 |
/* Backtransform eigenvectors to the original problem. */ |
| 17662 |
|
| 17663 |
neig = *n; |
| 17664 |
if (*info > 0) { |
| 17665 |
neig = *info - 1; |
| 17666 |
} |
| 17667 |
if (*itype == 1 || *itype == 2) { |
| 17668 |
|
| 17669 |
/* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */ |
| 17670 |
/* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */ |
| 17671 |
|
| 17672 |
if (upper) { |
| 17673 |
*(unsigned char *)trans = 'N'; |
| 17674 |
} else { |
| 17675 |
*(unsigned char *)trans = 'T'; |
| 17676 |
} |
| 17677 |
|
| 17678 |
dtrsm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b16, &b[ |
| 17679 |
b_offset], ldb, &a[a_offset], lda); |
| 17680 |
|
| 17681 |
} else if (*itype == 3) { |
| 17682 |
|
| 17683 |
/* For B*A*x=(lambda)*x; */ |
| 17684 |
/* backtransform eigenvectors: x = L*y or U'*y */ |
| 17685 |
|
| 17686 |
if (upper) { |
| 17687 |
*(unsigned char *)trans = 'T'; |
| 17688 |
} else { |
| 17689 |
*(unsigned char *)trans = 'N'; |
| 17690 |
} |
| 17691 |
|
| 17692 |
dtrmm_("Left", uplo, trans, "Non-unit", n, &neig, &c_b16, &b[ |
| 17693 |
b_offset], ldb, &a[a_offset], lda); |
| 17694 |
} |
| 17695 |
} |
| 17696 |
|
| 17697 |
work[1] = (double) lwkopt; |
| 17698 |
return 0; |
| 17699 |
|
| 17700 |
/* End of DSYGV */ |
| 17701 |
|
| 17702 |
} /* dsygv_ */ |
| 17703 |
|
| 17704 |
/* Subroutine */ int dsygvd_(integer *itype, const char *jobz, const char *uplo, integer * |
| 17705 |
n, double *a, integer *lda, double *b, integer *ldb, |
| 17706 |
double *w, double *work, integer *lwork, integer *iwork, |
| 17707 |
integer *liwork, integer *info) |
| 17708 |
{ |
| 17709 |
/* Table of constant values */ |
| 17710 |
static double c_b11 = 1.; |
| 17711 |
|
| 17712 |
/* System generated locals */ |
| 17713 |
integer a_dim1, a_offset, b_dim1, b_offset, i__1; |
| 17714 |
double d__1, d__2; |
| 17715 |
|
| 17716 |
/* Local variables */ |
| 17717 |
integer lopt; |
| 17718 |
integer lwmin; |
| 17719 |
char trans[1]; |
| 17720 |
integer liopt; |
| 17721 |
bool upper, wantz; |
| 17722 |
integer liwmin; |
| 17723 |
bool lquery; |
| 17724 |
|
| 17725 |
|
| 17726 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 17727 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 17728 |
/* November 2006 */ |
| 17729 |
|
| 17730 |
/* .. Scalar Arguments .. */ |
| 17731 |
/* .. */ |
| 17732 |
/* .. Array Arguments .. */ |
| 17733 |
/* .. */ |
| 17734 |
|
| 17735 |
/* Purpose */ |
| 17736 |
/* ======= */ |
| 17737 |
|
| 17738 |
/* DSYGVD computes all the eigenvalues, and optionally, the eigenvectors */ |
| 17739 |
/* of a real generalized symmetric-definite eigenproblem, of the form */ |
| 17740 |
/* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A and */ |
| 17741 |
/* B are assumed to be symmetric and B is also positive definite. */ |
| 17742 |
/* If eigenvectors are desired, it uses a divide and conquer algorithm. */ |
| 17743 |
|
| 17744 |
/* The divide and conquer algorithm makes very mild assumptions about */ |
| 17745 |
/* floating point arithmetic. It will work on machines with a guard */ |
| 17746 |
/* digit in add/subtract, or on those binary machines without guard */ |
| 17747 |
/* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */ |
| 17748 |
/* Cray-2. It could conceivably fail on hexadecimal or decimal machines */ |
| 17749 |
/* without guard digits, but we know of none. */ |
| 17750 |
|
| 17751 |
/* Arguments */ |
| 17752 |
/* ========= */ |
| 17753 |
|
| 17754 |
/* ITYPE (input) INTEGER */ |
| 17755 |
/* Specifies the problem type to be solved: */ |
| 17756 |
/* = 1: A*x = (lambda)*B*x */ |
| 17757 |
/* = 2: A*B*x = (lambda)*x */ |
| 17758 |
/* = 3: B*A*x = (lambda)*x */ |
| 17759 |
|
| 17760 |
/* JOBZ (input) CHARACTER*1 */ |
| 17761 |
/* = 'N': Compute eigenvalues only; */ |
| 17762 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 17763 |
|
| 17764 |
/* UPLO (input) CHARACTER*1 */ |
| 17765 |
/* = 'U': Upper triangles of A and B are stored; */ |
| 17766 |
/* = 'L': Lower triangles of A and B are stored. */ |
| 17767 |
|
| 17768 |
/* N (input) INTEGER */ |
| 17769 |
/* The order of the matrices A and B. N >= 0. */ |
| 17770 |
|
| 17771 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */ |
| 17772 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the */ |
| 17773 |
/* leading N-by-N upper triangular part of A contains the */ |
| 17774 |
/* upper triangular part of the matrix A. If UPLO = 'L', */ |
| 17775 |
/* the leading N-by-N lower triangular part of A contains */ |
| 17776 |
/* the lower triangular part of the matrix A. */ |
| 17777 |
|
| 17778 |
/* On exit, if JOBZ = 'V', then if INFO = 0, A contains the */ |
| 17779 |
/* matrix Z of eigenvectors. The eigenvectors are normalized */ |
| 17780 |
/* as follows: */ |
| 17781 |
/* if ITYPE = 1 or 2, Z**T*B*Z = I; */ |
| 17782 |
/* if ITYPE = 3, Z**T*inv(B)*Z = I. */ |
| 17783 |
/* If JOBZ = 'N', then on exit the upper triangle (if UPLO='U') */ |
| 17784 |
/* or the lower triangle (if UPLO='L') of A, including the */ |
| 17785 |
/* diagonal, is destroyed. */ |
| 17786 |
|
| 17787 |
/* LDA (input) INTEGER */ |
| 17788 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 17789 |
|
| 17790 |
/* B (input/output) DOUBLE PRECISION array, dimension (LDB, N) */ |
| 17791 |
/* On entry, the symmetric matrix B. If UPLO = 'U', the */ |
| 17792 |
/* leading N-by-N upper triangular part of B contains the */ |
| 17793 |
/* upper triangular part of the matrix B. If UPLO = 'L', */ |
| 17794 |
/* the leading N-by-N lower triangular part of B contains */ |
| 17795 |
/* the lower triangular part of the matrix B. */ |
| 17796 |
|
| 17797 |
/* On exit, if INFO <= N, the part of B containing the matrix is */ |
| 17798 |
/* overwritten by the triangular factor U or L from the Cholesky */ |
| 17799 |
/* factorization B = U**T*U or B = L*L**T. */ |
| 17800 |
|
| 17801 |
/* LDB (input) INTEGER */ |
| 17802 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 17803 |
|
| 17804 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 17805 |
/* If INFO = 0, the eigenvalues in ascending order. */ |
| 17806 |
|
| 17807 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 17808 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 17809 |
|
| 17810 |
/* LWORK (input) INTEGER */ |
| 17811 |
/* The dimension of the array WORK. */ |
| 17812 |
/* If N <= 1, LWORK >= 1. */ |
| 17813 |
/* If JOBZ = 'N' and N > 1, LWORK >= 2*N+1. */ |
| 17814 |
/* If JOBZ = 'V' and N > 1, LWORK >= 1 + 6*N + 2*N**2. */ |
| 17815 |
|
| 17816 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 17817 |
/* only calculates the optimal sizes of the WORK and IWORK */ |
| 17818 |
/* arrays, returns these values as the first entries of the WORK */ |
| 17819 |
/* and IWORK arrays, and no error message related to LWORK or */ |
| 17820 |
/* LIWORK is issued by XERBLA. */ |
| 17821 |
|
| 17822 |
/* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ |
| 17823 |
/* On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */ |
| 17824 |
|
| 17825 |
/* LIWORK (input) INTEGER */ |
| 17826 |
/* The dimension of the array IWORK. */ |
| 17827 |
/* If N <= 1, LIWORK >= 1. */ |
| 17828 |
/* If JOBZ = 'N' and N > 1, LIWORK >= 1. */ |
| 17829 |
/* If JOBZ = 'V' and N > 1, LIWORK >= 3 + 5*N. */ |
| 17830 |
|
| 17831 |
/* If LIWORK = -1, then a workspace query is assumed; the */ |
| 17832 |
/* routine only calculates the optimal sizes of the WORK and */ |
| 17833 |
/* IWORK arrays, returns these values as the first entries of */ |
| 17834 |
/* the WORK and IWORK arrays, and no error message related to */ |
| 17835 |
/* LWORK or LIWORK is issued by XERBLA. */ |
| 17836 |
|
| 17837 |
/* INFO (output) INTEGER */ |
| 17838 |
/* = 0: successful exit */ |
| 17839 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 17840 |
/* > 0: DPOTRF or DSYEVD returned an error code: */ |
| 17841 |
/* <= N: if INFO = i and JOBZ = 'N', then the algorithm */ |
| 17842 |
/* failed to converge; i off-diagonal elements of an */ |
| 17843 |
/* intermediate tridiagonal form did not converge to */ |
| 17844 |
/* zero; */ |
| 17845 |
/* if INFO = i and JOBZ = 'V', then the algorithm */ |
| 17846 |
/* failed to compute an eigenvalue while working on */ |
| 17847 |
/* the submatrix lying in rows and columns INFO/(N+1) */ |
| 17848 |
/* through mod(INFO,N+1); */ |
| 17849 |
/* > N: if INFO = N + i, for 1 <= i <= N, then the leading */ |
| 17850 |
/* minor of order i of B is not positive definite. */ |
| 17851 |
/* The factorization of B could not be completed and */ |
| 17852 |
/* no eigenvalues or eigenvectors were computed. */ |
| 17853 |
|
| 17854 |
/* Further Details */ |
| 17855 |
/* =============== */ |
| 17856 |
|
| 17857 |
/* Based on contributions by */ |
| 17858 |
/* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */ |
| 17859 |
|
| 17860 |
/* Modified so that no backsubstitution is performed if DSYEVD fails to */ |
| 17861 |
/* converge (NEIG in old code could be greater than N causing out of */ |
| 17862 |
/* bounds reference to A - reported by Ralf Meyer). Also corrected the */ |
| 17863 |
/* description of INFO and the test on ITYPE. Sven, 16 Feb 05. */ |
| 17864 |
/* ===================================================================== */ |
| 17865 |
|
| 17866 |
/* .. Parameters .. */ |
| 17867 |
/* .. */ |
| 17868 |
/* .. Local Scalars .. */ |
| 17869 |
/* .. */ |
| 17870 |
/* .. External Functions .. */ |
| 17871 |
/* .. */ |
| 17872 |
/* .. External Subroutines .. */ |
| 17873 |
/* .. */ |
| 17874 |
/* .. Intrinsic Functions .. */ |
| 17875 |
/* .. */ |
| 17876 |
/* .. Executable Statements .. */ |
| 17877 |
|
| 17878 |
/* Test the input parameters. */ |
| 17879 |
|
| 17880 |
/* Parameter adjustments */ |
| 17881 |
a_dim1 = *lda; |
| 17882 |
a_offset = 1 + a_dim1; |
| 17883 |
a -= a_offset; |
| 17884 |
b_dim1 = *ldb; |
| 17885 |
b_offset = 1 + b_dim1; |
| 17886 |
b -= b_offset; |
| 17887 |
--w; |
| 17888 |
--work; |
| 17889 |
--iwork; |
| 17890 |
|
| 17891 |
/* Function Body */ |
| 17892 |
wantz = lsame_(jobz, "V"); |
| 17893 |
upper = lsame_(uplo, "U"); |
| 17894 |
lquery = *lwork == -1 || *liwork == -1; |
| 17895 |
|
| 17896 |
*info = 0; |
| 17897 |
if (*n <= 1) { |
| 17898 |
liwmin = 1; |
| 17899 |
lwmin = 1; |
| 17900 |
} else if (wantz) { |
| 17901 |
liwmin = *n * 5 + 3; |
| 17902 |
/* Computing 2nd power */ |
| 17903 |
i__1 = *n; |
| 17904 |
lwmin = *n * 6 + 1 + (i__1 * i__1 << 1); |
| 17905 |
} else { |
| 17906 |
liwmin = 1; |
| 17907 |
lwmin = (*n << 1) + 1; |
| 17908 |
} |
| 17909 |
lopt = lwmin; |
| 17910 |
liopt = liwmin; |
| 17911 |
if (*itype < 1 || *itype > 3) { |
| 17912 |
*info = -1; |
| 17913 |
} else if (! (wantz || lsame_(jobz, "N"))) { |
| 17914 |
*info = -2; |
| 17915 |
} else if (! (upper || lsame_(uplo, "L"))) { |
| 17916 |
*info = -3; |
| 17917 |
} else if (*n < 0) { |
| 17918 |
*info = -4; |
| 17919 |
} else if (*lda < std::max(1_integer,*n)) { |
| 17920 |
*info = -6; |
| 17921 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 17922 |
*info = -8; |
| 17923 |
} |
| 17924 |
|
| 17925 |
if (*info == 0) { |
| 17926 |
work[1] = (double) lopt; |
| 17927 |
iwork[1] = liopt; |
| 17928 |
|
| 17929 |
if (*lwork < lwmin && ! lquery) { |
| 17930 |
*info = -11; |
| 17931 |
} else if (*liwork < liwmin && ! lquery) { |
| 17932 |
*info = -13; |
| 17933 |
} |
| 17934 |
} |
| 17935 |
|
| 17936 |
if (*info != 0) { |
| 17937 |
i__1 = -(*info); |
| 17938 |
xerbla_("DSYGVD", &i__1); |
| 17939 |
return 0; |
| 17940 |
} else if (lquery) { |
| 17941 |
return 0; |
| 17942 |
} |
| 17943 |
|
| 17944 |
/* Quick return if possible */ |
| 17945 |
|
| 17946 |
if (*n == 0) { |
| 17947 |
return 0; |
| 17948 |
} |
| 17949 |
|
| 17950 |
/* Form a Cholesky factorization of B. */ |
| 17951 |
|
| 17952 |
dpotrf_(uplo, n, &b[b_offset], ldb, info); |
| 17953 |
if (*info != 0) { |
| 17954 |
*info = *n + *info; |
| 17955 |
return 0; |
| 17956 |
} |
| 17957 |
|
| 17958 |
/* Transform problem to standard eigenvalue problem and solve. */ |
| 17959 |
|
| 17960 |
dsygst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info); |
| 17961 |
dsyevd_(jobz, uplo, n, &a[a_offset], lda, &w[1], &work[1], lwork, &iwork[ |
| 17962 |
1], liwork, info); |
| 17963 |
/* Computing MAX */ |
| 17964 |
d__1 = (double) lopt; |
| 17965 |
lopt = (integer) std::max(d__1,work[1]); |
| 17966 |
/* Computing MAX */ |
| 17967 |
d__1 = (double) liopt, d__2 = (double) iwork[1]; |
| 17968 |
liopt = (integer) std::max(d__1,d__2); |
| 17969 |
|
| 17970 |
if (wantz && *info == 0) { |
| 17971 |
|
| 17972 |
/* Backtransform eigenvectors to the original problem. */ |
| 17973 |
|
| 17974 |
if (*itype == 1 || *itype == 2) { |
| 17975 |
|
| 17976 |
/* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */ |
| 17977 |
/* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */ |
| 17978 |
|
| 17979 |
if (upper) { |
| 17980 |
*(unsigned char *)trans = 'N'; |
| 17981 |
} else { |
| 17982 |
*(unsigned char *)trans = 'T'; |
| 17983 |
} |
| 17984 |
|
| 17985 |
dtrsm_("Left", uplo, trans, "Non-unit", n, n, &c_b11, &b[b_offset] |
| 17986 |
, ldb, &a[a_offset], lda); |
| 17987 |
|
| 17988 |
} else if (*itype == 3) { |
| 17989 |
|
| 17990 |
/* For B*A*x=(lambda)*x; */ |
| 17991 |
/* backtransform eigenvectors: x = L*y or U'*y */ |
| 17992 |
|
| 17993 |
if (upper) { |
| 17994 |
*(unsigned char *)trans = 'T'; |
| 17995 |
} else { |
| 17996 |
*(unsigned char *)trans = 'N'; |
| 17997 |
} |
| 17998 |
|
| 17999 |
dtrmm_("Left", uplo, trans, "Non-unit", n, n, &c_b11, &b[b_offset] |
| 18000 |
, ldb, &a[a_offset], lda); |
| 18001 |
} |
| 18002 |
} |
| 18003 |
|
| 18004 |
work[1] = (double) lopt; |
| 18005 |
iwork[1] = liopt; |
| 18006 |
|
| 18007 |
return 0; |
| 18008 |
|
| 18009 |
/* End of DSYGVD */ |
| 18010 |
|
| 18011 |
} /* dsygvd_ */ |
| 18012 |
|
| 18013 |
/* Subroutine */ int dsygvx_(integer *itype, const char *jobz, const char *range, const char * |
| 18014 |
uplo, integer *n, double *a, integer *lda, double *b, integer |
| 18015 |
*ldb, double *vl, double *vu, integer *il, integer *iu, |
| 18016 |
double *abstol, integer *m, double *w, double *z__, |
| 18017 |
integer *ldz, double *work, integer *lwork, integer *iwork, |
| 18018 |
integer *ifail, integer *info) |
| 18019 |
{ |
| 18020 |
/* Table of constant values */ |
| 18021 |
static integer c__1 = 1; |
| 18022 |
static integer c_n1 = -1; |
| 18023 |
static double c_b19 = 1.; |
| 18024 |
|
| 18025 |
/* System generated locals */ |
| 18026 |
integer a_dim1, a_offset, b_dim1, b_offset, z_dim1, z_offset, i__1, i__2; |
| 18027 |
|
| 18028 |
/* Local variables */ |
| 18029 |
integer nb; |
| 18030 |
char trans[1]; |
| 18031 |
bool upper, wantz, alleig, indeig, valeig; |
| 18032 |
integer lwkmin; |
| 18033 |
integer lwkopt; |
| 18034 |
bool lquery; |
| 18035 |
|
| 18036 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 18037 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 18038 |
/* November 2006 */ |
| 18039 |
|
| 18040 |
/* .. Scalar Arguments .. */ |
| 18041 |
/* .. */ |
| 18042 |
/* .. Array Arguments .. */ |
| 18043 |
/* .. */ |
| 18044 |
|
| 18045 |
/* Purpose */ |
| 18046 |
/* ======= */ |
| 18047 |
|
| 18048 |
/* DSYGVX computes selected eigenvalues, and optionally, eigenvectors */ |
| 18049 |
/* of a real generalized symmetric-definite eigenproblem, of the form */ |
| 18050 |
/* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A */ |
| 18051 |
/* and B are assumed to be symmetric and B is also positive definite. */ |
| 18052 |
/* Eigenvalues and eigenvectors can be selected by specifying either a */ |
| 18053 |
/* range of values or a range of indices for the desired eigenvalues. */ |
| 18054 |
|
| 18055 |
/* Arguments */ |
| 18056 |
/* ========= */ |
| 18057 |
|
| 18058 |
/* ITYPE (input) INTEGER */ |
| 18059 |
/* Specifies the problem type to be solved: */ |
| 18060 |
/* = 1: A*x = (lambda)*B*x */ |
| 18061 |
/* = 2: A*B*x = (lambda)*x */ |
| 18062 |
/* = 3: B*A*x = (lambda)*x */ |
| 18063 |
|
| 18064 |
/* JOBZ (input) CHARACTER*1 */ |
| 18065 |
/* = 'N': Compute eigenvalues only; */ |
| 18066 |
/* = 'V': Compute eigenvalues and eigenvectors. */ |
| 18067 |
|
| 18068 |
/* RANGE (input) CHARACTER*1 */ |
| 18069 |
/* = 'A': all eigenvalues will be found. */ |
| 18070 |
/* = 'V': all eigenvalues in the half-open interval (VL,VU] */ |
| 18071 |
/* will be found. */ |
| 18072 |
/* = 'I': the IL-th through IU-th eigenvalues will be found. */ |
| 18073 |
|
| 18074 |
/* UPLO (input) CHARACTER*1 */ |
| 18075 |
/* = 'U': Upper triangle of A and B are stored; */ |
| 18076 |
/* = 'L': Lower triangle of A and B are stored. */ |
| 18077 |
|
| 18078 |
/* N (input) INTEGER */ |
| 18079 |
/* The order of the matrix pencil (A,B). N >= 0. */ |
| 18080 |
|
| 18081 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */ |
| 18082 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the */ |
| 18083 |
/* leading N-by-N upper triangular part of A contains the */ |
| 18084 |
/* upper triangular part of the matrix A. If UPLO = 'L', */ |
| 18085 |
/* the leading N-by-N lower triangular part of A contains */ |
| 18086 |
/* the lower triangular part of the matrix A. */ |
| 18087 |
|
| 18088 |
/* On exit, the lower triangle (if UPLO='L') or the upper */ |
| 18089 |
/* triangle (if UPLO='U') of A, including the diagonal, is */ |
| 18090 |
/* destroyed. */ |
| 18091 |
|
| 18092 |
/* LDA (input) INTEGER */ |
| 18093 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 18094 |
|
| 18095 |
/* B (input/output) DOUBLE PRECISION array, dimension (LDA, N) */ |
| 18096 |
/* On entry, the symmetric matrix B. If UPLO = 'U', the */ |
| 18097 |
/* leading N-by-N upper triangular part of B contains the */ |
| 18098 |
/* upper triangular part of the matrix B. If UPLO = 'L', */ |
| 18099 |
/* the leading N-by-N lower triangular part of B contains */ |
| 18100 |
/* the lower triangular part of the matrix B. */ |
| 18101 |
|
| 18102 |
/* On exit, if INFO <= N, the part of B containing the matrix is */ |
| 18103 |
/* overwritten by the triangular factor U or L from the Cholesky */ |
| 18104 |
/* factorization B = U**T*U or B = L*L**T. */ |
| 18105 |
|
| 18106 |
/* LDB (input) INTEGER */ |
| 18107 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 18108 |
|
| 18109 |
/* VL (input) DOUBLE PRECISION */ |
| 18110 |
/* VU (input) DOUBLE PRECISION */ |
| 18111 |
/* If RANGE='V', the lower and upper bounds of the interval to */ |
| 18112 |
/* be searched for eigenvalues. VL < VU. */ |
| 18113 |
/* Not referenced if RANGE = 'A' or 'I'. */ |
| 18114 |
|
| 18115 |
/* IL (input) INTEGER */ |
| 18116 |
/* IU (input) INTEGER */ |
| 18117 |
/* If RANGE='I', the indices (in ascending order) of the */ |
| 18118 |
/* smallest and largest eigenvalues to be returned. */ |
| 18119 |
/* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ |
| 18120 |
/* Not referenced if RANGE = 'A' or 'V'. */ |
| 18121 |
|
| 18122 |
/* ABSTOL (input) DOUBLE PRECISION */ |
| 18123 |
/* The absolute error tolerance for the eigenvalues. */ |
| 18124 |
/* An approximate eigenvalue is accepted as converged */ |
| 18125 |
/* when it is determined to lie in an interval [a,b] */ |
| 18126 |
/* of width less than or equal to */ |
| 18127 |
|
| 18128 |
/* ABSTOL + EPS * max( |a|,|b| ) , */ |
| 18129 |
|
| 18130 |
/* where EPS is the machine precision. If ABSTOL is less than */ |
| 18131 |
/* or equal to zero, then EPS*|T| will be used in its place, */ |
| 18132 |
/* where |T| is the 1-norm of the tridiagonal matrix obtained */ |
| 18133 |
/* by reducing A to tridiagonal form. */ |
| 18134 |
|
| 18135 |
/* Eigenvalues will be computed most accurately when ABSTOL is */ |
| 18136 |
/* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */ |
| 18137 |
/* If this routine returns with INFO>0, indicating that some */ |
| 18138 |
/* eigenvectors did not converge, try setting ABSTOL to */ |
| 18139 |
/* 2*DLAMCH('S'). */ |
| 18140 |
|
| 18141 |
/* M (output) INTEGER */ |
| 18142 |
/* The total number of eigenvalues found. 0 <= M <= N. */ |
| 18143 |
/* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ |
| 18144 |
|
| 18145 |
/* W (output) DOUBLE PRECISION array, dimension (N) */ |
| 18146 |
/* On normal exit, the first M elements contain the selected */ |
| 18147 |
/* eigenvalues in ascending order. */ |
| 18148 |
|
| 18149 |
/* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */ |
| 18150 |
/* If JOBZ = 'N', then Z is not referenced. */ |
| 18151 |
/* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ |
| 18152 |
/* contain the orthonormal eigenvectors of the matrix A */ |
| 18153 |
/* corresponding to the selected eigenvalues, with the i-th */ |
| 18154 |
/* column of Z holding the eigenvector associated with W(i). */ |
| 18155 |
/* The eigenvectors are normalized as follows: */ |
| 18156 |
/* if ITYPE = 1 or 2, Z**T*B*Z = I; */ |
| 18157 |
/* if ITYPE = 3, Z**T*inv(B)*Z = I. */ |
| 18158 |
|
| 18159 |
/* If an eigenvector fails to converge, then that column of Z */ |
| 18160 |
/* contains the latest approximation to the eigenvector, and the */ |
| 18161 |
/* index of the eigenvector is returned in IFAIL. */ |
| 18162 |
/* Note: the user must ensure that at least max(1,M) columns are */ |
| 18163 |
/* supplied in the array Z; if RANGE = 'V', the exact value of M */ |
| 18164 |
/* is not known in advance and an upper bound must be used. */ |
| 18165 |
|
| 18166 |
/* LDZ (input) INTEGER */ |
| 18167 |
/* The leading dimension of the array Z. LDZ >= 1, and if */ |
| 18168 |
/* JOBZ = 'V', LDZ >= max(1,N). */ |
| 18169 |
|
| 18170 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 18171 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 18172 |
|
| 18173 |
/* LWORK (input) INTEGER */ |
| 18174 |
/* The length of the array WORK. LWORK >= max(1,8*N). */ |
| 18175 |
/* For optimal efficiency, LWORK >= (NB+3)*N, */ |
| 18176 |
/* where NB is the blocksize for DSYTRD returned by ILAENV. */ |
| 18177 |
|
| 18178 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 18179 |
/* only calculates the optimal size of the WORK array, returns */ |
| 18180 |
/* this value as the first entry of the WORK array, and no error */ |
| 18181 |
/* message related to LWORK is issued by XERBLA. */ |
| 18182 |
|
| 18183 |
/* IWORK (workspace) INTEGER array, dimension (5*N) */ |
| 18184 |
|
| 18185 |
/* IFAIL (output) INTEGER array, dimension (N) */ |
| 18186 |
/* If JOBZ = 'V', then if INFO = 0, the first M elements of */ |
| 18187 |
/* IFAIL are zero. If INFO > 0, then IFAIL contains the */ |
| 18188 |
/* indices of the eigenvectors that failed to converge. */ |
| 18189 |
/* If JOBZ = 'N', then IFAIL is not referenced. */ |
| 18190 |
|
| 18191 |
/* INFO (output) INTEGER */ |
| 18192 |
/* = 0: successful exit */ |
| 18193 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 18194 |
/* > 0: DPOTRF or DSYEVX returned an error code: */ |
| 18195 |
/* <= N: if INFO = i, DSYEVX failed to converge; */ |
| 18196 |
/* i eigenvectors failed to converge. Their indices */ |
| 18197 |
/* are stored in array IFAIL. */ |
| 18198 |
/* > N: if INFO = N + i, for 1 <= i <= N, then the leading */ |
| 18199 |
/* minor of order i of B is not positive definite. */ |
| 18200 |
/* The factorization of B could not be completed and */ |
| 18201 |
/* no eigenvalues or eigenvectors were computed. */ |
| 18202 |
|
| 18203 |
/* Further Details */ |
| 18204 |
/* =============== */ |
| 18205 |
|
| 18206 |
/* Based on contributions by */ |
| 18207 |
/* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */ |
| 18208 |
|
| 18209 |
/* ===================================================================== */ |
| 18210 |
|
| 18211 |
/* .. Parameters .. */ |
| 18212 |
/* .. */ |
| 18213 |
/* .. Local Scalars .. */ |
| 18214 |
/* .. */ |
| 18215 |
/* .. External Functions .. */ |
| 18216 |
/* .. */ |
| 18217 |
/* .. External Subroutines .. */ |
| 18218 |
/* .. */ |
| 18219 |
/* .. Intrinsic Functions .. */ |
| 18220 |
/* .. */ |
| 18221 |
/* .. Executable Statements .. */ |
| 18222 |
|
| 18223 |
/* Test the input parameters. */ |
| 18224 |
|
| 18225 |
/* Parameter adjustments */ |
| 18226 |
a_dim1 = *lda; |
| 18227 |
a_offset = 1 + a_dim1; |
| 18228 |
a -= a_offset; |
| 18229 |
b_dim1 = *ldb; |
| 18230 |
b_offset = 1 + b_dim1; |
| 18231 |
b -= b_offset; |
| 18232 |
--w; |
| 18233 |
z_dim1 = *ldz; |
| 18234 |
z_offset = 1 + z_dim1; |
| 18235 |
z__ -= z_offset; |
| 18236 |
--work; |
| 18237 |
--iwork; |
| 18238 |
--ifail; |
| 18239 |
|
| 18240 |
/* Function Body */ |
| 18241 |
upper = lsame_(uplo, "U"); |
| 18242 |
wantz = lsame_(jobz, "V"); |
| 18243 |
alleig = lsame_(range, "A"); |
| 18244 |
valeig = lsame_(range, "V"); |
| 18245 |
indeig = lsame_(range, "I"); |
| 18246 |
lquery = *lwork == -1; |
| 18247 |
|
| 18248 |
*info = 0; |
| 18249 |
if (*itype < 1 || *itype > 3) { |
| 18250 |
*info = -1; |
| 18251 |
} else if (! (wantz || lsame_(jobz, "N"))) { |
| 18252 |
*info = -2; |
| 18253 |
} else if (! (alleig || valeig || indeig)) { |
| 18254 |
*info = -3; |
| 18255 |
} else if (! (upper || lsame_(uplo, "L"))) { |
| 18256 |
*info = -4; |
| 18257 |
} else if (*n < 0) { |
| 18258 |
*info = -5; |
| 18259 |
} else if (*lda < std::max(1_integer,*n)) { |
| 18260 |
*info = -7; |
| 18261 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 18262 |
*info = -9; |
| 18263 |
} else { |
| 18264 |
if (valeig) { |
| 18265 |
if (*n > 0 && *vu <= *vl) { |
| 18266 |
*info = -11; |
| 18267 |
} |
| 18268 |
} else if (indeig) { |
| 18269 |
if (*il < 1 || *il > std::max(1_integer,*n)) { |
| 18270 |
*info = -12; |
| 18271 |
} else if (*iu < std::min(*n,*il) || *iu > *n) { |
| 18272 |
*info = -13; |
| 18273 |
} |
| 18274 |
} |
| 18275 |
} |
| 18276 |
if (*info == 0) { |
| 18277 |
if (*ldz < 1 || wantz && *ldz < *n) { |
| 18278 |
*info = -18; |
| 18279 |
} |
| 18280 |
} |
| 18281 |
|
| 18282 |
if (*info == 0) { |
| 18283 |
/* Computing MAX */ |
| 18284 |
i__1 = 1, i__2 = *n << 3; |
| 18285 |
lwkmin = std::max(i__1,i__2); |
| 18286 |
nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1); |
| 18287 |
/* Computing MAX */ |
| 18288 |
i__1 = lwkmin, i__2 = (nb + 3) * *n; |
| 18289 |
lwkopt = std::max(i__1,i__2); |
| 18290 |
work[1] = (double) lwkopt; |
| 18291 |
|
| 18292 |
if (*lwork < lwkmin && ! lquery) { |
| 18293 |
*info = -20; |
| 18294 |
} |
| 18295 |
} |
| 18296 |
|
| 18297 |
if (*info != 0) { |
| 18298 |
i__1 = -(*info); |
| 18299 |
xerbla_("DSYGVX", &i__1); |
| 18300 |
return 0; |
| 18301 |
} else if (lquery) { |
| 18302 |
return 0; |
| 18303 |
} |
| 18304 |
|
| 18305 |
/* Quick return if possible */ |
| 18306 |
|
| 18307 |
*m = 0; |
| 18308 |
if (*n == 0) { |
| 18309 |
return 0; |
| 18310 |
} |
| 18311 |
|
| 18312 |
/* Form a Cholesky factorization of B. */ |
| 18313 |
|
| 18314 |
dpotrf_(uplo, n, &b[b_offset], ldb, info); |
| 18315 |
if (*info != 0) { |
| 18316 |
*info = *n + *info; |
| 18317 |
return 0; |
| 18318 |
} |
| 18319 |
|
| 18320 |
/* Transform problem to standard eigenvalue problem and solve. */ |
| 18321 |
|
| 18322 |
dsygst_(itype, uplo, n, &a[a_offset], lda, &b[b_offset], ldb, info); |
| 18323 |
dsyevx_(jobz, range, uplo, n, &a[a_offset], lda, vl, vu, il, iu, abstol, |
| 18324 |
m, &w[1], &z__[z_offset], ldz, &work[1], lwork, &iwork[1], &ifail[ |
| 18325 |
1], info); |
| 18326 |
|
| 18327 |
if (wantz) { |
| 18328 |
|
| 18329 |
/* Backtransform eigenvectors to the original problem. */ |
| 18330 |
|
| 18331 |
if (*info > 0) { |
| 18332 |
*m = *info - 1; |
| 18333 |
} |
| 18334 |
if (*itype == 1 || *itype == 2) { |
| 18335 |
|
| 18336 |
/* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */ |
| 18337 |
/* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */ |
| 18338 |
|
| 18339 |
if (upper) { |
| 18340 |
*(unsigned char *)trans = 'N'; |
| 18341 |
} else { |
| 18342 |
*(unsigned char *)trans = 'T'; |
| 18343 |
} |
| 18344 |
|
| 18345 |
dtrsm_("Left", uplo, trans, "Non-unit", n, m, &c_b19, &b[b_offset] |
| 18346 |
, ldb, &z__[z_offset], ldz); |
| 18347 |
|
| 18348 |
} else if (*itype == 3) { |
| 18349 |
|
| 18350 |
/* For B*A*x=(lambda)*x; */ |
| 18351 |
/* backtransform eigenvectors: x = L*y or U'*y */ |
| 18352 |
|
| 18353 |
if (upper) { |
| 18354 |
*(unsigned char *)trans = 'T'; |
| 18355 |
} else { |
| 18356 |
*(unsigned char *)trans = 'N'; |
| 18357 |
} |
| 18358 |
|
| 18359 |
dtrmm_("Left", uplo, trans, "Non-unit", n, m, &c_b19, &b[b_offset] |
| 18360 |
, ldb, &z__[z_offset], ldz); |
| 18361 |
} |
| 18362 |
} |
| 18363 |
|
| 18364 |
/* Set WORK(1) to optimal workspace size. */ |
| 18365 |
|
| 18366 |
work[1] = (double) lwkopt; |
| 18367 |
|
| 18368 |
return 0; |
| 18369 |
|
| 18370 |
/* End of DSYGVX */ |
| 18371 |
|
| 18372 |
} /* dsygvx_ */ |
| 18373 |
|
| 18374 |
/* Subroutine */ int dsyrfs_(const char *uplo, integer *n, integer *nrhs, |
| 18375 |
double *a, integer *lda, double *af, integer *ldaf, integer * |
| 18376 |
ipiv, double *b, integer *ldb, double *x, integer *ldx, |
| 18377 |
double *ferr, double *berr, double *work, integer *iwork, |
| 18378 |
integer *info) |
| 18379 |
{ |
| 18380 |
/* Table of constant values */ |
| 18381 |
static integer c__1 = 1; |
| 18382 |
static double c_b12 = -1.; |
| 18383 |
static double c_b14 = 1.; |
| 18384 |
|
| 18385 |
/* System generated locals */ |
| 18386 |
integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, |
| 18387 |
x_offset, i__1, i__2, i__3; |
| 18388 |
double d__1, d__2, d__3; |
| 18389 |
|
| 18390 |
/* Local variables */ |
| 18391 |
integer i__, j, k; |
| 18392 |
double s, xk; |
| 18393 |
integer nz; |
| 18394 |
double eps; |
| 18395 |
integer kase; |
| 18396 |
double safe1, safe2; |
| 18397 |
integer isave[3]; |
| 18398 |
integer count; |
| 18399 |
bool upper; |
| 18400 |
double safmin; |
| 18401 |
double lstres; |
| 18402 |
|
| 18403 |
/* -- LAPACK routine (version 3.1) -- */ |
| 18404 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 18405 |
/* November 2006 */ |
| 18406 |
|
| 18407 |
/* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */ |
| 18408 |
|
| 18409 |
/* .. Scalar Arguments .. */ |
| 18410 |
/* .. */ |
| 18411 |
/* .. Array Arguments .. */ |
| 18412 |
/* .. */ |
| 18413 |
|
| 18414 |
/* Purpose */ |
| 18415 |
/* ======= */ |
| 18416 |
|
| 18417 |
/* DSYRFS improves the computed solution to a system of linear */ |
| 18418 |
/* equations when the coefficient matrix is symmetric indefinite, and */ |
| 18419 |
/* provides error bounds and backward error estimates for the solution. */ |
| 18420 |
|
| 18421 |
/* Arguments */ |
| 18422 |
/* ========= */ |
| 18423 |
|
| 18424 |
/* UPLO (input) CHARACTER*1 */ |
| 18425 |
/* = 'U': Upper triangle of A is stored; */ |
| 18426 |
/* = 'L': Lower triangle of A is stored. */ |
| 18427 |
|
| 18428 |
/* N (input) INTEGER */ |
| 18429 |
/* The order of the matrix A. N >= 0. */ |
| 18430 |
|
| 18431 |
/* NRHS (input) INTEGER */ |
| 18432 |
/* The number of right hand sides, i.e., the number of columns */ |
| 18433 |
/* of the matrices B and X. NRHS >= 0. */ |
| 18434 |
|
| 18435 |
/* A (input) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 18436 |
/* The symmetric matrix A. If UPLO = 'U', the leading N-by-N */ |
| 18437 |
/* upper triangular part of A contains the upper triangular part */ |
| 18438 |
/* of the matrix A, and the strictly lower triangular part of A */ |
| 18439 |
/* is not referenced. If UPLO = 'L', the leading N-by-N lower */ |
| 18440 |
/* triangular part of A contains the lower triangular part of */ |
| 18441 |
/* the matrix A, and the strictly upper triangular part of A is */ |
| 18442 |
/* not referenced. */ |
| 18443 |
|
| 18444 |
/* LDA (input) INTEGER */ |
| 18445 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 18446 |
|
| 18447 |
/* AF (input) DOUBLE PRECISION array, dimension (LDAF,N) */ |
| 18448 |
/* The factored form of the matrix A. AF contains the block */ |
| 18449 |
/* diagonal matrix D and the multipliers used to obtain the */ |
| 18450 |
/* factor U or L from the factorization A = U*D*U**T or */ |
| 18451 |
/* A = L*D*L**T as computed by DSYTRF. */ |
| 18452 |
|
| 18453 |
/* LDAF (input) INTEGER */ |
| 18454 |
/* The leading dimension of the array AF. LDAF >= max(1,N). */ |
| 18455 |
|
| 18456 |
/* IPIV (input) INTEGER array, dimension (N) */ |
| 18457 |
/* Details of the interchanges and the block structure of D */ |
| 18458 |
/* as determined by DSYTRF. */ |
| 18459 |
|
| 18460 |
/* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 18461 |
/* The right hand side matrix B. */ |
| 18462 |
|
| 18463 |
/* LDB (input) INTEGER */ |
| 18464 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 18465 |
|
| 18466 |
/* X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */ |
| 18467 |
/* On entry, the solution matrix X, as computed by DSYTRS. */ |
| 18468 |
/* On exit, the improved solution matrix X. */ |
| 18469 |
|
| 18470 |
/* LDX (input) INTEGER */ |
| 18471 |
/* The leading dimension of the array X. LDX >= max(1,N). */ |
| 18472 |
|
| 18473 |
/* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 18474 |
/* The estimated forward error bound for each solution vector */ |
| 18475 |
/* X(j) (the j-th column of the solution matrix X). */ |
| 18476 |
/* If XTRUE is the true solution corresponding to X(j), FERR(j) */ |
| 18477 |
/* is an estimated upper bound for the magnitude of the largest */ |
| 18478 |
/* element in (X(j) - XTRUE) divided by the magnitude of the */ |
| 18479 |
/* largest element in X(j). The estimate is as reliable as */ |
| 18480 |
/* the estimate for RCOND, and is almost always a slight */ |
| 18481 |
/* overestimate of the true error. */ |
| 18482 |
|
| 18483 |
/* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 18484 |
/* The componentwise relative backward error of each solution */ |
| 18485 |
/* vector X(j) (i.e., the smallest relative change in */ |
| 18486 |
/* any element of A or B that makes X(j) an exact solution). */ |
| 18487 |
|
| 18488 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */ |
| 18489 |
|
| 18490 |
/* IWORK (workspace) INTEGER array, dimension (N) */ |
| 18491 |
|
| 18492 |
/* INFO (output) INTEGER */ |
| 18493 |
/* = 0: successful exit */ |
| 18494 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 18495 |
|
| 18496 |
/* Internal Parameters */ |
| 18497 |
/* =================== */ |
| 18498 |
|
| 18499 |
/* ITMAX is the maximum number of steps of iterative refinement. */ |
| 18500 |
|
| 18501 |
/* ===================================================================== */ |
| 18502 |
|
| 18503 |
/* .. Parameters .. */ |
| 18504 |
/* .. */ |
| 18505 |
/* .. Local Scalars .. */ |
| 18506 |
/* .. */ |
| 18507 |
/* .. Local Arrays .. */ |
| 18508 |
/* .. */ |
| 18509 |
/* .. External Subroutines .. */ |
| 18510 |
/* .. */ |
| 18511 |
/* .. Intrinsic Functions .. */ |
| 18512 |
/* .. */ |
| 18513 |
/* .. External Functions .. */ |
| 18514 |
/* .. */ |
| 18515 |
/* .. Executable Statements .. */ |
| 18516 |
|
| 18517 |
/* Test the input parameters. */ |
| 18518 |
|
| 18519 |
/* Parameter adjustments */ |
| 18520 |
a_dim1 = *lda; |
| 18521 |
a_offset = 1 + a_dim1; |
| 18522 |
a -= a_offset; |
| 18523 |
af_dim1 = *ldaf; |
| 18524 |
af_offset = 1 + af_dim1; |
| 18525 |
af -= af_offset; |
| 18526 |
--ipiv; |
| 18527 |
b_dim1 = *ldb; |
| 18528 |
b_offset = 1 + b_dim1; |
| 18529 |
b -= b_offset; |
| 18530 |
x_dim1 = *ldx; |
| 18531 |
x_offset = 1 + x_dim1; |
| 18532 |
x -= x_offset; |
| 18533 |
--ferr; |
| 18534 |
--berr; |
| 18535 |
--work; |
| 18536 |
--iwork; |
| 18537 |
|
| 18538 |
/* Function Body */ |
| 18539 |
*info = 0; |
| 18540 |
upper = lsame_(uplo, "U"); |
| 18541 |
if (! upper && ! lsame_(uplo, "L")) { |
| 18542 |
*info = -1; |
| 18543 |
} else if (*n < 0) { |
| 18544 |
*info = -2; |
| 18545 |
} else if (*nrhs < 0) { |
| 18546 |
*info = -3; |
| 18547 |
} else if (*lda < std::max(1_integer,*n)) { |
| 18548 |
*info = -5; |
| 18549 |
} else if (*ldaf < std::max(1_integer,*n)) { |
| 18550 |
*info = -7; |
| 18551 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 18552 |
*info = -10; |
| 18553 |
} else if (*ldx < std::max(1_integer,*n)) { |
| 18554 |
*info = -12; |
| 18555 |
} |
| 18556 |
if (*info != 0) { |
| 18557 |
i__1 = -(*info); |
| 18558 |
xerbla_("DSYRFS", &i__1); |
| 18559 |
return 0; |
| 18560 |
} |
| 18561 |
|
| 18562 |
/* Quick return if possible */ |
| 18563 |
|
| 18564 |
if (*n == 0 || *nrhs == 0) { |
| 18565 |
i__1 = *nrhs; |
| 18566 |
for (j = 1; j <= i__1; ++j) { |
| 18567 |
ferr[j] = 0.; |
| 18568 |
berr[j] = 0.; |
| 18569 |
/* L10: */ |
| 18570 |
} |
| 18571 |
return 0; |
| 18572 |
} |
| 18573 |
|
| 18574 |
/* NZ = maximum number of nonzero elements in each row of A, plus 1 */ |
| 18575 |
|
| 18576 |
nz = *n + 1; |
| 18577 |
eps = dlamch_("Epsilon"); |
| 18578 |
safmin = dlamch_("Safe minimum"); |
| 18579 |
safe1 = nz * safmin; |
| 18580 |
safe2 = safe1 / eps; |
| 18581 |
|
| 18582 |
/* Do for each right hand side */ |
| 18583 |
|
| 18584 |
i__1 = *nrhs; |
| 18585 |
for (j = 1; j <= i__1; ++j) { |
| 18586 |
|
| 18587 |
count = 1; |
| 18588 |
lstres = 3.; |
| 18589 |
L20: |
| 18590 |
|
| 18591 |
/* Loop until stopping criterion is satisfied. */ |
| 18592 |
|
| 18593 |
/* Compute residual R = B - A * X */ |
| 18594 |
|
| 18595 |
dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1); |
| 18596 |
dsymv_(uplo, n, &c_b12, &a[a_offset], lda, &x[j * x_dim1 + 1], &c__1, |
| 18597 |
&c_b14, &work[*n + 1], &c__1); |
| 18598 |
|
| 18599 |
/* Compute componentwise relative backward error from formula */ |
| 18600 |
|
| 18601 |
/* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */ |
| 18602 |
|
| 18603 |
/* where abs(Z) is the componentwise absolute value of the matrix */ |
| 18604 |
/* or vector Z. If the i-th component of the denominator is less */ |
| 18605 |
/* than SAFE2, then SAFE1 is added to the i-th components of the */ |
| 18606 |
/* numerator and denominator before dividing. */ |
| 18607 |
|
| 18608 |
i__2 = *n; |
| 18609 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 18610 |
work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1)); |
| 18611 |
/* L30: */ |
| 18612 |
} |
| 18613 |
|
| 18614 |
/* Compute abs(A)*abs(X) + abs(B). */ |
| 18615 |
|
| 18616 |
if (upper) { |
| 18617 |
i__2 = *n; |
| 18618 |
for (k = 1; k <= i__2; ++k) { |
| 18619 |
s = 0.; |
| 18620 |
xk = (d__1 = x[k + j * x_dim1], abs(d__1)); |
| 18621 |
i__3 = k - 1; |
| 18622 |
for (i__ = 1; i__ <= i__3; ++i__) { |
| 18623 |
work[i__] += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * xk; |
| 18624 |
s += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * (d__2 = x[ |
| 18625 |
i__ + j * x_dim1], abs(d__2)); |
| 18626 |
/* L40: */ |
| 18627 |
} |
| 18628 |
work[k] = work[k] + (d__1 = a[k + k * a_dim1], abs(d__1)) * |
| 18629 |
xk + s; |
| 18630 |
/* L50: */ |
| 18631 |
} |
| 18632 |
} else { |
| 18633 |
i__2 = *n; |
| 18634 |
for (k = 1; k <= i__2; ++k) { |
| 18635 |
s = 0.; |
| 18636 |
xk = (d__1 = x[k + j * x_dim1], abs(d__1)); |
| 18637 |
work[k] += (d__1 = a[k + k * a_dim1], abs(d__1)) * xk; |
| 18638 |
i__3 = *n; |
| 18639 |
for (i__ = k + 1; i__ <= i__3; ++i__) { |
| 18640 |
work[i__] += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * xk; |
| 18641 |
s += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * (d__2 = x[ |
| 18642 |
i__ + j * x_dim1], abs(d__2)); |
| 18643 |
/* L60: */ |
| 18644 |
} |
| 18645 |
work[k] += s; |
| 18646 |
/* L70: */ |
| 18647 |
} |
| 18648 |
} |
| 18649 |
s = 0.; |
| 18650 |
i__2 = *n; |
| 18651 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 18652 |
if (work[i__] > safe2) { |
| 18653 |
/* Computing MAX */ |
| 18654 |
d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[ |
| 18655 |
i__]; |
| 18656 |
s = std::max(d__2,d__3); |
| 18657 |
} else { |
| 18658 |
/* Computing MAX */ |
| 18659 |
d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1) |
| 18660 |
/ (work[i__] + safe1); |
| 18661 |
s = std::max(d__2,d__3); |
| 18662 |
} |
| 18663 |
/* L80: */ |
| 18664 |
} |
| 18665 |
berr[j] = s; |
| 18666 |
|
| 18667 |
/* Test stopping criterion. Continue iterating if */ |
| 18668 |
/* 1) The residual BERR(J) is larger than machine epsilon, and */ |
| 18669 |
/* 2) BERR(J) decreased by at least a factor of 2 during the */ |
| 18670 |
/* last iteration, and */ |
| 18671 |
/* 3) At most ITMAX iterations tried. */ |
| 18672 |
|
| 18673 |
if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) { |
| 18674 |
|
| 18675 |
/* Update solution and try again. */ |
| 18676 |
|
| 18677 |
dsytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[*n |
| 18678 |
+ 1], n, info); |
| 18679 |
daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1) |
| 18680 |
; |
| 18681 |
lstres = berr[j]; |
| 18682 |
++count; |
| 18683 |
goto L20; |
| 18684 |
} |
| 18685 |
|
| 18686 |
/* Bound error from formula */ |
| 18687 |
|
| 18688 |
/* norm(X - XTRUE) / norm(X) .le. FERR = */ |
| 18689 |
/* norm( abs(inv(A))* */ |
| 18690 |
/* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */ |
| 18691 |
|
| 18692 |
/* where */ |
| 18693 |
/* norm(Z) is the magnitude of the largest component of Z */ |
| 18694 |
/* inv(A) is the inverse of A */ |
| 18695 |
/* abs(Z) is the componentwise absolute value of the matrix or */ |
| 18696 |
/* vector Z */ |
| 18697 |
/* NZ is the maximum number of nonzeros in any row of A, plus 1 */ |
| 18698 |
/* EPS is machine epsilon */ |
| 18699 |
|
| 18700 |
/* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */ |
| 18701 |
/* is incremented by SAFE1 if the i-th component of */ |
| 18702 |
/* abs(A)*abs(X) + abs(B) is less than SAFE2. */ |
| 18703 |
|
| 18704 |
/* Use DLACN2 to estimate the infinity-norm of the matrix */ |
| 18705 |
/* inv(A) * diag(W), */ |
| 18706 |
/* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */ |
| 18707 |
|
| 18708 |
i__2 = *n; |
| 18709 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 18710 |
if (work[i__] > safe2) { |
| 18711 |
work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * |
| 18712 |
work[i__]; |
| 18713 |
} else { |
| 18714 |
work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * |
| 18715 |
work[i__] + safe1; |
| 18716 |
} |
| 18717 |
/* L90: */ |
| 18718 |
} |
| 18719 |
|
| 18720 |
kase = 0; |
| 18721 |
L100: |
| 18722 |
dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], & |
| 18723 |
kase, isave); |
| 18724 |
if (kase != 0) { |
| 18725 |
if (kase == 1) { |
| 18726 |
|
| 18727 |
/* Multiply by diag(W)*inv(A'). */ |
| 18728 |
|
| 18729 |
dsytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ |
| 18730 |
*n + 1], n, info); |
| 18731 |
i__2 = *n; |
| 18732 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 18733 |
work[*n + i__] = work[i__] * work[*n + i__]; |
| 18734 |
/* L110: */ |
| 18735 |
} |
| 18736 |
} else if (kase == 2) { |
| 18737 |
|
| 18738 |
/* Multiply by inv(A)*diag(W). */ |
| 18739 |
|
| 18740 |
i__2 = *n; |
| 18741 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 18742 |
work[*n + i__] = work[i__] * work[*n + i__]; |
| 18743 |
/* L120: */ |
| 18744 |
} |
| 18745 |
dsytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[ |
| 18746 |
*n + 1], n, info); |
| 18747 |
} |
| 18748 |
goto L100; |
| 18749 |
} |
| 18750 |
|
| 18751 |
/* Normalize error. */ |
| 18752 |
|
| 18753 |
lstres = 0.; |
| 18754 |
i__2 = *n; |
| 18755 |
for (i__ = 1; i__ <= i__2; ++i__) { |
| 18756 |
/* Computing MAX */ |
| 18757 |
d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1)); |
| 18758 |
lstres = std::max(d__2,d__3); |
| 18759 |
/* L130: */ |
| 18760 |
} |
| 18761 |
if (lstres != 0.) { |
| 18762 |
ferr[j] /= lstres; |
| 18763 |
} |
| 18764 |
|
| 18765 |
/* L140: */ |
| 18766 |
} |
| 18767 |
|
| 18768 |
return 0; |
| 18769 |
|
| 18770 |
/* End of DSYRFS */ |
| 18771 |
|
| 18772 |
} /* dsyrfs_ */ |
| 18773 |
|
| 18774 |
#if 0 |
| 18775 |
int dsyrfsx_(const char *uplo, const char *equed, integer *n, integer *nrhs, double *a, |
| 18776 |
integer *lda, double *af, integer *ldaf, integer *ipiv, double *s, double *b, integer *ldb, |
| 18777 |
double *x, integer *ldx, double *rcond, double *berr, integer *n_err_bnds__, |
| 18778 |
double *err_bnds_norm__, double *err_bnds_comp__, integer *nparams, double *params, |
| 18779 |
double *work, integer *iwork, integer *info) |
| 18780 |
{ |
| 18781 |
/* Table of constant values */ |
| 18782 |
static integer c_n1 = -1; |
| 18783 |
static integer c__0 = 0; |
| 18784 |
static integer c__1 = 1; |
| 18785 |
|
| 18786 |
/* System generated locals */ |
| 18787 |
integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, |
| 18788 |
x_offset, err_bnds_norm_dim1, err_bnds_norm_offset, |
| 18789 |
err_bnds_comp_dim1, err_bnds_comp_offset, i__1; |
| 18790 |
double d__1, d__2; |
| 18791 |
|
| 18792 |
/* Local variables */ |
| 18793 |
double illrcond_thresh__, unstable_thresh__, err_lbnd__; |
| 18794 |
integer ref_type__, j; |
| 18795 |
double rcond_tmp__; |
| 18796 |
integer prec_type__; |
| 18797 |
double cwise_wrong__; |
| 18798 |
char norm[1]; |
| 18799 |
bool ignore_cwise__; |
| 18800 |
double anorm; |
| 18801 |
bool rcequ; |
| 18802 |
integer ithresh, n_norms__; |
| 18803 |
double rthresh; |
| 18804 |
|
| 18805 |
|
| 18806 |
/* -- LAPACK routine (version 3.2.1) -- */ |
| 18807 |
/* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */ |
| 18808 |
/* -- Jason Riedy of Univ. of California Berkeley. -- */ |
| 18809 |
/* -- April 2009 -- */ |
| 18810 |
|
| 18811 |
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ |
| 18812 |
/* -- Univ. of California Berkeley and NAG Ltd. -- */ |
| 18813 |
|
| 18814 |
/* .. */ |
| 18815 |
/* .. Scalar Arguments .. */ |
| 18816 |
/* .. */ |
| 18817 |
/* .. Array Arguments .. */ |
| 18818 |
/* .. */ |
| 18819 |
|
| 18820 |
/* Purpose */ |
| 18821 |
/* ======= */ |
| 18822 |
|
| 18823 |
/* DSYRFSX improves the computed solution to a system of linear */ |
| 18824 |
/* equations when the coefficient matrix is symmetric indefinite, and */ |
| 18825 |
/* provides error bounds and backward error estimates for the */ |
| 18826 |
/* solution. In addition to normwise error bound, the code provides */ |
| 18827 |
/* maximum componentwise error bound if possible. See comments for */ |
| 18828 |
/* ERR_BNDS_NORM and ERR_BNDS_COMP for details of the error bounds. */ |
| 18829 |
|
| 18830 |
/* The original system of linear equations may have been equilibrated */ |
| 18831 |
/* before calling this routine, as described by arguments EQUED and S */ |
| 18832 |
/* below. In this case, the solution and error bounds returned are */ |
| 18833 |
/* for the original unequilibrated system. */ |
| 18834 |
|
| 18835 |
/* Arguments */ |
| 18836 |
/* ========= */ |
| 18837 |
|
| 18838 |
/* Some optional parameters are bundled in the PARAMS array. These */ |
| 18839 |
/* settings determine how refinement is performed, but often the */ |
| 18840 |
/* defaults are acceptable. If the defaults are acceptable, users */ |
| 18841 |
/* can pass NPARAMS = 0 which prevents the source code from accessing */ |
| 18842 |
/* the PARAMS argument. */ |
| 18843 |
|
| 18844 |
/* UPLO (input) CHARACTER*1 */ |
| 18845 |
/* = 'U': Upper triangle of A is stored; */ |
| 18846 |
/* = 'L': Lower triangle of A is stored. */ |
| 18847 |
|
| 18848 |
/* EQUED (input) CHARACTER*1 */ |
| 18849 |
/* Specifies the form of equilibration that was done to A */ |
| 18850 |
/* before calling this routine. This is needed to compute */ |
| 18851 |
/* the solution and error bounds correctly. */ |
| 18852 |
/* = 'N': No equilibration */ |
| 18853 |
/* = 'Y': Both row and column equilibration, i.e., A has been */ |
| 18854 |
/* replaced by diag(S) * A * diag(S). */ |
| 18855 |
/* The right hand side B has been changed accordingly. */ |
| 18856 |
|
| 18857 |
/* N (input) INTEGER */ |
| 18858 |
/* The order of the matrix A. N >= 0. */ |
| 18859 |
|
| 18860 |
/* NRHS (input) INTEGER */ |
| 18861 |
/* The number of right hand sides, i.e., the number of columns */ |
| 18862 |
/* of the matrices B and X. NRHS >= 0. */ |
| 18863 |
|
| 18864 |
/* A (input) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 18865 |
/* The symmetric matrix A. If UPLO = 'U', the leading N-by-N */ |
| 18866 |
/* upper triangular part of A contains the upper triangular */ |
| 18867 |
/* part of the matrix A, and the strictly lower triangular */ |
| 18868 |
/* part of A is not referenced. If UPLO = 'L', the leading */ |
| 18869 |
/* N-by-N lower triangular part of A contains the lower */ |
| 18870 |
/* triangular part of the matrix A, and the strictly upper */ |
| 18871 |
/* triangular part of A is not referenced. */ |
| 18872 |
|
| 18873 |
/* LDA (input) INTEGER */ |
| 18874 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 18875 |
|
| 18876 |
/* AF (input) DOUBLE PRECISION array, dimension (LDAF,N) */ |
| 18877 |
/* The factored form of the matrix A. AF contains the block */ |
| 18878 |
/* diagonal matrix D and the multipliers used to obtain the */ |
| 18879 |
/* factor U or L from the factorization A = U*D*U**T or A = */ |
| 18880 |
/* L*D*L**T as computed by DSYTRF. */ |
| 18881 |
|
| 18882 |
/* LDAF (input) INTEGER */ |
| 18883 |
/* The leading dimension of the array AF. LDAF >= max(1,N). */ |
| 18884 |
|
| 18885 |
/* IPIV (input) INTEGER array, dimension (N) */ |
| 18886 |
/* Details of the interchanges and the block structure of D */ |
| 18887 |
/* as determined by DSYTRF. */ |
| 18888 |
|
| 18889 |
/* S (input or output) DOUBLE PRECISION array, dimension (N) */ |
| 18890 |
/* The scale factors for A. If EQUED = 'Y', A is multiplied on */ |
| 18891 |
/* the left and right by diag(S). S is an input argument if FACT = */ |
| 18892 |
/* 'F'; otherwise, S is an output argument. If FACT = 'F' and EQUED */ |
| 18893 |
/* = 'Y', each element of S must be positive. If S is output, each */ |
| 18894 |
/* element of S is a power of the radix. If S is input, each element */ |
| 18895 |
/* of S should be a power of the radix to ensure a reliable solution */ |
| 18896 |
/* and error estimates. Scaling by powers of the radix does not cause */ |
| 18897 |
/* rounding errors unless the result underflows or overflows. */ |
| 18898 |
/* Rounding errors during scaling lead to refining with a matrix that */ |
| 18899 |
/* is not equivalent to the input matrix, producing error estimates */ |
| 18900 |
/* that may not be reliable. */ |
| 18901 |
|
| 18902 |
/* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 18903 |
/* The right hand side matrix B. */ |
| 18904 |
|
| 18905 |
/* LDB (input) INTEGER */ |
| 18906 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 18907 |
|
| 18908 |
/* X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */ |
| 18909 |
/* On entry, the solution matrix X, as computed by DGETRS. */ |
| 18910 |
/* On exit, the improved solution matrix X. */ |
| 18911 |
|
| 18912 |
/* LDX (input) INTEGER */ |
| 18913 |
/* The leading dimension of the array X. LDX >= max(1,N). */ |
| 18914 |
|
| 18915 |
/* RCOND (output) DOUBLE PRECISION */ |
| 18916 |
/* Reciprocal scaled condition number. This is an estimate of the */ |
| 18917 |
/* reciprocal Skeel condition number of the matrix A after */ |
| 18918 |
/* equilibration (if done). If this is less than the machine */ |
| 18919 |
/* precision (in particular, if it is zero), the matrix is singular */ |
| 18920 |
/* to working precision. Note that the error may still be small even */ |
| 18921 |
/* if this number is very small and the matrix appears ill- */ |
| 18922 |
/* conditioned. */ |
| 18923 |
|
| 18924 |
/* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 18925 |
/* Componentwise relative backward error. This is the */ |
| 18926 |
/* componentwise relative backward error of each solution vector X(j) */ |
| 18927 |
/* (i.e., the smallest relative change in any element of A or B that */ |
| 18928 |
/* makes X(j) an exact solution). */ |
| 18929 |
|
| 18930 |
/* N_ERR_BNDS (input) INTEGER */ |
| 18931 |
/* Number of error bounds to return for each right hand side */ |
| 18932 |
/* and each type (normwise or componentwise). See ERR_BNDS_NORM and */ |
| 18933 |
/* ERR_BNDS_COMP below. */ |
| 18934 |
|
| 18935 |
/* ERR_BNDS_NORM (output) DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) */ |
| 18936 |
/* For each right-hand side, this array contains information about */ |
| 18937 |
/* various error bounds and condition numbers corresponding to the */ |
| 18938 |
/* normwise relative error, which is defined as follows: */ |
| 18939 |
|
| 18940 |
/* Normwise relative error in the ith solution vector: */ |
| 18941 |
/* max_j (abs(XTRUE(j,i) - X(j,i))) */ |
| 18942 |
/* ------------------------------ */ |
| 18943 |
/* max_j abs(X(j,i)) */ |
| 18944 |
|
| 18945 |
/* The array is indexed by the type of error information as described */ |
| 18946 |
/* below. There currently are up to three pieces of information */ |
| 18947 |
/* returned. */ |
| 18948 |
|
| 18949 |
/* The first index in ERR_BNDS_NORM(i,:) corresponds to the ith */ |
| 18950 |
/* right-hand side. */ |
| 18951 |
|
| 18952 |
/* The second index in ERR_BNDS_NORM(:,err) contains the following */ |
| 18953 |
/* three fields: */ |
| 18954 |
/* err = 1 "Trust/don't trust" boolean. Trust the answer if the */ |
| 18955 |
/* reciprocal condition number is less than the threshold */ |
| 18956 |
/* sqrt(n) * dlamch('Epsilon'). */ |
| 18957 |
|
| 18958 |
/* err = 2 "Guaranteed" error bound: The estimated forward error, */ |
| 18959 |
/* almost certainly within a factor of 10 of the true error */ |
| 18960 |
/* so long as the next entry is greater than the threshold */ |
| 18961 |
/* sqrt(n) * dlamch('Epsilon'). This error bound should only */ |
| 18962 |
/* be trusted if the previous boolean is true. */ |
| 18963 |
|
| 18964 |
/* err = 3 Reciprocal condition number: Estimated normwise */ |
| 18965 |
/* reciprocal condition number. Compared with the threshold */ |
| 18966 |
/* sqrt(n) * dlamch('Epsilon') to determine if the error */ |
| 18967 |
/* estimate is "guaranteed". These reciprocal condition */ |
| 18968 |
/* numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */ |
| 18969 |
/* appropriately scaled matrix Z. */ |
| 18970 |
/* Let Z = S*A, where S scales each row by a power of the */ |
| 18971 |
/* radix so all absolute row sums of Z are approximately 1. */ |
| 18972 |
|
| 18973 |
/* See Lapack Working Note 165 for further details and extra */ |
| 18974 |
/* cautions. */ |
| 18975 |
|
| 18976 |
/* ERR_BNDS_COMP (output) DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) */ |
| 18977 |
/* For each right-hand side, this array contains information about */ |
| 18978 |
/* various error bounds and condition numbers corresponding to the */ |
| 18979 |
/* componentwise relative error, which is defined as follows: */ |
| 18980 |
|
| 18981 |
/* Componentwise relative error in the ith solution vector: */ |
| 18982 |
/* abs(XTRUE(j,i) - X(j,i)) */ |
| 18983 |
/* max_j ---------------------- */ |
| 18984 |
/* abs(X(j,i)) */ |
| 18985 |
|
| 18986 |
/* The array is indexed by the right-hand side i (on which the */ |
| 18987 |
/* componentwise relative error depends), and the type of error */ |
| 18988 |
/* information as described below. There currently are up to three */ |
| 18989 |
/* pieces of information returned for each right-hand side. If */ |
| 18990 |
/* componentwise accuracy is not requested (PARAMS(3) = 0.0), then */ |
| 18991 |
/* ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most */ |
| 18992 |
/* the first (:,N_ERR_BNDS) entries are returned. */ |
| 18993 |
|
| 18994 |
/* The first index in ERR_BNDS_COMP(i,:) corresponds to the ith */ |
| 18995 |
/* right-hand side. */ |
| 18996 |
|
| 18997 |
/* The second index in ERR_BNDS_COMP(:,err) contains the following */ |
| 18998 |
/* three fields: */ |
| 18999 |
/* err = 1 "Trust/don't trust" boolean. Trust the answer if the */ |
| 19000 |
/* reciprocal condition number is less than the threshold */ |
| 19001 |
/* sqrt(n) * dlamch('Epsilon'). */ |
| 19002 |
|
| 19003 |
/* err = 2 "Guaranteed" error bound: The estimated forward error, */ |
| 19004 |
/* almost certainly within a factor of 10 of the true error */ |
| 19005 |
/* so long as the next entry is greater than the threshold */ |
| 19006 |
/* sqrt(n) * dlamch('Epsilon'). This error bound should only */ |
| 19007 |
/* be trusted if the previous boolean is true. */ |
| 19008 |
|
| 19009 |
/* err = 3 Reciprocal condition number: Estimated componentwise */ |
| 19010 |
/* reciprocal condition number. Compared with the threshold */ |
| 19011 |
/* sqrt(n) * dlamch('Epsilon') to determine if the error */ |
| 19012 |
/* estimate is "guaranteed". These reciprocal condition */ |
| 19013 |
/* numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */ |
| 19014 |
/* appropriately scaled matrix Z. */ |
| 19015 |
/* Let Z = S*(A*diag(x)), where x is the solution for the */ |
| 19016 |
/* current right-hand side and S scales each row of */ |
| 19017 |
/* A*diag(x) by a power of the radix so all absolute row */ |
| 19018 |
/* sums of Z are approximately 1. */ |
| 19019 |
|
| 19020 |
/* See Lapack Working Note 165 for further details and extra */ |
| 19021 |
/* cautions. */ |
| 19022 |
|
| 19023 |
/* NPARAMS (input) INTEGER */ |
| 19024 |
/* Specifies the number of parameters set in PARAMS. If .LE. 0, the */ |
| 19025 |
/* PARAMS array is never referenced and default values are used. */ |
| 19026 |
|
| 19027 |
/* PARAMS (input / output) DOUBLE PRECISION array, dimension NPARAMS */ |
| 19028 |
/* Specifies algorithm parameters. If an entry is .LT. 0.0, then */ |
| 19029 |
/* that entry will be filled with default value used for that */ |
| 19030 |
/* parameter. Only positions up to NPARAMS are accessed; defaults */ |
| 19031 |
/* are used for higher-numbered parameters. */ |
| 19032 |
|
| 19033 |
/* PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative */ |
| 19034 |
/* refinement or not. */ |
| 19035 |
/* Default: 1.0D+0 */ |
| 19036 |
/* = 0.0 : No refinement is performed, and no error bounds are */ |
| 19037 |
/* computed. */ |
| 19038 |
/* = 1.0 : Use the double-precision refinement algorithm, */ |
| 19039 |
/* possibly with doubled-single computations if the */ |
| 19040 |
/* compilation environment does not support DOUBLE */ |
| 19041 |
/* PRECISION. */ |
| 19042 |
/* (other values are reserved for future use) */ |
| 19043 |
|
| 19044 |
/* PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual */ |
| 19045 |
/* computations allowed for refinement. */ |
| 19046 |
/* Default: 10 */ |
| 19047 |
/* Aggressive: Set to 100 to permit convergence using approximate */ |
| 19048 |
/* factorizations or factorizations other than LU. If */ |
| 19049 |
/* the factorization uses a technique other than */ |
| 19050 |
/* Gaussian elimination, the guarantees in */ |
| 19051 |
/* err_bnds_norm and err_bnds_comp may no longer be */ |
| 19052 |
/* trustworthy. */ |
| 19053 |
|
| 19054 |
/* PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code */ |
| 19055 |
/* will attempt to find a solution with small componentwise */ |
| 19056 |
/* relative error in the double-precision algorithm. Positive */ |
| 19057 |
/* is true, 0.0 is false. */ |
| 19058 |
/* Default: 1.0 (attempt componentwise convergence) */ |
| 19059 |
|
| 19060 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (4*N) */ |
| 19061 |
|
| 19062 |
/* IWORK (workspace) INTEGER array, dimension (N) */ |
| 19063 |
|
| 19064 |
/* INFO (output) INTEGER */ |
| 19065 |
/* = 0: Successful exit. The solution to every right-hand side is */ |
| 19066 |
/* guaranteed. */ |
| 19067 |
/* < 0: If INFO = -i, the i-th argument had an illegal value */ |
| 19068 |
/* > 0 and <= N: U(INFO,INFO) is exactly zero. The factorization */ |
| 19069 |
/* has been completed, but the factor U is exactly singular, so */ |
| 19070 |
/* the solution and error bounds could not be computed. RCOND = 0 */ |
| 19071 |
/* is returned. */ |
| 19072 |
/* = N+J: The solution corresponding to the Jth right-hand side is */ |
| 19073 |
/* not guaranteed. The solutions corresponding to other right- */ |
| 19074 |
/* hand sides K with K > J may not be guaranteed as well, but */ |
| 19075 |
/* only the first such right-hand side is reported. If a small */ |
| 19076 |
/* componentwise error is not requested (PARAMS(3) = 0.0) then */ |
| 19077 |
/* the Jth right-hand side is the first with a normwise error */ |
| 19078 |
/* bound that is not guaranteed (the smallest J such */ |
| 19079 |
/* that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0) */ |
| 19080 |
/* the Jth right-hand side is the first with either a normwise or */ |
| 19081 |
/* componentwise error bound that is not guaranteed (the smallest */ |
| 19082 |
/* J such that either ERR_BNDS_NORM(J,1) = 0.0 or */ |
| 19083 |
/* ERR_BNDS_COMP(J,1) = 0.0). See the definition of */ |
| 19084 |
/* ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information */ |
| 19085 |
/* about all of the right-hand sides check ERR_BNDS_NORM or */ |
| 19086 |
/* ERR_BNDS_COMP. */ |
| 19087 |
|
| 19088 |
/* ================================================================== */ |
| 19089 |
|
| 19090 |
/* .. Parameters .. */ |
| 19091 |
/* .. */ |
| 19092 |
/* .. Local Scalars .. */ |
| 19093 |
/* .. */ |
| 19094 |
/* .. External Subroutines .. */ |
| 19095 |
/* .. */ |
| 19096 |
/* .. Intrinsic Functions .. */ |
| 19097 |
/* .. */ |
| 19098 |
/* .. External Functions .. */ |
| 19099 |
/* .. */ |
| 19100 |
/* .. Executable Statements .. */ |
| 19101 |
|
| 19102 |
/* Check the input parameters. */ |
| 19103 |
|
| 19104 |
/* Parameter adjustments */ |
| 19105 |
err_bnds_comp_dim1 = *nrhs; |
| 19106 |
err_bnds_comp_offset = 1 + err_bnds_comp_dim1; |
| 19107 |
err_bnds_comp__ -= err_bnds_comp_offset; |
| 19108 |
err_bnds_norm_dim1 = *nrhs; |
| 19109 |
err_bnds_norm_offset = 1 + err_bnds_norm_dim1; |
| 19110 |
err_bnds_norm__ -= err_bnds_norm_offset; |
| 19111 |
a_dim1 = *lda; |
| 19112 |
a_offset = 1 + a_dim1; |
| 19113 |
a -= a_offset; |
| 19114 |
af_dim1 = *ldaf; |
| 19115 |
af_offset = 1 + af_dim1; |
| 19116 |
af -= af_offset; |
| 19117 |
--ipiv; |
| 19118 |
--s; |
| 19119 |
b_dim1 = *ldb; |
| 19120 |
b_offset = 1 + b_dim1; |
| 19121 |
b -= b_offset; |
| 19122 |
x_dim1 = *ldx; |
| 19123 |
x_offset = 1 + x_dim1; |
| 19124 |
x -= x_offset; |
| 19125 |
--berr; |
| 19126 |
--params; |
| 19127 |
--work; |
| 19128 |
--iwork; |
| 19129 |
|
| 19130 |
/* Function Body */ |
| 19131 |
*info = 0; |
| 19132 |
ref_type__ = 1; |
| 19133 |
if (*nparams >= 1) { |
| 19134 |
if (params[1] < 0.) { |
| 19135 |
params[1] = 1.; |
| 19136 |
} else { |
| 19137 |
ref_type__ = (integer) params[1]; |
| 19138 |
} |
| 19139 |
} |
| 19140 |
|
| 19141 |
/* Set default parameters. */ |
| 19142 |
|
| 19143 |
illrcond_thresh__ = (double) (*n) * dlamch_("Epsilon"); |
| 19144 |
ithresh = 10; |
| 19145 |
rthresh = .5; |
| 19146 |
unstable_thresh__ = .25; |
| 19147 |
ignore_cwise__ = false; |
| 19148 |
|
| 19149 |
if (*nparams >= 2) { |
| 19150 |
if (params[2] < 0.) { |
| 19151 |
params[2] = (double) ithresh; |
| 19152 |
} else { |
| 19153 |
ithresh = (integer) params[2]; |
| 19154 |
} |
| 19155 |
} |
| 19156 |
if (*nparams >= 3) { |
| 19157 |
if (params[3] < 0.) { |
| 19158 |
if (ignore_cwise__) { |
| 19159 |
params[3] = 0.; |
| 19160 |
} else { |
| 19161 |
params[3] = 1.; |
| 19162 |
} |
| 19163 |
} else { |
| 19164 |
ignore_cwise__ = params[3] == 0.; |
| 19165 |
} |
| 19166 |
} |
| 19167 |
if (ref_type__ == 0 || *n_err_bnds__ == 0) { |
| 19168 |
n_norms__ = 0; |
| 19169 |
} else if (ignore_cwise__) { |
| 19170 |
n_norms__ = 1; |
| 19171 |
} else { |
| 19172 |
n_norms__ = 2; |
| 19173 |
} |
| 19174 |
|
| 19175 |
rcequ = lsame_(equed, "Y"); |
| 19176 |
|
| 19177 |
/* Test input parameters. */ |
| 19178 |
|
| 19179 |
if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { |
| 19180 |
*info = -1; |
| 19181 |
} else if (! rcequ && ! lsame_(equed, "N")) { |
| 19182 |
*info = -2; |
| 19183 |
} else if (*n < 0) { |
| 19184 |
*info = -3; |
| 19185 |
} else if (*nrhs < 0) { |
| 19186 |
*info = -4; |
| 19187 |
} else if (*lda < std::max(1_integer,*n)) { |
| 19188 |
*info = -6; |
| 19189 |
} else if (*ldaf < std::max(1_integer,*n)) { |
| 19190 |
*info = -8; |
| 19191 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 19192 |
*info = -11; |
| 19193 |
} else if (*ldx < std::max(1_integer,*n)) { |
| 19194 |
*info = -13; |
| 19195 |
} |
| 19196 |
if (*info != 0) { |
| 19197 |
i__1 = -(*info); |
| 19198 |
xerbla_("DSYRFSX", &i__1); |
| 19199 |
return 0; |
| 19200 |
} |
| 19201 |
|
| 19202 |
/* Quick return if possible. */ |
| 19203 |
|
| 19204 |
if (*n == 0 || *nrhs == 0) { |
| 19205 |
*rcond = 1.; |
| 19206 |
i__1 = *nrhs; |
| 19207 |
for (j = 1; j <= i__1; ++j) { |
| 19208 |
berr[j] = 0.; |
| 19209 |
if (*n_err_bnds__ >= 1) { |
| 19210 |
err_bnds_norm__[j + err_bnds_norm_dim1] = 1.; |
| 19211 |
err_bnds_comp__[j + err_bnds_comp_dim1] = 1.; |
| 19212 |
} else if (*n_err_bnds__ >= 2) { |
| 19213 |
err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 0.; |
| 19214 |
err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 0.; |
| 19215 |
} else if (*n_err_bnds__ >= 3) { |
| 19216 |
err_bnds_norm__[j + err_bnds_norm_dim1 * 3] = 1.; |
| 19217 |
err_bnds_comp__[j + err_bnds_comp_dim1 * 3] = 1.; |
| 19218 |
} |
| 19219 |
} |
| 19220 |
return 0; |
| 19221 |
} |
| 19222 |
|
| 19223 |
/* Default to failure. */ |
| 19224 |
|
| 19225 |
*rcond = 0.; |
| 19226 |
i__1 = *nrhs; |
| 19227 |
for (j = 1; j <= i__1; ++j) { |
| 19228 |
berr[j] = 1.; |
| 19229 |
if (*n_err_bnds__ >= 1) { |
| 19230 |
err_bnds_norm__[j + err_bnds_norm_dim1] = 1.; |
| 19231 |
err_bnds_comp__[j + err_bnds_comp_dim1] = 1.; |
| 19232 |
} else if (*n_err_bnds__ >= 2) { |
| 19233 |
err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 1.; |
| 19234 |
err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 1.; |
| 19235 |
} else if (*n_err_bnds__ >= 3) { |
| 19236 |
err_bnds_norm__[j + err_bnds_norm_dim1 * 3] = 0.; |
| 19237 |
err_bnds_comp__[j + err_bnds_comp_dim1 * 3] = 0.; |
| 19238 |
} |
| 19239 |
} |
| 19240 |
|
| 19241 |
/* Compute the norm of A and the reciprocal of the condition */ |
| 19242 |
/* number of A. */ |
| 19243 |
|
| 19244 |
*(unsigned char *)norm = 'I'; |
| 19245 |
anorm = dlansy_(norm, uplo, n, &a[a_offset], lda, &work[1]); |
| 19246 |
dsycon_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &anorm, rcond, &work[1], |
| 19247 |
&iwork[1], info); |
| 19248 |
|
| 19249 |
/* Perform refinement on each right-hand side */ |
| 19250 |
|
| 19251 |
if (ref_type__ != 0) { |
| 19252 |
prec_type__ = ilaprec_("E"); |
| 19253 |
dla_syrfsx_extended__(&prec_type__, uplo, n, nrhs, &a[a_offset], lda, |
| 19254 |
&af[af_offset], ldaf, &ipiv[1], &rcequ, &s[1], &b[b_offset], |
| 19255 |
ldb, &x[x_offset], ldx, &berr[1], &n_norms__, & |
| 19256 |
err_bnds_norm__[err_bnds_norm_offset], &err_bnds_comp__[ |
| 19257 |
err_bnds_comp_offset], &work[*n + 1], &work[1], &work[(*n << |
| 19258 |
1) + 1], &work[1], rcond, &ithresh, &rthresh, & |
| 19259 |
unstable_thresh__, &ignore_cwise__, info, 1_integer); |
| 19260 |
} |
| 19261 |
/* Computing MAX */ |
| 19262 |
d__1 = 10., d__2 = sqrt((double) (*n)); |
| 19263 |
err_lbnd__ = std::max(d__1,d__2) * dlamch_("Epsilon"); |
| 19264 |
if (*n_err_bnds__ >= 1 && n_norms__ >= 1) { |
| 19265 |
|
| 19266 |
/* Compute scaled normwise condition number cond(A*C). */ |
| 19267 |
|
| 19268 |
if (rcequ) { |
| 19269 |
rcond_tmp__ = dla_syrcond__(uplo, n, &a[a_offset], lda, &af[ |
| 19270 |
af_offset], ldaf, &ipiv[1], &c_n1, &s[1], info, &work[1], |
| 19271 |
&iwork[1], 1_integer); |
| 19272 |
} else { |
| 19273 |
rcond_tmp__ = dla_syrcond__(uplo, n, &a[a_offset], lda, &af[ |
| 19274 |
af_offset], ldaf, &ipiv[1], &c__0, &s[1], info, &work[1], |
| 19275 |
&iwork[1], 1_integer); |
| 19276 |
} |
| 19277 |
i__1 = *nrhs; |
| 19278 |
for (j = 1; j <= i__1; ++j) { |
| 19279 |
|
| 19280 |
/* Cap the error at 1.0. */ |
| 19281 |
|
| 19282 |
if (*n_err_bnds__ >= 2 && err_bnds_norm__[j + (err_bnds_norm_dim1 |
| 19283 |
<< 1)] > 1.) { |
| 19284 |
err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 1.; |
| 19285 |
} |
| 19286 |
|
| 19287 |
/* Threshold the error (see LAWN). */ |
| 19288 |
|
| 19289 |
if (rcond_tmp__ < illrcond_thresh__) { |
| 19290 |
err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 1.; |
| 19291 |
err_bnds_norm__[j + err_bnds_norm_dim1] = 0.; |
| 19292 |
if (*info <= *n) { |
| 19293 |
*info = *n + j; |
| 19294 |
} |
| 19295 |
} else if (err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] < |
| 19296 |
err_lbnd__) { |
| 19297 |
err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = err_lbnd__; |
| 19298 |
err_bnds_norm__[j + err_bnds_norm_dim1] = 1.; |
| 19299 |
} |
| 19300 |
|
| 19301 |
/* Save the condition number. */ |
| 19302 |
|
| 19303 |
if (*n_err_bnds__ >= 3) { |
| 19304 |
err_bnds_norm__[j + err_bnds_norm_dim1 * 3] = rcond_tmp__; |
| 19305 |
} |
| 19306 |
} |
| 19307 |
} |
| 19308 |
if (*n_err_bnds__ >= 1 && n_norms__ >= 2) { |
| 19309 |
|
| 19310 |
/* Compute componentwise condition number cond(A*diag(Y(:,J))) for */ |
| 19311 |
/* each right-hand side using the current solution as an estimate of */ |
| 19312 |
/* the true solution. If the componentwise error estimate is too */ |
| 19313 |
/* large, then the solution is a lousy estimate of truth and the */ |
| 19314 |
/* estimated RCOND may be too optimistic. To avoid misleading users, */ |
| 19315 |
/* the inverse condition number is set to 0.0 when the estimated */ |
| 19316 |
/* cwise error is at least CWISE_WRONG. */ |
| 19317 |
|
| 19318 |
cwise_wrong__ = sqrt(dlamch_("Epsilon")); |
| 19319 |
i__1 = *nrhs; |
| 19320 |
for (j = 1; j <= i__1; ++j) { |
| 19321 |
if (err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] < |
| 19322 |
cwise_wrong__) { |
| 19323 |
rcond_tmp__ = dla_syrcond__(uplo, n, &a[a_offset], lda, &af[ |
| 19324 |
af_offset], ldaf, &ipiv[1], &c__1, &x[j * x_dim1 + 1], |
| 19325 |
info, &work[1], &iwork[1], 1_integer); |
| 19326 |
} else { |
| 19327 |
rcond_tmp__ = 0.; |
| 19328 |
} |
| 19329 |
|
| 19330 |
/* Cap the error at 1.0. */ |
| 19331 |
|
| 19332 |
if (*n_err_bnds__ >= 2 && err_bnds_comp__[j + (err_bnds_comp_dim1 |
| 19333 |
<< 1)] > 1.) { |
| 19334 |
err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 1.; |
| 19335 |
} |
| 19336 |
|
| 19337 |
/* Threshold the error (see LAWN). */ |
| 19338 |
|
| 19339 |
if (rcond_tmp__ < illrcond_thresh__) { |
| 19340 |
err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 1.; |
| 19341 |
err_bnds_comp__[j + err_bnds_comp_dim1] = 0.; |
| 19342 |
if (params[3] == 1. && *info < *n + j) { |
| 19343 |
*info = *n + j; |
| 19344 |
} |
| 19345 |
} else if (err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] < |
| 19346 |
err_lbnd__) { |
| 19347 |
err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = err_lbnd__; |
| 19348 |
err_bnds_comp__[j + err_bnds_comp_dim1] = 1.; |
| 19349 |
} |
| 19350 |
|
| 19351 |
/* Save the condition number. */ |
| 19352 |
|
| 19353 |
if (*n_err_bnds__ >= 3) { |
| 19354 |
err_bnds_comp__[j + err_bnds_comp_dim1 * 3] = rcond_tmp__; |
| 19355 |
} |
| 19356 |
} |
| 19357 |
} |
| 19358 |
|
| 19359 |
return 0; |
| 19360 |
|
| 19361 |
/* End of DSYRFSX */ |
| 19362 |
|
| 19363 |
} /* dsyrfsx_ */ |
| 19364 |
#endif |
| 19365 |
|
| 19366 |
/* Subroutine */ int dsysv_(const char *uplo, integer *n, integer *nrhs, double |
| 19367 |
*a, integer *lda, integer *ipiv, double *b, integer *ldb, |
| 19368 |
double *work, integer *lwork, integer *info) |
| 19369 |
{ |
| 19370 |
/* Table of constant values */ |
| 19371 |
static integer c__1 = 1; |
| 19372 |
static integer c_n1 = -1; |
| 19373 |
|
| 19374 |
/* System generated locals */ |
| 19375 |
integer a_dim1, a_offset, b_dim1, b_offset, i__1; |
| 19376 |
|
| 19377 |
/* Local variables */ |
| 19378 |
integer nb; |
| 19379 |
integer lwkopt; |
| 19380 |
bool lquery; |
| 19381 |
|
| 19382 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 19383 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 19384 |
/* November 2006 */ |
| 19385 |
|
| 19386 |
/* .. Scalar Arguments .. */ |
| 19387 |
/* .. */ |
| 19388 |
/* .. Array Arguments .. */ |
| 19389 |
/* .. */ |
| 19390 |
|
| 19391 |
/* Purpose */ |
| 19392 |
/* ======= */ |
| 19393 |
|
| 19394 |
/* DSYSV computes the solution to a real system of linear equations */ |
| 19395 |
/* A * X = B, */ |
| 19396 |
/* where A is an N-by-N symmetric matrix and X and B are N-by-NRHS */ |
| 19397 |
/* matrices. */ |
| 19398 |
|
| 19399 |
/* The diagonal pivoting method is used to factor A as */ |
| 19400 |
/* A = U * D * U**T, if UPLO = 'U', or */ |
| 19401 |
/* A = L * D * L**T, if UPLO = 'L', */ |
| 19402 |
/* where U (or L) is a product of permutation and unit upper (lower) */ |
| 19403 |
/* triangular matrices, and D is symmetric and block diagonal with */ |
| 19404 |
/* 1-by-1 and 2-by-2 diagonal blocks. The factored form of A is then */ |
| 19405 |
/* used to solve the system of equations A * X = B. */ |
| 19406 |
|
| 19407 |
/* Arguments */ |
| 19408 |
/* ========= */ |
| 19409 |
|
| 19410 |
/* UPLO (input) CHARACTER*1 */ |
| 19411 |
/* = 'U': Upper triangle of A is stored; */ |
| 19412 |
/* = 'L': Lower triangle of A is stored. */ |
| 19413 |
|
| 19414 |
/* N (input) INTEGER */ |
| 19415 |
/* The number of linear equations, i.e., the order of the */ |
| 19416 |
/* matrix A. N >= 0. */ |
| 19417 |
|
| 19418 |
/* NRHS (input) INTEGER */ |
| 19419 |
/* The number of right hand sides, i.e., the number of columns */ |
| 19420 |
/* of the matrix B. NRHS >= 0. */ |
| 19421 |
|
| 19422 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 19423 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the leading */ |
| 19424 |
/* N-by-N upper triangular part of A contains the upper */ |
| 19425 |
/* triangular part of the matrix A, and the strictly lower */ |
| 19426 |
/* triangular part of A is not referenced. If UPLO = 'L', the */ |
| 19427 |
/* leading N-by-N lower triangular part of A contains the lower */ |
| 19428 |
/* triangular part of the matrix A, and the strictly upper */ |
| 19429 |
/* triangular part of A is not referenced. */ |
| 19430 |
|
| 19431 |
/* On exit, if INFO = 0, the block diagonal matrix D and the */ |
| 19432 |
/* multipliers used to obtain the factor U or L from the */ |
| 19433 |
/* factorization A = U*D*U**T or A = L*D*L**T as computed by */ |
| 19434 |
/* DSYTRF. */ |
| 19435 |
|
| 19436 |
/* LDA (input) INTEGER */ |
| 19437 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 19438 |
|
| 19439 |
/* IPIV (output) INTEGER array, dimension (N) */ |
| 19440 |
/* Details of the interchanges and the block structure of D, as */ |
| 19441 |
/* determined by DSYTRF. If IPIV(k) > 0, then rows and columns */ |
| 19442 |
/* k and IPIV(k) were interchanged, and D(k,k) is a 1-by-1 */ |
| 19443 |
/* diagonal block. If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, */ |
| 19444 |
/* then rows and columns k-1 and -IPIV(k) were interchanged and */ |
| 19445 |
/* D(k-1:k,k-1:k) is a 2-by-2 diagonal block. If UPLO = 'L' and */ |
| 19446 |
/* IPIV(k) = IPIV(k+1) < 0, then rows and columns k+1 and */ |
| 19447 |
/* -IPIV(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2 */ |
| 19448 |
/* diagonal block. */ |
| 19449 |
|
| 19450 |
/* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 19451 |
/* On entry, the N-by-NRHS right hand side matrix B. */ |
| 19452 |
/* On exit, if INFO = 0, the N-by-NRHS solution matrix X. */ |
| 19453 |
|
| 19454 |
/* LDB (input) INTEGER */ |
| 19455 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 19456 |
|
| 19457 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 19458 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 19459 |
|
| 19460 |
/* LWORK (input) INTEGER */ |
| 19461 |
/* The length of WORK. LWORK >= 1, and for best performance */ |
| 19462 |
/* LWORK >= max(1,N*NB), where NB is the optimal blocksize for */ |
| 19463 |
/* DSYTRF. */ |
| 19464 |
|
| 19465 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 19466 |
/* only calculates the optimal size of the WORK array, returns */ |
| 19467 |
/* this value as the first entry of the WORK array, and no error */ |
| 19468 |
/* message related to LWORK is issued by XERBLA. */ |
| 19469 |
|
| 19470 |
/* INFO (output) INTEGER */ |
| 19471 |
/* = 0: successful exit */ |
| 19472 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 19473 |
/* > 0: if INFO = i, D(i,i) is exactly zero. The factorization */ |
| 19474 |
/* has been completed, but the block diagonal matrix D is */ |
| 19475 |
/* exactly singular, so the solution could not be computed. */ |
| 19476 |
|
| 19477 |
/* ===================================================================== */ |
| 19478 |
|
| 19479 |
/* .. Local Scalars .. */ |
| 19480 |
/* .. */ |
| 19481 |
/* .. External Functions .. */ |
| 19482 |
/* .. */ |
| 19483 |
/* .. External Subroutines .. */ |
| 19484 |
/* .. */ |
| 19485 |
/* .. Intrinsic Functions .. */ |
| 19486 |
/* .. */ |
| 19487 |
/* .. Executable Statements .. */ |
| 19488 |
|
| 19489 |
/* Test the input parameters. */ |
| 19490 |
|
| 19491 |
/* Parameter adjustments */ |
| 19492 |
a_dim1 = *lda; |
| 19493 |
a_offset = 1 + a_dim1; |
| 19494 |
a -= a_offset; |
| 19495 |
--ipiv; |
| 19496 |
b_dim1 = *ldb; |
| 19497 |
b_offset = 1 + b_dim1; |
| 19498 |
b -= b_offset; |
| 19499 |
--work; |
| 19500 |
|
| 19501 |
/* Function Body */ |
| 19502 |
*info = 0; |
| 19503 |
lquery = *lwork == -1; |
| 19504 |
if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { |
| 19505 |
*info = -1; |
| 19506 |
} else if (*n < 0) { |
| 19507 |
*info = -2; |
| 19508 |
} else if (*nrhs < 0) { |
| 19509 |
*info = -3; |
| 19510 |
} else if (*lda < std::max(1_integer,*n)) { |
| 19511 |
*info = -5; |
| 19512 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 19513 |
*info = -8; |
| 19514 |
} else if (*lwork < 1 && ! lquery) { |
| 19515 |
*info = -10; |
| 19516 |
} |
| 19517 |
|
| 19518 |
if (*info == 0) { |
| 19519 |
if (*n == 0) { |
| 19520 |
lwkopt = 1; |
| 19521 |
} else { |
| 19522 |
nb = ilaenv_(&c__1, "DSYTRF", uplo, n, &c_n1, &c_n1, &c_n1); |
| 19523 |
lwkopt = *n * nb; |
| 19524 |
} |
| 19525 |
work[1] = (double) lwkopt; |
| 19526 |
} |
| 19527 |
|
| 19528 |
if (*info != 0) { |
| 19529 |
i__1 = -(*info); |
| 19530 |
xerbla_("DSYSV ", &i__1); |
| 19531 |
return 0; |
| 19532 |
} else if (lquery) { |
| 19533 |
return 0; |
| 19534 |
} |
| 19535 |
|
| 19536 |
/* Compute the factorization A = U*D*U' or A = L*D*L'. */ |
| 19537 |
|
| 19538 |
dsytrf_(uplo, n, &a[a_offset], lda, &ipiv[1], &work[1], lwork, info); |
| 19539 |
if (*info == 0) { |
| 19540 |
|
| 19541 |
/* Solve the system A*X = B, overwriting B with X. */ |
| 19542 |
|
| 19543 |
dsytrs_(uplo, n, nrhs, &a[a_offset], lda, &ipiv[1], &b[b_offset], ldb, |
| 19544 |
info); |
| 19545 |
|
| 19546 |
} |
| 19547 |
|
| 19548 |
work[1] = (double) lwkopt; |
| 19549 |
|
| 19550 |
return 0; |
| 19551 |
|
| 19552 |
/* End of DSYSV */ |
| 19553 |
|
| 19554 |
} /* dsysv_ */ |
| 19555 |
|
| 19556 |
/* Subroutine */ int dsysvx_(const char *fact, const char *uplo, integer *n, integer * |
| 19557 |
nrhs, double *a, integer *lda, double *af, integer *ldaf, |
| 19558 |
integer *ipiv, double *b, integer *ldb, double *x, integer * |
| 19559 |
ldx, double *rcond, double *ferr, double *berr, |
| 19560 |
double *work, integer *lwork, integer *iwork, integer *info) |
| 19561 |
{ |
| 19562 |
/* Table of constant values */ |
| 19563 |
static integer c__1 = 1; |
| 19564 |
static integer c_n1 = -1; |
| 19565 |
|
| 19566 |
/* System generated locals */ |
| 19567 |
integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, |
| 19568 |
x_offset, i__1, i__2; |
| 19569 |
|
| 19570 |
/* Local variables */ |
| 19571 |
integer nb; |
| 19572 |
double anorm; |
| 19573 |
bool nofact; |
| 19574 |
integer lwkopt; |
| 19575 |
bool lquery; |
| 19576 |
|
| 19577 |
/* -- LAPACK driver routine (version 3.1) -- */ |
| 19578 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 19579 |
/* November 2006 */ |
| 19580 |
|
| 19581 |
/* .. Scalar Arguments .. */ |
| 19582 |
/* .. */ |
| 19583 |
/* .. Array Arguments .. */ |
| 19584 |
/* .. */ |
| 19585 |
|
| 19586 |
/* Purpose */ |
| 19587 |
/* ======= */ |
| 19588 |
|
| 19589 |
/* DSYSVX uses the diagonal pivoting factorization to compute the */ |
| 19590 |
/* solution to a real system of linear equations A * X = B, */ |
| 19591 |
/* where A is an N-by-N symmetric matrix and X and B are N-by-NRHS */ |
| 19592 |
/* matrices. */ |
| 19593 |
|
| 19594 |
/* Error bounds on the solution and a condition estimate are also */ |
| 19595 |
/* provided. */ |
| 19596 |
|
| 19597 |
/* Description */ |
| 19598 |
/* =========== */ |
| 19599 |
|
| 19600 |
/* The following steps are performed: */ |
| 19601 |
|
| 19602 |
/* 1. If FACT = 'N', the diagonal pivoting method is used to factor A. */ |
| 19603 |
/* The form of the factorization is */ |
| 19604 |
/* A = U * D * U**T, if UPLO = 'U', or */ |
| 19605 |
/* A = L * D * L**T, if UPLO = 'L', */ |
| 19606 |
/* where U (or L) is a product of permutation and unit upper (lower) */ |
| 19607 |
/* triangular matrices, and D is symmetric and block diagonal with */ |
| 19608 |
/* 1-by-1 and 2-by-2 diagonal blocks. */ |
| 19609 |
|
| 19610 |
/* 2. If some D(i,i)=0, so that D is exactly singular, then the routine */ |
| 19611 |
/* returns with INFO = i. Otherwise, the factored form of A is used */ |
| 19612 |
/* to estimate the condition number of the matrix A. If the */ |
| 19613 |
/* reciprocal of the condition number is less than machine precision, */ |
| 19614 |
/* INFO = N+1 is returned as a warning, but the routine still goes on */ |
| 19615 |
/* to solve for X and compute error bounds as described below. */ |
| 19616 |
|
| 19617 |
/* 3. The system of equations is solved for X using the factored form */ |
| 19618 |
/* of A. */ |
| 19619 |
|
| 19620 |
/* 4. Iterative refinement is applied to improve the computed solution */ |
| 19621 |
/* matrix and calculate error bounds and backward error estimates */ |
| 19622 |
/* for it. */ |
| 19623 |
|
| 19624 |
/* Arguments */ |
| 19625 |
/* ========= */ |
| 19626 |
|
| 19627 |
/* FACT (input) CHARACTER*1 */ |
| 19628 |
/* Specifies whether or not the factored form of A has been */ |
| 19629 |
/* supplied on entry. */ |
| 19630 |
/* = 'F': On entry, AF and IPIV contain the factored form of */ |
| 19631 |
/* A. AF and IPIV will not be modified. */ |
| 19632 |
/* = 'N': The matrix A will be copied to AF and factored. */ |
| 19633 |
|
| 19634 |
/* UPLO (input) CHARACTER*1 */ |
| 19635 |
/* = 'U': Upper triangle of A is stored; */ |
| 19636 |
/* = 'L': Lower triangle of A is stored. */ |
| 19637 |
|
| 19638 |
/* N (input) INTEGER */ |
| 19639 |
/* The number of linear equations, i.e., the order of the */ |
| 19640 |
/* matrix A. N >= 0. */ |
| 19641 |
|
| 19642 |
/* NRHS (input) INTEGER */ |
| 19643 |
/* The number of right hand sides, i.e., the number of columns */ |
| 19644 |
/* of the matrices B and X. NRHS >= 0. */ |
| 19645 |
|
| 19646 |
/* A (input) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 19647 |
/* The symmetric matrix A. If UPLO = 'U', the leading N-by-N */ |
| 19648 |
/* upper triangular part of A contains the upper triangular part */ |
| 19649 |
/* of the matrix A, and the strictly lower triangular part of A */ |
| 19650 |
/* is not referenced. If UPLO = 'L', the leading N-by-N lower */ |
| 19651 |
/* triangular part of A contains the lower triangular part of */ |
| 19652 |
/* the matrix A, and the strictly upper triangular part of A is */ |
| 19653 |
/* not referenced. */ |
| 19654 |
|
| 19655 |
/* LDA (input) INTEGER */ |
| 19656 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 19657 |
|
| 19658 |
/* AF (input or output) DOUBLE PRECISION array, dimension (LDAF,N) */ |
| 19659 |
/* If FACT = 'F', then AF is an input argument and on entry */ |
| 19660 |
/* contains the block diagonal matrix D and the multipliers used */ |
| 19661 |
/* to obtain the factor U or L from the factorization */ |
| 19662 |
/* A = U*D*U**T or A = L*D*L**T as computed by DSYTRF. */ |
| 19663 |
|
| 19664 |
/* If FACT = 'N', then AF is an output argument and on exit */ |
| 19665 |
/* returns the block diagonal matrix D and the multipliers used */ |
| 19666 |
/* to obtain the factor U or L from the factorization */ |
| 19667 |
/* A = U*D*U**T or A = L*D*L**T. */ |
| 19668 |
|
| 19669 |
/* LDAF (input) INTEGER */ |
| 19670 |
/* The leading dimension of the array AF. LDAF >= max(1,N). */ |
| 19671 |
|
| 19672 |
/* IPIV (input or output) INTEGER array, dimension (N) */ |
| 19673 |
/* If FACT = 'F', then IPIV is an input argument and on entry */ |
| 19674 |
/* contains details of the interchanges and the block structure */ |
| 19675 |
/* of D, as determined by DSYTRF. */ |
| 19676 |
/* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */ |
| 19677 |
/* interchanged and D(k,k) is a 1-by-1 diagonal block. */ |
| 19678 |
/* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */ |
| 19679 |
/* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */ |
| 19680 |
/* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */ |
| 19681 |
/* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */ |
| 19682 |
/* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */ |
| 19683 |
|
| 19684 |
/* If FACT = 'N', then IPIV is an output argument and on exit */ |
| 19685 |
/* contains details of the interchanges and the block structure */ |
| 19686 |
/* of D, as determined by DSYTRF. */ |
| 19687 |
|
| 19688 |
/* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 19689 |
/* The N-by-NRHS right hand side matrix B. */ |
| 19690 |
|
| 19691 |
/* LDB (input) INTEGER */ |
| 19692 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 19693 |
|
| 19694 |
/* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */ |
| 19695 |
/* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X. */ |
| 19696 |
|
| 19697 |
/* LDX (input) INTEGER */ |
| 19698 |
/* The leading dimension of the array X. LDX >= max(1,N). */ |
| 19699 |
|
| 19700 |
/* RCOND (output) DOUBLE PRECISION */ |
| 19701 |
/* The estimate of the reciprocal condition number of the matrix */ |
| 19702 |
/* A. If RCOND is less than the machine precision (in */ |
| 19703 |
/* particular, if RCOND = 0), the matrix is singular to working */ |
| 19704 |
/* precision. This condition is indicated by a return code of */ |
| 19705 |
/* INFO > 0. */ |
| 19706 |
|
| 19707 |
/* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 19708 |
/* The estimated forward error bound for each solution vector */ |
| 19709 |
/* X(j) (the j-th column of the solution matrix X). */ |
| 19710 |
/* If XTRUE is the true solution corresponding to X(j), FERR(j) */ |
| 19711 |
/* is an estimated upper bound for the magnitude of the largest */ |
| 19712 |
/* element in (X(j) - XTRUE) divided by the magnitude of the */ |
| 19713 |
/* largest element in X(j). The estimate is as reliable as */ |
| 19714 |
/* the estimate for RCOND, and is almost always a slight */ |
| 19715 |
/* overestimate of the true error. */ |
| 19716 |
|
| 19717 |
/* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 19718 |
/* The componentwise relative backward error of each solution */ |
| 19719 |
/* vector X(j) (i.e., the smallest relative change in */ |
| 19720 |
/* any element of A or B that makes X(j) an exact solution). */ |
| 19721 |
|
| 19722 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 19723 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 19724 |
|
| 19725 |
/* LWORK (input) INTEGER */ |
| 19726 |
/* The length of WORK. LWORK >= max(1,3*N), and for best */ |
| 19727 |
/* performance, when FACT = 'N', LWORK >= max(1,3*N,N*NB), where */ |
| 19728 |
/* NB is the optimal blocksize for DSYTRF. */ |
| 19729 |
|
| 19730 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 19731 |
/* only calculates the optimal size of the WORK array, returns */ |
| 19732 |
/* this value as the first entry of the WORK array, and no error */ |
| 19733 |
/* message related to LWORK is issued by XERBLA. */ |
| 19734 |
|
| 19735 |
/* IWORK (workspace) INTEGER array, dimension (N) */ |
| 19736 |
|
| 19737 |
/* INFO (output) INTEGER */ |
| 19738 |
/* = 0: successful exit */ |
| 19739 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 19740 |
/* > 0: if INFO = i, and i is */ |
| 19741 |
/* <= N: D(i,i) is exactly zero. The factorization */ |
| 19742 |
/* has been completed but the factor D is exactly */ |
| 19743 |
/* singular, so the solution and error bounds could */ |
| 19744 |
/* not be computed. RCOND = 0 is returned. */ |
| 19745 |
/* = N+1: D is nonsingular, but RCOND is less than machine */ |
| 19746 |
/* precision, meaning that the matrix is singular */ |
| 19747 |
/* to working precision. Nevertheless, the */ |
| 19748 |
/* solution and error bounds are computed because */ |
| 19749 |
/* there are a number of situations where the */ |
| 19750 |
/* computed solution can be more accurate than the */ |
| 19751 |
/* value of RCOND would suggest. */ |
| 19752 |
|
| 19753 |
/* ===================================================================== */ |
| 19754 |
|
| 19755 |
/* .. Parameters .. */ |
| 19756 |
/* .. */ |
| 19757 |
/* .. Local Scalars .. */ |
| 19758 |
/* .. */ |
| 19759 |
/* .. External Functions .. */ |
| 19760 |
/* .. */ |
| 19761 |
/* .. External Subroutines .. */ |
| 19762 |
/* .. */ |
| 19763 |
/* .. Intrinsic Functions .. */ |
| 19764 |
/* .. */ |
| 19765 |
/* .. Executable Statements .. */ |
| 19766 |
|
| 19767 |
/* Test the input parameters. */ |
| 19768 |
|
| 19769 |
/* Parameter adjustments */ |
| 19770 |
a_dim1 = *lda; |
| 19771 |
a_offset = 1 + a_dim1; |
| 19772 |
a -= a_offset; |
| 19773 |
af_dim1 = *ldaf; |
| 19774 |
af_offset = 1 + af_dim1; |
| 19775 |
af -= af_offset; |
| 19776 |
--ipiv; |
| 19777 |
b_dim1 = *ldb; |
| 19778 |
b_offset = 1 + b_dim1; |
| 19779 |
b -= b_offset; |
| 19780 |
x_dim1 = *ldx; |
| 19781 |
x_offset = 1 + x_dim1; |
| 19782 |
x -= x_offset; |
| 19783 |
--ferr; |
| 19784 |
--berr; |
| 19785 |
--work; |
| 19786 |
--iwork; |
| 19787 |
|
| 19788 |
/* Function Body */ |
| 19789 |
*info = 0; |
| 19790 |
nofact = lsame_(fact, "N"); |
| 19791 |
lquery = *lwork == -1; |
| 19792 |
if (! nofact && ! lsame_(fact, "F")) { |
| 19793 |
*info = -1; |
| 19794 |
} else if (! lsame_(uplo, "U") && ! lsame_(uplo, |
| 19795 |
"L")) { |
| 19796 |
*info = -2; |
| 19797 |
} else if (*n < 0) { |
| 19798 |
*info = -3; |
| 19799 |
} else if (*nrhs < 0) { |
| 19800 |
*info = -4; |
| 19801 |
} else if (*lda < std::max(1_integer,*n)) { |
| 19802 |
*info = -6; |
| 19803 |
} else if (*ldaf < std::max(1_integer,*n)) { |
| 19804 |
*info = -8; |
| 19805 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 19806 |
*info = -11; |
| 19807 |
} else if (*ldx < std::max(1_integer,*n)) { |
| 19808 |
*info = -13; |
| 19809 |
} else /* if(complicated condition) */ { |
| 19810 |
/* Computing MAX */ |
| 19811 |
i__1 = 1, i__2 = *n * 3; |
| 19812 |
if (*lwork < std::max(i__1,i__2) && ! lquery) { |
| 19813 |
*info = -18; |
| 19814 |
} |
| 19815 |
} |
| 19816 |
|
| 19817 |
if (*info == 0) { |
| 19818 |
/* Computing MAX */ |
| 19819 |
i__1 = 1, i__2 = *n * 3; |
| 19820 |
lwkopt = std::max(i__1,i__2); |
| 19821 |
if (nofact) { |
| 19822 |
nb = ilaenv_(&c__1, "DSYTRF", uplo, n, &c_n1, &c_n1, &c_n1); |
| 19823 |
/* Computing MAX */ |
| 19824 |
i__1 = lwkopt, i__2 = *n * nb; |
| 19825 |
lwkopt = std::max(i__1,i__2); |
| 19826 |
} |
| 19827 |
work[1] = (double) lwkopt; |
| 19828 |
} |
| 19829 |
|
| 19830 |
if (*info != 0) { |
| 19831 |
i__1 = -(*info); |
| 19832 |
xerbla_("DSYSVX", &i__1); |
| 19833 |
return 0; |
| 19834 |
} else if (lquery) { |
| 19835 |
return 0; |
| 19836 |
} |
| 19837 |
|
| 19838 |
if (nofact) { |
| 19839 |
|
| 19840 |
/* Compute the factorization A = U*D*U' or A = L*D*L'. */ |
| 19841 |
|
| 19842 |
dlacpy_(uplo, n, n, &a[a_offset], lda, &af[af_offset], ldaf); |
| 19843 |
dsytrf_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &work[1], lwork, |
| 19844 |
info); |
| 19845 |
|
| 19846 |
/* Return if INFO is non-zero. */ |
| 19847 |
|
| 19848 |
if (*info > 0) { |
| 19849 |
*rcond = 0.; |
| 19850 |
return 0; |
| 19851 |
} |
| 19852 |
} |
| 19853 |
|
| 19854 |
/* Compute the norm of the matrix A. */ |
| 19855 |
|
| 19856 |
anorm = dlansy_("I", uplo, n, &a[a_offset], lda, &work[1]); |
| 19857 |
|
| 19858 |
/* Compute the reciprocal of the condition number of A. */ |
| 19859 |
|
| 19860 |
dsycon_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &anorm, rcond, &work[1], |
| 19861 |
&iwork[1], info); |
| 19862 |
|
| 19863 |
/* Compute the solution vectors X. */ |
| 19864 |
|
| 19865 |
dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx); |
| 19866 |
dsytrs_(uplo, n, nrhs, &af[af_offset], ldaf, &ipiv[1], &x[x_offset], ldx, |
| 19867 |
info); |
| 19868 |
|
| 19869 |
/* Use iterative refinement to improve the computed solutions and */ |
| 19870 |
/* compute error bounds and backward error estimates for them. */ |
| 19871 |
|
| 19872 |
dsyrfs_(uplo, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, &ipiv[1], |
| 19873 |
&b[b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1] |
| 19874 |
, &iwork[1], info); |
| 19875 |
|
| 19876 |
/* Set INFO = N+1 if the matrix is singular to working precision. */ |
| 19877 |
|
| 19878 |
if (*rcond < dlamch_("Epsilon")) { |
| 19879 |
*info = *n + 1; |
| 19880 |
} |
| 19881 |
|
| 19882 |
work[1] = (double) lwkopt; |
| 19883 |
|
| 19884 |
return 0; |
| 19885 |
|
| 19886 |
/* End of DSYSVX */ |
| 19887 |
|
| 19888 |
} /* dsysvx_ */ |
| 19889 |
|
| 19890 |
#if 0 |
| 19891 |
int dsysvxx_(const char *fact, const char *uplo, integer *n, integer * |
| 19892 |
nrhs, double *a, integer *lda, double *af, integer *ldaf, |
| 19893 |
integer *ipiv, char *equed, double *s, double *b, integer * |
| 19894 |
ldb, double *x, integer *ldx, double *rcond, double * |
| 19895 |
rpvgrw, double *berr, integer *n_err_bnds__, double * |
| 19896 |
err_bnds_norm__, double *err_bnds_comp__, integer *nparams, |
| 19897 |
double *params, double *work, integer *iwork, integer *info) |
| 19898 |
{ |
| 19899 |
/* System generated locals */ |
| 19900 |
integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, |
| 19901 |
x_offset, err_bnds_norm_dim1, err_bnds_norm_offset, |
| 19902 |
err_bnds_comp_dim1, err_bnds_comp_offset, i__1; |
| 19903 |
double d__1, d__2; |
| 19904 |
|
| 19905 |
/* Local variables */ |
| 19906 |
integer j; |
| 19907 |
double amax, smin, smax; |
| 19908 |
double scond; |
| 19909 |
bool equil, rcequ, nofact; |
| 19910 |
double bignum; |
| 19911 |
integer infequ; |
| 19912 |
double smlnum; |
| 19913 |
|
| 19914 |
|
| 19915 |
/* -- LAPACK routine (version 3.2.1) -- */ |
| 19916 |
/* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */ |
| 19917 |
/* -- Jason Riedy of Univ. of California Berkeley. -- */ |
| 19918 |
/* -- April 2009 -- */ |
| 19919 |
|
| 19920 |
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ |
| 19921 |
/* -- Univ. of California Berkeley and NAG Ltd. -- */ |
| 19922 |
|
| 19923 |
/* .. */ |
| 19924 |
/* .. Scalar Arguments .. */ |
| 19925 |
/* .. */ |
| 19926 |
/* .. Array Arguments .. */ |
| 19927 |
/* .. */ |
| 19928 |
|
| 19929 |
/* Purpose */ |
| 19930 |
/* ======= */ |
| 19931 |
|
| 19932 |
/* DSYSVXX uses the diagonal pivoting factorization to compute the */ |
| 19933 |
/* solution to a double precision system of linear equations A * X = B, where A */ |
| 19934 |
/* is an N-by-N symmetric matrix and X and B are N-by-NRHS matrices. */ |
| 19935 |
|
| 19936 |
/* If requested, both normwise and maximum componentwise error bounds */ |
| 19937 |
/* are returned. DSYSVXX will return a solution with a tiny */ |
| 19938 |
/* guaranteed error (O(eps) where eps is the working machine */ |
| 19939 |
/* precision) unless the matrix is very ill-conditioned, in which */ |
| 19940 |
/* case a warning is returned. Relevant condition numbers also are */ |
| 19941 |
/* calculated and returned. */ |
| 19942 |
|
| 19943 |
/* DSYSVXX accepts user-provided factorizations and equilibration */ |
| 19944 |
/* factors; see the definitions of the FACT and EQUED options. */ |
| 19945 |
/* Solving with refinement and using a factorization from a previous */ |
| 19946 |
/* DSYSVXX call will also produce a solution with either O(eps) */ |
| 19947 |
/* errors or warnings, but we cannot make that claim for general */ |
| 19948 |
/* user-provided factorizations and equilibration factors if they */ |
| 19949 |
/* differ from what DSYSVXX would itself produce. */ |
| 19950 |
|
| 19951 |
/* Description */ |
| 19952 |
/* =========== */ |
| 19953 |
|
| 19954 |
/* The following steps are performed: */ |
| 19955 |
|
| 19956 |
/* 1. If FACT = 'E', double precision scaling factors are computed to equilibrate */ |
| 19957 |
/* the system: */ |
| 19958 |
|
| 19959 |
/* diag(S)*A*diag(S) *inv(diag(S))*X = diag(S)*B */ |
| 19960 |
|
| 19961 |
/* Whether or not the system will be equilibrated depends on the */ |
| 19962 |
/* scaling of the matrix A, but if equilibration is used, A is */ |
| 19963 |
/* overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */ |
| 19964 |
|
| 19965 |
/* 2. If FACT = 'N' or 'E', the LU decomposition is used to factor */ |
| 19966 |
/* the matrix A (after equilibration if FACT = 'E') as */ |
| 19967 |
|
| 19968 |
/* A = U * D * U**T, if UPLO = 'U', or */ |
| 19969 |
/* A = L * D * L**T, if UPLO = 'L', */ |
| 19970 |
|
| 19971 |
/* where U (or L) is a product of permutation and unit upper (lower) */ |
| 19972 |
/* triangular matrices, and D is symmetric and block diagonal with */ |
| 19973 |
/* 1-by-1 and 2-by-2 diagonal blocks. */ |
| 19974 |
|
| 19975 |
/* 3. If some D(i,i)=0, so that D is exactly singular, then the */ |
| 19976 |
/* routine returns with INFO = i. Otherwise, the factored form of A */ |
| 19977 |
/* is used to estimate the condition number of the matrix A (see */ |
| 19978 |
/* argument RCOND). If the reciprocal of the condition number is */ |
| 19979 |
/* less than machine precision, the routine still goes on to solve */ |
| 19980 |
/* for X and compute error bounds as described below. */ |
| 19981 |
|
| 19982 |
/* 4. The system of equations is solved for X using the factored form */ |
| 19983 |
/* of A. */ |
| 19984 |
|
| 19985 |
/* 5. By default (unless PARAMS(LA_LINRX_ITREF_I) is set to zero), */ |
| 19986 |
/* the routine will use iterative refinement to try to get a small */ |
| 19987 |
/* error and error bounds. Refinement calculates the residual to at */ |
| 19988 |
/* least twice the working precision. */ |
| 19989 |
|
| 19990 |
/* 6. If equilibration was used, the matrix X is premultiplied by */ |
| 19991 |
/* diag(R) so that it solves the original system before */ |
| 19992 |
/* equilibration. */ |
| 19993 |
|
| 19994 |
/* Arguments */ |
| 19995 |
/* ========= */ |
| 19996 |
|
| 19997 |
/* Some optional parameters are bundled in the PARAMS array. These */ |
| 19998 |
/* settings determine how refinement is performed, but often the */ |
| 19999 |
/* defaults are acceptable. If the defaults are acceptable, users */ |
| 20000 |
/* can pass NPARAMS = 0 which prevents the source code from accessing */ |
| 20001 |
/* the PARAMS argument. */ |
| 20002 |
|
| 20003 |
/* FACT (input) CHARACTER*1 */ |
| 20004 |
/* Specifies whether or not the factored form of the matrix A is */ |
| 20005 |
/* supplied on entry, and if not, whether the matrix A should be */ |
| 20006 |
/* equilibrated before it is factored. */ |
| 20007 |
/* = 'F': On entry, AF and IPIV contain the factored form of A. */ |
| 20008 |
/* If EQUED is not 'N', the matrix A has been */ |
| 20009 |
/* equilibrated with scaling factors given by S. */ |
| 20010 |
/* A, AF, and IPIV are not modified. */ |
| 20011 |
/* = 'N': The matrix A will be copied to AF and factored. */ |
| 20012 |
/* = 'E': The matrix A will be equilibrated if necessary, then */ |
| 20013 |
/* copied to AF and factored. */ |
| 20014 |
|
| 20015 |
/* UPLO (input) CHARACTER*1 */ |
| 20016 |
/* = 'U': Upper triangle of A is stored; */ |
| 20017 |
/* = 'L': Lower triangle of A is stored. */ |
| 20018 |
|
| 20019 |
/* N (input) INTEGER */ |
| 20020 |
/* The number of linear equations, i.e., the order of the */ |
| 20021 |
/* matrix A. N >= 0. */ |
| 20022 |
|
| 20023 |
/* NRHS (input) INTEGER */ |
| 20024 |
/* The number of right hand sides, i.e., the number of columns */ |
| 20025 |
/* of the matrices B and X. NRHS >= 0. */ |
| 20026 |
|
| 20027 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 20028 |
/* The symmetric matrix A. If UPLO = 'U', the leading N-by-N */ |
| 20029 |
/* upper triangular part of A contains the upper triangular */ |
| 20030 |
/* part of the matrix A, and the strictly lower triangular */ |
| 20031 |
/* part of A is not referenced. If UPLO = 'L', the leading */ |
| 20032 |
/* N-by-N lower triangular part of A contains the lower */ |
| 20033 |
/* triangular part of the matrix A, and the strictly upper */ |
| 20034 |
/* triangular part of A is not referenced. */ |
| 20035 |
|
| 20036 |
/* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */ |
| 20037 |
/* diag(S)*A*diag(S). */ |
| 20038 |
|
| 20039 |
/* LDA (input) INTEGER */ |
| 20040 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 20041 |
|
| 20042 |
/* AF (input or output) DOUBLE PRECISION array, dimension (LDAF,N) */ |
| 20043 |
/* If FACT = 'F', then AF is an input argument and on entry */ |
| 20044 |
/* contains the block diagonal matrix D and the multipliers */ |
| 20045 |
/* used to obtain the factor U or L from the factorization A = */ |
| 20046 |
/* U*D*U**T or A = L*D*L**T as computed by DSYTRF. */ |
| 20047 |
|
| 20048 |
/* If FACT = 'N', then AF is an output argument and on exit */ |
| 20049 |
/* returns the block diagonal matrix D and the multipliers */ |
| 20050 |
/* used to obtain the factor U or L from the factorization A = */ |
| 20051 |
/* U*D*U**T or A = L*D*L**T. */ |
| 20052 |
|
| 20053 |
/* LDAF (input) INTEGER */ |
| 20054 |
/* The leading dimension of the array AF. LDAF >= max(1,N). */ |
| 20055 |
|
| 20056 |
/* IPIV (input or output) INTEGER array, dimension (N) */ |
| 20057 |
/* If FACT = 'F', then IPIV is an input argument and on entry */ |
| 20058 |
/* contains details of the interchanges and the block */ |
| 20059 |
/* structure of D, as determined by DSYTRF. If IPIV(k) > 0, */ |
| 20060 |
/* then rows and columns k and IPIV(k) were interchanged and */ |
| 20061 |
/* D(k,k) is a 1-by-1 diagonal block. If UPLO = 'U' and */ |
| 20062 |
/* IPIV(k) = IPIV(k-1) < 0, then rows and columns k-1 and */ |
| 20063 |
/* -IPIV(k) were interchanged and D(k-1:k,k-1:k) is a 2-by-2 */ |
| 20064 |
/* diagonal block. If UPLO = 'L' and IPIV(k) = IPIV(k+1) < 0, */ |
| 20065 |
/* then rows and columns k+1 and -IPIV(k) were interchanged */ |
| 20066 |
/* and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */ |
| 20067 |
|
| 20068 |
/* If FACT = 'N', then IPIV is an output argument and on exit */ |
| 20069 |
/* contains details of the interchanges and the block */ |
| 20070 |
/* structure of D, as determined by DSYTRF. */ |
| 20071 |
|
| 20072 |
/* EQUED (input or output) CHARACTER*1 */ |
| 20073 |
/* Specifies the form of equilibration that was done. */ |
| 20074 |
/* = 'N': No equilibration (always true if FACT = 'N'). */ |
| 20075 |
/* = 'Y': Both row and column equilibration, i.e., A has been */ |
| 20076 |
/* replaced by diag(S) * A * diag(S). */ |
| 20077 |
/* EQUED is an input argument if FACT = 'F'; otherwise, it is an */ |
| 20078 |
/* output argument. */ |
| 20079 |
|
| 20080 |
/* S (input or output) DOUBLE PRECISION array, dimension (N) */ |
| 20081 |
/* The scale factors for A. If EQUED = 'Y', A is multiplied on */ |
| 20082 |
/* the left and right by diag(S). S is an input argument if FACT = */ |
| 20083 |
/* 'F'; otherwise, S is an output argument. If FACT = 'F' and EQUED */ |
| 20084 |
/* = 'Y', each element of S must be positive. If S is output, each */ |
| 20085 |
/* element of S is a power of the radix. If S is input, each element */ |
| 20086 |
/* of S should be a power of the radix to ensure a reliable solution */ |
| 20087 |
/* and error estimates. Scaling by powers of the radix does not cause */ |
| 20088 |
/* rounding errors unless the result underflows or overflows. */ |
| 20089 |
/* Rounding errors during scaling lead to refining with a matrix that */ |
| 20090 |
/* is not equivalent to the input matrix, producing error estimates */ |
| 20091 |
/* that may not be reliable. */ |
| 20092 |
|
| 20093 |
/* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 20094 |
/* On entry, the N-by-NRHS right hand side matrix B. */ |
| 20095 |
/* On exit, */ |
| 20096 |
/* if EQUED = 'N', B is not modified; */ |
| 20097 |
/* if EQUED = 'Y', B is overwritten by diag(S)*B; */ |
| 20098 |
|
| 20099 |
/* LDB (input) INTEGER */ |
| 20100 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 20101 |
|
| 20102 |
/* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */ |
| 20103 |
/* If INFO = 0, the N-by-NRHS solution matrix X to the original */ |
| 20104 |
/* system of equations. Note that A and B are modified on exit if */ |
| 20105 |
/* EQUED .ne. 'N', and the solution to the equilibrated system is */ |
| 20106 |
/* inv(diag(S))*X. */ |
| 20107 |
|
| 20108 |
/* LDX (input) INTEGER */ |
| 20109 |
/* The leading dimension of the array X. LDX >= max(1,N). */ |
| 20110 |
|
| 20111 |
/* RCOND (output) DOUBLE PRECISION */ |
| 20112 |
/* Reciprocal scaled condition number. This is an estimate of the */ |
| 20113 |
/* reciprocal Skeel condition number of the matrix A after */ |
| 20114 |
/* equilibration (if done). If this is less than the machine */ |
| 20115 |
/* precision (in particular, if it is zero), the matrix is singular */ |
| 20116 |
/* to working precision. Note that the error may still be small even */ |
| 20117 |
/* if this number is very small and the matrix appears ill- */ |
| 20118 |
/* conditioned. */ |
| 20119 |
|
| 20120 |
/* RPVGRW (output) DOUBLE PRECISION */ |
| 20121 |
/* Reciprocal pivot growth. On exit, this contains the reciprocal */ |
| 20122 |
/* pivot growth factor norm(A)/norm(U). The "max absolute element" */ |
| 20123 |
/* norm is used. If this is much less than 1, then the stability of */ |
| 20124 |
/* the LU factorization of the (equilibrated) matrix A could be poor. */ |
| 20125 |
/* This also means that the solution X, estimated condition numbers, */ |
| 20126 |
/* and error bounds could be unreliable. If factorization fails with */ |
| 20127 |
/* 0<INFO<=N, then this contains the reciprocal pivot growth factor */ |
| 20128 |
/* for the leading INFO columns of A. */ |
| 20129 |
|
| 20130 |
/* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */ |
| 20131 |
/* Componentwise relative backward error. This is the */ |
| 20132 |
/* componentwise relative backward error of each solution vector X(j) */ |
| 20133 |
/* (i.e., the smallest relative change in any element of A or B that */ |
| 20134 |
/* makes X(j) an exact solution). */ |
| 20135 |
|
| 20136 |
/* N_ERR_BNDS (input) INTEGER */ |
| 20137 |
/* Number of error bounds to return for each right hand side */ |
| 20138 |
/* and each type (normwise or componentwise). See ERR_BNDS_NORM and */ |
| 20139 |
/* ERR_BNDS_COMP below. */ |
| 20140 |
|
| 20141 |
/* ERR_BNDS_NORM (output) DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) */ |
| 20142 |
/* For each right-hand side, this array contains information about */ |
| 20143 |
/* various error bounds and condition numbers corresponding to the */ |
| 20144 |
/* normwise relative error, which is defined as follows: */ |
| 20145 |
|
| 20146 |
/* Normwise relative error in the ith solution vector: */ |
| 20147 |
/* max_j (abs(XTRUE(j,i) - X(j,i))) */ |
| 20148 |
/* ------------------------------ */ |
| 20149 |
/* max_j abs(X(j,i)) */ |
| 20150 |
|
| 20151 |
/* The array is indexed by the type of error information as described */ |
| 20152 |
/* below. There currently are up to three pieces of information */ |
| 20153 |
/* returned. */ |
| 20154 |
|
| 20155 |
/* The first index in ERR_BNDS_NORM(i,:) corresponds to the ith */ |
| 20156 |
/* right-hand side. */ |
| 20157 |
|
| 20158 |
/* The second index in ERR_BNDS_NORM(:,err) contains the following */ |
| 20159 |
/* three fields: */ |
| 20160 |
/* err = 1 "Trust/don't trust" boolean. Trust the answer if the */ |
| 20161 |
/* reciprocal condition number is less than the threshold */ |
| 20162 |
/* sqrt(n) * dlamch('Epsilon'). */ |
| 20163 |
|
| 20164 |
/* err = 2 "Guaranteed" error bound: The estimated forward error, */ |
| 20165 |
/* almost certainly within a factor of 10 of the true error */ |
| 20166 |
/* so long as the next entry is greater than the threshold */ |
| 20167 |
/* sqrt(n) * dlamch('Epsilon'). This error bound should only */ |
| 20168 |
/* be trusted if the previous boolean is true. */ |
| 20169 |
|
| 20170 |
/* err = 3 Reciprocal condition number: Estimated normwise */ |
| 20171 |
/* reciprocal condition number. Compared with the threshold */ |
| 20172 |
/* sqrt(n) * dlamch('Epsilon') to determine if the error */ |
| 20173 |
/* estimate is "guaranteed". These reciprocal condition */ |
| 20174 |
/* numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */ |
| 20175 |
/* appropriately scaled matrix Z. */ |
| 20176 |
/* Let Z = S*A, where S scales each row by a power of the */ |
| 20177 |
/* radix so all absolute row sums of Z are approximately 1. */ |
| 20178 |
|
| 20179 |
/* See Lapack Working Note 165 for further details and extra */ |
| 20180 |
/* cautions. */ |
| 20181 |
|
| 20182 |
/* ERR_BNDS_COMP (output) DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) */ |
| 20183 |
/* For each right-hand side, this array contains information about */ |
| 20184 |
/* various error bounds and condition numbers corresponding to the */ |
| 20185 |
/* componentwise relative error, which is defined as follows: */ |
| 20186 |
|
| 20187 |
/* Componentwise relative error in the ith solution vector: */ |
| 20188 |
/* abs(XTRUE(j,i) - X(j,i)) */ |
| 20189 |
/* max_j ---------------------- */ |
| 20190 |
/* abs(X(j,i)) */ |
| 20191 |
|
| 20192 |
/* The array is indexed by the right-hand side i (on which the */ |
| 20193 |
/* componentwise relative error depends), and the type of error */ |
| 20194 |
/* information as described below. There currently are up to three */ |
| 20195 |
/* pieces of information returned for each right-hand side. If */ |
| 20196 |
/* componentwise accuracy is not requested (PARAMS(3) = 0.0), then */ |
| 20197 |
/* ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most */ |
| 20198 |
/* the first (:,N_ERR_BNDS) entries are returned. */ |
| 20199 |
|
| 20200 |
/* The first index in ERR_BNDS_COMP(i,:) corresponds to the ith */ |
| 20201 |
/* right-hand side. */ |
| 20202 |
|
| 20203 |
/* The second index in ERR_BNDS_COMP(:,err) contains the following */ |
| 20204 |
/* three fields: */ |
| 20205 |
/* err = 1 "Trust/don't trust" boolean. Trust the answer if the */ |
| 20206 |
/* reciprocal condition number is less than the threshold */ |
| 20207 |
/* sqrt(n) * dlamch('Epsilon'). */ |
| 20208 |
|
| 20209 |
/* err = 2 "Guaranteed" error bound: The estimated forward error, */ |
| 20210 |
/* almost certainly within a factor of 10 of the true error */ |
| 20211 |
/* so long as the next entry is greater than the threshold */ |
| 20212 |
/* sqrt(n) * dlamch('Epsilon'). This error bound should only */ |
| 20213 |
/* be trusted if the previous boolean is true. */ |
| 20214 |
|
| 20215 |
/* err = 3 Reciprocal condition number: Estimated componentwise */ |
| 20216 |
/* reciprocal condition number. Compared with the threshold */ |
| 20217 |
/* sqrt(n) * dlamch('Epsilon') to determine if the error */ |
| 20218 |
/* estimate is "guaranteed". These reciprocal condition */ |
| 20219 |
/* numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */ |
| 20220 |
/* appropriately scaled matrix Z. */ |
| 20221 |
/* Let Z = S*(A*diag(x)), where x is the solution for the */ |
| 20222 |
/* current right-hand side and S scales each row of */ |
| 20223 |
/* A*diag(x) by a power of the radix so all absolute row */ |
| 20224 |
/* sums of Z are approximately 1. */ |
| 20225 |
|
| 20226 |
/* See Lapack Working Note 165 for further details and extra */ |
| 20227 |
/* cautions. */ |
| 20228 |
|
| 20229 |
/* NPARAMS (input) INTEGER */ |
| 20230 |
/* Specifies the number of parameters set in PARAMS. If .LE. 0, the */ |
| 20231 |
/* PARAMS array is never referenced and default values are used. */ |
| 20232 |
|
| 20233 |
/* PARAMS (input / output) DOUBLE PRECISION array, dimension NPARAMS */ |
| 20234 |
/* Specifies algorithm parameters. If an entry is .LT. 0.0, then */ |
| 20235 |
/* that entry will be filled with default value used for that */ |
| 20236 |
/* parameter. Only positions up to NPARAMS are accessed; defaults */ |
| 20237 |
/* are used for higher-numbered parameters. */ |
| 20238 |
|
| 20239 |
/* PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative */ |
| 20240 |
/* refinement or not. */ |
| 20241 |
/* Default: 1.0D+0 */ |
| 20242 |
/* = 0.0 : No refinement is performed, and no error bounds are */ |
| 20243 |
/* computed. */ |
| 20244 |
/* = 1.0 : Use the extra-precise refinement algorithm. */ |
| 20245 |
/* (other values are reserved for future use) */ |
| 20246 |
|
| 20247 |
/* PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual */ |
| 20248 |
/* computations allowed for refinement. */ |
| 20249 |
/* Default: 10 */ |
| 20250 |
/* Aggressive: Set to 100 to permit convergence using approximate */ |
| 20251 |
/* factorizations or factorizations other than LU. If */ |
| 20252 |
/* the factorization uses a technique other than */ |
| 20253 |
/* Gaussian elimination, the guarantees in */ |
| 20254 |
/* err_bnds_norm and err_bnds_comp may no longer be */ |
| 20255 |
/* trustworthy. */ |
| 20256 |
|
| 20257 |
/* PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code */ |
| 20258 |
/* will attempt to find a solution with small componentwise */ |
| 20259 |
/* relative error in the double-precision algorithm. Positive */ |
| 20260 |
/* is true, 0.0 is false. */ |
| 20261 |
/* Default: 1.0 (attempt componentwise convergence) */ |
| 20262 |
|
| 20263 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (4*N) */ |
| 20264 |
|
| 20265 |
/* IWORK (workspace) INTEGER array, dimension (N) */ |
| 20266 |
|
| 20267 |
/* INFO (output) INTEGER */ |
| 20268 |
/* = 0: Successful exit. The solution to every right-hand side is */ |
| 20269 |
/* guaranteed. */ |
| 20270 |
/* < 0: If INFO = -i, the i-th argument had an illegal value */ |
| 20271 |
/* > 0 and <= N: U(INFO,INFO) is exactly zero. The factorization */ |
| 20272 |
/* has been completed, but the factor U is exactly singular, so */ |
| 20273 |
/* the solution and error bounds could not be computed. RCOND = 0 */ |
| 20274 |
/* is returned. */ |
| 20275 |
/* = N+J: The solution corresponding to the Jth right-hand side is */ |
| 20276 |
/* not guaranteed. The solutions corresponding to other right- */ |
| 20277 |
/* hand sides K with K > J may not be guaranteed as well, but */ |
| 20278 |
/* only the first such right-hand side is reported. If a small */ |
| 20279 |
/* componentwise error is not requested (PARAMS(3) = 0.0) then */ |
| 20280 |
/* the Jth right-hand side is the first with a normwise error */ |
| 20281 |
/* bound that is not guaranteed (the smallest J such */ |
| 20282 |
/* that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0) */ |
| 20283 |
/* the Jth right-hand side is the first with either a normwise or */ |
| 20284 |
/* componentwise error bound that is not guaranteed (the smallest */ |
| 20285 |
/* J such that either ERR_BNDS_NORM(J,1) = 0.0 or */ |
| 20286 |
/* ERR_BNDS_COMP(J,1) = 0.0). See the definition of */ |
| 20287 |
/* ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information */ |
| 20288 |
/* about all of the right-hand sides check ERR_BNDS_NORM or */ |
| 20289 |
/* ERR_BNDS_COMP. */ |
| 20290 |
|
| 20291 |
/* ================================================================== */ |
| 20292 |
|
| 20293 |
/* .. Parameters .. */ |
| 20294 |
/* .. */ |
| 20295 |
/* .. Local Scalars .. */ |
| 20296 |
/* .. */ |
| 20297 |
/* .. External Functions .. */ |
| 20298 |
/* .. */ |
| 20299 |
/* .. External Subroutines .. */ |
| 20300 |
/* .. */ |
| 20301 |
/* .. Intrinsic Functions .. */ |
| 20302 |
/* .. */ |
| 20303 |
/* .. Executable Statements .. */ |
| 20304 |
|
| 20305 |
/* Parameter adjustments */ |
| 20306 |
err_bnds_comp_dim1 = *nrhs; |
| 20307 |
err_bnds_comp_offset = 1 + err_bnds_comp_dim1; |
| 20308 |
err_bnds_comp__ -= err_bnds_comp_offset; |
| 20309 |
err_bnds_norm_dim1 = *nrhs; |
| 20310 |
err_bnds_norm_offset = 1 + err_bnds_norm_dim1; |
| 20311 |
err_bnds_norm__ -= err_bnds_norm_offset; |
| 20312 |
a_dim1 = *lda; |
| 20313 |
a_offset = 1 + a_dim1; |
| 20314 |
a -= a_offset; |
| 20315 |
af_dim1 = *ldaf; |
| 20316 |
af_offset = 1 + af_dim1; |
| 20317 |
af -= af_offset; |
| 20318 |
--ipiv; |
| 20319 |
--s; |
| 20320 |
b_dim1 = *ldb; |
| 20321 |
b_offset = 1 + b_dim1; |
| 20322 |
b -= b_offset; |
| 20323 |
x_dim1 = *ldx; |
| 20324 |
x_offset = 1 + x_dim1; |
| 20325 |
x -= x_offset; |
| 20326 |
--berr; |
| 20327 |
--params; |
| 20328 |
--work; |
| 20329 |
--iwork; |
| 20330 |
|
| 20331 |
/* Function Body */ |
| 20332 |
*info = 0; |
| 20333 |
nofact = lsame_(fact, "N"); |
| 20334 |
equil = lsame_(fact, "E"); |
| 20335 |
smlnum = dlamch_("Safe minimum"); |
| 20336 |
bignum = 1. / smlnum; |
| 20337 |
if (nofact || equil) { |
| 20338 |
*(unsigned char *)equed = 'N'; |
| 20339 |
rcequ = false; |
| 20340 |
} else { |
| 20341 |
rcequ = lsame_(equed, "Y"); |
| 20342 |
} |
| 20343 |
|
| 20344 |
/* Default is failure. If an input parameter is wrong or */ |
| 20345 |
/* factorization fails, make everything look horrible. Only the */ |
| 20346 |
/* pivot growth is set here, the rest is initialized in DSYRFSX. */ |
| 20347 |
|
| 20348 |
*rpvgrw = 0.; |
| 20349 |
|
| 20350 |
/* Test the input parameters. PARAMS is not tested until DSYRFSX. */ |
| 20351 |
|
| 20352 |
if (! nofact && ! equil && ! lsame_(fact, "F")) { |
| 20353 |
*info = -1; |
| 20354 |
} else if (! lsame_(uplo, "U") && ! lsame_(uplo, |
| 20355 |
"L")) { |
| 20356 |
*info = -2; |
| 20357 |
} else if (*n < 0) { |
| 20358 |
*info = -3; |
| 20359 |
} else if (*nrhs < 0) { |
| 20360 |
*info = -4; |
| 20361 |
} else if (*lda < std::max(1_integer,*n)) { |
| 20362 |
*info = -6; |
| 20363 |
} else if (*ldaf < std::max(1_integer,*n)) { |
| 20364 |
*info = -8; |
| 20365 |
} else if (lsame_(fact, "F") && ! (rcequ || lsame_( |
| 20366 |
equed, "N"))) { |
| 20367 |
*info = -9; |
| 20368 |
} else { |
| 20369 |
if (rcequ) { |
| 20370 |
smin = bignum; |
| 20371 |
smax = 0.; |
| 20372 |
i__1 = *n; |
| 20373 |
for (j = 1; j <= i__1; ++j) { |
| 20374 |
/* Computing MIN */ |
| 20375 |
d__1 = smin, d__2 = s[j]; |
| 20376 |
smin = std::min(d__1,d__2); |
| 20377 |
/* Computing MAX */ |
| 20378 |
d__1 = smax, d__2 = s[j]; |
| 20379 |
smax = std::max(d__1,d__2); |
| 20380 |
/* L10: */ |
| 20381 |
} |
| 20382 |
if (smin <= 0.) { |
| 20383 |
*info = -10; |
| 20384 |
} else if (*n > 0) { |
| 20385 |
scond = std::max(smin,smlnum) / min(smax,bignum); |
| 20386 |
} else { |
| 20387 |
scond = 1.; |
| 20388 |
} |
| 20389 |
} |
| 20390 |
if (*info == 0) { |
| 20391 |
if (*ldb < std::max(1_integer,*n)) { |
| 20392 |
*info = -12; |
| 20393 |
} else if (*ldx < std::max(1_integer,*n)) { |
| 20394 |
*info = -14; |
| 20395 |
} |
| 20396 |
} |
| 20397 |
} |
| 20398 |
|
| 20399 |
if (*info != 0) { |
| 20400 |
i__1 = -(*info); |
| 20401 |
xerbla_("DSYSVXX", &i__1); |
| 20402 |
return 0; |
| 20403 |
} |
| 20404 |
|
| 20405 |
if (equil) { |
| 20406 |
|
| 20407 |
/* Compute row and column scalings to equilibrate the matrix A. */ |
| 20408 |
|
| 20409 |
dsyequb_(uplo, n, &a[a_offset], lda, &s[1], &scond, &amax, &work[1], & |
| 20410 |
infequ); |
| 20411 |
if (infequ == 0) { |
| 20412 |
|
| 20413 |
/* Equilibrate the matrix. */ |
| 20414 |
|
| 20415 |
dlaqsy_(uplo, n, &a[a_offset], lda, &s[1], &scond, &amax, equed); |
| 20416 |
rcequ = lsame_(equed, "Y"); |
| 20417 |
} |
| 20418 |
} |
| 20419 |
|
| 20420 |
/* Scale the right-hand side. */ |
| 20421 |
|
| 20422 |
if (rcequ) { |
| 20423 |
dlascl2_(n, nrhs, &s[1], &b[b_offset], ldb); |
| 20424 |
} |
| 20425 |
|
| 20426 |
if (nofact || equil) { |
| 20427 |
|
| 20428 |
/* Compute the LU factorization of A. */ |
| 20429 |
|
| 20430 |
dlacpy_(uplo, n, n, &a[a_offset], lda, &af[af_offset], ldaf); |
| 20431 |
i__1 = std::max(1_integer,*n) * 5; |
| 20432 |
dsytrf_(uplo, n, &af[af_offset], ldaf, &ipiv[1], &work[1], &i__1, |
| 20433 |
info); |
| 20434 |
|
| 20435 |
/* Return if INFO is non-zero. */ |
| 20436 |
|
| 20437 |
if (*info > 0) { |
| 20438 |
|
| 20439 |
/* Pivot in column INFO is exactly 0 */ |
| 20440 |
/* Compute the reciprocal pivot growth factor of the */ |
| 20441 |
/* leading rank-deficient INFO columns of A. */ |
| 20442 |
|
| 20443 |
if (*n > 0) { |
| 20444 |
*rpvgrw = dla_syrpvgrw__(uplo, n, info, &a[a_offset], lda, & |
| 20445 |
af[af_offset], ldaf, &ipiv[1], &work[1], 1_integer); |
| 20446 |
} |
| 20447 |
return 0; |
| 20448 |
} |
| 20449 |
} |
| 20450 |
|
| 20451 |
/* Compute the reciprocal pivot growth factor RPVGRW. */ |
| 20452 |
|
| 20453 |
if (*n > 0) { |
| 20454 |
*rpvgrw = dla_syrpvgrw__(uplo, n, info, &a[a_offset], lda, &af[ |
| 20455 |
af_offset], ldaf, &ipiv[1], &work[1], 1_integer); |
| 20456 |
} |
| 20457 |
|
| 20458 |
/* Compute the solution matrix X. */ |
| 20459 |
|
| 20460 |
dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx); |
| 20461 |
dsytrs_(uplo, n, nrhs, &af[af_offset], ldaf, &ipiv[1], &x[x_offset], ldx, info); |
| 20462 |
|
| 20463 |
/* Use iterative refinement to improve the computed solution and */ |
| 20464 |
/* compute error bounds and backward error estimates for it. */ |
| 20465 |
|
| 20466 |
dsyrfsx_(uplo, equed, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, & |
| 20467 |
ipiv[1], &s[1], &b[b_offset], ldb, &x[x_offset], ldx, rcond, & |
| 20468 |
berr[1], n_err_bnds__, &err_bnds_norm__[err_bnds_norm_offset], & |
| 20469 |
err_bnds_comp__[err_bnds_comp_offset], nparams, ¶ms[1], &work[ |
| 20470 |
1], &iwork[1], info); |
| 20471 |
|
| 20472 |
/* Scale solutions. */ |
| 20473 |
|
| 20474 |
if (rcequ) { |
| 20475 |
dlascl2_(n, nrhs, &s[1], &x[x_offset], ldx); |
| 20476 |
} |
| 20477 |
|
| 20478 |
return 0; |
| 20479 |
|
| 20480 |
/* End of DSYSVXX */ |
| 20481 |
|
| 20482 |
} /* dsysvxx_ */ |
| 20483 |
#endif |
| 20484 |
|
| 20485 |
/* Subroutine */ int dsytd2_(const char *uplo, integer *n, double *a, integer * |
| 20486 |
lda, double *d__, double *e, double *tau, integer *info) |
| 20487 |
{ |
| 20488 |
/* Table of constant values */ |
| 20489 |
static integer c__1 = 1; |
| 20490 |
static double c_b8 = 0.; |
| 20491 |
static double c_b14 = -1.; |
| 20492 |
|
| 20493 |
/* System generated locals */ |
| 20494 |
integer a_dim1, a_offset, i__1, i__2, i__3; |
| 20495 |
|
| 20496 |
/* Local variables */ |
| 20497 |
integer i__; |
| 20498 |
double taui; |
| 20499 |
double alpha; |
| 20500 |
bool upper; |
| 20501 |
|
| 20502 |
/* -- LAPACK routine (version 3.1) -- */ |
| 20503 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 20504 |
/* November 2006 */ |
| 20505 |
|
| 20506 |
/* .. Scalar Arguments .. */ |
| 20507 |
/* .. */ |
| 20508 |
/* .. Array Arguments .. */ |
| 20509 |
/* .. */ |
| 20510 |
|
| 20511 |
/* Purpose */ |
| 20512 |
/* ======= */ |
| 20513 |
|
| 20514 |
/* DSYTD2 reduces a real symmetric matrix A to symmetric tridiagonal */ |
| 20515 |
/* form T by an orthogonal similarity transformation: Q' * A * Q = T. */ |
| 20516 |
|
| 20517 |
/* Arguments */ |
| 20518 |
/* ========= */ |
| 20519 |
|
| 20520 |
/* UPLO (input) CHARACTER*1 */ |
| 20521 |
/* Specifies whether the upper or lower triangular part of the */ |
| 20522 |
/* symmetric matrix A is stored: */ |
| 20523 |
/* = 'U': Upper triangular */ |
| 20524 |
/* = 'L': Lower triangular */ |
| 20525 |
|
| 20526 |
/* N (input) INTEGER */ |
| 20527 |
/* The order of the matrix A. N >= 0. */ |
| 20528 |
|
| 20529 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 20530 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the leading */ |
| 20531 |
/* n-by-n upper triangular part of A contains the upper */ |
| 20532 |
/* triangular part of the matrix A, and the strictly lower */ |
| 20533 |
/* triangular part of A is not referenced. If UPLO = 'L', the */ |
| 20534 |
/* leading n-by-n lower triangular part of A contains the lower */ |
| 20535 |
/* triangular part of the matrix A, and the strictly upper */ |
| 20536 |
/* triangular part of A is not referenced. */ |
| 20537 |
/* On exit, if UPLO = 'U', the diagonal and first superdiagonal */ |
| 20538 |
/* of A are overwritten by the corresponding elements of the */ |
| 20539 |
/* tridiagonal matrix T, and the elements above the first */ |
| 20540 |
/* superdiagonal, with the array TAU, represent the orthogonal */ |
| 20541 |
/* matrix Q as a product of elementary reflectors; if UPLO */ |
| 20542 |
/* = 'L', the diagonal and first subdiagonal of A are over- */ |
| 20543 |
/* written by the corresponding elements of the tridiagonal */ |
| 20544 |
/* matrix T, and the elements below the first subdiagonal, with */ |
| 20545 |
/* the array TAU, represent the orthogonal matrix Q as a product */ |
| 20546 |
/* of elementary reflectors. See Further Details. */ |
| 20547 |
|
| 20548 |
/* LDA (input) INTEGER */ |
| 20549 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 20550 |
|
| 20551 |
/* D (output) DOUBLE PRECISION array, dimension (N) */ |
| 20552 |
/* The diagonal elements of the tridiagonal matrix T: */ |
| 20553 |
/* D(i) = A(i,i). */ |
| 20554 |
|
| 20555 |
/* E (output) DOUBLE PRECISION array, dimension (N-1) */ |
| 20556 |
/* The off-diagonal elements of the tridiagonal matrix T: */ |
| 20557 |
/* E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */ |
| 20558 |
|
| 20559 |
/* TAU (output) DOUBLE PRECISION array, dimension (N-1) */ |
| 20560 |
/* The scalar factors of the elementary reflectors (see Further */ |
| 20561 |
/* Details). */ |
| 20562 |
|
| 20563 |
/* INFO (output) INTEGER */ |
| 20564 |
/* = 0: successful exit */ |
| 20565 |
/* < 0: if INFO = -i, the i-th argument had an illegal value. */ |
| 20566 |
|
| 20567 |
/* Further Details */ |
| 20568 |
/* =============== */ |
| 20569 |
|
| 20570 |
/* If UPLO = 'U', the matrix Q is represented as a product of elementary */ |
| 20571 |
/* reflectors */ |
| 20572 |
|
| 20573 |
/* Q = H(n-1) . . . H(2) H(1). */ |
| 20574 |
|
| 20575 |
/* Each H(i) has the form */ |
| 20576 |
|
| 20577 |
/* H(i) = I - tau * v * v' */ |
| 20578 |
|
| 20579 |
/* where tau is a real scalar, and v is a real vector with */ |
| 20580 |
/* v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in */ |
| 20581 |
/* A(1:i-1,i+1), and tau in TAU(i). */ |
| 20582 |
|
| 20583 |
/* If UPLO = 'L', the matrix Q is represented as a product of elementary */ |
| 20584 |
/* reflectors */ |
| 20585 |
|
| 20586 |
/* Q = H(1) H(2) . . . H(n-1). */ |
| 20587 |
|
| 20588 |
/* Each H(i) has the form */ |
| 20589 |
|
| 20590 |
/* H(i) = I - tau * v * v' */ |
| 20591 |
|
| 20592 |
/* where tau is a real scalar, and v is a real vector with */ |
| 20593 |
/* v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i), */ |
| 20594 |
/* and tau in TAU(i). */ |
| 20595 |
|
| 20596 |
/* The contents of A on exit are illustrated by the following examples */ |
| 20597 |
/* with n = 5: */ |
| 20598 |
|
| 20599 |
/* if UPLO = 'U': if UPLO = 'L': */ |
| 20600 |
|
| 20601 |
/* ( d e v2 v3 v4 ) ( d ) */ |
| 20602 |
/* ( d e v3 v4 ) ( e d ) */ |
| 20603 |
/* ( d e v4 ) ( v1 e d ) */ |
| 20604 |
/* ( d e ) ( v1 v2 e d ) */ |
| 20605 |
/* ( d ) ( v1 v2 v3 e d ) */ |
| 20606 |
|
| 20607 |
/* where d and e denote diagonal and off-diagonal elements of T, and vi */ |
| 20608 |
/* denotes an element of the vector defining H(i). */ |
| 20609 |
|
| 20610 |
/* ===================================================================== */ |
| 20611 |
|
| 20612 |
/* .. Parameters .. */ |
| 20613 |
/* .. */ |
| 20614 |
/* .. Local Scalars .. */ |
| 20615 |
/* .. */ |
| 20616 |
/* .. External Subroutines .. */ |
| 20617 |
/* .. */ |
| 20618 |
/* .. External Functions .. */ |
| 20619 |
/* .. */ |
| 20620 |
/* .. Intrinsic Functions .. */ |
| 20621 |
/* .. */ |
| 20622 |
/* .. Executable Statements .. */ |
| 20623 |
|
| 20624 |
/* Test the input parameters */ |
| 20625 |
|
| 20626 |
/* Parameter adjustments */ |
| 20627 |
a_dim1 = *lda; |
| 20628 |
a_offset = 1 + a_dim1; |
| 20629 |
a -= a_offset; |
| 20630 |
--d__; |
| 20631 |
--e; |
| 20632 |
--tau; |
| 20633 |
|
| 20634 |
/* Function Body */ |
| 20635 |
*info = 0; |
| 20636 |
upper = lsame_(uplo, "U"); |
| 20637 |
if (! upper && ! lsame_(uplo, "L")) { |
| 20638 |
*info = -1; |
| 20639 |
} else if (*n < 0) { |
| 20640 |
*info = -2; |
| 20641 |
} else if (*lda < std::max(1_integer,*n)) { |
| 20642 |
*info = -4; |
| 20643 |
} |
| 20644 |
if (*info != 0) { |
| 20645 |
i__1 = -(*info); |
| 20646 |
xerbla_("DSYTD2", &i__1); |
| 20647 |
return 0; |
| 20648 |
} |
| 20649 |
|
| 20650 |
/* Quick return if possible */ |
| 20651 |
|
| 20652 |
if (*n <= 0) { |
| 20653 |
return 0; |
| 20654 |
} |
| 20655 |
|
| 20656 |
if (upper) { |
| 20657 |
|
| 20658 |
/* Reduce the upper triangle of A */ |
| 20659 |
|
| 20660 |
for (i__ = *n - 1; i__ >= 1; --i__) { |
| 20661 |
|
| 20662 |
/* Generate elementary reflector H(i) = I - tau * v * v' */ |
| 20663 |
/* to annihilate A(1:i-1,i+1) */ |
| 20664 |
|
| 20665 |
dlarfg_(&i__, &a[i__ + (i__ + 1) * a_dim1], &a[(i__ + 1) * a_dim1 |
| 20666 |
+ 1], &c__1, &taui); |
| 20667 |
e[i__] = a[i__ + (i__ + 1) * a_dim1]; |
| 20668 |
|
| 20669 |
if (taui != 0.) { |
| 20670 |
|
| 20671 |
/* Apply H(i) from both sides to A(1:i,1:i) */ |
| 20672 |
|
| 20673 |
a[i__ + (i__ + 1) * a_dim1] = 1.; |
| 20674 |
|
| 20675 |
/* Compute x := tau * A * v storing x in TAU(1:i) */ |
| 20676 |
|
| 20677 |
dsymv_(uplo, &i__, &taui, &a[a_offset], lda, &a[(i__ + 1) * |
| 20678 |
a_dim1 + 1], &c__1, &c_b8, &tau[1], &c__1); |
| 20679 |
|
| 20680 |
/* Compute w := x - 1/2 * tau * (x'*v) * v */ |
| 20681 |
|
| 20682 |
alpha = taui * -.5 * ddot_(&i__, &tau[1], &c__1, &a[(i__ + 1) |
| 20683 |
* a_dim1 + 1], &c__1); |
| 20684 |
daxpy_(&i__, &alpha, &a[(i__ + 1) * a_dim1 + 1], &c__1, &tau[ |
| 20685 |
1], &c__1); |
| 20686 |
|
| 20687 |
/* Apply the transformation as a rank-2 update: */ |
| 20688 |
/* A := A - v * w' - w * v' */ |
| 20689 |
|
| 20690 |
dsyr2_(uplo, &i__, &c_b14, &a[(i__ + 1) * a_dim1 + 1], &c__1, |
| 20691 |
&tau[1], &c__1, &a[a_offset], lda); |
| 20692 |
|
| 20693 |
a[i__ + (i__ + 1) * a_dim1] = e[i__]; |
| 20694 |
} |
| 20695 |
d__[i__ + 1] = a[i__ + 1 + (i__ + 1) * a_dim1]; |
| 20696 |
tau[i__] = taui; |
| 20697 |
/* L10: */ |
| 20698 |
} |
| 20699 |
d__[1] = a[a_dim1 + 1]; |
| 20700 |
} else { |
| 20701 |
|
| 20702 |
/* Reduce the lower triangle of A */ |
| 20703 |
|
| 20704 |
i__1 = *n - 1; |
| 20705 |
for (i__ = 1; i__ <= i__1; ++i__) { |
| 20706 |
|
| 20707 |
/* Generate elementary reflector H(i) = I - tau * v * v' */ |
| 20708 |
/* to annihilate A(i+2:n,i) */ |
| 20709 |
|
| 20710 |
i__2 = *n - i__; |
| 20711 |
/* Computing MIN */ |
| 20712 |
i__3 = i__ + 2; |
| 20713 |
dlarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[std::min(i__3, *n)+ i__ * |
| 20714 |
a_dim1], &c__1, &taui); |
| 20715 |
e[i__] = a[i__ + 1 + i__ * a_dim1]; |
| 20716 |
|
| 20717 |
if (taui != 0.) { |
| 20718 |
|
| 20719 |
/* Apply H(i) from both sides to A(i+1:n,i+1:n) */ |
| 20720 |
|
| 20721 |
a[i__ + 1 + i__ * a_dim1] = 1.; |
| 20722 |
|
| 20723 |
/* Compute x := tau * A * v storing y in TAU(i:n-1) */ |
| 20724 |
|
| 20725 |
i__2 = *n - i__; |
| 20726 |
dsymv_(uplo, &i__2, &taui, &a[i__ + 1 + (i__ + 1) * a_dim1], |
| 20727 |
lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b8, &tau[ |
| 20728 |
i__], &c__1); |
| 20729 |
|
| 20730 |
/* Compute w := x - 1/2 * tau * (x'*v) * v */ |
| 20731 |
|
| 20732 |
i__2 = *n - i__; |
| 20733 |
alpha = taui * -.5 * ddot_(&i__2, &tau[i__], &c__1, &a[i__ + |
| 20734 |
1 + i__ * a_dim1], &c__1); |
| 20735 |
i__2 = *n - i__; |
| 20736 |
daxpy_(&i__2, &alpha, &a[i__ + 1 + i__ * a_dim1], &c__1, &tau[ |
| 20737 |
i__], &c__1); |
| 20738 |
|
| 20739 |
/* Apply the transformation as a rank-2 update: */ |
| 20740 |
/* A := A - v * w' - w * v' */ |
| 20741 |
|
| 20742 |
i__2 = *n - i__; |
| 20743 |
dsyr2_(uplo, &i__2, &c_b14, &a[i__ + 1 + i__ * a_dim1], &c__1, |
| 20744 |
&tau[i__], &c__1, &a[i__ + 1 + (i__ + 1) * a_dim1], |
| 20745 |
lda); |
| 20746 |
|
| 20747 |
a[i__ + 1 + i__ * a_dim1] = e[i__]; |
| 20748 |
} |
| 20749 |
d__[i__] = a[i__ + i__ * a_dim1]; |
| 20750 |
tau[i__] = taui; |
| 20751 |
/* L20: */ |
| 20752 |
} |
| 20753 |
d__[*n] = a[*n + *n * a_dim1]; |
| 20754 |
} |
| 20755 |
|
| 20756 |
return 0; |
| 20757 |
|
| 20758 |
/* End of DSYTD2 */ |
| 20759 |
|
| 20760 |
} /* dsytd2_ */ |
| 20761 |
|
| 20762 |
/* Subroutine */ int dsytf2_(const char *uplo, integer *n, double *a, integer * |
| 20763 |
lda, integer *ipiv, integer *info) |
| 20764 |
{ |
| 20765 |
/* Table of constant values */ |
| 20766 |
static integer c__1 = 1; |
| 20767 |
|
| 20768 |
/* System generated locals */ |
| 20769 |
integer a_dim1, a_offset, i__1, i__2; |
| 20770 |
double d__1, d__2, d__3; |
| 20771 |
|
| 20772 |
/* Local variables */ |
| 20773 |
integer i__, j, k; |
| 20774 |
double t, r1, d11, d12, d21, d22; |
| 20775 |
integer kk, kp; |
| 20776 |
double wk, wkm1, wkp1; |
| 20777 |
integer imax, jmax; |
| 20778 |
double alpha; |
| 20779 |
integer kstep; |
| 20780 |
bool upper; |
| 20781 |
double absakk; |
| 20782 |
double colmax, rowmax; |
| 20783 |
|
| 20784 |
|
| 20785 |
/* -- LAPACK routine (version 3.1) -- */ |
| 20786 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 20787 |
/* November 2006 */ |
| 20788 |
|
| 20789 |
/* .. Scalar Arguments .. */ |
| 20790 |
/* .. */ |
| 20791 |
/* .. Array Arguments .. */ |
| 20792 |
/* .. */ |
| 20793 |
|
| 20794 |
/* Purpose */ |
| 20795 |
/* ======= */ |
| 20796 |
|
| 20797 |
/* DSYTF2 computes the factorization of a real symmetric matrix A using */ |
| 20798 |
/* the Bunch-Kaufman diagonal pivoting method: */ |
| 20799 |
|
| 20800 |
/* A = U*D*U' or A = L*D*L' */ |
| 20801 |
|
| 20802 |
/* where U (or L) is a product of permutation and unit upper (lower) */ |
| 20803 |
/* triangular matrices, U' is the transpose of U, and D is symmetric and */ |
| 20804 |
/* block diagonal with 1-by-1 and 2-by-2 diagonal blocks. */ |
| 20805 |
|
| 20806 |
/* This is the unblocked version of the algorithm, calling Level 2 BLAS. */ |
| 20807 |
|
| 20808 |
/* Arguments */ |
| 20809 |
/* ========= */ |
| 20810 |
|
| 20811 |
/* UPLO (input) CHARACTER*1 */ |
| 20812 |
/* Specifies whether the upper or lower triangular part of the */ |
| 20813 |
/* symmetric matrix A is stored: */ |
| 20814 |
/* = 'U': Upper triangular */ |
| 20815 |
/* = 'L': Lower triangular */ |
| 20816 |
|
| 20817 |
/* N (input) INTEGER */ |
| 20818 |
/* The order of the matrix A. N >= 0. */ |
| 20819 |
|
| 20820 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 20821 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the leading */ |
| 20822 |
/* n-by-n upper triangular part of A contains the upper */ |
| 20823 |
/* triangular part of the matrix A, and the strictly lower */ |
| 20824 |
/* triangular part of A is not referenced. If UPLO = 'L', the */ |
| 20825 |
/* leading n-by-n lower triangular part of A contains the lower */ |
| 20826 |
/* triangular part of the matrix A, and the strictly upper */ |
| 20827 |
/* triangular part of A is not referenced. */ |
| 20828 |
|
| 20829 |
/* On exit, the block diagonal matrix D and the multipliers used */ |
| 20830 |
/* to obtain the factor U or L (see below for further details). */ |
| 20831 |
|
| 20832 |
/* LDA (input) INTEGER */ |
| 20833 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 20834 |
|
| 20835 |
/* IPIV (output) INTEGER array, dimension (N) */ |
| 20836 |
/* Details of the interchanges and the block structure of D. */ |
| 20837 |
/* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */ |
| 20838 |
/* interchanged and D(k,k) is a 1-by-1 diagonal block. */ |
| 20839 |
/* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */ |
| 20840 |
/* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */ |
| 20841 |
/* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */ |
| 20842 |
/* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */ |
| 20843 |
/* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */ |
| 20844 |
|
| 20845 |
/* INFO (output) INTEGER */ |
| 20846 |
/* = 0: successful exit */ |
| 20847 |
/* < 0: if INFO = -k, the k-th argument had an illegal value */ |
| 20848 |
/* > 0: if INFO = k, D(k,k) is exactly zero. The factorization */ |
| 20849 |
/* has been completed, but the block diagonal matrix D is */ |
| 20850 |
/* exactly singular, and division by zero will occur if it */ |
| 20851 |
/* is used to solve a system of equations. */ |
| 20852 |
|
| 20853 |
/* Further Details */ |
| 20854 |
/* =============== */ |
| 20855 |
|
| 20856 |
/* 09-29-06 - patch from */ |
| 20857 |
/* Bobby Cheng, MathWorks */ |
| 20858 |
|
| 20859 |
/* Replace l.204 and l.372 */ |
| 20860 |
/* IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN */ |
| 20861 |
/* by */ |
| 20862 |
/* IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN */ |
| 20863 |
|
| 20864 |
/* 01-01-96 - Based on modifications by */ |
| 20865 |
/* J. Lewis, Boeing Computer Services Company */ |
| 20866 |
/* A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA */ |
| 20867 |
/* 1-96 - Based on modifications by J. Lewis, Boeing Computer Services */ |
| 20868 |
/* Company */ |
| 20869 |
|
| 20870 |
/* If UPLO = 'U', then A = U*D*U', where */ |
| 20871 |
/* U = P(n)*U(n)* ... *P(k)U(k)* ..., */ |
| 20872 |
/* i.e., U is a product of terms P(k)*U(k), where k decreases from n to */ |
| 20873 |
/* 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */ |
| 20874 |
/* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */ |
| 20875 |
/* defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */ |
| 20876 |
/* that if the diagonal block D(k) is of order s (s = 1 or 2), then */ |
| 20877 |
|
| 20878 |
/* ( I v 0 ) k-s */ |
| 20879 |
/* U(k) = ( 0 I 0 ) s */ |
| 20880 |
/* ( 0 0 I ) n-k */ |
| 20881 |
/* k-s s n-k */ |
| 20882 |
|
| 20883 |
/* If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */ |
| 20884 |
/* If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */ |
| 20885 |
/* and A(k,k), and v overwrites A(1:k-2,k-1:k). */ |
| 20886 |
|
| 20887 |
/* If UPLO = 'L', then A = L*D*L', where */ |
| 20888 |
/* L = P(1)*L(1)* ... *P(k)*L(k)* ..., */ |
| 20889 |
/* i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */ |
| 20890 |
/* n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */ |
| 20891 |
/* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */ |
| 20892 |
/* defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */ |
| 20893 |
/* that if the diagonal block D(k) is of order s (s = 1 or 2), then */ |
| 20894 |
|
| 20895 |
/* ( I 0 0 ) k-1 */ |
| 20896 |
/* L(k) = ( 0 I 0 ) s */ |
| 20897 |
/* ( 0 v I ) n-k-s+1 */ |
| 20898 |
/* k-1 s n-k-s+1 */ |
| 20899 |
|
| 20900 |
/* If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */ |
| 20901 |
/* If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */ |
| 20902 |
/* and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */ |
| 20903 |
|
| 20904 |
/* ===================================================================== */ |
| 20905 |
|
| 20906 |
/* .. Parameters .. */ |
| 20907 |
/* .. */ |
| 20908 |
/* .. Local Scalars .. */ |
| 20909 |
/* .. */ |
| 20910 |
/* .. External Functions .. */ |
| 20911 |
/* .. */ |
| 20912 |
/* .. External Subroutines .. */ |
| 20913 |
/* .. */ |
| 20914 |
/* .. Intrinsic Functions .. */ |
| 20915 |
/* .. */ |
| 20916 |
/* .. Executable Statements .. */ |
| 20917 |
|
| 20918 |
/* Test the input parameters. */ |
| 20919 |
|
| 20920 |
/* Parameter adjustments */ |
| 20921 |
a_dim1 = *lda; |
| 20922 |
a_offset = 1 + a_dim1; |
| 20923 |
a -= a_offset; |
| 20924 |
--ipiv; |
| 20925 |
|
| 20926 |
/* Function Body */ |
| 20927 |
*info = 0; |
| 20928 |
upper = lsame_(uplo, "U"); |
| 20929 |
if (! upper && ! lsame_(uplo, "L")) { |
| 20930 |
*info = -1; |
| 20931 |
} else if (*n < 0) { |
| 20932 |
*info = -2; |
| 20933 |
} else if (*lda < std::max(1_integer,*n)) { |
| 20934 |
*info = -4; |
| 20935 |
} |
| 20936 |
if (*info != 0) { |
| 20937 |
i__1 = -(*info); |
| 20938 |
xerbla_("DSYTF2", &i__1); |
| 20939 |
return 0; |
| 20940 |
} |
| 20941 |
|
| 20942 |
/* Initialize ALPHA for use in choosing pivot block size. */ |
| 20943 |
|
| 20944 |
alpha = (sqrt(17.) + 1.) / 8.; |
| 20945 |
|
| 20946 |
if (upper) { |
| 20947 |
|
| 20948 |
/* Factorize A as U*D*U' using the upper triangle of A */ |
| 20949 |
|
| 20950 |
/* K is the main loop index, decreasing from N to 1 in steps of */ |
| 20951 |
/* 1 or 2 */ |
| 20952 |
|
| 20953 |
k = *n; |
| 20954 |
L10: |
| 20955 |
|
| 20956 |
/* If K < 1, exit from loop */ |
| 20957 |
|
| 20958 |
if (k < 1) { |
| 20959 |
goto L70; |
| 20960 |
} |
| 20961 |
kstep = 1; |
| 20962 |
|
| 20963 |
/* Determine rows and columns to be interchanged and whether */ |
| 20964 |
/* a 1-by-1 or 2-by-2 pivot block will be used */ |
| 20965 |
|
| 20966 |
absakk = (d__1 = a[k + k * a_dim1], abs(d__1)); |
| 20967 |
|
| 20968 |
/* IMAX is the row-index of the largest off-diagonal element in */ |
| 20969 |
/* column K, and COLMAX is its absolute value */ |
| 20970 |
|
| 20971 |
if (k > 1) { |
| 20972 |
i__1 = k - 1; |
| 20973 |
imax = idamax_(&i__1, &a[k * a_dim1 + 1], &c__1); |
| 20974 |
colmax = (d__1 = a[imax + k * a_dim1], abs(d__1)); |
| 20975 |
} else { |
| 20976 |
colmax = 0.; |
| 20977 |
} |
| 20978 |
|
| 20979 |
if (std::max(absakk,colmax) == 0. || disnan_(&absakk)) { |
| 20980 |
|
| 20981 |
/* Column K is zero or contains a NaN: set INFO and continue */ |
| 20982 |
|
| 20983 |
if (*info == 0) { |
| 20984 |
*info = k; |
| 20985 |
} |
| 20986 |
kp = k; |
| 20987 |
} else { |
| 20988 |
if (absakk >= alpha * colmax) { |
| 20989 |
|
| 20990 |
/* no interchange, use 1-by-1 pivot block */ |
| 20991 |
|
| 20992 |
kp = k; |
| 20993 |
} else { |
| 20994 |
|
| 20995 |
/* JMAX is the column-index of the largest off-diagonal */ |
| 20996 |
/* element in row IMAX, and ROWMAX is its absolute value */ |
| 20997 |
|
| 20998 |
i__1 = k - imax; |
| 20999 |
jmax = imax + idamax_(&i__1, &a[imax + (imax + 1) * a_dim1], |
| 21000 |
lda); |
| 21001 |
rowmax = (d__1 = a[imax + jmax * a_dim1], abs(d__1)); |
| 21002 |
if (imax > 1) { |
| 21003 |
i__1 = imax - 1; |
| 21004 |
jmax = idamax_(&i__1, &a[imax * a_dim1 + 1], &c__1); |
| 21005 |
/* Computing MAX */ |
| 21006 |
d__2 = rowmax, d__3 = (d__1 = a[jmax + imax * a_dim1], |
| 21007 |
abs(d__1)); |
| 21008 |
rowmax = std::max(d__2,d__3); |
| 21009 |
} |
| 21010 |
|
| 21011 |
if (absakk >= alpha * colmax * (colmax / rowmax)) { |
| 21012 |
|
| 21013 |
/* no interchange, use 1-by-1 pivot block */ |
| 21014 |
|
| 21015 |
kp = k; |
| 21016 |
} else if ((d__1 = a[imax + imax * a_dim1], abs(d__1)) >= |
| 21017 |
alpha * rowmax) { |
| 21018 |
|
| 21019 |
/* interchange rows and columns K and IMAX, use 1-by-1 */ |
| 21020 |
/* pivot block */ |
| 21021 |
|
| 21022 |
kp = imax; |
| 21023 |
} else { |
| 21024 |
|
| 21025 |
/* interchange rows and columns K-1 and IMAX, use 2-by-2 */ |
| 21026 |
/* pivot block */ |
| 21027 |
|
| 21028 |
kp = imax; |
| 21029 |
kstep = 2; |
| 21030 |
} |
| 21031 |
} |
| 21032 |
|
| 21033 |
kk = k - kstep + 1; |
| 21034 |
if (kp != kk) { |
| 21035 |
|
| 21036 |
/* Interchange rows and columns KK and KP in the leading */ |
| 21037 |
/* submatrix A(1:k,1:k) */ |
| 21038 |
|
| 21039 |
i__1 = kp - 1; |
| 21040 |
dswap_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1], |
| 21041 |
&c__1); |
| 21042 |
i__1 = kk - kp - 1; |
| 21043 |
dswap_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp + |
| 21044 |
1) * a_dim1], lda); |
| 21045 |
t = a[kk + kk * a_dim1]; |
| 21046 |
a[kk + kk * a_dim1] = a[kp + kp * a_dim1]; |
| 21047 |
a[kp + kp * a_dim1] = t; |
| 21048 |
if (kstep == 2) { |
| 21049 |
t = a[k - 1 + k * a_dim1]; |
| 21050 |
a[k - 1 + k * a_dim1] = a[kp + k * a_dim1]; |
| 21051 |
a[kp + k * a_dim1] = t; |
| 21052 |
} |
| 21053 |
} |
| 21054 |
|
| 21055 |
/* Update the leading submatrix */ |
| 21056 |
|
| 21057 |
if (kstep == 1) { |
| 21058 |
|
| 21059 |
/* 1-by-1 pivot block D(k): column k now holds */ |
| 21060 |
|
| 21061 |
/* W(k) = U(k)*D(k) */ |
| 21062 |
|
| 21063 |
/* where U(k) is the k-th column of U */ |
| 21064 |
|
| 21065 |
/* Perform a rank-1 update of A(1:k-1,1:k-1) as */ |
| 21066 |
|
| 21067 |
/* A := A - U(k)*D(k)*U(k)' = A - W(k)*1/D(k)*W(k)' */ |
| 21068 |
|
| 21069 |
r1 = 1. / a[k + k * a_dim1]; |
| 21070 |
i__1 = k - 1; |
| 21071 |
d__1 = -r1; |
| 21072 |
dsyr_(uplo, &i__1, &d__1, &a[k * a_dim1 + 1], &c__1, &a[ |
| 21073 |
a_offset], lda); |
| 21074 |
|
| 21075 |
/* Store U(k) in column k */ |
| 21076 |
|
| 21077 |
i__1 = k - 1; |
| 21078 |
dscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1); |
| 21079 |
} else { |
| 21080 |
|
| 21081 |
/* 2-by-2 pivot block D(k): columns k and k-1 now hold */ |
| 21082 |
|
| 21083 |
/* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */ |
| 21084 |
|
| 21085 |
/* where U(k) and U(k-1) are the k-th and (k-1)-th columns */ |
| 21086 |
/* of U */ |
| 21087 |
|
| 21088 |
/* Perform a rank-2 update of A(1:k-2,1:k-2) as */ |
| 21089 |
|
| 21090 |
/* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )' */ |
| 21091 |
/* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )' */ |
| 21092 |
|
| 21093 |
if (k > 2) { |
| 21094 |
|
| 21095 |
d12 = a[k - 1 + k * a_dim1]; |
| 21096 |
d22 = a[k - 1 + (k - 1) * a_dim1] / d12; |
| 21097 |
d11 = a[k + k * a_dim1] / d12; |
| 21098 |
t = 1. / (d11 * d22 - 1.); |
| 21099 |
d12 = t / d12; |
| 21100 |
|
| 21101 |
for (j = k - 2; j >= 1; --j) { |
| 21102 |
wkm1 = d12 * (d11 * a[j + (k - 1) * a_dim1] - a[j + k |
| 21103 |
* a_dim1]); |
| 21104 |
wk = d12 * (d22 * a[j + k * a_dim1] - a[j + (k - 1) * |
| 21105 |
a_dim1]); |
| 21106 |
for (i__ = j; i__ >= 1; --i__) { |
| 21107 |
a[i__ + j * a_dim1] = a[i__ + j * a_dim1] - a[i__ |
| 21108 |
+ k * a_dim1] * wk - a[i__ + (k - 1) * |
| 21109 |
a_dim1] * wkm1; |
| 21110 |
/* L20: */ |
| 21111 |
} |
| 21112 |
a[j + k * a_dim1] = wk; |
| 21113 |
a[j + (k - 1) * a_dim1] = wkm1; |
| 21114 |
/* L30: */ |
| 21115 |
} |
| 21116 |
|
| 21117 |
} |
| 21118 |
|
| 21119 |
} |
| 21120 |
} |
| 21121 |
|
| 21122 |
/* Store details of the interchanges in IPIV */ |
| 21123 |
|
| 21124 |
if (kstep == 1) { |
| 21125 |
ipiv[k] = kp; |
| 21126 |
} else { |
| 21127 |
ipiv[k] = -kp; |
| 21128 |
ipiv[k - 1] = -kp; |
| 21129 |
} |
| 21130 |
|
| 21131 |
/* Decrease K and return to the start of the main loop */ |
| 21132 |
|
| 21133 |
k -= kstep; |
| 21134 |
goto L10; |
| 21135 |
|
| 21136 |
} else { |
| 21137 |
|
| 21138 |
/* Factorize A as L*D*L' using the lower triangle of A */ |
| 21139 |
|
| 21140 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 21141 |
/* 1 or 2 */ |
| 21142 |
|
| 21143 |
k = 1; |
| 21144 |
L40: |
| 21145 |
|
| 21146 |
/* If K > N, exit from loop */ |
| 21147 |
|
| 21148 |
if (k > *n) { |
| 21149 |
goto L70; |
| 21150 |
} |
| 21151 |
kstep = 1; |
| 21152 |
|
| 21153 |
/* Determine rows and columns to be interchanged and whether */ |
| 21154 |
/* a 1-by-1 or 2-by-2 pivot block will be used */ |
| 21155 |
|
| 21156 |
absakk = (d__1 = a[k + k * a_dim1], abs(d__1)); |
| 21157 |
|
| 21158 |
/* IMAX is the row-index of the largest off-diagonal element in */ |
| 21159 |
/* column K, and COLMAX is its absolute value */ |
| 21160 |
|
| 21161 |
if (k < *n) { |
| 21162 |
i__1 = *n - k; |
| 21163 |
imax = k + idamax_(&i__1, &a[k + 1 + k * a_dim1], &c__1); |
| 21164 |
colmax = (d__1 = a[imax + k * a_dim1], abs(d__1)); |
| 21165 |
} else { |
| 21166 |
colmax = 0.; |
| 21167 |
} |
| 21168 |
|
| 21169 |
if (std::max(absakk,colmax) == 0. || disnan_(&absakk)) { |
| 21170 |
|
| 21171 |
/* Column K is zero or contains a NaN: set INFO and continue */ |
| 21172 |
|
| 21173 |
if (*info == 0) { |
| 21174 |
*info = k; |
| 21175 |
} |
| 21176 |
kp = k; |
| 21177 |
} else { |
| 21178 |
if (absakk >= alpha * colmax) { |
| 21179 |
|
| 21180 |
/* no interchange, use 1-by-1 pivot block */ |
| 21181 |
|
| 21182 |
kp = k; |
| 21183 |
} else { |
| 21184 |
|
| 21185 |
/* JMAX is the column-index of the largest off-diagonal */ |
| 21186 |
/* element in row IMAX, and ROWMAX is its absolute value */ |
| 21187 |
|
| 21188 |
i__1 = imax - k; |
| 21189 |
jmax = k - 1 + idamax_(&i__1, &a[imax + k * a_dim1], lda); |
| 21190 |
rowmax = (d__1 = a[imax + jmax * a_dim1], abs(d__1)); |
| 21191 |
if (imax < *n) { |
| 21192 |
i__1 = *n - imax; |
| 21193 |
jmax = imax + idamax_(&i__1, &a[imax + 1 + imax * a_dim1], |
| 21194 |
&c__1); |
| 21195 |
/* Computing MAX */ |
| 21196 |
d__2 = rowmax, d__3 = (d__1 = a[jmax + imax * a_dim1], |
| 21197 |
abs(d__1)); |
| 21198 |
rowmax = std::max(d__2,d__3); |
| 21199 |
} |
| 21200 |
|
| 21201 |
if (absakk >= alpha * colmax * (colmax / rowmax)) { |
| 21202 |
|
| 21203 |
/* no interchange, use 1-by-1 pivot block */ |
| 21204 |
|
| 21205 |
kp = k; |
| 21206 |
} else if ((d__1 = a[imax + imax * a_dim1], abs(d__1)) >= |
| 21207 |
alpha * rowmax) { |
| 21208 |
|
| 21209 |
/* interchange rows and columns K and IMAX, use 1-by-1 */ |
| 21210 |
/* pivot block */ |
| 21211 |
|
| 21212 |
kp = imax; |
| 21213 |
} else { |
| 21214 |
|
| 21215 |
/* interchange rows and columns K+1 and IMAX, use 2-by-2 */ |
| 21216 |
/* pivot block */ |
| 21217 |
|
| 21218 |
kp = imax; |
| 21219 |
kstep = 2; |
| 21220 |
} |
| 21221 |
} |
| 21222 |
|
| 21223 |
kk = k + kstep - 1; |
| 21224 |
if (kp != kk) { |
| 21225 |
|
| 21226 |
/* Interchange rows and columns KK and KP in the trailing */ |
| 21227 |
/* submatrix A(k:n,k:n) */ |
| 21228 |
|
| 21229 |
if (kp < *n) { |
| 21230 |
i__1 = *n - kp; |
| 21231 |
dswap_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1 |
| 21232 |
+ kp * a_dim1], &c__1); |
| 21233 |
} |
| 21234 |
i__1 = kp - kk - 1; |
| 21235 |
dswap_(&i__1, &a[kk + 1 + kk * a_dim1], &c__1, &a[kp + (kk + |
| 21236 |
1) * a_dim1], lda); |
| 21237 |
t = a[kk + kk * a_dim1]; |
| 21238 |
a[kk + kk * a_dim1] = a[kp + kp * a_dim1]; |
| 21239 |
a[kp + kp * a_dim1] = t; |
| 21240 |
if (kstep == 2) { |
| 21241 |
t = a[k + 1 + k * a_dim1]; |
| 21242 |
a[k + 1 + k * a_dim1] = a[kp + k * a_dim1]; |
| 21243 |
a[kp + k * a_dim1] = t; |
| 21244 |
} |
| 21245 |
} |
| 21246 |
|
| 21247 |
/* Update the trailing submatrix */ |
| 21248 |
|
| 21249 |
if (kstep == 1) { |
| 21250 |
|
| 21251 |
/* 1-by-1 pivot block D(k): column k now holds */ |
| 21252 |
|
| 21253 |
/* W(k) = L(k)*D(k) */ |
| 21254 |
|
| 21255 |
/* where L(k) is the k-th column of L */ |
| 21256 |
|
| 21257 |
if (k < *n) { |
| 21258 |
|
| 21259 |
/* Perform a rank-1 update of A(k+1:n,k+1:n) as */ |
| 21260 |
|
| 21261 |
/* A := A - L(k)*D(k)*L(k)' = A - W(k)*(1/D(k))*W(k)' */ |
| 21262 |
|
| 21263 |
d11 = 1. / a[k + k * a_dim1]; |
| 21264 |
i__1 = *n - k; |
| 21265 |
d__1 = -d11; |
| 21266 |
dsyr_(uplo, &i__1, &d__1, &a[k + 1 + k * a_dim1], &c__1, & |
| 21267 |
a[k + 1 + (k + 1) * a_dim1], lda); |
| 21268 |
|
| 21269 |
/* Store L(k) in column K */ |
| 21270 |
|
| 21271 |
i__1 = *n - k; |
| 21272 |
dscal_(&i__1, &d11, &a[k + 1 + k * a_dim1], &c__1); |
| 21273 |
} |
| 21274 |
} else { |
| 21275 |
|
| 21276 |
/* 2-by-2 pivot block D(k) */ |
| 21277 |
|
| 21278 |
if (k < *n - 1) { |
| 21279 |
|
| 21280 |
/* Perform a rank-2 update of A(k+2:n,k+2:n) as */ |
| 21281 |
|
| 21282 |
/* A := A - ( (A(k) A(k+1))*D(k)**(-1) ) * (A(k) A(k+1))' */ |
| 21283 |
|
| 21284 |
/* where L(k) and L(k+1) are the k-th and (k+1)-th */ |
| 21285 |
/* columns of L */ |
| 21286 |
|
| 21287 |
d21 = a[k + 1 + k * a_dim1]; |
| 21288 |
d11 = a[k + 1 + (k + 1) * a_dim1] / d21; |
| 21289 |
d22 = a[k + k * a_dim1] / d21; |
| 21290 |
t = 1. / (d11 * d22 - 1.); |
| 21291 |
d21 = t / d21; |
| 21292 |
|
| 21293 |
i__1 = *n; |
| 21294 |
for (j = k + 2; j <= i__1; ++j) { |
| 21295 |
|
| 21296 |
wk = d21 * (d11 * a[j + k * a_dim1] - a[j + (k + 1) * |
| 21297 |
a_dim1]); |
| 21298 |
wkp1 = d21 * (d22 * a[j + (k + 1) * a_dim1] - a[j + k |
| 21299 |
* a_dim1]); |
| 21300 |
|
| 21301 |
i__2 = *n; |
| 21302 |
for (i__ = j; i__ <= i__2; ++i__) { |
| 21303 |
a[i__ + j * a_dim1] = a[i__ + j * a_dim1] - a[i__ |
| 21304 |
+ k * a_dim1] * wk - a[i__ + (k + 1) * |
| 21305 |
a_dim1] * wkp1; |
| 21306 |
/* L50: */ |
| 21307 |
} |
| 21308 |
|
| 21309 |
a[j + k * a_dim1] = wk; |
| 21310 |
a[j + (k + 1) * a_dim1] = wkp1; |
| 21311 |
|
| 21312 |
/* L60: */ |
| 21313 |
} |
| 21314 |
} |
| 21315 |
} |
| 21316 |
} |
| 21317 |
|
| 21318 |
/* Store details of the interchanges in IPIV */ |
| 21319 |
|
| 21320 |
if (kstep == 1) { |
| 21321 |
ipiv[k] = kp; |
| 21322 |
} else { |
| 21323 |
ipiv[k] = -kp; |
| 21324 |
ipiv[k + 1] = -kp; |
| 21325 |
} |
| 21326 |
|
| 21327 |
/* Increase K and return to the start of the main loop */ |
| 21328 |
|
| 21329 |
k += kstep; |
| 21330 |
goto L40; |
| 21331 |
|
| 21332 |
} |
| 21333 |
|
| 21334 |
L70: |
| 21335 |
|
| 21336 |
return 0; |
| 21337 |
|
| 21338 |
/* End of DSYTF2 */ |
| 21339 |
|
| 21340 |
} /* dsytf2_ */ |
| 21341 |
|
| 21342 |
/* Subroutine */ int dsytrd_(const char *uplo, integer *n, double *a, integer * |
| 21343 |
lda, double *d__, double *e, double *tau, double * |
| 21344 |
work, integer *lwork, integer *info) |
| 21345 |
{ |
| 21346 |
/* Table of constant values */ |
| 21347 |
static integer c__1 = 1; |
| 21348 |
static integer c_n1 = -1; |
| 21349 |
static integer c__3 = 3; |
| 21350 |
static integer c__2 = 2; |
| 21351 |
static double c_b22 = -1.; |
| 21352 |
static double c_b23 = 1.; |
| 21353 |
|
| 21354 |
/* System generated locals */ |
| 21355 |
integer a_dim1, a_offset, i__1, i__2, i__3; |
| 21356 |
|
| 21357 |
/* Local variables */ |
| 21358 |
integer i__, j, nb, kk, nx, iws; |
| 21359 |
integer nbmin, iinfo; |
| 21360 |
bool upper; |
| 21361 |
integer ldwork, lwkopt; |
| 21362 |
bool lquery; |
| 21363 |
|
| 21364 |
/* -- LAPACK routine (version 3.1) -- */ |
| 21365 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 21366 |
/* November 2006 */ |
| 21367 |
|
| 21368 |
/* .. Scalar Arguments .. */ |
| 21369 |
/* .. */ |
| 21370 |
/* .. Array Arguments .. */ |
| 21371 |
/* .. */ |
| 21372 |
|
| 21373 |
/* Purpose */ |
| 21374 |
/* ======= */ |
| 21375 |
|
| 21376 |
/* DSYTRD reduces a real symmetric matrix A to real symmetric */ |
| 21377 |
/* tridiagonal form T by an orthogonal similarity transformation: */ |
| 21378 |
/* Q**T * A * Q = T. */ |
| 21379 |
|
| 21380 |
/* Arguments */ |
| 21381 |
/* ========= */ |
| 21382 |
|
| 21383 |
/* UPLO (input) CHARACTER*1 */ |
| 21384 |
/* = 'U': Upper triangle of A is stored; */ |
| 21385 |
/* = 'L': Lower triangle of A is stored. */ |
| 21386 |
|
| 21387 |
/* N (input) INTEGER */ |
| 21388 |
/* The order of the matrix A. N >= 0. */ |
| 21389 |
|
| 21390 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 21391 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the leading */ |
| 21392 |
/* N-by-N upper triangular part of A contains the upper */ |
| 21393 |
/* triangular part of the matrix A, and the strictly lower */ |
| 21394 |
/* triangular part of A is not referenced. If UPLO = 'L', the */ |
| 21395 |
/* leading N-by-N lower triangular part of A contains the lower */ |
| 21396 |
/* triangular part of the matrix A, and the strictly upper */ |
| 21397 |
/* triangular part of A is not referenced. */ |
| 21398 |
/* On exit, if UPLO = 'U', the diagonal and first superdiagonal */ |
| 21399 |
/* of A are overwritten by the corresponding elements of the */ |
| 21400 |
/* tridiagonal matrix T, and the elements above the first */ |
| 21401 |
/* superdiagonal, with the array TAU, represent the orthogonal */ |
| 21402 |
/* matrix Q as a product of elementary reflectors; if UPLO */ |
| 21403 |
/* = 'L', the diagonal and first subdiagonal of A are over- */ |
| 21404 |
/* written by the corresponding elements of the tridiagonal */ |
| 21405 |
/* matrix T, and the elements below the first subdiagonal, with */ |
| 21406 |
/* the array TAU, represent the orthogonal matrix Q as a product */ |
| 21407 |
/* of elementary reflectors. See Further Details. */ |
| 21408 |
|
| 21409 |
/* LDA (input) INTEGER */ |
| 21410 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 21411 |
|
| 21412 |
/* D (output) DOUBLE PRECISION array, dimension (N) */ |
| 21413 |
/* The diagonal elements of the tridiagonal matrix T: */ |
| 21414 |
/* D(i) = A(i,i). */ |
| 21415 |
|
| 21416 |
/* E (output) DOUBLE PRECISION array, dimension (N-1) */ |
| 21417 |
/* The off-diagonal elements of the tridiagonal matrix T: */ |
| 21418 |
/* E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */ |
| 21419 |
|
| 21420 |
/* TAU (output) DOUBLE PRECISION array, dimension (N-1) */ |
| 21421 |
/* The scalar factors of the elementary reflectors (see Further */ |
| 21422 |
/* Details). */ |
| 21423 |
|
| 21424 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 21425 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 21426 |
|
| 21427 |
/* LWORK (input) INTEGER */ |
| 21428 |
/* The dimension of the array WORK. LWORK >= 1. */ |
| 21429 |
/* For optimum performance LWORK >= N*NB, where NB is the */ |
| 21430 |
/* optimal blocksize. */ |
| 21431 |
|
| 21432 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 21433 |
/* only calculates the optimal size of the WORK array, returns */ |
| 21434 |
/* this value as the first entry of the WORK array, and no error */ |
| 21435 |
/* message related to LWORK is issued by XERBLA. */ |
| 21436 |
|
| 21437 |
/* INFO (output) INTEGER */ |
| 21438 |
/* = 0: successful exit */ |
| 21439 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 21440 |
|
| 21441 |
/* Further Details */ |
| 21442 |
/* =============== */ |
| 21443 |
|
| 21444 |
/* If UPLO = 'U', the matrix Q is represented as a product of elementary */ |
| 21445 |
/* reflectors */ |
| 21446 |
|
| 21447 |
/* Q = H(n-1) . . . H(2) H(1). */ |
| 21448 |
|
| 21449 |
/* Each H(i) has the form */ |
| 21450 |
|
| 21451 |
/* H(i) = I - tau * v * v' */ |
| 21452 |
|
| 21453 |
/* where tau is a real scalar, and v is a real vector with */ |
| 21454 |
/* v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in */ |
| 21455 |
/* A(1:i-1,i+1), and tau in TAU(i). */ |
| 21456 |
|
| 21457 |
/* If UPLO = 'L', the matrix Q is represented as a product of elementary */ |
| 21458 |
/* reflectors */ |
| 21459 |
|
| 21460 |
/* Q = H(1) H(2) . . . H(n-1). */ |
| 21461 |
|
| 21462 |
/* Each H(i) has the form */ |
| 21463 |
|
| 21464 |
/* H(i) = I - tau * v * v' */ |
| 21465 |
|
| 21466 |
/* where tau is a real scalar, and v is a real vector with */ |
| 21467 |
/* v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i), */ |
| 21468 |
/* and tau in TAU(i). */ |
| 21469 |
|
| 21470 |
/* The contents of A on exit are illustrated by the following examples */ |
| 21471 |
/* with n = 5: */ |
| 21472 |
|
| 21473 |
/* if UPLO = 'U': if UPLO = 'L': */ |
| 21474 |
|
| 21475 |
/* ( d e v2 v3 v4 ) ( d ) */ |
| 21476 |
/* ( d e v3 v4 ) ( e d ) */ |
| 21477 |
/* ( d e v4 ) ( v1 e d ) */ |
| 21478 |
/* ( d e ) ( v1 v2 e d ) */ |
| 21479 |
/* ( d ) ( v1 v2 v3 e d ) */ |
| 21480 |
|
| 21481 |
/* where d and e denote diagonal and off-diagonal elements of T, and vi */ |
| 21482 |
/* denotes an element of the vector defining H(i). */ |
| 21483 |
|
| 21484 |
/* ===================================================================== */ |
| 21485 |
|
| 21486 |
/* .. Parameters .. */ |
| 21487 |
/* .. */ |
| 21488 |
/* .. Local Scalars .. */ |
| 21489 |
/* .. */ |
| 21490 |
/* .. External Subroutines .. */ |
| 21491 |
/* .. */ |
| 21492 |
/* .. Intrinsic Functions .. */ |
| 21493 |
/* .. */ |
| 21494 |
/* .. External Functions .. */ |
| 21495 |
/* .. */ |
| 21496 |
/* .. Executable Statements .. */ |
| 21497 |
|
| 21498 |
/* Test the input parameters */ |
| 21499 |
|
| 21500 |
/* Parameter adjustments */ |
| 21501 |
a_dim1 = *lda; |
| 21502 |
a_offset = 1 + a_dim1; |
| 21503 |
a -= a_offset; |
| 21504 |
--d__; |
| 21505 |
--e; |
| 21506 |
--tau; |
| 21507 |
--work; |
| 21508 |
|
| 21509 |
/* Function Body */ |
| 21510 |
*info = 0; |
| 21511 |
upper = lsame_(uplo, "U"); |
| 21512 |
lquery = *lwork == -1; |
| 21513 |
if (! upper && ! lsame_(uplo, "L")) { |
| 21514 |
*info = -1; |
| 21515 |
} else if (*n < 0) { |
| 21516 |
*info = -2; |
| 21517 |
} else if (*lda < std::max(1_integer,*n)) { |
| 21518 |
*info = -4; |
| 21519 |
} else if (*lwork < 1 && ! lquery) { |
| 21520 |
*info = -9; |
| 21521 |
} |
| 21522 |
|
| 21523 |
if (*info == 0) { |
| 21524 |
|
| 21525 |
/* Determine the block size. */ |
| 21526 |
|
| 21527 |
nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1); |
| 21528 |
lwkopt = *n * nb; |
| 21529 |
work[1] = (double) lwkopt; |
| 21530 |
} |
| 21531 |
|
| 21532 |
if (*info != 0) { |
| 21533 |
i__1 = -(*info); |
| 21534 |
xerbla_("DSYTRD", &i__1); |
| 21535 |
return 0; |
| 21536 |
} else if (lquery) { |
| 21537 |
return 0; |
| 21538 |
} |
| 21539 |
|
| 21540 |
/* Quick return if possible */ |
| 21541 |
|
| 21542 |
if (*n == 0) { |
| 21543 |
work[1] = 1.; |
| 21544 |
return 0; |
| 21545 |
} |
| 21546 |
|
| 21547 |
nx = *n; |
| 21548 |
iws = 1; |
| 21549 |
if (nb > 1 && nb < *n) { |
| 21550 |
|
| 21551 |
/* Determine when to cross over from blocked to unblocked code */ |
| 21552 |
/* (last block is always handled by unblocked code). */ |
| 21553 |
|
| 21554 |
/* Computing MAX */ |
| 21555 |
i__1 = nb, i__2 = ilaenv_(&c__3, "DSYTRD", uplo, n, &c_n1, &c_n1, & |
| 21556 |
c_n1); |
| 21557 |
nx = std::max(i__1,i__2); |
| 21558 |
if (nx < *n) { |
| 21559 |
|
| 21560 |
/* Determine if workspace is large enough for blocked code. */ |
| 21561 |
|
| 21562 |
ldwork = *n; |
| 21563 |
iws = ldwork * nb; |
| 21564 |
if (*lwork < iws) { |
| 21565 |
|
| 21566 |
/* Not enough workspace to use optimal NB: determine the */ |
| 21567 |
/* minimum value of NB, and reduce NB or force use of */ |
| 21568 |
/* unblocked code by setting NX = N. */ |
| 21569 |
|
| 21570 |
/* Computing MAX */ |
| 21571 |
i__1 = *lwork / ldwork; |
| 21572 |
nb = std::max(i__1,1_integer); |
| 21573 |
nbmin = ilaenv_(&c__2, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1); |
| 21574 |
if (nb < nbmin) { |
| 21575 |
nx = *n; |
| 21576 |
} |
| 21577 |
} |
| 21578 |
} else { |
| 21579 |
nx = *n; |
| 21580 |
} |
| 21581 |
} else { |
| 21582 |
nb = 1; |
| 21583 |
} |
| 21584 |
|
| 21585 |
if (upper) { |
| 21586 |
|
| 21587 |
/* Reduce the upper triangle of A. */ |
| 21588 |
/* Columns 1:kk are handled by the unblocked method. */ |
| 21589 |
|
| 21590 |
kk = *n - (*n - nx + nb - 1) / nb * nb; |
| 21591 |
i__1 = kk + 1; |
| 21592 |
i__2 = -nb; |
| 21593 |
for (i__ = *n - nb + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += |
| 21594 |
i__2) { |
| 21595 |
|
| 21596 |
/* Reduce columns i:i+nb-1 to tridiagonal form and form the */ |
| 21597 |
/* matrix W which is needed to update the unreduced part of */ |
| 21598 |
/* the matrix */ |
| 21599 |
|
| 21600 |
i__3 = i__ + nb - 1; |
| 21601 |
dlatrd_(uplo, &i__3, &nb, &a[a_offset], lda, &e[1], &tau[1], & |
| 21602 |
work[1], &ldwork); |
| 21603 |
|
| 21604 |
/* Update the unreduced submatrix A(1:i-1,1:i-1), using an */ |
| 21605 |
/* update of the form: A := A - V*W' - W*V' */ |
| 21606 |
|
| 21607 |
i__3 = i__ - 1; |
| 21608 |
dsyr2k_(uplo, "No transpose", &i__3, &nb, &c_b22, &a[i__ * a_dim1 |
| 21609 |
+ 1], lda, &work[1], &ldwork, &c_b23, &a[a_offset], lda); |
| 21610 |
|
| 21611 |
/* Copy superdiagonal elements back into A, and diagonal */ |
| 21612 |
/* elements into D */ |
| 21613 |
|
| 21614 |
i__3 = i__ + nb - 1; |
| 21615 |
for (j = i__; j <= i__3; ++j) { |
| 21616 |
a[j - 1 + j * a_dim1] = e[j - 1]; |
| 21617 |
d__[j] = a[j + j * a_dim1]; |
| 21618 |
/* L10: */ |
| 21619 |
} |
| 21620 |
/* L20: */ |
| 21621 |
} |
| 21622 |
|
| 21623 |
/* Use unblocked code to reduce the last or only block */ |
| 21624 |
|
| 21625 |
dsytd2_(uplo, &kk, &a[a_offset], lda, &d__[1], &e[1], &tau[1], &iinfo); |
| 21626 |
} else { |
| 21627 |
|
| 21628 |
/* Reduce the lower triangle of A */ |
| 21629 |
|
| 21630 |
i__2 = *n - nx; |
| 21631 |
i__1 = nb; |
| 21632 |
for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) { |
| 21633 |
|
| 21634 |
/* Reduce columns i:i+nb-1 to tridiagonal form and form the */ |
| 21635 |
/* matrix W which is needed to update the unreduced part of */ |
| 21636 |
/* the matrix */ |
| 21637 |
|
| 21638 |
i__3 = *n - i__ + 1; |
| 21639 |
dlatrd_(uplo, &i__3, &nb, &a[i__ + i__ * a_dim1], lda, &e[i__], & |
| 21640 |
tau[i__], &work[1], &ldwork); |
| 21641 |
|
| 21642 |
/* Update the unreduced submatrix A(i+ib:n,i+ib:n), using */ |
| 21643 |
/* an update of the form: A := A - V*W' - W*V' */ |
| 21644 |
|
| 21645 |
i__3 = *n - i__ - nb + 1; |
| 21646 |
dsyr2k_(uplo, "No transpose", &i__3, &nb, &c_b22, &a[i__ + nb + |
| 21647 |
i__ * a_dim1], lda, &work[nb + 1], &ldwork, &c_b23, &a[ |
| 21648 |
i__ + nb + (i__ + nb) * a_dim1], lda); |
| 21649 |
|
| 21650 |
/* Copy subdiagonal elements back into A, and diagonal */ |
| 21651 |
/* elements into D */ |
| 21652 |
|
| 21653 |
i__3 = i__ + nb - 1; |
| 21654 |
for (j = i__; j <= i__3; ++j) { |
| 21655 |
a[j + 1 + j * a_dim1] = e[j]; |
| 21656 |
d__[j] = a[j + j * a_dim1]; |
| 21657 |
/* L30: */ |
| 21658 |
} |
| 21659 |
/* L40: */ |
| 21660 |
} |
| 21661 |
|
| 21662 |
/* Use unblocked code to reduce the last or only block */ |
| 21663 |
|
| 21664 |
i__1 = *n - i__ + 1; |
| 21665 |
dsytd2_(uplo, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__], |
| 21666 |
&tau[i__], &iinfo); |
| 21667 |
} |
| 21668 |
|
| 21669 |
work[1] = (double) lwkopt; |
| 21670 |
return 0; |
| 21671 |
|
| 21672 |
/* End of DSYTRD */ |
| 21673 |
|
| 21674 |
} /* dsytrd_ */ |
| 21675 |
|
| 21676 |
/* Subroutine */ int dsytrf_(const char *uplo, integer *n, double *a, integer * |
| 21677 |
lda, integer *ipiv, double *work, integer *lwork, integer *info) |
| 21678 |
{ |
| 21679 |
/* Table of constant values */ |
| 21680 |
static integer c__1 = 1; |
| 21681 |
static integer c_n1 = -1; |
| 21682 |
static integer c__2 = 2; |
| 21683 |
|
| 21684 |
/* System generated locals */ |
| 21685 |
integer a_dim1, a_offset, i__1, i__2; |
| 21686 |
|
| 21687 |
/* Local variables */ |
| 21688 |
integer j, k, kb, nb, iws; |
| 21689 |
|
| 21690 |
integer nbmin, iinfo; |
| 21691 |
bool upper; |
| 21692 |
integer ldwork, lwkopt; |
| 21693 |
bool lquery; |
| 21694 |
|
| 21695 |
|
| 21696 |
/* -- LAPACK routine (version 3.1) -- */ |
| 21697 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 21698 |
/* November 2006 */ |
| 21699 |
|
| 21700 |
/* .. Scalar Arguments .. */ |
| 21701 |
/* .. */ |
| 21702 |
/* .. Array Arguments .. */ |
| 21703 |
/* .. */ |
| 21704 |
|
| 21705 |
/* Purpose */ |
| 21706 |
/* ======= */ |
| 21707 |
|
| 21708 |
/* DSYTRF computes the factorization of a real symmetric matrix A using */ |
| 21709 |
/* the Bunch-Kaufman diagonal pivoting method. The form of the */ |
| 21710 |
/* factorization is */ |
| 21711 |
|
| 21712 |
/* A = U*D*U**T or A = L*D*L**T */ |
| 21713 |
|
| 21714 |
/* where U (or L) is a product of permutation and unit upper (lower) */ |
| 21715 |
/* triangular matrices, and D is symmetric and block diagonal with */ |
| 21716 |
/* 1-by-1 and 2-by-2 diagonal blocks. */ |
| 21717 |
|
| 21718 |
/* This is the blocked version of the algorithm, calling Level 3 BLAS. */ |
| 21719 |
|
| 21720 |
/* Arguments */ |
| 21721 |
/* ========= */ |
| 21722 |
|
| 21723 |
/* UPLO (input) CHARACTER*1 */ |
| 21724 |
/* = 'U': Upper triangle of A is stored; */ |
| 21725 |
/* = 'L': Lower triangle of A is stored. */ |
| 21726 |
|
| 21727 |
/* N (input) INTEGER */ |
| 21728 |
/* The order of the matrix A. N >= 0. */ |
| 21729 |
|
| 21730 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 21731 |
/* On entry, the symmetric matrix A. If UPLO = 'U', the leading */ |
| 21732 |
/* N-by-N upper triangular part of A contains the upper */ |
| 21733 |
/* triangular part of the matrix A, and the strictly lower */ |
| 21734 |
/* triangular part of A is not referenced. If UPLO = 'L', the */ |
| 21735 |
/* leading N-by-N lower triangular part of A contains the lower */ |
| 21736 |
/* triangular part of the matrix A, and the strictly upper */ |
| 21737 |
/* triangular part of A is not referenced. */ |
| 21738 |
|
| 21739 |
/* On exit, the block diagonal matrix D and the multipliers used */ |
| 21740 |
/* to obtain the factor U or L (see below for further details). */ |
| 21741 |
|
| 21742 |
/* LDA (input) INTEGER */ |
| 21743 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 21744 |
|
| 21745 |
/* IPIV (output) INTEGER array, dimension (N) */ |
| 21746 |
/* Details of the interchanges and the block structure of D. */ |
| 21747 |
/* If IPIV(k) > 0, then rows and columns k and IPIV(k) were */ |
| 21748 |
/* interchanged and D(k,k) is a 1-by-1 diagonal block. */ |
| 21749 |
/* If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */ |
| 21750 |
/* columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */ |
| 21751 |
/* is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */ |
| 21752 |
/* IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */ |
| 21753 |
/* interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */ |
| 21754 |
|
| 21755 |
/* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ |
| 21756 |
/* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ |
| 21757 |
|
| 21758 |
/* LWORK (input) INTEGER */ |
| 21759 |
/* The length of WORK. LWORK >=1. For best performance */ |
| 21760 |
/* LWORK >= N*NB, where NB is the block size returned by ILAENV. */ |
| 21761 |
|
| 21762 |
/* If LWORK = -1, then a workspace query is assumed; the routine */ |
| 21763 |
/* only calculates the optimal size of the WORK array, returns */ |
| 21764 |
/* this value as the first entry of the WORK array, and no error */ |
| 21765 |
/* message related to LWORK is issued by XERBLA. */ |
| 21766 |
|
| 21767 |
/* INFO (output) INTEGER */ |
| 21768 |
/* = 0: successful exit */ |
| 21769 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 21770 |
/* > 0: if INFO = i, D(i,i) is exactly zero. The factorization */ |
| 21771 |
/* has been completed, but the block diagonal matrix D is */ |
| 21772 |
/* exactly singular, and division by zero will occur if it */ |
| 21773 |
/* is used to solve a system of equations. */ |
| 21774 |
|
| 21775 |
/* Further Details */ |
| 21776 |
/* =============== */ |
| 21777 |
|
| 21778 |
/* If UPLO = 'U', then A = U*D*U', where */ |
| 21779 |
/* U = P(n)*U(n)* ... *P(k)U(k)* ..., */ |
| 21780 |
/* i.e., U is a product of terms P(k)*U(k), where k decreases from n to */ |
| 21781 |
/* 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */ |
| 21782 |
/* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */ |
| 21783 |
/* defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */ |
| 21784 |
/* that if the diagonal block D(k) is of order s (s = 1 or 2), then */ |
| 21785 |
|
| 21786 |
/* ( I v 0 ) k-s */ |
| 21787 |
/* U(k) = ( 0 I 0 ) s */ |
| 21788 |
/* ( 0 0 I ) n-k */ |
| 21789 |
/* k-s s n-k */ |
| 21790 |
|
| 21791 |
/* If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */ |
| 21792 |
/* If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */ |
| 21793 |
/* and A(k,k), and v overwrites A(1:k-2,k-1:k). */ |
| 21794 |
|
| 21795 |
/* If UPLO = 'L', then A = L*D*L', where */ |
| 21796 |
/* L = P(1)*L(1)* ... *P(k)*L(k)* ..., */ |
| 21797 |
/* i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */ |
| 21798 |
/* n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */ |
| 21799 |
/* and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */ |
| 21800 |
/* defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */ |
| 21801 |
/* that if the diagonal block D(k) is of order s (s = 1 or 2), then */ |
| 21802 |
|
| 21803 |
/* ( I 0 0 ) k-1 */ |
| 21804 |
/* L(k) = ( 0 I 0 ) s */ |
| 21805 |
/* ( 0 v I ) n-k-s+1 */ |
| 21806 |
/* k-1 s n-k-s+1 */ |
| 21807 |
|
| 21808 |
/* If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */ |
| 21809 |
/* If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */ |
| 21810 |
/* and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */ |
| 21811 |
|
| 21812 |
/* ===================================================================== */ |
| 21813 |
|
| 21814 |
/* .. Local Scalars .. */ |
| 21815 |
/* .. */ |
| 21816 |
/* .. External Functions .. */ |
| 21817 |
/* .. */ |
| 21818 |
/* .. External Subroutines .. */ |
| 21819 |
/* .. */ |
| 21820 |
/* .. Intrinsic Functions .. */ |
| 21821 |
/* .. */ |
| 21822 |
/* .. Executable Statements .. */ |
| 21823 |
|
| 21824 |
/* Test the input parameters. */ |
| 21825 |
|
| 21826 |
/* Parameter adjustments */ |
| 21827 |
a_dim1 = *lda; |
| 21828 |
a_offset = 1 + a_dim1; |
| 21829 |
a -= a_offset; |
| 21830 |
--ipiv; |
| 21831 |
--work; |
| 21832 |
|
| 21833 |
/* Function Body */ |
| 21834 |
*info = 0; |
| 21835 |
upper = lsame_(uplo, "U"); |
| 21836 |
lquery = *lwork == -1; |
| 21837 |
if (! upper && ! lsame_(uplo, "L")) { |
| 21838 |
*info = -1; |
| 21839 |
} else if (*n < 0) { |
| 21840 |
*info = -2; |
| 21841 |
} else if (*lda < std::max(1_integer,*n)) { |
| 21842 |
*info = -4; |
| 21843 |
} else if (*lwork < 1 && ! lquery) { |
| 21844 |
*info = -7; |
| 21845 |
} |
| 21846 |
|
| 21847 |
if (*info == 0) { |
| 21848 |
|
| 21849 |
/* Determine the block size */ |
| 21850 |
|
| 21851 |
nb = ilaenv_(&c__1, "DSYTRF", uplo, n, &c_n1, &c_n1, &c_n1); |
| 21852 |
lwkopt = *n * nb; |
| 21853 |
work[1] = (double) lwkopt; |
| 21854 |
} |
| 21855 |
|
| 21856 |
if (*info != 0) { |
| 21857 |
i__1 = -(*info); |
| 21858 |
xerbla_("DSYTRF", &i__1); |
| 21859 |
return 0; |
| 21860 |
} else if (lquery) { |
| 21861 |
return 0; |
| 21862 |
} |
| 21863 |
|
| 21864 |
nbmin = 2; |
| 21865 |
ldwork = *n; |
| 21866 |
if (nb > 1 && nb < *n) { |
| 21867 |
iws = ldwork * nb; |
| 21868 |
if (*lwork < iws) { |
| 21869 |
/* Computing MAX */ |
| 21870 |
i__1 = *lwork / ldwork; |
| 21871 |
nb = std::max(i__1,1_integer); |
| 21872 |
/* Computing MAX */ |
| 21873 |
i__1 = 2, i__2 = ilaenv_(&c__2, "DSYTRF", uplo, n, &c_n1, &c_n1, & |
| 21874 |
c_n1); |
| 21875 |
nbmin = std::max(i__1,i__2); |
| 21876 |
} |
| 21877 |
} else { |
| 21878 |
iws = 1; |
| 21879 |
} |
| 21880 |
if (nb < nbmin) { |
| 21881 |
nb = *n; |
| 21882 |
} |
| 21883 |
|
| 21884 |
if (upper) { |
| 21885 |
|
| 21886 |
/* Factorize A as U*D*U' using the upper triangle of A */ |
| 21887 |
|
| 21888 |
/* K is the main loop index, decreasing from N to 1 in steps of */ |
| 21889 |
/* KB, where KB is the number of columns factorized by DLASYF; */ |
| 21890 |
/* KB is either NB or NB-1, or K for the last block */ |
| 21891 |
|
| 21892 |
k = *n; |
| 21893 |
L10: |
| 21894 |
|
| 21895 |
/* If K < 1, exit from loop */ |
| 21896 |
|
| 21897 |
if (k < 1) { |
| 21898 |
goto L40; |
| 21899 |
} |
| 21900 |
|
| 21901 |
if (k > nb) { |
| 21902 |
|
| 21903 |
/* Factorize columns k-kb+1:k of A and use blocked code to */ |
| 21904 |
/* update columns 1:k-kb */ |
| 21905 |
|
| 21906 |
dlasyf_(uplo, &k, &nb, &kb, &a[a_offset], lda, &ipiv[1], &work[1], |
| 21907 |
&ldwork, &iinfo); |
| 21908 |
} else { |
| 21909 |
|
| 21910 |
/* Use unblocked code to factorize columns 1:k of A */ |
| 21911 |
|
| 21912 |
dsytf2_(uplo, &k, &a[a_offset], lda, &ipiv[1], &iinfo); |
| 21913 |
kb = k; |
| 21914 |
} |
| 21915 |
|
| 21916 |
/* Set INFO on the first occurrence of a zero pivot */ |
| 21917 |
|
| 21918 |
if (*info == 0 && iinfo > 0) { |
| 21919 |
*info = iinfo; |
| 21920 |
} |
| 21921 |
|
| 21922 |
/* Decrease K and return to the start of the main loop */ |
| 21923 |
|
| 21924 |
k -= kb; |
| 21925 |
goto L10; |
| 21926 |
|
| 21927 |
} else { |
| 21928 |
|
| 21929 |
/* Factorize A as L*D*L' using the lower triangle of A */ |
| 21930 |
|
| 21931 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 21932 |
/* KB, where KB is the number of columns factorized by DLASYF; */ |
| 21933 |
/* KB is either NB or NB-1, or N-K+1 for the last block */ |
| 21934 |
|
| 21935 |
k = 1; |
| 21936 |
L20: |
| 21937 |
|
| 21938 |
/* If K > N, exit from loop */ |
| 21939 |
|
| 21940 |
if (k > *n) { |
| 21941 |
goto L40; |
| 21942 |
} |
| 21943 |
|
| 21944 |
if (k <= *n - nb) { |
| 21945 |
|
| 21946 |
/* Factorize columns k:k+kb-1 of A and use blocked code to */ |
| 21947 |
/* update columns k+kb:n */ |
| 21948 |
|
| 21949 |
i__1 = *n - k + 1; |
| 21950 |
dlasyf_(uplo, &i__1, &nb, &kb, &a[k + k * a_dim1], lda, &ipiv[k], |
| 21951 |
&work[1], &ldwork, &iinfo); |
| 21952 |
} else { |
| 21953 |
|
| 21954 |
/* Use unblocked code to factorize columns k:n of A */ |
| 21955 |
|
| 21956 |
i__1 = *n - k + 1; |
| 21957 |
dsytf2_(uplo, &i__1, &a[k + k * a_dim1], lda, &ipiv[k], &iinfo); |
| 21958 |
kb = *n - k + 1; |
| 21959 |
} |
| 21960 |
|
| 21961 |
/* Set INFO on the first occurrence of a zero pivot */ |
| 21962 |
|
| 21963 |
if (*info == 0 && iinfo > 0) { |
| 21964 |
*info = iinfo + k - 1; |
| 21965 |
} |
| 21966 |
|
| 21967 |
/* Adjust IPIV */ |
| 21968 |
|
| 21969 |
i__1 = k + kb - 1; |
| 21970 |
for (j = k; j <= i__1; ++j) { |
| 21971 |
if (ipiv[j] > 0) { |
| 21972 |
ipiv[j] = ipiv[j] + k - 1; |
| 21973 |
} else { |
| 21974 |
ipiv[j] = ipiv[j] - k + 1; |
| 21975 |
} |
| 21976 |
/* L30: */ |
| 21977 |
} |
| 21978 |
|
| 21979 |
/* Increase K and return to the start of the main loop */ |
| 21980 |
|
| 21981 |
k += kb; |
| 21982 |
goto L20; |
| 21983 |
|
| 21984 |
} |
| 21985 |
|
| 21986 |
L40: |
| 21987 |
work[1] = (double) lwkopt; |
| 21988 |
return 0; |
| 21989 |
|
| 21990 |
/* End of DSYTRF */ |
| 21991 |
|
| 21992 |
} /* dsytrf_ */ |
| 21993 |
|
| 21994 |
/* Subroutine */ int dsytri_(const char *uplo, integer *n, double *a, integer * |
| 21995 |
lda, integer *ipiv, double *work, integer *info) |
| 21996 |
{ |
| 21997 |
/* Table of constant values */ |
| 21998 |
static integer c__1 = 1; |
| 21999 |
static double c_b11 = -1.; |
| 22000 |
static double c_b13 = 0.; |
| 22001 |
|
| 22002 |
/* System generated locals */ |
| 22003 |
integer a_dim1, a_offset, i__1; |
| 22004 |
double d__1; |
| 22005 |
|
| 22006 |
/* Local variables */ |
| 22007 |
double d__; |
| 22008 |
integer k; |
| 22009 |
double t, ak; |
| 22010 |
integer kp; |
| 22011 |
double akp1; |
| 22012 |
double temp, akkp1; |
| 22013 |
integer kstep; |
| 22014 |
bool upper; |
| 22015 |
|
| 22016 |
|
| 22017 |
/* -- LAPACK routine (version 3.1) -- */ |
| 22018 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 22019 |
/* November 2006 */ |
| 22020 |
|
| 22021 |
/* .. Scalar Arguments .. */ |
| 22022 |
/* .. */ |
| 22023 |
/* .. Array Arguments .. */ |
| 22024 |
/* .. */ |
| 22025 |
|
| 22026 |
/* Purpose */ |
| 22027 |
/* ======= */ |
| 22028 |
|
| 22029 |
/* DSYTRI computes the inverse of a real symmetric indefinite matrix */ |
| 22030 |
/* A using the factorization A = U*D*U**T or A = L*D*L**T computed by */ |
| 22031 |
/* DSYTRF. */ |
| 22032 |
|
| 22033 |
/* Arguments */ |
| 22034 |
/* ========= */ |
| 22035 |
|
| 22036 |
/* UPLO (input) CHARACTER*1 */ |
| 22037 |
/* Specifies whether the details of the factorization are stored */ |
| 22038 |
/* as an upper or lower triangular matrix. */ |
| 22039 |
/* = 'U': Upper triangular, form is A = U*D*U**T; */ |
| 22040 |
/* = 'L': Lower triangular, form is A = L*D*L**T. */ |
| 22041 |
|
| 22042 |
/* N (input) INTEGER */ |
| 22043 |
/* The order of the matrix A. N >= 0. */ |
| 22044 |
|
| 22045 |
/* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 22046 |
/* On entry, the block diagonal matrix D and the multipliers */ |
| 22047 |
/* used to obtain the factor U or L as computed by DSYTRF. */ |
| 22048 |
|
| 22049 |
/* On exit, if INFO = 0, the (symmetric) inverse of the original */ |
| 22050 |
/* matrix. If UPLO = 'U', the upper triangular part of the */ |
| 22051 |
/* inverse is formed and the part of A below the diagonal is not */ |
| 22052 |
/* referenced; if UPLO = 'L' the lower triangular part of the */ |
| 22053 |
/* inverse is formed and the part of A above the diagonal is */ |
| 22054 |
/* not referenced. */ |
| 22055 |
|
| 22056 |
/* LDA (input) INTEGER */ |
| 22057 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 22058 |
|
| 22059 |
/* IPIV (input) INTEGER array, dimension (N) */ |
| 22060 |
/* Details of the interchanges and the block structure of D */ |
| 22061 |
/* as determined by DSYTRF. */ |
| 22062 |
|
| 22063 |
/* WORK (workspace) DOUBLE PRECISION array, dimension (N) */ |
| 22064 |
|
| 22065 |
/* INFO (output) INTEGER */ |
| 22066 |
/* = 0: successful exit */ |
| 22067 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 22068 |
/* > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its */ |
| 22069 |
/* inverse could not be computed. */ |
| 22070 |
|
| 22071 |
/* ===================================================================== */ |
| 22072 |
|
| 22073 |
/* .. Parameters .. */ |
| 22074 |
/* .. */ |
| 22075 |
/* .. Local Scalars .. */ |
| 22076 |
/* .. */ |
| 22077 |
/* .. External Functions .. */ |
| 22078 |
/* .. */ |
| 22079 |
/* .. External Subroutines .. */ |
| 22080 |
/* .. */ |
| 22081 |
/* .. Intrinsic Functions .. */ |
| 22082 |
/* .. */ |
| 22083 |
/* .. Executable Statements .. */ |
| 22084 |
|
| 22085 |
/* Test the input parameters. */ |
| 22086 |
|
| 22087 |
/* Parameter adjustments */ |
| 22088 |
a_dim1 = *lda; |
| 22089 |
a_offset = 1 + a_dim1; |
| 22090 |
a -= a_offset; |
| 22091 |
--ipiv; |
| 22092 |
--work; |
| 22093 |
|
| 22094 |
/* Function Body */ |
| 22095 |
*info = 0; |
| 22096 |
upper = lsame_(uplo, "U"); |
| 22097 |
if (! upper && ! lsame_(uplo, "L")) { |
| 22098 |
*info = -1; |
| 22099 |
} else if (*n < 0) { |
| 22100 |
*info = -2; |
| 22101 |
} else if (*lda < std::max(1_integer,*n)) { |
| 22102 |
*info = -4; |
| 22103 |
} |
| 22104 |
if (*info != 0) { |
| 22105 |
i__1 = -(*info); |
| 22106 |
xerbla_("DSYTRI", &i__1); |
| 22107 |
return 0; |
| 22108 |
} |
| 22109 |
|
| 22110 |
/* Quick return if possible */ |
| 22111 |
|
| 22112 |
if (*n == 0) { |
| 22113 |
return 0; |
| 22114 |
} |
| 22115 |
|
| 22116 |
/* Check that the diagonal matrix D is nonsingular. */ |
| 22117 |
|
| 22118 |
if (upper) { |
| 22119 |
|
| 22120 |
/* Upper triangular storage: examine D from bottom to top */ |
| 22121 |
|
| 22122 |
for (*info = *n; *info >= 1; --(*info)) { |
| 22123 |
if (ipiv[*info] > 0 && a[*info + *info * a_dim1] == 0.) { |
| 22124 |
return 0; |
| 22125 |
} |
| 22126 |
/* L10: */ |
| 22127 |
} |
| 22128 |
} else { |
| 22129 |
|
| 22130 |
/* Lower triangular storage: examine D from top to bottom. */ |
| 22131 |
|
| 22132 |
i__1 = *n; |
| 22133 |
for (*info = 1; *info <= i__1; ++(*info)) { |
| 22134 |
if (ipiv[*info] > 0 && a[*info + *info * a_dim1] == 0.) { |
| 22135 |
return 0; |
| 22136 |
} |
| 22137 |
/* L20: */ |
| 22138 |
} |
| 22139 |
} |
| 22140 |
*info = 0; |
| 22141 |
|
| 22142 |
if (upper) { |
| 22143 |
|
| 22144 |
/* Compute inv(A) from the factorization A = U*D*U'. */ |
| 22145 |
|
| 22146 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 22147 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 22148 |
|
| 22149 |
k = 1; |
| 22150 |
L30: |
| 22151 |
|
| 22152 |
/* If K > N, exit from loop. */ |
| 22153 |
|
| 22154 |
if (k > *n) { |
| 22155 |
goto L40; |
| 22156 |
} |
| 22157 |
|
| 22158 |
if (ipiv[k] > 0) { |
| 22159 |
|
| 22160 |
/* 1 x 1 diagonal block */ |
| 22161 |
|
| 22162 |
/* Invert the diagonal block. */ |
| 22163 |
|
| 22164 |
a[k + k * a_dim1] = 1. / a[k + k * a_dim1]; |
| 22165 |
|
| 22166 |
/* Compute column K of the inverse. */ |
| 22167 |
|
| 22168 |
if (k > 1) { |
| 22169 |
i__1 = k - 1; |
| 22170 |
dcopy_(&i__1, &a[k * a_dim1 + 1], &c__1, &work[1], &c__1); |
| 22171 |
i__1 = k - 1; |
| 22172 |
dsymv_(uplo, &i__1, &c_b11, &a[a_offset], lda, &work[1], & |
| 22173 |
c__1, &c_b13, &a[k * a_dim1 + 1], &c__1); |
| 22174 |
i__1 = k - 1; |
| 22175 |
a[k + k * a_dim1] -= ddot_(&i__1, &work[1], &c__1, &a[k * |
| 22176 |
a_dim1 + 1], &c__1); |
| 22177 |
} |
| 22178 |
kstep = 1; |
| 22179 |
} else { |
| 22180 |
|
| 22181 |
/* 2 x 2 diagonal block */ |
| 22182 |
|
| 22183 |
/* Invert the diagonal block. */ |
| 22184 |
|
| 22185 |
t = (d__1 = a[k + (k + 1) * a_dim1], abs(d__1)); |
| 22186 |
ak = a[k + k * a_dim1] / t; |
| 22187 |
akp1 = a[k + 1 + (k + 1) * a_dim1] / t; |
| 22188 |
akkp1 = a[k + (k + 1) * a_dim1] / t; |
| 22189 |
d__ = t * (ak * akp1 - 1.); |
| 22190 |
a[k + k * a_dim1] = akp1 / d__; |
| 22191 |
a[k + 1 + (k + 1) * a_dim1] = ak / d__; |
| 22192 |
a[k + (k + 1) * a_dim1] = -akkp1 / d__; |
| 22193 |
|
| 22194 |
/* Compute columns K and K+1 of the inverse. */ |
| 22195 |
|
| 22196 |
if (k > 1) { |
| 22197 |
i__1 = k - 1; |
| 22198 |
dcopy_(&i__1, &a[k * a_dim1 + 1], &c__1, &work[1], &c__1); |
| 22199 |
i__1 = k - 1; |
| 22200 |
dsymv_(uplo, &i__1, &c_b11, &a[a_offset], lda, &work[1], & |
| 22201 |
c__1, &c_b13, &a[k * a_dim1 + 1], &c__1); |
| 22202 |
i__1 = k - 1; |
| 22203 |
a[k + k * a_dim1] -= ddot_(&i__1, &work[1], &c__1, &a[k * |
| 22204 |
a_dim1 + 1], &c__1); |
| 22205 |
i__1 = k - 1; |
| 22206 |
a[k + (k + 1) * a_dim1] -= ddot_(&i__1, &a[k * a_dim1 + 1], & |
| 22207 |
c__1, &a[(k + 1) * a_dim1 + 1], &c__1); |
| 22208 |
i__1 = k - 1; |
| 22209 |
dcopy_(&i__1, &a[(k + 1) * a_dim1 + 1], &c__1, &work[1], & |
| 22210 |
c__1); |
| 22211 |
i__1 = k - 1; |
| 22212 |
dsymv_(uplo, &i__1, &c_b11, &a[a_offset], lda, &work[1], & |
| 22213 |
c__1, &c_b13, &a[(k + 1) * a_dim1 + 1], &c__1); |
| 22214 |
i__1 = k - 1; |
| 22215 |
a[k + 1 + (k + 1) * a_dim1] -= ddot_(&i__1, &work[1], &c__1, & |
| 22216 |
a[(k + 1) * a_dim1 + 1], &c__1); |
| 22217 |
} |
| 22218 |
kstep = 2; |
| 22219 |
} |
| 22220 |
|
| 22221 |
kp = (i__1 = ipiv[k], abs(i__1)); |
| 22222 |
if (kp != k) { |
| 22223 |
|
| 22224 |
/* Interchange rows and columns K and KP in the leading */ |
| 22225 |
/* submatrix A(1:k+1,1:k+1) */ |
| 22226 |
|
| 22227 |
i__1 = kp - 1; |
| 22228 |
dswap_(&i__1, &a[k * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1], & |
| 22229 |
c__1); |
| 22230 |
i__1 = k - kp - 1; |
| 22231 |
dswap_(&i__1, &a[kp + 1 + k * a_dim1], &c__1, &a[kp + (kp + 1) * |
| 22232 |
a_dim1], lda); |
| 22233 |
temp = a[k + k * a_dim1]; |
| 22234 |
a[k + k * a_dim1] = a[kp + kp * a_dim1]; |
| 22235 |
a[kp + kp * a_dim1] = temp; |
| 22236 |
if (kstep == 2) { |
| 22237 |
temp = a[k + (k + 1) * a_dim1]; |
| 22238 |
a[k + (k + 1) * a_dim1] = a[kp + (k + 1) * a_dim1]; |
| 22239 |
a[kp + (k + 1) * a_dim1] = temp; |
| 22240 |
} |
| 22241 |
} |
| 22242 |
|
| 22243 |
k += kstep; |
| 22244 |
goto L30; |
| 22245 |
L40: |
| 22246 |
|
| 22247 |
; |
| 22248 |
} else { |
| 22249 |
|
| 22250 |
/* Compute inv(A) from the factorization A = L*D*L'. */ |
| 22251 |
|
| 22252 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 22253 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 22254 |
|
| 22255 |
k = *n; |
| 22256 |
L50: |
| 22257 |
|
| 22258 |
/* If K < 1, exit from loop. */ |
| 22259 |
|
| 22260 |
if (k < 1) { |
| 22261 |
goto L60; |
| 22262 |
} |
| 22263 |
|
| 22264 |
if (ipiv[k] > 0) { |
| 22265 |
|
| 22266 |
/* 1 x 1 diagonal block */ |
| 22267 |
|
| 22268 |
/* Invert the diagonal block. */ |
| 22269 |
|
| 22270 |
a[k + k * a_dim1] = 1. / a[k + k * a_dim1]; |
| 22271 |
|
| 22272 |
/* Compute column K of the inverse. */ |
| 22273 |
|
| 22274 |
if (k < *n) { |
| 22275 |
i__1 = *n - k; |
| 22276 |
dcopy_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &work[1], &c__1); |
| 22277 |
i__1 = *n - k; |
| 22278 |
dsymv_(uplo, &i__1, &c_b11, &a[k + 1 + (k + 1) * a_dim1], lda, |
| 22279 |
&work[1], &c__1, &c_b13, &a[k + 1 + k * a_dim1], & |
| 22280 |
c__1); |
| 22281 |
i__1 = *n - k; |
| 22282 |
a[k + k * a_dim1] -= ddot_(&i__1, &work[1], &c__1, &a[k + 1 + |
| 22283 |
k * a_dim1], &c__1); |
| 22284 |
} |
| 22285 |
kstep = 1; |
| 22286 |
} else { |
| 22287 |
|
| 22288 |
/* 2 x 2 diagonal block */ |
| 22289 |
|
| 22290 |
/* Invert the diagonal block. */ |
| 22291 |
|
| 22292 |
t = (d__1 = a[k + (k - 1) * a_dim1], abs(d__1)); |
| 22293 |
ak = a[k - 1 + (k - 1) * a_dim1] / t; |
| 22294 |
akp1 = a[k + k * a_dim1] / t; |
| 22295 |
akkp1 = a[k + (k - 1) * a_dim1] / t; |
| 22296 |
d__ = t * (ak * akp1 - 1.); |
| 22297 |
a[k - 1 + (k - 1) * a_dim1] = akp1 / d__; |
| 22298 |
a[k + k * a_dim1] = ak / d__; |
| 22299 |
a[k + (k - 1) * a_dim1] = -akkp1 / d__; |
| 22300 |
|
| 22301 |
/* Compute columns K-1 and K of the inverse. */ |
| 22302 |
|
| 22303 |
if (k < *n) { |
| 22304 |
i__1 = *n - k; |
| 22305 |
dcopy_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &work[1], &c__1); |
| 22306 |
i__1 = *n - k; |
| 22307 |
dsymv_(uplo, &i__1, &c_b11, &a[k + 1 + (k + 1) * a_dim1], lda, |
| 22308 |
&work[1], &c__1, &c_b13, &a[k + 1 + k * a_dim1], & |
| 22309 |
c__1); |
| 22310 |
i__1 = *n - k; |
| 22311 |
a[k + k * a_dim1] -= ddot_(&i__1, &work[1], &c__1, &a[k + 1 + |
| 22312 |
k * a_dim1], &c__1); |
| 22313 |
i__1 = *n - k; |
| 22314 |
a[k + (k - 1) * a_dim1] -= ddot_(&i__1, &a[k + 1 + k * a_dim1] |
| 22315 |
, &c__1, &a[k + 1 + (k - 1) * a_dim1], &c__1); |
| 22316 |
i__1 = *n - k; |
| 22317 |
dcopy_(&i__1, &a[k + 1 + (k - 1) * a_dim1], &c__1, &work[1], & |
| 22318 |
c__1); |
| 22319 |
i__1 = *n - k; |
| 22320 |
dsymv_(uplo, &i__1, &c_b11, &a[k + 1 + (k + 1) * a_dim1], lda, |
| 22321 |
&work[1], &c__1, &c_b13, &a[k + 1 + (k - 1) * a_dim1] |
| 22322 |
, &c__1); |
| 22323 |
i__1 = *n - k; |
| 22324 |
a[k - 1 + (k - 1) * a_dim1] -= ddot_(&i__1, &work[1], &c__1, & |
| 22325 |
a[k + 1 + (k - 1) * a_dim1], &c__1); |
| 22326 |
} |
| 22327 |
kstep = 2; |
| 22328 |
} |
| 22329 |
|
| 22330 |
kp = (i__1 = ipiv[k], abs(i__1)); |
| 22331 |
if (kp != k) { |
| 22332 |
|
| 22333 |
/* Interchange rows and columns K and KP in the trailing */ |
| 22334 |
/* submatrix A(k-1:n,k-1:n) */ |
| 22335 |
|
| 22336 |
if (kp < *n) { |
| 22337 |
i__1 = *n - kp; |
| 22338 |
dswap_(&i__1, &a[kp + 1 + k * a_dim1], &c__1, &a[kp + 1 + kp * |
| 22339 |
a_dim1], &c__1); |
| 22340 |
} |
| 22341 |
i__1 = kp - k - 1; |
| 22342 |
dswap_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &a[kp + (k + 1) * |
| 22343 |
a_dim1], lda); |
| 22344 |
temp = a[k + k * a_dim1]; |
| 22345 |
a[k + k * a_dim1] = a[kp + kp * a_dim1]; |
| 22346 |
a[kp + kp * a_dim1] = temp; |
| 22347 |
if (kstep == 2) { |
| 22348 |
temp = a[k + (k - 1) * a_dim1]; |
| 22349 |
a[k + (k - 1) * a_dim1] = a[kp + (k - 1) * a_dim1]; |
| 22350 |
a[kp + (k - 1) * a_dim1] = temp; |
| 22351 |
} |
| 22352 |
} |
| 22353 |
|
| 22354 |
k -= kstep; |
| 22355 |
goto L50; |
| 22356 |
L60: |
| 22357 |
; |
| 22358 |
} |
| 22359 |
|
| 22360 |
return 0; |
| 22361 |
|
| 22362 |
/* End of DSYTRI */ |
| 22363 |
|
| 22364 |
} /* dsytri_ */ |
| 22365 |
|
| 22366 |
/* Subroutine */ int dsytrs_(const char *uplo, integer *n, integer *nrhs, |
| 22367 |
double *a, integer *lda, integer *ipiv, double *b, integer * |
| 22368 |
ldb, integer *info) |
| 22369 |
{ |
| 22370 |
/* Table of constant values */ |
| 22371 |
static double c_b7 = -1.; |
| 22372 |
static integer c__1 = 1; |
| 22373 |
static double c_b19 = 1.; |
| 22374 |
|
| 22375 |
/* System generated locals */ |
| 22376 |
integer a_dim1, a_offset, b_dim1, b_offset, i__1; |
| 22377 |
double d__1; |
| 22378 |
|
| 22379 |
/* Local variables */ |
| 22380 |
integer j, k; |
| 22381 |
double ak, bk; |
| 22382 |
integer kp; |
| 22383 |
double akm1, bkm1; |
| 22384 |
double akm1k; |
| 22385 |
double denom; |
| 22386 |
bool upper; |
| 22387 |
|
| 22388 |
|
| 22389 |
/* -- LAPACK routine (version 3.1) -- */ |
| 22390 |
/* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
| 22391 |
/* November 2006 */ |
| 22392 |
|
| 22393 |
/* .. Scalar Arguments .. */ |
| 22394 |
/* .. */ |
| 22395 |
/* .. Array Arguments .. */ |
| 22396 |
/* .. */ |
| 22397 |
|
| 22398 |
/* Purpose */ |
| 22399 |
/* ======= */ |
| 22400 |
|
| 22401 |
/* DSYTRS solves a system of linear equations A*X = B with a real */ |
| 22402 |
/* symmetric matrix A using the factorization A = U*D*U**T or */ |
| 22403 |
/* A = L*D*L**T computed by DSYTRF. */ |
| 22404 |
|
| 22405 |
/* Arguments */ |
| 22406 |
/* ========= */ |
| 22407 |
|
| 22408 |
/* UPLO (input) CHARACTER*1 */ |
| 22409 |
/* Specifies whether the details of the factorization are stored */ |
| 22410 |
/* as an upper or lower triangular matrix. */ |
| 22411 |
/* = 'U': Upper triangular, form is A = U*D*U**T; */ |
| 22412 |
/* = 'L': Lower triangular, form is A = L*D*L**T. */ |
| 22413 |
|
| 22414 |
/* N (input) INTEGER */ |
| 22415 |
/* The order of the matrix A. N >= 0. */ |
| 22416 |
|
| 22417 |
/* NRHS (input) INTEGER */ |
| 22418 |
/* The number of right hand sides, i.e., the number of columns */ |
| 22419 |
/* of the matrix B. NRHS >= 0. */ |
| 22420 |
|
| 22421 |
/* A (input) DOUBLE PRECISION array, dimension (LDA,N) */ |
| 22422 |
/* The block diagonal matrix D and the multipliers used to */ |
| 22423 |
/* obtain the factor U or L as computed by DSYTRF. */ |
| 22424 |
|
| 22425 |
/* LDA (input) INTEGER */ |
| 22426 |
/* The leading dimension of the array A. LDA >= max(1,N). */ |
| 22427 |
|
| 22428 |
/* IPIV (input) INTEGER array, dimension (N) */ |
| 22429 |
/* Details of the interchanges and the block structure of D */ |
| 22430 |
/* as determined by DSYTRF. */ |
| 22431 |
|
| 22432 |
/* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */ |
| 22433 |
/* On entry, the right hand side matrix B. */ |
| 22434 |
/* On exit, the solution matrix X. */ |
| 22435 |
|
| 22436 |
/* LDB (input) INTEGER */ |
| 22437 |
/* The leading dimension of the array B. LDB >= max(1,N). */ |
| 22438 |
|
| 22439 |
/* INFO (output) INTEGER */ |
| 22440 |
/* = 0: successful exit */ |
| 22441 |
/* < 0: if INFO = -i, the i-th argument had an illegal value */ |
| 22442 |
|
| 22443 |
/* ===================================================================== */ |
| 22444 |
|
| 22445 |
/* .. Parameters .. */ |
| 22446 |
/* .. */ |
| 22447 |
/* .. Local Scalars .. */ |
| 22448 |
/* .. */ |
| 22449 |
/* .. External Functions .. */ |
| 22450 |
/* .. */ |
| 22451 |
/* .. External Subroutines .. */ |
| 22452 |
/* .. */ |
| 22453 |
/* .. Intrinsic Functions .. */ |
| 22454 |
/* .. */ |
| 22455 |
/* .. Executable Statements .. */ |
| 22456 |
|
| 22457 |
/* Parameter adjustments */ |
| 22458 |
a_dim1 = *lda; |
| 22459 |
a_offset = 1 + a_dim1; |
| 22460 |
a -= a_offset; |
| 22461 |
--ipiv; |
| 22462 |
b_dim1 = *ldb; |
| 22463 |
b_offset = 1 + b_dim1; |
| 22464 |
b -= b_offset; |
| 22465 |
|
| 22466 |
/* Function Body */ |
| 22467 |
*info = 0; |
| 22468 |
upper = lsame_(uplo, "U"); |
| 22469 |
if (! upper && ! lsame_(uplo, "L")) { |
| 22470 |
*info = -1; |
| 22471 |
} else if (*n < 0) { |
| 22472 |
*info = -2; |
| 22473 |
} else if (*nrhs < 0) { |
| 22474 |
*info = -3; |
| 22475 |
} else if (*lda < std::max(1_integer,*n)) { |
| 22476 |
*info = -5; |
| 22477 |
} else if (*ldb < std::max(1_integer,*n)) { |
| 22478 |
*info = -8; |
| 22479 |
} |
| 22480 |
if (*info != 0) { |
| 22481 |
i__1 = -(*info); |
| 22482 |
xerbla_("DSYTRS", &i__1); |
| 22483 |
return 0; |
| 22484 |
} |
| 22485 |
|
| 22486 |
/* Quick return if possible */ |
| 22487 |
|
| 22488 |
if (*n == 0 || *nrhs == 0) { |
| 22489 |
return 0; |
| 22490 |
} |
| 22491 |
|
| 22492 |
if (upper) { |
| 22493 |
|
| 22494 |
/* Solve A*X = B, where A = U*D*U'. */ |
| 22495 |
|
| 22496 |
/* First solve U*D*X = B, overwriting B with X. */ |
| 22497 |
|
| 22498 |
/* K is the main loop index, decreasing from N to 1 in steps of */ |
| 22499 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 22500 |
|
| 22501 |
k = *n; |
| 22502 |
L10: |
| 22503 |
|
| 22504 |
/* If K < 1, exit from loop. */ |
| 22505 |
|
| 22506 |
if (k < 1) { |
| 22507 |
goto L30; |
| 22508 |
} |
| 22509 |
|
| 22510 |
if (ipiv[k] > 0) { |
| 22511 |
|
| 22512 |
/* 1 x 1 diagonal block */ |
| 22513 |
|
| 22514 |
/* Interchange rows K and IPIV(K). */ |
| 22515 |
|
| 22516 |
kp = ipiv[k]; |
| 22517 |
if (kp != k) { |
| 22518 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 22519 |
} |
| 22520 |
|
| 22521 |
/* Multiply by inv(U(K)), where U(K) is the transformation */ |
| 22522 |
/* stored in column K of A. */ |
| 22523 |
|
| 22524 |
i__1 = k - 1; |
| 22525 |
dger_(&i__1, nrhs, &c_b7, &a[k * a_dim1 + 1], &c__1, &b[k + |
| 22526 |
b_dim1], ldb, &b[b_dim1 + 1], ldb); |
| 22527 |
|
| 22528 |
/* Multiply by the inverse of the diagonal block. */ |
| 22529 |
|
| 22530 |
d__1 = 1. / a[k + k * a_dim1]; |
| 22531 |
dscal_(nrhs, &d__1, &b[k + b_dim1], ldb); |
| 22532 |
--k; |
| 22533 |
} else { |
| 22534 |
|
| 22535 |
/* 2 x 2 diagonal block */ |
| 22536 |
|
| 22537 |
/* Interchange rows K-1 and -IPIV(K). */ |
| 22538 |
|
| 22539 |
kp = -ipiv[k]; |
| 22540 |
if (kp != k - 1) { |
| 22541 |
dswap_(nrhs, &b[k - 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 22542 |
} |
| 22543 |
|
| 22544 |
/* Multiply by inv(U(K)), where U(K) is the transformation */ |
| 22545 |
/* stored in columns K-1 and K of A. */ |
| 22546 |
|
| 22547 |
i__1 = k - 2; |
| 22548 |
dger_(&i__1, nrhs, &c_b7, &a[k * a_dim1 + 1], &c__1, &b[k + |
| 22549 |
b_dim1], ldb, &b[b_dim1 + 1], ldb); |
| 22550 |
i__1 = k - 2; |
| 22551 |
dger_(&i__1, nrhs, &c_b7, &a[(k - 1) * a_dim1 + 1], &c__1, &b[k - |
| 22552 |
1 + b_dim1], ldb, &b[b_dim1 + 1], ldb); |
| 22553 |
|
| 22554 |
/* Multiply by the inverse of the diagonal block. */ |
| 22555 |
|
| 22556 |
akm1k = a[k - 1 + k * a_dim1]; |
| 22557 |
akm1 = a[k - 1 + (k - 1) * a_dim1] / akm1k; |
| 22558 |
ak = a[k + k * a_dim1] / akm1k; |
| 22559 |
denom = akm1 * ak - 1.; |
| 22560 |
i__1 = *nrhs; |
| 22561 |
for (j = 1; j <= i__1; ++j) { |
| 22562 |
bkm1 = b[k - 1 + j * b_dim1] / akm1k; |
| 22563 |
bk = b[k + j * b_dim1] / akm1k; |
| 22564 |
b[k - 1 + j * b_dim1] = (ak * bkm1 - bk) / denom; |
| 22565 |
b[k + j * b_dim1] = (akm1 * bk - bkm1) / denom; |
| 22566 |
/* L20: */ |
| 22567 |
} |
| 22568 |
k += -2; |
| 22569 |
} |
| 22570 |
|
| 22571 |
goto L10; |
| 22572 |
L30: |
| 22573 |
|
| 22574 |
/* Next solve U'*X = B, overwriting B with X. */ |
| 22575 |
|
| 22576 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 22577 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 22578 |
|
| 22579 |
k = 1; |
| 22580 |
L40: |
| 22581 |
|
| 22582 |
/* If K > N, exit from loop. */ |
| 22583 |
|
| 22584 |
if (k > *n) { |
| 22585 |
goto L50; |
| 22586 |
} |
| 22587 |
|
| 22588 |
if (ipiv[k] > 0) { |
| 22589 |
|
| 22590 |
/* 1 x 1 diagonal block */ |
| 22591 |
|
| 22592 |
/* Multiply by inv(U'(K)), where U(K) is the transformation */ |
| 22593 |
/* stored in column K of A. */ |
| 22594 |
|
| 22595 |
i__1 = k - 1; |
| 22596 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[b_offset], ldb, &a[k * |
| 22597 |
a_dim1 + 1], &c__1, &c_b19, &b[k + b_dim1], ldb); |
| 22598 |
|
| 22599 |
/* Interchange rows K and IPIV(K). */ |
| 22600 |
|
| 22601 |
kp = ipiv[k]; |
| 22602 |
if (kp != k) { |
| 22603 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 22604 |
} |
| 22605 |
++k; |
| 22606 |
} else { |
| 22607 |
|
| 22608 |
/* 2 x 2 diagonal block */ |
| 22609 |
|
| 22610 |
/* Multiply by inv(U'(K+1)), where U(K+1) is the transformation */ |
| 22611 |
/* stored in columns K and K+1 of A. */ |
| 22612 |
|
| 22613 |
i__1 = k - 1; |
| 22614 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[b_offset], ldb, &a[k * |
| 22615 |
a_dim1 + 1], &c__1, &c_b19, &b[k + b_dim1], ldb); |
| 22616 |
i__1 = k - 1; |
| 22617 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[b_offset], ldb, &a[(k |
| 22618 |
+ 1) * a_dim1 + 1], &c__1, &c_b19, &b[k + 1 + b_dim1], |
| 22619 |
ldb); |
| 22620 |
|
| 22621 |
/* Interchange rows K and -IPIV(K). */ |
| 22622 |
|
| 22623 |
kp = -ipiv[k]; |
| 22624 |
if (kp != k) { |
| 22625 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 22626 |
} |
| 22627 |
k += 2; |
| 22628 |
} |
| 22629 |
|
| 22630 |
goto L40; |
| 22631 |
L50: |
| 22632 |
|
| 22633 |
; |
| 22634 |
} else { |
| 22635 |
|
| 22636 |
/* Solve A*X = B, where A = L*D*L'. */ |
| 22637 |
|
| 22638 |
/* First solve L*D*X = B, overwriting B with X. */ |
| 22639 |
|
| 22640 |
/* K is the main loop index, increasing from 1 to N in steps of */ |
| 22641 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 22642 |
|
| 22643 |
k = 1; |
| 22644 |
L60: |
| 22645 |
|
| 22646 |
/* If K > N, exit from loop. */ |
| 22647 |
|
| 22648 |
if (k > *n) { |
| 22649 |
goto L80; |
| 22650 |
} |
| 22651 |
|
| 22652 |
if (ipiv[k] > 0) { |
| 22653 |
|
| 22654 |
/* 1 x 1 diagonal block */ |
| 22655 |
|
| 22656 |
/* Interchange rows K and IPIV(K). */ |
| 22657 |
|
| 22658 |
kp = ipiv[k]; |
| 22659 |
if (kp != k) { |
| 22660 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 22661 |
} |
| 22662 |
|
| 22663 |
/* Multiply by inv(L(K)), where L(K) is the transformation */ |
| 22664 |
/* stored in column K of A. */ |
| 22665 |
|
| 22666 |
if (k < *n) { |
| 22667 |
i__1 = *n - k; |
| 22668 |
dger_(&i__1, nrhs, &c_b7, &a[k + 1 + k * a_dim1], &c__1, &b[k |
| 22669 |
+ b_dim1], ldb, &b[k + 1 + b_dim1], ldb); |
| 22670 |
} |
| 22671 |
|
| 22672 |
/* Multiply by the inverse of the diagonal block. */ |
| 22673 |
|
| 22674 |
d__1 = 1. / a[k + k * a_dim1]; |
| 22675 |
dscal_(nrhs, &d__1, &b[k + b_dim1], ldb); |
| 22676 |
++k; |
| 22677 |
} else { |
| 22678 |
|
| 22679 |
/* 2 x 2 diagonal block */ |
| 22680 |
|
| 22681 |
/* Interchange rows K+1 and -IPIV(K). */ |
| 22682 |
|
| 22683 |
kp = -ipiv[k]; |
| 22684 |
if (kp != k + 1) { |
| 22685 |
dswap_(nrhs, &b[k + 1 + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 22686 |
} |
| 22687 |
|
| 22688 |
/* Multiply by inv(L(K)), where L(K) is the transformation */ |
| 22689 |
/* stored in columns K and K+1 of A. */ |
| 22690 |
|
| 22691 |
if (k < *n - 1) { |
| 22692 |
i__1 = *n - k - 1; |
| 22693 |
dger_(&i__1, nrhs, &c_b7, &a[k + 2 + k * a_dim1], &c__1, &b[k |
| 22694 |
+ b_dim1], ldb, &b[k + 2 + b_dim1], ldb); |
| 22695 |
i__1 = *n - k - 1; |
| 22696 |
dger_(&i__1, nrhs, &c_b7, &a[k + 2 + (k + 1) * a_dim1], &c__1, |
| 22697 |
&b[k + 1 + b_dim1], ldb, &b[k + 2 + b_dim1], ldb); |
| 22698 |
} |
| 22699 |
|
| 22700 |
/* Multiply by the inverse of the diagonal block. */ |
| 22701 |
|
| 22702 |
akm1k = a[k + 1 + k * a_dim1]; |
| 22703 |
akm1 = a[k + k * a_dim1] / akm1k; |
| 22704 |
ak = a[k + 1 + (k + 1) * a_dim1] / akm1k; |
| 22705 |
denom = akm1 * ak - 1.; |
| 22706 |
i__1 = *nrhs; |
| 22707 |
for (j = 1; j <= i__1; ++j) { |
| 22708 |
bkm1 = b[k + j * b_dim1] / akm1k; |
| 22709 |
bk = b[k + 1 + j * b_dim1] / akm1k; |
| 22710 |
b[k + j * b_dim1] = (ak * bkm1 - bk) / denom; |
| 22711 |
b[k + 1 + j * b_dim1] = (akm1 * bk - bkm1) / denom; |
| 22712 |
/* L70: */ |
| 22713 |
} |
| 22714 |
k += 2; |
| 22715 |
} |
| 22716 |
|
| 22717 |
goto L60; |
| 22718 |
L80: |
| 22719 |
|
| 22720 |
/* Next solve L'*X = B, overwriting B with X. */ |
| 22721 |
|
| 22722 |
/* K is the main loop index, decreasing from N to 1 in steps of */ |
| 22723 |
/* 1 or 2, depending on the size of the diagonal blocks. */ |
| 22724 |
|
| 22725 |
k = *n; |
| 22726 |
L90: |
| 22727 |
|
| 22728 |
/* If K < 1, exit from loop. */ |
| 22729 |
|
| 22730 |
if (k < 1) { |
| 22731 |
goto L100; |
| 22732 |
} |
| 22733 |
|
| 22734 |
if (ipiv[k] > 0) { |
| 22735 |
|
| 22736 |
/* 1 x 1 diagonal block */ |
| 22737 |
|
| 22738 |
/* Multiply by inv(L'(K)), where L(K) is the transformation */ |
| 22739 |
/* stored in column K of A. */ |
| 22740 |
|
| 22741 |
if (k < *n) { |
| 22742 |
i__1 = *n - k; |
| 22743 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[k + 1 + b_dim1], |
| 22744 |
ldb, &a[k + 1 + k * a_dim1], &c__1, &c_b19, &b[k + |
| 22745 |
b_dim1], ldb); |
| 22746 |
} |
| 22747 |
|
| 22748 |
/* Interchange rows K and IPIV(K). */ |
| 22749 |
|
| 22750 |
kp = ipiv[k]; |
| 22751 |
if (kp != k) { |
| 22752 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 22753 |
} |
| 22754 |
--k; |
| 22755 |
} else { |
| 22756 |
|
| 22757 |
/* 2 x 2 diagonal block */ |
| 22758 |
|
| 22759 |
/* Multiply by inv(L'(K-1)), where L(K-1) is the transformation */ |
| 22760 |
/* stored in columns K-1 and K of A. */ |
| 22761 |
|
| 22762 |
if (k < *n) { |
| 22763 |
i__1 = *n - k; |
| 22764 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[k + 1 + b_dim1], |
| 22765 |
ldb, &a[k + 1 + k * a_dim1], &c__1, &c_b19, &b[k + |
| 22766 |
b_dim1], ldb); |
| 22767 |
i__1 = *n - k; |
| 22768 |
dgemv_("Transpose", &i__1, nrhs, &c_b7, &b[k + 1 + b_dim1], |
| 22769 |
ldb, &a[k + 1 + (k - 1) * a_dim1], &c__1, &c_b19, &b[ |
| 22770 |
k - 1 + b_dim1], ldb); |
| 22771 |
} |
| 22772 |
|
| 22773 |
/* Interchange rows K and -IPIV(K). */ |
| 22774 |
|
| 22775 |
kp = -ipiv[k]; |
| 22776 |
if (kp != k) { |
| 22777 |
dswap_(nrhs, &b[k + b_dim1], ldb, &b[kp + b_dim1], ldb); |
| 22778 |
} |
| 22779 |
k += -2; |
| 22780 |
} |
| 22781 |
|
| 22782 |
goto L90; |
| 22783 |
L100: |
| 22784 |
; |
| 22785 |
} |
| 22786 |
|
| 22787 |
return 0; |
| 22788 |
|
| 22789 |
/* End of DSYTRS */ |
| 22790 |
|
| 22791 |
} /* dsytrs_ */ |