Debian Codegraph @

external/clapack/lapack.cpp

raw
1 #include "clapack.h"
2 #include "f2cP.h"
3
4 #if 0
5 void chla_transtype__(char *ret_val, integer ret_val_len, integer *trans)
6 {
7
8 /* -- LAPACK routine (version 3.2) -- */
9 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
10 /* October 2008 */
11 /* .. Scalar Arguments .. */
12 /* .. */
13
14 /* Purpose */
15 /* ======= */
16
17 /* This subroutine translates from a BLAST-specified integer constant to */
18 /* the character string specifying a transposition operation. */
19
20 /* CHLA_TRANSTYPE returns an CHARACTER*1. If CHLA_TRANSTYPE is 'X', */
21 /* then input is not an integer indicating a transposition operator. */
22 /* Otherwise CHLA_TRANSTYPE returns the constant value corresponding to */
23 /* TRANS. */
24
25 /* Arguments */
26 /* ========= */
27 /* TRANS (input) INTEGER */
28 /* Specifies the form of the system of equations: */
29 /* = BLAS_NO_TRANS = 111 : No Transpose */
30 /* = BLAS_TRANS = 112 : Transpose */
31 /* = BLAS_CONJ_TRANS = 113 : Conjugate Transpose */
32 /* ===================================================================== */
33
34 /* .. Parameters .. */
35 /* .. */
36 /* .. Executable Statements .. */
37 if (*trans == 111) {
38 *(unsigned char *)ret_val = 'N';
39 } else if (*trans == 112) {
40 *(unsigned char *)ret_val = 'T';
41 } else if (*trans == 113) {
42 *(unsigned char *)ret_val = 'C';
43 } else {
44 *(unsigned char *)ret_val = 'X';
45 }
46 return ;
47
48 /* End of CHLA_TRANSTYPE */
49
50 } /* chla_transtype__ */
51 #endif
52
53 /* Subroutine */ int dbdsdc_(const char *uplo, const char *compq, integer *n, double *
54 d__, double *e, double *u, integer *ldu, double *vt,
55 integer *ldvt, double *q, integer *iq, double *work, integer *
56 iwork, integer *info)
57 {
58 /* Table of constant values */
59 static integer c__9 = 9;
60 static integer c__0 = 0;
61 static double c_b15 = 1.;
62 static integer c__1 = 1;
63 static double c_b29 = 0.;
64
65 /* System generated locals */
66 integer u_dim1, u_offset, vt_dim1, vt_offset, i__1, i__2;
67 double d__1;
68
69 /* Local variables */
70 integer i__, j, k;
71 double p, r__;
72 integer z__, ic, ii, kk;
73 double cs;
74 integer is, iu;
75 double sn;
76 integer nm1;
77 double eps;
78 integer ivt, difl, difr, ierr, perm, mlvl, sqre;
79 integer poles, iuplo, nsize, start;
80 integer givcol;
81 integer icompq;
82 double orgnrm;
83 integer givnum, givptr, qstart, smlsiz, wstart, smlszp;
84
85
86 /* -- LAPACK routine (version 3.1) -- */
87 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
88 /* November 2006 */
89
90 /* .. Scalar Arguments .. */
91 /* .. */
92 /* .. Array Arguments .. */
93 /* .. */
94
95 /* Purpose */
96 /* ======= */
97
98 /* DBDSDC computes the singular value decomposition (SVD) of a real */
99 /* N-by-N (upper or lower) bidiagonal matrix B: B = U * S * VT, */
100 /* using a divide and conquer method, where S is a diagonal matrix */
101 /* with non-negative diagonal elements (the singular values of B), and */
102 /* U and VT are orthogonal matrices of left and right singular vectors, */
103 /* respectively. DBDSDC can be used to compute all singular values, */
104 /* and optionally, singular vectors or singular vectors in compact form. */
105
106 /* This code makes very mild assumptions about floating point */
107 /* arithmetic. It will work on machines with a guard digit in */
108 /* add/subtract, or on those binary machines without guard digits */
109 /* which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2. */
110 /* It could conceivably fail on hexadecimal or decimal machines */
111 /* without guard digits, but we know of none. See DLASD3 for details. */
112
113 /* The code currently calls DLASDQ if singular values only are desired. */
114 /* However, it can be slightly modified to compute singular values */
115 /* using the divide and conquer method. */
116
117 /* Arguments */
118 /* ========= */
119
120 /* UPLO (input) CHARACTER*1 */
121 /* = 'U': B is upper bidiagonal. */
122 /* = 'L': B is lower bidiagonal. */
123
124 /* COMPQ (input) CHARACTER*1 */
125 /* Specifies whether singular vectors are to be computed */
126 /* as follows: */
127 /* = 'N': Compute singular values only; */
128 /* = 'P': Compute singular values and compute singular */
129 /* vectors in compact form; */
130 /* = 'I': Compute singular values and singular vectors. */
131
132 /* N (input) INTEGER */
133 /* The order of the matrix B. N >= 0. */
134
135 /* D (input/output) DOUBLE PRECISION array, dimension (N) */
136 /* On entry, the n diagonal elements of the bidiagonal matrix B. */
137 /* On exit, if INFO=0, the singular values of B. */
138
139 /* E (input/output) DOUBLE PRECISION array, dimension (N-1) */
140 /* On entry, the elements of E contain the offdiagonal */
141 /* elements of the bidiagonal matrix whose SVD is desired. */
142 /* On exit, E has been destroyed. */
143
144 /* U (output) DOUBLE PRECISION array, dimension (LDU,N) */
145 /* If COMPQ = 'I', then: */
146 /* On exit, if INFO = 0, U contains the left singular vectors */
147 /* of the bidiagonal matrix. */
148 /* For other values of COMPQ, U is not referenced. */
149
150 /* LDU (input) INTEGER */
151 /* The leading dimension of the array U. LDU >= 1. */
152 /* If singular vectors are desired, then LDU >= max( 1, N ). */
153
154 /* VT (output) DOUBLE PRECISION array, dimension (LDVT,N) */
155 /* If COMPQ = 'I', then: */
156 /* On exit, if INFO = 0, VT' contains the right singular */
157 /* vectors of the bidiagonal matrix. */
158 /* For other values of COMPQ, VT is not referenced. */
159
160 /* LDVT (input) INTEGER */
161 /* The leading dimension of the array VT. LDVT >= 1. */
162 /* If singular vectors are desired, then LDVT >= max( 1, N ). */
163
164 /* Q (output) DOUBLE PRECISION array, dimension (LDQ) */
165 /* If COMPQ = 'P', then: */
166 /* On exit, if INFO = 0, Q and IQ contain the left */
167 /* and right singular vectors in a compact form, */
168 /* requiring O(N log N) space instead of 2*N**2. */
169 /* In particular, Q contains all the DOUBLE PRECISION data in */
170 /* LDQ >= N*(11 + 2*SMLSIZ + 8*INT(LOG_2(N/(SMLSIZ+1)))) */
171 /* words of memory, where SMLSIZ is returned by ILAENV and */
172 /* is equal to the maximum size of the subproblems at the */
173 /* bottom of the computation tree (usually about 25). */
174 /* For other values of COMPQ, Q is not referenced. */
175
176 /* IQ (output) INTEGER array, dimension (LDIQ) */
177 /* If COMPQ = 'P', then: */
178 /* On exit, if INFO = 0, Q and IQ contain the left */
179 /* and right singular vectors in a compact form, */
180 /* requiring O(N log N) space instead of 2*N**2. */
181 /* In particular, IQ contains all INTEGER data in */
182 /* LDIQ >= N*(3 + 3*INT(LOG_2(N/(SMLSIZ+1)))) */
183 /* words of memory, where SMLSIZ is returned by ILAENV and */
184 /* is equal to the maximum size of the subproblems at the */
185 /* bottom of the computation tree (usually about 25). */
186 /* For other values of COMPQ, IQ is not referenced. */
187
188 /* WORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
189 /* If COMPQ = 'N' then LWORK >= (4 * N). */
190 /* If COMPQ = 'P' then LWORK >= (6 * N). */
191 /* If COMPQ = 'I' then LWORK >= (3 * N**2 + 4 * N). */
192
193 /* IWORK (workspace) INTEGER array, dimension (8*N) */
194
195 /* INFO (output) INTEGER */
196 /* = 0: successful exit. */
197 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
198 /* > 0: The algorithm failed to compute an singular value. */
199 /* The update process of divide and conquer failed. */
200
201 /* Further Details */
202 /* =============== */
203
204 /* Based on contributions by */
205 /* Ming Gu and Huan Ren, Computer Science Division, University of */
206 /* California at Berkeley, USA */
207
208 /* ===================================================================== */
209 /* Changed dimension statement in comment describing E from (N) to */
210 /* (N-1). Sven, 17 Feb 05. */
211 /* ===================================================================== */
212
213 /* .. Parameters .. */
214 /* .. */
215 /* .. Local Scalars .. */
216 /* .. */
217 /* .. External Functions .. */
218 /* .. */
219 /* .. External Subroutines .. */
220 /* .. */
221 /* .. Intrinsic Functions .. */
222 /* .. */
223 /* .. Executable Statements .. */
224
225 /* Test the input parameters. */
226
227 /* Parameter adjustments */
228 --d__;
229 --e;
230 u_dim1 = *ldu;
231 u_offset = 1 + u_dim1;
232 u -= u_offset;
233 vt_dim1 = *ldvt;
234 vt_offset = 1 + vt_dim1;
235 vt -= vt_offset;
236 --q;
237 --iq;
238 --work;
239 --iwork;
240
241 /* Function Body */
242 *info = 0;
243
244 iuplo = 0;
245 if (lsame_(uplo, "U")) {
246 iuplo = 1;
247 }
248 if (lsame_(uplo, "L")) {
249 iuplo = 2;
250 }
251 if (lsame_(compq, "N")) {
252 icompq = 0;
253 } else if (lsame_(compq, "P")) {
254 icompq = 1;
255 } else if (lsame_(compq, "I")) {
256 icompq = 2;
257 } else {
258 icompq = -1;
259 }
260 if (iuplo == 0) {
261 *info = -1;
262 } else if (icompq < 0) {
263 *info = -2;
264 } else if (*n < 0) {
265 *info = -3;
266 } else if (*ldu < 1 || icompq == 2 && *ldu < *n) {
267 *info = -7;
268 } else if (*ldvt < 1 || icompq == 2 && *ldvt < *n) {
269 *info = -9;
270 }
271 if (*info != 0) {
272 i__1 = -(*info);
273 xerbla_("DBDSDC", &i__1);
274 return 0;
275 }
276
277 /* Quick return if possible */
278
279 if (*n == 0) {
280 return 0;
281 }
282 smlsiz = ilaenv_(&c__9, "DBDSDC", " ", &c__0, &c__0, &c__0, &c__0);
283 if (*n == 1) {
284 if (icompq == 1) {
285 q[1] = d_sign(&c_b15, &d__[1]);
286 q[smlsiz * *n + 1] = 1.;
287 } else if (icompq == 2) {
288 u[u_dim1 + 1] = d_sign(&c_b15, &d__[1]);
289 vt[vt_dim1 + 1] = 1.;
290 }
291 d__[1] = abs(d__[1]);
292 return 0;
293 }
294 nm1 = *n - 1;
295
296 /* If matrix lower bidiagonal, rotate to be upper bidiagonal */
297 /* by applying Givens rotations on the left */
298
299 wstart = 1;
300 qstart = 3;
301 if (icompq == 1) {
302 dcopy_(n, &d__[1], &c__1, &q[1], &c__1);
303 i__1 = *n - 1;
304 dcopy_(&i__1, &e[1], &c__1, &q[*n + 1], &c__1);
305 }
306 if (iuplo == 2) {
307 qstart = 5;
308 wstart = (*n << 1) - 1;
309 i__1 = *n - 1;
310 for (i__ = 1; i__ <= i__1; ++i__) {
311 dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
312 d__[i__] = r__;
313 e[i__] = sn * d__[i__ + 1];
314 d__[i__ + 1] = cs * d__[i__ + 1];
315 if (icompq == 1) {
316 q[i__ + (*n << 1)] = cs;
317 q[i__ + *n * 3] = sn;
318 } else if (icompq == 2) {
319 work[i__] = cs;
320 work[nm1 + i__] = -sn;
321 }
322 /* L10: */
323 }
324 }
325
326 /* If ICOMPQ = 0, use DLASDQ to compute the singular values. */
327
328 if (icompq == 0) {
329 dlasdq_("U", &c__0, n, &c__0, &c__0, &c__0, &d__[1], &e[1], &vt[
330 vt_offset], ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[
331 wstart], info);
332 goto L40;
333 }
334
335 /* If N is smaller than the minimum divide size SMLSIZ, then solve */
336 /* the problem with another solver. */
337
338 if (*n <= smlsiz) {
339 if (icompq == 2) {
340 dlaset_("A", n, n, &c_b29, &c_b15, &u[u_offset], ldu);
341 dlaset_("A", n, n, &c_b29, &c_b15, &vt[vt_offset], ldvt);
342 dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &vt[vt_offset]
343 , ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[
344 wstart], info);
345 } else if (icompq == 1) {
346 iu = 1;
347 ivt = iu + *n;
348 dlaset_("A", n, n, &c_b29, &c_b15, &q[iu + (qstart - 1) * *n], n);
349 dlaset_("A", n, n, &c_b29, &c_b15, &q[ivt + (qstart - 1) * *n], n);
350 dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &q[ivt + (
351 qstart - 1) * *n], n, &q[iu + (qstart - 1) * *n], n, &q[
352 iu + (qstart - 1) * *n], n, &work[wstart], info);
353 }
354 goto L40;
355 }
356
357 if (icompq == 2) {
358 dlaset_("A", n, n, &c_b29, &c_b15, &u[u_offset], ldu);
359 dlaset_("A", n, n, &c_b29, &c_b15, &vt[vt_offset], ldvt);
360 }
361
362 /* Scale. */
363
364 orgnrm = dlanst_("M", n, &d__[1], &e[1]);
365 if (orgnrm == 0.) {
366 return 0;
367 }
368 dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, n, &c__1, &d__[1], n, &ierr);
369 dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, &nm1, &c__1, &e[1], &nm1, &
370 ierr);
371
372 eps = dlamch_("Epsilon");
373
374 mlvl = (integer) (log((double) (*n) / (double) (smlsiz + 1)) /
375 log(2.)) + 1;
376 smlszp = smlsiz + 1;
377
378 if (icompq == 1) {
379 iu = 1;
380 ivt = smlsiz + 1;
381 difl = ivt + smlszp;
382 difr = difl + mlvl;
383 z__ = difr + (mlvl << 1);
384 ic = z__ + mlvl;
385 is = ic + 1;
386 poles = is + 1;
387 givnum = poles + (mlvl << 1);
388
389 k = 1;
390 givptr = 2;
391 perm = 3;
392 givcol = perm + mlvl;
393 }
394
395 i__1 = *n;
396 for (i__ = 1; i__ <= i__1; ++i__) {
397 if ((d__1 = d__[i__], abs(d__1)) < eps) {
398 d__[i__] = d_sign(&eps, &d__[i__]);
399 }
400 /* L20: */
401 }
402
403 start = 1;
404 sqre = 0;
405
406 i__1 = nm1;
407 for (i__ = 1; i__ <= i__1; ++i__) {
408 if ((d__1 = e[i__], abs(d__1)) < eps || i__ == nm1) {
409
410 /* Subproblem found. First determine its size and then */
411 /* apply divide and conquer on it. */
412
413 if (i__ < nm1) {
414
415 /* A subproblem with E(I) small for I < NM1. */
416
417 nsize = i__ - start + 1;
418 } else if ((d__1 = e[i__], abs(d__1)) >= eps) {
419
420 /* A subproblem with E(NM1) not too small but I = NM1. */
421
422 nsize = *n - start + 1;
423 } else {
424
425 /* A subproblem with E(NM1) small. This implies an */
426 /* 1-by-1 subproblem at D(N). Solve this 1-by-1 problem */
427 /* first. */
428
429 nsize = i__ - start + 1;
430 if (icompq == 2) {
431 u[*n + *n * u_dim1] = d_sign(&c_b15, &d__[*n]);
432 vt[*n + *n * vt_dim1] = 1.;
433 } else if (icompq == 1) {
434 q[*n + (qstart - 1) * *n] = d_sign(&c_b15, &d__[*n]);
435 q[*n + (smlsiz + qstart - 1) * *n] = 1.;
436 }
437 d__[*n] = (d__1 = d__[*n], abs(d__1));
438 }
439 if (icompq == 2) {
440 dlasd0_(&nsize, &sqre, &d__[start], &e[start], &u[start +
441 start * u_dim1], ldu, &vt[start + start * vt_dim1],
442 ldvt, &smlsiz, &iwork[1], &work[wstart], info);
443 } else {
444 dlasda_(&icompq, &smlsiz, &nsize, &sqre, &d__[start], &e[
445 start], &q[start + (iu + qstart - 2) * *n], n, &q[
446 start + (ivt + qstart - 2) * *n], &iq[start + k * *n],
447 &q[start + (difl + qstart - 2) * *n], &q[start + (
448 difr + qstart - 2) * *n], &q[start + (z__ + qstart -
449 2) * *n], &q[start + (poles + qstart - 2) * *n], &iq[
450 start + givptr * *n], &iq[start + givcol * *n], n, &
451 iq[start + perm * *n], &q[start + (givnum + qstart -
452 2) * *n], &q[start + (ic + qstart - 2) * *n], &q[
453 start + (is + qstart - 2) * *n], &work[wstart], &
454 iwork[1], info);
455 if (*info != 0) {
456 return 0;
457 }
458 }
459 start = i__ + 1;
460 }
461 /* L30: */
462 }
463
464 /* Unscale */
465
466 dlascl_("G", &c__0, &c__0, &c_b15, &orgnrm, n, &c__1, &d__[1], n, &ierr);
467 L40:
468
469 /* Use Selection Sort to minimize swaps of singular vectors */
470
471 i__1 = *n;
472 for (ii = 2; ii <= i__1; ++ii) {
473 i__ = ii - 1;
474 kk = i__;
475 p = d__[i__];
476 i__2 = *n;
477 for (j = ii; j <= i__2; ++j) {
478 if (d__[j] > p) {
479 kk = j;
480 p = d__[j];
481 }
482 /* L50: */
483 }
484 if (kk != i__) {
485 d__[kk] = d__[i__];
486 d__[i__] = p;
487 if (icompq == 1) {
488 iq[i__] = kk;
489 } else if (icompq == 2) {
490 dswap_(n, &u[i__ * u_dim1 + 1], &c__1, &u[kk * u_dim1 + 1], &
491 c__1);
492 dswap_(n, &vt[i__ + vt_dim1], ldvt, &vt[kk + vt_dim1], ldvt);
493 }
494 } else if (icompq == 1) {
495 iq[i__] = i__;
496 }
497 /* L60: */
498 }
499
500 /* If ICOMPQ = 1, use IQ(N,1) as the indicator for UPLO */
501
502 if (icompq == 1) {
503 if (iuplo == 1) {
504 iq[*n] = 1;
505 } else {
506 iq[*n] = 0;
507 }
508 }
509
510 /* If B is lower bidiagonal, update U by those Givens rotations */
511 /* which rotated B to be upper bidiagonal */
512
513 if (iuplo == 2 && icompq == 2) {
514 dlasr_("L", "V", "B", n, n, &work[1], &work[*n], &u[u_offset], ldu);
515 }
516
517 return 0;
518
519 /* End of DBDSDC */
520
521 } /* dbdsdc_ */
522
523 /* Subroutine */ int dbdsqr_(const char *uplo, integer *n, integer *ncvt, integer *
524 nru, integer *ncc, double *d__, double *e, double *vt,
525 integer *ldvt, double *u, integer *ldu, double *c__, integer *
526 ldc, double *work, integer *info)
527 {
528 /* Table of constant values */
529 static double c_b15 = -.125;
530 static integer c__1 = 1;
531 static double c_b49 = 1.;
532 static double c_b72 = -1.;
533
534 /* System generated locals */
535 integer c_dim1, c_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1,
536 i__2;
537 double d__1, d__2, d__3, d__4;
538
539 /* Local variables */
540 double f, g, h__;
541 integer i__, j, m;
542 double r__, cs;
543 integer ll;
544 double sn, mu;
545 integer nm1, nm12, nm13, lll;
546 double eps, sll, tol, abse;
547 integer idir;
548 double abss;
549 integer oldm;
550 double cosl;
551 integer isub, iter;
552 double unfl, sinl, cosr, smin, smax, sinr;
553 double oldcs;
554 integer oldll;
555 double shift, sigmn, oldsn;
556 integer maxit;
557 double sminl, sigmx;
558 bool lower;
559 double sminoa, thresh;
560 bool rotate;
561 double tolmul;
562
563
564 /* -- LAPACK routine (version 3.1.1) -- */
565 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
566 /* January 2007 */
567
568 /* .. Scalar Arguments .. */
569 /* .. */
570 /* .. Array Arguments .. */
571 /* .. */
572
573 /* Purpose */
574 /* ======= */
575
576 /* DBDSQR computes the singular values and, optionally, the right and/or */
577 /* left singular vectors from the singular value decomposition (SVD) of */
578 /* a real N-by-N (upper or lower) bidiagonal matrix B using the implicit */
579 /* zero-shift QR algorithm. The SVD of B has the form */
580
581 /* B = Q * S * P**T */
582
583 /* where S is the diagonal matrix of singular values, Q is an orthogonal */
584 /* matrix of left singular vectors, and P is an orthogonal matrix of */
585 /* right singular vectors. If left singular vectors are requested, this */
586 /* subroutine actually returns U*Q instead of Q, and, if right singular */
587 /* vectors are requested, this subroutine returns P**T*VT instead of */
588 /* P**T, for given real input matrices U and VT. When U and VT are the */
589 /* orthogonal matrices that reduce a general matrix A to bidiagonal */
590 /* form: A = U*B*VT, as computed by DGEBRD, then */
591
592 /* A = (U*Q) * S * (P**T*VT) */
593
594 /* is the SVD of A. Optionally, the subroutine may also compute Q**T*C */
595 /* for a given real input matrix C. */
596
597 /* See "Computing Small Singular Values of Bidiagonal Matrices With */
598 /* Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan, */
599 /* LAPACK Working Note #3 (or SIAM J. Sci. Statist. Comput. vol. 11, */
600 /* no. 5, pp. 873-912, Sept 1990) and */
601 /* "Accurate singular values and differential qd algorithms," by */
602 /* B. Parlett and V. Fernando, Technical Report CPAM-554, Mathematics */
603 /* Department, University of California at Berkeley, July 1992 */
604 /* for a detailed description of the algorithm. */
605
606 /* Arguments */
607 /* ========= */
608
609 /* UPLO (input) CHARACTER*1 */
610 /* = 'U': B is upper bidiagonal; */
611 /* = 'L': B is lower bidiagonal. */
612
613 /* N (input) INTEGER */
614 /* The order of the matrix B. N >= 0. */
615
616 /* NCVT (input) INTEGER */
617 /* The number of columns of the matrix VT. NCVT >= 0. */
618
619 /* NRU (input) INTEGER */
620 /* The number of rows of the matrix U. NRU >= 0. */
621
622 /* NCC (input) INTEGER */
623 /* The number of columns of the matrix C. NCC >= 0. */
624
625 /* D (input/output) DOUBLE PRECISION array, dimension (N) */
626 /* On entry, the n diagonal elements of the bidiagonal matrix B. */
627 /* On exit, if INFO=0, the singular values of B in decreasing */
628 /* order. */
629
630 /* E (input/output) DOUBLE PRECISION array, dimension (N-1) */
631 /* On entry, the N-1 offdiagonal elements of the bidiagonal */
632 /* matrix B. */
633 /* On exit, if INFO = 0, E is destroyed; if INFO > 0, D and E */
634 /* will contain the diagonal and superdiagonal elements of a */
635 /* bidiagonal matrix orthogonally equivalent to the one given */
636 /* as input. */
637
638 /* VT (input/output) DOUBLE PRECISION array, dimension (LDVT, NCVT) */
639 /* On entry, an N-by-NCVT matrix VT. */
640 /* On exit, VT is overwritten by P**T * VT. */
641 /* Not referenced if NCVT = 0. */
642
643 /* LDVT (input) INTEGER */
644 /* The leading dimension of the array VT. */
645 /* LDVT >= max(1,N) if NCVT > 0; LDVT >= 1 if NCVT = 0. */
646
647 /* U (input/output) DOUBLE PRECISION array, dimension (LDU, N) */
648 /* On entry, an NRU-by-N matrix U. */
649 /* On exit, U is overwritten by U * Q. */
650 /* Not referenced if NRU = 0. */
651
652 /* LDU (input) INTEGER */
653 /* The leading dimension of the array U. LDU >= max(1,NRU). */
654
655 /* C (input/output) DOUBLE PRECISION array, dimension (LDC, NCC) */
656 /* On entry, an N-by-NCC matrix C. */
657 /* On exit, C is overwritten by Q**T * C. */
658 /* Not referenced if NCC = 0. */
659
660 /* LDC (input) INTEGER */
661 /* The leading dimension of the array C. */
662 /* LDC >= max(1,N) if NCC > 0; LDC >=1 if NCC = 0. */
663
664 /* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */
665 /* if NCVT = NRU = NCC = 0, (max(1, 4*N)) otherwise */
666
667 /* INFO (output) INTEGER */
668 /* = 0: successful exit */
669 /* < 0: If INFO = -i, the i-th argument had an illegal value */
670 /* > 0: the algorithm did not converge; D and E contain the */
671 /* elements of a bidiagonal matrix which is orthogonally */
672 /* similar to the input matrix B; if INFO = i, i */
673 /* elements of E have not converged to zero. */
674
675 /* Internal Parameters */
676 /* =================== */
677
678 /* TOLMUL DOUBLE PRECISION, default = max(10,min(100,EPS**(-1/8))) */
679 /* TOLMUL controls the convergence criterion of the QR loop. */
680 /* If it is positive, TOLMUL*EPS is the desired relative */
681 /* precision in the computed singular values. */
682 /* If it is negative, abs(TOLMUL*EPS*sigma_max) is the */
683 /* desired absolute accuracy in the computed singular */
684 /* values (corresponds to relative accuracy */
685 /* abs(TOLMUL*EPS) in the largest singular value. */
686 /* abs(TOLMUL) should be between 1 and 1/EPS, and preferably */
687 /* between 10 (for fast convergence) and .1/EPS */
688 /* (for there to be some accuracy in the results). */
689 /* Default is to lose at either one eighth or 2 of the */
690 /* available decimal digits in each computed singular value */
691 /* (whichever is smaller). */
692
693 /* MAXITR INTEGER, default = 6 */
694 /* MAXITR controls the maximum number of passes of the */
695 /* algorithm through its inner loop. The algorithms stops */
696 /* (and so fails to converge) if the number of passes */
697 /* through the inner loop exceeds MAXITR*N**2. */
698
699 /* ===================================================================== */
700
701 /* .. Parameters .. */
702 /* .. */
703 /* .. Local Scalars .. */
704 /* .. */
705 /* .. External Functions .. */
706 /* .. */
707 /* .. External Subroutines .. */
708 /* .. */
709 /* .. Intrinsic Functions .. */
710 /* .. */
711 /* .. Executable Statements .. */
712
713 /* Test the input parameters. */
714
715 /* Parameter adjustments */
716 --d__;
717 --e;
718 vt_dim1 = *ldvt;
719 vt_offset = 1 + vt_dim1;
720 vt -= vt_offset;
721 u_dim1 = *ldu;
722 u_offset = 1 + u_dim1;
723 u -= u_offset;
724 c_dim1 = *ldc;
725 c_offset = 1 + c_dim1;
726 c__ -= c_offset;
727 --work;
728
729 /* Function Body */
730 *info = 0;
731 lower = lsame_(uplo, "L");
732 if (! lsame_(uplo, "U") && ! lower) {
733 *info = -1;
734 } else if (*n < 0) {
735 *info = -2;
736 } else if (*ncvt < 0) {
737 *info = -3;
738 } else if (*nru < 0) {
739 *info = -4;
740 } else if (*ncc < 0) {
741 *info = -5;
742 } else if (*ncvt == 0 && *ldvt < 1 || *ncvt > 0 && *ldvt < std::max(1_integer,*n)) {
743 *info = -9;
744 } else if (*ldu < std::max(1_integer,*nru)) {
745 *info = -11;
746 } else if (*ncc == 0 && *ldc < 1 || *ncc > 0 && *ldc < std::max(1_integer,*n)) {
747 *info = -13;
748 }
749 if (*info != 0) {
750 i__1 = -(*info);
751 xerbla_("DBDSQR", &i__1);
752 return 0;
753 }
754 if (*n == 0) {
755 return 0;
756 }
757 if (*n == 1) {
758 goto L160;
759 }
760
761 /* ROTATE is true if any singular vectors desired, false otherwise */
762
763 rotate = *ncvt > 0 || *nru > 0 || *ncc > 0;
764
765 /* If no singular vectors desired, use qd algorithm */
766
767 if (! rotate) {
768 dlasq1_(n, &d__[1], &e[1], &work[1], info);
769 return 0;
770 }
771
772 nm1 = *n - 1;
773 nm12 = nm1 + nm1;
774 nm13 = nm12 + nm1;
775 idir = 0;
776
777 /* Get machine constants */
778
779 eps = dlamch_("Epsilon");
780 unfl = dlamch_("Safe minimum");
781
782 /* If matrix lower bidiagonal, rotate to be upper bidiagonal */
783 /* by applying Givens rotations on the left */
784
785 if (lower) {
786 i__1 = *n - 1;
787 for (i__ = 1; i__ <= i__1; ++i__) {
788 dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
789 d__[i__] = r__;
790 e[i__] = sn * d__[i__ + 1];
791 d__[i__ + 1] = cs * d__[i__ + 1];
792 work[i__] = cs;
793 work[nm1 + i__] = sn;
794 /* L10: */
795 }
796
797 /* Update singular vectors if desired */
798
799 if (*nru > 0) {
800 dlasr_("R", "V", "F", nru, n, &work[1], &work[*n], &u[u_offset],
801 ldu);
802 }
803 if (*ncc > 0) {
804 dlasr_("L", "V", "F", n, ncc, &work[1], &work[*n], &c__[c_offset],
805 ldc);
806 }
807 }
808
809 /* Compute singular values to relative accuracy TOL */
810 /* (By setting TOL to be negative, algorithm will compute */
811 /* singular values to absolute accuracy ABS(TOL)*norm(input matrix)) */
812
813 /* Computing MAX */
814 /* Computing MIN */
815 d__3 = 100., d__4 = pow_dd(&eps, &c_b15);
816 d__1 = 10., d__2 = std::min(d__3,d__4);
817 tolmul = std::max(d__1,d__2);
818 tol = tolmul * eps;
819
820 /* Compute approximate maximum, minimum singular values */
821
822 smax = 0.;
823 i__1 = *n;
824 for (i__ = 1; i__ <= i__1; ++i__) {
825 /* Computing MAX */
826 d__2 = smax, d__3 = (d__1 = d__[i__], abs(d__1));
827 smax = std::max(d__2,d__3);
828 /* L20: */
829 }
830 i__1 = *n - 1;
831 for (i__ = 1; i__ <= i__1; ++i__) {
832 /* Computing MAX */
833 d__2 = smax, d__3 = (d__1 = e[i__], abs(d__1));
834 smax = std::max(d__2,d__3);
835 /* L30: */
836 }
837 sminl = 0.;
838 if (tol >= 0.) {
839
840 /* Relative accuracy desired */
841
842 sminoa = abs(d__[1]);
843 if (sminoa == 0.) {
844 goto L50;
845 }
846 mu = sminoa;
847 i__1 = *n;
848 for (i__ = 2; i__ <= i__1; ++i__) {
849 mu = (d__2 = d__[i__], abs(d__2)) * (mu / (mu + (d__1 = e[i__ - 1]
850 , abs(d__1))));
851 sminoa = std::min(sminoa,mu);
852 if (sminoa == 0.) {
853 goto L50;
854 }
855 /* L40: */
856 }
857 L50:
858 sminoa /= sqrt((double) (*n));
859 /* Computing MAX */
860 d__1 = tol * sminoa, d__2 = *n * 6 * *n * unfl;
861 thresh = std::max(d__1,d__2);
862 } else {
863
864 /* Absolute accuracy desired */
865
866 /* Computing MAX */
867 d__1 = abs(tol) * smax, d__2 = *n * 6 * *n * unfl;
868 thresh = std::max(d__1,d__2);
869 }
870
871 /* Prepare for main iteration loop for the singular values */
872 /* (MAXIT is the maximum number of passes through the inner */
873 /* loop permitted before nonconvergence signalled.) */
874
875 maxit = *n * 6 * *n;
876 iter = 0;
877 oldll = -1;
878 oldm = -1;
879
880 /* M points to last element of unconverged part of matrix */
881
882 m = *n;
883
884 /* Begin main iteration loop */
885
886 L60:
887
888 /* Check for convergence or exceeding iteration count */
889
890 if (m <= 1) {
891 goto L160;
892 }
893 if (iter > maxit) {
894 goto L200;
895 }
896
897 /* Find diagonal block of matrix to work on */
898
899 if (tol < 0. && (d__1 = d__[m], abs(d__1)) <= thresh) {
900 d__[m] = 0.;
901 }
902 smax = (d__1 = d__[m], abs(d__1));
903 smin = smax;
904 i__1 = m - 1;
905 for (lll = 1; lll <= i__1; ++lll) {
906 ll = m - lll;
907 abss = (d__1 = d__[ll], abs(d__1));
908 abse = (d__1 = e[ll], abs(d__1));
909 if (tol < 0. && abss <= thresh) {
910 d__[ll] = 0.;
911 }
912 if (abse <= thresh) {
913 goto L80;
914 }
915 smin = std::min(smin,abss);
916 /* Computing MAX */
917 d__1 = std::max(smax,abss);
918 smax = std::max(d__1,abse);
919 /* L70: */
920 }
921 ll = 0;
922 goto L90;
923 L80:
924 e[ll] = 0.;
925
926 /* Matrix splits since E(LL) = 0 */
927
928 if (ll == m - 1) {
929
930 /* Convergence of bottom singular value, return to top of loop */
931
932 --m;
933 goto L60;
934 }
935 L90:
936 ++ll;
937
938 /* E(LL) through E(M-1) are nonzero, E(LL-1) is zero */
939
940 if (ll == m - 1) {
941
942 /* 2 by 2 block, handle separately */
943
944 dlasv2_(&d__[m - 1], &e[m - 1], &d__[m], &sigmn, &sigmx, &sinr, &cosr,
945 &sinl, &cosl);
946 d__[m - 1] = sigmx;
947 e[m - 1] = 0.;
948 d__[m] = sigmn;
949
950 /* Compute singular vectors, if desired */
951
952 if (*ncvt > 0) {
953 drot_(ncvt, &vt[m - 1 + vt_dim1], ldvt, &vt[m + vt_dim1], ldvt, &
954 cosr, &sinr);
955 }
956 if (*nru > 0) {
957 drot_(nru, &u[(m - 1) * u_dim1 + 1], &c__1, &u[m * u_dim1 + 1], &
958 c__1, &cosl, &sinl);
959 }
960 if (*ncc > 0) {
961 drot_(ncc, &c__[m - 1 + c_dim1], ldc, &c__[m + c_dim1], ldc, &
962 cosl, &sinl);
963 }
964 m += -2;
965 goto L60;
966 }
967
968 /* If working on new submatrix, choose shift direction */
969 /* (from larger end diagonal element towards smaller) */
970
971 if (ll > oldm || m < oldll) {
972 if ((d__1 = d__[ll], abs(d__1)) >= (d__2 = d__[m], abs(d__2))) {
973
974 /* Chase bulge from top (big end) to bottom (small end) */
975
976 idir = 1;
977 } else {
978
979 /* Chase bulge from bottom (big end) to top (small end) */
980
981 idir = 2;
982 }
983 }
984
985 /* Apply convergence tests */
986
987 if (idir == 1) {
988
989 /* Run convergence test in forward direction */
990 /* First apply standard test to bottom of matrix */
991
992 if ((d__2 = e[m - 1], abs(d__2)) <= abs(tol) * (d__1 = d__[m], abs(
993 d__1)) || tol < 0. && (d__3 = e[m - 1], abs(d__3)) <= thresh)
994 {
995 e[m - 1] = 0.;
996 goto L60;
997 }
998
999 if (tol >= 0.) {
1000
1001 /* If relative accuracy desired, */
1002 /* apply convergence criterion forward */
1003
1004 mu = (d__1 = d__[ll], abs(d__1));
1005 sminl = mu;
1006 i__1 = m - 1;
1007 for (lll = ll; lll <= i__1; ++lll) {
1008 if ((d__1 = e[lll], abs(d__1)) <= tol * mu) {
1009 e[lll] = 0.;
1010 goto L60;
1011 }
1012 mu = (d__2 = d__[lll + 1], abs(d__2)) * (mu / (mu + (d__1 = e[
1013 lll], abs(d__1))));
1014 sminl = std::min(sminl,mu);
1015 /* L100: */
1016 }
1017 }
1018
1019 } else {
1020
1021 /* Run convergence test in backward direction */
1022 /* First apply standard test to top of matrix */
1023
1024 if ((d__2 = e[ll], abs(d__2)) <= abs(tol) * (d__1 = d__[ll], abs(d__1)
1025 ) || tol < 0. && (d__3 = e[ll], abs(d__3)) <= thresh) {
1026 e[ll] = 0.;
1027 goto L60;
1028 }
1029
1030 if (tol >= 0.) {
1031
1032 /* If relative accuracy desired, */
1033 /* apply convergence criterion backward */
1034
1035 mu = (d__1 = d__[m], abs(d__1));
1036 sminl = mu;
1037 i__1 = ll;
1038 for (lll = m - 1; lll >= i__1; --lll) {
1039 if ((d__1 = e[lll], abs(d__1)) <= tol * mu) {
1040 e[lll] = 0.;
1041 goto L60;
1042 }
1043 mu = (d__2 = d__[lll], abs(d__2)) * (mu / (mu + (d__1 = e[lll]
1044 , abs(d__1))));
1045 sminl = std::min(sminl,mu);
1046 /* L110: */
1047 }
1048 }
1049 }
1050 oldll = ll;
1051 oldm = m;
1052
1053 /* Compute shift. First, test if shifting would ruin relative */
1054 /* accuracy, and if so set the shift to zero. */
1055
1056 /* Computing MAX */
1057 d__1 = eps, d__2 = tol * .01;
1058 if (tol >= 0. && *n * tol * (sminl / smax) <= std::max(d__1,d__2)) {
1059
1060 /* Use a zero shift to avoid loss of relative accuracy */
1061
1062 shift = 0.;
1063 } else {
1064
1065 /* Compute the shift from 2-by-2 block at end of matrix */
1066
1067 if (idir == 1) {
1068 sll = (d__1 = d__[ll], abs(d__1));
1069 dlas2_(&d__[m - 1], &e[m - 1], &d__[m], &shift, &r__);
1070 } else {
1071 sll = (d__1 = d__[m], abs(d__1));
1072 dlas2_(&d__[ll], &e[ll], &d__[ll + 1], &shift, &r__);
1073 }
1074
1075 /* Test if shift negligible, and if so set to zero */
1076
1077 if (sll > 0.) {
1078 /* Computing 2nd power */
1079 d__1 = shift / sll;
1080 if (d__1 * d__1 < eps) {
1081 shift = 0.;
1082 }
1083 }
1084 }
1085
1086 /* Increment iteration count */
1087
1088 iter = iter + m - ll;
1089
1090 /* If SHIFT = 0, do simplified QR iteration */
1091
1092 if (shift == 0.) {
1093 if (idir == 1) {
1094
1095 /* Chase bulge from top to bottom */
1096 /* Save cosines and sines for later singular vector updates */
1097
1098 cs = 1.;
1099 oldcs = 1.;
1100 i__1 = m - 1;
1101 for (i__ = ll; i__ <= i__1; ++i__) {
1102 d__1 = d__[i__] * cs;
1103 dlartg_(&d__1, &e[i__], &cs, &sn, &r__);
1104 if (i__ > ll) {
1105 e[i__ - 1] = oldsn * r__;
1106 }
1107 d__1 = oldcs * r__;
1108 d__2 = d__[i__ + 1] * sn;
1109 dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]);
1110 work[i__ - ll + 1] = cs;
1111 work[i__ - ll + 1 + nm1] = sn;
1112 work[i__ - ll + 1 + nm12] = oldcs;
1113 work[i__ - ll + 1 + nm13] = oldsn;
1114 /* L120: */
1115 }
1116 h__ = d__[m] * cs;
1117 d__[m] = h__ * oldcs;
1118 e[m - 1] = h__ * oldsn;
1119
1120 /* Update singular vectors */
1121
1122 if (*ncvt > 0) {
1123 i__1 = m - ll + 1;
1124 dlasr_("L", "V", "F", &i__1, ncvt, &work[1], &work[*n], &vt[
1125 ll + vt_dim1], ldvt);
1126 }
1127 if (*nru > 0) {
1128 i__1 = m - ll + 1;
1129 dlasr_("R", "V", "F", nru, &i__1, &work[nm12 + 1], &work[nm13
1130 + 1], &u[ll * u_dim1 + 1], ldu);
1131 }
1132 if (*ncc > 0) {
1133 i__1 = m - ll + 1;
1134 dlasr_("L", "V", "F", &i__1, ncc, &work[nm12 + 1], &work[nm13
1135 + 1], &c__[ll + c_dim1], ldc);
1136 }
1137
1138 /* Test convergence */
1139
1140 if ((d__1 = e[m - 1], abs(d__1)) <= thresh) {
1141 e[m - 1] = 0.;
1142 }
1143
1144 } else {
1145
1146 /* Chase bulge from bottom to top */
1147 /* Save cosines and sines for later singular vector updates */
1148
1149 cs = 1.;
1150 oldcs = 1.;
1151 i__1 = ll + 1;
1152 for (i__ = m; i__ >= i__1; --i__) {
1153 d__1 = d__[i__] * cs;
1154 dlartg_(&d__1, &e[i__ - 1], &cs, &sn, &r__);
1155 if (i__ < m) {
1156 e[i__] = oldsn * r__;
1157 }
1158 d__1 = oldcs * r__;
1159 d__2 = d__[i__ - 1] * sn;
1160 dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]);
1161 work[i__ - ll] = cs;
1162 work[i__ - ll + nm1] = -sn;
1163 work[i__ - ll + nm12] = oldcs;
1164 work[i__ - ll + nm13] = -oldsn;
1165 /* L130: */
1166 }
1167 h__ = d__[ll] * cs;
1168 d__[ll] = h__ * oldcs;
1169 e[ll] = h__ * oldsn;
1170
1171 /* Update singular vectors */
1172
1173 if (*ncvt > 0) {
1174 i__1 = m - ll + 1;
1175 dlasr_("L", "V", "B", &i__1, ncvt, &work[nm12 + 1], &work[
1176 nm13 + 1], &vt[ll + vt_dim1], ldvt);
1177 }
1178 if (*nru > 0) {
1179 i__1 = m - ll + 1;
1180 dlasr_("R", "V", "B", nru, &i__1, &work[1], &work[*n], &u[ll *
1181 u_dim1 + 1], ldu);
1182 }
1183 if (*ncc > 0) {
1184 i__1 = m - ll + 1;
1185 dlasr_("L", "V", "B", &i__1, ncc, &work[1], &work[*n], &c__[
1186 ll + c_dim1], ldc);
1187 }
1188
1189 /* Test convergence */
1190
1191 if ((d__1 = e[ll], abs(d__1)) <= thresh) {
1192 e[ll] = 0.;
1193 }
1194 }
1195 } else {
1196
1197 /* Use nonzero shift */
1198
1199 if (idir == 1) {
1200
1201 /* Chase bulge from top to bottom */
1202 /* Save cosines and sines for later singular vector updates */
1203
1204 f = ((d__1 = d__[ll], abs(d__1)) - shift) * (d_sign(&c_b49, &d__[
1205 ll]) + shift / d__[ll]);
1206 g = e[ll];
1207 i__1 = m - 1;
1208 for (i__ = ll; i__ <= i__1; ++i__) {
1209 dlartg_(&f, &g, &cosr, &sinr, &r__);
1210 if (i__ > ll) {
1211 e[i__ - 1] = r__;
1212 }
1213 f = cosr * d__[i__] + sinr * e[i__];
1214 e[i__] = cosr * e[i__] - sinr * d__[i__];
1215 g = sinr * d__[i__ + 1];
1216 d__[i__ + 1] = cosr * d__[i__ + 1];
1217 dlartg_(&f, &g, &cosl, &sinl, &r__);
1218 d__[i__] = r__;
1219 f = cosl * e[i__] + sinl * d__[i__ + 1];
1220 d__[i__ + 1] = cosl * d__[i__ + 1] - sinl * e[i__];
1221 if (i__ < m - 1) {
1222 g = sinl * e[i__ + 1];
1223 e[i__ + 1] = cosl * e[i__ + 1];
1224 }
1225 work[i__ - ll + 1] = cosr;
1226 work[i__ - ll + 1 + nm1] = sinr;
1227 work[i__ - ll + 1 + nm12] = cosl;
1228 work[i__ - ll + 1 + nm13] = sinl;
1229 /* L140: */
1230 }
1231 e[m - 1] = f;
1232
1233 /* Update singular vectors */
1234
1235 if (*ncvt > 0) {
1236 i__1 = m - ll + 1;
1237 dlasr_("L", "V", "F", &i__1, ncvt, &work[1], &work[*n], &vt[
1238 ll + vt_dim1], ldvt);
1239 }
1240 if (*nru > 0) {
1241 i__1 = m - ll + 1;
1242 dlasr_("R", "V", "F", nru, &i__1, &work[nm12 + 1], &work[nm13
1243 + 1], &u[ll * u_dim1 + 1], ldu);
1244 }
1245 if (*ncc > 0) {
1246 i__1 = m - ll + 1;
1247 dlasr_("L", "V", "F", &i__1, ncc, &work[nm12 + 1], &work[nm13
1248 + 1], &c__[ll + c_dim1], ldc);
1249 }
1250
1251 /* Test convergence */
1252
1253 if ((d__1 = e[m - 1], abs(d__1)) <= thresh) {
1254 e[m - 1] = 0.;
1255 }
1256
1257 } else {
1258
1259 /* Chase bulge from bottom to top */
1260 /* Save cosines and sines for later singular vector updates */
1261
1262 f = ((d__1 = d__[m], abs(d__1)) - shift) * (d_sign(&c_b49, &d__[m]
1263 ) + shift / d__[m]);
1264 g = e[m - 1];
1265 i__1 = ll + 1;
1266 for (i__ = m; i__ >= i__1; --i__) {
1267 dlartg_(&f, &g, &cosr, &sinr, &r__);
1268 if (i__ < m) {
1269 e[i__] = r__;
1270 }
1271 f = cosr * d__[i__] + sinr * e[i__ - 1];
1272 e[i__ - 1] = cosr * e[i__ - 1] - sinr * d__[i__];
1273 g = sinr * d__[i__ - 1];
1274 d__[i__ - 1] = cosr * d__[i__ - 1];
1275 dlartg_(&f, &g, &cosl, &sinl, &r__);
1276 d__[i__] = r__;
1277 f = cosl * e[i__ - 1] + sinl * d__[i__ - 1];
1278 d__[i__ - 1] = cosl * d__[i__ - 1] - sinl * e[i__ - 1];
1279 if (i__ > ll + 1) {
1280 g = sinl * e[i__ - 2];
1281 e[i__ - 2] = cosl * e[i__ - 2];
1282 }
1283 work[i__ - ll] = cosr;
1284 work[i__ - ll + nm1] = -sinr;
1285 work[i__ - ll + nm12] = cosl;
1286 work[i__ - ll + nm13] = -sinl;
1287 /* L150: */
1288 }
1289 e[ll] = f;
1290
1291 /* Test convergence */
1292
1293 if ((d__1 = e[ll], abs(d__1)) <= thresh) {
1294 e[ll] = 0.;
1295 }
1296
1297 /* Update singular vectors if desired */
1298
1299 if (*ncvt > 0) {
1300 i__1 = m - ll + 1;
1301 dlasr_("L", "V", "B", &i__1, ncvt, &work[nm12 + 1], &work[
1302 nm13 + 1], &vt[ll + vt_dim1], ldvt);
1303 }
1304 if (*nru > 0) {
1305 i__1 = m - ll + 1;
1306 dlasr_("R", "V", "B", nru, &i__1, &work[1], &work[*n], &u[ll *
1307 u_dim1 + 1], ldu);
1308 }
1309 if (*ncc > 0) {
1310 i__1 = m - ll + 1;
1311 dlasr_("L", "V", "B", &i__1, ncc, &work[1], &work[*n], &c__[
1312 ll + c_dim1], ldc);
1313 }
1314 }
1315 }
1316
1317 /* QR iteration finished, go back and check convergence */
1318
1319 goto L60;
1320
1321 /* All singular values converged, so make them positive */
1322
1323 L160:
1324 i__1 = *n;
1325 for (i__ = 1; i__ <= i__1; ++i__) {
1326 if (d__[i__] < 0.) {
1327 d__[i__] = -d__[i__];
1328
1329 /* Change sign of singular vectors, if desired */
1330
1331 if (*ncvt > 0) {
1332 dscal_(ncvt, &c_b72, &vt[i__ + vt_dim1], ldvt);
1333 }
1334 }
1335 /* L170: */
1336 }
1337
1338 /* Sort the singular values into decreasing order (insertion sort on */
1339 /* singular values, but only one transposition per singular vector) */
1340
1341 i__1 = *n - 1;
1342 for (i__ = 1; i__ <= i__1; ++i__) {
1343
1344 /* Scan for smallest D(I) */
1345
1346 isub = 1;
1347 smin = d__[1];
1348 i__2 = *n + 1 - i__;
1349 for (j = 2; j <= i__2; ++j) {
1350 if (d__[j] <= smin) {
1351 isub = j;
1352 smin = d__[j];
1353 }
1354 /* L180: */
1355 }
1356 if (isub != *n + 1 - i__) {
1357
1358 /* Swap singular values and vectors */
1359
1360 d__[isub] = d__[*n + 1 - i__];
1361 d__[*n + 1 - i__] = smin;
1362 if (*ncvt > 0) {
1363 dswap_(ncvt, &vt[isub + vt_dim1], ldvt, &vt[*n + 1 - i__ +
1364 vt_dim1], ldvt);
1365 }
1366 if (*nru > 0) {
1367 dswap_(nru, &u[isub * u_dim1 + 1], &c__1, &u[(*n + 1 - i__) *
1368 u_dim1 + 1], &c__1);
1369 }
1370 if (*ncc > 0) {
1371 dswap_(ncc, &c__[isub + c_dim1], ldc, &c__[*n + 1 - i__ +
1372 c_dim1], ldc);
1373 }
1374 }
1375 /* L190: */
1376 }
1377 goto L220;
1378
1379 /* Maximum number of iterations exceeded, failure to converge */
1380
1381 L200:
1382 *info = 0;
1383 i__1 = *n - 1;
1384 for (i__ = 1; i__ <= i__1; ++i__) {
1385 if (e[i__] != 0.) {
1386 ++(*info);
1387 }
1388 /* L210: */
1389 }
1390 L220:
1391 return 0;
1392
1393 /* End of DBDSQR */
1394
1395 } /* dbdsqr_ */
1396
1397 /* Subroutine */ int ddisna_(const char *job, integer *m, integer *n, double *
1398 d__, double *sep, integer *info)
1399 {
1400 /* System generated locals */
1401 integer i__1;
1402 double d__1, d__2, d__3;
1403
1404 /* Local variables */
1405 integer i__, k;
1406 double eps;
1407 bool decr, left, incr, sing, eigen;
1408
1409 double anorm;
1410 bool right;
1411
1412 double oldgap, safmin;
1413
1414 double newgap, thresh;
1415
1416
1417 /* -- LAPACK routine (version 3.1) -- */
1418 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1419 /* November 2006 */
1420
1421 /* .. Scalar Arguments .. */
1422 /* .. */
1423 /* .. Array Arguments .. */
1424 /* .. */
1425
1426 /* Purpose */
1427 /* ======= */
1428
1429 /* DDISNA computes the reciprocal condition numbers for the eigenvectors */
1430 /* of a real symmetric or complex Hermitian matrix or for the left or */
1431 /* right singular vectors of a general m-by-n matrix. The reciprocal */
1432 /* condition number is the 'gap' between the corresponding eigenvalue or */
1433 /* singular value and the nearest other one. */
1434
1435 /* The bound on the error, measured by angle in radians, in the I-th */
1436 /* computed vector is given by */
1437
1438 /* DLAMCH( 'E' ) * ( ANORM / SEP( I ) ) */
1439
1440 /* where ANORM = 2-norm(A) = max( abs( D(j) ) ). SEP(I) is not allowed */
1441 /* to be smaller than DLAMCH( 'E' )*ANORM in order to limit the size of */
1442 /* the error bound. */
1443
1444 /* DDISNA may also be used to compute error bounds for eigenvectors of */
1445 /* the generalized symmetric definite eigenproblem. */
1446
1447 /* Arguments */
1448 /* ========= */
1449
1450 /* JOB (input) CHARACTER*1 */
1451 /* Specifies for which problem the reciprocal condition numbers */
1452 /* should be computed: */
1453 /* = 'E': the eigenvectors of a symmetric/Hermitian matrix; */
1454 /* = 'L': the left singular vectors of a general matrix; */
1455 /* = 'R': the right singular vectors of a general matrix. */
1456
1457 /* M (input) INTEGER */
1458 /* The number of rows of the matrix. M >= 0. */
1459
1460 /* N (input) INTEGER */
1461 /* If JOB = 'L' or 'R', the number of columns of the matrix, */
1462 /* in which case N >= 0. Ignored if JOB = 'E'. */
1463
1464 /* D (input) DOUBLE PRECISION array, dimension (M) if JOB = 'E' */
1465 /* dimension (min(M,N)) if JOB = 'L' or 'R' */
1466 /* The eigenvalues (if JOB = 'E') or singular values (if JOB = */
1467 /* 'L' or 'R') of the matrix, in either increasing or decreasing */
1468 /* order. If singular values, they must be non-negative. */
1469
1470 /* SEP (output) DOUBLE PRECISION array, dimension (M) if JOB = 'E' */
1471 /* dimension (min(M,N)) if JOB = 'L' or 'R' */
1472 /* The reciprocal condition numbers of the vectors. */
1473
1474 /* INFO (output) INTEGER */
1475 /* = 0: successful exit. */
1476 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
1477
1478 /* ===================================================================== */
1479
1480 /* .. Parameters .. */
1481 /* .. */
1482 /* .. Local Scalars .. */
1483 /* .. */
1484 /* .. External Functions .. */
1485 /* .. */
1486 /* .. Intrinsic Functions .. */
1487 /* .. */
1488 /* .. External Subroutines .. */
1489 /* .. */
1490 /* .. Executable Statements .. */
1491
1492 /* Test the input arguments */
1493
1494 /* Parameter adjustments */
1495 --sep;
1496 --d__;
1497
1498 /* Function Body */
1499 *info = 0;
1500 eigen = lsame_(job, "E");
1501 left = lsame_(job, "L");
1502 right = lsame_(job, "R");
1503 sing = left || right;
1504 if (eigen) {
1505 k = *m;
1506 } else if (sing) {
1507 k = std::min(*m,*n);
1508 }
1509 if (! eigen && ! sing) {
1510 *info = -1;
1511 } else if (*m < 0) {
1512 *info = -2;
1513 } else if (k < 0) {
1514 *info = -3;
1515 } else {
1516 incr = true;
1517 decr = true;
1518 i__1 = k - 1;
1519 for (i__ = 1; i__ <= i__1; ++i__) {
1520 if (incr) {
1521 incr = incr && d__[i__] <= d__[i__ + 1];
1522 }
1523 if (decr) {
1524 decr = decr && d__[i__] >= d__[i__ + 1];
1525 }
1526 /* L10: */
1527 }
1528 if (sing && k > 0) {
1529 if (incr) {
1530 incr = incr && 0. <= d__[1];
1531 }
1532 if (decr) {
1533 decr = decr && d__[k] >= 0.;
1534 }
1535 }
1536 if (! (incr || decr)) {
1537 *info = -4;
1538 }
1539 }
1540 if (*info != 0) {
1541 i__1 = -(*info);
1542 xerbla_("DDISNA", &i__1);
1543 return 0;
1544 }
1545
1546 /* Quick return if possible */
1547
1548 if (k == 0) {
1549 return 0;
1550 }
1551
1552 /* Compute reciprocal condition numbers */
1553
1554 if (k == 1) {
1555 sep[1] = dlamch_("O");
1556 } else {
1557 oldgap = (d__1 = d__[2] - d__[1], abs(d__1));
1558 sep[1] = oldgap;
1559 i__1 = k - 1;
1560 for (i__ = 2; i__ <= i__1; ++i__) {
1561 newgap = (d__1 = d__[i__ + 1] - d__[i__], abs(d__1));
1562 sep[i__] = std::min(oldgap,newgap);
1563 oldgap = newgap;
1564 /* L20: */
1565 }
1566 sep[k] = oldgap;
1567 }
1568 if (sing) {
1569 if (left && *m > *n || right && *m < *n) {
1570 if (incr) {
1571 sep[1] = std::min(sep[1],d__[1]);
1572 }
1573 if (decr) {
1574 /* Computing MIN */
1575 d__1 = sep[k], d__2 = d__[k];
1576 sep[k] = std::min(d__1,d__2);
1577 }
1578 }
1579 }
1580
1581 /* Ensure that reciprocal condition numbers are not less than */
1582 /* threshold, in order to limit the size of the error bound */
1583
1584 eps = dlamch_("E");
1585 safmin = dlamch_("S");
1586 /* Computing MAX */
1587 d__2 = abs(d__[1]), d__3 = (d__1 = d__[k], abs(d__1));
1588 anorm = std::max(d__2,d__3);
1589 if (anorm == 0.) {
1590 thresh = eps;
1591 } else {
1592 /* Computing MAX */
1593 d__1 = eps * anorm;
1594 thresh = std::max(d__1,safmin);
1595 }
1596 i__1 = k;
1597 for (i__ = 1; i__ <= i__1; ++i__) {
1598 /* Computing MAX */
1599 d__1 = sep[i__];
1600 sep[i__] = std::max(d__1,thresh);
1601 /* L30: */
1602 }
1603
1604 return 0;
1605
1606 /* End of DDISNA */
1607
1608 } /* ddisna_ */
1609
1610 /* Subroutine */ int dhgeqz_(const char *job, const char *compq, const char *compz, integer *n,
1611 integer *ilo, integer *ihi, double *h__, integer *ldh, double
1612 *t, integer *ldt, double *alphar, double *alphai, double *
1613 beta, double *q, integer *ldq, double *z__, integer *ldz,
1614 double *work, integer *lwork, integer *info)
1615 {
1616 /* Table of constant values */
1617 static double c_b12 = 0.;
1618 static double c_b13 = 1.;
1619 static integer c__1 = 1;
1620 static integer c__3 = 3;
1621
1622 /* System generated locals */
1623 integer h_dim1, h_offset, q_dim1, q_offset, t_dim1, t_offset, z_dim1,
1624 z_offset, i__1, i__2, i__3, i__4;
1625 double d__1, d__2, d__3, d__4;
1626
1627 /* Local variables */
1628 double c__;
1629 integer j;
1630 double s, v[3], s1, s2, t1, u1, u2, a11, a12, a21, a22, b11, b22, c12,
1631 c21;
1632 integer jc;
1633 double an, bn, cl, cq, cr;
1634 integer in;
1635 double u12, w11, w12, w21;
1636 integer jr;
1637 double cz, w22, sl, wi, sr, vs, wr, b1a, b2a, a1i, a2i, b1i, b2i, a1r,
1638 a2r, b1r, b2r, wr2, ad11, ad12, ad21, ad22, c11i, c22i;
1639 integer jch;
1640 double c11r, c22r;
1641 bool ilq;
1642 double u12l, tau, sqi;
1643 bool ilz;
1644 double ulp, sqr, szi, szr, ad11l, ad12l, ad21l, ad22l, ad32l, wabs,
1645 atol, btol, temp;
1646 double temp2, s1inv, scale;
1647 integer iiter, ilast, jiter;
1648 double anorm, bnorm;
1649 integer maxit;
1650 double tempi, tempr;
1651 bool ilazr2;
1652 double ascale, bscale;
1653 double safmin;
1654 double safmax;
1655 double eshift;
1656 bool ilschr;
1657 integer icompq, ilastm, ischur;
1658 bool ilazro;
1659 integer icompz, ifirst, ifrstm, istart;
1660 bool ilpivt, lquery;
1661
1662
1663 /* -- LAPACK routine (version 3.1) -- */
1664 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1665 /* November 2006 */
1666
1667 /* .. Scalar Arguments .. */
1668 /* .. */
1669 /* .. Array Arguments .. */
1670 /* .. */
1671
1672 /* Purpose */
1673 /* ======= */
1674
1675 /* DHGEQZ computes the eigenvalues of a real matrix pair (H,T), */
1676 /* where H is an upper Hessenberg matrix and T is upper triangular, */
1677 /* using the double-shift QZ method. */
1678 /* Matrix pairs of this type are produced by the reduction to */
1679 /* generalized upper Hessenberg form of a real matrix pair (A,B): */
1680
1681 /* A = Q1*H*Z1**T, B = Q1*T*Z1**T, */
1682
1683 /* as computed by DGGHRD. */
1684
1685 /* If JOB='S', then the Hessenberg-triangular pair (H,T) is */
1686 /* also reduced to generalized Schur form, */
1687
1688 /* H = Q*S*Z**T, T = Q*P*Z**T, */
1689
1690 /* where Q and Z are orthogonal matrices, P is an upper triangular */
1691 /* matrix, and S is a quasi-triangular matrix with 1-by-1 and 2-by-2 */
1692 /* diagonal blocks. */
1693
1694 /* The 1-by-1 blocks correspond to real eigenvalues of the matrix pair */
1695 /* (H,T) and the 2-by-2 blocks correspond to complex conjugate pairs of */
1696 /* eigenvalues. */
1697
1698 /* Additionally, the 2-by-2 upper triangular diagonal blocks of P */
1699 /* corresponding to 2-by-2 blocks of S are reduced to positive diagonal */
1700 /* form, i.e., if S(j+1,j) is non-zero, then P(j+1,j) = P(j,j+1) = 0, */
1701 /* P(j,j) > 0, and P(j+1,j+1) > 0. */
1702
1703 /* Optionally, the orthogonal matrix Q from the generalized Schur */
1704 /* factorization may be postmultiplied into an input matrix Q1, and the */
1705 /* orthogonal matrix Z may be postmultiplied into an input matrix Z1. */
1706 /* If Q1 and Z1 are the orthogonal matrices from DGGHRD that reduced */
1707 /* the matrix pair (A,B) to generalized upper Hessenberg form, then the */
1708 /* output matrices Q1*Q and Z1*Z are the orthogonal factors from the */
1709 /* generalized Schur factorization of (A,B): */
1710
1711 /* A = (Q1*Q)*S*(Z1*Z)**T, B = (Q1*Q)*P*(Z1*Z)**T. */
1712
1713 /* To avoid overflow, eigenvalues of the matrix pair (H,T) (equivalently, */
1714 /* of (A,B)) are computed as a pair of values (alpha,beta), where alpha is */
1715 /* complex and beta real. */
1716 /* If beta is nonzero, lambda = alpha / beta is an eigenvalue of the */
1717 /* generalized nonsymmetric eigenvalue problem (GNEP) */
1718 /* A*x = lambda*B*x */
1719 /* and if alpha is nonzero, mu = beta / alpha is an eigenvalue of the */
1720 /* alternate form of the GNEP */
1721 /* mu*A*y = B*y. */
1722 /* Real eigenvalues can be read directly from the generalized Schur */
1723 /* form: */
1724 /* alpha = S(i,i), beta = P(i,i). */
1725
1726 /* Ref: C.B. Moler & G.W. Stewart, "An Algorithm for Generalized Matrix */
1727 /* Eigenvalue Problems", SIAM J. Numer. Anal., 10(1973), */
1728 /* pp. 241--256. */
1729
1730 /* Arguments */
1731 /* ========= */
1732
1733 /* JOB (input) CHARACTER*1 */
1734 /* = 'E': Compute eigenvalues only; */
1735 /* = 'S': Compute eigenvalues and the Schur form. */
1736
1737 /* COMPQ (input) CHARACTER*1 */
1738 /* = 'N': Left Schur vectors (Q) are not computed; */
1739 /* = 'I': Q is initialized to the unit matrix and the matrix Q */
1740 /* of left Schur vectors of (H,T) is returned; */
1741 /* = 'V': Q must contain an orthogonal matrix Q1 on entry and */
1742 /* the product Q1*Q is returned. */
1743
1744 /* COMPZ (input) CHARACTER*1 */
1745 /* = 'N': Right Schur vectors (Z) are not computed; */
1746 /* = 'I': Z is initialized to the unit matrix and the matrix Z */
1747 /* of right Schur vectors of (H,T) is returned; */
1748 /* = 'V': Z must contain an orthogonal matrix Z1 on entry and */
1749 /* the product Z1*Z is returned. */
1750
1751 /* N (input) INTEGER */
1752 /* The order of the matrices H, T, Q, and Z. N >= 0. */
1753
1754 /* ILO (input) INTEGER */
1755 /* IHI (input) INTEGER */
1756 /* ILO and IHI mark the rows and columns of H which are in */
1757 /* Hessenberg form. It is assumed that A is already upper */
1758 /* triangular in rows and columns 1:ILO-1 and IHI+1:N. */
1759 /* If N > 0, 1 <= ILO <= IHI <= N; if N = 0, ILO=1 and IHI=0. */
1760
1761 /* H (input/output) DOUBLE PRECISION array, dimension (LDH, N) */
1762 /* On entry, the N-by-N upper Hessenberg matrix H. */
1763 /* On exit, if JOB = 'S', H contains the upper quasi-triangular */
1764 /* matrix S from the generalized Schur factorization; */
1765 /* 2-by-2 diagonal blocks (corresponding to complex conjugate */
1766 /* pairs of eigenvalues) are returned in standard form, with */
1767 /* H(i,i) = H(i+1,i+1) and H(i+1,i)*H(i,i+1) < 0. */
1768 /* If JOB = 'E', the diagonal blocks of H match those of S, but */
1769 /* the rest of H is unspecified. */
1770
1771 /* LDH (input) INTEGER */
1772 /* The leading dimension of the array H. LDH >= max( 1, N ). */
1773
1774 /* T (input/output) DOUBLE PRECISION array, dimension (LDT, N) */
1775 /* On entry, the N-by-N upper triangular matrix T. */
1776 /* On exit, if JOB = 'S', T contains the upper triangular */
1777 /* matrix P from the generalized Schur factorization; */
1778 /* 2-by-2 diagonal blocks of P corresponding to 2-by-2 blocks of S */
1779 /* are reduced to positive diagonal form, i.e., if H(j+1,j) is */
1780 /* non-zero, then T(j+1,j) = T(j,j+1) = 0, T(j,j) > 0, and */
1781 /* T(j+1,j+1) > 0. */
1782 /* If JOB = 'E', the diagonal blocks of T match those of P, but */
1783 /* the rest of T is unspecified. */
1784
1785 /* LDT (input) INTEGER */
1786 /* The leading dimension of the array T. LDT >= max( 1, N ). */
1787
1788 /* ALPHAR (output) DOUBLE PRECISION array, dimension (N) */
1789 /* The real parts of each scalar alpha defining an eigenvalue */
1790 /* of GNEP. */
1791
1792 /* ALPHAI (output) DOUBLE PRECISION array, dimension (N) */
1793 /* The imaginary parts of each scalar alpha defining an */
1794 /* eigenvalue of GNEP. */
1795 /* If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
1796 /* positive, then the j-th and (j+1)-st eigenvalues are a */
1797 /* complex conjugate pair, with ALPHAI(j+1) = -ALPHAI(j). */
1798
1799 /* BETA (output) DOUBLE PRECISION array, dimension (N) */
1800 /* The scalars beta that define the eigenvalues of GNEP. */
1801 /* Together, the quantities alpha = (ALPHAR(j),ALPHAI(j)) and */
1802 /* beta = BETA(j) represent the j-th eigenvalue of the matrix */
1803 /* pair (A,B), in one of the forms lambda = alpha/beta or */
1804 /* mu = beta/alpha. Since either lambda or mu may overflow, */
1805 /* they should not, in general, be computed. */
1806
1807 /* Q (input/output) DOUBLE PRECISION array, dimension (LDQ, N) */
1808 /* On entry, if COMPZ = 'V', the orthogonal matrix Q1 used in */
1809 /* the reduction of (A,B) to generalized Hessenberg form. */
1810 /* On exit, if COMPZ = 'I', the orthogonal matrix of left Schur */
1811 /* vectors of (H,T), and if COMPZ = 'V', the orthogonal matrix */
1812 /* of left Schur vectors of (A,B). */
1813 /* Not referenced if COMPZ = 'N'. */
1814
1815 /* LDQ (input) INTEGER */
1816 /* The leading dimension of the array Q. LDQ >= 1. */
1817 /* If COMPQ='V' or 'I', then LDQ >= N. */
1818
1819 /* Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N) */
1820 /* On entry, if COMPZ = 'V', the orthogonal matrix Z1 used in */
1821 /* the reduction of (A,B) to generalized Hessenberg form. */
1822 /* On exit, if COMPZ = 'I', the orthogonal matrix of */
1823 /* right Schur vectors of (H,T), and if COMPZ = 'V', the */
1824 /* orthogonal matrix of right Schur vectors of (A,B). */
1825 /* Not referenced if COMPZ = 'N'. */
1826
1827 /* LDZ (input) INTEGER */
1828 /* The leading dimension of the array Z. LDZ >= 1. */
1829 /* If COMPZ='V' or 'I', then LDZ >= N. */
1830
1831 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
1832 /* On exit, if INFO >= 0, WORK(1) returns the optimal LWORK. */
1833
1834 /* LWORK (input) INTEGER */
1835 /* The dimension of the array WORK. LWORK >= max(1,N). */
1836
1837 /* If LWORK = -1, then a workspace query is assumed; the routine */
1838 /* only calculates the optimal size of the WORK array, returns */
1839 /* this value as the first entry of the WORK array, and no error */
1840 /* message related to LWORK is issued by XERBLA. */
1841
1842 /* INFO (output) INTEGER */
1843 /* = 0: successful exit */
1844 /* < 0: if INFO = -i, the i-th argument had an illegal value */
1845 /* = 1,...,N: the QZ iteration did not converge. (H,T) is not */
1846 /* in Schur form, but ALPHAR(i), ALPHAI(i), and */
1847 /* BETA(i), i=INFO+1,...,N should be correct. */
1848 /* = N+1,...,2*N: the shift calculation failed. (H,T) is not */
1849 /* in Schur form, but ALPHAR(i), ALPHAI(i), and */
1850 /* BETA(i), i=INFO-N+1,...,N should be correct. */
1851
1852 /* Further Details */
1853 /* =============== */
1854
1855 /* Iteration counters: */
1856
1857 /* JITER -- counts iterations. */
1858 /* IITER -- counts iterations run since ILAST was last */
1859 /* changed. This is therefore reset only when a 1-by-1 or */
1860 /* 2-by-2 block deflates off the bottom. */
1861
1862 /* ===================================================================== */
1863
1864 /* .. Parameters .. */
1865 /* $ SAFETY = 1.0E+0 ) */
1866 /* .. */
1867 /* .. Local Scalars .. */
1868 /* .. */
1869 /* .. Local Arrays .. */
1870 /* .. */
1871 /* .. External Functions .. */
1872 /* .. */
1873 /* .. External Subroutines .. */
1874 /* .. */
1875 /* .. Intrinsic Functions .. */
1876 /* .. */
1877 /* .. Executable Statements .. */
1878
1879 /* Decode JOB, COMPQ, COMPZ */
1880
1881 /* Parameter adjustments */
1882 h_dim1 = *ldh;
1883 h_offset = 1 + h_dim1;
1884 h__ -= h_offset;
1885 t_dim1 = *ldt;
1886 t_offset = 1 + t_dim1;
1887 t -= t_offset;
1888 --alphar;
1889 --alphai;
1890 --beta;
1891 q_dim1 = *ldq;
1892 q_offset = 1 + q_dim1;
1893 q -= q_offset;
1894 z_dim1 = *ldz;
1895 z_offset = 1 + z_dim1;
1896 z__ -= z_offset;
1897 --work;
1898
1899 /* Function Body */
1900 if (lsame_(job, "E")) {
1901 ilschr = false;
1902 ischur = 1;
1903 } else if (lsame_(job, "S")) {
1904 ilschr = true;
1905 ischur = 2;
1906 } else {
1907 ischur = 0;
1908 }
1909
1910 if (lsame_(compq, "N")) {
1911 ilq = false;
1912 icompq = 1;
1913 } else if (lsame_(compq, "V")) {
1914 ilq = true;
1915 icompq = 2;
1916 } else if (lsame_(compq, "I")) {
1917 ilq = true;
1918 icompq = 3;
1919 } else {
1920 icompq = 0;
1921 }
1922
1923 if (lsame_(compz, "N")) {
1924 ilz = false;
1925 icompz = 1;
1926 } else if (lsame_(compz, "V")) {
1927 ilz = true;
1928 icompz = 2;
1929 } else if (lsame_(compz, "I")) {
1930 ilz = true;
1931 icompz = 3;
1932 } else {
1933 icompz = 0;
1934 }
1935
1936 /* Check Argument Values */
1937
1938 *info = 0;
1939 work[1] = (double) std::max(1_integer,*n);
1940 lquery = *lwork == -1;
1941 if (ischur == 0) {
1942 *info = -1;
1943 } else if (icompq == 0) {
1944 *info = -2;
1945 } else if (icompz == 0) {
1946 *info = -3;
1947 } else if (*n < 0) {
1948 *info = -4;
1949 } else if (*ilo < 1) {
1950 *info = -5;
1951 } else if (*ihi > *n || *ihi < *ilo - 1) {
1952 *info = -6;
1953 } else if (*ldh < *n) {
1954 *info = -8;
1955 } else if (*ldt < *n) {
1956 *info = -10;
1957 } else if (*ldq < 1 || ilq && *ldq < *n) {
1958 *info = -15;
1959 } else if (*ldz < 1 || ilz && *ldz < *n) {
1960 *info = -17;
1961 } else if (*lwork < std::max(1_integer,*n) && ! lquery) {
1962 *info = -19;
1963 }
1964 if (*info != 0) {
1965 i__1 = -(*info);
1966 xerbla_("DHGEQZ", &i__1);
1967 return 0;
1968 } else if (lquery) {
1969 return 0;
1970 }
1971
1972 /* Quick return if possible */
1973
1974 if (*n <= 0) {
1975 work[1] = 1.;
1976 return 0;
1977 }
1978
1979 /* Initialize Q and Z */
1980
1981 if (icompq == 3) {
1982 dlaset_("Full", n, n, &c_b12, &c_b13, &q[q_offset], ldq);
1983 }
1984 if (icompz == 3) {
1985 dlaset_("Full", n, n, &c_b12, &c_b13, &z__[z_offset], ldz);
1986 }
1987
1988 /* Machine Constants */
1989
1990 in = *ihi + 1 - *ilo;
1991 safmin = dlamch_("S");
1992 safmax = 1. / safmin;
1993 ulp = dlamch_("E") * dlamch_("B");
1994 anorm = dlanhs_("F", &in, &h__[*ilo + *ilo * h_dim1], ldh, &work[1]);
1995 bnorm = dlanhs_("F", &in, &t[*ilo + *ilo * t_dim1], ldt, &work[1]);
1996 /* Computing MAX */
1997 d__1 = safmin, d__2 = ulp * anorm;
1998 atol = std::max(d__1,d__2);
1999 /* Computing MAX */
2000 d__1 = safmin, d__2 = ulp * bnorm;
2001 btol = std::max(d__1,d__2);
2002 ascale = 1. / std::max(safmin,anorm);
2003 bscale = 1. / std::max(safmin,bnorm);
2004
2005 /* Set Eigenvalues IHI+1:N */
2006
2007 i__1 = *n;
2008 for (j = *ihi + 1; j <= i__1; ++j) {
2009 if (t[j + j * t_dim1] < 0.) {
2010 if (ilschr) {
2011 i__2 = j;
2012 for (jr = 1; jr <= i__2; ++jr) {
2013 h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
2014 t[jr + j * t_dim1] = -t[jr + j * t_dim1];
2015 /* L10: */
2016 }
2017 } else {
2018 h__[j + j * h_dim1] = -h__[j + j * h_dim1];
2019 t[j + j * t_dim1] = -t[j + j * t_dim1];
2020 }
2021 if (ilz) {
2022 i__2 = *n;
2023 for (jr = 1; jr <= i__2; ++jr) {
2024 z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
2025 /* L20: */
2026 }
2027 }
2028 }
2029 alphar[j] = h__[j + j * h_dim1];
2030 alphai[j] = 0.;
2031 beta[j] = t[j + j * t_dim1];
2032 /* L30: */
2033 }
2034
2035 /* If IHI < ILO, skip QZ steps */
2036
2037 if (*ihi < *ilo) {
2038 goto L380;
2039 }
2040
2041 /* MAIN QZ ITERATION LOOP */
2042
2043 /* Initialize dynamic indices */
2044
2045 /* Eigenvalues ILAST+1:N have been found. */
2046 /* Column operations modify rows IFRSTM:whatever. */
2047 /* Row operations modify columns whatever:ILASTM. */
2048
2049 /* If only eigenvalues are being computed, then */
2050 /* IFRSTM is the row of the last splitting row above row ILAST; */
2051 /* this is always at least ILO. */
2052 /* IITER counts iterations since the last eigenvalue was found, */
2053 /* to tell when to use an extraordinary shift. */
2054 /* MAXIT is the maximum number of QZ sweeps allowed. */
2055
2056 ilast = *ihi;
2057 if (ilschr) {
2058 ifrstm = 1;
2059 ilastm = *n;
2060 } else {
2061 ifrstm = *ilo;
2062 ilastm = *ihi;
2063 }
2064 iiter = 0;
2065 eshift = 0.;
2066 maxit = (*ihi - *ilo + 1) * 30;
2067
2068 i__1 = maxit;
2069 for (jiter = 1; jiter <= i__1; ++jiter) {
2070
2071 /* Split the matrix if possible. */
2072
2073 /* Two tests: */
2074 /* 1: H(j,j-1)=0 or j=ILO */
2075 /* 2: T(j,j)=0 */
2076
2077 if (ilast == *ilo) {
2078
2079 /* Special case: j=ILAST */
2080
2081 goto L80;
2082 } else {
2083 if ((d__1 = h__[ilast + (ilast - 1) * h_dim1], abs(d__1)) <= atol)
2084 {
2085 h__[ilast + (ilast - 1) * h_dim1] = 0.;
2086 goto L80;
2087 }
2088 }
2089
2090 if ((d__1 = t[ilast + ilast * t_dim1], abs(d__1)) <= btol) {
2091 t[ilast + ilast * t_dim1] = 0.;
2092 goto L70;
2093 }
2094
2095 /* General case: j<ILAST */
2096
2097 i__2 = *ilo;
2098 for (j = ilast - 1; j >= i__2; --j) {
2099
2100 /* Test 1: for H(j,j-1)=0 or j=ILO */
2101
2102 if (j == *ilo) {
2103 ilazro = true;
2104 } else {
2105 if ((d__1 = h__[j + (j - 1) * h_dim1], abs(d__1)) <= atol) {
2106 h__[j + (j - 1) * h_dim1] = 0.;
2107 ilazro = true;
2108 } else {
2109 ilazro = false;
2110 }
2111 }
2112
2113 /* Test 2: for T(j,j)=0 */
2114
2115 if ((d__1 = t[j + j * t_dim1], abs(d__1)) < btol) {
2116 t[j + j * t_dim1] = 0.;
2117
2118 /* Test 1a: Check for 2 consecutive small subdiagonals in A */
2119
2120 ilazr2 = false;
2121 if (! ilazro) {
2122 temp = (d__1 = h__[j + (j - 1) * h_dim1], abs(d__1));
2123 temp2 = (d__1 = h__[j + j * h_dim1], abs(d__1));
2124 tempr = std::max(temp,temp2);
2125 if (tempr < 1. && tempr != 0.) {
2126 temp /= tempr;
2127 temp2 /= tempr;
2128 }
2129 if (temp * (ascale * (d__1 = h__[j + 1 + j * h_dim1], abs(
2130 d__1))) <= temp2 * (ascale * atol)) {
2131 ilazr2 = true;
2132 }
2133 }
2134
2135 /* If both tests pass (1 & 2), i.e., the leading diagonal */
2136 /* element of B in the block is zero, split a 1x1 block off */
2137 /* at the top. (I.e., at the J-th row/column) The leading */
2138 /* diagonal element of the remainder can also be zero, so */
2139 /* this may have to be done repeatedly. */
2140
2141 if (ilazro || ilazr2) {
2142 i__3 = ilast - 1;
2143 for (jch = j; jch <= i__3; ++jch) {
2144 temp = h__[jch + jch * h_dim1];
2145 dlartg_(&temp, &h__[jch + 1 + jch * h_dim1], &c__, &s,
2146 &h__[jch + jch * h_dim1]);
2147 h__[jch + 1 + jch * h_dim1] = 0.;
2148 i__4 = ilastm - jch;
2149 drot_(&i__4, &h__[jch + (jch + 1) * h_dim1], ldh, &
2150 h__[jch + 1 + (jch + 1) * h_dim1], ldh, &c__,
2151 &s);
2152 i__4 = ilastm - jch;
2153 drot_(&i__4, &t[jch + (jch + 1) * t_dim1], ldt, &t[
2154 jch + 1 + (jch + 1) * t_dim1], ldt, &c__, &s);
2155 if (ilq) {
2156 drot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
2157 * q_dim1 + 1], &c__1, &c__, &s);
2158 }
2159 if (ilazr2) {
2160 h__[jch + (jch - 1) * h_dim1] *= c__;
2161 }
2162 ilazr2 = false;
2163 if ((d__1 = t[jch + 1 + (jch + 1) * t_dim1], abs(d__1)
2164 ) >= btol) {
2165 if (jch + 1 >= ilast) {
2166 goto L80;
2167 } else {
2168 ifirst = jch + 1;
2169 goto L110;
2170 }
2171 }
2172 t[jch + 1 + (jch + 1) * t_dim1] = 0.;
2173 /* L40: */
2174 }
2175 goto L70;
2176 } else {
2177
2178 /* Only test 2 passed -- chase the zero to T(ILAST,ILAST) */
2179 /* Then process as in the case T(ILAST,ILAST)=0 */
2180
2181 i__3 = ilast - 1;
2182 for (jch = j; jch <= i__3; ++jch) {
2183 temp = t[jch + (jch + 1) * t_dim1];
2184 dlartg_(&temp, &t[jch + 1 + (jch + 1) * t_dim1], &c__,
2185 &s, &t[jch + (jch + 1) * t_dim1]);
2186 t[jch + 1 + (jch + 1) * t_dim1] = 0.;
2187 if (jch < ilastm - 1) {
2188 i__4 = ilastm - jch - 1;
2189 drot_(&i__4, &t[jch + (jch + 2) * t_dim1], ldt, &
2190 t[jch + 1 + (jch + 2) * t_dim1], ldt, &
2191 c__, &s);
2192 }
2193 i__4 = ilastm - jch + 2;
2194 drot_(&i__4, &h__[jch + (jch - 1) * h_dim1], ldh, &
2195 h__[jch + 1 + (jch - 1) * h_dim1], ldh, &c__,
2196 &s);
2197 if (ilq) {
2198 drot_(n, &q[jch * q_dim1 + 1], &c__1, &q[(jch + 1)
2199 * q_dim1 + 1], &c__1, &c__, &s);
2200 }
2201 temp = h__[jch + 1 + jch * h_dim1];
2202 dlartg_(&temp, &h__[jch + 1 + (jch - 1) * h_dim1], &
2203 c__, &s, &h__[jch + 1 + jch * h_dim1]);
2204 h__[jch + 1 + (jch - 1) * h_dim1] = 0.;
2205 i__4 = jch + 1 - ifrstm;
2206 drot_(&i__4, &h__[ifrstm + jch * h_dim1], &c__1, &h__[
2207 ifrstm + (jch - 1) * h_dim1], &c__1, &c__, &s)
2208 ;
2209 i__4 = jch - ifrstm;
2210 drot_(&i__4, &t[ifrstm + jch * t_dim1], &c__1, &t[
2211 ifrstm + (jch - 1) * t_dim1], &c__1, &c__, &s)
2212 ;
2213 if (ilz) {
2214 drot_(n, &z__[jch * z_dim1 + 1], &c__1, &z__[(jch
2215 - 1) * z_dim1 + 1], &c__1, &c__, &s);
2216 }
2217 /* L50: */
2218 }
2219 goto L70;
2220 }
2221 } else if (ilazro) {
2222
2223 /* Only test 1 passed -- work on J:ILAST */
2224
2225 ifirst = j;
2226 goto L110;
2227 }
2228
2229 /* Neither test passed -- try next J */
2230
2231 /* L60: */
2232 }
2233
2234 /* (Drop-through is "impossible") */
2235
2236 *info = *n + 1;
2237 goto L420;
2238
2239 /* T(ILAST,ILAST)=0 -- clear H(ILAST,ILAST-1) to split off a */
2240 /* 1x1 block. */
2241
2242 L70:
2243 temp = h__[ilast + ilast * h_dim1];
2244 dlartg_(&temp, &h__[ilast + (ilast - 1) * h_dim1], &c__, &s, &h__[
2245 ilast + ilast * h_dim1]);
2246 h__[ilast + (ilast - 1) * h_dim1] = 0.;
2247 i__2 = ilast - ifrstm;
2248 drot_(&i__2, &h__[ifrstm + ilast * h_dim1], &c__1, &h__[ifrstm + (
2249 ilast - 1) * h_dim1], &c__1, &c__, &s);
2250 i__2 = ilast - ifrstm;
2251 drot_(&i__2, &t[ifrstm + ilast * t_dim1], &c__1, &t[ifrstm + (ilast -
2252 1) * t_dim1], &c__1, &c__, &s);
2253 if (ilz) {
2254 drot_(n, &z__[ilast * z_dim1 + 1], &c__1, &z__[(ilast - 1) *
2255 z_dim1 + 1], &c__1, &c__, &s);
2256 }
2257
2258 /* H(ILAST,ILAST-1)=0 -- Standardize B, set ALPHAR, ALPHAI, */
2259 /* and BETA */
2260
2261 L80:
2262 if (t[ilast + ilast * t_dim1] < 0.) {
2263 if (ilschr) {
2264 i__2 = ilast;
2265 for (j = ifrstm; j <= i__2; ++j) {
2266 h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
2267 t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
2268 /* L90: */
2269 }
2270 } else {
2271 h__[ilast + ilast * h_dim1] = -h__[ilast + ilast * h_dim1];
2272 t[ilast + ilast * t_dim1] = -t[ilast + ilast * t_dim1];
2273 }
2274 if (ilz) {
2275 i__2 = *n;
2276 for (j = 1; j <= i__2; ++j) {
2277 z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
2278 /* L100: */
2279 }
2280 }
2281 }
2282 alphar[ilast] = h__[ilast + ilast * h_dim1];
2283 alphai[ilast] = 0.;
2284 beta[ilast] = t[ilast + ilast * t_dim1];
2285
2286 /* Go to next block -- exit if finished. */
2287
2288 --ilast;
2289 if (ilast < *ilo) {
2290 goto L380;
2291 }
2292
2293 /* Reset counters */
2294
2295 iiter = 0;
2296 eshift = 0.;
2297 if (! ilschr) {
2298 ilastm = ilast;
2299 if (ifrstm > ilast) {
2300 ifrstm = *ilo;
2301 }
2302 }
2303 goto L350;
2304
2305 /* QZ step */
2306
2307 /* This iteration only involves rows/columns IFIRST:ILAST. We */
2308 /* assume IFIRST < ILAST, and that the diagonal of B is non-zero. */
2309
2310 L110:
2311 ++iiter;
2312 if (! ilschr) {
2313 ifrstm = ifirst;
2314 }
2315
2316 /* Compute single shifts. */
2317
2318 /* At this point, IFIRST < ILAST, and the diagonal elements of */
2319 /* T(IFIRST:ILAST,IFIRST,ILAST) are larger than BTOL (in */
2320 /* magnitude) */
2321
2322 if (iiter / 10 * 10 == iiter) {
2323
2324 /* Exceptional shift. Chosen for no particularly good reason. */
2325 /* (Single shift only.) */
2326
2327 if ((double) maxit * safmin * (d__1 = h__[ilast - 1 + ilast *
2328 h_dim1], abs(d__1)) < (d__2 = t[ilast - 1 + (ilast - 1) *
2329 t_dim1], abs(d__2))) {
2330 eshift += h__[ilast - 1 + ilast * h_dim1] / t[ilast - 1 + (
2331 ilast - 1) * t_dim1];
2332 } else {
2333 eshift += 1. / (safmin * (double) maxit);
2334 }
2335 s1 = 1.;
2336 wr = eshift;
2337
2338 } else {
2339
2340 /* Shifts based on the generalized eigenvalues of the */
2341 /* bottom-right 2x2 block of A and B. The first eigenvalue */
2342 /* returned by DLAG2 is the Wilkinson shift (AEP p.512), */
2343
2344 d__1 = safmin * 100.;
2345 dlag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
2346 + (ilast - 1) * t_dim1], ldt, &d__1, &s1, &s2, &wr, &wr2,
2347 &wi);
2348
2349 /* Computing MAX */
2350 /* Computing MAX */
2351 d__3 = 1., d__4 = abs(wr), d__3 = std::max(d__3,d__4), d__4 = abs(wi);
2352 d__1 = s1, d__2 = safmin * std::max(d__3,d__4);
2353 temp = std::max(d__1,d__2);
2354 if (wi != 0.) {
2355 goto L200;
2356 }
2357 }
2358
2359 /* Fiddle with shift to avoid overflow */
2360
2361 temp = std::min(ascale,1.) * (safmax * .5);
2362 if (s1 > temp) {
2363 scale = temp / s1;
2364 } else {
2365 scale = 1.;
2366 }
2367
2368 temp = std::min(bscale,1.) * (safmax * .5);
2369 if (abs(wr) > temp) {
2370 /* Computing MIN */
2371 d__1 = scale, d__2 = temp / abs(wr);
2372 scale = std::min(d__1,d__2);
2373 }
2374 s1 = scale * s1;
2375 wr = scale * wr;
2376
2377 /* Now check for two consecutive small subdiagonals. */
2378
2379 i__2 = ifirst + 1;
2380 for (j = ilast - 1; j >= i__2; --j) {
2381 istart = j;
2382 temp = (d__1 = s1 * h__[j + (j - 1) * h_dim1], abs(d__1));
2383 temp2 = (d__1 = s1 * h__[j + j * h_dim1] - wr * t[j + j * t_dim1],
2384 abs(d__1));
2385 tempr = std::max(temp,temp2);
2386 if (tempr < 1. && tempr != 0.) {
2387 temp /= tempr;
2388 temp2 /= tempr;
2389 }
2390 if ((d__1 = ascale * h__[j + 1 + j * h_dim1] * temp, abs(d__1)) <=
2391 ascale * atol * temp2) {
2392 goto L130;
2393 }
2394 /* L120: */
2395 }
2396
2397 istart = ifirst;
2398 L130:
2399
2400 /* Do an implicit single-shift QZ sweep. */
2401
2402 /* Initial Q */
2403
2404 temp = s1 * h__[istart + istart * h_dim1] - wr * t[istart + istart *
2405 t_dim1];
2406 temp2 = s1 * h__[istart + 1 + istart * h_dim1];
2407 dlartg_(&temp, &temp2, &c__, &s, &tempr);
2408
2409 /* Sweep */
2410
2411 i__2 = ilast - 1;
2412 for (j = istart; j <= i__2; ++j) {
2413 if (j > istart) {
2414 temp = h__[j + (j - 1) * h_dim1];
2415 dlartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[
2416 j + (j - 1) * h_dim1]);
2417 h__[j + 1 + (j - 1) * h_dim1] = 0.;
2418 }
2419
2420 i__3 = ilastm;
2421 for (jc = j; jc <= i__3; ++jc) {
2422 temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
2423 h_dim1];
2424 h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
2425 h__[j + 1 + jc * h_dim1];
2426 h__[j + jc * h_dim1] = temp;
2427 temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
2428 t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
2429 + 1 + jc * t_dim1];
2430 t[j + jc * t_dim1] = temp2;
2431 /* L140: */
2432 }
2433 if (ilq) {
2434 i__3 = *n;
2435 for (jr = 1; jr <= i__3; ++jr) {
2436 temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
2437 q_dim1];
2438 q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
2439 q[jr + (j + 1) * q_dim1];
2440 q[jr + j * q_dim1] = temp;
2441 /* L150: */
2442 }
2443 }
2444
2445 temp = t[j + 1 + (j + 1) * t_dim1];
2446 dlartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
2447 1) * t_dim1]);
2448 t[j + 1 + j * t_dim1] = 0.;
2449
2450 /* Computing MIN */
2451 i__4 = j + 2;
2452 i__3 = std::min(i__4,ilast);
2453 for (jr = ifrstm; jr <= i__3; ++jr) {
2454 temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
2455 h_dim1];
2456 h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
2457 h__[jr + j * h_dim1];
2458 h__[jr + (j + 1) * h_dim1] = temp;
2459 /* L160: */
2460 }
2461 i__3 = j;
2462 for (jr = ifrstm; jr <= i__3; ++jr) {
2463 temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
2464 ;
2465 t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
2466 jr + j * t_dim1];
2467 t[jr + (j + 1) * t_dim1] = temp;
2468 /* L170: */
2469 }
2470 if (ilz) {
2471 i__3 = *n;
2472 for (jr = 1; jr <= i__3; ++jr) {
2473 temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
2474 z_dim1];
2475 z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
2476 c__ * z__[jr + j * z_dim1];
2477 z__[jr + (j + 1) * z_dim1] = temp;
2478 /* L180: */
2479 }
2480 }
2481 /* L190: */
2482 }
2483
2484 goto L350;
2485
2486 /* Use Francis double-shift */
2487
2488 /* Note: the Francis double-shift should work with real shifts, */
2489 /* but only if the block is at least 3x3. */
2490 /* This code may break if this point is reached with */
2491 /* a 2x2 block with real eigenvalues. */
2492
2493 L200:
2494 if (ifirst + 1 == ilast) {
2495
2496 /* Special case -- 2x2 block with complex eigenvectors */
2497
2498 /* Step 1: Standardize, that is, rotate so that */
2499
2500 /* ( B11 0 ) */
2501 /* B = ( ) with B11 non-negative. */
2502 /* ( 0 B22 ) */
2503
2504 dlasv2_(&t[ilast - 1 + (ilast - 1) * t_dim1], &t[ilast - 1 +
2505 ilast * t_dim1], &t[ilast + ilast * t_dim1], &b22, &b11, &
2506 sr, &cr, &sl, &cl);
2507
2508 if (b11 < 0.) {
2509 cr = -cr;
2510 sr = -sr;
2511 b11 = -b11;
2512 b22 = -b22;
2513 }
2514
2515 i__2 = ilastm + 1 - ifirst;
2516 drot_(&i__2, &h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &h__[
2517 ilast + (ilast - 1) * h_dim1], ldh, &cl, &sl);
2518 i__2 = ilast + 1 - ifrstm;
2519 drot_(&i__2, &h__[ifrstm + (ilast - 1) * h_dim1], &c__1, &h__[
2520 ifrstm + ilast * h_dim1], &c__1, &cr, &sr);
2521
2522 if (ilast < ilastm) {
2523 i__2 = ilastm - ilast;
2524 drot_(&i__2, &t[ilast - 1 + (ilast + 1) * t_dim1], ldt, &t[
2525 ilast + (ilast + 1) * t_dim1], ldh, &cl, &sl);
2526 }
2527 if (ifrstm < ilast - 1) {
2528 i__2 = ifirst - ifrstm;
2529 drot_(&i__2, &t[ifrstm + (ilast - 1) * t_dim1], &c__1, &t[
2530 ifrstm + ilast * t_dim1], &c__1, &cr, &sr);
2531 }
2532
2533 if (ilq) {
2534 drot_(n, &q[(ilast - 1) * q_dim1 + 1], &c__1, &q[ilast *
2535 q_dim1 + 1], &c__1, &cl, &sl);
2536 }
2537 if (ilz) {
2538 drot_(n, &z__[(ilast - 1) * z_dim1 + 1], &c__1, &z__[ilast *
2539 z_dim1 + 1], &c__1, &cr, &sr);
2540 }
2541
2542 t[ilast - 1 + (ilast - 1) * t_dim1] = b11;
2543 t[ilast - 1 + ilast * t_dim1] = 0.;
2544 t[ilast + (ilast - 1) * t_dim1] = 0.;
2545 t[ilast + ilast * t_dim1] = b22;
2546
2547 /* If B22 is negative, negate column ILAST */
2548
2549 if (b22 < 0.) {
2550 i__2 = ilast;
2551 for (j = ifrstm; j <= i__2; ++j) {
2552 h__[j + ilast * h_dim1] = -h__[j + ilast * h_dim1];
2553 t[j + ilast * t_dim1] = -t[j + ilast * t_dim1];
2554 /* L210: */
2555 }
2556
2557 if (ilz) {
2558 i__2 = *n;
2559 for (j = 1; j <= i__2; ++j) {
2560 z__[j + ilast * z_dim1] = -z__[j + ilast * z_dim1];
2561 /* L220: */
2562 }
2563 }
2564 }
2565
2566 /* Step 2: Compute ALPHAR, ALPHAI, and BETA (see refs.) */
2567
2568 /* Recompute shift */
2569
2570 d__1 = safmin * 100.;
2571 dlag2_(&h__[ilast - 1 + (ilast - 1) * h_dim1], ldh, &t[ilast - 1
2572 + (ilast - 1) * t_dim1], ldt, &d__1, &s1, &temp, &wr, &
2573 temp2, &wi);
2574
2575 /* If standardization has perturbed the shift onto real line, */
2576 /* do another (real single-shift) QR step. */
2577
2578 if (wi == 0.) {
2579 goto L350;
2580 }
2581 s1inv = 1. / s1;
2582
2583 /* Do EISPACK (QZVAL) computation of alpha and beta */
2584
2585 a11 = h__[ilast - 1 + (ilast - 1) * h_dim1];
2586 a21 = h__[ilast + (ilast - 1) * h_dim1];
2587 a12 = h__[ilast - 1 + ilast * h_dim1];
2588 a22 = h__[ilast + ilast * h_dim1];
2589
2590 /* Compute complex Givens rotation on right */
2591 /* (Assume some element of C = (sA - wB) > unfl ) */
2592 /* __ */
2593 /* (sA - wB) ( CZ -SZ ) */
2594 /* ( SZ CZ ) */
2595
2596 c11r = s1 * a11 - wr * b11;
2597 c11i = -wi * b11;
2598 c12 = s1 * a12;
2599 c21 = s1 * a21;
2600 c22r = s1 * a22 - wr * b22;
2601 c22i = -wi * b22;
2602
2603 if (abs(c11r) + abs(c11i) + abs(c12) > abs(c21) + abs(c22r) + abs(
2604 c22i)) {
2605 t1 = dlapy3_(&c12, &c11r, &c11i);
2606 cz = c12 / t1;
2607 szr = -c11r / t1;
2608 szi = -c11i / t1;
2609 } else {
2610 cz = dlapy2_(&c22r, &c22i);
2611 if (cz <= safmin) {
2612 cz = 0.;
2613 szr = 1.;
2614 szi = 0.;
2615 } else {
2616 tempr = c22r / cz;
2617 tempi = c22i / cz;
2618 t1 = dlapy2_(&cz, &c21);
2619 cz /= t1;
2620 szr = -c21 * tempr / t1;
2621 szi = c21 * tempi / t1;
2622 }
2623 }
2624
2625 /* Compute Givens rotation on left */
2626
2627 /* ( CQ SQ ) */
2628 /* ( __ ) A or B */
2629 /* ( -SQ CQ ) */
2630
2631 an = abs(a11) + abs(a12) + abs(a21) + abs(a22);
2632 bn = abs(b11) + abs(b22);
2633 wabs = abs(wr) + abs(wi);
2634 if (s1 * an > wabs * bn) {
2635 cq = cz * b11;
2636 sqr = szr * b22;
2637 sqi = -szi * b22;
2638 } else {
2639 a1r = cz * a11 + szr * a12;
2640 a1i = szi * a12;
2641 a2r = cz * a21 + szr * a22;
2642 a2i = szi * a22;
2643 cq = dlapy2_(&a1r, &a1i);
2644 if (cq <= safmin) {
2645 cq = 0.;
2646 sqr = 1.;
2647 sqi = 0.;
2648 } else {
2649 tempr = a1r / cq;
2650 tempi = a1i / cq;
2651 sqr = tempr * a2r + tempi * a2i;
2652 sqi = tempi * a2r - tempr * a2i;
2653 }
2654 }
2655 t1 = dlapy3_(&cq, &sqr, &sqi);
2656 cq /= t1;
2657 sqr /= t1;
2658 sqi /= t1;
2659
2660 /* Compute diagonal elements of QBZ */
2661
2662 tempr = sqr * szr - sqi * szi;
2663 tempi = sqr * szi + sqi * szr;
2664 b1r = cq * cz * b11 + tempr * b22;
2665 b1i = tempi * b22;
2666 b1a = dlapy2_(&b1r, &b1i);
2667 b2r = cq * cz * b22 + tempr * b11;
2668 b2i = -tempi * b11;
2669 b2a = dlapy2_(&b2r, &b2i);
2670
2671 /* Normalize so beta > 0, and Im( alpha1 ) > 0 */
2672
2673 beta[ilast - 1] = b1a;
2674 beta[ilast] = b2a;
2675 alphar[ilast - 1] = wr * b1a * s1inv;
2676 alphai[ilast - 1] = wi * b1a * s1inv;
2677 alphar[ilast] = wr * b2a * s1inv;
2678 alphai[ilast] = -(wi * b2a) * s1inv;
2679
2680 /* Step 3: Go to next block -- exit if finished. */
2681
2682 ilast = ifirst - 1;
2683 if (ilast < *ilo) {
2684 goto L380;
2685 }
2686
2687 /* Reset counters */
2688
2689 iiter = 0;
2690 eshift = 0.;
2691 if (! ilschr) {
2692 ilastm = ilast;
2693 if (ifrstm > ilast) {
2694 ifrstm = *ilo;
2695 }
2696 }
2697 goto L350;
2698 } else {
2699
2700 /* Usual case: 3x3 or larger block, using Francis implicit */
2701 /* double-shift */
2702
2703 /* 2 */
2704 /* Eigenvalue equation is w - c w + d = 0, */
2705
2706 /* -1 2 -1 */
2707 /* so compute 1st column of (A B ) - c A B + d */
2708 /* using the formula in QZIT (from EISPACK) */
2709
2710 /* We assume that the block is at least 3x3 */
2711
2712 ad11 = ascale * h__[ilast - 1 + (ilast - 1) * h_dim1] / (bscale *
2713 t[ilast - 1 + (ilast - 1) * t_dim1]);
2714 ad21 = ascale * h__[ilast + (ilast - 1) * h_dim1] / (bscale * t[
2715 ilast - 1 + (ilast - 1) * t_dim1]);
2716 ad12 = ascale * h__[ilast - 1 + ilast * h_dim1] / (bscale * t[
2717 ilast + ilast * t_dim1]);
2718 ad22 = ascale * h__[ilast + ilast * h_dim1] / (bscale * t[ilast +
2719 ilast * t_dim1]);
2720 u12 = t[ilast - 1 + ilast * t_dim1] / t[ilast + ilast * t_dim1];
2721 ad11l = ascale * h__[ifirst + ifirst * h_dim1] / (bscale * t[
2722 ifirst + ifirst * t_dim1]);
2723 ad21l = ascale * h__[ifirst + 1 + ifirst * h_dim1] / (bscale * t[
2724 ifirst + ifirst * t_dim1]);
2725 ad12l = ascale * h__[ifirst + (ifirst + 1) * h_dim1] / (bscale *
2726 t[ifirst + 1 + (ifirst + 1) * t_dim1]);
2727 ad22l = ascale * h__[ifirst + 1 + (ifirst + 1) * h_dim1] / (
2728 bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
2729 ad32l = ascale * h__[ifirst + 2 + (ifirst + 1) * h_dim1] / (
2730 bscale * t[ifirst + 1 + (ifirst + 1) * t_dim1]);
2731 u12l = t[ifirst + (ifirst + 1) * t_dim1] / t[ifirst + 1 + (ifirst
2732 + 1) * t_dim1];
2733
2734 v[0] = (ad11 - ad11l) * (ad22 - ad11l) - ad12 * ad21 + ad21 * u12
2735 * ad11l + (ad12l - ad11l * u12l) * ad21l;
2736 v[1] = (ad22l - ad11l - ad21l * u12l - (ad11 - ad11l) - (ad22 -
2737 ad11l) + ad21 * u12) * ad21l;
2738 v[2] = ad32l * ad21l;
2739
2740 istart = ifirst;
2741
2742 dlarfg_(&c__3, v, &v[1], &c__1, &tau);
2743 v[0] = 1.;
2744
2745 /* Sweep */
2746
2747 i__2 = ilast - 2;
2748 for (j = istart; j <= i__2; ++j) {
2749
2750 /* All but last elements: use 3x3 Householder transforms. */
2751
2752 /* Zero (j-1)st column of A */
2753
2754 if (j > istart) {
2755 v[0] = h__[j + (j - 1) * h_dim1];
2756 v[1] = h__[j + 1 + (j - 1) * h_dim1];
2757 v[2] = h__[j + 2 + (j - 1) * h_dim1];
2758
2759 dlarfg_(&c__3, &h__[j + (j - 1) * h_dim1], &v[1], &c__1, &
2760 tau);
2761 v[0] = 1.;
2762 h__[j + 1 + (j - 1) * h_dim1] = 0.;
2763 h__[j + 2 + (j - 1) * h_dim1] = 0.;
2764 }
2765
2766 i__3 = ilastm;
2767 for (jc = j; jc <= i__3; ++jc) {
2768 temp = tau * (h__[j + jc * h_dim1] + v[1] * h__[j + 1 +
2769 jc * h_dim1] + v[2] * h__[j + 2 + jc * h_dim1]);
2770 h__[j + jc * h_dim1] -= temp;
2771 h__[j + 1 + jc * h_dim1] -= temp * v[1];
2772 h__[j + 2 + jc * h_dim1] -= temp * v[2];
2773 temp2 = tau * (t[j + jc * t_dim1] + v[1] * t[j + 1 + jc *
2774 t_dim1] + v[2] * t[j + 2 + jc * t_dim1]);
2775 t[j + jc * t_dim1] -= temp2;
2776 t[j + 1 + jc * t_dim1] -= temp2 * v[1];
2777 t[j + 2 + jc * t_dim1] -= temp2 * v[2];
2778 /* L230: */
2779 }
2780 if (ilq) {
2781 i__3 = *n;
2782 for (jr = 1; jr <= i__3; ++jr) {
2783 temp = tau * (q[jr + j * q_dim1] + v[1] * q[jr + (j +
2784 1) * q_dim1] + v[2] * q[jr + (j + 2) * q_dim1]
2785 );
2786 q[jr + j * q_dim1] -= temp;
2787 q[jr + (j + 1) * q_dim1] -= temp * v[1];
2788 q[jr + (j + 2) * q_dim1] -= temp * v[2];
2789 /* L240: */
2790 }
2791 }
2792
2793 /* Zero j-th column of B (see DLAGBC for details) */
2794
2795 /* Swap rows to pivot */
2796
2797 ilpivt = false;
2798 /* Computing MAX */
2799 d__3 = (d__1 = t[j + 1 + (j + 1) * t_dim1], abs(d__1)), d__4 =
2800 (d__2 = t[j + 1 + (j + 2) * t_dim1], abs(d__2));
2801 temp = std::max(d__3,d__4);
2802 /* Computing MAX */
2803 d__3 = (d__1 = t[j + 2 + (j + 1) * t_dim1], abs(d__1)), d__4 =
2804 (d__2 = t[j + 2 + (j + 2) * t_dim1], abs(d__2));
2805 temp2 = std::max(d__3,d__4);
2806 if (std::max(temp,temp2) < safmin) {
2807 scale = 0.;
2808 u1 = 1.;
2809 u2 = 0.;
2810 goto L250;
2811 } else if (temp >= temp2) {
2812 w11 = t[j + 1 + (j + 1) * t_dim1];
2813 w21 = t[j + 2 + (j + 1) * t_dim1];
2814 w12 = t[j + 1 + (j + 2) * t_dim1];
2815 w22 = t[j + 2 + (j + 2) * t_dim1];
2816 u1 = t[j + 1 + j * t_dim1];
2817 u2 = t[j + 2 + j * t_dim1];
2818 } else {
2819 w21 = t[j + 1 + (j + 1) * t_dim1];
2820 w11 = t[j + 2 + (j + 1) * t_dim1];
2821 w22 = t[j + 1 + (j + 2) * t_dim1];
2822 w12 = t[j + 2 + (j + 2) * t_dim1];
2823 u2 = t[j + 1 + j * t_dim1];
2824 u1 = t[j + 2 + j * t_dim1];
2825 }
2826
2827 /* Swap columns if nec. */
2828
2829 if (abs(w12) > abs(w11)) {
2830 ilpivt = true;
2831 temp = w12;
2832 temp2 = w22;
2833 w12 = w11;
2834 w22 = w21;
2835 w11 = temp;
2836 w21 = temp2;
2837 }
2838
2839 /* LU-factor */
2840
2841 temp = w21 / w11;
2842 u2 -= temp * u1;
2843 w22 -= temp * w12;
2844 w21 = 0.;
2845
2846 /* Compute SCALE */
2847
2848 scale = 1.;
2849 if (abs(w22) < safmin) {
2850 scale = 0.;
2851 u2 = 1.;
2852 u1 = -w12 / w11;
2853 goto L250;
2854 }
2855 if (abs(w22) < abs(u2)) {
2856 scale = (d__1 = w22 / u2, abs(d__1));
2857 }
2858 if (abs(w11) < abs(u1)) {
2859 /* Computing MIN */
2860 d__2 = scale, d__3 = (d__1 = w11 / u1, abs(d__1));
2861 scale = std::min(d__2,d__3);
2862 }
2863
2864 /* Solve */
2865
2866 u2 = scale * u2 / w22;
2867 u1 = (scale * u1 - w12 * u2) / w11;
2868
2869 L250:
2870 if (ilpivt) {
2871 temp = u2;
2872 u2 = u1;
2873 u1 = temp;
2874 }
2875
2876 /* Compute Householder Vector */
2877
2878 /* Computing 2nd power */
2879 d__1 = scale;
2880 /* Computing 2nd power */
2881 d__2 = u1;
2882 /* Computing 2nd power */
2883 d__3 = u2;
2884 t1 = sqrt(d__1 * d__1 + d__2 * d__2 + d__3 * d__3);
2885 tau = scale / t1 + 1.;
2886 vs = -1. / (scale + t1);
2887 v[0] = 1.;
2888 v[1] = vs * u1;
2889 v[2] = vs * u2;
2890
2891 /* Apply transformations from the right. */
2892
2893 /* Computing MIN */
2894 i__4 = j + 3;
2895 i__3 = std::min(i__4,ilast);
2896 for (jr = ifrstm; jr <= i__3; ++jr) {
2897 temp = tau * (h__[jr + j * h_dim1] + v[1] * h__[jr + (j +
2898 1) * h_dim1] + v[2] * h__[jr + (j + 2) * h_dim1]);
2899 h__[jr + j * h_dim1] -= temp;
2900 h__[jr + (j + 1) * h_dim1] -= temp * v[1];
2901 h__[jr + (j + 2) * h_dim1] -= temp * v[2];
2902 /* L260: */
2903 }
2904 i__3 = j + 2;
2905 for (jr = ifrstm; jr <= i__3; ++jr) {
2906 temp = tau * (t[jr + j * t_dim1] + v[1] * t[jr + (j + 1) *
2907 t_dim1] + v[2] * t[jr + (j + 2) * t_dim1]);
2908 t[jr + j * t_dim1] -= temp;
2909 t[jr + (j + 1) * t_dim1] -= temp * v[1];
2910 t[jr + (j + 2) * t_dim1] -= temp * v[2];
2911 /* L270: */
2912 }
2913 if (ilz) {
2914 i__3 = *n;
2915 for (jr = 1; jr <= i__3; ++jr) {
2916 temp = tau * (z__[jr + j * z_dim1] + v[1] * z__[jr + (
2917 j + 1) * z_dim1] + v[2] * z__[jr + (j + 2) *
2918 z_dim1]);
2919 z__[jr + j * z_dim1] -= temp;
2920 z__[jr + (j + 1) * z_dim1] -= temp * v[1];
2921 z__[jr + (j + 2) * z_dim1] -= temp * v[2];
2922 /* L280: */
2923 }
2924 }
2925 t[j + 1 + j * t_dim1] = 0.;
2926 t[j + 2 + j * t_dim1] = 0.;
2927 /* L290: */
2928 }
2929
2930 /* Last elements: Use Givens rotations */
2931
2932 /* Rotations from the left */
2933
2934 j = ilast - 1;
2935 temp = h__[j + (j - 1) * h_dim1];
2936 dlartg_(&temp, &h__[j + 1 + (j - 1) * h_dim1], &c__, &s, &h__[j +
2937 (j - 1) * h_dim1]);
2938 h__[j + 1 + (j - 1) * h_dim1] = 0.;
2939
2940 i__2 = ilastm;
2941 for (jc = j; jc <= i__2; ++jc) {
2942 temp = c__ * h__[j + jc * h_dim1] + s * h__[j + 1 + jc *
2943 h_dim1];
2944 h__[j + 1 + jc * h_dim1] = -s * h__[j + jc * h_dim1] + c__ *
2945 h__[j + 1 + jc * h_dim1];
2946 h__[j + jc * h_dim1] = temp;
2947 temp2 = c__ * t[j + jc * t_dim1] + s * t[j + 1 + jc * t_dim1];
2948 t[j + 1 + jc * t_dim1] = -s * t[j + jc * t_dim1] + c__ * t[j
2949 + 1 + jc * t_dim1];
2950 t[j + jc * t_dim1] = temp2;
2951 /* L300: */
2952 }
2953 if (ilq) {
2954 i__2 = *n;
2955 for (jr = 1; jr <= i__2; ++jr) {
2956 temp = c__ * q[jr + j * q_dim1] + s * q[jr + (j + 1) *
2957 q_dim1];
2958 q[jr + (j + 1) * q_dim1] = -s * q[jr + j * q_dim1] + c__ *
2959 q[jr + (j + 1) * q_dim1];
2960 q[jr + j * q_dim1] = temp;
2961 /* L310: */
2962 }
2963 }
2964
2965 /* Rotations from the right. */
2966
2967 temp = t[j + 1 + (j + 1) * t_dim1];
2968 dlartg_(&temp, &t[j + 1 + j * t_dim1], &c__, &s, &t[j + 1 + (j +
2969 1) * t_dim1]);
2970 t[j + 1 + j * t_dim1] = 0.;
2971
2972 i__2 = ilast;
2973 for (jr = ifrstm; jr <= i__2; ++jr) {
2974 temp = c__ * h__[jr + (j + 1) * h_dim1] + s * h__[jr + j *
2975 h_dim1];
2976 h__[jr + j * h_dim1] = -s * h__[jr + (j + 1) * h_dim1] + c__ *
2977 h__[jr + j * h_dim1];
2978 h__[jr + (j + 1) * h_dim1] = temp;
2979 /* L320: */
2980 }
2981 i__2 = ilast - 1;
2982 for (jr = ifrstm; jr <= i__2; ++jr) {
2983 temp = c__ * t[jr + (j + 1) * t_dim1] + s * t[jr + j * t_dim1]
2984 ;
2985 t[jr + j * t_dim1] = -s * t[jr + (j + 1) * t_dim1] + c__ * t[
2986 jr + j * t_dim1];
2987 t[jr + (j + 1) * t_dim1] = temp;
2988 /* L330: */
2989 }
2990 if (ilz) {
2991 i__2 = *n;
2992 for (jr = 1; jr <= i__2; ++jr) {
2993 temp = c__ * z__[jr + (j + 1) * z_dim1] + s * z__[jr + j *
2994 z_dim1];
2995 z__[jr + j * z_dim1] = -s * z__[jr + (j + 1) * z_dim1] +
2996 c__ * z__[jr + j * z_dim1];
2997 z__[jr + (j + 1) * z_dim1] = temp;
2998 /* L340: */
2999 }
3000 }
3001
3002 /* End of Double-Shift code */
3003
3004 }
3005
3006 goto L350;
3007
3008 /* End of iteration loop */
3009
3010 L350:
3011 /* L360: */
3012 ;
3013 }
3014
3015 /* Drop-through = non-convergence */
3016
3017 *info = ilast;
3018 goto L420;
3019
3020 /* Successful completion of all QZ steps */
3021
3022 L380:
3023
3024 /* Set Eigenvalues 1:ILO-1 */
3025
3026 i__1 = *ilo - 1;
3027 for (j = 1; j <= i__1; ++j) {
3028 if (t[j + j * t_dim1] < 0.) {
3029 if (ilschr) {
3030 i__2 = j;
3031 for (jr = 1; jr <= i__2; ++jr) {
3032 h__[jr + j * h_dim1] = -h__[jr + j * h_dim1];
3033 t[jr + j * t_dim1] = -t[jr + j * t_dim1];
3034 /* L390: */
3035 }
3036 } else {
3037 h__[j + j * h_dim1] = -h__[j + j * h_dim1];
3038 t[j + j * t_dim1] = -t[j + j * t_dim1];
3039 }
3040 if (ilz) {
3041 i__2 = *n;
3042 for (jr = 1; jr <= i__2; ++jr) {
3043 z__[jr + j * z_dim1] = -z__[jr + j * z_dim1];
3044 /* L400: */
3045 }
3046 }
3047 }
3048 alphar[j] = h__[j + j * h_dim1];
3049 alphai[j] = 0.;
3050 beta[j] = t[j + j * t_dim1];
3051 /* L410: */
3052 }
3053
3054 /* Normal Termination */
3055
3056 *info = 0;
3057
3058 /* Exit (other than argument error) -- return optimal workspace size */
3059
3060 L420:
3061 work[1] = (double) (*n);
3062 return 0;
3063
3064 /* End of DHGEQZ */
3065
3066 } /* dhgeqz_ */
3067
3068 /* Subroutine */ int dhsein_(const char *side, const char *eigsrc, const char *initv, bool *
3069 select, integer *n, double *h__, integer *ldh, double *wr,
3070 double *wi, double *vl, integer *ldvl, double *vr,
3071 integer *ldvr, integer *mm, integer *m, double *work, integer *
3072 ifaill, integer *ifailr, integer *info)
3073 {
3074 /* Table of constant values */
3075 static bool c_false = false;
3076 static bool c_true = true;
3077
3078 /* System generated locals */
3079 integer h_dim1, h_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
3080 i__2;
3081 double d__1, d__2;
3082
3083 /* Local variables */
3084 integer i__, k, kl, kr, kln, ksi;
3085 double wki;
3086 integer ksr;
3087 double ulp, wkr, eps3;
3088 bool pair;
3089 double unfl;
3090 integer iinfo;
3091 bool leftv, bothv;
3092 double hnorm;
3093 double bignum;
3094 bool noinit;
3095 integer ldwork;
3096 bool rightv, fromqr;
3097 double smlnum;
3098
3099
3100 /* -- LAPACK routine (version 3.1) -- */
3101 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
3102 /* November 2006 */
3103
3104 /* .. Scalar Arguments .. */
3105 /* .. */
3106 /* .. Array Arguments .. */
3107 /* .. */
3108
3109 /* Purpose */
3110 /* ======= */
3111
3112 /* DHSEIN uses inverse iteration to find specified right and/or left */
3113 /* eigenvectors of a real upper Hessenberg matrix H. */
3114
3115 /* The right eigenvector x and the left eigenvector y of the matrix H */
3116 /* corresponding to an eigenvalue w are defined by: */
3117
3118 /* H * x = w * x, y**h * H = w * y**h */
3119
3120 /* where y**h denotes the conjugate transpose of the vector y. */
3121
3122 /* Arguments */
3123 /* ========= */
3124
3125 /* SIDE (input) CHARACTER*1 */
3126 /* = 'R': compute right eigenvectors only; */
3127 /* = 'L': compute left eigenvectors only; */
3128 /* = 'B': compute both right and left eigenvectors. */
3129
3130 /* EIGSRC (input) CHARACTER*1 */
3131 /* Specifies the source of eigenvalues supplied in (WR,WI): */
3132 /* = 'Q': the eigenvalues were found using DHSEQR; thus, if */
3133 /* H has zero subdiagonal elements, and so is */
3134 /* block-triangular, then the j-th eigenvalue can be */
3135 /* assumed to be an eigenvalue of the block containing */
3136 /* the j-th row/column. This property allows DHSEIN to */
3137 /* perform inverse iteration on just one diagonal block. */
3138 /* = 'N': no assumptions are made on the correspondence */
3139 /* between eigenvalues and diagonal blocks. In this */
3140 /* case, DHSEIN must always perform inverse iteration */
3141 /* using the whole matrix H. */
3142
3143 /* INITV (input) CHARACTER*1 */
3144 /* = 'N': no initial vectors are supplied; */
3145 /* = 'U': user-supplied initial vectors are stored in the arrays */
3146 /* VL and/or VR. */
3147
3148 /* SELECT (input/output) LOGICAL array, dimension (N) */
3149 /* Specifies the eigenvectors to be computed. To select the */
3150 /* real eigenvector corresponding to a real eigenvalue WR(j), */
3151 /* SELECT(j) must be set to .TRUE.. To select the complex */
3152 /* eigenvector corresponding to a complex eigenvalue */
3153 /* (WR(j),WI(j)), with complex conjugate (WR(j+1),WI(j+1)), */
3154 /* either SELECT(j) or SELECT(j+1) or both must be set to */
3155 /* .TRUE.; then on exit SELECT(j) is .TRUE. and SELECT(j+1) is */
3156 /* .FALSE.. */
3157
3158 /* N (input) INTEGER */
3159 /* The order of the matrix H. N >= 0. */
3160
3161 /* H (input) DOUBLE PRECISION array, dimension (LDH,N) */
3162 /* The upper Hessenberg matrix H. */
3163
3164 /* LDH (input) INTEGER */
3165 /* The leading dimension of the array H. LDH >= max(1,N). */
3166
3167 /* WR (input/output) DOUBLE PRECISION array, dimension (N) */
3168 /* WI (input) DOUBLE PRECISION array, dimension (N) */
3169 /* On entry, the real and imaginary parts of the eigenvalues of */
3170 /* H; a complex conjugate pair of eigenvalues must be stored in */
3171 /* consecutive elements of WR and WI. */
3172 /* On exit, WR may have been altered since close eigenvalues */
3173 /* are perturbed slightly in searching for independent */
3174 /* eigenvectors. */
3175
3176 /* VL (input/output) DOUBLE PRECISION array, dimension (LDVL,MM) */
3177 /* On entry, if INITV = 'U' and SIDE = 'L' or 'B', VL must */
3178 /* contain starting vectors for the inverse iteration for the */
3179 /* left eigenvectors; the starting vector for each eigenvector */
3180 /* must be in the same column(s) in which the eigenvector will */
3181 /* be stored. */
3182 /* On exit, if SIDE = 'L' or 'B', the left eigenvectors */
3183 /* specified by SELECT will be stored consecutively in the */
3184 /* columns of VL, in the same order as their eigenvalues. A */
3185 /* complex eigenvector corresponding to a complex eigenvalue is */
3186 /* stored in two consecutive columns, the first holding the real */
3187 /* part and the second the imaginary part. */
3188 /* If SIDE = 'R', VL is not referenced. */
3189
3190 /* LDVL (input) INTEGER */
3191 /* The leading dimension of the array VL. */
3192 /* LDVL >= max(1,N) if SIDE = 'L' or 'B'; LDVL >= 1 otherwise. */
3193
3194 /* VR (input/output) DOUBLE PRECISION array, dimension (LDVR,MM) */
3195 /* On entry, if INITV = 'U' and SIDE = 'R' or 'B', VR must */
3196 /* contain starting vectors for the inverse iteration for the */
3197 /* right eigenvectors; the starting vector for each eigenvector */
3198 /* must be in the same column(s) in which the eigenvector will */
3199 /* be stored. */
3200 /* On exit, if SIDE = 'R' or 'B', the right eigenvectors */
3201 /* specified by SELECT will be stored consecutively in the */
3202 /* columns of VR, in the same order as their eigenvalues. A */
3203 /* complex eigenvector corresponding to a complex eigenvalue is */
3204 /* stored in two consecutive columns, the first holding the real */
3205 /* part and the second the imaginary part. */
3206 /* If SIDE = 'L', VR is not referenced. */
3207
3208 /* LDVR (input) INTEGER */
3209 /* The leading dimension of the array VR. */
3210 /* LDVR >= max(1,N) if SIDE = 'R' or 'B'; LDVR >= 1 otherwise. */
3211
3212 /* MM (input) INTEGER */
3213 /* The number of columns in the arrays VL and/or VR. MM >= M. */
3214
3215 /* M (output) INTEGER */
3216 /* The number of columns in the arrays VL and/or VR required to */
3217 /* store the eigenvectors; each selected real eigenvector */
3218 /* occupies one column and each selected complex eigenvector */
3219 /* occupies two columns. */
3220
3221 /* WORK (workspace) DOUBLE PRECISION array, dimension ((N+2)*N) */
3222
3223 /* IFAILL (output) INTEGER array, dimension (MM) */
3224 /* If SIDE = 'L' or 'B', IFAILL(i) = j > 0 if the left */
3225 /* eigenvector in the i-th column of VL (corresponding to the */
3226 /* eigenvalue w(j)) failed to converge; IFAILL(i) = 0 if the */
3227 /* eigenvector converged satisfactorily. If the i-th and (i+1)th */
3228 /* columns of VL hold a complex eigenvector, then IFAILL(i) and */
3229 /* IFAILL(i+1) are set to the same value. */
3230 /* If SIDE = 'R', IFAILL is not referenced. */
3231
3232 /* IFAILR (output) INTEGER array, dimension (MM) */
3233 /* If SIDE = 'R' or 'B', IFAILR(i) = j > 0 if the right */
3234 /* eigenvector in the i-th column of VR (corresponding to the */
3235 /* eigenvalue w(j)) failed to converge; IFAILR(i) = 0 if the */
3236 /* eigenvector converged satisfactorily. If the i-th and (i+1)th */
3237 /* columns of VR hold a complex eigenvector, then IFAILR(i) and */
3238 /* IFAILR(i+1) are set to the same value. */
3239 /* If SIDE = 'L', IFAILR is not referenced. */
3240
3241 /* INFO (output) INTEGER */
3242 /* = 0: successful exit */
3243 /* < 0: if INFO = -i, the i-th argument had an illegal value */
3244 /* > 0: if INFO = i, i is the number of eigenvectors which */
3245 /* failed to converge; see IFAILL and IFAILR for further */
3246 /* details. */
3247
3248 /* Further Details */
3249 /* =============== */
3250
3251 /* Each eigenvector is normalized so that the element of largest */
3252 /* magnitude has magnitude 1; here the magnitude of a complex number */
3253 /* (x,y) is taken to be |x|+|y|. */
3254
3255 /* ===================================================================== */
3256
3257 /* .. Parameters .. */
3258 /* .. */
3259 /* .. Local Scalars .. */
3260 /* .. */
3261 /* .. External Functions .. */
3262 /* .. */
3263 /* .. External Subroutines .. */
3264 /* .. */
3265 /* .. Intrinsic Functions .. */
3266 /* .. */
3267 /* .. Executable Statements .. */
3268
3269 /* Decode and test the input parameters. */
3270
3271 /* Parameter adjustments */
3272 --select;
3273 h_dim1 = *ldh;
3274 h_offset = 1 + h_dim1;
3275 h__ -= h_offset;
3276 --wr;
3277 --wi;
3278 vl_dim1 = *ldvl;
3279 vl_offset = 1 + vl_dim1;
3280 vl -= vl_offset;
3281 vr_dim1 = *ldvr;
3282 vr_offset = 1 + vr_dim1;
3283 vr -= vr_offset;
3284 --work;
3285 --ifaill;
3286 --ifailr;
3287
3288 /* Function Body */
3289 bothv = lsame_(side, "B");
3290 rightv = lsame_(side, "R") || bothv;
3291 leftv = lsame_(side, "L") || bothv;
3292
3293 fromqr = lsame_(eigsrc, "Q");
3294
3295 noinit = lsame_(initv, "N");
3296
3297 /* Set M to the number of columns required to store the selected */
3298 /* eigenvectors, and standardize the array SELECT. */
3299
3300 *m = 0;
3301 pair = false;
3302 i__1 = *n;
3303 for (k = 1; k <= i__1; ++k) {
3304 if (pair) {
3305 pair = false;
3306 select[k] = false;
3307 } else {
3308 if (wi[k] == 0.) {
3309 if (select[k]) {
3310 ++(*m);
3311 }
3312 } else {
3313 pair = true;
3314 if (select[k] || select[k + 1]) {
3315 select[k] = true;
3316 *m += 2;
3317 }
3318 }
3319 }
3320 /* L10: */
3321 }
3322
3323 *info = 0;
3324 if (! rightv && ! leftv) {
3325 *info = -1;
3326 } else if (! fromqr && ! lsame_(eigsrc, "N")) {
3327 *info = -2;
3328 } else if (! noinit && ! lsame_(initv, "U")) {
3329 *info = -3;
3330 } else if (*n < 0) {
3331 *info = -5;
3332 } else if (*ldh < std::max(1_integer,*n)) {
3333 *info = -7;
3334 } else if (*ldvl < 1 || leftv && *ldvl < *n) {
3335 *info = -11;
3336 } else if (*ldvr < 1 || rightv && *ldvr < *n) {
3337 *info = -13;
3338 } else if (*mm < *m) {
3339 *info = -14;
3340 }
3341 if (*info != 0) {
3342 i__1 = -(*info);
3343 xerbla_("DHSEIN", &i__1);
3344 return 0;
3345 }
3346
3347 /* Quick return if possible. */
3348
3349 if (*n == 0) {
3350 return 0;
3351 }
3352
3353 /* Set machine-dependent constants. */
3354
3355 unfl = dlamch_("Safe minimum");
3356 ulp = dlamch_("Precision");
3357 smlnum = unfl * (*n / ulp);
3358 bignum = (1. - ulp) / smlnum;
3359
3360 ldwork = *n + 1;
3361
3362 kl = 1;
3363 kln = 0;
3364 if (fromqr) {
3365 kr = 0;
3366 } else {
3367 kr = *n;
3368 }
3369 ksr = 1;
3370
3371 i__1 = *n;
3372 for (k = 1; k <= i__1; ++k) {
3373 if (select[k]) {
3374
3375 /* Compute eigenvector(s) corresponding to W(K). */
3376
3377 if (fromqr) {
3378
3379 /* If affiliation of eigenvalues is known, check whether */
3380 /* the matrix splits. */
3381
3382 /* Determine KL and KR such that 1 <= KL <= K <= KR <= N */
3383 /* and H(KL,KL-1) and H(KR+1,KR) are zero (or KL = 1 or */
3384 /* KR = N). */
3385
3386 /* Then inverse iteration can be performed with the */
3387 /* submatrix H(KL:N,KL:N) for a left eigenvector, and with */
3388 /* the submatrix H(1:KR,1:KR) for a right eigenvector. */
3389
3390 i__2 = kl + 1;
3391 for (i__ = k; i__ >= i__2; --i__) {
3392 if (h__[i__ + (i__ - 1) * h_dim1] == 0.) {
3393 goto L30;
3394 }
3395 /* L20: */
3396 }
3397 L30:
3398 kl = i__;
3399 if (k > kr) {
3400 i__2 = *n - 1;
3401 for (i__ = k; i__ <= i__2; ++i__) {
3402 if (h__[i__ + 1 + i__ * h_dim1] == 0.) {
3403 goto L50;
3404 }
3405 /* L40: */
3406 }
3407 L50:
3408 kr = i__;
3409 }
3410 }
3411
3412 if (kl != kln) {
3413 kln = kl;
3414
3415 /* Compute infinity-norm of submatrix H(KL:KR,KL:KR) if it */
3416 /* has not ben computed before. */
3417
3418 i__2 = kr - kl + 1;
3419 hnorm = dlanhs_("I", &i__2, &h__[kl + kl * h_dim1], ldh, &
3420 work[1]);
3421 if (hnorm > 0.) {
3422 eps3 = hnorm * ulp;
3423 } else {
3424 eps3 = smlnum;
3425 }
3426 }
3427
3428 /* Perturb eigenvalue if it is close to any previous */
3429 /* selected eigenvalues affiliated to the submatrix */
3430 /* H(KL:KR,KL:KR). Close roots are modified by EPS3. */
3431
3432 wkr = wr[k];
3433 wki = wi[k];
3434 L60:
3435 i__2 = kl;
3436 for (i__ = k - 1; i__ >= i__2; --i__) {
3437 if (select[i__] && (d__1 = wr[i__] - wkr, abs(d__1)) + (d__2 =
3438 wi[i__] - wki, abs(d__2)) < eps3) {
3439 wkr += eps3;
3440 goto L60;
3441 }
3442 /* L70: */
3443 }
3444 wr[k] = wkr;
3445
3446 pair = wki != 0.;
3447 if (pair) {
3448 ksi = ksr + 1;
3449 } else {
3450 ksi = ksr;
3451 }
3452 if (leftv) {
3453
3454 /* Compute left eigenvector. */
3455
3456 i__2 = *n - kl + 1;
3457 dlaein_(&c_false, &noinit, &i__2, &h__[kl + kl * h_dim1], ldh,
3458 &wkr, &wki, &vl[kl + ksr * vl_dim1], &vl[kl + ksi *
3459 vl_dim1], &work[1], &ldwork, &work[*n * *n + *n + 1],
3460 &eps3, &smlnum, &bignum, &iinfo);
3461 if (iinfo > 0) {
3462 if (pair) {
3463 *info += 2;
3464 } else {
3465 ++(*info);
3466 }
3467 ifaill[ksr] = k;
3468 ifaill[ksi] = k;
3469 } else {
3470 ifaill[ksr] = 0;
3471 ifaill[ksi] = 0;
3472 }
3473 i__2 = kl - 1;
3474 for (i__ = 1; i__ <= i__2; ++i__) {
3475 vl[i__ + ksr * vl_dim1] = 0.;
3476 /* L80: */
3477 }
3478 if (pair) {
3479 i__2 = kl - 1;
3480 for (i__ = 1; i__ <= i__2; ++i__) {
3481 vl[i__ + ksi * vl_dim1] = 0.;
3482 /* L90: */
3483 }
3484 }
3485 }
3486 if (rightv) {
3487
3488 /* Compute right eigenvector. */
3489
3490 dlaein_(&c_true, &noinit, &kr, &h__[h_offset], ldh, &wkr, &
3491 wki, &vr[ksr * vr_dim1 + 1], &vr[ksi * vr_dim1 + 1], &
3492 work[1], &ldwork, &work[*n * *n + *n + 1], &eps3, &
3493 smlnum, &bignum, &iinfo);
3494 if (iinfo > 0) {
3495 if (pair) {
3496 *info += 2;
3497 } else {
3498 ++(*info);
3499 }
3500 ifailr[ksr] = k;
3501 ifailr[ksi] = k;
3502 } else {
3503 ifailr[ksr] = 0;
3504 ifailr[ksi] = 0;
3505 }
3506 i__2 = *n;
3507 for (i__ = kr + 1; i__ <= i__2; ++i__) {
3508 vr[i__ + ksr * vr_dim1] = 0.;
3509 /* L100: */
3510 }
3511 if (pair) {
3512 i__2 = *n;
3513 for (i__ = kr + 1; i__ <= i__2; ++i__) {
3514 vr[i__ + ksi * vr_dim1] = 0.;
3515 /* L110: */
3516 }
3517 }
3518 }
3519
3520 if (pair) {
3521 ksr += 2;
3522 } else {
3523 ++ksr;
3524 }
3525 }
3526 /* L120: */
3527 }
3528
3529 return 0;
3530
3531 /* End of DHSEIN */
3532
3533 } /* dhsein_ */
3534
3535 /* Subroutine */ int dhseqr_(const char *job, const char *compz, integer *n, integer *ilo, integer *ihi, double *h__,
3536 integer *ldh, double *wr, double *wi, double *z__, integer *ldz, double *work,
3537 integer *lwork, integer *info)
3538 {
3539 /* Table of constant values */
3540 static double c_b11 = 0.;
3541 static double c_b12 = 1.;
3542 static integer c__12 = 12;
3543 static integer c__2 = 2;
3544 static integer c__49 = 49;
3545
3546 /* System generated locals */
3547 char *a__1[2];
3548 integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2[2], i__3;
3549 double d__1;
3550 char ch__1[3];
3551
3552 /* Local variables */
3553 integer i__;
3554 double hl[2401] /* was [49][49] */;
3555 integer kbot, nmin;
3556 bool initz;
3557 double workl[49];
3558 bool wantt, wantz;
3559 bool lquery;
3560
3561
3562 /* -- LAPACK driver routine (version 3.2) -- */
3563 /* Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. */
3564 /* November 2006 */
3565
3566 /* .. Scalar Arguments .. */
3567 /* .. */
3568 /* .. Array Arguments .. */
3569 /* .. */
3570 /* Purpose */
3571 /* ======= */
3572
3573 /* DHSEQR computes the eigenvalues of a Hessenberg matrix H */
3574 /* and, optionally, the matrices T and Z from the Schur decomposition */
3575 /* H = Z T Z**T, where T is an upper quasi-triangular matrix (the */
3576 /* Schur form), and Z is the orthogonal matrix of Schur vectors. */
3577
3578 /* Optionally Z may be postmultiplied into an input orthogonal */
3579 /* matrix Q so that this routine can give the Schur factorization */
3580 /* of a matrix A which has been reduced to the Hessenberg form H */
3581 /* by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T. */
3582
3583 /* Arguments */
3584 /* ========= */
3585
3586 /* JOB (input) CHARACTER*1 */
3587 /* = 'E': compute eigenvalues only; */
3588 /* = 'S': compute eigenvalues and the Schur form T. */
3589
3590 /* COMPZ (input) CHARACTER*1 */
3591 /* = 'N': no Schur vectors are computed; */
3592 /* = 'I': Z is initialized to the unit matrix and the matrix Z */
3593 /* of Schur vectors of H is returned; */
3594 /* = 'V': Z must contain an orthogonal matrix Q on entry, and */
3595 /* the product Q*Z is returned. */
3596
3597 /* N (input) INTEGER */
3598 /* The order of the matrix H. N .GE. 0. */
3599
3600 /* ILO (input) INTEGER */
3601 /* IHI (input) INTEGER */
3602 /* It is assumed that H is already upper triangular in rows */
3603 /* and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally */
3604 /* set by a previous call to DGEBAL, and then passed to DGEHRD */
3605 /* when the matrix output by DGEBAL is reduced to Hessenberg */
3606 /* form. Otherwise ILO and IHI should be set to 1 and N */
3607 /* respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N. */
3608 /* If N = 0, then ILO = 1 and IHI = 0. */
3609
3610 /* H (input/output) DOUBLE PRECISION array, dimension (LDH,N) */
3611 /* On entry, the upper Hessenberg matrix H. */
3612 /* On exit, if INFO = 0 and JOB = 'S', then H contains the */
3613 /* upper quasi-triangular matrix T from the Schur decomposition */
3614 /* (the Schur form); 2-by-2 diagonal blocks (corresponding to */
3615 /* complex conjugate pairs of eigenvalues) are returned in */
3616 /* standard form, with H(i,i) = H(i+1,i+1) and */
3617 /* H(i+1,i)*H(i,i+1).LT.0. If INFO = 0 and JOB = 'E', the */
3618 /* contents of H are unspecified on exit. (The output value of */
3619 /* H when INFO.GT.0 is given under the description of INFO */
3620 /* below.) */
3621
3622 /* Unlike earlier versions of DHSEQR, this subroutine may */
3623 /* explicitly H(i,j) = 0 for i.GT.j and j = 1, 2, ... ILO-1 */
3624 /* or j = IHI+1, IHI+2, ... N. */
3625
3626 /* LDH (input) INTEGER */
3627 /* The leading dimension of the array H. LDH .GE. max(1,N). */
3628
3629 /* WR (output) DOUBLE PRECISION array, dimension (N) */
3630 /* WI (output) DOUBLE PRECISION array, dimension (N) */
3631 /* The real and imaginary parts, respectively, of the computed */
3632 /* eigenvalues. If two eigenvalues are computed as a complex */
3633 /* conjugate pair, they are stored in consecutive elements of */
3634 /* WR and WI, say the i-th and (i+1)th, with WI(i) .GT. 0 and */
3635 /* WI(i+1) .LT. 0. If JOB = 'S', the eigenvalues are stored in */
3636 /* the same order as on the diagonal of the Schur form returned */
3637 /* in H, with WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 */
3638 /* diagonal block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and */
3639 /* WI(i+1) = -WI(i). */
3640
3641 /* Z (input/output) DOUBLE PRECISION array, dimension (LDZ,N) */
3642 /* If COMPZ = 'N', Z is not referenced. */
3643 /* If COMPZ = 'I', on entry Z need not be set and on exit, */
3644 /* if INFO = 0, Z contains the orthogonal matrix Z of the Schur */
3645 /* vectors of H. If COMPZ = 'V', on entry Z must contain an */
3646 /* N-by-N matrix Q, which is assumed to be equal to the unit */
3647 /* matrix except for the submatrix Z(ILO:IHI,ILO:IHI). On exit, */
3648 /* if INFO = 0, Z contains Q*Z. */
3649 /* Normally Q is the orthogonal matrix generated by DORGHR */
3650 /* after the call to DGEHRD which formed the Hessenberg matrix */
3651 /* H. (The output value of Z when INFO.GT.0 is given under */
3652 /* the description of INFO below.) */
3653
3654 /* LDZ (input) INTEGER */
3655 /* The leading dimension of the array Z. if COMPZ = 'I' or */
3656 /* COMPZ = 'V', then LDZ.GE.MAX(1,N). Otherwize, LDZ.GE.1. */
3657
3658 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK) */
3659 /* On exit, if INFO = 0, WORK(1) returns an estimate of */
3660 /* the optimal value for LWORK. */
3661
3662 /* LWORK (input) INTEGER */
3663 /* The dimension of the array WORK. LWORK .GE. max(1,N) */
3664 /* is sufficient and delivers very good and sometimes */
3665 /* optimal performance. However, LWORK as large as 11*N */
3666 /* may be required for optimal performance. A workspace */
3667 /* query is recommended to determine the optimal workspace */
3668 /* size. */
3669
3670 /* If LWORK = -1, then DHSEQR does a workspace query. */
3671 /* In this case, DHSEQR checks the input parameters and */
3672 /* estimates the optimal workspace size for the given */
3673 /* values of N, ILO and IHI. The estimate is returned */
3674 /* in WORK(1). No error message related to LWORK is */
3675 /* issued by XERBLA. Neither H nor Z are accessed. */
3676
3677
3678 /* INFO (output) INTEGER */
3679 /* = 0: successful exit */
3680 /* .LT. 0: if INFO = -i, the i-th argument had an illegal */
3681 /* value */
3682 /* .GT. 0: if INFO = i, DHSEQR failed to compute all of */
3683 /* the eigenvalues. Elements 1:ilo-1 and i+1:n of WR */
3684 /* and WI contain those eigenvalues which have been */
3685 /* successfully computed. (Failures are rare.) */
3686
3687 /* If INFO .GT. 0 and JOB = 'E', then on exit, the */
3688 /* remaining unconverged eigenvalues are the eigen- */
3689 /* values of the upper Hessenberg matrix rows and */
3690 /* columns ILO through INFO of the final, output */
3691 /* value of H. */
3692
3693 /* If INFO .GT. 0 and JOB = 'S', then on exit */
3694
3695 /* (*) (initial value of H)*U = U*(final value of H) */
3696
3697 /* where U is an orthogonal matrix. The final */
3698 /* value of H is upper Hessenberg and quasi-triangular */
3699 /* in rows and columns INFO+1 through IHI. */
3700
3701 /* If INFO .GT. 0 and COMPZ = 'V', then on exit */
3702
3703 /* (final value of Z) = (initial value of Z)*U */
3704
3705 /* where U is the orthogonal matrix in (*) (regard- */
3706 /* less of the value of JOB.) */
3707
3708 /* If INFO .GT. 0 and COMPZ = 'I', then on exit */
3709 /* (final value of Z) = U */
3710 /* where U is the orthogonal matrix in (*) (regard- */
3711 /* less of the value of JOB.) */
3712
3713 /* If INFO .GT. 0 and COMPZ = 'N', then Z is not */
3714 /* accessed. */
3715
3716 /* ================================================================ */
3717 /* Default values supplied by */
3718 /* ILAENV(ISPEC,'DHSEQR',JOB(:1)//COMPZ(:1),N,ILO,IHI,LWORK). */
3719 /* It is suggested that these defaults be adjusted in order */
3720 /* to attain best performance in each particular */
3721 /* computational environment. */
3722
3723 /* ISPEC=12: The DLAHQR vs DLAQR0 crossover point. */
3724 /* Default: 75. (Must be at least 11.) */
3725
3726 /* ISPEC=13: Recommended deflation window size. */
3727 /* This depends on ILO, IHI and NS. NS is the */
3728 /* number of simultaneous shifts returned */
3729 /* by ILAENV(ISPEC=15). (See ISPEC=15 below.) */
3730 /* The default for (IHI-ILO+1).LE.500 is NS. */
3731 /* The default for (IHI-ILO+1).GT.500 is 3*NS/2. */
3732
3733 /* ISPEC=14: Nibble crossover point. (See IPARMQ for */
3734 /* details.) Default: 14% of deflation window */
3735 /* size. */
3736
3737 /* ISPEC=15: Number of simultaneous shifts in a multishift */
3738 /* QR iteration. */
3739
3740 /* If IHI-ILO+1 is ... */
3741
3742 /* greater than ...but less ... the */
3743 /* or equal to ... than default is */
3744
3745 /* 1 30 NS = 2(+) */
3746 /* 30 60 NS = 4(+) */
3747 /* 60 150 NS = 10(+) */
3748 /* 150 590 NS = ** */
3749 /* 590 3000 NS = 64 */
3750 /* 3000 6000 NS = 128 */
3751 /* 6000 infinity NS = 256 */
3752
3753 /* (+) By default some or all matrices of this order */
3754 /* are passed to the implicit double shift routine */
3755 /* DLAHQR and this parameter is ignored. See */
3756 /* ISPEC=12 above and comments in IPARMQ for */
3757 /* details. */
3758
3759 /* (**) The asterisks (**) indicate an ad-hoc */
3760 /* function of N increasing from 10 to 64. */
3761
3762 /* ISPEC=16: Select structured matrix multiply. */
3763 /* If the number of simultaneous shifts (specified */
3764 /* by ISPEC=15) is less than 14, then the default */
3765 /* for ISPEC=16 is 0. Otherwise the default for */
3766 /* ISPEC=16 is 2. */
3767
3768 /* ================================================================ */
3769 /* Based on contributions by */
3770 /* Karen Braman and Ralph Byers, Department of Mathematics, */
3771 /* University of Kansas, USA */
3772
3773 /* ================================================================ */
3774 /* References: */
3775 /* K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
3776 /* Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */
3777 /* Performance, SIAM Journal of Matrix Analysis, volume 23, pages */
3778 /* 929--947, 2002. */
3779
3780 /* K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
3781 /* Algorithm Part II: Aggressive Early Deflation, SIAM Journal */
3782 /* of Matrix Analysis, volume 23, pages 948--973, 2002. */
3783
3784 /* ================================================================ */
3785 /* .. Parameters .. */
3786
3787 /* ==== Matrices of order NTINY or smaller must be processed by */
3788 /* . DLAHQR because of insufficient subdiagonal scratch space. */
3789 /* . (This is a hard limit.) ==== */
3790
3791 /* ==== NL allocates some local workspace to help small matrices */
3792 /* . through a rare DLAHQR failure. NL .GT. NTINY = 11 is */
3793 /* . required and NL .LE. NMIN = ILAENV(ISPEC=12,...) is recom- */
3794 /* . mended. (The default value of NMIN is 75.) Using NL = 49 */
3795 /* . allows up to six simultaneous shifts and a 16-by-16 */
3796 /* . deflation window. ==== */
3797 /* .. */
3798 /* .. Local Arrays .. */
3799 /* .. */
3800 /* .. Local Scalars .. */
3801 /* .. */
3802 /* .. External Functions .. */
3803 /* .. */
3804 /* .. External Subroutines .. */
3805 /* .. */
3806 /* .. Intrinsic Functions .. */
3807 /* .. */
3808 /* .. Executable Statements .. */
3809
3810 /* ==== Decode and check the input parameters. ==== */
3811
3812 /* Parameter adjustments */
3813 h_dim1 = *ldh;
3814 h_offset = 1 + h_dim1;
3815 h__ -= h_offset;
3816 --wr;
3817 --wi;
3818 z_dim1 = *ldz;
3819 z_offset = 1 + z_dim1;
3820 z__ -= z_offset;
3821 --work;
3822
3823 /* Function Body */
3824 wantt = lsame_(job, "S");
3825 initz = lsame_(compz, "I");
3826 wantz = initz || lsame_(compz, "V");
3827 work[1] = (double)std::max(1_integer,*n);
3828 lquery = *lwork == -1;
3829
3830 *info = 0;
3831 if (! lsame_(job, "E") && ! wantt) {
3832 *info = -1;
3833 } else if (! lsame_(compz, "N") && ! wantz) {
3834 *info = -2;
3835 } else if (*n < 0) {
3836 *info = -3;
3837 } else if (*ilo < 1 || *ilo >std::max(1_integer,*n)) {
3838 *info = -4;
3839 } else if (*ihi <std::min(*ilo,*n) || *ihi > *n) {
3840 *info = -5;
3841 } else if (*ldh <std::max(1_integer,*n)) {
3842 *info = -7;
3843 } else if (*ldz < 1 || wantz && *ldz <std::max(1_integer,*n)) {
3844 *info = -11;
3845 } else if (*lwork <std::max(1_integer,*n) && ! lquery) {
3846 *info = -13;
3847 }
3848
3849 if (*info != 0) {
3850
3851 /* ==== Quick return in case of invalid argument. ==== */
3852
3853 i__1 = -(*info);
3854 xerbla_("DHSEQR", &i__1);
3855 return 0;
3856
3857 } else if (*n == 0) {
3858
3859 /* ==== Quick return in case N = 0; nothing to do. ==== */
3860
3861 return 0;
3862
3863 } else if (lquery) {
3864
3865 /* ==== Quick return in case of a workspace query ==== */
3866
3867 dlaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], &wi[
3868 1], ilo, ihi, &z__[z_offset], ldz, &work[1], lwork, info);
3869 /* ==== Ensure reported workspace size is backward-compatible with */
3870 /* . previous LAPACK versions. ==== */
3871 /* Computing MAX */
3872 d__1 = (double)std::max(1_integer,*n);
3873 work[1] =std::max(d__1,work[1]);
3874 return 0;
3875
3876 } else {
3877
3878 /* ==== copy eigenvalues isolated by DGEBAL ==== */
3879
3880 i__1 = *ilo - 1;
3881 for (i__ = 1; i__ <= i__1; ++i__) {
3882 wr[i__] = h__[i__ + i__ * h_dim1];
3883 wi[i__] = 0.;
3884 /* L10: */
3885 }
3886 i__1 = *n;
3887 for (i__ = *ihi + 1; i__ <= i__1; ++i__) {
3888 wr[i__] = h__[i__ + i__ * h_dim1];
3889 wi[i__] = 0.;
3890 /* L20: */
3891 }
3892
3893 /* ==== Initialize Z, if requested ==== */
3894
3895 if (initz) {
3896 dlaset_("A", n, n, &c_b11, &c_b12, &z__[z_offset], ldz)
3897 ;
3898 }
3899
3900 /* ==== Quick return if possible ==== */
3901
3902 if (*ilo == *ihi) {
3903 wr[*ilo] = h__[*ilo + *ilo * h_dim1];
3904 wi[*ilo] = 0.;
3905 return 0;
3906 }
3907
3908 /* ==== DLAHQR/DLAQR0 crossover point ==== */
3909
3910 /* Writing concatenation */
3911 i__2[0] = 1, a__1[0] = const_cast<char *>(job);
3912 i__2[1] = 1, a__1[1] = const_cast<char *>(compz);
3913 s_cat(ch__1, a__1, i__2, &c__2, 2_integer);
3914 ch__1 [2] = '\0';
3915 nmin = ilaenv_(&c__12, "DHSEQR", ch__1, n, ilo, ihi, lwork);
3916 nmin =std::max(11_integer,nmin);
3917
3918 /* ==== DLAQR0 for big matrices; DLAHQR for small ones ==== */
3919
3920 if (*n > nmin) {
3921 dlaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1],
3922 &wi[1], ilo, ihi, &z__[z_offset], ldz, &work[1], lwork,
3923 info);
3924 } else {
3925
3926 /* ==== Small matrix ==== */
3927
3928 dlahqr_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1],
3929 &wi[1], ilo, ihi, &z__[z_offset], ldz, info);
3930
3931 if (*info > 0) {
3932
3933 /* ==== A rare DLAHQR failure! DLAQR0 sometimes succeeds */
3934 /* . when DLAHQR fails. ==== */
3935
3936 kbot = *info;
3937
3938 if (*n >= 49) {
3939
3940 /* ==== Larger matrices have enough subdiagonal scratch */
3941 /* . space to call DLAQR0 directly. ==== */
3942
3943 dlaqr0_(&wantt, &wantz, n, ilo, &kbot, &h__[h_offset],
3944 ldh, &wr[1], &wi[1], ilo, ihi, &z__[z_offset],
3945 ldz, &work[1], lwork, info);
3946
3947 } else {
3948
3949 /* ==== Tiny matrices don't have enough subdiagonal */
3950 /* . scratch space to benefit from DLAQR0. Hence, */
3951 /* . tiny matrices must be copied into a larger */
3952 /* . array before calling DLAQR0. ==== */
3953
3954 dlacpy_("A", n, n, &h__[h_offset], ldh, hl, &c__49);
3955 hl[*n + 1 + *n * 49 - 50] = 0.;
3956 i__1 = 49 - *n;
3957 dlaset_("A", &c__49, &i__1, &c_b11, &c_b11, &hl[(*n + 1) *
3958 49 - 49], &c__49);
3959 dlaqr0_(&wantt, &wantz, &c__49, ilo, &kbot, hl, &c__49, &
3960 wr[1], &wi[1], ilo, ihi, &z__[z_offset], ldz,
3961 workl, &c__49, info);
3962 if (wantt || *info != 0) {
3963 dlacpy_("A", n, n, hl, &c__49, &h__[h_offset], ldh);
3964 }
3965 }
3966 }
3967 }
3968
3969 /* ==== Clear out the trash, if necessary. ==== */
3970
3971 if ((wantt || *info != 0) && *n > 2) {
3972 i__1 = *n - 2;
3973 i__3 = *n - 2;
3974 dlaset_("L", &i__1, &i__3, &c_b11, &c_b11, &h__[h_dim1 + 3], ldh);
3975 }
3976
3977 /* ==== Ensure reported workspace size is backward-compatible with */
3978 /* . previous LAPACK versions. ==== */
3979
3980 /* Computing MAX */
3981 d__1 = (double)std::max(1_integer,*n);
3982 work[1] =std::max(d__1,work[1]);
3983 }
3984
3985 /* ==== End of DHSEQR ==== */
3986
3987 return 0;
3988 } /* dhseqr_ */
3989
3990 /* Subroutine */ bool disnan_(double *din)
3991 {
3992 /* System generated locals */
3993 bool ret_val;
3994
3995 /* Local variables */
3996
3997 /* -- LAPACK auxiliary routine (version 3.1) -- */
3998 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
3999 /* November 2006 */
4000
4001 /* .. Scalar Arguments .. */
4002 /* .. */
4003
4004 /* Purpose */
4005 /* ======= */
4006
4007 /* DISNAN returns .TRUE. if its argument is NaN, and .FALSE. */
4008 /* otherwise. To be replaced by the Fortran 2003 intrinsic in the */
4009 /* future. */
4010
4011 /* Arguments */
4012 /* ========= */
4013
4014 /* DIN (input) DOUBLE PRECISION */
4015 /* Input to test for NaN. */
4016
4017 /* ===================================================================== */
4018
4019 /* .. External Functions .. */
4020 /* .. */
4021 /* .. Executable Statements .. */
4022 ret_val = dlaisnan_(din, din);
4023 return ret_val;
4024 } /* disnan_ */
4025
4026 /* Subroutine */ int dopgtr_(const char *uplo, integer *n, double *ap,
4027 double *tau, double *q, integer *ldq, double *work,
4028 integer *info)
4029 {
4030 /* System generated locals */
4031 integer q_dim1, q_offset, i__1, i__2, i__3;
4032
4033 /* Local variables */
4034 integer i__, j, ij;
4035 integer iinfo;
4036 bool upper;
4037
4038
4039 /* -- LAPACK routine (version 3.1) -- */
4040 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
4041 /* November 2006 */
4042
4043 /* .. Scalar Arguments .. */
4044 /* .. */
4045 /* .. Array Arguments .. */
4046 /* .. */
4047
4048 /* Purpose */
4049 /* ======= */
4050
4051 /* DOPGTR generates a real orthogonal matrix Q which is defined as the */
4052 /* product of n-1 elementary reflectors H(i) of order n, as returned by */
4053 /* DSPTRD using packed storage: */
4054
4055 /* if UPLO = 'U', Q = H(n-1) . . . H(2) H(1), */
4056
4057 /* if UPLO = 'L', Q = H(1) H(2) . . . H(n-1). */
4058
4059 /* Arguments */
4060 /* ========= */
4061
4062 /* UPLO (input) CHARACTER*1 */
4063 /* = 'U': Upper triangular packed storage used in previous */
4064 /* call to DSPTRD; */
4065 /* = 'L': Lower triangular packed storage used in previous */
4066 /* call to DSPTRD. */
4067
4068 /* N (input) INTEGER */
4069 /* The order of the matrix Q. N >= 0. */
4070
4071 /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
4072 /* The vectors which define the elementary reflectors, as */
4073 /* returned by DSPTRD. */
4074
4075 /* TAU (input) DOUBLE PRECISION array, dimension (N-1) */
4076 /* TAU(i) must contain the scalar factor of the elementary */
4077 /* reflector H(i), as returned by DSPTRD. */
4078
4079 /* Q (output) DOUBLE PRECISION array, dimension (LDQ,N) */
4080 /* The N-by-N orthogonal matrix Q. */
4081
4082 /* LDQ (input) INTEGER */
4083 /* The leading dimension of the array Q. LDQ >= max(1,N). */
4084
4085 /* WORK (workspace) DOUBLE PRECISION array, dimension (N-1) */
4086
4087 /* INFO (output) INTEGER */
4088 /* = 0: successful exit */
4089 /* < 0: if INFO = -i, the i-th argument had an illegal value */
4090
4091 /* ===================================================================== */
4092
4093 /* .. Parameters .. */
4094 /* .. */
4095 /* .. Local Scalars .. */
4096 /* .. */
4097 /* .. External Functions .. */
4098 /* .. */
4099 /* .. External Subroutines .. */
4100 /* .. */
4101 /* .. Intrinsic Functions .. */
4102 /* .. */
4103 /* .. Executable Statements .. */
4104
4105 /* Test the input arguments */
4106
4107 /* Parameter adjustments */
4108 --ap;
4109 --tau;
4110 q_dim1 = *ldq;
4111 q_offset = 1 + q_dim1;
4112 q -= q_offset;
4113 --work;
4114
4115 /* Function Body */
4116 *info = 0;
4117 upper = lsame_(uplo, "U");
4118 if (! upper && ! lsame_(uplo, "L")) {
4119 *info = -1;
4120 } else if (*n < 0) {
4121 *info = -2;
4122 } else if (*ldq < std::max(1_integer,*n)) {
4123 *info = -6;
4124 }
4125 if (*info != 0) {
4126 i__1 = -(*info);
4127 xerbla_("DOPGTR", &i__1);
4128 return 0;
4129 }
4130
4131 /* Quick return if possible */
4132
4133 if (*n == 0) {
4134 return 0;
4135 }
4136
4137 if (upper) {
4138
4139 /* Q was determined by a call to DSPTRD with UPLO = 'U' */
4140
4141 /* Unpack the vectors which define the elementary reflectors and */
4142 /* set the last row and column of Q equal to those of the unit */
4143 /* matrix */
4144
4145 ij = 2;
4146 i__1 = *n - 1;
4147 for (j = 1; j <= i__1; ++j) {
4148 i__2 = j - 1;
4149 for (i__ = 1; i__ <= i__2; ++i__) {
4150 q[i__ + j * q_dim1] = ap[ij];
4151 ++ij;
4152 /* L10: */
4153 }
4154 ij += 2;
4155 q[*n + j * q_dim1] = 0.;
4156 /* L20: */
4157 }
4158 i__1 = *n - 1;
4159 for (i__ = 1; i__ <= i__1; ++i__) {
4160 q[i__ + *n * q_dim1] = 0.;
4161 /* L30: */
4162 }
4163 q[*n + *n * q_dim1] = 1.;
4164
4165 /* Generate Q(1:n-1,1:n-1) */
4166
4167 i__1 = *n - 1;
4168 i__2 = *n - 1;
4169 i__3 = *n - 1;
4170 dorg2l_(&i__1, &i__2, &i__3, &q[q_offset], ldq, &tau[1], &work[1], &
4171 iinfo);
4172
4173 } else {
4174
4175 /* Q was determined by a call to DSPTRD with UPLO = 'L'. */
4176
4177 /* Unpack the vectors which define the elementary reflectors and */
4178 /* set the first row and column of Q equal to those of the unit */
4179 /* matrix */
4180
4181 q[q_dim1 + 1] = 1.;
4182 i__1 = *n;
4183 for (i__ = 2; i__ <= i__1; ++i__) {
4184 q[i__ + q_dim1] = 0.;
4185 /* L40: */
4186 }
4187 ij = 3;
4188 i__1 = *n;
4189 for (j = 2; j <= i__1; ++j) {
4190 q[j * q_dim1 + 1] = 0.;
4191 i__2 = *n;
4192 for (i__ = j + 1; i__ <= i__2; ++i__) {
4193 q[i__ + j * q_dim1] = ap[ij];
4194 ++ij;
4195 /* L50: */
4196 }
4197 ij += 2;
4198 /* L60: */
4199 }
4200 if (*n > 1) {
4201
4202 /* Generate Q(2:n,2:n) */
4203
4204 i__1 = *n - 1;
4205 i__2 = *n - 1;
4206 i__3 = *n - 1;
4207 dorg2r_(&i__1, &i__2, &i__3, &q[(q_dim1 << 1) + 2], ldq, &tau[1],
4208 &work[1], &iinfo);
4209 }
4210 }
4211 return 0;
4212
4213 /* End of DOPGTR */
4214
4215 } /* dopgtr_ */
4216
4217 /* Subroutine */ int dopmtr_(const char *side, const char *uplo, const char *trans, integer *m,
4218 integer *n, double *ap, double *tau, double *c__, integer
4219 *ldc, double *work, integer *info)
4220 {
4221 /* Table of constant values */
4222 static integer c__1 = 1;
4223
4224 /* System generated locals */
4225 integer c_dim1, c_offset, i__1, i__2;
4226
4227 /* Local variables */
4228 integer i__, i1, i2, i3, ic, jc, ii, mi, ni, nq;
4229 double aii;
4230 bool left;
4231 bool upper;
4232 bool notran, forwrd;
4233
4234
4235 /* -- LAPACK routine (version 3.1) -- */
4236 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
4237 /* November 2006 */
4238
4239 /* .. Scalar Arguments .. */
4240 /* .. */
4241 /* .. Array Arguments .. */
4242 /* .. */
4243
4244 /* Purpose */
4245 /* ======= */
4246
4247 /* DOPMTR overwrites the general real M-by-N matrix C with */
4248
4249 /* SIDE = 'L' SIDE = 'R' */
4250 /* TRANS = 'N': Q * C C * Q */
4251 /* TRANS = 'T': Q**T * C C * Q**T */
4252
4253 /* where Q is a real orthogonal matrix of order nq, with nq = m if */
4254 /* SIDE = 'L' and nq = n if SIDE = 'R'. Q is defined as the product of */
4255 /* nq-1 elementary reflectors, as returned by DSPTRD using packed */
4256 /* storage: */
4257
4258 /* if UPLO = 'U', Q = H(nq-1) . . . H(2) H(1); */
4259
4260 /* if UPLO = 'L', Q = H(1) H(2) . . . H(nq-1). */
4261
4262 /* Arguments */
4263 /* ========= */
4264
4265 /* SIDE (input) CHARACTER*1 */
4266 /* = 'L': apply Q or Q**T from the Left; */
4267 /* = 'R': apply Q or Q**T from the Right. */
4268
4269 /* UPLO (input) CHARACTER*1 */
4270 /* = 'U': Upper triangular packed storage used in previous */
4271 /* call to DSPTRD; */
4272 /* = 'L': Lower triangular packed storage used in previous */
4273 /* call to DSPTRD. */
4274
4275 /* TRANS (input) CHARACTER*1 */
4276 /* = 'N': No transpose, apply Q; */
4277 /* = 'T': Transpose, apply Q**T. */
4278
4279 /* M (input) INTEGER */
4280 /* The number of rows of the matrix C. M >= 0. */
4281
4282 /* N (input) INTEGER */
4283 /* The number of columns of the matrix C. N >= 0. */
4284
4285 /* AP (input) DOUBLE PRECISION array, dimension */
4286 /* (M*(M+1)/2) if SIDE = 'L' */
4287 /* (N*(N+1)/2) if SIDE = 'R' */
4288 /* The vectors which define the elementary reflectors, as */
4289 /* returned by DSPTRD. AP is modified by the routine but */
4290 /* restored on exit. */
4291
4292 /* TAU (input) DOUBLE PRECISION array, dimension (M-1) if SIDE = 'L' */
4293 /* or (N-1) if SIDE = 'R' */
4294 /* TAU(i) must contain the scalar factor of the elementary */
4295 /* reflector H(i), as returned by DSPTRD. */
4296
4297 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
4298 /* On entry, the M-by-N matrix C. */
4299 /* On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */
4300
4301 /* LDC (input) INTEGER */
4302 /* The leading dimension of the array C. LDC >= max(1,M). */
4303
4304 /* WORK (workspace) DOUBLE PRECISION array, dimension */
4305 /* (N) if SIDE = 'L' */
4306 /* (M) if SIDE = 'R' */
4307
4308 /* INFO (output) INTEGER */
4309 /* = 0: successful exit */
4310 /* < 0: if INFO = -i, the i-th argument had an illegal value */
4311
4312 /* ===================================================================== */
4313
4314 /* .. Parameters .. */
4315 /* .. */
4316 /* .. Local Scalars .. */
4317 /* .. */
4318 /* .. External Functions .. */
4319 /* .. */
4320 /* .. External Subroutines .. */
4321 /* .. */
4322 /* .. Intrinsic Functions .. */
4323 /* .. */
4324 /* .. Executable Statements .. */
4325
4326 /* Test the input arguments */
4327
4328 /* Parameter adjustments */
4329 --ap;
4330 --tau;
4331 c_dim1 = *ldc;
4332 c_offset = 1 + c_dim1;
4333 c__ -= c_offset;
4334 --work;
4335
4336 /* Function Body */
4337 *info = 0;
4338 left = lsame_(side, "L");
4339 notran = lsame_(trans, "N");
4340 upper = lsame_(uplo, "U");
4341
4342 /* NQ is the order of Q */
4343
4344 if (left) {
4345 nq = *m;
4346 } else {
4347 nq = *n;
4348 }
4349 if (! left && ! lsame_(side, "R")) {
4350 *info = -1;
4351 } else if (! upper && ! lsame_(uplo, "L")) {
4352 *info = -2;
4353 } else if (! notran && ! lsame_(trans, "T")) {
4354 *info = -3;
4355 } else if (*m < 0) {
4356 *info = -4;
4357 } else if (*n < 0) {
4358 *info = -5;
4359 } else if (*ldc < std::max(1_integer,*m)) {
4360 *info = -9;
4361 }
4362 if (*info != 0) {
4363 i__1 = -(*info);
4364 xerbla_("DOPMTR", &i__1);
4365 return 0;
4366 }
4367
4368 /* Quick return if possible */
4369
4370 if (*m == 0 || *n == 0) {
4371 return 0;
4372 }
4373
4374 if (upper) {
4375
4376 /* Q was determined by a call to DSPTRD with UPLO = 'U' */
4377
4378 forwrd = left && notran || ! left && ! notran;
4379
4380 if (forwrd) {
4381 i1 = 1;
4382 i2 = nq - 1;
4383 i3 = 1;
4384 ii = 2;
4385 } else {
4386 i1 = nq - 1;
4387 i2 = 1;
4388 i3 = -1;
4389 ii = nq * (nq + 1) / 2 - 1;
4390 }
4391
4392 if (left) {
4393 ni = *n;
4394 } else {
4395 mi = *m;
4396 }
4397
4398 i__1 = i2;
4399 i__2 = i3;
4400 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
4401 if (left) {
4402
4403 /* H(i) is applied to C(1:i,1:n) */
4404
4405 mi = i__;
4406 } else {
4407
4408 /* H(i) is applied to C(1:m,1:i) */
4409
4410 ni = i__;
4411 }
4412
4413 /* Apply H(i) */
4414
4415 aii = ap[ii];
4416 ap[ii] = 1.;
4417 dlarf_(side, &mi, &ni, &ap[ii - i__ + 1], &c__1, &tau[i__], &c__[
4418 c_offset], ldc, &work[1]);
4419 ap[ii] = aii;
4420
4421 if (forwrd) {
4422 ii = ii + i__ + 2;
4423 } else {
4424 ii = ii - i__ - 1;
4425 }
4426 /* L10: */
4427 }
4428 } else {
4429
4430 /* Q was determined by a call to DSPTRD with UPLO = 'L'. */
4431
4432 forwrd = left && ! notran || ! left && notran;
4433
4434 if (forwrd) {
4435 i1 = 1;
4436 i2 = nq - 1;
4437 i3 = 1;
4438 ii = 2;
4439 } else {
4440 i1 = nq - 1;
4441 i2 = 1;
4442 i3 = -1;
4443 ii = nq * (nq + 1) / 2 - 1;
4444 }
4445
4446 if (left) {
4447 ni = *n;
4448 jc = 1;
4449 } else {
4450 mi = *m;
4451 ic = 1;
4452 }
4453
4454 i__2 = i2;
4455 i__1 = i3;
4456 for (i__ = i1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) {
4457 aii = ap[ii];
4458 ap[ii] = 1.;
4459 if (left) {
4460
4461 /* H(i) is applied to C(i+1:m,1:n) */
4462
4463 mi = *m - i__;
4464 ic = i__ + 1;
4465 } else {
4466
4467 /* H(i) is applied to C(1:m,i+1:n) */
4468
4469 ni = *n - i__;
4470 jc = i__ + 1;
4471 }
4472
4473 /* Apply H(i) */
4474
4475 dlarf_(side, &mi, &ni, &ap[ii], &c__1, &tau[i__], &c__[ic + jc *
4476 c_dim1], ldc, &work[1]);
4477 ap[ii] = aii;
4478
4479 if (forwrd) {
4480 ii = ii + nq - i__ + 1;
4481 } else {
4482 ii = ii - nq + i__ - 2;
4483 }
4484 /* L20: */
4485 }
4486 }
4487 return 0;
4488
4489 /* End of DOPMTR */
4490
4491 } /* dopmtr_ */
4492
4493 /* Subroutine */ int dorg2l_(integer *m, integer *n, integer *k, double *
4494 a, integer *lda, double *tau, double *work, integer *info)
4495 {
4496 /* Table of constant values */
4497 static integer c__1 = 1;
4498
4499 /* System generated locals */
4500 integer a_dim1, a_offset, i__1, i__2, i__3;
4501 double d__1;
4502
4503 /* Local variables */
4504 integer i__, j, l, ii;
4505
4506 /* -- LAPACK routine (version 3.1) -- */
4507 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
4508 /* November 2006 */
4509
4510 /* .. Scalar Arguments .. */
4511 /* .. */
4512 /* .. Array Arguments .. */
4513 /* .. */
4514
4515 /* Purpose */
4516 /* ======= */
4517
4518 /* DORG2L generates an m by n real matrix Q with orthonormal columns, */
4519 /* which is defined as the last n columns of a product of k elementary */
4520 /* reflectors of order m */
4521
4522 /* Q = H(k) . . . H(2) H(1) */
4523
4524 /* as returned by DGEQLF. */
4525
4526 /* Arguments */
4527 /* ========= */
4528
4529 /* M (input) INTEGER */
4530 /* The number of rows of the matrix Q. M >= 0. */
4531
4532 /* N (input) INTEGER */
4533 /* The number of columns of the matrix Q. M >= N >= 0. */
4534
4535 /* K (input) INTEGER */
4536 /* The number of elementary reflectors whose product defines the */
4537 /* matrix Q. N >= K >= 0. */
4538
4539 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
4540 /* On entry, the (n-k+i)-th column must contain the vector which */
4541 /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
4542 /* returned by DGEQLF in the last k columns of its array */
4543 /* argument A. */
4544 /* On exit, the m by n matrix Q. */
4545
4546 /* LDA (input) INTEGER */
4547 /* The first dimension of the array A. LDA >= max(1,M). */
4548
4549 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
4550 /* TAU(i) must contain the scalar factor of the elementary */
4551 /* reflector H(i), as returned by DGEQLF. */
4552
4553 /* WORK (workspace) DOUBLE PRECISION array, dimension (N) */
4554
4555 /* INFO (output) INTEGER */
4556 /* = 0: successful exit */
4557 /* < 0: if INFO = -i, the i-th argument has an illegal value */
4558
4559 /* ===================================================================== */
4560
4561 /* .. Parameters .. */
4562 /* .. */
4563 /* .. Local Scalars .. */
4564 /* .. */
4565 /* .. External Subroutines .. */
4566 /* .. */
4567 /* .. Intrinsic Functions .. */
4568 /* .. */
4569 /* .. Executable Statements .. */
4570
4571 /* Test the input arguments */
4572
4573 /* Parameter adjustments */
4574 a_dim1 = *lda;
4575 a_offset = 1 + a_dim1;
4576 a -= a_offset;
4577 --tau;
4578 --work;
4579
4580 /* Function Body */
4581 *info = 0;
4582 if (*m < 0) {
4583 *info = -1;
4584 } else if (*n < 0 || *n > *m) {
4585 *info = -2;
4586 } else if (*k < 0 || *k > *n) {
4587 *info = -3;
4588 } else if (*lda < std::max(1_integer,*m)) {
4589 *info = -5;
4590 }
4591 if (*info != 0) {
4592 i__1 = -(*info);
4593 xerbla_("DORG2L", &i__1);
4594 return 0;
4595 }
4596
4597 /* Quick return if possible */
4598
4599 if (*n <= 0) {
4600 return 0;
4601 }
4602
4603 /* Initialise columns 1:n-k to columns of the unit matrix */
4604
4605 i__1 = *n - *k;
4606 for (j = 1; j <= i__1; ++j) {
4607 i__2 = *m;
4608 for (l = 1; l <= i__2; ++l) {
4609 a[l + j * a_dim1] = 0.;
4610 /* L10: */
4611 }
4612 a[*m - *n + j + j * a_dim1] = 1.;
4613 /* L20: */
4614 }
4615
4616 i__1 = *k;
4617 for (i__ = 1; i__ <= i__1; ++i__) {
4618 ii = *n - *k + i__;
4619
4620 /* Apply H(i) to A(1:m-k+i,1:n-k+i) from the left */
4621
4622 a[*m - *n + ii + ii * a_dim1] = 1.;
4623 i__2 = *m - *n + ii;
4624 i__3 = ii - 1;
4625 dlarf_("Left", &i__2, &i__3, &a[ii * a_dim1 + 1], &c__1, &tau[i__], &
4626 a[a_offset], lda, &work[1]);
4627 i__2 = *m - *n + ii - 1;
4628 d__1 = -tau[i__];
4629 dscal_(&i__2, &d__1, &a[ii * a_dim1 + 1], &c__1);
4630 a[*m - *n + ii + ii * a_dim1] = 1. - tau[i__];
4631
4632 /* Set A(m-k+i+1:m,n-k+i) to zero */
4633
4634 i__2 = *m;
4635 for (l = *m - *n + ii + 1; l <= i__2; ++l) {
4636 a[l + ii * a_dim1] = 0.;
4637 /* L30: */
4638 }
4639 /* L40: */
4640 }
4641 return 0;
4642
4643 /* End of DORG2L */
4644
4645 } /* dorg2l_ */
4646
4647 /* Subroutine */ int dorg2r_(integer *m, integer *n, integer *k, double *
4648 a, integer *lda, double *tau, double *work, integer *info)
4649 {
4650 /* Table of constant values */
4651 static integer c__1 = 1;
4652
4653 /* System generated locals */
4654 integer a_dim1, a_offset, i__1, i__2;
4655 double d__1;
4656
4657 /* Local variables */
4658 integer i__, j, l;
4659
4660
4661 /* -- LAPACK routine (version 3.1) -- */
4662 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
4663 /* November 2006 */
4664
4665 /* .. Scalar Arguments .. */
4666 /* .. */
4667 /* .. Array Arguments .. */
4668 /* .. */
4669
4670 /* Purpose */
4671 /* ======= */
4672
4673 /* DORG2R generates an m by n real matrix Q with orthonormal columns, */
4674 /* which is defined as the first n columns of a product of k elementary */
4675 /* reflectors of order m */
4676
4677 /* Q = H(1) H(2) . . . H(k) */
4678
4679 /* as returned by DGEQRF. */
4680
4681 /* Arguments */
4682 /* ========= */
4683
4684 /* M (input) INTEGER */
4685 /* The number of rows of the matrix Q. M >= 0. */
4686
4687 /* N (input) INTEGER */
4688 /* The number of columns of the matrix Q. M >= N >= 0. */
4689
4690 /* K (input) INTEGER */
4691 /* The number of elementary reflectors whose product defines the */
4692 /* matrix Q. N >= K >= 0. */
4693
4694 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
4695 /* On entry, the i-th column must contain the vector which */
4696 /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
4697 /* returned by DGEQRF in the first k columns of its array */
4698 /* argument A. */
4699 /* On exit, the m-by-n matrix Q. */
4700
4701 /* LDA (input) INTEGER */
4702 /* The first dimension of the array A. LDA >= max(1,M). */
4703
4704 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
4705 /* TAU(i) must contain the scalar factor of the elementary */
4706 /* reflector H(i), as returned by DGEQRF. */
4707
4708 /* WORK (workspace) DOUBLE PRECISION array, dimension (N) */
4709
4710 /* INFO (output) INTEGER */
4711 /* = 0: successful exit */
4712 /* < 0: if INFO = -i, the i-th argument has an illegal value */
4713
4714 /* ===================================================================== */
4715
4716 /* .. Parameters .. */
4717 /* .. */
4718 /* .. Local Scalars .. */
4719 /* .. */
4720 /* .. External Subroutines .. */
4721 /* .. */
4722 /* .. Intrinsic Functions .. */
4723 /* .. */
4724 /* .. Executable Statements .. */
4725
4726 /* Test the input arguments */
4727
4728 /* Parameter adjustments */
4729 a_dim1 = *lda;
4730 a_offset = 1 + a_dim1;
4731 a -= a_offset;
4732 --tau;
4733 --work;
4734
4735 /* Function Body */
4736 *info = 0;
4737 if (*m < 0) {
4738 *info = -1;
4739 } else if (*n < 0 || *n > *m) {
4740 *info = -2;
4741 } else if (*k < 0 || *k > *n) {
4742 *info = -3;
4743 } else if (*lda < std::max(1_integer,*m)) {
4744 *info = -5;
4745 }
4746 if (*info != 0) {
4747 i__1 = -(*info);
4748 xerbla_("DORG2R", &i__1);
4749 return 0;
4750 }
4751
4752 /* Quick return if possible */
4753
4754 if (*n <= 0) {
4755 return 0;
4756 }
4757
4758 /* Initialise columns k+1:n to columns of the unit matrix */
4759
4760 i__1 = *n;
4761 for (j = *k + 1; j <= i__1; ++j) {
4762 i__2 = *m;
4763 for (l = 1; l <= i__2; ++l) {
4764 a[l + j * a_dim1] = 0.;
4765 /* L10: */
4766 }
4767 a[j + j * a_dim1] = 1.;
4768 /* L20: */
4769 }
4770
4771 for (i__ = *k; i__ >= 1; --i__) {
4772
4773 /* Apply H(i) to A(i:m,i:n) from the left */
4774
4775 if (i__ < *n) {
4776 a[i__ + i__ * a_dim1] = 1.;
4777 i__1 = *m - i__ + 1;
4778 i__2 = *n - i__;
4779 dlarf_("Left", &i__1, &i__2, &a[i__ + i__ * a_dim1], &c__1, &tau[
4780 i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]);
4781 }
4782 if (i__ < *m) {
4783 i__1 = *m - i__;
4784 d__1 = -tau[i__];
4785 dscal_(&i__1, &d__1, &a[i__ + 1 + i__ * a_dim1], &c__1);
4786 }
4787 a[i__ + i__ * a_dim1] = 1. - tau[i__];
4788
4789 /* Set A(1:i-1,i) to zero */
4790
4791 i__1 = i__ - 1;
4792 for (l = 1; l <= i__1; ++l) {
4793 a[l + i__ * a_dim1] = 0.;
4794 /* L30: */
4795 }
4796 /* L40: */
4797 }
4798 return 0;
4799
4800 /* End of DORG2R */
4801
4802 } /* dorg2r_ */
4803
4804 /* Subroutine */ int dorgbr_(const char *vect, integer *m, integer *n, integer *k,
4805 double *a, integer *lda, double *tau, double *work,
4806 integer *lwork, integer *info)
4807 {
4808 /* Table of constant values */
4809 static integer c__1 = 1;
4810 static integer c_n1 = -1;
4811
4812 /* System generated locals */
4813 integer a_dim1, a_offset, i__1, i__2, i__3;
4814
4815 /* Local variables */
4816 integer i__, j, nb, mn;
4817 integer iinfo;
4818 bool wantq;
4819 integer lwkopt;
4820 bool lquery;
4821
4822
4823 /* -- LAPACK routine (version 3.1) -- */
4824 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
4825 /* November 2006 */
4826
4827 /* .. Scalar Arguments .. */
4828 /* .. */
4829 /* .. Array Arguments .. */
4830 /* .. */
4831
4832 /* Purpose */
4833 /* ======= */
4834
4835 /* DORGBR generates one of the real orthogonal matrices Q or P**T */
4836 /* determined by DGEBRD when reducing a real matrix A to bidiagonal */
4837 /* form: A = Q * B * P**T. Q and P**T are defined as products of */
4838 /* elementary reflectors H(i) or G(i) respectively. */
4839
4840 /* If VECT = 'Q', A is assumed to have been an M-by-K matrix, and Q */
4841 /* is of order M: */
4842 /* if m >= k, Q = H(1) H(2) . . . H(k) and DORGBR returns the first n */
4843 /* columns of Q, where m >= n >= k; */
4844 /* if m < k, Q = H(1) H(2) . . . H(m-1) and DORGBR returns Q as an */
4845 /* M-by-M matrix. */
4846
4847 /* If VECT = 'P', A is assumed to have been a K-by-N matrix, and P**T */
4848 /* is of order N: */
4849 /* if k < n, P**T = G(k) . . . G(2) G(1) and DORGBR returns the first m */
4850 /* rows of P**T, where n >= m >= k; */
4851 /* if k >= n, P**T = G(n-1) . . . G(2) G(1) and DORGBR returns P**T as */
4852 /* an N-by-N matrix. */
4853
4854 /* Arguments */
4855 /* ========= */
4856
4857 /* VECT (input) CHARACTER*1 */
4858 /* Specifies whether the matrix Q or the matrix P**T is */
4859 /* required, as defined in the transformation applied by DGEBRD: */
4860 /* = 'Q': generate Q; */
4861 /* = 'P': generate P**T. */
4862
4863 /* M (input) INTEGER */
4864 /* The number of rows of the matrix Q or P**T to be returned. */
4865 /* M >= 0. */
4866
4867 /* N (input) INTEGER */
4868 /* The number of columns of the matrix Q or P**T to be returned. */
4869 /* N >= 0. */
4870 /* If VECT = 'Q', M >= N >= min(M,K); */
4871 /* if VECT = 'P', N >= M >= min(N,K). */
4872
4873 /* K (input) INTEGER */
4874 /* If VECT = 'Q', the number of columns in the original M-by-K */
4875 /* matrix reduced by DGEBRD. */
4876 /* If VECT = 'P', the number of rows in the original K-by-N */
4877 /* matrix reduced by DGEBRD. */
4878 /* K >= 0. */
4879
4880 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
4881 /* On entry, the vectors which define the elementary reflectors, */
4882 /* as returned by DGEBRD. */
4883 /* On exit, the M-by-N matrix Q or P**T. */
4884
4885 /* LDA (input) INTEGER */
4886 /* The leading dimension of the array A. LDA >= max(1,M). */
4887
4888 /* TAU (input) DOUBLE PRECISION array, dimension */
4889 /* (min(M,K)) if VECT = 'Q' */
4890 /* (min(N,K)) if VECT = 'P' */
4891 /* TAU(i) must contain the scalar factor of the elementary */
4892 /* reflector H(i) or G(i), which determines Q or P**T, as */
4893 /* returned by DGEBRD in its array argument TAUQ or TAUP. */
4894
4895 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
4896 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
4897
4898 /* LWORK (input) INTEGER */
4899 /* The dimension of the array WORK. LWORK >= max(1,min(M,N)). */
4900 /* For optimum performance LWORK >= min(M,N)*NB, where NB */
4901 /* is the optimal blocksize. */
4902
4903 /* If LWORK = -1, then a workspace query is assumed; the routine */
4904 /* only calculates the optimal size of the WORK array, returns */
4905 /* this value as the first entry of the WORK array, and no error */
4906 /* message related to LWORK is issued by XERBLA. */
4907
4908 /* INFO (output) INTEGER */
4909 /* = 0: successful exit */
4910 /* < 0: if INFO = -i, the i-th argument had an illegal value */
4911
4912 /* ===================================================================== */
4913
4914 /* .. Parameters .. */
4915 /* .. */
4916 /* .. Local Scalars .. */
4917 /* .. */
4918 /* .. External Functions .. */
4919 /* .. */
4920 /* .. External Subroutines .. */
4921 /* .. */
4922 /* .. Intrinsic Functions .. */
4923 /* .. */
4924 /* .. Executable Statements .. */
4925
4926 /* Test the input arguments */
4927
4928 /* Parameter adjustments */
4929 a_dim1 = *lda;
4930 a_offset = 1 + a_dim1;
4931 a -= a_offset;
4932 --tau;
4933 --work;
4934
4935 /* Function Body */
4936 *info = 0;
4937 wantq = lsame_(vect, "Q");
4938 mn = std::min(*m,*n);
4939 lquery = *lwork == -1;
4940 if (! wantq && ! lsame_(vect, "P")) {
4941 *info = -1;
4942 } else if (*m < 0) {
4943 *info = -2;
4944 } else if (*n < 0 || wantq && (*n > *m || *n < std::min(*m,*k)) || ! wantq && (
4945 *m > *n || *m < std::min(*n,*k))) {
4946 *info = -3;
4947 } else if (*k < 0) {
4948 *info = -4;
4949 } else if (*lda < std::max(1_integer,*m)) {
4950 *info = -6;
4951 } else if (*lwork < std::max(1_integer,mn) && ! lquery) {
4952 *info = -9;
4953 }
4954
4955 if (*info == 0) {
4956 if (wantq) {
4957 nb = ilaenv_(&c__1, "DORGQR", " ", m, n, k, &c_n1);
4958 } else {
4959 nb = ilaenv_(&c__1, "DORGLQ", " ", m, n, k, &c_n1);
4960 }
4961 lwkopt = std::max(1_integer,mn) * nb;
4962 work[1] = (double) lwkopt;
4963 }
4964
4965 if (*info != 0) {
4966 i__1 = -(*info);
4967 xerbla_("DORGBR", &i__1);
4968 return 0;
4969 } else if (lquery) {
4970 return 0;
4971 }
4972
4973 /* Quick return if possible */
4974
4975 if (*m == 0 || *n == 0) {
4976 work[1] = 1.;
4977 return 0;
4978 }
4979
4980 if (wantq) {
4981
4982 /* Form Q, determined by a call to DGEBRD to reduce an m-by-k */
4983 /* matrix */
4984
4985 if (*m >= *k) {
4986
4987 /* If m >= k, assume m >= n >= k */
4988
4989 dorgqr_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, &
4990 iinfo);
4991
4992 } else {
4993
4994 /* If m < k, assume m = n */
4995
4996 /* Shift the vectors which define the elementary reflectors one */
4997 /* column to the right, and set the first row and column of Q */
4998 /* to those of the unit matrix */
4999
5000 for (j = *m; j >= 2; --j) {
5001 a[j * a_dim1 + 1] = 0.;
5002 i__1 = *m;
5003 for (i__ = j + 1; i__ <= i__1; ++i__) {
5004 a[i__ + j * a_dim1] = a[i__ + (j - 1) * a_dim1];
5005 /* L10: */
5006 }
5007 /* L20: */
5008 }
5009 a[a_dim1 + 1] = 1.;
5010 i__1 = *m;
5011 for (i__ = 2; i__ <= i__1; ++i__) {
5012 a[i__ + a_dim1] = 0.;
5013 /* L30: */
5014 }
5015 if (*m > 1) {
5016
5017 /* Form Q(2:m,2:m) */
5018
5019 i__1 = *m - 1;
5020 i__2 = *m - 1;
5021 i__3 = *m - 1;
5022 dorgqr_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[
5023 1], &work[1], lwork, &iinfo);
5024 }
5025 }
5026 } else {
5027
5028 /* Form P', determined by a call to DGEBRD to reduce a k-by-n */
5029 /* matrix */
5030
5031 if (*k < *n) {
5032
5033 /* If k < n, assume k <= m <= n */
5034
5035 dorglq_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, &
5036 iinfo);
5037
5038 } else {
5039
5040 /* If k >= n, assume m = n */
5041
5042 /* Shift the vectors which define the elementary reflectors one */
5043 /* row downward, and set the first row and column of P' to */
5044 /* those of the unit matrix */
5045
5046 a[a_dim1 + 1] = 1.;
5047 i__1 = *n;
5048 for (i__ = 2; i__ <= i__1; ++i__) {
5049 a[i__ + a_dim1] = 0.;
5050 /* L40: */
5051 }
5052 i__1 = *n;
5053 for (j = 2; j <= i__1; ++j) {
5054 for (i__ = j - 1; i__ >= 2; --i__) {
5055 a[i__ + j * a_dim1] = a[i__ - 1 + j * a_dim1];
5056 /* L50: */
5057 }
5058 a[j * a_dim1 + 1] = 0.;
5059 /* L60: */
5060 }
5061 if (*n > 1) {
5062
5063 /* Form P'(2:n,2:n) */
5064
5065 i__1 = *n - 1;
5066 i__2 = *n - 1;
5067 i__3 = *n - 1;
5068 dorglq_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[
5069 1], &work[1], lwork, &iinfo);
5070 }
5071 }
5072 }
5073 work[1] = (double) lwkopt;
5074 return 0;
5075
5076 /* End of DORGBR */
5077
5078 } /* dorgbr_ */
5079
5080 /* Subroutine */ int dorghr_(integer *n, integer *ilo, integer *ihi,
5081 double *a, integer *lda, double *tau, double *work,
5082 integer *lwork, integer *info)
5083 {
5084 /* Table of constant values */
5085 static integer c__1 = 1;
5086 static integer c_n1 = -1;
5087
5088 /* System generated locals */
5089 integer a_dim1, a_offset, i__1, i__2;
5090
5091 /* Local variables */
5092 integer i__, j, nb, nh, iinfo;
5093 integer lwkopt;
5094 bool lquery;
5095
5096
5097 /* -- LAPACK routine (version 3.1) -- */
5098 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
5099 /* November 2006 */
5100
5101 /* .. Scalar Arguments .. */
5102 /* .. */
5103 /* .. Array Arguments .. */
5104 /* .. */
5105
5106 /* Purpose */
5107 /* ======= */
5108
5109 /* DORGHR generates a real orthogonal matrix Q which is defined as the */
5110 /* product of IHI-ILO elementary reflectors of order N, as returned by */
5111 /* DGEHRD: */
5112
5113 /* Q = H(ilo) H(ilo+1) . . . H(ihi-1). */
5114
5115 /* Arguments */
5116 /* ========= */
5117
5118 /* N (input) INTEGER */
5119 /* The order of the matrix Q. N >= 0. */
5120
5121 /* ILO (input) INTEGER */
5122 /* IHI (input) INTEGER */
5123 /* ILO and IHI must have the same values as in the previous call */
5124 /* of DGEHRD. Q is equal to the unit matrix except in the */
5125 /* submatrix Q(ilo+1:ihi,ilo+1:ihi). */
5126 /* 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. */
5127
5128 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
5129 /* On entry, the vectors which define the elementary reflectors, */
5130 /* as returned by DGEHRD. */
5131 /* On exit, the N-by-N orthogonal matrix Q. */
5132
5133 /* LDA (input) INTEGER */
5134 /* The leading dimension of the array A. LDA >= max(1,N). */
5135
5136 /* TAU (input) DOUBLE PRECISION array, dimension (N-1) */
5137 /* TAU(i) must contain the scalar factor of the elementary */
5138 /* reflector H(i), as returned by DGEHRD. */
5139
5140 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
5141 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
5142
5143 /* LWORK (input) INTEGER */
5144 /* The dimension of the array WORK. LWORK >= IHI-ILO. */
5145 /* For optimum performance LWORK >= (IHI-ILO)*NB, where NB is */
5146 /* the optimal blocksize. */
5147
5148 /* If LWORK = -1, then a workspace query is assumed; the routine */
5149 /* only calculates the optimal size of the WORK array, returns */
5150 /* this value as the first entry of the WORK array, and no error */
5151 /* message related to LWORK is issued by XERBLA. */
5152
5153 /* INFO (output) INTEGER */
5154 /* = 0: successful exit */
5155 /* < 0: if INFO = -i, the i-th argument had an illegal value */
5156
5157 /* ===================================================================== */
5158
5159 /* .. Parameters .. */
5160 /* .. */
5161 /* .. Local Scalars .. */
5162 /* .. */
5163 /* .. External Subroutines .. */
5164 /* .. */
5165 /* .. External Functions .. */
5166 /* .. */
5167 /* .. Intrinsic Functions .. */
5168 /* .. */
5169 /* .. Executable Statements .. */
5170
5171 /* Test the input arguments */
5172
5173 /* Parameter adjustments */
5174 a_dim1 = *lda;
5175 a_offset = 1 + a_dim1;
5176 a -= a_offset;
5177 --tau;
5178 --work;
5179
5180 /* Function Body */
5181 *info = 0;
5182 nh = *ihi - *ilo;
5183 lquery = *lwork == -1;
5184 if (*n < 0) {
5185 *info = -1;
5186 } else if (*ilo < 1 || *ilo > std::max(1_integer,*n)) {
5187 *info = -2;
5188 } else if (*ihi < std::min(*ilo,*n) || *ihi > *n) {
5189 *info = -3;
5190 } else if (*lda < std::max(1_integer,*n)) {
5191 *info = -5;
5192 } else if (*lwork < std::max(1_integer,nh) && ! lquery) {
5193 *info = -8;
5194 }
5195
5196 if (*info == 0) {
5197 nb = ilaenv_(&c__1, "DORGQR", " ", &nh, &nh, &nh, &c_n1);
5198 lwkopt = std::max(1_integer,nh) * nb;
5199 work[1] = (double) lwkopt;
5200 }
5201
5202 if (*info != 0) {
5203 i__1 = -(*info);
5204 xerbla_("DORGHR", &i__1);
5205 return 0;
5206 } else if (lquery) {
5207 return 0;
5208 }
5209
5210 /* Quick return if possible */
5211
5212 if (*n == 0) {
5213 work[1] = 1.;
5214 return 0;
5215 }
5216
5217 /* Shift the vectors which define the elementary reflectors one */
5218 /* column to the right, and set the first ilo and the last n-ihi */
5219 /* rows and columns to those of the unit matrix */
5220
5221 i__1 = *ilo + 1;
5222 for (j = *ihi; j >= i__1; --j) {
5223 i__2 = j - 1;
5224 for (i__ = 1; i__ <= i__2; ++i__) {
5225 a[i__ + j * a_dim1] = 0.;
5226 /* L10: */
5227 }
5228 i__2 = *ihi;
5229 for (i__ = j + 1; i__ <= i__2; ++i__) {
5230 a[i__ + j * a_dim1] = a[i__ + (j - 1) * a_dim1];
5231 /* L20: */
5232 }
5233 i__2 = *n;
5234 for (i__ = *ihi + 1; i__ <= i__2; ++i__) {
5235 a[i__ + j * a_dim1] = 0.;
5236 /* L30: */
5237 }
5238 /* L40: */
5239 }
5240 i__1 = *ilo;
5241 for (j = 1; j <= i__1; ++j) {
5242 i__2 = *n;
5243 for (i__ = 1; i__ <= i__2; ++i__) {
5244 a[i__ + j * a_dim1] = 0.;
5245 /* L50: */
5246 }
5247 a[j + j * a_dim1] = 1.;
5248 /* L60: */
5249 }
5250 i__1 = *n;
5251 for (j = *ihi + 1; j <= i__1; ++j) {
5252 i__2 = *n;
5253 for (i__ = 1; i__ <= i__2; ++i__) {
5254 a[i__ + j * a_dim1] = 0.;
5255 /* L70: */
5256 }
5257 a[j + j * a_dim1] = 1.;
5258 /* L80: */
5259 }
5260
5261 if (nh > 0) {
5262
5263 /* Generate Q(ilo+1:ihi,ilo+1:ihi) */
5264
5265 dorgqr_(&nh, &nh, &nh, &a[*ilo + 1 + (*ilo + 1) * a_dim1], lda, &tau[*
5266 ilo], &work[1], lwork, &iinfo);
5267 }
5268 work[1] = (double) lwkopt;
5269 return 0;
5270
5271 /* End of DORGHR */
5272
5273 } /* dorghr_ */
5274
5275 /* Subroutine */ int dorgl2_(integer *m, integer *n, integer *k, double *
5276 a, integer *lda, double *tau, double *work, integer *info)
5277 {
5278 /* System generated locals */
5279 integer a_dim1, a_offset, i__1, i__2;
5280 double d__1;
5281
5282 /* Local variables */
5283 integer i__, j, l;
5284
5285 /* -- LAPACK routine (version 3.1) -- */
5286 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
5287 /* November 2006 */
5288
5289 /* .. Scalar Arguments .. */
5290 /* .. */
5291 /* .. Array Arguments .. */
5292 /* .. */
5293
5294 /* Purpose */
5295 /* ======= */
5296
5297 /* DORGL2 generates an m by n real matrix Q with orthonormal rows, */
5298 /* which is defined as the first m rows of a product of k elementary */
5299 /* reflectors of order n */
5300
5301 /* Q = H(k) . . . H(2) H(1) */
5302
5303 /* as returned by DGELQF. */
5304
5305 /* Arguments */
5306 /* ========= */
5307
5308 /* M (input) INTEGER */
5309 /* The number of rows of the matrix Q. M >= 0. */
5310
5311 /* N (input) INTEGER */
5312 /* The number of columns of the matrix Q. N >= M. */
5313
5314 /* K (input) INTEGER */
5315 /* The number of elementary reflectors whose product defines the */
5316 /* matrix Q. M >= K >= 0. */
5317
5318 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
5319 /* On entry, the i-th row must contain the vector which defines */
5320 /* the elementary reflector H(i), for i = 1,2,...,k, as returned */
5321 /* by DGELQF in the first k rows of its array argument A. */
5322 /* On exit, the m-by-n matrix Q. */
5323
5324 /* LDA (input) INTEGER */
5325 /* The first dimension of the array A. LDA >= max(1,M). */
5326
5327 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
5328 /* TAU(i) must contain the scalar factor of the elementary */
5329 /* reflector H(i), as returned by DGELQF. */
5330
5331 /* WORK (workspace) DOUBLE PRECISION array, dimension (M) */
5332
5333 /* INFO (output) INTEGER */
5334 /* = 0: successful exit */
5335 /* < 0: if INFO = -i, the i-th argument has an illegal value */
5336
5337 /* ===================================================================== */
5338
5339 /* .. Parameters .. */
5340 /* .. */
5341 /* .. Local Scalars .. */
5342 /* .. */
5343 /* .. External Subroutines .. */
5344 /* .. */
5345 /* .. Intrinsic Functions .. */
5346 /* .. */
5347 /* .. Executable Statements .. */
5348
5349 /* Test the input arguments */
5350
5351 /* Parameter adjustments */
5352 a_dim1 = *lda;
5353 a_offset = 1 + a_dim1;
5354 a -= a_offset;
5355 --tau;
5356 --work;
5357
5358 /* Function Body */
5359 *info = 0;
5360 if (*m < 0) {
5361 *info = -1;
5362 } else if (*n < *m) {
5363 *info = -2;
5364 } else if (*k < 0 || *k > *m) {
5365 *info = -3;
5366 } else if (*lda < std::max(1_integer,*m)) {
5367 *info = -5;
5368 }
5369 if (*info != 0) {
5370 i__1 = -(*info);
5371 xerbla_("DORGL2", &i__1);
5372 return 0;
5373 }
5374
5375 /* Quick return if possible */
5376
5377 if (*m <= 0) {
5378 return 0;
5379 }
5380
5381 if (*k < *m) {
5382
5383 /* Initialise rows k+1:m to rows of the unit matrix */
5384
5385 i__1 = *n;
5386 for (j = 1; j <= i__1; ++j) {
5387 i__2 = *m;
5388 for (l = *k + 1; l <= i__2; ++l) {
5389 a[l + j * a_dim1] = 0.;
5390 /* L10: */
5391 }
5392 if (j > *k && j <= *m) {
5393 a[j + j * a_dim1] = 1.;
5394 }
5395 /* L20: */
5396 }
5397 }
5398
5399 for (i__ = *k; i__ >= 1; --i__) {
5400
5401 /* Apply H(i) to A(i:m,i:n) from the right */
5402
5403 if (i__ < *n) {
5404 if (i__ < *m) {
5405 a[i__ + i__ * a_dim1] = 1.;
5406 i__1 = *m - i__;
5407 i__2 = *n - i__ + 1;
5408 dlarf_("Right", &i__1, &i__2, &a[i__ + i__ * a_dim1], lda, &
5409 tau[i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
5410 }
5411 i__1 = *n - i__;
5412 d__1 = -tau[i__];
5413 dscal_(&i__1, &d__1, &a[i__ + (i__ + 1) * a_dim1], lda);
5414 }
5415 a[i__ + i__ * a_dim1] = 1. - tau[i__];
5416
5417 /* Set A(i,1:i-1) to zero */
5418
5419 i__1 = i__ - 1;
5420 for (l = 1; l <= i__1; ++l) {
5421 a[i__ + l * a_dim1] = 0.;
5422 /* L30: */
5423 }
5424 /* L40: */
5425 }
5426 return 0;
5427
5428 /* End of DORGL2 */
5429
5430 } /* dorgl2_ */
5431
5432 /* Subroutine */ int dorglq_(integer *m, integer *n, integer *k, double *
5433 a, integer *lda, double *tau, double *work, integer *lwork,
5434 integer *info)
5435 {
5436 /* Table of constant values */
5437 static integer c__1 = 1;
5438 static integer c_n1 = -1;
5439 static integer c__3 = 3;
5440 static integer c__2 = 2;
5441
5442 /* System generated locals */
5443 integer a_dim1, a_offset, i__1, i__2, i__3;
5444
5445 /* Local variables */
5446 integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
5447 integer ldwork, lwkopt;
5448 bool lquery;
5449
5450
5451 /* -- LAPACK routine (version 3.1) -- */
5452 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
5453 /* November 2006 */
5454
5455 /* .. Scalar Arguments .. */
5456 /* .. */
5457 /* .. Array Arguments .. */
5458 /* .. */
5459
5460 /* Purpose */
5461 /* ======= */
5462
5463 /* DORGLQ generates an M-by-N real matrix Q with orthonormal rows, */
5464 /* which is defined as the first M rows of a product of K elementary */
5465 /* reflectors of order N */
5466
5467 /* Q = H(k) . . . H(2) H(1) */
5468
5469 /* as returned by DGELQF. */
5470
5471 /* Arguments */
5472 /* ========= */
5473
5474 /* M (input) INTEGER */
5475 /* The number of rows of the matrix Q. M >= 0. */
5476
5477 /* N (input) INTEGER */
5478 /* The number of columns of the matrix Q. N >= M. */
5479
5480 /* K (input) INTEGER */
5481 /* The number of elementary reflectors whose product defines the */
5482 /* matrix Q. M >= K >= 0. */
5483
5484 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
5485 /* On entry, the i-th row must contain the vector which defines */
5486 /* the elementary reflector H(i), for i = 1,2,...,k, as returned */
5487 /* by DGELQF in the first k rows of its array argument A. */
5488 /* On exit, the M-by-N matrix Q. */
5489
5490 /* LDA (input) INTEGER */
5491 /* The first dimension of the array A. LDA >= max(1,M). */
5492
5493 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
5494 /* TAU(i) must contain the scalar factor of the elementary */
5495 /* reflector H(i), as returned by DGELQF. */
5496
5497 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
5498 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
5499
5500 /* LWORK (input) INTEGER */
5501 /* The dimension of the array WORK. LWORK >= max(1,M). */
5502 /* For optimum performance LWORK >= M*NB, where NB is */
5503 /* the optimal blocksize. */
5504
5505 /* If LWORK = -1, then a workspace query is assumed; the routine */
5506 /* only calculates the optimal size of the WORK array, returns */
5507 /* this value as the first entry of the WORK array, and no error */
5508 /* message related to LWORK is issued by XERBLA. */
5509
5510 /* INFO (output) INTEGER */
5511 /* = 0: successful exit */
5512 /* < 0: if INFO = -i, the i-th argument has an illegal value */
5513
5514 /* ===================================================================== */
5515
5516 /* .. Parameters .. */
5517 /* .. */
5518 /* .. Local Scalars .. */
5519 /* .. */
5520 /* .. External Subroutines .. */
5521 /* .. */
5522 /* .. Intrinsic Functions .. */
5523 /* .. */
5524 /* .. External Functions .. */
5525 /* .. */
5526 /* .. Executable Statements .. */
5527
5528 /* Test the input arguments */
5529
5530 /* Parameter adjustments */
5531 a_dim1 = *lda;
5532 a_offset = 1 + a_dim1;
5533 a -= a_offset;
5534 --tau;
5535 --work;
5536
5537 /* Function Body */
5538 *info = 0;
5539 nb = ilaenv_(&c__1, "DORGLQ", " ", m, n, k, &c_n1);
5540 lwkopt = std::max(1_integer,*m) * nb;
5541 work[1] = (double) lwkopt;
5542 lquery = *lwork == -1;
5543 if (*m < 0) {
5544 *info = -1;
5545 } else if (*n < *m) {
5546 *info = -2;
5547 } else if (*k < 0 || *k > *m) {
5548 *info = -3;
5549 } else if (*lda < std::max(1_integer,*m)) {
5550 *info = -5;
5551 } else if (*lwork < std::max(1_integer,*m) && ! lquery) {
5552 *info = -8;
5553 }
5554 if (*info != 0) {
5555 i__1 = -(*info);
5556 xerbla_("DORGLQ", &i__1);
5557 return 0;
5558 } else if (lquery) {
5559 return 0;
5560 }
5561
5562 /* Quick return if possible */
5563
5564 if (*m <= 0) {
5565 work[1] = 1.;
5566 return 0;
5567 }
5568
5569 nbmin = 2;
5570 nx = 0;
5571 iws = *m;
5572 if (nb > 1 && nb < *k) {
5573
5574 /* Determine when to cross over from blocked to unblocked code. */
5575
5576 /* Computing MAX */
5577 i__1 = 0, i__2 = ilaenv_(&c__3, "DORGLQ", " ", m, n, k, &c_n1);
5578 nx = std::max(i__1,i__2);
5579 if (nx < *k) {
5580
5581 /* Determine if workspace is large enough for blocked code. */
5582
5583 ldwork = *m;
5584 iws = ldwork * nb;
5585 if (*lwork < iws) {
5586
5587 /* Not enough workspace to use optimal NB: reduce NB and */
5588 /* determine the minimum value of NB. */
5589
5590 nb = *lwork / ldwork;
5591 /* Computing MAX */
5592 i__1 = 2, i__2 = ilaenv_(&c__2, "DORGLQ", " ", m, n, k, &c_n1);
5593 nbmin = std::max(i__1,i__2);
5594 }
5595 }
5596 }
5597
5598 if (nb >= nbmin && nb < *k && nx < *k) {
5599
5600 /* Use blocked code after the last block. */
5601 /* The first kk rows are handled by the block method. */
5602
5603 ki = (*k - nx - 1) / nb * nb;
5604 /* Computing MIN */
5605 i__1 = *k, i__2 = ki + nb;
5606 kk = std::min(i__1,i__2);
5607
5608 /* Set A(kk+1:m,1:kk) to zero. */
5609
5610 i__1 = kk;
5611 for (j = 1; j <= i__1; ++j) {
5612 i__2 = *m;
5613 for (i__ = kk + 1; i__ <= i__2; ++i__) {
5614 a[i__ + j * a_dim1] = 0.;
5615 /* L10: */
5616 }
5617 /* L20: */
5618 }
5619 } else {
5620 kk = 0;
5621 }
5622
5623 /* Use unblocked code for the last or only block. */
5624
5625 if (kk < *m) {
5626 i__1 = *m - kk;
5627 i__2 = *n - kk;
5628 i__3 = *k - kk;
5629 dorgl2_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
5630 tau[kk + 1], &work[1], &iinfo);
5631 }
5632
5633 if (kk > 0) {
5634
5635 /* Use blocked code */
5636
5637 i__1 = -nb;
5638 for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
5639 /* Computing MIN */
5640 i__2 = nb, i__3 = *k - i__ + 1;
5641 ib = std::min(i__2,i__3);
5642 if (i__ + ib <= *m) {
5643
5644 /* Form the triangular factor of the block reflector */
5645 /* H = H(i) H(i+1) . . . H(i+ib-1) */
5646
5647 i__2 = *n - i__ + 1;
5648 dlarft_("Forward", "Rowwise", &i__2, &ib, &a[i__ + i__ *
5649 a_dim1], lda, &tau[i__], &work[1], &ldwork);
5650
5651 /* Apply H' to A(i+ib:m,i:n) from the right */
5652
5653 i__2 = *m - i__ - ib + 1;
5654 i__3 = *n - i__ + 1;
5655 dlarfb_("Right", "Transpose", "Forward", "Rowwise", &i__2, &
5656 i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
5657 ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[ib +
5658 1], &ldwork);
5659 }
5660
5661 /* Apply H' to columns i:n of current block */
5662
5663 i__2 = *n - i__ + 1;
5664 dorgl2_(&ib, &i__2, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
5665 work[1], &iinfo);
5666
5667 /* Set columns 1:i-1 of current block to zero */
5668
5669 i__2 = i__ - 1;
5670 for (j = 1; j <= i__2; ++j) {
5671 i__3 = i__ + ib - 1;
5672 for (l = i__; l <= i__3; ++l) {
5673 a[l + j * a_dim1] = 0.;
5674 /* L30: */
5675 }
5676 /* L40: */
5677 }
5678 /* L50: */
5679 }
5680 }
5681
5682 work[1] = (double) iws;
5683 return 0;
5684
5685 /* End of DORGLQ */
5686
5687 } /* dorglq_ */
5688
5689 /* Subroutine */ int dorgql_(integer *m, integer *n, integer *k, double *
5690 a, integer *lda, double *tau, double *work, integer *lwork,
5691 integer *info)
5692 {
5693 /* Table of constant values */
5694 static integer c__1 = 1;
5695 static integer c_n1 = -1;
5696 static integer c__3 = 3;
5697 static integer c__2 = 2;
5698
5699 /* System generated locals */
5700 integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
5701
5702 /* Local variables */
5703 integer i__, j, l, ib, nb, kk, nx, iws, nbmin, iinfo;
5704 integer ldwork, lwkopt;
5705 bool lquery;
5706
5707
5708 /* -- LAPACK routine (version 3.1) -- */
5709 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
5710 /* November 2006 */
5711
5712 /* .. Scalar Arguments .. */
5713 /* .. */
5714 /* .. Array Arguments .. */
5715 /* .. */
5716
5717 /* Purpose */
5718 /* ======= */
5719
5720 /* DORGQL generates an M-by-N real matrix Q with orthonormal columns, */
5721 /* which is defined as the last N columns of a product of K elementary */
5722 /* reflectors of order M */
5723
5724 /* Q = H(k) . . . H(2) H(1) */
5725
5726 /* as returned by DGEQLF. */
5727
5728 /* Arguments */
5729 /* ========= */
5730
5731 /* M (input) INTEGER */
5732 /* The number of rows of the matrix Q. M >= 0. */
5733
5734 /* N (input) INTEGER */
5735 /* The number of columns of the matrix Q. M >= N >= 0. */
5736
5737 /* K (input) INTEGER */
5738 /* The number of elementary reflectors whose product defines the */
5739 /* matrix Q. N >= K >= 0. */
5740
5741 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
5742 /* On entry, the (n-k+i)-th column must contain the vector which */
5743 /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
5744 /* returned by DGEQLF in the last k columns of its array */
5745 /* argument A. */
5746 /* On exit, the M-by-N matrix Q. */
5747
5748 /* LDA (input) INTEGER */
5749 /* The first dimension of the array A. LDA >= max(1,M). */
5750
5751 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
5752 /* TAU(i) must contain the scalar factor of the elementary */
5753 /* reflector H(i), as returned by DGEQLF. */
5754
5755 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
5756 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
5757
5758 /* LWORK (input) INTEGER */
5759 /* The dimension of the array WORK. LWORK >= max(1,N). */
5760 /* For optimum performance LWORK >= N*NB, where NB is the */
5761 /* optimal blocksize. */
5762
5763 /* If LWORK = -1, then a workspace query is assumed; the routine */
5764 /* only calculates the optimal size of the WORK array, returns */
5765 /* this value as the first entry of the WORK array, and no error */
5766 /* message related to LWORK is issued by XERBLA. */
5767
5768 /* INFO (output) INTEGER */
5769 /* = 0: successful exit */
5770 /* < 0: if INFO = -i, the i-th argument has an illegal value */
5771
5772 /* ===================================================================== */
5773
5774 /* .. Parameters .. */
5775 /* .. */
5776 /* .. Local Scalars .. */
5777 /* .. */
5778 /* .. External Subroutines .. */
5779 /* .. */
5780 /* .. Intrinsic Functions .. */
5781 /* .. */
5782 /* .. External Functions .. */
5783 /* .. */
5784 /* .. Executable Statements .. */
5785
5786 /* Test the input arguments */
5787
5788 /* Parameter adjustments */
5789 a_dim1 = *lda;
5790 a_offset = 1 + a_dim1;
5791 a -= a_offset;
5792 --tau;
5793 --work;
5794
5795 /* Function Body */
5796 *info = 0;
5797 lquery = *lwork == -1;
5798 if (*m < 0) {
5799 *info = -1;
5800 } else if (*n < 0 || *n > *m) {
5801 *info = -2;
5802 } else if (*k < 0 || *k > *n) {
5803 *info = -3;
5804 } else if (*lda < std::max(1_integer,*m)) {
5805 *info = -5;
5806 }
5807
5808 if (*info == 0) {
5809 if (*n == 0) {
5810 lwkopt = 1;
5811 } else {
5812 nb = ilaenv_(&c__1, "DORGQL", " ", m, n, k, &c_n1);
5813 lwkopt = *n * nb;
5814 }
5815 work[1] = (double) lwkopt;
5816
5817 if (*lwork < std::max(1_integer,*n) && ! lquery) {
5818 *info = -8;
5819 }
5820 }
5821
5822 if (*info != 0) {
5823 i__1 = -(*info);
5824 xerbla_("DORGQL", &i__1);
5825 return 0;
5826 } else if (lquery) {
5827 return 0;
5828 }
5829
5830 /* Quick return if possible */
5831
5832 if (*n <= 0) {
5833 return 0;
5834 }
5835
5836 nbmin = 2;
5837 nx = 0;
5838 iws = *n;
5839 if (nb > 1 && nb < *k) {
5840
5841 /* Determine when to cross over from blocked to unblocked code. */
5842
5843 /* Computing MAX */
5844 i__1 = 0, i__2 = ilaenv_(&c__3, "DORGQL", " ", m, n, k, &c_n1);
5845 nx = std::max(i__1,i__2);
5846 if (nx < *k) {
5847
5848 /* Determine if workspace is large enough for blocked code. */
5849
5850 ldwork = *n;
5851 iws = ldwork * nb;
5852 if (*lwork < iws) {
5853
5854 /* Not enough workspace to use optimal NB: reduce NB and */
5855 /* determine the minimum value of NB. */
5856
5857 nb = *lwork / ldwork;
5858 /* Computing MAX */
5859 i__1 = 2, i__2 = ilaenv_(&c__2, "DORGQL", " ", m, n, k, &c_n1);
5860 nbmin = std::max(i__1,i__2);
5861 }
5862 }
5863 }
5864
5865 if (nb >= nbmin && nb < *k && nx < *k) {
5866
5867 /* Use blocked code after the first block. */
5868 /* The last kk columns are handled by the block method. */
5869
5870 /* Computing MIN */
5871 i__1 = *k, i__2 = (*k - nx + nb - 1) / nb * nb;
5872 kk = std::min(i__1,i__2);
5873
5874 /* Set A(m-kk+1:m,1:n-kk) to zero. */
5875
5876 i__1 = *n - kk;
5877 for (j = 1; j <= i__1; ++j) {
5878 i__2 = *m;
5879 for (i__ = *m - kk + 1; i__ <= i__2; ++i__) {
5880 a[i__ + j * a_dim1] = 0.;
5881 /* L10: */
5882 }
5883 /* L20: */
5884 }
5885 } else {
5886 kk = 0;
5887 }
5888
5889 /* Use unblocked code for the first or only block. */
5890
5891 i__1 = *m - kk;
5892 i__2 = *n - kk;
5893 i__3 = *k - kk;
5894 dorg2l_(&i__1, &i__2, &i__3, &a[a_offset], lda, &tau[1], &work[1], &iinfo)
5895 ;
5896
5897 if (kk > 0) {
5898
5899 /* Use blocked code */
5900
5901 i__1 = *k;
5902 i__2 = nb;
5903 for (i__ = *k - kk + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
5904 i__2) {
5905 /* Computing MIN */
5906 i__3 = nb, i__4 = *k - i__ + 1;
5907 ib = std::min(i__3,i__4);
5908 if (*n - *k + i__ > 1) {
5909
5910 /* Form the triangular factor of the block reflector */
5911 /* H = H(i+ib-1) . . . H(i+1) H(i) */
5912
5913 i__3 = *m - *k + i__ + ib - 1;
5914 dlarft_("Backward", "Columnwise", &i__3, &ib, &a[(*n - *k +
5915 i__) * a_dim1 + 1], lda, &tau[i__], &work[1], &ldwork);
5916
5917 /* Apply H to A(1:m-k+i+ib-1,1:n-k+i-1) from the left */
5918
5919 i__3 = *m - *k + i__ + ib - 1;
5920 i__4 = *n - *k + i__ - 1;
5921 dlarfb_("Left", "No transpose", "Backward", "Columnwise", &
5922 i__3, &i__4, &ib, &a[(*n - *k + i__) * a_dim1 + 1],
5923 lda, &work[1], &ldwork, &a[a_offset], lda, &work[ib +
5924 1], &ldwork);
5925 }
5926
5927 /* Apply H to rows 1:m-k+i+ib-1 of current block */
5928
5929 i__3 = *m - *k + i__ + ib - 1;
5930 dorg2l_(&i__3, &ib, &ib, &a[(*n - *k + i__) * a_dim1 + 1], lda, &
5931 tau[i__], &work[1], &iinfo);
5932
5933 /* Set rows m-k+i+ib:m of current block to zero */
5934
5935 i__3 = *n - *k + i__ + ib - 1;
5936 for (j = *n - *k + i__; j <= i__3; ++j) {
5937 i__4 = *m;
5938 for (l = *m - *k + i__ + ib; l <= i__4; ++l) {
5939 a[l + j * a_dim1] = 0.;
5940 /* L30: */
5941 }
5942 /* L40: */
5943 }
5944 /* L50: */
5945 }
5946 }
5947
5948 work[1] = (double) iws;
5949 return 0;
5950
5951 /* End of DORGQL */
5952
5953 } /* dorgql_ */
5954
5955 /* Subroutine */ int dorgqr_(integer *m, integer *n, integer *k, double *
5956 a, integer *lda, double *tau, double *work, integer *lwork,
5957 integer *info)
5958 {
5959 /* Table of constant values */
5960 static integer c__1 = 1;
5961 static integer c_n1 = -1;
5962 static integer c__3 = 3;
5963 static integer c__2 = 2;
5964
5965 /* System generated locals */
5966 integer a_dim1, a_offset, i__1, i__2, i__3;
5967
5968 /* Local variables */
5969 integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
5970 integer ldwork, lwkopt;
5971 bool lquery;
5972
5973
5974 /* -- LAPACK routine (version 3.1) -- */
5975 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
5976 /* November 2006 */
5977
5978 /* .. Scalar Arguments .. */
5979 /* .. */
5980 /* .. Array Arguments .. */
5981 /* .. */
5982
5983 /* Purpose */
5984 /* ======= */
5985
5986 /* DORGQR generates an M-by-N real matrix Q with orthonormal columns, */
5987 /* which is defined as the first N columns of a product of K elementary */
5988 /* reflectors of order M */
5989
5990 /* Q = H(1) H(2) . . . H(k) */
5991
5992 /* as returned by DGEQRF. */
5993
5994 /* Arguments */
5995 /* ========= */
5996
5997 /* M (input) INTEGER */
5998 /* The number of rows of the matrix Q. M >= 0. */
5999
6000 /* N (input) INTEGER */
6001 /* The number of columns of the matrix Q. M >= N >= 0. */
6002
6003 /* K (input) INTEGER */
6004 /* The number of elementary reflectors whose product defines the */
6005 /* matrix Q. N >= K >= 0. */
6006
6007 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
6008 /* On entry, the i-th column must contain the vector which */
6009 /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
6010 /* returned by DGEQRF in the first k columns of its array */
6011 /* argument A. */
6012 /* On exit, the M-by-N matrix Q. */
6013
6014 /* LDA (input) INTEGER */
6015 /* The first dimension of the array A. LDA >= max(1,M). */
6016
6017 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
6018 /* TAU(i) must contain the scalar factor of the elementary */
6019 /* reflector H(i), as returned by DGEQRF. */
6020
6021 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
6022 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
6023
6024 /* LWORK (input) INTEGER */
6025 /* The dimension of the array WORK. LWORK >= max(1,N). */
6026 /* For optimum performance LWORK >= N*NB, where NB is the */
6027 /* optimal blocksize. */
6028
6029 /* If LWORK = -1, then a workspace query is assumed; the routine */
6030 /* only calculates the optimal size of the WORK array, returns */
6031 /* this value as the first entry of the WORK array, and no error */
6032 /* message related to LWORK is issued by XERBLA. */
6033
6034 /* INFO (output) INTEGER */
6035 /* = 0: successful exit */
6036 /* < 0: if INFO = -i, the i-th argument has an illegal value */
6037
6038 /* ===================================================================== */
6039
6040 /* .. Parameters .. */
6041 /* .. */
6042 /* .. Local Scalars .. */
6043 /* .. */
6044 /* .. External Subroutines .. */
6045 /* .. */
6046 /* .. Intrinsic Functions .. */
6047 /* .. */
6048 /* .. External Functions .. */
6049 /* .. */
6050 /* .. Executable Statements .. */
6051
6052 /* Test the input arguments */
6053
6054 /* Parameter adjustments */
6055 a_dim1 = *lda;
6056 a_offset = 1 + a_dim1;
6057 a -= a_offset;
6058 --tau;
6059 --work;
6060
6061 /* Function Body */
6062 *info = 0;
6063 nb = ilaenv_(&c__1, "DORGQR", " ", m, n, k, &c_n1);
6064 lwkopt = std::max(1_integer,*n) * nb;
6065 work[1] = (double) lwkopt;
6066 lquery = *lwork == -1;
6067 if (*m < 0) {
6068 *info = -1;
6069 } else if (*n < 0 || *n > *m) {
6070 *info = -2;
6071 } else if (*k < 0 || *k > *n) {
6072 *info = -3;
6073 } else if (*lda < std::max(1_integer,*m)) {
6074 *info = -5;
6075 } else if (*lwork < std::max(1_integer,*n) && ! lquery) {
6076 *info = -8;
6077 }
6078 if (*info != 0) {
6079 i__1 = -(*info);
6080 xerbla_("DORGQR", &i__1);
6081 return 0;
6082 } else if (lquery) {
6083 return 0;
6084 }
6085
6086 /* Quick return if possible */
6087
6088 if (*n <= 0) {
6089 work[1] = 1.;
6090 return 0;
6091 }
6092
6093 nbmin = 2;
6094 nx = 0;
6095 iws = *n;
6096 if (nb > 1 && nb < *k) {
6097
6098 /* Determine when to cross over from blocked to unblocked code. */
6099
6100 /* Computing MAX */
6101 i__1 = 0, i__2 = ilaenv_(&c__3, "DORGQR", " ", m, n, k, &c_n1);
6102 nx = std::max(i__1,i__2);
6103 if (nx < *k) {
6104
6105 /* Determine if workspace is large enough for blocked code. */
6106
6107 ldwork = *n;
6108 iws = ldwork * nb;
6109 if (*lwork < iws) {
6110
6111 /* Not enough workspace to use optimal NB: reduce NB and */
6112 /* determine the minimum value of NB. */
6113
6114 nb = *lwork / ldwork;
6115 /* Computing MAX */
6116 i__1 = 2, i__2 = ilaenv_(&c__2, "DORGQR", " ", m, n, k, &c_n1);
6117 nbmin = std::max(i__1,i__2);
6118 }
6119 }
6120 }
6121
6122 if (nb >= nbmin && nb < *k && nx < *k) {
6123
6124 /* Use blocked code after the last block. */
6125 /* The first kk columns are handled by the block method. */
6126
6127 ki = (*k - nx - 1) / nb * nb;
6128 /* Computing MIN */
6129 i__1 = *k, i__2 = ki + nb;
6130 kk = std::min(i__1,i__2);
6131
6132 /* Set A(1:kk,kk+1:n) to zero. */
6133
6134 i__1 = *n;
6135 for (j = kk + 1; j <= i__1; ++j) {
6136 i__2 = kk;
6137 for (i__ = 1; i__ <= i__2; ++i__) {
6138 a[i__ + j * a_dim1] = 0.;
6139 /* L10: */
6140 }
6141 /* L20: */
6142 }
6143 } else {
6144 kk = 0;
6145 }
6146
6147 /* Use unblocked code for the last or only block. */
6148
6149 if (kk < *n) {
6150 i__1 = *m - kk;
6151 i__2 = *n - kk;
6152 i__3 = *k - kk;
6153 dorg2r_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
6154 tau[kk + 1], &work[1], &iinfo);
6155 }
6156
6157 if (kk > 0) {
6158
6159 /* Use blocked code */
6160
6161 i__1 = -nb;
6162 for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
6163 /* Computing MIN */
6164 i__2 = nb, i__3 = *k - i__ + 1;
6165 ib = std::min(i__2,i__3);
6166 if (i__ + ib <= *n) {
6167
6168 /* Form the triangular factor of the block reflector */
6169 /* H = H(i) H(i+1) . . . H(i+ib-1) */
6170
6171 i__2 = *m - i__ + 1;
6172 dlarft_("Forward", "Columnwise", &i__2, &ib, &a[i__ + i__ *
6173 a_dim1], lda, &tau[i__], &work[1], &ldwork);
6174
6175 /* Apply H to A(i:m,i+ib:n) from the left */
6176
6177 i__2 = *m - i__ + 1;
6178 i__3 = *n - i__ - ib + 1;
6179 dlarfb_("Left", "No transpose", "Forward", "Columnwise", &
6180 i__2, &i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[
6181 1], &ldwork, &a[i__ + (i__ + ib) * a_dim1], lda, &
6182 work[ib + 1], &ldwork);
6183 }
6184
6185 /* Apply H to rows i:m of current block */
6186
6187 i__2 = *m - i__ + 1;
6188 dorg2r_(&i__2, &ib, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
6189 work[1], &iinfo);
6190
6191 /* Set rows 1:i-1 of current block to zero */
6192
6193 i__2 = i__ + ib - 1;
6194 for (j = i__; j <= i__2; ++j) {
6195 i__3 = i__ - 1;
6196 for (l = 1; l <= i__3; ++l) {
6197 a[l + j * a_dim1] = 0.;
6198 /* L30: */
6199 }
6200 /* L40: */
6201 }
6202 /* L50: */
6203 }
6204 }
6205
6206 work[1] = (double) iws;
6207 return 0;
6208
6209 /* End of DORGQR */
6210
6211 } /* dorgqr_ */
6212
6213 /* Subroutine */ int dorgr2_(integer *m, integer *n, integer *k, double *
6214 a, integer *lda, double *tau, double *work, integer *info)
6215 {
6216 /* System generated locals */
6217 integer a_dim1, a_offset, i__1, i__2, i__3;
6218 double d__1;
6219
6220 /* Local variables */
6221 integer i__, j, l, ii;
6222
6223
6224 /* -- LAPACK routine (version 3.1) -- */
6225 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
6226 /* November 2006 */
6227
6228 /* .. Scalar Arguments .. */
6229 /* .. */
6230 /* .. Array Arguments .. */
6231 /* .. */
6232
6233 /* Purpose */
6234 /* ======= */
6235
6236 /* DORGR2 generates an m by n real matrix Q with orthonormal rows, */
6237 /* which is defined as the last m rows of a product of k elementary */
6238 /* reflectors of order n */
6239
6240 /* Q = H(1) H(2) . . . H(k) */
6241
6242 /* as returned by DGERQF. */
6243
6244 /* Arguments */
6245 /* ========= */
6246
6247 /* M (input) INTEGER */
6248 /* The number of rows of the matrix Q. M >= 0. */
6249
6250 /* N (input) INTEGER */
6251 /* The number of columns of the matrix Q. N >= M. */
6252
6253 /* K (input) INTEGER */
6254 /* The number of elementary reflectors whose product defines the */
6255 /* matrix Q. M >= K >= 0. */
6256
6257 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
6258 /* On entry, the (m-k+i)-th row must contain the vector which */
6259 /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
6260 /* returned by DGERQF in the last k rows of its array argument */
6261 /* A. */
6262 /* On exit, the m by n matrix Q. */
6263
6264 /* LDA (input) INTEGER */
6265 /* The first dimension of the array A. LDA >= max(1,M). */
6266
6267 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
6268 /* TAU(i) must contain the scalar factor of the elementary */
6269 /* reflector H(i), as returned by DGERQF. */
6270
6271 /* WORK (workspace) DOUBLE PRECISION array, dimension (M) */
6272
6273 /* INFO (output) INTEGER */
6274 /* = 0: successful exit */
6275 /* < 0: if INFO = -i, the i-th argument has an illegal value */
6276
6277 /* ===================================================================== */
6278
6279 /* .. Parameters .. */
6280 /* .. */
6281 /* .. Local Scalars .. */
6282 /* .. */
6283 /* .. External Subroutines .. */
6284 /* .. */
6285 /* .. Intrinsic Functions .. */
6286 /* .. */
6287 /* .. Executable Statements .. */
6288
6289 /* Test the input arguments */
6290
6291 /* Parameter adjustments */
6292 a_dim1 = *lda;
6293 a_offset = 1 + a_dim1;
6294 a -= a_offset;
6295 --tau;
6296 --work;
6297
6298 /* Function Body */
6299 *info = 0;
6300 if (*m < 0) {
6301 *info = -1;
6302 } else if (*n < *m) {
6303 *info = -2;
6304 } else if (*k < 0 || *k > *m) {
6305 *info = -3;
6306 } else if (*lda < std::max(1_integer,*m)) {
6307 *info = -5;
6308 }
6309 if (*info != 0) {
6310 i__1 = -(*info);
6311 xerbla_("DORGR2", &i__1);
6312 return 0;
6313 }
6314
6315 /* Quick return if possible */
6316
6317 if (*m <= 0) {
6318 return 0;
6319 }
6320
6321 if (*k < *m) {
6322
6323 /* Initialise rows 1:m-k to rows of the unit matrix */
6324
6325 i__1 = *n;
6326 for (j = 1; j <= i__1; ++j) {
6327 i__2 = *m - *k;
6328 for (l = 1; l <= i__2; ++l) {
6329 a[l + j * a_dim1] = 0.;
6330 /* L10: */
6331 }
6332 if (j > *n - *m && j <= *n - *k) {
6333 a[*m - *n + j + j * a_dim1] = 1.;
6334 }
6335 /* L20: */
6336 }
6337 }
6338
6339 i__1 = *k;
6340 for (i__ = 1; i__ <= i__1; ++i__) {
6341 ii = *m - *k + i__;
6342
6343 /* Apply H(i) to A(1:m-k+i,1:n-k+i) from the right */
6344
6345 a[ii + (*n - *m + ii) * a_dim1] = 1.;
6346 i__2 = ii - 1;
6347 i__3 = *n - *m + ii;
6348 dlarf_("Right", &i__2, &i__3, &a[ii + a_dim1], lda, &tau[i__], &a[
6349 a_offset], lda, &work[1]);
6350 i__2 = *n - *m + ii - 1;
6351 d__1 = -tau[i__];
6352 dscal_(&i__2, &d__1, &a[ii + a_dim1], lda);
6353 a[ii + (*n - *m + ii) * a_dim1] = 1. - tau[i__];
6354
6355 /* Set A(m-k+i,n-k+i+1:n) to zero */
6356
6357 i__2 = *n;
6358 for (l = *n - *m + ii + 1; l <= i__2; ++l) {
6359 a[ii + l * a_dim1] = 0.;
6360 /* L30: */
6361 }
6362 /* L40: */
6363 }
6364 return 0;
6365
6366 /* End of DORGR2 */
6367
6368 } /* dorgr2_ */
6369
6370 /* Subroutine */ int dorgrq_(integer *m, integer *n, integer *k, double *
6371 a, integer *lda, double *tau, double *work, integer *lwork,
6372 integer *info)
6373 {
6374 /* Table of constant values */
6375 static integer c__1 = 1;
6376 static integer c_n1 = -1;
6377 static integer c__3 = 3;
6378 static integer c__2 = 2;
6379
6380 /* System generated locals */
6381 integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
6382
6383 /* Local variables */
6384 integer i__, j, l, ib, nb, ii, kk, nx, iws, nbmin, iinfo;
6385 integer ldwork, lwkopt;
6386 bool lquery;
6387
6388
6389 /* -- LAPACK routine (version 3.1) -- */
6390 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
6391 /* November 2006 */
6392
6393 /* .. Scalar Arguments .. */
6394 /* .. */
6395 /* .. Array Arguments .. */
6396 /* .. */
6397
6398 /* Purpose */
6399 /* ======= */
6400
6401 /* DORGRQ generates an M-by-N real matrix Q with orthonormal rows, */
6402 /* which is defined as the last M rows of a product of K elementary */
6403 /* reflectors of order N */
6404
6405 /* Q = H(1) H(2) . . . H(k) */
6406
6407 /* as returned by DGERQF. */
6408
6409 /* Arguments */
6410 /* ========= */
6411
6412 /* M (input) INTEGER */
6413 /* The number of rows of the matrix Q. M >= 0. */
6414
6415 /* N (input) INTEGER */
6416 /* The number of columns of the matrix Q. N >= M. */
6417
6418 /* K (input) INTEGER */
6419 /* The number of elementary reflectors whose product defines the */
6420 /* matrix Q. M >= K >= 0. */
6421
6422 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
6423 /* On entry, the (m-k+i)-th row must contain the vector which */
6424 /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
6425 /* returned by DGERQF in the last k rows of its array argument */
6426 /* A. */
6427 /* On exit, the M-by-N matrix Q. */
6428
6429 /* LDA (input) INTEGER */
6430 /* The first dimension of the array A. LDA >= max(1,M). */
6431
6432 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
6433 /* TAU(i) must contain the scalar factor of the elementary */
6434 /* reflector H(i), as returned by DGERQF. */
6435
6436 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
6437 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
6438
6439 /* LWORK (input) INTEGER */
6440 /* The dimension of the array WORK. LWORK >= max(1,M). */
6441 /* For optimum performance LWORK >= M*NB, where NB is the */
6442 /* optimal blocksize. */
6443
6444 /* If LWORK = -1, then a workspace query is assumed; the routine */
6445 /* only calculates the optimal size of the WORK array, returns */
6446 /* this value as the first entry of the WORK array, and no error */
6447 /* message related to LWORK is issued by XERBLA. */
6448
6449 /* INFO (output) INTEGER */
6450 /* = 0: successful exit */
6451 /* < 0: if INFO = -i, the i-th argument has an illegal value */
6452
6453 /* ===================================================================== */
6454
6455 /* .. Parameters .. */
6456 /* .. */
6457 /* .. Local Scalars .. */
6458 /* .. */
6459 /* .. External Subroutines .. */
6460 /* .. */
6461 /* .. Intrinsic Functions .. */
6462 /* .. */
6463 /* .. External Functions .. */
6464 /* .. */
6465 /* .. Executable Statements .. */
6466
6467 /* Test the input arguments */
6468
6469 /* Parameter adjustments */
6470 a_dim1 = *lda;
6471 a_offset = 1 + a_dim1;
6472 a -= a_offset;
6473 --tau;
6474 --work;
6475
6476 /* Function Body */
6477 *info = 0;
6478 lquery = *lwork == -1;
6479 if (*m < 0) {
6480 *info = -1;
6481 } else if (*n < *m) {
6482 *info = -2;
6483 } else if (*k < 0 || *k > *m) {
6484 *info = -3;
6485 } else if (*lda < std::max(1_integer,*m)) {
6486 *info = -5;
6487 }
6488
6489 if (*info == 0) {
6490 if (*m <= 0) {
6491 lwkopt = 1;
6492 } else {
6493 nb = ilaenv_(&c__1, "DORGRQ", " ", m, n, k, &c_n1);
6494 lwkopt = *m * nb;
6495 }
6496 work[1] = (double) lwkopt;
6497
6498 if (*lwork < std::max(1_integer,*m) && ! lquery) {
6499 *info = -8;
6500 }
6501 }
6502
6503 if (*info != 0) {
6504 i__1 = -(*info);
6505 xerbla_("DORGRQ", &i__1);
6506 return 0;
6507 } else if (lquery) {
6508 return 0;
6509 }
6510
6511 /* Quick return if possible */
6512
6513 if (*m <= 0) {
6514 return 0;
6515 }
6516
6517 nbmin = 2;
6518 nx = 0;
6519 iws = *m;
6520 if (nb > 1 && nb < *k) {
6521
6522 /* Determine when to cross over from blocked to unblocked code. */
6523
6524 /* Computing MAX */
6525 i__1 = 0, i__2 = ilaenv_(&c__3, "DORGRQ", " ", m, n, k, &c_n1);
6526 nx = std::max(i__1,i__2);
6527 if (nx < *k) {
6528
6529 /* Determine if workspace is large enough for blocked code. */
6530
6531 ldwork = *m;
6532 iws = ldwork * nb;
6533 if (*lwork < iws) {
6534
6535 /* Not enough workspace to use optimal NB: reduce NB and */
6536 /* determine the minimum value of NB. */
6537
6538 nb = *lwork / ldwork;
6539 /* Computing MAX */
6540 i__1 = 2, i__2 = ilaenv_(&c__2, "DORGRQ", " ", m, n, k, &c_n1);
6541 nbmin = std::max(i__1,i__2);
6542 }
6543 }
6544 }
6545
6546 if (nb >= nbmin && nb < *k && nx < *k) {
6547
6548 /* Use blocked code after the first block. */
6549 /* The last kk rows are handled by the block method. */
6550
6551 /* Computing MIN */
6552 i__1 = *k, i__2 = (*k - nx + nb - 1) / nb * nb;
6553 kk = std::min(i__1,i__2);
6554
6555 /* Set A(1:m-kk,n-kk+1:n) to zero. */
6556
6557 i__1 = *n;
6558 for (j = *n - kk + 1; j <= i__1; ++j) {
6559 i__2 = *m - kk;
6560 for (i__ = 1; i__ <= i__2; ++i__) {
6561 a[i__ + j * a_dim1] = 0.;
6562 /* L10: */
6563 }
6564 /* L20: */
6565 }
6566 } else {
6567 kk = 0;
6568 }
6569
6570 /* Use unblocked code for the first or only block. */
6571
6572 i__1 = *m - kk;
6573 i__2 = *n - kk;
6574 i__3 = *k - kk;
6575 dorgr2_(&i__1, &i__2, &i__3, &a[a_offset], lda, &tau[1], &work[1], &iinfo)
6576 ;
6577
6578 if (kk > 0) {
6579
6580 /* Use blocked code */
6581
6582 i__1 = *k;
6583 i__2 = nb;
6584 for (i__ = *k - kk + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
6585 i__2) {
6586 /* Computing MIN */
6587 i__3 = nb, i__4 = *k - i__ + 1;
6588 ib = std::min(i__3,i__4);
6589 ii = *m - *k + i__;
6590 if (ii > 1) {
6591
6592 /* Form the triangular factor of the block reflector */
6593 /* H = H(i+ib-1) . . . H(i+1) H(i) */
6594
6595 i__3 = *n - *k + i__ + ib - 1;
6596 dlarft_("Backward", "Rowwise", &i__3, &ib, &a[ii + a_dim1],
6597 lda, &tau[i__], &work[1], &ldwork);
6598
6599 /* Apply H' to A(1:m-k+i-1,1:n-k+i+ib-1) from the right */
6600
6601 i__3 = ii - 1;
6602 i__4 = *n - *k + i__ + ib - 1;
6603 dlarfb_("Right", "Transpose", "Backward", "Rowwise", &i__3, &
6604 i__4, &ib, &a[ii + a_dim1], lda, &work[1], &ldwork, &
6605 a[a_offset], lda, &work[ib + 1], &ldwork);
6606 }
6607
6608 /* Apply H' to columns 1:n-k+i+ib-1 of current block */
6609
6610 i__3 = *n - *k + i__ + ib - 1;
6611 dorgr2_(&ib, &i__3, &ib, &a[ii + a_dim1], lda, &tau[i__], &work[1]
6612 , &iinfo);
6613
6614 /* Set columns n-k+i+ib:n of current block to zero */
6615
6616 i__3 = *n;
6617 for (l = *n - *k + i__ + ib; l <= i__3; ++l) {
6618 i__4 = ii + ib - 1;
6619 for (j = ii; j <= i__4; ++j) {
6620 a[j + l * a_dim1] = 0.;
6621 /* L30: */
6622 }
6623 /* L40: */
6624 }
6625 /* L50: */
6626 }
6627 }
6628
6629 work[1] = (double) iws;
6630 return 0;
6631
6632 /* End of DORGRQ */
6633
6634 } /* dorgrq_ */
6635
6636 /* Subroutine */ int dorgtr_(const char *uplo, integer *n, double *a, integer *
6637 lda, double *tau, double *work, integer *lwork, integer *info)
6638 {
6639 /* Table of constant values */
6640 static integer c__1 = 1;
6641 static integer c_n1 = -1;
6642
6643 /* System generated locals */
6644 integer a_dim1, a_offset, i__1, i__2, i__3;
6645
6646 /* Local variables */
6647 integer i__, j, nb;
6648 integer iinfo;
6649 bool upper;
6650 integer lwkopt;
6651 bool lquery;
6652
6653
6654 /* -- LAPACK routine (version 3.1) -- */
6655 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
6656 /* November 2006 */
6657
6658 /* .. Scalar Arguments .. */
6659 /* .. */
6660 /* .. Array Arguments .. */
6661 /* .. */
6662
6663 /* Purpose */
6664 /* ======= */
6665
6666 /* DORGTR generates a real orthogonal matrix Q which is defined as the */
6667 /* product of n-1 elementary reflectors of order N, as returned by */
6668 /* DSYTRD: */
6669
6670 /* if UPLO = 'U', Q = H(n-1) . . . H(2) H(1), */
6671
6672 /* if UPLO = 'L', Q = H(1) H(2) . . . H(n-1). */
6673
6674 /* Arguments */
6675 /* ========= */
6676
6677 /* UPLO (input) CHARACTER*1 */
6678 /* = 'U': Upper triangle of A contains elementary reflectors */
6679 /* from DSYTRD; */
6680 /* = 'L': Lower triangle of A contains elementary reflectors */
6681 /* from DSYTRD. */
6682
6683 /* N (input) INTEGER */
6684 /* The order of the matrix Q. N >= 0. */
6685
6686 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
6687 /* On entry, the vectors which define the elementary reflectors, */
6688 /* as returned by DSYTRD. */
6689 /* On exit, the N-by-N orthogonal matrix Q. */
6690
6691 /* LDA (input) INTEGER */
6692 /* The leading dimension of the array A. LDA >= max(1,N). */
6693
6694 /* TAU (input) DOUBLE PRECISION array, dimension (N-1) */
6695 /* TAU(i) must contain the scalar factor of the elementary */
6696 /* reflector H(i), as returned by DSYTRD. */
6697
6698 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
6699 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
6700
6701 /* LWORK (input) INTEGER */
6702 /* The dimension of the array WORK. LWORK >= max(1,N-1). */
6703 /* For optimum performance LWORK >= (N-1)*NB, where NB is */
6704 /* the optimal blocksize. */
6705
6706 /* If LWORK = -1, then a workspace query is assumed; the routine */
6707 /* only calculates the optimal size of the WORK array, returns */
6708 /* this value as the first entry of the WORK array, and no error */
6709 /* message related to LWORK is issued by XERBLA. */
6710
6711 /* INFO (output) INTEGER */
6712 /* = 0: successful exit */
6713 /* < 0: if INFO = -i, the i-th argument had an illegal value */
6714
6715 /* ===================================================================== */
6716
6717 /* .. Parameters .. */
6718 /* .. */
6719 /* .. Local Scalars .. */
6720 /* .. */
6721 /* .. External Functions .. */
6722 /* .. */
6723 /* .. External Subroutines .. */
6724 /* .. */
6725 /* .. Intrinsic Functions .. */
6726 /* .. */
6727 /* .. Executable Statements .. */
6728
6729 /* Test the input arguments */
6730
6731 /* Parameter adjustments */
6732 a_dim1 = *lda;
6733 a_offset = 1 + a_dim1;
6734 a -= a_offset;
6735 --tau;
6736 --work;
6737
6738 /* Function Body */
6739 *info = 0;
6740 lquery = *lwork == -1;
6741 upper = lsame_(uplo, "U");
6742 if (! upper && ! lsame_(uplo, "L")) {
6743 *info = -1;
6744 } else if (*n < 0) {
6745 *info = -2;
6746 } else if (*lda < std::max(1_integer,*n)) {
6747 *info = -4;
6748 } else /* if(complicated condition) */ {
6749 /* Computing MAX */
6750 i__1 = 1, i__2 = *n - 1;
6751 if (*lwork < std::max(i__1,i__2) && ! lquery) {
6752 *info = -7;
6753 }
6754 }
6755
6756 if (*info == 0) {
6757 if (upper) {
6758 i__1 = *n - 1;
6759 i__2 = *n - 1;
6760 i__3 = *n - 1;
6761 nb = ilaenv_(&c__1, "DORGQL", " ", &i__1, &i__2, &i__3, &c_n1);
6762 } else {
6763 i__1 = *n - 1;
6764 i__2 = *n - 1;
6765 i__3 = *n - 1;
6766 nb = ilaenv_(&c__1, "DORGQR", " ", &i__1, &i__2, &i__3, &c_n1);
6767 }
6768 /* Computing MAX */
6769 i__1 = 1, i__2 = *n - 1;
6770 lwkopt = std::max(i__1,i__2) * nb;
6771 work[1] = (double) lwkopt;
6772 }
6773
6774 if (*info != 0) {
6775 i__1 = -(*info);
6776 xerbla_("DORGTR", &i__1);
6777 return 0;
6778 } else if (lquery) {
6779 return 0;
6780 }
6781
6782 /* Quick return if possible */
6783
6784 if (*n == 0) {
6785 work[1] = 1.;
6786 return 0;
6787 }
6788
6789 if (upper) {
6790
6791 /* Q was determined by a call to DSYTRD with UPLO = 'U' */
6792
6793 /* Shift the vectors which define the elementary reflectors one */
6794 /* column to the left, and set the last row and column of Q to */
6795 /* those of the unit matrix */
6796
6797 i__1 = *n - 1;
6798 for (j = 1; j <= i__1; ++j) {
6799 i__2 = j - 1;
6800 for (i__ = 1; i__ <= i__2; ++i__) {
6801 a[i__ + j * a_dim1] = a[i__ + (j + 1) * a_dim1];
6802 /* L10: */
6803 }
6804 a[*n + j * a_dim1] = 0.;
6805 /* L20: */
6806 }
6807 i__1 = *n - 1;
6808 for (i__ = 1; i__ <= i__1; ++i__) {
6809 a[i__ + *n * a_dim1] = 0.;
6810 /* L30: */
6811 }
6812 a[*n + *n * a_dim1] = 1.;
6813
6814 /* Generate Q(1:n-1,1:n-1) */
6815
6816 i__1 = *n - 1;
6817 i__2 = *n - 1;
6818 i__3 = *n - 1;
6819 dorgql_(&i__1, &i__2, &i__3, &a[a_offset], lda, &tau[1], &work[1],
6820 lwork, &iinfo);
6821
6822 } else {
6823
6824 /* Q was determined by a call to DSYTRD with UPLO = 'L'. */
6825
6826 /* Shift the vectors which define the elementary reflectors one */
6827 /* column to the right, and set the first row and column of Q to */
6828 /* those of the unit matrix */
6829
6830 for (j = *n; j >= 2; --j) {
6831 a[j * a_dim1 + 1] = 0.;
6832 i__1 = *n;
6833 for (i__ = j + 1; i__ <= i__1; ++i__) {
6834 a[i__ + j * a_dim1] = a[i__ + (j - 1) * a_dim1];
6835 /* L40: */
6836 }
6837 /* L50: */
6838 }
6839 a[a_dim1 + 1] = 1.;
6840 i__1 = *n;
6841 for (i__ = 2; i__ <= i__1; ++i__) {
6842 a[i__ + a_dim1] = 0.;
6843 /* L60: */
6844 }
6845 if (*n > 1) {
6846
6847 /* Generate Q(2:n,2:n) */
6848
6849 i__1 = *n - 1;
6850 i__2 = *n - 1;
6851 i__3 = *n - 1;
6852 dorgqr_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[1],
6853 &work[1], lwork, &iinfo);
6854 }
6855 }
6856 work[1] = (double) lwkopt;
6857 return 0;
6858
6859 /* End of DORGTR */
6860
6861 } /* dorgtr_ */
6862
6863 /* Subroutine */ int dorm2l_(const char *side, const char *trans, integer *m, integer *n,
6864 integer *k, double *a, integer *lda, double *tau, double *
6865 c__, integer *ldc, double *work, integer *info)
6866 {
6867 /* Table of constant values */
6868 static integer c__1 = 1;
6869
6870 /* System generated locals */
6871 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2;
6872
6873 /* Local variables */
6874 integer i__, i1, i2, i3, mi, ni, nq;
6875 double aii;
6876 bool left;
6877 bool notran;
6878
6879
6880 /* -- LAPACK routine (version 3.1) -- */
6881 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
6882 /* November 2006 */
6883
6884 /* .. Scalar Arguments .. */
6885 /* .. */
6886 /* .. Array Arguments .. */
6887 /* .. */
6888
6889 /* Purpose */
6890 /* ======= */
6891
6892 /* DORM2L overwrites the general real m by n matrix C with */
6893
6894 /* Q * C if SIDE = 'L' and TRANS = 'N', or */
6895
6896 /* Q'* C if SIDE = 'L' and TRANS = 'T', or */
6897
6898 /* C * Q if SIDE = 'R' and TRANS = 'N', or */
6899
6900 /* C * Q' if SIDE = 'R' and TRANS = 'T', */
6901
6902 /* where Q is a real orthogonal matrix defined as the product of k */
6903 /* elementary reflectors */
6904
6905 /* Q = H(k) . . . H(2) H(1) */
6906
6907 /* as returned by DGEQLF. Q is of order m if SIDE = 'L' and of order n */
6908 /* if SIDE = 'R'. */
6909
6910 /* Arguments */
6911 /* ========= */
6912
6913 /* SIDE (input) CHARACTER*1 */
6914 /* = 'L': apply Q or Q' from the Left */
6915 /* = 'R': apply Q or Q' from the Right */
6916
6917 /* TRANS (input) CHARACTER*1 */
6918 /* = 'N': apply Q (No transpose) */
6919 /* = 'T': apply Q' (Transpose) */
6920
6921 /* M (input) INTEGER */
6922 /* The number of rows of the matrix C. M >= 0. */
6923
6924 /* N (input) INTEGER */
6925 /* The number of columns of the matrix C. N >= 0. */
6926
6927 /* K (input) INTEGER */
6928 /* The number of elementary reflectors whose product defines */
6929 /* the matrix Q. */
6930 /* If SIDE = 'L', M >= K >= 0; */
6931 /* if SIDE = 'R', N >= K >= 0. */
6932
6933 /* A (input) DOUBLE PRECISION array, dimension (LDA,K) */
6934 /* The i-th column must contain the vector which defines the */
6935 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
6936 /* DGEQLF in the last k columns of its array argument A. */
6937 /* A is modified by the routine but restored on exit. */
6938
6939 /* LDA (input) INTEGER */
6940 /* The leading dimension of the array A. */
6941 /* If SIDE = 'L', LDA >= max(1,M); */
6942 /* if SIDE = 'R', LDA >= max(1,N). */
6943
6944 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
6945 /* TAU(i) must contain the scalar factor of the elementary */
6946 /* reflector H(i), as returned by DGEQLF. */
6947
6948 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
6949 /* On entry, the m by n matrix C. */
6950 /* On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q. */
6951
6952 /* LDC (input) INTEGER */
6953 /* The leading dimension of the array C. LDC >= max(1,M). */
6954
6955 /* WORK (workspace) DOUBLE PRECISION array, dimension */
6956 /* (N) if SIDE = 'L', */
6957 /* (M) if SIDE = 'R' */
6958
6959 /* INFO (output) INTEGER */
6960 /* = 0: successful exit */
6961 /* < 0: if INFO = -i, the i-th argument had an illegal value */
6962
6963 /* ===================================================================== */
6964
6965 /* .. Parameters .. */
6966 /* .. */
6967 /* .. Local Scalars .. */
6968 /* .. */
6969 /* .. External Functions .. */
6970 /* .. */
6971 /* .. External Subroutines .. */
6972 /* .. */
6973 /* .. Intrinsic Functions .. */
6974 /* .. */
6975 /* .. Executable Statements .. */
6976
6977 /* Test the input arguments */
6978
6979 /* Parameter adjustments */
6980 a_dim1 = *lda;
6981 a_offset = 1 + a_dim1;
6982 a -= a_offset;
6983 --tau;
6984 c_dim1 = *ldc;
6985 c_offset = 1 + c_dim1;
6986 c__ -= c_offset;
6987 --work;
6988
6989 /* Function Body */
6990 *info = 0;
6991 left = lsame_(side, "L");
6992 notran = lsame_(trans, "N");
6993
6994 /* NQ is the order of Q */
6995
6996 if (left) {
6997 nq = *m;
6998 } else {
6999 nq = *n;
7000 }
7001 if (! left && ! lsame_(side, "R")) {
7002 *info = -1;
7003 } else if (! notran && ! lsame_(trans, "T")) {
7004 *info = -2;
7005 } else if (*m < 0) {
7006 *info = -3;
7007 } else if (*n < 0) {
7008 *info = -4;
7009 } else if (*k < 0 || *k > nq) {
7010 *info = -5;
7011 } else if (*lda < std::max(1_integer,nq)) {
7012 *info = -7;
7013 } else if (*ldc < std::max(1_integer,*m)) {
7014 *info = -10;
7015 }
7016 if (*info != 0) {
7017 i__1 = -(*info);
7018 xerbla_("DORM2L", &i__1);
7019 return 0;
7020 }
7021
7022 /* Quick return if possible */
7023
7024 if (*m == 0 || *n == 0 || *k == 0) {
7025 return 0;
7026 }
7027
7028 if (left && notran || ! left && ! notran) {
7029 i1 = 1;
7030 i2 = *k;
7031 i3 = 1;
7032 } else {
7033 i1 = *k;
7034 i2 = 1;
7035 i3 = -1;
7036 }
7037
7038 if (left) {
7039 ni = *n;
7040 } else {
7041 mi = *m;
7042 }
7043
7044 i__1 = i2;
7045 i__2 = i3;
7046 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
7047 if (left) {
7048
7049 /* H(i) is applied to C(1:m-k+i,1:n) */
7050
7051 mi = *m - *k + i__;
7052 } else {
7053
7054 /* H(i) is applied to C(1:m,1:n-k+i) */
7055
7056 ni = *n - *k + i__;
7057 }
7058
7059 /* Apply H(i) */
7060
7061 aii = a[nq - *k + i__ + i__ * a_dim1];
7062 a[nq - *k + i__ + i__ * a_dim1] = 1.;
7063 dlarf_(side, &mi, &ni, &a[i__ * a_dim1 + 1], &c__1, &tau[i__], &c__[
7064 c_offset], ldc, &work[1]);
7065 a[nq - *k + i__ + i__ * a_dim1] = aii;
7066 /* L10: */
7067 }
7068 return 0;
7069
7070 /* End of DORM2L */
7071
7072 } /* dorm2l_ */
7073
7074 /* Subroutine */ int dorm2r_(const char *side, const char *trans, integer *m, integer *n,
7075 integer *k, double *a, integer *lda, double *tau, double *
7076 c__, integer *ldc, double *work, integer *info)
7077 {
7078 /* Table of constant values */
7079 static integer c__1 = 1;
7080
7081 /* System generated locals */
7082 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2;
7083
7084 /* Local variables */
7085 integer i__, i1, i2, i3, ic, jc, mi, ni, nq;
7086 double aii;
7087 bool left;
7088 bool notran;
7089
7090
7091 /* -- LAPACK routine (version 3.1) -- */
7092 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
7093 /* November 2006 */
7094
7095 /* .. Scalar Arguments .. */
7096 /* .. */
7097 /* .. Array Arguments .. */
7098 /* .. */
7099
7100 /* Purpose */
7101 /* ======= */
7102
7103 /* DORM2R overwrites the general real m by n matrix C with */
7104
7105 /* Q * C if SIDE = 'L' and TRANS = 'N', or */
7106
7107 /* Q'* C if SIDE = 'L' and TRANS = 'T', or */
7108
7109 /* C * Q if SIDE = 'R' and TRANS = 'N', or */
7110
7111 /* C * Q' if SIDE = 'R' and TRANS = 'T', */
7112
7113 /* where Q is a real orthogonal matrix defined as the product of k */
7114 /* elementary reflectors */
7115
7116 /* Q = H(1) H(2) . . . H(k) */
7117
7118 /* as returned by DGEQRF. Q is of order m if SIDE = 'L' and of order n */
7119 /* if SIDE = 'R'. */
7120
7121 /* Arguments */
7122 /* ========= */
7123
7124 /* SIDE (input) CHARACTER*1 */
7125 /* = 'L': apply Q or Q' from the Left */
7126 /* = 'R': apply Q or Q' from the Right */
7127
7128 /* TRANS (input) CHARACTER*1 */
7129 /* = 'N': apply Q (No transpose) */
7130 /* = 'T': apply Q' (Transpose) */
7131
7132 /* M (input) INTEGER */
7133 /* The number of rows of the matrix C. M >= 0. */
7134
7135 /* N (input) INTEGER */
7136 /* The number of columns of the matrix C. N >= 0. */
7137
7138 /* K (input) INTEGER */
7139 /* The number of elementary reflectors whose product defines */
7140 /* the matrix Q. */
7141 /* If SIDE = 'L', M >= K >= 0; */
7142 /* if SIDE = 'R', N >= K >= 0. */
7143
7144 /* A (input) DOUBLE PRECISION array, dimension (LDA,K) */
7145 /* The i-th column must contain the vector which defines the */
7146 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
7147 /* DGEQRF in the first k columns of its array argument A. */
7148 /* A is modified by the routine but restored on exit. */
7149
7150 /* LDA (input) INTEGER */
7151 /* The leading dimension of the array A. */
7152 /* If SIDE = 'L', LDA >= max(1,M); */
7153 /* if SIDE = 'R', LDA >= max(1,N). */
7154
7155 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
7156 /* TAU(i) must contain the scalar factor of the elementary */
7157 /* reflector H(i), as returned by DGEQRF. */
7158
7159 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
7160 /* On entry, the m by n matrix C. */
7161 /* On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q. */
7162
7163 /* LDC (input) INTEGER */
7164 /* The leading dimension of the array C. LDC >= max(1,M). */
7165
7166 /* WORK (workspace) DOUBLE PRECISION array, dimension */
7167 /* (N) if SIDE = 'L', */
7168 /* (M) if SIDE = 'R' */
7169
7170 /* INFO (output) INTEGER */
7171 /* = 0: successful exit */
7172 /* < 0: if INFO = -i, the i-th argument had an illegal value */
7173
7174 /* ===================================================================== */
7175
7176 /* .. Parameters .. */
7177 /* .. */
7178 /* .. Local Scalars .. */
7179 /* .. */
7180 /* .. External Functions .. */
7181 /* .. */
7182 /* .. External Subroutines .. */
7183 /* .. */
7184 /* .. Intrinsic Functions .. */
7185 /* .. */
7186 /* .. Executable Statements .. */
7187
7188 /* Test the input arguments */
7189
7190 /* Parameter adjustments */
7191 a_dim1 = *lda;
7192 a_offset = 1 + a_dim1;
7193 a -= a_offset;
7194 --tau;
7195 c_dim1 = *ldc;
7196 c_offset = 1 + c_dim1;
7197 c__ -= c_offset;
7198 --work;
7199
7200 /* Function Body */
7201 *info = 0;
7202 left = lsame_(side, "L");
7203 notran = lsame_(trans, "N");
7204
7205 /* NQ is the order of Q */
7206
7207 if (left) {
7208 nq = *m;
7209 } else {
7210 nq = *n;
7211 }
7212 if (! left && ! lsame_(side, "R")) {
7213 *info = -1;
7214 } else if (! notran && ! lsame_(trans, "T")) {
7215 *info = -2;
7216 } else if (*m < 0) {
7217 *info = -3;
7218 } else if (*n < 0) {
7219 *info = -4;
7220 } else if (*k < 0 || *k > nq) {
7221 *info = -5;
7222 } else if (*lda < std::max(1_integer,nq)) {
7223 *info = -7;
7224 } else if (*ldc < std::max(1_integer,*m)) {
7225 *info = -10;
7226 }
7227 if (*info != 0) {
7228 i__1 = -(*info);
7229 xerbla_("DORM2R", &i__1);
7230 return 0;
7231 }
7232
7233 /* Quick return if possible */
7234
7235 if (*m == 0 || *n == 0 || *k == 0) {
7236 return 0;
7237 }
7238
7239 if (left && ! notran || ! left && notran) {
7240 i1 = 1;
7241 i2 = *k;
7242 i3 = 1;
7243 } else {
7244 i1 = *k;
7245 i2 = 1;
7246 i3 = -1;
7247 }
7248
7249 if (left) {
7250 ni = *n;
7251 jc = 1;
7252 } else {
7253 mi = *m;
7254 ic = 1;
7255 }
7256
7257 i__1 = i2;
7258 i__2 = i3;
7259 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
7260 if (left) {
7261
7262 /* H(i) is applied to C(i:m,1:n) */
7263
7264 mi = *m - i__ + 1;
7265 ic = i__;
7266 } else {
7267
7268 /* H(i) is applied to C(1:m,i:n) */
7269
7270 ni = *n - i__ + 1;
7271 jc = i__;
7272 }
7273
7274 /* Apply H(i) */
7275
7276 aii = a[i__ + i__ * a_dim1];
7277 a[i__ + i__ * a_dim1] = 1.;
7278 dlarf_(side, &mi, &ni, &a[i__ + i__ * a_dim1], &c__1, &tau[i__], &c__[
7279 ic + jc * c_dim1], ldc, &work[1]);
7280 a[i__ + i__ * a_dim1] = aii;
7281 /* L10: */
7282 }
7283 return 0;
7284
7285 /* End of DORM2R */
7286
7287 } /* dorm2r_ */
7288
7289 /* Subroutine */ int dormbr_(const char *vect, const char *side, const char *trans, integer *m,
7290 integer *n, integer *k, double *a, integer *lda, double *tau,
7291 double *c__, integer *ldc, double *work, integer *lwork,
7292 integer *info)
7293 {
7294 /* Table of constant values */
7295 static integer c__1 = 1;
7296 static integer c_n1 = -1;
7297 static integer c__2 = 2;
7298
7299 /* System generated locals */
7300 char * a__1[2];
7301 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2];
7302 char ch__1[3];
7303
7304 /* Local variables */
7305 integer i1, i2, nb, mi, ni, nq, nw;
7306 bool left;
7307 integer iinfo;
7308 bool notran;
7309 bool applyq;
7310 char transt[1];
7311 integer lwkopt;
7312 bool lquery;
7313
7314
7315 /* -- LAPACK routine (version 3.1) -- */
7316 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
7317 /* November 2006 */
7318
7319 /* .. Scalar Arguments .. */
7320 /* .. */
7321 /* .. Array Arguments .. */
7322 /* .. */
7323
7324 /* Purpose */
7325 /* ======= */
7326
7327 /* If VECT = 'Q', DORMBR overwrites the general real M-by-N matrix C */
7328 /* with */
7329 /* SIDE = 'L' SIDE = 'R' */
7330 /* TRANS = 'N': Q * C C * Q */
7331 /* TRANS = 'T': Q**T * C C * Q**T */
7332
7333 /* If VECT = 'P', DORMBR overwrites the general real M-by-N matrix C */
7334 /* with */
7335 /* SIDE = 'L' SIDE = 'R' */
7336 /* TRANS = 'N': P * C C * P */
7337 /* TRANS = 'T': P**T * C C * P**T */
7338
7339 /* Here Q and P**T are the orthogonal matrices determined by DGEBRD when */
7340 /* reducing a real matrix A to bidiagonal form: A = Q * B * P**T. Q and */
7341 /* P**T are defined as products of elementary reflectors H(i) and G(i) */
7342 /* respectively. */
7343
7344 /* Let nq = m if SIDE = 'L' and nq = n if SIDE = 'R'. Thus nq is the */
7345 /* order of the orthogonal matrix Q or P**T that is applied. */
7346
7347 /* If VECT = 'Q', A is assumed to have been an NQ-by-K matrix: */
7348 /* if nq >= k, Q = H(1) H(2) . . . H(k); */
7349 /* if nq < k, Q = H(1) H(2) . . . H(nq-1). */
7350
7351 /* If VECT = 'P', A is assumed to have been a K-by-NQ matrix: */
7352 /* if k < nq, P = G(1) G(2) . . . G(k); */
7353 /* if k >= nq, P = G(1) G(2) . . . G(nq-1). */
7354
7355 /* Arguments */
7356 /* ========= */
7357
7358 /* VECT (input) CHARACTER*1 */
7359 /* = 'Q': apply Q or Q**T; */
7360 /* = 'P': apply P or P**T. */
7361
7362 /* SIDE (input) CHARACTER*1 */
7363 /* = 'L': apply Q, Q**T, P or P**T from the Left; */
7364 /* = 'R': apply Q, Q**T, P or P**T from the Right. */
7365
7366 /* TRANS (input) CHARACTER*1 */
7367 /* = 'N': No transpose, apply Q or P; */
7368 /* = 'T': Transpose, apply Q**T or P**T. */
7369
7370 /* M (input) INTEGER */
7371 /* The number of rows of the matrix C. M >= 0. */
7372
7373 /* N (input) INTEGER */
7374 /* The number of columns of the matrix C. N >= 0. */
7375
7376 /* K (input) INTEGER */
7377 /* If VECT = 'Q', the number of columns in the original */
7378 /* matrix reduced by DGEBRD. */
7379 /* If VECT = 'P', the number of rows in the original */
7380 /* matrix reduced by DGEBRD. */
7381 /* K >= 0. */
7382
7383 /* A (input) DOUBLE PRECISION array, dimension */
7384 /* (LDA,min(nq,K)) if VECT = 'Q' */
7385 /* (LDA,nq) if VECT = 'P' */
7386 /* The vectors which define the elementary reflectors H(i) and */
7387 /* G(i), whose products determine the matrices Q and P, as */
7388 /* returned by DGEBRD. */
7389
7390 /* LDA (input) INTEGER */
7391 /* The leading dimension of the array A. */
7392 /* If VECT = 'Q', LDA >= max(1,nq); */
7393 /* if VECT = 'P', LDA >= max(1,min(nq,K)). */
7394
7395 /* TAU (input) DOUBLE PRECISION array, dimension (min(nq,K)) */
7396 /* TAU(i) must contain the scalar factor of the elementary */
7397 /* reflector H(i) or G(i) which determines Q or P, as returned */
7398 /* by DGEBRD in the array argument TAUQ or TAUP. */
7399
7400 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
7401 /* On entry, the M-by-N matrix C. */
7402 /* On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q */
7403 /* or P*C or P**T*C or C*P or C*P**T. */
7404
7405 /* LDC (input) INTEGER */
7406 /* The leading dimension of the array C. LDC >= max(1,M). */
7407
7408 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
7409 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
7410
7411 /* LWORK (input) INTEGER */
7412 /* The dimension of the array WORK. */
7413 /* If SIDE = 'L', LWORK >= max(1,N); */
7414 /* if SIDE = 'R', LWORK >= max(1,M). */
7415 /* For optimum performance LWORK >= N*NB if SIDE = 'L', and */
7416 /* LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
7417 /* blocksize. */
7418
7419 /* If LWORK = -1, then a workspace query is assumed; the routine */
7420 /* only calculates the optimal size of the WORK array, returns */
7421 /* this value as the first entry of the WORK array, and no error */
7422 /* message related to LWORK is issued by XERBLA. */
7423
7424 /* INFO (output) INTEGER */
7425 /* = 0: successful exit */
7426 /* < 0: if INFO = -i, the i-th argument had an illegal value */
7427
7428 /* ===================================================================== */
7429
7430 /* .. Local Scalars .. */
7431 /* .. */
7432 /* .. External Functions .. */
7433 /* .. */
7434 /* .. External Subroutines .. */
7435 /* .. */
7436 /* .. Intrinsic Functions .. */
7437 /* .. */
7438 /* .. Executable Statements .. */
7439
7440 /* Test the input arguments */
7441
7442 /* Parameter adjustments */
7443 a_dim1 = *lda;
7444 a_offset = 1 + a_dim1;
7445 a -= a_offset;
7446 --tau;
7447 c_dim1 = *ldc;
7448 c_offset = 1 + c_dim1;
7449 c__ -= c_offset;
7450 --work;
7451
7452 /* Function Body */
7453 *info = 0;
7454 applyq = lsame_(vect, "Q");
7455 left = lsame_(side, "L");
7456 notran = lsame_(trans, "N");
7457 lquery = *lwork == -1;
7458
7459 /* NQ is the order of Q or P and NW is the minimum dimension of WORK */
7460
7461 if (left) {
7462 nq = *m;
7463 nw = *n;
7464 } else {
7465 nq = *n;
7466 nw = *m;
7467 }
7468 if (! applyq && ! lsame_(vect, "P")) {
7469 *info = -1;
7470 } else if (! left && ! lsame_(side, "R")) {
7471 *info = -2;
7472 } else if (! notran && ! lsame_(trans, "T")) {
7473 *info = -3;
7474 } else if (*m < 0) {
7475 *info = -4;
7476 } else if (*n < 0) {
7477 *info = -5;
7478 } else if (*k < 0) {
7479 *info = -6;
7480 } else /* if(complicated condition) */ {
7481 /* Computing MAX */
7482 i__1 = 1, i__2 = std::min(nq,*k);
7483 if (applyq && *lda < std::max(1_integer,nq) || ! applyq && *lda < std::max(i__1,i__2)) {
7484 *info = -8;
7485 } else if (*ldc < std::max(1_integer,*m)) {
7486 *info = -11;
7487 } else if (*lwork < std::max(1_integer,nw) && ! lquery) {
7488 *info = -13;
7489 }
7490 }
7491
7492 if (*info == 0) {
7493 if (applyq) {
7494 if (left) {
7495 /* Writing concatenation */
7496 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
7497 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
7498 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
7499 ch__1 [2] = '\0';
7500 i__1 = *m - 1;
7501 i__2 = *m - 1;
7502 nb = ilaenv_(&c__1, "DORMQR", ch__1, &i__1, n, &i__2, &c_n1);
7503 } else {
7504 /* Writing concatenation */
7505 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
7506 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
7507 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
7508 ch__1 [2] = '\0';
7509 i__1 = *n - 1;
7510 i__2 = *n - 1;
7511 nb = ilaenv_(&c__1, "DORMQR", ch__1, m, &i__1, &i__2, &c_n1);
7512 }
7513 } else {
7514 if (left) {
7515 /* Writing concatenation */
7516 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
7517 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
7518 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
7519 ch__1 [2] = '\0';
7520 i__1 = *m - 1;
7521 i__2 = *m - 1;
7522 nb = ilaenv_(&c__1, "DORMLQ", ch__1, &i__1, n, &i__2, &c_n1);
7523 } else {
7524 /* Writing concatenation */
7525 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
7526 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
7527 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
7528 ch__1 [2] = '\0';
7529 i__1 = *n - 1;
7530 i__2 = *n - 1;
7531 nb = ilaenv_(&c__1, "DORMLQ", ch__1, m, &i__1, &i__2, &c_n1);
7532 }
7533 }
7534 lwkopt = std::max(1_integer,nw) * nb;
7535 work[1] = (double) lwkopt;
7536 }
7537
7538 if (*info != 0) {
7539 i__1 = -(*info);
7540 xerbla_("DORMBR", &i__1);
7541 return 0;
7542 } else if (lquery) {
7543 return 0;
7544 }
7545
7546 /* Quick return if possible */
7547
7548 work[1] = 1.;
7549 if (*m == 0 || *n == 0) {
7550 return 0;
7551 }
7552
7553 if (applyq) {
7554
7555 /* Apply Q */
7556
7557 if (nq >= *k) {
7558
7559 /* Q was determined by a call to DGEBRD with nq >= k */
7560
7561 dormqr_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
7562 c_offset], ldc, &work[1], lwork, &iinfo);
7563 } else if (nq > 1) {
7564
7565 /* Q was determined by a call to DGEBRD with nq < k */
7566
7567 if (left) {
7568 mi = *m - 1;
7569 ni = *n;
7570 i1 = 2;
7571 i2 = 1;
7572 } else {
7573 mi = *m;
7574 ni = *n - 1;
7575 i1 = 1;
7576 i2 = 2;
7577 }
7578 i__1 = nq - 1;
7579 dormqr_(side, trans, &mi, &ni, &i__1, &a[a_dim1 + 2], lda, &tau[1]
7580 , &c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &iinfo);
7581 }
7582 } else {
7583
7584 /* Apply P */
7585
7586 if (notran) {
7587 *(unsigned char *)transt = 'T';
7588 } else {
7589 *(unsigned char *)transt = 'N';
7590 }
7591 if (nq > *k) {
7592
7593 /* P was determined by a call to DGEBRD with nq > k */
7594
7595 dormlq_(side, transt, m, n, k, &a[a_offset], lda, &tau[1], &c__[
7596 c_offset], ldc, &work[1], lwork, &iinfo);
7597 } else if (nq > 1) {
7598
7599 /* P was determined by a call to DGEBRD with nq <= k */
7600
7601 if (left) {
7602 mi = *m - 1;
7603 ni = *n;
7604 i1 = 2;
7605 i2 = 1;
7606 } else {
7607 mi = *m;
7608 ni = *n - 1;
7609 i1 = 1;
7610 i2 = 2;
7611 }
7612 i__1 = nq - 1;
7613 dormlq_(side, transt, &mi, &ni, &i__1, &a[(a_dim1 << 1) + 1], lda,
7614 &tau[1], &c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &
7615 iinfo);
7616 }
7617 }
7618 work[1] = (double) lwkopt;
7619 return 0;
7620
7621 /* End of DORMBR */
7622
7623 } /* dormbr_ */
7624
7625 /* Subroutine */ int dormhr_(const char *side, const char *trans, integer *m, integer *n,
7626 integer *ilo, integer *ihi, double *a, integer *lda, double *
7627 tau, double *c__, integer *ldc, double *work, integer *lwork,
7628 integer *info)
7629 {
7630 /* Table of constant values */
7631 static integer c__1 = 1;
7632 static integer c_n1 = -1;
7633 static integer c__2 = 2;
7634
7635 /* System generated locals */
7636 char * a__1[2];
7637 integer a_dim1, a_offset, c_dim1, c_offset, i__1[2], i__2;
7638 char ch__1[3];
7639
7640 /* Local variables */
7641 integer i1, i2, nb, mi, nh, ni, nq, nw;
7642 bool left;
7643 integer iinfo;
7644 integer lwkopt;
7645 bool lquery;
7646
7647
7648 /* -- LAPACK routine (version 3.1) -- */
7649 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
7650 /* November 2006 */
7651
7652 /* .. Scalar Arguments .. */
7653 /* .. */
7654 /* .. Array Arguments .. */
7655 /* .. */
7656
7657 /* Purpose */
7658 /* ======= */
7659
7660 /* DORMHR overwrites the general real M-by-N matrix C with */
7661
7662 /* SIDE = 'L' SIDE = 'R' */
7663 /* TRANS = 'N': Q * C C * Q */
7664 /* TRANS = 'T': Q**T * C C * Q**T */
7665
7666 /* where Q is a real orthogonal matrix of order nq, with nq = m if */
7667 /* SIDE = 'L' and nq = n if SIDE = 'R'. Q is defined as the product of */
7668 /* IHI-ILO elementary reflectors, as returned by DGEHRD: */
7669
7670 /* Q = H(ilo) H(ilo+1) . . . H(ihi-1). */
7671
7672 /* Arguments */
7673 /* ========= */
7674
7675 /* SIDE (input) CHARACTER*1 */
7676 /* = 'L': apply Q or Q**T from the Left; */
7677 /* = 'R': apply Q or Q**T from the Right. */
7678
7679 /* TRANS (input) CHARACTER*1 */
7680 /* = 'N': No transpose, apply Q; */
7681 /* = 'T': Transpose, apply Q**T. */
7682
7683 /* M (input) INTEGER */
7684 /* The number of rows of the matrix C. M >= 0. */
7685
7686 /* N (input) INTEGER */
7687 /* The number of columns of the matrix C. N >= 0. */
7688
7689 /* ILO (input) INTEGER */
7690 /* IHI (input) INTEGER */
7691 /* ILO and IHI must have the same values as in the previous call */
7692 /* of DGEHRD. Q is equal to the unit matrix except in the */
7693 /* submatrix Q(ilo+1:ihi,ilo+1:ihi). */
7694 /* If SIDE = 'L', then 1 <= ILO <= IHI <= M, if M > 0, and */
7695 /* ILO = 1 and IHI = 0, if M = 0; */
7696 /* if SIDE = 'R', then 1 <= ILO <= IHI <= N, if N > 0, and */
7697 /* ILO = 1 and IHI = 0, if N = 0. */
7698
7699 /* A (input) DOUBLE PRECISION array, dimension */
7700 /* (LDA,M) if SIDE = 'L' */
7701 /* (LDA,N) if SIDE = 'R' */
7702 /* The vectors which define the elementary reflectors, as */
7703 /* returned by DGEHRD. */
7704
7705 /* LDA (input) INTEGER */
7706 /* The leading dimension of the array A. */
7707 /* LDA >= max(1,M) if SIDE = 'L'; LDA >= max(1,N) if SIDE = 'R'. */
7708
7709 /* TAU (input) DOUBLE PRECISION array, dimension */
7710 /* (M-1) if SIDE = 'L' */
7711 /* (N-1) if SIDE = 'R' */
7712 /* TAU(i) must contain the scalar factor of the elementary */
7713 /* reflector H(i), as returned by DGEHRD. */
7714
7715 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
7716 /* On entry, the M-by-N matrix C. */
7717 /* On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */
7718
7719 /* LDC (input) INTEGER */
7720 /* The leading dimension of the array C. LDC >= max(1,M). */
7721
7722 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
7723 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
7724
7725 /* LWORK (input) INTEGER */
7726 /* The dimension of the array WORK. */
7727 /* If SIDE = 'L', LWORK >= max(1,N); */
7728 /* if SIDE = 'R', LWORK >= max(1,M). */
7729 /* For optimum performance LWORK >= N*NB if SIDE = 'L', and */
7730 /* LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
7731 /* blocksize. */
7732
7733 /* If LWORK = -1, then a workspace query is assumed; the routine */
7734 /* only calculates the optimal size of the WORK array, returns */
7735 /* this value as the first entry of the WORK array, and no error */
7736 /* message related to LWORK is issued by XERBLA. */
7737
7738 /* INFO (output) INTEGER */
7739 /* = 0: successful exit */
7740 /* < 0: if INFO = -i, the i-th argument had an illegal value */
7741
7742 /* ===================================================================== */
7743
7744 /* .. Local Scalars .. */
7745 /* .. */
7746 /* .. External Functions .. */
7747 /* .. */
7748 /* .. External Subroutines .. */
7749 /* .. */
7750 /* .. Intrinsic Functions .. */
7751 /* .. */
7752 /* .. Executable Statements .. */
7753
7754 /* Test the input arguments */
7755
7756 /* Parameter adjustments */
7757 a_dim1 = *lda;
7758 a_offset = 1 + a_dim1;
7759 a -= a_offset;
7760 --tau;
7761 c_dim1 = *ldc;
7762 c_offset = 1 + c_dim1;
7763 c__ -= c_offset;
7764 --work;
7765
7766 /* Function Body */
7767 *info = 0;
7768 nh = *ihi - *ilo;
7769 left = lsame_(side, "L");
7770 lquery = *lwork == -1;
7771
7772 /* NQ is the order of Q and NW is the minimum dimension of WORK */
7773
7774 if (left) {
7775 nq = *m;
7776 nw = *n;
7777 } else {
7778 nq = *n;
7779 nw = *m;
7780 }
7781 if (! left && ! lsame_(side, "R")) {
7782 *info = -1;
7783 } else if (! lsame_(trans, "N") && ! lsame_(trans,
7784 "T")) {
7785 *info = -2;
7786 } else if (*m < 0) {
7787 *info = -3;
7788 } else if (*n < 0) {
7789 *info = -4;
7790 } else if (*ilo < 1 || *ilo > std::max(1_integer,nq)) {
7791 *info = -5;
7792 } else if (*ihi < std::min(*ilo,nq) || *ihi > nq) {
7793 *info = -6;
7794 } else if (*lda < std::max(1_integer,nq)) {
7795 *info = -8;
7796 } else if (*ldc < std::max(1_integer,*m)) {
7797 *info = -11;
7798 } else if (*lwork < std::max(1_integer,nw) && ! lquery) {
7799 *info = -13;
7800 }
7801
7802 if (*info == 0) {
7803 if (left) {
7804 /* Writing concatenation */
7805 i__1[0] = 1, a__1[0] = const_cast<char *> (side);
7806 i__1[1] = 1, a__1[1] = const_cast<char *> (trans);
7807 s_cat(ch__1, a__1, i__1, &c__2, 2_integer);
7808 ch__1 [2] = '\0';
7809 nb = ilaenv_(&c__1, "DORMQR", ch__1, &nh, n, &nh, &c_n1);
7810 } else {
7811 /* Writing concatenation */
7812 i__1[0] = 1, a__1[0] = const_cast<char *> (side);
7813 i__1[1] = 1, a__1[1] = const_cast<char *> (trans);
7814 s_cat(ch__1, a__1, i__1, &c__2, 2_integer);
7815 ch__1 [2] = '\0';
7816 nb = ilaenv_(&c__1, "DORMQR", ch__1, m, &nh, &nh, &c_n1);
7817 }
7818 lwkopt = std::max(1_integer,nw) * nb;
7819 work[1] = (double) lwkopt;
7820 }
7821
7822 if (*info != 0) {
7823 i__2 = -(*info);
7824 xerbla_("DORMHR", &i__2);
7825 return 0;
7826 } else if (lquery) {
7827 return 0;
7828 }
7829
7830 /* Quick return if possible */
7831
7832 if (*m == 0 || *n == 0 || nh == 0) {
7833 work[1] = 1.;
7834 return 0;
7835 }
7836
7837 if (left) {
7838 mi = nh;
7839 ni = *n;
7840 i1 = *ilo + 1;
7841 i2 = 1;
7842 } else {
7843 mi = *m;
7844 ni = nh;
7845 i1 = 1;
7846 i2 = *ilo + 1;
7847 }
7848
7849 dormqr_(side, trans, &mi, &ni, &nh, &a[*ilo + 1 + *ilo * a_dim1], lda, &
7850 tau[*ilo], &c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &iinfo);
7851
7852 work[1] = (double) lwkopt;
7853 return 0;
7854
7855 /* End of DORMHR */
7856
7857 } /* dormhr_ */
7858
7859 /* Subroutine */ int dorml2_(const char *side, const char *trans, integer *m, integer *n,
7860 integer *k, double *a, integer *lda, double *tau, double *
7861 c__, integer *ldc, double *work, integer *info)
7862 {
7863 /* System generated locals */
7864 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2;
7865
7866 /* Local variables */
7867 integer i__, i1, i2, i3, ic, jc, mi, ni, nq;
7868 double aii;
7869 bool left;
7870 bool notran;
7871
7872
7873 /* -- LAPACK routine (version 3.1) -- */
7874 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
7875 /* November 2006 */
7876
7877 /* .. Scalar Arguments .. */
7878 /* .. */
7879 /* .. Array Arguments .. */
7880 /* .. */
7881
7882 /* Purpose */
7883 /* ======= */
7884
7885 /* DORML2 overwrites the general real m by n matrix C with */
7886
7887 /* Q * C if SIDE = 'L' and TRANS = 'N', or */
7888
7889 /* Q'* C if SIDE = 'L' and TRANS = 'T', or */
7890
7891 /* C * Q if SIDE = 'R' and TRANS = 'N', or */
7892
7893 /* C * Q' if SIDE = 'R' and TRANS = 'T', */
7894
7895 /* where Q is a real orthogonal matrix defined as the product of k */
7896 /* elementary reflectors */
7897
7898 /* Q = H(k) . . . H(2) H(1) */
7899
7900 /* as returned by DGELQF. Q is of order m if SIDE = 'L' and of order n */
7901 /* if SIDE = 'R'. */
7902
7903 /* Arguments */
7904 /* ========= */
7905
7906 /* SIDE (input) CHARACTER*1 */
7907 /* = 'L': apply Q or Q' from the Left */
7908 /* = 'R': apply Q or Q' from the Right */
7909
7910 /* TRANS (input) CHARACTER*1 */
7911 /* = 'N': apply Q (No transpose) */
7912 /* = 'T': apply Q' (Transpose) */
7913
7914 /* M (input) INTEGER */
7915 /* The number of rows of the matrix C. M >= 0. */
7916
7917 /* N (input) INTEGER */
7918 /* The number of columns of the matrix C. N >= 0. */
7919
7920 /* K (input) INTEGER */
7921 /* The number of elementary reflectors whose product defines */
7922 /* the matrix Q. */
7923 /* If SIDE = 'L', M >= K >= 0; */
7924 /* if SIDE = 'R', N >= K >= 0. */
7925
7926 /* A (input) DOUBLE PRECISION array, dimension */
7927 /* (LDA,M) if SIDE = 'L', */
7928 /* (LDA,N) if SIDE = 'R' */
7929 /* The i-th row must contain the vector which defines the */
7930 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
7931 /* DGELQF in the first k rows of its array argument A. */
7932 /* A is modified by the routine but restored on exit. */
7933
7934 /* LDA (input) INTEGER */
7935 /* The leading dimension of the array A. LDA >= max(1,K). */
7936
7937 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
7938 /* TAU(i) must contain the scalar factor of the elementary */
7939 /* reflector H(i), as returned by DGELQF. */
7940
7941 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
7942 /* On entry, the m by n matrix C. */
7943 /* On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q. */
7944
7945 /* LDC (input) INTEGER */
7946 /* The leading dimension of the array C. LDC >= max(1,M). */
7947
7948 /* WORK (workspace) DOUBLE PRECISION array, dimension */
7949 /* (N) if SIDE = 'L', */
7950 /* (M) if SIDE = 'R' */
7951
7952 /* INFO (output) INTEGER */
7953 /* = 0: successful exit */
7954 /* < 0: if INFO = -i, the i-th argument had an illegal value */
7955
7956 /* ===================================================================== */
7957
7958 /* .. Parameters .. */
7959 /* .. */
7960 /* .. Local Scalars .. */
7961 /* .. */
7962 /* .. External Functions .. */
7963 /* .. */
7964 /* .. External Subroutines .. */
7965 /* .. */
7966 /* .. Intrinsic Functions .. */
7967 /* .. */
7968 /* .. Executable Statements .. */
7969
7970 /* Test the input arguments */
7971
7972 /* Parameter adjustments */
7973 a_dim1 = *lda;
7974 a_offset = 1 + a_dim1;
7975 a -= a_offset;
7976 --tau;
7977 c_dim1 = *ldc;
7978 c_offset = 1 + c_dim1;
7979 c__ -= c_offset;
7980 --work;
7981
7982 /* Function Body */
7983 *info = 0;
7984 left = lsame_(side, "L");
7985 notran = lsame_(trans, "N");
7986
7987 /* NQ is the order of Q */
7988
7989 if (left) {
7990 nq = *m;
7991 } else {
7992 nq = *n;
7993 }
7994 if (! left && ! lsame_(side, "R")) {
7995 *info = -1;
7996 } else if (! notran && ! lsame_(trans, "T")) {
7997 *info = -2;
7998 } else if (*m < 0) {
7999 *info = -3;
8000 } else if (*n < 0) {
8001 *info = -4;
8002 } else if (*k < 0 || *k > nq) {
8003 *info = -5;
8004 } else if (*lda < std::max(1_integer,*k)) {
8005 *info = -7;
8006 } else if (*ldc < std::max(1_integer,*m)) {
8007 *info = -10;
8008 }
8009 if (*info != 0) {
8010 i__1 = -(*info);
8011 xerbla_("DORML2", &i__1);
8012 return 0;
8013 }
8014
8015 /* Quick return if possible */
8016
8017 if (*m == 0 || *n == 0 || *k == 0) {
8018 return 0;
8019 }
8020
8021 if (left && notran || ! left && ! notran) {
8022 i1 = 1;
8023 i2 = *k;
8024 i3 = 1;
8025 } else {
8026 i1 = *k;
8027 i2 = 1;
8028 i3 = -1;
8029 }
8030
8031 if (left) {
8032 ni = *n;
8033 jc = 1;
8034 } else {
8035 mi = *m;
8036 ic = 1;
8037 }
8038
8039 i__1 = i2;
8040 i__2 = i3;
8041 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
8042 if (left) {
8043
8044 /* H(i) is applied to C(i:m,1:n) */
8045
8046 mi = *m - i__ + 1;
8047 ic = i__;
8048 } else {
8049
8050 /* H(i) is applied to C(1:m,i:n) */
8051
8052 ni = *n - i__ + 1;
8053 jc = i__;
8054 }
8055
8056 /* Apply H(i) */
8057
8058 aii = a[i__ + i__ * a_dim1];
8059 a[i__ + i__ * a_dim1] = 1.;
8060 dlarf_(side, &mi, &ni, &a[i__ + i__ * a_dim1], lda, &tau[i__], &c__[
8061 ic + jc * c_dim1], ldc, &work[1]);
8062 a[i__ + i__ * a_dim1] = aii;
8063 /* L10: */
8064 }
8065 return 0;
8066
8067 /* End of DORML2 */
8068
8069 } /* dorml2_ */
8070
8071 /* Subroutine */ int dormlq_(const char *side, const char *trans, integer *m, integer *n,
8072 integer *k, double *a, integer *lda, double *tau, double *
8073 c__, integer *ldc, double *work, integer *lwork, integer *info)
8074 {
8075 /* Table of constant values */
8076 static integer c__1 = 1;
8077 static integer c_n1 = -1;
8078 static integer c__2 = 2;
8079 static integer c__65 = 65;
8080
8081 /* System generated locals */
8082 char * a__1[2];
8083 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
8084 i__5;
8085 char ch__1[3];
8086
8087 /* Local variables */
8088 integer i__;
8089 double t[4160] /* was [65][64] */;
8090 integer i1, i2, i3, ib, ic, jc, nb, mi, ni, nq, nw, iws;
8091 bool left;
8092 integer nbmin, iinfo;
8093 bool notran;
8094 integer ldwork;
8095 char transt[1];
8096 integer lwkopt;
8097 bool lquery;
8098
8099
8100 /* -- LAPACK routine (version 3.1) -- */
8101 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
8102 /* November 2006 */
8103
8104 /* .. Scalar Arguments .. */
8105 /* .. */
8106 /* .. Array Arguments .. */
8107 /* .. */
8108
8109 /* Purpose */
8110 /* ======= */
8111
8112 /* DORMLQ overwrites the general real M-by-N matrix C with */
8113
8114 /* SIDE = 'L' SIDE = 'R' */
8115 /* TRANS = 'N': Q * C C * Q */
8116 /* TRANS = 'T': Q**T * C C * Q**T */
8117
8118 /* where Q is a real orthogonal matrix defined as the product of k */
8119 /* elementary reflectors */
8120
8121 /* Q = H(k) . . . H(2) H(1) */
8122
8123 /* as returned by DGELQF. Q is of order M if SIDE = 'L' and of order N */
8124 /* if SIDE = 'R'. */
8125
8126 /* Arguments */
8127 /* ========= */
8128
8129 /* SIDE (input) CHARACTER*1 */
8130 /* = 'L': apply Q or Q**T from the Left; */
8131 /* = 'R': apply Q or Q**T from the Right. */
8132
8133 /* TRANS (input) CHARACTER*1 */
8134 /* = 'N': No transpose, apply Q; */
8135 /* = 'T': Transpose, apply Q**T. */
8136
8137 /* M (input) INTEGER */
8138 /* The number of rows of the matrix C. M >= 0. */
8139
8140 /* N (input) INTEGER */
8141 /* The number of columns of the matrix C. N >= 0. */
8142
8143 /* K (input) INTEGER */
8144 /* The number of elementary reflectors whose product defines */
8145 /* the matrix Q. */
8146 /* If SIDE = 'L', M >= K >= 0; */
8147 /* if SIDE = 'R', N >= K >= 0. */
8148
8149 /* A (input) DOUBLE PRECISION array, dimension */
8150 /* (LDA,M) if SIDE = 'L', */
8151 /* (LDA,N) if SIDE = 'R' */
8152 /* The i-th row must contain the vector which defines the */
8153 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
8154 /* DGELQF in the first k rows of its array argument A. */
8155 /* A is modified by the routine but restored on exit. */
8156
8157 /* LDA (input) INTEGER */
8158 /* The leading dimension of the array A. LDA >= max(1,K). */
8159
8160 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
8161 /* TAU(i) must contain the scalar factor of the elementary */
8162 /* reflector H(i), as returned by DGELQF. */
8163
8164 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
8165 /* On entry, the M-by-N matrix C. */
8166 /* On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */
8167
8168 /* LDC (input) INTEGER */
8169 /* The leading dimension of the array C. LDC >= max(1,M). */
8170
8171 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
8172 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
8173
8174 /* LWORK (input) INTEGER */
8175 /* The dimension of the array WORK. */
8176 /* If SIDE = 'L', LWORK >= max(1,N); */
8177 /* if SIDE = 'R', LWORK >= max(1,M). */
8178 /* For optimum performance LWORK >= N*NB if SIDE = 'L', and */
8179 /* LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
8180 /* blocksize. */
8181
8182 /* If LWORK = -1, then a workspace query is assumed; the routine */
8183 /* only calculates the optimal size of the WORK array, returns */
8184 /* this value as the first entry of the WORK array, and no error */
8185 /* message related to LWORK is issued by XERBLA. */
8186
8187 /* INFO (output) INTEGER */
8188 /* = 0: successful exit */
8189 /* < 0: if INFO = -i, the i-th argument had an illegal value */
8190
8191 /* ===================================================================== */
8192
8193 /* .. Parameters .. */
8194 /* .. */
8195 /* .. Local Scalars .. */
8196 /* .. */
8197 /* .. Local Arrays .. */
8198 /* .. */
8199 /* .. External Functions .. */
8200 /* .. */
8201 /* .. External Subroutines .. */
8202 /* .. */
8203 /* .. Intrinsic Functions .. */
8204 /* .. */
8205 /* .. Executable Statements .. */
8206
8207 /* Test the input arguments */
8208
8209 /* Parameter adjustments */
8210 a_dim1 = *lda;
8211 a_offset = 1 + a_dim1;
8212 a -= a_offset;
8213 --tau;
8214 c_dim1 = *ldc;
8215 c_offset = 1 + c_dim1;
8216 c__ -= c_offset;
8217 --work;
8218
8219 /* Function Body */
8220 *info = 0;
8221 left = lsame_(side, "L");
8222 notran = lsame_(trans, "N");
8223 lquery = *lwork == -1;
8224
8225 /* NQ is the order of Q and NW is the minimum dimension of WORK */
8226
8227 if (left) {
8228 nq = *m;
8229 nw = *n;
8230 } else {
8231 nq = *n;
8232 nw = *m;
8233 }
8234 if (! left && ! lsame_(side, "R")) {
8235 *info = -1;
8236 } else if (! notran && ! lsame_(trans, "T")) {
8237 *info = -2;
8238 } else if (*m < 0) {
8239 *info = -3;
8240 } else if (*n < 0) {
8241 *info = -4;
8242 } else if (*k < 0 || *k > nq) {
8243 *info = -5;
8244 } else if (*lda < std::max(1_integer,*k)) {
8245 *info = -7;
8246 } else if (*ldc < std::max(1_integer,*m)) {
8247 *info = -10;
8248 } else if (*lwork < std::max(1_integer,nw) && ! lquery) {
8249 *info = -12;
8250 }
8251
8252 if (*info == 0) {
8253
8254 /* Determine the block size. NB may be at most NBMAX, where NBMAX */
8255 /* is used to define the local array T. */
8256
8257 /* Computing MIN */
8258 /* Writing concatenation */
8259 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
8260 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
8261 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
8262 ch__1 [2] = '\0';
8263 i__1 = 64, i__2 = ilaenv_(&c__1, "DORMLQ", ch__1, m, n, k, &c_n1);
8264 nb = std::min(i__1,i__2);
8265 lwkopt = std::max(1_integer,nw) * nb;
8266 work[1] = (double) lwkopt;
8267 }
8268
8269 if (*info != 0) {
8270 i__1 = -(*info);
8271 xerbla_("DORMLQ", &i__1);
8272 return 0;
8273 } else if (lquery) {
8274 return 0;
8275 }
8276
8277 /* Quick return if possible */
8278
8279 if (*m == 0 || *n == 0 || *k == 0) {
8280 work[1] = 1.;
8281 return 0;
8282 }
8283
8284 nbmin = 2;
8285 ldwork = nw;
8286 if (nb > 1 && nb < *k) {
8287 iws = nw * nb;
8288 if (*lwork < iws) {
8289 nb = *lwork / ldwork;
8290 /* Computing MAX */
8291 /* Writing concatenation */
8292 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
8293 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
8294 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
8295 ch__1 [2] = '\0';
8296 i__1 = 2, i__2 = ilaenv_(&c__2, "DORMLQ", ch__1, m, n, k, &c_n1);
8297 nbmin = std::max(i__1,i__2);
8298 }
8299 } else {
8300 iws = nw;
8301 }
8302
8303 if (nb < nbmin || nb >= *k) {
8304
8305 /* Use unblocked code */
8306
8307 dorml2_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
8308 c_offset], ldc, &work[1], &iinfo);
8309 } else {
8310
8311 /* Use blocked code */
8312
8313 if (left && notran || ! left && ! notran) {
8314 i1 = 1;
8315 i2 = *k;
8316 i3 = nb;
8317 } else {
8318 i1 = (*k - 1) / nb * nb + 1;
8319 i2 = 1;
8320 i3 = -nb;
8321 }
8322
8323 if (left) {
8324 ni = *n;
8325 jc = 1;
8326 } else {
8327 mi = *m;
8328 ic = 1;
8329 }
8330
8331 if (notran) {
8332 *(unsigned char *)transt = 'T';
8333 } else {
8334 *(unsigned char *)transt = 'N';
8335 }
8336
8337 i__1 = i2;
8338 i__2 = i3;
8339 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
8340 /* Computing MIN */
8341 i__4 = nb, i__5 = *k - i__ + 1;
8342 ib = std::min(i__4,i__5);
8343
8344 /* Form the triangular factor of the block reflector */
8345 /* H = H(i) H(i+1) . . . H(i+ib-1) */
8346
8347 i__4 = nq - i__ + 1;
8348 dlarft_("Forward", "Rowwise", &i__4, &ib, &a[i__ + i__ * a_dim1],
8349 lda, &tau[i__], t, &c__65);
8350 if (left) {
8351
8352 /* H or H' is applied to C(i:m,1:n) */
8353
8354 mi = *m - i__ + 1;
8355 ic = i__;
8356 } else {
8357
8358 /* H or H' is applied to C(1:m,i:n) */
8359
8360 ni = *n - i__ + 1;
8361 jc = i__;
8362 }
8363
8364 /* Apply H or H' */
8365
8366 dlarfb_(side, transt, "Forward", "Rowwise", &mi, &ni, &ib, &a[i__
8367 + i__ * a_dim1], lda, t, &c__65, &c__[ic + jc * c_dim1],
8368 ldc, &work[1], &ldwork);
8369 /* L10: */
8370 }
8371 }
8372 work[1] = (double) lwkopt;
8373 return 0;
8374
8375 /* End of DORMLQ */
8376
8377 } /* dormlq_ */
8378
8379 /* Subroutine */ int dormql_(const char *side, const char *trans, integer *m, integer *n,
8380 integer *k, double *a, integer *lda, double *tau, double *
8381 c__, integer *ldc, double *work, integer *lwork, integer *info)
8382 {
8383 /* Table of constant values */
8384 static integer c__1 = 1;
8385 static integer c_n1 = -1;
8386 static integer c__2 = 2;
8387 static integer c__65 = 65;
8388
8389 /* System generated locals */
8390 char * a__1[2];
8391 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
8392 i__5;
8393 char ch__1[3];
8394
8395 /* Local variables */
8396 integer i__;
8397 double t[4160] /* was [65][64] */;
8398 integer i1, i2, i3, ib, nb, mi, ni, nq, nw, iws;
8399 bool left;
8400 integer nbmin, iinfo;
8401 bool notran;
8402 integer ldwork, lwkopt;
8403 bool lquery;
8404
8405
8406 /* -- LAPACK routine (version 3.1) -- */
8407 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
8408 /* November 2006 */
8409
8410 /* .. Scalar Arguments .. */
8411 /* .. */
8412 /* .. Array Arguments .. */
8413 /* .. */
8414
8415 /* Purpose */
8416 /* ======= */
8417
8418 /* DORMQL overwrites the general real M-by-N matrix C with */
8419
8420 /* SIDE = 'L' SIDE = 'R' */
8421 /* TRANS = 'N': Q * C C * Q */
8422 /* TRANS = 'T': Q**T * C C * Q**T */
8423
8424 /* where Q is a real orthogonal matrix defined as the product of k */
8425 /* elementary reflectors */
8426
8427 /* Q = H(k) . . . H(2) H(1) */
8428
8429 /* as returned by DGEQLF. Q is of order M if SIDE = 'L' and of order N */
8430 /* if SIDE = 'R'. */
8431
8432 /* Arguments */
8433 /* ========= */
8434
8435 /* SIDE (input) CHARACTER*1 */
8436 /* = 'L': apply Q or Q**T from the Left; */
8437 /* = 'R': apply Q or Q**T from the Right. */
8438
8439 /* TRANS (input) CHARACTER*1 */
8440 /* = 'N': No transpose, apply Q; */
8441 /* = 'T': Transpose, apply Q**T. */
8442
8443 /* M (input) INTEGER */
8444 /* The number of rows of the matrix C. M >= 0. */
8445
8446 /* N (input) INTEGER */
8447 /* The number of columns of the matrix C. N >= 0. */
8448
8449 /* K (input) INTEGER */
8450 /* The number of elementary reflectors whose product defines */
8451 /* the matrix Q. */
8452 /* If SIDE = 'L', M >= K >= 0; */
8453 /* if SIDE = 'R', N >= K >= 0. */
8454
8455 /* A (input) DOUBLE PRECISION array, dimension (LDA,K) */
8456 /* The i-th column must contain the vector which defines the */
8457 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
8458 /* DGEQLF in the last k columns of its array argument A. */
8459 /* A is modified by the routine but restored on exit. */
8460
8461 /* LDA (input) INTEGER */
8462 /* The leading dimension of the array A. */
8463 /* If SIDE = 'L', LDA >= max(1,M); */
8464 /* if SIDE = 'R', LDA >= max(1,N). */
8465
8466 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
8467 /* TAU(i) must contain the scalar factor of the elementary */
8468 /* reflector H(i), as returned by DGEQLF. */
8469
8470 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
8471 /* On entry, the M-by-N matrix C. */
8472 /* On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */
8473
8474 /* LDC (input) INTEGER */
8475 /* The leading dimension of the array C. LDC >= max(1,M). */
8476
8477 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
8478 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
8479
8480 /* LWORK (input) INTEGER */
8481 /* The dimension of the array WORK. */
8482 /* If SIDE = 'L', LWORK >= max(1,N); */
8483 /* if SIDE = 'R', LWORK >= max(1,M). */
8484 /* For optimum performance LWORK >= N*NB if SIDE = 'L', and */
8485 /* LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
8486 /* blocksize. */
8487
8488 /* If LWORK = -1, then a workspace query is assumed; the routine */
8489 /* only calculates the optimal size of the WORK array, returns */
8490 /* this value as the first entry of the WORK array, and no error */
8491 /* message related to LWORK is issued by XERBLA. */
8492
8493 /* INFO (output) INTEGER */
8494 /* = 0: successful exit */
8495 /* < 0: if INFO = -i, the i-th argument had an illegal value */
8496
8497 /* ===================================================================== */
8498
8499 /* .. Parameters .. */
8500 /* .. */
8501 /* .. Local Scalars .. */
8502 /* .. */
8503 /* .. Local Arrays .. */
8504 /* .. */
8505 /* .. External Functions .. */
8506 /* .. */
8507 /* .. External Subroutines .. */
8508 /* .. */
8509 /* .. Intrinsic Functions .. */
8510 /* .. */
8511 /* .. Executable Statements .. */
8512
8513 /* Test the input arguments */
8514
8515 /* Parameter adjustments */
8516 a_dim1 = *lda;
8517 a_offset = 1 + a_dim1;
8518 a -= a_offset;
8519 --tau;
8520 c_dim1 = *ldc;
8521 c_offset = 1 + c_dim1;
8522 c__ -= c_offset;
8523 --work;
8524
8525 /* Function Body */
8526 *info = 0;
8527 left = lsame_(side, "L");
8528 notran = lsame_(trans, "N");
8529 lquery = *lwork == -1;
8530
8531 /* NQ is the order of Q and NW is the minimum dimension of WORK */
8532
8533 if (left) {
8534 nq = *m;
8535 nw = std::max(1_integer,*n);
8536 } else {
8537 nq = *n;
8538 nw = std::max(1_integer,*m);
8539 }
8540 if (! left && ! lsame_(side, "R")) {
8541 *info = -1;
8542 } else if (! notran && ! lsame_(trans, "T")) {
8543 *info = -2;
8544 } else if (*m < 0) {
8545 *info = -3;
8546 } else if (*n < 0) {
8547 *info = -4;
8548 } else if (*k < 0 || *k > nq) {
8549 *info = -5;
8550 } else if (*lda < std::max(1_integer,nq)) {
8551 *info = -7;
8552 } else if (*ldc < std::max(1_integer,*m)) {
8553 *info = -10;
8554 }
8555
8556 if (*info == 0) {
8557 if (*m == 0 || *n == 0) {
8558 lwkopt = 1;
8559 } else {
8560
8561 /* Determine the block size. NB may be at most NBMAX, where */
8562 /* NBMAX is used to define the local array T. */
8563
8564 /* Computing MIN */
8565 /* Writing concatenation */
8566 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
8567 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
8568 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
8569 ch__1 [2] = '\0';
8570 i__1 = 64, i__2 = ilaenv_(&c__1, "DORMQL", ch__1, m, n, k, &c_n1);
8571 nb = std::min(i__1,i__2);
8572 lwkopt = nw * nb;
8573 }
8574 work[1] = (double) lwkopt;
8575
8576 if (*lwork < nw && ! lquery) {
8577 *info = -12;
8578 }
8579 }
8580
8581 if (*info != 0) {
8582 i__1 = -(*info);
8583 xerbla_("DORMQL", &i__1);
8584 return 0;
8585 } else if (lquery) {
8586 return 0;
8587 }
8588
8589 /* Quick return if possible */
8590
8591 if (*m == 0 || *n == 0) {
8592 return 0;
8593 }
8594
8595 nbmin = 2;
8596 ldwork = nw;
8597 if (nb > 1 && nb < *k) {
8598 iws = nw * nb;
8599 if (*lwork < iws) {
8600 nb = *lwork / ldwork;
8601 /* Computing MAX */
8602 /* Writing concatenation */
8603 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
8604 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
8605 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
8606 ch__1 [2] = '\0';
8607 i__1 = 2, i__2 = ilaenv_(&c__2, "DORMQL", ch__1, m, n, k, &c_n1);
8608 nbmin = std::max(i__1,i__2);
8609 }
8610 } else {
8611 iws = nw;
8612 }
8613
8614 if (nb < nbmin || nb >= *k) {
8615
8616 /* Use unblocked code */
8617
8618 dorm2l_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
8619 c_offset], ldc, &work[1], &iinfo);
8620 } else {
8621
8622 /* Use blocked code */
8623
8624 if (left && notran || ! left && ! notran) {
8625 i1 = 1;
8626 i2 = *k;
8627 i3 = nb;
8628 } else {
8629 i1 = (*k - 1) / nb * nb + 1;
8630 i2 = 1;
8631 i3 = -nb;
8632 }
8633
8634 if (left) {
8635 ni = *n;
8636 } else {
8637 mi = *m;
8638 }
8639
8640 i__1 = i2;
8641 i__2 = i3;
8642 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
8643 /* Computing MIN */
8644 i__4 = nb, i__5 = *k - i__ + 1;
8645 ib = std::min(i__4,i__5);
8646
8647 /* Form the triangular factor of the block reflector */
8648 /* H = H(i+ib-1) . . . H(i+1) H(i) */
8649
8650 i__4 = nq - *k + i__ + ib - 1;
8651 dlarft_("Backward", "Columnwise", &i__4, &ib, &a[i__ * a_dim1 + 1]
8652 , lda, &tau[i__], t, &c__65);
8653 if (left) {
8654
8655 /* H or H' is applied to C(1:m-k+i+ib-1,1:n) */
8656
8657 mi = *m - *k + i__ + ib - 1;
8658 } else {
8659
8660 /* H or H' is applied to C(1:m,1:n-k+i+ib-1) */
8661
8662 ni = *n - *k + i__ + ib - 1;
8663 }
8664
8665 /* Apply H or H' */
8666
8667 dlarfb_(side, trans, "Backward", "Columnwise", &mi, &ni, &ib, &a[
8668 i__ * a_dim1 + 1], lda, t, &c__65, &c__[c_offset], ldc, &
8669 work[1], &ldwork);
8670 /* L10: */
8671 }
8672 }
8673 work[1] = (double) lwkopt;
8674 return 0;
8675
8676 /* End of DORMQL */
8677
8678 } /* dormql_ */
8679
8680 /* Subroutine */ int dormqr_(const char *side, const char *trans, integer *m, integer *n,
8681 integer *k, double *a, integer *lda, double *tau, double *
8682 c__, integer *ldc, double *work, integer *lwork, integer *info)
8683 {
8684 /* Table of constant values */
8685 static integer c__1 = 1;
8686 static integer c_n1 = -1;
8687 static integer c__2 = 2;
8688 static integer c__65 = 65;
8689
8690 /* System generated locals */
8691 char * a__1[2];
8692 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
8693 i__5;
8694 char ch__1[3];
8695
8696 /* Local variables */
8697 integer i__;
8698 double t[4160] /* was [65][64] */;
8699 integer i1, i2, i3, ib, ic, jc, nb, mi, ni, nq, nw, iws;
8700 bool left;
8701 integer nbmin, iinfo;
8702 bool notran;
8703 integer ldwork, lwkopt;
8704 bool lquery;
8705
8706
8707 /* -- LAPACK routine (version 3.1) -- */
8708 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
8709 /* November 2006 */
8710
8711 /* .. Scalar Arguments .. */
8712 /* .. */
8713 /* .. Array Arguments .. */
8714 /* .. */
8715
8716 /* Purpose */
8717 /* ======= */
8718
8719 /* DORMQR overwrites the general real M-by-N matrix C with */
8720
8721 /* SIDE = 'L' SIDE = 'R' */
8722 /* TRANS = 'N': Q * C C * Q */
8723 /* TRANS = 'T': Q**T * C C * Q**T */
8724
8725 /* where Q is a real orthogonal matrix defined as the product of k */
8726 /* elementary reflectors */
8727
8728 /* Q = H(1) H(2) . . . H(k) */
8729
8730 /* as returned by DGEQRF. Q is of order M if SIDE = 'L' and of order N */
8731 /* if SIDE = 'R'. */
8732
8733 /* Arguments */
8734 /* ========= */
8735
8736 /* SIDE (input) CHARACTER*1 */
8737 /* = 'L': apply Q or Q**T from the Left; */
8738 /* = 'R': apply Q or Q**T from the Right. */
8739
8740 /* TRANS (input) CHARACTER*1 */
8741 /* = 'N': No transpose, apply Q; */
8742 /* = 'T': Transpose, apply Q**T. */
8743
8744 /* M (input) INTEGER */
8745 /* The number of rows of the matrix C. M >= 0. */
8746
8747 /* N (input) INTEGER */
8748 /* The number of columns of the matrix C. N >= 0. */
8749
8750 /* K (input) INTEGER */
8751 /* The number of elementary reflectors whose product defines */
8752 /* the matrix Q. */
8753 /* If SIDE = 'L', M >= K >= 0; */
8754 /* if SIDE = 'R', N >= K >= 0. */
8755
8756 /* A (input) DOUBLE PRECISION array, dimension (LDA,K) */
8757 /* The i-th column must contain the vector which defines the */
8758 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
8759 /* DGEQRF in the first k columns of its array argument A. */
8760 /* A is modified by the routine but restored on exit. */
8761
8762 /* LDA (input) INTEGER */
8763 /* The leading dimension of the array A. */
8764 /* If SIDE = 'L', LDA >= max(1,M); */
8765 /* if SIDE = 'R', LDA >= max(1,N). */
8766
8767 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
8768 /* TAU(i) must contain the scalar factor of the elementary */
8769 /* reflector H(i), as returned by DGEQRF. */
8770
8771 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
8772 /* On entry, the M-by-N matrix C. */
8773 /* On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */
8774
8775 /* LDC (input) INTEGER */
8776 /* The leading dimension of the array C. LDC >= max(1,M). */
8777
8778 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
8779 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
8780
8781 /* LWORK (input) INTEGER */
8782 /* The dimension of the array WORK. */
8783 /* If SIDE = 'L', LWORK >= max(1,N); */
8784 /* if SIDE = 'R', LWORK >= max(1,M). */
8785 /* For optimum performance LWORK >= N*NB if SIDE = 'L', and */
8786 /* LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
8787 /* blocksize. */
8788
8789 /* If LWORK = -1, then a workspace query is assumed; the routine */
8790 /* only calculates the optimal size of the WORK array, returns */
8791 /* this value as the first entry of the WORK array, and no error */
8792 /* message related to LWORK is issued by XERBLA. */
8793
8794 /* INFO (output) INTEGER */
8795 /* = 0: successful exit */
8796 /* < 0: if INFO = -i, the i-th argument had an illegal value */
8797
8798 /* ===================================================================== */
8799
8800 /* .. Parameters .. */
8801 /* .. */
8802 /* .. Local Scalars .. */
8803 /* .. */
8804 /* .. Local Arrays .. */
8805 /* .. */
8806 /* .. External Functions .. */
8807 /* .. */
8808 /* .. External Subroutines .. */
8809 /* .. */
8810 /* .. Intrinsic Functions .. */
8811 /* .. */
8812 /* .. Executable Statements .. */
8813
8814 /* Test the input arguments */
8815
8816 /* Parameter adjustments */
8817 a_dim1 = *lda;
8818 a_offset = 1 + a_dim1;
8819 a -= a_offset;
8820 --tau;
8821 c_dim1 = *ldc;
8822 c_offset = 1 + c_dim1;
8823 c__ -= c_offset;
8824 --work;
8825
8826 /* Function Body */
8827 *info = 0;
8828 left = lsame_(side, "L");
8829 notran = lsame_(trans, "N");
8830 lquery = *lwork == -1;
8831
8832 /* NQ is the order of Q and NW is the minimum dimension of WORK */
8833
8834 if (left) {
8835 nq = *m;
8836 nw = *n;
8837 } else {
8838 nq = *n;
8839 nw = *m;
8840 }
8841 if (! left && ! lsame_(side, "R")) {
8842 *info = -1;
8843 } else if (! notran && ! lsame_(trans, "T")) {
8844 *info = -2;
8845 } else if (*m < 0) {
8846 *info = -3;
8847 } else if (*n < 0) {
8848 *info = -4;
8849 } else if (*k < 0 || *k > nq) {
8850 *info = -5;
8851 } else if (*lda < std::max(1_integer,nq)) {
8852 *info = -7;
8853 } else if (*ldc < std::max(1_integer,*m)) {
8854 *info = -10;
8855 } else if (*lwork < std::max(1_integer,nw) && ! lquery) {
8856 *info = -12;
8857 }
8858
8859 if (*info == 0) {
8860
8861 /* Determine the block size. NB may be at most NBMAX, where NBMAX */
8862 /* is used to define the local array T. */
8863
8864 /* Computing MIN */
8865 /* Writing concatenation */
8866 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
8867 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
8868 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
8869 ch__1 [2] = '\0';
8870 i__1 = 64, i__2 = ilaenv_(&c__1, "DORMQR", ch__1, m, n, k, &c_n1);
8871 nb = std::min(i__1,i__2);
8872 lwkopt = std::max(1_integer,nw) * nb;
8873 work[1] = (double) lwkopt;
8874 }
8875
8876 if (*info != 0) {
8877 i__1 = -(*info);
8878 xerbla_("DORMQR", &i__1);
8879 return 0;
8880 } else if (lquery) {
8881 return 0;
8882 }
8883
8884 /* Quick return if possible */
8885
8886 if (*m == 0 || *n == 0 || *k == 0) {
8887 work[1] = 1.;
8888 return 0;
8889 }
8890
8891 nbmin = 2;
8892 ldwork = nw;
8893 if (nb > 1 && nb < *k) {
8894 iws = nw * nb;
8895 if (*lwork < iws) {
8896 nb = *lwork / ldwork;
8897 /* Computing MAX */
8898 /* Writing concatenation */
8899 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
8900 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
8901 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
8902 ch__1 [2] = '\0';
8903 i__1 = 2, i__2 = ilaenv_(&c__2, "DORMQR", ch__1, m, n, k, &c_n1);
8904 nbmin = std::max(i__1,i__2);
8905 }
8906 } else {
8907 iws = nw;
8908 }
8909
8910 if (nb < nbmin || nb >= *k) {
8911
8912 /* Use unblocked code */
8913
8914 dorm2r_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
8915 c_offset], ldc, &work[1], &iinfo);
8916 } else {
8917
8918 /* Use blocked code */
8919
8920 if (left && ! notran || ! left && notran) {
8921 i1 = 1;
8922 i2 = *k;
8923 i3 = nb;
8924 } else {
8925 i1 = (*k - 1) / nb * nb + 1;
8926 i2 = 1;
8927 i3 = -nb;
8928 }
8929
8930 if (left) {
8931 ni = *n;
8932 jc = 1;
8933 } else {
8934 mi = *m;
8935 ic = 1;
8936 }
8937
8938 i__1 = i2;
8939 i__2 = i3;
8940 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
8941 /* Computing MIN */
8942 i__4 = nb, i__5 = *k - i__ + 1;
8943 ib = std::min(i__4,i__5);
8944
8945 /* Form the triangular factor of the block reflector */
8946 /* H = H(i) H(i+1) . . . H(i+ib-1) */
8947
8948 i__4 = nq - i__ + 1;
8949 dlarft_("Forward", "Columnwise", &i__4, &ib, &a[i__ + i__ *
8950 a_dim1], lda, &tau[i__], t, &c__65)
8951 ;
8952 if (left) {
8953
8954 /* H or H' is applied to C(i:m,1:n) */
8955
8956 mi = *m - i__ + 1;
8957 ic = i__;
8958 } else {
8959
8960 /* H or H' is applied to C(1:m,i:n) */
8961
8962 ni = *n - i__ + 1;
8963 jc = i__;
8964 }
8965
8966 /* Apply H or H' */
8967
8968 dlarfb_(side, trans, "Forward", "Columnwise", &mi, &ni, &ib, &a[
8969 i__ + i__ * a_dim1], lda, t, &c__65, &c__[ic + jc *
8970 c_dim1], ldc, &work[1], &ldwork);
8971 /* L10: */
8972 }
8973 }
8974 work[1] = (double) lwkopt;
8975 return 0;
8976
8977 /* End of DORMQR */
8978
8979 } /* dormqr_ */
8980
8981 /* Subroutine */ int dormr2_(const char *side, const char *trans, integer *m, integer *n,
8982 integer *k, double *a, integer *lda, double *tau, double *
8983 c__, integer *ldc, double *work, integer *info)
8984 {
8985 /* System generated locals */
8986 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2;
8987
8988 /* Local variables */
8989 integer i__, i1, i2, i3, mi, ni, nq;
8990 double aii;
8991 bool left;
8992 bool notran;
8993
8994
8995 /* -- LAPACK routine (version 3.1) -- */
8996 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
8997 /* November 2006 */
8998
8999 /* .. Scalar Arguments .. */
9000 /* .. */
9001 /* .. Array Arguments .. */
9002 /* .. */
9003
9004 /* Purpose */
9005 /* ======= */
9006
9007 /* DORMR2 overwrites the general real m by n matrix C with */
9008
9009 /* Q * C if SIDE = 'L' and TRANS = 'N', or */
9010
9011 /* Q'* C if SIDE = 'L' and TRANS = 'T', or */
9012
9013 /* C * Q if SIDE = 'R' and TRANS = 'N', or */
9014
9015 /* C * Q' if SIDE = 'R' and TRANS = 'T', */
9016
9017 /* where Q is a real orthogonal matrix defined as the product of k */
9018 /* elementary reflectors */
9019
9020 /* Q = H(1) H(2) . . . H(k) */
9021
9022 /* as returned by DGERQF. Q is of order m if SIDE = 'L' and of order n */
9023 /* if SIDE = 'R'. */
9024
9025 /* Arguments */
9026 /* ========= */
9027
9028 /* SIDE (input) CHARACTER*1 */
9029 /* = 'L': apply Q or Q' from the Left */
9030 /* = 'R': apply Q or Q' from the Right */
9031
9032 /* TRANS (input) CHARACTER*1 */
9033 /* = 'N': apply Q (No transpose) */
9034 /* = 'T': apply Q' (Transpose) */
9035
9036 /* M (input) INTEGER */
9037 /* The number of rows of the matrix C. M >= 0. */
9038
9039 /* N (input) INTEGER */
9040 /* The number of columns of the matrix C. N >= 0. */
9041
9042 /* K (input) INTEGER */
9043 /* The number of elementary reflectors whose product defines */
9044 /* the matrix Q. */
9045 /* If SIDE = 'L', M >= K >= 0; */
9046 /* if SIDE = 'R', N >= K >= 0. */
9047
9048 /* A (input) DOUBLE PRECISION array, dimension */
9049 /* (LDA,M) if SIDE = 'L', */
9050 /* (LDA,N) if SIDE = 'R' */
9051 /* The i-th row must contain the vector which defines the */
9052 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
9053 /* DGERQF in the last k rows of its array argument A. */
9054 /* A is modified by the routine but restored on exit. */
9055
9056 /* LDA (input) INTEGER */
9057 /* The leading dimension of the array A. LDA >= max(1,K). */
9058
9059 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
9060 /* TAU(i) must contain the scalar factor of the elementary */
9061 /* reflector H(i), as returned by DGERQF. */
9062
9063 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
9064 /* On entry, the m by n matrix C. */
9065 /* On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q. */
9066
9067 /* LDC (input) INTEGER */
9068 /* The leading dimension of the array C. LDC >= max(1,M). */
9069
9070 /* WORK (workspace) DOUBLE PRECISION array, dimension */
9071 /* (N) if SIDE = 'L', */
9072 /* (M) if SIDE = 'R' */
9073
9074 /* INFO (output) INTEGER */
9075 /* = 0: successful exit */
9076 /* < 0: if INFO = -i, the i-th argument had an illegal value */
9077
9078 /* ===================================================================== */
9079
9080 /* .. Parameters .. */
9081 /* .. */
9082 /* .. Local Scalars .. */
9083 /* .. */
9084 /* .. External Functions .. */
9085 /* .. */
9086 /* .. External Subroutines .. */
9087 /* .. */
9088 /* .. Intrinsic Functions .. */
9089 /* .. */
9090 /* .. Executable Statements .. */
9091
9092 /* Test the input arguments */
9093
9094 /* Parameter adjustments */
9095 a_dim1 = *lda;
9096 a_offset = 1 + a_dim1;
9097 a -= a_offset;
9098 --tau;
9099 c_dim1 = *ldc;
9100 c_offset = 1 + c_dim1;
9101 c__ -= c_offset;
9102 --work;
9103
9104 /* Function Body */
9105 *info = 0;
9106 left = lsame_(side, "L");
9107 notran = lsame_(trans, "N");
9108
9109 /* NQ is the order of Q */
9110
9111 if (left) {
9112 nq = *m;
9113 } else {
9114 nq = *n;
9115 }
9116 if (! left && ! lsame_(side, "R")) {
9117 *info = -1;
9118 } else if (! notran && ! lsame_(trans, "T")) {
9119 *info = -2;
9120 } else if (*m < 0) {
9121 *info = -3;
9122 } else if (*n < 0) {
9123 *info = -4;
9124 } else if (*k < 0 || *k > nq) {
9125 *info = -5;
9126 } else if (*lda < std::max(1_integer,*k)) {
9127 *info = -7;
9128 } else if (*ldc < std::max(1_integer,*m)) {
9129 *info = -10;
9130 }
9131 if (*info != 0) {
9132 i__1 = -(*info);
9133 xerbla_("DORMR2", &i__1);
9134 return 0;
9135 }
9136
9137 /* Quick return if possible */
9138
9139 if (*m == 0 || *n == 0 || *k == 0) {
9140 return 0;
9141 }
9142
9143 if (left && ! notran || ! left && notran) {
9144 i1 = 1;
9145 i2 = *k;
9146 i3 = 1;
9147 } else {
9148 i1 = *k;
9149 i2 = 1;
9150 i3 = -1;
9151 }
9152
9153 if (left) {
9154 ni = *n;
9155 } else {
9156 mi = *m;
9157 }
9158
9159 i__1 = i2;
9160 i__2 = i3;
9161 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
9162 if (left) {
9163
9164 /* H(i) is applied to C(1:m-k+i,1:n) */
9165
9166 mi = *m - *k + i__;
9167 } else {
9168
9169 /* H(i) is applied to C(1:m,1:n-k+i) */
9170
9171 ni = *n - *k + i__;
9172 }
9173
9174 /* Apply H(i) */
9175
9176 aii = a[i__ + (nq - *k + i__) * a_dim1];
9177 a[i__ + (nq - *k + i__) * a_dim1] = 1.;
9178 dlarf_(side, &mi, &ni, &a[i__ + a_dim1], lda, &tau[i__], &c__[
9179 c_offset], ldc, &work[1]);
9180 a[i__ + (nq - *k + i__) * a_dim1] = aii;
9181 /* L10: */
9182 }
9183 return 0;
9184
9185 /* End of DORMR2 */
9186
9187 } /* dormr2_ */
9188
9189 /* Subroutine */ int dormr3_(const char *side, const char *trans, integer *m, integer *n,
9190 integer *k, integer *l, double *a, integer *lda, double *tau,
9191 double *c__, integer *ldc, double *work, integer *info)
9192 {
9193 /* System generated locals */
9194 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2;
9195
9196 /* Local variables */
9197 integer i__, i1, i2, i3, ja, ic, jc, mi, ni, nq;
9198 bool left;
9199 bool notran;
9200
9201
9202 /* -- LAPACK routine (version 3.1) -- */
9203 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
9204 /* November 2006 */
9205
9206 /* .. Scalar Arguments .. */
9207 /* .. */
9208 /* .. Array Arguments .. */
9209 /* .. */
9210
9211 /* Purpose */
9212 /* ======= */
9213
9214 /* DORMR3 overwrites the general real m by n matrix C with */
9215
9216 /* Q * C if SIDE = 'L' and TRANS = 'N', or */
9217
9218 /* Q'* C if SIDE = 'L' and TRANS = 'T', or */
9219
9220 /* C * Q if SIDE = 'R' and TRANS = 'N', or */
9221
9222 /* C * Q' if SIDE = 'R' and TRANS = 'T', */
9223
9224 /* where Q is a real orthogonal matrix defined as the product of k */
9225 /* elementary reflectors */
9226
9227 /* Q = H(1) H(2) . . . H(k) */
9228
9229 /* as returned by DTZRZF. Q is of order m if SIDE = 'L' and of order n */
9230 /* if SIDE = 'R'. */
9231
9232 /* Arguments */
9233 /* ========= */
9234
9235 /* SIDE (input) CHARACTER*1 */
9236 /* = 'L': apply Q or Q' from the Left */
9237 /* = 'R': apply Q or Q' from the Right */
9238
9239 /* TRANS (input) CHARACTER*1 */
9240 /* = 'N': apply Q (No transpose) */
9241 /* = 'T': apply Q' (Transpose) */
9242
9243 /* M (input) INTEGER */
9244 /* The number of rows of the matrix C. M >= 0. */
9245
9246 /* N (input) INTEGER */
9247 /* The number of columns of the matrix C. N >= 0. */
9248
9249 /* K (input) INTEGER */
9250 /* The number of elementary reflectors whose product defines */
9251 /* the matrix Q. */
9252 /* If SIDE = 'L', M >= K >= 0; */
9253 /* if SIDE = 'R', N >= K >= 0. */
9254
9255 /* L (input) INTEGER */
9256 /* The number of columns of the matrix A containing */
9257 /* the meaningful part of the Householder reflectors. */
9258 /* If SIDE = 'L', M >= L >= 0, if SIDE = 'R', N >= L >= 0. */
9259
9260 /* A (input) DOUBLE PRECISION array, dimension */
9261 /* (LDA,M) if SIDE = 'L', */
9262 /* (LDA,N) if SIDE = 'R' */
9263 /* The i-th row must contain the vector which defines the */
9264 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
9265 /* DTZRZF in the last k rows of its array argument A. */
9266 /* A is modified by the routine but restored on exit. */
9267
9268 /* LDA (input) INTEGER */
9269 /* The leading dimension of the array A. LDA >= max(1,K). */
9270
9271 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
9272 /* TAU(i) must contain the scalar factor of the elementary */
9273 /* reflector H(i), as returned by DTZRZF. */
9274
9275 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
9276 /* On entry, the m-by-n matrix C. */
9277 /* On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q. */
9278
9279 /* LDC (input) INTEGER */
9280 /* The leading dimension of the array C. LDC >= max(1,M). */
9281
9282 /* WORK (workspace) DOUBLE PRECISION array, dimension */
9283 /* (N) if SIDE = 'L', */
9284 /* (M) if SIDE = 'R' */
9285
9286 /* INFO (output) INTEGER */
9287 /* = 0: successful exit */
9288 /* < 0: if INFO = -i, the i-th argument had an illegal value */
9289
9290 /* Further Details */
9291 /* =============== */
9292
9293 /* Based on contributions by */
9294 /* A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA */
9295
9296 /* ===================================================================== */
9297
9298 /* .. Local Scalars .. */
9299 /* .. */
9300 /* .. External Functions .. */
9301 /* .. */
9302 /* .. External Subroutines .. */
9303 /* .. */
9304 /* .. Intrinsic Functions .. */
9305 /* .. */
9306 /* .. Executable Statements .. */
9307
9308 /* Test the input arguments */
9309
9310 /* Parameter adjustments */
9311 a_dim1 = *lda;
9312 a_offset = 1 + a_dim1;
9313 a -= a_offset;
9314 --tau;
9315 c_dim1 = *ldc;
9316 c_offset = 1 + c_dim1;
9317 c__ -= c_offset;
9318 --work;
9319
9320 /* Function Body */
9321 *info = 0;
9322 left = lsame_(side, "L");
9323 notran = lsame_(trans, "N");
9324
9325 /* NQ is the order of Q */
9326
9327 if (left) {
9328 nq = *m;
9329 } else {
9330 nq = *n;
9331 }
9332 if (! left && ! lsame_(side, "R")) {
9333 *info = -1;
9334 } else if (! notran && ! lsame_(trans, "T")) {
9335 *info = -2;
9336 } else if (*m < 0) {
9337 *info = -3;
9338 } else if (*n < 0) {
9339 *info = -4;
9340 } else if (*k < 0 || *k > nq) {
9341 *info = -5;
9342 } else if (*l < 0 || left && *l > *m || ! left && *l > *n) {
9343 *info = -6;
9344 } else if (*lda < std::max(1_integer,*k)) {
9345 *info = -8;
9346 } else if (*ldc < std::max(1_integer,*m)) {
9347 *info = -11;
9348 }
9349 if (*info != 0) {
9350 i__1 = -(*info);
9351 xerbla_("DORMR3", &i__1);
9352 return 0;
9353 }
9354
9355 /* Quick return if possible */
9356
9357 if (*m == 0 || *n == 0 || *k == 0) {
9358 return 0;
9359 }
9360
9361 if (left && ! notran || ! left && notran) {
9362 i1 = 1;
9363 i2 = *k;
9364 i3 = 1;
9365 } else {
9366 i1 = *k;
9367 i2 = 1;
9368 i3 = -1;
9369 }
9370
9371 if (left) {
9372 ni = *n;
9373 ja = *m - *l + 1;
9374 jc = 1;
9375 } else {
9376 mi = *m;
9377 ja = *n - *l + 1;
9378 ic = 1;
9379 }
9380
9381 i__1 = i2;
9382 i__2 = i3;
9383 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
9384 if (left) {
9385
9386 /* H(i) or H(i)' is applied to C(i:m,1:n) */
9387
9388 mi = *m - i__ + 1;
9389 ic = i__;
9390 } else {
9391
9392 /* H(i) or H(i)' is applied to C(1:m,i:n) */
9393
9394 ni = *n - i__ + 1;
9395 jc = i__;
9396 }
9397
9398 /* Apply H(i) or H(i)' */
9399
9400 dlarz_(side, &mi, &ni, l, &a[i__ + ja * a_dim1], lda, &tau[i__], &c__[
9401 ic + jc * c_dim1], ldc, &work[1]);
9402
9403 /* L10: */
9404 }
9405
9406 return 0;
9407
9408 /* End of DORMR3 */
9409
9410 } /* dormr3_ */
9411
9412 /* Subroutine */ int dormrq_(const char *side, const char *trans, integer *m, integer *n,
9413 integer *k, double *a, integer *lda, double *tau, double *
9414 c__, integer *ldc, double *work, integer *lwork, integer *info)
9415 {
9416 /* Table of constant values */
9417 static integer c__1 = 1;
9418 static integer c_n1 = -1;
9419 static integer c__2 = 2;
9420 static integer c__65 = 65;
9421
9422 /* System generated locals */
9423 char * a__1[2];
9424 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
9425 i__5;
9426 char ch__1[3];
9427
9428 /* Local variables */
9429 integer i__;
9430 double t[4160] /* was [65][64] */;
9431 integer i1, i2, i3, ib, nb, mi, ni, nq, nw, iws;
9432 bool left;
9433 integer nbmin, iinfo;
9434 bool notran;
9435 integer ldwork;
9436 char transt[1];
9437 integer lwkopt;
9438 bool lquery;
9439
9440
9441 /* -- LAPACK routine (version 3.1) -- */
9442 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
9443 /* November 2006 */
9444
9445 /* .. Scalar Arguments .. */
9446 /* .. */
9447 /* .. Array Arguments .. */
9448 /* .. */
9449
9450 /* Purpose */
9451 /* ======= */
9452
9453 /* DORMRQ overwrites the general real M-by-N matrix C with */
9454
9455 /* SIDE = 'L' SIDE = 'R' */
9456 /* TRANS = 'N': Q * C C * Q */
9457 /* TRANS = 'T': Q**T * C C * Q**T */
9458
9459 /* where Q is a real orthogonal matrix defined as the product of k */
9460 /* elementary reflectors */
9461
9462 /* Q = H(1) H(2) . . . H(k) */
9463
9464 /* as returned by DGERQF. Q is of order M if SIDE = 'L' and of order N */
9465 /* if SIDE = 'R'. */
9466
9467 /* Arguments */
9468 /* ========= */
9469
9470 /* SIDE (input) CHARACTER*1 */
9471 /* = 'L': apply Q or Q**T from the Left; */
9472 /* = 'R': apply Q or Q**T from the Right. */
9473
9474 /* TRANS (input) CHARACTER*1 */
9475 /* = 'N': No transpose, apply Q; */
9476 /* = 'T': Transpose, apply Q**T. */
9477
9478 /* M (input) INTEGER */
9479 /* The number of rows of the matrix C. M >= 0. */
9480
9481 /* N (input) INTEGER */
9482 /* The number of columns of the matrix C. N >= 0. */
9483
9484 /* K (input) INTEGER */
9485 /* The number of elementary reflectors whose product defines */
9486 /* the matrix Q. */
9487 /* If SIDE = 'L', M >= K >= 0; */
9488 /* if SIDE = 'R', N >= K >= 0. */
9489
9490 /* A (input) DOUBLE PRECISION array, dimension */
9491 /* (LDA,M) if SIDE = 'L', */
9492 /* (LDA,N) if SIDE = 'R' */
9493 /* The i-th row must contain the vector which defines the */
9494 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
9495 /* DGERQF in the last k rows of its array argument A. */
9496 /* A is modified by the routine but restored on exit. */
9497
9498 /* LDA (input) INTEGER */
9499 /* The leading dimension of the array A. LDA >= max(1,K). */
9500
9501 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
9502 /* TAU(i) must contain the scalar factor of the elementary */
9503 /* reflector H(i), as returned by DGERQF. */
9504
9505 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
9506 /* On entry, the M-by-N matrix C. */
9507 /* On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */
9508
9509 /* LDC (input) INTEGER */
9510 /* The leading dimension of the array C. LDC >= max(1,M). */
9511
9512 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
9513 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
9514
9515 /* LWORK (input) INTEGER */
9516 /* The dimension of the array WORK. */
9517 /* If SIDE = 'L', LWORK >= max(1,N); */
9518 /* if SIDE = 'R', LWORK >= max(1,M). */
9519 /* For optimum performance LWORK >= N*NB if SIDE = 'L', and */
9520 /* LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
9521 /* blocksize. */
9522
9523 /* If LWORK = -1, then a workspace query is assumed; the routine */
9524 /* only calculates the optimal size of the WORK array, returns */
9525 /* this value as the first entry of the WORK array, and no error */
9526 /* message related to LWORK is issued by XERBLA. */
9527
9528 /* INFO (output) INTEGER */
9529 /* = 0: successful exit */
9530 /* < 0: if INFO = -i, the i-th argument had an illegal value */
9531
9532 /* ===================================================================== */
9533
9534 /* .. Parameters .. */
9535 /* .. */
9536 /* .. Local Scalars .. */
9537 /* .. */
9538 /* .. Local Arrays .. */
9539 /* .. */
9540 /* .. External Functions .. */
9541 /* .. */
9542 /* .. External Subroutines .. */
9543 /* .. */
9544 /* .. Intrinsic Functions .. */
9545 /* .. */
9546 /* .. Executable Statements .. */
9547
9548 /* Test the input arguments */
9549
9550 /* Parameter adjustments */
9551 a_dim1 = *lda;
9552 a_offset = 1 + a_dim1;
9553 a -= a_offset;
9554 --tau;
9555 c_dim1 = *ldc;
9556 c_offset = 1 + c_dim1;
9557 c__ -= c_offset;
9558 --work;
9559
9560 /* Function Body */
9561 *info = 0;
9562 left = lsame_(side, "L");
9563 notran = lsame_(trans, "N");
9564 lquery = *lwork == -1;
9565
9566 /* NQ is the order of Q and NW is the minimum dimension of WORK */
9567
9568 if (left) {
9569 nq = *m;
9570 nw = std::max(1_integer,*n);
9571 } else {
9572 nq = *n;
9573 nw = std::max(1_integer,*m);
9574 }
9575 if (! left && ! lsame_(side, "R")) {
9576 *info = -1;
9577 } else if (! notran && ! lsame_(trans, "T")) {
9578 *info = -2;
9579 } else if (*m < 0) {
9580 *info = -3;
9581 } else if (*n < 0) {
9582 *info = -4;
9583 } else if (*k < 0 || *k > nq) {
9584 *info = -5;
9585 } else if (*lda < std::max(1_integer,*k)) {
9586 *info = -7;
9587 } else if (*ldc < std::max(1_integer,*m)) {
9588 *info = -10;
9589 }
9590
9591 if (*info == 0) {
9592 if (*m == 0 || *n == 0) {
9593 lwkopt = 1;
9594 } else {
9595
9596 /* Determine the block size. NB may be at most NBMAX, where */
9597 /* NBMAX is used to define the local array T. */
9598
9599 /* Computing MIN */
9600 /* Writing concatenation */
9601 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
9602 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
9603 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
9604 ch__1 [2] = '\0';
9605 i__1 = 64, i__2 = ilaenv_(&c__1, "DORMRQ", ch__1, m, n, k, &c_n1);
9606 nb = std::min(i__1,i__2);
9607 lwkopt = nw * nb;
9608 }
9609 work[1] = (double) lwkopt;
9610
9611 if (*lwork < nw && ! lquery) {
9612 *info = -12;
9613 }
9614 }
9615
9616 if (*info != 0) {
9617 i__1 = -(*info);
9618 xerbla_("DORMRQ", &i__1);
9619 return 0;
9620 } else if (lquery) {
9621 return 0;
9622 }
9623
9624 /* Quick return if possible */
9625
9626 if (*m == 0 || *n == 0) {
9627 return 0;
9628 }
9629
9630 nbmin = 2;
9631 ldwork = nw;
9632 if (nb > 1 && nb < *k) {
9633 iws = nw * nb;
9634 if (*lwork < iws) {
9635 nb = *lwork / ldwork;
9636 /* Computing MAX */
9637 /* Writing concatenation */
9638 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
9639 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
9640 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
9641 ch__1 [2] = '\0';
9642 i__1 = 2, i__2 = ilaenv_(&c__2, "DORMRQ", ch__1, m, n, k, &c_n1);
9643 nbmin = std::max(i__1,i__2);
9644 }
9645 } else {
9646 iws = nw;
9647 }
9648
9649 if (nb < nbmin || nb >= *k) {
9650
9651 /* Use unblocked code */
9652
9653 dormr2_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
9654 c_offset], ldc, &work[1], &iinfo);
9655 } else {
9656
9657 /* Use blocked code */
9658
9659 if (left && ! notran || ! left && notran) {
9660 i1 = 1;
9661 i2 = *k;
9662 i3 = nb;
9663 } else {
9664 i1 = (*k - 1) / nb * nb + 1;
9665 i2 = 1;
9666 i3 = -nb;
9667 }
9668
9669 if (left) {
9670 ni = *n;
9671 } else {
9672 mi = *m;
9673 }
9674
9675 if (notran) {
9676 *(unsigned char *)transt = 'T';
9677 } else {
9678 *(unsigned char *)transt = 'N';
9679 }
9680
9681 i__1 = i2;
9682 i__2 = i3;
9683 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
9684 /* Computing MIN */
9685 i__4 = nb, i__5 = *k - i__ + 1;
9686 ib = std::min(i__4,i__5);
9687
9688 /* Form the triangular factor of the block reflector */
9689 /* H = H(i+ib-1) . . . H(i+1) H(i) */
9690
9691 i__4 = nq - *k + i__ + ib - 1;
9692 dlarft_("Backward", "Rowwise", &i__4, &ib, &a[i__ + a_dim1], lda,
9693 &tau[i__], t, &c__65);
9694 if (left) {
9695
9696 /* H or H' is applied to C(1:m-k+i+ib-1,1:n) */
9697
9698 mi = *m - *k + i__ + ib - 1;
9699 } else {
9700
9701 /* H or H' is applied to C(1:m,1:n-k+i+ib-1) */
9702
9703 ni = *n - *k + i__ + ib - 1;
9704 }
9705
9706 /* Apply H or H' */
9707
9708 dlarfb_(side, transt, "Backward", "Rowwise", &mi, &ni, &ib, &a[
9709 i__ + a_dim1], lda, t, &c__65, &c__[c_offset], ldc, &work[
9710 1], &ldwork);
9711 /* L10: */
9712 }
9713 }
9714 work[1] = (double) lwkopt;
9715 return 0;
9716
9717 /* End of DORMRQ */
9718
9719 } /* dormrq_ */
9720
9721 /* Subroutine */ int dormrz_(const char *side, const char *trans, integer *m, integer *n,
9722 integer *k, integer *l, double *a, integer *lda, double *tau,
9723 double *c__, integer *ldc, double *work, integer *lwork,
9724 integer *info)
9725 {
9726 /* Table of constant values */
9727 static integer c__1 = 1;
9728 static integer c_n1 = -1;
9729 static integer c__2 = 2;
9730 static integer c__65 = 65;
9731
9732 /* System generated locals */
9733 char * a__1[2];
9734 integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
9735 i__5;
9736 char ch__1[3];
9737
9738 /* Local variables */
9739 integer i__;
9740 double t[4160] /* was [65][64] */;
9741 integer i1, i2, i3, ib, ic, ja, jc, nb, mi, ni, nq, nw, iws;
9742 bool left;
9743 integer nbmin, iinfo;
9744 bool notran;
9745 integer ldwork;
9746 char transt[1];
9747 integer lwkopt;
9748 bool lquery;
9749
9750
9751 /* -- LAPACK routine (version 3.1.1) -- */
9752 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
9753 /* January 2007 */
9754
9755 /* .. Scalar Arguments .. */
9756 /* .. */
9757 /* .. Array Arguments .. */
9758 /* .. */
9759
9760 /* Purpose */
9761 /* ======= */
9762
9763 /* DORMRZ overwrites the general real M-by-N matrix C with */
9764
9765 /* SIDE = 'L' SIDE = 'R' */
9766 /* TRANS = 'N': Q * C C * Q */
9767 /* TRANS = 'T': Q**T * C C * Q**T */
9768
9769 /* where Q is a real orthogonal matrix defined as the product of k */
9770 /* elementary reflectors */
9771
9772 /* Q = H(1) H(2) . . . H(k) */
9773
9774 /* as returned by DTZRZF. Q is of order M if SIDE = 'L' and of order N */
9775 /* if SIDE = 'R'. */
9776
9777 /* Arguments */
9778 /* ========= */
9779
9780 /* SIDE (input) CHARACTER*1 */
9781 /* = 'L': apply Q or Q**T from the Left; */
9782 /* = 'R': apply Q or Q**T from the Right. */
9783
9784 /* TRANS (input) CHARACTER*1 */
9785 /* = 'N': No transpose, apply Q; */
9786 /* = 'T': Transpose, apply Q**T. */
9787
9788 /* M (input) INTEGER */
9789 /* The number of rows of the matrix C. M >= 0. */
9790
9791 /* N (input) INTEGER */
9792 /* The number of columns of the matrix C. N >= 0. */
9793
9794 /* K (input) INTEGER */
9795 /* The number of elementary reflectors whose product defines */
9796 /* the matrix Q. */
9797 /* If SIDE = 'L', M >= K >= 0; */
9798 /* if SIDE = 'R', N >= K >= 0. */
9799
9800 /* L (input) INTEGER */
9801 /* The number of columns of the matrix A containing */
9802 /* the meaningful part of the Householder reflectors. */
9803 /* If SIDE = 'L', M >= L >= 0, if SIDE = 'R', N >= L >= 0. */
9804
9805 /* A (input) DOUBLE PRECISION array, dimension */
9806 /* (LDA,M) if SIDE = 'L', */
9807 /* (LDA,N) if SIDE = 'R' */
9808 /* The i-th row must contain the vector which defines the */
9809 /* elementary reflector H(i), for i = 1,2,...,k, as returned by */
9810 /* DTZRZF in the last k rows of its array argument A. */
9811 /* A is modified by the routine but restored on exit. */
9812
9813 /* LDA (input) INTEGER */
9814 /* The leading dimension of the array A. LDA >= max(1,K). */
9815
9816 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
9817 /* TAU(i) must contain the scalar factor of the elementary */
9818 /* reflector H(i), as returned by DTZRZF. */
9819
9820 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
9821 /* On entry, the M-by-N matrix C. */
9822 /* On exit, C is overwritten by Q*C or Q**H*C or C*Q**H or C*Q. */
9823
9824 /* LDC (input) INTEGER */
9825 /* The leading dimension of the array C. LDC >= max(1,M). */
9826
9827 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
9828 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
9829
9830 /* LWORK (input) INTEGER */
9831 /* The dimension of the array WORK. */
9832 /* If SIDE = 'L', LWORK >= max(1,N); */
9833 /* if SIDE = 'R', LWORK >= max(1,M). */
9834 /* For optimum performance LWORK >= N*NB if SIDE = 'L', and */
9835 /* LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
9836 /* blocksize. */
9837
9838 /* If LWORK = -1, then a workspace query is assumed; the routine */
9839 /* only calculates the optimal size of the WORK array, returns */
9840 /* this value as the first entry of the WORK array, and no error */
9841 /* message related to LWORK is issued by XERBLA. */
9842
9843 /* INFO (output) INTEGER */
9844 /* = 0: successful exit */
9845 /* < 0: if INFO = -i, the i-th argument had an illegal value */
9846
9847 /* Further Details */
9848 /* =============== */
9849
9850 /* Based on contributions by */
9851 /* A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA */
9852
9853 /* ===================================================================== */
9854
9855 /* .. Parameters .. */
9856 /* .. */
9857 /* .. Local Scalars .. */
9858 /* .. */
9859 /* .. Local Arrays .. */
9860 /* .. */
9861 /* .. External Functions .. */
9862 /* .. */
9863 /* .. External Subroutines .. */
9864 /* .. */
9865 /* .. Intrinsic Functions .. */
9866 /* .. */
9867 /* .. Executable Statements .. */
9868
9869 /* Test the input arguments */
9870
9871 /* Parameter adjustments */
9872 a_dim1 = *lda;
9873 a_offset = 1 + a_dim1;
9874 a -= a_offset;
9875 --tau;
9876 c_dim1 = *ldc;
9877 c_offset = 1 + c_dim1;
9878 c__ -= c_offset;
9879 --work;
9880
9881 /* Function Body */
9882 *info = 0;
9883 left = lsame_(side, "L");
9884 notran = lsame_(trans, "N");
9885 lquery = *lwork == -1;
9886
9887 /* NQ is the order of Q and NW is the minimum dimension of WORK */
9888
9889 if (left) {
9890 nq = *m;
9891 nw = std::max(1_integer,*n);
9892 } else {
9893 nq = *n;
9894 nw = std::max(1_integer,*m);
9895 }
9896 if (! left && ! lsame_(side, "R")) {
9897 *info = -1;
9898 } else if (! notran && ! lsame_(trans, "T")) {
9899 *info = -2;
9900 } else if (*m < 0) {
9901 *info = -3;
9902 } else if (*n < 0) {
9903 *info = -4;
9904 } else if (*k < 0 || *k > nq) {
9905 *info = -5;
9906 } else if (*l < 0 || left && *l > *m || ! left && *l > *n) {
9907 *info = -6;
9908 } else if (*lda < std::max(1_integer,*k)) {
9909 *info = -8;
9910 } else if (*ldc < std::max(1_integer,*m)) {
9911 *info = -11;
9912 }
9913
9914 if (*info == 0) {
9915 if (*m == 0 || *n == 0) {
9916 lwkopt = 1;
9917 } else {
9918
9919 /* Determine the block size. NB may be at most NBMAX, where */
9920 /* NBMAX is used to define the local array T. */
9921
9922 /* Computing MIN */
9923 /* Writing concatenation */
9924 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
9925 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
9926 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
9927 ch__1 [2] = '\0';
9928 i__1 = 64, i__2 = ilaenv_(&c__1, "DORMRQ", ch__1, m, n, k, &c_n1);
9929 nb = std::min(i__1,i__2);
9930 lwkopt = nw * nb;
9931 }
9932 work[1] = (double) lwkopt;
9933
9934 if (*lwork < std::max(1_integer,nw) && ! lquery) {
9935 *info = -13;
9936 }
9937 }
9938
9939 if (*info != 0) {
9940 i__1 = -(*info);
9941 xerbla_("DORMRZ", &i__1);
9942 return 0;
9943 } else if (lquery) {
9944 return 0;
9945 }
9946
9947 /* Quick return if possible */
9948
9949 if (*m == 0 || *n == 0) {
9950 work[1] = 1.;
9951 return 0;
9952 }
9953
9954 nbmin = 2;
9955 ldwork = nw;
9956 if (nb > 1 && nb < *k) {
9957 iws = nw * nb;
9958 if (*lwork < iws) {
9959 nb = *lwork / ldwork;
9960 /* Computing MAX */
9961 /* Writing concatenation */
9962 i__3[0] = 1, a__1[0] = const_cast<char *> (side);
9963 i__3[1] = 1, a__1[1] = const_cast<char *> (trans);
9964 s_cat(ch__1, a__1, i__3, &c__2, 2_integer);
9965 ch__1 [2] = '\0';
9966 i__1 = 2, i__2 = ilaenv_(&c__2, "DORMRQ", ch__1, m, n, k, &c_n1);
9967 nbmin = std::max(i__1,i__2);
9968 }
9969 } else {
9970 iws = nw;
9971 }
9972
9973 if (nb < nbmin || nb >= *k) {
9974
9975 /* Use unblocked code */
9976
9977 dormr3_(side, trans, m, n, k, l, &a[a_offset], lda, &tau[1], &c__[
9978 c_offset], ldc, &work[1], &iinfo);
9979 } else {
9980
9981 /* Use blocked code */
9982
9983 if (left && ! notran || ! left && notran) {
9984 i1 = 1;
9985 i2 = *k;
9986 i3 = nb;
9987 } else {
9988 i1 = (*k - 1) / nb * nb + 1;
9989 i2 = 1;
9990 i3 = -nb;
9991 }
9992
9993 if (left) {
9994 ni = *n;
9995 jc = 1;
9996 ja = *m - *l + 1;
9997 } else {
9998 mi = *m;
9999 ic = 1;
10000 ja = *n - *l + 1;
10001 }
10002
10003 if (notran) {
10004 *(unsigned char *)transt = 'T';
10005 } else {
10006 *(unsigned char *)transt = 'N';
10007 }
10008
10009 i__1 = i2;
10010 i__2 = i3;
10011 for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
10012 /* Computing MIN */
10013 i__4 = nb, i__5 = *k - i__ + 1;
10014 ib = std::min(i__4,i__5);
10015
10016 /* Form the triangular factor of the block reflector */
10017 /* H = H(i+ib-1) . . . H(i+1) H(i) */
10018
10019 dlarzt_("Backward", "Rowwise", l, &ib, &a[i__ + ja * a_dim1], lda,
10020 &tau[i__], t, &c__65);
10021
10022 if (left) {
10023
10024 /* H or H' is applied to C(i:m,1:n) */
10025
10026 mi = *m - i__ + 1;
10027 ic = i__;
10028 } else {
10029
10030 /* H or H' is applied to C(1:m,i:n) */
10031
10032 ni = *n - i__ + 1;
10033 jc = i__;
10034 }
10035
10036 /* Apply H or H' */
10037
10038 dlarzb_(side, transt, "Backward", "Rowwise", &mi, &ni, &ib, l, &a[
10039 i__ + ja * a_dim1], lda, t, &c__65, &c__[ic + jc * c_dim1]
10040 , ldc, &work[1], &ldwork);
10041 /* L10: */
10042 }
10043
10044 }
10045
10046 work[1] = (double) lwkopt;
10047
10048 return 0;
10049
10050 /* End of DORMRZ */
10051
10052 } /* dormrz_ */
10053
10054 /* Subroutine */ int dormtr_(const char *side, const char *uplo, const char *trans, integer *m,
10055 integer *n, double *a, integer *lda, double *tau, double *
10056 c__, integer *ldc, double *work, integer *lwork, integer *info)
10057 {
10058 /* Table of constant values */
10059 static integer c__1 = 1;
10060 static integer c_n1 = -1;
10061 static integer c__2 = 2;
10062
10063 /* System generated locals */
10064 char * a__1[2];
10065 integer a_dim1, a_offset, c_dim1, c_offset, i__1[2], i__2, i__3;
10066 char ch__1[3];
10067
10068 /* Local variables */
10069 integer i1, i2, nb, mi, ni, nq, nw;
10070 bool left;
10071 integer iinfo;
10072 bool upper;
10073 integer lwkopt;
10074 bool lquery;
10075
10076
10077 /* -- LAPACK routine (version 3.1) -- */
10078 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
10079 /* November 2006 */
10080
10081 /* .. Scalar Arguments .. */
10082 /* .. */
10083 /* .. Array Arguments .. */
10084 /* .. */
10085
10086 /* Purpose */
10087 /* ======= */
10088
10089 /* DORMTR overwrites the general real M-by-N matrix C with */
10090
10091 /* SIDE = 'L' SIDE = 'R' */
10092 /* TRANS = 'N': Q * C C * Q */
10093 /* TRANS = 'T': Q**T * C C * Q**T */
10094
10095 /* where Q is a real orthogonal matrix of order nq, with nq = m if */
10096 /* SIDE = 'L' and nq = n if SIDE = 'R'. Q is defined as the product of */
10097 /* nq-1 elementary reflectors, as returned by DSYTRD: */
10098
10099 /* if UPLO = 'U', Q = H(nq-1) . . . H(2) H(1); */
10100
10101 /* if UPLO = 'L', Q = H(1) H(2) . . . H(nq-1). */
10102
10103 /* Arguments */
10104 /* ========= */
10105
10106 /* SIDE (input) CHARACTER*1 */
10107 /* = 'L': apply Q or Q**T from the Left; */
10108 /* = 'R': apply Q or Q**T from the Right. */
10109
10110 /* UPLO (input) CHARACTER*1 */
10111 /* = 'U': Upper triangle of A contains elementary reflectors */
10112 /* from DSYTRD; */
10113 /* = 'L': Lower triangle of A contains elementary reflectors */
10114 /* from DSYTRD. */
10115
10116 /* TRANS (input) CHARACTER*1 */
10117 /* = 'N': No transpose, apply Q; */
10118 /* = 'T': Transpose, apply Q**T. */
10119
10120 /* M (input) INTEGER */
10121 /* The number of rows of the matrix C. M >= 0. */
10122
10123 /* N (input) INTEGER */
10124 /* The number of columns of the matrix C. N >= 0. */
10125
10126 /* A (input) DOUBLE PRECISION array, dimension */
10127 /* (LDA,M) if SIDE = 'L' */
10128 /* (LDA,N) if SIDE = 'R' */
10129 /* The vectors which define the elementary reflectors, as */
10130 /* returned by DSYTRD. */
10131
10132 /* LDA (input) INTEGER */
10133 /* The leading dimension of the array A. */
10134 /* LDA >= max(1,M) if SIDE = 'L'; LDA >= max(1,N) if SIDE = 'R'. */
10135
10136 /* TAU (input) DOUBLE PRECISION array, dimension */
10137 /* (M-1) if SIDE = 'L' */
10138 /* (N-1) if SIDE = 'R' */
10139 /* TAU(i) must contain the scalar factor of the elementary */
10140 /* reflector H(i), as returned by DSYTRD. */
10141
10142 /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
10143 /* On entry, the M-by-N matrix C. */
10144 /* On exit, C is overwritten by Q*C or Q**T*C or C*Q**T or C*Q. */
10145
10146 /* LDC (input) INTEGER */
10147 /* The leading dimension of the array C. LDC >= max(1,M). */
10148
10149 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
10150 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
10151
10152 /* LWORK (input) INTEGER */
10153 /* The dimension of the array WORK. */
10154 /* If SIDE = 'L', LWORK >= max(1,N); */
10155 /* if SIDE = 'R', LWORK >= max(1,M). */
10156 /* For optimum performance LWORK >= N*NB if SIDE = 'L', and */
10157 /* LWORK >= M*NB if SIDE = 'R', where NB is the optimal */
10158 /* blocksize. */
10159
10160 /* If LWORK = -1, then a workspace query is assumed; the routine */
10161 /* only calculates the optimal size of the WORK array, returns */
10162 /* this value as the first entry of the WORK array, and no error */
10163 /* message related to LWORK is issued by XERBLA. */
10164
10165 /* INFO (output) INTEGER */
10166 /* = 0: successful exit */
10167 /* < 0: if INFO = -i, the i-th argument had an illegal value */
10168
10169 /* ===================================================================== */
10170
10171 /* .. Local Scalars .. */
10172 /* .. */
10173 /* .. External Functions .. */
10174 /* .. */
10175 /* .. External Subroutines .. */
10176 /* .. */
10177 /* .. Intrinsic Functions .. */
10178 /* .. */
10179 /* .. Executable Statements .. */
10180
10181 /* Test the input arguments */
10182
10183 /* Parameter adjustments */
10184 a_dim1 = *lda;
10185 a_offset = 1 + a_dim1;
10186 a -= a_offset;
10187 --tau;
10188 c_dim1 = *ldc;
10189 c_offset = 1 + c_dim1;
10190 c__ -= c_offset;
10191 --work;
10192
10193 /* Function Body */
10194 *info = 0;
10195 left = lsame_(side, "L");
10196 upper = lsame_(uplo, "U");
10197 lquery = *lwork == -1;
10198
10199 /* NQ is the order of Q and NW is the minimum dimension of WORK */
10200
10201 if (left) {
10202 nq = *m;
10203 nw = *n;
10204 } else {
10205 nq = *n;
10206 nw = *m;
10207 }
10208 if (! left && ! lsame_(side, "R")) {
10209 *info = -1;
10210 } else if (! upper && ! lsame_(uplo, "L")) {
10211 *info = -2;
10212 } else if (! lsame_(trans, "N") && ! lsame_(trans,
10213 "T")) {
10214 *info = -3;
10215 } else if (*m < 0) {
10216 *info = -4;
10217 } else if (*n < 0) {
10218 *info = -5;
10219 } else if (*lda < std::max(1_integer,nq)) {
10220 *info = -7;
10221 } else if (*ldc < std::max(1_integer,*m)) {
10222 *info = -10;
10223 } else if (*lwork < std::max(1_integer,nw) && ! lquery) {
10224 *info = -12;
10225 }
10226
10227 if (*info == 0) {
10228 if (upper) {
10229 if (left) {
10230 /* Writing concatenation */
10231 i__1[0] = 1, a__1[0] = const_cast<char *> (side);
10232 i__1[1] = 1, a__1[1] = const_cast<char *> (trans);
10233 s_cat(ch__1, a__1, i__1, &c__2, 2_integer);
10234 ch__1 [2] = '\0';
10235 i__2 = *m - 1;
10236 i__3 = *m - 1;
10237 nb = ilaenv_(&c__1, "DORMQL", ch__1, &i__2, n, &i__3, &c_n1);
10238 } else {
10239 /* Writing concatenation */
10240 i__1[0] = 1, a__1[0] = const_cast<char *> (side);
10241 i__1[1] = 1, a__1[1] = const_cast<char *> (trans);
10242 s_cat(ch__1, a__1, i__1, &c__2, 2_integer);
10243 ch__1 [2] = '\0';
10244 i__2 = *n - 1;
10245 i__3 = *n - 1;
10246 nb = ilaenv_(&c__1, "DORMQL", ch__1, m, &i__2, &i__3, &c_n1);
10247 }
10248 } else {
10249 if (left) {
10250 /* Writing concatenation */
10251 i__1[0] = 1, a__1[0] = const_cast<char *> (side);
10252 i__1[1] = 1, a__1[1] = const_cast<char *> (trans);
10253 s_cat(ch__1, a__1, i__1, &c__2, 2_integer);
10254 ch__1 [2] = '\0';
10255 i__2 = *m - 1;
10256 i__3 = *m - 1;
10257 nb = ilaenv_(&c__1, "DORMQR", ch__1, &i__2, n, &i__3, &c_n1);
10258 } else {
10259 /* Writing concatenation */
10260 i__1[0] = 1, a__1[0] = const_cast<char *> (side);
10261 i__1[1] = 1, a__1[1] = const_cast<char *> (trans);
10262 s_cat(ch__1, a__1, i__1, &c__2, 2_integer);
10263 ch__1 [2] = '\0';
10264 i__2 = *n - 1;
10265 i__3 = *n - 1;
10266 nb = ilaenv_(&c__1, "DORMQR", ch__1, m, &i__2, &i__3, &c_n1);
10267 }
10268 }
10269 lwkopt = std::max(1_integer,nw) * nb;
10270 work[1] = (double) lwkopt;
10271 }
10272
10273 if (*info != 0) {
10274 i__2 = -(*info);
10275 xerbla_("DORMTR", &i__2);
10276 return 0;
10277 } else if (lquery) {
10278 return 0;
10279 }
10280
10281 /* Quick return if possible */
10282
10283 if (*m == 0 || *n == 0 || nq == 1) {
10284 work[1] = 1.;
10285 return 0;
10286 }
10287
10288 if (left) {
10289 mi = *m - 1;
10290 ni = *n;
10291 } else {
10292 mi = *m;
10293 ni = *n - 1;
10294 }
10295
10296 if (upper) {
10297
10298 /* Q was determined by a call to DSYTRD with UPLO = 'U' */
10299
10300 i__2 = nq - 1;
10301 dormql_(side, trans, &mi, &ni, &i__2, &a[(a_dim1 << 1) + 1], lda, &
10302 tau[1], &c__[c_offset], ldc, &work[1], lwork, &iinfo);
10303 } else {
10304
10305 /* Q was determined by a call to DSYTRD with UPLO = 'L' */
10306
10307 if (left) {
10308 i1 = 2;
10309 i2 = 1;
10310 } else {
10311 i1 = 1;
10312 i2 = 2;
10313 }
10314 i__2 = nq - 1;
10315 dormqr_(side, trans, &mi, &ni, &i__2, &a[a_dim1 + 2], lda, &tau[1], &
10316 c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &iinfo);
10317 }
10318 work[1] = (double) lwkopt;
10319 return 0;
10320
10321 /* End of DORMTR */
10322
10323 } /* dormtr_ */
10324
10325 /* Subroutine */ int dpbcon_(const char *uplo, integer *n, integer *kd, double *
10326 ab, integer *ldab, double *anorm, double *rcond, double *
10327 work, integer *iwork, integer *info)
10328 {
10329 /* Table of constant values */
10330 static integer c__1 = 1;
10331
10332 /* System generated locals */
10333 integer ab_dim1, ab_offset, i__1;
10334 double d__1;
10335
10336 /* Local variables */
10337 integer ix, kase;
10338 double scale;
10339 integer isave[3];
10340 bool upper;
10341 double scalel;
10342 double scaleu;
10343 double ainvnm;
10344 char normin[1];
10345 double smlnum;
10346
10347
10348 /* -- LAPACK routine (version 3.1) -- */
10349 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
10350 /* November 2006 */
10351
10352 /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
10353
10354 /* .. Scalar Arguments .. */
10355 /* .. */
10356 /* .. Array Arguments .. */
10357 /* .. */
10358
10359 /* Purpose */
10360 /* ======= */
10361
10362 /* DPBCON estimates the reciprocal of the condition number (in the */
10363 /* 1-norm) of a real symmetric positive definite band matrix using the */
10364 /* Cholesky factorization A = U**T*U or A = L*L**T computed by DPBTRF. */
10365
10366 /* An estimate is obtained for norm(inv(A)), and the reciprocal of the */
10367 /* condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). */
10368
10369 /* Arguments */
10370 /* ========= */
10371
10372 /* UPLO (input) CHARACTER*1 */
10373 /* = 'U': Upper triangular factor stored in AB; */
10374 /* = 'L': Lower triangular factor stored in AB. */
10375
10376 /* N (input) INTEGER */
10377 /* The order of the matrix A. N >= 0. */
10378
10379 /* KD (input) INTEGER */
10380 /* The number of superdiagonals of the matrix A if UPLO = 'U', */
10381 /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
10382
10383 /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
10384 /* The triangular factor U or L from the Cholesky factorization */
10385 /* A = U**T*U or A = L*L**T of the band matrix A, stored in the */
10386 /* first KD+1 rows of the array. The j-th column of U or L is */
10387 /* stored in the j-th column of the array AB as follows: */
10388 /* if UPLO ='U', AB(kd+1+i-j,j) = U(i,j) for max(1,j-kd)<=i<=j; */
10389 /* if UPLO ='L', AB(1+i-j,j) = L(i,j) for j<=i<=min(n,j+kd). */
10390
10391 /* LDAB (input) INTEGER */
10392 /* The leading dimension of the array AB. LDAB >= KD+1. */
10393
10394 /* ANORM (input) DOUBLE PRECISION */
10395 /* The 1-norm (or infinity-norm) of the symmetric band matrix A. */
10396
10397 /* RCOND (output) DOUBLE PRECISION */
10398 /* The reciprocal of the condition number of the matrix A, */
10399 /* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an */
10400 /* estimate of the 1-norm of inv(A) computed in this routine. */
10401
10402 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
10403
10404 /* IWORK (workspace) INTEGER array, dimension (N) */
10405
10406 /* INFO (output) INTEGER */
10407 /* = 0: successful exit */
10408 /* < 0: if INFO = -i, the i-th argument had an illegal value */
10409
10410 /* ===================================================================== */
10411
10412 /* .. Parameters .. */
10413 /* .. */
10414 /* .. Local Scalars .. */
10415 /* .. */
10416 /* .. Local Arrays .. */
10417 /* .. */
10418 /* .. External Functions .. */
10419 /* .. */
10420 /* .. External Subroutines .. */
10421 /* .. */
10422 /* .. Intrinsic Functions .. */
10423 /* .. */
10424 /* .. Executable Statements .. */
10425
10426 /* Test the input parameters. */
10427
10428 /* Parameter adjustments */
10429 ab_dim1 = *ldab;
10430 ab_offset = 1 + ab_dim1;
10431 ab -= ab_offset;
10432 --work;
10433 --iwork;
10434
10435 /* Function Body */
10436 *info = 0;
10437 upper = lsame_(uplo, "U");
10438 if (! upper && ! lsame_(uplo, "L")) {
10439 *info = -1;
10440 } else if (*n < 0) {
10441 *info = -2;
10442 } else if (*kd < 0) {
10443 *info = -3;
10444 } else if (*ldab < *kd + 1) {
10445 *info = -5;
10446 } else if (*anorm < 0.) {
10447 *info = -6;
10448 }
10449 if (*info != 0) {
10450 i__1 = -(*info);
10451 xerbla_("DPBCON", &i__1);
10452 return 0;
10453 }
10454
10455 /* Quick return if possible */
10456
10457 *rcond = 0.;
10458 if (*n == 0) {
10459 *rcond = 1.;
10460 return 0;
10461 } else if (*anorm == 0.) {
10462 return 0;
10463 }
10464
10465 smlnum = dlamch_("Safe minimum");
10466
10467 /* Estimate the 1-norm of the inverse. */
10468
10469 kase = 0;
10470 *(unsigned char *)normin = 'N';
10471 L10:
10472 dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
10473 if (kase != 0) {
10474 if (upper) {
10475
10476 /* Multiply by inv(U'). */
10477
10478 dlatbs_("Upper", "Transpose", "Non-unit", normin, n, kd, &ab[
10479 ab_offset], ldab, &work[1], &scalel, &work[(*n << 1) + 1],
10480 info);
10481 *(unsigned char *)normin = 'Y';
10482
10483 /* Multiply by inv(U). */
10484
10485 dlatbs_("Upper", "No transpose", "Non-unit", normin, n, kd, &ab[
10486 ab_offset], ldab, &work[1], &scaleu, &work[(*n << 1) + 1],
10487 info);
10488 } else {
10489
10490 /* Multiply by inv(L). */
10491
10492 dlatbs_("Lower", "No transpose", "Non-unit", normin, n, kd, &ab[
10493 ab_offset], ldab, &work[1], &scalel, &work[(*n << 1) + 1],
10494 info);
10495 *(unsigned char *)normin = 'Y';
10496
10497 /* Multiply by inv(L'). */
10498
10499 dlatbs_("Lower", "Transpose", "Non-unit", normin, n, kd, &ab[
10500 ab_offset], ldab, &work[1], &scaleu, &work[(*n << 1) + 1],
10501 info);
10502 }
10503
10504 /* Multiply by 1/SCALE if doing so will not cause overflow. */
10505
10506 scale = scalel * scaleu;
10507 if (scale != 1.) {
10508 ix = idamax_(n, &work[1], &c__1);
10509 if (scale < (d__1 = work[ix], abs(d__1)) * smlnum || scale == 0.)
10510 {
10511 goto L20;
10512 }
10513 drscl_(n, &scale, &work[1], &c__1);
10514 }
10515 goto L10;
10516 }
10517
10518 /* Compute the estimate of the reciprocal condition number. */
10519
10520 if (ainvnm != 0.) {
10521 *rcond = 1. / ainvnm / *anorm;
10522 }
10523
10524 L20:
10525
10526 return 0;
10527
10528 /* End of DPBCON */
10529
10530 } /* dpbcon_ */
10531
10532 /* Subroutine */ int dpbequ_(const char *uplo, integer *n, integer *kd, double *
10533 ab, integer *ldab, double *s, double *scond, double *amax,
10534 integer *info)
10535 {
10536 /* System generated locals */
10537 integer ab_dim1, ab_offset, i__1;
10538 double d__1, d__2;
10539
10540 /* Local variables */
10541 integer i__, j;
10542 double smin;
10543 bool upper;
10544
10545
10546 /* -- LAPACK routine (version 3.1) -- */
10547 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
10548 /* November 2006 */
10549
10550 /* .. Scalar Arguments .. */
10551 /* .. */
10552 /* .. Array Arguments .. */
10553 /* .. */
10554
10555 /* Purpose */
10556 /* ======= */
10557
10558 /* DPBEQU computes row and column scalings intended to equilibrate a */
10559 /* symmetric positive definite band matrix A and reduce its condition */
10560 /* number (with respect to the two-norm). S contains the scale factors, */
10561 /* S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with */
10562 /* elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This */
10563 /* choice of S puts the condition number of B within a factor N of the */
10564 /* smallest possible condition number over all possible diagonal */
10565 /* scalings. */
10566
10567 /* Arguments */
10568 /* ========= */
10569
10570 /* UPLO (input) CHARACTER*1 */
10571 /* = 'U': Upper triangular of A is stored; */
10572 /* = 'L': Lower triangular of A is stored. */
10573
10574 /* N (input) INTEGER */
10575 /* The order of the matrix A. N >= 0. */
10576
10577 /* KD (input) INTEGER */
10578 /* The number of superdiagonals of the matrix A if UPLO = 'U', */
10579 /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
10580
10581 /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
10582 /* The upper or lower triangle of the symmetric band matrix A, */
10583 /* stored in the first KD+1 rows of the array. The j-th column */
10584 /* of A is stored in the j-th column of the array AB as follows: */
10585 /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
10586 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
10587
10588 /* LDAB (input) INTEGER */
10589 /* The leading dimension of the array A. LDAB >= KD+1. */
10590
10591 /* S (output) DOUBLE PRECISION array, dimension (N) */
10592 /* If INFO = 0, S contains the scale factors for A. */
10593
10594 /* SCOND (output) DOUBLE PRECISION */
10595 /* If INFO = 0, S contains the ratio of the smallest S(i) to */
10596 /* the largest S(i). If SCOND >= 0.1 and AMAX is neither too */
10597 /* large nor too small, it is not worth scaling by S. */
10598
10599 /* AMAX (output) DOUBLE PRECISION */
10600 /* Absolute value of largest matrix element. If AMAX is very */
10601 /* close to overflow or very close to underflow, the matrix */
10602 /* should be scaled. */
10603
10604 /* INFO (output) INTEGER */
10605 /* = 0: successful exit */
10606 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
10607 /* > 0: if INFO = i, the i-th diagonal element is nonpositive. */
10608
10609 /* ===================================================================== */
10610
10611 /* .. Parameters .. */
10612 /* .. */
10613 /* .. Local Scalars .. */
10614 /* .. */
10615 /* .. External Functions .. */
10616 /* .. */
10617 /* .. External Subroutines .. */
10618 /* .. */
10619 /* .. Intrinsic Functions .. */
10620 /* .. */
10621 /* .. Executable Statements .. */
10622
10623 /* Test the input parameters. */
10624
10625 /* Parameter adjustments */
10626 ab_dim1 = *ldab;
10627 ab_offset = 1 + ab_dim1;
10628 ab -= ab_offset;
10629 --s;
10630
10631 /* Function Body */
10632 *info = 0;
10633 upper = lsame_(uplo, "U");
10634 if (! upper && ! lsame_(uplo, "L")) {
10635 *info = -1;
10636 } else if (*n < 0) {
10637 *info = -2;
10638 } else if (*kd < 0) {
10639 *info = -3;
10640 } else if (*ldab < *kd + 1) {
10641 *info = -5;
10642 }
10643 if (*info != 0) {
10644 i__1 = -(*info);
10645 xerbla_("DPBEQU", &i__1);
10646 return 0;
10647 }
10648
10649 /* Quick return if possible */
10650
10651 if (*n == 0) {
10652 *scond = 1.;
10653 *amax = 0.;
10654 return 0;
10655 }
10656
10657 if (upper) {
10658 j = *kd + 1;
10659 } else {
10660 j = 1;
10661 }
10662
10663 /* Initialize SMIN and AMAX. */
10664
10665 s[1] = ab[j + ab_dim1];
10666 smin = s[1];
10667 *amax = s[1];
10668
10669 /* Find the minimum and maximum diagonal elements. */
10670
10671 i__1 = *n;
10672 for (i__ = 2; i__ <= i__1; ++i__) {
10673 s[i__] = ab[j + i__ * ab_dim1];
10674 /* Computing MIN */
10675 d__1 = smin, d__2 = s[i__];
10676 smin = std::min(d__1,d__2);
10677 /* Computing MAX */
10678 d__1 = *amax, d__2 = s[i__];
10679 *amax = std::max(d__1,d__2);
10680 /* L10: */
10681 }
10682
10683 if (smin <= 0.) {
10684
10685 /* Find the first non-positive diagonal element and return. */
10686
10687 i__1 = *n;
10688 for (i__ = 1; i__ <= i__1; ++i__) {
10689 if (s[i__] <= 0.) {
10690 *info = i__;
10691 return 0;
10692 }
10693 /* L20: */
10694 }
10695 } else {
10696
10697 /* Set the scale factors to the reciprocals */
10698 /* of the diagonal elements. */
10699
10700 i__1 = *n;
10701 for (i__ = 1; i__ <= i__1; ++i__) {
10702 s[i__] = 1. / sqrt(s[i__]);
10703 /* L30: */
10704 }
10705
10706 /* Compute SCOND = min(S(I)) / max(S(I)) */
10707
10708 *scond = sqrt(smin) / sqrt(*amax);
10709 }
10710 return 0;
10711
10712 /* End of DPBEQU */
10713
10714 } /* dpbequ_ */
10715
10716 /* Subroutine */ int dpbrfs_(const char *uplo, integer *n, integer *kd, integer *
10717 nrhs, double *ab, integer *ldab, double *afb, integer *ldafb,
10718 double *b, integer *ldb, double *x, integer *ldx, double *
10719 ferr, double *berr, double *work, integer *iwork, integer *
10720 info)
10721 {
10722 /* Table of constant values */
10723 static integer c__1 = 1;
10724 static double c_b12 = -1.;
10725 static double c_b14 = 1.;
10726
10727 /* System generated locals */
10728 integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset,
10729 x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5;
10730 double d__1, d__2, d__3;
10731
10732 /* Local variables */
10733 integer i__, j, k, l;
10734 double s, xk;
10735 integer nz;
10736 double eps;
10737 integer kase;
10738 double safe1, safe2;
10739 integer isave[3];
10740 integer count;
10741 bool upper;
10742 double safmin;
10743 double lstres;
10744
10745
10746 /* -- LAPACK routine (version 3.1) -- */
10747 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
10748 /* November 2006 */
10749
10750 /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
10751
10752 /* .. Scalar Arguments .. */
10753 /* .. */
10754 /* .. Array Arguments .. */
10755 /* .. */
10756
10757 /* Purpose */
10758 /* ======= */
10759
10760 /* DPBRFS improves the computed solution to a system of linear */
10761 /* equations when the coefficient matrix is symmetric positive definite */
10762 /* and banded, and provides error bounds and backward error estimates */
10763 /* for the solution. */
10764
10765 /* Arguments */
10766 /* ========= */
10767
10768 /* UPLO (input) CHARACTER*1 */
10769 /* = 'U': Upper triangle of A is stored; */
10770 /* = 'L': Lower triangle of A is stored. */
10771
10772 /* N (input) INTEGER */
10773 /* The order of the matrix A. N >= 0. */
10774
10775 /* KD (input) INTEGER */
10776 /* The number of superdiagonals of the matrix A if UPLO = 'U', */
10777 /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
10778
10779 /* NRHS (input) INTEGER */
10780 /* The number of right hand sides, i.e., the number of columns */
10781 /* of the matrices B and X. NRHS >= 0. */
10782
10783 /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
10784 /* The upper or lower triangle of the symmetric band matrix A, */
10785 /* stored in the first KD+1 rows of the array. The j-th column */
10786 /* of A is stored in the j-th column of the array AB as follows: */
10787 /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
10788 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
10789
10790 /* LDAB (input) INTEGER */
10791 /* The leading dimension of the array AB. LDAB >= KD+1. */
10792
10793 /* AFB (input) DOUBLE PRECISION array, dimension (LDAFB,N) */
10794 /* The triangular factor U or L from the Cholesky factorization */
10795 /* A = U**T*U or A = L*L**T of the band matrix A as computed by */
10796 /* DPBTRF, in the same storage format as A (see AB). */
10797
10798 /* LDAFB (input) INTEGER */
10799 /* The leading dimension of the array AFB. LDAFB >= KD+1. */
10800
10801 /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
10802 /* The right hand side matrix B. */
10803
10804 /* LDB (input) INTEGER */
10805 /* The leading dimension of the array B. LDB >= max(1,N). */
10806
10807 /* X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
10808 /* On entry, the solution matrix X, as computed by DPBTRS. */
10809 /* On exit, the improved solution matrix X. */
10810
10811 /* LDX (input) INTEGER */
10812 /* The leading dimension of the array X. LDX >= max(1,N). */
10813
10814 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
10815 /* The estimated forward error bound for each solution vector */
10816 /* X(j) (the j-th column of the solution matrix X). */
10817 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
10818 /* is an estimated upper bound for the magnitude of the largest */
10819 /* element in (X(j) - XTRUE) divided by the magnitude of the */
10820 /* largest element in X(j). The estimate is as reliable as */
10821 /* the estimate for RCOND, and is almost always a slight */
10822 /* overestimate of the true error. */
10823
10824 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
10825 /* The componentwise relative backward error of each solution */
10826 /* vector X(j) (i.e., the smallest relative change in */
10827 /* any element of A or B that makes X(j) an exact solution). */
10828
10829 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
10830
10831 /* IWORK (workspace) INTEGER array, dimension (N) */
10832
10833 /* INFO (output) INTEGER */
10834 /* = 0: successful exit */
10835 /* < 0: if INFO = -i, the i-th argument had an illegal value */
10836
10837 /* Internal Parameters */
10838 /* =================== */
10839
10840 /* ITMAX is the maximum number of steps of iterative refinement. */
10841
10842 /* ===================================================================== */
10843
10844 /* .. Parameters .. */
10845 /* .. */
10846 /* .. Local Scalars .. */
10847 /* .. */
10848 /* .. Local Arrays .. */
10849 /* .. */
10850 /* .. External Subroutines .. */
10851 /* .. */
10852 /* .. Intrinsic Functions .. */
10853 /* .. */
10854 /* .. External Functions .. */
10855 /* .. */
10856 /* .. Executable Statements .. */
10857
10858 /* Test the input parameters. */
10859
10860 /* Parameter adjustments */
10861 ab_dim1 = *ldab;
10862 ab_offset = 1 + ab_dim1;
10863 ab -= ab_offset;
10864 afb_dim1 = *ldafb;
10865 afb_offset = 1 + afb_dim1;
10866 afb -= afb_offset;
10867 b_dim1 = *ldb;
10868 b_offset = 1 + b_dim1;
10869 b -= b_offset;
10870 x_dim1 = *ldx;
10871 x_offset = 1 + x_dim1;
10872 x -= x_offset;
10873 --ferr;
10874 --berr;
10875 --work;
10876 --iwork;
10877
10878 /* Function Body */
10879 *info = 0;
10880 upper = lsame_(uplo, "U");
10881 if (! upper && ! lsame_(uplo, "L")) {
10882 *info = -1;
10883 } else if (*n < 0) {
10884 *info = -2;
10885 } else if (*kd < 0) {
10886 *info = -3;
10887 } else if (*nrhs < 0) {
10888 *info = -4;
10889 } else if (*ldab < *kd + 1) {
10890 *info = -6;
10891 } else if (*ldafb < *kd + 1) {
10892 *info = -8;
10893 } else if (*ldb < std::max(1_integer,*n)) {
10894 *info = -10;
10895 } else if (*ldx < std::max(1_integer,*n)) {
10896 *info = -12;
10897 }
10898 if (*info != 0) {
10899 i__1 = -(*info);
10900 xerbla_("DPBRFS", &i__1);
10901 return 0;
10902 }
10903
10904 /* Quick return if possible */
10905
10906 if (*n == 0 || *nrhs == 0) {
10907 i__1 = *nrhs;
10908 for (j = 1; j <= i__1; ++j) {
10909 ferr[j] = 0.;
10910 berr[j] = 0.;
10911 /* L10: */
10912 }
10913 return 0;
10914 }
10915
10916 /* NZ = maximum number of nonzero elements in each row of A, plus 1 */
10917
10918 /* Computing MIN */
10919 i__1 = *n + 1, i__2 = (*kd << 1) + 2;
10920 nz = std::min(i__1,i__2);
10921 eps = dlamch_("Epsilon");
10922 safmin = dlamch_("Safe minimum");
10923 safe1 = nz * safmin;
10924 safe2 = safe1 / eps;
10925
10926 /* Do for each right hand side */
10927
10928 i__1 = *nrhs;
10929 for (j = 1; j <= i__1; ++j) {
10930
10931 count = 1;
10932 lstres = 3.;
10933 L20:
10934
10935 /* Loop until stopping criterion is satisfied. */
10936
10937 /* Compute residual R = B - A * X */
10938
10939 dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
10940 dsbmv_(uplo, n, kd, &c_b12, &ab[ab_offset], ldab, &x[j * x_dim1 + 1],
10941 &c__1, &c_b14, &work[*n + 1], &c__1);
10942
10943 /* Compute componentwise relative backward error from formula */
10944
10945 /* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
10946
10947 /* where abs(Z) is the componentwise absolute value of the matrix */
10948 /* or vector Z. If the i-th component of the denominator is less */
10949 /* than SAFE2, then SAFE1 is added to the i-th components of the */
10950 /* numerator and denominator before dividing. */
10951
10952 i__2 = *n;
10953 for (i__ = 1; i__ <= i__2; ++i__) {
10954 work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
10955 /* L30: */
10956 }
10957
10958 /* Compute abs(A)*abs(X) + abs(B). */
10959
10960 if (upper) {
10961 i__2 = *n;
10962 for (k = 1; k <= i__2; ++k) {
10963 s = 0.;
10964 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
10965 l = *kd + 1 - k;
10966 /* Computing MAX */
10967 i__3 = 1, i__4 = k - *kd;
10968 i__5 = k - 1;
10969 for (i__ = std::max(i__3,i__4); i__ <= i__5; ++i__) {
10970 work[i__] += (d__1 = ab[l + i__ + k * ab_dim1], abs(d__1))
10971 * xk;
10972 s += (d__1 = ab[l + i__ + k * ab_dim1], abs(d__1)) * (
10973 d__2 = x[i__ + j * x_dim1], abs(d__2));
10974 /* L40: */
10975 }
10976 work[k] = work[k] + (d__1 = ab[*kd + 1 + k * ab_dim1], abs(
10977 d__1)) * xk + s;
10978 /* L50: */
10979 }
10980 } else {
10981 i__2 = *n;
10982 for (k = 1; k <= i__2; ++k) {
10983 s = 0.;
10984 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
10985 work[k] += (d__1 = ab[k * ab_dim1 + 1], abs(d__1)) * xk;
10986 l = 1 - k;
10987 /* Computing MIN */
10988 i__3 = *n, i__4 = k + *kd;
10989 i__5 = std::min(i__3,i__4);
10990 for (i__ = k + 1; i__ <= i__5; ++i__) {
10991 work[i__] += (d__1 = ab[l + i__ + k * ab_dim1], abs(d__1))
10992 * xk;
10993 s += (d__1 = ab[l + i__ + k * ab_dim1], abs(d__1)) * (
10994 d__2 = x[i__ + j * x_dim1], abs(d__2));
10995 /* L60: */
10996 }
10997 work[k] += s;
10998 /* L70: */
10999 }
11000 }
11001 s = 0.;
11002 i__2 = *n;
11003 for (i__ = 1; i__ <= i__2; ++i__) {
11004 if (work[i__] > safe2) {
11005 /* Computing MAX */
11006 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
11007 i__];
11008 s = std::max(d__2,d__3);
11009 } else {
11010 /* Computing MAX */
11011 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1)
11012 / (work[i__] + safe1);
11013 s = std::max(d__2,d__3);
11014 }
11015 /* L80: */
11016 }
11017 berr[j] = s;
11018
11019 /* Test stopping criterion. Continue iterating if */
11020 /* 1) The residual BERR(J) is larger than machine epsilon, and */
11021 /* 2) BERR(J) decreased by at least a factor of 2 during the */
11022 /* last iteration, and */
11023 /* 3) At most ITMAX iterations tried. */
11024
11025 if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
11026
11027 /* Update solution and try again. */
11028
11029 dpbtrs_(uplo, n, kd, &c__1, &afb[afb_offset], ldafb, &work[*n + 1]
11030 , n, info);
11031 daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
11032 ;
11033 lstres = berr[j];
11034 ++count;
11035 goto L20;
11036 }
11037
11038 /* Bound error from formula */
11039
11040 /* norm(X - XTRUE) / norm(X) .le. FERR = */
11041 /* norm( abs(inv(A))* */
11042 /* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
11043
11044 /* where */
11045 /* norm(Z) is the magnitude of the largest component of Z */
11046 /* inv(A) is the inverse of A */
11047 /* abs(Z) is the componentwise absolute value of the matrix or */
11048 /* vector Z */
11049 /* NZ is the maximum number of nonzeros in any row of A, plus 1 */
11050 /* EPS is machine epsilon */
11051
11052 /* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
11053 /* is incremented by SAFE1 if the i-th component of */
11054 /* abs(A)*abs(X) + abs(B) is less than SAFE2. */
11055
11056 /* Use DLACN2 to estimate the infinity-norm of the matrix */
11057 /* inv(A) * diag(W), */
11058 /* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
11059
11060 i__2 = *n;
11061 for (i__ = 1; i__ <= i__2; ++i__) {
11062 if (work[i__] > safe2) {
11063 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
11064 work[i__];
11065 } else {
11066 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
11067 work[i__] + safe1;
11068 }
11069 /* L90: */
11070 }
11071
11072 kase = 0;
11073 L100:
11074 dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
11075 kase, isave);
11076 if (kase != 0) {
11077 if (kase == 1) {
11078
11079 /* Multiply by diag(W)*inv(A'). */
11080
11081 dpbtrs_(uplo, n, kd, &c__1, &afb[afb_offset], ldafb, &work[*n
11082 + 1], n, info);
11083 i__2 = *n;
11084 for (i__ = 1; i__ <= i__2; ++i__) {
11085 work[*n + i__] *= work[i__];
11086 /* L110: */
11087 }
11088 } else if (kase == 2) {
11089
11090 /* Multiply by inv(A)*diag(W). */
11091
11092 i__2 = *n;
11093 for (i__ = 1; i__ <= i__2; ++i__) {
11094 work[*n + i__] *= work[i__];
11095 /* L120: */
11096 }
11097 dpbtrs_(uplo, n, kd, &c__1, &afb[afb_offset], ldafb, &work[*n
11098 + 1], n, info);
11099 }
11100 goto L100;
11101 }
11102
11103 /* Normalize error. */
11104
11105 lstres = 0.;
11106 i__2 = *n;
11107 for (i__ = 1; i__ <= i__2; ++i__) {
11108 /* Computing MAX */
11109 d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
11110 lstres = std::max(d__2,d__3);
11111 /* L130: */
11112 }
11113 if (lstres != 0.) {
11114 ferr[j] /= lstres;
11115 }
11116
11117 /* L140: */
11118 }
11119
11120 return 0;
11121
11122 /* End of DPBRFS */
11123
11124 } /* dpbrfs_ */
11125
11126 /* Subroutine */ int dpbstf_(const char *uplo, integer *n, integer *kd, double *
11127 ab, integer *ldab, integer *info)
11128 {
11129 /* Table of constant values */
11130 static integer c__1 = 1;
11131 static double c_b9 = -1.;
11132
11133 /* System generated locals */
11134 integer ab_dim1, ab_offset, i__1, i__2, i__3;
11135 double d__1;
11136
11137 /* Local variables */
11138 integer j, m, km;
11139 double ajj;
11140 integer kld;
11141 bool upper;
11142
11143
11144 /* -- LAPACK routine (version 3.1) -- */
11145 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
11146 /* November 2006 */
11147
11148 /* .. Scalar Arguments .. */
11149 /* .. */
11150 /* .. Array Arguments .. */
11151 /* .. */
11152
11153 /* Purpose */
11154 /* ======= */
11155
11156 /* DPBSTF computes a split Cholesky factorization of a real */
11157 /* symmetric positive definite band matrix A. */
11158
11159 /* This routine is designed to be used in conjunction with DSBGST. */
11160
11161 /* The factorization has the form A = S**T*S where S is a band matrix */
11162 /* of the same bandwidth as A and the following structure: */
11163
11164 /* S = ( U ) */
11165 /* ( M L ) */
11166
11167 /* where U is upper triangular of order m = (n+kd)/2, and L is lower */
11168 /* triangular of order n-m. */
11169
11170 /* Arguments */
11171 /* ========= */
11172
11173 /* UPLO (input) CHARACTER*1 */
11174 /* = 'U': Upper triangle of A is stored; */
11175 /* = 'L': Lower triangle of A is stored. */
11176
11177 /* N (input) INTEGER */
11178 /* The order of the matrix A. N >= 0. */
11179
11180 /* KD (input) INTEGER */
11181 /* The number of superdiagonals of the matrix A if UPLO = 'U', */
11182 /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
11183
11184 /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */
11185 /* On entry, the upper or lower triangle of the symmetric band */
11186 /* matrix A, stored in the first kd+1 rows of the array. The */
11187 /* j-th column of A is stored in the j-th column of the array AB */
11188 /* as follows: */
11189 /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
11190 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
11191
11192 /* On exit, if INFO = 0, the factor S from the split Cholesky */
11193 /* factorization A = S**T*S. See Further Details. */
11194
11195 /* LDAB (input) INTEGER */
11196 /* The leading dimension of the array AB. LDAB >= KD+1. */
11197
11198 /* INFO (output) INTEGER */
11199 /* = 0: successful exit */
11200 /* < 0: if INFO = -i, the i-th argument had an illegal value */
11201 /* > 0: if INFO = i, the factorization could not be completed, */
11202 /* because the updated element a(i,i) was negative; the */
11203 /* matrix A is not positive definite. */
11204
11205 /* Further Details */
11206 /* =============== */
11207
11208 /* The band storage scheme is illustrated by the following example, when */
11209 /* N = 7, KD = 2: */
11210
11211 /* S = ( s11 s12 s13 ) */
11212 /* ( s22 s23 s24 ) */
11213 /* ( s33 s34 ) */
11214 /* ( s44 ) */
11215 /* ( s53 s54 s55 ) */
11216 /* ( s64 s65 s66 ) */
11217 /* ( s75 s76 s77 ) */
11218
11219 /* If UPLO = 'U', the array AB holds: */
11220
11221 /* on entry: on exit: */
11222
11223 /* * * a13 a24 a35 a46 a57 * * s13 s24 s53 s64 s75 */
11224 /* * a12 a23 a34 a45 a56 a67 * s12 s23 s34 s54 s65 s76 */
11225 /* a11 a22 a33 a44 a55 a66 a77 s11 s22 s33 s44 s55 s66 s77 */
11226
11227 /* If UPLO = 'L', the array AB holds: */
11228
11229 /* on entry: on exit: */
11230
11231 /* a11 a22 a33 a44 a55 a66 a77 s11 s22 s33 s44 s55 s66 s77 */
11232 /* a21 a32 a43 a54 a65 a76 * s12 s23 s34 s54 s65 s76 * */
11233 /* a31 a42 a53 a64 a64 * * s13 s24 s53 s64 s75 * * */
11234
11235 /* Array elements marked * are not used by the routine. */
11236
11237 /* ===================================================================== */
11238
11239 /* .. Parameters .. */
11240 /* .. */
11241 /* .. Local Scalars .. */
11242 /* .. */
11243 /* .. External Functions .. */
11244 /* .. */
11245 /* .. External Subroutines .. */
11246 /* .. */
11247 /* .. Intrinsic Functions .. */
11248 /* .. */
11249 /* .. Executable Statements .. */
11250
11251 /* Test the input parameters. */
11252
11253 /* Parameter adjustments */
11254 ab_dim1 = *ldab;
11255 ab_offset = 1 + ab_dim1;
11256 ab -= ab_offset;
11257
11258 /* Function Body */
11259 *info = 0;
11260 upper = lsame_(uplo, "U");
11261 if (! upper && ! lsame_(uplo, "L")) {
11262 *info = -1;
11263 } else if (*n < 0) {
11264 *info = -2;
11265 } else if (*kd < 0) {
11266 *info = -3;
11267 } else if (*ldab < *kd + 1) {
11268 *info = -5;
11269 }
11270 if (*info != 0) {
11271 i__1 = -(*info);
11272 xerbla_("DPBSTF", &i__1);
11273 return 0;
11274 }
11275
11276 /* Quick return if possible */
11277
11278 if (*n == 0) {
11279 return 0;
11280 }
11281
11282 /* Computing MAX */
11283 i__1 = 1, i__2 = *ldab - 1;
11284 kld = std::max(i__1,i__2);
11285
11286 /* Set the splitting point m. */
11287
11288 m = (*n + *kd) / 2;
11289
11290 if (upper) {
11291
11292 /* Factorize A(m+1:n,m+1:n) as L**T*L, and update A(1:m,1:m). */
11293
11294 i__1 = m + 1;
11295 for (j = *n; j >= i__1; --j) {
11296
11297 /* Compute s(j,j) and test for non-positive-definiteness. */
11298
11299 ajj = ab[*kd + 1 + j * ab_dim1];
11300 if (ajj <= 0.) {
11301 goto L50;
11302 }
11303 ajj = sqrt(ajj);
11304 ab[*kd + 1 + j * ab_dim1] = ajj;
11305 /* Computing MIN */
11306 i__2 = j - 1;
11307 km = std::min(i__2,*kd);
11308
11309 /* Compute elements j-km:j-1 of the j-th column and update the */
11310 /* the leading submatrix within the band. */
11311
11312 d__1 = 1. / ajj;
11313 dscal_(&km, &d__1, &ab[*kd + 1 - km + j * ab_dim1], &c__1);
11314 dsyr_("Upper", &km, &c_b9, &ab[*kd + 1 - km + j * ab_dim1], &c__1,
11315 &ab[*kd + 1 + (j - km) * ab_dim1], &kld);
11316 /* L10: */
11317 }
11318
11319 /* Factorize the updated submatrix A(1:m,1:m) as U**T*U. */
11320
11321 i__1 = m;
11322 for (j = 1; j <= i__1; ++j) {
11323
11324 /* Compute s(j,j) and test for non-positive-definiteness. */
11325
11326 ajj = ab[*kd + 1 + j * ab_dim1];
11327 if (ajj <= 0.) {
11328 goto L50;
11329 }
11330 ajj = sqrt(ajj);
11331 ab[*kd + 1 + j * ab_dim1] = ajj;
11332 /* Computing MIN */
11333 i__2 = *kd, i__3 = m - j;
11334 km = std::min(i__2,i__3);
11335
11336 /* Compute elements j+1:j+km of the j-th row and update the */
11337 /* trailing submatrix within the band. */
11338
11339 if (km > 0) {
11340 d__1 = 1. / ajj;
11341 dscal_(&km, &d__1, &ab[*kd + (j + 1) * ab_dim1], &kld);
11342 dsyr_("Upper", &km, &c_b9, &ab[*kd + (j + 1) * ab_dim1], &kld,
11343 &ab[*kd + 1 + (j + 1) * ab_dim1], &kld);
11344 }
11345 /* L20: */
11346 }
11347 } else {
11348
11349 /* Factorize A(m+1:n,m+1:n) as L**T*L, and update A(1:m,1:m). */
11350
11351 i__1 = m + 1;
11352 for (j = *n; j >= i__1; --j) {
11353
11354 /* Compute s(j,j) and test for non-positive-definiteness. */
11355
11356 ajj = ab[j * ab_dim1 + 1];
11357 if (ajj <= 0.) {
11358 goto L50;
11359 }
11360 ajj = sqrt(ajj);
11361 ab[j * ab_dim1 + 1] = ajj;
11362 /* Computing MIN */
11363 i__2 = j - 1;
11364 km = std::min(i__2,*kd);
11365
11366 /* Compute elements j-km:j-1 of the j-th row and update the */
11367 /* trailing submatrix within the band. */
11368
11369 d__1 = 1. / ajj;
11370 dscal_(&km, &d__1, &ab[km + 1 + (j - km) * ab_dim1], &kld);
11371 dsyr_("Lower", &km, &c_b9, &ab[km + 1 + (j - km) * ab_dim1], &kld,
11372 &ab[(j - km) * ab_dim1 + 1], &kld);
11373 /* L30: */
11374 }
11375
11376 /* Factorize the updated submatrix A(1:m,1:m) as U**T*U. */
11377
11378 i__1 = m;
11379 for (j = 1; j <= i__1; ++j) {
11380
11381 /* Compute s(j,j) and test for non-positive-definiteness. */
11382
11383 ajj = ab[j * ab_dim1 + 1];
11384 if (ajj <= 0.) {
11385 goto L50;
11386 }
11387 ajj = sqrt(ajj);
11388 ab[j * ab_dim1 + 1] = ajj;
11389 /* Computing MIN */
11390 i__2 = *kd, i__3 = m - j;
11391 km = std::min(i__2,i__3);
11392
11393 /* Compute elements j+1:j+km of the j-th column and update the */
11394 /* trailing submatrix within the band. */
11395
11396 if (km > 0) {
11397 d__1 = 1. / ajj;
11398 dscal_(&km, &d__1, &ab[j * ab_dim1 + 2], &c__1);
11399 dsyr_("Lower", &km, &c_b9, &ab[j * ab_dim1 + 2], &c__1, &ab[(
11400 j + 1) * ab_dim1 + 1], &kld);
11401 }
11402 /* L40: */
11403 }
11404 }
11405 return 0;
11406
11407 L50:
11408 *info = j;
11409 return 0;
11410
11411 /* End of DPBSTF */
11412
11413 } /* dpbstf_ */
11414
11415 /* Subroutine */ int dpbsv_(const char *uplo, integer *n, integer *kd, integer *
11416 nrhs, double *ab, integer *ldab, double *b, integer *ldb,
11417 integer *info)
11418 {
11419 /* System generated locals */
11420 integer ab_dim1, ab_offset, b_dim1, b_offset, i__1;
11421
11422 /* -- LAPACK driver routine (version 3.1) -- */
11423 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
11424 /* November 2006 */
11425
11426 /* .. Scalar Arguments .. */
11427 /* .. */
11428 /* .. Array Arguments .. */
11429 /* .. */
11430
11431 /* Purpose */
11432 /* ======= */
11433
11434 /* DPBSV computes the solution to a real system of linear equations */
11435 /* A * X = B, */
11436 /* where A is an N-by-N symmetric positive definite band matrix and X */
11437 /* and B are N-by-NRHS matrices. */
11438
11439 /* The Cholesky decomposition is used to factor A as */
11440 /* A = U**T * U, if UPLO = 'U', or */
11441 /* A = L * L**T, if UPLO = 'L', */
11442 /* where U is an upper triangular band matrix, and L is a lower */
11443 /* triangular band matrix, with the same number of superdiagonals or */
11444 /* subdiagonals as A. The factored form of A is then used to solve the */
11445 /* system of equations A * X = B. */
11446
11447 /* Arguments */
11448 /* ========= */
11449
11450 /* UPLO (input) CHARACTER*1 */
11451 /* = 'U': Upper triangle of A is stored; */
11452 /* = 'L': Lower triangle of A is stored. */
11453
11454 /* N (input) INTEGER */
11455 /* The number of linear equations, i.e., the order of the */
11456 /* matrix A. N >= 0. */
11457
11458 /* KD (input) INTEGER */
11459 /* The number of superdiagonals of the matrix A if UPLO = 'U', */
11460 /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
11461
11462 /* NRHS (input) INTEGER */
11463 /* The number of right hand sides, i.e., the number of columns */
11464 /* of the matrix B. NRHS >= 0. */
11465
11466 /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */
11467 /* On entry, the upper or lower triangle of the symmetric band */
11468 /* matrix A, stored in the first KD+1 rows of the array. The */
11469 /* j-th column of A is stored in the j-th column of the array AB */
11470 /* as follows: */
11471 /* if UPLO = 'U', AB(KD+1+i-j,j) = A(i,j) for max(1,j-KD)<=i<=j; */
11472 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(N,j+KD). */
11473 /* See below for further details. */
11474
11475 /* On exit, if INFO = 0, the triangular factor U or L from the */
11476 /* Cholesky factorization A = U**T*U or A = L*L**T of the band */
11477 /* matrix A, in the same storage format as A. */
11478
11479 /* LDAB (input) INTEGER */
11480 /* The leading dimension of the array AB. LDAB >= KD+1. */
11481
11482 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
11483 /* On entry, the N-by-NRHS right hand side matrix B. */
11484 /* On exit, if INFO = 0, the N-by-NRHS solution matrix X. */
11485
11486 /* LDB (input) INTEGER */
11487 /* The leading dimension of the array B. LDB >= max(1,N). */
11488
11489 /* INFO (output) INTEGER */
11490 /* = 0: successful exit */
11491 /* < 0: if INFO = -i, the i-th argument had an illegal value */
11492 /* > 0: if INFO = i, the leading minor of order i of A is not */
11493 /* positive definite, so the factorization could not be */
11494 /* completed, and the solution has not been computed. */
11495
11496 /* Further Details */
11497 /* =============== */
11498
11499 /* The band storage scheme is illustrated by the following example, when */
11500 /* N = 6, KD = 2, and UPLO = 'U': */
11501
11502 /* On entry: On exit: */
11503
11504 /* * * a13 a24 a35 a46 * * u13 u24 u35 u46 */
11505 /* * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56 */
11506 /* a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66 */
11507
11508 /* Similarly, if UPLO = 'L' the format of A is as follows: */
11509
11510 /* On entry: On exit: */
11511
11512 /* a11 a22 a33 a44 a55 a66 l11 l22 l33 l44 l55 l66 */
11513 /* a21 a32 a43 a54 a65 * l21 l32 l43 l54 l65 * */
11514 /* a31 a42 a53 a64 * * l31 l42 l53 l64 * * */
11515
11516 /* Array elements marked * are not used by the routine. */
11517
11518 /* ===================================================================== */
11519
11520 /* .. External Functions .. */
11521 /* .. */
11522 /* .. External Subroutines .. */
11523 /* .. */
11524 /* .. Intrinsic Functions .. */
11525 /* .. */
11526 /* .. Executable Statements .. */
11527
11528 /* Test the input parameters. */
11529
11530 /* Parameter adjustments */
11531 ab_dim1 = *ldab;
11532 ab_offset = 1 + ab_dim1;
11533 ab -= ab_offset;
11534 b_dim1 = *ldb;
11535 b_offset = 1 + b_dim1;
11536 b -= b_offset;
11537
11538 /* Function Body */
11539 *info = 0;
11540 if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
11541 *info = -1;
11542 } else if (*n < 0) {
11543 *info = -2;
11544 } else if (*kd < 0) {
11545 *info = -3;
11546 } else if (*nrhs < 0) {
11547 *info = -4;
11548 } else if (*ldab < *kd + 1) {
11549 *info = -6;
11550 } else if (*ldb < std::max(1_integer,*n)) {
11551 *info = -8;
11552 }
11553 if (*info != 0) {
11554 i__1 = -(*info);
11555 xerbla_("DPBSV ", &i__1);
11556 return 0;
11557 }
11558
11559 /* Compute the Cholesky factorization A = U'*U or A = L*L'. */
11560
11561 dpbtrf_(uplo, n, kd, &ab[ab_offset], ldab, info);
11562 if (*info == 0) {
11563
11564 /* Solve the system A*X = B, overwriting B with X. */
11565
11566 dpbtrs_(uplo, n, kd, nrhs, &ab[ab_offset], ldab, &b[b_offset], ldb,
11567 info);
11568
11569 }
11570 return 0;
11571
11572 /* End of DPBSV */
11573
11574 } /* dpbsv_ */
11575
11576 /* Subroutine */ int dpbsvx_(const char *fact, const char *uplo, integer *n, integer *kd,
11577 integer *nrhs, double *ab, integer *ldab, double *afb,
11578 integer *ldafb, char *equed, double *s, double *b, integer *
11579 ldb, double *x, integer *ldx, double *rcond, double *ferr,
11580 double *berr, double *work, integer *iwork, integer *info)
11581 {
11582 /* Table of constant values */
11583 static integer c__1 = 1;
11584
11585 /* System generated locals */
11586 integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset,
11587 x_dim1, x_offset, i__1, i__2;
11588 double d__1, d__2;
11589
11590 /* Local variables */
11591 integer i__, j, j1, j2;
11592 double amax, smin, smax;
11593 double scond, anorm;
11594 bool equil, rcequ, upper;
11595 bool nofact;
11596 double bignum;
11597 integer infequ;
11598 double smlnum;
11599
11600
11601 /* -- LAPACK driver routine (version 3.1) -- */
11602 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
11603 /* November 2006 */
11604
11605 /* .. Scalar Arguments .. */
11606 /* .. */
11607 /* .. Array Arguments .. */
11608 /* .. */
11609
11610 /* Purpose */
11611 /* ======= */
11612
11613 /* DPBSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to */
11614 /* compute the solution to a real system of linear equations */
11615 /* A * X = B, */
11616 /* where A is an N-by-N symmetric positive definite band matrix and X */
11617 /* and B are N-by-NRHS matrices. */
11618
11619 /* Error bounds on the solution and a condition estimate are also */
11620 /* provided. */
11621
11622 /* Description */
11623 /* =========== */
11624
11625 /* The following steps are performed: */
11626
11627 /* 1. If FACT = 'E', real scaling factors are computed to equilibrate */
11628 /* the system: */
11629 /* diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B */
11630 /* Whether or not the system will be equilibrated depends on the */
11631 /* scaling of the matrix A, but if equilibration is used, A is */
11632 /* overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */
11633
11634 /* 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to */
11635 /* factor the matrix A (after equilibration if FACT = 'E') as */
11636 /* A = U**T * U, if UPLO = 'U', or */
11637 /* A = L * L**T, if UPLO = 'L', */
11638 /* where U is an upper triangular band matrix, and L is a lower */
11639 /* triangular band matrix. */
11640
11641 /* 3. If the leading i-by-i principal minor is not positive definite, */
11642 /* then the routine returns with INFO = i. Otherwise, the factored */
11643 /* form of A is used to estimate the condition number of the matrix */
11644 /* A. If the reciprocal of the condition number is less than machine */
11645 /* precision, INFO = N+1 is returned as a warning, but the routine */
11646 /* still goes on to solve for X and compute error bounds as */
11647 /* described below. */
11648
11649 /* 4. The system of equations is solved for X using the factored form */
11650 /* of A. */
11651
11652 /* 5. Iterative refinement is applied to improve the computed solution */
11653 /* matrix and calculate error bounds and backward error estimates */
11654 /* for it. */
11655
11656 /* 6. If equilibration was used, the matrix X is premultiplied by */
11657 /* diag(S) so that it solves the original system before */
11658 /* equilibration. */
11659
11660 /* Arguments */
11661 /* ========= */
11662
11663 /* FACT (input) CHARACTER*1 */
11664 /* Specifies whether or not the factored form of the matrix A is */
11665 /* supplied on entry, and if not, whether the matrix A should be */
11666 /* equilibrated before it is factored. */
11667 /* = 'F': On entry, AFB contains the factored form of A. */
11668 /* If EQUED = 'Y', the matrix A has been equilibrated */
11669 /* with scaling factors given by S. AB and AFB will not */
11670 /* be modified. */
11671 /* = 'N': The matrix A will be copied to AFB and factored. */
11672 /* = 'E': The matrix A will be equilibrated if necessary, then */
11673 /* copied to AFB and factored. */
11674
11675 /* UPLO (input) CHARACTER*1 */
11676 /* = 'U': Upper triangle of A is stored; */
11677 /* = 'L': Lower triangle of A is stored. */
11678
11679 /* N (input) INTEGER */
11680 /* The number of linear equations, i.e., the order of the */
11681 /* matrix A. N >= 0. */
11682
11683 /* KD (input) INTEGER */
11684 /* The number of superdiagonals of the matrix A if UPLO = 'U', */
11685 /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
11686
11687 /* NRHS (input) INTEGER */
11688 /* The number of right-hand sides, i.e., the number of columns */
11689 /* of the matrices B and X. NRHS >= 0. */
11690
11691 /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */
11692 /* On entry, the upper or lower triangle of the symmetric band */
11693 /* matrix A, stored in the first KD+1 rows of the array, except */
11694 /* if FACT = 'F' and EQUED = 'Y', then A must contain the */
11695 /* equilibrated matrix diag(S)*A*diag(S). The j-th column of A */
11696 /* is stored in the j-th column of the array AB as follows: */
11697 /* if UPLO = 'U', AB(KD+1+i-j,j) = A(i,j) for max(1,j-KD)<=i<=j; */
11698 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(N,j+KD). */
11699 /* See below for further details. */
11700
11701 /* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */
11702 /* diag(S)*A*diag(S). */
11703
11704 /* LDAB (input) INTEGER */
11705 /* The leading dimension of the array A. LDAB >= KD+1. */
11706
11707 /* AFB (input or output) DOUBLE PRECISION array, dimension (LDAFB,N) */
11708 /* If FACT = 'F', then AFB is an input argument and on entry */
11709 /* contains the triangular factor U or L from the Cholesky */
11710 /* factorization A = U**T*U or A = L*L**T of the band matrix */
11711 /* A, in the same storage format as A (see AB). If EQUED = 'Y', */
11712 /* then AFB is the factored form of the equilibrated matrix A. */
11713
11714 /* If FACT = 'N', then AFB is an output argument and on exit */
11715 /* returns the triangular factor U or L from the Cholesky */
11716 /* factorization A = U**T*U or A = L*L**T. */
11717
11718 /* If FACT = 'E', then AFB is an output argument and on exit */
11719 /* returns the triangular factor U or L from the Cholesky */
11720 /* factorization A = U**T*U or A = L*L**T of the equilibrated */
11721 /* matrix A (see the description of A for the form of the */
11722 /* equilibrated matrix). */
11723
11724 /* LDAFB (input) INTEGER */
11725 /* The leading dimension of the array AFB. LDAFB >= KD+1. */
11726
11727 /* EQUED (input or output) CHARACTER*1 */
11728 /* Specifies the form of equilibration that was done. */
11729 /* = 'N': No equilibration (always true if FACT = 'N'). */
11730 /* = 'Y': Equilibration was done, i.e., A has been replaced by */
11731 /* diag(S) * A * diag(S). */
11732 /* EQUED is an input argument if FACT = 'F'; otherwise, it is an */
11733 /* output argument. */
11734
11735 /* S (input or output) DOUBLE PRECISION array, dimension (N) */
11736 /* The scale factors for A; not accessed if EQUED = 'N'. S is */
11737 /* an input argument if FACT = 'F'; otherwise, S is an output */
11738 /* argument. If FACT = 'F' and EQUED = 'Y', each element of S */
11739 /* must be positive. */
11740
11741 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
11742 /* On entry, the N-by-NRHS right hand side matrix B. */
11743 /* On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', */
11744 /* B is overwritten by diag(S) * B. */
11745
11746 /* LDB (input) INTEGER */
11747 /* The leading dimension of the array B. LDB >= max(1,N). */
11748
11749 /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
11750 /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to */
11751 /* the original system of equations. Note that if EQUED = 'Y', */
11752 /* A and B are modified on exit, and the solution to the */
11753 /* equilibrated system is inv(diag(S))*X. */
11754
11755 /* LDX (input) INTEGER */
11756 /* The leading dimension of the array X. LDX >= max(1,N). */
11757
11758 /* RCOND (output) DOUBLE PRECISION */
11759 /* The estimate of the reciprocal condition number of the matrix */
11760 /* A after equilibration (if done). If RCOND is less than the */
11761 /* machine precision (in particular, if RCOND = 0), the matrix */
11762 /* is singular to working precision. This condition is */
11763 /* indicated by a return code of INFO > 0. */
11764
11765 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
11766 /* The estimated forward error bound for each solution vector */
11767 /* X(j) (the j-th column of the solution matrix X). */
11768 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
11769 /* is an estimated upper bound for the magnitude of the largest */
11770 /* element in (X(j) - XTRUE) divided by the magnitude of the */
11771 /* largest element in X(j). The estimate is as reliable as */
11772 /* the estimate for RCOND, and is almost always a slight */
11773 /* overestimate of the true error. */
11774
11775 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
11776 /* The componentwise relative backward error of each solution */
11777 /* vector X(j) (i.e., the smallest relative change in */
11778 /* any element of A or B that makes X(j) an exact solution). */
11779
11780 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
11781
11782 /* IWORK (workspace) INTEGER array, dimension (N) */
11783
11784 /* INFO (output) INTEGER */
11785 /* = 0: successful exit */
11786 /* < 0: if INFO = -i, the i-th argument had an illegal value */
11787 /* > 0: if INFO = i, and i is */
11788 /* <= N: the leading minor of order i of A is */
11789 /* not positive definite, so the factorization */
11790 /* could not be completed, and the solution has not */
11791 /* been computed. RCOND = 0 is returned. */
11792 /* = N+1: U is nonsingular, but RCOND is less than machine */
11793 /* precision, meaning that the matrix is singular */
11794 /* to working precision. Nevertheless, the */
11795 /* solution and error bounds are computed because */
11796 /* there are a number of situations where the */
11797 /* computed solution can be more accurate than the */
11798 /* value of RCOND would suggest. */
11799
11800 /* Further Details */
11801 /* =============== */
11802
11803 /* The band storage scheme is illustrated by the following example, when */
11804 /* N = 6, KD = 2, and UPLO = 'U': */
11805
11806 /* Two-dimensional storage of the symmetric matrix A: */
11807
11808 /* a11 a12 a13 */
11809 /* a22 a23 a24 */
11810 /* a33 a34 a35 */
11811 /* a44 a45 a46 */
11812 /* a55 a56 */
11813 /* (aij=conjg(aji)) a66 */
11814
11815 /* Band storage of the upper triangle of A: */
11816
11817 /* * * a13 a24 a35 a46 */
11818 /* * a12 a23 a34 a45 a56 */
11819 /* a11 a22 a33 a44 a55 a66 */
11820
11821 /* Similarly, if UPLO = 'L' the format of A is as follows: */
11822
11823 /* a11 a22 a33 a44 a55 a66 */
11824 /* a21 a32 a43 a54 a65 * */
11825 /* a31 a42 a53 a64 * * */
11826
11827 /* Array elements marked * are not used by the routine. */
11828
11829 /* ===================================================================== */
11830
11831 /* .. Parameters .. */
11832 /* .. */
11833 /* .. Local Scalars .. */
11834 /* .. */
11835 /* .. External Functions .. */
11836 /* .. */
11837 /* .. External Subroutines .. */
11838 /* .. */
11839 /* .. Intrinsic Functions .. */
11840 /* .. */
11841 /* .. Executable Statements .. */
11842
11843 /* Parameter adjustments */
11844 ab_dim1 = *ldab;
11845 ab_offset = 1 + ab_dim1;
11846 ab -= ab_offset;
11847 afb_dim1 = *ldafb;
11848 afb_offset = 1 + afb_dim1;
11849 afb -= afb_offset;
11850 --s;
11851 b_dim1 = *ldb;
11852 b_offset = 1 + b_dim1;
11853 b -= b_offset;
11854 x_dim1 = *ldx;
11855 x_offset = 1 + x_dim1;
11856 x -= x_offset;
11857 --ferr;
11858 --berr;
11859 --work;
11860 --iwork;
11861
11862 /* Function Body */
11863 *info = 0;
11864 nofact = lsame_(fact, "N");
11865 equil = lsame_(fact, "E");
11866 upper = lsame_(uplo, "U");
11867 if (nofact || equil) {
11868 *(unsigned char *)equed = 'N';
11869 rcequ = false;
11870 } else {
11871 rcequ = lsame_(equed, "Y");
11872 smlnum = dlamch_("Safe minimum");
11873 bignum = 1. / smlnum;
11874 }
11875
11876 /* Test the input parameters. */
11877
11878 if (! nofact && ! equil && ! lsame_(fact, "F")) {
11879 *info = -1;
11880 } else if (! upper && ! lsame_(uplo, "L")) {
11881 *info = -2;
11882 } else if (*n < 0) {
11883 *info = -3;
11884 } else if (*kd < 0) {
11885 *info = -4;
11886 } else if (*nrhs < 0) {
11887 *info = -5;
11888 } else if (*ldab < *kd + 1) {
11889 *info = -7;
11890 } else if (*ldafb < *kd + 1) {
11891 *info = -9;
11892 } else if (lsame_(fact, "F") && ! (rcequ || lsame_(
11893 equed, "N"))) {
11894 *info = -10;
11895 } else {
11896 if (rcequ) {
11897 smin = bignum;
11898 smax = 0.;
11899 i__1 = *n;
11900 for (j = 1; j <= i__1; ++j) {
11901 /* Computing MIN */
11902 d__1 = smin, d__2 = s[j];
11903 smin = std::min(d__1,d__2);
11904 /* Computing MAX */
11905 d__1 = smax, d__2 = s[j];
11906 smax = std::max(d__1,d__2);
11907 /* L10: */
11908 }
11909 if (smin <= 0.) {
11910 *info = -11;
11911 } else if (*n > 0) {
11912 scond = std::max(smin,smlnum) / std::min(smax,bignum);
11913 } else {
11914 scond = 1.;
11915 }
11916 }
11917 if (*info == 0) {
11918 if (*ldb < std::max(1_integer,*n)) {
11919 *info = -13;
11920 } else if (*ldx < std::max(1_integer,*n)) {
11921 *info = -15;
11922 }
11923 }
11924 }
11925
11926 if (*info != 0) {
11927 i__1 = -(*info);
11928 xerbla_("DPBSVX", &i__1);
11929 return 0;
11930 }
11931
11932 if (equil) {
11933
11934 /* Compute row and column scalings to equilibrate the matrix A. */
11935
11936 dpbequ_(uplo, n, kd, &ab[ab_offset], ldab, &s[1], &scond, &amax, &
11937 infequ);
11938 if (infequ == 0) {
11939
11940 /* Equilibrate the matrix. */
11941
11942 dlaqsb_(uplo, n, kd, &ab[ab_offset], ldab, &s[1], &scond, &amax,
11943 equed);
11944 rcequ = lsame_(equed, "Y");
11945 }
11946 }
11947
11948 /* Scale the right-hand side. */
11949
11950 if (rcequ) {
11951 i__1 = *nrhs;
11952 for (j = 1; j <= i__1; ++j) {
11953 i__2 = *n;
11954 for (i__ = 1; i__ <= i__2; ++i__) {
11955 b[i__ + j * b_dim1] = s[i__] * b[i__ + j * b_dim1];
11956 /* L20: */
11957 }
11958 /* L30: */
11959 }
11960 }
11961
11962 if (nofact || equil) {
11963
11964 /* Compute the Cholesky factorization A = U'*U or A = L*L'. */
11965
11966 if (upper) {
11967 i__1 = *n;
11968 for (j = 1; j <= i__1; ++j) {
11969 /* Computing MAX */
11970 i__2 = j - *kd;
11971 j1 = std::max(i__2,1_integer);
11972 i__2 = j - j1 + 1;
11973 dcopy_(&i__2, &ab[*kd + 1 - j + j1 + j * ab_dim1], &c__1, &
11974 afb[*kd + 1 - j + j1 + j * afb_dim1], &c__1);
11975 /* L40: */
11976 }
11977 } else {
11978 i__1 = *n;
11979 for (j = 1; j <= i__1; ++j) {
11980 /* Computing MIN */
11981 i__2 = j + *kd;
11982 j2 = std::min(i__2,*n);
11983 i__2 = j2 - j + 1;
11984 dcopy_(&i__2, &ab[j * ab_dim1 + 1], &c__1, &afb[j * afb_dim1
11985 + 1], &c__1);
11986 /* L50: */
11987 }
11988 }
11989
11990 dpbtrf_(uplo, n, kd, &afb[afb_offset], ldafb, info);
11991
11992 /* Return if INFO is non-zero. */
11993
11994 if (*info > 0) {
11995 *rcond = 0.;
11996 return 0;
11997 }
11998 }
11999
12000 /* Compute the norm of the matrix A. */
12001
12002 anorm = dlansb_("1", uplo, n, kd, &ab[ab_offset], ldab, &work[1]);
12003
12004 /* Compute the reciprocal of the condition number of A. */
12005
12006 dpbcon_(uplo, n, kd, &afb[afb_offset], ldafb, &anorm, rcond, &work[1], &
12007 iwork[1], info);
12008
12009 /* Compute the solution matrix X. */
12010
12011 dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
12012 dpbtrs_(uplo, n, kd, nrhs, &afb[afb_offset], ldafb, &x[x_offset], ldx,
12013 info);
12014
12015 /* Use iterative refinement to improve the computed solution and */
12016 /* compute error bounds and backward error estimates for it. */
12017
12018 dpbrfs_(uplo, n, kd, nrhs, &ab[ab_offset], ldab, &afb[afb_offset], ldafb,
12019 &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1]
12020 , &iwork[1], info);
12021
12022 /* Transform the solution matrix X to a solution of the original */
12023 /* system. */
12024
12025 if (rcequ) {
12026 i__1 = *nrhs;
12027 for (j = 1; j <= i__1; ++j) {
12028 i__2 = *n;
12029 for (i__ = 1; i__ <= i__2; ++i__) {
12030 x[i__ + j * x_dim1] = s[i__] * x[i__ + j * x_dim1];
12031 /* L60: */
12032 }
12033 /* L70: */
12034 }
12035 i__1 = *nrhs;
12036 for (j = 1; j <= i__1; ++j) {
12037 ferr[j] /= scond;
12038 /* L80: */
12039 }
12040 }
12041
12042 /* Set INFO = N+1 if the matrix is singular to working precision. */
12043
12044 if (*rcond < dlamch_("Epsilon")) {
12045 *info = *n + 1;
12046 }
12047
12048 return 0;
12049
12050 /* End of DPBSVX */
12051
12052 } /* dpbsvx_ */
12053
12054 /* Subroutine */ int dpbtf2_(const char *uplo, integer *n, integer *kd, double *
12055 ab, integer *ldab, integer *info)
12056 {
12057 /* Table of constant values */
12058 static double c_b8 = -1.;
12059 static integer c__1 = 1;
12060
12061 /* System generated locals */
12062 integer ab_dim1, ab_offset, i__1, i__2, i__3;
12063 double d__1;
12064
12065 /* Local variables */
12066 integer j, kn;
12067 double ajj;
12068 integer kld;
12069 bool upper;
12070
12071
12072 /* -- LAPACK routine (version 3.1) -- */
12073 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
12074 /* November 2006 */
12075
12076 /* .. Scalar Arguments .. */
12077 /* .. */
12078 /* .. Array Arguments .. */
12079 /* .. */
12080
12081 /* Purpose */
12082 /* ======= */
12083
12084 /* DPBTF2 computes the Cholesky factorization of a real symmetric */
12085 /* positive definite band matrix A. */
12086
12087 /* The factorization has the form */
12088 /* A = U' * U , if UPLO = 'U', or */
12089 /* A = L * L', if UPLO = 'L', */
12090 /* where U is an upper triangular matrix, U' is the transpose of U, and */
12091 /* L is lower triangular. */
12092
12093 /* This is the unblocked version of the algorithm, calling Level 2 BLAS. */
12094
12095 /* Arguments */
12096 /* ========= */
12097
12098 /* UPLO (input) CHARACTER*1 */
12099 /* Specifies whether the upper or lower triangular part of the */
12100 /* symmetric matrix A is stored: */
12101 /* = 'U': Upper triangular */
12102 /* = 'L': Lower triangular */
12103
12104 /* N (input) INTEGER */
12105 /* The order of the matrix A. N >= 0. */
12106
12107 /* KD (input) INTEGER */
12108 /* The number of super-diagonals of the matrix A if UPLO = 'U', */
12109 /* or the number of sub-diagonals if UPLO = 'L'. KD >= 0. */
12110
12111 /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */
12112 /* On entry, the upper or lower triangle of the symmetric band */
12113 /* matrix A, stored in the first KD+1 rows of the array. The */
12114 /* j-th column of A is stored in the j-th column of the array AB */
12115 /* as follows: */
12116 /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
12117 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
12118
12119 /* On exit, if INFO = 0, the triangular factor U or L from the */
12120 /* Cholesky factorization A = U'*U or A = L*L' of the band */
12121 /* matrix A, in the same storage format as A. */
12122
12123 /* LDAB (input) INTEGER */
12124 /* The leading dimension of the array AB. LDAB >= KD+1. */
12125
12126 /* INFO (output) INTEGER */
12127 /* = 0: successful exit */
12128 /* < 0: if INFO = -k, the k-th argument had an illegal value */
12129 /* > 0: if INFO = k, the leading minor of order k is not */
12130 /* positive definite, and the factorization could not be */
12131 /* completed. */
12132
12133 /* Further Details */
12134 /* =============== */
12135
12136 /* The band storage scheme is illustrated by the following example, when */
12137 /* N = 6, KD = 2, and UPLO = 'U': */
12138
12139 /* On entry: On exit: */
12140
12141 /* * * a13 a24 a35 a46 * * u13 u24 u35 u46 */
12142 /* * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56 */
12143 /* a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66 */
12144
12145 /* Similarly, if UPLO = 'L' the format of A is as follows: */
12146
12147 /* On entry: On exit: */
12148
12149 /* a11 a22 a33 a44 a55 a66 l11 l22 l33 l44 l55 l66 */
12150 /* a21 a32 a43 a54 a65 * l21 l32 l43 l54 l65 * */
12151 /* a31 a42 a53 a64 * * l31 l42 l53 l64 * * */
12152
12153 /* Array elements marked * are not used by the routine. */
12154
12155 /* ===================================================================== */
12156
12157 /* .. Parameters .. */
12158 /* .. */
12159 /* .. Local Scalars .. */
12160 /* .. */
12161 /* .. External Functions .. */
12162 /* .. */
12163 /* .. External Subroutines .. */
12164 /* .. */
12165 /* .. Intrinsic Functions .. */
12166 /* .. */
12167 /* .. Executable Statements .. */
12168
12169 /* Test the input parameters. */
12170
12171 /* Parameter adjustments */
12172 ab_dim1 = *ldab;
12173 ab_offset = 1 + ab_dim1;
12174 ab -= ab_offset;
12175
12176 /* Function Body */
12177 *info = 0;
12178 upper = lsame_(uplo, "U");
12179 if (! upper && ! lsame_(uplo, "L")) {
12180 *info = -1;
12181 } else if (*n < 0) {
12182 *info = -2;
12183 } else if (*kd < 0) {
12184 *info = -3;
12185 } else if (*ldab < *kd + 1) {
12186 *info = -5;
12187 }
12188 if (*info != 0) {
12189 i__1 = -(*info);
12190 xerbla_("DPBTF2", &i__1);
12191 return 0;
12192 }
12193
12194 /* Quick return if possible */
12195
12196 if (*n == 0) {
12197 return 0;
12198 }
12199
12200 /* Computing MAX */
12201 i__1 = 1, i__2 = *ldab - 1;
12202 kld = std::max(i__1,i__2);
12203
12204 if (upper) {
12205
12206 /* Compute the Cholesky factorization A = U'*U. */
12207
12208 i__1 = *n;
12209 for (j = 1; j <= i__1; ++j) {
12210
12211 /* Compute U(J,J) and test for non-positive-definiteness. */
12212
12213 ajj = ab[*kd + 1 + j * ab_dim1];
12214 if (ajj <= 0.) {
12215 goto L30;
12216 }
12217 ajj = sqrt(ajj);
12218 ab[*kd + 1 + j * ab_dim1] = ajj;
12219
12220 /* Compute elements J+1:J+KN of row J and update the */
12221 /* trailing submatrix within the band. */
12222
12223 /* Computing MIN */
12224 i__2 = *kd, i__3 = *n - j;
12225 kn = std::min(i__2,i__3);
12226 if (kn > 0) {
12227 d__1 = 1. / ajj;
12228 dscal_(&kn, &d__1, &ab[*kd + (j + 1) * ab_dim1], &kld);
12229 dsyr_("Upper", &kn, &c_b8, &ab[*kd + (j + 1) * ab_dim1], &kld,
12230 &ab[*kd + 1 + (j + 1) * ab_dim1], &kld);
12231 }
12232 /* L10: */
12233 }
12234 } else {
12235
12236 /* Compute the Cholesky factorization A = L*L'. */
12237
12238 i__1 = *n;
12239 for (j = 1; j <= i__1; ++j) {
12240
12241 /* Compute L(J,J) and test for non-positive-definiteness. */
12242
12243 ajj = ab[j * ab_dim1 + 1];
12244 if (ajj <= 0.) {
12245 goto L30;
12246 }
12247 ajj = sqrt(ajj);
12248 ab[j * ab_dim1 + 1] = ajj;
12249
12250 /* Compute elements J+1:J+KN of column J and update the */
12251 /* trailing submatrix within the band. */
12252
12253 /* Computing MIN */
12254 i__2 = *kd, i__3 = *n - j;
12255 kn = std::min(i__2,i__3);
12256 if (kn > 0) {
12257 d__1 = 1. / ajj;
12258 dscal_(&kn, &d__1, &ab[j * ab_dim1 + 2], &c__1);
12259 dsyr_("Lower", &kn, &c_b8, &ab[j * ab_dim1 + 2], &c__1, &ab[(
12260 j + 1) * ab_dim1 + 1], &kld);
12261 }
12262 /* L20: */
12263 }
12264 }
12265 return 0;
12266
12267 L30:
12268 *info = j;
12269 return 0;
12270
12271 /* End of DPBTF2 */
12272
12273 } /* dpbtf2_ */
12274
12275 /* Subroutine */ int dpbtrf_(const char *uplo, integer *n, integer *kd, double *
12276 ab, integer *ldab, integer *info)
12277 {
12278 /* Table of constant values */
12279 static integer c__1 = 1;
12280 static integer c_n1 = -1;
12281 static double c_b18 = 1.;
12282 static double c_b21 = -1.;
12283 static integer c__33 = 33;
12284
12285 /* System generated locals */
12286 integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
12287
12288 /* Local variables */
12289 integer i__, j, i2, i3, ib, nb, ii, jj;
12290 double work[1056] /* was [33][32] */;
12291
12292 /* -- LAPACK routine (version 3.1) -- */
12293 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
12294 /* November 2006 */
12295
12296 /* .. Scalar Arguments .. */
12297 /* .. */
12298 /* .. Array Arguments .. */
12299 /* .. */
12300
12301 /* Purpose */
12302 /* ======= */
12303
12304 /* DPBTRF computes the Cholesky factorization of a real symmetric */
12305 /* positive definite band matrix A. */
12306
12307 /* The factorization has the form */
12308 /* A = U**T * U, if UPLO = 'U', or */
12309 /* A = L * L**T, if UPLO = 'L', */
12310 /* where U is an upper triangular matrix and L is lower triangular. */
12311
12312 /* Arguments */
12313 /* ========= */
12314
12315 /* UPLO (input) CHARACTER*1 */
12316 /* = 'U': Upper triangle of A is stored; */
12317 /* = 'L': Lower triangle of A is stored. */
12318
12319 /* N (input) INTEGER */
12320 /* The order of the matrix A. N >= 0. */
12321
12322 /* KD (input) INTEGER */
12323 /* The number of superdiagonals of the matrix A if UPLO = 'U', */
12324 /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
12325
12326 /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */
12327 /* On entry, the upper or lower triangle of the symmetric band */
12328 /* matrix A, stored in the first KD+1 rows of the array. The */
12329 /* j-th column of A is stored in the j-th column of the array AB */
12330 /* as follows: */
12331 /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
12332 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
12333
12334 /* On exit, if INFO = 0, the triangular factor U or L from the */
12335 /* Cholesky factorization A = U**T*U or A = L*L**T of the band */
12336 /* matrix A, in the same storage format as A. */
12337
12338 /* LDAB (input) INTEGER */
12339 /* The leading dimension of the array AB. LDAB >= KD+1. */
12340
12341 /* INFO (output) INTEGER */
12342 /* = 0: successful exit */
12343 /* < 0: if INFO = -i, the i-th argument had an illegal value */
12344 /* > 0: if INFO = i, the leading minor of order i is not */
12345 /* positive definite, and the factorization could not be */
12346 /* completed. */
12347
12348 /* Further Details */
12349 /* =============== */
12350
12351 /* The band storage scheme is illustrated by the following example, when */
12352 /* N = 6, KD = 2, and UPLO = 'U': */
12353
12354 /* On entry: On exit: */
12355
12356 /* * * a13 a24 a35 a46 * * u13 u24 u35 u46 */
12357 /* * a12 a23 a34 a45 a56 * u12 u23 u34 u45 u56 */
12358 /* a11 a22 a33 a44 a55 a66 u11 u22 u33 u44 u55 u66 */
12359
12360 /* Similarly, if UPLO = 'L' the format of A is as follows: */
12361
12362 /* On entry: On exit: */
12363
12364 /* a11 a22 a33 a44 a55 a66 l11 l22 l33 l44 l55 l66 */
12365 /* a21 a32 a43 a54 a65 * l21 l32 l43 l54 l65 * */
12366 /* a31 a42 a53 a64 * * l31 l42 l53 l64 * * */
12367
12368 /* Array elements marked * are not used by the routine. */
12369
12370 /* Contributed by */
12371 /* Peter Mayes and Giuseppe Radicati, IBM ECSEC, Rome, March 23, 1989 */
12372
12373 /* ===================================================================== */
12374
12375 /* .. Parameters .. */
12376 /* .. */
12377 /* .. Local Scalars .. */
12378 /* .. */
12379 /* .. Local Arrays .. */
12380 /* .. */
12381 /* .. External Functions .. */
12382 /* .. */
12383 /* .. External Subroutines .. */
12384 /* .. */
12385 /* .. Intrinsic Functions .. */
12386 /* .. */
12387 /* .. Executable Statements .. */
12388
12389 /* Test the input parameters. */
12390
12391 /* Parameter adjustments */
12392 ab_dim1 = *ldab;
12393 ab_offset = 1 + ab_dim1;
12394 ab -= ab_offset;
12395
12396 /* Function Body */
12397 *info = 0;
12398 if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
12399 *info = -1;
12400 } else if (*n < 0) {
12401 *info = -2;
12402 } else if (*kd < 0) {
12403 *info = -3;
12404 } else if (*ldab < *kd + 1) {
12405 *info = -5;
12406 }
12407 if (*info != 0) {
12408 i__1 = -(*info);
12409 xerbla_("DPBTRF", &i__1);
12410 return 0;
12411 }
12412
12413 /* Quick return if possible */
12414
12415 if (*n == 0) {
12416 return 0;
12417 }
12418
12419 /* Determine the block size for this environment */
12420
12421 nb = ilaenv_(&c__1, "DPBTRF", uplo, n, kd, &c_n1, &c_n1);
12422
12423 /* The block size must not exceed the semi-bandwidth KD, and must not */
12424 /* exceed the limit set by the size of the local array WORK. */
12425
12426 nb = std::min(nb,32_integer);
12427
12428 if (nb <= 1 || nb > *kd) {
12429
12430 /* Use unblocked code */
12431
12432 dpbtf2_(uplo, n, kd, &ab[ab_offset], ldab, info);
12433 } else {
12434
12435 /* Use blocked code */
12436
12437 if (lsame_(uplo, "U")) {
12438
12439 /* Compute the Cholesky factorization of a symmetric band */
12440 /* matrix, given the upper triangle of the matrix in band */
12441 /* storage. */
12442
12443 /* Zero the upper triangle of the work array. */
12444
12445 i__1 = nb;
12446 for (j = 1; j <= i__1; ++j) {
12447 i__2 = j - 1;
12448 for (i__ = 1; i__ <= i__2; ++i__) {
12449 work[i__ + j * 33 - 34] = 0.;
12450 /* L10: */
12451 }
12452 /* L20: */
12453 }
12454
12455 /* Process the band matrix one diagonal block at a time. */
12456
12457 i__1 = *n;
12458 i__2 = nb;
12459 for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
12460 /* Computing MIN */
12461 i__3 = nb, i__4 = *n - i__ + 1;
12462 ib = std::min(i__3,i__4);
12463
12464 /* Factorize the diagonal block */
12465
12466 i__3 = *ldab - 1;
12467 dpotf2_(uplo, &ib, &ab[*kd + 1 + i__ * ab_dim1], &i__3, &ii);
12468 if (ii != 0) {
12469 *info = i__ + ii - 1;
12470 goto L150;
12471 }
12472 if (i__ + ib <= *n) {
12473
12474 /* Update the relevant part of the trailing submatrix. */
12475 /* If A11 denotes the diagonal block which has just been */
12476 /* factorized, then we need to update the remaining */
12477 /* blocks in the diagram: */
12478
12479 /* A11 A12 A13 */
12480 /* A22 A23 */
12481 /* A33 */
12482
12483 /* The numbers of rows and columns in the partitioning */
12484 /* are IB, I2, I3 respectively. The blocks A12, A22 and */
12485 /* A23 are empty if IB = KD. The upper triangle of A13 */
12486 /* lies outside the band. */
12487
12488 /* Computing MIN */
12489 i__3 = *kd - ib, i__4 = *n - i__ - ib + 1;
12490 i2 = std::min(i__3,i__4);
12491 /* Computing MIN */
12492 i__3 = ib, i__4 = *n - i__ - *kd + 1;
12493 i3 = std::min(i__3,i__4);
12494
12495 if (i2 > 0) {
12496
12497 /* Update A12 */
12498
12499 i__3 = *ldab - 1;
12500 i__4 = *ldab - 1;
12501 dtrsm_("Left", "Upper", "Transpose", "Non-unit", &ib,
12502 &i2, &c_b18, &ab[*kd + 1 + i__ * ab_dim1], &
12503 i__3, &ab[*kd + 1 - ib + (i__ + ib) * ab_dim1]
12504 , &i__4);
12505
12506 /* Update A22 */
12507
12508 i__3 = *ldab - 1;
12509 i__4 = *ldab - 1;
12510 dsyrk_("Upper", "Transpose", &i2, &ib, &c_b21, &ab[*
12511 kd + 1 - ib + (i__ + ib) * ab_dim1], &i__3, &
12512 c_b18, &ab[*kd + 1 + (i__ + ib) * ab_dim1], &
12513 i__4);
12514 }
12515
12516 if (i3 > 0) {
12517
12518 /* Copy the lower triangle of A13 into the work array. */
12519
12520 i__3 = i3;
12521 for (jj = 1; jj <= i__3; ++jj) {
12522 i__4 = ib;
12523 for (ii = jj; ii <= i__4; ++ii) {
12524 work[ii + jj * 33 - 34] = ab[ii - jj + 1 + (
12525 jj + i__ + *kd - 1) * ab_dim1];
12526 /* L30: */
12527 }
12528 /* L40: */
12529 }
12530
12531 /* Update A13 (in the work array). */
12532
12533 i__3 = *ldab - 1;
12534 dtrsm_("Left", "Upper", "Transpose", "Non-unit", &ib,
12535 &i3, &c_b18, &ab[*kd + 1 + i__ * ab_dim1], &
12536 i__3, work, &c__33);
12537
12538 /* Update A23 */
12539
12540 if (i2 > 0) {
12541 i__3 = *ldab - 1;
12542 i__4 = *ldab - 1;
12543 dgemm_("Transpose", "No Transpose", &i2, &i3, &ib,
12544 &c_b21, &ab[*kd + 1 - ib + (i__ + ib) *
12545 ab_dim1], &i__3, work, &c__33, &c_b18, &
12546 ab[ib + 1 + (i__ + *kd) * ab_dim1], &i__4);
12547 }
12548
12549 /* Update A33 */
12550
12551 i__3 = *ldab - 1;
12552 dsyrk_("Upper", "Transpose", &i3, &ib, &c_b21, work, &
12553 c__33, &c_b18, &ab[*kd + 1 + (i__ + *kd) *
12554 ab_dim1], &i__3);
12555
12556 /* Copy the lower triangle of A13 back into place. */
12557
12558 i__3 = i3;
12559 for (jj = 1; jj <= i__3; ++jj) {
12560 i__4 = ib;
12561 for (ii = jj; ii <= i__4; ++ii) {
12562 ab[ii - jj + 1 + (jj + i__ + *kd - 1) *
12563 ab_dim1] = work[ii + jj * 33 - 34];
12564 /* L50: */
12565 }
12566 /* L60: */
12567 }
12568 }
12569 }
12570 /* L70: */
12571 }
12572 } else {
12573
12574 /* Compute the Cholesky factorization of a symmetric band */
12575 /* matrix, given the lower triangle of the matrix in band */
12576 /* storage. */
12577
12578 /* Zero the lower triangle of the work array. */
12579
12580 i__2 = nb;
12581 for (j = 1; j <= i__2; ++j) {
12582 i__1 = nb;
12583 for (i__ = j + 1; i__ <= i__1; ++i__) {
12584 work[i__ + j * 33 - 34] = 0.;
12585 /* L80: */
12586 }
12587 /* L90: */
12588 }
12589
12590 /* Process the band matrix one diagonal block at a time. */
12591
12592 i__2 = *n;
12593 i__1 = nb;
12594 for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) {
12595 /* Computing MIN */
12596 i__3 = nb, i__4 = *n - i__ + 1;
12597 ib = std::min(i__3,i__4);
12598
12599 /* Factorize the diagonal block */
12600
12601 i__3 = *ldab - 1;
12602 dpotf2_(uplo, &ib, &ab[i__ * ab_dim1 + 1], &i__3, &ii);
12603 if (ii != 0) {
12604 *info = i__ + ii - 1;
12605 goto L150;
12606 }
12607 if (i__ + ib <= *n) {
12608
12609 /* Update the relevant part of the trailing submatrix. */
12610 /* If A11 denotes the diagonal block which has just been */
12611 /* factorized, then we need to update the remaining */
12612 /* blocks in the diagram: */
12613
12614 /* A11 */
12615 /* A21 A22 */
12616 /* A31 A32 A33 */
12617
12618 /* The numbers of rows and columns in the partitioning */
12619 /* are IB, I2, I3 respectively. The blocks A21, A22 and */
12620 /* A32 are empty if IB = KD. The lower triangle of A31 */
12621 /* lies outside the band. */
12622
12623 /* Computing MIN */
12624 i__3 = *kd - ib, i__4 = *n - i__ - ib + 1;
12625 i2 = std::min(i__3,i__4);
12626 /* Computing MIN */
12627 i__3 = ib, i__4 = *n - i__ - *kd + 1;
12628 i3 = std::min(i__3,i__4);
12629
12630 if (i2 > 0) {
12631
12632 /* Update A21 */
12633
12634 i__3 = *ldab - 1;
12635 i__4 = *ldab - 1;
12636 dtrsm_("Right", "Lower", "Transpose", "Non-unit", &i2,
12637 &ib, &c_b18, &ab[i__ * ab_dim1 + 1], &i__3, &
12638 ab[ib + 1 + i__ * ab_dim1], &i__4);
12639
12640 /* Update A22 */
12641
12642 i__3 = *ldab - 1;
12643 i__4 = *ldab - 1;
12644 dsyrk_("Lower", "No Transpose", &i2, &ib, &c_b21, &ab[
12645 ib + 1 + i__ * ab_dim1], &i__3, &c_b18, &ab[(
12646 i__ + ib) * ab_dim1 + 1], &i__4);
12647 }
12648
12649 if (i3 > 0) {
12650
12651 /* Copy the upper triangle of A31 into the work array. */
12652
12653 i__3 = ib;
12654 for (jj = 1; jj <= i__3; ++jj) {
12655 i__4 = std::min(jj,i3);
12656 for (ii = 1; ii <= i__4; ++ii) {
12657 work[ii + jj * 33 - 34] = ab[*kd + 1 - jj +
12658 ii + (jj + i__ - 1) * ab_dim1];
12659 /* L100: */
12660 }
12661 /* L110: */
12662 }
12663
12664 /* Update A31 (in the work array). */
12665
12666 i__3 = *ldab - 1;
12667 dtrsm_("Right", "Lower", "Transpose", "Non-unit", &i3,
12668 &ib, &c_b18, &ab[i__ * ab_dim1 + 1], &i__3,
12669 work, &c__33);
12670
12671 /* Update A32 */
12672
12673 if (i2 > 0) {
12674 i__3 = *ldab - 1;
12675 i__4 = *ldab - 1;
12676 dgemm_("No transpose", "Transpose", &i3, &i2, &ib,
12677 &c_b21, work, &c__33, &ab[ib + 1 + i__ *
12678 ab_dim1], &i__3, &c_b18, &ab[*kd + 1 - ib
12679 + (i__ + ib) * ab_dim1], &i__4);
12680 }
12681
12682 /* Update A33 */
12683
12684 i__3 = *ldab - 1;
12685 dsyrk_("Lower", "No Transpose", &i3, &ib, &c_b21,
12686 work, &c__33, &c_b18, &ab[(i__ + *kd) *
12687 ab_dim1 + 1], &i__3);
12688
12689 /* Copy the upper triangle of A31 back into place. */
12690
12691 i__3 = ib;
12692 for (jj = 1; jj <= i__3; ++jj) {
12693 i__4 = std::min(jj,i3);
12694 for (ii = 1; ii <= i__4; ++ii) {
12695 ab[*kd + 1 - jj + ii + (jj + i__ - 1) *
12696 ab_dim1] = work[ii + jj * 33 - 34];
12697 /* L120: */
12698 }
12699 /* L130: */
12700 }
12701 }
12702 }
12703 /* L140: */
12704 }
12705 }
12706 }
12707 return 0;
12708
12709 L150:
12710 return 0;
12711
12712 /* End of DPBTRF */
12713
12714 } /* dpbtrf_ */
12715
12716 /* Subroutine */ int dpbtrs_(const char *uplo, integer *n, integer *kd, integer *
12717 nrhs, double *ab, integer *ldab, double *b, integer *ldb,
12718 integer *info)
12719 {
12720 /* Table of constant values */
12721 static integer c__1 = 1;
12722
12723 /* System generated locals */
12724 integer ab_dim1, ab_offset, b_dim1, b_offset, i__1;
12725
12726 /* Local variables */
12727 integer j;
12728 bool upper;
12729
12730
12731 /* -- LAPACK routine (version 3.1) -- */
12732 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
12733 /* November 2006 */
12734
12735 /* .. Scalar Arguments .. */
12736 /* .. */
12737 /* .. Array Arguments .. */
12738 /* .. */
12739
12740 /* Purpose */
12741 /* ======= */
12742
12743 /* DPBTRS solves a system of linear equations A*X = B with a symmetric */
12744 /* positive definite band matrix A using the Cholesky factorization */
12745 /* A = U**T*U or A = L*L**T computed by DPBTRF. */
12746
12747 /* Arguments */
12748 /* ========= */
12749
12750 /* UPLO (input) CHARACTER*1 */
12751 /* = 'U': Upper triangular factor stored in AB; */
12752 /* = 'L': Lower triangular factor stored in AB. */
12753
12754 /* N (input) INTEGER */
12755 /* The order of the matrix A. N >= 0. */
12756
12757 /* KD (input) INTEGER */
12758 /* The number of superdiagonals of the matrix A if UPLO = 'U', */
12759 /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
12760
12761 /* NRHS (input) INTEGER */
12762 /* The number of right hand sides, i.e., the number of columns */
12763 /* of the matrix B. NRHS >= 0. */
12764
12765 /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
12766 /* The triangular factor U or L from the Cholesky factorization */
12767 /* A = U**T*U or A = L*L**T of the band matrix A, stored in the */
12768 /* first KD+1 rows of the array. The j-th column of U or L is */
12769 /* stored in the j-th column of the array AB as follows: */
12770 /* if UPLO ='U', AB(kd+1+i-j,j) = U(i,j) for max(1,j-kd)<=i<=j; */
12771 /* if UPLO ='L', AB(1+i-j,j) = L(i,j) for j<=i<=min(n,j+kd). */
12772
12773 /* LDAB (input) INTEGER */
12774 /* The leading dimension of the array AB. LDAB >= KD+1. */
12775
12776 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
12777 /* On entry, the right hand side matrix B. */
12778 /* On exit, the solution matrix X. */
12779
12780 /* LDB (input) INTEGER */
12781 /* The leading dimension of the array B. LDB >= max(1,N). */
12782
12783 /* INFO (output) INTEGER */
12784 /* = 0: successful exit */
12785 /* < 0: if INFO = -i, the i-th argument had an illegal value */
12786
12787 /* ===================================================================== */
12788
12789 /* .. Local Scalars .. */
12790 /* .. */
12791 /* .. External Functions .. */
12792 /* .. */
12793 /* .. External Subroutines .. */
12794 /* .. */
12795 /* .. Intrinsic Functions .. */
12796 /* .. */
12797 /* .. Executable Statements .. */
12798
12799 /* Test the input parameters. */
12800
12801 /* Parameter adjustments */
12802 ab_dim1 = *ldab;
12803 ab_offset = 1 + ab_dim1;
12804 ab -= ab_offset;
12805 b_dim1 = *ldb;
12806 b_offset = 1 + b_dim1;
12807 b -= b_offset;
12808
12809 /* Function Body */
12810 *info = 0;
12811 upper = lsame_(uplo, "U");
12812 if (! upper && ! lsame_(uplo, "L")) {
12813 *info = -1;
12814 } else if (*n < 0) {
12815 *info = -2;
12816 } else if (*kd < 0) {
12817 *info = -3;
12818 } else if (*nrhs < 0) {
12819 *info = -4;
12820 } else if (*ldab < *kd + 1) {
12821 *info = -6;
12822 } else if (*ldb < std::max(1_integer,*n)) {
12823 *info = -8;
12824 }
12825 if (*info != 0) {
12826 i__1 = -(*info);
12827 xerbla_("DPBTRS", &i__1);
12828 return 0;
12829 }
12830
12831 /* Quick return if possible */
12832
12833 if (*n == 0 || *nrhs == 0) {
12834 return 0;
12835 }
12836
12837 if (upper) {
12838
12839 /* Solve A*X = B where A = U'*U. */
12840
12841 i__1 = *nrhs;
12842 for (j = 1; j <= i__1; ++j) {
12843
12844 /* Solve U'*X = B, overwriting B with X. */
12845
12846 dtbsv_("Upper", "Transpose", "Non-unit", n, kd, &ab[ab_offset],
12847 ldab, &b[j * b_dim1 + 1], &c__1);
12848
12849 /* Solve U*X = B, overwriting B with X. */
12850
12851 dtbsv_("Upper", "No transpose", "Non-unit", n, kd, &ab[ab_offset],
12852 ldab, &b[j * b_dim1 + 1], &c__1);
12853 /* L10: */
12854 }
12855 } else {
12856
12857 /* Solve A*X = B where A = L*L'. */
12858
12859 i__1 = *nrhs;
12860 for (j = 1; j <= i__1; ++j) {
12861
12862 /* Solve L*X = B, overwriting B with X. */
12863
12864 dtbsv_("Lower", "No transpose", "Non-unit", n, kd, &ab[ab_offset],
12865 ldab, &b[j * b_dim1 + 1], &c__1);
12866
12867 /* Solve L'*X = B, overwriting B with X. */
12868
12869 dtbsv_("Lower", "Transpose", "Non-unit", n, kd, &ab[ab_offset],
12870 ldab, &b[j * b_dim1 + 1], &c__1);
12871 /* L20: */
12872 }
12873 }
12874
12875 return 0;
12876
12877 /* End of DPBTRS */
12878
12879 } /* dpbtrs_ */
12880
12881 int dpftrf_(const char *transr, const char *uplo, integer *n, double *a, integer *info)
12882 {
12883 /* Table of constant values */
12884 static double c_b12 = 1.;
12885 static double c_b15 = -1.;
12886
12887 /* System generated locals */
12888 integer i__1, i__2;
12889
12890 /* Local variables */
12891 integer k, n1, n2;
12892 bool normaltransr;
12893 bool lower;
12894 bool nisodd;
12895
12896
12897 /* -- LAPACK routine (version 3.2) -- */
12898
12899 /* -- Contributed by Fred Gustavson of the IBM Watson Research Center -- */
12900 /* -- November 2008 -- */
12901
12902 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
12903 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
12904
12905 /* .. */
12906 /* .. Scalar Arguments .. */
12907 /* .. */
12908 /* .. Array Arguments .. */
12909
12910 /* Purpose */
12911 /* ======= */
12912
12913 /* DPFTRF computes the Cholesky factorization of a real symmetric */
12914 /* positive definite matrix A. */
12915
12916 /* The factorization has the form */
12917 /* A = U**T * U, if UPLO = 'U', or */
12918 /* A = L * L**T, if UPLO = 'L', */
12919 /* where U is an upper triangular matrix and L is lower triangular. */
12920
12921 /* This is the block version of the algorithm, calling Level 3 BLAS. */
12922
12923 /* Arguments */
12924 /* ========= */
12925
12926 /* TRANSR (input) CHARACTER */
12927 /* = 'N': The Normal TRANSR of RFP A is stored; */
12928 /* = 'T': The Transpose TRANSR of RFP A is stored. */
12929
12930 /* UPLO (input) CHARACTER */
12931 /* = 'U': Upper triangle of RFP A is stored; */
12932 /* = 'L': Lower triangle of RFP A is stored. */
12933
12934 /* N (input) INTEGER */
12935 /* The order of the matrix A. N >= 0. */
12936
12937 /* A (input/output) DOUBLE PRECISION array, dimension ( N*(N+1)/2 ); */
12938 /* On entry, the symmetric matrix A in RFP format. RFP format is */
12939 /* described by TRANSR, UPLO, and N as follows: If TRANSR = 'N' */
12940 /* then RFP A is (0:N,0:k-1) when N is even; k=N/2. RFP A is */
12941 /* (0:N-1,0:k) when N is odd; k=N/2. IF TRANSR = 'T' then RFP is */
12942 /* the transpose of RFP A as defined when */
12943 /* TRANSR = 'N'. The contents of RFP A are defined by UPLO as */
12944 /* follows: If UPLO = 'U' the RFP A contains the NT elements of */
12945 /* upper packed A. If UPLO = 'L' the RFP A contains the elements */
12946 /* of lower packed A. The LDA of RFP A is (N+1)/2 when TRANSR = */
12947 /* 'T'. When TRANSR is 'N' the LDA is N+1 when N is even and N */
12948 /* is odd. See the Note below for more details. */
12949
12950 /* On exit, if INFO = 0, the factor U or L from the Cholesky */
12951 /* factorization RFP A = U**T*U or RFP A = L*L**T. */
12952
12953 /* INFO (output) INTEGER */
12954 /* = 0: successful exit */
12955 /* < 0: if INFO = -i, the i-th argument had an illegal value */
12956 /* > 0: if INFO = i, the leading minor of order i is not */
12957 /* positive definite, and the factorization could not be */
12958 /* completed. */
12959
12960 /* Notes */
12961 /* ===== */
12962
12963 /* We first consider Rectangular Full Packed (RFP) Format when N is */
12964 /* even. We give an example where N = 6. */
12965
12966 /* AP is Upper AP is Lower */
12967
12968 /* 00 01 02 03 04 05 00 */
12969 /* 11 12 13 14 15 10 11 */
12970 /* 22 23 24 25 20 21 22 */
12971 /* 33 34 35 30 31 32 33 */
12972 /* 44 45 40 41 42 43 44 */
12973 /* 55 50 51 52 53 54 55 */
12974
12975
12976 /* Let TRANSR = 'N'. RFP holds AP as follows: */
12977 /* For UPLO = 'U' the upper trapezoid A(0:5,0:2) consists of the last */
12978 /* three columns of AP upper. The lower triangle A(4:6,0:2) consists of */
12979 /* the transpose of the first three columns of AP upper. */
12980 /* For UPLO = 'L' the lower trapezoid A(1:6,0:2) consists of the first */
12981 /* three columns of AP lower. The upper triangle A(0:2,0:2) consists of */
12982 /* the transpose of the last three columns of AP lower. */
12983 /* This covers the case N even and TRANSR = 'N'. */
12984
12985 /* RFP A RFP A */
12986
12987 /* 03 04 05 33 43 53 */
12988 /* 13 14 15 00 44 54 */
12989 /* 23 24 25 10 11 55 */
12990 /* 33 34 35 20 21 22 */
12991 /* 00 44 45 30 31 32 */
12992 /* 01 11 55 40 41 42 */
12993 /* 02 12 22 50 51 52 */
12994
12995 /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
12996 /* transpose of RFP A above. One therefore gets: */
12997
12998
12999 /* RFP A RFP A */
13000
13001 /* 03 13 23 33 00 01 02 33 00 10 20 30 40 50 */
13002 /* 04 14 24 34 44 11 12 43 44 11 21 31 41 51 */
13003 /* 05 15 25 35 45 55 22 53 54 55 22 32 42 52 */
13004
13005
13006 /* We first consider Rectangular Full Packed (RFP) Format when N is */
13007 /* odd. We give an example where N = 5. */
13008
13009 /* AP is Upper AP is Lower */
13010
13011 /* 00 01 02 03 04 00 */
13012 /* 11 12 13 14 10 11 */
13013 /* 22 23 24 20 21 22 */
13014 /* 33 34 30 31 32 33 */
13015 /* 44 40 41 42 43 44 */
13016
13017
13018 /* Let TRANSR = 'N'. RFP holds AP as follows: */
13019 /* For UPLO = 'U' the upper trapezoid A(0:4,0:2) consists of the last */
13020 /* three columns of AP upper. The lower triangle A(3:4,0:1) consists of */
13021 /* the transpose of the first two columns of AP upper. */
13022 /* For UPLO = 'L' the lower trapezoid A(0:4,0:2) consists of the first */
13023 /* three columns of AP lower. The upper triangle A(0:1,1:2) consists of */
13024 /* the transpose of the last two columns of AP lower. */
13025 /* This covers the case N odd and TRANSR = 'N'. */
13026
13027 /* RFP A RFP A */
13028
13029 /* 02 03 04 00 33 43 */
13030 /* 12 13 14 10 11 44 */
13031 /* 22 23 24 20 21 22 */
13032 /* 00 33 34 30 31 32 */
13033 /* 01 11 44 40 41 42 */
13034
13035 /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
13036 /* transpose of RFP A above. One therefore gets: */
13037
13038 /* RFP A RFP A */
13039
13040 /* 02 12 22 00 01 00 10 20 30 40 50 */
13041 /* 03 13 23 33 11 33 11 21 31 41 51 */
13042 /* 04 14 24 34 44 43 44 22 32 42 52 */
13043
13044 /* ===================================================================== */
13045
13046 /* .. Parameters .. */
13047 /* .. */
13048 /* .. Local Scalars .. */
13049 /* .. */
13050 /* .. External Functions .. */
13051 /* .. */
13052 /* .. External Subroutines .. */
13053 /* .. */
13054 /* .. Intrinsic Functions .. */
13055 /* .. */
13056 /* .. Executable Statements .. */
13057
13058 /* Test the input parameters. */
13059
13060 *info = 0;
13061 normaltransr = lsame_(transr, "N");
13062 lower = lsame_(uplo, "L");
13063 if (! normaltransr && ! lsame_(transr, "T")) {
13064 *info = -1;
13065 } else if (! lower && ! lsame_(uplo, "U")) {
13066 *info = -2;
13067 } else if (*n < 0) {
13068 *info = -3;
13069 }
13070 if (*info != 0) {
13071 i__1 = -(*info);
13072 xerbla_("DPFTRF", &i__1);
13073 return 0;
13074 }
13075
13076 /* Quick return if possible */
13077
13078 if (*n == 0) {
13079 return 0;
13080 }
13081
13082 /* If N is odd, set NISODD = .TRUE. */
13083 /* If N is even, set K = N/2 and NISODD = .FALSE. */
13084
13085 if (*n % 2 == 0) {
13086 k = *n / 2;
13087 nisodd = false;
13088 } else {
13089 nisodd = true;
13090 }
13091
13092 /* Set N1 and N2 depending on LOWER */
13093
13094 if (lower) {
13095 n2 = *n / 2;
13096 n1 = *n - n2;
13097 } else {
13098 n1 = *n / 2;
13099 n2 = *n - n1;
13100 }
13101
13102 /* start execution: there are eight cases */
13103
13104 if (nisodd) {
13105
13106 /* N is odd */
13107
13108 if (normaltransr) {
13109
13110 /* N is odd and TRANSR = 'N' */
13111
13112 if (lower) {
13113
13114 /* SRPA for LOWER, NORMAL and N is odd ( a(0:n-1,0:n1-1) ) */
13115 /* T1 -> a(0,0), T2 -> a(0,1), S -> a(n1,0) */
13116 /* T1 -> a(0), T2 -> a(n), S -> a(n1) */
13117
13118 dpotrf_("L", &n1, a, n, info);
13119 if (*info > 0) {
13120 return 0;
13121 }
13122 dtrsm_("R", "L", "T", "N", &n2, &n1, &c_b12, a, n, &a[n1], n);
13123 dsyrk_("U", "N", &n2, &n1, &c_b15, &a[n1], n, &c_b12, &a[*n],
13124 n);
13125 dpotrf_("U", &n2, &a[*n], n, info);
13126 if (*info > 0) {
13127 *info += n1;
13128 }
13129
13130 } else {
13131
13132 /* SRPA for UPPER, NORMAL and N is odd ( a(0:n-1,0:n2-1) */
13133 /* T1 -> a(n1+1,0), T2 -> a(n1,0), S -> a(0,0) */
13134 /* T1 -> a(n2), T2 -> a(n1), S -> a(0) */
13135
13136 dpotrf_("L", &n1, &a[n2], n, info);
13137 if (*info > 0) {
13138 return 0;
13139 }
13140 dtrsm_("L", "L", "N", "N", &n1, &n2, &c_b12, &a[n2], n, a, n);
13141 dsyrk_("U", "T", &n2, &n1, &c_b15, a, n, &c_b12, &a[n1], n);
13142 dpotrf_("U", &n2, &a[n1], n, info);
13143 if (*info > 0) {
13144 *info += n1;
13145 }
13146
13147 }
13148
13149 } else {
13150
13151 /* N is odd and TRANSR = 'T' */
13152
13153 if (lower) {
13154
13155 /* SRPA for LOWER, TRANSPOSE and N is odd */
13156 /* T1 -> A(0,0) , T2 -> A(1,0) , S -> A(0,n1) */
13157 /* T1 -> a(0+0) , T2 -> a(1+0) , S -> a(0+n1*n1); lda=n1 */
13158
13159 dpotrf_("U", &n1, a, &n1, info);
13160 if (*info > 0) {
13161 return 0;
13162 }
13163 dtrsm_("L", "U", "T", "N", &n1, &n2, &c_b12, a, &n1, &a[n1 *
13164 n1], &n1);
13165 dsyrk_("L", "T", &n2, &n1, &c_b15, &a[n1 * n1], &n1, &c_b12, &
13166 a[1], &n1);
13167 dpotrf_("L", &n2, &a[1], &n1, info);
13168 if (*info > 0) {
13169 *info += n1;
13170 }
13171
13172 } else {
13173
13174 /* SRPA for UPPER, TRANSPOSE and N is odd */
13175 /* T1 -> A(0,n1+1), T2 -> A(0,n1), S -> A(0,0) */
13176 /* T1 -> a(n2*n2), T2 -> a(n1*n2), S -> a(0); lda = n2 */
13177
13178 dpotrf_("U", &n1, &a[n2 * n2], &n2, info);
13179 if (*info > 0) {
13180 return 0;
13181 }
13182 dtrsm_("R", "U", "N", "N", &n2, &n1, &c_b12, &a[n2 * n2], &n2,
13183 a, &n2);
13184 dsyrk_("L", "N", &n2, &n1, &c_b15, a, &n2, &c_b12, &a[n1 * n2]
13185 , &n2);
13186 dpotrf_("L", &n2, &a[n1 * n2], &n2, info);
13187 if (*info > 0) {
13188 *info += n1;
13189 }
13190
13191 }
13192
13193 }
13194
13195 } else {
13196
13197 /* N is even */
13198
13199 if (normaltransr) {
13200
13201 /* N is even and TRANSR = 'N' */
13202
13203 if (lower) {
13204
13205 /* SRPA for LOWER, NORMAL, and N is even ( a(0:n,0:k-1) ) */
13206 /* T1 -> a(1,0), T2 -> a(0,0), S -> a(k+1,0) */
13207 /* T1 -> a(1), T2 -> a(0), S -> a(k+1) */
13208
13209 i__1 = *n + 1;
13210 dpotrf_("L", &k, &a[1], &i__1, info);
13211 if (*info > 0) {
13212 return 0;
13213 }
13214 i__1 = *n + 1;
13215 i__2 = *n + 1;
13216 dtrsm_("R", "L", "T", "N", &k, &k, &c_b12, &a[1], &i__1, &a[k
13217 + 1], &i__2);
13218 i__1 = *n + 1;
13219 i__2 = *n + 1;
13220 dsyrk_("U", "N", &k, &k, &c_b15, &a[k + 1], &i__1, &c_b12, a,
13221 &i__2);
13222 i__1 = *n + 1;
13223 dpotrf_("U", &k, a, &i__1, info);
13224 if (*info > 0) {
13225 *info += k;
13226 }
13227
13228 } else {
13229
13230 /* SRPA for UPPER, NORMAL, and N is even ( a(0:n,0:k-1) ) */
13231 /* T1 -> a(k+1,0) , T2 -> a(k,0), S -> a(0,0) */
13232 /* T1 -> a(k+1), T2 -> a(k), S -> a(0) */
13233
13234 i__1 = *n + 1;
13235 dpotrf_("L", &k, &a[k + 1], &i__1, info);
13236 if (*info > 0) {
13237 return 0;
13238 }
13239 i__1 = *n + 1;
13240 i__2 = *n + 1;
13241 dtrsm_("L", "L", "N", "N", &k, &k, &c_b12, &a[k + 1], &i__1,
13242 a, &i__2);
13243 i__1 = *n + 1;
13244 i__2 = *n + 1;
13245 dsyrk_("U", "T", &k, &k, &c_b15, a, &i__1, &c_b12, &a[k], &
13246 i__2);
13247 i__1 = *n + 1;
13248 dpotrf_("U", &k, &a[k], &i__1, info);
13249 if (*info > 0) {
13250 *info += k;
13251 }
13252
13253 }
13254
13255 } else {
13256
13257 /* N is even and TRANSR = 'T' */
13258
13259 if (lower) {
13260
13261 /* SRPA for LOWER, TRANSPOSE and N is even (see paper) */
13262 /* T1 -> B(0,1), T2 -> B(0,0), S -> B(0,k+1) */
13263 /* T1 -> a(0+k), T2 -> a(0+0), S -> a(0+k*(k+1)); lda=k */
13264
13265 dpotrf_("U", &k, &a[k], &k, info);
13266 if (*info > 0) {
13267 return 0;
13268 }
13269 dtrsm_("L", "U", "T", "N", &k, &k, &c_b12, &a[k], &n1, &a[k *
13270 (k + 1)], &k);
13271 dsyrk_("L", "T", &k, &k, &c_b15, &a[k * (k + 1)], &k, &c_b12,
13272 a, &k);
13273 dpotrf_("L", &k, a, &k, info);
13274 if (*info > 0) {
13275 *info += k;
13276 }
13277
13278 } else {
13279
13280 /* SRPA for UPPER, TRANSPOSE and N is even (see paper) */
13281 /* T1 -> B(0,k+1), T2 -> B(0,k), S -> B(0,0) */
13282 /* T1 -> a(0+k*(k+1)), T2 -> a(0+k*k), S -> a(0+0)); lda=k */
13283
13284 dpotrf_("U", &k, &a[k * (k + 1)], &k, info);
13285 if (*info > 0) {
13286 return 0;
13287 }
13288 dtrsm_("R", "U", "N", "N", &k, &k, &c_b12, &a[k * (k + 1)], &
13289 k, a, &k);
13290 dsyrk_("L", "N", &k, &k, &c_b15, a, &k, &c_b12, &a[k * k], &k);
13291 dpotrf_("L", &k, &a[k * k], &k, info);
13292 if (*info > 0) {
13293 *info += k;
13294 }
13295
13296 }
13297
13298 }
13299
13300 }
13301
13302 return 0;
13303
13304 /* End of DPFTRF */
13305
13306 } /* dpftrf_ */
13307
13308 int dpftri_(const char *transr, const char *uplo, integer *n, double *a, integer *info)
13309 {
13310 /* Table of constant values */
13311 static double c_b11 = 1.;
13312
13313 /* System generated locals */
13314 integer i__1, i__2;
13315
13316 /* Local variables */
13317 integer k, n1, n2;
13318 bool normaltransr, lower, nisodd;
13319
13320
13321 /* -- LAPACK routine (version 3.2) -- */
13322
13323 /* -- Contributed by Fred Gustavson of the IBM Watson Research Center -- */
13324 /* -- November 2008 -- */
13325
13326 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
13327 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
13328
13329 /* .. Scalar Arguments .. */
13330 /* .. Array Arguments .. */
13331 /* .. */
13332
13333 /* Purpose */
13334 /* ======= */
13335
13336 /* DPFTRI computes the inverse of a (real) symmetric positive definite */
13337 /* matrix A using the Cholesky factorization A = U**T*U or A = L*L**T */
13338 /* computed by DPFTRF. */
13339
13340 /* Arguments */
13341 /* ========= */
13342
13343 /* TRANSR (input) CHARACTER */
13344 /* = 'N': The Normal TRANSR of RFP A is stored; */
13345 /* = 'T': The Transpose TRANSR of RFP A is stored. */
13346
13347 /* UPLO (input) CHARACTER */
13348 /* = 'U': Upper triangle of A is stored; */
13349 /* = 'L': Lower triangle of A is stored. */
13350
13351 /* N (input) INTEGER */
13352 /* The order of the matrix A. N >= 0. */
13353
13354 /* A (input/output) DOUBLE PRECISION array, dimension ( N*(N+1)/2 ) */
13355 /* On entry, the symmetric matrix A in RFP format. RFP format is */
13356 /* described by TRANSR, UPLO, and N as follows: If TRANSR = 'N' */
13357 /* then RFP A is (0:N,0:k-1) when N is even; k=N/2. RFP A is */
13358 /* (0:N-1,0:k) when N is odd; k=N/2. IF TRANSR = 'T' then RFP is */
13359 /* the transpose of RFP A as defined when */
13360 /* TRANSR = 'N'. The contents of RFP A are defined by UPLO as */
13361 /* follows: If UPLO = 'U' the RFP A contains the nt elements of */
13362 /* upper packed A. If UPLO = 'L' the RFP A contains the elements */
13363 /* of lower packed A. The LDA of RFP A is (N+1)/2 when TRANSR = */
13364 /* 'T'. When TRANSR is 'N' the LDA is N+1 when N is even and N */
13365 /* is odd. See the Note below for more details. */
13366
13367 /* On exit, the symmetric inverse of the original matrix, in the */
13368 /* same storage format. */
13369
13370 /* INFO (output) INTEGER */
13371 /* = 0: successful exit */
13372 /* < 0: if INFO = -i, the i-th argument had an illegal value */
13373 /* > 0: if INFO = i, the (i,i) element of the factor U or L is */
13374 /* zero, and the inverse could not be computed. */
13375
13376 /* Notes */
13377 /* ===== */
13378
13379 /* We first consider Rectangular Full Packed (RFP) Format when N is */
13380 /* even. We give an example where N = 6. */
13381
13382 /* AP is Upper AP is Lower */
13383
13384 /* 00 01 02 03 04 05 00 */
13385 /* 11 12 13 14 15 10 11 */
13386 /* 22 23 24 25 20 21 22 */
13387 /* 33 34 35 30 31 32 33 */
13388 /* 44 45 40 41 42 43 44 */
13389 /* 55 50 51 52 53 54 55 */
13390
13391
13392 /* Let TRANSR = 'N'. RFP holds AP as follows: */
13393 /* For UPLO = 'U' the upper trapezoid A(0:5,0:2) consists of the last */
13394 /* three columns of AP upper. The lower triangle A(4:6,0:2) consists of */
13395 /* the transpose of the first three columns of AP upper. */
13396 /* For UPLO = 'L' the lower trapezoid A(1:6,0:2) consists of the first */
13397 /* three columns of AP lower. The upper triangle A(0:2,0:2) consists of */
13398 /* the transpose of the last three columns of AP lower. */
13399 /* This covers the case N even and TRANSR = 'N'. */
13400
13401 /* RFP A RFP A */
13402
13403 /* 03 04 05 33 43 53 */
13404 /* 13 14 15 00 44 54 */
13405 /* 23 24 25 10 11 55 */
13406 /* 33 34 35 20 21 22 */
13407 /* 00 44 45 30 31 32 */
13408 /* 01 11 55 40 41 42 */
13409 /* 02 12 22 50 51 52 */
13410
13411 /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
13412 /* transpose of RFP A above. One therefore gets: */
13413
13414
13415 /* RFP A RFP A */
13416
13417 /* 03 13 23 33 00 01 02 33 00 10 20 30 40 50 */
13418 /* 04 14 24 34 44 11 12 43 44 11 21 31 41 51 */
13419 /* 05 15 25 35 45 55 22 53 54 55 22 32 42 52 */
13420
13421
13422 /* We first consider Rectangular Full Packed (RFP) Format when N is */
13423 /* odd. We give an example where N = 5. */
13424
13425 /* AP is Upper AP is Lower */
13426
13427 /* 00 01 02 03 04 00 */
13428 /* 11 12 13 14 10 11 */
13429 /* 22 23 24 20 21 22 */
13430 /* 33 34 30 31 32 33 */
13431 /* 44 40 41 42 43 44 */
13432
13433
13434 /* Let TRANSR = 'N'. RFP holds AP as follows: */
13435 /* For UPLO = 'U' the upper trapezoid A(0:4,0:2) consists of the last */
13436 /* three columns of AP upper. The lower triangle A(3:4,0:1) consists of */
13437 /* the transpose of the first two columns of AP upper. */
13438 /* For UPLO = 'L' the lower trapezoid A(0:4,0:2) consists of the first */
13439 /* three columns of AP lower. The upper triangle A(0:1,1:2) consists of */
13440 /* the transpose of the last two columns of AP lower. */
13441 /* This covers the case N odd and TRANSR = 'N'. */
13442
13443 /* RFP A RFP A */
13444
13445 /* 02 03 04 00 33 43 */
13446 /* 12 13 14 10 11 44 */
13447 /* 22 23 24 20 21 22 */
13448 /* 00 33 34 30 31 32 */
13449 /* 01 11 44 40 41 42 */
13450
13451 /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
13452 /* transpose of RFP A above. One therefore gets: */
13453
13454 /* RFP A RFP A */
13455
13456 /* 02 12 22 00 01 00 10 20 30 40 50 */
13457 /* 03 13 23 33 11 33 11 21 31 41 51 */
13458 /* 04 14 24 34 44 43 44 22 32 42 52 */
13459
13460 /* ===================================================================== */
13461
13462 /* .. Parameters .. */
13463 /* .. */
13464 /* .. Local Scalars .. */
13465 /* .. */
13466 /* .. External Functions .. */
13467 /* .. */
13468 /* .. External Subroutines .. */
13469 /* .. */
13470 /* .. Intrinsic Functions .. */
13471 /* .. */
13472 /* .. Executable Statements .. */
13473
13474 /* Test the input parameters. */
13475
13476 *info = 0;
13477 normaltransr = lsame_(transr, "N");
13478 lower = lsame_(uplo, "L");
13479 if (! normaltransr && ! lsame_(transr, "T")) {
13480 *info = -1;
13481 } else if (! lower && ! lsame_(uplo, "U")) {
13482 *info = -2;
13483 } else if (*n < 0) {
13484 *info = -3;
13485 }
13486 if (*info != 0) {
13487 i__1 = -(*info);
13488 xerbla_("DPFTRI", &i__1);
13489 return 0;
13490 }
13491
13492 /* Quick return if possible */
13493
13494 if (*n == 0) {
13495 return 0;
13496 }
13497
13498 /* Invert the triangular Cholesky factor U or L. */
13499
13500 dtftri_(transr, uplo, "N", n, a, info);
13501 if (*info > 0) {
13502 return 0;
13503 }
13504
13505 /* If N is odd, set NISODD = .TRUE. */
13506 /* If N is even, set K = N/2 and NISODD = .FALSE. */
13507
13508 if (*n % 2 == 0) {
13509 k = *n / 2;
13510 nisodd = false;
13511 } else {
13512 nisodd = true;
13513 }
13514
13515 /* Set N1 and N2 depending on LOWER */
13516
13517 if (lower) {
13518 n2 = *n / 2;
13519 n1 = *n - n2;
13520 } else {
13521 n1 = *n / 2;
13522 n2 = *n - n1;
13523 }
13524
13525 /* Start execution of triangular matrix multiply: inv(U)*inv(U)^C or */
13526 /* inv(L)^C*inv(L). There are eight cases. */
13527
13528 if (nisodd) {
13529
13530 /* N is odd */
13531
13532 if (normaltransr) {
13533
13534 /* N is odd and TRANSR = 'N' */
13535
13536 if (lower) {
13537
13538 /* SRPA for LOWER, NORMAL and N is odd ( a(0:n-1,0:N1-1) ) */
13539 /* T1 -> a(0,0), T2 -> a(0,1), S -> a(N1,0) */
13540 /* T1 -> a(0), T2 -> a(n), S -> a(N1) */
13541
13542 dlauum_("L", &n1, a, n, info);
13543 dsyrk_("L", "T", &n1, &n2, &c_b11, &a[n1], n, &c_b11, a, n);
13544 dtrmm_("L", "U", "N", "N", &n2, &n1, &c_b11, &a[*n], n, &a[n1]
13545 , n);
13546 dlauum_("U", &n2, &a[*n], n, info);
13547
13548 } else {
13549
13550 /* SRPA for UPPER, NORMAL and N is odd ( a(0:n-1,0:N2-1) */
13551 /* T1 -> a(N1+1,0), T2 -> a(N1,0), S -> a(0,0) */
13552 /* T1 -> a(N2), T2 -> a(N1), S -> a(0) */
13553
13554 dlauum_("L", &n1, &a[n2], n, info);
13555 dsyrk_("L", "N", &n1, &n2, &c_b11, a, n, &c_b11, &a[n2], n);
13556 dtrmm_("R", "U", "T", "N", &n1, &n2, &c_b11, &a[n1], n, a, n);
13557 dlauum_("U", &n2, &a[n1], n, info);
13558
13559 }
13560
13561 } else {
13562
13563 /* N is odd and TRANSR = 'T' */
13564
13565 if (lower) {
13566
13567 /* SRPA for LOWER, TRANSPOSE, and N is odd */
13568 /* T1 -> a(0), T2 -> a(1), S -> a(0+N1*N1) */
13569
13570 dlauum_("U", &n1, a, &n1, info);
13571 dsyrk_("U", "N", &n1, &n2, &c_b11, &a[n1 * n1], &n1, &c_b11,
13572 a, &n1);
13573 dtrmm_("R", "L", "N", "N", &n1, &n2, &c_b11, &a[1], &n1, &a[
13574 n1 * n1], &n1);
13575 dlauum_("L", &n2, &a[1], &n1, info);
13576
13577 } else {
13578
13579 /* SRPA for UPPER, TRANSPOSE, and N is odd */
13580 /* T1 -> a(0+N2*N2), T2 -> a(0+N1*N2), S -> a(0) */
13581
13582 dlauum_("U", &n1, &a[n2 * n2], &n2, info);
13583 dsyrk_("U", "T", &n1, &n2, &c_b11, a, &n2, &c_b11, &a[n2 * n2]
13584 , &n2);
13585 dtrmm_("L", "L", "T", "N", &n2, &n1, &c_b11, &a[n1 * n2], &n2,
13586 a, &n2);
13587 dlauum_("L", &n2, &a[n1 * n2], &n2, info);
13588
13589 }
13590
13591 }
13592
13593 } else {
13594
13595 /* N is even */
13596
13597 if (normaltransr) {
13598
13599 /* N is even and TRANSR = 'N' */
13600
13601 if (lower) {
13602
13603 /* SRPA for LOWER, NORMAL, and N is even ( a(0:n,0:k-1) ) */
13604 /* T1 -> a(1,0), T2 -> a(0,0), S -> a(k+1,0) */
13605 /* T1 -> a(1), T2 -> a(0), S -> a(k+1) */
13606
13607 i__1 = *n + 1;
13608 dlauum_("L", &k, &a[1], &i__1, info);
13609 i__1 = *n + 1;
13610 i__2 = *n + 1;
13611 dsyrk_("L", "T", &k, &k, &c_b11, &a[k + 1], &i__1, &c_b11, &a[
13612 1], &i__2);
13613 i__1 = *n + 1;
13614 i__2 = *n + 1;
13615 dtrmm_("L", "U", "N", "N", &k, &k, &c_b11, a, &i__1, &a[k + 1]
13616 , &i__2);
13617 i__1 = *n + 1;
13618 dlauum_("U", &k, a, &i__1, info);
13619
13620 } else {
13621
13622 /* SRPA for UPPER, NORMAL, and N is even ( a(0:n,0:k-1) ) */
13623 /* T1 -> a(k+1,0) , T2 -> a(k,0), S -> a(0,0) */
13624 /* T1 -> a(k+1), T2 -> a(k), S -> a(0) */
13625
13626 i__1 = *n + 1;
13627 dlauum_("L", &k, &a[k + 1], &i__1, info);
13628 i__1 = *n + 1;
13629 i__2 = *n + 1;
13630 dsyrk_("L", "N", &k, &k, &c_b11, a, &i__1, &c_b11, &a[k + 1],
13631 &i__2);
13632 i__1 = *n + 1;
13633 i__2 = *n + 1;
13634 dtrmm_("R", "U", "T", "N", &k, &k, &c_b11, &a[k], &i__1, a, &
13635 i__2);
13636 i__1 = *n + 1;
13637 dlauum_("U", &k, &a[k], &i__1, info);
13638
13639 }
13640
13641 } else {
13642
13643 /* N is even and TRANSR = 'T' */
13644
13645 if (lower) {
13646
13647 /* SRPA for LOWER, TRANSPOSE, and N is even (see paper) */
13648 /* T1 -> B(0,1), T2 -> B(0,0), S -> B(0,k+1), */
13649 /* T1 -> a(0+k), T2 -> a(0+0), S -> a(0+k*(k+1)); lda=k */
13650
13651 dlauum_("U", &k, &a[k], &k, info);
13652 dsyrk_("U", "N", &k, &k, &c_b11, &a[k * (k + 1)], &k, &c_b11,
13653 &a[k], &k);
13654 dtrmm_("R", "L", "N", "N", &k, &k, &c_b11, a, &k, &a[k * (k +
13655 1)], &k);
13656 dlauum_("L", &k, a, &k, info);
13657
13658 } else {
13659
13660 /* SRPA for UPPER, TRANSPOSE, and N is even (see paper) */
13661 /* T1 -> B(0,k+1), T2 -> B(0,k), S -> B(0,0), */
13662 /* T1 -> a(0+k*(k+1)), T2 -> a(0+k*k), S -> a(0+0)); lda=k */
13663
13664 dlauum_("U", &k, &a[k * (k + 1)], &k, info);
13665 dsyrk_("U", "T", &k, &k, &c_b11, a, &k, &c_b11, &a[k * (k + 1)
13666 ], &k);
13667 dtrmm_("L", "L", "T", "N", &k, &k, &c_b11, &a[k * k], &k, a, &
13668 k);
13669 dlauum_("L", &k, &a[k * k], &k, info);
13670
13671 }
13672
13673 }
13674
13675 }
13676
13677 return 0;
13678
13679 /* End of DPFTRI */
13680
13681 } /* dpftri_ */
13682
13683 int dpftrs_(char *transr, char *uplo, integer *n, integer *nrhs, double *a, double *b, integer *ldb, integer *info)
13684 {
13685 /* Table of constant values */
13686 static double c_b10 = 1.;
13687
13688 /* System generated locals */
13689 integer b_dim1, b_offset, i__1;
13690
13691 /* Local variables */
13692 bool normaltransr, lower;
13693
13694
13695 /* -- LAPACK routine (version 3.2) -- */
13696
13697 /* -- Contributed by Fred Gustavson of the IBM Watson Research Center -- */
13698 /* -- November 2008 -- */
13699
13700 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
13701 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
13702
13703 /* .. Scalar Arguments .. */
13704 /* .. */
13705 /* .. Array Arguments .. */
13706 /* .. */
13707
13708 /* Purpose */
13709 /* ======= */
13710
13711 /* DPFTRS solves a system of linear equations A*X = B with a symmetric */
13712 /* positive definite matrix A using the Cholesky factorization */
13713 /* A = U**T*U or A = L*L**T computed by DPFTRF. */
13714
13715 /* Arguments */
13716 /* ========= */
13717
13718 /* TRANSR (input) CHARACTER */
13719 /* = 'N': The Normal TRANSR of RFP A is stored; */
13720 /* = 'T': The Transpose TRANSR of RFP A is stored. */
13721
13722 /* UPLO (input) CHARACTER */
13723 /* = 'U': Upper triangle of RFP A is stored; */
13724 /* = 'L': Lower triangle of RFP A is stored. */
13725
13726 /* N (input) INTEGER */
13727 /* The order of the matrix A. N >= 0. */
13728
13729 /* NRHS (input) INTEGER */
13730 /* The number of right hand sides, i.e., the number of columns */
13731 /* of the matrix B. NRHS >= 0. */
13732
13733 /* A (input) DOUBLE PRECISION array, dimension ( N*(N+1)/2 ). */
13734 /* The triangular factor U or L from the Cholesky factorization */
13735 /* of RFP A = U**T*U or RFP A = L*L**T, as computed by DPFTRF. */
13736 /* See note below for more details about RFP A. */
13737
13738 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
13739 /* On entry, the right hand side matrix B. */
13740 /* On exit, the solution matrix X. */
13741
13742 /* LDB (input) INTEGER */
13743 /* The leading dimension of the array B. LDB >= max(1,N). */
13744
13745 /* INFO (output) INTEGER */
13746 /* = 0: successful exit */
13747 /* < 0: if INFO = -i, the i-th argument had an illegal value */
13748
13749 /* Notes */
13750 /* ===== */
13751
13752 /* We first consider Rectangular Full Packed (RFP) Format when N is */
13753 /* even. We give an example where N = 6. */
13754
13755 /* AP is Upper AP is Lower */
13756
13757 /* 00 01 02 03 04 05 00 */
13758 /* 11 12 13 14 15 10 11 */
13759 /* 22 23 24 25 20 21 22 */
13760 /* 33 34 35 30 31 32 33 */
13761 /* 44 45 40 41 42 43 44 */
13762 /* 55 50 51 52 53 54 55 */
13763
13764
13765 /* Let TRANSR = 'N'. RFP holds AP as follows: */
13766 /* For UPLO = 'U' the upper trapezoid A(0:5,0:2) consists of the last */
13767 /* three columns of AP upper. The lower triangle A(4:6,0:2) consists of */
13768 /* the transpose of the first three columns of AP upper. */
13769 /* For UPLO = 'L' the lower trapezoid A(1:6,0:2) consists of the first */
13770 /* three columns of AP lower. The upper triangle A(0:2,0:2) consists of */
13771 /* the transpose of the last three columns of AP lower. */
13772 /* This covers the case N even and TRANSR = 'N'. */
13773
13774 /* RFP A RFP A */
13775
13776 /* 03 04 05 33 43 53 */
13777 /* 13 14 15 00 44 54 */
13778 /* 23 24 25 10 11 55 */
13779 /* 33 34 35 20 21 22 */
13780 /* 00 44 45 30 31 32 */
13781 /* 01 11 55 40 41 42 */
13782 /* 02 12 22 50 51 52 */
13783
13784 /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
13785 /* transpose of RFP A above. One therefore gets: */
13786
13787
13788 /* RFP A RFP A */
13789
13790 /* 03 13 23 33 00 01 02 33 00 10 20 30 40 50 */
13791 /* 04 14 24 34 44 11 12 43 44 11 21 31 41 51 */
13792 /* 05 15 25 35 45 55 22 53 54 55 22 32 42 52 */
13793
13794
13795 /* We first consider Rectangular Full Packed (RFP) Format when N is */
13796 /* odd. We give an example where N = 5. */
13797
13798 /* AP is Upper AP is Lower */
13799
13800 /* 00 01 02 03 04 00 */
13801 /* 11 12 13 14 10 11 */
13802 /* 22 23 24 20 21 22 */
13803 /* 33 34 30 31 32 33 */
13804 /* 44 40 41 42 43 44 */
13805
13806
13807 /* Let TRANSR = 'N'. RFP holds AP as follows: */
13808 /* For UPLO = 'U' the upper trapezoid A(0:4,0:2) consists of the last */
13809 /* three columns of AP upper. The lower triangle A(3:4,0:1) consists of */
13810 /* the transpose of the first two columns of AP upper. */
13811 /* For UPLO = 'L' the lower trapezoid A(0:4,0:2) consists of the first */
13812 /* three columns of AP lower. The upper triangle A(0:1,1:2) consists of */
13813 /* the transpose of the last two columns of AP lower. */
13814 /* This covers the case N odd and TRANSR = 'N'. */
13815
13816 /* RFP A RFP A */
13817
13818 /* 02 03 04 00 33 43 */
13819 /* 12 13 14 10 11 44 */
13820 /* 22 23 24 20 21 22 */
13821 /* 00 33 34 30 31 32 */
13822 /* 01 11 44 40 41 42 */
13823
13824 /* Now let TRANSR = 'T'. RFP A in both UPLO cases is just the */
13825 /* transpose of RFP A above. One therefore gets: */
13826
13827 /* RFP A RFP A */
13828
13829 /* 02 12 22 00 01 00 10 20 30 40 50 */
13830 /* 03 13 23 33 11 33 11 21 31 41 51 */
13831 /* 04 14 24 34 44 43 44 22 32 42 52 */
13832
13833 /* ===================================================================== */
13834
13835 /* .. Parameters .. */
13836 /* .. */
13837 /* .. Local Scalars .. */
13838 /* .. */
13839 /* .. External Functions .. */
13840 /* .. */
13841 /* .. External Subroutines .. */
13842 /* .. */
13843 /* .. Intrinsic Functions .. */
13844 /* .. */
13845 /* .. Executable Statements .. */
13846
13847 /* Test the input parameters. */
13848
13849 /* Parameter adjustments */
13850 b_dim1 = *ldb;
13851 b_offset = 1 + b_dim1;
13852 b -= b_offset;
13853
13854 /* Function Body */
13855 *info = 0;
13856 normaltransr = lsame_(transr, "N");
13857 lower = lsame_(uplo, "L");
13858 if (! normaltransr && ! lsame_(transr, "T")) {
13859 *info = -1;
13860 } else if (! lower && ! lsame_(uplo, "U")) {
13861 *info = -2;
13862 } else if (*n < 0) {
13863 *info = -3;
13864 } else if (*nrhs < 0) {
13865 *info = -4;
13866 } else if (*ldb < std::max(1_integer,*n)) {
13867 *info = -7;
13868 }
13869 if (*info != 0) {
13870 i__1 = -(*info);
13871 xerbla_("DPFTRS", &i__1);
13872 return 0;
13873 }
13874
13875 /* Quick return if possible */
13876
13877 if (*n == 0 || *nrhs == 0) {
13878 return 0;
13879 }
13880
13881 /* start execution: there are two triangular solves */
13882
13883 if (lower) {
13884 dtfsm_(transr, "L", uplo, "N", "N", n, nrhs, &c_b10, a, &b[b_offset],
13885 ldb);
13886 dtfsm_(transr, "L", uplo, "T", "N", n, nrhs, &c_b10, a, &b[b_offset],
13887 ldb);
13888 } else {
13889 dtfsm_(transr, "L", uplo, "T", "N", n, nrhs, &c_b10, a, &b[b_offset],
13890 ldb);
13891 dtfsm_(transr, "L", uplo, "N", "N", n, nrhs, &c_b10, a, &b[b_offset],
13892 ldb);
13893 }
13894
13895 return 0;
13896
13897 /* End of DPFTRS */
13898
13899 } /* dpftrs_ */
13900
13901 /* Subroutine */ int dpocon_(const char *uplo, integer *n, double *a, integer *
13902 lda, double *anorm, double *rcond, double *work, integer *
13903 iwork, integer *info)
13904 {
13905 /* Table of constant values */
13906 static integer c__1 = 1;
13907
13908 /* System generated locals */
13909 integer a_dim1, a_offset, i__1;
13910 double d__1;
13911
13912 /* Local variables */
13913 integer ix, kase;
13914 double scale;
13915 integer isave[3];
13916 bool upper;
13917 double scalel;
13918 double scaleu;
13919 double ainvnm;
13920 char normin[1];
13921 double smlnum;
13922
13923
13924 /* -- LAPACK routine (version 3.1) -- */
13925 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
13926 /* November 2006 */
13927
13928 /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
13929
13930 /* .. Scalar Arguments .. */
13931 /* .. */
13932 /* .. Array Arguments .. */
13933 /* .. */
13934
13935 /* Purpose */
13936 /* ======= */
13937
13938 /* DPOCON estimates the reciprocal of the condition number (in the */
13939 /* 1-norm) of a real symmetric positive definite matrix using the */
13940 /* Cholesky factorization A = U**T*U or A = L*L**T computed by DPOTRF. */
13941
13942 /* An estimate is obtained for norm(inv(A)), and the reciprocal of the */
13943 /* condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). */
13944
13945 /* Arguments */
13946 /* ========= */
13947
13948 /* UPLO (input) CHARACTER*1 */
13949 /* = 'U': Upper triangle of A is stored; */
13950 /* = 'L': Lower triangle of A is stored. */
13951
13952 /* N (input) INTEGER */
13953 /* The order of the matrix A. N >= 0. */
13954
13955 /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
13956 /* The triangular factor U or L from the Cholesky factorization */
13957 /* A = U**T*U or A = L*L**T, as computed by DPOTRF. */
13958
13959 /* LDA (input) INTEGER */
13960 /* The leading dimension of the array A. LDA >= max(1,N). */
13961
13962 /* ANORM (input) DOUBLE PRECISION */
13963 /* The 1-norm (or infinity-norm) of the symmetric matrix A. */
13964
13965 /* RCOND (output) DOUBLE PRECISION */
13966 /* The reciprocal of the condition number of the matrix A, */
13967 /* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an */
13968 /* estimate of the 1-norm of inv(A) computed in this routine. */
13969
13970 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
13971
13972 /* IWORK (workspace) INTEGER array, dimension (N) */
13973
13974 /* INFO (output) INTEGER */
13975 /* = 0: successful exit */
13976 /* < 0: if INFO = -i, the i-th argument had an illegal value */
13977
13978 /* ===================================================================== */
13979
13980 /* .. Parameters .. */
13981 /* .. */
13982 /* .. Local Scalars .. */
13983 /* .. */
13984 /* .. Local Arrays .. */
13985 /* .. */
13986 /* .. External Functions .. */
13987 /* .. */
13988 /* .. External Subroutines .. */
13989 /* .. */
13990 /* .. Intrinsic Functions .. */
13991 /* .. */
13992 /* .. Executable Statements .. */
13993
13994 /* Test the input parameters. */
13995
13996 /* Parameter adjustments */
13997 a_dim1 = *lda;
13998 a_offset = 1 + a_dim1;
13999 a -= a_offset;
14000 --work;
14001 --iwork;
14002
14003 /* Function Body */
14004 *info = 0;
14005 upper = lsame_(uplo, "U");
14006 if (! upper && ! lsame_(uplo, "L")) {
14007 *info = -1;
14008 } else if (*n < 0) {
14009 *info = -2;
14010 } else if (*lda < std::max(1_integer,*n)) {
14011 *info = -4;
14012 } else if (*anorm < 0.) {
14013 *info = -5;
14014 }
14015 if (*info != 0) {
14016 i__1 = -(*info);
14017 xerbla_("DPOCON", &i__1);
14018 return 0;
14019 }
14020
14021 /* Quick return if possible */
14022
14023 *rcond = 0.;
14024 if (*n == 0) {
14025 *rcond = 1.;
14026 return 0;
14027 } else if (*anorm == 0.) {
14028 return 0;
14029 }
14030
14031 smlnum = dlamch_("Safe minimum");
14032
14033 /* Estimate the 1-norm of inv(A). */
14034
14035 kase = 0;
14036 *(unsigned char *)normin = 'N';
14037 L10:
14038 dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
14039 if (kase != 0) {
14040 if (upper) {
14041
14042 /* Multiply by inv(U'). */
14043
14044 dlatrs_("Upper", "Transpose", "Non-unit", normin, n, &a[a_offset],
14045 lda, &work[1], &scalel, &work[(*n << 1) + 1], info);
14046 *(unsigned char *)normin = 'Y';
14047
14048 /* Multiply by inv(U). */
14049
14050 dlatrs_("Upper", "No transpose", "Non-unit", normin, n, &a[
14051 a_offset], lda, &work[1], &scaleu, &work[(*n << 1) + 1],
14052 info);
14053 } else {
14054
14055 /* Multiply by inv(L). */
14056
14057 dlatrs_("Lower", "No transpose", "Non-unit", normin, n, &a[
14058 a_offset], lda, &work[1], &scalel, &work[(*n << 1) + 1],
14059 info);
14060 *(unsigned char *)normin = 'Y';
14061
14062 /* Multiply by inv(L'). */
14063
14064 dlatrs_("Lower", "Transpose", "Non-unit", normin, n, &a[a_offset],
14065 lda, &work[1], &scaleu, &work[(*n << 1) + 1], info);
14066 }
14067
14068 /* Multiply by 1/SCALE if doing so will not cause overflow. */
14069
14070 scale = scalel * scaleu;
14071 if (scale != 1.) {
14072 ix = idamax_(n, &work[1], &c__1);
14073 if (scale < (d__1 = work[ix], abs(d__1)) * smlnum || scale == 0.)
14074 {
14075 goto L20;
14076 }
14077 drscl_(n, &scale, &work[1], &c__1);
14078 }
14079 goto L10;
14080 }
14081
14082 /* Compute the estimate of the reciprocal condition number. */
14083
14084 if (ainvnm != 0.) {
14085 *rcond = 1. / ainvnm / *anorm;
14086 }
14087
14088 L20:
14089 return 0;
14090
14091 /* End of DPOCON */
14092
14093 } /* dpocon_ */
14094
14095 /* Subroutine */ int dpoequ_(integer *n, double *a, integer *lda,
14096 double *s, double *scond, double *amax, integer *info)
14097 {
14098 /* System generated locals */
14099 integer a_dim1, a_offset, i__1;
14100 double d__1, d__2;
14101
14102 /* Local variables */
14103 integer i__;
14104 double smin;
14105
14106
14107
14108 /* -- LAPACK routine (version 3.1) -- */
14109 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
14110 /* November 2006 */
14111
14112 /* .. Scalar Arguments .. */
14113 /* .. */
14114 /* .. Array Arguments .. */
14115 /* .. */
14116
14117 /* Purpose */
14118 /* ======= */
14119
14120 /* DPOEQU computes row and column scalings intended to equilibrate a */
14121 /* symmetric positive definite matrix A and reduce its condition number */
14122 /* (with respect to the two-norm). S contains the scale factors, */
14123 /* S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with */
14124 /* elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This */
14125 /* choice of S puts the condition number of B within a factor N of the */
14126 /* smallest possible condition number over all possible diagonal */
14127 /* scalings. */
14128
14129 /* Arguments */
14130 /* ========= */
14131
14132 /* N (input) INTEGER */
14133 /* The order of the matrix A. N >= 0. */
14134
14135 /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
14136 /* The N-by-N symmetric positive definite matrix whose scaling */
14137 /* factors are to be computed. Only the diagonal elements of A */
14138 /* are referenced. */
14139
14140 /* LDA (input) INTEGER */
14141 /* The leading dimension of the array A. LDA >= max(1,N). */
14142
14143 /* S (output) DOUBLE PRECISION array, dimension (N) */
14144 /* If INFO = 0, S contains the scale factors for A. */
14145
14146 /* SCOND (output) DOUBLE PRECISION */
14147 /* If INFO = 0, S contains the ratio of the smallest S(i) to */
14148 /* the largest S(i). If SCOND >= 0.1 and AMAX is neither too */
14149 /* large nor too small, it is not worth scaling by S. */
14150
14151 /* AMAX (output) DOUBLE PRECISION */
14152 /* Absolute value of largest matrix element. If AMAX is very */
14153 /* close to overflow or very close to underflow, the matrix */
14154 /* should be scaled. */
14155
14156 /* INFO (output) INTEGER */
14157 /* = 0: successful exit */
14158 /* < 0: if INFO = -i, the i-th argument had an illegal value */
14159 /* > 0: if INFO = i, the i-th diagonal element is nonpositive. */
14160
14161 /* ===================================================================== */
14162
14163 /* .. Parameters .. */
14164 /* .. */
14165 /* .. Local Scalars .. */
14166 /* .. */
14167 /* .. External Subroutines .. */
14168 /* .. */
14169 /* .. Intrinsic Functions .. */
14170 /* .. */
14171 /* .. Executable Statements .. */
14172
14173 /* Test the input parameters. */
14174
14175 /* Parameter adjustments */
14176 a_dim1 = *lda;
14177 a_offset = 1 + a_dim1;
14178 a -= a_offset;
14179 --s;
14180
14181 /* Function Body */
14182 *info = 0;
14183 if (*n < 0) {
14184 *info = -1;
14185 } else if (*lda < std::max(1_integer,*n)) {
14186 *info = -3;
14187 }
14188 if (*info != 0) {
14189 i__1 = -(*info);
14190 xerbla_("DPOEQU", &i__1);
14191 return 0;
14192 }
14193
14194 /* Quick return if possible */
14195
14196 if (*n == 0) {
14197 *scond = 1.;
14198 *amax = 0.;
14199 return 0;
14200 }
14201
14202 /* Find the minimum and maximum diagonal elements. */
14203
14204 s[1] = a[a_dim1 + 1];
14205 smin = s[1];
14206 *amax = s[1];
14207 i__1 = *n;
14208 for (i__ = 2; i__ <= i__1; ++i__) {
14209 s[i__] = a[i__ + i__ * a_dim1];
14210 /* Computing MIN */
14211 d__1 = smin, d__2 = s[i__];
14212 smin = std::min(d__1,d__2);
14213 /* Computing MAX */
14214 d__1 = *amax, d__2 = s[i__];
14215 *amax = std::max(d__1,d__2);
14216 /* L10: */
14217 }
14218
14219 if (smin <= 0.) {
14220
14221 /* Find the first non-positive diagonal element and return. */
14222
14223 i__1 = *n;
14224 for (i__ = 1; i__ <= i__1; ++i__) {
14225 if (s[i__] <= 0.) {
14226 *info = i__;
14227 return 0;
14228 }
14229 /* L20: */
14230 }
14231 } else {
14232
14233 /* Set the scale factors to the reciprocals */
14234 /* of the diagonal elements. */
14235
14236 i__1 = *n;
14237 for (i__ = 1; i__ <= i__1; ++i__) {
14238 s[i__] = 1. / sqrt(s[i__]);
14239 /* L30: */
14240 }
14241
14242 /* Compute SCOND = min(S(I)) / max(S(I)) */
14243
14244 *scond = sqrt(smin) / sqrt(*amax);
14245 }
14246 return 0;
14247
14248 /* End of DPOEQU */
14249
14250 } /* dpoequ_ */
14251
14252 int dpoequb_(integer *n, double *a, integer *lda, double *s, double *scond, double *amax, integer *info)
14253 {
14254 /* System generated locals */
14255 integer a_dim1, a_offset, i__1, i__2;
14256 double d__1, d__2;
14257
14258 /* Local variables */
14259 integer i__;
14260 double tmp, base, smin;
14261
14262 /* -- LAPACK routine (version 3.2) -- */
14263 /* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */
14264 /* -- Jason Riedy of Univ. of California Berkeley. -- */
14265 /* -- November 2008 -- */
14266
14267 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
14268 /* -- Univ. of California Berkeley and NAG Ltd. -- */
14269
14270 /* .. */
14271 /* .. Scalar Arguments .. */
14272 /* .. */
14273 /* .. Array Arguments .. */
14274 /* .. */
14275
14276 /* Purpose */
14277 /* ======= */
14278
14279 /* DPOEQU computes row and column scalings intended to equilibrate a */
14280 /* symmetric positive definite matrix A and reduce its condition number */
14281 /* (with respect to the two-norm). S contains the scale factors, */
14282 /* S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with */
14283 /* elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal. This */
14284 /* choice of S puts the condition number of B within a factor N of the */
14285 /* smallest possible condition number over all possible diagonal */
14286 /* scalings. */
14287
14288 /* Arguments */
14289 /* ========= */
14290
14291 /* N (input) INTEGER */
14292 /* The order of the matrix A. N >= 0. */
14293
14294 /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
14295 /* The N-by-N symmetric positive definite matrix whose scaling */
14296 /* factors are to be computed. Only the diagonal elements of A */
14297 /* are referenced. */
14298
14299 /* LDA (input) INTEGER */
14300 /* The leading dimension of the array A. LDA >= max(1,N). */
14301
14302 /* S (output) DOUBLE PRECISION array, dimension (N) */
14303 /* If INFO = 0, S contains the scale factors for A. */
14304
14305 /* SCOND (output) DOUBLE PRECISION */
14306 /* If INFO = 0, S contains the ratio of the smallest S(i) to */
14307 /* the largest S(i). If SCOND >= 0.1 and AMAX is neither too */
14308 /* large nor too small, it is not worth scaling by S. */
14309
14310 /* AMAX (output) DOUBLE PRECISION */
14311 /* Absolute value of largest matrix element. If AMAX is very */
14312 /* close to overflow or very close to underflow, the matrix */
14313 /* should be scaled. */
14314
14315 /* INFO (output) INTEGER */
14316 /* = 0: successful exit */
14317 /* < 0: if INFO = -i, the i-th argument had an illegal value */
14318 /* > 0: if INFO = i, the i-th diagonal element is nonpositive. */
14319
14320 /* ===================================================================== */
14321
14322 /* .. Parameters .. */
14323 /* .. */
14324 /* .. Local Scalars .. */
14325 /* .. */
14326 /* .. External Functions .. */
14327 /* .. */
14328 /* .. External Subroutines .. */
14329 /* .. */
14330 /* .. Intrinsic Functions .. */
14331 /* .. */
14332 /* .. Executable Statements .. */
14333
14334 /* Test the input parameters. */
14335
14336 /* Positive definite only performs 1 pass of equilibration. */
14337
14338 /* Parameter adjustments */
14339 a_dim1 = *lda;
14340 a_offset = 1 + a_dim1;
14341 a -= a_offset;
14342 --s;
14343
14344 /* Function Body */
14345 *info = 0;
14346 if (*n < 0) {
14347 *info = -1;
14348 } else if (*lda < std::max(1_integer,*n)) {
14349 *info = -3;
14350 }
14351 if (*info != 0) {
14352 i__1 = -(*info);
14353 xerbla_("DPOEQUB", &i__1);
14354 return 0;
14355 }
14356
14357 /* Quick return if possible. */
14358
14359 if (*n == 0) {
14360 *scond = 1.;
14361 *amax = 0.;
14362 return 0;
14363 }
14364 base = dlamch_("B");
14365 tmp = -.5 / log(base);
14366
14367 /* Find the minimum and maximum diagonal elements. */
14368
14369 s[1] = a[a_dim1 + 1];
14370 smin = s[1];
14371 *amax = s[1];
14372 i__1 = *n;
14373 for (i__ = 2; i__ <= i__1; ++i__) {
14374 s[i__] = a[i__ + i__ * a_dim1];
14375 /* Computing MIN */
14376 d__1 = smin, d__2 = s[i__];
14377 smin = std::min(d__1,d__2);
14378 /* Computing MAX */
14379 d__1 = *amax, d__2 = s[i__];
14380 *amax = std::max(d__1,d__2);
14381 /* L10: */
14382 }
14383
14384 if (smin <= 0.) {
14385
14386 /* Find the first non-positive diagonal element and return. */
14387
14388 i__1 = *n;
14389 for (i__ = 1; i__ <= i__1; ++i__) {
14390 if (s[i__] <= 0.) {
14391 *info = i__;
14392 return 0;
14393 }
14394 /* L20: */
14395 }
14396 } else {
14397
14398 /* Set the scale factors to the reciprocals */
14399 /* of the diagonal elements. */
14400
14401 i__1 = *n;
14402 for (i__ = 1; i__ <= i__1; ++i__) {
14403 i__2 = (integer) (tmp * log(s[i__]));
14404 s[i__] = pow_di(&base, &i__2);
14405 /* L30: */
14406 }
14407
14408 /* Compute SCOND = min(S(I)) / max(S(I)). */
14409
14410 *scond = sqrt(smin) / sqrt(*amax);
14411 }
14412
14413 return 0;
14414
14415 /* End of DPOEQUB */
14416
14417 } /* dpoequb_ */
14418
14419 /* Subroutine */ int dporfs_(const char *uplo, integer *n, integer *nrhs,
14420 double *a, integer *lda, double *af, integer *ldaf,
14421 double *b, integer *ldb, double *x, integer *ldx, double *
14422 ferr, double *berr, double *work, integer *iwork, integer *
14423 info)
14424 {
14425 /* Table of constant values */
14426 static integer c__1 = 1;
14427 static double c_b12 = -1.;
14428 static double c_b14 = 1.;
14429
14430 /* System generated locals */
14431 integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1,
14432 x_offset, i__1, i__2, i__3;
14433 double d__1, d__2, d__3;
14434
14435 /* Local variables */
14436 integer i__, j, k;
14437 double s, xk;
14438 integer nz;
14439 double eps;
14440 integer kase;
14441 double safe1, safe2;
14442 integer isave[3];
14443 integer count;
14444 bool upper;
14445 double safmin;
14446 double lstres;
14447
14448
14449 /* -- LAPACK routine (version 3.1) -- */
14450 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
14451 /* November 2006 */
14452
14453 /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
14454
14455 /* .. Scalar Arguments .. */
14456 /* .. */
14457 /* .. Array Arguments .. */
14458 /* .. */
14459
14460 /* Purpose */
14461 /* ======= */
14462
14463 /* DPORFS improves the computed solution to a system of linear */
14464 /* equations when the coefficient matrix is symmetric positive definite, */
14465 /* and provides error bounds and backward error estimates for the */
14466 /* solution. */
14467
14468 /* Arguments */
14469 /* ========= */
14470
14471 /* UPLO (input) CHARACTER*1 */
14472 /* = 'U': Upper triangle of A is stored; */
14473 /* = 'L': Lower triangle of A is stored. */
14474
14475 /* N (input) INTEGER */
14476 /* The order of the matrix A. N >= 0. */
14477
14478 /* NRHS (input) INTEGER */
14479 /* The number of right hand sides, i.e., the number of columns */
14480 /* of the matrices B and X. NRHS >= 0. */
14481
14482 /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
14483 /* The symmetric matrix A. If UPLO = 'U', the leading N-by-N */
14484 /* upper triangular part of A contains the upper triangular part */
14485 /* of the matrix A, and the strictly lower triangular part of A */
14486 /* is not referenced. If UPLO = 'L', the leading N-by-N lower */
14487 /* triangular part of A contains the lower triangular part of */
14488 /* the matrix A, and the strictly upper triangular part of A is */
14489 /* not referenced. */
14490
14491 /* LDA (input) INTEGER */
14492 /* The leading dimension of the array A. LDA >= max(1,N). */
14493
14494 /* AF (input) DOUBLE PRECISION array, dimension (LDAF,N) */
14495 /* The triangular factor U or L from the Cholesky factorization */
14496 /* A = U**T*U or A = L*L**T, as computed by DPOTRF. */
14497
14498 /* LDAF (input) INTEGER */
14499 /* The leading dimension of the array AF. LDAF >= max(1,N). */
14500
14501 /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
14502 /* The right hand side matrix B. */
14503
14504 /* LDB (input) INTEGER */
14505 /* The leading dimension of the array B. LDB >= max(1,N). */
14506
14507 /* X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
14508 /* On entry, the solution matrix X, as computed by DPOTRS. */
14509 /* On exit, the improved solution matrix X. */
14510
14511 /* LDX (input) INTEGER */
14512 /* The leading dimension of the array X. LDX >= max(1,N). */
14513
14514 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
14515 /* The estimated forward error bound for each solution vector */
14516 /* X(j) (the j-th column of the solution matrix X). */
14517 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
14518 /* is an estimated upper bound for the magnitude of the largest */
14519 /* element in (X(j) - XTRUE) divided by the magnitude of the */
14520 /* largest element in X(j). The estimate is as reliable as */
14521 /* the estimate for RCOND, and is almost always a slight */
14522 /* overestimate of the true error. */
14523
14524 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
14525 /* The componentwise relative backward error of each solution */
14526 /* vector X(j) (i.e., the smallest relative change in */
14527 /* any element of A or B that makes X(j) an exact solution). */
14528
14529 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
14530
14531 /* IWORK (workspace) INTEGER array, dimension (N) */
14532
14533 /* INFO (output) INTEGER */
14534 /* = 0: successful exit */
14535 /* < 0: if INFO = -i, the i-th argument had an illegal value */
14536
14537 /* Internal Parameters */
14538 /* =================== */
14539
14540 /* ITMAX is the maximum number of steps of iterative refinement. */
14541
14542 /* ===================================================================== */
14543
14544 /* .. Parameters .. */
14545 /* .. */
14546 /* .. Local Scalars .. */
14547 /* .. */
14548 /* .. Local Arrays .. */
14549 /* .. */
14550 /* .. External Subroutines .. */
14551 /* .. */
14552 /* .. Intrinsic Functions .. */
14553 /* .. */
14554 /* .. External Functions .. */
14555 /* .. */
14556 /* .. Executable Statements .. */
14557
14558 /* Test the input parameters. */
14559
14560 /* Parameter adjustments */
14561 a_dim1 = *lda;
14562 a_offset = 1 + a_dim1;
14563 a -= a_offset;
14564 af_dim1 = *ldaf;
14565 af_offset = 1 + af_dim1;
14566 af -= af_offset;
14567 b_dim1 = *ldb;
14568 b_offset = 1 + b_dim1;
14569 b -= b_offset;
14570 x_dim1 = *ldx;
14571 x_offset = 1 + x_dim1;
14572 x -= x_offset;
14573 --ferr;
14574 --berr;
14575 --work;
14576 --iwork;
14577
14578 /* Function Body */
14579 *info = 0;
14580 upper = lsame_(uplo, "U");
14581 if (! upper && ! lsame_(uplo, "L")) {
14582 *info = -1;
14583 } else if (*n < 0) {
14584 *info = -2;
14585 } else if (*nrhs < 0) {
14586 *info = -3;
14587 } else if (*lda < std::max(1_integer,*n)) {
14588 *info = -5;
14589 } else if (*ldaf < std::max(1_integer,*n)) {
14590 *info = -7;
14591 } else if (*ldb < std::max(1_integer,*n)) {
14592 *info = -9;
14593 } else if (*ldx < std::max(1_integer,*n)) {
14594 *info = -11;
14595 }
14596 if (*info != 0) {
14597 i__1 = -(*info);
14598 xerbla_("DPORFS", &i__1);
14599 return 0;
14600 }
14601
14602 /* Quick return if possible */
14603
14604 if (*n == 0 || *nrhs == 0) {
14605 i__1 = *nrhs;
14606 for (j = 1; j <= i__1; ++j) {
14607 ferr[j] = 0.;
14608 berr[j] = 0.;
14609 /* L10: */
14610 }
14611 return 0;
14612 }
14613
14614 /* NZ = maximum number of nonzero elements in each row of A, plus 1 */
14615
14616 nz = *n + 1;
14617 eps = dlamch_("Epsilon");
14618 safmin = dlamch_("Safe minimum");
14619 safe1 = nz * safmin;
14620 safe2 = safe1 / eps;
14621
14622 /* Do for each right hand side */
14623
14624 i__1 = *nrhs;
14625 for (j = 1; j <= i__1; ++j) {
14626
14627 count = 1;
14628 lstres = 3.;
14629 L20:
14630
14631 /* Loop until stopping criterion is satisfied. */
14632
14633 /* Compute residual R = B - A * X */
14634
14635 dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
14636 dsymv_(uplo, n, &c_b12, &a[a_offset], lda, &x[j * x_dim1 + 1], &c__1,
14637 &c_b14, &work[*n + 1], &c__1);
14638
14639 /* Compute componentwise relative backward error from formula */
14640
14641 /* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
14642
14643 /* where abs(Z) is the componentwise absolute value of the matrix */
14644 /* or vector Z. If the i-th component of the denominator is less */
14645 /* than SAFE2, then SAFE1 is added to the i-th components of the */
14646 /* numerator and denominator before dividing. */
14647
14648 i__2 = *n;
14649 for (i__ = 1; i__ <= i__2; ++i__) {
14650 work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
14651 /* L30: */
14652 }
14653
14654 /* Compute abs(A)*abs(X) + abs(B). */
14655
14656 if (upper) {
14657 i__2 = *n;
14658 for (k = 1; k <= i__2; ++k) {
14659 s = 0.;
14660 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
14661 i__3 = k - 1;
14662 for (i__ = 1; i__ <= i__3; ++i__) {
14663 work[i__] += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * xk;
14664 s += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * (d__2 = x[
14665 i__ + j * x_dim1], abs(d__2));
14666 /* L40: */
14667 }
14668 work[k] = work[k] + (d__1 = a[k + k * a_dim1], abs(d__1)) *
14669 xk + s;
14670 /* L50: */
14671 }
14672 } else {
14673 i__2 = *n;
14674 for (k = 1; k <= i__2; ++k) {
14675 s = 0.;
14676 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
14677 work[k] += (d__1 = a[k + k * a_dim1], abs(d__1)) * xk;
14678 i__3 = *n;
14679 for (i__ = k + 1; i__ <= i__3; ++i__) {
14680 work[i__] += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * xk;
14681 s += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * (d__2 = x[
14682 i__ + j * x_dim1], abs(d__2));
14683 /* L60: */
14684 }
14685 work[k] += s;
14686 /* L70: */
14687 }
14688 }
14689 s = 0.;
14690 i__2 = *n;
14691 for (i__ = 1; i__ <= i__2; ++i__) {
14692 if (work[i__] > safe2) {
14693 /* Computing MAX */
14694 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
14695 i__];
14696 s = std::max(d__2,d__3);
14697 } else {
14698 /* Computing MAX */
14699 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1)
14700 / (work[i__] + safe1);
14701 s = std::max(d__2,d__3);
14702 }
14703 /* L80: */
14704 }
14705 berr[j] = s;
14706
14707 /* Test stopping criterion. Continue iterating if */
14708 /* 1) The residual BERR(J) is larger than machine epsilon, and */
14709 /* 2) BERR(J) decreased by at least a factor of 2 during the */
14710 /* last iteration, and */
14711 /* 3) At most ITMAX iterations tried. */
14712
14713 if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
14714
14715 /* Update solution and try again. */
14716
14717 dpotrs_(uplo, n, &c__1, &af[af_offset], ldaf, &work[*n + 1], n,
14718 info);
14719 daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
14720 ;
14721 lstres = berr[j];
14722 ++count;
14723 goto L20;
14724 }
14725
14726 /* Bound error from formula */
14727
14728 /* norm(X - XTRUE) / norm(X) .le. FERR = */
14729 /* norm( abs(inv(A))* */
14730 /* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
14731
14732 /* where */
14733 /* norm(Z) is the magnitude of the largest component of Z */
14734 /* inv(A) is the inverse of A */
14735 /* abs(Z) is the componentwise absolute value of the matrix or */
14736 /* vector Z */
14737 /* NZ is the maximum number of nonzeros in any row of A, plus 1 */
14738 /* EPS is machine epsilon */
14739
14740 /* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
14741 /* is incremented by SAFE1 if the i-th component of */
14742 /* abs(A)*abs(X) + abs(B) is less than SAFE2. */
14743
14744 /* Use DLACN2 to estimate the infinity-norm of the matrix */
14745 /* inv(A) * diag(W), */
14746 /* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
14747
14748 i__2 = *n;
14749 for (i__ = 1; i__ <= i__2; ++i__) {
14750 if (work[i__] > safe2) {
14751 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
14752 work[i__];
14753 } else {
14754 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
14755 work[i__] + safe1;
14756 }
14757 /* L90: */
14758 }
14759
14760 kase = 0;
14761 L100:
14762 dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
14763 kase, isave);
14764 if (kase != 0) {
14765 if (kase == 1) {
14766
14767 /* Multiply by diag(W)*inv(A'). */
14768
14769 dpotrs_(uplo, n, &c__1, &af[af_offset], ldaf, &work[*n + 1],
14770 n, info);
14771 i__2 = *n;
14772 for (i__ = 1; i__ <= i__2; ++i__) {
14773 work[*n + i__] = work[i__] * work[*n + i__];
14774 /* L110: */
14775 }
14776 } else if (kase == 2) {
14777
14778 /* Multiply by inv(A)*diag(W). */
14779
14780 i__2 = *n;
14781 for (i__ = 1; i__ <= i__2; ++i__) {
14782 work[*n + i__] = work[i__] * work[*n + i__];
14783 /* L120: */
14784 }
14785 dpotrs_(uplo, n, &c__1, &af[af_offset], ldaf, &work[*n + 1],
14786 n, info);
14787 }
14788 goto L100;
14789 }
14790
14791 /* Normalize error. */
14792
14793 lstres = 0.;
14794 i__2 = *n;
14795 for (i__ = 1; i__ <= i__2; ++i__) {
14796 /* Computing MAX */
14797 d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
14798 lstres = std::max(d__2,d__3);
14799 /* L130: */
14800 }
14801 if (lstres != 0.) {
14802 ferr[j] /= lstres;
14803 }
14804
14805 /* L140: */
14806 }
14807
14808 return 0;
14809
14810 /* End of DPORFS */
14811
14812 } /* dporfs_ */
14813
14814 #if 0
14815 int dporfsx_(const char *uplo, const char *equed, integer *n, integer *nrhs, double *a, integer *lda,
14816 double *af, integer *ldaf, double *s, double *b, integer *ldb, double *x, integer *
14817 ldx, double *rcond, double *berr, integer *n_err_bnds__, double *err_bnds_norm__, double *err_bnds_comp__,
14818 integer *nparams, double *params, double *work, integer *iwork, integer *info)
14819 {
14820 /* Table of constant values */
14821 static integer c_n1 = -1;
14822 static integer c__0 = 0;
14823 static integer c__1 = 1;
14824
14825 /* System generated locals */
14826 integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1,
14827 x_offset, err_bnds_norm_dim1, err_bnds_norm_offset,
14828 err_bnds_comp_dim1, err_bnds_comp_offset, i__1;
14829 double d__1, d__2;
14830
14831 /* Builtin functions */
14832 double sqrt(double);
14833
14834 /* Local variables */
14835 double illrcond_thresh__, unstable_thresh__, err_lbnd__;
14836 integer ref_type__, j;
14837 double rcond_tmp__;
14838 integer prec_type__;
14839 double cwise_wrong__;
14840 char norm[1];
14841 bool ignore_cwise__;
14842 double anorm;
14843 bool rcequ;
14844 integer ithresh, n_norms__;
14845 double rthresh;
14846
14847
14848 /* -- LAPACK routine (version 3.2.1) -- */
14849 /* -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */
14850 /* -- Jason Riedy of Univ. of California Berkeley. -- */
14851 /* -- April 2009 -- */
14852
14853 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
14854 /* -- Univ. of California Berkeley and NAG Ltd. -- */
14855
14856 /* .. */
14857 /* .. Scalar Arguments .. */
14858 /* .. */
14859 /* .. Array Arguments .. */
14860 /* .. */
14861
14862 /* Purpose */
14863 /* ======= */
14864
14865 /* DPORFSX improves the computed solution to a system of linear */
14866 /* equations when the coefficient matrix is symmetric positive */
14867 /* definite, and provides error bounds and backward error estimates */
14868 /* for the solution. In addition to normwise error bound, the code */
14869 /* provides maximum componentwise error bound if possible. See */
14870 /* comments for ERR_BNDS_NORM and ERR_BNDS_COMP for details of the */
14871 /* error bounds. */
14872
14873 /* The original system of linear equations may have been equilibrated */
14874 /* before calling this routine, as described by arguments EQUED and S */
14875 /* below. In this case, the solution and error bounds returned are */
14876 /* for the original unequilibrated system. */
14877
14878 /* Arguments */
14879 /* ========= */
14880
14881 /* Some optional parameters are bundled in the PARAMS array. These */
14882 /* settings determine how refinement is performed, but often the */
14883 /* defaults are acceptable. If the defaults are acceptable, users */
14884 /* can pass NPARAMS = 0 which prevents the source code from accessing */
14885 /* the PARAMS argument. */
14886
14887 /* UPLO (input) CHARACTER*1 */
14888 /* = 'U': Upper triangle of A is stored; */
14889 /* = 'L': Lower triangle of A is stored. */
14890
14891 /* EQUED (input) CHARACTER*1 */
14892 /* Specifies the form of equilibration that was done to A */
14893 /* before calling this routine. This is needed to compute */
14894 /* the solution and error bounds correctly. */
14895 /* = 'N': No equilibration */
14896 /* = 'Y': Both row and column equilibration, i.e., A has been */
14897 /* replaced by diag(S) * A * diag(S). */
14898 /* The right hand side B has been changed accordingly. */
14899
14900 /* N (input) INTEGER */
14901 /* The order of the matrix A. N >= 0. */
14902
14903 /* NRHS (input) INTEGER */
14904 /* The number of right hand sides, i.e., the number of columns */
14905 /* of the matrices B and X. NRHS >= 0. */
14906
14907 /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
14908 /* The symmetric matrix A. If UPLO = 'U', the leading N-by-N */
14909 /* upper triangular part of A contains the upper triangular part */
14910 /* of the matrix A, and the strictly lower triangular part of A */
14911 /* is not referenced. If UPLO = 'L', the leading N-by-N lower */
14912 /* triangular part of A contains the lower triangular part of */
14913 /* the matrix A, and the strictly upper triangular part of A is */
14914 /* not referenced. */
14915
14916 /* LDA (input) INTEGER */
14917 /* The leading dimension of the array A. LDA >= max(1,N). */
14918
14919 /* AF (input) DOUBLE PRECISION array, dimension (LDAF,N) */
14920 /* The triangular factor U or L from the Cholesky factorization */
14921 /* A = U**T*U or A = L*L**T, as computed by DPOTRF. */
14922
14923 /* LDAF (input) INTEGER */
14924 /* The leading dimension of the array AF. LDAF >= max(1,N). */
14925
14926 /* S (input or output) DOUBLE PRECISION array, dimension (N) */
14927 /* The row scale factors for A. If EQUED = 'Y', A is multiplied on */
14928 /* the left and right by diag(S). S is an input argument if FACT = */
14929 /* 'F'; otherwise, S is an output argument. If FACT = 'F' and EQUED */
14930 /* = 'Y', each element of S must be positive. If S is output, each */
14931 /* element of S is a power of the radix. If S is input, each element */
14932 /* of S should be a power of the radix to ensure a reliable solution */
14933 /* and error estimates. Scaling by powers of the radix does not cause */
14934 /* rounding errors unless the result underflows or overflows. */
14935 /* Rounding errors during scaling lead to refining with a matrix that */
14936 /* is not equivalent to the input matrix, producing error estimates */
14937 /* that may not be reliable. */
14938
14939 /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
14940 /* The right hand side matrix B. */
14941
14942 /* LDB (input) INTEGER */
14943 /* The leading dimension of the array B. LDB >= max(1,N). */
14944
14945 /* X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
14946 /* On entry, the solution matrix X, as computed by DGETRS. */
14947 /* On exit, the improved solution matrix X. */
14948
14949 /* LDX (input) INTEGER */
14950 /* The leading dimension of the array X. LDX >= max(1,N). */
14951
14952 /* RCOND (output) DOUBLE PRECISION */
14953 /* Reciprocal scaled condition number. This is an estimate of the */
14954 /* reciprocal Skeel condition number of the matrix A after */
14955 /* equilibration (if done). If this is less than the machine */
14956 /* precision (in particular, if it is zero), the matrix is singular */
14957 /* to working precision. Note that the error may still be small even */
14958 /* if this number is very small and the matrix appears ill- */
14959 /* conditioned. */
14960
14961 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
14962 /* Componentwise relative backward error. This is the */
14963 /* componentwise relative backward error of each solution vector X(j) */
14964 /* (i.e., the smallest relative change in any element of A or B that */
14965 /* makes X(j) an exact solution). */
14966
14967 /* N_ERR_BNDS (input) INTEGER */
14968 /* Number of error bounds to return for each right hand side */
14969 /* and each type (normwise or componentwise). See ERR_BNDS_NORM and */
14970 /* ERR_BNDS_COMP below. */
14971
14972 /* ERR_BNDS_NORM (output) DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) */
14973 /* For each right-hand side, this array contains information about */
14974 /* various error bounds and condition numbers corresponding to the */
14975 /* normwise relative error, which is defined as follows: */
14976
14977 /* Normwise relative error in the ith solution vector: */
14978 /* max_j (abs(XTRUE(j,i) - X(j,i))) */
14979 /* ------------------------------ */
14980 /* max_j abs(X(j,i)) */
14981
14982 /* The array is indexed by the type of error information as described */
14983 /* below. There currently are up to three pieces of information */
14984 /* returned. */
14985
14986 /* The first index in ERR_BNDS_NORM(i,:) corresponds to the ith */
14987 /* right-hand side. */
14988
14989 /* The second index in ERR_BNDS_NORM(:,err) contains the following */
14990 /* three fields: */
14991 /* err = 1 "Trust/don't trust" boolean. Trust the answer if the */
14992 /* reciprocal condition number is less than the threshold */
14993 /* sqrt(n) * dlamch('Epsilon'). */
14994
14995 /* err = 2 "Guaranteed" error bound: The estimated forward error, */
14996 /* almost certainly within a factor of 10 of the true error */
14997 /* so long as the next entry is greater than the threshold */
14998 /* sqrt(n) * dlamch('Epsilon'). This error bound should only */
14999 /* be trusted if the previous boolean is true. */
15000
15001 /* err = 3 Reciprocal condition number: Estimated normwise */
15002 /* reciprocal condition number. Compared with the threshold */
15003 /* sqrt(n) * dlamch('Epsilon') to determine if the error */
15004 /* estimate is "guaranteed". These reciprocal condition */
15005 /* numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */
15006 /* appropriately scaled matrix Z. */
15007 /* Let Z = S*A, where S scales each row by a power of the */
15008 /* radix so all absolute row sums of Z are approximately 1. */
15009
15010 /* See Lapack Working Note 165 for further details and extra */
15011 /* cautions. */
15012
15013 /* ERR_BNDS_COMP (output) DOUBLE PRECISION array, dimension (NRHS, N_ERR_BNDS) */
15014 /* For each right-hand side, this array contains information about */
15015 /* various error bounds and condition numbers corresponding to the */
15016 /* componentwise relative error, which is defined as follows: */
15017
15018 /* Componentwise relative error in the ith solution vector: */
15019 /* abs(XTRUE(j,i) - X(j,i)) */
15020 /* max_j ---------------------- */
15021 /* abs(X(j,i)) */
15022
15023 /* The array is indexed by the right-hand side i (on which the */
15024 /* componentwise relative error depends), and the type of error */
15025 /* information as described below. There currently are up to three */
15026 /* pieces of information returned for each right-hand side. If */
15027 /* componentwise accuracy is not requested (PARAMS(3) = 0.0), then */
15028 /* ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most */
15029 /* the first (:,N_ERR_BNDS) entries are returned. */
15030
15031 /* The first index in ERR_BNDS_COMP(i,:) corresponds to the ith */
15032 /* right-hand side. */
15033
15034 /* The second index in ERR_BNDS_COMP(:,err) contains the following */
15035 /* three fields: */
15036 /* err = 1 "Trust/don't trust" boolean. Trust the answer if the */
15037 /* reciprocal condition number is less than the threshold */
15038 /* sqrt(n) * dlamch('Epsilon'). */
15039
15040 /* err = 2 "Guaranteed" error bound: The estimated forward error, */
15041 /* almost certainly within a factor of 10 of the true error */
15042 /* so long as the next entry is greater than the threshold */
15043 /* sqrt(n) * dlamch('Epsilon'). This error bound should only */
15044 /* be trusted if the previous boolean is true. */
15045
15046 /* err = 3 Reciprocal condition number: Estimated componentwise */
15047 /* reciprocal condition number. Compared with the threshold */
15048 /* sqrt(n) * dlamch('Epsilon') to determine if the error */
15049 /* estimate is "guaranteed". These reciprocal condition */
15050 /* numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some */
15051 /* appropriately scaled matrix Z. */
15052 /* Let Z = S*(A*diag(x)), where x is the solution for the */
15053 /* current right-hand side and S scales each row of */
15054 /* A*diag(x) by a power of the radix so all absolute row */
15055 /* sums of Z are approximately 1. */
15056
15057 /* See Lapack Working Note 165 for further details and extra */
15058 /* cautions. */
15059
15060 /* NPARAMS (input) INTEGER */
15061 /* Specifies the number of parameters set in PARAMS. If .LE. 0, the */
15062 /* PARAMS array is never referenced and default values are used. */
15063
15064 /* PARAMS (input / output) DOUBLE PRECISION array, dimension NPARAMS */
15065 /* Specifies algorithm parameters. If an entry is .LT. 0.0, then */
15066 /* that entry will be filled with default value used for that */
15067 /* parameter. Only positions up to NPARAMS are accessed; defaults */
15068 /* are used for higher-numbered parameters. */
15069
15070 /* PARAMS(LA_LINRX_ITREF_I = 1) : Whether to perform iterative */
15071 /* refinement or not. */
15072 /* Default: 1.0D+0 */
15073 /* = 0.0 : No refinement is performed, and no error bounds are */
15074 /* computed. */
15075 /* = 1.0 : Use the double-precision refinement algorithm, */
15076 /* possibly with doubled-single computations if the */
15077 /* compilation environment does not support DOUBLE */
15078 /* PRECISION. */
15079 /* (other values are reserved for future use) */
15080
15081 /* PARAMS(LA_LINRX_ITHRESH_I = 2) : Maximum number of residual */
15082 /* computations allowed for refinement. */
15083 /* Default: 10 */
15084 /* Aggressive: Set to 100 to permit convergence using approximate */
15085 /* factorizations or factorizations other than LU. If */
15086 /* the factorization uses a technique other than */
15087 /* Gaussian elimination, the guarantees in */
15088 /* err_bnds_norm and err_bnds_comp may no longer be */
15089 /* trustworthy. */
15090
15091 /* PARAMS(LA_LINRX_CWISE_I = 3) : Flag determining if the code */
15092 /* will attempt to find a solution with small componentwise */
15093 /* relative error in the double-precision algorithm. Positive */
15094 /* is true, 0.0 is false. */
15095 /* Default: 1.0 (attempt componentwise convergence) */
15096
15097 /* WORK (workspace) DOUBLE PRECISION array, dimension (4*N) */
15098
15099 /* IWORK (workspace) INTEGER array, dimension (N) */
15100
15101 /* INFO (output) INTEGER */
15102 /* = 0: Successful exit. The solution to every right-hand side is */
15103 /* guaranteed. */
15104 /* < 0: If INFO = -i, the i-th argument had an illegal value */
15105 /* > 0 and <= N: U(INFO,INFO) is exactly zero. The factorization */
15106 /* has been completed, but the factor U is exactly singular, so */
15107 /* the solution and error bounds could not be computed. RCOND = 0 */
15108 /* is returned. */
15109 /* = N+J: The solution corresponding to the Jth right-hand side is */
15110 /* not guaranteed. The solutions corresponding to other right- */
15111 /* hand sides K with K > J may not be guaranteed as well, but */
15112 /* only the first such right-hand side is reported. If a small */
15113 /* componentwise error is not requested (PARAMS(3) = 0.0) then */
15114 /* the Jth right-hand side is the first with a normwise error */
15115 /* bound that is not guaranteed (the smallest J such */
15116 /* that ERR_BNDS_NORM(J,1) = 0.0). By default (PARAMS(3) = 1.0) */
15117 /* the Jth right-hand side is the first with either a normwise or */
15118 /* componentwise error bound that is not guaranteed (the smallest */
15119 /* J such that either ERR_BNDS_NORM(J,1) = 0.0 or */
15120 /* ERR_BNDS_COMP(J,1) = 0.0). See the definition of */
15121 /* ERR_BNDS_NORM(:,1) and ERR_BNDS_COMP(:,1). To get information */
15122 /* about all of the right-hand sides check ERR_BNDS_NORM or */
15123 /* ERR_BNDS_COMP. */
15124
15125 /* ================================================================== */
15126
15127 /* .. Parameters .. */
15128 /* .. */
15129 /* .. Local Scalars .. */
15130 /* .. */
15131 /* .. External Subroutines .. */
15132 /* .. */
15133 /* .. Intrinsic Functions .. */
15134 /* .. */
15135 /* .. External Functions .. */
15136 /* .. */
15137 /* .. Executable Statements .. */
15138
15139 /* Check the input parameters. */
15140
15141 /* Parameter adjustments */
15142 err_bnds_comp_dim1 = *nrhs;
15143 err_bnds_comp_offset = 1 + err_bnds_comp_dim1;
15144 err_bnds_comp__ -= err_bnds_comp_offset;
15145 err_bnds_norm_dim1 = *nrhs;
15146 err_bnds_norm_offset = 1 + err_bnds_norm_dim1;
15147 err_bnds_norm__ -= err_bnds_norm_offset;
15148 a_dim1 = *lda;
15149 a_offset = 1 + a_dim1;
15150 a -= a_offset;
15151 af_dim1 = *ldaf;
15152 af_offset = 1 + af_dim1;
15153 af -= af_offset;
15154 --s;
15155 b_dim1 = *ldb;
15156 b_offset = 1 + b_dim1;
15157 b -= b_offset;
15158 x_dim1 = *ldx;
15159 x_offset = 1 + x_dim1;
15160 x -= x_offset;
15161 --berr;
15162 --params;
15163 --work;
15164 --iwork;
15165
15166 /* Function Body */
15167 *info = 0;
15168 ref_type__ = 1;
15169 if (*nparams >= 1) {
15170 if (params[1] < 0.) {
15171 params[1] = 1.;
15172 } else {
15173 ref_type__ = (integer) params[1];
15174 }
15175 }
15176
15177 /* Set default parameters. */
15178
15179 illrcond_thresh__ = (double) (*n) * dlamch_("Epsilon");
15180 ithresh = 10;
15181 rthresh = .5;
15182 unstable_thresh__ = .25;
15183 ignore_cwise__ = false;
15184
15185 if (*nparams >= 2) {
15186 if (params[2] < 0.) {
15187 params[2] = (double) ithresh;
15188 } else {
15189 ithresh = (integer) params[2];
15190 }
15191 }
15192 if (*nparams >= 3) {
15193 if (params[3] < 0.) {
15194 if (ignore_cwise__) {
15195 params[3] = 0.;
15196 } else {
15197 params[3] = 1.;
15198 }
15199 } else {
15200 ignore_cwise__ = params[3] == 0.;
15201 }
15202 }
15203 if (ref_type__ == 0 || *n_err_bnds__ == 0) {
15204 n_norms__ = 0;
15205 } else if (ignore_cwise__) {
15206 n_norms__ = 1;
15207 } else {
15208 n_norms__ = 2;
15209 }
15210
15211 rcequ = lsame_(equed, "Y");
15212
15213 /* Test input parameters. */
15214
15215 if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
15216 *info = -1;
15217 } else if (! rcequ && ! lsame_(equed, "N")) {
15218 *info = -2;
15219 } else if (*n < 0) {
15220 *info = -3;
15221 } else if (*nrhs < 0) {
15222 *info = -4;
15223 } else if (*lda < std::max(1_integer,*n)) {
15224 *info = -6;
15225 } else if (*ldaf < std::max(1_integer,*n)) {
15226 *info = -8;
15227 } else if (*ldb < std::max(1_integer,*n)) {
15228 *info = -11;
15229 } else if (*ldx < std::max(1_integer,*n)) {
15230 *info = -13;
15231 }
15232 if (*info != 0) {
15233 i__1 = -(*info);
15234 xerbla_("DPORFSX", &i__1);
15235 return 0;
15236 }
15237
15238 /* Quick return if possible. */
15239
15240 if (*n == 0 || *nrhs == 0) {
15241 *rcond = 1.;
15242 i__1 = *nrhs;
15243 for (j = 1; j <= i__1; ++j) {
15244 berr[j] = 0.;
15245 if (*n_err_bnds__ >= 1) {
15246 err_bnds_norm__[j + err_bnds_norm_dim1] = 1.;
15247 err_bnds_comp__[j + err_bnds_comp_dim1] = 1.;
15248 } else if (*n_err_bnds__ >= 2) {
15249 err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 0.;
15250 err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 0.;
15251 } else if (*n_err_bnds__ >= 3) {
15252 err_bnds_norm__[j + err_bnds_norm_dim1 * 3] = 1.;
15253 err_bnds_comp__[j + err_bnds_comp_dim1 * 3] = 1.;
15254 }
15255 }
15256 return 0;
15257 }
15258
15259 /* Default to failure. */
15260
15261 *rcond = 0.;
15262 i__1 = *nrhs;
15263 for (j = 1; j <= i__1; ++j) {
15264 berr[j] = 1.;
15265 if (*n_err_bnds__ >= 1) {
15266 err_bnds_norm__[j + err_bnds_norm_dim1] = 1.;
15267 err_bnds_comp__[j + err_bnds_comp_dim1] = 1.;
15268 } else if (*n_err_bnds__ >= 2) {
15269 err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 1.;
15270 err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 1.;
15271 } else if (*n_err_bnds__ >= 3) {
15272 err_bnds_norm__[j + err_bnds_norm_dim1 * 3] = 0.;
15273 err_bnds_comp__[j + err_bnds_comp_dim1 * 3] = 0.;
15274 }
15275 }
15276
15277 /* Compute the norm of A and the reciprocal of the condition */
15278 /* number of A. */
15279
15280 *(unsigned char *)norm = 'I';
15281 anorm = dlansy_(norm, uplo, n, &a[a_offset], lda, &work[1]);
15282 dpocon_(uplo, n, &af[af_offset], ldaf, &anorm, rcond, &work[1], &iwork[1],
15283 info);
15284
15285 /* Perform refinement on each right-hand side */
15286
15287 if (ref_type__ != 0) {
15288 prec_type__ = ilaprec_("E");
15289 dla_porfsx_extended__(&prec_type__, uplo, n, nrhs, &a[a_offset], lda,
15290 &af[af_offset], ldaf, &rcequ, &s[1], &b[b_offset], ldb, &x[
15291 x_offset], ldx, &berr[1], &n_norms__, &err_bnds_norm__[
15292 err_bnds_norm_offset], &err_bnds_comp__[err_bnds_comp_offset],
15293 &work[*n + 1], &work[1], &work[(*n << 1) + 1], &work[1],
15294 rcond, &ithresh, &rthresh, &unstable_thresh__, &
15295 ignore_cwise__, info, 1_integer);
15296 }
15297 /* Computing MAX */
15298 d__1 = 10., d__2 = sqrt((double) (*n));
15299 err_lbnd__ = std::max(d__1,d__2) * dlamch_("Epsilon");
15300 if (*n_err_bnds__ >= 1 && n_norms__ >= 1) {
15301
15302 /* Compute scaled normwise condition number cond(A*C). */
15303
15304 if (rcequ) {
15305 rcond_tmp__ = dla_porcond__(uplo, n, &a[a_offset], lda, &af[
15306 af_offset], ldaf, &c_n1, &s[1], info, &work[1], &iwork[1], 1_integer);
15307 } else {
15308 rcond_tmp__ = dla_porcond__(uplo, n, &a[a_offset], lda, &af[
15309 af_offset], ldaf, &c__0, &s[1], info, &work[1], &iwork[1], 1_integer);
15310 }
15311 i__1 = *nrhs;
15312 for (j = 1; j <= i__1; ++j) {
15313
15314 /* Cap the error at 1.0. */
15315
15316 if (*n_err_bnds__ >= 2 && err_bnds_norm__[j + (err_bnds_norm_dim1
15317 << 1)] > 1.) {
15318 err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 1.;
15319 }
15320
15321 /* Threshold the error (see LAWN). */
15322
15323 if (rcond_tmp__ < illrcond_thresh__) {
15324 err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = 1.;
15325 err_bnds_norm__[j + err_bnds_norm_dim1] = 0.;
15326 if (*info <= *n) {
15327 *info = *n + j;
15328 }
15329 } else if (err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] <
15330 err_lbnd__) {
15331 err_bnds_norm__[j + (err_bnds_norm_dim1 << 1)] = err_lbnd__;
15332 err_bnds_norm__[j + err_bnds_norm_dim1] = 1.;
15333 }
15334
15335 /* Save the condition number. */
15336
15337 if (*n_err_bnds__ >= 3) {
15338 err_bnds_norm__[j + err_bnds_norm_dim1 * 3] = rcond_tmp__;
15339 }
15340 }
15341 }
15342 if (*n_err_bnds__ >= 1 && n_norms__ >= 2) {
15343
15344 /* Compute componentwise condition number cond(A*diag(Y(:,J))) for */
15345 /* each right-hand side using the current solution as an estimate of */
15346 /* the true solution. If the componentwise error estimate is too */
15347 /* large, then the solution is a lousy estimate of truth and the */
15348 /* estimated RCOND may be too optimistic. To avoid misleading users, */
15349 /* the inverse condition number is set to 0.0 when the estimated */
15350 /* cwise error is at least CWISE_WRONG. */
15351
15352 cwise_wrong__ = sqrt(dlamch_("Epsilon"));
15353 i__1 = *nrhs;
15354 for (j = 1; j <= i__1; ++j) {
15355 if (err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] <
15356 cwise_wrong__) {
15357 rcond_tmp__ = dla_porcond__(uplo, n, &a[a_offset], lda, &af[
15358 af_offset], ldaf, &c__1, &x[j * x_dim1 + 1], info, &
15359 work[1], &iwork[1], 1_integer);
15360 } else {
15361 rcond_tmp__ = 0.;
15362 }
15363
15364 /* Cap the error at 1.0. */
15365
15366 if (*n_err_bnds__ >= 2 && err_bnds_comp__[j + (err_bnds_comp_dim1
15367 << 1)] > 1.) {
15368 err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 1.;
15369 }
15370
15371 /* Threshold the error (see LAWN). */
15372
15373 if (rcond_tmp__ < illrcond_thresh__) {
15374 err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = 1.;
15375 err_bnds_comp__[j + err_bnds_comp_dim1] = 0.;
15376 if (params[3] == 1. && *info < *n + j) {
15377 *info = *n + j;
15378 }
15379 } else if (err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] <
15380 err_lbnd__) {
15381 err_bnds_comp__[j + (err_bnds_comp_dim1 << 1)] = err_lbnd__;
15382 err_bnds_comp__[j + err_bnds_comp_dim1] = 1.;
15383 }
15384
15385 /* Save the condition number. */
15386
15387 if (*n_err_bnds__ >= 3) {
15388 err_bnds_comp__[j + err_bnds_comp_dim1 * 3] = rcond_tmp__;
15389 }
15390 }
15391 }
15392
15393 return 0;
15394
15395 /* End of DPORFSX */
15396
15397 } /* dporfsx_ */
15398 #endif
15399
15400 /* Subroutine */ int dposv_(const char *uplo, integer *n, integer *nrhs, double
15401 *a, integer *lda, double *b, integer *ldb, integer *info)
15402 {
15403 /* System generated locals */
15404 integer a_dim1, a_offset, b_dim1, b_offset, i__1;
15405
15406 /* -- LAPACK driver routine (version 3.1) -- */
15407 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
15408 /* November 2006 */
15409
15410 /* .. Scalar Arguments .. */
15411 /* .. */
15412 /* .. Array Arguments .. */
15413 /* .. */
15414
15415 /* Purpose */
15416 /* ======= */
15417
15418 /* DPOSV computes the solution to a real system of linear equations */
15419 /* A * X = B, */
15420 /* where A is an N-by-N symmetric positive definite matrix and X and B */
15421 /* are N-by-NRHS matrices. */
15422
15423 /* The Cholesky decomposition is used to factor A as */
15424 /* A = U**T* U, if UPLO = 'U', or */
15425 /* A = L * L**T, if UPLO = 'L', */
15426 /* where U is an upper triangular matrix and L is a lower triangular */
15427 /* matrix. The factored form of A is then used to solve the system of */
15428 /* equations A * X = B. */
15429
15430 /* Arguments */
15431 /* ========= */
15432
15433 /* UPLO (input) CHARACTER*1 */
15434 /* = 'U': Upper triangle of A is stored; */
15435 /* = 'L': Lower triangle of A is stored. */
15436
15437 /* N (input) INTEGER */
15438 /* The number of linear equations, i.e., the order of the */
15439 /* matrix A. N >= 0. */
15440
15441 /* NRHS (input) INTEGER */
15442 /* The number of right hand sides, i.e., the number of columns */
15443 /* of the matrix B. NRHS >= 0. */
15444
15445 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
15446 /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
15447 /* N-by-N upper triangular part of A contains the upper */
15448 /* triangular part of the matrix A, and the strictly lower */
15449 /* triangular part of A is not referenced. If UPLO = 'L', the */
15450 /* leading N-by-N lower triangular part of A contains the lower */
15451 /* triangular part of the matrix A, and the strictly upper */
15452 /* triangular part of A is not referenced. */
15453
15454 /* On exit, if INFO = 0, the factor U or L from the Cholesky */
15455 /* factorization A = U**T*U or A = L*L**T. */
15456
15457 /* LDA (input) INTEGER */
15458 /* The leading dimension of the array A. LDA >= max(1,N). */
15459
15460 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
15461 /* On entry, the N-by-NRHS right hand side matrix B. */
15462 /* On exit, if INFO = 0, the N-by-NRHS solution matrix X. */
15463
15464 /* LDB (input) INTEGER */
15465 /* The leading dimension of the array B. LDB >= max(1,N). */
15466
15467 /* INFO (output) INTEGER */
15468 /* = 0: successful exit */
15469 /* < 0: if INFO = -i, the i-th argument had an illegal value */
15470 /* > 0: if INFO = i, the leading minor of order i of A is not */
15471 /* positive definite, so the factorization could not be */
15472 /* completed, and the solution has not been computed. */
15473
15474 /* ===================================================================== */
15475
15476 /* .. External Functions .. */
15477 /* .. */
15478 /* .. External Subroutines .. */
15479 /* .. */
15480 /* .. Intrinsic Functions .. */
15481 /* .. */
15482 /* .. Executable Statements .. */
15483
15484 /* Test the input parameters. */
15485
15486 /* Parameter adjustments */
15487 a_dim1 = *lda;
15488 a_offset = 1 + a_dim1;
15489 a -= a_offset;
15490 b_dim1 = *ldb;
15491 b_offset = 1 + b_dim1;
15492 b -= b_offset;
15493
15494 /* Function Body */
15495 *info = 0;
15496 if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
15497 *info = -1;
15498 } else if (*n < 0) {
15499 *info = -2;
15500 } else if (*nrhs < 0) {
15501 *info = -3;
15502 } else if (*lda < std::max(1_integer,*n)) {
15503 *info = -5;
15504 } else if (*ldb < std::max(1_integer,*n)) {
15505 *info = -7;
15506 }
15507 if (*info != 0) {
15508 i__1 = -(*info);
15509 xerbla_("DPOSV ", &i__1);
15510 return 0;
15511 }
15512
15513 /* Compute the Cholesky factorization A = U'*U or A = L*L'. */
15514
15515 dpotrf_(uplo, n, &a[a_offset], lda, info);
15516 if (*info == 0) {
15517
15518 /* Solve the system A*X = B, overwriting B with X. */
15519
15520 dpotrs_(uplo, n, nrhs, &a[a_offset], lda, &b[b_offset], ldb, info);
15521
15522 }
15523 return 0;
15524
15525 /* End of DPOSV */
15526
15527 } /* dposv_ */
15528
15529 /* Subroutine */ int dposvx_(const char *fact, const char *uplo, integer *n, integer *
15530 nrhs, double *a, integer *lda, double *af, integer *ldaf,
15531 char *equed, double *s, double *b, integer *ldb, double *
15532 x, integer *ldx, double *rcond, double *ferr, double *
15533 berr, double *work, integer *iwork, integer *info)
15534 {
15535 /* System generated locals */
15536 integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1,
15537 x_offset, i__1, i__2;
15538 double d__1, d__2;
15539
15540 /* Local variables */
15541 integer i__, j;
15542 double amax, smin, smax;
15543 double scond, anorm;
15544 bool equil, rcequ;
15545 bool nofact;
15546 double bignum;
15547 integer infequ;
15548 double smlnum;
15549
15550 /* -- LAPACK driver routine (version 3.1) -- */
15551 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
15552 /* November 2006 */
15553
15554 /* .. Scalar Arguments .. */
15555 /* .. */
15556 /* .. Array Arguments .. */
15557 /* .. */
15558
15559 /* Purpose */
15560 /* ======= */
15561
15562 /* DPOSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to */
15563 /* compute the solution to a real system of linear equations */
15564 /* A * X = B, */
15565 /* where A is an N-by-N symmetric positive definite matrix and X and B */
15566 /* are N-by-NRHS matrices. */
15567
15568 /* Error bounds on the solution and a condition estimate are also */
15569 /* provided. */
15570
15571 /* Description */
15572 /* =========== */
15573
15574 /* The following steps are performed: */
15575
15576 /* 1. If FACT = 'E', real scaling factors are computed to equilibrate */
15577 /* the system: */
15578 /* diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B */
15579 /* Whether or not the system will be equilibrated depends on the */
15580 /* scaling of the matrix A, but if equilibration is used, A is */
15581 /* overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */
15582
15583 /* 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to */
15584 /* factor the matrix A (after equilibration if FACT = 'E') as */
15585 /* A = U**T* U, if UPLO = 'U', or */
15586 /* A = L * L**T, if UPLO = 'L', */
15587 /* where U is an upper triangular matrix and L is a lower triangular */
15588 /* matrix. */
15589
15590 /* 3. If the leading i-by-i principal minor is not positive definite, */
15591 /* then the routine returns with INFO = i. Otherwise, the factored */
15592 /* form of A is used to estimate the condition number of the matrix */
15593 /* A. If the reciprocal of the condition number is less than machine */
15594 /* precision, INFO = N+1 is returned as a warning, but the routine */
15595 /* still goes on to solve for X and compute error bounds as */
15596 /* described below. */
15597
15598 /* 4. The system of equations is solved for X using the factored form */
15599 /* of A. */
15600
15601 /* 5. Iterative refinement is applied to improve the computed solution */
15602 /* matrix and calculate error bounds and backward error estimates */
15603 /* for it. */
15604
15605 /* 6. If equilibration was used, the matrix X is premultiplied by */
15606 /* diag(S) so that it solves the original system before */
15607 /* equilibration. */
15608
15609 /* Arguments */
15610 /* ========= */
15611
15612 /* FACT (input) CHARACTER*1 */
15613 /* Specifies whether or not the factored form of the matrix A is */
15614 /* supplied on entry, and if not, whether the matrix A should be */
15615 /* equilibrated before it is factored. */
15616 /* = 'F': On entry, AF contains the factored form of A. */
15617 /* If EQUED = 'Y', the matrix A has been equilibrated */
15618 /* with scaling factors given by S. A and AF will not */
15619 /* be modified. */
15620 /* = 'N': The matrix A will be copied to AF and factored. */
15621 /* = 'E': The matrix A will be equilibrated if necessary, then */
15622 /* copied to AF and factored. */
15623
15624 /* UPLO (input) CHARACTER*1 */
15625 /* = 'U': Upper triangle of A is stored; */
15626 /* = 'L': Lower triangle of A is stored. */
15627
15628 /* N (input) INTEGER */
15629 /* The number of linear equations, i.e., the order of the */
15630 /* matrix A. N >= 0. */
15631
15632 /* NRHS (input) INTEGER */
15633 /* The number of right hand sides, i.e., the number of columns */
15634 /* of the matrices B and X. NRHS >= 0. */
15635
15636 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
15637 /* On entry, the symmetric matrix A, except if FACT = 'F' and */
15638 /* EQUED = 'Y', then A must contain the equilibrated matrix */
15639 /* diag(S)*A*diag(S). If UPLO = 'U', the leading */
15640 /* N-by-N upper triangular part of A contains the upper */
15641 /* triangular part of the matrix A, and the strictly lower */
15642 /* triangular part of A is not referenced. If UPLO = 'L', the */
15643 /* leading N-by-N lower triangular part of A contains the lower */
15644 /* triangular part of the matrix A, and the strictly upper */
15645 /* triangular part of A is not referenced. A is not modified if */
15646 /* FACT = 'F' or 'N', or if FACT = 'E' and EQUED = 'N' on exit. */
15647
15648 /* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */
15649 /* diag(S)*A*diag(S). */
15650
15651 /* LDA (input) INTEGER */
15652 /* The leading dimension of the array A. LDA >= max(1,N). */
15653
15654 /* AF (input or output) DOUBLE PRECISION array, dimension (LDAF,N) */
15655 /* If FACT = 'F', then AF is an input argument and on entry */
15656 /* contains the triangular factor U or L from the Cholesky */
15657 /* factorization A = U**T*U or A = L*L**T, in the same storage */
15658 /* format as A. If EQUED .ne. 'N', then AF is the factored form */
15659 /* of the equilibrated matrix diag(S)*A*diag(S). */
15660
15661 /* If FACT = 'N', then AF is an output argument and on exit */
15662 /* returns the triangular factor U or L from the Cholesky */
15663 /* factorization A = U**T*U or A = L*L**T of the original */
15664 /* matrix A. */
15665
15666 /* If FACT = 'E', then AF is an output argument and on exit */
15667 /* returns the triangular factor U or L from the Cholesky */
15668 /* factorization A = U**T*U or A = L*L**T of the equilibrated */
15669 /* matrix A (see the description of A for the form of the */
15670 /* equilibrated matrix). */
15671
15672 /* LDAF (input) INTEGER */
15673 /* The leading dimension of the array AF. LDAF >= max(1,N). */
15674
15675 /* EQUED (input or output) CHARACTER*1 */
15676 /* Specifies the form of equilibration that was done. */
15677 /* = 'N': No equilibration (always true if FACT = 'N'). */
15678 /* = 'Y': Equilibration was done, i.e., A has been replaced by */
15679 /* diag(S) * A * diag(S). */
15680 /* EQUED is an input argument if FACT = 'F'; otherwise, it is an */
15681 /* output argument. */
15682
15683 /* S (input or output) DOUBLE PRECISION array, dimension (N) */
15684 /* The scale factors for A; not accessed if EQUED = 'N'. S is */
15685 /* an input argument if FACT = 'F'; otherwise, S is an output */
15686 /* argument. If FACT = 'F' and EQUED = 'Y', each element of S */
15687 /* must be positive. */
15688
15689 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
15690 /* On entry, the N-by-NRHS right hand side matrix B. */
15691 /* On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', */
15692 /* B is overwritten by diag(S) * B. */
15693
15694 /* LDB (input) INTEGER */
15695 /* The leading dimension of the array B. LDB >= max(1,N). */
15696
15697 /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
15698 /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to */
15699 /* the original system of equations. Note that if EQUED = 'Y', */
15700 /* A and B are modified on exit, and the solution to the */
15701 /* equilibrated system is inv(diag(S))*X. */
15702
15703 /* LDX (input) INTEGER */
15704 /* The leading dimension of the array X. LDX >= max(1,N). */
15705
15706 /* RCOND (output) DOUBLE PRECISION */
15707 /* The estimate of the reciprocal condition number of the matrix */
15708 /* A after equilibration (if done). If RCOND is less than the */
15709 /* machine precision (in particular, if RCOND = 0), the matrix */
15710 /* is singular to working precision. This condition is */
15711 /* indicated by a return code of INFO > 0. */
15712
15713 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
15714 /* The estimated forward error bound for each solution vector */
15715 /* X(j) (the j-th column of the solution matrix X). */
15716 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
15717 /* is an estimated upper bound for the magnitude of the largest */
15718 /* element in (X(j) - XTRUE) divided by the magnitude of the */
15719 /* largest element in X(j). The estimate is as reliable as */
15720 /* the estimate for RCOND, and is almost always a slight */
15721 /* overestimate of the true error. */
15722
15723 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
15724 /* The componentwise relative backward error of each solution */
15725 /* vector X(j) (i.e., the smallest relative change in */
15726 /* any element of A or B that makes X(j) an exact solution). */
15727
15728 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
15729
15730 /* IWORK (workspace) INTEGER array, dimension (N) */
15731
15732 /* INFO (output) INTEGER */
15733 /* = 0: successful exit */
15734 /* < 0: if INFO = -i, the i-th argument had an illegal value */
15735 /* > 0: if INFO = i, and i is */
15736 /* <= N: the leading minor of order i of A is */
15737 /* not positive definite, so the factorization */
15738 /* could not be completed, and the solution has not */
15739 /* been computed. RCOND = 0 is returned. */
15740 /* = N+1: U is nonsingular, but RCOND is less than machine */
15741 /* precision, meaning that the matrix is singular */
15742 /* to working precision. Nevertheless, the */
15743 /* solution and error bounds are computed because */
15744 /* there are a number of situations where the */
15745 /* computed solution can be more accurate than the */
15746 /* value of RCOND would suggest. */
15747
15748 /* ===================================================================== */
15749
15750 /* .. Parameters .. */
15751 /* .. */
15752 /* .. Local Scalars .. */
15753 /* .. */
15754 /* .. External Functions .. */
15755 /* .. */
15756 /* .. External Subroutines .. */
15757 /* .. */
15758 /* .. Intrinsic Functions .. */
15759 /* .. */
15760 /* .. Executable Statements .. */
15761
15762 /* Parameter adjustments */
15763 a_dim1 = *lda;
15764 a_offset = 1 + a_dim1;
15765 a -= a_offset;
15766 af_dim1 = *ldaf;
15767 af_offset = 1 + af_dim1;
15768 af -= af_offset;
15769 --s;
15770 b_dim1 = *ldb;
15771 b_offset = 1 + b_dim1;
15772 b -= b_offset;
15773 x_dim1 = *ldx;
15774 x_offset = 1 + x_dim1;
15775 x -= x_offset;
15776 --ferr;
15777 --berr;
15778 --work;
15779 --iwork;
15780
15781 /* Function Body */
15782 *info = 0;
15783 nofact = lsame_(fact, "N");
15784 equil = lsame_(fact, "E");
15785 if (nofact || equil) {
15786 *(unsigned char *)equed = 'N';
15787 rcequ = false;
15788 } else {
15789 rcequ = lsame_(equed, "Y");
15790 smlnum = dlamch_("Safe minimum");
15791 bignum = 1. / smlnum;
15792 }
15793
15794 /* Test the input parameters. */
15795
15796 if (! nofact && ! equil && ! lsame_(fact, "F")) {
15797 *info = -1;
15798 } else if (! lsame_(uplo, "U") && ! lsame_(uplo,
15799 "L")) {
15800 *info = -2;
15801 } else if (*n < 0) {
15802 *info = -3;
15803 } else if (*nrhs < 0) {
15804 *info = -4;
15805 } else if (*lda < std::max(1_integer,*n)) {
15806 *info = -6;
15807 } else if (*ldaf < std::max(1_integer,*n)) {
15808 *info = -8;
15809 } else if (lsame_(fact, "F") && ! (rcequ || lsame_(
15810 equed, "N"))) {
15811 *info = -9;
15812 } else {
15813 if (rcequ) {
15814 smin = bignum;
15815 smax = 0.;
15816 i__1 = *n;
15817 for (j = 1; j <= i__1; ++j) {
15818 /* Computing MIN */
15819 d__1 = smin, d__2 = s[j];
15820 smin = std::min(d__1,d__2);
15821 /* Computing MAX */
15822 d__1 = smax, d__2 = s[j];
15823 smax = std::max(d__1,d__2);
15824 /* L10: */
15825 }
15826 if (smin <= 0.) {
15827 *info = -10;
15828 } else if (*n > 0) {
15829 scond = std::max(smin,smlnum) / std::min(smax,bignum);
15830 } else {
15831 scond = 1.;
15832 }
15833 }
15834 if (*info == 0) {
15835 if (*ldb < std::max(1_integer,*n)) {
15836 *info = -12;
15837 } else if (*ldx < std::max(1_integer,*n)) {
15838 *info = -14;
15839 }
15840 }
15841 }
15842
15843 if (*info != 0) {
15844 i__1 = -(*info);
15845 xerbla_("DPOSVX", &i__1);
15846 return 0;
15847 }
15848
15849 if (equil) {
15850
15851 /* Compute row and column scalings to equilibrate the matrix A. */
15852
15853 dpoequ_(n, &a[a_offset], lda, &s[1], &scond, &amax, &infequ);
15854 if (infequ == 0) {
15855
15856 /* Equilibrate the matrix. */
15857
15858 dlaqsy_(uplo, n, &a[a_offset], lda, &s[1], &scond, &amax, equed);
15859 rcequ = lsame_(equed, "Y");
15860 }
15861 }
15862
15863 /* Scale the right hand side. */
15864
15865 if (rcequ) {
15866 i__1 = *nrhs;
15867 for (j = 1; j <= i__1; ++j) {
15868 i__2 = *n;
15869 for (i__ = 1; i__ <= i__2; ++i__) {
15870 b[i__ + j * b_dim1] = s[i__] * b[i__ + j * b_dim1];
15871 /* L20: */
15872 }
15873 /* L30: */
15874 }
15875 }
15876
15877 if (nofact || equil) {
15878
15879 /* Compute the Cholesky factorization A = U'*U or A = L*L'. */
15880
15881 dlacpy_(uplo, n, n, &a[a_offset], lda, &af[af_offset], ldaf);
15882 dpotrf_(uplo, n, &af[af_offset], ldaf, info);
15883
15884 /* Return if INFO is non-zero. */
15885
15886 if (*info > 0) {
15887 *rcond = 0.;
15888 return 0;
15889 }
15890 }
15891
15892 /* Compute the norm of the matrix A. */
15893
15894 anorm = dlansy_("1", uplo, n, &a[a_offset], lda, &work[1]);
15895
15896 /* Compute the reciprocal of the condition number of A. */
15897
15898 dpocon_(uplo, n, &af[af_offset], ldaf, &anorm, rcond, &work[1], &iwork[1],
15899 info);
15900
15901 /* Compute the solution matrix X. */
15902
15903 dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
15904 dpotrs_(uplo, n, nrhs, &af[af_offset], ldaf, &x[x_offset], ldx, info);
15905
15906 /* Use iterative refinement to improve the computed solution and */
15907 /* compute error bounds and backward error estimates for it. */
15908
15909 dporfs_(uplo, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, &b[
15910 b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1], &
15911 iwork[1], info);
15912
15913 /* Transform the solution matrix X to a solution of the original */
15914 /* system. */
15915
15916 if (rcequ) {
15917 i__1 = *nrhs;
15918 for (j = 1; j <= i__1; ++j) {
15919 i__2 = *n;
15920 for (i__ = 1; i__ <= i__2; ++i__) {
15921 x[i__ + j * x_dim1] = s[i__] * x[i__ + j * x_dim1];
15922 /* L40: */
15923 }
15924 /* L50: */
15925 }
15926 i__1 = *nrhs;
15927 for (j = 1; j <= i__1; ++j) {
15928 ferr[j] /= scond;
15929 /* L60: */
15930 }
15931 }
15932
15933 /* Set INFO = N+1 if the matrix is singular to working precision. */
15934
15935 if (*rcond < dlamch_("Epsilon")) {
15936 *info = *n + 1;
15937 }
15938
15939 return 0;
15940
15941 /* End of DPOSVX */
15942
15943 } /* dposvx_ */
15944
15945 /* Subroutine */ int dpotf2_(const char *uplo, integer *n, double *a, integer *lda, integer *info)
15946 {
15947 /* Table of constant values */
15948 static integer c__1 = 1;
15949 static double c_b10 = -1.;
15950 static double c_b12 = 1.;
15951
15952 /* System generated locals */
15953 integer a_dim1, a_offset, i__1, i__2, i__3;
15954 double d__1;
15955
15956 /* Local variables */
15957 integer j;
15958 double ajj;
15959 bool upper;
15960
15961
15962 /* -- LAPACK routine (version 3.2) -- */
15963 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
15964 /* November 2006 */
15965
15966 /* .. Scalar Arguments .. */
15967 /* .. */
15968 /* .. Array Arguments .. */
15969 /* .. */
15970
15971 /* Purpose */
15972 /* ======= */
15973
15974 /* DPOTF2 computes the Cholesky factorization of a real symmetric */
15975 /* positive definite matrix A. */
15976
15977 /* The factorization has the form */
15978 /* A = U' * U , if UPLO = 'U', or */
15979 /* A = L * L', if UPLO = 'L', */
15980 /* where U is an upper triangular matrix and L is lower triangular. */
15981
15982 /* This is the unblocked version of the algorithm, calling Level 2 BLAS. */
15983
15984 /* Arguments */
15985 /* ========= */
15986
15987 /* UPLO (input) CHARACTER*1 */
15988 /* Specifies whether the upper or lower triangular part of the */
15989 /* symmetric matrix A is stored. */
15990 /* = 'U': Upper triangular */
15991 /* = 'L': Lower triangular */
15992
15993 /* N (input) INTEGER */
15994 /* The order of the matrix A. N >= 0. */
15995
15996 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
15997 /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
15998 /* n by n upper triangular part of A contains the upper */
15999 /* triangular part of the matrix A, and the strictly lower */
16000 /* triangular part of A is not referenced. If UPLO = 'L', the */
16001 /* leading n by n lower triangular part of A contains the lower */
16002 /* triangular part of the matrix A, and the strictly upper */
16003 /* triangular part of A is not referenced. */
16004
16005 /* On exit, if INFO = 0, the factor U or L from the Cholesky */
16006 /* factorization A = U'*U or A = L*L'. */
16007
16008 /* LDA (input) INTEGER */
16009 /* The leading dimension of the array A. LDA >= max(1,N). */
16010
16011 /* INFO (output) INTEGER */
16012 /* = 0: successful exit */
16013 /* < 0: if INFO = -k, the k-th argument had an illegal value */
16014 /* > 0: if INFO = k, the leading minor of order k is not */
16015 /* positive definite, and the factorization could not be */
16016 /* completed. */
16017
16018 /* ===================================================================== */
16019
16020 /* .. Parameters .. */
16021 /* .. */
16022 /* .. Local Scalars .. */
16023 /* .. */
16024 /* .. External Functions .. */
16025 /* .. */
16026 /* .. External Subroutines .. */
16027 /* .. */
16028 /* .. Intrinsic Functions .. */
16029 /* .. */
16030 /* .. Executable Statements .. */
16031
16032 /* Test the input parameters. */
16033
16034 /* Parameter adjustments */
16035 a_dim1 = *lda;
16036 a_offset = 1 + a_dim1;
16037 a -= a_offset;
16038
16039 /* Function Body */
16040 *info = 0;
16041 upper = lsame_(uplo, "U");
16042 if (! upper && ! lsame_(uplo, "L")) {
16043 *info = -1;
16044 } else if (*n < 0) {
16045 *info = -2;
16046 } else if (*lda < std::max(1_integer,*n)) {
16047 *info = -4;
16048 }
16049 if (*info != 0) {
16050 i__1 = -(*info);
16051 xerbla_("DPOTF2", &i__1);
16052 return 0;
16053 }
16054
16055 /* Quick return if possible */
16056
16057 if (*n == 0) {
16058 return 0;
16059 }
16060
16061 if (upper) {
16062
16063 /* Compute the Cholesky factorization A = U'*U. */
16064
16065 i__1 = *n;
16066 for (j = 1; j <= i__1; ++j) {
16067
16068 /* Compute U(J,J) and test for non-positive-definiteness. */
16069
16070 i__2 = j - 1;
16071 ajj = a[j + j * a_dim1] - ddot_(&i__2, &a[j * a_dim1 + 1], &c__1,
16072 &a[j * a_dim1 + 1], &c__1);
16073 if (ajj <= 0. || disnan_(&ajj)) {
16074 a[j + j * a_dim1] = ajj;
16075 goto L30;
16076 }
16077 ajj = sqrt(ajj);
16078 a[j + j * a_dim1] = ajj;
16079
16080 /* Compute elements J+1:N of row J. */
16081
16082 if (j < *n) {
16083 i__2 = j - 1;
16084 i__3 = *n - j;
16085 dgemv_("Transpose", &i__2, &i__3, &c_b10, &a[(j + 1) * a_dim1
16086 + 1], lda, &a[j * a_dim1 + 1], &c__1, &c_b12, &a[j + (
16087 j + 1) * a_dim1], lda);
16088 i__2 = *n - j;
16089 d__1 = 1. / ajj;
16090 dscal_(&i__2, &d__1, &a[j + (j + 1) * a_dim1], lda);
16091 }
16092 /* L10: */
16093 }
16094 } else {
16095
16096 /* Compute the Cholesky factorization A = L*L'. */
16097
16098 i__1 = *n;
16099 for (j = 1; j <= i__1; ++j) {
16100
16101 /* Compute L(J,J) and test for non-positive-definiteness. */
16102
16103 i__2 = j - 1;
16104 ajj = a[j + j * a_dim1] - ddot_(&i__2, &a[j + a_dim1], lda, &a[j
16105 + a_dim1], lda);
16106 if (ajj <= 0. || disnan_(&ajj)) {
16107 a[j + j * a_dim1] = ajj;
16108 goto L30;
16109 }
16110 ajj = sqrt(ajj);
16111 a[j + j * a_dim1] = ajj;
16112
16113 /* Compute elements J+1:N of column J. */
16114
16115 if (j < *n) {
16116 i__2 = *n - j;
16117 i__3 = j - 1;
16118 dgemv_("No transpose", &i__2, &i__3, &c_b10, &a[j + 1 +
16119 a_dim1], lda, &a[j + a_dim1], lda, &c_b12, &a[j + 1 +
16120 j * a_dim1], &c__1);
16121 i__2 = *n - j;
16122 d__1 = 1. / ajj;
16123 dscal_(&i__2, &d__1, &a[j + 1 + j * a_dim1], &c__1);
16124 }
16125 /* L20: */
16126 }
16127 }
16128 goto L40;
16129
16130 L30:
16131 *info = j;
16132
16133 L40:
16134 return 0;
16135
16136 /* End of DPOTF2 */
16137
16138 } /* dpotf2_ */
16139
16140 /* Subroutine */ int dpotrf_(const char *uplo, integer *n, double *a, integer *
16141 lda, integer *info)
16142 {
16143 /* Table of constant values */
16144 static integer c__1 = 1;
16145 static integer c_n1 = -1;
16146 static double c_b13 = -1.;
16147 static double c_b14 = 1.;
16148
16149 /* System generated locals */
16150 integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
16151
16152 /* Local variables */
16153 integer j, jb, nb;
16154 bool upper;
16155
16156
16157 /* -- LAPACK routine (version 3.1) -- */
16158 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
16159 /* November 2006 */
16160
16161 /* .. Scalar Arguments .. */
16162 /* .. */
16163 /* .. Array Arguments .. */
16164 /* .. */
16165
16166 /* Purpose */
16167 /* ======= */
16168
16169 /* DPOTRF computes the Cholesky factorization of a real symmetric */
16170 /* positive definite matrix A. */
16171
16172 /* The factorization has the form */
16173 /* A = U**T * U, if UPLO = 'U', or */
16174 /* A = L * L**T, if UPLO = 'L', */
16175 /* where U is an upper triangular matrix and L is lower triangular. */
16176
16177 /* This is the block version of the algorithm, calling Level 3 BLAS. */
16178
16179 /* Arguments */
16180 /* ========= */
16181
16182 /* UPLO (input) CHARACTER*1 */
16183 /* = 'U': Upper triangle of A is stored; */
16184 /* = 'L': Lower triangle of A is stored. */
16185
16186 /* N (input) INTEGER */
16187 /* The order of the matrix A. N >= 0. */
16188
16189 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
16190 /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
16191 /* N-by-N upper triangular part of A contains the upper */
16192 /* triangular part of the matrix A, and the strictly lower */
16193 /* triangular part of A is not referenced. If UPLO = 'L', the */
16194 /* leading N-by-N lower triangular part of A contains the lower */
16195 /* triangular part of the matrix A, and the strictly upper */
16196 /* triangular part of A is not referenced. */
16197
16198 /* On exit, if INFO = 0, the factor U or L from the Cholesky */
16199 /* factorization A = U**T*U or A = L*L**T. */
16200
16201 /* LDA (input) INTEGER */
16202 /* The leading dimension of the array A. LDA >= max(1,N). */
16203
16204 /* INFO (output) INTEGER */
16205 /* = 0: successful exit */
16206 /* < 0: if INFO = -i, the i-th argument had an illegal value */
16207 /* > 0: if INFO = i, the leading minor of order i is not */
16208 /* positive definite, and the factorization could not be */
16209 /* completed. */
16210
16211 /* ===================================================================== */
16212
16213 /* .. Parameters .. */
16214 /* .. */
16215 /* .. Local Scalars .. */
16216 /* .. */
16217 /* .. External Functions .. */
16218 /* .. */
16219 /* .. External Subroutines .. */
16220 /* .. */
16221 /* .. Intrinsic Functions .. */
16222 /* .. */
16223 /* .. Executable Statements .. */
16224
16225 /* Test the input parameters. */
16226
16227 /* Parameter adjustments */
16228 a_dim1 = *lda;
16229 a_offset = 1 + a_dim1;
16230 a -= a_offset;
16231
16232 /* Function Body */
16233 *info = 0;
16234 upper = lsame_(uplo, "U");
16235 if (! upper && ! lsame_(uplo, "L")) {
16236 *info = -1;
16237 } else if (*n < 0) {
16238 *info = -2;
16239 } else if (*lda < std::max(1_integer,*n)) {
16240 *info = -4;
16241 }
16242 if (*info != 0) {
16243 i__1 = -(*info);
16244 xerbla_("DPOTRF", &i__1);
16245 return 0;
16246 }
16247
16248 /* Quick return if possible */
16249
16250 if (*n == 0) {
16251 return 0;
16252 }
16253
16254 /* Determine the block size for this environment. */
16255
16256 nb = ilaenv_(&c__1, "DPOTRF", uplo, n, &c_n1, &c_n1, &c_n1);
16257 if (nb <= 1 || nb >= *n) {
16258
16259 /* Use unblocked code. */
16260
16261 dpotf2_(uplo, n, &a[a_offset], lda, info);
16262 } else {
16263
16264 /* Use blocked code. */
16265
16266 if (upper) {
16267
16268 /* Compute the Cholesky factorization A = U'*U. */
16269
16270 i__1 = *n;
16271 i__2 = nb;
16272 for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
16273
16274 /* Update and factorize the current diagonal block and test */
16275 /* for non-positive-definiteness. */
16276
16277 /* Computing MIN */
16278 i__3 = nb, i__4 = *n - j + 1;
16279 jb = std::min(i__3,i__4);
16280 i__3 = j - 1;
16281 dsyrk_("Upper", "Transpose", &jb, &i__3, &c_b13, &a[j *
16282 a_dim1 + 1], lda, &c_b14, &a[j + j * a_dim1], lda);
16283 dpotf2_("Upper", &jb, &a[j + j * a_dim1], lda, info);
16284 if (*info != 0) {
16285 goto L30;
16286 }
16287 if (j + jb <= *n) {
16288
16289 /* Compute the current block row. */
16290
16291 i__3 = *n - j - jb + 1;
16292 i__4 = j - 1;
16293 dgemm_("Transpose", "No transpose", &jb, &i__3, &i__4, &
16294 c_b13, &a[j * a_dim1 + 1], lda, &a[(j + jb) *
16295 a_dim1 + 1], lda, &c_b14, &a[j + (j + jb) *
16296 a_dim1], lda);
16297 i__3 = *n - j - jb + 1;
16298 dtrsm_("Left", "Upper", "Transpose", "Non-unit", &jb, &
16299 i__3, &c_b14, &a[j + j * a_dim1], lda, &a[j + (j
16300 + jb) * a_dim1], lda);
16301 }
16302 /* L10: */
16303 }
16304
16305 } else {
16306
16307 /* Compute the Cholesky factorization A = L*L'. */
16308
16309 i__2 = *n;
16310 i__1 = nb;
16311 for (j = 1; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
16312
16313 /* Update and factorize the current diagonal block and test */
16314 /* for non-positive-definiteness. */
16315
16316 /* Computing MIN */
16317 i__3 = nb, i__4 = *n - j + 1;
16318 jb = std::min(i__3,i__4);
16319 i__3 = j - 1;
16320 dsyrk_("Lower", "No transpose", &jb, &i__3, &c_b13, &a[j +
16321 a_dim1], lda, &c_b14, &a[j + j * a_dim1], lda);
16322 dpotf2_("Lower", &jb, &a[j + j * a_dim1], lda, info);
16323 if (*info != 0) {
16324 goto L30;
16325 }
16326 if (j + jb <= *n) {
16327
16328 /* Compute the current block column. */
16329
16330 i__3 = *n - j - jb + 1;
16331 i__4 = j - 1;
16332 dgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &
16333 c_b13, &a[j + jb + a_dim1], lda, &a[j + a_dim1],
16334 lda, &c_b14, &a[j + jb + j * a_dim1], lda);
16335 i__3 = *n - j - jb + 1;
16336 dtrsm_("Right", "Lower", "Transpose", "Non-unit", &i__3, &
16337 jb, &c_b14, &a[j + j * a_dim1], lda, &a[j + jb +
16338 j * a_dim1], lda);
16339 }
16340 /* L20: */
16341 }
16342 }
16343 }
16344 goto L40;
16345
16346 L30:
16347 *info = *info + j - 1;
16348
16349 L40:
16350 return 0;
16351
16352 /* End of DPOTRF */
16353
16354 } /* dpotrf_ */
16355
16356 /* Subroutine */ int dpotri_(const char *uplo, integer *n, double *a, integer *
16357 lda, integer *info)
16358 {
16359 /* System generated locals */
16360 integer a_dim1, a_offset, i__1;
16361
16362 /* -- LAPACK routine (version 3.1) -- */
16363 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
16364 /* November 2006 */
16365
16366 /* .. Scalar Arguments .. */
16367 /* .. */
16368 /* .. Array Arguments .. */
16369 /* .. */
16370
16371 /* Purpose */
16372 /* ======= */
16373
16374 /* DPOTRI computes the inverse of a real symmetric positive definite */
16375 /* matrix A using the Cholesky factorization A = U**T*U or A = L*L**T */
16376 /* computed by DPOTRF. */
16377
16378 /* Arguments */
16379 /* ========= */
16380
16381 /* UPLO (input) CHARACTER*1 */
16382 /* = 'U': Upper triangle of A is stored; */
16383 /* = 'L': Lower triangle of A is stored. */
16384
16385 /* N (input) INTEGER */
16386 /* The order of the matrix A. N >= 0. */
16387
16388 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
16389 /* On entry, the triangular factor U or L from the Cholesky */
16390 /* factorization A = U**T*U or A = L*L**T, as computed by */
16391 /* DPOTRF. */
16392 /* On exit, the upper or lower triangle of the (symmetric) */
16393 /* inverse of A, overwriting the input factor U or L. */
16394
16395 /* LDA (input) INTEGER */
16396 /* The leading dimension of the array A. LDA >= max(1,N). */
16397
16398 /* INFO (output) INTEGER */
16399 /* = 0: successful exit */
16400 /* < 0: if INFO = -i, the i-th argument had an illegal value */
16401 /* > 0: if INFO = i, the (i,i) element of the factor U or L is */
16402 /* zero, and the inverse could not be computed. */
16403
16404 /* ===================================================================== */
16405
16406 /* .. External Functions .. */
16407 /* .. */
16408 /* .. External Subroutines .. */
16409 /* .. */
16410 /* .. Intrinsic Functions .. */
16411 /* .. */
16412 /* .. Executable Statements .. */
16413
16414 /* Test the input parameters. */
16415
16416 /* Parameter adjustments */
16417 a_dim1 = *lda;
16418 a_offset = 1 + a_dim1;
16419 a -= a_offset;
16420
16421 /* Function Body */
16422 *info = 0;
16423 if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
16424 *info = -1;
16425 } else if (*n < 0) {
16426 *info = -2;
16427 } else if (*lda < std::max(1_integer,*n)) {
16428 *info = -4;
16429 }
16430 if (*info != 0) {
16431 i__1 = -(*info);
16432 xerbla_("DPOTRI", &i__1);
16433 return 0;
16434 }
16435
16436 /* Quick return if possible */
16437
16438 if (*n == 0) {
16439 return 0;
16440 }
16441
16442 /* Invert the triangular Cholesky factor U or L. */
16443
16444 dtrtri_(uplo, "Non-unit", n, &a[a_offset], lda, info);
16445 if (*info > 0) {
16446 return 0;
16447 }
16448
16449 /* Form inv(U)*inv(U)' or inv(L)'*inv(L). */
16450
16451 dlauum_(uplo, n, &a[a_offset], lda, info);
16452
16453 return 0;
16454
16455 /* End of DPOTRI */
16456
16457 } /* dpotri_ */
16458
16459 /* Subroutine */ int dpotrs_(const char *uplo, integer *n, integer *nrhs,
16460 double *a, integer *lda, double *b, integer *ldb, integer *
16461 info)
16462 {
16463 /* Table of constant values */
16464
16465 static double c_b9 = 1.;
16466
16467 /* System generated locals */
16468 integer a_dim1, a_offset, b_dim1, b_offset, i__1;
16469
16470 /* Local variables */
16471 bool upper;
16472
16473 /* -- LAPACK routine (version 3.1) -- */
16474 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
16475 /* November 2006 */
16476
16477 /* .. Scalar Arguments .. */
16478 /* .. */
16479 /* .. Array Arguments .. */
16480 /* .. */
16481
16482 /* Purpose */
16483 /* ======= */
16484
16485 /* DPOTRS solves a system of linear equations A*X = B with a symmetric */
16486 /* positive definite matrix A using the Cholesky factorization */
16487 /* A = U**T*U or A = L*L**T computed by DPOTRF. */
16488
16489 /* Arguments */
16490 /* ========= */
16491
16492 /* UPLO (input) CHARACTER*1 */
16493 /* = 'U': Upper triangle of A is stored; */
16494 /* = 'L': Lower triangle of A is stored. */
16495
16496 /* N (input) INTEGER */
16497 /* The order of the matrix A. N >= 0. */
16498
16499 /* NRHS (input) INTEGER */
16500 /* The number of right hand sides, i.e., the number of columns */
16501 /* of the matrix B. NRHS >= 0. */
16502
16503 /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
16504 /* The triangular factor U or L from the Cholesky factorization */
16505 /* A = U**T*U or A = L*L**T, as computed by DPOTRF. */
16506
16507 /* LDA (input) INTEGER */
16508 /* The leading dimension of the array A. LDA >= max(1,N). */
16509
16510 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
16511 /* On entry, the right hand side matrix B. */
16512 /* On exit, the solution matrix X. */
16513
16514 /* LDB (input) INTEGER */
16515 /* The leading dimension of the array B. LDB >= max(1,N). */
16516
16517 /* INFO (output) INTEGER */
16518 /* = 0: successful exit */
16519 /* < 0: if INFO = -i, the i-th argument had an illegal value */
16520
16521 /* ===================================================================== */
16522
16523 /* .. Parameters .. */
16524 /* .. */
16525 /* .. Local Scalars .. */
16526 /* .. */
16527 /* .. External Functions .. */
16528 /* .. */
16529 /* .. External Subroutines .. */
16530 /* .. */
16531 /* .. Intrinsic Functions .. */
16532 /* .. */
16533 /* .. Executable Statements .. */
16534
16535 /* Test the input parameters. */
16536
16537 /* Parameter adjustments */
16538 a_dim1 = *lda;
16539 a_offset = 1 + a_dim1;
16540 a -= a_offset;
16541 b_dim1 = *ldb;
16542 b_offset = 1 + b_dim1;
16543 b -= b_offset;
16544
16545 /* Function Body */
16546 *info = 0;
16547 upper = lsame_(uplo, "U");
16548 if (! upper && ! lsame_(uplo, "L")) {
16549 *info = -1;
16550 } else if (*n < 0) {
16551 *info = -2;
16552 } else if (*nrhs < 0) {
16553 *info = -3;
16554 } else if (*lda < std::max(1_integer,*n)) {
16555 *info = -5;
16556 } else if (*ldb < std::max(1_integer,*n)) {
16557 *info = -7;
16558 }
16559 if (*info != 0) {
16560 i__1 = -(*info);
16561 xerbla_("DPOTRS", &i__1);
16562 return 0;
16563 }
16564
16565 /* Quick return if possible */
16566
16567 if (*n == 0 || *nrhs == 0) {
16568 return 0;
16569 }
16570
16571 if (upper) {
16572
16573 /* Solve A*X = B where A = U'*U. */
16574
16575 /* Solve U'*X = B, overwriting B with X. */
16576
16577 dtrsm_("Left", "Upper", "Transpose", "Non-unit", n, nrhs, &c_b9, &a[
16578 a_offset], lda, &b[b_offset], ldb);
16579
16580 /* Solve U*X = B, overwriting B with X. */
16581
16582 dtrsm_("Left", "Upper", "No transpose", "Non-unit", n, nrhs, &c_b9, &
16583 a[a_offset], lda, &b[b_offset], ldb);
16584 } else {
16585
16586 /* Solve A*X = B where A = L*L'. */
16587
16588 /* Solve L*X = B, overwriting B with X. */
16589
16590 dtrsm_("Left", "Lower", "No transpose", "Non-unit", n, nrhs, &c_b9, &
16591 a[a_offset], lda, &b[b_offset], ldb);
16592
16593 /* Solve L'*X = B, overwriting B with X. */
16594
16595 dtrsm_("Left", "Lower", "Transpose", "Non-unit", n, nrhs, &c_b9, &a[
16596 a_offset], lda, &b[b_offset], ldb);
16597 }
16598
16599 return 0;
16600
16601 /* End of DPOTRS */
16602
16603 } /* dpotrs_ */
16604
16605 /* Subroutine */ int dppcon_(const char *uplo, integer *n, double *ap,
16606 double *anorm, double *rcond, double *work, integer *
16607 iwork, integer *info)
16608 {
16609 /* Table of constant values */
16610 static integer c__1 = 1;
16611
16612 /* System generated locals */
16613 integer i__1;
16614 double d__1;
16615
16616 /* Local variables */
16617 integer ix, kase;
16618 double scale;
16619 integer isave[3];
16620 bool upper;
16621 double scalel;
16622 double scaleu;
16623 double ainvnm;
16624 char normin[1];
16625 double smlnum;
16626
16627
16628 /* -- LAPACK routine (version 3.1) -- */
16629 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
16630 /* November 2006 */
16631
16632 /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
16633
16634 /* .. Scalar Arguments .. */
16635 /* .. */
16636 /* .. Array Arguments .. */
16637 /* .. */
16638
16639 /* Purpose */
16640 /* ======= */
16641
16642 /* DPPCON estimates the reciprocal of the condition number (in the */
16643 /* 1-norm) of a real symmetric positive definite packed matrix using */
16644 /* the Cholesky factorization A = U**T*U or A = L*L**T computed by */
16645 /* DPPTRF. */
16646
16647 /* An estimate is obtained for norm(inv(A)), and the reciprocal of the */
16648 /* condition number is computed as RCOND = 1 / (ANORM * norm(inv(A))). */
16649
16650 /* Arguments */
16651 /* ========= */
16652
16653 /* UPLO (input) CHARACTER*1 */
16654 /* = 'U': Upper triangle of A is stored; */
16655 /* = 'L': Lower triangle of A is stored. */
16656
16657 /* N (input) INTEGER */
16658 /* The order of the matrix A. N >= 0. */
16659
16660 /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
16661 /* The triangular factor U or L from the Cholesky factorization */
16662 /* A = U**T*U or A = L*L**T, packed columnwise in a linear */
16663 /* array. The j-th column of U or L is stored in the array AP */
16664 /* as follows: */
16665 /* if UPLO = 'U', AP(i + (j-1)*j/2) = U(i,j) for 1<=i<=j; */
16666 /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = L(i,j) for j<=i<=n. */
16667
16668 /* ANORM (input) DOUBLE PRECISION */
16669 /* The 1-norm (or infinity-norm) of the symmetric matrix A. */
16670
16671 /* RCOND (output) DOUBLE PRECISION */
16672 /* The reciprocal of the condition number of the matrix A, */
16673 /* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is an */
16674 /* estimate of the 1-norm of inv(A) computed in this routine. */
16675
16676 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
16677
16678 /* IWORK (workspace) INTEGER array, dimension (N) */
16679
16680 /* INFO (output) INTEGER */
16681 /* = 0: successful exit */
16682 /* < 0: if INFO = -i, the i-th argument had an illegal value */
16683
16684 /* ===================================================================== */
16685
16686 /* .. Parameters .. */
16687 /* .. */
16688 /* .. Local Scalars .. */
16689 /* .. */
16690 /* .. Local Arrays .. */
16691 /* .. */
16692 /* .. External Functions .. */
16693 /* .. */
16694 /* .. External Subroutines .. */
16695 /* .. */
16696 /* .. Intrinsic Functions .. */
16697 /* .. */
16698 /* .. Executable Statements .. */
16699
16700 /* Test the input parameters. */
16701
16702 /* Parameter adjustments */
16703 --iwork;
16704 --work;
16705 --ap;
16706
16707 /* Function Body */
16708 *info = 0;
16709 upper = lsame_(uplo, "U");
16710 if (! upper && ! lsame_(uplo, "L")) {
16711 *info = -1;
16712 } else if (*n < 0) {
16713 *info = -2;
16714 } else if (*anorm < 0.) {
16715 *info = -4;
16716 }
16717 if (*info != 0) {
16718 i__1 = -(*info);
16719 xerbla_("DPPCON", &i__1);
16720 return 0;
16721 }
16722
16723 /* Quick return if possible */
16724
16725 *rcond = 0.;
16726 if (*n == 0) {
16727 *rcond = 1.;
16728 return 0;
16729 } else if (*anorm == 0.) {
16730 return 0;
16731 }
16732
16733 smlnum = dlamch_("Safe minimum");
16734
16735 /* Estimate the 1-norm of the inverse. */
16736
16737 kase = 0;
16738 *(unsigned char *)normin = 'N';
16739 L10:
16740 dlacn2_(n, &work[*n + 1], &work[1], &iwork[1], &ainvnm, &kase, isave);
16741 if (kase != 0) {
16742 if (upper) {
16743
16744 /* Multiply by inv(U'). */
16745
16746 dlatps_("Upper", "Transpose", "Non-unit", normin, n, &ap[1], &
16747 work[1], &scalel, &work[(*n << 1) + 1], info);
16748 *(unsigned char *)normin = 'Y';
16749
16750 /* Multiply by inv(U). */
16751
16752 dlatps_("Upper", "No transpose", "Non-unit", normin, n, &ap[1], &
16753 work[1], &scaleu, &work[(*n << 1) + 1], info);
16754 } else {
16755
16756 /* Multiply by inv(L). */
16757
16758 dlatps_("Lower", "No transpose", "Non-unit", normin, n, &ap[1], &
16759 work[1], &scalel, &work[(*n << 1) + 1], info);
16760 *(unsigned char *)normin = 'Y';
16761
16762 /* Multiply by inv(L'). */
16763
16764 dlatps_("Lower", "Transpose", "Non-unit", normin, n, &ap[1], &
16765 work[1], &scaleu, &work[(*n << 1) + 1], info);
16766 }
16767
16768 /* Multiply by 1/SCALE if doing so will not cause overflow. */
16769
16770 scale = scalel * scaleu;
16771 if (scale != 1.) {
16772 ix = idamax_(n, &work[1], &c__1);
16773 if (scale < (d__1 = work[ix], abs(d__1)) * smlnum || scale == 0.)
16774 {
16775 goto L20;
16776 }
16777 drscl_(n, &scale, &work[1], &c__1);
16778 }
16779 goto L10;
16780 }
16781
16782 /* Compute the estimate of the reciprocal condition number. */
16783
16784 if (ainvnm != 0.) {
16785 *rcond = 1. / ainvnm / *anorm;
16786 }
16787
16788 L20:
16789 return 0;
16790
16791 /* End of DPPCON */
16792
16793 } /* dppcon_ */
16794
16795 /* Subroutine */ int dppequ_(const char *uplo, integer *n, double *ap,
16796 double *s, double *scond, double *amax, integer *info)
16797 {
16798 /* System generated locals */
16799 integer i__1;
16800 double d__1, d__2;
16801
16802 /* Local variables */
16803 integer i__, jj;
16804 double smin;
16805
16806 bool upper;
16807
16808
16809
16810 /* -- LAPACK routine (version 3.1) -- */
16811 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
16812 /* November 2006 */
16813
16814 /* .. Scalar Arguments .. */
16815 /* .. */
16816 /* .. Array Arguments .. */
16817 /* .. */
16818
16819 /* Purpose */
16820 /* ======= */
16821
16822 /* DPPEQU computes row and column scalings intended to equilibrate a */
16823 /* symmetric positive definite matrix A in packed storage and reduce */
16824 /* its condition number (with respect to the two-norm). S contains the */
16825 /* scale factors, S(i)=1/sqrt(A(i,i)), chosen so that the scaled matrix */
16826 /* B with elements B(i,j)=S(i)*A(i,j)*S(j) has ones on the diagonal. */
16827 /* This choice of S puts the condition number of B within a factor N of */
16828 /* the smallest possible condition number over all possible diagonal */
16829 /* scalings. */
16830
16831 /* Arguments */
16832 /* ========= */
16833
16834 /* UPLO (input) CHARACTER*1 */
16835 /* = 'U': Upper triangle of A is stored; */
16836 /* = 'L': Lower triangle of A is stored. */
16837
16838 /* N (input) INTEGER */
16839 /* The order of the matrix A. N >= 0. */
16840
16841 /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
16842 /* The upper or lower triangle of the symmetric matrix A, packed */
16843 /* columnwise in a linear array. The j-th column of A is stored */
16844 /* in the array AP as follows: */
16845 /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
16846 /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
16847
16848 /* S (output) DOUBLE PRECISION array, dimension (N) */
16849 /* If INFO = 0, S contains the scale factors for A. */
16850
16851 /* SCOND (output) DOUBLE PRECISION */
16852 /* If INFO = 0, S contains the ratio of the smallest S(i) to */
16853 /* the largest S(i). If SCOND >= 0.1 and AMAX is neither too */
16854 /* large nor too small, it is not worth scaling by S. */
16855
16856 /* AMAX (output) DOUBLE PRECISION */
16857 /* Absolute value of largest matrix element. If AMAX is very */
16858 /* close to overflow or very close to underflow, the matrix */
16859 /* should be scaled. */
16860
16861 /* INFO (output) INTEGER */
16862 /* = 0: successful exit */
16863 /* < 0: if INFO = -i, the i-th argument had an illegal value */
16864 /* > 0: if INFO = i, the i-th diagonal element is nonpositive. */
16865
16866 /* ===================================================================== */
16867
16868 /* .. Parameters .. */
16869 /* .. */
16870 /* .. Local Scalars .. */
16871 /* .. */
16872 /* .. External Functions .. */
16873 /* .. */
16874 /* .. External Subroutines .. */
16875 /* .. */
16876 /* .. Intrinsic Functions .. */
16877 /* .. */
16878 /* .. Executable Statements .. */
16879
16880 /* Test the input parameters. */
16881
16882 /* Parameter adjustments */
16883 --s;
16884 --ap;
16885
16886 /* Function Body */
16887 *info = 0;
16888 upper = lsame_(uplo, "U");
16889 if (! upper && ! lsame_(uplo, "L")) {
16890 *info = -1;
16891 } else if (*n < 0) {
16892 *info = -2;
16893 }
16894 if (*info != 0) {
16895 i__1 = -(*info);
16896 xerbla_("DPPEQU", &i__1);
16897 return 0;
16898 }
16899
16900 /* Quick return if possible */
16901
16902 if (*n == 0) {
16903 *scond = 1.;
16904 *amax = 0.;
16905 return 0;
16906 }
16907
16908 /* Initialize SMIN and AMAX. */
16909
16910 s[1] = ap[1];
16911 smin = s[1];
16912 *amax = s[1];
16913
16914 if (upper) {
16915
16916 /* UPLO = 'U': Upper triangle of A is stored. */
16917 /* Find the minimum and maximum diagonal elements. */
16918
16919 jj = 1;
16920 i__1 = *n;
16921 for (i__ = 2; i__ <= i__1; ++i__) {
16922 jj += i__;
16923 s[i__] = ap[jj];
16924 /* Computing MIN */
16925 d__1 = smin, d__2 = s[i__];
16926 smin = std::min(d__1,d__2);
16927 /* Computing MAX */
16928 d__1 = *amax, d__2 = s[i__];
16929 *amax = std::max(d__1,d__2);
16930 /* L10: */
16931 }
16932
16933 } else {
16934
16935 /* UPLO = 'L': Lower triangle of A is stored. */
16936 /* Find the minimum and maximum diagonal elements. */
16937
16938 jj = 1;
16939 i__1 = *n;
16940 for (i__ = 2; i__ <= i__1; ++i__) {
16941 jj = jj + *n - i__ + 2;
16942 s[i__] = ap[jj];
16943 /* Computing MIN */
16944 d__1 = smin, d__2 = s[i__];
16945 smin = std::min(d__1,d__2);
16946 /* Computing MAX */
16947 d__1 = *amax, d__2 = s[i__];
16948 *amax = std::max(d__1,d__2);
16949 /* L20: */
16950 }
16951 }
16952
16953 if (smin <= 0.) {
16954
16955 /* Find the first non-positive diagonal element and return. */
16956
16957 i__1 = *n;
16958 for (i__ = 1; i__ <= i__1; ++i__) {
16959 if (s[i__] <= 0.) {
16960 *info = i__;
16961 return 0;
16962 }
16963 /* L30: */
16964 }
16965 } else {
16966
16967 /* Set the scale factors to the reciprocals */
16968 /* of the diagonal elements. */
16969
16970 i__1 = *n;
16971 for (i__ = 1; i__ <= i__1; ++i__) {
16972 s[i__] = 1. / sqrt(s[i__]);
16973 /* L40: */
16974 }
16975
16976 /* Compute SCOND = min(S(I)) / max(S(I)) */
16977
16978 *scond = sqrt(smin) / sqrt(*amax);
16979 }
16980 return 0;
16981
16982 /* End of DPPEQU */
16983
16984 } /* dppequ_ */
16985
16986 /* Subroutine */ int dpprfs_(const char *uplo, integer *n, integer *nrhs,
16987 double *ap, double *afp, double *b, integer *ldb,
16988 double *x, integer *ldx, double *ferr, double *berr,
16989 double *work, integer *iwork, integer *info)
16990 {
16991 /* Table of constant values */
16992 static integer c__1 = 1;
16993 static double c_b12 = -1.;
16994 static double c_b14 = 1.;
16995
16996 /* System generated locals */
16997 integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3;
16998 double d__1, d__2, d__3;
16999
17000 /* Local variables */
17001 integer i__, j, k;
17002 double s;
17003 integer ik, kk;
17004 double xk;
17005 integer nz;
17006 double eps;
17007 integer kase;
17008 double safe1, safe2;
17009 integer isave[3];
17010 integer count;
17011 bool upper;
17012 double safmin;
17013 double lstres;
17014
17015
17016 /* -- LAPACK routine (version 3.1) -- */
17017 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
17018 /* November 2006 */
17019
17020 /* Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
17021
17022 /* .. Scalar Arguments .. */
17023 /* .. */
17024 /* .. Array Arguments .. */
17025 /* .. */
17026
17027 /* Purpose */
17028 /* ======= */
17029
17030 /* DPPRFS improves the computed solution to a system of linear */
17031 /* equations when the coefficient matrix is symmetric positive definite */
17032 /* and packed, and provides error bounds and backward error estimates */
17033 /* for the solution. */
17034
17035 /* Arguments */
17036 /* ========= */
17037
17038 /* UPLO (input) CHARACTER*1 */
17039 /* = 'U': Upper triangle of A is stored; */
17040 /* = 'L': Lower triangle of A is stored. */
17041
17042 /* N (input) INTEGER */
17043 /* The order of the matrix A. N >= 0. */
17044
17045 /* NRHS (input) INTEGER */
17046 /* The number of right hand sides, i.e., the number of columns */
17047 /* of the matrices B and X. NRHS >= 0. */
17048
17049 /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
17050 /* The upper or lower triangle of the symmetric matrix A, packed */
17051 /* columnwise in a linear array. The j-th column of A is stored */
17052 /* in the array AP as follows: */
17053 /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
17054 /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
17055
17056 /* AFP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
17057 /* The triangular factor U or L from the Cholesky factorization */
17058 /* A = U**T*U or A = L*L**T, as computed by DPPTRF/ZPPTRF, */
17059 /* packed columnwise in a linear array in the same format as A */
17060 /* (see AP). */
17061
17062 /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
17063 /* The right hand side matrix B. */
17064
17065 /* LDB (input) INTEGER */
17066 /* The leading dimension of the array B. LDB >= max(1,N). */
17067
17068 /* X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
17069 /* On entry, the solution matrix X, as computed by DPPTRS. */
17070 /* On exit, the improved solution matrix X. */
17071
17072 /* LDX (input) INTEGER */
17073 /* The leading dimension of the array X. LDX >= max(1,N). */
17074
17075 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
17076 /* The estimated forward error bound for each solution vector */
17077 /* X(j) (the j-th column of the solution matrix X). */
17078 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
17079 /* is an estimated upper bound for the magnitude of the largest */
17080 /* element in (X(j) - XTRUE) divided by the magnitude of the */
17081 /* largest element in X(j). The estimate is as reliable as */
17082 /* the estimate for RCOND, and is almost always a slight */
17083 /* overestimate of the true error. */
17084
17085 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
17086 /* The componentwise relative backward error of each solution */
17087 /* vector X(j) (i.e., the smallest relative change in */
17088 /* any element of A or B that makes X(j) an exact solution). */
17089
17090 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
17091
17092 /* IWORK (workspace) INTEGER array, dimension (N) */
17093
17094 /* INFO (output) INTEGER */
17095 /* = 0: successful exit */
17096 /* < 0: if INFO = -i, the i-th argument had an illegal value */
17097
17098 /* Internal Parameters */
17099 /* =================== */
17100
17101 /* ITMAX is the maximum number of steps of iterative refinement. */
17102
17103 /* ===================================================================== */
17104
17105 /* .. Parameters .. */
17106 /* .. */
17107 /* .. Local Scalars .. */
17108 /* .. */
17109 /* .. Local Arrays .. */
17110 /* .. */
17111 /* .. External Subroutines .. */
17112 /* .. */
17113 /* .. Intrinsic Functions .. */
17114 /* .. */
17115 /* .. External Functions .. */
17116 /* .. */
17117 /* .. Executable Statements .. */
17118
17119 /* Test the input parameters. */
17120
17121 /* Parameter adjustments */
17122 --ap;
17123 --afp;
17124 b_dim1 = *ldb;
17125 b_offset = 1 + b_dim1;
17126 b -= b_offset;
17127 x_dim1 = *ldx;
17128 x_offset = 1 + x_dim1;
17129 x -= x_offset;
17130 --ferr;
17131 --berr;
17132 --work;
17133 --iwork;
17134
17135 /* Function Body */
17136 *info = 0;
17137 upper = lsame_(uplo, "U");
17138 if (! upper && ! lsame_(uplo, "L")) {
17139 *info = -1;
17140 } else if (*n < 0) {
17141 *info = -2;
17142 } else if (*nrhs < 0) {
17143 *info = -3;
17144 } else if (*ldb < std::max(1_integer,*n)) {
17145 *info = -7;
17146 } else if (*ldx < std::max(1_integer,*n)) {
17147 *info = -9;
17148 }
17149 if (*info != 0) {
17150 i__1 = -(*info);
17151 xerbla_("DPPRFS", &i__1);
17152 return 0;
17153 }
17154
17155 /* Quick return if possible */
17156
17157 if (*n == 0 || *nrhs == 0) {
17158 i__1 = *nrhs;
17159 for (j = 1; j <= i__1; ++j) {
17160 ferr[j] = 0.;
17161 berr[j] = 0.;
17162 /* L10: */
17163 }
17164 return 0;
17165 }
17166
17167 /* NZ = maximum number of nonzero elements in each row of A, plus 1 */
17168
17169 nz = *n + 1;
17170 eps = dlamch_("Epsilon");
17171 safmin = dlamch_("Safe minimum");
17172 safe1 = nz * safmin;
17173 safe2 = safe1 / eps;
17174
17175 /* Do for each right hand side */
17176
17177 i__1 = *nrhs;
17178 for (j = 1; j <= i__1; ++j) {
17179
17180 count = 1;
17181 lstres = 3.;
17182 L20:
17183
17184 /* Loop until stopping criterion is satisfied. */
17185
17186 /* Compute residual R = B - A * X */
17187
17188 dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
17189 dspmv_(uplo, n, &c_b12, &ap[1], &x[j * x_dim1 + 1], &c__1, &c_b14, &
17190 work[*n + 1], &c__1);
17191
17192 /* Compute componentwise relative backward error from formula */
17193
17194 /* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
17195
17196 /* where abs(Z) is the componentwise absolute value of the matrix */
17197 /* or vector Z. If the i-th component of the denominator is less */
17198 /* than SAFE2, then SAFE1 is added to the i-th components of the */
17199 /* numerator and denominator before dividing. */
17200
17201 i__2 = *n;
17202 for (i__ = 1; i__ <= i__2; ++i__) {
17203 work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
17204 /* L30: */
17205 }
17206
17207 /* Compute abs(A)*abs(X) + abs(B). */
17208
17209 kk = 1;
17210 if (upper) {
17211 i__2 = *n;
17212 for (k = 1; k <= i__2; ++k) {
17213 s = 0.;
17214 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
17215 ik = kk;
17216 i__3 = k - 1;
17217 for (i__ = 1; i__ <= i__3; ++i__) {
17218 work[i__] += (d__1 = ap[ik], abs(d__1)) * xk;
17219 s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j *
17220 x_dim1], abs(d__2));
17221 ++ik;
17222 /* L40: */
17223 }
17224 work[k] = work[k] + (d__1 = ap[kk + k - 1], abs(d__1)) * xk +
17225 s;
17226 kk += k;
17227 /* L50: */
17228 }
17229 } else {
17230 i__2 = *n;
17231 for (k = 1; k <= i__2; ++k) {
17232 s = 0.;
17233 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
17234 work[k] += (d__1 = ap[kk], abs(d__1)) * xk;
17235 ik = kk + 1;
17236 i__3 = *n;
17237 for (i__ = k + 1; i__ <= i__3; ++i__) {
17238 work[i__] += (d__1 = ap[ik], abs(d__1)) * xk;
17239 s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j *
17240 x_dim1], abs(d__2));
17241 ++ik;
17242 /* L60: */
17243 }
17244 work[k] += s;
17245 kk += *n - k + 1;
17246 /* L70: */
17247 }
17248 }
17249 s = 0.;
17250 i__2 = *n;
17251 for (i__ = 1; i__ <= i__2; ++i__) {
17252 if (work[i__] > safe2) {
17253 /* Computing MAX */
17254 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
17255 i__];
17256 s = std::max(d__2,d__3);
17257 } else {
17258 /* Computing MAX */
17259 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1)
17260 / (work[i__] + safe1);
17261 s = std::max(d__2,d__3);
17262 }
17263 /* L80: */
17264 }
17265 berr[j] = s;
17266
17267 /* Test stopping criterion. Continue iterating if */
17268 /* 1) The residual BERR(J) is larger than machine epsilon, and */
17269 /* 2) BERR(J) decreased by at least a factor of 2 during the */
17270 /* last iteration, and */
17271 /* 3) At most ITMAX iterations tried. */
17272
17273 if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
17274
17275 /* Update solution and try again. */
17276
17277 dpptrs_(uplo, n, &c__1, &afp[1], &work[*n + 1], n, info);
17278 daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
17279 ;
17280 lstres = berr[j];
17281 ++count;
17282 goto L20;
17283 }
17284
17285 /* Bound error from formula */
17286
17287 /* norm(X - XTRUE) / norm(X) .le. FERR = */
17288 /* norm( abs(inv(A))* */
17289 /* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
17290
17291 /* where */
17292 /* norm(Z) is the magnitude of the largest component of Z */
17293 /* inv(A) is the inverse of A */
17294 /* abs(Z) is the componentwise absolute value of the matrix or */
17295 /* vector Z */
17296 /* NZ is the maximum number of nonzeros in any row of A, plus 1 */
17297 /* EPS is machine epsilon */
17298
17299 /* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
17300 /* is incremented by SAFE1 if the i-th component of */
17301 /* abs(A)*abs(X) + abs(B) is less than SAFE2. */
17302
17303 /* Use DLACN2 to estimate the infinity-norm of the matrix */
17304 /* inv(A) * diag(W), */
17305 /* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
17306
17307 i__2 = *n;
17308 for (i__ = 1; i__ <= i__2; ++i__) {
17309 if (work[i__] > safe2) {
17310 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
17311 work[i__];
17312 } else {
17313 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
17314 work[i__] + safe1;
17315 }
17316 /* L90: */
17317 }
17318
17319 kase = 0;
17320 L100:
17321 dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
17322 kase, isave);
17323 if (kase != 0) {
17324 if (kase == 1) {
17325
17326 /* Multiply by diag(W)*inv(A'). */
17327
17328 dpptrs_(uplo, n, &c__1, &afp[1], &work[*n + 1], n, info);
17329 i__2 = *n;
17330 for (i__ = 1; i__ <= i__2; ++i__) {
17331 work[*n + i__] = work[i__] * work[*n + i__];
17332 /* L110: */
17333 }
17334 } else if (kase == 2) {
17335
17336 /* Multiply by inv(A)*diag(W). */
17337
17338 i__2 = *n;
17339 for (i__ = 1; i__ <= i__2; ++i__) {
17340 work[*n + i__] = work[i__] * work[*n + i__];
17341 /* L120: */
17342 }
17343 dpptrs_(uplo, n, &c__1, &afp[1], &work[*n + 1], n, info);
17344 }
17345 goto L100;
17346 }
17347
17348 /* Normalize error. */
17349
17350 lstres = 0.;
17351 i__2 = *n;
17352 for (i__ = 1; i__ <= i__2; ++i__) {
17353 /* Computing MAX */
17354 d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
17355 lstres = std::max(d__2,d__3);
17356 /* L130: */
17357 }
17358 if (lstres != 0.) {
17359 ferr[j] /= lstres;
17360 }
17361
17362 /* L140: */
17363 }
17364
17365 return 0;
17366
17367 /* End of DPPRFS */
17368
17369 } /* dpprfs_ */
17370
17371 /* Subroutine */ int dppsv_(const char *uplo, integer *n, integer *nrhs, double
17372 *ap, double *b, integer *ldb, integer *info)
17373 {
17374 /* System generated locals */
17375 integer b_dim1, b_offset, i__1;
17376
17377 /* -- LAPACK driver routine (version 3.1) -- */
17378 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
17379 /* November 2006 */
17380
17381 /* .. Scalar Arguments .. */
17382 /* .. */
17383 /* .. Array Arguments .. */
17384 /* .. */
17385
17386 /* Purpose */
17387 /* ======= */
17388
17389 /* DPPSV computes the solution to a real system of linear equations */
17390 /* A * X = B, */
17391 /* where A is an N-by-N symmetric positive definite matrix stored in */
17392 /* packed format and X and B are N-by-NRHS matrices. */
17393
17394 /* The Cholesky decomposition is used to factor A as */
17395 /* A = U**T* U, if UPLO = 'U', or */
17396 /* A = L * L**T, if UPLO = 'L', */
17397 /* where U is an upper triangular matrix and L is a lower triangular */
17398 /* matrix. The factored form of A is then used to solve the system of */
17399 /* equations A * X = B. */
17400
17401 /* Arguments */
17402 /* ========= */
17403
17404 /* UPLO (input) CHARACTER*1 */
17405 /* = 'U': Upper triangle of A is stored; */
17406 /* = 'L': Lower triangle of A is stored. */
17407
17408 /* N (input) INTEGER */
17409 /* The number of linear equations, i.e., the order of the */
17410 /* matrix A. N >= 0. */
17411
17412 /* NRHS (input) INTEGER */
17413 /* The number of right hand sides, i.e., the number of columns */
17414 /* of the matrix B. NRHS >= 0. */
17415
17416 /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
17417 /* On entry, the upper or lower triangle of the symmetric matrix */
17418 /* A, packed columnwise in a linear array. The j-th column of A */
17419 /* is stored in the array AP as follows: */
17420 /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
17421 /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
17422 /* See below for further details. */
17423
17424 /* On exit, if INFO = 0, the factor U or L from the Cholesky */
17425 /* factorization A = U**T*U or A = L*L**T, in the same storage */
17426 /* format as A. */
17427
17428 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
17429 /* On entry, the N-by-NRHS right hand side matrix B. */
17430 /* On exit, if INFO = 0, the N-by-NRHS solution matrix X. */
17431
17432 /* LDB (input) INTEGER */
17433 /* The leading dimension of the array B. LDB >= max(1,N). */
17434
17435 /* INFO (output) INTEGER */
17436 /* = 0: successful exit */
17437 /* < 0: if INFO = -i, the i-th argument had an illegal value */
17438 /* > 0: if INFO = i, the leading minor of order i of A is not */
17439 /* positive definite, so the factorization could not be */
17440 /* completed, and the solution has not been computed. */
17441
17442 /* Further Details */
17443 /* =============== */
17444
17445 /* The packed storage scheme is illustrated by the following example */
17446 /* when N = 4, UPLO = 'U': */
17447
17448 /* Two-dimensional storage of the symmetric matrix A: */
17449
17450 /* a11 a12 a13 a14 */
17451 /* a22 a23 a24 */
17452 /* a33 a34 (aij = conjg(aji)) */
17453 /* a44 */
17454
17455 /* Packed storage of the upper triangle of A: */
17456
17457 /* AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] */
17458
17459 /* ===================================================================== */
17460
17461 /* .. External Functions .. */
17462 /* .. */
17463 /* .. External Subroutines .. */
17464 /* .. */
17465 /* .. Intrinsic Functions .. */
17466 /* .. */
17467 /* .. Executable Statements .. */
17468
17469 /* Test the input parameters. */
17470
17471 /* Parameter adjustments */
17472 --ap;
17473 b_dim1 = *ldb;
17474 b_offset = 1 + b_dim1;
17475 b -= b_offset;
17476
17477 /* Function Body */
17478 *info = 0;
17479 if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
17480 *info = -1;
17481 } else if (*n < 0) {
17482 *info = -2;
17483 } else if (*nrhs < 0) {
17484 *info = -3;
17485 } else if (*ldb < std::max(1_integer,*n)) {
17486 *info = -6;
17487 }
17488 if (*info != 0) {
17489 i__1 = -(*info);
17490 xerbla_("DPPSV ", &i__1);
17491 return 0;
17492 }
17493
17494 /* Compute the Cholesky factorization A = U'*U or A = L*L'. */
17495
17496 dpptrf_(uplo, n, &ap[1], info);
17497 if (*info == 0) {
17498
17499 /* Solve the system A*X = B, overwriting B with X. */
17500
17501 dpptrs_(uplo, n, nrhs, &ap[1], &b[b_offset], ldb, info);
17502
17503 }
17504 return 0;
17505
17506 /* End of DPPSV */
17507
17508 } /* dppsv_ */
17509
17510 /* Subroutine */ int dppsvx_(const char *fact, const char *uplo, integer *n, integer *
17511 nrhs, double *ap, double *afp, char *equed, double *s,
17512 double *b, integer *ldb, double *x, integer *ldx, double *
17513 rcond, double *ferr, double *berr, double *work, integer *
17514 iwork, integer *info)
17515 {
17516 /* Table of constant values */
17517 static integer c__1 = 1;
17518
17519 /* System generated locals */
17520 integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2;
17521 double d__1, d__2;
17522
17523 /* Local variables */
17524 integer i__, j;
17525 double amax, smin, smax;
17526 double scond, anorm;
17527 bool equil, rcequ;
17528 bool nofact;
17529 double bignum;
17530 integer infequ;
17531 double smlnum;
17532
17533 /* -- LAPACK driver routine (version 3.1) -- */
17534 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
17535 /* November 2006 */
17536
17537 /* .. Scalar Arguments .. */
17538 /* .. */
17539 /* .. Array Arguments .. */
17540 /* .. */
17541
17542 /* Purpose */
17543 /* ======= */
17544
17545 /* DPPSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to */
17546 /* compute the solution to a real system of linear equations */
17547 /* A * X = B, */
17548 /* where A is an N-by-N symmetric positive definite matrix stored in */
17549 /* packed format and X and B are N-by-NRHS matrices. */
17550
17551 /* Error bounds on the solution and a condition estimate are also */
17552 /* provided. */
17553
17554 /* Description */
17555 /* =========== */
17556
17557 /* The following steps are performed: */
17558
17559 /* 1. If FACT = 'E', real scaling factors are computed to equilibrate */
17560 /* the system: */
17561 /* diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B */
17562 /* Whether or not the system will be equilibrated depends on the */
17563 /* scaling of the matrix A, but if equilibration is used, A is */
17564 /* overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */
17565
17566 /* 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to */
17567 /* factor the matrix A (after equilibration if FACT = 'E') as */
17568 /* A = U**T* U, if UPLO = 'U', or */
17569 /* A = L * L**T, if UPLO = 'L', */
17570 /* where U is an upper triangular matrix and L is a lower triangular */
17571 /* matrix. */
17572
17573 /* 3. If the leading i-by-i principal minor is not positive definite, */
17574 /* then the routine returns with INFO = i. Otherwise, the factored */
17575 /* form of A is used to estimate the condition number of the matrix */
17576 /* A. If the reciprocal of the condition number is less than machine */
17577 /* precision, INFO = N+1 is returned as a warning, but the routine */
17578 /* still goes on to solve for X and compute error bounds as */
17579 /* described below. */
17580
17581 /* 4. The system of equations is solved for X using the factored form */
17582 /* of A. */
17583
17584 /* 5. Iterative refinement is applied to improve the computed solution */
17585 /* matrix and calculate error bounds and backward error estimates */
17586 /* for it. */
17587
17588 /* 6. If equilibration was used, the matrix X is premultiplied by */
17589 /* diag(S) so that it solves the original system before */
17590 /* equilibration. */
17591
17592 /* Arguments */
17593 /* ========= */
17594
17595 /* FACT (input) CHARACTER*1 */
17596 /* Specifies whether or not the factored form of the matrix A is */
17597 /* supplied on entry, and if not, whether the matrix A should be */
17598 /* equilibrated before it is factored. */
17599 /* = 'F': On entry, AFP contains the factored form of A. */
17600 /* If EQUED = 'Y', the matrix A has been equilibrated */
17601 /* with scaling factors given by S. AP and AFP will not */
17602 /* be modified. */
17603 /* = 'N': The matrix A will be copied to AFP and factored. */
17604 /* = 'E': The matrix A will be equilibrated if necessary, then */
17605 /* copied to AFP and factored. */
17606
17607 /* UPLO (input) CHARACTER*1 */
17608 /* = 'U': Upper triangle of A is stored; */
17609 /* = 'L': Lower triangle of A is stored. */
17610
17611 /* N (input) INTEGER */
17612 /* The number of linear equations, i.e., the order of the */
17613 /* matrix A. N >= 0. */
17614
17615 /* NRHS (input) INTEGER */
17616 /* The number of right hand sides, i.e., the number of columns */
17617 /* of the matrices B and X. NRHS >= 0. */
17618
17619 /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
17620 /* On entry, the upper or lower triangle of the symmetric matrix */
17621 /* A, packed columnwise in a linear array, except if FACT = 'F' */
17622 /* and EQUED = 'Y', then A must contain the equilibrated matrix */
17623 /* diag(S)*A*diag(S). The j-th column of A is stored in the */
17624 /* array AP as follows: */
17625 /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
17626 /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
17627 /* See below for further details. A is not modified if */
17628 /* FACT = 'F' or 'N', or if FACT = 'E' and EQUED = 'N' on exit. */
17629
17630 /* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */
17631 /* diag(S)*A*diag(S). */
17632
17633 /* AFP (input or output) DOUBLE PRECISION array, dimension */
17634 /* (N*(N+1)/2) */
17635 /* If FACT = 'F', then AFP is an input argument and on entry */
17636 /* contains the triangular factor U or L from the Cholesky */
17637 /* factorization A = U'*U or A = L*L', in the same storage */
17638 /* format as A. If EQUED .ne. 'N', then AFP is the factored */
17639 /* form of the equilibrated matrix A. */
17640
17641 /* If FACT = 'N', then AFP is an output argument and on exit */
17642 /* returns the triangular factor U or L from the Cholesky */
17643 /* factorization A = U'*U or A = L*L' of the original matrix A. */
17644
17645 /* If FACT = 'E', then AFP is an output argument and on exit */
17646 /* returns the triangular factor U or L from the Cholesky */
17647 /* factorization A = U'*U or A = L*L' of the equilibrated */
17648 /* matrix A (see the description of AP for the form of the */
17649 /* equilibrated matrix). */
17650
17651 /* EQUED (input or output) CHARACTER*1 */
17652 /* Specifies the form of equilibration that was done. */
17653 /* = 'N': No equilibration (always true if FACT = 'N'). */
17654 /* = 'Y': Equilibration was done, i.e., A has been replaced by */
17655 /* diag(S) * A * diag(S). */
17656 /* EQUED is an input argument if FACT = 'F'; otherwise, it is an */
17657 /* output argument. */
17658
17659 /* S (input or output) DOUBLE PRECISION array, dimension (N) */
17660 /* The scale factors for A; not accessed if EQUED = 'N'. S is */
17661 /* an input argument if FACT = 'F'; otherwise, S is an output */
17662 /* argument. If FACT = 'F' and EQUED = 'Y', each element of S */
17663 /* must be positive. */
17664
17665 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
17666 /* On entry, the N-by-NRHS right hand side matrix B. */
17667 /* On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', */
17668 /* B is overwritten by diag(S) * B. */
17669
17670 /* LDB (input) INTEGER */
17671 /* The leading dimension of the array B. LDB >= max(1,N). */
17672
17673 /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
17674 /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to */
17675 /* the original system of equations. Note that if EQUED = 'Y', */
17676 /* A and B are modified on exit, and the solution to the */
17677 /* equilibrated system is inv(diag(S))*X. */
17678
17679 /* LDX (input) INTEGER */
17680 /* The leading dimension of the array X. LDX >= max(1,N). */
17681
17682 /* RCOND (output) DOUBLE PRECISION */
17683 /* The estimate of the reciprocal condition number of the matrix */
17684 /* A after equilibration (if done). If RCOND is less than the */
17685 /* machine precision (in particular, if RCOND = 0), the matrix */
17686 /* is singular to working precision. This condition is */
17687 /* indicated by a return code of INFO > 0. */
17688
17689 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
17690 /* The estimated forward error bound for each solution vector */
17691 /* X(j) (the j-th column of the solution matrix X). */
17692 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
17693 /* is an estimated upper bound for the magnitude of the largest */
17694 /* element in (X(j) - XTRUE) divided by the magnitude of the */
17695 /* largest element in X(j). The estimate is as reliable as */
17696 /* the estimate for RCOND, and is almost always a slight */
17697 /* overestimate of the true error. */
17698
17699 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
17700 /* The componentwise relative backward error of each solution */
17701 /* vector X(j) (i.e., the smallest relative change in */
17702 /* any element of A or B that makes X(j) an exact solution). */
17703
17704 /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
17705
17706 /* IWORK (workspace) INTEGER array, dimension (N) */
17707
17708 /* INFO (output) INTEGER */
17709 /* = 0: successful exit */
17710 /* < 0: if INFO = -i, the i-th argument had an illegal value */
17711 /* > 0: if INFO = i, and i is */
17712 /* <= N: the leading minor of order i of A is */
17713 /* not positive definite, so the factorization */
17714 /* could not be completed, and the solution has not */
17715 /* been computed. RCOND = 0 is returned. */
17716 /* = N+1: U is nonsingular, but RCOND is less than machine */
17717 /* precision, meaning that the matrix is singular */
17718 /* to working precision. Nevertheless, the */
17719 /* solution and error bounds are computed because */
17720 /* there are a number of situations where the */
17721 /* computed solution can be more accurate than the */
17722 /* value of RCOND would suggest. */
17723
17724 /* Further Details */
17725 /* =============== */
17726
17727 /* The packed storage scheme is illustrated by the following example */
17728 /* when N = 4, UPLO = 'U': */
17729
17730 /* Two-dimensional storage of the symmetric matrix A: */
17731
17732 /* a11 a12 a13 a14 */
17733 /* a22 a23 a24 */
17734 /* a33 a34 (aij = conjg(aji)) */
17735 /* a44 */
17736
17737 /* Packed storage of the upper triangle of A: */
17738
17739 /* AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] */
17740
17741 /* ===================================================================== */
17742
17743 /* .. Parameters .. */
17744 /* .. */
17745 /* .. Local Scalars .. */
17746 /* .. */
17747 /* .. External Functions .. */
17748 /* .. */
17749 /* .. External Subroutines .. */
17750 /* .. */
17751 /* .. Intrinsic Functions .. */
17752 /* .. */
17753 /* .. Executable Statements .. */
17754
17755 /* Parameter adjustments */
17756 --ap;
17757 --afp;
17758 --s;
17759 b_dim1 = *ldb;
17760 b_offset = 1 + b_dim1;
17761 b -= b_offset;
17762 x_dim1 = *ldx;
17763 x_offset = 1 + x_dim1;
17764 x -= x_offset;
17765 --ferr;
17766 --berr;
17767 --work;
17768 --iwork;
17769
17770 /* Function Body */
17771 *info = 0;
17772 nofact = lsame_(fact, "N");
17773 equil = lsame_(fact, "E");
17774 if (nofact || equil) {
17775 *(unsigned char *)equed = 'N';
17776 rcequ = false;
17777 } else {
17778 rcequ = lsame_(equed, "Y");
17779 smlnum = dlamch_("Safe minimum");
17780 bignum = 1. / smlnum;
17781 }
17782
17783 /* Test the input parameters. */
17784
17785 if (! nofact && ! equil && ! lsame_(fact, "F")) {
17786 *info = -1;
17787 } else if (! lsame_(uplo, "U") && ! lsame_(uplo,
17788 "L")) {
17789 *info = -2;
17790 } else if (*n < 0) {
17791 *info = -3;
17792 } else if (*nrhs < 0) {
17793 *info = -4;
17794 } else if (lsame_(fact, "F") && ! (rcequ || lsame_(
17795 equed, "N"))) {
17796 *info = -7;
17797 } else {
17798 if (rcequ) {
17799 smin = bignum;
17800 smax = 0.;
17801 i__1 = *n;
17802 for (j = 1; j <= i__1; ++j) {
17803 /* Computing MIN */
17804 d__1 = smin, d__2 = s[j];
17805 smin = std::min(d__1,d__2);
17806 /* Computing MAX */
17807 d__1 = smax, d__2 = s[j];
17808 smax = std::max(d__1,d__2);
17809 /* L10: */
17810 }
17811 if (smin <= 0.) {
17812 *info = -8;
17813 } else if (*n > 0) {
17814 scond = std::max(smin,smlnum) / std::min(smax,bignum);
17815 } else {
17816 scond = 1.;
17817 }
17818 }
17819 if (*info == 0) {
17820 if (*ldb < std::max(1_integer,*n)) {
17821 *info = -10;
17822 } else if (*ldx < std::max(1_integer,*n)) {
17823 *info = -12;
17824 }
17825 }
17826 }
17827
17828 if (*info != 0) {
17829 i__1 = -(*info);
17830 xerbla_("DPPSVX", &i__1);
17831 return 0;
17832 }
17833
17834 if (equil) {
17835
17836 /* Compute row and column scalings to equilibrate the matrix A. */
17837
17838 dppequ_(uplo, n, &ap[1], &s[1], &scond, &amax, &infequ);
17839 if (infequ == 0) {
17840
17841 /* Equilibrate the matrix. */
17842
17843 dlaqsp_(uplo, n, &ap[1], &s[1], &scond, &amax, equed);
17844 rcequ = lsame_(equed, "Y");
17845 }
17846 }
17847
17848 /* Scale the right-hand side. */
17849
17850 if (rcequ) {
17851 i__1 = *nrhs;
17852 for (j = 1; j <= i__1; ++j) {
17853 i__2 = *n;
17854 for (i__ = 1; i__ <= i__2; ++i__) {
17855 b[i__ + j * b_dim1] = s[i__] * b[i__ + j * b_dim1];
17856 /* L20: */
17857 }
17858 /* L30: */
17859 }
17860 }
17861
17862 if (nofact || equil) {
17863
17864 /* Compute the Cholesky factorization A = U'*U or A = L*L'. */
17865
17866 i__1 = *n * (*n + 1) / 2;
17867 dcopy_(&i__1, &ap[1], &c__1, &afp[1], &c__1);
17868 dpptrf_(uplo, n, &afp[1], info);
17869
17870 /* Return if INFO is non-zero. */
17871
17872 if (*info > 0) {
17873 *rcond = 0.;
17874 return 0;
17875 }
17876 }
17877
17878 /* Compute the norm of the matrix A. */
17879
17880 anorm = dlansp_("I", uplo, n, &ap[1], &work[1]);
17881
17882 /* Compute the reciprocal of the condition number of A. */
17883
17884 dppcon_(uplo, n, &afp[1], &anorm, rcond, &work[1], &iwork[1], info);
17885
17886 /* Compute the solution matrix X. */
17887
17888 dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
17889 dpptrs_(uplo, n, nrhs, &afp[1], &x[x_offset], ldx, info);
17890
17891 /* Use iterative refinement to improve the computed solution and */
17892 /* compute error bounds and backward error estimates for it. */
17893
17894 dpprfs_(uplo, n, nrhs, &ap[1], &afp[1], &b[b_offset], ldb, &x[x_offset],
17895 ldx, &ferr[1], &berr[1], &work[1], &iwork[1], info);
17896
17897 /* Transform the solution matrix X to a solution of the original */
17898 /* system. */
17899
17900 if (rcequ) {
17901 i__1 = *nrhs;
17902 for (j = 1; j <= i__1; ++j) {
17903 i__2 = *n;
17904 for (i__ = 1; i__ <= i__2; ++i__) {
17905 x[i__ + j * x_dim1] = s[i__] * x[i__ + j * x_dim1];
17906 /* L40: */
17907 }
17908 /* L50: */
17909 }
17910 i__1 = *nrhs;
17911 for (j = 1; j <= i__1; ++j) {
17912 ferr[j] /= scond;
17913 /* L60: */
17914 }
17915 }
17916
17917 /* Set INFO = N+1 if the matrix is singular to working precision. */
17918
17919 if (*rcond < dlamch_("Epsilon")) {
17920 *info = *n + 1;
17921 }
17922
17923 return 0;
17924
17925 /* End of DPPSVX */
17926
17927 } /* dppsvx_ */
17928
17929 /* Subroutine */ int dpptrf_(const char *uplo, integer *n, double *ap, integer *
17930 info)
17931 {
17932 /* Table of constant values */
17933 static integer c__1 = 1;
17934 static double c_b16 = -1.;
17935
17936 /* System generated locals */
17937 integer i__1, i__2;
17938 double d__1;
17939
17940 /* Local variables */
17941 integer j, jc, jj;
17942 double ajj;
17943 bool upper;
17944
17945
17946 /* -- LAPACK routine (version 3.1) -- */
17947 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
17948 /* November 2006 */
17949
17950 /* .. Scalar Arguments .. */
17951 /* .. */
17952 /* .. Array Arguments .. */
17953 /* .. */
17954
17955 /* Purpose */
17956 /* ======= */
17957
17958 /* DPPTRF computes the Cholesky factorization of a real symmetric */
17959 /* positive definite matrix A stored in packed format. */
17960
17961 /* The factorization has the form */
17962 /* A = U**T * U, if UPLO = 'U', or */
17963 /* A = L * L**T, if UPLO = 'L', */
17964 /* where U is an upper triangular matrix and L is lower triangular. */
17965
17966 /* Arguments */
17967 /* ========= */
17968
17969 /* UPLO (input) CHARACTER*1 */
17970 /* = 'U': Upper triangle of A is stored; */
17971 /* = 'L': Lower triangle of A is stored. */
17972
17973 /* N (input) INTEGER */
17974 /* The order of the matrix A. N >= 0. */
17975
17976 /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
17977 /* On entry, the upper or lower triangle of the symmetric matrix */
17978 /* A, packed columnwise in a linear array. The j-th column of A */
17979 /* is stored in the array AP as follows: */
17980 /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
17981 /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
17982 /* See below for further details. */
17983
17984 /* On exit, if INFO = 0, the triangular factor U or L from the */
17985 /* Cholesky factorization A = U**T*U or A = L*L**T, in the same */
17986 /* storage format as A. */
17987
17988 /* INFO (output) INTEGER */
17989 /* = 0: successful exit */
17990 /* < 0: if INFO = -i, the i-th argument had an illegal value */
17991 /* > 0: if INFO = i, the leading minor of order i is not */
17992 /* positive definite, and the factorization could not be */
17993 /* completed. */
17994
17995 /* Further Details */
17996 /* ======= ======= */
17997
17998 /* The packed storage scheme is illustrated by the following example */
17999 /* when N = 4, UPLO = 'U': */
18000
18001 /* Two-dimensional storage of the symmetric matrix A: */
18002
18003 /* a11 a12 a13 a14 */
18004 /* a22 a23 a24 */
18005 /* a33 a34 (aij = aji) */
18006 /* a44 */
18007
18008 /* Packed storage of the upper triangle of A: */
18009
18010 /* AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ] */
18011
18012 /* ===================================================================== */
18013
18014 /* .. Parameters .. */
18015 /* .. */
18016 /* .. Local Scalars .. */
18017 /* .. */
18018 /* .. External Functions .. */
18019 /* .. */
18020 /* .. External Subroutines .. */
18021 /* .. */
18022 /* .. Intrinsic Functions .. */
18023 /* .. */
18024 /* .. Executable Statements .. */
18025
18026 /* Test the input parameters. */
18027
18028 /* Parameter adjustments */
18029 --ap;
18030
18031 /* Function Body */
18032 *info = 0;
18033 upper = lsame_(uplo, "U");
18034 if (! upper && ! lsame_(uplo, "L")) {
18035 *info = -1;
18036 } else if (*n < 0) {
18037 *info = -2;
18038 }
18039 if (*info != 0) {
18040 i__1 = -(*info);
18041 xerbla_("DPPTRF", &i__1);
18042 return 0;
18043 }
18044
18045 /* Quick return if possible */
18046
18047 if (*n == 0) {
18048 return 0;
18049 }
18050
18051 if (upper) {
18052
18053 /* Compute the Cholesky factorization A = U'*U. */
18054
18055 jj = 0;
18056 i__1 = *n;
18057 for (j = 1; j <= i__1; ++j) {
18058 jc = jj + 1;
18059 jj += j;
18060
18061 /* Compute elements 1:J-1 of column J. */
18062
18063 if (j > 1) {
18064 i__2 = j - 1;
18065 dtpsv_("Upper", "Transpose", "Non-unit", &i__2, &ap[1], &ap[
18066 jc], &c__1);
18067 }
18068
18069 /* Compute U(J,J) and test for non-positive-definiteness. */
18070
18071 i__2 = j - 1;
18072 ajj = ap[jj] - ddot_(&i__2, &ap[jc], &c__1, &ap[jc], &c__1);
18073 if (ajj <= 0.) {
18074 ap[jj] = ajj;
18075 goto L30;
18076 }
18077 ap[jj] = sqrt(ajj);
18078 /* L10: */
18079 }
18080 } else {
18081
18082 /* Compute the Cholesky factorization A = L*L'. */
18083
18084 jj = 1;
18085 i__1 = *n;
18086 for (j = 1; j <= i__1; ++j) {
18087
18088 /* Compute L(J,J) and test for non-positive-definiteness. */
18089
18090 ajj = ap[jj];
18091 if (ajj <= 0.) {
18092 ap[jj] = ajj;
18093 goto L30;
18094 }
18095 ajj = sqrt(ajj);
18096 ap[jj] = ajj;
18097
18098 /* Compute elements J+1:N of column J and update the trailing */
18099 /* submatrix. */
18100
18101 if (j < *n) {
18102 i__2 = *n - j;
18103 d__1 = 1. / ajj;
18104 dscal_(&i__2, &d__1, &ap[jj + 1], &c__1);
18105 i__2 = *n - j;
18106 dspr_("Lower", &i__2, &c_b16, &ap[jj + 1], &c__1, &ap[jj + *n
18107 - j + 1]);
18108 jj = jj + *n - j + 1;
18109 }
18110 /* L20: */
18111 }
18112 }
18113 goto L40;
18114
18115 L30:
18116 *info = j;
18117
18118 L40:
18119 return 0;
18120
18121 /* End of DPPTRF */
18122
18123 } /* dpptrf_ */
18124
18125 /* Subroutine */ int dpptri_(const char *uplo, integer *n, double *ap, integer *
18126 info)
18127 {
18128 /* Table of constant values */
18129 static double c_b8 = 1.;
18130 static integer c__1 = 1;
18131
18132 /* System generated locals */
18133 integer i__1, i__2;
18134
18135 /* Local variables */
18136 integer j, jc, jj;
18137 double ajj;
18138 integer jjn;
18139 bool upper;
18140
18141
18142 /* -- LAPACK routine (version 3.1) -- */
18143 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
18144 /* November 2006 */
18145
18146 /* .. Scalar Arguments .. */
18147 /* .. */
18148 /* .. Array Arguments .. */
18149 /* .. */
18150
18151 /* Purpose */
18152 /* ======= */
18153
18154 /* DPPTRI computes the inverse of a real symmetric positive definite */
18155 /* matrix A using the Cholesky factorization A = U**T*U or A = L*L**T */
18156 /* computed by DPPTRF. */
18157
18158 /* Arguments */
18159 /* ========= */
18160
18161 /* UPLO (input) CHARACTER*1 */
18162 /* = 'U': Upper triangular factor is stored in AP; */
18163 /* = 'L': Lower triangular factor is stored in AP. */
18164
18165 /* N (input) INTEGER */
18166 /* The order of the matrix A. N >= 0. */
18167
18168 /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
18169 /* On entry, the triangular factor U or L from the Cholesky */
18170 /* factorization A = U**T*U or A = L*L**T, packed columnwise as */
18171 /* a linear array. The j-th column of U or L is stored in the */
18172 /* array AP as follows: */
18173 /* if UPLO = 'U', AP(i + (j-1)*j/2) = U(i,j) for 1<=i<=j; */
18174 /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = L(i,j) for j<=i<=n. */
18175
18176 /* On exit, the upper or lower triangle of the (symmetric) */
18177 /* inverse of A, overwriting the input factor U or L. */
18178
18179 /* INFO (output) INTEGER */
18180 /* = 0: successful exit */
18181 /* < 0: if INFO = -i, the i-th argument had an illegal value */
18182 /* > 0: if INFO = i, the (i,i) element of the factor U or L is */
18183 /* zero, and the inverse could not be computed. */
18184
18185 /* ===================================================================== */
18186
18187 /* .. Parameters .. */
18188 /* .. */
18189 /* .. Local Scalars .. */
18190 /* .. */
18191 /* .. External Functions .. */
18192 /* .. */
18193 /* .. External Subroutines .. */
18194 /* .. */
18195 /* .. Executable Statements .. */
18196
18197 /* Test the input parameters. */
18198
18199 /* Parameter adjustments */
18200 --ap;
18201
18202 /* Function Body */
18203 *info = 0;
18204 upper = lsame_(uplo, "U");
18205 if (! upper && ! lsame_(uplo, "L")) {
18206 *info = -1;
18207 } else if (*n < 0) {
18208 *info = -2;
18209 }
18210 if (*info != 0) {
18211 i__1 = -(*info);
18212 xerbla_("DPPTRI", &i__1);
18213 return 0;
18214 }
18215
18216 /* Quick return if possible */
18217
18218 if (*n == 0) {
18219 return 0;
18220 }
18221
18222 /* Invert the triangular Cholesky factor U or L. */
18223
18224 dtptri_(uplo, "Non-unit", n, &ap[1], info);
18225 if (*info > 0) {
18226 return 0;
18227 }
18228
18229 if (upper) {
18230
18231 /* Compute the product inv(U) * inv(U)'. */
18232
18233 jj = 0;
18234 i__1 = *n;
18235 for (j = 1; j <= i__1; ++j) {
18236 jc = jj + 1;
18237 jj += j;
18238 if (j > 1) {
18239 i__2 = j - 1;
18240 dspr_("Upper", &i__2, &c_b8, &ap[jc], &c__1, &ap[1]);
18241 }
18242 ajj = ap[jj];
18243 dscal_(&j, &ajj, &ap[jc], &c__1);
18244 /* L10: */
18245 }
18246
18247 } else {
18248
18249 /* Compute the product inv(L)' * inv(L). */
18250
18251 jj = 1;
18252 i__1 = *n;
18253 for (j = 1; j <= i__1; ++j) {
18254 jjn = jj + *n - j + 1;
18255 i__2 = *n - j + 1;
18256 ap[jj] = ddot_(&i__2, &ap[jj], &c__1, &ap[jj], &c__1);
18257 if (j < *n) {
18258 i__2 = *n - j;
18259 dtpmv_("Lower", "Transpose", "Non-unit", &i__2, &ap[jjn], &ap[
18260 jj + 1], &c__1);
18261 }
18262 jj = jjn;
18263 /* L20: */
18264 }
18265 }
18266
18267 return 0;
18268
18269 /* End of DPPTRI */
18270
18271 } /* dpptri_ */
18272
18273 /* Subroutine */ int dpptrs_(const char *uplo, integer *n, integer *nrhs,
18274 double *ap, double *b, integer *ldb, integer *info)
18275 {
18276 /* Table of constant values */
18277 static integer c__1 = 1;
18278
18279 /* System generated locals */
18280 integer b_dim1, b_offset, i__1;
18281
18282 /* Local variables */
18283 integer i__;
18284 bool upper;
18285
18286
18287 /* -- LAPACK routine (version 3.1) -- */
18288 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
18289 /* November 2006 */
18290
18291 /* .. Scalar Arguments .. */
18292 /* .. */
18293 /* .. Array Arguments .. */
18294 /* .. */
18295
18296 /* Purpose */
18297 /* ======= */
18298
18299 /* DPPTRS solves a system of linear equations A*X = B with a symmetric */
18300 /* positive definite matrix A in packed storage using the Cholesky */
18301 /* factorization A = U**T*U or A = L*L**T computed by DPPTRF. */
18302
18303 /* Arguments */
18304 /* ========= */
18305
18306 /* UPLO (input) CHARACTER*1 */
18307 /* = 'U': Upper triangle of A is stored; */
18308 /* = 'L': Lower triangle of A is stored. */
18309
18310 /* N (input) INTEGER */
18311 /* The order of the matrix A. N >= 0. */
18312
18313 /* NRHS (input) INTEGER */
18314 /* The number of right hand sides, i.e., the number of columns */
18315 /* of the matrix B. NRHS >= 0. */
18316
18317 /* AP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
18318 /* The triangular factor U or L from the Cholesky factorization */
18319 /* A = U**T*U or A = L*L**T, packed columnwise in a linear */
18320 /* array. The j-th column of U or L is stored in the array AP */
18321 /* as follows: */
18322 /* if UPLO = 'U', AP(i + (j-1)*j/2) = U(i,j) for 1<=i<=j; */
18323 /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = L(i,j) for j<=i<=n. */
18324
18325 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
18326 /* On entry, the right hand side matrix B. */
18327 /* On exit, the solution matrix X. */
18328
18329 /* LDB (input) INTEGER */
18330 /* The leading dimension of the array B. LDB >= max(1,N). */
18331
18332 /* INFO (output) INTEGER */
18333 /* = 0: successful exit */
18334 /* < 0: if INFO = -i, the i-th argument had an illegal value */
18335
18336 /* ===================================================================== */
18337
18338 /* .. Local Scalars .. */
18339 /* .. */
18340 /* .. External Functions .. */
18341 /* .. */
18342 /* .. External Subroutines .. */
18343 /* .. */
18344 /* .. Intrinsic Functions .. */
18345 /* .. */
18346 /* .. Executable Statements .. */
18347
18348 /* Test the input parameters. */
18349
18350 /* Parameter adjustments */
18351 --ap;
18352 b_dim1 = *ldb;
18353 b_offset = 1 + b_dim1;
18354 b -= b_offset;
18355
18356 /* Function Body */
18357 *info = 0;
18358 upper = lsame_(uplo, "U");
18359 if (! upper && ! lsame_(uplo, "L")) {
18360 *info = -1;
18361 } else if (*n < 0) {
18362 *info = -2;
18363 } else if (*nrhs < 0) {
18364 *info = -3;
18365 } else if (*ldb < std::max(1_integer,*n)) {
18366 *info = -6;
18367 }
18368 if (*info != 0) {
18369 i__1 = -(*info);
18370 xerbla_("DPPTRS", &i__1);
18371 return 0;
18372 }
18373
18374 /* Quick return if possible */
18375
18376 if (*n == 0 || *nrhs == 0) {
18377 return 0;
18378 }
18379
18380 if (upper) {
18381
18382 /* Solve A*X = B where A = U'*U. */
18383
18384 i__1 = *nrhs;
18385 for (i__ = 1; i__ <= i__1; ++i__) {
18386
18387 /* Solve U'*X = B, overwriting B with X. */
18388
18389 dtpsv_("Upper", "Transpose", "Non-unit", n, &ap[1], &b[i__ *
18390 b_dim1 + 1], &c__1);
18391
18392 /* Solve U*X = B, overwriting B with X. */
18393
18394 dtpsv_("Upper", "No transpose", "Non-unit", n, &ap[1], &b[i__ *
18395 b_dim1 + 1], &c__1);
18396 /* L10: */
18397 }
18398 } else {
18399
18400 /* Solve A*X = B where A = L*L'. */
18401
18402 i__1 = *nrhs;
18403 for (i__ = 1; i__ <= i__1; ++i__) {
18404
18405 /* Solve L*Y = B, overwriting B with X. */
18406
18407 dtpsv_("Lower", "No transpose", "Non-unit", n, &ap[1], &b[i__ *
18408 b_dim1 + 1], &c__1);
18409
18410 /* Solve L'*X = Y, overwriting B with X. */
18411
18412 dtpsv_("Lower", "Transpose", "Non-unit", n, &ap[1], &b[i__ *
18413 b_dim1 + 1], &c__1);
18414 /* L20: */
18415 }
18416 }
18417
18418 return 0;
18419
18420 /* End of DPPTRS */
18421
18422 } /* dpptrs_ */
18423
18424 #if 0
18425 int dpstf2_(const char *uplo, integer *n, double *a, integer *lda, integer *piv, integer *rank,
18426 double *tol, double *work, integer *info)
18427 {
18428 /* Table of constant values */
18429 static integer c__1 = 1;
18430 static double c_b16 = -1.;
18431 static double c_b18 = 1.;
18432
18433 /* System generated locals */
18434 integer a_dim1, a_offset, i__1, i__2, i__3;
18435 double d__1;
18436
18437 /* Local variables */
18438 integer i__, j, maxlocval;
18439 double ajj;
18440 integer pvt;
18441 double dtemp;
18442 integer itemp;
18443 double dstop;
18444 bool upper;
18445
18446
18447 /* -- LAPACK PROTOTYPE routine (version 3.2) -- */
18448 /* Craig Lucas, University of Manchester / NAG Ltd. */
18449 /* October, 2008 */
18450
18451 /* .. Scalar Arguments .. */
18452 /* .. */
18453 /* .. Array Arguments .. */
18454 /* .. */
18455
18456 /* Purpose */
18457 /* ======= */
18458
18459 /* DPSTF2 computes the Cholesky factorization with complete */
18460 /* pivoting of a real symmetric positive semidefinite matrix A. */
18461
18462 /* The factorization has the form */
18463 /* P' * A * P = U' * U , if UPLO = 'U', */
18464 /* P' * A * P = L * L', if UPLO = 'L', */
18465 /* where U is an upper triangular matrix and L is lower triangular, and */
18466 /* P is stored as vector PIV. */
18467
18468 /* This algorithm does not attempt to check that A is positive */
18469 /* semidefinite. This version of the algorithm calls level 2 BLAS. */
18470
18471 /* Arguments */
18472 /* ========= */
18473
18474 /* UPLO (input) CHARACTER*1 */
18475 /* Specifies whether the upper or lower triangular part of the */
18476 /* symmetric matrix A is stored. */
18477 /* = 'U': Upper triangular */
18478 /* = 'L': Lower triangular */
18479
18480 /* N (input) INTEGER */
18481 /* The order of the matrix A. N >= 0. */
18482
18483 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
18484 /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
18485 /* n by n upper triangular part of A contains the upper */
18486 /* triangular part of the matrix A, and the strictly lower */
18487 /* triangular part of A is not referenced. If UPLO = 'L', the */
18488 /* leading n by n lower triangular part of A contains the lower */
18489 /* triangular part of the matrix A, and the strictly upper */
18490 /* triangular part of A is not referenced. */
18491
18492 /* On exit, if INFO = 0, the factor U or L from the Cholesky */
18493 /* factorization as above. */
18494
18495 /* PIV (output) INTEGER array, dimension (N) */
18496 /* PIV is such that the nonzero entries are P( PIV(K), K ) = 1. */
18497
18498 /* RANK (output) INTEGER */
18499 /* The rank of A given by the number of steps the algorithm */
18500 /* completed. */
18501
18502 /* TOL (input) DOUBLE PRECISION */
18503 /* User defined tolerance. If TOL < 0, then N*U*MAX( A( K,K ) ) */
18504 /* will be used. The algorithm terminates at the (K-1)st step */
18505 /* if the pivot <= TOL. */
18506
18507 /* LDA (input) INTEGER */
18508 /* The leading dimension of the array A. LDA >= max(1,N). */
18509
18510 /* WORK DOUBLE PRECISION array, dimension (2*N) */
18511 /* Work space. */
18512
18513 /* INFO (output) INTEGER */
18514 /* < 0: If INFO = -K, the K-th argument had an illegal value, */
18515 /* = 0: algorithm completed successfully, and */
18516 /* > 0: the matrix A is either rank deficient with computed rank */
18517 /* as returned in RANK, or is indefinite. See Section 7 of */
18518 /* LAPACK Working Note #161 for further information. */
18519
18520 /* ===================================================================== */
18521
18522 /* .. Parameters .. */
18523 /* .. */
18524 /* .. Local Scalars .. */
18525 /* .. */
18526 /* .. External Functions .. */
18527 /* .. */
18528 /* .. External Subroutines .. */
18529 /* .. */
18530 /* .. Intrinsic Functions .. */
18531 /* .. */
18532 /* .. Executable Statements .. */
18533
18534 /* Test the input parameters */
18535
18536 /* Parameter adjustments */
18537 --work;
18538 --piv;
18539 a_dim1 = *lda;
18540 a_offset = 1 + a_dim1;
18541 a -= a_offset;
18542
18543 /* Function Body */
18544 *info = 0;
18545 upper = lsame_(uplo, "U");
18546 if (! upper && ! lsame_(uplo, "L")) {
18547 *info = -1;
18548 } else if (*n < 0) {
18549 *info = -2;
18550 } else if (*lda < std::max(1_integer,*n)) {
18551 *info = -4;
18552 }
18553 if (*info != 0) {
18554 i__1 = -(*info);
18555 xerbla_("DPSTF2", &i__1);
18556 return 0;
18557 }
18558
18559 /* Quick return if possible */
18560
18561 if (*n == 0) {
18562 return 0;
18563 }
18564
18565 /* Initialize PIV */
18566
18567 i__1 = *n;
18568 for (i__ = 1; i__ <= i__1; ++i__) {
18569 piv[i__] = i__;
18570 /* L100: */
18571 }
18572
18573 /* Compute stopping value */
18574
18575 pvt = 1;
18576 ajj = a[pvt + pvt * a_dim1];
18577 i__1 = *n;
18578 for (i__ = 2; i__ <= i__1; ++i__) {
18579 if (a[i__ + i__ * a_dim1] > ajj) {
18580 pvt = i__;
18581 ajj = a[pvt + pvt * a_dim1];
18582 }
18583 }
18584 if (ajj == 0. || disnan_(&ajj)) {
18585 *rank = 0;
18586 *info = 1;
18587 goto L170;
18588 }
18589
18590 /* Compute stopping value if not supplied */
18591
18592 if (*tol < 0.) {
18593 dstop = *n * dlamch_("Epsilon") * ajj;
18594 } else {
18595 dstop = *tol;
18596 }
18597
18598 /* Set first half of WORK to zero, holds dot products */
18599
18600 i__1 = *n;
18601 for (i__ = 1; i__ <= i__1; ++i__) {
18602 work[i__] = 0.;
18603 /* L110: */
18604 }
18605
18606 if (upper) {
18607
18608 /* Compute the Cholesky factorization P' * A * P = U' * U */
18609
18610 i__1 = *n;
18611 for (j = 1; j <= i__1; ++j) {
18612
18613 /* Find pivot, test for exit, else swap rows and columns */
18614 /* Update dot products, compute possible pivots which are */
18615 /* stored in the second half of WORK */
18616
18617 i__2 = *n;
18618 for (i__ = j; i__ <= i__2; ++i__) {
18619
18620 if (j > 1) {
18621 /* Computing 2nd power */
18622 d__1 = a[j - 1 + i__ * a_dim1];
18623 work[i__] += d__1 * d__1;
18624 }
18625 work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
18626
18627 /* L120: */
18628 }
18629
18630 if (j > 1) {
18631 maxlocval = (*n << 1) - (*n + j) + 1;
18632 itemp = dmaxloc_(&work[*n + j], &maxlocval);
18633 pvt = itemp + j - 1;
18634 ajj = work[*n + pvt];
18635 if (ajj <= dstop || disnan_(&ajj)) {
18636 a[j + j * a_dim1] = ajj;
18637 goto L160;
18638 }
18639 }
18640
18641 if (j != pvt) {
18642
18643 /* Pivot OK, so can now swap pivot rows and columns */
18644
18645 a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
18646 i__2 = j - 1;
18647 dswap_(&i__2, &a[j * a_dim1 + 1], &c__1, &a[pvt * a_dim1 + 1],
18648 &c__1);
18649 if (pvt < *n) {
18650 i__2 = *n - pvt;
18651 dswap_(&i__2, &a[j + (pvt + 1) * a_dim1], lda, &a[pvt + (
18652 pvt + 1) * a_dim1], lda);
18653 }
18654 i__2 = pvt - j - 1;
18655 dswap_(&i__2, &a[j + (j + 1) * a_dim1], lda, &a[j + 1 + pvt *
18656 a_dim1], &c__1);
18657
18658 /* Swap dot products and PIV */
18659
18660 dtemp = work[j];
18661 work[j] = work[pvt];
18662 work[pvt] = dtemp;
18663 itemp = piv[pvt];
18664 piv[pvt] = piv[j];
18665 piv[j] = itemp;
18666 }
18667
18668 ajj = sqrt(ajj);
18669 a[j + j * a_dim1] = ajj;
18670
18671 /* Compute elements J+1:N of row J */
18672
18673 if (j < *n) {
18674 i__2 = j - 1;
18675 i__3 = *n - j;
18676 dgemv_("Trans", &i__2, &i__3, &c_b16, &a[(j + 1) * a_dim1 + 1]
18677 , lda, &a[j * a_dim1 + 1], &c__1, &c_b18, &a[j + (j +
18678 1) * a_dim1], lda);
18679 i__2 = *n - j;
18680 d__1 = 1. / ajj;
18681 dscal_(&i__2, &d__1, &a[j + (j + 1) * a_dim1], lda);
18682 }
18683
18684 /* L130: */
18685 }
18686
18687 } else {
18688
18689 /* Compute the Cholesky factorization P' * A * P = L * L' */
18690
18691 i__1 = *n;
18692 for (j = 1; j <= i__1; ++j) {
18693
18694 /* Find pivot, test for exit, else swap rows and columns */
18695 /* Update dot products, compute possible pivots which are */
18696 /* stored in the second half of WORK */
18697
18698 i__2 = *n;
18699 for (i__ = j; i__ <= i__2; ++i__) {
18700
18701 if (j > 1) {
18702 /* Computing 2nd power */
18703 d__1 = a[i__ + (j - 1) * a_dim1];
18704 work[i__] += d__1 * d__1;
18705 }
18706 work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
18707
18708 /* L140: */
18709 }
18710
18711 if (j > 1) {
18712 maxlocval = (*n << 1) - (*n + j) + 1;
18713 itemp = dmaxloc_(&work[*n + j], &maxlocval);
18714 pvt = itemp + j - 1;
18715 ajj = work[*n + pvt];
18716 if (ajj <= dstop || disnan_(&ajj)) {
18717 a[j + j * a_dim1] = ajj;
18718 goto L160;
18719 }
18720 }
18721
18722 if (j != pvt) {
18723
18724 /* Pivot OK, so can now swap pivot rows and columns */
18725
18726 a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
18727 i__2 = j - 1;
18728 dswap_(&i__2, &a[j + a_dim1], lda, &a[pvt + a_dim1], lda);
18729 if (pvt < *n) {
18730 i__2 = *n - pvt;
18731 dswap_(&i__2, &a[pvt + 1 + j * a_dim1], &c__1, &a[pvt + 1
18732 + pvt * a_dim1], &c__1);
18733 }
18734 i__2 = pvt - j - 1;
18735 dswap_(&i__2, &a[j + 1 + j * a_dim1], &c__1, &a[pvt + (j + 1)
18736 * a_dim1], lda);
18737
18738 /* Swap dot products and PIV */
18739
18740 dtemp = work[j];
18741 work[j] = work[pvt];
18742 work[pvt] = dtemp;
18743 itemp = piv[pvt];
18744 piv[pvt] = piv[j];
18745 piv[j] = itemp;
18746 }
18747
18748 ajj = sqrt(ajj);
18749 a[j + j * a_dim1] = ajj;
18750
18751 /* Compute elements J+1:N of column J */
18752
18753 if (j < *n) {
18754 i__2 = *n - j;
18755 i__3 = j - 1;
18756 dgemv_("No Trans", &i__2, &i__3, &c_b16, &a[j + 1 + a_dim1],
18757 lda, &a[j + a_dim1], lda, &c_b18, &a[j + 1 + j *
18758 a_dim1], &c__1);
18759 i__2 = *n - j;
18760 d__1 = 1. / ajj;
18761 dscal_(&i__2, &d__1, &a[j + 1 + j * a_dim1], &c__1);
18762 }
18763
18764 /* L150: */
18765 }
18766
18767 }
18768
18769 /* Ran to completion, A has full rank */
18770
18771 *rank = *n;
18772
18773 goto L170;
18774 L160:
18775
18776 /* Rank is number of steps completed. Set INFO = 1 to signal */
18777 /* that the factorization cannot be used to solve a system. */
18778
18779 *rank = j - 1;
18780 *info = 1;
18781
18782 L170:
18783 return 0;
18784
18785 /* End of DPSTF2 */
18786
18787 } /* dpstf2_ */
18788 #endif
18789
18790 #if 0
18791 int dpstrf_(const char *uplo, integer *n, double *a, integer *lda, integer *piv, integer *rank,
18792 double *tol, double *work, integer *info)
18793 {
18794 /* Table of constant values */
18795 static integer c__1 = 1;
18796 static integer c_n1 = -1;
18797 static double c_b22 = -1.;
18798 static double c_b24 = 1.;
18799
18800 /* System generated locals */
18801 integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
18802 double d__1;
18803
18804 /* Local variables */
18805 integer i__, j, k, maxlocvar, jb, nb;
18806 double ajj;
18807 integer pvt;
18808 double dtemp;
18809 integer itemp;
18810 double dstop;
18811 bool upper;
18812
18813
18814 /* -- LAPACK routine (version 3.2) -- */
18815 /* Craig Lucas, University of Manchester / NAG Ltd. */
18816 /* October, 2008 */
18817
18818 /* .. Scalar Arguments .. */
18819 /* .. */
18820 /* .. Array Arguments .. */
18821 /* .. */
18822
18823 /* Purpose */
18824 /* ======= */
18825
18826 /* DPSTRF computes the Cholesky factorization with complete */
18827 /* pivoting of a real symmetric positive semidefinite matrix A. */
18828
18829 /* The factorization has the form */
18830 /* P' * A * P = U' * U , if UPLO = 'U', */
18831 /* P' * A * P = L * L', if UPLO = 'L', */
18832 /* where U is an upper triangular matrix and L is lower triangular, and */
18833 /* P is stored as vector PIV. */
18834
18835 /* This algorithm does not attempt to check that A is positive */
18836 /* semidefinite. This version of the algorithm calls level 3 BLAS. */
18837
18838 /* Arguments */
18839 /* ========= */
18840
18841 /* UPLO (input) CHARACTER*1 */
18842 /* Specifies whether the upper or lower triangular part of the */
18843 /* symmetric matrix A is stored. */
18844 /* = 'U': Upper triangular */
18845 /* = 'L': Lower triangular */
18846
18847 /* N (input) INTEGER */
18848 /* The order of the matrix A. N >= 0. */
18849
18850 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
18851 /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
18852 /* n by n upper triangular part of A contains the upper */
18853 /* triangular part of the matrix A, and the strictly lower */
18854 /* triangular part of A is not referenced. If UPLO = 'L', the */
18855 /* leading n by n lower triangular part of A contains the lower */
18856 /* triangular part of the matrix A, and the strictly upper */
18857 /* triangular part of A is not referenced. */
18858
18859 /* On exit, if INFO = 0, the factor U or L from the Cholesky */
18860 /* factorization as above. */
18861
18862 /* LDA (input) INTEGER */
18863 /* The leading dimension of the array A. LDA >= max(1,N). */
18864
18865 /* PIV (output) INTEGER array, dimension (N) */
18866 /* PIV is such that the nonzero entries are P( PIV(K), K ) = 1. */
18867
18868 /* RANK (output) INTEGER */
18869 /* The rank of A given by the number of steps the algorithm */
18870 /* completed. */
18871
18872 /* TOL (input) DOUBLE PRECISION */
18873 /* User defined tolerance. If TOL < 0, then N*U*MAX( A(K,K) ) */
18874 /* will be used. The algorithm terminates at the (K-1)st step */
18875 /* if the pivot <= TOL. */
18876
18877 /* WORK DOUBLE PRECISION array, dimension (2*N) */
18878 /* Work space. */
18879
18880 /* INFO (output) INTEGER */
18881 /* < 0: If INFO = -K, the K-th argument had an illegal value, */
18882 /* = 0: algorithm completed successfully, and */
18883 /* > 0: the matrix A is either rank deficient with computed rank */
18884 /* as returned in RANK, or is indefinite. See Section 7 of */
18885 /* LAPACK Working Note #161 for further information. */
18886
18887 /* ===================================================================== */
18888
18889 /* .. Parameters .. */
18890 /* .. */
18891 /* .. Local Scalars .. */
18892 /* .. */
18893 /* .. External Functions .. */
18894 /* .. */
18895 /* .. External Subroutines .. */
18896 /* .. */
18897 /* .. Intrinsic Functions .. */
18898 /* .. */
18899 /* .. Executable Statements .. */
18900
18901 /* Test the input parameters. */
18902
18903 /* Parameter adjustments */
18904 --work;
18905 --piv;
18906 a_dim1 = *lda;
18907 a_offset = 1 + a_dim1;
18908 a -= a_offset;
18909
18910 /* Function Body */
18911 *info = 0;
18912 upper = lsame_(uplo, "U");
18913 if (! upper && ! lsame_(uplo, "L")) {
18914 *info = -1;
18915 } else if (*n < 0) {
18916 *info = -2;
18917 } else if (*lda < std::max(1_integer,*n)) {
18918 *info = -4;
18919 }
18920 if (*info != 0) {
18921 i__1 = -(*info);
18922 xerbla_("DPSTRF", &i__1);
18923 return 0;
18924 }
18925
18926 /* Quick return if possible */
18927
18928 if (*n == 0) {
18929 return 0;
18930 }
18931
18932 /* Get block size */
18933
18934 nb = ilaenv_(&c__1, "DPOTRF", uplo, n, &c_n1, &c_n1, &c_n1);
18935 if (nb <= 1 || nb >= *n) {
18936
18937 /* Use unblocked code */
18938
18939 dpstf2_(uplo, n, &a[a_dim1 + 1], lda, &piv[1], rank, tol, &work[1],
18940 info);
18941 goto L200;
18942
18943 } else {
18944
18945 /* Initialize PIV */
18946
18947 i__1 = *n;
18948 for (i__ = 1; i__ <= i__1; ++i__) {
18949 piv[i__] = i__;
18950 /* L100: */
18951 }
18952
18953 /* Compute stopping value */
18954
18955 pvt = 1;
18956 ajj = a[pvt + pvt * a_dim1];
18957 i__1 = *n;
18958 for (i__ = 2; i__ <= i__1; ++i__) {
18959 if (a[i__ + i__ * a_dim1] > ajj) {
18960 pvt = i__;
18961 ajj = a[pvt + pvt * a_dim1];
18962 }
18963 }
18964 if (ajj == 0. || disnan_(&ajj)) {
18965 *rank = 0;
18966 *info = 1;
18967 goto L200;
18968 }
18969
18970 /* Compute stopping value if not supplied */
18971
18972 if (*tol < 0.) {
18973 dstop = *n * dlamch_("Epsilon") * ajj;
18974 } else {
18975 dstop = *tol;
18976 }
18977
18978
18979 if (upper) {
18980
18981 /* Compute the Cholesky factorization P' * A * P = U' * U */
18982
18983 i__1 = *n;
18984 i__2 = nb;
18985 for (k = 1; i__2 < 0 ? k >= i__1 : k <= i__1; k += i__2) {
18986
18987 /* Account for last block not being NB wide */
18988
18989 /* Computing MIN */
18990 i__3 = nb, i__4 = *n - k + 1;
18991 jb = std::min(i__3,i__4);
18992
18993 /* Set relevant part of first half of WORK to zero, */
18994 /* holds dot products */
18995
18996 i__3 = *n;
18997 for (i__ = k; i__ <= i__3; ++i__) {
18998 work[i__] = 0.;
18999 /* L110: */
19000 }
19001
19002 i__3 = k + jb - 1;
19003 for (j = k; j <= i__3; ++j) {
19004
19005 /* Find pivot, test for exit, else swap rows and columns */
19006 /* Update dot products, compute possible pivots which are */
19007 /* stored in the second half of WORK */
19008
19009 i__4 = *n;
19010 for (i__ = j; i__ <= i__4; ++i__) {
19011
19012 if (j > k) {
19013 /* Computing 2nd power */
19014 d__1 = a[j - 1 + i__ * a_dim1];
19015 work[i__] += d__1 * d__1;
19016 }
19017 work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
19018
19019 /* L120: */
19020 }
19021
19022 if (j > 1) {
19023 maxlocvar = (*n << 1) - (*n + j) + 1;
19024 itemp = dmaxloc_(&work[*n + j], &maxlocvar);
19025 pvt = itemp + j - 1;
19026 ajj = work[*n + pvt];
19027 if (ajj <= dstop || disnan_(&ajj)) {
19028 a[j + j * a_dim1] = ajj;
19029 goto L190;
19030 }
19031 }
19032
19033 if (j != pvt) {
19034
19035 /* Pivot OK, so can now swap pivot rows and columns */
19036
19037 a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
19038 i__4 = j - 1;
19039 dswap_(&i__4, &a[j * a_dim1 + 1], &c__1, &a[pvt *
19040 a_dim1 + 1], &c__1);
19041 if (pvt < *n) {
19042 i__4 = *n - pvt;
19043 dswap_(&i__4, &a[j + (pvt + 1) * a_dim1], lda, &a[
19044 pvt + (pvt + 1) * a_dim1], lda);
19045 }
19046 i__4 = pvt - j - 1;
19047 dswap_(&i__4, &a[j + (j + 1) * a_dim1], lda, &a[j + 1
19048 + pvt * a_dim1], &c__1);
19049
19050 /* Swap dot products and PIV */
19051
19052 dtemp = work[j];
19053 work[j] = work[pvt];
19054 work[pvt] = dtemp;
19055 itemp = piv[pvt];
19056 piv[pvt] = piv[j];
19057 piv[j] = itemp;
19058 }
19059
19060 ajj = sqrt(ajj);
19061 a[j + j * a_dim1] = ajj;
19062
19063 /* Compute elements J+1:N of row J. */
19064
19065 if (j < *n) {
19066 i__4 = j - k;
19067 i__5 = *n - j;
19068 dgemv_("Trans", &i__4, &i__5, &c_b22, &a[k + (j + 1) *
19069 a_dim1], lda, &a[k + j * a_dim1], &c__1, &
19070 c_b24, &a[j + (j + 1) * a_dim1], lda);
19071 i__4 = *n - j;
19072 d__1 = 1. / ajj;
19073 dscal_(&i__4, &d__1, &a[j + (j + 1) * a_dim1], lda);
19074 }
19075
19076 /* L130: */
19077 }
19078
19079 /* Update trailing matrix, J already incremented */
19080
19081 if (k + jb <= *n) {
19082 i__3 = *n - j + 1;
19083 dsyrk_("Upper", "Trans", &i__3, &jb, &c_b22, &a[k + j *
19084 a_dim1], lda, &c_b24, &a[j + j * a_dim1], lda);
19085 }
19086
19087 /* L140: */
19088 }
19089
19090 } else {
19091
19092 /* Compute the Cholesky factorization P' * A * P = L * L' */
19093
19094 i__2 = *n;
19095 i__1 = nb;
19096 for (k = 1; i__1 < 0 ? k >= i__2 : k <= i__2; k += i__1) {
19097
19098 /* Account for last block not being NB wide */
19099
19100 /* Computing MIN */
19101 i__3 = nb, i__4 = *n - k + 1;
19102 jb = std::min(i__3,i__4);
19103
19104 /* Set relevant part of first half of WORK to zero, */
19105 /* holds dot products */
19106
19107 i__3 = *n;
19108 for (i__ = k; i__ <= i__3; ++i__) {
19109 work[i__] = 0.;
19110 /* L150: */
19111 }
19112
19113 i__3 = k + jb - 1;
19114 for (j = k; j <= i__3; ++j) {
19115
19116 /* Find pivot, test for exit, else swap rows and columns */
19117 /* Update dot products, compute possible pivots which are */
19118 /* stored in the second half of WORK */
19119
19120 i__4 = *n;
19121 for (i__ = j; i__ <= i__4; ++i__) {
19122
19123 if (j > k) {
19124 /* Computing 2nd power */
19125 d__1 = a[i__ + (j - 1) * a_dim1];
19126 work[i__] += d__1 * d__1;
19127 }
19128 work[*n + i__] = a[i__ + i__ * a_dim1] - work[i__];
19129
19130 /* L160: */
19131 }
19132
19133 if (j > 1) {
19134 maxlocvar = (*n << 1) - (*n + j) + 1;
19135 itemp = dmaxloc_(&work[*n + j], &maxlocvar);
19136 pvt = itemp + j - 1;
19137 ajj = work[*n + pvt];
19138 if (ajj <= dstop || disnan_(&ajj)) {
19139 a[j + j * a_dim1] = ajj;
19140 goto L190;
19141 }
19142 }
19143
19144 if (j != pvt) {
19145
19146 /* Pivot OK, so can now swap pivot rows and columns */
19147
19148 a[pvt + pvt * a_dim1] = a[j + j * a_dim1];
19149 i__4 = j - 1;
19150 dswap_(&i__4, &a[j + a_dim1], lda, &a[pvt + a_dim1],
19151 lda);
19152 if (pvt < *n) {
19153 i__4 = *n - pvt;
19154 dswap_(&i__4, &a[pvt + 1 + j * a_dim1], &c__1, &a[
19155 pvt + 1 + pvt * a_dim1], &c__1);
19156 }
19157 i__4 = pvt - j - 1;
19158 dswap_(&i__4, &a[j + 1 + j * a_dim1], &c__1, &a[pvt +
19159 (j + 1) * a_dim1], lda);
19160
19161 /* Swap dot products and PIV */
19162
19163 dtemp = work[j];
19164 work[j] = work[pvt];
19165 work[pvt] = dtemp;
19166 itemp = piv[pvt];
19167 piv[pvt] = piv[j];
19168 piv[j] = itemp;
19169 }
19170
19171 ajj = sqrt(ajj);
19172 a[j + j * a_dim1] = ajj;
19173
19174 /* Compute elements J+1:N of column J. */
19175
19176 if (j < *n) {
19177 i__4 = *n - j;
19178 i__5 = j - k;
19179 dgemv_("No Trans", &i__4, &i__5, &c_b22, &a[j + 1 + k
19180 * a_dim1], lda, &a[j + k * a_dim1], lda, &
19181 c_b24, &a[j + 1 + j * a_dim1], &c__1);
19182 i__4 = *n - j;
19183 d__1 = 1. / ajj;
19184 dscal_(&i__4, &d__1, &a[j + 1 + j * a_dim1], &c__1);
19185 }
19186
19187 /* L170: */
19188 }
19189
19190 /* Update trailing matrix, J already incremented */
19191
19192 if (k + jb <= *n) {
19193 i__3 = *n - j + 1;
19194 dsyrk_("Lower", "No Trans", &i__3, &jb, &c_b22, &a[j + k *
19195 a_dim1], lda, &c_b24, &a[j + j * a_dim1], lda);
19196 }
19197
19198 /* L180: */
19199 }
19200
19201 }
19202 }
19203
19204 /* Ran to completion, A has full rank */
19205
19206 *rank = *n;
19207
19208 goto L200;
19209 L190:
19210
19211 /* Rank is the number of steps completed. Set INFO = 1 to signal */
19212 /* that the factorization cannot be used to solve a system. */
19213
19214 *rank = j - 1;
19215 *info = 1;
19216
19217 L200:
19218 return 0;
19219
19220 /* End of DPSTRF */
19221
19222 } /* dpstrf_ */
19223 #endif
19224
19225 /* Subroutine */ int dptcon_(integer *n, double *d__, double *e,
19226 double *anorm, double *rcond, double *work, integer *info)
19227 {
19228 /* Table of constant values */
19229 static integer c__1 = 1;
19230
19231 /* System generated locals */
19232 integer i__1;
19233 double d__1;
19234
19235 /* Local variables */
19236 integer i__, ix;
19237
19238
19239 double ainvnm;
19240
19241
19242 /* -- LAPACK routine (version 3.1) -- */
19243 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
19244 /* November 2006 */
19245
19246 /* .. Scalar Arguments .. */
19247 /* .. */
19248 /* .. Array Arguments .. */
19249 /* .. */
19250
19251 /* Purpose */
19252 /* ======= */
19253
19254 /* DPTCON computes the reciprocal of the condition number (in the */
19255 /* 1-norm) of a real symmetric positive definite tridiagonal matrix */
19256 /* using the factorization A = L*D*L**T or A = U**T*D*U computed by */
19257 /* DPTTRF. */
19258
19259 /* Norm(inv(A)) is computed by a direct method, and the reciprocal of */
19260 /* the condition number is computed as */
19261 /* RCOND = 1 / (ANORM * norm(inv(A))). */
19262
19263 /* Arguments */
19264 /* ========= */
19265
19266 /* N (input) INTEGER */
19267 /* The order of the matrix A. N >= 0. */
19268
19269 /* D (input) DOUBLE PRECISION array, dimension (N) */
19270 /* The n diagonal elements of the diagonal matrix D from the */
19271 /* factorization of A, as computed by DPTTRF. */
19272
19273 /* E (input) DOUBLE PRECISION array, dimension (N-1) */
19274 /* The (n-1) off-diagonal elements of the unit bidiagonal factor */
19275 /* U or L from the factorization of A, as computed by DPTTRF. */
19276
19277 /* ANORM (input) DOUBLE PRECISION */
19278 /* The 1-norm of the original matrix A. */
19279
19280 /* RCOND (output) DOUBLE PRECISION */
19281 /* The reciprocal of the condition number of the matrix A, */
19282 /* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is the */
19283 /* 1-norm of inv(A) computed in this routine. */
19284
19285 /* WORK (workspace) DOUBLE PRECISION array, dimension (N) */
19286
19287 /* INFO (output) INTEGER */
19288 /* = 0: successful exit */
19289 /* < 0: if INFO = -i, the i-th argument had an illegal value */
19290
19291 /* Further Details */
19292 /* =============== */
19293
19294 /* The method used is described in Nicholas J. Higham, "Efficient */
19295 /* Algorithms for Computing the Condition Number of a Tridiagonal */
19296 /* Matrix", SIAM J. Sci. Stat. Comput., Vol. 7, No. 1, January 1986. */
19297
19298 /* ===================================================================== */
19299
19300 /* .. Parameters .. */
19301 /* .. */
19302 /* .. Local Scalars .. */
19303 /* .. */
19304 /* .. External Functions .. */
19305 /* .. */
19306 /* .. External Subroutines .. */
19307 /* .. */
19308 /* .. Intrinsic Functions .. */
19309 /* .. */
19310 /* .. Executable Statements .. */
19311
19312 /* Test the input arguments. */
19313
19314 /* Parameter adjustments */
19315 --work;
19316 --e;
19317 --d__;
19318
19319 /* Function Body */
19320 *info = 0;
19321 if (*n < 0) {
19322 *info = -1;
19323 } else if (*anorm < 0.) {
19324 *info = -4;
19325 }
19326 if (*info != 0) {
19327 i__1 = -(*info);
19328 xerbla_("DPTCON", &i__1);
19329 return 0;
19330 }
19331
19332 /* Quick return if possible */
19333
19334 *rcond = 0.;
19335 if (*n == 0) {
19336 *rcond = 1.;
19337 return 0;
19338 } else if (*anorm == 0.) {
19339 return 0;
19340 }
19341
19342 /* Check that D(1:N) is positive. */
19343
19344 i__1 = *n;
19345 for (i__ = 1; i__ <= i__1; ++i__) {
19346 if (d__[i__] <= 0.) {
19347 return 0;
19348 }
19349 /* L10: */
19350 }
19351
19352 /* Solve M(A) * x = e, where M(A) = (m(i,j)) is given by */
19353
19354 /* m(i,j) = abs(A(i,j)), i = j, */
19355 /* m(i,j) = -abs(A(i,j)), i .ne. j, */
19356
19357 /* and e = [ 1, 1, ..., 1 ]'. Note M(A) = M(L)*D*M(L)'. */
19358
19359 /* Solve M(L) * x = e. */
19360
19361 work[1] = 1.;
19362 i__1 = *n;
19363 for (i__ = 2; i__ <= i__1; ++i__) {
19364 work[i__] = work[i__ - 1] * (d__1 = e[i__ - 1], abs(d__1)) + 1.;
19365 /* L20: */
19366 }
19367
19368 /* Solve D * M(L)' * x = b. */
19369
19370 work[*n] /= d__[*n];
19371 for (i__ = *n - 1; i__ >= 1; --i__) {
19372 work[i__] = work[i__] / d__[i__] + work[i__ + 1] * (d__1 = e[i__],
19373 abs(d__1));
19374 /* L30: */
19375 }
19376
19377 /* Compute AINVNM = max(x(i)), 1<=i<=n. */
19378
19379 ix = idamax_(n, &work[1], &c__1);
19380 ainvnm = (d__1 = work[ix], abs(d__1));
19381
19382 /* Compute the reciprocal condition number. */
19383
19384 if (ainvnm != 0.) {
19385 *rcond = 1. / ainvnm / *anorm;
19386 }
19387
19388 return 0;
19389
19390 /* End of DPTCON */
19391
19392 } /* dptcon_ */
19393
19394 /* Subroutine */ int dpteqr_(const char *compz, integer *n, double *d__,
19395 double *e, double *z__, integer *ldz, double *work,
19396 integer *info)
19397 {
19398 /* Table of constant values */
19399 static double c_b7 = 0.;
19400 static double c_b8 = 1.;
19401 static integer c__0 = 0;
19402 static integer c__1 = 1;
19403
19404 /* System generated locals */
19405 integer z_dim1, z_offset, i__1;
19406
19407 /* Local variables */
19408 double c__[1] /* was [1][1] */;
19409 integer i__;
19410 double vt[1] /* was [1][1] */;
19411 integer nru;
19412 integer icompz;
19413
19414 /* -- LAPACK routine (version 3.1) -- */
19415 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
19416 /* November 2006 */
19417
19418 /* .. Scalar Arguments .. */
19419 /* .. */
19420 /* .. Array Arguments .. */
19421 /* .. */
19422
19423 /* Purpose */
19424 /* ======= */
19425
19426 /* DPTEQR computes all eigenvalues and, optionally, eigenvectors of a */
19427 /* symmetric positive definite tridiagonal matrix by first factoring the */
19428 /* matrix using DPTTRF, and then calling DBDSQR to compute the singular */
19429 /* values of the bidiagonal factor. */
19430
19431 /* This routine computes the eigenvalues of the positive definite */
19432 /* tridiagonal matrix to high relative accuracy. This means that if the */
19433 /* eigenvalues range over many orders of magnitude in size, then the */
19434 /* small eigenvalues and corresponding eigenvectors will be computed */
19435 /* more accurately than, for example, with the standard QR method. */
19436
19437 /* The eigenvectors of a full or band symmetric positive definite matrix */
19438 /* can also be found if DSYTRD, DSPTRD, or DSBTRD has been used to */
19439 /* reduce this matrix to tridiagonal form. (The reduction to tridiagonal */
19440 /* form, however, may preclude the possibility of obtaining high */
19441 /* relative accuracy in the small eigenvalues of the original matrix, if */
19442 /* these eigenvalues range over many orders of magnitude.) */
19443
19444 /* Arguments */
19445 /* ========= */
19446
19447 /* COMPZ (input) CHARACTER*1 */
19448 /* = 'N': Compute eigenvalues only. */
19449 /* = 'V': Compute eigenvectors of original symmetric */
19450 /* matrix also. Array Z contains the orthogonal */
19451 /* matrix used to reduce the original matrix to */
19452 /* tridiagonal form. */
19453 /* = 'I': Compute eigenvectors of tridiagonal matrix also. */
19454
19455 /* N (input) INTEGER */
19456 /* The order of the matrix. N >= 0. */
19457
19458 /* D (input/output) DOUBLE PRECISION array, dimension (N) */
19459 /* On entry, the n diagonal elements of the tridiagonal */
19460 /* matrix. */
19461 /* On normal exit, D contains the eigenvalues, in descending */
19462 /* order. */
19463
19464 /* E (input/output) DOUBLE PRECISION array, dimension (N-1) */
19465 /* On entry, the (n-1) subdiagonal elements of the tridiagonal */
19466 /* matrix. */
19467 /* On exit, E has been destroyed. */
19468
19469 /* Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N) */
19470 /* On entry, if COMPZ = 'V', the orthogonal matrix used in the */
19471 /* reduction to tridiagonal form. */
19472 /* On exit, if COMPZ = 'V', the orthonormal eigenvectors of the */
19473 /* original symmetric matrix; */
19474 /* if COMPZ = 'I', the orthonormal eigenvectors of the */
19475 /* tridiagonal matrix. */
19476 /* If INFO > 0 on exit, Z contains the eigenvectors associated */
19477 /* with only the stored eigenvalues. */
19478 /* If COMPZ = 'N', then Z is not referenced. */
19479
19480 /* LDZ (input) INTEGER */
19481 /* The leading dimension of the array Z. LDZ >= 1, and if */
19482 /* COMPZ = 'V' or 'I', LDZ >= max(1,N). */
19483
19484 /* WORK (workspace) DOUBLE PRECISION array, dimension (4*N) */
19485
19486 /* INFO (output) INTEGER */
19487 /* = 0: successful exit. */
19488 /* < 0: if INFO = -i, the i-th argument had an illegal value. */
19489 /* > 0: if INFO = i, and i is: */
19490 /* <= N the Cholesky factorization of the matrix could */
19491 /* not be performed because the i-th principal minor */
19492 /* was not positive definite. */
19493 /* > N the SVD algorithm failed to converge; */
19494 /* if INFO = N+i, i off-diagonal elements of the */
19495 /* bidiagonal factor did not converge to zero. */
19496
19497 /* ===================================================================== */
19498
19499 /* .. Parameters .. */
19500 /* .. */
19501 /* .. External Functions .. */
19502 /* .. */
19503 /* .. External Subroutines .. */
19504 /* .. */
19505 /* .. Local Arrays .. */
19506 /* .. */
19507 /* .. Local Scalars .. */
19508 /* .. */
19509 /* .. Intrinsic Functions .. */
19510 /* .. */
19511 /* .. Executable Statements .. */
19512
19513 /* Test the input parameters. */
19514
19515 /* Parameter adjustments */
19516 --d__;
19517 --e;
19518 z_dim1 = *ldz;
19519 z_offset = 1 + z_dim1;
19520 z__ -= z_offset;
19521 --work;
19522
19523 /* Function Body */
19524 *info = 0;
19525
19526 if (lsame_(compz, "N")) {
19527 icompz = 0;
19528 } else if (lsame_(compz, "V")) {
19529 icompz = 1;
19530 } else if (lsame_(compz, "I")) {
19531 icompz = 2;
19532 } else {
19533 icompz = -1;
19534 }
19535 if (icompz < 0) {
19536 *info = -1;
19537 } else if (*n < 0) {
19538 *info = -2;
19539 } else if (*ldz < 1 || icompz > 0 && *ldz < std::max(1_integer,*n)) {
19540 *info = -6;
19541 }
19542 if (*info != 0) {
19543 i__1 = -(*info);
19544 xerbla_("DPTEQR", &i__1);
19545 return 0;
19546 }
19547
19548 /* Quick return if possible */
19549
19550 if (*n == 0) {
19551 return 0;
19552 }
19553
19554 if (*n == 1) {
19555 if (icompz > 0) {
19556 z__[z_dim1 + 1] = 1.;
19557 }
19558 return 0;
19559 }
19560 if (icompz == 2) {
19561 dlaset_("Full", n, n, &c_b7, &c_b8, &z__[z_offset], ldz);
19562 }
19563
19564 /* Call DPTTRF to factor the matrix. */
19565
19566 dpttrf_(n, &d__[1], &e[1], info);
19567 if (*info != 0) {
19568 return 0;
19569 }
19570 i__1 = *n;
19571 for (i__ = 1; i__ <= i__1; ++i__) {
19572 d__[i__] = sqrt(d__[i__]);
19573 /* L10: */
19574 }
19575 i__1 = *n - 1;
19576 for (i__ = 1; i__ <= i__1; ++i__) {
19577 e[i__] *= d__[i__];
19578 /* L20: */
19579 }
19580
19581 /* Call DBDSQR to compute the singular values/vectors of the */
19582 /* bidiagonal factor. */
19583
19584 if (icompz > 0) {
19585 nru = *n;
19586 } else {
19587 nru = 0;
19588 }
19589 dbdsqr_("Lower", n, &c__0, &nru, &c__0, &d__[1], &e[1], vt, &c__1, &z__[
19590 z_offset], ldz, c__, &c__1, &work[1], info);
19591
19592 /* Square the singular values. */
19593
19594 if (*info == 0) {
19595 i__1 = *n;
19596 for (i__ = 1; i__ <= i__1; ++i__) {
19597 d__[i__] *= d__[i__];
19598 /* L30: */
19599 }
19600 } else {
19601 *info = *n + *info;
19602 }
19603
19604 return 0;
19605
19606 /* End of DPTEQR */
19607
19608 } /* dpteqr_ */
19609
19610 /* Subroutine */ int dptrfs_(integer *n, integer *nrhs, double *d__,
19611 double *e, double *df, double *ef, double *b, integer
19612 *ldb, double *x, integer *ldx, double *ferr, double *berr,
19613 double *work, integer *info)
19614 {
19615 /* Table of constant values */
19616 static integer c__1 = 1;
19617 static double c_b11 = 1.;
19618
19619 /* System generated locals */
19620 integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2;
19621 double d__1, d__2, d__3;
19622
19623 /* Local variables */
19624 integer i__, j;
19625 double s, bi, cx, dx, ex;
19626 integer ix, nz;
19627 double eps, safe1, safe2;
19628 integer count;
19629 double safmin;
19630 double lstres;
19631
19632 /* -- LAPACK routine (version 3.1) -- */
19633 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
19634 /* November 2006 */
19635
19636 /* .. Scalar Arguments .. */
19637 /* .. */
19638 /* .. Array Arguments .. */
19639 /* .. */
19640
19641 /* Purpose */
19642 /* ======= */
19643
19644 /* DPTRFS improves the computed solution to a system of linear */
19645 /* equations when the coefficient matrix is symmetric positive definite */
19646 /* and tridiagonal, and provides error bounds and backward error */
19647 /* estimates for the solution. */
19648
19649 /* Arguments */
19650 /* ========= */
19651
19652 /* N (input) INTEGER */
19653 /* The order of the matrix A. N >= 0. */
19654
19655 /* NRHS (input) INTEGER */
19656 /* The number of right hand sides, i.e., the number of columns */
19657 /* of the matrix B. NRHS >= 0. */
19658
19659 /* D (input) DOUBLE PRECISION array, dimension (N) */
19660 /* The n diagonal elements of the tridiagonal matrix A. */
19661
19662 /* E (input) DOUBLE PRECISION array, dimension (N-1) */
19663 /* The (n-1) subdiagonal elements of the tridiagonal matrix A. */
19664
19665 /* DF (input) DOUBLE PRECISION array, dimension (N) */
19666 /* The n diagonal elements of the diagonal matrix D from the */
19667 /* factorization computed by DPTTRF. */
19668
19669 /* EF (input) DOUBLE PRECISION array, dimension (N-1) */
19670 /* The (n-1) subdiagonal elements of the unit bidiagonal factor */
19671 /* L from the factorization computed by DPTTRF. */
19672
19673 /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
19674 /* The right hand side matrix B. */
19675
19676 /* LDB (input) INTEGER */
19677 /* The leading dimension of the array B. LDB >= max(1,N). */
19678
19679 /* X (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
19680 /* On entry, the solution matrix X, as computed by DPTTRS. */
19681 /* On exit, the improved solution matrix X. */
19682
19683 /* LDX (input) INTEGER */
19684 /* The leading dimension of the array X. LDX >= max(1,N). */
19685
19686 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
19687 /* The forward error bound for each solution vector */
19688 /* X(j) (the j-th column of the solution matrix X). */
19689 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
19690 /* is an estimated upper bound for the magnitude of the largest */
19691 /* element in (X(j) - XTRUE) divided by the magnitude of the */
19692 /* largest element in X(j). */
19693
19694 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
19695 /* The componentwise relative backward error of each solution */
19696 /* vector X(j) (i.e., the smallest relative change in */
19697 /* any element of A or B that makes X(j) an exact solution). */
19698
19699 /* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */
19700
19701 /* INFO (output) INTEGER */
19702 /* = 0: successful exit */
19703 /* < 0: if INFO = -i, the i-th argument had an illegal value */
19704
19705 /* Internal Parameters */
19706 /* =================== */
19707
19708 /* ITMAX is the maximum number of steps of iterative refinement. */
19709
19710 /* ===================================================================== */
19711
19712 /* .. Parameters .. */
19713 /* .. */
19714 /* .. Local Scalars .. */
19715 /* .. */
19716 /* .. External Subroutines .. */
19717 /* .. */
19718 /* .. Intrinsic Functions .. */
19719 /* .. */
19720 /* .. External Functions .. */
19721 /* .. */
19722 /* .. Executable Statements .. */
19723
19724 /* Test the input parameters. */
19725
19726 /* Parameter adjustments */
19727 --d__;
19728 --e;
19729 --df;
19730 --ef;
19731 b_dim1 = *ldb;
19732 b_offset = 1 + b_dim1;
19733 b -= b_offset;
19734 x_dim1 = *ldx;
19735 x_offset = 1 + x_dim1;
19736 x -= x_offset;
19737 --ferr;
19738 --berr;
19739 --work;
19740
19741 /* Function Body */
19742 *info = 0;
19743 if (*n < 0) {
19744 *info = -1;
19745 } else if (*nrhs < 0) {
19746 *info = -2;
19747 } else if (*ldb < std::max(1_integer,*n)) {
19748 *info = -8;
19749 } else if (*ldx < std::max(1_integer,*n)) {
19750 *info = -10;
19751 }
19752 if (*info != 0) {
19753 i__1 = -(*info);
19754 xerbla_("DPTRFS", &i__1);
19755 return 0;
19756 }
19757
19758 /* Quick return if possible */
19759
19760 if (*n == 0 || *nrhs == 0) {
19761 i__1 = *nrhs;
19762 for (j = 1; j <= i__1; ++j) {
19763 ferr[j] = 0.;
19764 berr[j] = 0.;
19765 /* L10: */
19766 }
19767 return 0;
19768 }
19769
19770 /* NZ = maximum number of nonzero elements in each row of A, plus 1 */
19771
19772 nz = 4;
19773 eps = dlamch_("Epsilon");
19774 safmin = dlamch_("Safe minimum");
19775 safe1 = nz * safmin;
19776 safe2 = safe1 / eps;
19777
19778 /* Do for each right hand side */
19779
19780 i__1 = *nrhs;
19781 for (j = 1; j <= i__1; ++j) {
19782
19783 count = 1;
19784 lstres = 3.;
19785 L20:
19786
19787 /* Loop until stopping criterion is satisfied. */
19788
19789 /* Compute residual R = B - A * X. Also compute */
19790 /* abs(A)*abs(x) + abs(b) for use in the backward error bound. */
19791
19792 if (*n == 1) {
19793 bi = b[j * b_dim1 + 1];
19794 dx = d__[1] * x[j * x_dim1 + 1];
19795 work[*n + 1] = bi - dx;
19796 work[1] = abs(bi) + abs(dx);
19797 } else {
19798 bi = b[j * b_dim1 + 1];
19799 dx = d__[1] * x[j * x_dim1 + 1];
19800 ex = e[1] * x[j * x_dim1 + 2];
19801 work[*n + 1] = bi - dx - ex;
19802 work[1] = abs(bi) + abs(dx) + abs(ex);
19803 i__2 = *n - 1;
19804 for (i__ = 2; i__ <= i__2; ++i__) {
19805 bi = b[i__ + j * b_dim1];
19806 cx = e[i__ - 1] * x[i__ - 1 + j * x_dim1];
19807 dx = d__[i__] * x[i__ + j * x_dim1];
19808 ex = e[i__] * x[i__ + 1 + j * x_dim1];
19809 work[*n + i__] = bi - cx - dx - ex;
19810 work[i__] = abs(bi) + abs(cx) + abs(dx) + abs(ex);
19811 /* L30: */
19812 }
19813 bi = b[*n + j * b_dim1];
19814 cx = e[*n - 1] * x[*n - 1 + j * x_dim1];
19815 dx = d__[*n] * x[*n + j * x_dim1];
19816 work[*n + *n] = bi - cx - dx;
19817 work[*n] = abs(bi) + abs(cx) + abs(dx);
19818 }
19819
19820 /* Compute componentwise relative backward error from formula */
19821
19822 /* max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
19823
19824 /* where abs(Z) is the componentwise absolute value of the matrix */
19825 /* or vector Z. If the i-th component of the denominator is less */
19826 /* than SAFE2, then SAFE1 is added to the i-th components of the */
19827 /* numerator and denominator before dividing. */
19828
19829 s = 0.;
19830 i__2 = *n;
19831 for (i__ = 1; i__ <= i__2; ++i__) {
19832 if (work[i__] > safe2) {
19833 /* Computing MAX */
19834 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
19835 i__];
19836 s = std::max(d__2,d__3);
19837 } else {
19838 /* Computing MAX */
19839 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1)
19840 / (work[i__] + safe1);
19841 s = std::max(d__2,d__3);
19842 }
19843 /* L40: */
19844 }
19845 berr[j] = s;
19846
19847 /* Test stopping criterion. Continue iterating if */
19848 /* 1) The residual BERR(J) is larger than machine epsilon, and */
19849 /* 2) BERR(J) decreased by at least a factor of 2 during the */
19850 /* last iteration, and */
19851 /* 3) At most ITMAX iterations tried. */
19852
19853 if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
19854
19855 /* Update solution and try again. */
19856
19857 dpttrs_(n, &c__1, &df[1], &ef[1], &work[*n + 1], n, info);
19858 daxpy_(n, &c_b11, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
19859 ;
19860 lstres = berr[j];
19861 ++count;
19862 goto L20;
19863 }
19864
19865 /* Bound error from formula */
19866
19867 /* norm(X - XTRUE) / norm(X) .le. FERR = */
19868 /* norm( abs(inv(A))* */
19869 /* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
19870
19871 /* where */
19872 /* norm(Z) is the magnitude of the largest component of Z */
19873 /* inv(A) is the inverse of A */
19874 /* abs(Z) is the componentwise absolute value of the matrix or */
19875 /* vector Z */
19876 /* NZ is the maximum number of nonzeros in any row of A, plus 1 */
19877 /* EPS is machine epsilon */
19878
19879 /* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
19880 /* is incremented by SAFE1 if the i-th component of */
19881 /* abs(A)*abs(X) + abs(B) is less than SAFE2. */
19882
19883 i__2 = *n;
19884 for (i__ = 1; i__ <= i__2; ++i__) {
19885 if (work[i__] > safe2) {
19886 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
19887 work[i__];
19888 } else {
19889 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps *
19890 work[i__] + safe1;
19891 }
19892 /* L50: */
19893 }
19894 ix = idamax_(n, &work[1], &c__1);
19895 ferr[j] = work[ix];
19896
19897 /* Estimate the norm of inv(A). */
19898
19899 /* Solve M(A) * x = e, where M(A) = (m(i,j)) is given by */
19900
19901 /* m(i,j) = abs(A(i,j)), i = j, */
19902 /* m(i,j) = -abs(A(i,j)), i .ne. j, */
19903
19904 /* and e = [ 1, 1, ..., 1 ]'. Note M(A) = M(L)*D*M(L)'. */
19905
19906 /* Solve M(L) * x = e. */
19907
19908 work[1] = 1.;
19909 i__2 = *n;
19910 for (i__ = 2; i__ <= i__2; ++i__) {
19911 work[i__] = work[i__ - 1] * (d__1 = ef[i__ - 1], abs(d__1)) + 1.;
19912 /* L60: */
19913 }
19914
19915 /* Solve D * M(L)' * x = b. */
19916
19917 work[*n] /= df[*n];
19918 for (i__ = *n - 1; i__ >= 1; --i__) {
19919 work[i__] = work[i__] / df[i__] + work[i__ + 1] * (d__1 = ef[i__],
19920 abs(d__1));
19921 /* L70: */
19922 }
19923
19924 /* Compute norm(inv(A)) = max(x(i)), 1<=i<=n. */
19925
19926 ix = idamax_(n, &work[1], &c__1);
19927 ferr[j] *= (d__1 = work[ix], abs(d__1));
19928
19929 /* Normalize error. */
19930
19931 lstres = 0.;
19932 i__2 = *n;
19933 for (i__ = 1; i__ <= i__2; ++i__) {
19934 /* Computing MAX */
19935 d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
19936 lstres = std::max(d__2,d__3);
19937 /* L80: */
19938 }
19939 if (lstres != 0.) {
19940 ferr[j] /= lstres;
19941 }
19942
19943 /* L90: */
19944 }
19945
19946 return 0;
19947
19948 /* End of DPTRFS */
19949
19950 } /* dptrfs_ */
19951
19952 /* Subroutine */ int dptsv_(integer *n, integer *nrhs, double *d__,
19953 double *e, double *b, integer *ldb, integer *info)
19954 {
19955 /* System generated locals */
19956 integer b_dim1, b_offset, i__1;
19957
19958 /* -- LAPACK routine (version 3.1) -- */
19959 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
19960 /* November 2006 */
19961
19962 /* .. Scalar Arguments .. */
19963 /* .. */
19964 /* .. Array Arguments .. */
19965 /* .. */
19966
19967 /* Purpose */
19968 /* ======= */
19969
19970 /* DPTSV computes the solution to a real system of linear equations */
19971 /* A*X = B, where A is an N-by-N symmetric positive definite tridiagonal */
19972 /* matrix, and X and B are N-by-NRHS matrices. */
19973
19974 /* A is factored as A = L*D*L**T, and the factored form of A is then */
19975 /* used to solve the system of equations. */
19976
19977 /* Arguments */
19978 /* ========= */
19979
19980 /* N (input) INTEGER */
19981 /* The order of the matrix A. N >= 0. */
19982
19983 /* NRHS (input) INTEGER */
19984 /* The number of right hand sides, i.e., the number of columns */
19985 /* of the matrix B. NRHS >= 0. */
19986
19987 /* D (input/output) DOUBLE PRECISION array, dimension (N) */
19988 /* On entry, the n diagonal elements of the tridiagonal matrix */
19989 /* A. On exit, the n diagonal elements of the diagonal matrix */
19990 /* D from the factorization A = L*D*L**T. */
19991
19992 /* E (input/output) DOUBLE PRECISION array, dimension (N-1) */
19993 /* On entry, the (n-1) subdiagonal elements of the tridiagonal */
19994 /* matrix A. On exit, the (n-1) subdiagonal elements of the */
19995 /* unit bidiagonal factor L from the L*D*L**T factorization of */
19996 /* A. (E can also be regarded as the superdiagonal of the unit */
19997 /* bidiagonal factor U from the U**T*D*U factorization of A.) */
19998
19999 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
20000 /* On entry, the N-by-NRHS right hand side matrix B. */
20001 /* On exit, if INFO = 0, the N-by-NRHS solution matrix X. */
20002
20003 /* LDB (input) INTEGER */
20004 /* The leading dimension of the array B. LDB >= max(1,N). */
20005
20006 /* INFO (output) INTEGER */
20007 /* = 0: successful exit */
20008 /* < 0: if INFO = -i, the i-th argument had an illegal value */
20009 /* > 0: if INFO = i, the leading minor of order i is not */
20010 /* positive definite, and the solution has not been */
20011 /* computed. The factorization has not been completed */
20012 /* unless i = N. */
20013
20014 /* ===================================================================== */
20015
20016 /* .. External Subroutines .. */
20017 /* .. */
20018 /* .. Intrinsic Functions .. */
20019 /* .. */
20020 /* .. Executable Statements .. */
20021
20022 /* Test the input parameters. */
20023
20024 /* Parameter adjustments */
20025 --d__;
20026 --e;
20027 b_dim1 = *ldb;
20028 b_offset = 1 + b_dim1;
20029 b -= b_offset;
20030
20031 /* Function Body */
20032 *info = 0;
20033 if (*n < 0) {
20034 *info = -1;
20035 } else if (*nrhs < 0) {
20036 *info = -2;
20037 } else if (*ldb < std::max(1_integer,*n)) {
20038 *info = -6;
20039 }
20040 if (*info != 0) {
20041 i__1 = -(*info);
20042 xerbla_("DPTSV ", &i__1);
20043 return 0;
20044 }
20045
20046 /* Compute the L*D*L' (or U'*D*U) factorization of A. */
20047
20048 dpttrf_(n, &d__[1], &e[1], info);
20049 if (*info == 0) {
20050
20051 /* Solve the system A*X = B, overwriting B with X. */
20052
20053 dpttrs_(n, nrhs, &d__[1], &e[1], &b[b_offset], ldb, info);
20054 }
20055 return 0;
20056
20057 /* End of DPTSV */
20058
20059 } /* dptsv_ */
20060
20061 /* Subroutine */ int dptsvx_(const char *fact, integer *n, integer *nrhs,
20062 double *d__, double *e, double *df, double *ef,
20063 double *b, integer *ldb, double *x, integer *ldx, double *
20064 rcond, double *ferr, double *berr, double *work, integer *
20065 info)
20066 {
20067 /* Table of constant values */
20068 static integer c__1 = 1;
20069
20070 /* System generated locals */
20071 integer b_dim1, b_offset, x_dim1, x_offset, i__1;
20072
20073 /* Local variables */
20074 double anorm;
20075 bool nofact;
20076
20077 /* -- LAPACK routine (version 3.1) -- */
20078 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
20079 /* November 2006 */
20080
20081 /* .. Scalar Arguments .. */
20082 /* .. */
20083 /* .. Array Arguments .. */
20084 /* .. */
20085
20086 /* Purpose */
20087 /* ======= */
20088
20089 /* DPTSVX uses the factorization A = L*D*L**T to compute the solution */
20090 /* to a real system of linear equations A*X = B, where A is an N-by-N */
20091 /* symmetric positive definite tridiagonal matrix and X and B are */
20092 /* N-by-NRHS matrices. */
20093
20094 /* Error bounds on the solution and a condition estimate are also */
20095 /* provided. */
20096
20097 /* Description */
20098 /* =========== */
20099
20100 /* The following steps are performed: */
20101
20102 /* 1. If FACT = 'N', the matrix A is factored as A = L*D*L**T, where L */
20103 /* is a unit lower bidiagonal matrix and D is diagonal. The */
20104 /* factorization can also be regarded as having the form */
20105 /* A = U**T*D*U. */
20106
20107 /* 2. If the leading i-by-i principal minor is not positive definite, */
20108 /* then the routine returns with INFO = i. Otherwise, the factored */
20109 /* form of A is used to estimate the condition number of the matrix */
20110 /* A. If the reciprocal of the condition number is less than machine */
20111 /* precision, INFO = N+1 is returned as a warning, but the routine */
20112 /* still goes on to solve for X and compute error bounds as */
20113 /* described below. */
20114
20115 /* 3. The system of equations is solved for X using the factored form */
20116 /* of A. */
20117
20118 /* 4. Iterative refinement is applied to improve the computed solution */
20119 /* matrix and calculate error bounds and backward error estimates */
20120 /* for it. */
20121
20122 /* Arguments */
20123 /* ========= */
20124
20125 /* FACT (input) CHARACTER*1 */
20126 /* Specifies whether or not the factored form of A has been */
20127 /* supplied on entry. */
20128 /* = 'F': On entry, DF and EF contain the factored form of A. */
20129 /* D, E, DF, and EF will not be modified. */
20130 /* = 'N': The matrix A will be copied to DF and EF and */
20131 /* factored. */
20132
20133 /* N (input) INTEGER */
20134 /* The order of the matrix A. N >= 0. */
20135
20136 /* NRHS (input) INTEGER */
20137 /* The number of right hand sides, i.e., the number of columns */
20138 /* of the matrices B and X. NRHS >= 0. */
20139
20140 /* D (input) DOUBLE PRECISION array, dimension (N) */
20141 /* The n diagonal elements of the tridiagonal matrix A. */
20142
20143 /* E (input) DOUBLE PRECISION array, dimension (N-1) */
20144 /* The (n-1) subdiagonal elements of the tridiagonal matrix A. */
20145
20146 /* DF (input or output) DOUBLE PRECISION array, dimension (N) */
20147 /* If FACT = 'F', then DF is an input argument and on entry */
20148 /* contains the n diagonal elements of the diagonal matrix D */
20149 /* from the L*D*L**T factorization of A. */
20150 /* If FACT = 'N', then DF is an output argument and on exit */
20151 /* contains the n diagonal elements of the diagonal matrix D */
20152 /* from the L*D*L**T factorization of A. */
20153
20154 /* EF (input or output) DOUBLE PRECISION array, dimension (N-1) */
20155 /* If FACT = 'F', then EF is an input argument and on entry */
20156 /* contains the (n-1) subdiagonal elements of the unit */
20157 /* bidiagonal factor L from the L*D*L**T factorization of A. */
20158 /* If FACT = 'N', then EF is an output argument and on exit */
20159 /* contains the (n-1) subdiagonal elements of the unit */
20160 /* bidiagonal factor L from the L*D*L**T factorization of A. */
20161
20162 /* B (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
20163 /* The N-by-NRHS right hand side matrix B. */
20164
20165 /* LDB (input) INTEGER */
20166 /* The leading dimension of the array B. LDB >= max(1,N). */
20167
20168 /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
20169 /* If INFO = 0 of INFO = N+1, the N-by-NRHS solution matrix X. */
20170
20171 /* LDX (input) INTEGER */
20172 /* The leading dimension of the array X. LDX >= max(1,N). */
20173
20174 /* RCOND (output) DOUBLE PRECISION */
20175 /* The reciprocal condition number of the matrix A. If RCOND */
20176 /* is less than the machine precision (in particular, if */
20177 /* RCOND = 0), the matrix is singular to working precision. */
20178 /* This condition is indicated by a return code of INFO > 0. */
20179
20180 /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
20181 /* The forward error bound for each solution vector */
20182 /* X(j) (the j-th column of the solution matrix X). */
20183 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
20184 /* is an estimated upper bound for the magnitude of the largest */
20185 /* element in (X(j) - XTRUE) divided by the magnitude of the */
20186 /* largest element in X(j). */
20187
20188 /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
20189 /* The componentwise relative backward error of each solution */
20190 /* vector X(j) (i.e., the smallest relative change in any */
20191 /* element of A or B that makes X(j) an exact solution). */
20192
20193 /* WORK (workspace) DOUBLE PRECISION array, dimension (2*N) */
20194
20195 /* INFO (output) INTEGER */
20196 /* = 0: successful exit */
20197 /* < 0: if INFO = -i, the i-th argument had an illegal value */
20198 /* > 0: if INFO = i, and i is */
20199 /* <= N: the leading minor of order i of A is */
20200 /* not positive definite, so the factorization */
20201 /* could not be completed, and the solution has not */
20202 /* been computed. RCOND = 0 is returned. */
20203 /* = N+1: U is nonsingular, but RCOND is less than machine */
20204 /* precision, meaning that the matrix is singular */
20205 /* to working precision. Nevertheless, the */
20206 /* solution and error bounds are computed because */
20207 /* there are a number of situations where the */
20208 /* computed solution can be more accurate than the */
20209 /* value of RCOND would suggest. */
20210
20211 /* ===================================================================== */
20212
20213 /* .. Parameters .. */
20214 /* .. */
20215 /* .. Local Scalars .. */
20216 /* .. */
20217 /* .. External Functions .. */
20218 /* .. */
20219 /* .. External Subroutines .. */
20220 /* .. */
20221 /* .. Intrinsic Functions .. */
20222 /* .. */
20223 /* .. Executable Statements .. */
20224
20225 /* Test the input parameters. */
20226
20227 /* Parameter adjustments */
20228 --d__;
20229 --e;
20230 --df;
20231 --ef;
20232 b_dim1 = *ldb;
20233 b_offset = 1 + b_dim1;
20234 b -= b_offset;
20235 x_dim1 = *ldx;
20236 x_offset = 1 + x_dim1;
20237 x -= x_offset;
20238 --ferr;
20239 --berr;
20240 --work;
20241
20242 /* Function Body */
20243 *info = 0;
20244 nofact = lsame_(fact, "N");
20245 if (! nofact && ! lsame_(fact, "F")) {
20246 *info = -1;
20247 } else if (*n < 0) {
20248 *info = -2;
20249 } else if (*nrhs < 0) {
20250 *info = -3;
20251 } else if (*ldb < std::max(1_integer,*n)) {
20252 *info = -9;
20253 } else if (*ldx < std::max(1_integer,*n)) {
20254 *info = -11;
20255 }
20256 if (*info != 0) {
20257 i__1 = -(*info);
20258 xerbla_("DPTSVX", &i__1);
20259 return 0;
20260 }
20261
20262 if (nofact) {
20263
20264 /* Compute the L*D*L' (or U'*D*U) factorization of A. */
20265
20266 dcopy_(n, &d__[1], &c__1, &df[1], &c__1);
20267 if (*n > 1) {
20268 i__1 = *n - 1;
20269 dcopy_(&i__1, &e[1], &c__1, &ef[1], &c__1);
20270 }
20271 dpttrf_(n, &df[1], &ef[1], info);
20272
20273 /* Return if INFO is non-zero. */
20274
20275 if (*info > 0) {
20276 *rcond = 0.;
20277 return 0;
20278 }
20279 }
20280
20281 /* Compute the norm of the matrix A. */
20282
20283 anorm = dlanst_("1", n, &d__[1], &e[1]);
20284
20285 /* Compute the reciprocal of the condition number of A. */
20286
20287 dptcon_(n, &df[1], &ef[1], &anorm, rcond, &work[1], info);
20288
20289 /* Compute the solution vectors X. */
20290
20291 dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
20292 dpttrs_(n, nrhs, &df[1], &ef[1], &x[x_offset], ldx, info);
20293
20294 /* Use iterative refinement to improve the computed solutions and */
20295 /* compute error bounds and backward error estimates for them. */
20296
20297 dptrfs_(n, nrhs, &d__[1], &e[1], &df[1], &ef[1], &b[b_offset], ldb, &x[
20298 x_offset], ldx, &ferr[1], &berr[1], &work[1], info);
20299
20300 /* Set INFO = N+1 if the matrix is singular to working precision. */
20301
20302 if (*rcond < dlamch_("Epsilon")) {
20303 *info = *n + 1;
20304 }
20305
20306 return 0;
20307
20308 /* End of DPTSVX */
20309
20310 } /* dptsvx_ */
20311
20312 /* Subroutine */ int dpttrf_(integer *n, double *d__, double *e,
20313 integer *info)
20314 {
20315 /* System generated locals */
20316 integer i__1;
20317
20318 /* Local variables */
20319 integer i__, i4;
20320 double ei;
20321
20322
20323
20324 /* -- LAPACK routine (version 3.1) -- */
20325 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
20326 /* November 2006 */
20327
20328 /* .. Scalar Arguments .. */
20329 /* .. */
20330 /* .. Array Arguments .. */
20331 /* .. */
20332
20333 /* Purpose */
20334 /* ======= */
20335
20336 /* DPTTRF computes the L*D*L' factorization of a real symmetric */
20337 /* positive definite tridiagonal matrix A. The factorization may also */
20338 /* be regarded as having the form A = U'*D*U. */
20339
20340 /* Arguments */
20341 /* ========= */
20342
20343 /* N (input) INTEGER */
20344 /* The order of the matrix A. N >= 0. */
20345
20346 /* D (input/output) DOUBLE PRECISION array, dimension (N) */
20347 /* On entry, the n diagonal elements of the tridiagonal matrix */
20348 /* A. On exit, the n diagonal elements of the diagonal matrix */
20349 /* D from the L*D*L' factorization of A. */
20350
20351 /* E (input/output) DOUBLE PRECISION array, dimension (N-1) */
20352 /* On entry, the (n-1) subdiagonal elements of the tridiagonal */
20353 /* matrix A. On exit, the (n-1) subdiagonal elements of the */
20354 /* unit bidiagonal factor L from the L*D*L' factorization of A. */
20355 /* E can also be regarded as the superdiagonal of the unit */
20356 /* bidiagonal factor U from the U'*D*U factorization of A. */
20357
20358 /* INFO (output) INTEGER */
20359 /* = 0: successful exit */
20360 /* < 0: if INFO = -k, the k-th argument had an illegal value */
20361 /* > 0: if INFO = k, the leading minor of order k is not */
20362 /* positive definite; if k < N, the factorization could not */
20363 /* be completed, while if k = N, the factorization was */
20364 /* completed, but D(N) <= 0. */
20365
20366 /* ===================================================================== */
20367
20368 /* .. Parameters .. */
20369 /* .. */
20370 /* .. Local Scalars .. */
20371 /* .. */
20372 /* .. External Subroutines .. */
20373 /* .. */
20374 /* .. Intrinsic Functions .. */
20375 /* .. */
20376 /* .. Executable Statements .. */
20377
20378 /* Test the input parameters. */
20379
20380 /* Parameter adjustments */
20381 --e;
20382 --d__;
20383
20384 /* Function Body */
20385 *info = 0;
20386 if (*n < 0) {
20387 *info = -1;
20388 i__1 = -(*info);
20389 xerbla_("DPTTRF", &i__1);
20390 return 0;
20391 }
20392
20393 /* Quick return if possible */
20394
20395 if (*n == 0) {
20396 return 0;
20397 }
20398
20399 /* Compute the L*D*L' (or U'*D*U) factorization of A. */
20400
20401 i4 = (*n - 1) % 4;
20402 i__1 = i4;
20403 for (i__ = 1; i__ <= i__1; ++i__) {
20404 if (d__[i__] <= 0.) {
20405 *info = i__;
20406 goto L30;
20407 }
20408 ei = e[i__];
20409 e[i__] = ei / d__[i__];
20410 d__[i__ + 1] -= e[i__] * ei;
20411 /* L10: */
20412 }
20413
20414 i__1 = *n - 4;
20415 for (i__ = i4 + 1; i__ <= i__1; i__ += 4) {
20416
20417 /* Drop out of the loop if d(i) <= 0: the matrix is not positive */
20418 /* definite. */
20419
20420 if (d__[i__] <= 0.) {
20421 *info = i__;
20422 goto L30;
20423 }
20424
20425 /* Solve for e(i) and d(i+1). */
20426
20427 ei = e[i__];
20428 e[i__] = ei / d__[i__];
20429 d__[i__ + 1] -= e[i__] * ei;
20430
20431 if (d__[i__ + 1] <= 0.) {
20432 *info = i__ + 1;
20433 goto L30;
20434 }
20435
20436 /* Solve for e(i+1) and d(i+2). */
20437
20438 ei = e[i__ + 1];
20439 e[i__ + 1] = ei / d__[i__ + 1];
20440 d__[i__ + 2] -= e[i__ + 1] * ei;
20441
20442 if (d__[i__ + 2] <= 0.) {
20443 *info = i__ + 2;
20444 goto L30;
20445 }
20446
20447 /* Solve for e(i+2) and d(i+3). */
20448
20449 ei = e[i__ + 2];
20450 e[i__ + 2] = ei / d__[i__ + 2];
20451 d__[i__ + 3] -= e[i__ + 2] * ei;
20452
20453 if (d__[i__ + 3] <= 0.) {
20454 *info = i__ + 3;
20455 goto L30;
20456 }
20457
20458 /* Solve for e(i+3) and d(i+4). */
20459
20460 ei = e[i__ + 3];
20461 e[i__ + 3] = ei / d__[i__ + 3];
20462 d__[i__ + 4] -= e[i__ + 3] * ei;
20463 /* L20: */
20464 }
20465
20466 /* Check d(n) for positive definiteness. */
20467
20468 if (d__[*n] <= 0.) {
20469 *info = *n;
20470 }
20471
20472 L30:
20473 return 0;
20474
20475 /* End of DPTTRF */
20476
20477 } /* dpttrf_ */
20478
20479 /* Subroutine */ int dpttrs_(integer *n, integer *nrhs, double *d__,
20480 double *e, double *b, integer *ldb, integer *info)
20481 {
20482 /* Table of constant values */
20483 static integer c__1 = 1;
20484 static integer c_n1 = -1;
20485
20486 /* System generated locals */
20487 integer b_dim1, b_offset, i__1, i__2, i__3;
20488
20489 /* Local variables */
20490 integer j, jb, nb;
20491
20492
20493 /* -- LAPACK routine (version 3.1) -- */
20494 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
20495 /* November 2006 */
20496
20497 /* .. Scalar Arguments .. */
20498 /* .. */
20499 /* .. Array Arguments .. */
20500 /* .. */
20501
20502 /* Purpose */
20503 /* ======= */
20504
20505 /* DPTTRS solves a tridiagonal system of the form */
20506 /* A * X = B */
20507 /* using the L*D*L' factorization of A computed by DPTTRF. D is a */
20508 /* diagonal matrix specified in the vector D, L is a unit bidiagonal */
20509 /* matrix whose subdiagonal is specified in the vector E, and X and B */
20510 /* are N by NRHS matrices. */
20511
20512 /* Arguments */
20513 /* ========= */
20514
20515 /* N (input) INTEGER */
20516 /* The order of the tridiagonal matrix A. N >= 0. */
20517
20518 /* NRHS (input) INTEGER */
20519 /* The number of right hand sides, i.e., the number of columns */
20520 /* of the matrix B. NRHS >= 0. */
20521
20522 /* D (input) DOUBLE PRECISION array, dimension (N) */
20523 /* The n diagonal elements of the diagonal matrix D from the */
20524 /* L*D*L' factorization of A. */
20525
20526 /* E (input) DOUBLE PRECISION array, dimension (N-1) */
20527 /* The (n-1) subdiagonal elements of the unit bidiagonal factor */
20528 /* L from the L*D*L' factorization of A. E can also be regarded */
20529 /* as the superdiagonal of the unit bidiagonal factor U from the */
20530 /* factorization A = U'*D*U. */
20531
20532 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
20533 /* On entry, the right hand side vectors B for the system of */
20534 /* linear equations. */
20535 /* On exit, the solution vectors, X. */
20536
20537 /* LDB (input) INTEGER */
20538 /* The leading dimension of the array B. LDB >= max(1,N). */
20539
20540 /* INFO (output) INTEGER */
20541 /* = 0: successful exit */
20542 /* < 0: if INFO = -k, the k-th argument had an illegal value */
20543
20544 /* ===================================================================== */
20545
20546 /* .. Local Scalars .. */
20547 /* .. */
20548 /* .. External Functions .. */
20549 /* .. */
20550 /* .. External Subroutines .. */
20551 /* .. */
20552 /* .. Intrinsic Functions .. */
20553 /* .. */
20554 /* .. Executable Statements .. */
20555
20556 /* Test the input arguments. */
20557
20558 /* Parameter adjustments */
20559 --d__;
20560 --e;
20561 b_dim1 = *ldb;
20562 b_offset = 1 + b_dim1;
20563 b -= b_offset;
20564
20565 /* Function Body */
20566 *info = 0;
20567 if (*n < 0) {
20568 *info = -1;
20569 } else if (*nrhs < 0) {
20570 *info = -2;
20571 } else if (*ldb < std::max(1_integer,*n)) {
20572 *info = -6;
20573 }
20574 if (*info != 0) {
20575 i__1 = -(*info);
20576 xerbla_("DPTTRS", &i__1);
20577 return 0;
20578 }
20579
20580 /* Quick return if possible */
20581
20582 if (*n == 0 || *nrhs == 0) {
20583 return 0;
20584 }
20585
20586 /* Determine the number of right-hand sides to solve at a time. */
20587
20588 if (*nrhs == 1) {
20589 nb = 1;
20590 } else {
20591 /* Computing MAX */
20592 i__1 = 1, i__2 = ilaenv_(&c__1, "DPTTRS", " ", n, nrhs, &c_n1, &c_n1);
20593 nb = std::max(i__1,i__2);
20594 }
20595
20596 if (nb >= *nrhs) {
20597 dptts2_(n, nrhs, &d__[1], &e[1], &b[b_offset], ldb);
20598 } else {
20599 i__1 = *nrhs;
20600 i__2 = nb;
20601 for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
20602 /* Computing MIN */
20603 i__3 = *nrhs - j + 1;
20604 jb = std::min(i__3,nb);
20605 dptts2_(n, &jb, &d__[1], &e[1], &b[j * b_dim1 + 1], ldb);
20606 /* L10: */
20607 }
20608 }
20609
20610 return 0;
20611
20612 /* End of DPTTRS */
20613
20614 } /* dpttrs_ */
20615
20616 /* Subroutine */ int dptts2_(integer *n, integer *nrhs, double *d__,
20617 double *e, double *b, integer *ldb)
20618 {
20619 /* System generated locals */
20620 integer b_dim1, b_offset, i__1, i__2;
20621 double d__1;
20622
20623 /* Local variables */
20624 integer i__, j;
20625
20626 /* -- LAPACK routine (version 3.1) -- */
20627 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
20628 /* November 2006 */
20629
20630 /* .. Scalar Arguments .. */
20631 /* .. */
20632 /* .. Array Arguments .. */
20633 /* .. */
20634
20635 /* Purpose */
20636 /* ======= */
20637
20638 /* DPTTS2 solves a tridiagonal system of the form */
20639 /* A * X = B */
20640 /* using the L*D*L' factorization of A computed by DPTTRF. D is a */
20641 /* diagonal matrix specified in the vector D, L is a unit bidiagonal */
20642 /* matrix whose subdiagonal is specified in the vector E, and X and B */
20643 /* are N by NRHS matrices. */
20644
20645 /* Arguments */
20646 /* ========= */
20647
20648 /* N (input) INTEGER */
20649 /* The order of the tridiagonal matrix A. N >= 0. */
20650
20651 /* NRHS (input) INTEGER */
20652 /* The number of right hand sides, i.e., the number of columns */
20653 /* of the matrix B. NRHS >= 0. */
20654
20655 /* D (input) DOUBLE PRECISION array, dimension (N) */
20656 /* The n diagonal elements of the diagonal matrix D from the */
20657 /* L*D*L' factorization of A. */
20658
20659 /* E (input) DOUBLE PRECISION array, dimension (N-1) */
20660 /* The (n-1) subdiagonal elements of the unit bidiagonal factor */
20661 /* L from the L*D*L' factorization of A. E can also be regarded */
20662 /* as the superdiagonal of the unit bidiagonal factor U from the */
20663 /* factorization A = U'*D*U. */
20664
20665 /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
20666 /* On entry, the right hand side vectors B for the system of */
20667 /* linear equations. */
20668 /* On exit, the solution vectors, X. */
20669
20670 /* LDB (input) INTEGER */
20671 /* The leading dimension of the array B. LDB >= max(1,N). */
20672
20673 /* ===================================================================== */
20674
20675 /* .. Local Scalars .. */
20676 /* .. */
20677 /* .. External Subroutines .. */
20678 /* .. */
20679 /* .. Executable Statements .. */
20680
20681 /* Quick return if possible */
20682
20683 /* Parameter adjustments */
20684 --d__;
20685 --e;
20686 b_dim1 = *ldb;
20687 b_offset = 1 + b_dim1;
20688 b -= b_offset;
20689
20690 /* Function Body */
20691 if (*n <= 1) {
20692 if (*n == 1) {
20693 d__1 = 1. / d__[1];
20694 dscal_(nrhs, &d__1, &b[b_offset], ldb);
20695 }
20696 return 0;
20697 }
20698
20699 /* Solve A * X = B using the factorization A = L*D*L', */
20700 /* overwriting each right hand side vector with its solution. */
20701
20702 i__1 = *nrhs;
20703 for (j = 1; j <= i__1; ++j) {
20704
20705 /* Solve L * x = b. */
20706
20707 i__2 = *n;
20708 for (i__ = 2; i__ <= i__2; ++i__) {
20709 b[i__ + j * b_dim1] -= b[i__ - 1 + j * b_dim1] * e[i__ - 1];
20710 /* L10: */
20711 }
20712
20713 /* Solve D * L' * x = b. */
20714
20715 b[*n + j * b_dim1] /= d__[*n];
20716 for (i__ = *n - 1; i__ >= 1; --i__) {
20717 b[i__ + j * b_dim1] = b[i__ + j * b_dim1] / d__[i__] - b[i__ + 1
20718 + j * b_dim1] * e[i__];
20719 /* L20: */
20720 }
20721 /* L30: */
20722 }
20723
20724 return 0;
20725
20726 /* End of DPTTS2 */
20727
20728 } /* dptts2_ */
20729
20730 /* Subroutine */ int drscl_(integer *n, double *sa, double *sx,
20731 integer *incx)
20732 {
20733 double mul, cden;
20734 bool done;
20735 double cnum, cden1, cnum1;
20736 double bignum, smlnum;
20737
20738
20739 /* -- LAPACK auxiliary routine (version 3.1) -- */
20740 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
20741 /* November 2006 */
20742
20743 /* .. Scalar Arguments .. */
20744 /* .. */
20745 /* .. Array Arguments .. */
20746 /* .. */
20747
20748 /* Purpose */
20749 /* ======= */
20750
20751 /* DRSCL multiplies an n-element real vector x by the real scalar 1/a. */
20752 /* This is done without overflow or underflow as long as */
20753 /* the final result x/a does not overflow or underflow. */
20754
20755 /* Arguments */
20756 /* ========= */
20757
20758 /* N (input) INTEGER */
20759 /* The number of components of the vector x. */
20760
20761 /* SA (input) DOUBLE PRECISION */
20762 /* The scalar a which is used to divide each component of x. */
20763 /* SA must be >= 0, or the subroutine will divide by zero. */
20764
20765 /* SX (input/output) DOUBLE PRECISION array, dimension */
20766 /* (1+(N-1)*abs(INCX)) */
20767 /* The n-element vector x. */
20768
20769 /* INCX (input) INTEGER */
20770 /* The increment between successive values of the vector SX. */
20771 /* > 0: SX(1) = X(1) and SX(1+(i-1)*INCX) = x(i), 1< i<= n */
20772
20773 /* ===================================================================== */
20774
20775 /* .. Parameters .. */
20776 /* .. */
20777 /* .. Local Scalars .. */
20778 /* .. */
20779 /* .. External Functions .. */
20780 /* .. */
20781 /* .. External Subroutines .. */
20782 /* .. */
20783 /* .. Intrinsic Functions .. */
20784 /* .. */
20785 /* .. Executable Statements .. */
20786
20787 /* Quick return if possible */
20788
20789 /* Parameter adjustments */
20790 --sx;
20791
20792 /* Function Body */
20793 if (*n <= 0) {
20794 return 0;
20795 }
20796
20797 /* Get machine parameters */
20798
20799 smlnum = dlamch_("S");
20800 bignum = 1. / smlnum;
20801 dlabad_(&smlnum, &bignum);
20802
20803 /* Initialize the denominator to SA and the numerator to 1. */
20804
20805 cden = *sa;
20806 cnum = 1.;
20807
20808 L10:
20809 cden1 = cden * smlnum;
20810 cnum1 = cnum / bignum;
20811 if (abs(cden1) > abs(cnum) && cnum != 0.) {
20812
20813 /* Pre-multiply X by SMLNUM if CDEN is large compared to CNUM. */
20814
20815 mul = smlnum;
20816 done = false;
20817 cden = cden1;
20818 } else if (abs(cnum1) > abs(cden)) {
20819
20820 /* Pre-multiply X by BIGNUM if CDEN is small compared to CNUM. */
20821
20822 mul = bignum;
20823 done = false;
20824 cnum = cnum1;
20825 } else {
20826
20827 /* Multiply X by CNUM / CDEN and return. */
20828
20829 mul = cnum / cden;
20830 done = true;
20831 }
20832
20833 /* Scale the vector X by MUL */
20834
20835 dscal_(n, &mul, &sx[1], incx);
20836
20837 if (! done) {
20838 goto L10;
20839 }
20840
20841 return 0;
20842
20843 /* End of DRSCL */
20844
20845 } /* drscl_ */
20846
20847 /* Subroutine */ integer ieeeck_(integer *ispec, float *zero, float *one)
20848 {
20849 /* System generated locals */
20850 integer ret_val;
20851
20852 /* Local variables */
20853 float nan1, nan2, nan3, nan4, nan5, nan6, neginf, posinf, negzro, newzro;
20854
20855
20856 /* -- LAPACK auxiliary routine (version 3.1) -- */
20857 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
20858 /* November 2006 */
20859
20860 /* .. Scalar Arguments .. */
20861 /* .. */
20862
20863 /* Purpose */
20864 /* ======= */
20865
20866 /* IEEECK is called from the ILAENV to verify that Infinity and */
20867 /* possibly NaN arithmetic is safe (i.e. will not trap). */
20868
20869 /* Arguments */
20870 /* ========= */
20871
20872 /* ISPEC (input) INTEGER */
20873 /* Specifies whether to test just for inifinity arithmetic */
20874 /* or whether to test for infinity and NaN arithmetic. */
20875 /* = 0: Verify infinity arithmetic only. */
20876 /* = 1: Verify infinity and NaN arithmetic. */
20877
20878 /* ZERO (input) REAL */
20879 /* Must contain the value 0.0 */
20880 /* This is passed to prevent the compiler from optimizing */
20881 /* away this code. */
20882
20883 /* ONE (input) REAL */
20884 /* Must contain the value 1.0 */
20885 /* This is passed to prevent the compiler from optimizing */
20886 /* away this code. */
20887
20888 /* RETURN VALUE: INTEGER */
20889 /* = 0: Arithmetic failed to produce the correct answers */
20890 /* = 1: Arithmetic produced the correct answers */
20891
20892 /* .. Local Scalars .. */
20893 /* .. */
20894 /* .. Executable Statements .. */
20895 ret_val = 1;
20896
20897 posinf = *one / *zero;
20898 if (posinf <= *one) {
20899 ret_val = 0;
20900 return ret_val;
20901 }
20902
20903 neginf = -(*one) / *zero;
20904 if (neginf >= *zero) {
20905 ret_val = 0;
20906 return ret_val;
20907 }
20908
20909 negzro = *one / (neginf + *one);
20910 if (negzro != *zero) {
20911 ret_val = 0;
20912 return ret_val;
20913 }
20914
20915 neginf = *one / negzro;
20916 if (neginf >= *zero) {
20917 ret_val = 0;
20918 return ret_val;
20919 }
20920
20921 newzro = negzro + *zero;
20922 if (newzro != *zero) {
20923 ret_val = 0;
20924 return ret_val;
20925 }
20926
20927 posinf = *one / newzro;
20928 if (posinf <= *one) {
20929 ret_val = 0;
20930 return ret_val;
20931 }
20932
20933 neginf *= posinf;
20934 if (neginf >= *zero) {
20935 ret_val = 0;
20936 return ret_val;
20937 }
20938
20939 posinf *= posinf;
20940 if (posinf <= *one) {
20941 ret_val = 0;
20942 return ret_val;
20943 }
20944
20945
20946
20947
20948 /* Return if we were only asked to check infinity arithmetic */
20949
20950 if (*ispec == 0) {
20951 return ret_val;
20952 }
20953
20954 nan1 = posinf + neginf;
20955
20956 nan2 = posinf / neginf;
20957
20958 nan3 = posinf / posinf;
20959
20960 nan4 = posinf * *zero;
20961
20962 nan5 = neginf * negzro;
20963
20964 nan6 = nan5 * 0.f;
20965
20966 if (nan1 == nan1) {
20967 ret_val = 0;
20968 return ret_val;
20969 }
20970
20971 if (nan2 == nan2) {
20972 ret_val = 0;
20973 return ret_val;
20974 }
20975
20976 if (nan3 == nan3) {
20977 ret_val = 0;
20978 return ret_val;
20979 }
20980
20981 if (nan4 == nan4) {
20982 ret_val = 0;
20983 return ret_val;
20984 }
20985
20986 if (nan5 == nan5) {
20987 ret_val = 0;
20988 return ret_val;
20989 }
20990
20991 if (nan6 == nan6) {
20992 ret_val = 0;
20993 return ret_val;
20994 }
20995
20996 return ret_val;
20997 } /* ieeeck_ */
20998
20999 /* Subroutine */ integer iladlc_(integer *m, integer *n, double *a, integer *lda)
21000 {
21001 /* System generated locals */
21002 integer a_dim1, a_offset, ret_val, i__1;
21003
21004 /* Local variables */
21005 integer i__;
21006
21007
21008 /* -- LAPACK auxiliary routine (version 3.2.1) -- */
21009
21010 /* -- April 2009 -- */
21011
21012 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
21013 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
21014
21015 /* .. Scalar Arguments .. */
21016 /* .. */
21017 /* .. Array Arguments .. */
21018 /* .. */
21019
21020 /* Purpose */
21021 /* ======= */
21022
21023 /* ILADLC scans A for its last non-zero column. */
21024
21025 /* Arguments */
21026 /* ========= */
21027
21028 /* M (input) INTEGER */
21029 /* The number of rows of the matrix A. */
21030
21031 /* N (input) INTEGER */
21032 /* The number of columns of the matrix A. */
21033
21034 /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
21035 /* The m by n matrix A. */
21036
21037 /* LDA (input) INTEGER */
21038 /* The leading dimension of the array A. LDA >= max(1,M). */
21039
21040 /* ===================================================================== */
21041
21042 /* .. Parameters .. */
21043 /* .. */
21044 /* .. Local Scalars .. */
21045 /* .. */
21046 /* .. Executable Statements .. */
21047
21048 /* Quick test for the common case where one corner is non-zero. */
21049 /* Parameter adjustments */
21050 a_dim1 = *lda;
21051 a_offset = 1 + a_dim1;
21052 a -= a_offset;
21053
21054 /* Function Body */
21055 if (*n == 0) {
21056 ret_val = *n;
21057 } else if (a[*n * a_dim1 + 1] != 0. || a[*m + *n * a_dim1] != 0.) {
21058 ret_val = *n;
21059 } else {
21060 /* Now scan each column from the end, returning with the first non-zero. */
21061 for (ret_val = *n; ret_val >= 1; --ret_val) {
21062 i__1 = *m;
21063 for (i__ = 1; i__ <= i__1; ++i__) {
21064 if (a[i__ + ret_val * a_dim1] != 0.) {
21065 return ret_val;
21066 }
21067 }
21068 }
21069 }
21070 return ret_val;
21071 } /* iladlc_ */
21072
21073 /* Subroutine */ integer iladlr_(integer *m, integer *n, double *a, integer *lda)
21074 {
21075 /* System generated locals */
21076 integer a_dim1, a_offset, ret_val, i__1;
21077
21078 /* Local variables */
21079 integer i__, j;
21080
21081
21082 /* -- LAPACK auxiliary routine (version 3.2.1) -- */
21083
21084 /* -- April 2009 -- */
21085
21086 /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
21087 /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
21088
21089 /* .. Scalar Arguments .. */
21090 /* .. */
21091 /* .. Array Arguments .. */
21092 /* .. */
21093
21094 /* Purpose */
21095 /* ======= */
21096
21097 /* ILADLR scans A for its last non-zero row. */
21098
21099 /* Arguments */
21100 /* ========= */
21101
21102 /* M (input) INTEGER */
21103 /* The number of rows of the matrix A. */
21104
21105 /* N (input) INTEGER */
21106 /* The number of columns of the matrix A. */
21107
21108 /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
21109 /* The m by n matrix A. */
21110
21111 /* LDA (input) INTEGER */
21112 /* The leading dimension of the array A. LDA >= max(1,M). */
21113
21114 /* ===================================================================== */
21115
21116 /* .. Parameters .. */
21117 /* .. */
21118 /* .. Local Scalars .. */
21119 /* .. */
21120 /* .. Executable Statements .. */
21121
21122 /* Quick test for the common case where one corner is non-zero. */
21123 /* Parameter adjustments */
21124 a_dim1 = *lda;
21125 a_offset = 1 + a_dim1;
21126 a -= a_offset;
21127
21128 /* Function Body */
21129 if (*m == 0) {
21130 ret_val = *m;
21131 } else if (a[*m + a_dim1] != 0. || a[*m + *n * a_dim1] != 0.) {
21132 ret_val = *m;
21133 } else {
21134 /* Scan up each column tracking the last zero row seen. */
21135 ret_val = 0;
21136 i__1 = *n;
21137 for (j = 1; j <= i__1; ++j) {
21138 for (i__ = *m; i__ >= 1; --i__) {
21139 if (a[i__ + j * a_dim1] != 0.) {
21140 break;
21141 }
21142 }
21143 ret_val = std::max(ret_val,i__);
21144 }
21145 }
21146 return ret_val;
21147 } /* iladlr_ */
21148
21149 /* Subroutine */ integer ilaenv_(integer *ispec, const char *name__, const char *opts, integer *n1,
21150 integer *n2, integer *n3, integer *n4)
21151 {
21152 /* Table of constant values */
21153 static integer c__1 = 1;
21154 static float c_b163 = 0.f;
21155 static float c_b164 = 1.f;
21156 static integer c__0 = 0;
21157
21158 /* System generated locals */
21159 integer ret_val;
21160
21161 /* Local variables */
21162 integer i__;
21163 char c1[1], c2[1], c3[1], c4[1];
21164 integer ic, nb, iz, nx;
21165 bool cname;
21166 integer nbmin;
21167 bool sname;
21168 char subnam[1];
21169 integer name_len;//, opts_len;
21170
21171 name_len = strlen (name__);
21172 // opts_len = strlen (opts);
21173
21174 /* -- LAPACK auxiliary routine (version 3.2) -- */
21175 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
21176 /* January 2007 */
21177
21178 /* .. Scalar Arguments .. */
21179 /* .. */
21180
21181 /* Purpose */
21182 /* ======= */
21183
21184 /* ILAENV is called from the LAPACK routines to choose problem-dependent */
21185 /* parameters for the local environment. See ISPEC for a description of */
21186 /* the parameters. */
21187
21188 /* ILAENV returns an INTEGER */
21189 /* if ILAENV >= 0: ILAENV returns the value of the parameter specified by ISPEC */
21190 /* if ILAENV < 0: if ILAENV = -k, the k-th argument had an illegal value. */
21191
21192 /* This version provides a set of parameters which should give good, */
21193 /* but not optimal, performance on many of the currently available */
21194 /* computers. Users are encouraged to modify this subroutine to set */
21195 /* the tuning parameters for their particular machine using the option */
21196 /* and problem size information in the arguments. */
21197
21198 /* This routine will not function correctly if it is converted to all */
21199 /* lower case. Converting it to all upper case is allowed. */
21200
21201 /* Arguments */
21202 /* ========= */
21203
21204 /* ISPEC (input) INTEGER */
21205 /* Specifies the parameter to be returned as the value of */
21206 /* ILAENV. */
21207 /* = 1: the optimal blocksize; if this value is 1, an unblocked */
21208 /* algorithm will give the best performance. */
21209 /* = 2: the minimum block size for which the block routine */
21210 /* should be used; if the usable block size is less than */
21211 /* this value, an unblocked routine should be used. */
21212 /* = 3: the crossover point (in a block routine, for N less */
21213 /* than this value, an unblocked routine should be used) */
21214 /* = 4: the number of shifts, used in the nonsymmetric */
21215 /* eigenvalue routines (DEPRECATED) */
21216 /* = 5: the minimum column dimension for blocking to be used; */
21217 /* rectangular blocks must have dimension at least k by m, */
21218 /* where k is given by ILAENV(2,...) and m by ILAENV(5,...) */
21219 /* = 6: the crossover point for the SVD (when reducing an m by n */
21220 /* matrix to bidiagonal form, if max(m,n)/min(m,n) exceeds */
21221 /* this value, a QR factorization is used first to reduce */
21222 /* the matrix to a triangular form.) */
21223 /* = 7: the number of processors */
21224 /* = 8: the crossover point for the multishift QR method */
21225 /* for nonsymmetric eigenvalue problems (DEPRECATED) */
21226 /* = 9: maximum size of the subproblems at the bottom of the */
21227 /* computation tree in the divide-and-conquer algorithm */
21228 /* (used by xGELSD and xGESDD) */
21229 /* =10: ieee NaN arithmetic can be trusted not to trap */
21230 /* =11: infinity arithmetic can be trusted not to trap */
21231 /* 12 <= ISPEC <= 16: */
21232 /* xHSEQR or one of its subroutines, */
21233 /* see IPARMQ for detailed explanation */
21234
21235 /* NAME (input) CHARACTER*(*) */
21236 /* The name of the calling subroutine, in either upper case or */
21237 /* lower case. */
21238
21239 /* OPTS (input) CHARACTER*(*) */
21240 /* The character options to the subroutine NAME, concatenated */
21241 /* into a single character string. For example, UPLO = 'U', */
21242 /* TRANS = 'T', and DIAG = 'N' for a triangular routine would */
21243 /* be specified as OPTS = 'UTN'. */
21244
21245 /* N1 (input) INTEGER */
21246 /* N2 (input) INTEGER */
21247 /* N3 (input) INTEGER */
21248 /* N4 (input) INTEGER */
21249 /* Problem dimensions for the subroutine NAME; these may not all */
21250 /* be required. */
21251
21252 /* Further Details */
21253 /* =============== */
21254
21255 /* The following conventions have been used when calling ILAENV from the */
21256 /* LAPACK routines: */
21257 /* 1) OPTS is a concatenation of all of the character options to */
21258 /* subroutine NAME, in the same order that they appear in the */
21259 /* argument list for NAME, even if they are not used in determining */
21260 /* the value of the parameter specified by ISPEC. */
21261 /* 2) The problem dimensions N1, N2, N3, N4 are specified in the order */
21262 /* that they appear in the argument list for NAME. N1 is used */
21263 /* first, N2 second, and so on, and unused problem dimensions are */
21264 /* passed a value of -1. */
21265 /* 3) The parameter value returned by ILAENV is checked for validity in */
21266 /* the calling subroutine. For example, ILAENV is used to retrieve */
21267 /* the optimal blocksize for STRTRI as follows: */
21268
21269 /* NB = ILAENV( 1, 'STRTRI', UPLO // DIAG, N, -1, -1, -1 ) */
21270 /* IF( NB.LE.1 ) NB = MAX( 1, N ) */
21271
21272 /* ===================================================================== */
21273
21274 /* .. Local Scalars .. */
21275 /* .. */
21276 /* .. Intrinsic Functions .. */
21277 /* .. */
21278 /* .. External Functions .. */
21279 /* .. */
21280 /* .. Executable Statements .. */
21281
21282 switch (*ispec) {
21283 case 1: goto L10;
21284 case 2: goto L10;
21285 case 3: goto L10;
21286 case 4: goto L80;
21287 case 5: goto L90;
21288 case 6: goto L100;
21289 case 7: goto L110;
21290 case 8: goto L120;
21291 case 9: goto L130;
21292 case 10: goto L140;
21293 case 11: goto L150;
21294 case 12: goto L160;
21295 case 13: goto L160;
21296 case 14: goto L160;
21297 case 15: goto L160;
21298 case 16: goto L160;
21299 }
21300
21301 /* Invalid value for ISPEC */
21302
21303 ret_val = -1;
21304 return ret_val;
21305
21306 L10:
21307
21308 /* Convert NAME to upper case if the first character is lower case. */
21309
21310 ret_val = 1;
21311 s_copy(subnam, name__, 1_integer, name_len);
21312 ic = *(unsigned char *)subnam;
21313 iz = 'Z';
21314 if (iz == 90 || iz == 122) {
21315
21316 /* ASCII character set */
21317
21318 if (ic >= 97 && ic <= 122) {
21319 *(unsigned char *)subnam = (char) (ic - 32);
21320 for (i__ = 2; i__ <= 6; ++i__) {
21321 ic = *(unsigned char *)&subnam[i__ - 1];
21322 if (ic >= 97 && ic <= 122) {
21323 *(unsigned char *)&subnam[i__ - 1] = (char) (ic - 32);
21324 }
21325 /* L20: */
21326 }
21327 }
21328
21329 } else if (iz == 233 || iz == 169) {
21330
21331 /* EBCDIC character set */
21332
21333 if (ic >= 129 && ic <= 137 || ic >= 145 && ic <= 153 || ic >= 162 &&
21334 ic <= 169) {
21335 *(unsigned char *)subnam = (char) (ic + 64);
21336 for (i__ = 2; i__ <= 6; ++i__) {
21337 ic = *(unsigned char *)&subnam[i__ - 1];
21338 if (ic >= 129 && ic <= 137 || ic >= 145 && ic <= 153 || ic >=
21339 162 && ic <= 169) {
21340 *(unsigned char *)&subnam[i__ - 1] = (char) (ic + 64);
21341 }
21342 /* L30: */
21343 }
21344 }
21345
21346 } else if (iz == 218 || iz == 250) {
21347
21348 /* Prime machines: ASCII+128 */
21349
21350 if (ic >= 225 && ic <= 250) {
21351 *(unsigned char *)subnam = (char) (ic - 32);
21352 for (i__ = 2; i__ <= 6; ++i__) {
21353 ic = *(unsigned char *)&subnam[i__ - 1];
21354 if (ic >= 225 && ic <= 250) {
21355 *(unsigned char *)&subnam[i__ - 1] = (char) (ic - 32);
21356 }
21357 /* L40: */
21358 }
21359 }
21360 }
21361
21362 *(unsigned char *)c1 = *(unsigned char *)subnam;
21363 sname = *(unsigned char *)c1 == 'S' || *(unsigned char *)c1 == 'D';
21364 cname = *(unsigned char *)c1 == 'C' || *(unsigned char *)c1 == 'Z';
21365 if (! (cname || sname)) {
21366 return ret_val;
21367 }
21368 s_copy(c2, subnam + 1, 1_integer, 2_integer);
21369 s_copy(c3, subnam + 3, 1_integer, 3_integer);
21370 s_copy(c4, c3 + 1, 1_integer, 2_integer);
21371
21372 switch (*ispec) {
21373 case 1: goto L50;
21374 case 2: goto L60;
21375 case 3: goto L70;
21376 }
21377
21378 L50:
21379
21380 /* ISPEC = 1: block size */
21381
21382 /* In these examples, separate code is provided for setting NB for */
21383 /* real and complex. We assume that NB will take the same value in */
21384 /* single or double precision. */
21385
21386 nb = 1;
21387
21388 if (s_cmp(c2, "GE", 1_integer, 2_integer) == 0) {
21389 if (s_cmp(c3, "TRF", 1_integer, 3_integer) == 0) {
21390 if (sname) {
21391 nb = 64;
21392 } else {
21393 nb = 64;
21394 }
21395 } else if (s_cmp(c3, "QRF", 1_integer, 3_integer) == 0 || s_cmp(c3,
21396 "RQF", 1_integer, 3_integer) == 0 || s_cmp(c3, "LQF", 1_integer,
21397 3_integer) == 0 || s_cmp(c3, "QLF", 1_integer, 3_integer) == 0) {
21398 if (sname) {
21399 nb = 32;
21400 } else {
21401 nb = 32;
21402 }
21403 } else if (s_cmp(c3, "HRD", 1_integer, 3_integer) == 0) {
21404 if (sname) {
21405 nb = 32;
21406 } else {
21407 nb = 32;
21408 }
21409 } else if (s_cmp(c3, "BRD", 1_integer, 3_integer) == 0) {
21410 if (sname) {
21411 nb = 32;
21412 } else {
21413 nb = 32;
21414 }
21415 } else if (s_cmp(c3, "TRI", 1_integer, 3_integer) == 0) {
21416 if (sname) {
21417 nb = 64;
21418 } else {
21419 nb = 64;
21420 }
21421 }
21422 } else if (s_cmp(c2, "PO", 1_integer, 2_integer) == 0) {
21423 if (s_cmp(c3, "TRF", 1_integer, 3_integer) == 0) {
21424 if (sname) {
21425 nb = 64;
21426 } else {
21427 nb = 64;
21428 }
21429 }
21430 } else if (s_cmp(c2, "SY", 1_integer, 2_integer) == 0) {
21431 if (s_cmp(c3, "TRF", 1_integer, 3_integer) == 0) {
21432 if (sname) {
21433 nb = 64;
21434 } else {
21435 nb = 64;
21436 }
21437 } else if (sname && s_cmp(c3, "TRD", 1_integer, 3_integer) == 0) {
21438 nb = 32;
21439 } else if (sname && s_cmp(c3, "GST", 1_integer, 3_integer) == 0) {
21440 nb = 64;
21441 }
21442 } else if (cname && s_cmp(c2, "HE", 1_integer, 2_integer) == 0) {
21443 if (s_cmp(c3, "TRF", 1_integer, 3_integer) == 0) {
21444 nb = 64;
21445 } else if (s_cmp(c3, "TRD", 1_integer, 3_integer) == 0) {
21446 nb = 32;
21447 } else if (s_cmp(c3, "GST", 1_integer, 3_integer) == 0) {
21448 nb = 64;
21449 }
21450 } else if (sname && s_cmp(c2, "OR", 1_integer, 2_integer) == 0) {
21451 if (*(unsigned char *)c3 == 'G') {
21452 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21453 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21454 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21455 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21456 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21457 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21458 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21459 nb = 32;
21460 }
21461 } else if (*(unsigned char *)c3 == 'M') {
21462 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21463 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21464 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21465 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21466 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21467 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21468 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21469 nb = 32;
21470 }
21471 }
21472 } else if (cname && s_cmp(c2, "UN", 1_integer, 2_integer) == 0) {
21473 if (*(unsigned char *)c3 == 'G') {
21474 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21475 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21476 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21477 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21478 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21479 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21480 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21481 nb = 32;
21482 }
21483 } else if (*(unsigned char *)c3 == 'M') {
21484 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21485 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21486 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21487 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21488 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21489 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21490 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21491 nb = 32;
21492 }
21493 }
21494 } else if (s_cmp(c2, "GB", 1_integer, 2_integer) == 0) {
21495 if (s_cmp(c3, "TRF", 1_integer, 3_integer) == 0) {
21496 if (sname) {
21497 if (*n4 <= 64) {
21498 nb = 1;
21499 } else {
21500 nb = 32;
21501 }
21502 } else {
21503 if (*n4 <= 64) {
21504 nb = 1;
21505 } else {
21506 nb = 32;
21507 }
21508 }
21509 }
21510 } else if (s_cmp(c2, "PB", 1_integer, 2_integer) == 0) {
21511 if (s_cmp(c3, "TRF", 1_integer, 3_integer) == 0) {
21512 if (sname) {
21513 if (*n2 <= 64) {
21514 nb = 1;
21515 } else {
21516 nb = 32;
21517 }
21518 } else {
21519 if (*n2 <= 64) {
21520 nb = 1;
21521 } else {
21522 nb = 32;
21523 }
21524 }
21525 }
21526 } else if (s_cmp(c2, "TR", 1_integer, 2_integer) == 0) {
21527 if (s_cmp(c3, "TRI", 1_integer, 3_integer) == 0) {
21528 if (sname) {
21529 nb = 64;
21530 } else {
21531 nb = 64;
21532 }
21533 }
21534 } else if (s_cmp(c2, "LA", 1_integer, 2_integer) == 0) {
21535 if (s_cmp(c3, "UUM", 1_integer, 3_integer) == 0) {
21536 if (sname) {
21537 nb = 64;
21538 } else {
21539 nb = 64;
21540 }
21541 }
21542 } else if (sname && s_cmp(c2, "ST", 1_integer, 2_integer) == 0) {
21543 if (s_cmp(c3, "EBZ", 1_integer, 3_integer) == 0) {
21544 nb = 1;
21545 }
21546 }
21547 ret_val = nb;
21548 return ret_val;
21549
21550 L60:
21551
21552 /* ISPEC = 2: minimum block size */
21553
21554 nbmin = 2;
21555 if (s_cmp(c2, "GE", 1_integer, 2_integer) == 0) {
21556 if (s_cmp(c3, "QRF", 1_integer, 3_integer) == 0 ||
21557 s_cmp(c3, "RQF", 1_integer, 3_integer) == 0 ||
21558 s_cmp(c3, "LQF", 1_integer, 3_integer) == 0 ||
21559 s_cmp(c3, "QLF", 1_integer, 3_integer) == 0) {
21560 if (sname) {
21561 nbmin = 2;
21562 } else {
21563 nbmin = 2;
21564 }
21565 } else if (s_cmp(c3, "HRD", 1_integer, 3_integer) == 0) {
21566 if (sname) {
21567 nbmin = 2;
21568 } else {
21569 nbmin = 2;
21570 }
21571 } else if (s_cmp(c3, "BRD", 1_integer, 3_integer) == 0) {
21572 if (sname) {
21573 nbmin = 2;
21574 } else {
21575 nbmin = 2;
21576 }
21577 } else if (s_cmp(c3, "TRI", 1_integer, 3_integer) == 0) {
21578 if (sname) {
21579 nbmin = 2;
21580 } else {
21581 nbmin = 2;
21582 }
21583 }
21584 } else if (s_cmp(c2, "SY", 1_integer, 2_integer) == 0) {
21585 if (s_cmp(c3, "TRF", 1_integer, 3_integer) == 0) {
21586 if (sname) {
21587 nbmin = 8;
21588 } else {
21589 nbmin = 8;
21590 }
21591 } else if (sname && s_cmp(c3, "TRD", 1_integer, 3_integer) == 0) {
21592 nbmin = 2;
21593 }
21594 } else if (cname && s_cmp(c2, "HE", 1_integer, 2_integer) == 0) {
21595 if (s_cmp(c3, "TRD", 1_integer, 3_integer) == 0) {
21596 nbmin = 2;
21597 }
21598 } else if (sname && s_cmp(c2, "OR", 1_integer, 2_integer) == 0) {
21599 if (*(unsigned char *)c3 == 'G') {
21600 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21601 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21602 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21603 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21604 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21605 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21606 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21607 nbmin = 2;
21608 }
21609 } else if (*(unsigned char *)c3 == 'M') {
21610 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21611 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21612 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21613 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21614 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21615 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21616 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21617 nbmin = 2;
21618 }
21619 }
21620 } else if (cname && s_cmp(c2, "UN", 1_integer, 2_integer) == 0) {
21621 if (*(unsigned char *)c3 == 'G') {
21622 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21623 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21624 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21625 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21626 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21627 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21628 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21629 nbmin = 2;
21630 }
21631 } else if (*(unsigned char *)c3 == 'M') {
21632 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21633 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21634 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21635 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21636 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21637 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21638 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21639 nbmin = 2;
21640 }
21641 }
21642 }
21643 ret_val = nbmin;
21644 return ret_val;
21645
21646 L70:
21647
21648 /* ISPEC = 3: crossover point */
21649
21650 nx = 0;
21651 if (s_cmp(c2, "GE", 1_integer, 2_integer) == 0) {
21652 if (s_cmp(c3, "QRF", 1_integer, 3_integer) == 0 ||
21653 s_cmp(c3, "RQF", 1_integer, 3_integer) == 0 ||
21654 s_cmp(c3, "LQF", 1_integer, 3_integer) == 0 ||
21655 s_cmp(c3, "QLF", 1_integer, 3_integer) == 0) {
21656 if (sname) {
21657 nx = 128;
21658 } else {
21659 nx = 128;
21660 }
21661 } else if (s_cmp(c3, "HRD", 1_integer, 3_integer) == 0) {
21662 if (sname) {
21663 nx = 128;
21664 } else {
21665 nx = 128;
21666 }
21667 } else if (s_cmp(c3, "BRD", 1_integer, 3_integer) == 0) {
21668 if (sname) {
21669 nx = 128;
21670 } else {
21671 nx = 128;
21672 }
21673 }
21674 } else if (s_cmp(c2, "SY", 1_integer, 2_integer) == 0) {
21675 if (sname && s_cmp(c3, "TRD", 1_integer, 3_integer) == 0) {
21676 nx = 32;
21677 }
21678 } else if (cname && s_cmp(c2, "HE", 1_integer, 2_integer) == 0) {
21679 if (s_cmp(c3, "TRD", 1_integer, 3_integer) == 0) {
21680 nx = 32;
21681 }
21682 } else if (sname && s_cmp(c2, "OR", 1_integer, 2_integer) == 0) {
21683 if (*(unsigned char *)c3 == 'G') {
21684 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21685 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21686 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21687 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21688 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21689 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21690 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21691 nx = 128;
21692 }
21693 }
21694 } else if (cname && s_cmp(c2, "UN", 1_integer, 2_integer) == 0) {
21695 if (*(unsigned char *)c3 == 'G') {
21696 if (s_cmp(c4, "QR", 1_integer, 2_integer) == 0 ||
21697 s_cmp(c4, "RQ", 1_integer, 2_integer) == 0 ||
21698 s_cmp(c4, "LQ", 1_integer, 2_integer) == 0 ||
21699 s_cmp(c4, "QL", 1_integer, 2_integer) == 0 ||
21700 s_cmp(c4, "HR", 1_integer, 2_integer) == 0 ||
21701 s_cmp(c4, "TR", 1_integer, 2_integer) == 0 ||
21702 s_cmp(c4, "BR", 1_integer, 2_integer) == 0) {
21703 nx = 128;
21704 }
21705 }
21706 }
21707 ret_val = nx;
21708 return ret_val;
21709
21710 L80:
21711
21712 /* ISPEC = 4: number of shifts (used by xHSEQR) */
21713
21714 ret_val = 6;
21715 return ret_val;
21716
21717 L90:
21718
21719 /* ISPEC = 5: minimum column dimension (not used) */
21720
21721 ret_val = 2;
21722 return ret_val;
21723
21724 L100:
21725
21726 /* ISPEC = 6: crossover point for SVD (used by xGELSS and xGESVD) */
21727
21728 ret_val = (integer) ((float) std::min(*n1,*n2) * 1.6f);
21729 return ret_val;
21730
21731 L110:
21732
21733 /* ISPEC = 7: number of processors (not used) */
21734
21735 ret_val = 1;
21736 return ret_val;
21737
21738 L120:
21739
21740 /* ISPEC = 8: crossover point for multishift (used by xHSEQR) */
21741
21742 ret_val = 50;
21743 return ret_val;
21744
21745 L130:
21746
21747 /* ISPEC = 9: maximum size of the subproblems at the bottom of the */
21748 /* computation tree in the divide-and-conquer algorithm */
21749 /* (used by xGELSD and xGESDD) */
21750
21751 ret_val = 25;
21752 return ret_val;
21753
21754 L140:
21755
21756 /* ISPEC = 10: ieee NaN arithmetic can be trusted not to trap */
21757
21758 /* ILAENV = 0 */
21759 ret_val = 1;
21760 if (ret_val == 1) {
21761 ret_val = ieeeck_(&c__1, &c_b163, &c_b164);
21762 }
21763 return ret_val;
21764
21765 L150:
21766
21767 /* ISPEC = 11: infinity arithmetic can be trusted not to trap */
21768
21769 /* ILAENV = 0 */
21770 ret_val = 1;
21771 if (ret_val == 1) {
21772 ret_val = ieeeck_(&c__0, &c_b163, &c_b164);
21773 }
21774 return ret_val;
21775
21776 L160:
21777
21778 /* 12 <= ISPEC <= 16: xHSEQR or one of its subroutines. */
21779
21780 ret_val = iparmq_(ispec, name__, opts, n1, n2, n3, n4)
21781 ;
21782 return ret_val;
21783
21784 /* End of ILAENV */
21785
21786 } /* ilaenv_ */
21787
21788 integer ilaprec_(const char *prec)
21789 {
21790 /* System generated locals */
21791 integer ret_val;
21792
21793
21794 /* -- LAPACK routine (version 3.2) -- */
21795 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
21796 /* October 2008 */
21797 /* .. Scalar Arguments .. */
21798 /* .. */
21799
21800 /* Purpose */
21801 /* ======= */
21802
21803 /* This subroutine translated from a character string specifying an */
21804 /* intermediate precision to the relevant BLAST-specified integer */
21805 /* constant. */
21806
21807 /* ILAPREC returns an INTEGER. If ILAPREC < 0, then the input is not a */
21808 /* character indicating a supported intermediate precision. Otherwise */
21809 /* ILAPREC returns the constant value corresponding to PREC. */
21810
21811 /* Arguments */
21812 /* ========= */
21813 /* PREC (input) CHARACTER*1 */
21814 /* Specifies the form of the system of equations: */
21815 /* = 'S': Single */
21816 /* = 'D': Double */
21817 /* = 'I': Indigenous */
21818 /* = 'X', 'E': Extra */
21819 /* ===================================================================== */
21820
21821 /* .. Parameters .. */
21822 /* .. */
21823 /* .. External Functions .. */
21824 /* .. */
21825 /* .. Executable Statements .. */
21826 if (lsame_(prec, "S")) {
21827 ret_val = 211;
21828 } else if (lsame_(prec, "D")) {
21829 ret_val = 212;
21830 } else if (lsame_(prec, "I")) {
21831 ret_val = 213;
21832 } else if (lsame_(prec, "X") || lsame_(prec, "E")) {
21833 ret_val = 214;
21834 } else {
21835 ret_val = -1;
21836 }
21837 return ret_val;
21838
21839 /* End of ILAPREC */
21840
21841 } /* ilaprec_ */
21842
21843 integer ilatrans_(const char *trans)
21844 {
21845 /* System generated locals */
21846 integer ret_val;
21847
21848 /* -- LAPACK routine (version 3.2) -- */
21849 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
21850 /* October 2008 */
21851 /* .. Scalar Arguments .. */
21852 /* .. */
21853
21854 /* Purpose */
21855 /* ======= */
21856
21857 /* This subroutine translates from a character string specifying a */
21858 /* transposition operation to the relevant BLAST-specified integer */
21859 /* constant. */
21860
21861 /* ILATRANS returns an INTEGER. If ILATRANS < 0, then the input is not */
21862 /* a character indicating a transposition operator. Otherwise ILATRANS */
21863 /* returns the constant value corresponding to TRANS. */
21864
21865 /* Arguments */
21866 /* ========= */
21867 /* TRANS (input) CHARACTER*1 */
21868 /* Specifies the form of the system of equations: */
21869 /* = 'N': No transpose */
21870 /* = 'T': Transpose */
21871 /* = 'C': Conjugate transpose */
21872 /* ===================================================================== */
21873
21874 /* .. Parameters .. */
21875 /* .. */
21876 /* .. External Functions .. */
21877 /* .. */
21878 /* .. Executable Statements .. */
21879 if (lsame_(trans, "N")) {
21880 ret_val = 111;
21881 } else if (lsame_(trans, "T")) {
21882 ret_val = 112;
21883 } else if (lsame_(trans, "C")) {
21884 ret_val = 113;
21885 } else {
21886 ret_val = -1;
21887 }
21888 return ret_val;
21889
21890 /* End of ILATRANS */
21891
21892 } /* ilatrans_ */
21893
21894 /* Subroutine */ int ilaver_(integer *vers_major__, integer *vers_minor__,
21895 integer *vers_patch__)
21896 {
21897
21898 /* -- LAPACK routine (version 3.1.1) -- */
21899 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
21900 /* January 2007 */
21901
21902 /* .. Scalar Arguments .. */
21903 /* .. */
21904
21905 /* Purpose */
21906 /* ======= */
21907
21908 /* This subroutine return the Lapack version. */
21909
21910 /* Arguments */
21911 /* ========= */
21912
21913 /* VERS_MAJOR (output) INTEGER */
21914 /* return the lapack major version */
21915 /* VERS_MINOR (output) INTEGER */
21916 /* return the lapack minor version from the major version */
21917 /* VERS_PATCH (output) INTEGER */
21918 /* return the lapack patch version from the minor version */
21919
21920 /* .. Executable Statements .. */
21921
21922 *vers_major__ = 3;
21923 *vers_minor__ = 1;
21924 *vers_patch__ = 1;
21925 /* ===================================================================== */
21926
21927 return 0;
21928 } /* ilaver_ */
21929
21930 /* Subroutine */ integer iparmq_(integer *ispec, const char *name__, const char *opts, integer *n, integer
21931 *ilo, integer *ihi, integer *lwork)
21932 {
21933 /* System generated locals */
21934 integer ret_val, i__1, i__2;
21935 float r__1;
21936
21937 /* Local variables */
21938 integer nh, ns;
21939
21940
21941 /* -- LAPACK auxiliary routine (version 3.1) -- */
21942 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
21943 /* November 2006 */
21944
21945 /* .. Scalar Arguments .. */
21946
21947 /* Purpose */
21948 /* ======= */
21949
21950 /* This program sets problem and machine dependent parameters */
21951 /* useful for xHSEQR and its subroutines. It is called whenever */
21952 /* ILAENV is called with 12 <= ISPEC <= 16 */
21953
21954 /* Arguments */
21955 /* ========= */
21956
21957 /* ISPEC (input) integer scalar */
21958 /* ISPEC specifies which tunable parameter IPARMQ should */
21959 /* return. */
21960
21961 /* ISPEC=12: (INMIN) Matrices of order nmin or less */
21962 /* are sent directly to xLAHQR, the implicit */
21963 /* double shift QR algorithm. NMIN must be */
21964 /* at least 11. */
21965
21966 /* ISPEC=13: (INWIN) Size of the deflation window. */
21967 /* This is best set greater than or equal to */
21968 /* the number of simultaneous shifts NS. */
21969 /* Larger matrices benefit from larger deflation */
21970 /* windows. */
21971
21972 /* ISPEC=14: (INIBL) Determines when to stop nibbling and */
21973 /* invest in an (expensive) multi-shift QR sweep. */
21974 /* If the aggressive early deflation subroutine */
21975 /* finds LD converged eigenvalues from an order */
21976 /* NW deflation window and LD.GT.(NW*NIBBLE)/100, */
21977 /* then the next QR sweep is skipped and early */
21978 /* deflation is applied immediately to the */
21979 /* remaining active diagonal block. Setting */
21980 /* IPARMQ(ISPEC=14) = 0 causes TTQRE to skip a */
21981 /* multi-shift QR sweep whenever early deflation */
21982 /* finds a converged eigenvalue. Setting */
21983 /* IPARMQ(ISPEC=14) greater than or equal to 100 */
21984 /* prevents TTQRE from skipping a multi-shift */
21985 /* QR sweep. */
21986
21987 /* ISPEC=15: (NSHFTS) The number of simultaneous shifts in */
21988 /* a multi-shift QR iteration. */
21989
21990 /* ISPEC=16: (IACC22) IPARMQ is set to 0, 1 or 2 with the */
21991 /* following meanings. */
21992 /* 0: During the multi-shift QR sweep, */
21993 /* xLAQR5 does not accumulate reflections and */
21994 /* does not use matrix-matrix multiply to */
21995 /* update the far-from-diagonal matrix */
21996 /* entries. */
21997 /* 1: During the multi-shift QR sweep, */
21998 /* xLAQR5 and/or xLAQRaccumulates reflections and uses */
21999 /* matrix-matrix multiply to update the */
22000 /* far-from-diagonal matrix entries. */
22001 /* 2: During the multi-shift QR sweep. */
22002 /* xLAQR5 accumulates reflections and takes */
22003 /* advantage of 2-by-2 block structure during */
22004 /* matrix-matrix multiplies. */
22005 /* (If xTRMM is slower than xGEMM, then */
22006 /* IPARMQ(ISPEC=16)=1 may be more efficient than */
22007 /* IPARMQ(ISPEC=16)=2 despite the greater level of */
22008 /* arithmetic work implied by the latter choice.) */
22009
22010 /* NAME (input) character string */
22011 /* Name of the calling subroutine */
22012
22013 /* OPTS (input) character string */
22014 /* This is a concatenation of the string arguments to */
22015 /* TTQRE. */
22016
22017 /* N (input) integer scalar */
22018 /* N is the order of the Hessenberg matrix H. */
22019
22020 /* ILO (input) INTEGER */
22021 /* IHI (input) INTEGER */
22022 /* It is assumed that H is already upper triangular */
22023 /* in rows and columns 1:ILO-1 and IHI+1:N. */
22024
22025 /* LWORK (input) integer scalar */
22026 /* The amount of workspace available. */
22027
22028 /* Further Details */
22029 /* =============== */
22030
22031 /* Little is known about how best to choose these parameters. */
22032 /* It is possible to use different values of the parameters */
22033 /* for each of CHSEQR, DHSEQR, SHSEQR and ZHSEQR. */
22034
22035 /* It is probably best to choose different parameters for */
22036 /* different matrices and different parameters at different */
22037 /* times during the iteration, but this has not been */
22038 /* implemented --- yet. */
22039
22040
22041 /* The best choices of most of the parameters depend */
22042 /* in an ill-understood way on the relative execution */
22043 /* rate of xLAQR3 and xLAQR5 and on the nature of each */
22044 /* particular eigenvalue problem. Experiment may be the */
22045 /* only practical way to determine which choices are most */
22046 /* effective. */
22047
22048 /* Following is a list of default values supplied by IPARMQ. */
22049 /* These defaults may be adjusted in order to attain better */
22050 /* performance in any particular computational environment. */
22051
22052 /* IPARMQ(ISPEC=12) The xLAHQR vs xLAQR0 crossover point. */
22053 /* Default: 75. (Must be at least 11.) */
22054
22055 /* IPARMQ(ISPEC=13) Recommended deflation window size. */
22056 /* This depends on ILO, IHI and NS, the */
22057 /* number of simultaneous shifts returned */
22058 /* by IPARMQ(ISPEC=15). The default for */
22059 /* (IHI-ILO+1).LE.500 is NS. The default */
22060 /* for (IHI-ILO+1).GT.500 is 3*NS/2. */
22061
22062 /* IPARMQ(ISPEC=14) Nibble crossover point. Default: 14. */
22063
22064 /* IPARMQ(ISPEC=15) Number of simultaneous shifts, NS. */
22065 /* a multi-shift QR iteration. */
22066
22067 /* If IHI-ILO+1 is ... */
22068
22069 /* greater than ...but less ... the */
22070 /* or equal to ... than default is */
22071
22072 /* 0 30 NS = 2+ */
22073 /* 30 60 NS = 4+ */
22074 /* 60 150 NS = 10 */
22075 /* 150 590 NS = ** */
22076 /* 590 3000 NS = 64 */
22077 /* 3000 6000 NS = 128 */
22078 /* 6000 infinity NS = 256 */
22079
22080 /* (+) By default matrices of this order are */
22081 /* passed to the implicit double shift routine */
22082 /* xLAHQR. See IPARMQ(ISPEC=12) above. These */
22083 /* values of NS are used only in case of a rare */
22084 /* xLAHQR failure. */
22085
22086 /* (**) The asterisks (**) indicate an ad-hoc */
22087 /* function increasing from 10 to 64. */
22088
22089 /* IPARMQ(ISPEC=16) Select structured matrix multiply. */
22090 /* (See ISPEC=16 above for details.) */
22091 /* Default: 3. */
22092
22093 /* ================================================================ */
22094 /* .. Parameters .. */
22095 /* .. */
22096 /* .. Local Scalars .. */
22097 /* .. */
22098 /* .. Intrinsic Functions .. */
22099 /* .. */
22100 /* .. Executable Statements .. */
22101 if (*ispec == 15 || *ispec == 13 || *ispec == 16) {
22102
22103 /* ==== Set the number simultaneous shifts ==== */
22104
22105 nh = *ihi - *ilo + 1;
22106 ns = 2;
22107 if (nh >= 30) {
22108 ns = 4;
22109 }
22110 if (nh >= 60) {
22111 ns = 10;
22112 }
22113 if (nh >= 150) {
22114 /* Computing MAX */
22115 r__1 = log((float) nh) / log(2.f);
22116 i__1 = 10, i__2 = nh / i_nint(&r__1);
22117 ns = std::max(i__1,i__2);
22118 }
22119 if (nh >= 590) {
22120 ns = 64;
22121 }
22122 if (nh >= 3000) {
22123 ns = 128;
22124 }
22125 if (nh >= 6000) {
22126 ns = 256;
22127 }
22128 /* Computing MAX */
22129 i__1 = 2, i__2 = ns - ns % 2;
22130 ns = std::max(i__1,i__2);
22131 }
22132
22133 if (*ispec == 12) {
22134
22135
22136 /* ===== Matrices of order smaller than NMIN get sent */
22137 /* . to xLAHQR, the classic double shift algorithm. */
22138 /* . This must be at least 11. ==== */
22139
22140 ret_val = 75;
22141
22142 } else if (*ispec == 14) {
22143
22144 /* ==== INIBL: skip a multi-shift qr iteration and */
22145 /* . whenever aggressive early deflation finds */
22146 /* . at least (NIBBLE*(window size)/100) deflations. ==== */
22147
22148 ret_val = 14;
22149
22150 } else if (*ispec == 15) {
22151
22152 /* ==== NSHFTS: The number of simultaneous shifts ===== */
22153
22154 ret_val = ns;
22155
22156 } else if (*ispec == 13) {
22157
22158 /* ==== NW: deflation window size. ==== */
22159
22160 if (nh <= 500) {
22161 ret_val = ns;
22162 } else {
22163 ret_val = ns * 3 / 2;
22164 }
22165
22166 } else if (*ispec == 16) {
22167
22168 /* ==== IACC22: Whether to accumulate reflections */
22169 /* . before updating the far-from-diagonal elements */
22170 /* . and whether to use 2-by-2 block structure while */
22171 /* . doing it. A small amount of work could be saved */
22172 /* . by making this choice dependent also upon the */
22173 /* . NH=IHI-ILO+1. */
22174
22175 ret_val = 0;
22176 if (ns >= 14) {
22177 ret_val = 1;
22178 }
22179 if (ns >= 14) {
22180 ret_val = 2;
22181 }
22182
22183 } else {
22184 /* ===== invalid value of ispec ===== */
22185 ret_val = -1;
22186
22187 }
22188
22189 /* ==== End of IPARMQ ==== */
22190
22191 return ret_val;
22192 } /* iparmq_ */
22193
22194 /* Subroutine */ bool lsame_(const char *ca, const char *cb)
22195 {
22196 /* System generated locals */
22197 bool ret_val;
22198
22199 /* Local variables */
22200 integer inta, intb, zcode;
22201
22202
22203 /* -- LAPACK auxiliary routine (version 3.1) -- */
22204 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
22205 /* November 2006 */
22206
22207 /* .. Scalar Arguments .. */
22208 /* .. */
22209
22210 /* Purpose */
22211 /* ======= */
22212
22213 /* LSAME returns .TRUE. if CA is the same letter as CB regardless of */
22214 /* case. */
22215
22216 /* Arguments */
22217 /* ========= */
22218
22219 /* CA (input) CHARACTER*1 */
22220 /* CB (input) CHARACTER*1 */
22221 /* CA and CB specify the single characters to be compared. */
22222
22223 /* ===================================================================== */
22224
22225 /* .. Intrinsic Functions .. */
22226 /* .. */
22227 /* .. Local Scalars .. */
22228 /* .. */
22229 /* .. Executable Statements .. */
22230
22231 /* Test if the characters are equal */
22232
22233 ret_val = *(unsigned char *)ca == *(unsigned char *)cb;
22234 if (ret_val) {
22235 return ret_val;
22236 }
22237
22238 /* Now test for equivalence if both characters are alphabetic. */
22239
22240 zcode = 'Z';
22241
22242 /* Use 'Z' rather than 'A' so that ASCII can be detected on Prime */
22243 /* machines, on which ICHAR returns a value with bit 8 set. */
22244 /* ICHAR('A') on Prime machines returns 193 which is the same as */
22245 /* ICHAR('A') on an EBCDIC machine. */
22246
22247 inta = *(unsigned char *)ca;
22248 intb = *(unsigned char *)cb;
22249
22250 if (zcode == 90 || zcode == 122) {
22251
22252 /* ASCII is assumed - ZCODE is the ASCII code of either lower or */
22253 /* upper case 'Z'. */
22254
22255 if (inta >= 97 && inta <= 122) {
22256 inta += -32;
22257 }
22258 if (intb >= 97 && intb <= 122) {
22259 intb += -32;
22260 }
22261
22262 } else if (zcode == 233 || zcode == 169) {
22263
22264 /* EBCDIC is assumed - ZCODE is the EBCDIC code of either lower or */
22265 /* upper case 'Z'. */
22266
22267 if (inta >= 129 && inta <= 137 || inta >= 145 && inta <= 153 || inta
22268 >= 162 && inta <= 169) {
22269 inta += 64;
22270 }
22271 if (intb >= 129 && intb <= 137 || intb >= 145 && intb <= 153 || intb
22272 >= 162 && intb <= 169) {
22273 intb += 64;
22274 }
22275
22276 } else if (zcode == 218 || zcode == 250) {
22277
22278 /* ASCII is assumed, on Prime machines - ZCODE is the ASCII code */
22279 /* plus 128 of either lower or upper case 'Z'. */
22280
22281 if (inta >= 225 && inta <= 250) {
22282 inta += -32;
22283 }
22284 if (intb >= 225 && intb <= 250) {
22285 intb += -32;
22286 }
22287 }
22288 ret_val = inta == intb;
22289
22290 /* RETURN */
22291
22292 /* End of LSAME */
22293
22294 return ret_val;
22295 } /* lsame_ */
22296
22297 /* Subroutine */ bool lsamen_(integer *n, const char *ca, const char *cb)
22298 {
22299 /* System generated locals */
22300 integer i__1;
22301 bool ret_val;
22302
22303 /* Local variables */
22304 integer i__;
22305
22306 /* -- LAPACK auxiliary routine (version 3.1) -- */
22307 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
22308 /* November 2006 */
22309
22310 /* .. Scalar Arguments .. */
22311 /* .. */
22312
22313 /* Purpose */
22314 /* ======= */
22315
22316 /* LSAMEN tests if the first N letters of CA are the same as the */
22317 /* first N letters of CB, regardless of case. */
22318 /* LSAMEN returns .TRUE. if CA and CB are equivalent except for case */
22319 /* and .FALSE. otherwise. LSAMEN also returns .FALSE. if LEN( CA ) */
22320 /* or LEN( CB ) is less than N. */
22321
22322 /* Arguments */
22323 /* ========= */
22324
22325 /* N (input) INTEGER */
22326 /* The number of characters in CA and CB to be compared. */
22327
22328 /* CA (input) CHARACTER*(*) */
22329 /* CB (input) CHARACTER*(*) */
22330 /* CA and CB specify two character strings of length at least N. */
22331 /* Only the first N characters of each string will be accessed. */
22332
22333 /* ===================================================================== */
22334
22335 /* .. Local Scalars .. */
22336 /* .. */
22337 /* .. External Functions .. */
22338 /* .. */
22339 /* .. Intrinsic Functions .. */
22340 /* .. */
22341 /* .. Executable Statements .. */
22342
22343 ret_val = false;
22344 if (strlen(ca) < *n || strlen(cb) < *n) {
22345 goto L20;
22346 }
22347
22348 /* Do for each character in the two strings. */
22349
22350 i__1 = *n;
22351 for (i__ = 1; i__ <= i__1; ++i__) {
22352
22353 /* Test if the characters are equal using LSAME. */
22354
22355 if (! lsame_(ca + (i__ - 1), cb + (i__ - 1))) {
22356 goto L20;
22357 }
22358
22359 /* L10: */
22360 }
22361 ret_val = true;
22362
22363 L20:
22364 return ret_val;
22365
22366 /* End of LSAMEN */
22367
22368 } /* lsamen_ */
22369
22370 int slamc1_(integer *beta, integer *t, bool *rnd, bool *ieee1);
22371 int slamc2_(integer *beta, integer *t, bool *rnd, float *
22372 eps, integer *emin, float *rmin, integer *emax, float *rmax);
22373 double slamc3_(float *a, float *b);
22374 int slamc4_(integer *emin, float *start, integer *base);
22375 int slamc5_(integer *beta, integer *p, integer *emin,
22376 bool *ieee, integer *emax, float *rmax);
22377
22378 double slamch_(const char *cmach)
22379 {
22380 /* Initialized data */
22381
22382 static bool first = true;
22383
22384 /* System generated locals */
22385 integer i__1;
22386 float ret_val;
22387
22388 /* Local variables */
22389 static float t;
22390 integer it;
22391 static float rnd, eps, base;
22392 integer beta;
22393 static float emin, prec, emax;
22394 integer imin, imax;
22395 bool lrnd;
22396 static float rmin, rmax;
22397 float rmach;
22398 float small;
22399 static float sfmin;
22400
22401
22402 /* -- LAPACK auxiliary routine (version 3.1) -- */
22403 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
22404 /* November 2006 */
22405
22406 /* .. Scalar Arguments .. */
22407 /* .. */
22408
22409 /* Purpose */
22410 /* ======= */
22411
22412 /* SLAMCH determines single precision machine parameters. */
22413
22414 /* Arguments */
22415 /* ========= */
22416
22417 /* CMACH (input) CHARACTER*1 */
22418 /* Specifies the value to be returned by SLAMCH: */
22419 /* = 'E' or 'e', SLAMCH := eps */
22420 /* = 'S' or 's , SLAMCH := sfmin */
22421 /* = 'B' or 'b', SLAMCH := base */
22422 /* = 'P' or 'p', SLAMCH := eps*base */
22423 /* = 'N' or 'n', SLAMCH := t */
22424 /* = 'R' or 'r', SLAMCH := rnd */
22425 /* = 'M' or 'm', SLAMCH := emin */
22426 /* = 'U' or 'u', SLAMCH := rmin */
22427 /* = 'L' or 'l', SLAMCH := emax */
22428 /* = 'O' or 'o', SLAMCH := rmax */
22429
22430 /* where */
22431
22432 /* eps = relative machine precision */
22433 /* sfmin = safe minimum, such that 1/sfmin does not overflow */
22434 /* base = base of the machine */
22435 /* prec = eps*base */
22436 /* t = number of (base) digits in the mantissa */
22437 /* rnd = 1.0 when rounding occurs in addition, 0.0 otherwise */
22438 /* emin = minimum exponent before (gradual) underflow */
22439 /* rmin = underflow threshold - base**(emin-1) */
22440 /* emax = largest exponent before overflow */
22441 /* rmax = overflow threshold - (base**emax)*(1-eps) */
22442
22443 /* ===================================================================== */
22444
22445 /* .. Parameters .. */
22446 /* .. */
22447 /* .. Local Scalars .. */
22448 /* .. */
22449 /* .. External Functions .. */
22450 /* .. */
22451 /* .. External Subroutines .. */
22452 /* .. */
22453 /* .. Save statement .. */
22454 /* .. */
22455 /* .. Data statements .. */
22456 /* .. */
22457 /* .. Executable Statements .. */
22458
22459 if (first) {
22460 slamc2_(&beta, &it, &lrnd, &eps, &imin, &rmin, &imax, &rmax);
22461 base = (float) beta;
22462 t = (float) it;
22463 if (lrnd) {
22464 rnd = 1.f;
22465 i__1 = 1 - it;
22466 eps = pow_ri(&base, &i__1) / 2;
22467 } else {
22468 rnd = 0.f;
22469 i__1 = 1 - it;
22470 eps = pow_ri(&base, &i__1);
22471 }
22472 prec = eps * base;
22473 emin = (float) imin;
22474 emax = (float) imax;
22475 sfmin = rmin;
22476 small = 1.f / rmax;
22477 if (small >= sfmin) {
22478
22479 /* Use SMALL plus a bit, to avoid the possibility of rounding */
22480 /* causing overflow when computing 1/sfmin. */
22481
22482 sfmin = small * (eps + 1.f);
22483 }
22484 }
22485
22486 if (lsame_(cmach, "E")) {
22487 rmach = eps;
22488 } else if (lsame_(cmach, "S")) {
22489 rmach = sfmin;
22490 } else if (lsame_(cmach, "B")) {
22491 rmach = base;
22492 } else if (lsame_(cmach, "P")) {
22493 rmach = prec;
22494 } else if (lsame_(cmach, "N")) {
22495 rmach = t;
22496 } else if (lsame_(cmach, "R")) {
22497 rmach = rnd;
22498 } else if (lsame_(cmach, "M")) {
22499 rmach = emin;
22500 } else if (lsame_(cmach, "U")) {
22501 rmach = rmin;
22502 } else if (lsame_(cmach, "L")) {
22503 rmach = emax;
22504 } else if (lsame_(cmach, "O")) {
22505 rmach = rmax;
22506 }
22507
22508 ret_val = rmach;
22509 first = false;
22510 return ret_val;
22511
22512 /* End of SLAMCH */
22513
22514 } /* slamch_ */
22515
22516
22517 /* *********************************************************************** */
22518
22519 /* Subroutine */ int slamc1_(integer *beta, integer *t, bool *rnd, bool
22520 *ieee1)
22521 {
22522 /* Initialized data */
22523
22524 static bool first = true;
22525
22526 /* System generated locals */
22527 float r__1, r__2;
22528
22529 /* Local variables */
22530 float a, b, c__, f, t1, t2;
22531 static integer lt;
22532 float one, qtr;
22533 static bool lrnd;
22534 static integer lbeta;
22535 float savec;
22536 static bool lieee1;
22537
22538
22539 /* -- LAPACK auxiliary routine (version 3.1) -- */
22540 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
22541 /* November 2006 */
22542
22543 /* .. Scalar Arguments .. */
22544 /* .. */
22545
22546 /* Purpose */
22547 /* ======= */
22548
22549 /* SLAMC1 determines the machine parameters given by BETA, T, RND, and */
22550 /* IEEE1. */
22551
22552 /* Arguments */
22553 /* ========= */
22554
22555 /* BETA (output) INTEGER */
22556 /* The base of the machine. */
22557
22558 /* T (output) INTEGER */
22559 /* The number of ( BETA ) digits in the mantissa. */
22560
22561 /* RND (output) LOGICAL */
22562 /* Specifies whether proper rounding ( RND = .TRUE. ) or */
22563 /* chopping ( RND = .FALSE. ) occurs in addition. This may not */
22564 /* be a reliable guide to the way in which the machine performs */
22565 /* its arithmetic. */
22566
22567 /* IEEE1 (output) LOGICAL */
22568 /* Specifies whether rounding appears to be done in the IEEE */
22569 /* 'round to nearest' style. */
22570
22571 /* Further Details */
22572 /* =============== */
22573
22574 /* The routine is based on the routine ENVRON by Malcolm and */
22575 /* incorporates suggestions by Gentleman and Marovich. See */
22576
22577 /* Malcolm M. A. (1972) Algorithms to reveal properties of */
22578 /* floating-point arithmetic. Comms. of the ACM, 15, 949-951. */
22579
22580 /* Gentleman W. M. and Marovich S. B. (1974) More on algorithms */
22581 /* that reveal properties of floating point arithmetic units. */
22582 /* Comms. of the ACM, 17, 276-277. */
22583
22584 /* ===================================================================== */
22585
22586 /* .. Local Scalars .. */
22587 /* .. */
22588 /* .. External Functions .. */
22589 /* .. */
22590 /* .. Save statement .. */
22591 /* .. */
22592 /* .. Data statements .. */
22593 /* .. */
22594 /* .. Executable Statements .. */
22595
22596 if (first) {
22597 one = 1.f;
22598
22599 /* LBETA, LIEEE1, LT and LRND are the local values of BETA, */
22600 /* IEEE1, T and RND. */
22601
22602 /* Throughout this routine we use the function SLAMC3 to ensure */
22603 /* that relevant values are stored and not held in registers, or */
22604 /* are not affected by optimizers. */
22605
22606 /* Compute a = 2.0**m with the smallest positive integer m such */
22607 /* that */
22608
22609 /* fl( a + 1.0 ) = a. */
22610
22611 a = 1.f;
22612 c__ = 1.f;
22613
22614 /* + WHILE( C.EQ.ONE )LOOP */
22615 L10:
22616 if (c__ == one) {
22617 a *= 2;
22618 c__ = slamc3_(&a, &one);
22619 r__1 = -a;
22620 c__ = slamc3_(&c__, &r__1);
22621 goto L10;
22622 }
22623 /* + END WHILE */
22624
22625 /* Now compute b = 2.0**m with the smallest positive integer m */
22626 /* such that */
22627
22628 /* fl( a + b ) .gt. a. */
22629
22630 b = 1.f;
22631 c__ = slamc3_(&a, &b);
22632
22633 /* + WHILE( C.EQ.A )LOOP */
22634 L20:
22635 if (c__ == a) {
22636 b *= 2;
22637 c__ = slamc3_(&a, &b);
22638 goto L20;
22639 }
22640 /* + END WHILE */
22641
22642 /* Now compute the base. a and c are neighbouring floating point */
22643 /* numbers in the interval ( beta**t, beta**( t + 1 ) ) and so */
22644 /* their difference is beta. Adding 0.25 to c is to ensure that it */
22645 /* is truncated to beta and not ( beta - 1 ). */
22646
22647 qtr = one / 4;
22648 savec = c__;
22649 r__1 = -a;
22650 c__ = slamc3_(&c__, &r__1);
22651 lbeta = c__ + qtr;
22652
22653 /* Now determine whether rounding or chopping occurs, by adding a */
22654 /* bit less than beta/2 and a bit more than beta/2 to a. */
22655
22656 b = (float) lbeta;
22657 r__1 = b / 2;
22658 r__2 = -b / 100;
22659 f = slamc3_(&r__1, &r__2);
22660 c__ = slamc3_(&f, &a);
22661 if (c__ == a) {
22662 lrnd = true;
22663 } else {
22664 lrnd = false;
22665 }
22666 r__1 = b / 2;
22667 r__2 = b / 100;
22668 f = slamc3_(&r__1, &r__2);
22669 c__ = slamc3_(&f, &a);
22670 if (lrnd && c__ == a) {
22671 lrnd = false;
22672 }
22673
22674 /* Try and decide whether rounding is done in the IEEE 'round to */
22675 /* nearest' style. B/2 is half a unit in the last place of the two */
22676 /* numbers A and SAVEC. Furthermore, A is even, i.e. has last bit */
22677 /* zero, and SAVEC is odd. Thus adding B/2 to A should not change */
22678 /* A, but adding B/2 to SAVEC should change SAVEC. */
22679
22680 r__1 = b / 2;
22681 t1 = slamc3_(&r__1, &a);
22682 r__1 = b / 2;
22683 t2 = slamc3_(&r__1, &savec);
22684 lieee1 = t1 == a && t2 > savec && lrnd;
22685
22686 /* Now find the mantissa, t. It should be the integer part of */
22687 /* log to the base beta of a, however it is safer to determine t */
22688 /* by powering. So we find t as the smallest positive integer for */
22689 /* which */
22690
22691 /* fl( beta**t + 1.0 ) = 1.0. */
22692
22693 lt = 0;
22694 a = 1.f;
22695 c__ = 1.f;
22696
22697 /* + WHILE( C.EQ.ONE )LOOP */
22698 L30:
22699 if (c__ == one) {
22700 ++lt;
22701 a *= lbeta;
22702 c__ = slamc3_(&a, &one);
22703 r__1 = -a;
22704 c__ = slamc3_(&c__, &r__1);
22705 goto L30;
22706 }
22707 /* + END WHILE */
22708
22709 }
22710
22711 *beta = lbeta;
22712 *t = lt;
22713 *rnd = lrnd;
22714 *ieee1 = lieee1;
22715 first = false;
22716 return 0;
22717
22718 /* End of SLAMC1 */
22719
22720 } /* slamc1_ */
22721
22722
22723 /* *********************************************************************** */
22724
22725 /* Subroutine */ int slamc2_(integer *beta, integer *t, bool *rnd, float *
22726 eps, integer *emin, float *rmin, integer *emax, float *rmax)
22727 {
22728 /* Initialized data */
22729
22730 static bool first = true;
22731 static bool iwarn = false;
22732
22733 /* System generated locals */
22734 integer i__1;
22735 float r__1, r__2, r__3, r__4, r__5;
22736
22737 /* Local variables */
22738 float a, b, c__;
22739 integer i__;
22740 static integer lt;
22741 float one, two;
22742 bool ieee;
22743 float half;
22744 bool lrnd;
22745 static float leps;
22746 float zero;
22747 static integer lbeta;
22748 float rbase;
22749 static integer lemin, lemax;
22750 integer gnmin;
22751 float small;
22752 integer gpmin;
22753 float third;
22754 static float lrmin, lrmax;
22755 float sixth;
22756 bool lieee1;
22757 integer ngnmin, ngpmin;
22758
22759 /* -- LAPACK auxiliary routine (version 3.1) -- */
22760 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
22761 /* November 2006 */
22762
22763 /* .. Scalar Arguments .. */
22764 /* .. */
22765
22766 /* Purpose */
22767 /* ======= */
22768
22769 /* SLAMC2 determines the machine parameters specified in its argument */
22770 /* list. */
22771
22772 /* Arguments */
22773 /* ========= */
22774
22775 /* BETA (output) INTEGER */
22776 /* The base of the machine. */
22777
22778 /* T (output) INTEGER */
22779 /* The number of ( BETA ) digits in the mantissa. */
22780
22781 /* RND (output) LOGICAL */
22782 /* Specifies whether proper rounding ( RND = .TRUE. ) or */
22783 /* chopping ( RND = .FALSE. ) occurs in addition. This may not */
22784 /* be a reliable guide to the way in which the machine performs */
22785 /* its arithmetic. */
22786
22787 /* EPS (output) REAL */
22788 /* The smallest positive number such that */
22789
22790 /* fl( 1.0 - EPS ) .LT. 1.0, */
22791
22792 /* where fl denotes the computed value. */
22793
22794 /* EMIN (output) INTEGER */
22795 /* The minimum exponent before (gradual) underflow occurs. */
22796
22797 /* RMIN (output) REAL */
22798 /* The smallest normalized number for the machine, given by */
22799 /* BASE**( EMIN - 1 ), where BASE is the floating point value */
22800 /* of BETA. */
22801
22802 /* EMAX (output) INTEGER */
22803 /* The maximum exponent before overflow occurs. */
22804
22805 /* RMAX (output) REAL */
22806 /* The largest positive number for the machine, given by */
22807 /* BASE**EMAX * ( 1 - EPS ), where BASE is the floating point */
22808 /* value of BETA. */
22809
22810 /* Further Details */
22811 /* =============== */
22812
22813 /* The computation of EPS is based on a routine PARANOIA by */
22814 /* W. Kahan of the University of California at Berkeley. */
22815
22816 /* ===================================================================== */
22817
22818 /* .. Local Scalars .. */
22819 /* .. */
22820 /* .. External Functions .. */
22821 /* .. */
22822 /* .. External Subroutines .. */
22823 /* .. */
22824 /* .. Intrinsic Functions .. */
22825 /* .. */
22826 /* .. Save statement .. */
22827 /* .. */
22828 /* .. Data statements .. */
22829 /* .. */
22830 /* .. Executable Statements .. */
22831
22832 if (first) {
22833 zero = 0.f;
22834 one = 1.f;
22835 two = 2.f;
22836
22837 /* LBETA, LT, LRND, LEPS, LEMIN and LRMIN are the local values of */
22838 /* BETA, T, RND, EPS, EMIN and RMIN. */
22839
22840 /* Throughout this routine we use the function SLAMC3 to ensure */
22841 /* that relevant values are stored and not held in registers, or */
22842 /* are not affected by optimizers. */
22843
22844 /* SLAMC1 returns the parameters LBETA, LT, LRND and LIEEE1. */
22845
22846 slamc1_(&lbeta, &lt, &lrnd, &lieee1);
22847
22848 /* Start to find EPS. */
22849
22850 b = (float) lbeta;
22851 i__1 = -lt;
22852 a = pow_ri(&b, &i__1);
22853 leps = a;
22854
22855 /* Try some tricks to see whether or not this is the correct EPS. */
22856
22857 b = two / 3;
22858 half = one / 2;
22859 r__1 = -half;
22860 sixth = slamc3_(&b, &r__1);
22861 third = slamc3_(&sixth, &sixth);
22862 r__1 = -half;
22863 b = slamc3_(&third, &r__1);
22864 b = slamc3_(&b, &sixth);
22865 b = abs(b);
22866 if (b < leps) {
22867 b = leps;
22868 }
22869
22870 leps = 1.f;
22871
22872 /* + WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP */
22873 L10:
22874 if (leps > b && b > zero) {
22875 leps = b;
22876 r__1 = half * leps;
22877 /* Computing 5th power */
22878 r__3 = two, r__4 = r__3, r__3 *= r__3;
22879 /* Computing 2nd power */
22880 r__5 = leps;
22881 r__2 = r__4 * (r__3 * r__3) * (r__5 * r__5);
22882 c__ = slamc3_(&r__1, &r__2);
22883 r__1 = -c__;
22884 c__ = slamc3_(&half, &r__1);
22885 b = slamc3_(&half, &c__);
22886 r__1 = -b;
22887 c__ = slamc3_(&half, &r__1);
22888 b = slamc3_(&half, &c__);
22889 goto L10;
22890 }
22891 /* + END WHILE */
22892
22893 if (a < leps) {
22894 leps = a;
22895 }
22896
22897 /* Computation of EPS complete. */
22898
22899 /* Now find EMIN. Let A = + or - 1, and + or - (1 + BASE**(-3)). */
22900 /* Keep dividing A by BETA until (gradual) underflow occurs. This */
22901 /* is detected when we cannot recover the previous A. */
22902
22903 rbase = one / lbeta;
22904 small = one;
22905 for (i__ = 1; i__ <= 3; ++i__) {
22906 r__1 = small * rbase;
22907 small = slamc3_(&r__1, &zero);
22908 /* L20: */
22909 }
22910 a = slamc3_(&one, &small);
22911 slamc4_(&ngpmin, &one, &lbeta);
22912 r__1 = -one;
22913 slamc4_(&ngnmin, &r__1, &lbeta);
22914 slamc4_(&gpmin, &a, &lbeta);
22915 r__1 = -a;
22916 slamc4_(&gnmin, &r__1, &lbeta);
22917 ieee = false;
22918
22919 if (ngpmin == ngnmin && gpmin == gnmin) {
22920 if (ngpmin == gpmin) {
22921 lemin = ngpmin;
22922 /* ( Non twos-complement machines, no gradual underflow; */
22923 /* e.g., VAX ) */
22924 } else if (gpmin - ngpmin == 3) {
22925 lemin = ngpmin - 1 + lt;
22926 ieee = true;
22927 /* ( Non twos-complement machines, with gradual underflow; */
22928 /* e.g., IEEE standard followers ) */
22929 } else {
22930 lemin = std::min(ngpmin,gpmin);
22931 /* ( A guess; no known machine ) */
22932 iwarn = true;
22933 }
22934
22935 } else if (ngpmin == gpmin && ngnmin == gnmin) {
22936 if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1) {
22937 lemin = std::max(ngpmin,ngnmin);
22938 /* ( Twos-complement machines, no gradual underflow; */
22939 /* e.g., CYBER 205 ) */
22940 } else {
22941 lemin = std::min(ngpmin,ngnmin);
22942 /* ( A guess; no known machine ) */
22943 iwarn = true;
22944 }
22945
22946 } else if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1 && gpmin == gnmin)
22947 {
22948 if (gpmin - std::min(ngpmin,ngnmin) == 3) {
22949 lemin = std::max(ngpmin,ngnmin) - 1 + lt;
22950 /* ( Twos-complement machines with gradual underflow; */
22951 /* no known machine ) */
22952 } else {
22953 lemin = std::min(ngpmin,ngnmin);
22954 /* ( A guess; no known machine ) */
22955 iwarn = true;
22956 }
22957
22958 } else {
22959 /* Computing MIN */
22960 i__1 = std::min(ngpmin,ngnmin), i__1 = std::min(i__1,gpmin);
22961 lemin = std::min(i__1,gnmin);
22962 /* ( A guess; no known machine ) */
22963 iwarn = true;
22964 }
22965 first = false;
22966 /* ** */
22967 /* Comment out this if block if EMIN is ok */
22968 if (iwarn) {
22969 first = true;
22970 Melder_warning (U"WARNING. The value EMIN may be incorrect:- \n"
22971 "EMIN = ", lemin,
22972 U"If, after inspection, the value EMIN looks acceptable please comment out \n"
22973 "the IF block as marked within the code of routine SLAMC2; \n "
22974 "otherwise, supply EMIN explicitly.\n");
22975 }
22976 /* ** */
22977
22978 /* Assume IEEE arithmetic if we found denormalised numbers above, */
22979 /* or if arithmetic seems to round in the IEEE style, determined */
22980 /* in routine SLAMC1. A true IEEE machine should have both things */
22981 /* true; however, faulty machines may have one or the other. */
22982
22983 ieee = ieee || lieee1;
22984
22985 /* Compute RMIN by successive division by BETA. We could compute */
22986 /* RMIN as BASE**( EMIN - 1 ), but some machines underflow during */
22987 /* this computation. */
22988
22989 lrmin = 1.f;
22990 i__1 = 1 - lemin;
22991 for (i__ = 1; i__ <= i__1; ++i__) {
22992 r__1 = lrmin * rbase;
22993 lrmin = slamc3_(&r__1, &zero);
22994 /* L30: */
22995 }
22996
22997 /* Finally, call SLAMC5 to compute EMAX and RMAX. */
22998
22999 slamc5_(&lbeta, &lt, &lemin, &ieee, &lemax, &lrmax);
23000 }
23001
23002 *beta = lbeta;
23003 *t = lt;
23004 *rnd = lrnd;
23005 *eps = leps;
23006 *emin = lemin;
23007 *rmin = lrmin;
23008 *emax = lemax;
23009 *rmax = lrmax;
23010
23011 return 0;
23012
23013
23014 /* End of SLAMC2 */
23015
23016 } /* slamc2_ */
23017
23018
23019 /* *********************************************************************** */
23020
23021 double slamc3_(float *a, float *b)
23022 {
23023 /* System generated locals */
23024 volatile float ret_val;
23025
23026
23027 /* -- LAPACK auxiliary routine (version 3.1) -- */
23028 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
23029 /* November 2006 */
23030
23031 /* .. Scalar Arguments .. */
23032 /* .. */
23033
23034 /* Purpose */
23035 /* ======= */
23036
23037 /* SLAMC3 is intended to force A and B to be stored prior to doing */
23038 /* the addition of A and B , for use in situations where optimizers */
23039 /* might hold one of these in a register. */
23040
23041 /* Arguments */
23042 /* ========= */
23043
23044 /* A (input) REAL */
23045 /* B (input) REAL */
23046 /* The values A and B. */
23047
23048 /* ===================================================================== */
23049
23050 /* .. Executable Statements .. */
23051
23052 ret_val = *a + *b;
23053
23054 return ret_val;
23055
23056 /* End of SLAMC3 */
23057
23058 } /* slamc3_ */
23059
23060
23061 /* *********************************************************************** */
23062
23063 /* Subroutine */ int slamc4_(integer *emin, float *start, integer *base)
23064 {
23065 /* System generated locals */
23066 integer i__1;
23067 float r__1;
23068
23069 /* Local variables */
23070 float a;
23071 integer i__;
23072 float b1, b2, c1, c2, d1, d2, one, zero, rbase;
23073
23074
23075 /* -- LAPACK auxiliary routine (version 3.1) -- */
23076 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
23077 /* November 2006 */
23078
23079 /* .. Scalar Arguments .. */
23080 /* .. */
23081
23082 /* Purpose */
23083 /* ======= */
23084
23085 /* SLAMC4 is a service routine for SLAMC2. */
23086
23087 /* Arguments */
23088 /* ========= */
23089
23090 /* EMIN (output) INTEGER */
23091 /* The minimum exponent before (gradual) underflow, computed by */
23092 /* setting A = START and dividing by BASE until the previous A */
23093 /* can not be recovered. */
23094
23095 /* START (input) REAL */
23096 /* The starting point for determining EMIN. */
23097
23098 /* BASE (input) INTEGER */
23099 /* The base of the machine. */
23100
23101 /* ===================================================================== */
23102
23103 /* .. Local Scalars .. */
23104 /* .. */
23105 /* .. External Functions .. */
23106 /* .. */
23107 /* .. Executable Statements .. */
23108
23109 a = *start;
23110 one = 1.f;
23111 rbase = one / *base;
23112 zero = 0.f;
23113 *emin = 1;
23114 r__1 = a * rbase;
23115 b1 = slamc3_(&r__1, &zero);
23116 c1 = a;
23117 c2 = a;
23118 d1 = a;
23119 d2 = a;
23120 /* + WHILE( ( C1.EQ.A ).AND.( C2.EQ.A ).AND. */
23121 /* $ ( D1.EQ.A ).AND.( D2.EQ.A ) )LOOP */
23122 L10:
23123 if (c1 == a && c2 == a && d1 == a && d2 == a) {
23124 --(*emin);
23125 a = b1;
23126 r__1 = a / *base;
23127 b1 = slamc3_(&r__1, &zero);
23128 r__1 = b1 * *base;
23129 c1 = slamc3_(&r__1, &zero);
23130 d1 = zero;
23131 i__1 = *base;
23132 for (i__ = 1; i__ <= i__1; ++i__) {
23133 d1 += b1;
23134 /* L20: */
23135 }
23136 r__1 = a * rbase;
23137 b2 = slamc3_(&r__1, &zero);
23138 r__1 = b2 / rbase;
23139 c2 = slamc3_(&r__1, &zero);
23140 d2 = zero;
23141 i__1 = *base;
23142 for (i__ = 1; i__ <= i__1; ++i__) {
23143 d2 += b2;
23144 /* L30: */
23145 }
23146 goto L10;
23147 }
23148 /* + END WHILE */
23149
23150 return 0;
23151
23152 /* End of SLAMC4 */
23153
23154 } /* slamc4_ */
23155
23156
23157 /* *********************************************************************** */
23158
23159 /* Subroutine */ int slamc5_(integer *beta, integer *p, integer *emin,
23160 bool *ieee, integer *emax, float *rmax)
23161 {
23162 /* Table of constant values */
23163 static float c_b32 = 0.f;
23164
23165 /* System generated locals */
23166 integer i__1;
23167 float r__1;
23168
23169 /* Local variables */
23170 integer i__;
23171 float y, z__;
23172 integer try__, lexp;
23173 float oldy;
23174 integer uexp, nbits;
23175 float recbas;
23176 integer exbits, expsum;
23177
23178
23179 /* -- LAPACK auxiliary routine (version 3.1) -- */
23180 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
23181 /* November 2006 */
23182
23183 /* .. Scalar Arguments .. */
23184 /* .. */
23185
23186 /* Purpose */
23187 /* ======= */
23188
23189 /* SLAMC5 attempts to compute RMAX, the largest machine floating-point */
23190 /* number, without overflow. It assumes that EMAX + abs(EMIN) sum */
23191 /* approximately to a power of 2. It will fail on machines where this */
23192 /* assumption does not hold, for example, the Cyber 205 (EMIN = -28625, */
23193 /* EMAX = 28718). It will also fail if the value supplied for EMIN is */
23194 /* too large (i.e. too close to zero), probably with overflow. */
23195
23196 /* Arguments */
23197 /* ========= */
23198
23199 /* BETA (input) INTEGER */
23200 /* The base of floating-point arithmetic. */
23201
23202 /* P (input) INTEGER */
23203 /* The number of base BETA digits in the mantissa of a */
23204 /* floating-point value. */
23205
23206 /* EMIN (input) INTEGER */
23207 /* The minimum exponent before (gradual) underflow. */
23208
23209 /* IEEE (input) LOGICAL */
23210 /* A logical flag specifying whether or not the arithmetic */
23211 /* system is thought to comply with the IEEE standard. */
23212
23213 /* EMAX (output) INTEGER */
23214 /* The largest exponent before overflow */
23215
23216 /* RMAX (output) REAL */
23217 /* The largest machine floating-point number. */
23218
23219 /* ===================================================================== */
23220
23221 /* .. Parameters .. */
23222 /* .. */
23223 /* .. Local Scalars .. */
23224 /* .. */
23225 /* .. External Functions .. */
23226 /* .. */
23227 /* .. Intrinsic Functions .. */
23228 /* .. */
23229 /* .. Executable Statements .. */
23230
23231 /* First compute LEXP and UEXP, two powers of 2 that bound */
23232 /* abs(EMIN). We then assume that EMAX + abs(EMIN) will sum */
23233 /* approximately to the bound that is closest to abs(EMIN). */
23234 /* (EMAX is the exponent of the required number RMAX). */
23235
23236 lexp = 1;
23237 exbits = 1;
23238 L10:
23239 try__ = lexp << 1;
23240 if (try__ <= -(*emin)) {
23241 lexp = try__;
23242 ++exbits;
23243 goto L10;
23244 }
23245 if (lexp == -(*emin)) {
23246 uexp = lexp;
23247 } else {
23248 uexp = try__;
23249 ++exbits;
23250 }
23251
23252 /* Now -LEXP is less than or equal to EMIN, and -UEXP is greater */
23253 /* than or equal to EMIN. EXBITS is the number of bits needed to */
23254 /* store the exponent. */
23255
23256 if (uexp + *emin > -lexp - *emin) {
23257 expsum = lexp << 1;
23258 } else {
23259 expsum = uexp << 1;
23260 }
23261
23262 /* EXPSUM is the exponent range, approximately equal to */
23263 /* EMAX - EMIN + 1 . */
23264
23265 *emax = expsum + *emin - 1;
23266 nbits = exbits + 1 + *p;
23267
23268 /* NBITS is the total number of bits needed to store a */
23269 /* floating-point number. */
23270
23271 if (nbits % 2 == 1 && *beta == 2) {
23272
23273 /* Either there are an odd number of bits used to store a */
23274 /* floating-point number, which is unlikely, or some bits are */
23275 /* not used in the representation of numbers, which is possible, */
23276 /* (e.g. Cray machines) or the mantissa has an implicit bit, */
23277 /* (e.g. IEEE machines, Dec Vax machines), which is perhaps the */
23278 /* most likely. We have to assume the last alternative. */
23279 /* If this is true, then we need to reduce EMAX by one because */
23280 /* there must be some way of representing zero in an implicit-bit */
23281 /* system. On machines like Cray, we are reducing EMAX by one */
23282 /* unnecessarily. */
23283
23284 --(*emax);
23285 }
23286
23287 if (*ieee) {
23288
23289 /* Assume we are on an IEEE machine which reserves one exponent */
23290 /* for infinity and NaN. */
23291
23292 --(*emax);
23293 }
23294
23295 /* Now create RMAX, the largest machine number, which should */
23296 /* be equal to (1.0 - BETA**(-P)) * BETA**EMAX . */
23297
23298 /* First compute 1.0 - BETA**(-P), being careful that the */
23299 /* result is less than 1.0 . */
23300
23301 recbas = 1.f / *beta;
23302 z__ = *beta - 1.f;
23303 y = 0.f;
23304 i__1 = *p;
23305 for (i__ = 1; i__ <= i__1; ++i__) {
23306 z__ *= recbas;
23307 if (y < 1.f) {
23308 oldy = y;
23309 }
23310 y = slamc3_(&y, &z__);
23311 /* L20: */
23312 }
23313 if (y >= 1.f) {
23314 y = oldy;
23315 }
23316
23317 /* Now multiply by BETA**EMAX to get RMAX. */
23318
23319 i__1 = *emax;
23320 for (i__ = 1; i__ <= i__1; ++i__) {
23321 r__1 = y * *beta;
23322 y = slamc3_(&r__1, &c_b32);
23323 /* L30: */
23324 }
23325
23326 *rmax = y;
23327 return 0;
23328
23329 /* End of SLAMC5 */
23330
23331 } /* slamc5_ */