Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
numpy
GitHub Repository: numpy/numpy
Path: blob/main/numpy/linalg/lapack_lite/f2c_z_lapack.c
2042 views
1
/*
2
* NOTE: This is generated code. Look in numpy/linalg/lapack_lite for
3
* information on remaking this file.
4
*/
5
#include "f2c.h"
6
7
#ifdef HAVE_CONFIG
8
#include "config.h"
9
#else
10
extern doublereal dlamch_(char *);
11
#define EPSILON dlamch_("Epsilon")
12
#define SAFEMINIMUM dlamch_("Safe minimum")
13
#define PRECISION dlamch_("Precision")
14
#define BASE dlamch_("Base")
15
#endif
16
17
extern doublereal dlapy2_(doublereal *x, doublereal *y);
18
19
/*
20
f2c knows the exact rules for precedence, and so omits parentheses where not
21
strictly necessary. Since this is generated code, we don't really care if
22
it's readable, and we know what is written is correct. So don't warn about
23
them.
24
*/
25
#if defined(__GNUC__)
26
#pragma GCC diagnostic ignored "-Wparentheses"
27
#endif
28
29
30
/* Table of constant values */
31
32
static integer c__1 = 1;
33
static doublecomplex c_b56 = {0.,0.};
34
static doublecomplex c_b57 = {1.,0.};
35
static integer c_n1 = -1;
36
static integer c__3 = 3;
37
static integer c__2 = 2;
38
static integer c__0 = 0;
39
static integer c__65 = 65;
40
static integer c__9 = 9;
41
static integer c__6 = 6;
42
static doublereal c_b328 = 0.;
43
static doublereal c_b1034 = 1.;
44
static integer c__12 = 12;
45
static integer c__49 = 49;
46
static doublereal c_b1276 = -1.;
47
static integer c__13 = 13;
48
static integer c__15 = 15;
49
static integer c__14 = 14;
50
static integer c__16 = 16;
51
static logical c_false = FALSE_;
52
static logical c_true = TRUE_;
53
static doublereal c_b2435 = .5;
54
55
/* Subroutine */ int zgebak_(char *job, char *side, integer *n, integer *ilo,
56
integer *ihi, doublereal *scale, integer *m, doublecomplex *v,
57
integer *ldv, integer *info)
58
{
59
/* System generated locals */
60
integer v_dim1, v_offset, i__1;
61
62
/* Local variables */
63
static integer i__, k;
64
static doublereal s;
65
static integer ii;
66
extern logical lsame_(char *, char *);
67
static logical leftv;
68
extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *,
69
doublecomplex *, integer *), xerbla_(char *, integer *),
70
zdscal_(integer *, doublereal *, doublecomplex *, integer *);
71
static logical rightv;
72
73
74
/*
75
-- LAPACK routine (version 3.2) --
76
-- LAPACK is a software package provided by Univ. of Tennessee, --
77
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
78
November 2006
79
80
81
Purpose
82
=======
83
84
ZGEBAK forms the right or left eigenvectors of a complex general
85
matrix by backward transformation on the computed eigenvectors of the
86
balanced matrix output by ZGEBAL.
87
88
Arguments
89
=========
90
91
JOB (input) CHARACTER*1
92
Specifies the type of backward transformation required:
93
= 'N', do nothing, return immediately;
94
= 'P', do backward transformation for permutation only;
95
= 'S', do backward transformation for scaling only;
96
= 'B', do backward transformations for both permutation and
97
scaling.
98
JOB must be the same as the argument JOB supplied to ZGEBAL.
99
100
SIDE (input) CHARACTER*1
101
= 'R': V contains right eigenvectors;
102
= 'L': V contains left eigenvectors.
103
104
N (input) INTEGER
105
The number of rows of the matrix V. N >= 0.
106
107
ILO (input) INTEGER
108
IHI (input) INTEGER
109
The integers ILO and IHI determined by ZGEBAL.
110
1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
111
112
SCALE (input) DOUBLE PRECISION array, dimension (N)
113
Details of the permutation and scaling factors, as returned
114
by ZGEBAL.
115
116
M (input) INTEGER
117
The number of columns of the matrix V. M >= 0.
118
119
V (input/output) COMPLEX*16 array, dimension (LDV,M)
120
On entry, the matrix of right or left eigenvectors to be
121
transformed, as returned by ZHSEIN or ZTREVC.
122
On exit, V is overwritten by the transformed eigenvectors.
123
124
LDV (input) INTEGER
125
The leading dimension of the array V. LDV >= max(1,N).
126
127
INFO (output) INTEGER
128
= 0: successful exit
129
< 0: if INFO = -i, the i-th argument had an illegal value.
130
131
=====================================================================
132
133
134
Decode and Test the input parameters
135
*/
136
137
/* Parameter adjustments */
138
--scale;
139
v_dim1 = *ldv;
140
v_offset = 1 + v_dim1;
141
v -= v_offset;
142
143
/* Function Body */
144
rightv = lsame_(side, "R");
145
leftv = lsame_(side, "L");
146
147
*info = 0;
148
if (! lsame_(job, "N") && ! lsame_(job, "P") && ! lsame_(job, "S")
149
&& ! lsame_(job, "B")) {
150
*info = -1;
151
} else if (! rightv && ! leftv) {
152
*info = -2;
153
} else if (*n < 0) {
154
*info = -3;
155
} else if (*ilo < 1 || *ilo > max(1,*n)) {
156
*info = -4;
157
} else if (*ihi < min(*ilo,*n) || *ihi > *n) {
158
*info = -5;
159
} else if (*m < 0) {
160
*info = -7;
161
} else if (*ldv < max(1,*n)) {
162
*info = -9;
163
}
164
if (*info != 0) {
165
i__1 = -(*info);
166
xerbla_("ZGEBAK", &i__1);
167
return 0;
168
}
169
170
/* Quick return if possible */
171
172
if (*n == 0) {
173
return 0;
174
}
175
if (*m == 0) {
176
return 0;
177
}
178
if (lsame_(job, "N")) {
179
return 0;
180
}
181
182
if (*ilo == *ihi) {
183
goto L30;
184
}
185
186
/* Backward balance */
187
188
if (lsame_(job, "S") || lsame_(job, "B")) {
189
190
if (rightv) {
191
i__1 = *ihi;
192
for (i__ = *ilo; i__ <= i__1; ++i__) {
193
s = scale[i__];
194
zdscal_(m, &s, &v[i__ + v_dim1], ldv);
195
/* L10: */
196
}
197
}
198
199
if (leftv) {
200
i__1 = *ihi;
201
for (i__ = *ilo; i__ <= i__1; ++i__) {
202
s = 1. / scale[i__];
203
zdscal_(m, &s, &v[i__ + v_dim1], ldv);
204
/* L20: */
205
}
206
}
207
208
}
209
210
/*
211
Backward permutation
212
213
For I = ILO-1 step -1 until 1,
214
IHI+1 step 1 until N do --
215
*/
216
217
L30:
218
if (lsame_(job, "P") || lsame_(job, "B")) {
219
if (rightv) {
220
i__1 = *n;
221
for (ii = 1; ii <= i__1; ++ii) {
222
i__ = ii;
223
if (i__ >= *ilo && i__ <= *ihi) {
224
goto L40;
225
}
226
if (i__ < *ilo) {
227
i__ = *ilo - ii;
228
}
229
k = (integer) scale[i__];
230
if (k == i__) {
231
goto L40;
232
}
233
zswap_(m, &v[i__ + v_dim1], ldv, &v[k + v_dim1], ldv);
234
L40:
235
;
236
}
237
}
238
239
if (leftv) {
240
i__1 = *n;
241
for (ii = 1; ii <= i__1; ++ii) {
242
i__ = ii;
243
if (i__ >= *ilo && i__ <= *ihi) {
244
goto L50;
245
}
246
if (i__ < *ilo) {
247
i__ = *ilo - ii;
248
}
249
k = (integer) scale[i__];
250
if (k == i__) {
251
goto L50;
252
}
253
zswap_(m, &v[i__ + v_dim1], ldv, &v[k + v_dim1], ldv);
254
L50:
255
;
256
}
257
}
258
}
259
260
return 0;
261
262
/* End of ZGEBAK */
263
264
} /* zgebak_ */
265
266
/* Subroutine */ int zgebal_(char *job, integer *n, doublecomplex *a, integer
267
*lda, integer *ilo, integer *ihi, doublereal *scale, integer *info)
268
{
269
/* System generated locals */
270
integer a_dim1, a_offset, i__1, i__2, i__3;
271
doublereal d__1, d__2;
272
273
/* Local variables */
274
static doublereal c__, f, g;
275
static integer i__, j, k, l, m;
276
static doublereal r__, s, ca, ra;
277
static integer ica, ira, iexc;
278
extern logical lsame_(char *, char *);
279
extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *,
280
doublecomplex *, integer *);
281
static doublereal sfmin1, sfmin2, sfmax1, sfmax2;
282
283
extern logical disnan_(doublereal *);
284
extern /* Subroutine */ int xerbla_(char *, integer *), zdscal_(
285
integer *, doublereal *, doublecomplex *, integer *);
286
extern integer izamax_(integer *, doublecomplex *, integer *);
287
static logical noconv;
288
289
290
/*
291
-- LAPACK routine (version 3.2.2) --
292
-- LAPACK is a software package provided by Univ. of Tennessee, --
293
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
294
June 2010
295
296
297
Purpose
298
=======
299
300
ZGEBAL balances a general complex matrix A. This involves, first,
301
permuting A by a similarity transformation to isolate eigenvalues
302
in the first 1 to ILO-1 and last IHI+1 to N elements on the
303
diagonal; and second, applying a diagonal similarity transformation
304
to rows and columns ILO to IHI to make the rows and columns as
305
close in norm as possible. Both steps are optional.
306
307
Balancing may reduce the 1-norm of the matrix, and improve the
308
accuracy of the computed eigenvalues and/or eigenvectors.
309
310
Arguments
311
=========
312
313
JOB (input) CHARACTER*1
314
Specifies the operations to be performed on A:
315
= 'N': none: simply set ILO = 1, IHI = N, SCALE(I) = 1.0
316
for i = 1,...,N;
317
= 'P': permute only;
318
= 'S': scale only;
319
= 'B': both permute and scale.
320
321
N (input) INTEGER
322
The order of the matrix A. N >= 0.
323
324
A (input/output) COMPLEX*16 array, dimension (LDA,N)
325
On entry, the input matrix A.
326
On exit, A is overwritten by the balanced matrix.
327
If JOB = 'N', A is not referenced.
328
See Further Details.
329
330
LDA (input) INTEGER
331
The leading dimension of the array A. LDA >= max(1,N).
332
333
ILO (output) INTEGER
334
IHI (output) INTEGER
335
ILO and IHI are set to integers such that on exit
336
A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N.
337
If JOB = 'N' or 'S', ILO = 1 and IHI = N.
338
339
SCALE (output) DOUBLE PRECISION array, dimension (N)
340
Details of the permutations and scaling factors applied to
341
A. If P(j) is the index of the row and column interchanged
342
with row and column j and D(j) is the scaling factor
343
applied to row and column j, then
344
SCALE(j) = P(j) for j = 1,...,ILO-1
345
= D(j) for j = ILO,...,IHI
346
= P(j) for j = IHI+1,...,N.
347
The order in which the interchanges are made is N to IHI+1,
348
then 1 to ILO-1.
349
350
INFO (output) INTEGER
351
= 0: successful exit.
352
< 0: if INFO = -i, the i-th argument had an illegal value.
353
354
Further Details
355
===============
356
357
The permutations consist of row and column interchanges which put
358
the matrix in the form
359
360
( T1 X Y )
361
P A P = ( 0 B Z )
362
( 0 0 T2 )
363
364
where T1 and T2 are upper triangular matrices whose eigenvalues lie
365
along the diagonal. The column indices ILO and IHI mark the starting
366
and ending columns of the submatrix B. Balancing consists of applying
367
a diagonal similarity transformation inv(D) * B * D to make the
368
1-norms of each row of B and its corresponding column nearly equal.
369
The output matrix is
370
371
( T1 X*D Y )
372
( 0 inv(D)*B*D inv(D)*Z ).
373
( 0 0 T2 )
374
375
Information about the permutations P and the diagonal matrix D is
376
returned in the vector SCALE.
377
378
This subroutine is based on the EISPACK routine CBAL.
379
380
Modified by Tzu-Yi Chen, Computer Science Division, University of
381
California at Berkeley, USA
382
383
=====================================================================
384
385
386
Test the input parameters
387
*/
388
389
/* Parameter adjustments */
390
a_dim1 = *lda;
391
a_offset = 1 + a_dim1;
392
a -= a_offset;
393
--scale;
394
395
/* Function Body */
396
*info = 0;
397
if (! lsame_(job, "N") && ! lsame_(job, "P") && ! lsame_(job, "S")
398
&& ! lsame_(job, "B")) {
399
*info = -1;
400
} else if (*n < 0) {
401
*info = -2;
402
} else if (*lda < max(1,*n)) {
403
*info = -4;
404
}
405
if (*info != 0) {
406
i__1 = -(*info);
407
xerbla_("ZGEBAL", &i__1);
408
return 0;
409
}
410
411
k = 1;
412
l = *n;
413
414
if (*n == 0) {
415
goto L210;
416
}
417
418
if (lsame_(job, "N")) {
419
i__1 = *n;
420
for (i__ = 1; i__ <= i__1; ++i__) {
421
scale[i__] = 1.;
422
/* L10: */
423
}
424
goto L210;
425
}
426
427
if (lsame_(job, "S")) {
428
goto L120;
429
}
430
431
/* Permutation to isolate eigenvalues if possible */
432
433
goto L50;
434
435
/* Row and column exchange. */
436
437
L20:
438
scale[m] = (doublereal) j;
439
if (j == m) {
440
goto L30;
441
}
442
443
zswap_(&l, &a[j * a_dim1 + 1], &c__1, &a[m * a_dim1 + 1], &c__1);
444
i__1 = *n - k + 1;
445
zswap_(&i__1, &a[j + k * a_dim1], lda, &a[m + k * a_dim1], lda);
446
447
L30:
448
switch (iexc) {
449
case 1: goto L40;
450
case 2: goto L80;
451
}
452
453
/* Search for rows isolating an eigenvalue and push them down. */
454
455
L40:
456
if (l == 1) {
457
goto L210;
458
}
459
--l;
460
461
L50:
462
for (j = l; j >= 1; --j) {
463
464
i__1 = l;
465
for (i__ = 1; i__ <= i__1; ++i__) {
466
if (i__ == j) {
467
goto L60;
468
}
469
i__2 = j + i__ * a_dim1;
470
if (a[i__2].r != 0. || d_imag(&a[j + i__ * a_dim1]) != 0.) {
471
goto L70;
472
}
473
L60:
474
;
475
}
476
477
m = l;
478
iexc = 1;
479
goto L20;
480
L70:
481
;
482
}
483
484
goto L90;
485
486
/* Search for columns isolating an eigenvalue and push them left. */
487
488
L80:
489
++k;
490
491
L90:
492
i__1 = l;
493
for (j = k; j <= i__1; ++j) {
494
495
i__2 = l;
496
for (i__ = k; i__ <= i__2; ++i__) {
497
if (i__ == j) {
498
goto L100;
499
}
500
i__3 = i__ + j * a_dim1;
501
if (a[i__3].r != 0. || d_imag(&a[i__ + j * a_dim1]) != 0.) {
502
goto L110;
503
}
504
L100:
505
;
506
}
507
508
m = k;
509
iexc = 2;
510
goto L20;
511
L110:
512
;
513
}
514
515
L120:
516
i__1 = l;
517
for (i__ = k; i__ <= i__1; ++i__) {
518
scale[i__] = 1.;
519
/* L130: */
520
}
521
522
if (lsame_(job, "P")) {
523
goto L210;
524
}
525
526
/*
527
Balance the submatrix in rows K to L.
528
529
Iterative loop for norm reduction
530
*/
531
532
sfmin1 = SAFEMINIMUM / PRECISION;
533
sfmax1 = 1. / sfmin1;
534
sfmin2 = sfmin1 * 2.;
535
sfmax2 = 1. / sfmin2;
536
L140:
537
noconv = FALSE_;
538
539
i__1 = l;
540
for (i__ = k; i__ <= i__1; ++i__) {
541
c__ = 0.;
542
r__ = 0.;
543
544
i__2 = l;
545
for (j = k; j <= i__2; ++j) {
546
if (j == i__) {
547
goto L150;
548
}
549
i__3 = j + i__ * a_dim1;
550
c__ += (d__1 = a[i__3].r, abs(d__1)) + (d__2 = d_imag(&a[j + i__ *
551
a_dim1]), abs(d__2));
552
i__3 = i__ + j * a_dim1;
553
r__ += (d__1 = a[i__3].r, abs(d__1)) + (d__2 = d_imag(&a[i__ + j *
554
a_dim1]), abs(d__2));
555
L150:
556
;
557
}
558
ica = izamax_(&l, &a[i__ * a_dim1 + 1], &c__1);
559
ca = z_abs(&a[ica + i__ * a_dim1]);
560
i__2 = *n - k + 1;
561
ira = izamax_(&i__2, &a[i__ + k * a_dim1], lda);
562
ra = z_abs(&a[i__ + (ira + k - 1) * a_dim1]);
563
564
/* Guard against zero C or R due to underflow. */
565
566
if (c__ == 0. || r__ == 0.) {
567
goto L200;
568
}
569
g = r__ / 2.;
570
f = 1.;
571
s = c__ + r__;
572
L160:
573
/* Computing MAX */
574
d__1 = max(f,c__);
575
/* Computing MIN */
576
d__2 = min(r__,g);
577
if (c__ >= g || max(d__1,ca) >= sfmax2 || min(d__2,ra) <= sfmin2) {
578
goto L170;
579
}
580
d__1 = c__ + f + ca + r__ + g + ra;
581
if (disnan_(&d__1)) {
582
583
/* Exit if NaN to avoid infinite loop */
584
585
*info = -3;
586
i__2 = -(*info);
587
xerbla_("ZGEBAL", &i__2);
588
return 0;
589
}
590
f *= 2.;
591
c__ *= 2.;
592
ca *= 2.;
593
r__ /= 2.;
594
g /= 2.;
595
ra /= 2.;
596
goto L160;
597
598
L170:
599
g = c__ / 2.;
600
L180:
601
/* Computing MIN */
602
d__1 = min(f,c__), d__1 = min(d__1,g);
603
if (g < r__ || max(r__,ra) >= sfmax2 || min(d__1,ca) <= sfmin2) {
604
goto L190;
605
}
606
f /= 2.;
607
c__ /= 2.;
608
g /= 2.;
609
ca /= 2.;
610
r__ *= 2.;
611
ra *= 2.;
612
goto L180;
613
614
/* Now balance. */
615
616
L190:
617
if (c__ + r__ >= s * .95) {
618
goto L200;
619
}
620
if (f < 1. && scale[i__] < 1.) {
621
if (f * scale[i__] <= sfmin1) {
622
goto L200;
623
}
624
}
625
if (f > 1. && scale[i__] > 1.) {
626
if (scale[i__] >= sfmax1 / f) {
627
goto L200;
628
}
629
}
630
g = 1. / f;
631
scale[i__] *= f;
632
noconv = TRUE_;
633
634
i__2 = *n - k + 1;
635
zdscal_(&i__2, &g, &a[i__ + k * a_dim1], lda);
636
zdscal_(&l, &f, &a[i__ * a_dim1 + 1], &c__1);
637
638
L200:
639
;
640
}
641
642
if (noconv) {
643
goto L140;
644
}
645
646
L210:
647
*ilo = k;
648
*ihi = l;
649
650
return 0;
651
652
/* End of ZGEBAL */
653
654
} /* zgebal_ */
655
656
/* Subroutine */ int zgebd2_(integer *m, integer *n, doublecomplex *a,
657
integer *lda, doublereal *d__, doublereal *e, doublecomplex *tauq,
658
doublecomplex *taup, doublecomplex *work, integer *info)
659
{
660
/* System generated locals */
661
integer a_dim1, a_offset, i__1, i__2, i__3;
662
doublecomplex z__1;
663
664
/* Local variables */
665
static integer i__;
666
static doublecomplex alpha;
667
extern /* Subroutine */ int zlarf_(char *, integer *, integer *,
668
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
669
integer *, doublecomplex *), xerbla_(char *, integer *), zlarfg_(integer *, doublecomplex *, doublecomplex *,
670
integer *, doublecomplex *), zlacgv_(integer *, doublecomplex *,
671
integer *);
672
673
674
/*
675
-- LAPACK routine (version 3.2) --
676
-- LAPACK is a software package provided by Univ. of Tennessee, --
677
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
678
November 2006
679
680
681
Purpose
682
=======
683
684
ZGEBD2 reduces a complex general m by n matrix A to upper or lower
685
real bidiagonal form B by a unitary transformation: Q' * A * P = B.
686
687
If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal.
688
689
Arguments
690
=========
691
692
M (input) INTEGER
693
The number of rows in the matrix A. M >= 0.
694
695
N (input) INTEGER
696
The number of columns in the matrix A. N >= 0.
697
698
A (input/output) COMPLEX*16 array, dimension (LDA,N)
699
On entry, the m by n general matrix to be reduced.
700
On exit,
701
if m >= n, the diagonal and the first superdiagonal are
702
overwritten with the upper bidiagonal matrix B; the
703
elements below the diagonal, with the array TAUQ, represent
704
the unitary matrix Q as a product of elementary
705
reflectors, and the elements above the first superdiagonal,
706
with the array TAUP, represent the unitary matrix P as
707
a product of elementary reflectors;
708
if m < n, the diagonal and the first subdiagonal are
709
overwritten with the lower bidiagonal matrix B; the
710
elements below the first subdiagonal, with the array TAUQ,
711
represent the unitary matrix Q as a product of
712
elementary reflectors, and the elements above the diagonal,
713
with the array TAUP, represent the unitary matrix P as
714
a product of elementary reflectors.
715
See Further Details.
716
717
LDA (input) INTEGER
718
The leading dimension of the array A. LDA >= max(1,M).
719
720
D (output) DOUBLE PRECISION array, dimension (min(M,N))
721
The diagonal elements of the bidiagonal matrix B:
722
D(i) = A(i,i).
723
724
E (output) DOUBLE PRECISION array, dimension (min(M,N)-1)
725
The off-diagonal elements of the bidiagonal matrix B:
726
if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1;
727
if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1.
728
729
TAUQ (output) COMPLEX*16 array dimension (min(M,N))
730
The scalar factors of the elementary reflectors which
731
represent the unitary matrix Q. See Further Details.
732
733
TAUP (output) COMPLEX*16 array, dimension (min(M,N))
734
The scalar factors of the elementary reflectors which
735
represent the unitary matrix P. See Further Details.
736
737
WORK (workspace) COMPLEX*16 array, dimension (max(M,N))
738
739
INFO (output) INTEGER
740
= 0: successful exit
741
< 0: if INFO = -i, the i-th argument had an illegal value.
742
743
Further Details
744
===============
745
746
The matrices Q and P are represented as products of elementary
747
reflectors:
748
749
If m >= n,
750
751
Q = H(1) H(2) . . . H(n) and P = G(1) G(2) . . . G(n-1)
752
753
Each H(i) and G(i) has the form:
754
755
H(i) = I - tauq * v * v' and G(i) = I - taup * u * u'
756
757
where tauq and taup are complex scalars, and v and u are complex
758
vectors; v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in
759
A(i+1:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in
760
A(i,i+2:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
761
762
If m < n,
763
764
Q = H(1) H(2) . . . H(m-1) and P = G(1) G(2) . . . G(m)
765
766
Each H(i) and G(i) has the form:
767
768
H(i) = I - tauq * v * v' and G(i) = I - taup * u * u'
769
770
where tauq and taup are complex scalars, v and u are complex vectors;
771
v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i);
772
u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n);
773
tauq is stored in TAUQ(i) and taup in TAUP(i).
774
775
The contents of A on exit are illustrated by the following examples:
776
777
m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n):
778
779
( d e u1 u1 u1 ) ( d u1 u1 u1 u1 u1 )
780
( v1 d e u2 u2 ) ( e d u2 u2 u2 u2 )
781
( v1 v2 d e u3 ) ( v1 e d u3 u3 u3 )
782
( v1 v2 v3 d e ) ( v1 v2 e d u4 u4 )
783
( v1 v2 v3 v4 d ) ( v1 v2 v3 e d u5 )
784
( v1 v2 v3 v4 v5 )
785
786
where d and e denote diagonal and off-diagonal elements of B, vi
787
denotes an element of the vector defining H(i), and ui an element of
788
the vector defining G(i).
789
790
=====================================================================
791
792
793
Test the input parameters
794
*/
795
796
/* Parameter adjustments */
797
a_dim1 = *lda;
798
a_offset = 1 + a_dim1;
799
a -= a_offset;
800
--d__;
801
--e;
802
--tauq;
803
--taup;
804
--work;
805
806
/* Function Body */
807
*info = 0;
808
if (*m < 0) {
809
*info = -1;
810
} else if (*n < 0) {
811
*info = -2;
812
} else if (*lda < max(1,*m)) {
813
*info = -4;
814
}
815
if (*info < 0) {
816
i__1 = -(*info);
817
xerbla_("ZGEBD2", &i__1);
818
return 0;
819
}
820
821
if (*m >= *n) {
822
823
/* Reduce to upper bidiagonal form */
824
825
i__1 = *n;
826
for (i__ = 1; i__ <= i__1; ++i__) {
827
828
/* Generate elementary reflector H(i) to annihilate A(i+1:m,i) */
829
830
i__2 = i__ + i__ * a_dim1;
831
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
832
i__2 = *m - i__ + 1;
833
/* Computing MIN */
834
i__3 = i__ + 1;
835
zlarfg_(&i__2, &alpha, &a[min(i__3,*m) + i__ * a_dim1], &c__1, &
836
tauq[i__]);
837
i__2 = i__;
838
d__[i__2] = alpha.r;
839
i__2 = i__ + i__ * a_dim1;
840
a[i__2].r = 1., a[i__2].i = 0.;
841
842
/* Apply H(i)' to A(i:m,i+1:n) from the left */
843
844
if (i__ < *n) {
845
i__2 = *m - i__ + 1;
846
i__3 = *n - i__;
847
d_cnjg(&z__1, &tauq[i__]);
848
zlarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &
849
z__1, &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]);
850
}
851
i__2 = i__ + i__ * a_dim1;
852
i__3 = i__;
853
a[i__2].r = d__[i__3], a[i__2].i = 0.;
854
855
if (i__ < *n) {
856
857
/*
858
Generate elementary reflector G(i) to annihilate
859
A(i,i+2:n)
860
*/
861
862
i__2 = *n - i__;
863
zlacgv_(&i__2, &a[i__ + (i__ + 1) * a_dim1], lda);
864
i__2 = i__ + (i__ + 1) * a_dim1;
865
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
866
i__2 = *n - i__;
867
/* Computing MIN */
868
i__3 = i__ + 2;
869
zlarfg_(&i__2, &alpha, &a[i__ + min(i__3,*n) * a_dim1], lda, &
870
taup[i__]);
871
i__2 = i__;
872
e[i__2] = alpha.r;
873
i__2 = i__ + (i__ + 1) * a_dim1;
874
a[i__2].r = 1., a[i__2].i = 0.;
875
876
/* Apply G(i) to A(i+1:m,i+1:n) from the right */
877
878
i__2 = *m - i__;
879
i__3 = *n - i__;
880
zlarf_("Right", &i__2, &i__3, &a[i__ + (i__ + 1) * a_dim1],
881
lda, &taup[i__], &a[i__ + 1 + (i__ + 1) * a_dim1],
882
lda, &work[1]);
883
i__2 = *n - i__;
884
zlacgv_(&i__2, &a[i__ + (i__ + 1) * a_dim1], lda);
885
i__2 = i__ + (i__ + 1) * a_dim1;
886
i__3 = i__;
887
a[i__2].r = e[i__3], a[i__2].i = 0.;
888
} else {
889
i__2 = i__;
890
taup[i__2].r = 0., taup[i__2].i = 0.;
891
}
892
/* L10: */
893
}
894
} else {
895
896
/* Reduce to lower bidiagonal form */
897
898
i__1 = *m;
899
for (i__ = 1; i__ <= i__1; ++i__) {
900
901
/* Generate elementary reflector G(i) to annihilate A(i,i+1:n) */
902
903
i__2 = *n - i__ + 1;
904
zlacgv_(&i__2, &a[i__ + i__ * a_dim1], lda);
905
i__2 = i__ + i__ * a_dim1;
906
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
907
i__2 = *n - i__ + 1;
908
/* Computing MIN */
909
i__3 = i__ + 1;
910
zlarfg_(&i__2, &alpha, &a[i__ + min(i__3,*n) * a_dim1], lda, &
911
taup[i__]);
912
i__2 = i__;
913
d__[i__2] = alpha.r;
914
i__2 = i__ + i__ * a_dim1;
915
a[i__2].r = 1., a[i__2].i = 0.;
916
917
/* Apply G(i) to A(i+1:m,i:n) from the right */
918
919
if (i__ < *m) {
920
i__2 = *m - i__;
921
i__3 = *n - i__ + 1;
922
zlarf_("Right", &i__2, &i__3, &a[i__ + i__ * a_dim1], lda, &
923
taup[i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
924
}
925
i__2 = *n - i__ + 1;
926
zlacgv_(&i__2, &a[i__ + i__ * a_dim1], lda);
927
i__2 = i__ + i__ * a_dim1;
928
i__3 = i__;
929
a[i__2].r = d__[i__3], a[i__2].i = 0.;
930
931
if (i__ < *m) {
932
933
/*
934
Generate elementary reflector H(i) to annihilate
935
A(i+2:m,i)
936
*/
937
938
i__2 = i__ + 1 + i__ * a_dim1;
939
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
940
i__2 = *m - i__;
941
/* Computing MIN */
942
i__3 = i__ + 2;
943
zlarfg_(&i__2, &alpha, &a[min(i__3,*m) + i__ * a_dim1], &c__1,
944
&tauq[i__]);
945
i__2 = i__;
946
e[i__2] = alpha.r;
947
i__2 = i__ + 1 + i__ * a_dim1;
948
a[i__2].r = 1., a[i__2].i = 0.;
949
950
/* Apply H(i)' to A(i+1:m,i+1:n) from the left */
951
952
i__2 = *m - i__;
953
i__3 = *n - i__;
954
d_cnjg(&z__1, &tauq[i__]);
955
zlarf_("Left", &i__2, &i__3, &a[i__ + 1 + i__ * a_dim1], &
956
c__1, &z__1, &a[i__ + 1 + (i__ + 1) * a_dim1], lda, &
957
work[1]);
958
i__2 = i__ + 1 + i__ * a_dim1;
959
i__3 = i__;
960
a[i__2].r = e[i__3], a[i__2].i = 0.;
961
} else {
962
i__2 = i__;
963
tauq[i__2].r = 0., tauq[i__2].i = 0.;
964
}
965
/* L20: */
966
}
967
}
968
return 0;
969
970
/* End of ZGEBD2 */
971
972
} /* zgebd2_ */
973
974
/* Subroutine */ int zgebrd_(integer *m, integer *n, doublecomplex *a,
975
integer *lda, doublereal *d__, doublereal *e, doublecomplex *tauq,
976
doublecomplex *taup, doublecomplex *work, integer *lwork, integer *
977
info)
978
{
979
/* System generated locals */
980
integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
981
doublereal d__1;
982
doublecomplex z__1;
983
984
/* Local variables */
985
static integer i__, j, nb, nx;
986
static doublereal ws;
987
static integer nbmin, iinfo, minmn;
988
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
989
integer *, doublecomplex *, doublecomplex *, integer *,
990
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
991
integer *), zgebd2_(integer *, integer *,
992
doublecomplex *, integer *, doublereal *, doublereal *,
993
doublecomplex *, doublecomplex *, doublecomplex *, integer *),
994
xerbla_(char *, integer *), zlabrd_(integer *, integer *,
995
integer *, doublecomplex *, integer *, doublereal *, doublereal *,
996
doublecomplex *, doublecomplex *, doublecomplex *, integer *,
997
doublecomplex *, integer *);
998
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
999
integer *, integer *, ftnlen, ftnlen);
1000
static integer ldwrkx, ldwrky, lwkopt;
1001
static logical lquery;
1002
1003
1004
/*
1005
-- LAPACK routine (version 3.2) --
1006
-- LAPACK is a software package provided by Univ. of Tennessee, --
1007
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
1008
November 2006
1009
1010
1011
Purpose
1012
=======
1013
1014
ZGEBRD reduces a general complex M-by-N matrix A to upper or lower
1015
bidiagonal form B by a unitary transformation: Q**H * A * P = B.
1016
1017
If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal.
1018
1019
Arguments
1020
=========
1021
1022
M (input) INTEGER
1023
The number of rows in the matrix A. M >= 0.
1024
1025
N (input) INTEGER
1026
The number of columns in the matrix A. N >= 0.
1027
1028
A (input/output) COMPLEX*16 array, dimension (LDA,N)
1029
On entry, the M-by-N general matrix to be reduced.
1030
On exit,
1031
if m >= n, the diagonal and the first superdiagonal are
1032
overwritten with the upper bidiagonal matrix B; the
1033
elements below the diagonal, with the array TAUQ, represent
1034
the unitary matrix Q as a product of elementary
1035
reflectors, and the elements above the first superdiagonal,
1036
with the array TAUP, represent the unitary matrix P as
1037
a product of elementary reflectors;
1038
if m < n, the diagonal and the first subdiagonal are
1039
overwritten with the lower bidiagonal matrix B; the
1040
elements below the first subdiagonal, with the array TAUQ,
1041
represent the unitary matrix Q as a product of
1042
elementary reflectors, and the elements above the diagonal,
1043
with the array TAUP, represent the unitary matrix P as
1044
a product of elementary reflectors.
1045
See Further Details.
1046
1047
LDA (input) INTEGER
1048
The leading dimension of the array A. LDA >= max(1,M).
1049
1050
D (output) DOUBLE PRECISION array, dimension (min(M,N))
1051
The diagonal elements of the bidiagonal matrix B:
1052
D(i) = A(i,i).
1053
1054
E (output) DOUBLE PRECISION array, dimension (min(M,N)-1)
1055
The off-diagonal elements of the bidiagonal matrix B:
1056
if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1;
1057
if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1.
1058
1059
TAUQ (output) COMPLEX*16 array dimension (min(M,N))
1060
The scalar factors of the elementary reflectors which
1061
represent the unitary matrix Q. See Further Details.
1062
1063
TAUP (output) COMPLEX*16 array, dimension (min(M,N))
1064
The scalar factors of the elementary reflectors which
1065
represent the unitary matrix P. See Further Details.
1066
1067
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
1068
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
1069
1070
LWORK (input) INTEGER
1071
The length of the array WORK. LWORK >= max(1,M,N).
1072
For optimum performance LWORK >= (M+N)*NB, where NB
1073
is the optimal blocksize.
1074
1075
If LWORK = -1, then a workspace query is assumed; the routine
1076
only calculates the optimal size of the WORK array, returns
1077
this value as the first entry of the WORK array, and no error
1078
message related to LWORK is issued by XERBLA.
1079
1080
INFO (output) INTEGER
1081
= 0: successful exit.
1082
< 0: if INFO = -i, the i-th argument had an illegal value.
1083
1084
Further Details
1085
===============
1086
1087
The matrices Q and P are represented as products of elementary
1088
reflectors:
1089
1090
If m >= n,
1091
1092
Q = H(1) H(2) . . . H(n) and P = G(1) G(2) . . . G(n-1)
1093
1094
Each H(i) and G(i) has the form:
1095
1096
H(i) = I - tauq * v * v' and G(i) = I - taup * u * u'
1097
1098
where tauq and taup are complex scalars, and v and u are complex
1099
vectors; v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in
1100
A(i+1:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in
1101
A(i,i+2:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
1102
1103
If m < n,
1104
1105
Q = H(1) H(2) . . . H(m-1) and P = G(1) G(2) . . . G(m)
1106
1107
Each H(i) and G(i) has the form:
1108
1109
H(i) = I - tauq * v * v' and G(i) = I - taup * u * u'
1110
1111
where tauq and taup are complex scalars, and v and u are complex
1112
vectors; v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in
1113
A(i+2:m,i); u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in
1114
A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
1115
1116
The contents of A on exit are illustrated by the following examples:
1117
1118
m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n):
1119
1120
( d e u1 u1 u1 ) ( d u1 u1 u1 u1 u1 )
1121
( v1 d e u2 u2 ) ( e d u2 u2 u2 u2 )
1122
( v1 v2 d e u3 ) ( v1 e d u3 u3 u3 )
1123
( v1 v2 v3 d e ) ( v1 v2 e d u4 u4 )
1124
( v1 v2 v3 v4 d ) ( v1 v2 v3 e d u5 )
1125
( v1 v2 v3 v4 v5 )
1126
1127
where d and e denote diagonal and off-diagonal elements of B, vi
1128
denotes an element of the vector defining H(i), and ui an element of
1129
the vector defining G(i).
1130
1131
=====================================================================
1132
1133
1134
Test the input parameters
1135
*/
1136
1137
/* Parameter adjustments */
1138
a_dim1 = *lda;
1139
a_offset = 1 + a_dim1;
1140
a -= a_offset;
1141
--d__;
1142
--e;
1143
--tauq;
1144
--taup;
1145
--work;
1146
1147
/* Function Body */
1148
*info = 0;
1149
/* Computing MAX */
1150
i__1 = 1, i__2 = ilaenv_(&c__1, "ZGEBRD", " ", m, n, &c_n1, &c_n1, (
1151
ftnlen)6, (ftnlen)1);
1152
nb = max(i__1,i__2);
1153
lwkopt = (*m + *n) * nb;
1154
d__1 = (doublereal) lwkopt;
1155
work[1].r = d__1, work[1].i = 0.;
1156
lquery = *lwork == -1;
1157
if (*m < 0) {
1158
*info = -1;
1159
} else if (*n < 0) {
1160
*info = -2;
1161
} else if (*lda < max(1,*m)) {
1162
*info = -4;
1163
} else /* if(complicated condition) */ {
1164
/* Computing MAX */
1165
i__1 = max(1,*m);
1166
if (*lwork < max(i__1,*n) && ! lquery) {
1167
*info = -10;
1168
}
1169
}
1170
if (*info < 0) {
1171
i__1 = -(*info);
1172
xerbla_("ZGEBRD", &i__1);
1173
return 0;
1174
} else if (lquery) {
1175
return 0;
1176
}
1177
1178
/* Quick return if possible */
1179
1180
minmn = min(*m,*n);
1181
if (minmn == 0) {
1182
work[1].r = 1., work[1].i = 0.;
1183
return 0;
1184
}
1185
1186
ws = (doublereal) max(*m,*n);
1187
ldwrkx = *m;
1188
ldwrky = *n;
1189
1190
if (nb > 1 && nb < minmn) {
1191
1192
/*
1193
Set the crossover point NX.
1194
1195
Computing MAX
1196
*/
1197
i__1 = nb, i__2 = ilaenv_(&c__3, "ZGEBRD", " ", m, n, &c_n1, &c_n1, (
1198
ftnlen)6, (ftnlen)1);
1199
nx = max(i__1,i__2);
1200
1201
/* Determine when to switch from blocked to unblocked code. */
1202
1203
if (nx < minmn) {
1204
ws = (doublereal) ((*m + *n) * nb);
1205
if ((doublereal) (*lwork) < ws) {
1206
1207
/*
1208
Not enough work space for the optimal NB, consider using
1209
a smaller block size.
1210
*/
1211
1212
nbmin = ilaenv_(&c__2, "ZGEBRD", " ", m, n, &c_n1, &c_n1, (
1213
ftnlen)6, (ftnlen)1);
1214
if (*lwork >= (*m + *n) * nbmin) {
1215
nb = *lwork / (*m + *n);
1216
} else {
1217
nb = 1;
1218
nx = minmn;
1219
}
1220
}
1221
}
1222
} else {
1223
nx = minmn;
1224
}
1225
1226
i__1 = minmn - nx;
1227
i__2 = nb;
1228
for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
1229
1230
/*
1231
Reduce rows and columns i:i+ib-1 to bidiagonal form and return
1232
the matrices X and Y which are needed to update the unreduced
1233
part of the matrix
1234
*/
1235
1236
i__3 = *m - i__ + 1;
1237
i__4 = *n - i__ + 1;
1238
zlabrd_(&i__3, &i__4, &nb, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[
1239
i__], &tauq[i__], &taup[i__], &work[1], &ldwrkx, &work[ldwrkx
1240
* nb + 1], &ldwrky);
1241
1242
/*
1243
Update the trailing submatrix A(i+ib:m,i+ib:n), using
1244
an update of the form A := A - V*Y' - X*U'
1245
*/
1246
1247
i__3 = *m - i__ - nb + 1;
1248
i__4 = *n - i__ - nb + 1;
1249
z__1.r = -1., z__1.i = -0.;
1250
zgemm_("No transpose", "Conjugate transpose", &i__3, &i__4, &nb, &
1251
z__1, &a[i__ + nb + i__ * a_dim1], lda, &work[ldwrkx * nb +
1252
nb + 1], &ldwrky, &c_b57, &a[i__ + nb + (i__ + nb) * a_dim1],
1253
lda);
1254
i__3 = *m - i__ - nb + 1;
1255
i__4 = *n - i__ - nb + 1;
1256
z__1.r = -1., z__1.i = -0.;
1257
zgemm_("No transpose", "No transpose", &i__3, &i__4, &nb, &z__1, &
1258
work[nb + 1], &ldwrkx, &a[i__ + (i__ + nb) * a_dim1], lda, &
1259
c_b57, &a[i__ + nb + (i__ + nb) * a_dim1], lda);
1260
1261
/* Copy diagonal and off-diagonal elements of B back into A */
1262
1263
if (*m >= *n) {
1264
i__3 = i__ + nb - 1;
1265
for (j = i__; j <= i__3; ++j) {
1266
i__4 = j + j * a_dim1;
1267
i__5 = j;
1268
a[i__4].r = d__[i__5], a[i__4].i = 0.;
1269
i__4 = j + (j + 1) * a_dim1;
1270
i__5 = j;
1271
a[i__4].r = e[i__5], a[i__4].i = 0.;
1272
/* L10: */
1273
}
1274
} else {
1275
i__3 = i__ + nb - 1;
1276
for (j = i__; j <= i__3; ++j) {
1277
i__4 = j + j * a_dim1;
1278
i__5 = j;
1279
a[i__4].r = d__[i__5], a[i__4].i = 0.;
1280
i__4 = j + 1 + j * a_dim1;
1281
i__5 = j;
1282
a[i__4].r = e[i__5], a[i__4].i = 0.;
1283
/* L20: */
1284
}
1285
}
1286
/* L30: */
1287
}
1288
1289
/* Use unblocked code to reduce the remainder of the matrix */
1290
1291
i__2 = *m - i__ + 1;
1292
i__1 = *n - i__ + 1;
1293
zgebd2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__], &
1294
tauq[i__], &taup[i__], &work[1], &iinfo);
1295
work[1].r = ws, work[1].i = 0.;
1296
return 0;
1297
1298
/* End of ZGEBRD */
1299
1300
} /* zgebrd_ */
1301
1302
/* Subroutine */ int zgeev_(char *jobvl, char *jobvr, integer *n,
1303
doublecomplex *a, integer *lda, doublecomplex *w, doublecomplex *vl,
1304
integer *ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work,
1305
integer *lwork, doublereal *rwork, integer *info)
1306
{
1307
/* System generated locals */
1308
integer a_dim1, a_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
1309
i__2, i__3;
1310
doublereal d__1, d__2;
1311
doublecomplex z__1, z__2;
1312
1313
/* Local variables */
1314
static integer i__, k, ihi;
1315
static doublereal scl;
1316
static integer ilo;
1317
static doublereal dum[1], eps;
1318
static doublecomplex tmp;
1319
static integer ibal;
1320
static char side[1];
1321
static doublereal anrm;
1322
static integer ierr, itau, iwrk, nout;
1323
extern logical lsame_(char *, char *);
1324
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
1325
doublecomplex *, integer *), dlabad_(doublereal *, doublereal *);
1326
extern doublereal dznrm2_(integer *, doublecomplex *, integer *);
1327
static logical scalea;
1328
1329
static doublereal cscale;
1330
extern /* Subroutine */ int zgebak_(char *, char *, integer *, integer *,
1331
integer *, doublereal *, integer *, doublecomplex *, integer *,
1332
integer *), zgebal_(char *, integer *,
1333
doublecomplex *, integer *, integer *, integer *, doublereal *,
1334
integer *);
1335
extern integer idamax_(integer *, doublereal *, integer *);
1336
extern /* Subroutine */ int xerbla_(char *, integer *);
1337
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
1338
integer *, integer *, ftnlen, ftnlen);
1339
static logical select[1];
1340
extern /* Subroutine */ int zdscal_(integer *, doublereal *,
1341
doublecomplex *, integer *);
1342
static doublereal bignum;
1343
extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
1344
integer *, doublereal *);
1345
extern /* Subroutine */ int zgehrd_(integer *, integer *, integer *,
1346
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
1347
integer *, integer *), zlascl_(char *, integer *, integer *,
1348
doublereal *, doublereal *, integer *, integer *, doublecomplex *,
1349
integer *, integer *), zlacpy_(char *, integer *,
1350
integer *, doublecomplex *, integer *, doublecomplex *, integer *);
1351
static integer minwrk, maxwrk;
1352
static logical wantvl;
1353
static doublereal smlnum;
1354
static integer hswork, irwork;
1355
extern /* Subroutine */ int zhseqr_(char *, char *, integer *, integer *,
1356
integer *, doublecomplex *, integer *, doublecomplex *,
1357
doublecomplex *, integer *, doublecomplex *, integer *, integer *), ztrevc_(char *, char *, logical *, integer *,
1358
doublecomplex *, integer *, doublecomplex *, integer *,
1359
doublecomplex *, integer *, integer *, integer *, doublecomplex *,
1360
doublereal *, integer *);
1361
static logical lquery, wantvr;
1362
extern /* Subroutine */ int zunghr_(integer *, integer *, integer *,
1363
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
1364
integer *, integer *);
1365
1366
1367
/*
1368
-- LAPACK driver routine (version 3.2) --
1369
-- LAPACK is a software package provided by Univ. of Tennessee, --
1370
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
1371
November 2006
1372
1373
1374
Purpose
1375
=======
1376
1377
ZGEEV computes for an N-by-N complex nonsymmetric matrix A, the
1378
eigenvalues and, optionally, the left and/or right eigenvectors.
1379
1380
The right eigenvector v(j) of A satisfies
1381
A * v(j) = lambda(j) * v(j)
1382
where lambda(j) is its eigenvalue.
1383
The left eigenvector u(j) of A satisfies
1384
u(j)**H * A = lambda(j) * u(j)**H
1385
where u(j)**H denotes the conjugate transpose of u(j).
1386
1387
The computed eigenvectors are normalized to have Euclidean norm
1388
equal to 1 and largest component real.
1389
1390
Arguments
1391
=========
1392
1393
JOBVL (input) CHARACTER*1
1394
= 'N': left eigenvectors of A are not computed;
1395
= 'V': left eigenvectors of are computed.
1396
1397
JOBVR (input) CHARACTER*1
1398
= 'N': right eigenvectors of A are not computed;
1399
= 'V': right eigenvectors of A are computed.
1400
1401
N (input) INTEGER
1402
The order of the matrix A. N >= 0.
1403
1404
A (input/output) COMPLEX*16 array, dimension (LDA,N)
1405
On entry, the N-by-N matrix A.
1406
On exit, A has been overwritten.
1407
1408
LDA (input) INTEGER
1409
The leading dimension of the array A. LDA >= max(1,N).
1410
1411
W (output) COMPLEX*16 array, dimension (N)
1412
W contains the computed eigenvalues.
1413
1414
VL (output) COMPLEX*16 array, dimension (LDVL,N)
1415
If JOBVL = 'V', the left eigenvectors u(j) are stored one
1416
after another in the columns of VL, in the same order
1417
as their eigenvalues.
1418
If JOBVL = 'N', VL is not referenced.
1419
u(j) = VL(:,j), the j-th column of VL.
1420
1421
LDVL (input) INTEGER
1422
The leading dimension of the array VL. LDVL >= 1; if
1423
JOBVL = 'V', LDVL >= N.
1424
1425
VR (output) COMPLEX*16 array, dimension (LDVR,N)
1426
If JOBVR = 'V', the right eigenvectors v(j) are stored one
1427
after another in the columns of VR, in the same order
1428
as their eigenvalues.
1429
If JOBVR = 'N', VR is not referenced.
1430
v(j) = VR(:,j), the j-th column of VR.
1431
1432
LDVR (input) INTEGER
1433
The leading dimension of the array VR. LDVR >= 1; if
1434
JOBVR = 'V', LDVR >= N.
1435
1436
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
1437
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
1438
1439
LWORK (input) INTEGER
1440
The dimension of the array WORK. LWORK >= max(1,2*N).
1441
For good performance, LWORK must generally be larger.
1442
1443
If LWORK = -1, then a workspace query is assumed; the routine
1444
only calculates the optimal size of the WORK array, returns
1445
this value as the first entry of the WORK array, and no error
1446
message related to LWORK is issued by XERBLA.
1447
1448
RWORK (workspace) DOUBLE PRECISION array, dimension (2*N)
1449
1450
INFO (output) INTEGER
1451
= 0: successful exit
1452
< 0: if INFO = -i, the i-th argument had an illegal value.
1453
> 0: if INFO = i, the QR algorithm failed to compute all the
1454
eigenvalues, and no eigenvectors have been computed;
1455
elements and i+1:N of W contain eigenvalues which have
1456
converged.
1457
1458
=====================================================================
1459
1460
1461
Test the input arguments
1462
*/
1463
1464
/* Parameter adjustments */
1465
a_dim1 = *lda;
1466
a_offset = 1 + a_dim1;
1467
a -= a_offset;
1468
--w;
1469
vl_dim1 = *ldvl;
1470
vl_offset = 1 + vl_dim1;
1471
vl -= vl_offset;
1472
vr_dim1 = *ldvr;
1473
vr_offset = 1 + vr_dim1;
1474
vr -= vr_offset;
1475
--work;
1476
--rwork;
1477
1478
/* Function Body */
1479
*info = 0;
1480
lquery = *lwork == -1;
1481
wantvl = lsame_(jobvl, "V");
1482
wantvr = lsame_(jobvr, "V");
1483
if (! wantvl && ! lsame_(jobvl, "N")) {
1484
*info = -1;
1485
} else if (! wantvr && ! lsame_(jobvr, "N")) {
1486
*info = -2;
1487
} else if (*n < 0) {
1488
*info = -3;
1489
} else if (*lda < max(1,*n)) {
1490
*info = -5;
1491
} else if (*ldvl < 1 || wantvl && *ldvl < *n) {
1492
*info = -8;
1493
} else if (*ldvr < 1 || wantvr && *ldvr < *n) {
1494
*info = -10;
1495
}
1496
1497
/*
1498
Compute workspace
1499
(Note: Comments in the code beginning "Workspace:" describe the
1500
minimal amount of workspace needed at that point in the code,
1501
as well as the preferred amount for good performance.
1502
CWorkspace refers to complex workspace, and RWorkspace to real
1503
workspace. NB refers to the optimal block size for the
1504
immediately following subroutine, as returned by ILAENV.
1505
HSWORK refers to the workspace preferred by ZHSEQR, as
1506
calculated below. HSWORK is computed assuming ILO=1 and IHI=N,
1507
the worst case.)
1508
*/
1509
1510
if (*info == 0) {
1511
if (*n == 0) {
1512
minwrk = 1;
1513
maxwrk = 1;
1514
} else {
1515
maxwrk = *n + *n * ilaenv_(&c__1, "ZGEHRD", " ", n, &c__1, n, &
1516
c__0, (ftnlen)6, (ftnlen)1);
1517
minwrk = *n << 1;
1518
if (wantvl) {
1519
/* Computing MAX */
1520
i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "ZUNGHR",
1521
" ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)1);
1522
maxwrk = max(i__1,i__2);
1523
zhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &w[1], &vl[
1524
vl_offset], ldvl, &work[1], &c_n1, info);
1525
} else if (wantvr) {
1526
/* Computing MAX */
1527
i__1 = maxwrk, i__2 = *n + (*n - 1) * ilaenv_(&c__1, "ZUNGHR",
1528
" ", n, &c__1, n, &c_n1, (ftnlen)6, (ftnlen)1);
1529
maxwrk = max(i__1,i__2);
1530
zhseqr_("S", "V", n, &c__1, n, &a[a_offset], lda, &w[1], &vr[
1531
vr_offset], ldvr, &work[1], &c_n1, info);
1532
} else {
1533
zhseqr_("E", "N", n, &c__1, n, &a[a_offset], lda, &w[1], &vr[
1534
vr_offset], ldvr, &work[1], &c_n1, info);
1535
}
1536
hswork = (integer) work[1].r;
1537
/* Computing MAX */
1538
i__1 = max(maxwrk,hswork);
1539
maxwrk = max(i__1,minwrk);
1540
}
1541
work[1].r = (doublereal) maxwrk, work[1].i = 0.;
1542
1543
if (*lwork < minwrk && ! lquery) {
1544
*info = -12;
1545
}
1546
}
1547
1548
if (*info != 0) {
1549
i__1 = -(*info);
1550
xerbla_("ZGEEV ", &i__1);
1551
return 0;
1552
} else if (lquery) {
1553
return 0;
1554
}
1555
1556
/* Quick return if possible */
1557
1558
if (*n == 0) {
1559
return 0;
1560
}
1561
1562
/* Get machine constants */
1563
1564
eps = PRECISION;
1565
smlnum = SAFEMINIMUM;
1566
bignum = 1. / smlnum;
1567
dlabad_(&smlnum, &bignum);
1568
smlnum = sqrt(smlnum) / eps;
1569
bignum = 1. / smlnum;
1570
1571
/* Scale A if max element outside range [SMLNUM,BIGNUM] */
1572
1573
anrm = zlange_("M", n, n, &a[a_offset], lda, dum);
1574
scalea = FALSE_;
1575
if (anrm > 0. && anrm < smlnum) {
1576
scalea = TRUE_;
1577
cscale = smlnum;
1578
} else if (anrm > bignum) {
1579
scalea = TRUE_;
1580
cscale = bignum;
1581
}
1582
if (scalea) {
1583
zlascl_("G", &c__0, &c__0, &anrm, &cscale, n, n, &a[a_offset], lda, &
1584
ierr);
1585
}
1586
1587
/*
1588
Balance the matrix
1589
(CWorkspace: none)
1590
(RWorkspace: need N)
1591
*/
1592
1593
ibal = 1;
1594
zgebal_("B", n, &a[a_offset], lda, &ilo, &ihi, &rwork[ibal], &ierr);
1595
1596
/*
1597
Reduce to upper Hessenberg form
1598
(CWorkspace: need 2*N, prefer N+N*NB)
1599
(RWorkspace: none)
1600
*/
1601
1602
itau = 1;
1603
iwrk = itau + *n;
1604
i__1 = *lwork - iwrk + 1;
1605
zgehrd_(n, &ilo, &ihi, &a[a_offset], lda, &work[itau], &work[iwrk], &i__1,
1606
&ierr);
1607
1608
if (wantvl) {
1609
1610
/*
1611
Want left eigenvectors
1612
Copy Householder vectors to VL
1613
*/
1614
1615
*(unsigned char *)side = 'L';
1616
zlacpy_("L", n, n, &a[a_offset], lda, &vl[vl_offset], ldvl)
1617
;
1618
1619
/*
1620
Generate unitary matrix in VL
1621
(CWorkspace: need 2*N-1, prefer N+(N-1)*NB)
1622
(RWorkspace: none)
1623
*/
1624
1625
i__1 = *lwork - iwrk + 1;
1626
zunghr_(n, &ilo, &ihi, &vl[vl_offset], ldvl, &work[itau], &work[iwrk],
1627
&i__1, &ierr);
1628
1629
/*
1630
Perform QR iteration, accumulating Schur vectors in VL
1631
(CWorkspace: need 1, prefer HSWORK (see comments) )
1632
(RWorkspace: none)
1633
*/
1634
1635
iwrk = itau;
1636
i__1 = *lwork - iwrk + 1;
1637
zhseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vl[
1638
vl_offset], ldvl, &work[iwrk], &i__1, info);
1639
1640
if (wantvr) {
1641
1642
/*
1643
Want left and right eigenvectors
1644
Copy Schur vectors to VR
1645
*/
1646
1647
*(unsigned char *)side = 'B';
1648
zlacpy_("F", n, n, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr);
1649
}
1650
1651
} else if (wantvr) {
1652
1653
/*
1654
Want right eigenvectors
1655
Copy Householder vectors to VR
1656
*/
1657
1658
*(unsigned char *)side = 'R';
1659
zlacpy_("L", n, n, &a[a_offset], lda, &vr[vr_offset], ldvr)
1660
;
1661
1662
/*
1663
Generate unitary matrix in VR
1664
(CWorkspace: need 2*N-1, prefer N+(N-1)*NB)
1665
(RWorkspace: none)
1666
*/
1667
1668
i__1 = *lwork - iwrk + 1;
1669
zunghr_(n, &ilo, &ihi, &vr[vr_offset], ldvr, &work[itau], &work[iwrk],
1670
&i__1, &ierr);
1671
1672
/*
1673
Perform QR iteration, accumulating Schur vectors in VR
1674
(CWorkspace: need 1, prefer HSWORK (see comments) )
1675
(RWorkspace: none)
1676
*/
1677
1678
iwrk = itau;
1679
i__1 = *lwork - iwrk + 1;
1680
zhseqr_("S", "V", n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vr[
1681
vr_offset], ldvr, &work[iwrk], &i__1, info);
1682
1683
} else {
1684
1685
/*
1686
Compute eigenvalues only
1687
(CWorkspace: need 1, prefer HSWORK (see comments) )
1688
(RWorkspace: none)
1689
*/
1690
1691
iwrk = itau;
1692
i__1 = *lwork - iwrk + 1;
1693
zhseqr_("E", "N", n, &ilo, &ihi, &a[a_offset], lda, &w[1], &vr[
1694
vr_offset], ldvr, &work[iwrk], &i__1, info);
1695
}
1696
1697
/* If INFO > 0 from ZHSEQR, then quit */
1698
1699
if (*info > 0) {
1700
goto L50;
1701
}
1702
1703
if (wantvl || wantvr) {
1704
1705
/*
1706
Compute left and/or right eigenvectors
1707
(CWorkspace: need 2*N)
1708
(RWorkspace: need 2*N)
1709
*/
1710
1711
irwork = ibal + *n;
1712
ztrevc_(side, "B", select, n, &a[a_offset], lda, &vl[vl_offset], ldvl,
1713
&vr[vr_offset], ldvr, n, &nout, &work[iwrk], &rwork[irwork],
1714
&ierr);
1715
}
1716
1717
if (wantvl) {
1718
1719
/*
1720
Undo balancing of left eigenvectors
1721
(CWorkspace: none)
1722
(RWorkspace: need N)
1723
*/
1724
1725
zgebak_("B", "L", n, &ilo, &ihi, &rwork[ibal], n, &vl[vl_offset],
1726
ldvl, &ierr);
1727
1728
/* Normalize left eigenvectors and make largest component real */
1729
1730
i__1 = *n;
1731
for (i__ = 1; i__ <= i__1; ++i__) {
1732
scl = 1. / dznrm2_(n, &vl[i__ * vl_dim1 + 1], &c__1);
1733
zdscal_(n, &scl, &vl[i__ * vl_dim1 + 1], &c__1);
1734
i__2 = *n;
1735
for (k = 1; k <= i__2; ++k) {
1736
i__3 = k + i__ * vl_dim1;
1737
/* Computing 2nd power */
1738
d__1 = vl[i__3].r;
1739
/* Computing 2nd power */
1740
d__2 = d_imag(&vl[k + i__ * vl_dim1]);
1741
rwork[irwork + k - 1] = d__1 * d__1 + d__2 * d__2;
1742
/* L10: */
1743
}
1744
k = idamax_(n, &rwork[irwork], &c__1);
1745
d_cnjg(&z__2, &vl[k + i__ * vl_dim1]);
1746
d__1 = sqrt(rwork[irwork + k - 1]);
1747
z__1.r = z__2.r / d__1, z__1.i = z__2.i / d__1;
1748
tmp.r = z__1.r, tmp.i = z__1.i;
1749
zscal_(n, &tmp, &vl[i__ * vl_dim1 + 1], &c__1);
1750
i__2 = k + i__ * vl_dim1;
1751
i__3 = k + i__ * vl_dim1;
1752
d__1 = vl[i__3].r;
1753
z__1.r = d__1, z__1.i = 0.;
1754
vl[i__2].r = z__1.r, vl[i__2].i = z__1.i;
1755
/* L20: */
1756
}
1757
}
1758
1759
if (wantvr) {
1760
1761
/*
1762
Undo balancing of right eigenvectors
1763
(CWorkspace: none)
1764
(RWorkspace: need N)
1765
*/
1766
1767
zgebak_("B", "R", n, &ilo, &ihi, &rwork[ibal], n, &vr[vr_offset],
1768
ldvr, &ierr);
1769
1770
/* Normalize right eigenvectors and make largest component real */
1771
1772
i__1 = *n;
1773
for (i__ = 1; i__ <= i__1; ++i__) {
1774
scl = 1. / dznrm2_(n, &vr[i__ * vr_dim1 + 1], &c__1);
1775
zdscal_(n, &scl, &vr[i__ * vr_dim1 + 1], &c__1);
1776
i__2 = *n;
1777
for (k = 1; k <= i__2; ++k) {
1778
i__3 = k + i__ * vr_dim1;
1779
/* Computing 2nd power */
1780
d__1 = vr[i__3].r;
1781
/* Computing 2nd power */
1782
d__2 = d_imag(&vr[k + i__ * vr_dim1]);
1783
rwork[irwork + k - 1] = d__1 * d__1 + d__2 * d__2;
1784
/* L30: */
1785
}
1786
k = idamax_(n, &rwork[irwork], &c__1);
1787
d_cnjg(&z__2, &vr[k + i__ * vr_dim1]);
1788
d__1 = sqrt(rwork[irwork + k - 1]);
1789
z__1.r = z__2.r / d__1, z__1.i = z__2.i / d__1;
1790
tmp.r = z__1.r, tmp.i = z__1.i;
1791
zscal_(n, &tmp, &vr[i__ * vr_dim1 + 1], &c__1);
1792
i__2 = k + i__ * vr_dim1;
1793
i__3 = k + i__ * vr_dim1;
1794
d__1 = vr[i__3].r;
1795
z__1.r = d__1, z__1.i = 0.;
1796
vr[i__2].r = z__1.r, vr[i__2].i = z__1.i;
1797
/* L40: */
1798
}
1799
}
1800
1801
/* Undo scaling if necessary */
1802
1803
L50:
1804
if (scalea) {
1805
i__1 = *n - *info;
1806
/* Computing MAX */
1807
i__3 = *n - *info;
1808
i__2 = max(i__3,1);
1809
zlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &w[*info + 1]
1810
, &i__2, &ierr);
1811
if (*info > 0) {
1812
i__1 = ilo - 1;
1813
zlascl_("G", &c__0, &c__0, &cscale, &anrm, &i__1, &c__1, &w[1], n,
1814
&ierr);
1815
}
1816
}
1817
1818
work[1].r = (doublereal) maxwrk, work[1].i = 0.;
1819
return 0;
1820
1821
/* End of ZGEEV */
1822
1823
} /* zgeev_ */
1824
1825
/* Subroutine */ int zgehd2_(integer *n, integer *ilo, integer *ihi,
1826
doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
1827
work, integer *info)
1828
{
1829
/* System generated locals */
1830
integer a_dim1, a_offset, i__1, i__2, i__3;
1831
doublecomplex z__1;
1832
1833
/* Local variables */
1834
static integer i__;
1835
static doublecomplex alpha;
1836
extern /* Subroutine */ int zlarf_(char *, integer *, integer *,
1837
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
1838
integer *, doublecomplex *), xerbla_(char *, integer *), zlarfg_(integer *, doublecomplex *, doublecomplex *,
1839
integer *, doublecomplex *);
1840
1841
1842
/*
1843
-- LAPACK routine (version 3.2) --
1844
-- LAPACK is a software package provided by Univ. of Tennessee, --
1845
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
1846
November 2006
1847
1848
1849
Purpose
1850
=======
1851
1852
ZGEHD2 reduces a complex general matrix A to upper Hessenberg form H
1853
by a unitary similarity transformation: Q' * A * Q = H .
1854
1855
Arguments
1856
=========
1857
1858
N (input) INTEGER
1859
The order of the matrix A. N >= 0.
1860
1861
ILO (input) INTEGER
1862
IHI (input) INTEGER
1863
It is assumed that A is already upper triangular in rows
1864
and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
1865
set by a previous call to ZGEBAL; otherwise they should be
1866
set to 1 and N respectively. See Further Details.
1867
1 <= ILO <= IHI <= max(1,N).
1868
1869
A (input/output) COMPLEX*16 array, dimension (LDA,N)
1870
On entry, the n by n general matrix to be reduced.
1871
On exit, the upper triangle and the first subdiagonal of A
1872
are overwritten with the upper Hessenberg matrix H, and the
1873
elements below the first subdiagonal, with the array TAU,
1874
represent the unitary matrix Q as a product of elementary
1875
reflectors. See Further Details.
1876
1877
LDA (input) INTEGER
1878
The leading dimension of the array A. LDA >= max(1,N).
1879
1880
TAU (output) COMPLEX*16 array, dimension (N-1)
1881
The scalar factors of the elementary reflectors (see Further
1882
Details).
1883
1884
WORK (workspace) COMPLEX*16 array, dimension (N)
1885
1886
INFO (output) INTEGER
1887
= 0: successful exit
1888
< 0: if INFO = -i, the i-th argument had an illegal value.
1889
1890
Further Details
1891
===============
1892
1893
The matrix Q is represented as a product of (ihi-ilo) elementary
1894
reflectors
1895
1896
Q = H(ilo) H(ilo+1) . . . H(ihi-1).
1897
1898
Each H(i) has the form
1899
1900
H(i) = I - tau * v * v'
1901
1902
where tau is a complex scalar, and v is a complex vector with
1903
v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
1904
exit in A(i+2:ihi,i), and tau in TAU(i).
1905
1906
The contents of A are illustrated by the following example, with
1907
n = 7, ilo = 2 and ihi = 6:
1908
1909
on entry, on exit,
1910
1911
( a a a a a a a ) ( a a h h h h a )
1912
( a a a a a a ) ( a h h h h a )
1913
( a a a a a a ) ( h h h h h h )
1914
( a a a a a a ) ( v2 h h h h h )
1915
( a a a a a a ) ( v2 v3 h h h h )
1916
( a a a a a a ) ( v2 v3 v4 h h h )
1917
( a ) ( a )
1918
1919
where a denotes an element of the original matrix A, h denotes a
1920
modified element of the upper Hessenberg matrix H, and vi denotes an
1921
element of the vector defining H(i).
1922
1923
=====================================================================
1924
1925
1926
Test the input parameters
1927
*/
1928
1929
/* Parameter adjustments */
1930
a_dim1 = *lda;
1931
a_offset = 1 + a_dim1;
1932
a -= a_offset;
1933
--tau;
1934
--work;
1935
1936
/* Function Body */
1937
*info = 0;
1938
if (*n < 0) {
1939
*info = -1;
1940
} else if (*ilo < 1 || *ilo > max(1,*n)) {
1941
*info = -2;
1942
} else if (*ihi < min(*ilo,*n) || *ihi > *n) {
1943
*info = -3;
1944
} else if (*lda < max(1,*n)) {
1945
*info = -5;
1946
}
1947
if (*info != 0) {
1948
i__1 = -(*info);
1949
xerbla_("ZGEHD2", &i__1);
1950
return 0;
1951
}
1952
1953
i__1 = *ihi - 1;
1954
for (i__ = *ilo; i__ <= i__1; ++i__) {
1955
1956
/* Compute elementary reflector H(i) to annihilate A(i+2:ihi,i) */
1957
1958
i__2 = i__ + 1 + i__ * a_dim1;
1959
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
1960
i__2 = *ihi - i__;
1961
/* Computing MIN */
1962
i__3 = i__ + 2;
1963
zlarfg_(&i__2, &alpha, &a[min(i__3,*n) + i__ * a_dim1], &c__1, &tau[
1964
i__]);
1965
i__2 = i__ + 1 + i__ * a_dim1;
1966
a[i__2].r = 1., a[i__2].i = 0.;
1967
1968
/* Apply H(i) to A(1:ihi,i+1:ihi) from the right */
1969
1970
i__2 = *ihi - i__;
1971
zlarf_("Right", ihi, &i__2, &a[i__ + 1 + i__ * a_dim1], &c__1, &tau[
1972
i__], &a[(i__ + 1) * a_dim1 + 1], lda, &work[1]);
1973
1974
/* Apply H(i)' to A(i+1:ihi,i+1:n) from the left */
1975
1976
i__2 = *ihi - i__;
1977
i__3 = *n - i__;
1978
d_cnjg(&z__1, &tau[i__]);
1979
zlarf_("Left", &i__2, &i__3, &a[i__ + 1 + i__ * a_dim1], &c__1, &z__1,
1980
&a[i__ + 1 + (i__ + 1) * a_dim1], lda, &work[1]);
1981
1982
i__2 = i__ + 1 + i__ * a_dim1;
1983
a[i__2].r = alpha.r, a[i__2].i = alpha.i;
1984
/* L10: */
1985
}
1986
1987
return 0;
1988
1989
/* End of ZGEHD2 */
1990
1991
} /* zgehd2_ */
1992
1993
/* Subroutine */ int zgehrd_(integer *n, integer *ilo, integer *ihi,
1994
doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
1995
work, integer *lwork, integer *info)
1996
{
1997
/* System generated locals */
1998
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
1999
doublecomplex z__1;
2000
2001
/* Local variables */
2002
static integer i__, j;
2003
static doublecomplex t[4160] /* was [65][64] */;
2004
static integer ib;
2005
static doublecomplex ei;
2006
static integer nb, nh, nx, iws, nbmin, iinfo;
2007
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
2008
integer *, doublecomplex *, doublecomplex *, integer *,
2009
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
2010
integer *), ztrmm_(char *, char *, char *, char *,
2011
integer *, integer *, doublecomplex *, doublecomplex *, integer *
2012
, doublecomplex *, integer *),
2013
zaxpy_(integer *, doublecomplex *, doublecomplex *, integer *,
2014
doublecomplex *, integer *), zgehd2_(integer *, integer *,
2015
integer *, doublecomplex *, integer *, doublecomplex *,
2016
doublecomplex *, integer *), zlahr2_(integer *, integer *,
2017
integer *, doublecomplex *, integer *, doublecomplex *,
2018
doublecomplex *, integer *, doublecomplex *, integer *), xerbla_(
2019
char *, integer *);
2020
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
2021
integer *, integer *, ftnlen, ftnlen);
2022
extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *,
2023
integer *, integer *, integer *, doublecomplex *, integer *,
2024
doublecomplex *, integer *, doublecomplex *, integer *,
2025
doublecomplex *, integer *);
2026
static integer ldwork, lwkopt;
2027
static logical lquery;
2028
2029
2030
/*
2031
-- LAPACK routine (version 3.2.1) --
2032
-- LAPACK is a software package provided by Univ. of Tennessee, --
2033
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
2034
-- April 2009 --
2035
2036
2037
Purpose
2038
=======
2039
2040
ZGEHRD reduces a complex general matrix A to upper Hessenberg form H by
2041
an unitary similarity transformation: Q' * A * Q = H .
2042
2043
Arguments
2044
=========
2045
2046
N (input) INTEGER
2047
The order of the matrix A. N >= 0.
2048
2049
ILO (input) INTEGER
2050
IHI (input) INTEGER
2051
It is assumed that A is already upper triangular in rows
2052
and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
2053
set by a previous call to ZGEBAL; otherwise they should be
2054
set to 1 and N respectively. See Further Details.
2055
1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
2056
2057
A (input/output) COMPLEX*16 array, dimension (LDA,N)
2058
On entry, the N-by-N general matrix to be reduced.
2059
On exit, the upper triangle and the first subdiagonal of A
2060
are overwritten with the upper Hessenberg matrix H, and the
2061
elements below the first subdiagonal, with the array TAU,
2062
represent the unitary matrix Q as a product of elementary
2063
reflectors. See Further Details.
2064
2065
LDA (input) INTEGER
2066
The leading dimension of the array A. LDA >= max(1,N).
2067
2068
TAU (output) COMPLEX*16 array, dimension (N-1)
2069
The scalar factors of the elementary reflectors (see Further
2070
Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to
2071
zero.
2072
2073
WORK (workspace/output) COMPLEX*16 array, dimension (LWORK)
2074
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
2075
2076
LWORK (input) INTEGER
2077
The length of the array WORK. LWORK >= max(1,N).
2078
For optimum performance LWORK >= N*NB, where NB is the
2079
optimal blocksize.
2080
2081
If LWORK = -1, then a workspace query is assumed; the routine
2082
only calculates the optimal size of the WORK array, returns
2083
this value as the first entry of the WORK array, and no error
2084
message related to LWORK is issued by XERBLA.
2085
2086
INFO (output) INTEGER
2087
= 0: successful exit
2088
< 0: if INFO = -i, the i-th argument had an illegal value.
2089
2090
Further Details
2091
===============
2092
2093
The matrix Q is represented as a product of (ihi-ilo) elementary
2094
reflectors
2095
2096
Q = H(ilo) H(ilo+1) . . . H(ihi-1).
2097
2098
Each H(i) has the form
2099
2100
H(i) = I - tau * v * v'
2101
2102
where tau is a complex scalar, and v is a complex vector with
2103
v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
2104
exit in A(i+2:ihi,i), and tau in TAU(i).
2105
2106
The contents of A are illustrated by the following example, with
2107
n = 7, ilo = 2 and ihi = 6:
2108
2109
on entry, on exit,
2110
2111
( a a a a a a a ) ( a a h h h h a )
2112
( a a a a a a ) ( a h h h h a )
2113
( a a a a a a ) ( h h h h h h )
2114
( a a a a a a ) ( v2 h h h h h )
2115
( a a a a a a ) ( v2 v3 h h h h )
2116
( a a a a a a ) ( v2 v3 v4 h h h )
2117
( a ) ( a )
2118
2119
where a denotes an element of the original matrix A, h denotes a
2120
modified element of the upper Hessenberg matrix H, and vi denotes an
2121
element of the vector defining H(i).
2122
2123
This file is a slight modification of LAPACK-3.0's DGEHRD
2124
subroutine incorporating improvements proposed by Quintana-Orti and
2125
Van de Geijn (2006). (See DLAHR2.)
2126
2127
=====================================================================
2128
2129
2130
Test the input parameters
2131
*/
2132
2133
/* Parameter adjustments */
2134
a_dim1 = *lda;
2135
a_offset = 1 + a_dim1;
2136
a -= a_offset;
2137
--tau;
2138
--work;
2139
2140
/* Function Body */
2141
*info = 0;
2142
/* Computing MIN */
2143
i__1 = 64, i__2 = ilaenv_(&c__1, "ZGEHRD", " ", n, ilo, ihi, &c_n1, (
2144
ftnlen)6, (ftnlen)1);
2145
nb = min(i__1,i__2);
2146
lwkopt = *n * nb;
2147
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
2148
lquery = *lwork == -1;
2149
if (*n < 0) {
2150
*info = -1;
2151
} else if (*ilo < 1 || *ilo > max(1,*n)) {
2152
*info = -2;
2153
} else if (*ihi < min(*ilo,*n) || *ihi > *n) {
2154
*info = -3;
2155
} else if (*lda < max(1,*n)) {
2156
*info = -5;
2157
} else if (*lwork < max(1,*n) && ! lquery) {
2158
*info = -8;
2159
}
2160
if (*info != 0) {
2161
i__1 = -(*info);
2162
xerbla_("ZGEHRD", &i__1);
2163
return 0;
2164
} else if (lquery) {
2165
return 0;
2166
}
2167
2168
/* Set elements 1:ILO-1 and IHI:N-1 of TAU to zero */
2169
2170
i__1 = *ilo - 1;
2171
for (i__ = 1; i__ <= i__1; ++i__) {
2172
i__2 = i__;
2173
tau[i__2].r = 0., tau[i__2].i = 0.;
2174
/* L10: */
2175
}
2176
i__1 = *n - 1;
2177
for (i__ = max(1,*ihi); i__ <= i__1; ++i__) {
2178
i__2 = i__;
2179
tau[i__2].r = 0., tau[i__2].i = 0.;
2180
/* L20: */
2181
}
2182
2183
/* Quick return if possible */
2184
2185
nh = *ihi - *ilo + 1;
2186
if (nh <= 1) {
2187
work[1].r = 1., work[1].i = 0.;
2188
return 0;
2189
}
2190
2191
/*
2192
Determine the block size
2193
2194
Computing MIN
2195
*/
2196
i__1 = 64, i__2 = ilaenv_(&c__1, "ZGEHRD", " ", n, ilo, ihi, &c_n1, (
2197
ftnlen)6, (ftnlen)1);
2198
nb = min(i__1,i__2);
2199
nbmin = 2;
2200
iws = 1;
2201
if (nb > 1 && nb < nh) {
2202
2203
/*
2204
Determine when to cross over from blocked to unblocked code
2205
(last block is always handled by unblocked code)
2206
2207
Computing MAX
2208
*/
2209
i__1 = nb, i__2 = ilaenv_(&c__3, "ZGEHRD", " ", n, ilo, ihi, &c_n1, (
2210
ftnlen)6, (ftnlen)1);
2211
nx = max(i__1,i__2);
2212
if (nx < nh) {
2213
2214
/* Determine if workspace is large enough for blocked code */
2215
2216
iws = *n * nb;
2217
if (*lwork < iws) {
2218
2219
/*
2220
Not enough workspace to use optimal NB: determine the
2221
minimum value of NB, and reduce NB or force use of
2222
unblocked code
2223
2224
Computing MAX
2225
*/
2226
i__1 = 2, i__2 = ilaenv_(&c__2, "ZGEHRD", " ", n, ilo, ihi, &
2227
c_n1, (ftnlen)6, (ftnlen)1);
2228
nbmin = max(i__1,i__2);
2229
if (*lwork >= *n * nbmin) {
2230
nb = *lwork / *n;
2231
} else {
2232
nb = 1;
2233
}
2234
}
2235
}
2236
}
2237
ldwork = *n;
2238
2239
if (nb < nbmin || nb >= nh) {
2240
2241
/* Use unblocked code below */
2242
2243
i__ = *ilo;
2244
2245
} else {
2246
2247
/* Use blocked code */
2248
2249
i__1 = *ihi - 1 - nx;
2250
i__2 = nb;
2251
for (i__ = *ilo; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
2252
/* Computing MIN */
2253
i__3 = nb, i__4 = *ihi - i__;
2254
ib = min(i__3,i__4);
2255
2256
/*
2257
Reduce columns i:i+ib-1 to Hessenberg form, returning the
2258
matrices V and T of the block reflector H = I - V*T*V'
2259
which performs the reduction, and also the matrix Y = A*V*T
2260
*/
2261
2262
zlahr2_(ihi, &i__, &ib, &a[i__ * a_dim1 + 1], lda, &tau[i__], t, &
2263
c__65, &work[1], &ldwork);
2264
2265
/*
2266
Apply the block reflector H to A(1:ihi,i+ib:ihi) from the
2267
right, computing A := A - Y * V'. V(i+ib,ib-1) must be set
2268
to 1
2269
*/
2270
2271
i__3 = i__ + ib + (i__ + ib - 1) * a_dim1;
2272
ei.r = a[i__3].r, ei.i = a[i__3].i;
2273
i__3 = i__ + ib + (i__ + ib - 1) * a_dim1;
2274
a[i__3].r = 1., a[i__3].i = 0.;
2275
i__3 = *ihi - i__ - ib + 1;
2276
z__1.r = -1., z__1.i = -0.;
2277
zgemm_("No transpose", "Conjugate transpose", ihi, &i__3, &ib, &
2278
z__1, &work[1], &ldwork, &a[i__ + ib + i__ * a_dim1], lda,
2279
&c_b57, &a[(i__ + ib) * a_dim1 + 1], lda);
2280
i__3 = i__ + ib + (i__ + ib - 1) * a_dim1;
2281
a[i__3].r = ei.r, a[i__3].i = ei.i;
2282
2283
/*
2284
Apply the block reflector H to A(1:i,i+1:i+ib-1) from the
2285
right
2286
*/
2287
2288
i__3 = ib - 1;
2289
ztrmm_("Right", "Lower", "Conjugate transpose", "Unit", &i__, &
2290
i__3, &c_b57, &a[i__ + 1 + i__ * a_dim1], lda, &work[1], &
2291
ldwork);
2292
i__3 = ib - 2;
2293
for (j = 0; j <= i__3; ++j) {
2294
z__1.r = -1., z__1.i = -0.;
2295
zaxpy_(&i__, &z__1, &work[ldwork * j + 1], &c__1, &a[(i__ + j
2296
+ 1) * a_dim1 + 1], &c__1);
2297
/* L30: */
2298
}
2299
2300
/*
2301
Apply the block reflector H to A(i+1:ihi,i+ib:n) from the
2302
left
2303
*/
2304
2305
i__3 = *ihi - i__;
2306
i__4 = *n - i__ - ib + 1;
2307
zlarfb_("Left", "Conjugate transpose", "Forward", "Columnwise", &
2308
i__3, &i__4, &ib, &a[i__ + 1 + i__ * a_dim1], lda, t, &
2309
c__65, &a[i__ + 1 + (i__ + ib) * a_dim1], lda, &work[1], &
2310
ldwork);
2311
/* L40: */
2312
}
2313
}
2314
2315
/* Use unblocked code to reduce the rest of the matrix */
2316
2317
zgehd2_(n, &i__, ihi, &a[a_offset], lda, &tau[1], &work[1], &iinfo);
2318
work[1].r = (doublereal) iws, work[1].i = 0.;
2319
2320
return 0;
2321
2322
/* End of ZGEHRD */
2323
2324
} /* zgehrd_ */
2325
2326
/* Subroutine */ int zgelq2_(integer *m, integer *n, doublecomplex *a,
2327
integer *lda, doublecomplex *tau, doublecomplex *work, integer *info)
2328
{
2329
/* System generated locals */
2330
integer a_dim1, a_offset, i__1, i__2, i__3;
2331
2332
/* Local variables */
2333
static integer i__, k;
2334
static doublecomplex alpha;
2335
extern /* Subroutine */ int zlarf_(char *, integer *, integer *,
2336
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
2337
integer *, doublecomplex *), xerbla_(char *, integer *), zlarfg_(integer *, doublecomplex *, doublecomplex *,
2338
integer *, doublecomplex *), zlacgv_(integer *, doublecomplex *,
2339
integer *);
2340
2341
2342
/*
2343
-- LAPACK routine (version 3.2.2) --
2344
-- LAPACK is a software package provided by Univ. of Tennessee, --
2345
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
2346
June 2010
2347
2348
2349
Purpose
2350
=======
2351
2352
ZGELQ2 computes an LQ factorization of a complex m by n matrix A:
2353
A = L * Q.
2354
2355
Arguments
2356
=========
2357
2358
M (input) INTEGER
2359
The number of rows of the matrix A. M >= 0.
2360
2361
N (input) INTEGER
2362
The number of columns of the matrix A. N >= 0.
2363
2364
A (input/output) COMPLEX*16 array, dimension (LDA,N)
2365
On entry, the m by n matrix A.
2366
On exit, the elements on and below the diagonal of the array
2367
contain the m by min(m,n) lower trapezoidal matrix L (L is
2368
lower triangular if m <= n); the elements above the diagonal,
2369
with the array TAU, represent the unitary matrix Q as a
2370
product of elementary reflectors (see Further Details).
2371
2372
LDA (input) INTEGER
2373
The leading dimension of the array A. LDA >= max(1,M).
2374
2375
TAU (output) COMPLEX*16 array, dimension (min(M,N))
2376
The scalar factors of the elementary reflectors (see Further
2377
Details).
2378
2379
WORK (workspace) COMPLEX*16 array, dimension (M)
2380
2381
INFO (output) INTEGER
2382
= 0: successful exit
2383
< 0: if INFO = -i, the i-th argument had an illegal value
2384
2385
Further Details
2386
===============
2387
2388
The matrix Q is represented as a product of elementary reflectors
2389
2390
Q = H(k)' . . . H(2)' H(1)', where k = min(m,n).
2391
2392
Each H(i) has the form
2393
2394
H(i) = I - tau * v * v'
2395
2396
where tau is a complex scalar, and v is a complex vector with
2397
v(1:i-1) = 0 and v(i) = 1; conjg(v(i+1:n)) is stored on exit in
2398
A(i,i+1:n), and tau in TAU(i).
2399
2400
=====================================================================
2401
2402
2403
Test the input arguments
2404
*/
2405
2406
/* Parameter adjustments */
2407
a_dim1 = *lda;
2408
a_offset = 1 + a_dim1;
2409
a -= a_offset;
2410
--tau;
2411
--work;
2412
2413
/* Function Body */
2414
*info = 0;
2415
if (*m < 0) {
2416
*info = -1;
2417
} else if (*n < 0) {
2418
*info = -2;
2419
} else if (*lda < max(1,*m)) {
2420
*info = -4;
2421
}
2422
if (*info != 0) {
2423
i__1 = -(*info);
2424
xerbla_("ZGELQ2", &i__1);
2425
return 0;
2426
}
2427
2428
k = min(*m,*n);
2429
2430
i__1 = k;
2431
for (i__ = 1; i__ <= i__1; ++i__) {
2432
2433
/* Generate elementary reflector H(i) to annihilate A(i,i+1:n) */
2434
2435
i__2 = *n - i__ + 1;
2436
zlacgv_(&i__2, &a[i__ + i__ * a_dim1], lda);
2437
i__2 = i__ + i__ * a_dim1;
2438
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
2439
i__2 = *n - i__ + 1;
2440
/* Computing MIN */
2441
i__3 = i__ + 1;
2442
zlarfg_(&i__2, &alpha, &a[i__ + min(i__3,*n) * a_dim1], lda, &tau[i__]
2443
);
2444
if (i__ < *m) {
2445
2446
/* Apply H(i) to A(i+1:m,i:n) from the right */
2447
2448
i__2 = i__ + i__ * a_dim1;
2449
a[i__2].r = 1., a[i__2].i = 0.;
2450
i__2 = *m - i__;
2451
i__3 = *n - i__ + 1;
2452
zlarf_("Right", &i__2, &i__3, &a[i__ + i__ * a_dim1], lda, &tau[
2453
i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
2454
}
2455
i__2 = i__ + i__ * a_dim1;
2456
a[i__2].r = alpha.r, a[i__2].i = alpha.i;
2457
i__2 = *n - i__ + 1;
2458
zlacgv_(&i__2, &a[i__ + i__ * a_dim1], lda);
2459
/* L10: */
2460
}
2461
return 0;
2462
2463
/* End of ZGELQ2 */
2464
2465
} /* zgelq2_ */
2466
2467
/* Subroutine */ int zgelqf_(integer *m, integer *n, doublecomplex *a,
2468
integer *lda, doublecomplex *tau, doublecomplex *work, integer *lwork,
2469
integer *info)
2470
{
2471
/* System generated locals */
2472
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
2473
2474
/* Local variables */
2475
static integer i__, k, ib, nb, nx, iws, nbmin, iinfo;
2476
extern /* Subroutine */ int zgelq2_(integer *, integer *, doublecomplex *,
2477
integer *, doublecomplex *, doublecomplex *, integer *), xerbla_(
2478
char *, integer *);
2479
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
2480
integer *, integer *, ftnlen, ftnlen);
2481
extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *,
2482
integer *, integer *, integer *, doublecomplex *, integer *,
2483
doublecomplex *, integer *, doublecomplex *, integer *,
2484
doublecomplex *, integer *);
2485
static integer ldwork;
2486
extern /* Subroutine */ int zlarft_(char *, char *, integer *, integer *,
2487
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
2488
integer *);
2489
static integer lwkopt;
2490
static logical lquery;
2491
2492
2493
/*
2494
-- LAPACK routine (version 3.2) --
2495
-- LAPACK is a software package provided by Univ. of Tennessee, --
2496
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
2497
November 2006
2498
2499
2500
Purpose
2501
=======
2502
2503
ZGELQF computes an LQ factorization of a complex M-by-N matrix A:
2504
A = L * Q.
2505
2506
Arguments
2507
=========
2508
2509
M (input) INTEGER
2510
The number of rows of the matrix A. M >= 0.
2511
2512
N (input) INTEGER
2513
The number of columns of the matrix A. N >= 0.
2514
2515
A (input/output) COMPLEX*16 array, dimension (LDA,N)
2516
On entry, the M-by-N matrix A.
2517
On exit, the elements on and below the diagonal of the array
2518
contain the m-by-min(m,n) lower trapezoidal matrix L (L is
2519
lower triangular if m <= n); the elements above the diagonal,
2520
with the array TAU, represent the unitary matrix Q as a
2521
product of elementary reflectors (see Further Details).
2522
2523
LDA (input) INTEGER
2524
The leading dimension of the array A. LDA >= max(1,M).
2525
2526
TAU (output) COMPLEX*16 array, dimension (min(M,N))
2527
The scalar factors of the elementary reflectors (see Further
2528
Details).
2529
2530
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
2531
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
2532
2533
LWORK (input) INTEGER
2534
The dimension of the array WORK. LWORK >= max(1,M).
2535
For optimum performance LWORK >= M*NB, where NB is the
2536
optimal blocksize.
2537
2538
If LWORK = -1, then a workspace query is assumed; the routine
2539
only calculates the optimal size of the WORK array, returns
2540
this value as the first entry of the WORK array, and no error
2541
message related to LWORK is issued by XERBLA.
2542
2543
INFO (output) INTEGER
2544
= 0: successful exit
2545
< 0: if INFO = -i, the i-th argument had an illegal value
2546
2547
Further Details
2548
===============
2549
2550
The matrix Q is represented as a product of elementary reflectors
2551
2552
Q = H(k)' . . . H(2)' H(1)', where k = min(m,n).
2553
2554
Each H(i) has the form
2555
2556
H(i) = I - tau * v * v'
2557
2558
where tau is a complex scalar, and v is a complex vector with
2559
v(1:i-1) = 0 and v(i) = 1; conjg(v(i+1:n)) is stored on exit in
2560
A(i,i+1:n), and tau in TAU(i).
2561
2562
=====================================================================
2563
2564
2565
Test the input arguments
2566
*/
2567
2568
/* Parameter adjustments */
2569
a_dim1 = *lda;
2570
a_offset = 1 + a_dim1;
2571
a -= a_offset;
2572
--tau;
2573
--work;
2574
2575
/* Function Body */
2576
*info = 0;
2577
nb = ilaenv_(&c__1, "ZGELQF", " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)
2578
1);
2579
lwkopt = *m * nb;
2580
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
2581
lquery = *lwork == -1;
2582
if (*m < 0) {
2583
*info = -1;
2584
} else if (*n < 0) {
2585
*info = -2;
2586
} else if (*lda < max(1,*m)) {
2587
*info = -4;
2588
} else if (*lwork < max(1,*m) && ! lquery) {
2589
*info = -7;
2590
}
2591
if (*info != 0) {
2592
i__1 = -(*info);
2593
xerbla_("ZGELQF", &i__1);
2594
return 0;
2595
} else if (lquery) {
2596
return 0;
2597
}
2598
2599
/* Quick return if possible */
2600
2601
k = min(*m,*n);
2602
if (k == 0) {
2603
work[1].r = 1., work[1].i = 0.;
2604
return 0;
2605
}
2606
2607
nbmin = 2;
2608
nx = 0;
2609
iws = *m;
2610
if (nb > 1 && nb < k) {
2611
2612
/*
2613
Determine when to cross over from blocked to unblocked code.
2614
2615
Computing MAX
2616
*/
2617
i__1 = 0, i__2 = ilaenv_(&c__3, "ZGELQF", " ", m, n, &c_n1, &c_n1, (
2618
ftnlen)6, (ftnlen)1);
2619
nx = max(i__1,i__2);
2620
if (nx < k) {
2621
2622
/* Determine if workspace is large enough for blocked code. */
2623
2624
ldwork = *m;
2625
iws = ldwork * nb;
2626
if (*lwork < iws) {
2627
2628
/*
2629
Not enough workspace to use optimal NB: reduce NB and
2630
determine the minimum value of NB.
2631
*/
2632
2633
nb = *lwork / ldwork;
2634
/* Computing MAX */
2635
i__1 = 2, i__2 = ilaenv_(&c__2, "ZGELQF", " ", m, n, &c_n1, &
2636
c_n1, (ftnlen)6, (ftnlen)1);
2637
nbmin = max(i__1,i__2);
2638
}
2639
}
2640
}
2641
2642
if (nb >= nbmin && nb < k && nx < k) {
2643
2644
/* Use blocked code initially */
2645
2646
i__1 = k - nx;
2647
i__2 = nb;
2648
for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
2649
/* Computing MIN */
2650
i__3 = k - i__ + 1;
2651
ib = min(i__3,nb);
2652
2653
/*
2654
Compute the LQ factorization of the current block
2655
A(i:i+ib-1,i:n)
2656
*/
2657
2658
i__3 = *n - i__ + 1;
2659
zgelq2_(&ib, &i__3, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
2660
1], &iinfo);
2661
if (i__ + ib <= *m) {
2662
2663
/*
2664
Form the triangular factor of the block reflector
2665
H = H(i) H(i+1) . . . H(i+ib-1)
2666
*/
2667
2668
i__3 = *n - i__ + 1;
2669
zlarft_("Forward", "Rowwise", &i__3, &ib, &a[i__ + i__ *
2670
a_dim1], lda, &tau[i__], &work[1], &ldwork);
2671
2672
/* Apply H to A(i+ib:m,i:n) from the right */
2673
2674
i__3 = *m - i__ - ib + 1;
2675
i__4 = *n - i__ + 1;
2676
zlarfb_("Right", "No transpose", "Forward", "Rowwise", &i__3,
2677
&i__4, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
2678
ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[ib +
2679
1], &ldwork);
2680
}
2681
/* L10: */
2682
}
2683
} else {
2684
i__ = 1;
2685
}
2686
2687
/* Use unblocked code to factor the last or only block. */
2688
2689
if (i__ <= k) {
2690
i__2 = *m - i__ + 1;
2691
i__1 = *n - i__ + 1;
2692
zgelq2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[1]
2693
, &iinfo);
2694
}
2695
2696
work[1].r = (doublereal) iws, work[1].i = 0.;
2697
return 0;
2698
2699
/* End of ZGELQF */
2700
2701
} /* zgelqf_ */
2702
2703
/* Subroutine */ int zgelsd_(integer *m, integer *n, integer *nrhs,
2704
doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
2705
doublereal *s, doublereal *rcond, integer *rank, doublecomplex *work,
2706
integer *lwork, doublereal *rwork, integer *iwork, integer *info)
2707
{
2708
/* System generated locals */
2709
integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
2710
2711
/* Local variables */
2712
static integer ie, il, mm;
2713
static doublereal eps, anrm, bnrm;
2714
static integer itau, nlvl, iascl, ibscl;
2715
static doublereal sfmin;
2716
static integer minmn, maxmn, itaup, itauq, mnthr, nwork;
2717
extern /* Subroutine */ int dlabad_(doublereal *, doublereal *);
2718
2719
extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
2720
doublereal *, doublereal *, integer *, integer *, doublereal *,
2721
integer *, integer *), dlaset_(char *, integer *, integer
2722
*, doublereal *, doublereal *, doublereal *, integer *),
2723
xerbla_(char *, integer *), zgebrd_(integer *, integer *,
2724
doublecomplex *, integer *, doublereal *, doublereal *,
2725
doublecomplex *, doublecomplex *, doublecomplex *, integer *,
2726
integer *);
2727
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
2728
integer *, integer *, ftnlen, ftnlen);
2729
extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
2730
integer *, doublereal *);
2731
static doublereal bignum;
2732
extern /* Subroutine */ int zgelqf_(integer *, integer *, doublecomplex *,
2733
integer *, doublecomplex *, doublecomplex *, integer *, integer *
2734
), zlalsd_(char *, integer *, integer *, integer *, doublereal *,
2735
doublereal *, doublecomplex *, integer *, doublereal *, integer *,
2736
doublecomplex *, doublereal *, integer *, integer *),
2737
zlascl_(char *, integer *, integer *, doublereal *, doublereal *,
2738
integer *, integer *, doublecomplex *, integer *, integer *), zgeqrf_(integer *, integer *, doublecomplex *, integer *,
2739
doublecomplex *, doublecomplex *, integer *, integer *);
2740
static integer ldwork;
2741
extern /* Subroutine */ int zlacpy_(char *, integer *, integer *,
2742
doublecomplex *, integer *, doublecomplex *, integer *),
2743
zlaset_(char *, integer *, integer *, doublecomplex *,
2744
doublecomplex *, doublecomplex *, integer *);
2745
static integer liwork, minwrk, maxwrk;
2746
static doublereal smlnum;
2747
extern /* Subroutine */ int zunmbr_(char *, char *, char *, integer *,
2748
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
2749
doublecomplex *, integer *, doublecomplex *, integer *, integer *
2750
);
2751
static integer lrwork;
2752
static logical lquery;
2753
static integer nrwork, smlsiz;
2754
extern /* Subroutine */ int zunmlq_(char *, char *, integer *, integer *,
2755
integer *, doublecomplex *, integer *, doublecomplex *,
2756
doublecomplex *, integer *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *,
2757
integer *, doublecomplex *, integer *, doublecomplex *,
2758
doublecomplex *, integer *, doublecomplex *, integer *, integer *);
2759
2760
2761
/*
2762
-- LAPACK driver routine (version 3.2) --
2763
-- LAPACK is a software package provided by Univ. of Tennessee, --
2764
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
2765
November 2006
2766
2767
2768
Purpose
2769
=======
2770
2771
ZGELSD computes the minimum-norm solution to a real linear least
2772
squares problem:
2773
minimize 2-norm(| b - A*x |)
2774
using the singular value decomposition (SVD) of A. A is an M-by-N
2775
matrix which may be rank-deficient.
2776
2777
Several right hand side vectors b and solution vectors x can be
2778
handled in a single call; they are stored as the columns of the
2779
M-by-NRHS right hand side matrix B and the N-by-NRHS solution
2780
matrix X.
2781
2782
The problem is solved in three steps:
2783
(1) Reduce the coefficient matrix A to bidiagonal form with
2784
Householder tranformations, reducing the original problem
2785
into a "bidiagonal least squares problem" (BLS)
2786
(2) Solve the BLS using a divide and conquer approach.
2787
(3) Apply back all the Householder tranformations to solve
2788
the original least squares problem.
2789
2790
The effective rank of A is determined by treating as zero those
2791
singular values which are less than RCOND times the largest singular
2792
value.
2793
2794
The divide and conquer algorithm makes very mild assumptions about
2795
floating point arithmetic. It will work on machines with a guard
2796
digit in add/subtract, or on those binary machines without guard
2797
digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
2798
Cray-2. It could conceivably fail on hexadecimal or decimal machines
2799
without guard digits, but we know of none.
2800
2801
Arguments
2802
=========
2803
2804
M (input) INTEGER
2805
The number of rows of the matrix A. M >= 0.
2806
2807
N (input) INTEGER
2808
The number of columns of the matrix A. N >= 0.
2809
2810
NRHS (input) INTEGER
2811
The number of right hand sides, i.e., the number of columns
2812
of the matrices B and X. NRHS >= 0.
2813
2814
A (input) COMPLEX*16 array, dimension (LDA,N)
2815
On entry, the M-by-N matrix A.
2816
On exit, A has been destroyed.
2817
2818
LDA (input) INTEGER
2819
The leading dimension of the array A. LDA >= max(1,M).
2820
2821
B (input/output) COMPLEX*16 array, dimension (LDB,NRHS)
2822
On entry, the M-by-NRHS right hand side matrix B.
2823
On exit, B is overwritten by the N-by-NRHS solution matrix X.
2824
If m >= n and RANK = n, the residual sum-of-squares for
2825
the solution in the i-th column is given by the sum of
2826
squares of the modulus of elements n+1:m in that column.
2827
2828
LDB (input) INTEGER
2829
The leading dimension of the array B. LDB >= max(1,M,N).
2830
2831
S (output) DOUBLE PRECISION array, dimension (min(M,N))
2832
The singular values of A in decreasing order.
2833
The condition number of A in the 2-norm = S(1)/S(min(m,n)).
2834
2835
RCOND (input) DOUBLE PRECISION
2836
RCOND is used to determine the effective rank of A.
2837
Singular values S(i) <= RCOND*S(1) are treated as zero.
2838
If RCOND < 0, machine precision is used instead.
2839
2840
RANK (output) INTEGER
2841
The effective rank of A, i.e., the number of singular values
2842
which are greater than RCOND*S(1).
2843
2844
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
2845
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
2846
2847
LWORK (input) INTEGER
2848
The dimension of the array WORK. LWORK must be at least 1.
2849
The exact minimum amount of workspace needed depends on M,
2850
N and NRHS. As long as LWORK is at least
2851
2*N + N*NRHS
2852
if M is greater than or equal to N or
2853
2*M + M*NRHS
2854
if M is less than N, the code will execute correctly.
2855
For good performance, LWORK should generally be larger.
2856
2857
If LWORK = -1, then a workspace query is assumed; the routine
2858
only calculates the optimal size of the array WORK and the
2859
minimum sizes of the arrays RWORK and IWORK, and returns
2860
these values as the first entries of the WORK, RWORK and
2861
IWORK arrays, and no error message related to LWORK is issued
2862
by XERBLA.
2863
2864
RWORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LRWORK))
2865
LRWORK >=
2866
10*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS +
2867
MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS )
2868
if M is greater than or equal to N or
2869
10*M + 2*M*SMLSIZ + 8*M*NLVL + 3*SMLSIZ*NRHS +
2870
MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS )
2871
if M is less than N, the code will execute correctly.
2872
SMLSIZ is returned by ILAENV and is equal to the maximum
2873
size of the subproblems at the bottom of the computation
2874
tree (usually about 25), and
2875
NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 )
2876
On exit, if INFO = 0, RWORK(1) returns the minimum LRWORK.
2877
2878
IWORK (workspace) INTEGER array, dimension (MAX(1,LIWORK))
2879
LIWORK >= max(1, 3*MINMN*NLVL + 11*MINMN),
2880
where MINMN = MIN( M,N ).
2881
On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK.
2882
2883
INFO (output) INTEGER
2884
= 0: successful exit
2885
< 0: if INFO = -i, the i-th argument had an illegal value.
2886
> 0: the algorithm for computing the SVD failed to converge;
2887
if INFO = i, i off-diagonal elements of an intermediate
2888
bidiagonal form did not converge to zero.
2889
2890
Further Details
2891
===============
2892
2893
Based on contributions by
2894
Ming Gu and Ren-Cang Li, Computer Science Division, University of
2895
California at Berkeley, USA
2896
Osni Marques, LBNL/NERSC, USA
2897
2898
=====================================================================
2899
2900
2901
Test the input arguments.
2902
*/
2903
2904
/* Parameter adjustments */
2905
a_dim1 = *lda;
2906
a_offset = 1 + a_dim1;
2907
a -= a_offset;
2908
b_dim1 = *ldb;
2909
b_offset = 1 + b_dim1;
2910
b -= b_offset;
2911
--s;
2912
--work;
2913
--rwork;
2914
--iwork;
2915
2916
/* Function Body */
2917
*info = 0;
2918
minmn = min(*m,*n);
2919
maxmn = max(*m,*n);
2920
lquery = *lwork == -1;
2921
if (*m < 0) {
2922
*info = -1;
2923
} else if (*n < 0) {
2924
*info = -2;
2925
} else if (*nrhs < 0) {
2926
*info = -3;
2927
} else if (*lda < max(1,*m)) {
2928
*info = -5;
2929
} else if (*ldb < max(1,maxmn)) {
2930
*info = -7;
2931
}
2932
2933
/*
2934
Compute workspace.
2935
(Note: Comments in the code beginning "Workspace:" describe the
2936
minimal amount of workspace needed at that point in the code,
2937
as well as the preferred amount for good performance.
2938
NB refers to the optimal block size for the immediately
2939
following subroutine, as returned by ILAENV.)
2940
*/
2941
2942
if (*info == 0) {
2943
minwrk = 1;
2944
maxwrk = 1;
2945
liwork = 1;
2946
lrwork = 1;
2947
if (minmn > 0) {
2948
smlsiz = ilaenv_(&c__9, "ZGELSD", " ", &c__0, &c__0, &c__0, &c__0,
2949
(ftnlen)6, (ftnlen)1);
2950
mnthr = ilaenv_(&c__6, "ZGELSD", " ", m, n, nrhs, &c_n1, (ftnlen)
2951
6, (ftnlen)1);
2952
/* Computing MAX */
2953
i__1 = (integer) (log((doublereal) minmn / (doublereal) (smlsiz +
2954
1)) / log(2.)) + 1;
2955
nlvl = max(i__1,0);
2956
liwork = minmn * 3 * nlvl + minmn * 11;
2957
mm = *m;
2958
if (*m >= *n && *m >= mnthr) {
2959
2960
/*
2961
Path 1a - overdetermined, with many more rows than
2962
columns.
2963
*/
2964
2965
mm = *n;
2966
/* Computing MAX */
2967
i__1 = maxwrk, i__2 = *n * ilaenv_(&c__1, "ZGEQRF", " ", m, n,
2968
&c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
2969
maxwrk = max(i__1,i__2);
2970
/* Computing MAX */
2971
i__1 = maxwrk, i__2 = *nrhs * ilaenv_(&c__1, "ZUNMQR", "LC",
2972
m, nrhs, n, &c_n1, (ftnlen)6, (ftnlen)2);
2973
maxwrk = max(i__1,i__2);
2974
}
2975
if (*m >= *n) {
2976
2977
/*
2978
Path 1 - overdetermined or exactly determined.
2979
2980
Computing MAX
2981
Computing 2nd power
2982
*/
2983
i__3 = smlsiz + 1;
2984
i__1 = i__3 * i__3, i__2 = *n * (*nrhs + 1) + (*nrhs << 1);
2985
lrwork = *n * 10 + (*n << 1) * smlsiz + (*n << 3) * nlvl +
2986
smlsiz * 3 * *nrhs + max(i__1,i__2);
2987
/* Computing MAX */
2988
i__1 = maxwrk, i__2 = (*n << 1) + (mm + *n) * ilaenv_(&c__1,
2989
"ZGEBRD", " ", &mm, n, &c_n1, &c_n1, (ftnlen)6, (
2990
ftnlen)1);
2991
maxwrk = max(i__1,i__2);
2992
/* Computing MAX */
2993
i__1 = maxwrk, i__2 = (*n << 1) + *nrhs * ilaenv_(&c__1,
2994
"ZUNMBR", "QLC", &mm, nrhs, n, &c_n1, (ftnlen)6, (
2995
ftnlen)3);
2996
maxwrk = max(i__1,i__2);
2997
/* Computing MAX */
2998
i__1 = maxwrk, i__2 = (*n << 1) + (*n - 1) * ilaenv_(&c__1,
2999
"ZUNMBR", "PLN", n, nrhs, n, &c_n1, (ftnlen)6, (
3000
ftnlen)3);
3001
maxwrk = max(i__1,i__2);
3002
/* Computing MAX */
3003
i__1 = maxwrk, i__2 = (*n << 1) + *n * *nrhs;
3004
maxwrk = max(i__1,i__2);
3005
/* Computing MAX */
3006
i__1 = (*n << 1) + mm, i__2 = (*n << 1) + *n * *nrhs;
3007
minwrk = max(i__1,i__2);
3008
}
3009
if (*n > *m) {
3010
/*
3011
Computing MAX
3012
Computing 2nd power
3013
*/
3014
i__3 = smlsiz + 1;
3015
i__1 = i__3 * i__3, i__2 = *n * (*nrhs + 1) + (*nrhs << 1);
3016
lrwork = *m * 10 + (*m << 1) * smlsiz + (*m << 3) * nlvl +
3017
smlsiz * 3 * *nrhs + max(i__1,i__2);
3018
if (*n >= mnthr) {
3019
3020
/*
3021
Path 2a - underdetermined, with many more columns
3022
than rows.
3023
*/
3024
3025
maxwrk = *m + *m * ilaenv_(&c__1, "ZGELQF", " ", m, n, &
3026
c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
3027
/* Computing MAX */
3028
i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m << 1) *
3029
ilaenv_(&c__1, "ZGEBRD", " ", m, m, &c_n1, &c_n1,
3030
(ftnlen)6, (ftnlen)1);
3031
maxwrk = max(i__1,i__2);
3032
/* Computing MAX */
3033
i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + *nrhs *
3034
ilaenv_(&c__1, "ZUNMBR", "QLC", m, nrhs, m, &c_n1,
3035
(ftnlen)6, (ftnlen)3);
3036
maxwrk = max(i__1,i__2);
3037
/* Computing MAX */
3038
i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m - 1) *
3039
ilaenv_(&c__1, "ZUNMLQ", "LC", n, nrhs, m, &c_n1,
3040
(ftnlen)6, (ftnlen)2);
3041
maxwrk = max(i__1,i__2);
3042
if (*nrhs > 1) {
3043
/* Computing MAX */
3044
i__1 = maxwrk, i__2 = *m * *m + *m + *m * *nrhs;
3045
maxwrk = max(i__1,i__2);
3046
} else {
3047
/* Computing MAX */
3048
i__1 = maxwrk, i__2 = *m * *m + (*m << 1);
3049
maxwrk = max(i__1,i__2);
3050
}
3051
/* Computing MAX */
3052
i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + *m * *nrhs;
3053
maxwrk = max(i__1,i__2);
3054
/*
3055
XXX: Ensure the Path 2a case below is triggered. The workspace
3056
calculation should use queries for all routines eventually.
3057
Computing MAX
3058
Computing MAX
3059
*/
3060
i__3 = *m, i__4 = (*m << 1) - 4, i__3 = max(i__3,i__4),
3061
i__3 = max(i__3,*nrhs), i__4 = *n - *m * 3;
3062
i__1 = maxwrk, i__2 = (*m << 2) + *m * *m + max(i__3,i__4)
3063
;
3064
maxwrk = max(i__1,i__2);
3065
} else {
3066
3067
/* Path 2 - underdetermined. */
3068
3069
maxwrk = (*m << 1) + (*n + *m) * ilaenv_(&c__1, "ZGEBRD",
3070
" ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
3071
/* Computing MAX */
3072
i__1 = maxwrk, i__2 = (*m << 1) + *nrhs * ilaenv_(&c__1,
3073
"ZUNMBR", "QLC", m, nrhs, m, &c_n1, (ftnlen)6, (
3074
ftnlen)3);
3075
maxwrk = max(i__1,i__2);
3076
/* Computing MAX */
3077
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
3078
"ZUNMBR", "PLN", n, nrhs, m, &c_n1, (ftnlen)6, (
3079
ftnlen)3);
3080
maxwrk = max(i__1,i__2);
3081
/* Computing MAX */
3082
i__1 = maxwrk, i__2 = (*m << 1) + *m * *nrhs;
3083
maxwrk = max(i__1,i__2);
3084
}
3085
/* Computing MAX */
3086
i__1 = (*m << 1) + *n, i__2 = (*m << 1) + *m * *nrhs;
3087
minwrk = max(i__1,i__2);
3088
}
3089
}
3090
minwrk = min(minwrk,maxwrk);
3091
work[1].r = (doublereal) maxwrk, work[1].i = 0.;
3092
iwork[1] = liwork;
3093
rwork[1] = (doublereal) lrwork;
3094
3095
if (*lwork < minwrk && ! lquery) {
3096
*info = -12;
3097
}
3098
}
3099
3100
if (*info != 0) {
3101
i__1 = -(*info);
3102
xerbla_("ZGELSD", &i__1);
3103
return 0;
3104
} else if (lquery) {
3105
return 0;
3106
}
3107
3108
/* Quick return if possible. */
3109
3110
if (*m == 0 || *n == 0) {
3111
*rank = 0;
3112
return 0;
3113
}
3114
3115
/* Get machine parameters. */
3116
3117
eps = PRECISION;
3118
sfmin = SAFEMINIMUM;
3119
smlnum = sfmin / eps;
3120
bignum = 1. / smlnum;
3121
dlabad_(&smlnum, &bignum);
3122
3123
/* Scale A if max entry outside range [SMLNUM,BIGNUM]. */
3124
3125
anrm = zlange_("M", m, n, &a[a_offset], lda, &rwork[1]);
3126
iascl = 0;
3127
if (anrm > 0. && anrm < smlnum) {
3128
3129
/* Scale matrix norm up to SMLNUM */
3130
3131
zlascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda,
3132
info);
3133
iascl = 1;
3134
} else if (anrm > bignum) {
3135
3136
/* Scale matrix norm down to BIGNUM. */
3137
3138
zlascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda,
3139
info);
3140
iascl = 2;
3141
} else if (anrm == 0.) {
3142
3143
/* Matrix all zero. Return zero solution. */
3144
3145
i__1 = max(*m,*n);
3146
zlaset_("F", &i__1, nrhs, &c_b56, &c_b56, &b[b_offset], ldb);
3147
dlaset_("F", &minmn, &c__1, &c_b328, &c_b328, &s[1], &c__1)
3148
;
3149
*rank = 0;
3150
goto L10;
3151
}
3152
3153
/* Scale B if max entry outside range [SMLNUM,BIGNUM]. */
3154
3155
bnrm = zlange_("M", m, nrhs, &b[b_offset], ldb, &rwork[1]);
3156
ibscl = 0;
3157
if (bnrm > 0. && bnrm < smlnum) {
3158
3159
/* Scale matrix norm up to SMLNUM. */
3160
3161
zlascl_("G", &c__0, &c__0, &bnrm, &smlnum, m, nrhs, &b[b_offset], ldb,
3162
info);
3163
ibscl = 1;
3164
} else if (bnrm > bignum) {
3165
3166
/* Scale matrix norm down to BIGNUM. */
3167
3168
zlascl_("G", &c__0, &c__0, &bnrm, &bignum, m, nrhs, &b[b_offset], ldb,
3169
info);
3170
ibscl = 2;
3171
}
3172
3173
/* If M < N make sure B(M+1:N,:) = 0 */
3174
3175
if (*m < *n) {
3176
i__1 = *n - *m;
3177
zlaset_("F", &i__1, nrhs, &c_b56, &c_b56, &b[*m + 1 + b_dim1], ldb);
3178
}
3179
3180
/* Overdetermined case. */
3181
3182
if (*m >= *n) {
3183
3184
/* Path 1 - overdetermined or exactly determined. */
3185
3186
mm = *m;
3187
if (*m >= mnthr) {
3188
3189
/* Path 1a - overdetermined, with many more rows than columns */
3190
3191
mm = *n;
3192
itau = 1;
3193
nwork = itau + *n;
3194
3195
/*
3196
Compute A=Q*R.
3197
(RWorkspace: need N)
3198
(CWorkspace: need N, prefer N*NB)
3199
*/
3200
3201
i__1 = *lwork - nwork + 1;
3202
zgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1,
3203
info);
3204
3205
/*
3206
Multiply B by transpose(Q).
3207
(RWorkspace: need N)
3208
(CWorkspace: need NRHS, prefer NRHS*NB)
3209
*/
3210
3211
i__1 = *lwork - nwork + 1;
3212
zunmqr_("L", "C", m, nrhs, n, &a[a_offset], lda, &work[itau], &b[
3213
b_offset], ldb, &work[nwork], &i__1, info);
3214
3215
/* Zero out below R. */
3216
3217
if (*n > 1) {
3218
i__1 = *n - 1;
3219
i__2 = *n - 1;
3220
zlaset_("L", &i__1, &i__2, &c_b56, &c_b56, &a[a_dim1 + 2],
3221
lda);
3222
}
3223
}
3224
3225
itauq = 1;
3226
itaup = itauq + *n;
3227
nwork = itaup + *n;
3228
ie = 1;
3229
nrwork = ie + *n;
3230
3231
/*
3232
Bidiagonalize R in A.
3233
(RWorkspace: need N)
3234
(CWorkspace: need 2*N+MM, prefer 2*N+(MM+N)*NB)
3235
*/
3236
3237
i__1 = *lwork - nwork + 1;
3238
zgebrd_(&mm, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq], &
3239
work[itaup], &work[nwork], &i__1, info);
3240
3241
/*
3242
Multiply B by transpose of left bidiagonalizing vectors of R.
3243
(CWorkspace: need 2*N+NRHS, prefer 2*N+NRHS*NB)
3244
*/
3245
3246
i__1 = *lwork - nwork + 1;
3247
zunmbr_("Q", "L", "C", &mm, nrhs, n, &a[a_offset], lda, &work[itauq],
3248
&b[b_offset], ldb, &work[nwork], &i__1, info);
3249
3250
/* Solve the bidiagonal least squares problem. */
3251
3252
zlalsd_("U", &smlsiz, n, nrhs, &s[1], &rwork[ie], &b[b_offset], ldb,
3253
rcond, rank, &work[nwork], &rwork[nrwork], &iwork[1], info);
3254
if (*info != 0) {
3255
goto L10;
3256
}
3257
3258
/* Multiply B by right bidiagonalizing vectors of R. */
3259
3260
i__1 = *lwork - nwork + 1;
3261
zunmbr_("P", "L", "N", n, nrhs, n, &a[a_offset], lda, &work[itaup], &
3262
b[b_offset], ldb, &work[nwork], &i__1, info);
3263
3264
} else /* if(complicated condition) */ {
3265
/* Computing MAX */
3266
i__1 = *m, i__2 = (*m << 1) - 4, i__1 = max(i__1,i__2), i__1 = max(
3267
i__1,*nrhs), i__2 = *n - *m * 3;
3268
if (*n >= mnthr && *lwork >= (*m << 2) + *m * *m + max(i__1,i__2)) {
3269
3270
/*
3271
Path 2a - underdetermined, with many more columns than rows
3272
and sufficient workspace for an efficient algorithm.
3273
*/
3274
3275
ldwork = *m;
3276
/*
3277
Computing MAX
3278
Computing MAX
3279
*/
3280
i__3 = *m, i__4 = (*m << 1) - 4, i__3 = max(i__3,i__4), i__3 =
3281
max(i__3,*nrhs), i__4 = *n - *m * 3;
3282
i__1 = (*m << 2) + *m * *lda + max(i__3,i__4), i__2 = *m * *lda +
3283
*m + *m * *nrhs;
3284
if (*lwork >= max(i__1,i__2)) {
3285
ldwork = *lda;
3286
}
3287
itau = 1;
3288
nwork = *m + 1;
3289
3290
/*
3291
Compute A=L*Q.
3292
(CWorkspace: need 2*M, prefer M+M*NB)
3293
*/
3294
3295
i__1 = *lwork - nwork + 1;
3296
zgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1,
3297
info);
3298
il = nwork;
3299
3300
/* Copy L to WORK(IL), zeroing out above its diagonal. */
3301
3302
zlacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwork);
3303
i__1 = *m - 1;
3304
i__2 = *m - 1;
3305
zlaset_("U", &i__1, &i__2, &c_b56, &c_b56, &work[il + ldwork], &
3306
ldwork);
3307
itauq = il + ldwork * *m;
3308
itaup = itauq + *m;
3309
nwork = itaup + *m;
3310
ie = 1;
3311
nrwork = ie + *m;
3312
3313
/*
3314
Bidiagonalize L in WORK(IL).
3315
(RWorkspace: need M)
3316
(CWorkspace: need M*M+4*M, prefer M*M+4*M+2*M*NB)
3317
*/
3318
3319
i__1 = *lwork - nwork + 1;
3320
zgebrd_(m, m, &work[il], &ldwork, &s[1], &rwork[ie], &work[itauq],
3321
&work[itaup], &work[nwork], &i__1, info);
3322
3323
/*
3324
Multiply B by transpose of left bidiagonalizing vectors of L.
3325
(CWorkspace: need M*M+4*M+NRHS, prefer M*M+4*M+NRHS*NB)
3326
*/
3327
3328
i__1 = *lwork - nwork + 1;
3329
zunmbr_("Q", "L", "C", m, nrhs, m, &work[il], &ldwork, &work[
3330
itauq], &b[b_offset], ldb, &work[nwork], &i__1, info);
3331
3332
/* Solve the bidiagonal least squares problem. */
3333
3334
zlalsd_("U", &smlsiz, m, nrhs, &s[1], &rwork[ie], &b[b_offset],
3335
ldb, rcond, rank, &work[nwork], &rwork[nrwork], &iwork[1],
3336
info);
3337
if (*info != 0) {
3338
goto L10;
3339
}
3340
3341
/* Multiply B by right bidiagonalizing vectors of L. */
3342
3343
i__1 = *lwork - nwork + 1;
3344
zunmbr_("P", "L", "N", m, nrhs, m, &work[il], &ldwork, &work[
3345
itaup], &b[b_offset], ldb, &work[nwork], &i__1, info);
3346
3347
/* Zero out below first M rows of B. */
3348
3349
i__1 = *n - *m;
3350
zlaset_("F", &i__1, nrhs, &c_b56, &c_b56, &b[*m + 1 + b_dim1],
3351
ldb);
3352
nwork = itau + *m;
3353
3354
/*
3355
Multiply transpose(Q) by B.
3356
(CWorkspace: need NRHS, prefer NRHS*NB)
3357
*/
3358
3359
i__1 = *lwork - nwork + 1;
3360
zunmlq_("L", "C", n, nrhs, m, &a[a_offset], lda, &work[itau], &b[
3361
b_offset], ldb, &work[nwork], &i__1, info);
3362
3363
} else {
3364
3365
/* Path 2 - remaining underdetermined cases. */
3366
3367
itauq = 1;
3368
itaup = itauq + *m;
3369
nwork = itaup + *m;
3370
ie = 1;
3371
nrwork = ie + *m;
3372
3373
/*
3374
Bidiagonalize A.
3375
(RWorkspace: need M)
3376
(CWorkspace: need 2*M+N, prefer 2*M+(M+N)*NB)
3377
*/
3378
3379
i__1 = *lwork - nwork + 1;
3380
zgebrd_(m, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq],
3381
&work[itaup], &work[nwork], &i__1, info);
3382
3383
/*
3384
Multiply B by transpose of left bidiagonalizing vectors.
3385
(CWorkspace: need 2*M+NRHS, prefer 2*M+NRHS*NB)
3386
*/
3387
3388
i__1 = *lwork - nwork + 1;
3389
zunmbr_("Q", "L", "C", m, nrhs, n, &a[a_offset], lda, &work[itauq]
3390
, &b[b_offset], ldb, &work[nwork], &i__1, info);
3391
3392
/* Solve the bidiagonal least squares problem. */
3393
3394
zlalsd_("L", &smlsiz, m, nrhs, &s[1], &rwork[ie], &b[b_offset],
3395
ldb, rcond, rank, &work[nwork], &rwork[nrwork], &iwork[1],
3396
info);
3397
if (*info != 0) {
3398
goto L10;
3399
}
3400
3401
/* Multiply B by right bidiagonalizing vectors of A. */
3402
3403
i__1 = *lwork - nwork + 1;
3404
zunmbr_("P", "L", "N", n, nrhs, m, &a[a_offset], lda, &work[itaup]
3405
, &b[b_offset], ldb, &work[nwork], &i__1, info);
3406
3407
}
3408
}
3409
3410
/* Undo scaling. */
3411
3412
if (iascl == 1) {
3413
zlascl_("G", &c__0, &c__0, &anrm, &smlnum, n, nrhs, &b[b_offset], ldb,
3414
info);
3415
dlascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], &
3416
minmn, info);
3417
} else if (iascl == 2) {
3418
zlascl_("G", &c__0, &c__0, &anrm, &bignum, n, nrhs, &b[b_offset], ldb,
3419
info);
3420
dlascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], &
3421
minmn, info);
3422
}
3423
if (ibscl == 1) {
3424
zlascl_("G", &c__0, &c__0, &smlnum, &bnrm, n, nrhs, &b[b_offset], ldb,
3425
info);
3426
} else if (ibscl == 2) {
3427
zlascl_("G", &c__0, &c__0, &bignum, &bnrm, n, nrhs, &b[b_offset], ldb,
3428
info);
3429
}
3430
3431
L10:
3432
work[1].r = (doublereal) maxwrk, work[1].i = 0.;
3433
iwork[1] = liwork;
3434
rwork[1] = (doublereal) lrwork;
3435
return 0;
3436
3437
/* End of ZGELSD */
3438
3439
} /* zgelsd_ */
3440
3441
/* Subroutine */ int zgeqr2_(integer *m, integer *n, doublecomplex *a,
3442
integer *lda, doublecomplex *tau, doublecomplex *work, integer *info)
3443
{
3444
/* System generated locals */
3445
integer a_dim1, a_offset, i__1, i__2, i__3;
3446
doublecomplex z__1;
3447
3448
/* Local variables */
3449
static integer i__, k;
3450
static doublecomplex alpha;
3451
extern /* Subroutine */ int zlarf_(char *, integer *, integer *,
3452
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
3453
integer *, doublecomplex *), xerbla_(char *, integer *), zlarfg_(integer *, doublecomplex *, doublecomplex *,
3454
integer *, doublecomplex *);
3455
3456
3457
/*
3458
-- LAPACK routine (version 3.2.2) --
3459
-- LAPACK is a software package provided by Univ. of Tennessee, --
3460
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
3461
June 2010
3462
3463
3464
Purpose
3465
=======
3466
3467
ZGEQR2 computes a QR factorization of a complex m by n matrix A:
3468
A = Q * R.
3469
3470
Arguments
3471
=========
3472
3473
M (input) INTEGER
3474
The number of rows of the matrix A. M >= 0.
3475
3476
N (input) INTEGER
3477
The number of columns of the matrix A. N >= 0.
3478
3479
A (input/output) COMPLEX*16 array, dimension (LDA,N)
3480
On entry, the m by n matrix A.
3481
On exit, the elements on and above the diagonal of the array
3482
contain the min(m,n) by n upper trapezoidal matrix R (R is
3483
upper triangular if m >= n); the elements below the diagonal,
3484
with the array TAU, represent the unitary matrix Q as a
3485
product of elementary reflectors (see Further Details).
3486
3487
LDA (input) INTEGER
3488
The leading dimension of the array A. LDA >= max(1,M).
3489
3490
TAU (output) COMPLEX*16 array, dimension (min(M,N))
3491
The scalar factors of the elementary reflectors (see Further
3492
Details).
3493
3494
WORK (workspace) COMPLEX*16 array, dimension (N)
3495
3496
INFO (output) INTEGER
3497
= 0: successful exit
3498
< 0: if INFO = -i, the i-th argument had an illegal value
3499
3500
Further Details
3501
===============
3502
3503
The matrix Q is represented as a product of elementary reflectors
3504
3505
Q = H(1) H(2) . . . H(k), where k = min(m,n).
3506
3507
Each H(i) has the form
3508
3509
H(i) = I - tau * v * v'
3510
3511
where tau is a complex scalar, and v is a complex vector with
3512
v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
3513
and tau in TAU(i).
3514
3515
=====================================================================
3516
3517
3518
Test the input arguments
3519
*/
3520
3521
/* Parameter adjustments */
3522
a_dim1 = *lda;
3523
a_offset = 1 + a_dim1;
3524
a -= a_offset;
3525
--tau;
3526
--work;
3527
3528
/* Function Body */
3529
*info = 0;
3530
if (*m < 0) {
3531
*info = -1;
3532
} else if (*n < 0) {
3533
*info = -2;
3534
} else if (*lda < max(1,*m)) {
3535
*info = -4;
3536
}
3537
if (*info != 0) {
3538
i__1 = -(*info);
3539
xerbla_("ZGEQR2", &i__1);
3540
return 0;
3541
}
3542
3543
k = min(*m,*n);
3544
3545
i__1 = k;
3546
for (i__ = 1; i__ <= i__1; ++i__) {
3547
3548
/* Generate elementary reflector H(i) to annihilate A(i+1:m,i) */
3549
3550
i__2 = *m - i__ + 1;
3551
/* Computing MIN */
3552
i__3 = i__ + 1;
3553
zlarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[min(i__3,*m) + i__ * a_dim1]
3554
, &c__1, &tau[i__]);
3555
if (i__ < *n) {
3556
3557
/* Apply H(i)' to A(i:m,i+1:n) from the left */
3558
3559
i__2 = i__ + i__ * a_dim1;
3560
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
3561
i__2 = i__ + i__ * a_dim1;
3562
a[i__2].r = 1., a[i__2].i = 0.;
3563
i__2 = *m - i__ + 1;
3564
i__3 = *n - i__;
3565
d_cnjg(&z__1, &tau[i__]);
3566
zlarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &z__1,
3567
&a[i__ + (i__ + 1) * a_dim1], lda, &work[1]);
3568
i__2 = i__ + i__ * a_dim1;
3569
a[i__2].r = alpha.r, a[i__2].i = alpha.i;
3570
}
3571
/* L10: */
3572
}
3573
return 0;
3574
3575
/* End of ZGEQR2 */
3576
3577
} /* zgeqr2_ */
3578
3579
/* Subroutine */ int zgeqrf_(integer *m, integer *n, doublecomplex *a,
3580
integer *lda, doublecomplex *tau, doublecomplex *work, integer *lwork,
3581
integer *info)
3582
{
3583
/* System generated locals */
3584
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
3585
3586
/* Local variables */
3587
static integer i__, k, ib, nb, nx, iws, nbmin, iinfo;
3588
extern /* Subroutine */ int zgeqr2_(integer *, integer *, doublecomplex *,
3589
integer *, doublecomplex *, doublecomplex *, integer *), xerbla_(
3590
char *, integer *);
3591
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
3592
integer *, integer *, ftnlen, ftnlen);
3593
extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *,
3594
integer *, integer *, integer *, doublecomplex *, integer *,
3595
doublecomplex *, integer *, doublecomplex *, integer *,
3596
doublecomplex *, integer *);
3597
static integer ldwork;
3598
extern /* Subroutine */ int zlarft_(char *, char *, integer *, integer *,
3599
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
3600
integer *);
3601
static integer lwkopt;
3602
static logical lquery;
3603
3604
3605
/*
3606
-- LAPACK routine (version 3.2) --
3607
-- LAPACK is a software package provided by Univ. of Tennessee, --
3608
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
3609
November 2006
3610
3611
3612
Purpose
3613
=======
3614
3615
ZGEQRF computes a QR factorization of a complex M-by-N matrix A:
3616
A = Q * R.
3617
3618
Arguments
3619
=========
3620
3621
M (input) INTEGER
3622
The number of rows of the matrix A. M >= 0.
3623
3624
N (input) INTEGER
3625
The number of columns of the matrix A. N >= 0.
3626
3627
A (input/output) COMPLEX*16 array, dimension (LDA,N)
3628
On entry, the M-by-N matrix A.
3629
On exit, the elements on and above the diagonal of the array
3630
contain the min(M,N)-by-N upper trapezoidal matrix R (R is
3631
upper triangular if m >= n); the elements below the diagonal,
3632
with the array TAU, represent the unitary matrix Q as a
3633
product of min(m,n) elementary reflectors (see Further
3634
Details).
3635
3636
LDA (input) INTEGER
3637
The leading dimension of the array A. LDA >= max(1,M).
3638
3639
TAU (output) COMPLEX*16 array, dimension (min(M,N))
3640
The scalar factors of the elementary reflectors (see Further
3641
Details).
3642
3643
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
3644
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
3645
3646
LWORK (input) INTEGER
3647
The dimension of the array WORK. LWORK >= max(1,N).
3648
For optimum performance LWORK >= N*NB, where NB is
3649
the optimal blocksize.
3650
3651
If LWORK = -1, then a workspace query is assumed; the routine
3652
only calculates the optimal size of the WORK array, returns
3653
this value as the first entry of the WORK array, and no error
3654
message related to LWORK is issued by XERBLA.
3655
3656
INFO (output) INTEGER
3657
= 0: successful exit
3658
< 0: if INFO = -i, the i-th argument had an illegal value
3659
3660
Further Details
3661
===============
3662
3663
The matrix Q is represented as a product of elementary reflectors
3664
3665
Q = H(1) H(2) . . . H(k), where k = min(m,n).
3666
3667
Each H(i) has the form
3668
3669
H(i) = I - tau * v * v'
3670
3671
where tau is a complex scalar, and v is a complex vector with
3672
v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
3673
and tau in TAU(i).
3674
3675
=====================================================================
3676
3677
3678
Test the input arguments
3679
*/
3680
3681
/* Parameter adjustments */
3682
a_dim1 = *lda;
3683
a_offset = 1 + a_dim1;
3684
a -= a_offset;
3685
--tau;
3686
--work;
3687
3688
/* Function Body */
3689
*info = 0;
3690
nb = ilaenv_(&c__1, "ZGEQRF", " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)
3691
1);
3692
lwkopt = *n * nb;
3693
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
3694
lquery = *lwork == -1;
3695
if (*m < 0) {
3696
*info = -1;
3697
} else if (*n < 0) {
3698
*info = -2;
3699
} else if (*lda < max(1,*m)) {
3700
*info = -4;
3701
} else if (*lwork < max(1,*n) && ! lquery) {
3702
*info = -7;
3703
}
3704
if (*info != 0) {
3705
i__1 = -(*info);
3706
xerbla_("ZGEQRF", &i__1);
3707
return 0;
3708
} else if (lquery) {
3709
return 0;
3710
}
3711
3712
/* Quick return if possible */
3713
3714
k = min(*m,*n);
3715
if (k == 0) {
3716
work[1].r = 1., work[1].i = 0.;
3717
return 0;
3718
}
3719
3720
nbmin = 2;
3721
nx = 0;
3722
iws = *n;
3723
if (nb > 1 && nb < k) {
3724
3725
/*
3726
Determine when to cross over from blocked to unblocked code.
3727
3728
Computing MAX
3729
*/
3730
i__1 = 0, i__2 = ilaenv_(&c__3, "ZGEQRF", " ", m, n, &c_n1, &c_n1, (
3731
ftnlen)6, (ftnlen)1);
3732
nx = max(i__1,i__2);
3733
if (nx < k) {
3734
3735
/* Determine if workspace is large enough for blocked code. */
3736
3737
ldwork = *n;
3738
iws = ldwork * nb;
3739
if (*lwork < iws) {
3740
3741
/*
3742
Not enough workspace to use optimal NB: reduce NB and
3743
determine the minimum value of NB.
3744
*/
3745
3746
nb = *lwork / ldwork;
3747
/* Computing MAX */
3748
i__1 = 2, i__2 = ilaenv_(&c__2, "ZGEQRF", " ", m, n, &c_n1, &
3749
c_n1, (ftnlen)6, (ftnlen)1);
3750
nbmin = max(i__1,i__2);
3751
}
3752
}
3753
}
3754
3755
if (nb >= nbmin && nb < k && nx < k) {
3756
3757
/* Use blocked code initially */
3758
3759
i__1 = k - nx;
3760
i__2 = nb;
3761
for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
3762
/* Computing MIN */
3763
i__3 = k - i__ + 1;
3764
ib = min(i__3,nb);
3765
3766
/*
3767
Compute the QR factorization of the current block
3768
A(i:m,i:i+ib-1)
3769
*/
3770
3771
i__3 = *m - i__ + 1;
3772
zgeqr2_(&i__3, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
3773
1], &iinfo);
3774
if (i__ + ib <= *n) {
3775
3776
/*
3777
Form the triangular factor of the block reflector
3778
H = H(i) H(i+1) . . . H(i+ib-1)
3779
*/
3780
3781
i__3 = *m - i__ + 1;
3782
zlarft_("Forward", "Columnwise", &i__3, &ib, &a[i__ + i__ *
3783
a_dim1], lda, &tau[i__], &work[1], &ldwork);
3784
3785
/* Apply H' to A(i:m,i+ib:n) from the left */
3786
3787
i__3 = *m - i__ + 1;
3788
i__4 = *n - i__ - ib + 1;
3789
zlarfb_("Left", "Conjugate transpose", "Forward", "Columnwise"
3790
, &i__3, &i__4, &ib, &a[i__ + i__ * a_dim1], lda, &
3791
work[1], &ldwork, &a[i__ + (i__ + ib) * a_dim1], lda,
3792
&work[ib + 1], &ldwork);
3793
}
3794
/* L10: */
3795
}
3796
} else {
3797
i__ = 1;
3798
}
3799
3800
/* Use unblocked code to factor the last or only block. */
3801
3802
if (i__ <= k) {
3803
i__2 = *m - i__ + 1;
3804
i__1 = *n - i__ + 1;
3805
zgeqr2_(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[1]
3806
, &iinfo);
3807
}
3808
3809
work[1].r = (doublereal) iws, work[1].i = 0.;
3810
return 0;
3811
3812
/* End of ZGEQRF */
3813
3814
} /* zgeqrf_ */
3815
3816
/* Subroutine */ int zgesdd_(char *jobz, integer *m, integer *n,
3817
doublecomplex *a, integer *lda, doublereal *s, doublecomplex *u,
3818
integer *ldu, doublecomplex *vt, integer *ldvt, doublecomplex *work,
3819
integer *lwork, doublereal *rwork, integer *iwork, integer *info)
3820
{
3821
/* System generated locals */
3822
integer a_dim1, a_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1,
3823
i__2, i__3;
3824
3825
/* Local variables */
3826
static integer i__, ie, il, ir, iu, blk;
3827
static doublereal dum[1], eps;
3828
static integer iru, ivt, iscl;
3829
static doublereal anrm;
3830
static integer idum[1], ierr, itau, irvt;
3831
extern logical lsame_(char *, char *);
3832
static integer chunk, minmn;
3833
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
3834
integer *, doublecomplex *, doublecomplex *, integer *,
3835
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
3836
integer *);
3837
static integer wrkbl, itaup, itauq;
3838
static logical wntqa;
3839
static integer nwork;
3840
static logical wntqn, wntqo, wntqs;
3841
extern /* Subroutine */ int zlacp2_(char *, integer *, integer *,
3842
doublereal *, integer *, doublecomplex *, integer *);
3843
static integer mnthr1, mnthr2;
3844
extern /* Subroutine */ int dbdsdc_(char *, char *, integer *, doublereal
3845
*, doublereal *, doublereal *, integer *, doublereal *, integer *,
3846
doublereal *, integer *, doublereal *, integer *, integer *);
3847
3848
extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
3849
doublereal *, doublereal *, integer *, integer *, doublereal *,
3850
integer *, integer *), xerbla_(char *, integer *),
3851
zgebrd_(integer *, integer *, doublecomplex *, integer *,
3852
doublereal *, doublereal *, doublecomplex *, doublecomplex *,
3853
doublecomplex *, integer *, integer *);
3854
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
3855
integer *, integer *, ftnlen, ftnlen);
3856
static doublereal bignum;
3857
extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
3858
integer *, doublereal *);
3859
extern /* Subroutine */ int zgelqf_(integer *, integer *, doublecomplex *,
3860
integer *, doublecomplex *, doublecomplex *, integer *, integer *
3861
), zlacrm_(integer *, integer *, doublecomplex *, integer *,
3862
doublereal *, integer *, doublecomplex *, integer *, doublereal *)
3863
, zlarcm_(integer *, integer *, doublereal *, integer *,
3864
doublecomplex *, integer *, doublecomplex *, integer *,
3865
doublereal *), zlascl_(char *, integer *, integer *, doublereal *,
3866
doublereal *, integer *, integer *, doublecomplex *, integer *,
3867
integer *), zgeqrf_(integer *, integer *, doublecomplex *,
3868
integer *, doublecomplex *, doublecomplex *, integer *, integer *
3869
);
3870
static integer ldwrkl;
3871
extern /* Subroutine */ int zlacpy_(char *, integer *, integer *,
3872
doublecomplex *, integer *, doublecomplex *, integer *),
3873
zlaset_(char *, integer *, integer *, doublecomplex *,
3874
doublecomplex *, doublecomplex *, integer *);
3875
static integer ldwrkr, minwrk, ldwrku, maxwrk;
3876
extern /* Subroutine */ int zungbr_(char *, integer *, integer *, integer
3877
*, doublecomplex *, integer *, doublecomplex *, doublecomplex *,
3878
integer *, integer *);
3879
static integer ldwkvt;
3880
static doublereal smlnum;
3881
static logical wntqas;
3882
extern /* Subroutine */ int zunmbr_(char *, char *, char *, integer *,
3883
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
3884
doublecomplex *, integer *, doublecomplex *, integer *, integer *
3885
), zunglq_(integer *, integer *, integer *
3886
, doublecomplex *, integer *, doublecomplex *, doublecomplex *,
3887
integer *, integer *);
3888
static integer nrwork;
3889
extern /* Subroutine */ int zungqr_(integer *, integer *, integer *,
3890
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
3891
integer *, integer *);
3892
3893
3894
/*
3895
-- LAPACK driver routine (version 3.2.2) --
3896
-- LAPACK is a software package provided by Univ. of Tennessee, --
3897
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
3898
June 2010
3899
8-15-00: Improve consistency of WS calculations (eca)
3900
3901
3902
Purpose
3903
=======
3904
3905
ZGESDD computes the singular value decomposition (SVD) of a complex
3906
M-by-N matrix A, optionally computing the left and/or right singular
3907
vectors, by using divide-and-conquer method. The SVD is written
3908
3909
A = U * SIGMA * conjugate-transpose(V)
3910
3911
where SIGMA is an M-by-N matrix which is zero except for its
3912
min(m,n) diagonal elements, U is an M-by-M unitary matrix, and
3913
V is an N-by-N unitary matrix. The diagonal elements of SIGMA
3914
are the singular values of A; they are real and non-negative, and
3915
are returned in descending order. The first min(m,n) columns of
3916
U and V are the left and right singular vectors of A.
3917
3918
Note that the routine returns VT = V**H, not V.
3919
3920
The divide and conquer algorithm makes very mild assumptions about
3921
floating point arithmetic. It will work on machines with a guard
3922
digit in add/subtract, or on those binary machines without guard
3923
digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
3924
Cray-2. It could conceivably fail on hexadecimal or decimal machines
3925
without guard digits, but we know of none.
3926
3927
Arguments
3928
=========
3929
3930
JOBZ (input) CHARACTER*1
3931
Specifies options for computing all or part of the matrix U:
3932
= 'A': all M columns of U and all N rows of V**H are
3933
returned in the arrays U and VT;
3934
= 'S': the first min(M,N) columns of U and the first
3935
min(M,N) rows of V**H are returned in the arrays U
3936
and VT;
3937
= 'O': If M >= N, the first N columns of U are overwritten
3938
in the array A and all rows of V**H are returned in
3939
the array VT;
3940
otherwise, all columns of U are returned in the
3941
array U and the first M rows of V**H are overwritten
3942
in the array A;
3943
= 'N': no columns of U or rows of V**H are computed.
3944
3945
M (input) INTEGER
3946
The number of rows of the input matrix A. M >= 0.
3947
3948
N (input) INTEGER
3949
The number of columns of the input matrix A. N >= 0.
3950
3951
A (input/output) COMPLEX*16 array, dimension (LDA,N)
3952
On entry, the M-by-N matrix A.
3953
On exit,
3954
if JOBZ = 'O', A is overwritten with the first N columns
3955
of U (the left singular vectors, stored
3956
columnwise) if M >= N;
3957
A is overwritten with the first M rows
3958
of V**H (the right singular vectors, stored
3959
rowwise) otherwise.
3960
if JOBZ .ne. 'O', the contents of A are destroyed.
3961
3962
LDA (input) INTEGER
3963
The leading dimension of the array A. LDA >= max(1,M).
3964
3965
S (output) DOUBLE PRECISION array, dimension (min(M,N))
3966
The singular values of A, sorted so that S(i) >= S(i+1).
3967
3968
U (output) COMPLEX*16 array, dimension (LDU,UCOL)
3969
UCOL = M if JOBZ = 'A' or JOBZ = 'O' and M < N;
3970
UCOL = min(M,N) if JOBZ = 'S'.
3971
If JOBZ = 'A' or JOBZ = 'O' and M < N, U contains the M-by-M
3972
unitary matrix U;
3973
if JOBZ = 'S', U contains the first min(M,N) columns of U
3974
(the left singular vectors, stored columnwise);
3975
if JOBZ = 'O' and M >= N, or JOBZ = 'N', U is not referenced.
3976
3977
LDU (input) INTEGER
3978
The leading dimension of the array U. LDU >= 1; if
3979
JOBZ = 'S' or 'A' or JOBZ = 'O' and M < N, LDU >= M.
3980
3981
VT (output) COMPLEX*16 array, dimension (LDVT,N)
3982
If JOBZ = 'A' or JOBZ = 'O' and M >= N, VT contains the
3983
N-by-N unitary matrix V**H;
3984
if JOBZ = 'S', VT contains the first min(M,N) rows of
3985
V**H (the right singular vectors, stored rowwise);
3986
if JOBZ = 'O' and M < N, or JOBZ = 'N', VT is not referenced.
3987
3988
LDVT (input) INTEGER
3989
The leading dimension of the array VT. LDVT >= 1; if
3990
JOBZ = 'A' or JOBZ = 'O' and M >= N, LDVT >= N;
3991
if JOBZ = 'S', LDVT >= min(M,N).
3992
3993
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
3994
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
3995
3996
LWORK (input) INTEGER
3997
The dimension of the array WORK. LWORK >= 1.
3998
if JOBZ = 'N', LWORK >= 2*min(M,N)+max(M,N).
3999
if JOBZ = 'O',
4000
LWORK >= 2*min(M,N)*min(M,N)+2*min(M,N)+max(M,N).
4001
if JOBZ = 'S' or 'A',
4002
LWORK >= min(M,N)*min(M,N)+2*min(M,N)+max(M,N).
4003
For good performance, LWORK should generally be larger.
4004
4005
If LWORK = -1, a workspace query is assumed. The optimal
4006
size for the WORK array is calculated and stored in WORK(1),
4007
and no other work except argument checking is performed.
4008
4009
RWORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LRWORK))
4010
If JOBZ = 'N', LRWORK >= 5*min(M,N).
4011
Otherwise,
4012
LRWORK >= min(M,N)*max(5*min(M,N)+7,2*max(M,N)+2*min(M,N)+1)
4013
4014
IWORK (workspace) INTEGER array, dimension (8*min(M,N))
4015
4016
INFO (output) INTEGER
4017
= 0: successful exit.
4018
< 0: if INFO = -i, the i-th argument had an illegal value.
4019
> 0: The updating process of DBDSDC did not converge.
4020
4021
Further Details
4022
===============
4023
4024
Based on contributions by
4025
Ming Gu and Huan Ren, Computer Science Division, University of
4026
California at Berkeley, USA
4027
4028
=====================================================================
4029
4030
4031
Test the input arguments
4032
*/
4033
4034
/* Parameter adjustments */
4035
a_dim1 = *lda;
4036
a_offset = 1 + a_dim1;
4037
a -= a_offset;
4038
--s;
4039
u_dim1 = *ldu;
4040
u_offset = 1 + u_dim1;
4041
u -= u_offset;
4042
vt_dim1 = *ldvt;
4043
vt_offset = 1 + vt_dim1;
4044
vt -= vt_offset;
4045
--work;
4046
--rwork;
4047
--iwork;
4048
4049
/* Function Body */
4050
*info = 0;
4051
minmn = min(*m,*n);
4052
mnthr1 = (integer) (minmn * 17. / 9.);
4053
mnthr2 = (integer) (minmn * 5. / 3.);
4054
wntqa = lsame_(jobz, "A");
4055
wntqs = lsame_(jobz, "S");
4056
wntqas = wntqa || wntqs;
4057
wntqo = lsame_(jobz, "O");
4058
wntqn = lsame_(jobz, "N");
4059
minwrk = 1;
4060
maxwrk = 1;
4061
4062
if (! (wntqa || wntqs || wntqo || wntqn)) {
4063
*info = -1;
4064
} else if (*m < 0) {
4065
*info = -2;
4066
} else if (*n < 0) {
4067
*info = -3;
4068
} else if (*lda < max(1,*m)) {
4069
*info = -5;
4070
} else if (*ldu < 1 || wntqas && *ldu < *m || wntqo && *m < *n && *ldu < *
4071
m) {
4072
*info = -8;
4073
} else if (*ldvt < 1 || wntqa && *ldvt < *n || wntqs && *ldvt < minmn ||
4074
wntqo && *m >= *n && *ldvt < *n) {
4075
*info = -10;
4076
}
4077
4078
/*
4079
Compute workspace
4080
(Note: Comments in the code beginning "Workspace:" describe the
4081
minimal amount of workspace needed at that point in the code,
4082
as well as the preferred amount for good performance.
4083
CWorkspace refers to complex workspace, and RWorkspace to
4084
real workspace. NB refers to the optimal block size for the
4085
immediately following subroutine, as returned by ILAENV.)
4086
*/
4087
4088
if (*info == 0 && *m > 0 && *n > 0) {
4089
if (*m >= *n) {
4090
4091
/*
4092
There is no complex work space needed for bidiagonal SVD
4093
The real work space needed for bidiagonal SVD is BDSPAC
4094
for computing singular values and singular vectors; BDSPAN
4095
for computing singular values only.
4096
BDSPAC = 5*N*N + 7*N
4097
BDSPAN = MAX(7*N+4, 3*N+2+SMLSIZ*(SMLSIZ+8))
4098
*/
4099
4100
if (*m >= mnthr1) {
4101
if (wntqn) {
4102
4103
/* Path 1 (M much larger than N, JOBZ='N') */
4104
4105
maxwrk = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", m, n, &
4106
c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4107
/* Computing MAX */
4108
i__1 = maxwrk, i__2 = (*n << 1) + (*n << 1) * ilaenv_(&
4109
c__1, "ZGEBRD", " ", n, n, &c_n1, &c_n1, (ftnlen)
4110
6, (ftnlen)1);
4111
maxwrk = max(i__1,i__2);
4112
minwrk = *n * 3;
4113
} else if (wntqo) {
4114
4115
/* Path 2 (M much larger than N, JOBZ='O') */
4116
4117
wrkbl = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", m, n, &
4118
c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4119
/* Computing MAX */
4120
i__1 = wrkbl, i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR",
4121
" ", m, n, n, &c_n1, (ftnlen)6, (ftnlen)1);
4122
wrkbl = max(i__1,i__2);
4123
/* Computing MAX */
4124
i__1 = wrkbl, i__2 = (*n << 1) + (*n << 1) * ilaenv_(&
4125
c__1, "ZGEBRD", " ", n, n, &c_n1, &c_n1, (ftnlen)
4126
6, (ftnlen)1);
4127
wrkbl = max(i__1,i__2);
4128
/* Computing MAX */
4129
i__1 = wrkbl, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4130
"ZUNMBR", "QLN", n, n, n, &c_n1, (ftnlen)6, (
4131
ftnlen)3);
4132
wrkbl = max(i__1,i__2);
4133
/* Computing MAX */
4134
i__1 = wrkbl, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4135
"ZUNMBR", "PRC", n, n, n, &c_n1, (ftnlen)6, (
4136
ftnlen)3);
4137
wrkbl = max(i__1,i__2);
4138
maxwrk = *m * *n + *n * *n + wrkbl;
4139
minwrk = (*n << 1) * *n + *n * 3;
4140
} else if (wntqs) {
4141
4142
/* Path 3 (M much larger than N, JOBZ='S') */
4143
4144
wrkbl = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", m, n, &
4145
c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4146
/* Computing MAX */
4147
i__1 = wrkbl, i__2 = *n + *n * ilaenv_(&c__1, "ZUNGQR",
4148
" ", m, n, n, &c_n1, (ftnlen)6, (ftnlen)1);
4149
wrkbl = max(i__1,i__2);
4150
/* Computing MAX */
4151
i__1 = wrkbl, i__2 = (*n << 1) + (*n << 1) * ilaenv_(&
4152
c__1, "ZGEBRD", " ", n, n, &c_n1, &c_n1, (ftnlen)
4153
6, (ftnlen)1);
4154
wrkbl = max(i__1,i__2);
4155
/* Computing MAX */
4156
i__1 = wrkbl, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4157
"ZUNMBR", "QLN", n, n, n, &c_n1, (ftnlen)6, (
4158
ftnlen)3);
4159
wrkbl = max(i__1,i__2);
4160
/* Computing MAX */
4161
i__1 = wrkbl, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4162
"ZUNMBR", "PRC", n, n, n, &c_n1, (ftnlen)6, (
4163
ftnlen)3);
4164
wrkbl = max(i__1,i__2);
4165
maxwrk = *n * *n + wrkbl;
4166
minwrk = *n * *n + *n * 3;
4167
} else if (wntqa) {
4168
4169
/* Path 4 (M much larger than N, JOBZ='A') */
4170
4171
wrkbl = *n + *n * ilaenv_(&c__1, "ZGEQRF", " ", m, n, &
4172
c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4173
/* Computing MAX */
4174
i__1 = wrkbl, i__2 = *n + *m * ilaenv_(&c__1, "ZUNGQR",
4175
" ", m, m, n, &c_n1, (ftnlen)6, (ftnlen)1);
4176
wrkbl = max(i__1,i__2);
4177
/* Computing MAX */
4178
i__1 = wrkbl, i__2 = (*n << 1) + (*n << 1) * ilaenv_(&
4179
c__1, "ZGEBRD", " ", n, n, &c_n1, &c_n1, (ftnlen)
4180
6, (ftnlen)1);
4181
wrkbl = max(i__1,i__2);
4182
/* Computing MAX */
4183
i__1 = wrkbl, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4184
"ZUNMBR", "QLN", n, n, n, &c_n1, (ftnlen)6, (
4185
ftnlen)3);
4186
wrkbl = max(i__1,i__2);
4187
/* Computing MAX */
4188
i__1 = wrkbl, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4189
"ZUNMBR", "PRC", n, n, n, &c_n1, (ftnlen)6, (
4190
ftnlen)3);
4191
wrkbl = max(i__1,i__2);
4192
maxwrk = *n * *n + wrkbl;
4193
minwrk = *n * *n + (*n << 1) + *m;
4194
}
4195
} else if (*m >= mnthr2) {
4196
4197
/* Path 5 (M much larger than N, but not as much as MNTHR1) */
4198
4199
maxwrk = (*n << 1) + (*m + *n) * ilaenv_(&c__1, "ZGEBRD",
4200
" ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4201
minwrk = (*n << 1) + *m;
4202
if (wntqo) {
4203
/* Computing MAX */
4204
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4205
"ZUNGBR", "P", n, n, n, &c_n1, (ftnlen)6, (ftnlen)
4206
1);
4207
maxwrk = max(i__1,i__2);
4208
/* Computing MAX */
4209
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4210
"ZUNGBR", "Q", m, n, n, &c_n1, (ftnlen)6, (ftnlen)
4211
1);
4212
maxwrk = max(i__1,i__2);
4213
maxwrk += *m * *n;
4214
minwrk += *n * *n;
4215
} else if (wntqs) {
4216
/* Computing MAX */
4217
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4218
"ZUNGBR", "P", n, n, n, &c_n1, (ftnlen)6, (ftnlen)
4219
1);
4220
maxwrk = max(i__1,i__2);
4221
/* Computing MAX */
4222
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4223
"ZUNGBR", "Q", m, n, n, &c_n1, (ftnlen)6, (ftnlen)
4224
1);
4225
maxwrk = max(i__1,i__2);
4226
} else if (wntqa) {
4227
/* Computing MAX */
4228
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4229
"ZUNGBR", "P", n, n, n, &c_n1, (ftnlen)6, (ftnlen)
4230
1);
4231
maxwrk = max(i__1,i__2);
4232
/* Computing MAX */
4233
i__1 = maxwrk, i__2 = (*n << 1) + *m * ilaenv_(&c__1,
4234
"ZUNGBR", "Q", m, m, n, &c_n1, (ftnlen)6, (ftnlen)
4235
1);
4236
maxwrk = max(i__1,i__2);
4237
}
4238
} else {
4239
4240
/* Path 6 (M at least N, but not much larger) */
4241
4242
maxwrk = (*n << 1) + (*m + *n) * ilaenv_(&c__1, "ZGEBRD",
4243
" ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4244
minwrk = (*n << 1) + *m;
4245
if (wntqo) {
4246
/* Computing MAX */
4247
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4248
"ZUNMBR", "PRC", n, n, n, &c_n1, (ftnlen)6, (
4249
ftnlen)3);
4250
maxwrk = max(i__1,i__2);
4251
/* Computing MAX */
4252
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4253
"ZUNMBR", "QLN", m, n, n, &c_n1, (ftnlen)6, (
4254
ftnlen)3);
4255
maxwrk = max(i__1,i__2);
4256
maxwrk += *m * *n;
4257
minwrk += *n * *n;
4258
} else if (wntqs) {
4259
/* Computing MAX */
4260
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4261
"ZUNMBR", "PRC", n, n, n, &c_n1, (ftnlen)6, (
4262
ftnlen)3);
4263
maxwrk = max(i__1,i__2);
4264
/* Computing MAX */
4265
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4266
"ZUNMBR", "QLN", m, n, n, &c_n1, (ftnlen)6, (
4267
ftnlen)3);
4268
maxwrk = max(i__1,i__2);
4269
} else if (wntqa) {
4270
/* Computing MAX */
4271
i__1 = maxwrk, i__2 = (*n << 1) + *n * ilaenv_(&c__1,
4272
"ZUNGBR", "PRC", n, n, n, &c_n1, (ftnlen)6, (
4273
ftnlen)3);
4274
maxwrk = max(i__1,i__2);
4275
/* Computing MAX */
4276
i__1 = maxwrk, i__2 = (*n << 1) + *m * ilaenv_(&c__1,
4277
"ZUNGBR", "QLN", m, m, n, &c_n1, (ftnlen)6, (
4278
ftnlen)3);
4279
maxwrk = max(i__1,i__2);
4280
}
4281
}
4282
} else {
4283
4284
/*
4285
There is no complex work space needed for bidiagonal SVD
4286
The real work space needed for bidiagonal SVD is BDSPAC
4287
for computing singular values and singular vectors; BDSPAN
4288
for computing singular values only.
4289
BDSPAC = 5*M*M + 7*M
4290
BDSPAN = MAX(7*M+4, 3*M+2+SMLSIZ*(SMLSIZ+8))
4291
*/
4292
4293
if (*n >= mnthr1) {
4294
if (wntqn) {
4295
4296
/* Path 1t (N much larger than M, JOBZ='N') */
4297
4298
maxwrk = *m + *m * ilaenv_(&c__1, "ZGELQF", " ", m, n, &
4299
c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4300
/* Computing MAX */
4301
i__1 = maxwrk, i__2 = (*m << 1) + (*m << 1) * ilaenv_(&
4302
c__1, "ZGEBRD", " ", m, m, &c_n1, &c_n1, (ftnlen)
4303
6, (ftnlen)1);
4304
maxwrk = max(i__1,i__2);
4305
minwrk = *m * 3;
4306
} else if (wntqo) {
4307
4308
/* Path 2t (N much larger than M, JOBZ='O') */
4309
4310
wrkbl = *m + *m * ilaenv_(&c__1, "ZGELQF", " ", m, n, &
4311
c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4312
/* Computing MAX */
4313
i__1 = wrkbl, i__2 = *m + *m * ilaenv_(&c__1, "ZUNGLQ",
4314
" ", m, n, m, &c_n1, (ftnlen)6, (ftnlen)1);
4315
wrkbl = max(i__1,i__2);
4316
/* Computing MAX */
4317
i__1 = wrkbl, i__2 = (*m << 1) + (*m << 1) * ilaenv_(&
4318
c__1, "ZGEBRD", " ", m, m, &c_n1, &c_n1, (ftnlen)
4319
6, (ftnlen)1);
4320
wrkbl = max(i__1,i__2);
4321
/* Computing MAX */
4322
i__1 = wrkbl, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4323
"ZUNMBR", "PRC", m, m, m, &c_n1, (ftnlen)6, (
4324
ftnlen)3);
4325
wrkbl = max(i__1,i__2);
4326
/* Computing MAX */
4327
i__1 = wrkbl, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4328
"ZUNMBR", "QLN", m, m, m, &c_n1, (ftnlen)6, (
4329
ftnlen)3);
4330
wrkbl = max(i__1,i__2);
4331
maxwrk = *m * *n + *m * *m + wrkbl;
4332
minwrk = (*m << 1) * *m + *m * 3;
4333
} else if (wntqs) {
4334
4335
/* Path 3t (N much larger than M, JOBZ='S') */
4336
4337
wrkbl = *m + *m * ilaenv_(&c__1, "ZGELQF", " ", m, n, &
4338
c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4339
/* Computing MAX */
4340
i__1 = wrkbl, i__2 = *m + *m * ilaenv_(&c__1, "ZUNGLQ",
4341
" ", m, n, m, &c_n1, (ftnlen)6, (ftnlen)1);
4342
wrkbl = max(i__1,i__2);
4343
/* Computing MAX */
4344
i__1 = wrkbl, i__2 = (*m << 1) + (*m << 1) * ilaenv_(&
4345
c__1, "ZGEBRD", " ", m, m, &c_n1, &c_n1, (ftnlen)
4346
6, (ftnlen)1);
4347
wrkbl = max(i__1,i__2);
4348
/* Computing MAX */
4349
i__1 = wrkbl, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4350
"ZUNMBR", "PRC", m, m, m, &c_n1, (ftnlen)6, (
4351
ftnlen)3);
4352
wrkbl = max(i__1,i__2);
4353
/* Computing MAX */
4354
i__1 = wrkbl, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4355
"ZUNMBR", "QLN", m, m, m, &c_n1, (ftnlen)6, (
4356
ftnlen)3);
4357
wrkbl = max(i__1,i__2);
4358
maxwrk = *m * *m + wrkbl;
4359
minwrk = *m * *m + *m * 3;
4360
} else if (wntqa) {
4361
4362
/* Path 4t (N much larger than M, JOBZ='A') */
4363
4364
wrkbl = *m + *m * ilaenv_(&c__1, "ZGELQF", " ", m, n, &
4365
c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4366
/* Computing MAX */
4367
i__1 = wrkbl, i__2 = *m + *n * ilaenv_(&c__1, "ZUNGLQ",
4368
" ", n, n, m, &c_n1, (ftnlen)6, (ftnlen)1);
4369
wrkbl = max(i__1,i__2);
4370
/* Computing MAX */
4371
i__1 = wrkbl, i__2 = (*m << 1) + (*m << 1) * ilaenv_(&
4372
c__1, "ZGEBRD", " ", m, m, &c_n1, &c_n1, (ftnlen)
4373
6, (ftnlen)1);
4374
wrkbl = max(i__1,i__2);
4375
/* Computing MAX */
4376
i__1 = wrkbl, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4377
"ZUNMBR", "PRC", m, m, m, &c_n1, (ftnlen)6, (
4378
ftnlen)3);
4379
wrkbl = max(i__1,i__2);
4380
/* Computing MAX */
4381
i__1 = wrkbl, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4382
"ZUNMBR", "QLN", m, m, m, &c_n1, (ftnlen)6, (
4383
ftnlen)3);
4384
wrkbl = max(i__1,i__2);
4385
maxwrk = *m * *m + wrkbl;
4386
minwrk = *m * *m + (*m << 1) + *n;
4387
}
4388
} else if (*n >= mnthr2) {
4389
4390
/* Path 5t (N much larger than M, but not as much as MNTHR1) */
4391
4392
maxwrk = (*m << 1) + (*m + *n) * ilaenv_(&c__1, "ZGEBRD",
4393
" ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4394
minwrk = (*m << 1) + *n;
4395
if (wntqo) {
4396
/* Computing MAX */
4397
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4398
"ZUNGBR", "P", m, n, m, &c_n1, (ftnlen)6, (ftnlen)
4399
1);
4400
maxwrk = max(i__1,i__2);
4401
/* Computing MAX */
4402
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4403
"ZUNGBR", "Q", m, m, n, &c_n1, (ftnlen)6, (ftnlen)
4404
1);
4405
maxwrk = max(i__1,i__2);
4406
maxwrk += *m * *n;
4407
minwrk += *m * *m;
4408
} else if (wntqs) {
4409
/* Computing MAX */
4410
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4411
"ZUNGBR", "P", m, n, m, &c_n1, (ftnlen)6, (ftnlen)
4412
1);
4413
maxwrk = max(i__1,i__2);
4414
/* Computing MAX */
4415
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4416
"ZUNGBR", "Q", m, m, n, &c_n1, (ftnlen)6, (ftnlen)
4417
1);
4418
maxwrk = max(i__1,i__2);
4419
} else if (wntqa) {
4420
/* Computing MAX */
4421
i__1 = maxwrk, i__2 = (*m << 1) + *n * ilaenv_(&c__1,
4422
"ZUNGBR", "P", n, n, m, &c_n1, (ftnlen)6, (ftnlen)
4423
1);
4424
maxwrk = max(i__1,i__2);
4425
/* Computing MAX */
4426
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4427
"ZUNGBR", "Q", m, m, n, &c_n1, (ftnlen)6, (ftnlen)
4428
1);
4429
maxwrk = max(i__1,i__2);
4430
}
4431
} else {
4432
4433
/* Path 6t (N greater than M, but not much larger) */
4434
4435
maxwrk = (*m << 1) + (*m + *n) * ilaenv_(&c__1, "ZGEBRD",
4436
" ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
4437
minwrk = (*m << 1) + *n;
4438
if (wntqo) {
4439
/* Computing MAX */
4440
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4441
"ZUNMBR", "PRC", m, n, m, &c_n1, (ftnlen)6, (
4442
ftnlen)3);
4443
maxwrk = max(i__1,i__2);
4444
/* Computing MAX */
4445
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4446
"ZUNMBR", "QLN", m, m, n, &c_n1, (ftnlen)6, (
4447
ftnlen)3);
4448
maxwrk = max(i__1,i__2);
4449
maxwrk += *m * *n;
4450
minwrk += *m * *m;
4451
} else if (wntqs) {
4452
/* Computing MAX */
4453
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4454
"ZUNGBR", "PRC", m, n, m, &c_n1, (ftnlen)6, (
4455
ftnlen)3);
4456
maxwrk = max(i__1,i__2);
4457
/* Computing MAX */
4458
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4459
"ZUNGBR", "QLN", m, m, n, &c_n1, (ftnlen)6, (
4460
ftnlen)3);
4461
maxwrk = max(i__1,i__2);
4462
} else if (wntqa) {
4463
/* Computing MAX */
4464
i__1 = maxwrk, i__2 = (*m << 1) + *n * ilaenv_(&c__1,
4465
"ZUNGBR", "PRC", n, n, m, &c_n1, (ftnlen)6, (
4466
ftnlen)3);
4467
maxwrk = max(i__1,i__2);
4468
/* Computing MAX */
4469
i__1 = maxwrk, i__2 = (*m << 1) + *m * ilaenv_(&c__1,
4470
"ZUNGBR", "QLN", m, m, n, &c_n1, (ftnlen)6, (
4471
ftnlen)3);
4472
maxwrk = max(i__1,i__2);
4473
}
4474
}
4475
}
4476
maxwrk = max(maxwrk,minwrk);
4477
}
4478
if (*info == 0) {
4479
work[1].r = (doublereal) maxwrk, work[1].i = 0.;
4480
if (*lwork < minwrk && *lwork != -1) {
4481
*info = -13;
4482
}
4483
}
4484
4485
/* Quick returns */
4486
4487
if (*info != 0) {
4488
i__1 = -(*info);
4489
xerbla_("ZGESDD", &i__1);
4490
return 0;
4491
}
4492
if (*lwork == -1) {
4493
return 0;
4494
}
4495
if (*m == 0 || *n == 0) {
4496
return 0;
4497
}
4498
4499
/* Get machine constants */
4500
4501
eps = PRECISION;
4502
smlnum = sqrt(SAFEMINIMUM) / eps;
4503
bignum = 1. / smlnum;
4504
4505
/* Scale A if max element outside range [SMLNUM,BIGNUM] */
4506
4507
anrm = zlange_("M", m, n, &a[a_offset], lda, dum);
4508
iscl = 0;
4509
if (anrm > 0. && anrm < smlnum) {
4510
iscl = 1;
4511
zlascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda, &
4512
ierr);
4513
} else if (anrm > bignum) {
4514
iscl = 1;
4515
zlascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda, &
4516
ierr);
4517
}
4518
4519
if (*m >= *n) {
4520
4521
/*
4522
A has at least as many rows as columns. If A has sufficiently
4523
more rows than columns, first reduce using the QR
4524
decomposition (if sufficient workspace available)
4525
*/
4526
4527
if (*m >= mnthr1) {
4528
4529
if (wntqn) {
4530
4531
/*
4532
Path 1 (M much larger than N, JOBZ='N')
4533
No singular vectors to be computed
4534
*/
4535
4536
itau = 1;
4537
nwork = itau + *n;
4538
4539
/*
4540
Compute A=Q*R
4541
(CWorkspace: need 2*N, prefer N+N*NB)
4542
(RWorkspace: need 0)
4543
*/
4544
4545
i__1 = *lwork - nwork + 1;
4546
zgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
4547
i__1, &ierr);
4548
4549
/* Zero out below R */
4550
4551
i__1 = *n - 1;
4552
i__2 = *n - 1;
4553
zlaset_("L", &i__1, &i__2, &c_b56, &c_b56, &a[a_dim1 + 2],
4554
lda);
4555
ie = 1;
4556
itauq = 1;
4557
itaup = itauq + *n;
4558
nwork = itaup + *n;
4559
4560
/*
4561
Bidiagonalize R in A
4562
(CWorkspace: need 3*N, prefer 2*N+2*N*NB)
4563
(RWorkspace: need N)
4564
*/
4565
4566
i__1 = *lwork - nwork + 1;
4567
zgebrd_(n, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[
4568
itauq], &work[itaup], &work[nwork], &i__1, &ierr);
4569
nrwork = ie + *n;
4570
4571
/*
4572
Perform bidiagonal SVD, compute singular values only
4573
(CWorkspace: 0)
4574
(RWorkspace: need BDSPAN)
4575
*/
4576
4577
dbdsdc_("U", "N", n, &s[1], &rwork[ie], dum, &c__1, dum, &
4578
c__1, dum, idum, &rwork[nrwork], &iwork[1], info);
4579
4580
} else if (wntqo) {
4581
4582
/*
4583
Path 2 (M much larger than N, JOBZ='O')
4584
N left singular vectors to be overwritten on A and
4585
N right singular vectors to be computed in VT
4586
*/
4587
4588
iu = 1;
4589
4590
/* WORK(IU) is N by N */
4591
4592
ldwrku = *n;
4593
ir = iu + ldwrku * *n;
4594
if (*lwork >= *m * *n + *n * *n + *n * 3) {
4595
4596
/* WORK(IR) is M by N */
4597
4598
ldwrkr = *m;
4599
} else {
4600
ldwrkr = (*lwork - *n * *n - *n * 3) / *n;
4601
}
4602
itau = ir + ldwrkr * *n;
4603
nwork = itau + *n;
4604
4605
/*
4606
Compute A=Q*R
4607
(CWorkspace: need N*N+2*N, prefer M*N+N+N*NB)
4608
(RWorkspace: 0)
4609
*/
4610
4611
i__1 = *lwork - nwork + 1;
4612
zgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
4613
i__1, &ierr);
4614
4615
/* Copy R to WORK( IR ), zeroing out below it */
4616
4617
zlacpy_("U", n, n, &a[a_offset], lda, &work[ir], &ldwrkr);
4618
i__1 = *n - 1;
4619
i__2 = *n - 1;
4620
zlaset_("L", &i__1, &i__2, &c_b56, &c_b56, &work[ir + 1], &
4621
ldwrkr);
4622
4623
/*
4624
Generate Q in A
4625
(CWorkspace: need 2*N, prefer N+N*NB)
4626
(RWorkspace: 0)
4627
*/
4628
4629
i__1 = *lwork - nwork + 1;
4630
zungqr_(m, n, n, &a[a_offset], lda, &work[itau], &work[nwork],
4631
&i__1, &ierr);
4632
ie = 1;
4633
itauq = itau;
4634
itaup = itauq + *n;
4635
nwork = itaup + *n;
4636
4637
/*
4638
Bidiagonalize R in WORK(IR)
4639
(CWorkspace: need N*N+3*N, prefer M*N+2*N+2*N*NB)
4640
(RWorkspace: need N)
4641
*/
4642
4643
i__1 = *lwork - nwork + 1;
4644
zgebrd_(n, n, &work[ir], &ldwrkr, &s[1], &rwork[ie], &work[
4645
itauq], &work[itaup], &work[nwork], &i__1, &ierr);
4646
4647
/*
4648
Perform bidiagonal SVD, computing left singular vectors
4649
of R in WORK(IRU) and computing right singular vectors
4650
of R in WORK(IRVT)
4651
(CWorkspace: need 0)
4652
(RWorkspace: need BDSPAC)
4653
*/
4654
4655
iru = ie + *n;
4656
irvt = iru + *n * *n;
4657
nrwork = irvt + *n * *n;
4658
dbdsdc_("U", "I", n, &s[1], &rwork[ie], &rwork[iru], n, &
4659
rwork[irvt], n, dum, idum, &rwork[nrwork], &iwork[1],
4660
info);
4661
4662
/*
4663
Copy real matrix RWORK(IRU) to complex matrix WORK(IU)
4664
Overwrite WORK(IU) by the left singular vectors of R
4665
(CWorkspace: need 2*N*N+3*N, prefer M*N+N*N+2*N+N*NB)
4666
(RWorkspace: 0)
4667
*/
4668
4669
zlacp2_("F", n, n, &rwork[iru], n, &work[iu], &ldwrku);
4670
i__1 = *lwork - nwork + 1;
4671
zunmbr_("Q", "L", "N", n, n, n, &work[ir], &ldwrkr, &work[
4672
itauq], &work[iu], &ldwrku, &work[nwork], &i__1, &
4673
ierr);
4674
4675
/*
4676
Copy real matrix RWORK(IRVT) to complex matrix VT
4677
Overwrite VT by the right singular vectors of R
4678
(CWorkspace: need N*N+3*N, prefer M*N+2*N+N*NB)
4679
(RWorkspace: 0)
4680
*/
4681
4682
zlacp2_("F", n, n, &rwork[irvt], n, &vt[vt_offset], ldvt);
4683
i__1 = *lwork - nwork + 1;
4684
zunmbr_("P", "R", "C", n, n, n, &work[ir], &ldwrkr, &work[
4685
itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
4686
ierr);
4687
4688
/*
4689
Multiply Q in A by left singular vectors of R in
4690
WORK(IU), storing result in WORK(IR) and copying to A
4691
(CWorkspace: need 2*N*N, prefer N*N+M*N)
4692
(RWorkspace: 0)
4693
*/
4694
4695
i__1 = *m;
4696
i__2 = ldwrkr;
4697
for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
4698
i__2) {
4699
/* Computing MIN */
4700
i__3 = *m - i__ + 1;
4701
chunk = min(i__3,ldwrkr);
4702
zgemm_("N", "N", &chunk, n, n, &c_b57, &a[i__ + a_dim1],
4703
lda, &work[iu], &ldwrku, &c_b56, &work[ir], &
4704
ldwrkr);
4705
zlacpy_("F", &chunk, n, &work[ir], &ldwrkr, &a[i__ +
4706
a_dim1], lda);
4707
/* L10: */
4708
}
4709
4710
} else if (wntqs) {
4711
4712
/*
4713
Path 3 (M much larger than N, JOBZ='S')
4714
N left singular vectors to be computed in U and
4715
N right singular vectors to be computed in VT
4716
*/
4717
4718
ir = 1;
4719
4720
/* WORK(IR) is N by N */
4721
4722
ldwrkr = *n;
4723
itau = ir + ldwrkr * *n;
4724
nwork = itau + *n;
4725
4726
/*
4727
Compute A=Q*R
4728
(CWorkspace: need N*N+2*N, prefer N*N+N+N*NB)
4729
(RWorkspace: 0)
4730
*/
4731
4732
i__2 = *lwork - nwork + 1;
4733
zgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
4734
i__2, &ierr);
4735
4736
/* Copy R to WORK(IR), zeroing out below it */
4737
4738
zlacpy_("U", n, n, &a[a_offset], lda, &work[ir], &ldwrkr);
4739
i__2 = *n - 1;
4740
i__1 = *n - 1;
4741
zlaset_("L", &i__2, &i__1, &c_b56, &c_b56, &work[ir + 1], &
4742
ldwrkr);
4743
4744
/*
4745
Generate Q in A
4746
(CWorkspace: need 2*N, prefer N+N*NB)
4747
(RWorkspace: 0)
4748
*/
4749
4750
i__2 = *lwork - nwork + 1;
4751
zungqr_(m, n, n, &a[a_offset], lda, &work[itau], &work[nwork],
4752
&i__2, &ierr);
4753
ie = 1;
4754
itauq = itau;
4755
itaup = itauq + *n;
4756
nwork = itaup + *n;
4757
4758
/*
4759
Bidiagonalize R in WORK(IR)
4760
(CWorkspace: need N*N+3*N, prefer N*N+2*N+2*N*NB)
4761
(RWorkspace: need N)
4762
*/
4763
4764
i__2 = *lwork - nwork + 1;
4765
zgebrd_(n, n, &work[ir], &ldwrkr, &s[1], &rwork[ie], &work[
4766
itauq], &work[itaup], &work[nwork], &i__2, &ierr);
4767
4768
/*
4769
Perform bidiagonal SVD, computing left singular vectors
4770
of bidiagonal matrix in RWORK(IRU) and computing right
4771
singular vectors of bidiagonal matrix in RWORK(IRVT)
4772
(CWorkspace: need 0)
4773
(RWorkspace: need BDSPAC)
4774
*/
4775
4776
iru = ie + *n;
4777
irvt = iru + *n * *n;
4778
nrwork = irvt + *n * *n;
4779
dbdsdc_("U", "I", n, &s[1], &rwork[ie], &rwork[iru], n, &
4780
rwork[irvt], n, dum, idum, &rwork[nrwork], &iwork[1],
4781
info);
4782
4783
/*
4784
Copy real matrix RWORK(IRU) to complex matrix U
4785
Overwrite U by left singular vectors of R
4786
(CWorkspace: need N*N+3*N, prefer N*N+2*N+N*NB)
4787
(RWorkspace: 0)
4788
*/
4789
4790
zlacp2_("F", n, n, &rwork[iru], n, &u[u_offset], ldu);
4791
i__2 = *lwork - nwork + 1;
4792
zunmbr_("Q", "L", "N", n, n, n, &work[ir], &ldwrkr, &work[
4793
itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
4794
4795
/*
4796
Copy real matrix RWORK(IRVT) to complex matrix VT
4797
Overwrite VT by right singular vectors of R
4798
(CWorkspace: need N*N+3*N, prefer N*N+2*N+N*NB)
4799
(RWorkspace: 0)
4800
*/
4801
4802
zlacp2_("F", n, n, &rwork[irvt], n, &vt[vt_offset], ldvt);
4803
i__2 = *lwork - nwork + 1;
4804
zunmbr_("P", "R", "C", n, n, n, &work[ir], &ldwrkr, &work[
4805
itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
4806
ierr);
4807
4808
/*
4809
Multiply Q in A by left singular vectors of R in
4810
WORK(IR), storing result in U
4811
(CWorkspace: need N*N)
4812
(RWorkspace: 0)
4813
*/
4814
4815
zlacpy_("F", n, n, &u[u_offset], ldu, &work[ir], &ldwrkr);
4816
zgemm_("N", "N", m, n, n, &c_b57, &a[a_offset], lda, &work[ir]
4817
, &ldwrkr, &c_b56, &u[u_offset], ldu);
4818
4819
} else if (wntqa) {
4820
4821
/*
4822
Path 4 (M much larger than N, JOBZ='A')
4823
M left singular vectors to be computed in U and
4824
N right singular vectors to be computed in VT
4825
*/
4826
4827
iu = 1;
4828
4829
/* WORK(IU) is N by N */
4830
4831
ldwrku = *n;
4832
itau = iu + ldwrku * *n;
4833
nwork = itau + *n;
4834
4835
/*
4836
Compute A=Q*R, copying result to U
4837
(CWorkspace: need 2*N, prefer N+N*NB)
4838
(RWorkspace: 0)
4839
*/
4840
4841
i__2 = *lwork - nwork + 1;
4842
zgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
4843
i__2, &ierr);
4844
zlacpy_("L", m, n, &a[a_offset], lda, &u[u_offset], ldu);
4845
4846
/*
4847
Generate Q in U
4848
(CWorkspace: need N+M, prefer N+M*NB)
4849
(RWorkspace: 0)
4850
*/
4851
4852
i__2 = *lwork - nwork + 1;
4853
zungqr_(m, m, n, &u[u_offset], ldu, &work[itau], &work[nwork],
4854
&i__2, &ierr);
4855
4856
/* Produce R in A, zeroing out below it */
4857
4858
i__2 = *n - 1;
4859
i__1 = *n - 1;
4860
zlaset_("L", &i__2, &i__1, &c_b56, &c_b56, &a[a_dim1 + 2],
4861
lda);
4862
ie = 1;
4863
itauq = itau;
4864
itaup = itauq + *n;
4865
nwork = itaup + *n;
4866
4867
/*
4868
Bidiagonalize R in A
4869
(CWorkspace: need 3*N, prefer 2*N+2*N*NB)
4870
(RWorkspace: need N)
4871
*/
4872
4873
i__2 = *lwork - nwork + 1;
4874
zgebrd_(n, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[
4875
itauq], &work[itaup], &work[nwork], &i__2, &ierr);
4876
iru = ie + *n;
4877
irvt = iru + *n * *n;
4878
nrwork = irvt + *n * *n;
4879
4880
/*
4881
Perform bidiagonal SVD, computing left singular vectors
4882
of bidiagonal matrix in RWORK(IRU) and computing right
4883
singular vectors of bidiagonal matrix in RWORK(IRVT)
4884
(CWorkspace: need 0)
4885
(RWorkspace: need BDSPAC)
4886
*/
4887
4888
dbdsdc_("U", "I", n, &s[1], &rwork[ie], &rwork[iru], n, &
4889
rwork[irvt], n, dum, idum, &rwork[nrwork], &iwork[1],
4890
info);
4891
4892
/*
4893
Copy real matrix RWORK(IRU) to complex matrix WORK(IU)
4894
Overwrite WORK(IU) by left singular vectors of R
4895
(CWorkspace: need N*N+3*N, prefer N*N+2*N+N*NB)
4896
(RWorkspace: 0)
4897
*/
4898
4899
zlacp2_("F", n, n, &rwork[iru], n, &work[iu], &ldwrku);
4900
i__2 = *lwork - nwork + 1;
4901
zunmbr_("Q", "L", "N", n, n, n, &a[a_offset], lda, &work[
4902
itauq], &work[iu], &ldwrku, &work[nwork], &i__2, &
4903
ierr);
4904
4905
/*
4906
Copy real matrix RWORK(IRVT) to complex matrix VT
4907
Overwrite VT by right singular vectors of R
4908
(CWorkspace: need 3*N, prefer 2*N+N*NB)
4909
(RWorkspace: 0)
4910
*/
4911
4912
zlacp2_("F", n, n, &rwork[irvt], n, &vt[vt_offset], ldvt);
4913
i__2 = *lwork - nwork + 1;
4914
zunmbr_("P", "R", "C", n, n, n, &a[a_offset], lda, &work[
4915
itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
4916
ierr);
4917
4918
/*
4919
Multiply Q in U by left singular vectors of R in
4920
WORK(IU), storing result in A
4921
(CWorkspace: need N*N)
4922
(RWorkspace: 0)
4923
*/
4924
4925
zgemm_("N", "N", m, n, n, &c_b57, &u[u_offset], ldu, &work[iu]
4926
, &ldwrku, &c_b56, &a[a_offset], lda);
4927
4928
/* Copy left singular vectors of A from A to U */
4929
4930
zlacpy_("F", m, n, &a[a_offset], lda, &u[u_offset], ldu);
4931
4932
}
4933
4934
} else if (*m >= mnthr2) {
4935
4936
/*
4937
MNTHR2 <= M < MNTHR1
4938
4939
Path 5 (M much larger than N, but not as much as MNTHR1)
4940
Reduce to bidiagonal form without QR decomposition, use
4941
ZUNGBR and matrix multiplication to compute singular vectors
4942
*/
4943
4944
ie = 1;
4945
nrwork = ie + *n;
4946
itauq = 1;
4947
itaup = itauq + *n;
4948
nwork = itaup + *n;
4949
4950
/*
4951
Bidiagonalize A
4952
(CWorkspace: need 2*N+M, prefer 2*N+(M+N)*NB)
4953
(RWorkspace: need N)
4954
*/
4955
4956
i__2 = *lwork - nwork + 1;
4957
zgebrd_(m, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq],
4958
&work[itaup], &work[nwork], &i__2, &ierr);
4959
if (wntqn) {
4960
4961
/*
4962
Compute singular values only
4963
(Cworkspace: 0)
4964
(Rworkspace: need BDSPAN)
4965
*/
4966
4967
dbdsdc_("U", "N", n, &s[1], &rwork[ie], dum, &c__1, dum, &
4968
c__1, dum, idum, &rwork[nrwork], &iwork[1], info);
4969
} else if (wntqo) {
4970
iu = nwork;
4971
iru = nrwork;
4972
irvt = iru + *n * *n;
4973
nrwork = irvt + *n * *n;
4974
4975
/*
4976
Copy A to VT, generate P**H
4977
(Cworkspace: need 2*N, prefer N+N*NB)
4978
(Rworkspace: 0)
4979
*/
4980
4981
zlacpy_("U", n, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
4982
i__2 = *lwork - nwork + 1;
4983
zungbr_("P", n, n, n, &vt[vt_offset], ldvt, &work[itaup], &
4984
work[nwork], &i__2, &ierr);
4985
4986
/*
4987
Generate Q in A
4988
(CWorkspace: need 2*N, prefer N+N*NB)
4989
(RWorkspace: 0)
4990
*/
4991
4992
i__2 = *lwork - nwork + 1;
4993
zungbr_("Q", m, n, n, &a[a_offset], lda, &work[itauq], &work[
4994
nwork], &i__2, &ierr);
4995
4996
if (*lwork >= *m * *n + *n * 3) {
4997
4998
/* WORK( IU ) is M by N */
4999
5000
ldwrku = *m;
5001
} else {
5002
5003
/* WORK(IU) is LDWRKU by N */
5004
5005
ldwrku = (*lwork - *n * 3) / *n;
5006
}
5007
nwork = iu + ldwrku * *n;
5008
5009
/*
5010
Perform bidiagonal SVD, computing left singular vectors
5011
of bidiagonal matrix in RWORK(IRU) and computing right
5012
singular vectors of bidiagonal matrix in RWORK(IRVT)
5013
(CWorkspace: need 0)
5014
(RWorkspace: need BDSPAC)
5015
*/
5016
5017
dbdsdc_("U", "I", n, &s[1], &rwork[ie], &rwork[iru], n, &
5018
rwork[irvt], n, dum, idum, &rwork[nrwork], &iwork[1],
5019
info);
5020
5021
/*
5022
Multiply real matrix RWORK(IRVT) by P**H in VT,
5023
storing the result in WORK(IU), copying to VT
5024
(Cworkspace: need 0)
5025
(Rworkspace: need 3*N*N)
5026
*/
5027
5028
zlarcm_(n, n, &rwork[irvt], n, &vt[vt_offset], ldvt, &work[iu]
5029
, &ldwrku, &rwork[nrwork]);
5030
zlacpy_("F", n, n, &work[iu], &ldwrku, &vt[vt_offset], ldvt);
5031
5032
/*
5033
Multiply Q in A by real matrix RWORK(IRU), storing the
5034
result in WORK(IU), copying to A
5035
(CWorkspace: need N*N, prefer M*N)
5036
(Rworkspace: need 3*N*N, prefer N*N+2*M*N)
5037
*/
5038
5039
nrwork = irvt;
5040
i__2 = *m;
5041
i__1 = ldwrku;
5042
for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ +=
5043
i__1) {
5044
/* Computing MIN */
5045
i__3 = *m - i__ + 1;
5046
chunk = min(i__3,ldwrku);
5047
zlacrm_(&chunk, n, &a[i__ + a_dim1], lda, &rwork[iru], n,
5048
&work[iu], &ldwrku, &rwork[nrwork]);
5049
zlacpy_("F", &chunk, n, &work[iu], &ldwrku, &a[i__ +
5050
a_dim1], lda);
5051
/* L20: */
5052
}
5053
5054
} else if (wntqs) {
5055
5056
/*
5057
Copy A to VT, generate P**H
5058
(Cworkspace: need 2*N, prefer N+N*NB)
5059
(Rworkspace: 0)
5060
*/
5061
5062
zlacpy_("U", n, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
5063
i__1 = *lwork - nwork + 1;
5064
zungbr_("P", n, n, n, &vt[vt_offset], ldvt, &work[itaup], &
5065
work[nwork], &i__1, &ierr);
5066
5067
/*
5068
Copy A to U, generate Q
5069
(Cworkspace: need 2*N, prefer N+N*NB)
5070
(Rworkspace: 0)
5071
*/
5072
5073
zlacpy_("L", m, n, &a[a_offset], lda, &u[u_offset], ldu);
5074
i__1 = *lwork - nwork + 1;
5075
zungbr_("Q", m, n, n, &u[u_offset], ldu, &work[itauq], &work[
5076
nwork], &i__1, &ierr);
5077
5078
/*
5079
Perform bidiagonal SVD, computing left singular vectors
5080
of bidiagonal matrix in RWORK(IRU) and computing right
5081
singular vectors of bidiagonal matrix in RWORK(IRVT)
5082
(CWorkspace: need 0)
5083
(RWorkspace: need BDSPAC)
5084
*/
5085
5086
iru = nrwork;
5087
irvt = iru + *n * *n;
5088
nrwork = irvt + *n * *n;
5089
dbdsdc_("U", "I", n, &s[1], &rwork[ie], &rwork[iru], n, &
5090
rwork[irvt], n, dum, idum, &rwork[nrwork], &iwork[1],
5091
info);
5092
5093
/*
5094
Multiply real matrix RWORK(IRVT) by P**H in VT,
5095
storing the result in A, copying to VT
5096
(Cworkspace: need 0)
5097
(Rworkspace: need 3*N*N)
5098
*/
5099
5100
zlarcm_(n, n, &rwork[irvt], n, &vt[vt_offset], ldvt, &a[
5101
a_offset], lda, &rwork[nrwork]);
5102
zlacpy_("F", n, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
5103
5104
/*
5105
Multiply Q in U by real matrix RWORK(IRU), storing the
5106
result in A, copying to U
5107
(CWorkspace: need 0)
5108
(Rworkspace: need N*N+2*M*N)
5109
*/
5110
5111
nrwork = irvt;
5112
zlacrm_(m, n, &u[u_offset], ldu, &rwork[iru], n, &a[a_offset],
5113
lda, &rwork[nrwork]);
5114
zlacpy_("F", m, n, &a[a_offset], lda, &u[u_offset], ldu);
5115
} else {
5116
5117
/*
5118
Copy A to VT, generate P**H
5119
(Cworkspace: need 2*N, prefer N+N*NB)
5120
(Rworkspace: 0)
5121
*/
5122
5123
zlacpy_("U", n, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
5124
i__1 = *lwork - nwork + 1;
5125
zungbr_("P", n, n, n, &vt[vt_offset], ldvt, &work[itaup], &
5126
work[nwork], &i__1, &ierr);
5127
5128
/*
5129
Copy A to U, generate Q
5130
(Cworkspace: need 2*N, prefer N+N*NB)
5131
(Rworkspace: 0)
5132
*/
5133
5134
zlacpy_("L", m, n, &a[a_offset], lda, &u[u_offset], ldu);
5135
i__1 = *lwork - nwork + 1;
5136
zungbr_("Q", m, m, n, &u[u_offset], ldu, &work[itauq], &work[
5137
nwork], &i__1, &ierr);
5138
5139
/*
5140
Perform bidiagonal SVD, computing left singular vectors
5141
of bidiagonal matrix in RWORK(IRU) and computing right
5142
singular vectors of bidiagonal matrix in RWORK(IRVT)
5143
(CWorkspace: need 0)
5144
(RWorkspace: need BDSPAC)
5145
*/
5146
5147
iru = nrwork;
5148
irvt = iru + *n * *n;
5149
nrwork = irvt + *n * *n;
5150
dbdsdc_("U", "I", n, &s[1], &rwork[ie], &rwork[iru], n, &
5151
rwork[irvt], n, dum, idum, &rwork[nrwork], &iwork[1],
5152
info);
5153
5154
/*
5155
Multiply real matrix RWORK(IRVT) by P**H in VT,
5156
storing the result in A, copying to VT
5157
(Cworkspace: need 0)
5158
(Rworkspace: need 3*N*N)
5159
*/
5160
5161
zlarcm_(n, n, &rwork[irvt], n, &vt[vt_offset], ldvt, &a[
5162
a_offset], lda, &rwork[nrwork]);
5163
zlacpy_("F", n, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
5164
5165
/*
5166
Multiply Q in U by real matrix RWORK(IRU), storing the
5167
result in A, copying to U
5168
(CWorkspace: 0)
5169
(Rworkspace: need 3*N*N)
5170
*/
5171
5172
nrwork = irvt;
5173
zlacrm_(m, n, &u[u_offset], ldu, &rwork[iru], n, &a[a_offset],
5174
lda, &rwork[nrwork]);
5175
zlacpy_("F", m, n, &a[a_offset], lda, &u[u_offset], ldu);
5176
}
5177
5178
} else {
5179
5180
/*
5181
M .LT. MNTHR2
5182
5183
Path 6 (M at least N, but not much larger)
5184
Reduce to bidiagonal form without QR decomposition
5185
Use ZUNMBR to compute singular vectors
5186
*/
5187
5188
ie = 1;
5189
nrwork = ie + *n;
5190
itauq = 1;
5191
itaup = itauq + *n;
5192
nwork = itaup + *n;
5193
5194
/*
5195
Bidiagonalize A
5196
(CWorkspace: need 2*N+M, prefer 2*N+(M+N)*NB)
5197
(RWorkspace: need N)
5198
*/
5199
5200
i__1 = *lwork - nwork + 1;
5201
zgebrd_(m, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq],
5202
&work[itaup], &work[nwork], &i__1, &ierr);
5203
if (wntqn) {
5204
5205
/*
5206
Compute singular values only
5207
(Cworkspace: 0)
5208
(Rworkspace: need BDSPAN)
5209
*/
5210
5211
dbdsdc_("U", "N", n, &s[1], &rwork[ie], dum, &c__1, dum, &
5212
c__1, dum, idum, &rwork[nrwork], &iwork[1], info);
5213
} else if (wntqo) {
5214
iu = nwork;
5215
iru = nrwork;
5216
irvt = iru + *n * *n;
5217
nrwork = irvt + *n * *n;
5218
if (*lwork >= *m * *n + *n * 3) {
5219
5220
/* WORK( IU ) is M by N */
5221
5222
ldwrku = *m;
5223
} else {
5224
5225
/* WORK( IU ) is LDWRKU by N */
5226
5227
ldwrku = (*lwork - *n * 3) / *n;
5228
}
5229
nwork = iu + ldwrku * *n;
5230
5231
/*
5232
Perform bidiagonal SVD, computing left singular vectors
5233
of bidiagonal matrix in RWORK(IRU) and computing right
5234
singular vectors of bidiagonal matrix in RWORK(IRVT)
5235
(CWorkspace: need 0)
5236
(RWorkspace: need BDSPAC)
5237
*/
5238
5239
dbdsdc_("U", "I", n, &s[1], &rwork[ie], &rwork[iru], n, &
5240
rwork[irvt], n, dum, idum, &rwork[nrwork], &iwork[1],
5241
info);
5242
5243
/*
5244
Copy real matrix RWORK(IRVT) to complex matrix VT
5245
Overwrite VT by right singular vectors of A
5246
(Cworkspace: need 2*N, prefer N+N*NB)
5247
(Rworkspace: need 0)
5248
*/
5249
5250
zlacp2_("F", n, n, &rwork[irvt], n, &vt[vt_offset], ldvt);
5251
i__1 = *lwork - nwork + 1;
5252
zunmbr_("P", "R", "C", n, n, n, &a[a_offset], lda, &work[
5253
itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
5254
ierr);
5255
5256
if (*lwork >= *m * *n + *n * 3) {
5257
5258
/*
5259
Copy real matrix RWORK(IRU) to complex matrix WORK(IU)
5260
Overwrite WORK(IU) by left singular vectors of A, copying
5261
to A
5262
(Cworkspace: need M*N+2*N, prefer M*N+N+N*NB)
5263
(Rworkspace: need 0)
5264
*/
5265
5266
zlaset_("F", m, n, &c_b56, &c_b56, &work[iu], &ldwrku);
5267
zlacp2_("F", n, n, &rwork[iru], n, &work[iu], &ldwrku);
5268
i__1 = *lwork - nwork + 1;
5269
zunmbr_("Q", "L", "N", m, n, n, &a[a_offset], lda, &work[
5270
itauq], &work[iu], &ldwrku, &work[nwork], &i__1, &
5271
ierr);
5272
zlacpy_("F", m, n, &work[iu], &ldwrku, &a[a_offset], lda);
5273
} else {
5274
5275
/*
5276
Generate Q in A
5277
(Cworkspace: need 2*N, prefer N+N*NB)
5278
(Rworkspace: need 0)
5279
*/
5280
5281
i__1 = *lwork - nwork + 1;
5282
zungbr_("Q", m, n, n, &a[a_offset], lda, &work[itauq], &
5283
work[nwork], &i__1, &ierr);
5284
5285
/*
5286
Multiply Q in A by real matrix RWORK(IRU), storing the
5287
result in WORK(IU), copying to A
5288
(CWorkspace: need N*N, prefer M*N)
5289
(Rworkspace: need 3*N*N, prefer N*N+2*M*N)
5290
*/
5291
5292
nrwork = irvt;
5293
i__1 = *m;
5294
i__2 = ldwrku;
5295
for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
5296
i__2) {
5297
/* Computing MIN */
5298
i__3 = *m - i__ + 1;
5299
chunk = min(i__3,ldwrku);
5300
zlacrm_(&chunk, n, &a[i__ + a_dim1], lda, &rwork[iru],
5301
n, &work[iu], &ldwrku, &rwork[nrwork]);
5302
zlacpy_("F", &chunk, n, &work[iu], &ldwrku, &a[i__ +
5303
a_dim1], lda);
5304
/* L30: */
5305
}
5306
}
5307
5308
} else if (wntqs) {
5309
5310
/*
5311
Perform bidiagonal SVD, computing left singular vectors
5312
of bidiagonal matrix in RWORK(IRU) and computing right
5313
singular vectors of bidiagonal matrix in RWORK(IRVT)
5314
(CWorkspace: need 0)
5315
(RWorkspace: need BDSPAC)
5316
*/
5317
5318
iru = nrwork;
5319
irvt = iru + *n * *n;
5320
nrwork = irvt + *n * *n;
5321
dbdsdc_("U", "I", n, &s[1], &rwork[ie], &rwork[iru], n, &
5322
rwork[irvt], n, dum, idum, &rwork[nrwork], &iwork[1],
5323
info);
5324
5325
/*
5326
Copy real matrix RWORK(IRU) to complex matrix U
5327
Overwrite U by left singular vectors of A
5328
(CWorkspace: need 3*N, prefer 2*N+N*NB)
5329
(RWorkspace: 0)
5330
*/
5331
5332
zlaset_("F", m, n, &c_b56, &c_b56, &u[u_offset], ldu);
5333
zlacp2_("F", n, n, &rwork[iru], n, &u[u_offset], ldu);
5334
i__2 = *lwork - nwork + 1;
5335
zunmbr_("Q", "L", "N", m, n, n, &a[a_offset], lda, &work[
5336
itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
5337
5338
/*
5339
Copy real matrix RWORK(IRVT) to complex matrix VT
5340
Overwrite VT by right singular vectors of A
5341
(CWorkspace: need 3*N, prefer 2*N+N*NB)
5342
(RWorkspace: 0)
5343
*/
5344
5345
zlacp2_("F", n, n, &rwork[irvt], n, &vt[vt_offset], ldvt);
5346
i__2 = *lwork - nwork + 1;
5347
zunmbr_("P", "R", "C", n, n, n, &a[a_offset], lda, &work[
5348
itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
5349
ierr);
5350
} else {
5351
5352
/*
5353
Perform bidiagonal SVD, computing left singular vectors
5354
of bidiagonal matrix in RWORK(IRU) and computing right
5355
singular vectors of bidiagonal matrix in RWORK(IRVT)
5356
(CWorkspace: need 0)
5357
(RWorkspace: need BDSPAC)
5358
*/
5359
5360
iru = nrwork;
5361
irvt = iru + *n * *n;
5362
nrwork = irvt + *n * *n;
5363
dbdsdc_("U", "I", n, &s[1], &rwork[ie], &rwork[iru], n, &
5364
rwork[irvt], n, dum, idum, &rwork[nrwork], &iwork[1],
5365
info);
5366
5367
/* Set the right corner of U to identity matrix */
5368
5369
zlaset_("F", m, m, &c_b56, &c_b56, &u[u_offset], ldu);
5370
if (*m > *n) {
5371
i__2 = *m - *n;
5372
i__1 = *m - *n;
5373
zlaset_("F", &i__2, &i__1, &c_b56, &c_b57, &u[*n + 1 + (*
5374
n + 1) * u_dim1], ldu);
5375
}
5376
5377
/*
5378
Copy real matrix RWORK(IRU) to complex matrix U
5379
Overwrite U by left singular vectors of A
5380
(CWorkspace: need 2*N+M, prefer 2*N+M*NB)
5381
(RWorkspace: 0)
5382
*/
5383
5384
zlacp2_("F", n, n, &rwork[iru], n, &u[u_offset], ldu);
5385
i__2 = *lwork - nwork + 1;
5386
zunmbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
5387
itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
5388
5389
/*
5390
Copy real matrix RWORK(IRVT) to complex matrix VT
5391
Overwrite VT by right singular vectors of A
5392
(CWorkspace: need 3*N, prefer 2*N+N*NB)
5393
(RWorkspace: 0)
5394
*/
5395
5396
zlacp2_("F", n, n, &rwork[irvt], n, &vt[vt_offset], ldvt);
5397
i__2 = *lwork - nwork + 1;
5398
zunmbr_("P", "R", "C", n, n, n, &a[a_offset], lda, &work[
5399
itaup], &vt[vt_offset], ldvt, &work[nwork], &i__2, &
5400
ierr);
5401
}
5402
5403
}
5404
5405
} else {
5406
5407
/*
5408
A has more columns than rows. If A has sufficiently more
5409
columns than rows, first reduce using the LQ decomposition (if
5410
sufficient workspace available)
5411
*/
5412
5413
if (*n >= mnthr1) {
5414
5415
if (wntqn) {
5416
5417
/*
5418
Path 1t (N much larger than M, JOBZ='N')
5419
No singular vectors to be computed
5420
*/
5421
5422
itau = 1;
5423
nwork = itau + *m;
5424
5425
/*
5426
Compute A=L*Q
5427
(CWorkspace: need 2*M, prefer M+M*NB)
5428
(RWorkspace: 0)
5429
*/
5430
5431
i__2 = *lwork - nwork + 1;
5432
zgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
5433
i__2, &ierr);
5434
5435
/* Zero out above L */
5436
5437
i__2 = *m - 1;
5438
i__1 = *m - 1;
5439
zlaset_("U", &i__2, &i__1, &c_b56, &c_b56, &a[(a_dim1 << 1) +
5440
1], lda);
5441
ie = 1;
5442
itauq = 1;
5443
itaup = itauq + *m;
5444
nwork = itaup + *m;
5445
5446
/*
5447
Bidiagonalize L in A
5448
(CWorkspace: need 3*M, prefer 2*M+2*M*NB)
5449
(RWorkspace: need M)
5450
*/
5451
5452
i__2 = *lwork - nwork + 1;
5453
zgebrd_(m, m, &a[a_offset], lda, &s[1], &rwork[ie], &work[
5454
itauq], &work[itaup], &work[nwork], &i__2, &ierr);
5455
nrwork = ie + *m;
5456
5457
/*
5458
Perform bidiagonal SVD, compute singular values only
5459
(CWorkspace: 0)
5460
(RWorkspace: need BDSPAN)
5461
*/
5462
5463
dbdsdc_("U", "N", m, &s[1], &rwork[ie], dum, &c__1, dum, &
5464
c__1, dum, idum, &rwork[nrwork], &iwork[1], info);
5465
5466
} else if (wntqo) {
5467
5468
/*
5469
Path 2t (N much larger than M, JOBZ='O')
5470
M right singular vectors to be overwritten on A and
5471
M left singular vectors to be computed in U
5472
*/
5473
5474
ivt = 1;
5475
ldwkvt = *m;
5476
5477
/* WORK(IVT) is M by M */
5478
5479
il = ivt + ldwkvt * *m;
5480
if (*lwork >= *m * *n + *m * *m + *m * 3) {
5481
5482
/* WORK(IL) M by N */
5483
5484
ldwrkl = *m;
5485
chunk = *n;
5486
} else {
5487
5488
/* WORK(IL) is M by CHUNK */
5489
5490
ldwrkl = *m;
5491
chunk = (*lwork - *m * *m - *m * 3) / *m;
5492
}
5493
itau = il + ldwrkl * chunk;
5494
nwork = itau + *m;
5495
5496
/*
5497
Compute A=L*Q
5498
(CWorkspace: need 2*M, prefer M+M*NB)
5499
(RWorkspace: 0)
5500
*/
5501
5502
i__2 = *lwork - nwork + 1;
5503
zgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
5504
i__2, &ierr);
5505
5506
/* Copy L to WORK(IL), zeroing about above it */
5507
5508
zlacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwrkl);
5509
i__2 = *m - 1;
5510
i__1 = *m - 1;
5511
zlaset_("U", &i__2, &i__1, &c_b56, &c_b56, &work[il + ldwrkl],
5512
&ldwrkl);
5513
5514
/*
5515
Generate Q in A
5516
(CWorkspace: need M*M+2*M, prefer M*M+M+M*NB)
5517
(RWorkspace: 0)
5518
*/
5519
5520
i__2 = *lwork - nwork + 1;
5521
zunglq_(m, n, m, &a[a_offset], lda, &work[itau], &work[nwork],
5522
&i__2, &ierr);
5523
ie = 1;
5524
itauq = itau;
5525
itaup = itauq + *m;
5526
nwork = itaup + *m;
5527
5528
/*
5529
Bidiagonalize L in WORK(IL)
5530
(CWorkspace: need M*M+3*M, prefer M*M+2*M+2*M*NB)
5531
(RWorkspace: need M)
5532
*/
5533
5534
i__2 = *lwork - nwork + 1;
5535
zgebrd_(m, m, &work[il], &ldwrkl, &s[1], &rwork[ie], &work[
5536
itauq], &work[itaup], &work[nwork], &i__2, &ierr);
5537
5538
/*
5539
Perform bidiagonal SVD, computing left singular vectors
5540
of bidiagonal matrix in RWORK(IRU) and computing right
5541
singular vectors of bidiagonal matrix in RWORK(IRVT)
5542
(CWorkspace: need 0)
5543
(RWorkspace: need BDSPAC)
5544
*/
5545
5546
iru = ie + *m;
5547
irvt = iru + *m * *m;
5548
nrwork = irvt + *m * *m;
5549
dbdsdc_("U", "I", m, &s[1], &rwork[ie], &rwork[iru], m, &
5550
rwork[irvt], m, dum, idum, &rwork[nrwork], &iwork[1],
5551
info);
5552
5553
/*
5554
Copy real matrix RWORK(IRU) to complex matrix WORK(IU)
5555
Overwrite WORK(IU) by the left singular vectors of L
5556
(CWorkspace: need N*N+3*N, prefer M*N+2*N+N*NB)
5557
(RWorkspace: 0)
5558
*/
5559
5560
zlacp2_("F", m, m, &rwork[iru], m, &u[u_offset], ldu);
5561
i__2 = *lwork - nwork + 1;
5562
zunmbr_("Q", "L", "N", m, m, m, &work[il], &ldwrkl, &work[
5563
itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
5564
5565
/*
5566
Copy real matrix RWORK(IRVT) to complex matrix WORK(IVT)
5567
Overwrite WORK(IVT) by the right singular vectors of L
5568
(CWorkspace: need N*N+3*N, prefer M*N+2*N+N*NB)
5569
(RWorkspace: 0)
5570
*/
5571
5572
zlacp2_("F", m, m, &rwork[irvt], m, &work[ivt], &ldwkvt);
5573
i__2 = *lwork - nwork + 1;
5574
zunmbr_("P", "R", "C", m, m, m, &work[il], &ldwrkl, &work[
5575
itaup], &work[ivt], &ldwkvt, &work[nwork], &i__2, &
5576
ierr);
5577
5578
/*
5579
Multiply right singular vectors of L in WORK(IL) by Q
5580
in A, storing result in WORK(IL) and copying to A
5581
(CWorkspace: need 2*M*M, prefer M*M+M*N))
5582
(RWorkspace: 0)
5583
*/
5584
5585
i__2 = *n;
5586
i__1 = chunk;
5587
for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ +=
5588
i__1) {
5589
/* Computing MIN */
5590
i__3 = *n - i__ + 1;
5591
blk = min(i__3,chunk);
5592
zgemm_("N", "N", m, &blk, m, &c_b57, &work[ivt], m, &a[
5593
i__ * a_dim1 + 1], lda, &c_b56, &work[il], &
5594
ldwrkl);
5595
zlacpy_("F", m, &blk, &work[il], &ldwrkl, &a[i__ * a_dim1
5596
+ 1], lda);
5597
/* L40: */
5598
}
5599
5600
} else if (wntqs) {
5601
5602
/*
5603
Path 3t (N much larger than M, JOBZ='S')
5604
M right singular vectors to be computed in VT and
5605
M left singular vectors to be computed in U
5606
*/
5607
5608
il = 1;
5609
5610
/* WORK(IL) is M by M */
5611
5612
ldwrkl = *m;
5613
itau = il + ldwrkl * *m;
5614
nwork = itau + *m;
5615
5616
/*
5617
Compute A=L*Q
5618
(CWorkspace: need 2*M, prefer M+M*NB)
5619
(RWorkspace: 0)
5620
*/
5621
5622
i__1 = *lwork - nwork + 1;
5623
zgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
5624
i__1, &ierr);
5625
5626
/* Copy L to WORK(IL), zeroing out above it */
5627
5628
zlacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwrkl);
5629
i__1 = *m - 1;
5630
i__2 = *m - 1;
5631
zlaset_("U", &i__1, &i__2, &c_b56, &c_b56, &work[il + ldwrkl],
5632
&ldwrkl);
5633
5634
/*
5635
Generate Q in A
5636
(CWorkspace: need M*M+2*M, prefer M*M+M+M*NB)
5637
(RWorkspace: 0)
5638
*/
5639
5640
i__1 = *lwork - nwork + 1;
5641
zunglq_(m, n, m, &a[a_offset], lda, &work[itau], &work[nwork],
5642
&i__1, &ierr);
5643
ie = 1;
5644
itauq = itau;
5645
itaup = itauq + *m;
5646
nwork = itaup + *m;
5647
5648
/*
5649
Bidiagonalize L in WORK(IL)
5650
(CWorkspace: need M*M+3*M, prefer M*M+2*M+2*M*NB)
5651
(RWorkspace: need M)
5652
*/
5653
5654
i__1 = *lwork - nwork + 1;
5655
zgebrd_(m, m, &work[il], &ldwrkl, &s[1], &rwork[ie], &work[
5656
itauq], &work[itaup], &work[nwork], &i__1, &ierr);
5657
5658
/*
5659
Perform bidiagonal SVD, computing left singular vectors
5660
of bidiagonal matrix in RWORK(IRU) and computing right
5661
singular vectors of bidiagonal matrix in RWORK(IRVT)
5662
(CWorkspace: need 0)
5663
(RWorkspace: need BDSPAC)
5664
*/
5665
5666
iru = ie + *m;
5667
irvt = iru + *m * *m;
5668
nrwork = irvt + *m * *m;
5669
dbdsdc_("U", "I", m, &s[1], &rwork[ie], &rwork[iru], m, &
5670
rwork[irvt], m, dum, idum, &rwork[nrwork], &iwork[1],
5671
info);
5672
5673
/*
5674
Copy real matrix RWORK(IRU) to complex matrix U
5675
Overwrite U by left singular vectors of L
5676
(CWorkspace: need M*M+3*M, prefer M*M+2*M+M*NB)
5677
(RWorkspace: 0)
5678
*/
5679
5680
zlacp2_("F", m, m, &rwork[iru], m, &u[u_offset], ldu);
5681
i__1 = *lwork - nwork + 1;
5682
zunmbr_("Q", "L", "N", m, m, m, &work[il], &ldwrkl, &work[
5683
itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
5684
5685
/*
5686
Copy real matrix RWORK(IRVT) to complex matrix VT
5687
Overwrite VT by left singular vectors of L
5688
(CWorkspace: need M*M+3*M, prefer M*M+2*M+M*NB)
5689
(RWorkspace: 0)
5690
*/
5691
5692
zlacp2_("F", m, m, &rwork[irvt], m, &vt[vt_offset], ldvt);
5693
i__1 = *lwork - nwork + 1;
5694
zunmbr_("P", "R", "C", m, m, m, &work[il], &ldwrkl, &work[
5695
itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
5696
ierr);
5697
5698
/*
5699
Copy VT to WORK(IL), multiply right singular vectors of L
5700
in WORK(IL) by Q in A, storing result in VT
5701
(CWorkspace: need M*M)
5702
(RWorkspace: 0)
5703
*/
5704
5705
zlacpy_("F", m, m, &vt[vt_offset], ldvt, &work[il], &ldwrkl);
5706
zgemm_("N", "N", m, n, m, &c_b57, &work[il], &ldwrkl, &a[
5707
a_offset], lda, &c_b56, &vt[vt_offset], ldvt);
5708
5709
} else if (wntqa) {
5710
5711
/*
5712
Path 9t (N much larger than M, JOBZ='A')
5713
N right singular vectors to be computed in VT and
5714
M left singular vectors to be computed in U
5715
*/
5716
5717
ivt = 1;
5718
5719
/* WORK(IVT) is M by M */
5720
5721
ldwkvt = *m;
5722
itau = ivt + ldwkvt * *m;
5723
nwork = itau + *m;
5724
5725
/*
5726
Compute A=L*Q, copying result to VT
5727
(CWorkspace: need 2*M, prefer M+M*NB)
5728
(RWorkspace: 0)
5729
*/
5730
5731
i__1 = *lwork - nwork + 1;
5732
zgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &
5733
i__1, &ierr);
5734
zlacpy_("U", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
5735
5736
/*
5737
Generate Q in VT
5738
(CWorkspace: need M+N, prefer M+N*NB)
5739
(RWorkspace: 0)
5740
*/
5741
5742
i__1 = *lwork - nwork + 1;
5743
zunglq_(n, n, m, &vt[vt_offset], ldvt, &work[itau], &work[
5744
nwork], &i__1, &ierr);
5745
5746
/* Produce L in A, zeroing out above it */
5747
5748
i__1 = *m - 1;
5749
i__2 = *m - 1;
5750
zlaset_("U", &i__1, &i__2, &c_b56, &c_b56, &a[(a_dim1 << 1) +
5751
1], lda);
5752
ie = 1;
5753
itauq = itau;
5754
itaup = itauq + *m;
5755
nwork = itaup + *m;
5756
5757
/*
5758
Bidiagonalize L in A
5759
(CWorkspace: need M*M+3*M, prefer M*M+2*M+2*M*NB)
5760
(RWorkspace: need M)
5761
*/
5762
5763
i__1 = *lwork - nwork + 1;
5764
zgebrd_(m, m, &a[a_offset], lda, &s[1], &rwork[ie], &work[
5765
itauq], &work[itaup], &work[nwork], &i__1, &ierr);
5766
5767
/*
5768
Perform bidiagonal SVD, computing left singular vectors
5769
of bidiagonal matrix in RWORK(IRU) and computing right
5770
singular vectors of bidiagonal matrix in RWORK(IRVT)
5771
(CWorkspace: need 0)
5772
(RWorkspace: need BDSPAC)
5773
*/
5774
5775
iru = ie + *m;
5776
irvt = iru + *m * *m;
5777
nrwork = irvt + *m * *m;
5778
dbdsdc_("U", "I", m, &s[1], &rwork[ie], &rwork[iru], m, &
5779
rwork[irvt], m, dum, idum, &rwork[nrwork], &iwork[1],
5780
info);
5781
5782
/*
5783
Copy real matrix RWORK(IRU) to complex matrix U
5784
Overwrite U by left singular vectors of L
5785
(CWorkspace: need 3*M, prefer 2*M+M*NB)
5786
(RWorkspace: 0)
5787
*/
5788
5789
zlacp2_("F", m, m, &rwork[iru], m, &u[u_offset], ldu);
5790
i__1 = *lwork - nwork + 1;
5791
zunmbr_("Q", "L", "N", m, m, m, &a[a_offset], lda, &work[
5792
itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
5793
5794
/*
5795
Copy real matrix RWORK(IRVT) to complex matrix WORK(IVT)
5796
Overwrite WORK(IVT) by right singular vectors of L
5797
(CWorkspace: need M*M+3*M, prefer M*M+2*M+M*NB)
5798
(RWorkspace: 0)
5799
*/
5800
5801
zlacp2_("F", m, m, &rwork[irvt], m, &work[ivt], &ldwkvt);
5802
i__1 = *lwork - nwork + 1;
5803
zunmbr_("P", "R", "C", m, m, m, &a[a_offset], lda, &work[
5804
itaup], &work[ivt], &ldwkvt, &work[nwork], &i__1, &
5805
ierr);
5806
5807
/*
5808
Multiply right singular vectors of L in WORK(IVT) by
5809
Q in VT, storing result in A
5810
(CWorkspace: need M*M)
5811
(RWorkspace: 0)
5812
*/
5813
5814
zgemm_("N", "N", m, n, m, &c_b57, &work[ivt], &ldwkvt, &vt[
5815
vt_offset], ldvt, &c_b56, &a[a_offset], lda);
5816
5817
/* Copy right singular vectors of A from A to VT */
5818
5819
zlacpy_("F", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
5820
5821
}
5822
5823
} else if (*n >= mnthr2) {
5824
5825
/*
5826
MNTHR2 <= N < MNTHR1
5827
5828
Path 5t (N much larger than M, but not as much as MNTHR1)
5829
Reduce to bidiagonal form without QR decomposition, use
5830
ZUNGBR and matrix multiplication to compute singular vectors
5831
*/
5832
5833
5834
ie = 1;
5835
nrwork = ie + *m;
5836
itauq = 1;
5837
itaup = itauq + *m;
5838
nwork = itaup + *m;
5839
5840
/*
5841
Bidiagonalize A
5842
(CWorkspace: need 2*M+N, prefer 2*M+(M+N)*NB)
5843
(RWorkspace: M)
5844
*/
5845
5846
i__1 = *lwork - nwork + 1;
5847
zgebrd_(m, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq],
5848
&work[itaup], &work[nwork], &i__1, &ierr);
5849
5850
if (wntqn) {
5851
5852
/*
5853
Compute singular values only
5854
(Cworkspace: 0)
5855
(Rworkspace: need BDSPAN)
5856
*/
5857
5858
dbdsdc_("L", "N", m, &s[1], &rwork[ie], dum, &c__1, dum, &
5859
c__1, dum, idum, &rwork[nrwork], &iwork[1], info);
5860
} else if (wntqo) {
5861
irvt = nrwork;
5862
iru = irvt + *m * *m;
5863
nrwork = iru + *m * *m;
5864
ivt = nwork;
5865
5866
/*
5867
Copy A to U, generate Q
5868
(Cworkspace: need 2*M, prefer M+M*NB)
5869
(Rworkspace: 0)
5870
*/
5871
5872
zlacpy_("L", m, m, &a[a_offset], lda, &u[u_offset], ldu);
5873
i__1 = *lwork - nwork + 1;
5874
zungbr_("Q", m, m, n, &u[u_offset], ldu, &work[itauq], &work[
5875
nwork], &i__1, &ierr);
5876
5877
/*
5878
Generate P**H in A
5879
(Cworkspace: need 2*M, prefer M+M*NB)
5880
(Rworkspace: 0)
5881
*/
5882
5883
i__1 = *lwork - nwork + 1;
5884
zungbr_("P", m, n, m, &a[a_offset], lda, &work[itaup], &work[
5885
nwork], &i__1, &ierr);
5886
5887
ldwkvt = *m;
5888
if (*lwork >= *m * *n + *m * 3) {
5889
5890
/* WORK( IVT ) is M by N */
5891
5892
nwork = ivt + ldwkvt * *n;
5893
chunk = *n;
5894
} else {
5895
5896
/* WORK( IVT ) is M by CHUNK */
5897
5898
chunk = (*lwork - *m * 3) / *m;
5899
nwork = ivt + ldwkvt * chunk;
5900
}
5901
5902
/*
5903
Perform bidiagonal SVD, computing left singular vectors
5904
of bidiagonal matrix in RWORK(IRU) and computing right
5905
singular vectors of bidiagonal matrix in RWORK(IRVT)
5906
(CWorkspace: need 0)
5907
(RWorkspace: need BDSPAC)
5908
*/
5909
5910
dbdsdc_("L", "I", m, &s[1], &rwork[ie], &rwork[iru], m, &
5911
rwork[irvt], m, dum, idum, &rwork[nrwork], &iwork[1],
5912
info);
5913
5914
/*
5915
Multiply Q in U by real matrix RWORK(IRVT)
5916
storing the result in WORK(IVT), copying to U
5917
(Cworkspace: need 0)
5918
(Rworkspace: need 2*M*M)
5919
*/
5920
5921
zlacrm_(m, m, &u[u_offset], ldu, &rwork[iru], m, &work[ivt], &
5922
ldwkvt, &rwork[nrwork]);
5923
zlacpy_("F", m, m, &work[ivt], &ldwkvt, &u[u_offset], ldu);
5924
5925
/*
5926
Multiply RWORK(IRVT) by P**H in A, storing the
5927
result in WORK(IVT), copying to A
5928
(CWorkspace: need M*M, prefer M*N)
5929
(Rworkspace: need 2*M*M, prefer 2*M*N)
5930
*/
5931
5932
nrwork = iru;
5933
i__1 = *n;
5934
i__2 = chunk;
5935
for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
5936
i__2) {
5937
/* Computing MIN */
5938
i__3 = *n - i__ + 1;
5939
blk = min(i__3,chunk);
5940
zlarcm_(m, &blk, &rwork[irvt], m, &a[i__ * a_dim1 + 1],
5941
lda, &work[ivt], &ldwkvt, &rwork[nrwork]);
5942
zlacpy_("F", m, &blk, &work[ivt], &ldwkvt, &a[i__ *
5943
a_dim1 + 1], lda);
5944
/* L50: */
5945
}
5946
} else if (wntqs) {
5947
5948
/*
5949
Copy A to U, generate Q
5950
(Cworkspace: need 2*M, prefer M+M*NB)
5951
(Rworkspace: 0)
5952
*/
5953
5954
zlacpy_("L", m, m, &a[a_offset], lda, &u[u_offset], ldu);
5955
i__2 = *lwork - nwork + 1;
5956
zungbr_("Q", m, m, n, &u[u_offset], ldu, &work[itauq], &work[
5957
nwork], &i__2, &ierr);
5958
5959
/*
5960
Copy A to VT, generate P**H
5961
(Cworkspace: need 2*M, prefer M+M*NB)
5962
(Rworkspace: 0)
5963
*/
5964
5965
zlacpy_("U", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
5966
i__2 = *lwork - nwork + 1;
5967
zungbr_("P", m, n, m, &vt[vt_offset], ldvt, &work[itaup], &
5968
work[nwork], &i__2, &ierr);
5969
5970
/*
5971
Perform bidiagonal SVD, computing left singular vectors
5972
of bidiagonal matrix in RWORK(IRU) and computing right
5973
singular vectors of bidiagonal matrix in RWORK(IRVT)
5974
(CWorkspace: need 0)
5975
(RWorkspace: need BDSPAC)
5976
*/
5977
5978
irvt = nrwork;
5979
iru = irvt + *m * *m;
5980
nrwork = iru + *m * *m;
5981
dbdsdc_("L", "I", m, &s[1], &rwork[ie], &rwork[iru], m, &
5982
rwork[irvt], m, dum, idum, &rwork[nrwork], &iwork[1],
5983
info);
5984
5985
/*
5986
Multiply Q in U by real matrix RWORK(IRU), storing the
5987
result in A, copying to U
5988
(CWorkspace: need 0)
5989
(Rworkspace: need 3*M*M)
5990
*/
5991
5992
zlacrm_(m, m, &u[u_offset], ldu, &rwork[iru], m, &a[a_offset],
5993
lda, &rwork[nrwork]);
5994
zlacpy_("F", m, m, &a[a_offset], lda, &u[u_offset], ldu);
5995
5996
/*
5997
Multiply real matrix RWORK(IRVT) by P**H in VT,
5998
storing the result in A, copying to VT
5999
(Cworkspace: need 0)
6000
(Rworkspace: need M*M+2*M*N)
6001
*/
6002
6003
nrwork = iru;
6004
zlarcm_(m, n, &rwork[irvt], m, &vt[vt_offset], ldvt, &a[
6005
a_offset], lda, &rwork[nrwork]);
6006
zlacpy_("F", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
6007
} else {
6008
6009
/*
6010
Copy A to U, generate Q
6011
(Cworkspace: need 2*M, prefer M+M*NB)
6012
(Rworkspace: 0)
6013
*/
6014
6015
zlacpy_("L", m, m, &a[a_offset], lda, &u[u_offset], ldu);
6016
i__2 = *lwork - nwork + 1;
6017
zungbr_("Q", m, m, n, &u[u_offset], ldu, &work[itauq], &work[
6018
nwork], &i__2, &ierr);
6019
6020
/*
6021
Copy A to VT, generate P**H
6022
(Cworkspace: need 2*M, prefer M+M*NB)
6023
(Rworkspace: 0)
6024
*/
6025
6026
zlacpy_("U", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
6027
i__2 = *lwork - nwork + 1;
6028
zungbr_("P", n, n, m, &vt[vt_offset], ldvt, &work[itaup], &
6029
work[nwork], &i__2, &ierr);
6030
6031
/*
6032
Perform bidiagonal SVD, computing left singular vectors
6033
of bidiagonal matrix in RWORK(IRU) and computing right
6034
singular vectors of bidiagonal matrix in RWORK(IRVT)
6035
(CWorkspace: need 0)
6036
(RWorkspace: need BDSPAC)
6037
*/
6038
6039
irvt = nrwork;
6040
iru = irvt + *m * *m;
6041
nrwork = iru + *m * *m;
6042
dbdsdc_("L", "I", m, &s[1], &rwork[ie], &rwork[iru], m, &
6043
rwork[irvt], m, dum, idum, &rwork[nrwork], &iwork[1],
6044
info);
6045
6046
/*
6047
Multiply Q in U by real matrix RWORK(IRU), storing the
6048
result in A, copying to U
6049
(CWorkspace: need 0)
6050
(Rworkspace: need 3*M*M)
6051
*/
6052
6053
zlacrm_(m, m, &u[u_offset], ldu, &rwork[iru], m, &a[a_offset],
6054
lda, &rwork[nrwork]);
6055
zlacpy_("F", m, m, &a[a_offset], lda, &u[u_offset], ldu);
6056
6057
/*
6058
Multiply real matrix RWORK(IRVT) by P**H in VT,
6059
storing the result in A, copying to VT
6060
(Cworkspace: need 0)
6061
(Rworkspace: need M*M+2*M*N)
6062
*/
6063
6064
zlarcm_(m, n, &rwork[irvt], m, &vt[vt_offset], ldvt, &a[
6065
a_offset], lda, &rwork[nrwork]);
6066
zlacpy_("F", m, n, &a[a_offset], lda, &vt[vt_offset], ldvt);
6067
}
6068
6069
} else {
6070
6071
/*
6072
N .LT. MNTHR2
6073
6074
Path 6t (N greater than M, but not much larger)
6075
Reduce to bidiagonal form without LQ decomposition
6076
Use ZUNMBR to compute singular vectors
6077
*/
6078
6079
ie = 1;
6080
nrwork = ie + *m;
6081
itauq = 1;
6082
itaup = itauq + *m;
6083
nwork = itaup + *m;
6084
6085
/*
6086
Bidiagonalize A
6087
(CWorkspace: need 2*M+N, prefer 2*M+(M+N)*NB)
6088
(RWorkspace: M)
6089
*/
6090
6091
i__2 = *lwork - nwork + 1;
6092
zgebrd_(m, n, &a[a_offset], lda, &s[1], &rwork[ie], &work[itauq],
6093
&work[itaup], &work[nwork], &i__2, &ierr);
6094
if (wntqn) {
6095
6096
/*
6097
Compute singular values only
6098
(Cworkspace: 0)
6099
(Rworkspace: need BDSPAN)
6100
*/
6101
6102
dbdsdc_("L", "N", m, &s[1], &rwork[ie], dum, &c__1, dum, &
6103
c__1, dum, idum, &rwork[nrwork], &iwork[1], info);
6104
} else if (wntqo) {
6105
ldwkvt = *m;
6106
ivt = nwork;
6107
if (*lwork >= *m * *n + *m * 3) {
6108
6109
/* WORK( IVT ) is M by N */
6110
6111
zlaset_("F", m, n, &c_b56, &c_b56, &work[ivt], &ldwkvt);
6112
nwork = ivt + ldwkvt * *n;
6113
} else {
6114
6115
/* WORK( IVT ) is M by CHUNK */
6116
6117
chunk = (*lwork - *m * 3) / *m;
6118
nwork = ivt + ldwkvt * chunk;
6119
}
6120
6121
/*
6122
Perform bidiagonal SVD, computing left singular vectors
6123
of bidiagonal matrix in RWORK(IRU) and computing right
6124
singular vectors of bidiagonal matrix in RWORK(IRVT)
6125
(CWorkspace: need 0)
6126
(RWorkspace: need BDSPAC)
6127
*/
6128
6129
irvt = nrwork;
6130
iru = irvt + *m * *m;
6131
nrwork = iru + *m * *m;
6132
dbdsdc_("L", "I", m, &s[1], &rwork[ie], &rwork[iru], m, &
6133
rwork[irvt], m, dum, idum, &rwork[nrwork], &iwork[1],
6134
info);
6135
6136
/*
6137
Copy real matrix RWORK(IRU) to complex matrix U
6138
Overwrite U by left singular vectors of A
6139
(Cworkspace: need 2*M, prefer M+M*NB)
6140
(Rworkspace: need 0)
6141
*/
6142
6143
zlacp2_("F", m, m, &rwork[iru], m, &u[u_offset], ldu);
6144
i__2 = *lwork - nwork + 1;
6145
zunmbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
6146
itauq], &u[u_offset], ldu, &work[nwork], &i__2, &ierr);
6147
6148
if (*lwork >= *m * *n + *m * 3) {
6149
6150
/*
6151
Copy real matrix RWORK(IRVT) to complex matrix WORK(IVT)
6152
Overwrite WORK(IVT) by right singular vectors of A,
6153
copying to A
6154
(Cworkspace: need M*N+2*M, prefer M*N+M+M*NB)
6155
(Rworkspace: need 0)
6156
*/
6157
6158
zlacp2_("F", m, m, &rwork[irvt], m, &work[ivt], &ldwkvt);
6159
i__2 = *lwork - nwork + 1;
6160
zunmbr_("P", "R", "C", m, n, m, &a[a_offset], lda, &work[
6161
itaup], &work[ivt], &ldwkvt, &work[nwork], &i__2,
6162
&ierr);
6163
zlacpy_("F", m, n, &work[ivt], &ldwkvt, &a[a_offset], lda);
6164
} else {
6165
6166
/*
6167
Generate P**H in A
6168
(Cworkspace: need 2*M, prefer M+M*NB)
6169
(Rworkspace: need 0)
6170
*/
6171
6172
i__2 = *lwork - nwork + 1;
6173
zungbr_("P", m, n, m, &a[a_offset], lda, &work[itaup], &
6174
work[nwork], &i__2, &ierr);
6175
6176
/*
6177
Multiply Q in A by real matrix RWORK(IRU), storing the
6178
result in WORK(IU), copying to A
6179
(CWorkspace: need M*M, prefer M*N)
6180
(Rworkspace: need 3*M*M, prefer M*M+2*M*N)
6181
*/
6182
6183
nrwork = iru;
6184
i__2 = *n;
6185
i__1 = chunk;
6186
for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ +=
6187
i__1) {
6188
/* Computing MIN */
6189
i__3 = *n - i__ + 1;
6190
blk = min(i__3,chunk);
6191
zlarcm_(m, &blk, &rwork[irvt], m, &a[i__ * a_dim1 + 1]
6192
, lda, &work[ivt], &ldwkvt, &rwork[nrwork]);
6193
zlacpy_("F", m, &blk, &work[ivt], &ldwkvt, &a[i__ *
6194
a_dim1 + 1], lda);
6195
/* L60: */
6196
}
6197
}
6198
} else if (wntqs) {
6199
6200
/*
6201
Perform bidiagonal SVD, computing left singular vectors
6202
of bidiagonal matrix in RWORK(IRU) and computing right
6203
singular vectors of bidiagonal matrix in RWORK(IRVT)
6204
(CWorkspace: need 0)
6205
(RWorkspace: need BDSPAC)
6206
*/
6207
6208
irvt = nrwork;
6209
iru = irvt + *m * *m;
6210
nrwork = iru + *m * *m;
6211
dbdsdc_("L", "I", m, &s[1], &rwork[ie], &rwork[iru], m, &
6212
rwork[irvt], m, dum, idum, &rwork[nrwork], &iwork[1],
6213
info);
6214
6215
/*
6216
Copy real matrix RWORK(IRU) to complex matrix U
6217
Overwrite U by left singular vectors of A
6218
(CWorkspace: need 3*M, prefer 2*M+M*NB)
6219
(RWorkspace: M*M)
6220
*/
6221
6222
zlacp2_("F", m, m, &rwork[iru], m, &u[u_offset], ldu);
6223
i__1 = *lwork - nwork + 1;
6224
zunmbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
6225
itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
6226
6227
/*
6228
Copy real matrix RWORK(IRVT) to complex matrix VT
6229
Overwrite VT by right singular vectors of A
6230
(CWorkspace: need 3*M, prefer 2*M+M*NB)
6231
(RWorkspace: M*M)
6232
*/
6233
6234
zlaset_("F", m, n, &c_b56, &c_b56, &vt[vt_offset], ldvt);
6235
zlacp2_("F", m, m, &rwork[irvt], m, &vt[vt_offset], ldvt);
6236
i__1 = *lwork - nwork + 1;
6237
zunmbr_("P", "R", "C", m, n, m, &a[a_offset], lda, &work[
6238
itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
6239
ierr);
6240
} else {
6241
6242
/*
6243
Perform bidiagonal SVD, computing left singular vectors
6244
of bidiagonal matrix in RWORK(IRU) and computing right
6245
singular vectors of bidiagonal matrix in RWORK(IRVT)
6246
(CWorkspace: need 0)
6247
(RWorkspace: need BDSPAC)
6248
*/
6249
6250
irvt = nrwork;
6251
iru = irvt + *m * *m;
6252
nrwork = iru + *m * *m;
6253
6254
dbdsdc_("L", "I", m, &s[1], &rwork[ie], &rwork[iru], m, &
6255
rwork[irvt], m, dum, idum, &rwork[nrwork], &iwork[1],
6256
info);
6257
6258
/*
6259
Copy real matrix RWORK(IRU) to complex matrix U
6260
Overwrite U by left singular vectors of A
6261
(CWorkspace: need 3*M, prefer 2*M+M*NB)
6262
(RWorkspace: M*M)
6263
*/
6264
6265
zlacp2_("F", m, m, &rwork[iru], m, &u[u_offset], ldu);
6266
i__1 = *lwork - nwork + 1;
6267
zunmbr_("Q", "L", "N", m, m, n, &a[a_offset], lda, &work[
6268
itauq], &u[u_offset], ldu, &work[nwork], &i__1, &ierr);
6269
6270
/* Set all of VT to identity matrix */
6271
6272
zlaset_("F", n, n, &c_b56, &c_b57, &vt[vt_offset], ldvt);
6273
6274
/*
6275
Copy real matrix RWORK(IRVT) to complex matrix VT
6276
Overwrite VT by right singular vectors of A
6277
(CWorkspace: need 2*M+N, prefer 2*M+N*NB)
6278
(RWorkspace: M*M)
6279
*/
6280
6281
zlacp2_("F", m, m, &rwork[irvt], m, &vt[vt_offset], ldvt);
6282
i__1 = *lwork - nwork + 1;
6283
zunmbr_("P", "R", "C", n, n, m, &a[a_offset], lda, &work[
6284
itaup], &vt[vt_offset], ldvt, &work[nwork], &i__1, &
6285
ierr);
6286
}
6287
6288
}
6289
6290
}
6291
6292
/* Undo scaling if necessary */
6293
6294
if (iscl == 1) {
6295
if (anrm > bignum) {
6296
dlascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], &
6297
minmn, &ierr);
6298
}
6299
if (*info != 0 && anrm > bignum) {
6300
i__1 = minmn - 1;
6301
dlascl_("G", &c__0, &c__0, &bignum, &anrm, &i__1, &c__1, &rwork[
6302
ie], &minmn, &ierr);
6303
}
6304
if (anrm < smlnum) {
6305
dlascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], &
6306
minmn, &ierr);
6307
}
6308
if (*info != 0 && anrm < smlnum) {
6309
i__1 = minmn - 1;
6310
dlascl_("G", &c__0, &c__0, &smlnum, &anrm, &i__1, &c__1, &rwork[
6311
ie], &minmn, &ierr);
6312
}
6313
}
6314
6315
/* Return optimal workspace in WORK(1) */
6316
6317
work[1].r = (doublereal) maxwrk, work[1].i = 0.;
6318
6319
return 0;
6320
6321
/* End of ZGESDD */
6322
6323
} /* zgesdd_ */
6324
6325
/* Subroutine */ int zgesv_(integer *n, integer *nrhs, doublecomplex *a,
6326
integer *lda, integer *ipiv, doublecomplex *b, integer *ldb, integer *
6327
info)
6328
{
6329
/* System generated locals */
6330
integer a_dim1, a_offset, b_dim1, b_offset, i__1;
6331
6332
/* Local variables */
6333
extern /* Subroutine */ int xerbla_(char *, integer *), zgetrf_(
6334
integer *, integer *, doublecomplex *, integer *, integer *,
6335
integer *), zgetrs_(char *, integer *, integer *, doublecomplex *,
6336
integer *, integer *, doublecomplex *, integer *, integer *);
6337
6338
6339
/*
6340
-- LAPACK driver routine (version 3.2) --
6341
-- LAPACK is a software package provided by Univ. of Tennessee, --
6342
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
6343
November 2006
6344
6345
6346
Purpose
6347
=======
6348
6349
ZGESV computes the solution to a complex system of linear equations
6350
A * X = B,
6351
where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
6352
6353
The LU decomposition with partial pivoting and row interchanges is
6354
used to factor A as
6355
A = P * L * U,
6356
where P is a permutation matrix, L is unit lower triangular, and U is
6357
upper triangular. The factored form of A is then used to solve the
6358
system of equations A * X = B.
6359
6360
Arguments
6361
=========
6362
6363
N (input) INTEGER
6364
The number of linear equations, i.e., the order of the
6365
matrix A. N >= 0.
6366
6367
NRHS (input) INTEGER
6368
The number of right hand sides, i.e., the number of columns
6369
of the matrix B. NRHS >= 0.
6370
6371
A (input/output) COMPLEX*16 array, dimension (LDA,N)
6372
On entry, the N-by-N coefficient matrix A.
6373
On exit, the factors L and U from the factorization
6374
A = P*L*U; the unit diagonal elements of L are not stored.
6375
6376
LDA (input) INTEGER
6377
The leading dimension of the array A. LDA >= max(1,N).
6378
6379
IPIV (output) INTEGER array, dimension (N)
6380
The pivot indices that define the permutation matrix P;
6381
row i of the matrix was interchanged with row IPIV(i).
6382
6383
B (input/output) COMPLEX*16 array, dimension (LDB,NRHS)
6384
On entry, the N-by-NRHS matrix of right hand side matrix B.
6385
On exit, if INFO = 0, the N-by-NRHS solution matrix X.
6386
6387
LDB (input) INTEGER
6388
The leading dimension of the array B. LDB >= max(1,N).
6389
6390
INFO (output) INTEGER
6391
= 0: successful exit
6392
< 0: if INFO = -i, the i-th argument had an illegal value
6393
> 0: if INFO = i, U(i,i) is exactly zero. The factorization
6394
has been completed, but the factor U is exactly
6395
singular, so the solution could not be computed.
6396
6397
=====================================================================
6398
6399
6400
Test the input parameters.
6401
*/
6402
6403
/* Parameter adjustments */
6404
a_dim1 = *lda;
6405
a_offset = 1 + a_dim1;
6406
a -= a_offset;
6407
--ipiv;
6408
b_dim1 = *ldb;
6409
b_offset = 1 + b_dim1;
6410
b -= b_offset;
6411
6412
/* Function Body */
6413
*info = 0;
6414
if (*n < 0) {
6415
*info = -1;
6416
} else if (*nrhs < 0) {
6417
*info = -2;
6418
} else if (*lda < max(1,*n)) {
6419
*info = -4;
6420
} else if (*ldb < max(1,*n)) {
6421
*info = -7;
6422
}
6423
if (*info != 0) {
6424
i__1 = -(*info);
6425
xerbla_("ZGESV ", &i__1);
6426
return 0;
6427
}
6428
6429
/* Compute the LU factorization of A. */
6430
6431
zgetrf_(n, n, &a[a_offset], lda, &ipiv[1], info);
6432
if (*info == 0) {
6433
6434
/* Solve the system A*X = B, overwriting B with X. */
6435
6436
zgetrs_("No transpose", n, nrhs, &a[a_offset], lda, &ipiv[1], &b[
6437
b_offset], ldb, info);
6438
}
6439
return 0;
6440
6441
/* End of ZGESV */
6442
6443
} /* zgesv_ */
6444
6445
/* Subroutine */ int zgetf2_(integer *m, integer *n, doublecomplex *a,
6446
integer *lda, integer *ipiv, integer *info)
6447
{
6448
/* System generated locals */
6449
integer a_dim1, a_offset, i__1, i__2, i__3;
6450
doublecomplex z__1;
6451
6452
/* Local variables */
6453
static integer i__, j, jp;
6454
static doublereal sfmin;
6455
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
6456
doublecomplex *, integer *), zgeru_(integer *, integer *,
6457
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
6458
integer *, doublecomplex *, integer *), zswap_(integer *,
6459
doublecomplex *, integer *, doublecomplex *, integer *);
6460
6461
extern /* Subroutine */ int xerbla_(char *, integer *);
6462
extern integer izamax_(integer *, doublecomplex *, integer *);
6463
6464
6465
/*
6466
-- LAPACK routine (version 3.2) --
6467
-- LAPACK is a software package provided by Univ. of Tennessee, --
6468
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
6469
November 2006
6470
6471
6472
Purpose
6473
=======
6474
6475
ZGETF2 computes an LU factorization of a general m-by-n matrix A
6476
using partial pivoting with row interchanges.
6477
6478
The factorization has the form
6479
A = P * L * U
6480
where P is a permutation matrix, L is lower triangular with unit
6481
diagonal elements (lower trapezoidal if m > n), and U is upper
6482
triangular (upper trapezoidal if m < n).
6483
6484
This is the right-looking Level 2 BLAS version of the algorithm.
6485
6486
Arguments
6487
=========
6488
6489
M (input) INTEGER
6490
The number of rows of the matrix A. M >= 0.
6491
6492
N (input) INTEGER
6493
The number of columns of the matrix A. N >= 0.
6494
6495
A (input/output) COMPLEX*16 array, dimension (LDA,N)
6496
On entry, the m by n matrix to be factored.
6497
On exit, the factors L and U from the factorization
6498
A = P*L*U; the unit diagonal elements of L are not stored.
6499
6500
LDA (input) INTEGER
6501
The leading dimension of the array A. LDA >= max(1,M).
6502
6503
IPIV (output) INTEGER array, dimension (min(M,N))
6504
The pivot indices; for 1 <= i <= min(M,N), row i of the
6505
matrix was interchanged with row IPIV(i).
6506
6507
INFO (output) INTEGER
6508
= 0: successful exit
6509
< 0: if INFO = -k, the k-th argument had an illegal value
6510
> 0: if INFO = k, U(k,k) is exactly zero. The factorization
6511
has been completed, but the factor U is exactly
6512
singular, and division by zero will occur if it is used
6513
to solve a system of equations.
6514
6515
=====================================================================
6516
6517
6518
Test the input parameters.
6519
*/
6520
6521
/* Parameter adjustments */
6522
a_dim1 = *lda;
6523
a_offset = 1 + a_dim1;
6524
a -= a_offset;
6525
--ipiv;
6526
6527
/* Function Body */
6528
*info = 0;
6529
if (*m < 0) {
6530
*info = -1;
6531
} else if (*n < 0) {
6532
*info = -2;
6533
} else if (*lda < max(1,*m)) {
6534
*info = -4;
6535
}
6536
if (*info != 0) {
6537
i__1 = -(*info);
6538
xerbla_("ZGETF2", &i__1);
6539
return 0;
6540
}
6541
6542
/* Quick return if possible */
6543
6544
if (*m == 0 || *n == 0) {
6545
return 0;
6546
}
6547
6548
/* Compute machine safe minimum */
6549
6550
sfmin = SAFEMINIMUM;
6551
6552
i__1 = min(*m,*n);
6553
for (j = 1; j <= i__1; ++j) {
6554
6555
/* Find pivot and test for singularity. */
6556
6557
i__2 = *m - j + 1;
6558
jp = j - 1 + izamax_(&i__2, &a[j + j * a_dim1], &c__1);
6559
ipiv[j] = jp;
6560
i__2 = jp + j * a_dim1;
6561
if (a[i__2].r != 0. || a[i__2].i != 0.) {
6562
6563
/* Apply the interchange to columns 1:N. */
6564
6565
if (jp != j) {
6566
zswap_(n, &a[j + a_dim1], lda, &a[jp + a_dim1], lda);
6567
}
6568
6569
/* Compute elements J+1:M of J-th column. */
6570
6571
if (j < *m) {
6572
if (z_abs(&a[j + j * a_dim1]) >= sfmin) {
6573
i__2 = *m - j;
6574
z_div(&z__1, &c_b57, &a[j + j * a_dim1]);
6575
zscal_(&i__2, &z__1, &a[j + 1 + j * a_dim1], &c__1);
6576
} else {
6577
i__2 = *m - j;
6578
for (i__ = 1; i__ <= i__2; ++i__) {
6579
i__3 = j + i__ + j * a_dim1;
6580
z_div(&z__1, &a[j + i__ + j * a_dim1], &a[j + j *
6581
a_dim1]);
6582
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
6583
/* L20: */
6584
}
6585
}
6586
}
6587
6588
} else if (*info == 0) {
6589
6590
*info = j;
6591
}
6592
6593
if (j < min(*m,*n)) {
6594
6595
/* Update trailing submatrix. */
6596
6597
i__2 = *m - j;
6598
i__3 = *n - j;
6599
z__1.r = -1., z__1.i = -0.;
6600
zgeru_(&i__2, &i__3, &z__1, &a[j + 1 + j * a_dim1], &c__1, &a[j +
6601
(j + 1) * a_dim1], lda, &a[j + 1 + (j + 1) * a_dim1], lda)
6602
;
6603
}
6604
/* L10: */
6605
}
6606
return 0;
6607
6608
/* End of ZGETF2 */
6609
6610
} /* zgetf2_ */
6611
6612
/* Subroutine */ int zgetrf_(integer *m, integer *n, doublecomplex *a,
6613
integer *lda, integer *ipiv, integer *info)
6614
{
6615
/* System generated locals */
6616
integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
6617
doublecomplex z__1;
6618
6619
/* Local variables */
6620
static integer i__, j, jb, nb, iinfo;
6621
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
6622
integer *, doublecomplex *, doublecomplex *, integer *,
6623
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
6624
integer *), ztrsm_(char *, char *, char *, char *,
6625
integer *, integer *, doublecomplex *, doublecomplex *, integer *
6626
, doublecomplex *, integer *),
6627
zgetf2_(integer *, integer *, doublecomplex *, integer *, integer
6628
*, integer *), xerbla_(char *, integer *);
6629
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
6630
integer *, integer *, ftnlen, ftnlen);
6631
extern /* Subroutine */ int zlaswp_(integer *, doublecomplex *, integer *,
6632
integer *, integer *, integer *, integer *);
6633
6634
6635
/*
6636
-- LAPACK routine (version 3.2) --
6637
-- LAPACK is a software package provided by Univ. of Tennessee, --
6638
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
6639
November 2006
6640
6641
6642
Purpose
6643
=======
6644
6645
ZGETRF computes an LU factorization of a general M-by-N matrix A
6646
using partial pivoting with row interchanges.
6647
6648
The factorization has the form
6649
A = P * L * U
6650
where P is a permutation matrix, L is lower triangular with unit
6651
diagonal elements (lower trapezoidal if m > n), and U is upper
6652
triangular (upper trapezoidal if m < n).
6653
6654
This is the right-looking Level 3 BLAS version of the algorithm.
6655
6656
Arguments
6657
=========
6658
6659
M (input) INTEGER
6660
The number of rows of the matrix A. M >= 0.
6661
6662
N (input) INTEGER
6663
The number of columns of the matrix A. N >= 0.
6664
6665
A (input/output) COMPLEX*16 array, dimension (LDA,N)
6666
On entry, the M-by-N matrix to be factored.
6667
On exit, the factors L and U from the factorization
6668
A = P*L*U; the unit diagonal elements of L are not stored.
6669
6670
LDA (input) INTEGER
6671
The leading dimension of the array A. LDA >= max(1,M).
6672
6673
IPIV (output) INTEGER array, dimension (min(M,N))
6674
The pivot indices; for 1 <= i <= min(M,N), row i of the
6675
matrix was interchanged with row IPIV(i).
6676
6677
INFO (output) INTEGER
6678
= 0: successful exit
6679
< 0: if INFO = -i, the i-th argument had an illegal value
6680
> 0: if INFO = i, U(i,i) is exactly zero. The factorization
6681
has been completed, but the factor U is exactly
6682
singular, and division by zero will occur if it is used
6683
to solve a system of equations.
6684
6685
=====================================================================
6686
6687
6688
Test the input parameters.
6689
*/
6690
6691
/* Parameter adjustments */
6692
a_dim1 = *lda;
6693
a_offset = 1 + a_dim1;
6694
a -= a_offset;
6695
--ipiv;
6696
6697
/* Function Body */
6698
*info = 0;
6699
if (*m < 0) {
6700
*info = -1;
6701
} else if (*n < 0) {
6702
*info = -2;
6703
} else if (*lda < max(1,*m)) {
6704
*info = -4;
6705
}
6706
if (*info != 0) {
6707
i__1 = -(*info);
6708
xerbla_("ZGETRF", &i__1);
6709
return 0;
6710
}
6711
6712
/* Quick return if possible */
6713
6714
if (*m == 0 || *n == 0) {
6715
return 0;
6716
}
6717
6718
/* Determine the block size for this environment. */
6719
6720
nb = ilaenv_(&c__1, "ZGETRF", " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)
6721
1);
6722
if (nb <= 1 || nb >= min(*m,*n)) {
6723
6724
/* Use unblocked code. */
6725
6726
zgetf2_(m, n, &a[a_offset], lda, &ipiv[1], info);
6727
} else {
6728
6729
/* Use blocked code. */
6730
6731
i__1 = min(*m,*n);
6732
i__2 = nb;
6733
for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
6734
/* Computing MIN */
6735
i__3 = min(*m,*n) - j + 1;
6736
jb = min(i__3,nb);
6737
6738
/*
6739
Factor diagonal and subdiagonal blocks and test for exact
6740
singularity.
6741
*/
6742
6743
i__3 = *m - j + 1;
6744
zgetf2_(&i__3, &jb, &a[j + j * a_dim1], lda, &ipiv[j], &iinfo);
6745
6746
/* Adjust INFO and the pivot indices. */
6747
6748
if (*info == 0 && iinfo > 0) {
6749
*info = iinfo + j - 1;
6750
}
6751
/* Computing MIN */
6752
i__4 = *m, i__5 = j + jb - 1;
6753
i__3 = min(i__4,i__5);
6754
for (i__ = j; i__ <= i__3; ++i__) {
6755
ipiv[i__] = j - 1 + ipiv[i__];
6756
/* L10: */
6757
}
6758
6759
/* Apply interchanges to columns 1:J-1. */
6760
6761
i__3 = j - 1;
6762
i__4 = j + jb - 1;
6763
zlaswp_(&i__3, &a[a_offset], lda, &j, &i__4, &ipiv[1], &c__1);
6764
6765
if (j + jb <= *n) {
6766
6767
/* Apply interchanges to columns J+JB:N. */
6768
6769
i__3 = *n - j - jb + 1;
6770
i__4 = j + jb - 1;
6771
zlaswp_(&i__3, &a[(j + jb) * a_dim1 + 1], lda, &j, &i__4, &
6772
ipiv[1], &c__1);
6773
6774
/* Compute block row of U. */
6775
6776
i__3 = *n - j - jb + 1;
6777
ztrsm_("Left", "Lower", "No transpose", "Unit", &jb, &i__3, &
6778
c_b57, &a[j + j * a_dim1], lda, &a[j + (j + jb) *
6779
a_dim1], lda);
6780
if (j + jb <= *m) {
6781
6782
/* Update trailing submatrix. */
6783
6784
i__3 = *m - j - jb + 1;
6785
i__4 = *n - j - jb + 1;
6786
z__1.r = -1., z__1.i = -0.;
6787
zgemm_("No transpose", "No transpose", &i__3, &i__4, &jb,
6788
&z__1, &a[j + jb + j * a_dim1], lda, &a[j + (j +
6789
jb) * a_dim1], lda, &c_b57, &a[j + jb + (j + jb) *
6790
a_dim1], lda);
6791
}
6792
}
6793
/* L20: */
6794
}
6795
}
6796
return 0;
6797
6798
/* End of ZGETRF */
6799
6800
} /* zgetrf_ */
6801
6802
/* Subroutine */ int zgetrs_(char *trans, integer *n, integer *nrhs,
6803
doublecomplex *a, integer *lda, integer *ipiv, doublecomplex *b,
6804
integer *ldb, integer *info)
6805
{
6806
/* System generated locals */
6807
integer a_dim1, a_offset, b_dim1, b_offset, i__1;
6808
6809
/* Local variables */
6810
extern logical lsame_(char *, char *);
6811
extern /* Subroutine */ int ztrsm_(char *, char *, char *, char *,
6812
integer *, integer *, doublecomplex *, doublecomplex *, integer *,
6813
doublecomplex *, integer *),
6814
xerbla_(char *, integer *);
6815
static logical notran;
6816
extern /* Subroutine */ int zlaswp_(integer *, doublecomplex *, integer *,
6817
integer *, integer *, integer *, integer *);
6818
6819
6820
/*
6821
-- LAPACK routine (version 3.2) --
6822
-- LAPACK is a software package provided by Univ. of Tennessee, --
6823
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
6824
November 2006
6825
6826
6827
Purpose
6828
=======
6829
6830
ZGETRS solves a system of linear equations
6831
A * X = B, A**T * X = B, or A**H * X = B
6832
with a general N-by-N matrix A using the LU factorization computed
6833
by ZGETRF.
6834
6835
Arguments
6836
=========
6837
6838
TRANS (input) CHARACTER*1
6839
Specifies the form of the system of equations:
6840
= 'N': A * X = B (No transpose)
6841
= 'T': A**T * X = B (Transpose)
6842
= 'C': A**H * X = B (Conjugate transpose)
6843
6844
N (input) INTEGER
6845
The order of the matrix A. N >= 0.
6846
6847
NRHS (input) INTEGER
6848
The number of right hand sides, i.e., the number of columns
6849
of the matrix B. NRHS >= 0.
6850
6851
A (input) COMPLEX*16 array, dimension (LDA,N)
6852
The factors L and U from the factorization A = P*L*U
6853
as computed by ZGETRF.
6854
6855
LDA (input) INTEGER
6856
The leading dimension of the array A. LDA >= max(1,N).
6857
6858
IPIV (input) INTEGER array, dimension (N)
6859
The pivot indices from ZGETRF; for 1<=i<=N, row i of the
6860
matrix was interchanged with row IPIV(i).
6861
6862
B (input/output) COMPLEX*16 array, dimension (LDB,NRHS)
6863
On entry, the right hand side matrix B.
6864
On exit, the solution matrix X.
6865
6866
LDB (input) INTEGER
6867
The leading dimension of the array B. LDB >= max(1,N).
6868
6869
INFO (output) INTEGER
6870
= 0: successful exit
6871
< 0: if INFO = -i, the i-th argument had an illegal value
6872
6873
=====================================================================
6874
6875
6876
Test the input parameters.
6877
*/
6878
6879
/* Parameter adjustments */
6880
a_dim1 = *lda;
6881
a_offset = 1 + a_dim1;
6882
a -= a_offset;
6883
--ipiv;
6884
b_dim1 = *ldb;
6885
b_offset = 1 + b_dim1;
6886
b -= b_offset;
6887
6888
/* Function Body */
6889
*info = 0;
6890
notran = lsame_(trans, "N");
6891
if (! notran && ! lsame_(trans, "T") && ! lsame_(
6892
trans, "C")) {
6893
*info = -1;
6894
} else if (*n < 0) {
6895
*info = -2;
6896
} else if (*nrhs < 0) {
6897
*info = -3;
6898
} else if (*lda < max(1,*n)) {
6899
*info = -5;
6900
} else if (*ldb < max(1,*n)) {
6901
*info = -8;
6902
}
6903
if (*info != 0) {
6904
i__1 = -(*info);
6905
xerbla_("ZGETRS", &i__1);
6906
return 0;
6907
}
6908
6909
/* Quick return if possible */
6910
6911
if (*n == 0 || *nrhs == 0) {
6912
return 0;
6913
}
6914
6915
if (notran) {
6916
6917
/*
6918
Solve A * X = B.
6919
6920
Apply row interchanges to the right hand sides.
6921
*/
6922
6923
zlaswp_(nrhs, &b[b_offset], ldb, &c__1, n, &ipiv[1], &c__1);
6924
6925
/* Solve L*X = B, overwriting B with X. */
6926
6927
ztrsm_("Left", "Lower", "No transpose", "Unit", n, nrhs, &c_b57, &a[
6928
a_offset], lda, &b[b_offset], ldb);
6929
6930
/* Solve U*X = B, overwriting B with X. */
6931
6932
ztrsm_("Left", "Upper", "No transpose", "Non-unit", n, nrhs, &c_b57, &
6933
a[a_offset], lda, &b[b_offset], ldb);
6934
} else {
6935
6936
/*
6937
Solve A**T * X = B or A**H * X = B.
6938
6939
Solve U'*X = B, overwriting B with X.
6940
*/
6941
6942
ztrsm_("Left", "Upper", trans, "Non-unit", n, nrhs, &c_b57, &a[
6943
a_offset], lda, &b[b_offset], ldb);
6944
6945
/* Solve L'*X = B, overwriting B with X. */
6946
6947
ztrsm_("Left", "Lower", trans, "Unit", n, nrhs, &c_b57, &a[a_offset],
6948
lda, &b[b_offset], ldb);
6949
6950
/* Apply row interchanges to the solution vectors. */
6951
6952
zlaswp_(nrhs, &b[b_offset], ldb, &c__1, n, &ipiv[1], &c_n1);
6953
}
6954
6955
return 0;
6956
6957
/* End of ZGETRS */
6958
6959
} /* zgetrs_ */
6960
6961
/* Subroutine */ int zheevd_(char *jobz, char *uplo, integer *n,
6962
doublecomplex *a, integer *lda, doublereal *w, doublecomplex *work,
6963
integer *lwork, doublereal *rwork, integer *lrwork, integer *iwork,
6964
integer *liwork, integer *info)
6965
{
6966
/* System generated locals */
6967
integer a_dim1, a_offset, i__1, i__2;
6968
doublereal d__1;
6969
6970
/* Local variables */
6971
static doublereal eps;
6972
static integer inde;
6973
static doublereal anrm;
6974
static integer imax;
6975
static doublereal rmin, rmax;
6976
static integer lopt;
6977
extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
6978
integer *);
6979
static doublereal sigma;
6980
extern logical lsame_(char *, char *);
6981
static integer iinfo, lwmin, liopt;
6982
static logical lower;
6983
static integer llrwk, lropt;
6984
static logical wantz;
6985
static integer indwk2, llwrk2;
6986
6987
static integer iscale;
6988
static doublereal safmin;
6989
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
6990
integer *, integer *, ftnlen, ftnlen);
6991
extern /* Subroutine */ int xerbla_(char *, integer *);
6992
static doublereal bignum;
6993
extern doublereal zlanhe_(char *, char *, integer *, doublecomplex *,
6994
integer *, doublereal *);
6995
static integer indtau;
6996
extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *,
6997
integer *), zlascl_(char *, integer *, integer *, doublereal *,
6998
doublereal *, integer *, integer *, doublecomplex *, integer *,
6999
integer *), zstedc_(char *, integer *, doublereal *,
7000
doublereal *, doublecomplex *, integer *, doublecomplex *,
7001
integer *, doublereal *, integer *, integer *, integer *, integer
7002
*);
7003
static integer indrwk, indwrk, liwmin;
7004
extern /* Subroutine */ int zhetrd_(char *, integer *, doublecomplex *,
7005
integer *, doublereal *, doublereal *, doublecomplex *,
7006
doublecomplex *, integer *, integer *), zlacpy_(char *,
7007
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
7008
integer *);
7009
static integer lrwmin, llwork;
7010
static doublereal smlnum;
7011
static logical lquery;
7012
extern /* Subroutine */ int zunmtr_(char *, char *, char *, integer *,
7013
integer *, doublecomplex *, integer *, doublecomplex *,
7014
doublecomplex *, integer *, doublecomplex *, integer *, integer *);
7015
7016
7017
/*
7018
-- LAPACK driver routine (version 3.2) --
7019
-- LAPACK is a software package provided by Univ. of Tennessee, --
7020
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
7021
November 2006
7022
7023
7024
Purpose
7025
=======
7026
7027
ZHEEVD computes all eigenvalues and, optionally, eigenvectors of a
7028
complex Hermitian matrix A. If eigenvectors are desired, it uses a
7029
divide and conquer algorithm.
7030
7031
The divide and conquer algorithm makes very mild assumptions about
7032
floating point arithmetic. It will work on machines with a guard
7033
digit in add/subtract, or on those binary machines without guard
7034
digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
7035
Cray-2. It could conceivably fail on hexadecimal or decimal machines
7036
without guard digits, but we know of none.
7037
7038
Arguments
7039
=========
7040
7041
JOBZ (input) CHARACTER*1
7042
= 'N': Compute eigenvalues only;
7043
= 'V': Compute eigenvalues and eigenvectors.
7044
7045
UPLO (input) CHARACTER*1
7046
= 'U': Upper triangle of A is stored;
7047
= 'L': Lower triangle of A is stored.
7048
7049
N (input) INTEGER
7050
The order of the matrix A. N >= 0.
7051
7052
A (input/output) COMPLEX*16 array, dimension (LDA, N)
7053
On entry, the Hermitian matrix A. If UPLO = 'U', the
7054
leading N-by-N upper triangular part of A contains the
7055
upper triangular part of the matrix A. If UPLO = 'L',
7056
the leading N-by-N lower triangular part of A contains
7057
the lower triangular part of the matrix A.
7058
On exit, if JOBZ = 'V', then if INFO = 0, A contains the
7059
orthonormal eigenvectors of the matrix A.
7060
If JOBZ = 'N', then on exit the lower triangle (if UPLO='L')
7061
or the upper triangle (if UPLO='U') of A, including the
7062
diagonal, is destroyed.
7063
7064
LDA (input) INTEGER
7065
The leading dimension of the array A. LDA >= max(1,N).
7066
7067
W (output) DOUBLE PRECISION array, dimension (N)
7068
If INFO = 0, the eigenvalues in ascending order.
7069
7070
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
7071
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
7072
7073
LWORK (input) INTEGER
7074
The length of the array WORK.
7075
If N <= 1, LWORK must be at least 1.
7076
If JOBZ = 'N' and N > 1, LWORK must be at least N + 1.
7077
If JOBZ = 'V' and N > 1, LWORK must be at least 2*N + N**2.
7078
7079
If LWORK = -1, then a workspace query is assumed; the routine
7080
only calculates the optimal sizes of the WORK, RWORK and
7081
IWORK arrays, returns these values as the first entries of
7082
the WORK, RWORK and IWORK arrays, and no error message
7083
related to LWORK or LRWORK or LIWORK is issued by XERBLA.
7084
7085
RWORK (workspace/output) DOUBLE PRECISION array,
7086
dimension (LRWORK)
7087
On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK.
7088
7089
LRWORK (input) INTEGER
7090
The dimension of the array RWORK.
7091
If N <= 1, LRWORK must be at least 1.
7092
If JOBZ = 'N' and N > 1, LRWORK must be at least N.
7093
If JOBZ = 'V' and N > 1, LRWORK must be at least
7094
1 + 5*N + 2*N**2.
7095
7096
If LRWORK = -1, then a workspace query is assumed; the
7097
routine only calculates the optimal sizes of the WORK, RWORK
7098
and IWORK arrays, returns these values as the first entries
7099
of the WORK, RWORK and IWORK arrays, and no error message
7100
related to LWORK or LRWORK or LIWORK is issued by XERBLA.
7101
7102
IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
7103
On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
7104
7105
LIWORK (input) INTEGER
7106
The dimension of the array IWORK.
7107
If N <= 1, LIWORK must be at least 1.
7108
If JOBZ = 'N' and N > 1, LIWORK must be at least 1.
7109
If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N.
7110
7111
If LIWORK = -1, then a workspace query is assumed; the
7112
routine only calculates the optimal sizes of the WORK, RWORK
7113
and IWORK arrays, returns these values as the first entries
7114
of the WORK, RWORK and IWORK arrays, and no error message
7115
related to LWORK or LRWORK or LIWORK is issued by XERBLA.
7116
7117
INFO (output) INTEGER
7118
= 0: successful exit
7119
< 0: if INFO = -i, the i-th argument had an illegal value
7120
> 0: if INFO = i and JOBZ = 'N', then the algorithm failed
7121
to converge; i off-diagonal elements of an intermediate
7122
tridiagonal form did not converge to zero;
7123
if INFO = i and JOBZ = 'V', then the algorithm failed
7124
to compute an eigenvalue while working on the submatrix
7125
lying in rows and columns INFO/(N+1) through
7126
mod(INFO,N+1).
7127
7128
Further Details
7129
===============
7130
7131
Based on contributions by
7132
Jeff Rutter, Computer Science Division, University of California
7133
at Berkeley, USA
7134
7135
Modified description of INFO. Sven, 16 Feb 05.
7136
=====================================================================
7137
7138
7139
Test the input parameters.
7140
*/
7141
7142
/* Parameter adjustments */
7143
a_dim1 = *lda;
7144
a_offset = 1 + a_dim1;
7145
a -= a_offset;
7146
--w;
7147
--work;
7148
--rwork;
7149
--iwork;
7150
7151
/* Function Body */
7152
wantz = lsame_(jobz, "V");
7153
lower = lsame_(uplo, "L");
7154
lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
7155
7156
*info = 0;
7157
if (! (wantz || lsame_(jobz, "N"))) {
7158
*info = -1;
7159
} else if (! (lower || lsame_(uplo, "U"))) {
7160
*info = -2;
7161
} else if (*n < 0) {
7162
*info = -3;
7163
} else if (*lda < max(1,*n)) {
7164
*info = -5;
7165
}
7166
7167
if (*info == 0) {
7168
if (*n <= 1) {
7169
lwmin = 1;
7170
lrwmin = 1;
7171
liwmin = 1;
7172
lopt = lwmin;
7173
lropt = lrwmin;
7174
liopt = liwmin;
7175
} else {
7176
if (wantz) {
7177
lwmin = (*n << 1) + *n * *n;
7178
/* Computing 2nd power */
7179
i__1 = *n;
7180
lrwmin = *n * 5 + 1 + (i__1 * i__1 << 1);
7181
liwmin = *n * 5 + 3;
7182
} else {
7183
lwmin = *n + 1;
7184
lrwmin = *n;
7185
liwmin = 1;
7186
}
7187
/* Computing MAX */
7188
i__1 = lwmin, i__2 = *n + ilaenv_(&c__1, "ZHETRD", uplo, n, &c_n1,
7189
&c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
7190
lopt = max(i__1,i__2);
7191
lropt = lrwmin;
7192
liopt = liwmin;
7193
}
7194
work[1].r = (doublereal) lopt, work[1].i = 0.;
7195
rwork[1] = (doublereal) lropt;
7196
iwork[1] = liopt;
7197
7198
if (*lwork < lwmin && ! lquery) {
7199
*info = -8;
7200
} else if (*lrwork < lrwmin && ! lquery) {
7201
*info = -10;
7202
} else if (*liwork < liwmin && ! lquery) {
7203
*info = -12;
7204
}
7205
}
7206
7207
if (*info != 0) {
7208
i__1 = -(*info);
7209
xerbla_("ZHEEVD", &i__1);
7210
return 0;
7211
} else if (lquery) {
7212
return 0;
7213
}
7214
7215
/* Quick return if possible */
7216
7217
if (*n == 0) {
7218
return 0;
7219
}
7220
7221
if (*n == 1) {
7222
i__1 = a_dim1 + 1;
7223
w[1] = a[i__1].r;
7224
if (wantz) {
7225
i__1 = a_dim1 + 1;
7226
a[i__1].r = 1., a[i__1].i = 0.;
7227
}
7228
return 0;
7229
}
7230
7231
/* Get machine constants. */
7232
7233
safmin = SAFEMINIMUM;
7234
eps = PRECISION;
7235
smlnum = safmin / eps;
7236
bignum = 1. / smlnum;
7237
rmin = sqrt(smlnum);
7238
rmax = sqrt(bignum);
7239
7240
/* Scale matrix to allowable range, if necessary. */
7241
7242
anrm = zlanhe_("M", uplo, n, &a[a_offset], lda, &rwork[1]);
7243
iscale = 0;
7244
if (anrm > 0. && anrm < rmin) {
7245
iscale = 1;
7246
sigma = rmin / anrm;
7247
} else if (anrm > rmax) {
7248
iscale = 1;
7249
sigma = rmax / anrm;
7250
}
7251
if (iscale == 1) {
7252
zlascl_(uplo, &c__0, &c__0, &c_b1034, &sigma, n, n, &a[a_offset], lda,
7253
info);
7254
}
7255
7256
/* Call ZHETRD to reduce Hermitian matrix to tridiagonal form. */
7257
7258
inde = 1;
7259
indtau = 1;
7260
indwrk = indtau + *n;
7261
indrwk = inde + *n;
7262
indwk2 = indwrk + *n * *n;
7263
llwork = *lwork - indwrk + 1;
7264
llwrk2 = *lwork - indwk2 + 1;
7265
llrwk = *lrwork - indrwk + 1;
7266
zhetrd_(uplo, n, &a[a_offset], lda, &w[1], &rwork[inde], &work[indtau], &
7267
work[indwrk], &llwork, &iinfo);
7268
7269
/*
7270
For eigenvalues only, call DSTERF. For eigenvectors, first call
7271
ZSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the
7272
tridiagonal matrix, then call ZUNMTR to multiply it to the
7273
Householder transformations represented as Householder vectors in
7274
A.
7275
*/
7276
7277
if (! wantz) {
7278
dsterf_(n, &w[1], &rwork[inde], info);
7279
} else {
7280
zstedc_("I", n, &w[1], &rwork[inde], &work[indwrk], n, &work[indwk2],
7281
&llwrk2, &rwork[indrwk], &llrwk, &iwork[1], liwork, info);
7282
zunmtr_("L", uplo, "N", n, n, &a[a_offset], lda, &work[indtau], &work[
7283
indwrk], n, &work[indwk2], &llwrk2, &iinfo);
7284
zlacpy_("A", n, n, &work[indwrk], n, &a[a_offset], lda);
7285
}
7286
7287
/* If matrix was scaled, then rescale eigenvalues appropriately. */
7288
7289
if (iscale == 1) {
7290
if (*info == 0) {
7291
imax = *n;
7292
} else {
7293
imax = *info - 1;
7294
}
7295
d__1 = 1. / sigma;
7296
dscal_(&imax, &d__1, &w[1], &c__1);
7297
}
7298
7299
work[1].r = (doublereal) lopt, work[1].i = 0.;
7300
rwork[1] = (doublereal) lropt;
7301
iwork[1] = liopt;
7302
7303
return 0;
7304
7305
/* End of ZHEEVD */
7306
7307
} /* zheevd_ */
7308
7309
/* Subroutine */ int zhetd2_(char *uplo, integer *n, doublecomplex *a,
7310
integer *lda, doublereal *d__, doublereal *e, doublecomplex *tau,
7311
integer *info)
7312
{
7313
/* System generated locals */
7314
integer a_dim1, a_offset, i__1, i__2, i__3;
7315
doublereal d__1;
7316
doublecomplex z__1, z__2, z__3, z__4;
7317
7318
/* Local variables */
7319
static integer i__;
7320
static doublecomplex taui;
7321
extern /* Subroutine */ int zher2_(char *, integer *, doublecomplex *,
7322
doublecomplex *, integer *, doublecomplex *, integer *,
7323
doublecomplex *, integer *);
7324
static doublecomplex alpha;
7325
extern logical lsame_(char *, char *);
7326
extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
7327
doublecomplex *, integer *, doublecomplex *, integer *);
7328
extern /* Subroutine */ int zhemv_(char *, integer *, doublecomplex *,
7329
doublecomplex *, integer *, doublecomplex *, integer *,
7330
doublecomplex *, doublecomplex *, integer *);
7331
static logical upper;
7332
extern /* Subroutine */ int zaxpy_(integer *, doublecomplex *,
7333
doublecomplex *, integer *, doublecomplex *, integer *), xerbla_(
7334
char *, integer *), zlarfg_(integer *, doublecomplex *,
7335
doublecomplex *, integer *, doublecomplex *);
7336
7337
7338
/*
7339
-- LAPACK routine (version 3.2) --
7340
-- LAPACK is a software package provided by Univ. of Tennessee, --
7341
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
7342
November 2006
7343
7344
7345
Purpose
7346
=======
7347
7348
ZHETD2 reduces a complex Hermitian matrix A to real symmetric
7349
tridiagonal form T by a unitary similarity transformation:
7350
Q' * A * Q = T.
7351
7352
Arguments
7353
=========
7354
7355
UPLO (input) CHARACTER*1
7356
Specifies whether the upper or lower triangular part of the
7357
Hermitian matrix A is stored:
7358
= 'U': Upper triangular
7359
= 'L': Lower triangular
7360
7361
N (input) INTEGER
7362
The order of the matrix A. N >= 0.
7363
7364
A (input/output) COMPLEX*16 array, dimension (LDA,N)
7365
On entry, the Hermitian matrix A. If UPLO = 'U', the leading
7366
n-by-n upper triangular part of A contains the upper
7367
triangular part of the matrix A, and the strictly lower
7368
triangular part of A is not referenced. If UPLO = 'L', the
7369
leading n-by-n lower triangular part of A contains the lower
7370
triangular part of the matrix A, and the strictly upper
7371
triangular part of A is not referenced.
7372
On exit, if UPLO = 'U', the diagonal and first superdiagonal
7373
of A are overwritten by the corresponding elements of the
7374
tridiagonal matrix T, and the elements above the first
7375
superdiagonal, with the array TAU, represent the unitary
7376
matrix Q as a product of elementary reflectors; if UPLO
7377
= 'L', the diagonal and first subdiagonal of A are over-
7378
written by the corresponding elements of the tridiagonal
7379
matrix T, and the elements below the first subdiagonal, with
7380
the array TAU, represent the unitary matrix Q as a product
7381
of elementary reflectors. See Further Details.
7382
7383
LDA (input) INTEGER
7384
The leading dimension of the array A. LDA >= max(1,N).
7385
7386
D (output) DOUBLE PRECISION array, dimension (N)
7387
The diagonal elements of the tridiagonal matrix T:
7388
D(i) = A(i,i).
7389
7390
E (output) DOUBLE PRECISION array, dimension (N-1)
7391
The off-diagonal elements of the tridiagonal matrix T:
7392
E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'.
7393
7394
TAU (output) COMPLEX*16 array, dimension (N-1)
7395
The scalar factors of the elementary reflectors (see Further
7396
Details).
7397
7398
INFO (output) INTEGER
7399
= 0: successful exit
7400
< 0: if INFO = -i, the i-th argument had an illegal value.
7401
7402
Further Details
7403
===============
7404
7405
If UPLO = 'U', the matrix Q is represented as a product of elementary
7406
reflectors
7407
7408
Q = H(n-1) . . . H(2) H(1).
7409
7410
Each H(i) has the form
7411
7412
H(i) = I - tau * v * v'
7413
7414
where tau is a complex scalar, and v is a complex vector with
7415
v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in
7416
A(1:i-1,i+1), and tau in TAU(i).
7417
7418
If UPLO = 'L', the matrix Q is represented as a product of elementary
7419
reflectors
7420
7421
Q = H(1) H(2) . . . H(n-1).
7422
7423
Each H(i) has the form
7424
7425
H(i) = I - tau * v * v'
7426
7427
where tau is a complex scalar, and v is a complex vector with
7428
v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i),
7429
and tau in TAU(i).
7430
7431
The contents of A on exit are illustrated by the following examples
7432
with n = 5:
7433
7434
if UPLO = 'U': if UPLO = 'L':
7435
7436
( d e v2 v3 v4 ) ( d )
7437
( d e v3 v4 ) ( e d )
7438
( d e v4 ) ( v1 e d )
7439
( d e ) ( v1 v2 e d )
7440
( d ) ( v1 v2 v3 e d )
7441
7442
where d and e denote diagonal and off-diagonal elements of T, and vi
7443
denotes an element of the vector defining H(i).
7444
7445
=====================================================================
7446
7447
7448
Test the input parameters
7449
*/
7450
7451
/* Parameter adjustments */
7452
a_dim1 = *lda;
7453
a_offset = 1 + a_dim1;
7454
a -= a_offset;
7455
--d__;
7456
--e;
7457
--tau;
7458
7459
/* Function Body */
7460
*info = 0;
7461
upper = lsame_(uplo, "U");
7462
if (! upper && ! lsame_(uplo, "L")) {
7463
*info = -1;
7464
} else if (*n < 0) {
7465
*info = -2;
7466
} else if (*lda < max(1,*n)) {
7467
*info = -4;
7468
}
7469
if (*info != 0) {
7470
i__1 = -(*info);
7471
xerbla_("ZHETD2", &i__1);
7472
return 0;
7473
}
7474
7475
/* Quick return if possible */
7476
7477
if (*n <= 0) {
7478
return 0;
7479
}
7480
7481
if (upper) {
7482
7483
/* Reduce the upper triangle of A */
7484
7485
i__1 = *n + *n * a_dim1;
7486
i__2 = *n + *n * a_dim1;
7487
d__1 = a[i__2].r;
7488
a[i__1].r = d__1, a[i__1].i = 0.;
7489
for (i__ = *n - 1; i__ >= 1; --i__) {
7490
7491
/*
7492
Generate elementary reflector H(i) = I - tau * v * v'
7493
to annihilate A(1:i-1,i+1)
7494
*/
7495
7496
i__1 = i__ + (i__ + 1) * a_dim1;
7497
alpha.r = a[i__1].r, alpha.i = a[i__1].i;
7498
zlarfg_(&i__, &alpha, &a[(i__ + 1) * a_dim1 + 1], &c__1, &taui);
7499
i__1 = i__;
7500
e[i__1] = alpha.r;
7501
7502
if (taui.r != 0. || taui.i != 0.) {
7503
7504
/* Apply H(i) from both sides to A(1:i,1:i) */
7505
7506
i__1 = i__ + (i__ + 1) * a_dim1;
7507
a[i__1].r = 1., a[i__1].i = 0.;
7508
7509
/* Compute x := tau * A * v storing x in TAU(1:i) */
7510
7511
zhemv_(uplo, &i__, &taui, &a[a_offset], lda, &a[(i__ + 1) *
7512
a_dim1 + 1], &c__1, &c_b56, &tau[1], &c__1)
7513
;
7514
7515
/* Compute w := x - 1/2 * tau * (x'*v) * v */
7516
7517
z__3.r = -.5, z__3.i = -0.;
7518
z__2.r = z__3.r * taui.r - z__3.i * taui.i, z__2.i = z__3.r *
7519
taui.i + z__3.i * taui.r;
7520
zdotc_(&z__4, &i__, &tau[1], &c__1, &a[(i__ + 1) * a_dim1 + 1]
7521
, &c__1);
7522
z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r *
7523
z__4.i + z__2.i * z__4.r;
7524
alpha.r = z__1.r, alpha.i = z__1.i;
7525
zaxpy_(&i__, &alpha, &a[(i__ + 1) * a_dim1 + 1], &c__1, &tau[
7526
1], &c__1);
7527
7528
/*
7529
Apply the transformation as a rank-2 update:
7530
A := A - v * w' - w * v'
7531
*/
7532
7533
z__1.r = -1., z__1.i = -0.;
7534
zher2_(uplo, &i__, &z__1, &a[(i__ + 1) * a_dim1 + 1], &c__1, &
7535
tau[1], &c__1, &a[a_offset], lda);
7536
7537
} else {
7538
i__1 = i__ + i__ * a_dim1;
7539
i__2 = i__ + i__ * a_dim1;
7540
d__1 = a[i__2].r;
7541
a[i__1].r = d__1, a[i__1].i = 0.;
7542
}
7543
i__1 = i__ + (i__ + 1) * a_dim1;
7544
i__2 = i__;
7545
a[i__1].r = e[i__2], a[i__1].i = 0.;
7546
i__1 = i__ + 1;
7547
i__2 = i__ + 1 + (i__ + 1) * a_dim1;
7548
d__[i__1] = a[i__2].r;
7549
i__1 = i__;
7550
tau[i__1].r = taui.r, tau[i__1].i = taui.i;
7551
/* L10: */
7552
}
7553
i__1 = a_dim1 + 1;
7554
d__[1] = a[i__1].r;
7555
} else {
7556
7557
/* Reduce the lower triangle of A */
7558
7559
i__1 = a_dim1 + 1;
7560
i__2 = a_dim1 + 1;
7561
d__1 = a[i__2].r;
7562
a[i__1].r = d__1, a[i__1].i = 0.;
7563
i__1 = *n - 1;
7564
for (i__ = 1; i__ <= i__1; ++i__) {
7565
7566
/*
7567
Generate elementary reflector H(i) = I - tau * v * v'
7568
to annihilate A(i+2:n,i)
7569
*/
7570
7571
i__2 = i__ + 1 + i__ * a_dim1;
7572
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
7573
i__2 = *n - i__;
7574
/* Computing MIN */
7575
i__3 = i__ + 2;
7576
zlarfg_(&i__2, &alpha, &a[min(i__3,*n) + i__ * a_dim1], &c__1, &
7577
taui);
7578
i__2 = i__;
7579
e[i__2] = alpha.r;
7580
7581
if (taui.r != 0. || taui.i != 0.) {
7582
7583
/* Apply H(i) from both sides to A(i+1:n,i+1:n) */
7584
7585
i__2 = i__ + 1 + i__ * a_dim1;
7586
a[i__2].r = 1., a[i__2].i = 0.;
7587
7588
/* Compute x := tau * A * v storing y in TAU(i:n-1) */
7589
7590
i__2 = *n - i__;
7591
zhemv_(uplo, &i__2, &taui, &a[i__ + 1 + (i__ + 1) * a_dim1],
7592
lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b56, &tau[
7593
i__], &c__1);
7594
7595
/* Compute w := x - 1/2 * tau * (x'*v) * v */
7596
7597
z__3.r = -.5, z__3.i = -0.;
7598
z__2.r = z__3.r * taui.r - z__3.i * taui.i, z__2.i = z__3.r *
7599
taui.i + z__3.i * taui.r;
7600
i__2 = *n - i__;
7601
zdotc_(&z__4, &i__2, &tau[i__], &c__1, &a[i__ + 1 + i__ *
7602
a_dim1], &c__1);
7603
z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r *
7604
z__4.i + z__2.i * z__4.r;
7605
alpha.r = z__1.r, alpha.i = z__1.i;
7606
i__2 = *n - i__;
7607
zaxpy_(&i__2, &alpha, &a[i__ + 1 + i__ * a_dim1], &c__1, &tau[
7608
i__], &c__1);
7609
7610
/*
7611
Apply the transformation as a rank-2 update:
7612
A := A - v * w' - w * v'
7613
*/
7614
7615
i__2 = *n - i__;
7616
z__1.r = -1., z__1.i = -0.;
7617
zher2_(uplo, &i__2, &z__1, &a[i__ + 1 + i__ * a_dim1], &c__1,
7618
&tau[i__], &c__1, &a[i__ + 1 + (i__ + 1) * a_dim1],
7619
lda);
7620
7621
} else {
7622
i__2 = i__ + 1 + (i__ + 1) * a_dim1;
7623
i__3 = i__ + 1 + (i__ + 1) * a_dim1;
7624
d__1 = a[i__3].r;
7625
a[i__2].r = d__1, a[i__2].i = 0.;
7626
}
7627
i__2 = i__ + 1 + i__ * a_dim1;
7628
i__3 = i__;
7629
a[i__2].r = e[i__3], a[i__2].i = 0.;
7630
i__2 = i__;
7631
i__3 = i__ + i__ * a_dim1;
7632
d__[i__2] = a[i__3].r;
7633
i__2 = i__;
7634
tau[i__2].r = taui.r, tau[i__2].i = taui.i;
7635
/* L20: */
7636
}
7637
i__1 = *n;
7638
i__2 = *n + *n * a_dim1;
7639
d__[i__1] = a[i__2].r;
7640
}
7641
7642
return 0;
7643
7644
/* End of ZHETD2 */
7645
7646
} /* zhetd2_ */
7647
7648
/* Subroutine */ int zhetrd_(char *uplo, integer *n, doublecomplex *a,
7649
integer *lda, doublereal *d__, doublereal *e, doublecomplex *tau,
7650
doublecomplex *work, integer *lwork, integer *info)
7651
{
7652
/* System generated locals */
7653
integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
7654
doublecomplex z__1;
7655
7656
/* Local variables */
7657
static integer i__, j, nb, kk, nx, iws;
7658
extern logical lsame_(char *, char *);
7659
static integer nbmin, iinfo;
7660
static logical upper;
7661
extern /* Subroutine */ int zhetd2_(char *, integer *, doublecomplex *,
7662
integer *, doublereal *, doublereal *, doublecomplex *, integer *), zher2k_(char *, char *, integer *, integer *,
7663
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
7664
integer *, doublereal *, doublecomplex *, integer *), xerbla_(char *, integer *);
7665
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
7666
integer *, integer *, ftnlen, ftnlen);
7667
extern /* Subroutine */ int zlatrd_(char *, integer *, integer *,
7668
doublecomplex *, integer *, doublereal *, doublecomplex *,
7669
doublecomplex *, integer *);
7670
static integer ldwork, lwkopt;
7671
static logical lquery;
7672
7673
7674
/*
7675
-- LAPACK routine (version 3.2) --
7676
-- LAPACK is a software package provided by Univ. of Tennessee, --
7677
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
7678
November 2006
7679
7680
7681
Purpose
7682
=======
7683
7684
ZHETRD reduces a complex Hermitian matrix A to real symmetric
7685
tridiagonal form T by a unitary similarity transformation:
7686
Q**H * A * Q = T.
7687
7688
Arguments
7689
=========
7690
7691
UPLO (input) CHARACTER*1
7692
= 'U': Upper triangle of A is stored;
7693
= 'L': Lower triangle of A is stored.
7694
7695
N (input) INTEGER
7696
The order of the matrix A. N >= 0.
7697
7698
A (input/output) COMPLEX*16 array, dimension (LDA,N)
7699
On entry, the Hermitian matrix A. If UPLO = 'U', the leading
7700
N-by-N upper triangular part of A contains the upper
7701
triangular part of the matrix A, and the strictly lower
7702
triangular part of A is not referenced. If UPLO = 'L', the
7703
leading N-by-N lower triangular part of A contains the lower
7704
triangular part of the matrix A, and the strictly upper
7705
triangular part of A is not referenced.
7706
On exit, if UPLO = 'U', the diagonal and first superdiagonal
7707
of A are overwritten by the corresponding elements of the
7708
tridiagonal matrix T, and the elements above the first
7709
superdiagonal, with the array TAU, represent the unitary
7710
matrix Q as a product of elementary reflectors; if UPLO
7711
= 'L', the diagonal and first subdiagonal of A are over-
7712
written by the corresponding elements of the tridiagonal
7713
matrix T, and the elements below the first subdiagonal, with
7714
the array TAU, represent the unitary matrix Q as a product
7715
of elementary reflectors. See Further Details.
7716
7717
LDA (input) INTEGER
7718
The leading dimension of the array A. LDA >= max(1,N).
7719
7720
D (output) DOUBLE PRECISION array, dimension (N)
7721
The diagonal elements of the tridiagonal matrix T:
7722
D(i) = A(i,i).
7723
7724
E (output) DOUBLE PRECISION array, dimension (N-1)
7725
The off-diagonal elements of the tridiagonal matrix T:
7726
E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'.
7727
7728
TAU (output) COMPLEX*16 array, dimension (N-1)
7729
The scalar factors of the elementary reflectors (see Further
7730
Details).
7731
7732
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
7733
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
7734
7735
LWORK (input) INTEGER
7736
The dimension of the array WORK. LWORK >= 1.
7737
For optimum performance LWORK >= N*NB, where NB is the
7738
optimal blocksize.
7739
7740
If LWORK = -1, then a workspace query is assumed; the routine
7741
only calculates the optimal size of the WORK array, returns
7742
this value as the first entry of the WORK array, and no error
7743
message related to LWORK is issued by XERBLA.
7744
7745
INFO (output) INTEGER
7746
= 0: successful exit
7747
< 0: if INFO = -i, the i-th argument had an illegal value
7748
7749
Further Details
7750
===============
7751
7752
If UPLO = 'U', the matrix Q is represented as a product of elementary
7753
reflectors
7754
7755
Q = H(n-1) . . . H(2) H(1).
7756
7757
Each H(i) has the form
7758
7759
H(i) = I - tau * v * v'
7760
7761
where tau is a complex scalar, and v is a complex vector with
7762
v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in
7763
A(1:i-1,i+1), and tau in TAU(i).
7764
7765
If UPLO = 'L', the matrix Q is represented as a product of elementary
7766
reflectors
7767
7768
Q = H(1) H(2) . . . H(n-1).
7769
7770
Each H(i) has the form
7771
7772
H(i) = I - tau * v * v'
7773
7774
where tau is a complex scalar, and v is a complex vector with
7775
v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i),
7776
and tau in TAU(i).
7777
7778
The contents of A on exit are illustrated by the following examples
7779
with n = 5:
7780
7781
if UPLO = 'U': if UPLO = 'L':
7782
7783
( d e v2 v3 v4 ) ( d )
7784
( d e v3 v4 ) ( e d )
7785
( d e v4 ) ( v1 e d )
7786
( d e ) ( v1 v2 e d )
7787
( d ) ( v1 v2 v3 e d )
7788
7789
where d and e denote diagonal and off-diagonal elements of T, and vi
7790
denotes an element of the vector defining H(i).
7791
7792
=====================================================================
7793
7794
7795
Test the input parameters
7796
*/
7797
7798
/* Parameter adjustments */
7799
a_dim1 = *lda;
7800
a_offset = 1 + a_dim1;
7801
a -= a_offset;
7802
--d__;
7803
--e;
7804
--tau;
7805
--work;
7806
7807
/* Function Body */
7808
*info = 0;
7809
upper = lsame_(uplo, "U");
7810
lquery = *lwork == -1;
7811
if (! upper && ! lsame_(uplo, "L")) {
7812
*info = -1;
7813
} else if (*n < 0) {
7814
*info = -2;
7815
} else if (*lda < max(1,*n)) {
7816
*info = -4;
7817
} else if (*lwork < 1 && ! lquery) {
7818
*info = -9;
7819
}
7820
7821
if (*info == 0) {
7822
7823
/* Determine the block size. */
7824
7825
nb = ilaenv_(&c__1, "ZHETRD", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6,
7826
(ftnlen)1);
7827
lwkopt = *n * nb;
7828
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
7829
}
7830
7831
if (*info != 0) {
7832
i__1 = -(*info);
7833
xerbla_("ZHETRD", &i__1);
7834
return 0;
7835
} else if (lquery) {
7836
return 0;
7837
}
7838
7839
/* Quick return if possible */
7840
7841
if (*n == 0) {
7842
work[1].r = 1., work[1].i = 0.;
7843
return 0;
7844
}
7845
7846
nx = *n;
7847
iws = 1;
7848
if (nb > 1 && nb < *n) {
7849
7850
/*
7851
Determine when to cross over from blocked to unblocked code
7852
(last block is always handled by unblocked code).
7853
7854
Computing MAX
7855
*/
7856
i__1 = nb, i__2 = ilaenv_(&c__3, "ZHETRD", uplo, n, &c_n1, &c_n1, &
7857
c_n1, (ftnlen)6, (ftnlen)1);
7858
nx = max(i__1,i__2);
7859
if (nx < *n) {
7860
7861
/* Determine if workspace is large enough for blocked code. */
7862
7863
ldwork = *n;
7864
iws = ldwork * nb;
7865
if (*lwork < iws) {
7866
7867
/*
7868
Not enough workspace to use optimal NB: determine the
7869
minimum value of NB, and reduce NB or force use of
7870
unblocked code by setting NX = N.
7871
7872
Computing MAX
7873
*/
7874
i__1 = *lwork / ldwork;
7875
nb = max(i__1,1);
7876
nbmin = ilaenv_(&c__2, "ZHETRD", uplo, n, &c_n1, &c_n1, &c_n1,
7877
(ftnlen)6, (ftnlen)1);
7878
if (nb < nbmin) {
7879
nx = *n;
7880
}
7881
}
7882
} else {
7883
nx = *n;
7884
}
7885
} else {
7886
nb = 1;
7887
}
7888
7889
if (upper) {
7890
7891
/*
7892
Reduce the upper triangle of A.
7893
Columns 1:kk are handled by the unblocked method.
7894
*/
7895
7896
kk = *n - (*n - nx + nb - 1) / nb * nb;
7897
i__1 = kk + 1;
7898
i__2 = -nb;
7899
for (i__ = *n - nb + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ +=
7900
i__2) {
7901
7902
/*
7903
Reduce columns i:i+nb-1 to tridiagonal form and form the
7904
matrix W which is needed to update the unreduced part of
7905
the matrix
7906
*/
7907
7908
i__3 = i__ + nb - 1;
7909
zlatrd_(uplo, &i__3, &nb, &a[a_offset], lda, &e[1], &tau[1], &
7910
work[1], &ldwork);
7911
7912
/*
7913
Update the unreduced submatrix A(1:i-1,1:i-1), using an
7914
update of the form: A := A - V*W' - W*V'
7915
*/
7916
7917
i__3 = i__ - 1;
7918
z__1.r = -1., z__1.i = -0.;
7919
zher2k_(uplo, "No transpose", &i__3, &nb, &z__1, &a[i__ * a_dim1
7920
+ 1], lda, &work[1], &ldwork, &c_b1034, &a[a_offset], lda);
7921
7922
/*
7923
Copy superdiagonal elements back into A, and diagonal
7924
elements into D
7925
*/
7926
7927
i__3 = i__ + nb - 1;
7928
for (j = i__; j <= i__3; ++j) {
7929
i__4 = j - 1 + j * a_dim1;
7930
i__5 = j - 1;
7931
a[i__4].r = e[i__5], a[i__4].i = 0.;
7932
i__4 = j;
7933
i__5 = j + j * a_dim1;
7934
d__[i__4] = a[i__5].r;
7935
/* L10: */
7936
}
7937
/* L20: */
7938
}
7939
7940
/* Use unblocked code to reduce the last or only block */
7941
7942
zhetd2_(uplo, &kk, &a[a_offset], lda, &d__[1], &e[1], &tau[1], &iinfo);
7943
} else {
7944
7945
/* Reduce the lower triangle of A */
7946
7947
i__2 = *n - nx;
7948
i__1 = nb;
7949
for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) {
7950
7951
/*
7952
Reduce columns i:i+nb-1 to tridiagonal form and form the
7953
matrix W which is needed to update the unreduced part of
7954
the matrix
7955
*/
7956
7957
i__3 = *n - i__ + 1;
7958
zlatrd_(uplo, &i__3, &nb, &a[i__ + i__ * a_dim1], lda, &e[i__], &
7959
tau[i__], &work[1], &ldwork);
7960
7961
/*
7962
Update the unreduced submatrix A(i+nb:n,i+nb:n), using
7963
an update of the form: A := A - V*W' - W*V'
7964
*/
7965
7966
i__3 = *n - i__ - nb + 1;
7967
z__1.r = -1., z__1.i = -0.;
7968
zher2k_(uplo, "No transpose", &i__3, &nb, &z__1, &a[i__ + nb +
7969
i__ * a_dim1], lda, &work[nb + 1], &ldwork, &c_b1034, &a[
7970
i__ + nb + (i__ + nb) * a_dim1], lda);
7971
7972
/*
7973
Copy subdiagonal elements back into A, and diagonal
7974
elements into D
7975
*/
7976
7977
i__3 = i__ + nb - 1;
7978
for (j = i__; j <= i__3; ++j) {
7979
i__4 = j + 1 + j * a_dim1;
7980
i__5 = j;
7981
a[i__4].r = e[i__5], a[i__4].i = 0.;
7982
i__4 = j;
7983
i__5 = j + j * a_dim1;
7984
d__[i__4] = a[i__5].r;
7985
/* L30: */
7986
}
7987
/* L40: */
7988
}
7989
7990
/* Use unblocked code to reduce the last or only block */
7991
7992
i__1 = *n - i__ + 1;
7993
zhetd2_(uplo, &i__1, &a[i__ + i__ * a_dim1], lda, &d__[i__], &e[i__],
7994
&tau[i__], &iinfo);
7995
}
7996
7997
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
7998
return 0;
7999
8000
/* End of ZHETRD */
8001
8002
} /* zhetrd_ */
8003
8004
/* Subroutine */ int zhseqr_(char *job, char *compz, integer *n, integer *ilo,
8005
integer *ihi, doublecomplex *h__, integer *ldh, doublecomplex *w,
8006
doublecomplex *z__, integer *ldz, doublecomplex *work, integer *lwork,
8007
integer *info)
8008
{
8009
/* System generated locals */
8010
address a__1[2];
8011
integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3[2];
8012
doublereal d__1, d__2, d__3;
8013
doublecomplex z__1;
8014
char ch__1[2];
8015
8016
/* Local variables */
8017
static doublecomplex hl[2401] /* was [49][49] */;
8018
static integer kbot, nmin;
8019
extern logical lsame_(char *, char *);
8020
static logical initz;
8021
static doublecomplex workl[49];
8022
static logical wantt, wantz;
8023
extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
8024
doublecomplex *, integer *), zlaqr0_(logical *, logical *,
8025
integer *, integer *, integer *, doublecomplex *, integer *,
8026
doublecomplex *, integer *, integer *, doublecomplex *, integer *,
8027
doublecomplex *, integer *, integer *), xerbla_(char *, integer *
8028
);
8029
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
8030
integer *, integer *, ftnlen, ftnlen);
8031
extern /* Subroutine */ int zlahqr_(logical *, logical *, integer *,
8032
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
8033
integer *, integer *, doublecomplex *, integer *, integer *),
8034
zlacpy_(char *, integer *, integer *, doublecomplex *, integer *,
8035
doublecomplex *, integer *), zlaset_(char *, integer *,
8036
integer *, doublecomplex *, doublecomplex *, doublecomplex *,
8037
integer *);
8038
static logical lquery;
8039
8040
8041
/*
8042
-- LAPACK computational routine (version 3.2.2) --
8043
Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
8044
June 2010
8045
8046
Purpose
8047
=======
8048
8049
ZHSEQR computes the eigenvalues of a Hessenberg matrix H
8050
and, optionally, the matrices T and Z from the Schur decomposition
8051
H = Z T Z**H, where T is an upper triangular matrix (the
8052
Schur form), and Z is the unitary matrix of Schur vectors.
8053
8054
Optionally Z may be postmultiplied into an input unitary
8055
matrix Q so that this routine can give the Schur factorization
8056
of a matrix A which has been reduced to the Hessenberg form H
8057
by the unitary matrix Q: A = Q*H*Q**H = (QZ)*H*(QZ)**H.
8058
8059
Arguments
8060
=========
8061
8062
JOB (input) CHARACTER*1
8063
= 'E': compute eigenvalues only;
8064
= 'S': compute eigenvalues and the Schur form T.
8065
8066
COMPZ (input) CHARACTER*1
8067
= 'N': no Schur vectors are computed;
8068
= 'I': Z is initialized to the unit matrix and the matrix Z
8069
of Schur vectors of H is returned;
8070
= 'V': Z must contain an unitary matrix Q on entry, and
8071
the product Q*Z is returned.
8072
8073
N (input) INTEGER
8074
The order of the matrix H. N .GE. 0.
8075
8076
ILO (input) INTEGER
8077
IHI (input) INTEGER
8078
It is assumed that H is already upper triangular in rows
8079
and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
8080
set by a previous call to ZGEBAL, and then passed to ZGEHRD
8081
when the matrix output by ZGEBAL is reduced to Hessenberg
8082
form. Otherwise ILO and IHI should be set to 1 and N
8083
respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
8084
If N = 0, then ILO = 1 and IHI = 0.
8085
8086
H (input/output) COMPLEX*16 array, dimension (LDH,N)
8087
On entry, the upper Hessenberg matrix H.
8088
On exit, if INFO = 0 and JOB = 'S', H contains the upper
8089
triangular matrix T from the Schur decomposition (the
8090
Schur form). If INFO = 0 and JOB = 'E', the contents of
8091
H are unspecified on exit. (The output value of H when
8092
INFO.GT.0 is given under the description of INFO below.)
8093
8094
Unlike earlier versions of ZHSEQR, this subroutine may
8095
explicitly H(i,j) = 0 for i.GT.j and j = 1, 2, ... ILO-1
8096
or j = IHI+1, IHI+2, ... N.
8097
8098
LDH (input) INTEGER
8099
The leading dimension of the array H. LDH .GE. max(1,N).
8100
8101
W (output) COMPLEX*16 array, dimension (N)
8102
The computed eigenvalues. If JOB = 'S', the eigenvalues are
8103
stored in the same order as on the diagonal of the Schur
8104
form returned in H, with W(i) = H(i,i).
8105
8106
Z (input/output) COMPLEX*16 array, dimension (LDZ,N)
8107
If COMPZ = 'N', Z is not referenced.
8108
If COMPZ = 'I', on entry Z need not be set and on exit,
8109
if INFO = 0, Z contains the unitary matrix Z of the Schur
8110
vectors of H. If COMPZ = 'V', on entry Z must contain an
8111
N-by-N matrix Q, which is assumed to be equal to the unit
8112
matrix except for the submatrix Z(ILO:IHI,ILO:IHI). On exit,
8113
if INFO = 0, Z contains Q*Z.
8114
Normally Q is the unitary matrix generated by ZUNGHR
8115
after the call to ZGEHRD which formed the Hessenberg matrix
8116
H. (The output value of Z when INFO.GT.0 is given under
8117
the description of INFO below.)
8118
8119
LDZ (input) INTEGER
8120
The leading dimension of the array Z. if COMPZ = 'I' or
8121
COMPZ = 'V', then LDZ.GE.MAX(1,N). Otherwize, LDZ.GE.1.
8122
8123
WORK (workspace/output) COMPLEX*16 array, dimension (LWORK)
8124
On exit, if INFO = 0, WORK(1) returns an estimate of
8125
the optimal value for LWORK.
8126
8127
LWORK (input) INTEGER
8128
The dimension of the array WORK. LWORK .GE. max(1,N)
8129
is sufficient and delivers very good and sometimes
8130
optimal performance. However, LWORK as large as 11*N
8131
may be required for optimal performance. A workspace
8132
query is recommended to determine the optimal workspace
8133
size.
8134
8135
If LWORK = -1, then ZHSEQR does a workspace query.
8136
In this case, ZHSEQR checks the input parameters and
8137
estimates the optimal workspace size for the given
8138
values of N, ILO and IHI. The estimate is returned
8139
in WORK(1). No error message related to LWORK is
8140
issued by XERBLA. Neither H nor Z are accessed.
8141
8142
8143
INFO (output) INTEGER
8144
= 0: successful exit
8145
.LT. 0: if INFO = -i, the i-th argument had an illegal
8146
value
8147
.GT. 0: if INFO = i, ZHSEQR failed to compute all of
8148
the eigenvalues. Elements 1:ilo-1 and i+1:n of WR
8149
and WI contain those eigenvalues which have been
8150
successfully computed. (Failures are rare.)
8151
8152
If INFO .GT. 0 and JOB = 'E', then on exit, the
8153
remaining unconverged eigenvalues are the eigen-
8154
values of the upper Hessenberg matrix rows and
8155
columns ILO through INFO of the final, output
8156
value of H.
8157
8158
If INFO .GT. 0 and JOB = 'S', then on exit
8159
8160
(*) (initial value of H)*U = U*(final value of H)
8161
8162
where U is a unitary matrix. The final
8163
value of H is upper Hessenberg and triangular in
8164
rows and columns INFO+1 through IHI.
8165
8166
If INFO .GT. 0 and COMPZ = 'V', then on exit
8167
8168
(final value of Z) = (initial value of Z)*U
8169
8170
where U is the unitary matrix in (*) (regard-
8171
less of the value of JOB.)
8172
8173
If INFO .GT. 0 and COMPZ = 'I', then on exit
8174
(final value of Z) = U
8175
where U is the unitary matrix in (*) (regard-
8176
less of the value of JOB.)
8177
8178
If INFO .GT. 0 and COMPZ = 'N', then Z is not
8179
accessed.
8180
8181
================================================================
8182
Default values supplied by
8183
ILAENV(ISPEC,'ZHSEQR',JOB(:1)//COMPZ(:1),N,ILO,IHI,LWORK).
8184
It is suggested that these defaults be adjusted in order
8185
to attain best performance in each particular
8186
computational environment.
8187
8188
ISPEC=12: The ZLAHQR vs ZLAQR0 crossover point.
8189
Default: 75. (Must be at least 11.)
8190
8191
ISPEC=13: Recommended deflation window size.
8192
This depends on ILO, IHI and NS. NS is the
8193
number of simultaneous shifts returned
8194
by ILAENV(ISPEC=15). (See ISPEC=15 below.)
8195
The default for (IHI-ILO+1).LE.500 is NS.
8196
The default for (IHI-ILO+1).GT.500 is 3*NS/2.
8197
8198
ISPEC=14: Nibble crossover point. (See IPARMQ for
8199
details.) Default: 14% of deflation window
8200
size.
8201
8202
ISPEC=15: Number of simultaneous shifts in a multishift
8203
QR iteration.
8204
8205
If IHI-ILO+1 is ...
8206
8207
greater than ...but less ... the
8208
or equal to ... than default is
8209
8210
1 30 NS = 2(+)
8211
30 60 NS = 4(+)
8212
60 150 NS = 10(+)
8213
150 590 NS = **
8214
590 3000 NS = 64
8215
3000 6000 NS = 128
8216
6000 infinity NS = 256
8217
8218
(+) By default some or all matrices of this order
8219
are passed to the implicit double shift routine
8220
ZLAHQR and this parameter is ignored. See
8221
ISPEC=12 above and comments in IPARMQ for
8222
details.
8223
8224
(**) The asterisks (**) indicate an ad-hoc
8225
function of N increasing from 10 to 64.
8226
8227
ISPEC=16: Select structured matrix multiply.
8228
If the number of simultaneous shifts (specified
8229
by ISPEC=15) is less than 14, then the default
8230
for ISPEC=16 is 0. Otherwise the default for
8231
ISPEC=16 is 2.
8232
8233
================================================================
8234
Based on contributions by
8235
Karen Braman and Ralph Byers, Department of Mathematics,
8236
University of Kansas, USA
8237
8238
================================================================
8239
References:
8240
K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
8241
Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
8242
Performance, SIAM Journal of Matrix Analysis, volume 23, pages
8243
929--947, 2002.
8244
8245
K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
8246
Algorithm Part II: Aggressive Early Deflation, SIAM Journal
8247
of Matrix Analysis, volume 23, pages 948--973, 2002.
8248
8249
================================================================
8250
8251
==== Matrices of order NTINY or smaller must be processed by
8252
. ZLAHQR because of insufficient subdiagonal scratch space.
8253
. (This is a hard limit.) ====
8254
8255
==== NL allocates some local workspace to help small matrices
8256
. through a rare ZLAHQR failure. NL .GT. NTINY = 11 is
8257
. required and NL .LE. NMIN = ILAENV(ISPEC=12,...) is recom-
8258
. mended. (The default value of NMIN is 75.) Using NL = 49
8259
. allows up to six simultaneous shifts and a 16-by-16
8260
. deflation window. ====
8261
8262
==== Decode and check the input parameters. ====
8263
*/
8264
8265
/* Parameter adjustments */
8266
h_dim1 = *ldh;
8267
h_offset = 1 + h_dim1;
8268
h__ -= h_offset;
8269
--w;
8270
z_dim1 = *ldz;
8271
z_offset = 1 + z_dim1;
8272
z__ -= z_offset;
8273
--work;
8274
8275
/* Function Body */
8276
wantt = lsame_(job, "S");
8277
initz = lsame_(compz, "I");
8278
wantz = initz || lsame_(compz, "V");
8279
d__1 = (doublereal) max(1,*n);
8280
z__1.r = d__1, z__1.i = 0.;
8281
work[1].r = z__1.r, work[1].i = z__1.i;
8282
lquery = *lwork == -1;
8283
8284
*info = 0;
8285
if (! lsame_(job, "E") && ! wantt) {
8286
*info = -1;
8287
} else if (! lsame_(compz, "N") && ! wantz) {
8288
*info = -2;
8289
} else if (*n < 0) {
8290
*info = -3;
8291
} else if (*ilo < 1 || *ilo > max(1,*n)) {
8292
*info = -4;
8293
} else if (*ihi < min(*ilo,*n) || *ihi > *n) {
8294
*info = -5;
8295
} else if (*ldh < max(1,*n)) {
8296
*info = -7;
8297
} else if (*ldz < 1 || wantz && *ldz < max(1,*n)) {
8298
*info = -10;
8299
} else if (*lwork < max(1,*n) && ! lquery) {
8300
*info = -12;
8301
}
8302
8303
if (*info != 0) {
8304
8305
/* ==== Quick return in case of invalid argument. ==== */
8306
8307
i__1 = -(*info);
8308
xerbla_("ZHSEQR", &i__1);
8309
return 0;
8310
8311
} else if (*n == 0) {
8312
8313
/* ==== Quick return in case N = 0; nothing to do. ==== */
8314
8315
return 0;
8316
8317
} else if (lquery) {
8318
8319
/* ==== Quick return in case of a workspace query ==== */
8320
8321
zlaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1], ilo,
8322
ihi, &z__[z_offset], ldz, &work[1], lwork, info);
8323
/*
8324
==== Ensure reported workspace size is backward-compatible with
8325
. previous LAPACK versions. ====
8326
Computing MAX
8327
*/
8328
d__2 = work[1].r, d__3 = (doublereal) max(1,*n);
8329
d__1 = max(d__2,d__3);
8330
z__1.r = d__1, z__1.i = 0.;
8331
work[1].r = z__1.r, work[1].i = z__1.i;
8332
return 0;
8333
8334
} else {
8335
8336
/* ==== copy eigenvalues isolated by ZGEBAL ==== */
8337
8338
if (*ilo > 1) {
8339
i__1 = *ilo - 1;
8340
i__2 = *ldh + 1;
8341
zcopy_(&i__1, &h__[h_offset], &i__2, &w[1], &c__1);
8342
}
8343
if (*ihi < *n) {
8344
i__1 = *n - *ihi;
8345
i__2 = *ldh + 1;
8346
zcopy_(&i__1, &h__[*ihi + 1 + (*ihi + 1) * h_dim1], &i__2, &w[*
8347
ihi + 1], &c__1);
8348
}
8349
8350
/* ==== Initialize Z, if requested ==== */
8351
8352
if (initz) {
8353
zlaset_("A", n, n, &c_b56, &c_b57, &z__[z_offset], ldz)
8354
;
8355
}
8356
8357
/* ==== Quick return if possible ==== */
8358
8359
if (*ilo == *ihi) {
8360
i__1 = *ilo;
8361
i__2 = *ilo + *ilo * h_dim1;
8362
w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
8363
return 0;
8364
}
8365
8366
/*
8367
==== ZLAHQR/ZLAQR0 crossover point ====
8368
8369
Writing concatenation
8370
*/
8371
i__3[0] = 1, a__1[0] = job;
8372
i__3[1] = 1, a__1[1] = compz;
8373
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
8374
nmin = ilaenv_(&c__12, "ZHSEQR", ch__1, n, ilo, ihi, lwork, (ftnlen)6,
8375
(ftnlen)2);
8376
nmin = max(11,nmin);
8377
8378
/* ==== ZLAQR0 for big matrices; ZLAHQR for small ones ==== */
8379
8380
if (*n > nmin) {
8381
zlaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1],
8382
ilo, ihi, &z__[z_offset], ldz, &work[1], lwork, info);
8383
} else {
8384
8385
/* ==== Small matrix ==== */
8386
8387
zlahqr_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1],
8388
ilo, ihi, &z__[z_offset], ldz, info);
8389
8390
if (*info > 0) {
8391
8392
/*
8393
==== A rare ZLAHQR failure! ZLAQR0 sometimes succeeds
8394
. when ZLAHQR fails. ====
8395
*/
8396
8397
kbot = *info;
8398
8399
if (*n >= 49) {
8400
8401
/*
8402
==== Larger matrices have enough subdiagonal scratch
8403
. space to call ZLAQR0 directly. ====
8404
*/
8405
8406
zlaqr0_(&wantt, &wantz, n, ilo, &kbot, &h__[h_offset],
8407
ldh, &w[1], ilo, ihi, &z__[z_offset], ldz, &work[
8408
1], lwork, info);
8409
8410
} else {
8411
8412
/*
8413
==== Tiny matrices don't have enough subdiagonal
8414
. scratch space to benefit from ZLAQR0. Hence,
8415
. tiny matrices must be copied into a larger
8416
. array before calling ZLAQR0. ====
8417
*/
8418
8419
zlacpy_("A", n, n, &h__[h_offset], ldh, hl, &c__49);
8420
i__1 = *n + 1 + *n * 49 - 50;
8421
hl[i__1].r = 0., hl[i__1].i = 0.;
8422
i__1 = 49 - *n;
8423
zlaset_("A", &c__49, &i__1, &c_b56, &c_b56, &hl[(*n + 1) *
8424
49 - 49], &c__49);
8425
zlaqr0_(&wantt, &wantz, &c__49, ilo, &kbot, hl, &c__49, &
8426
w[1], ilo, ihi, &z__[z_offset], ldz, workl, &
8427
c__49, info);
8428
if (wantt || *info != 0) {
8429
zlacpy_("A", n, n, hl, &c__49, &h__[h_offset], ldh);
8430
}
8431
}
8432
}
8433
}
8434
8435
/* ==== Clear out the trash, if necessary. ==== */
8436
8437
if ((wantt || *info != 0) && *n > 2) {
8438
i__1 = *n - 2;
8439
i__2 = *n - 2;
8440
zlaset_("L", &i__1, &i__2, &c_b56, &c_b56, &h__[h_dim1 + 3], ldh);
8441
}
8442
8443
/*
8444
==== Ensure reported workspace size is backward-compatible with
8445
. previous LAPACK versions. ====
8446
8447
Computing MAX
8448
*/
8449
d__2 = (doublereal) max(1,*n), d__3 = work[1].r;
8450
d__1 = max(d__2,d__3);
8451
z__1.r = d__1, z__1.i = 0.;
8452
work[1].r = z__1.r, work[1].i = z__1.i;
8453
}
8454
8455
/* ==== End of ZHSEQR ==== */
8456
8457
return 0;
8458
} /* zhseqr_ */
8459
8460
/* Subroutine */ int zlabrd_(integer *m, integer *n, integer *nb,
8461
doublecomplex *a, integer *lda, doublereal *d__, doublereal *e,
8462
doublecomplex *tauq, doublecomplex *taup, doublecomplex *x, integer *
8463
ldx, doublecomplex *y, integer *ldy)
8464
{
8465
/* System generated locals */
8466
integer a_dim1, a_offset, x_dim1, x_offset, y_dim1, y_offset, i__1, i__2,
8467
i__3;
8468
doublecomplex z__1;
8469
8470
/* Local variables */
8471
static integer i__;
8472
static doublecomplex alpha;
8473
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
8474
doublecomplex *, integer *), zgemv_(char *, integer *, integer *,
8475
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
8476
integer *, doublecomplex *, doublecomplex *, integer *),
8477
zlarfg_(integer *, doublecomplex *, doublecomplex *, integer *,
8478
doublecomplex *), zlacgv_(integer *, doublecomplex *, integer *);
8479
8480
8481
/*
8482
-- LAPACK auxiliary routine (version 3.2) --
8483
-- LAPACK is a software package provided by Univ. of Tennessee, --
8484
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
8485
November 2006
8486
8487
8488
Purpose
8489
=======
8490
8491
ZLABRD reduces the first NB rows and columns of a complex general
8492
m by n matrix A to upper or lower real bidiagonal form by a unitary
8493
transformation Q' * A * P, and returns the matrices X and Y which
8494
are needed to apply the transformation to the unreduced part of A.
8495
8496
If m >= n, A is reduced to upper bidiagonal form; if m < n, to lower
8497
bidiagonal form.
8498
8499
This is an auxiliary routine called by ZGEBRD
8500
8501
Arguments
8502
=========
8503
8504
M (input) INTEGER
8505
The number of rows in the matrix A.
8506
8507
N (input) INTEGER
8508
The number of columns in the matrix A.
8509
8510
NB (input) INTEGER
8511
The number of leading rows and columns of A to be reduced.
8512
8513
A (input/output) COMPLEX*16 array, dimension (LDA,N)
8514
On entry, the m by n general matrix to be reduced.
8515
On exit, the first NB rows and columns of the matrix are
8516
overwritten; the rest of the array is unchanged.
8517
If m >= n, elements on and below the diagonal in the first NB
8518
columns, with the array TAUQ, represent the unitary
8519
matrix Q as a product of elementary reflectors; and
8520
elements above the diagonal in the first NB rows, with the
8521
array TAUP, represent the unitary matrix P as a product
8522
of elementary reflectors.
8523
If m < n, elements below the diagonal in the first NB
8524
columns, with the array TAUQ, represent the unitary
8525
matrix Q as a product of elementary reflectors, and
8526
elements on and above the diagonal in the first NB rows,
8527
with the array TAUP, represent the unitary matrix P as
8528
a product of elementary reflectors.
8529
See Further Details.
8530
8531
LDA (input) INTEGER
8532
The leading dimension of the array A. LDA >= max(1,M).
8533
8534
D (output) DOUBLE PRECISION array, dimension (NB)
8535
The diagonal elements of the first NB rows and columns of
8536
the reduced matrix. D(i) = A(i,i).
8537
8538
E (output) DOUBLE PRECISION array, dimension (NB)
8539
The off-diagonal elements of the first NB rows and columns of
8540
the reduced matrix.
8541
8542
TAUQ (output) COMPLEX*16 array dimension (NB)
8543
The scalar factors of the elementary reflectors which
8544
represent the unitary matrix Q. See Further Details.
8545
8546
TAUP (output) COMPLEX*16 array, dimension (NB)
8547
The scalar factors of the elementary reflectors which
8548
represent the unitary matrix P. See Further Details.
8549
8550
X (output) COMPLEX*16 array, dimension (LDX,NB)
8551
The m-by-nb matrix X required to update the unreduced part
8552
of A.
8553
8554
LDX (input) INTEGER
8555
The leading dimension of the array X. LDX >= max(1,M).
8556
8557
Y (output) COMPLEX*16 array, dimension (LDY,NB)
8558
The n-by-nb matrix Y required to update the unreduced part
8559
of A.
8560
8561
LDY (input) INTEGER
8562
The leading dimension of the array Y. LDY >= max(1,N).
8563
8564
Further Details
8565
===============
8566
8567
The matrices Q and P are represented as products of elementary
8568
reflectors:
8569
8570
Q = H(1) H(2) . . . H(nb) and P = G(1) G(2) . . . G(nb)
8571
8572
Each H(i) and G(i) has the form:
8573
8574
H(i) = I - tauq * v * v' and G(i) = I - taup * u * u'
8575
8576
where tauq and taup are complex scalars, and v and u are complex
8577
vectors.
8578
8579
If m >= n, v(1:i-1) = 0, v(i) = 1, and v(i:m) is stored on exit in
8580
A(i:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+1:n) is stored on exit in
8581
A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
8582
8583
If m < n, v(1:i) = 0, v(i+1) = 1, and v(i+1:m) is stored on exit in
8584
A(i+2:m,i); u(1:i-1) = 0, u(i) = 1, and u(i:n) is stored on exit in
8585
A(i,i+1:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
8586
8587
The elements of the vectors v and u together form the m-by-nb matrix
8588
V and the nb-by-n matrix U' which are needed, with X and Y, to apply
8589
the transformation to the unreduced part of the matrix, using a block
8590
update of the form: A := A - V*Y' - X*U'.
8591
8592
The contents of A on exit are illustrated by the following examples
8593
with nb = 2:
8594
8595
m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n):
8596
8597
( 1 1 u1 u1 u1 ) ( 1 u1 u1 u1 u1 u1 )
8598
( v1 1 1 u2 u2 ) ( 1 1 u2 u2 u2 u2 )
8599
( v1 v2 a a a ) ( v1 1 a a a a )
8600
( v1 v2 a a a ) ( v1 v2 a a a a )
8601
( v1 v2 a a a ) ( v1 v2 a a a a )
8602
( v1 v2 a a a )
8603
8604
where a denotes an element of the original matrix which is unchanged,
8605
vi denotes an element of the vector defining H(i), and ui an element
8606
of the vector defining G(i).
8607
8608
=====================================================================
8609
8610
8611
Quick return if possible
8612
*/
8613
8614
/* Parameter adjustments */
8615
a_dim1 = *lda;
8616
a_offset = 1 + a_dim1;
8617
a -= a_offset;
8618
--d__;
8619
--e;
8620
--tauq;
8621
--taup;
8622
x_dim1 = *ldx;
8623
x_offset = 1 + x_dim1;
8624
x -= x_offset;
8625
y_dim1 = *ldy;
8626
y_offset = 1 + y_dim1;
8627
y -= y_offset;
8628
8629
/* Function Body */
8630
if (*m <= 0 || *n <= 0) {
8631
return 0;
8632
}
8633
8634
if (*m >= *n) {
8635
8636
/* Reduce to upper bidiagonal form */
8637
8638
i__1 = *nb;
8639
for (i__ = 1; i__ <= i__1; ++i__) {
8640
8641
/* Update A(i:m,i) */
8642
8643
i__2 = i__ - 1;
8644
zlacgv_(&i__2, &y[i__ + y_dim1], ldy);
8645
i__2 = *m - i__ + 1;
8646
i__3 = i__ - 1;
8647
z__1.r = -1., z__1.i = -0.;
8648
zgemv_("No transpose", &i__2, &i__3, &z__1, &a[i__ + a_dim1], lda,
8649
&y[i__ + y_dim1], ldy, &c_b57, &a[i__ + i__ * a_dim1], &
8650
c__1);
8651
i__2 = i__ - 1;
8652
zlacgv_(&i__2, &y[i__ + y_dim1], ldy);
8653
i__2 = *m - i__ + 1;
8654
i__3 = i__ - 1;
8655
z__1.r = -1., z__1.i = -0.;
8656
zgemv_("No transpose", &i__2, &i__3, &z__1, &x[i__ + x_dim1], ldx,
8657
&a[i__ * a_dim1 + 1], &c__1, &c_b57, &a[i__ + i__ *
8658
a_dim1], &c__1);
8659
8660
/* Generate reflection Q(i) to annihilate A(i+1:m,i) */
8661
8662
i__2 = i__ + i__ * a_dim1;
8663
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
8664
i__2 = *m - i__ + 1;
8665
/* Computing MIN */
8666
i__3 = i__ + 1;
8667
zlarfg_(&i__2, &alpha, &a[min(i__3,*m) + i__ * a_dim1], &c__1, &
8668
tauq[i__]);
8669
i__2 = i__;
8670
d__[i__2] = alpha.r;
8671
if (i__ < *n) {
8672
i__2 = i__ + i__ * a_dim1;
8673
a[i__2].r = 1., a[i__2].i = 0.;
8674
8675
/* Compute Y(i+1:n,i) */
8676
8677
i__2 = *m - i__ + 1;
8678
i__3 = *n - i__;
8679
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &a[i__ + (
8680
i__ + 1) * a_dim1], lda, &a[i__ + i__ * a_dim1], &
8681
c__1, &c_b56, &y[i__ + 1 + i__ * y_dim1], &c__1);
8682
i__2 = *m - i__ + 1;
8683
i__3 = i__ - 1;
8684
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &a[i__ +
8685
a_dim1], lda, &a[i__ + i__ * a_dim1], &c__1, &c_b56, &
8686
y[i__ * y_dim1 + 1], &c__1);
8687
i__2 = *n - i__;
8688
i__3 = i__ - 1;
8689
z__1.r = -1., z__1.i = -0.;
8690
zgemv_("No transpose", &i__2, &i__3, &z__1, &y[i__ + 1 +
8691
y_dim1], ldy, &y[i__ * y_dim1 + 1], &c__1, &c_b57, &y[
8692
i__ + 1 + i__ * y_dim1], &c__1);
8693
i__2 = *m - i__ + 1;
8694
i__3 = i__ - 1;
8695
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &x[i__ +
8696
x_dim1], ldx, &a[i__ + i__ * a_dim1], &c__1, &c_b56, &
8697
y[i__ * y_dim1 + 1], &c__1);
8698
i__2 = i__ - 1;
8699
i__3 = *n - i__;
8700
z__1.r = -1., z__1.i = -0.;
8701
zgemv_("Conjugate transpose", &i__2, &i__3, &z__1, &a[(i__ +
8702
1) * a_dim1 + 1], lda, &y[i__ * y_dim1 + 1], &c__1, &
8703
c_b57, &y[i__ + 1 + i__ * y_dim1], &c__1);
8704
i__2 = *n - i__;
8705
zscal_(&i__2, &tauq[i__], &y[i__ + 1 + i__ * y_dim1], &c__1);
8706
8707
/* Update A(i,i+1:n) */
8708
8709
i__2 = *n - i__;
8710
zlacgv_(&i__2, &a[i__ + (i__ + 1) * a_dim1], lda);
8711
zlacgv_(&i__, &a[i__ + a_dim1], lda);
8712
i__2 = *n - i__;
8713
z__1.r = -1., z__1.i = -0.;
8714
zgemv_("No transpose", &i__2, &i__, &z__1, &y[i__ + 1 +
8715
y_dim1], ldy, &a[i__ + a_dim1], lda, &c_b57, &a[i__ +
8716
(i__ + 1) * a_dim1], lda);
8717
zlacgv_(&i__, &a[i__ + a_dim1], lda);
8718
i__2 = i__ - 1;
8719
zlacgv_(&i__2, &x[i__ + x_dim1], ldx);
8720
i__2 = i__ - 1;
8721
i__3 = *n - i__;
8722
z__1.r = -1., z__1.i = -0.;
8723
zgemv_("Conjugate transpose", &i__2, &i__3, &z__1, &a[(i__ +
8724
1) * a_dim1 + 1], lda, &x[i__ + x_dim1], ldx, &c_b57,
8725
&a[i__ + (i__ + 1) * a_dim1], lda);
8726
i__2 = i__ - 1;
8727
zlacgv_(&i__2, &x[i__ + x_dim1], ldx);
8728
8729
/* Generate reflection P(i) to annihilate A(i,i+2:n) */
8730
8731
i__2 = i__ + (i__ + 1) * a_dim1;
8732
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
8733
i__2 = *n - i__;
8734
/* Computing MIN */
8735
i__3 = i__ + 2;
8736
zlarfg_(&i__2, &alpha, &a[i__ + min(i__3,*n) * a_dim1], lda, &
8737
taup[i__]);
8738
i__2 = i__;
8739
e[i__2] = alpha.r;
8740
i__2 = i__ + (i__ + 1) * a_dim1;
8741
a[i__2].r = 1., a[i__2].i = 0.;
8742
8743
/* Compute X(i+1:m,i) */
8744
8745
i__2 = *m - i__;
8746
i__3 = *n - i__;
8747
zgemv_("No transpose", &i__2, &i__3, &c_b57, &a[i__ + 1 + (
8748
i__ + 1) * a_dim1], lda, &a[i__ + (i__ + 1) * a_dim1],
8749
lda, &c_b56, &x[i__ + 1 + i__ * x_dim1], &c__1);
8750
i__2 = *n - i__;
8751
zgemv_("Conjugate transpose", &i__2, &i__, &c_b57, &y[i__ + 1
8752
+ y_dim1], ldy, &a[i__ + (i__ + 1) * a_dim1], lda, &
8753
c_b56, &x[i__ * x_dim1 + 1], &c__1);
8754
i__2 = *m - i__;
8755
z__1.r = -1., z__1.i = -0.;
8756
zgemv_("No transpose", &i__2, &i__, &z__1, &a[i__ + 1 +
8757
a_dim1], lda, &x[i__ * x_dim1 + 1], &c__1, &c_b57, &x[
8758
i__ + 1 + i__ * x_dim1], &c__1);
8759
i__2 = i__ - 1;
8760
i__3 = *n - i__;
8761
zgemv_("No transpose", &i__2, &i__3, &c_b57, &a[(i__ + 1) *
8762
a_dim1 + 1], lda, &a[i__ + (i__ + 1) * a_dim1], lda, &
8763
c_b56, &x[i__ * x_dim1 + 1], &c__1);
8764
i__2 = *m - i__;
8765
i__3 = i__ - 1;
8766
z__1.r = -1., z__1.i = -0.;
8767
zgemv_("No transpose", &i__2, &i__3, &z__1, &x[i__ + 1 +
8768
x_dim1], ldx, &x[i__ * x_dim1 + 1], &c__1, &c_b57, &x[
8769
i__ + 1 + i__ * x_dim1], &c__1);
8770
i__2 = *m - i__;
8771
zscal_(&i__2, &taup[i__], &x[i__ + 1 + i__ * x_dim1], &c__1);
8772
i__2 = *n - i__;
8773
zlacgv_(&i__2, &a[i__ + (i__ + 1) * a_dim1], lda);
8774
}
8775
/* L10: */
8776
}
8777
} else {
8778
8779
/* Reduce to lower bidiagonal form */
8780
8781
i__1 = *nb;
8782
for (i__ = 1; i__ <= i__1; ++i__) {
8783
8784
/* Update A(i,i:n) */
8785
8786
i__2 = *n - i__ + 1;
8787
zlacgv_(&i__2, &a[i__ + i__ * a_dim1], lda);
8788
i__2 = i__ - 1;
8789
zlacgv_(&i__2, &a[i__ + a_dim1], lda);
8790
i__2 = *n - i__ + 1;
8791
i__3 = i__ - 1;
8792
z__1.r = -1., z__1.i = -0.;
8793
zgemv_("No transpose", &i__2, &i__3, &z__1, &y[i__ + y_dim1], ldy,
8794
&a[i__ + a_dim1], lda, &c_b57, &a[i__ + i__ * a_dim1],
8795
lda);
8796
i__2 = i__ - 1;
8797
zlacgv_(&i__2, &a[i__ + a_dim1], lda);
8798
i__2 = i__ - 1;
8799
zlacgv_(&i__2, &x[i__ + x_dim1], ldx);
8800
i__2 = i__ - 1;
8801
i__3 = *n - i__ + 1;
8802
z__1.r = -1., z__1.i = -0.;
8803
zgemv_("Conjugate transpose", &i__2, &i__3, &z__1, &a[i__ *
8804
a_dim1 + 1], lda, &x[i__ + x_dim1], ldx, &c_b57, &a[i__ +
8805
i__ * a_dim1], lda);
8806
i__2 = i__ - 1;
8807
zlacgv_(&i__2, &x[i__ + x_dim1], ldx);
8808
8809
/* Generate reflection P(i) to annihilate A(i,i+1:n) */
8810
8811
i__2 = i__ + i__ * a_dim1;
8812
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
8813
i__2 = *n - i__ + 1;
8814
/* Computing MIN */
8815
i__3 = i__ + 1;
8816
zlarfg_(&i__2, &alpha, &a[i__ + min(i__3,*n) * a_dim1], lda, &
8817
taup[i__]);
8818
i__2 = i__;
8819
d__[i__2] = alpha.r;
8820
if (i__ < *m) {
8821
i__2 = i__ + i__ * a_dim1;
8822
a[i__2].r = 1., a[i__2].i = 0.;
8823
8824
/* Compute X(i+1:m,i) */
8825
8826
i__2 = *m - i__;
8827
i__3 = *n - i__ + 1;
8828
zgemv_("No transpose", &i__2, &i__3, &c_b57, &a[i__ + 1 + i__
8829
* a_dim1], lda, &a[i__ + i__ * a_dim1], lda, &c_b56, &
8830
x[i__ + 1 + i__ * x_dim1], &c__1);
8831
i__2 = *n - i__ + 1;
8832
i__3 = i__ - 1;
8833
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &y[i__ +
8834
y_dim1], ldy, &a[i__ + i__ * a_dim1], lda, &c_b56, &x[
8835
i__ * x_dim1 + 1], &c__1);
8836
i__2 = *m - i__;
8837
i__3 = i__ - 1;
8838
z__1.r = -1., z__1.i = -0.;
8839
zgemv_("No transpose", &i__2, &i__3, &z__1, &a[i__ + 1 +
8840
a_dim1], lda, &x[i__ * x_dim1 + 1], &c__1, &c_b57, &x[
8841
i__ + 1 + i__ * x_dim1], &c__1);
8842
i__2 = i__ - 1;
8843
i__3 = *n - i__ + 1;
8844
zgemv_("No transpose", &i__2, &i__3, &c_b57, &a[i__ * a_dim1
8845
+ 1], lda, &a[i__ + i__ * a_dim1], lda, &c_b56, &x[
8846
i__ * x_dim1 + 1], &c__1);
8847
i__2 = *m - i__;
8848
i__3 = i__ - 1;
8849
z__1.r = -1., z__1.i = -0.;
8850
zgemv_("No transpose", &i__2, &i__3, &z__1, &x[i__ + 1 +
8851
x_dim1], ldx, &x[i__ * x_dim1 + 1], &c__1, &c_b57, &x[
8852
i__ + 1 + i__ * x_dim1], &c__1);
8853
i__2 = *m - i__;
8854
zscal_(&i__2, &taup[i__], &x[i__ + 1 + i__ * x_dim1], &c__1);
8855
i__2 = *n - i__ + 1;
8856
zlacgv_(&i__2, &a[i__ + i__ * a_dim1], lda);
8857
8858
/* Update A(i+1:m,i) */
8859
8860
i__2 = i__ - 1;
8861
zlacgv_(&i__2, &y[i__ + y_dim1], ldy);
8862
i__2 = *m - i__;
8863
i__3 = i__ - 1;
8864
z__1.r = -1., z__1.i = -0.;
8865
zgemv_("No transpose", &i__2, &i__3, &z__1, &a[i__ + 1 +
8866
a_dim1], lda, &y[i__ + y_dim1], ldy, &c_b57, &a[i__ +
8867
1 + i__ * a_dim1], &c__1);
8868
i__2 = i__ - 1;
8869
zlacgv_(&i__2, &y[i__ + y_dim1], ldy);
8870
i__2 = *m - i__;
8871
z__1.r = -1., z__1.i = -0.;
8872
zgemv_("No transpose", &i__2, &i__, &z__1, &x[i__ + 1 +
8873
x_dim1], ldx, &a[i__ * a_dim1 + 1], &c__1, &c_b57, &a[
8874
i__ + 1 + i__ * a_dim1], &c__1);
8875
8876
/* Generate reflection Q(i) to annihilate A(i+2:m,i) */
8877
8878
i__2 = i__ + 1 + i__ * a_dim1;
8879
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
8880
i__2 = *m - i__;
8881
/* Computing MIN */
8882
i__3 = i__ + 2;
8883
zlarfg_(&i__2, &alpha, &a[min(i__3,*m) + i__ * a_dim1], &c__1,
8884
&tauq[i__]);
8885
i__2 = i__;
8886
e[i__2] = alpha.r;
8887
i__2 = i__ + 1 + i__ * a_dim1;
8888
a[i__2].r = 1., a[i__2].i = 0.;
8889
8890
/* Compute Y(i+1:n,i) */
8891
8892
i__2 = *m - i__;
8893
i__3 = *n - i__;
8894
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &a[i__ +
8895
1 + (i__ + 1) * a_dim1], lda, &a[i__ + 1 + i__ *
8896
a_dim1], &c__1, &c_b56, &y[i__ + 1 + i__ * y_dim1], &
8897
c__1);
8898
i__2 = *m - i__;
8899
i__3 = i__ - 1;
8900
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &a[i__ +
8901
1 + a_dim1], lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &
8902
c_b56, &y[i__ * y_dim1 + 1], &c__1);
8903
i__2 = *n - i__;
8904
i__3 = i__ - 1;
8905
z__1.r = -1., z__1.i = -0.;
8906
zgemv_("No transpose", &i__2, &i__3, &z__1, &y[i__ + 1 +
8907
y_dim1], ldy, &y[i__ * y_dim1 + 1], &c__1, &c_b57, &y[
8908
i__ + 1 + i__ * y_dim1], &c__1);
8909
i__2 = *m - i__;
8910
zgemv_("Conjugate transpose", &i__2, &i__, &c_b57, &x[i__ + 1
8911
+ x_dim1], ldx, &a[i__ + 1 + i__ * a_dim1], &c__1, &
8912
c_b56, &y[i__ * y_dim1 + 1], &c__1);
8913
i__2 = *n - i__;
8914
z__1.r = -1., z__1.i = -0.;
8915
zgemv_("Conjugate transpose", &i__, &i__2, &z__1, &a[(i__ + 1)
8916
* a_dim1 + 1], lda, &y[i__ * y_dim1 + 1], &c__1, &
8917
c_b57, &y[i__ + 1 + i__ * y_dim1], &c__1);
8918
i__2 = *n - i__;
8919
zscal_(&i__2, &tauq[i__], &y[i__ + 1 + i__ * y_dim1], &c__1);
8920
} else {
8921
i__2 = *n - i__ + 1;
8922
zlacgv_(&i__2, &a[i__ + i__ * a_dim1], lda);
8923
}
8924
/* L20: */
8925
}
8926
}
8927
return 0;
8928
8929
/* End of ZLABRD */
8930
8931
} /* zlabrd_ */
8932
8933
/* Subroutine */ int zlacgv_(integer *n, doublecomplex *x, integer *incx)
8934
{
8935
/* System generated locals */
8936
integer i__1, i__2;
8937
doublecomplex z__1;
8938
8939
/* Local variables */
8940
static integer i__, ioff;
8941
8942
8943
/*
8944
-- LAPACK auxiliary routine (version 3.2) --
8945
-- LAPACK is a software package provided by Univ. of Tennessee, --
8946
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
8947
November 2006
8948
8949
8950
Purpose
8951
=======
8952
8953
ZLACGV conjugates a complex vector of length N.
8954
8955
Arguments
8956
=========
8957
8958
N (input) INTEGER
8959
The length of the vector X. N >= 0.
8960
8961
X (input/output) COMPLEX*16 array, dimension
8962
(1+(N-1)*abs(INCX))
8963
On entry, the vector of length N to be conjugated.
8964
On exit, X is overwritten with conjg(X).
8965
8966
INCX (input) INTEGER
8967
The spacing between successive elements of X.
8968
8969
=====================================================================
8970
*/
8971
8972
8973
/* Parameter adjustments */
8974
--x;
8975
8976
/* Function Body */
8977
if (*incx == 1) {
8978
i__1 = *n;
8979
for (i__ = 1; i__ <= i__1; ++i__) {
8980
i__2 = i__;
8981
d_cnjg(&z__1, &x[i__]);
8982
x[i__2].r = z__1.r, x[i__2].i = z__1.i;
8983
/* L10: */
8984
}
8985
} else {
8986
ioff = 1;
8987
if (*incx < 0) {
8988
ioff = 1 - (*n - 1) * *incx;
8989
}
8990
i__1 = *n;
8991
for (i__ = 1; i__ <= i__1; ++i__) {
8992
i__2 = ioff;
8993
d_cnjg(&z__1, &x[ioff]);
8994
x[i__2].r = z__1.r, x[i__2].i = z__1.i;
8995
ioff += *incx;
8996
/* L20: */
8997
}
8998
}
8999
return 0;
9000
9001
/* End of ZLACGV */
9002
9003
} /* zlacgv_ */
9004
9005
/* Subroutine */ int zlacp2_(char *uplo, integer *m, integer *n, doublereal *
9006
a, integer *lda, doublecomplex *b, integer *ldb)
9007
{
9008
/* System generated locals */
9009
integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
9010
9011
/* Local variables */
9012
static integer i__, j;
9013
extern logical lsame_(char *, char *);
9014
9015
9016
/*
9017
-- LAPACK auxiliary routine (version 3.2) --
9018
-- LAPACK is a software package provided by Univ. of Tennessee, --
9019
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9020
November 2006
9021
9022
9023
Purpose
9024
=======
9025
9026
ZLACP2 copies all or part of a real two-dimensional matrix A to a
9027
complex matrix B.
9028
9029
Arguments
9030
=========
9031
9032
UPLO (input) CHARACTER*1
9033
Specifies the part of the matrix A to be copied to B.
9034
= 'U': Upper triangular part
9035
= 'L': Lower triangular part
9036
Otherwise: All of the matrix A
9037
9038
M (input) INTEGER
9039
The number of rows of the matrix A. M >= 0.
9040
9041
N (input) INTEGER
9042
The number of columns of the matrix A. N >= 0.
9043
9044
A (input) DOUBLE PRECISION array, dimension (LDA,N)
9045
The m by n matrix A. If UPLO = 'U', only the upper trapezium
9046
is accessed; if UPLO = 'L', only the lower trapezium is
9047
accessed.
9048
9049
LDA (input) INTEGER
9050
The leading dimension of the array A. LDA >= max(1,M).
9051
9052
B (output) COMPLEX*16 array, dimension (LDB,N)
9053
On exit, B = A in the locations specified by UPLO.
9054
9055
LDB (input) INTEGER
9056
The leading dimension of the array B. LDB >= max(1,M).
9057
9058
=====================================================================
9059
*/
9060
9061
9062
/* Parameter adjustments */
9063
a_dim1 = *lda;
9064
a_offset = 1 + a_dim1;
9065
a -= a_offset;
9066
b_dim1 = *ldb;
9067
b_offset = 1 + b_dim1;
9068
b -= b_offset;
9069
9070
/* Function Body */
9071
if (lsame_(uplo, "U")) {
9072
i__1 = *n;
9073
for (j = 1; j <= i__1; ++j) {
9074
i__2 = min(j,*m);
9075
for (i__ = 1; i__ <= i__2; ++i__) {
9076
i__3 = i__ + j * b_dim1;
9077
i__4 = i__ + j * a_dim1;
9078
b[i__3].r = a[i__4], b[i__3].i = 0.;
9079
/* L10: */
9080
}
9081
/* L20: */
9082
}
9083
9084
} else if (lsame_(uplo, "L")) {
9085
i__1 = *n;
9086
for (j = 1; j <= i__1; ++j) {
9087
i__2 = *m;
9088
for (i__ = j; i__ <= i__2; ++i__) {
9089
i__3 = i__ + j * b_dim1;
9090
i__4 = i__ + j * a_dim1;
9091
b[i__3].r = a[i__4], b[i__3].i = 0.;
9092
/* L30: */
9093
}
9094
/* L40: */
9095
}
9096
9097
} else {
9098
i__1 = *n;
9099
for (j = 1; j <= i__1; ++j) {
9100
i__2 = *m;
9101
for (i__ = 1; i__ <= i__2; ++i__) {
9102
i__3 = i__ + j * b_dim1;
9103
i__4 = i__ + j * a_dim1;
9104
b[i__3].r = a[i__4], b[i__3].i = 0.;
9105
/* L50: */
9106
}
9107
/* L60: */
9108
}
9109
}
9110
9111
return 0;
9112
9113
/* End of ZLACP2 */
9114
9115
} /* zlacp2_ */
9116
9117
/* Subroutine */ int zlacpy_(char *uplo, integer *m, integer *n,
9118
doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb)
9119
{
9120
/* System generated locals */
9121
integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
9122
9123
/* Local variables */
9124
static integer i__, j;
9125
extern logical lsame_(char *, char *);
9126
9127
9128
/*
9129
-- LAPACK auxiliary routine (version 3.2) --
9130
-- LAPACK is a software package provided by Univ. of Tennessee, --
9131
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9132
November 2006
9133
9134
9135
Purpose
9136
=======
9137
9138
ZLACPY copies all or part of a two-dimensional matrix A to another
9139
matrix B.
9140
9141
Arguments
9142
=========
9143
9144
UPLO (input) CHARACTER*1
9145
Specifies the part of the matrix A to be copied to B.
9146
= 'U': Upper triangular part
9147
= 'L': Lower triangular part
9148
Otherwise: All of the matrix A
9149
9150
M (input) INTEGER
9151
The number of rows of the matrix A. M >= 0.
9152
9153
N (input) INTEGER
9154
The number of columns of the matrix A. N >= 0.
9155
9156
A (input) COMPLEX*16 array, dimension (LDA,N)
9157
The m by n matrix A. If UPLO = 'U', only the upper trapezium
9158
is accessed; if UPLO = 'L', only the lower trapezium is
9159
accessed.
9160
9161
LDA (input) INTEGER
9162
The leading dimension of the array A. LDA >= max(1,M).
9163
9164
B (output) COMPLEX*16 array, dimension (LDB,N)
9165
On exit, B = A in the locations specified by UPLO.
9166
9167
LDB (input) INTEGER
9168
The leading dimension of the array B. LDB >= max(1,M).
9169
9170
=====================================================================
9171
*/
9172
9173
9174
/* Parameter adjustments */
9175
a_dim1 = *lda;
9176
a_offset = 1 + a_dim1;
9177
a -= a_offset;
9178
b_dim1 = *ldb;
9179
b_offset = 1 + b_dim1;
9180
b -= b_offset;
9181
9182
/* Function Body */
9183
if (lsame_(uplo, "U")) {
9184
i__1 = *n;
9185
for (j = 1; j <= i__1; ++j) {
9186
i__2 = min(j,*m);
9187
for (i__ = 1; i__ <= i__2; ++i__) {
9188
i__3 = i__ + j * b_dim1;
9189
i__4 = i__ + j * a_dim1;
9190
b[i__3].r = a[i__4].r, b[i__3].i = a[i__4].i;
9191
/* L10: */
9192
}
9193
/* L20: */
9194
}
9195
9196
} else if (lsame_(uplo, "L")) {
9197
i__1 = *n;
9198
for (j = 1; j <= i__1; ++j) {
9199
i__2 = *m;
9200
for (i__ = j; i__ <= i__2; ++i__) {
9201
i__3 = i__ + j * b_dim1;
9202
i__4 = i__ + j * a_dim1;
9203
b[i__3].r = a[i__4].r, b[i__3].i = a[i__4].i;
9204
/* L30: */
9205
}
9206
/* L40: */
9207
}
9208
9209
} else {
9210
i__1 = *n;
9211
for (j = 1; j <= i__1; ++j) {
9212
i__2 = *m;
9213
for (i__ = 1; i__ <= i__2; ++i__) {
9214
i__3 = i__ + j * b_dim1;
9215
i__4 = i__ + j * a_dim1;
9216
b[i__3].r = a[i__4].r, b[i__3].i = a[i__4].i;
9217
/* L50: */
9218
}
9219
/* L60: */
9220
}
9221
}
9222
9223
return 0;
9224
9225
/* End of ZLACPY */
9226
9227
} /* zlacpy_ */
9228
9229
/* Subroutine */ int zlacrm_(integer *m, integer *n, doublecomplex *a,
9230
integer *lda, doublereal *b, integer *ldb, doublecomplex *c__,
9231
integer *ldc, doublereal *rwork)
9232
{
9233
/* System generated locals */
9234
integer b_dim1, b_offset, a_dim1, a_offset, c_dim1, c_offset, i__1, i__2,
9235
i__3, i__4, i__5;
9236
doublereal d__1;
9237
doublecomplex z__1;
9238
9239
/* Local variables */
9240
static integer i__, j, l;
9241
extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
9242
integer *, doublereal *, doublereal *, integer *, doublereal *,
9243
integer *, doublereal *, doublereal *, integer *);
9244
9245
9246
/*
9247
-- LAPACK auxiliary routine (version 3.2) --
9248
-- LAPACK is a software package provided by Univ. of Tennessee, --
9249
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9250
November 2006
9251
9252
9253
Purpose
9254
=======
9255
9256
ZLACRM performs a very simple matrix-matrix multiplication:
9257
C := A * B,
9258
where A is M by N and complex; B is N by N and real;
9259
C is M by N and complex.
9260
9261
Arguments
9262
=========
9263
9264
M (input) INTEGER
9265
The number of rows of the matrix A and of the matrix C.
9266
M >= 0.
9267
9268
N (input) INTEGER
9269
The number of columns and rows of the matrix B and
9270
the number of columns of the matrix C.
9271
N >= 0.
9272
9273
A (input) COMPLEX*16 array, dimension (LDA, N)
9274
A contains the M by N matrix A.
9275
9276
LDA (input) INTEGER
9277
The leading dimension of the array A. LDA >=max(1,M).
9278
9279
B (input) DOUBLE PRECISION array, dimension (LDB, N)
9280
B contains the N by N matrix B.
9281
9282
LDB (input) INTEGER
9283
The leading dimension of the array B. LDB >=max(1,N).
9284
9285
C (input) COMPLEX*16 array, dimension (LDC, N)
9286
C contains the M by N matrix C.
9287
9288
LDC (input) INTEGER
9289
The leading dimension of the array C. LDC >=max(1,N).
9290
9291
RWORK (workspace) DOUBLE PRECISION array, dimension (2*M*N)
9292
9293
=====================================================================
9294
9295
9296
Quick return if possible.
9297
*/
9298
9299
/* Parameter adjustments */
9300
a_dim1 = *lda;
9301
a_offset = 1 + a_dim1;
9302
a -= a_offset;
9303
b_dim1 = *ldb;
9304
b_offset = 1 + b_dim1;
9305
b -= b_offset;
9306
c_dim1 = *ldc;
9307
c_offset = 1 + c_dim1;
9308
c__ -= c_offset;
9309
--rwork;
9310
9311
/* Function Body */
9312
if (*m == 0 || *n == 0) {
9313
return 0;
9314
}
9315
9316
i__1 = *n;
9317
for (j = 1; j <= i__1; ++j) {
9318
i__2 = *m;
9319
for (i__ = 1; i__ <= i__2; ++i__) {
9320
i__3 = i__ + j * a_dim1;
9321
rwork[(j - 1) * *m + i__] = a[i__3].r;
9322
/* L10: */
9323
}
9324
/* L20: */
9325
}
9326
9327
l = *m * *n + 1;
9328
dgemm_("N", "N", m, n, n, &c_b1034, &rwork[1], m, &b[b_offset], ldb, &
9329
c_b328, &rwork[l], m);
9330
i__1 = *n;
9331
for (j = 1; j <= i__1; ++j) {
9332
i__2 = *m;
9333
for (i__ = 1; i__ <= i__2; ++i__) {
9334
i__3 = i__ + j * c_dim1;
9335
i__4 = l + (j - 1) * *m + i__ - 1;
9336
c__[i__3].r = rwork[i__4], c__[i__3].i = 0.;
9337
/* L30: */
9338
}
9339
/* L40: */
9340
}
9341
9342
i__1 = *n;
9343
for (j = 1; j <= i__1; ++j) {
9344
i__2 = *m;
9345
for (i__ = 1; i__ <= i__2; ++i__) {
9346
rwork[(j - 1) * *m + i__] = d_imag(&a[i__ + j * a_dim1]);
9347
/* L50: */
9348
}
9349
/* L60: */
9350
}
9351
dgemm_("N", "N", m, n, n, &c_b1034, &rwork[1], m, &b[b_offset], ldb, &
9352
c_b328, &rwork[l], m);
9353
i__1 = *n;
9354
for (j = 1; j <= i__1; ++j) {
9355
i__2 = *m;
9356
for (i__ = 1; i__ <= i__2; ++i__) {
9357
i__3 = i__ + j * c_dim1;
9358
i__4 = i__ + j * c_dim1;
9359
d__1 = c__[i__4].r;
9360
i__5 = l + (j - 1) * *m + i__ - 1;
9361
z__1.r = d__1, z__1.i = rwork[i__5];
9362
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
9363
/* L70: */
9364
}
9365
/* L80: */
9366
}
9367
9368
return 0;
9369
9370
/* End of ZLACRM */
9371
9372
} /* zlacrm_ */
9373
9374
/* Double Complex */ VOID zladiv_(doublecomplex * ret_val, doublecomplex *x,
9375
doublecomplex *y)
9376
{
9377
/* System generated locals */
9378
doublereal d__1, d__2, d__3, d__4;
9379
doublecomplex z__1;
9380
9381
/* Local variables */
9382
static doublereal zi, zr;
9383
extern /* Subroutine */ int dladiv_(doublereal *, doublereal *,
9384
doublereal *, doublereal *, doublereal *, doublereal *);
9385
9386
9387
/*
9388
-- LAPACK auxiliary routine (version 3.2) --
9389
-- LAPACK is a software package provided by Univ. of Tennessee, --
9390
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9391
November 2006
9392
9393
9394
Purpose
9395
=======
9396
9397
ZLADIV := X / Y, where X and Y are complex. The computation of X / Y
9398
will not overflow on an intermediary step unless the results
9399
overflows.
9400
9401
Arguments
9402
=========
9403
9404
X (input) COMPLEX*16
9405
Y (input) COMPLEX*16
9406
The complex scalars X and Y.
9407
9408
=====================================================================
9409
*/
9410
9411
9412
d__1 = x->r;
9413
d__2 = d_imag(x);
9414
d__3 = y->r;
9415
d__4 = d_imag(y);
9416
dladiv_(&d__1, &d__2, &d__3, &d__4, &zr, &zi);
9417
z__1.r = zr, z__1.i = zi;
9418
ret_val->r = z__1.r, ret_val->i = z__1.i;
9419
9420
return ;
9421
9422
/* End of ZLADIV */
9423
9424
} /* zladiv_ */
9425
9426
/* Subroutine */ int zlaed0_(integer *qsiz, integer *n, doublereal *d__,
9427
doublereal *e, doublecomplex *q, integer *ldq, doublecomplex *qstore,
9428
integer *ldqs, doublereal *rwork, integer *iwork, integer *info)
9429
{
9430
/* System generated locals */
9431
integer q_dim1, q_offset, qstore_dim1, qstore_offset, i__1, i__2;
9432
doublereal d__1;
9433
9434
/* Local variables */
9435
static integer i__, j, k, ll, iq, lgn, msd2, smm1, spm1, spm2;
9436
static doublereal temp;
9437
static integer curr, iperm;
9438
extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
9439
doublereal *, integer *);
9440
static integer indxq, iwrem, iqptr, tlvls;
9441
extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
9442
doublecomplex *, integer *), zlaed7_(integer *, integer *,
9443
integer *, integer *, integer *, integer *, doublereal *,
9444
doublecomplex *, integer *, doublereal *, integer *, doublereal *,
9445
integer *, integer *, integer *, integer *, integer *,
9446
doublereal *, doublecomplex *, doublereal *, integer *, integer *)
9447
;
9448
static integer igivcl;
9449
extern /* Subroutine */ int xerbla_(char *, integer *);
9450
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
9451
integer *, integer *, ftnlen, ftnlen);
9452
extern /* Subroutine */ int zlacrm_(integer *, integer *, doublecomplex *,
9453
integer *, doublereal *, integer *, doublecomplex *, integer *,
9454
doublereal *);
9455
static integer igivnm, submat, curprb, subpbs, igivpt;
9456
extern /* Subroutine */ int dsteqr_(char *, integer *, doublereal *,
9457
doublereal *, doublereal *, integer *, doublereal *, integer *);
9458
static integer curlvl, matsiz, iprmpt, smlsiz;
9459
9460
9461
/*
9462
-- LAPACK routine (version 3.2) --
9463
-- LAPACK is a software package provided by Univ. of Tennessee, --
9464
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9465
November 2006
9466
9467
9468
Purpose
9469
=======
9470
9471
Using the divide and conquer method, ZLAED0 computes all eigenvalues
9472
of a symmetric tridiagonal matrix which is one diagonal block of
9473
those from reducing a dense or band Hermitian matrix and
9474
corresponding eigenvectors of the dense or band matrix.
9475
9476
Arguments
9477
=========
9478
9479
QSIZ (input) INTEGER
9480
The dimension of the unitary matrix used to reduce
9481
the full matrix to tridiagonal form. QSIZ >= N if ICOMPQ = 1.
9482
9483
N (input) INTEGER
9484
The dimension of the symmetric tridiagonal matrix. N >= 0.
9485
9486
D (input/output) DOUBLE PRECISION array, dimension (N)
9487
On entry, the diagonal elements of the tridiagonal matrix.
9488
On exit, the eigenvalues in ascending order.
9489
9490
E (input/output) DOUBLE PRECISION array, dimension (N-1)
9491
On entry, the off-diagonal elements of the tridiagonal matrix.
9492
On exit, E has been destroyed.
9493
9494
Q (input/output) COMPLEX*16 array, dimension (LDQ,N)
9495
On entry, Q must contain an QSIZ x N matrix whose columns
9496
unitarily orthonormal. It is a part of the unitary matrix
9497
that reduces the full dense Hermitian matrix to a
9498
(reducible) symmetric tridiagonal matrix.
9499
9500
LDQ (input) INTEGER
9501
The leading dimension of the array Q. LDQ >= max(1,N).
9502
9503
IWORK (workspace) INTEGER array,
9504
the dimension of IWORK must be at least
9505
6 + 6*N + 5*N*lg N
9506
( lg( N ) = smallest integer k
9507
such that 2^k >= N )
9508
9509
RWORK (workspace) DOUBLE PRECISION array,
9510
dimension (1 + 3*N + 2*N*lg N + 3*N**2)
9511
( lg( N ) = smallest integer k
9512
such that 2^k >= N )
9513
9514
QSTORE (workspace) COMPLEX*16 array, dimension (LDQS, N)
9515
Used to store parts of
9516
the eigenvector matrix when the updating matrix multiplies
9517
take place.
9518
9519
LDQS (input) INTEGER
9520
The leading dimension of the array QSTORE.
9521
LDQS >= max(1,N).
9522
9523
INFO (output) INTEGER
9524
= 0: successful exit.
9525
< 0: if INFO = -i, the i-th argument had an illegal value.
9526
> 0: The algorithm failed to compute an eigenvalue while
9527
working on the submatrix lying in rows and columns
9528
INFO/(N+1) through mod(INFO,N+1).
9529
9530
=====================================================================
9531
9532
Warning: N could be as big as QSIZ!
9533
9534
9535
Test the input parameters.
9536
*/
9537
9538
/* Parameter adjustments */
9539
--d__;
9540
--e;
9541
q_dim1 = *ldq;
9542
q_offset = 1 + q_dim1;
9543
q -= q_offset;
9544
qstore_dim1 = *ldqs;
9545
qstore_offset = 1 + qstore_dim1;
9546
qstore -= qstore_offset;
9547
--rwork;
9548
--iwork;
9549
9550
/* Function Body */
9551
*info = 0;
9552
9553
/*
9554
IF( ICOMPQ .LT. 0 .OR. ICOMPQ .GT. 2 ) THEN
9555
INFO = -1
9556
ELSE IF( ( ICOMPQ .EQ. 1 ) .AND. ( QSIZ .LT. MAX( 0, N ) ) )
9557
$ THEN
9558
*/
9559
if (*qsiz < max(0,*n)) {
9560
*info = -1;
9561
} else if (*n < 0) {
9562
*info = -2;
9563
} else if (*ldq < max(1,*n)) {
9564
*info = -6;
9565
} else if (*ldqs < max(1,*n)) {
9566
*info = -8;
9567
}
9568
if (*info != 0) {
9569
i__1 = -(*info);
9570
xerbla_("ZLAED0", &i__1);
9571
return 0;
9572
}
9573
9574
/* Quick return if possible */
9575
9576
if (*n == 0) {
9577
return 0;
9578
}
9579
9580
smlsiz = ilaenv_(&c__9, "ZLAED0", " ", &c__0, &c__0, &c__0, &c__0, (
9581
ftnlen)6, (ftnlen)1);
9582
9583
/*
9584
Determine the size and placement of the submatrices, and save in
9585
the leading elements of IWORK.
9586
*/
9587
9588
iwork[1] = *n;
9589
subpbs = 1;
9590
tlvls = 0;
9591
L10:
9592
if (iwork[subpbs] > smlsiz) {
9593
for (j = subpbs; j >= 1; --j) {
9594
iwork[j * 2] = (iwork[j] + 1) / 2;
9595
iwork[(j << 1) - 1] = iwork[j] / 2;
9596
/* L20: */
9597
}
9598
++tlvls;
9599
subpbs <<= 1;
9600
goto L10;
9601
}
9602
i__1 = subpbs;
9603
for (j = 2; j <= i__1; ++j) {
9604
iwork[j] += iwork[j - 1];
9605
/* L30: */
9606
}
9607
9608
/*
9609
Divide the matrix into SUBPBS submatrices of size at most SMLSIZ+1
9610
using rank-1 modifications (cuts).
9611
*/
9612
9613
spm1 = subpbs - 1;
9614
i__1 = spm1;
9615
for (i__ = 1; i__ <= i__1; ++i__) {
9616
submat = iwork[i__] + 1;
9617
smm1 = submat - 1;
9618
d__[smm1] -= (d__1 = e[smm1], abs(d__1));
9619
d__[submat] -= (d__1 = e[smm1], abs(d__1));
9620
/* L40: */
9621
}
9622
9623
indxq = (*n << 2) + 3;
9624
9625
/*
9626
Set up workspaces for eigenvalues only/accumulate new vectors
9627
routine
9628
*/
9629
9630
temp = log((doublereal) (*n)) / log(2.);
9631
lgn = (integer) temp;
9632
if (pow_ii(&c__2, &lgn) < *n) {
9633
++lgn;
9634
}
9635
if (pow_ii(&c__2, &lgn) < *n) {
9636
++lgn;
9637
}
9638
iprmpt = indxq + *n + 1;
9639
iperm = iprmpt + *n * lgn;
9640
iqptr = iperm + *n * lgn;
9641
igivpt = iqptr + *n + 2;
9642
igivcl = igivpt + *n * lgn;
9643
9644
igivnm = 1;
9645
iq = igivnm + (*n << 1) * lgn;
9646
/* Computing 2nd power */
9647
i__1 = *n;
9648
iwrem = iq + i__1 * i__1 + 1;
9649
/* Initialize pointers */
9650
i__1 = subpbs;
9651
for (i__ = 0; i__ <= i__1; ++i__) {
9652
iwork[iprmpt + i__] = 1;
9653
iwork[igivpt + i__] = 1;
9654
/* L50: */
9655
}
9656
iwork[iqptr] = 1;
9657
9658
/*
9659
Solve each submatrix eigenproblem at the bottom of the divide and
9660
conquer tree.
9661
*/
9662
9663
curr = 0;
9664
i__1 = spm1;
9665
for (i__ = 0; i__ <= i__1; ++i__) {
9666
if (i__ == 0) {
9667
submat = 1;
9668
matsiz = iwork[1];
9669
} else {
9670
submat = iwork[i__] + 1;
9671
matsiz = iwork[i__ + 1] - iwork[i__];
9672
}
9673
ll = iq - 1 + iwork[iqptr + curr];
9674
dsteqr_("I", &matsiz, &d__[submat], &e[submat], &rwork[ll], &matsiz, &
9675
rwork[1], info);
9676
zlacrm_(qsiz, &matsiz, &q[submat * q_dim1 + 1], ldq, &rwork[ll], &
9677
matsiz, &qstore[submat * qstore_dim1 + 1], ldqs, &rwork[iwrem]
9678
);
9679
/* Computing 2nd power */
9680
i__2 = matsiz;
9681
iwork[iqptr + curr + 1] = iwork[iqptr + curr] + i__2 * i__2;
9682
++curr;
9683
if (*info > 0) {
9684
*info = submat * (*n + 1) + submat + matsiz - 1;
9685
return 0;
9686
}
9687
k = 1;
9688
i__2 = iwork[i__ + 1];
9689
for (j = submat; j <= i__2; ++j) {
9690
iwork[indxq + j] = k;
9691
++k;
9692
/* L60: */
9693
}
9694
/* L70: */
9695
}
9696
9697
/*
9698
Successively merge eigensystems of adjacent submatrices
9699
into eigensystem for the corresponding larger matrix.
9700
9701
while ( SUBPBS > 1 )
9702
*/
9703
9704
curlvl = 1;
9705
L80:
9706
if (subpbs > 1) {
9707
spm2 = subpbs - 2;
9708
i__1 = spm2;
9709
for (i__ = 0; i__ <= i__1; i__ += 2) {
9710
if (i__ == 0) {
9711
submat = 1;
9712
matsiz = iwork[2];
9713
msd2 = iwork[1];
9714
curprb = 0;
9715
} else {
9716
submat = iwork[i__] + 1;
9717
matsiz = iwork[i__ + 2] - iwork[i__];
9718
msd2 = matsiz / 2;
9719
++curprb;
9720
}
9721
9722
/*
9723
Merge lower order eigensystems (of size MSD2 and MATSIZ - MSD2)
9724
into an eigensystem of size MATSIZ. ZLAED7 handles the case
9725
when the eigenvectors of a full or band Hermitian matrix (which
9726
was reduced to tridiagonal form) are desired.
9727
9728
I am free to use Q as a valuable working space until Loop 150.
9729
*/
9730
9731
zlaed7_(&matsiz, &msd2, qsiz, &tlvls, &curlvl, &curprb, &d__[
9732
submat], &qstore[submat * qstore_dim1 + 1], ldqs, &e[
9733
submat + msd2 - 1], &iwork[indxq + submat], &rwork[iq], &
9734
iwork[iqptr], &iwork[iprmpt], &iwork[iperm], &iwork[
9735
igivpt], &iwork[igivcl], &rwork[igivnm], &q[submat *
9736
q_dim1 + 1], &rwork[iwrem], &iwork[subpbs + 1], info);
9737
if (*info > 0) {
9738
*info = submat * (*n + 1) + submat + matsiz - 1;
9739
return 0;
9740
}
9741
iwork[i__ / 2 + 1] = iwork[i__ + 2];
9742
/* L90: */
9743
}
9744
subpbs /= 2;
9745
++curlvl;
9746
goto L80;
9747
}
9748
9749
/*
9750
end while
9751
9752
Re-merge the eigenvalues/vectors which were deflated at the final
9753
merge step.
9754
*/
9755
9756
i__1 = *n;
9757
for (i__ = 1; i__ <= i__1; ++i__) {
9758
j = iwork[indxq + i__];
9759
rwork[i__] = d__[j];
9760
zcopy_(qsiz, &qstore[j * qstore_dim1 + 1], &c__1, &q[i__ * q_dim1 + 1]
9761
, &c__1);
9762
/* L100: */
9763
}
9764
dcopy_(n, &rwork[1], &c__1, &d__[1], &c__1);
9765
9766
return 0;
9767
9768
/* End of ZLAED0 */
9769
9770
} /* zlaed0_ */
9771
9772
/* Subroutine */ int zlaed7_(integer *n, integer *cutpnt, integer *qsiz,
9773
integer *tlvls, integer *curlvl, integer *curpbm, doublereal *d__,
9774
doublecomplex *q, integer *ldq, doublereal *rho, integer *indxq,
9775
doublereal *qstore, integer *qptr, integer *prmptr, integer *perm,
9776
integer *givptr, integer *givcol, doublereal *givnum, doublecomplex *
9777
work, doublereal *rwork, integer *iwork, integer *info)
9778
{
9779
/* System generated locals */
9780
integer q_dim1, q_offset, i__1, i__2;
9781
9782
/* Local variables */
9783
static integer i__, k, n1, n2, iq, iw, iz, ptr, indx, curr, indxc, indxp;
9784
extern /* Subroutine */ int dlaed9_(integer *, integer *, integer *,
9785
integer *, doublereal *, doublereal *, integer *, doublereal *,
9786
doublereal *, doublereal *, doublereal *, integer *, integer *),
9787
zlaed8_(integer *, integer *, integer *, doublecomplex *, integer
9788
*, doublereal *, doublereal *, integer *, doublereal *,
9789
doublereal *, doublecomplex *, integer *, doublereal *, integer *,
9790
integer *, integer *, integer *, integer *, integer *,
9791
doublereal *, integer *), dlaeda_(integer *, integer *, integer *,
9792
integer *, integer *, integer *, integer *, integer *,
9793
doublereal *, doublereal *, integer *, doublereal *, doublereal *,
9794
integer *);
9795
static integer idlmda;
9796
extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
9797
integer *, integer *, integer *), xerbla_(char *, integer *), zlacrm_(integer *, integer *, doublecomplex *, integer *,
9798
doublereal *, integer *, doublecomplex *, integer *, doublereal *
9799
);
9800
static integer coltyp;
9801
9802
9803
/*
9804
-- LAPACK routine (version 3.2) --
9805
-- LAPACK is a software package provided by Univ. of Tennessee, --
9806
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
9807
November 2006
9808
9809
9810
Purpose
9811
=======
9812
9813
ZLAED7 computes the updated eigensystem of a diagonal
9814
matrix after modification by a rank-one symmetric matrix. This
9815
routine is used only for the eigenproblem which requires all
9816
eigenvalues and optionally eigenvectors of a dense or banded
9817
Hermitian matrix that has been reduced to tridiagonal form.
9818
9819
T = Q(in) ( D(in) + RHO * Z*Z' ) Q'(in) = Q(out) * D(out) * Q'(out)
9820
9821
where Z = Q'u, u is a vector of length N with ones in the
9822
CUTPNT and CUTPNT + 1 th elements and zeros elsewhere.
9823
9824
The eigenvectors of the original matrix are stored in Q, and the
9825
eigenvalues are in D. The algorithm consists of three stages:
9826
9827
The first stage consists of deflating the size of the problem
9828
when there are multiple eigenvalues or if there is a zero in
9829
the Z vector. For each such occurence the dimension of the
9830
secular equation problem is reduced by one. This stage is
9831
performed by the routine DLAED2.
9832
9833
The second stage consists of calculating the updated
9834
eigenvalues. This is done by finding the roots of the secular
9835
equation via the routine DLAED4 (as called by SLAED3).
9836
This routine also calculates the eigenvectors of the current
9837
problem.
9838
9839
The final stage consists of computing the updated eigenvectors
9840
directly using the updated eigenvalues. The eigenvectors for
9841
the current problem are multiplied with the eigenvectors from
9842
the overall problem.
9843
9844
Arguments
9845
=========
9846
9847
N (input) INTEGER
9848
The dimension of the symmetric tridiagonal matrix. N >= 0.
9849
9850
CUTPNT (input) INTEGER
9851
Contains the location of the last eigenvalue in the leading
9852
sub-matrix. min(1,N) <= CUTPNT <= N.
9853
9854
QSIZ (input) INTEGER
9855
The dimension of the unitary matrix used to reduce
9856
the full matrix to tridiagonal form. QSIZ >= N.
9857
9858
TLVLS (input) INTEGER
9859
The total number of merging levels in the overall divide and
9860
conquer tree.
9861
9862
CURLVL (input) INTEGER
9863
The current level in the overall merge routine,
9864
0 <= curlvl <= tlvls.
9865
9866
CURPBM (input) INTEGER
9867
The current problem in the current level in the overall
9868
merge routine (counting from upper left to lower right).
9869
9870
D (input/output) DOUBLE PRECISION array, dimension (N)
9871
On entry, the eigenvalues of the rank-1-perturbed matrix.
9872
On exit, the eigenvalues of the repaired matrix.
9873
9874
Q (input/output) COMPLEX*16 array, dimension (LDQ,N)
9875
On entry, the eigenvectors of the rank-1-perturbed matrix.
9876
On exit, the eigenvectors of the repaired tridiagonal matrix.
9877
9878
LDQ (input) INTEGER
9879
The leading dimension of the array Q. LDQ >= max(1,N).
9880
9881
RHO (input) DOUBLE PRECISION
9882
Contains the subdiagonal element used to create the rank-1
9883
modification.
9884
9885
INDXQ (output) INTEGER array, dimension (N)
9886
This contains the permutation which will reintegrate the
9887
subproblem just solved back into sorted order,
9888
ie. D( INDXQ( I = 1, N ) ) will be in ascending order.
9889
9890
IWORK (workspace) INTEGER array, dimension (4*N)
9891
9892
RWORK (workspace) DOUBLE PRECISION array,
9893
dimension (3*N+2*QSIZ*N)
9894
9895
WORK (workspace) COMPLEX*16 array, dimension (QSIZ*N)
9896
9897
QSTORE (input/output) DOUBLE PRECISION array, dimension (N**2+1)
9898
Stores eigenvectors of submatrices encountered during
9899
divide and conquer, packed together. QPTR points to
9900
beginning of the submatrices.
9901
9902
QPTR (input/output) INTEGER array, dimension (N+2)
9903
List of indices pointing to beginning of submatrices stored
9904
in QSTORE. The submatrices are numbered starting at the
9905
bottom left of the divide and conquer tree, from left to
9906
right and bottom to top.
9907
9908
PRMPTR (input) INTEGER array, dimension (N lg N)
9909
Contains a list of pointers which indicate where in PERM a
9910
level's permutation is stored. PRMPTR(i+1) - PRMPTR(i)
9911
indicates the size of the permutation and also the size of
9912
the full, non-deflated problem.
9913
9914
PERM (input) INTEGER array, dimension (N lg N)
9915
Contains the permutations (from deflation and sorting) to be
9916
applied to each eigenblock.
9917
9918
GIVPTR (input) INTEGER array, dimension (N lg N)
9919
Contains a list of pointers which indicate where in GIVCOL a
9920
level's Givens rotations are stored. GIVPTR(i+1) - GIVPTR(i)
9921
indicates the number of Givens rotations.
9922
9923
GIVCOL (input) INTEGER array, dimension (2, N lg N)
9924
Each pair of numbers indicates a pair of columns to take place
9925
in a Givens rotation.
9926
9927
GIVNUM (input) DOUBLE PRECISION array, dimension (2, N lg N)
9928
Each number indicates the S value to be used in the
9929
corresponding Givens rotation.
9930
9931
INFO (output) INTEGER
9932
= 0: successful exit.
9933
< 0: if INFO = -i, the i-th argument had an illegal value.
9934
> 0: if INFO = 1, an eigenvalue did not converge
9935
9936
=====================================================================
9937
9938
9939
Test the input parameters.
9940
*/
9941
9942
/* Parameter adjustments */
9943
--d__;
9944
q_dim1 = *ldq;
9945
q_offset = 1 + q_dim1;
9946
q -= q_offset;
9947
--indxq;
9948
--qstore;
9949
--qptr;
9950
--prmptr;
9951
--perm;
9952
--givptr;
9953
givcol -= 3;
9954
givnum -= 3;
9955
--work;
9956
--rwork;
9957
--iwork;
9958
9959
/* Function Body */
9960
*info = 0;
9961
9962
/*
9963
IF( ICOMPQ.LT.0 .OR. ICOMPQ.GT.1 ) THEN
9964
INFO = -1
9965
ELSE IF( N.LT.0 ) THEN
9966
*/
9967
if (*n < 0) {
9968
*info = -1;
9969
} else if (min(1,*n) > *cutpnt || *n < *cutpnt) {
9970
*info = -2;
9971
} else if (*qsiz < *n) {
9972
*info = -3;
9973
} else if (*ldq < max(1,*n)) {
9974
*info = -9;
9975
}
9976
if (*info != 0) {
9977
i__1 = -(*info);
9978
xerbla_("ZLAED7", &i__1);
9979
return 0;
9980
}
9981
9982
/* Quick return if possible */
9983
9984
if (*n == 0) {
9985
return 0;
9986
}
9987
9988
/*
9989
The following values are for bookkeeping purposes only. They are
9990
integer pointers which indicate the portion of the workspace
9991
used by a particular array in DLAED2 and SLAED3.
9992
*/
9993
9994
iz = 1;
9995
idlmda = iz + *n;
9996
iw = idlmda + *n;
9997
iq = iw + *n;
9998
9999
indx = 1;
10000
indxc = indx + *n;
10001
coltyp = indxc + *n;
10002
indxp = coltyp + *n;
10003
10004
/*
10005
Form the z-vector which consists of the last row of Q_1 and the
10006
first row of Q_2.
10007
*/
10008
10009
ptr = pow_ii(&c__2, tlvls) + 1;
10010
i__1 = *curlvl - 1;
10011
for (i__ = 1; i__ <= i__1; ++i__) {
10012
i__2 = *tlvls - i__;
10013
ptr += pow_ii(&c__2, &i__2);
10014
/* L10: */
10015
}
10016
curr = ptr + *curpbm;
10017
dlaeda_(n, tlvls, curlvl, curpbm, &prmptr[1], &perm[1], &givptr[1], &
10018
givcol[3], &givnum[3], &qstore[1], &qptr[1], &rwork[iz], &rwork[
10019
iz + *n], info);
10020
10021
/*
10022
When solving the final problem, we no longer need the stored data,
10023
so we will overwrite the data from this level onto the previously
10024
used storage space.
10025
*/
10026
10027
if (*curlvl == *tlvls) {
10028
qptr[curr] = 1;
10029
prmptr[curr] = 1;
10030
givptr[curr] = 1;
10031
}
10032
10033
/* Sort and Deflate eigenvalues. */
10034
10035
zlaed8_(&k, n, qsiz, &q[q_offset], ldq, &d__[1], rho, cutpnt, &rwork[iz],
10036
&rwork[idlmda], &work[1], qsiz, &rwork[iw], &iwork[indxp], &iwork[
10037
indx], &indxq[1], &perm[prmptr[curr]], &givptr[curr + 1], &givcol[
10038
(givptr[curr] << 1) + 1], &givnum[(givptr[curr] << 1) + 1], info);
10039
prmptr[curr + 1] = prmptr[curr] + *n;
10040
givptr[curr + 1] += givptr[curr];
10041
10042
/* Solve Secular Equation. */
10043
10044
if (k != 0) {
10045
dlaed9_(&k, &c__1, &k, n, &d__[1], &rwork[iq], &k, rho, &rwork[idlmda]
10046
, &rwork[iw], &qstore[qptr[curr]], &k, info);
10047
zlacrm_(qsiz, &k, &work[1], qsiz, &qstore[qptr[curr]], &k, &q[
10048
q_offset], ldq, &rwork[iq]);
10049
/* Computing 2nd power */
10050
i__1 = k;
10051
qptr[curr + 1] = qptr[curr] + i__1 * i__1;
10052
if (*info != 0) {
10053
return 0;
10054
}
10055
10056
/* Prepare the INDXQ sorting premutation. */
10057
10058
n1 = k;
10059
n2 = *n - k;
10060
dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &indxq[1]);
10061
} else {
10062
qptr[curr + 1] = qptr[curr];
10063
i__1 = *n;
10064
for (i__ = 1; i__ <= i__1; ++i__) {
10065
indxq[i__] = i__;
10066
/* L20: */
10067
}
10068
}
10069
10070
return 0;
10071
10072
/* End of ZLAED7 */
10073
10074
} /* zlaed7_ */
10075
10076
/* Subroutine */ int zlaed8_(integer *k, integer *n, integer *qsiz,
10077
doublecomplex *q, integer *ldq, doublereal *d__, doublereal *rho,
10078
integer *cutpnt, doublereal *z__, doublereal *dlamda, doublecomplex *
10079
q2, integer *ldq2, doublereal *w, integer *indxp, integer *indx,
10080
integer *indxq, integer *perm, integer *givptr, integer *givcol,
10081
doublereal *givnum, integer *info)
10082
{
10083
/* System generated locals */
10084
integer q_dim1, q_offset, q2_dim1, q2_offset, i__1;
10085
doublereal d__1;
10086
10087
/* Local variables */
10088
static doublereal c__;
10089
static integer i__, j;
10090
static doublereal s, t;
10091
static integer k2, n1, n2, jp, n1p1;
10092
static doublereal eps, tau, tol;
10093
static integer jlam, imax, jmax;
10094
extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
10095
integer *), dcopy_(integer *, doublereal *, integer *, doublereal
10096
*, integer *), zdrot_(integer *, doublecomplex *, integer *,
10097
doublecomplex *, integer *, doublereal *, doublereal *), zcopy_(
10098
integer *, doublecomplex *, integer *, doublecomplex *, integer *)
10099
;
10100
10101
extern integer idamax_(integer *, doublereal *, integer *);
10102
extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
10103
integer *, integer *, integer *), xerbla_(char *, integer *), zlacpy_(char *, integer *, integer *, doublecomplex *,
10104
integer *, doublecomplex *, integer *);
10105
10106
10107
/*
10108
-- LAPACK routine (version 3.2.2) --
10109
-- LAPACK is a software package provided by Univ. of Tennessee, --
10110
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
10111
June 2010
10112
10113
10114
Purpose
10115
=======
10116
10117
ZLAED8 merges the two sets of eigenvalues together into a single
10118
sorted set. Then it tries to deflate the size of the problem.
10119
There are two ways in which deflation can occur: when two or more
10120
eigenvalues are close together or if there is a tiny element in the
10121
Z vector. For each such occurrence the order of the related secular
10122
equation problem is reduced by one.
10123
10124
Arguments
10125
=========
10126
10127
K (output) INTEGER
10128
Contains the number of non-deflated eigenvalues.
10129
This is the order of the related secular equation.
10130
10131
N (input) INTEGER
10132
The dimension of the symmetric tridiagonal matrix. N >= 0.
10133
10134
QSIZ (input) INTEGER
10135
The dimension of the unitary matrix used to reduce
10136
the dense or band matrix to tridiagonal form.
10137
QSIZ >= N if ICOMPQ = 1.
10138
10139
Q (input/output) COMPLEX*16 array, dimension (LDQ,N)
10140
On entry, Q contains the eigenvectors of the partially solved
10141
system which has been previously updated in matrix
10142
multiplies with other partially solved eigensystems.
10143
On exit, Q contains the trailing (N-K) updated eigenvectors
10144
(those which were deflated) in its last N-K columns.
10145
10146
LDQ (input) INTEGER
10147
The leading dimension of the array Q. LDQ >= max( 1, N ).
10148
10149
D (input/output) DOUBLE PRECISION array, dimension (N)
10150
On entry, D contains the eigenvalues of the two submatrices to
10151
be combined. On exit, D contains the trailing (N-K) updated
10152
eigenvalues (those which were deflated) sorted into increasing
10153
order.
10154
10155
RHO (input/output) DOUBLE PRECISION
10156
Contains the off diagonal element associated with the rank-1
10157
cut which originally split the two submatrices which are now
10158
being recombined. RHO is modified during the computation to
10159
the value required by DLAED3.
10160
10161
CUTPNT (input) INTEGER
10162
Contains the location of the last eigenvalue in the leading
10163
sub-matrix. MIN(1,N) <= CUTPNT <= N.
10164
10165
Z (input) DOUBLE PRECISION array, dimension (N)
10166
On input this vector contains the updating vector (the last
10167
row of the first sub-eigenvector matrix and the first row of
10168
the second sub-eigenvector matrix). The contents of Z are
10169
destroyed during the updating process.
10170
10171
DLAMDA (output) DOUBLE PRECISION array, dimension (N)
10172
Contains a copy of the first K eigenvalues which will be used
10173
by DLAED3 to form the secular equation.
10174
10175
Q2 (output) COMPLEX*16 array, dimension (LDQ2,N)
10176
If ICOMPQ = 0, Q2 is not referenced. Otherwise,
10177
Contains a copy of the first K eigenvectors which will be used
10178
by DLAED7 in a matrix multiply (DGEMM) to update the new
10179
eigenvectors.
10180
10181
LDQ2 (input) INTEGER
10182
The leading dimension of the array Q2. LDQ2 >= max( 1, N ).
10183
10184
W (output) DOUBLE PRECISION array, dimension (N)
10185
This will hold the first k values of the final
10186
deflation-altered z-vector and will be passed to DLAED3.
10187
10188
INDXP (workspace) INTEGER array, dimension (N)
10189
This will contain the permutation used to place deflated
10190
values of D at the end of the array. On output INDXP(1:K)
10191
points to the nondeflated D-values and INDXP(K+1:N)
10192
points to the deflated eigenvalues.
10193
10194
INDX (workspace) INTEGER array, dimension (N)
10195
This will contain the permutation used to sort the contents of
10196
D into ascending order.
10197
10198
INDXQ (input) INTEGER array, dimension (N)
10199
This contains the permutation which separately sorts the two
10200
sub-problems in D into ascending order. Note that elements in
10201
the second half of this permutation must first have CUTPNT
10202
added to their values in order to be accurate.
10203
10204
PERM (output) INTEGER array, dimension (N)
10205
Contains the permutations (from deflation and sorting) to be
10206
applied to each eigenblock.
10207
10208
GIVPTR (output) INTEGER
10209
Contains the number of Givens rotations which took place in
10210
this subproblem.
10211
10212
GIVCOL (output) INTEGER array, dimension (2, N)
10213
Each pair of numbers indicates a pair of columns to take place
10214
in a Givens rotation.
10215
10216
GIVNUM (output) DOUBLE PRECISION array, dimension (2, N)
10217
Each number indicates the S value to be used in the
10218
corresponding Givens rotation.
10219
10220
INFO (output) INTEGER
10221
= 0: successful exit.
10222
< 0: if INFO = -i, the i-th argument had an illegal value.
10223
10224
=====================================================================
10225
10226
10227
Test the input parameters.
10228
*/
10229
10230
/* Parameter adjustments */
10231
q_dim1 = *ldq;
10232
q_offset = 1 + q_dim1;
10233
q -= q_offset;
10234
--d__;
10235
--z__;
10236
--dlamda;
10237
q2_dim1 = *ldq2;
10238
q2_offset = 1 + q2_dim1;
10239
q2 -= q2_offset;
10240
--w;
10241
--indxp;
10242
--indx;
10243
--indxq;
10244
--perm;
10245
givcol -= 3;
10246
givnum -= 3;
10247
10248
/* Function Body */
10249
*info = 0;
10250
10251
if (*n < 0) {
10252
*info = -2;
10253
} else if (*qsiz < *n) {
10254
*info = -3;
10255
} else if (*ldq < max(1,*n)) {
10256
*info = -5;
10257
} else if (*cutpnt < min(1,*n) || *cutpnt > *n) {
10258
*info = -8;
10259
} else if (*ldq2 < max(1,*n)) {
10260
*info = -12;
10261
}
10262
if (*info != 0) {
10263
i__1 = -(*info);
10264
xerbla_("ZLAED8", &i__1);
10265
return 0;
10266
}
10267
10268
/*
10269
Need to initialize GIVPTR to O here in case of quick exit
10270
to prevent an unspecified code behavior (usually sigfault)
10271
when IWORK array on entry to *stedc is not zeroed
10272
(or at least some IWORK entries which used in *laed7 for GIVPTR).
10273
*/
10274
10275
*givptr = 0;
10276
10277
/* Quick return if possible */
10278
10279
if (*n == 0) {
10280
return 0;
10281
}
10282
10283
n1 = *cutpnt;
10284
n2 = *n - n1;
10285
n1p1 = n1 + 1;
10286
10287
if (*rho < 0.) {
10288
dscal_(&n2, &c_b1276, &z__[n1p1], &c__1);
10289
}
10290
10291
/* Normalize z so that norm(z) = 1 */
10292
10293
t = 1. / sqrt(2.);
10294
i__1 = *n;
10295
for (j = 1; j <= i__1; ++j) {
10296
indx[j] = j;
10297
/* L10: */
10298
}
10299
dscal_(n, &t, &z__[1], &c__1);
10300
*rho = (d__1 = *rho * 2., abs(d__1));
10301
10302
/* Sort the eigenvalues into increasing order */
10303
10304
i__1 = *n;
10305
for (i__ = *cutpnt + 1; i__ <= i__1; ++i__) {
10306
indxq[i__] += *cutpnt;
10307
/* L20: */
10308
}
10309
i__1 = *n;
10310
for (i__ = 1; i__ <= i__1; ++i__) {
10311
dlamda[i__] = d__[indxq[i__]];
10312
w[i__] = z__[indxq[i__]];
10313
/* L30: */
10314
}
10315
i__ = 1;
10316
j = *cutpnt + 1;
10317
dlamrg_(&n1, &n2, &dlamda[1], &c__1, &c__1, &indx[1]);
10318
i__1 = *n;
10319
for (i__ = 1; i__ <= i__1; ++i__) {
10320
d__[i__] = dlamda[indx[i__]];
10321
z__[i__] = w[indx[i__]];
10322
/* L40: */
10323
}
10324
10325
/* Calculate the allowable deflation tolerance */
10326
10327
imax = idamax_(n, &z__[1], &c__1);
10328
jmax = idamax_(n, &d__[1], &c__1);
10329
eps = EPSILON;
10330
tol = eps * 8. * (d__1 = d__[jmax], abs(d__1));
10331
10332
/*
10333
If the rank-1 modifier is small enough, no more needs to be done
10334
-- except to reorganize Q so that its columns correspond with the
10335
elements in D.
10336
*/
10337
10338
if (*rho * (d__1 = z__[imax], abs(d__1)) <= tol) {
10339
*k = 0;
10340
i__1 = *n;
10341
for (j = 1; j <= i__1; ++j) {
10342
perm[j] = indxq[indx[j]];
10343
zcopy_(qsiz, &q[perm[j] * q_dim1 + 1], &c__1, &q2[j * q2_dim1 + 1]
10344
, &c__1);
10345
/* L50: */
10346
}
10347
zlacpy_("A", qsiz, n, &q2[q2_dim1 + 1], ldq2, &q[q_dim1 + 1], ldq);
10348
return 0;
10349
}
10350
10351
/*
10352
If there are multiple eigenvalues then the problem deflates. Here
10353
the number of equal eigenvalues are found. As each equal
10354
eigenvalue is found, an elementary reflector is computed to rotate
10355
the corresponding eigensubspace so that the corresponding
10356
components of Z are zero in this new basis.
10357
*/
10358
10359
*k = 0;
10360
k2 = *n + 1;
10361
i__1 = *n;
10362
for (j = 1; j <= i__1; ++j) {
10363
if (*rho * (d__1 = z__[j], abs(d__1)) <= tol) {
10364
10365
/* Deflate due to small z component. */
10366
10367
--k2;
10368
indxp[k2] = j;
10369
if (j == *n) {
10370
goto L100;
10371
}
10372
} else {
10373
jlam = j;
10374
goto L70;
10375
}
10376
/* L60: */
10377
}
10378
L70:
10379
++j;
10380
if (j > *n) {
10381
goto L90;
10382
}
10383
if (*rho * (d__1 = z__[j], abs(d__1)) <= tol) {
10384
10385
/* Deflate due to small z component. */
10386
10387
--k2;
10388
indxp[k2] = j;
10389
} else {
10390
10391
/* Check if eigenvalues are close enough to allow deflation. */
10392
10393
s = z__[jlam];
10394
c__ = z__[j];
10395
10396
/*
10397
Find sqrt(a**2+b**2) without overflow or
10398
destructive underflow.
10399
*/
10400
10401
tau = dlapy2_(&c__, &s);
10402
t = d__[j] - d__[jlam];
10403
c__ /= tau;
10404
s = -s / tau;
10405
if ((d__1 = t * c__ * s, abs(d__1)) <= tol) {
10406
10407
/* Deflation is possible. */
10408
10409
z__[j] = tau;
10410
z__[jlam] = 0.;
10411
10412
/* Record the appropriate Givens rotation */
10413
10414
++(*givptr);
10415
givcol[(*givptr << 1) + 1] = indxq[indx[jlam]];
10416
givcol[(*givptr << 1) + 2] = indxq[indx[j]];
10417
givnum[(*givptr << 1) + 1] = c__;
10418
givnum[(*givptr << 1) + 2] = s;
10419
zdrot_(qsiz, &q[indxq[indx[jlam]] * q_dim1 + 1], &c__1, &q[indxq[
10420
indx[j]] * q_dim1 + 1], &c__1, &c__, &s);
10421
t = d__[jlam] * c__ * c__ + d__[j] * s * s;
10422
d__[j] = d__[jlam] * s * s + d__[j] * c__ * c__;
10423
d__[jlam] = t;
10424
--k2;
10425
i__ = 1;
10426
L80:
10427
if (k2 + i__ <= *n) {
10428
if (d__[jlam] < d__[indxp[k2 + i__]]) {
10429
indxp[k2 + i__ - 1] = indxp[k2 + i__];
10430
indxp[k2 + i__] = jlam;
10431
++i__;
10432
goto L80;
10433
} else {
10434
indxp[k2 + i__ - 1] = jlam;
10435
}
10436
} else {
10437
indxp[k2 + i__ - 1] = jlam;
10438
}
10439
jlam = j;
10440
} else {
10441
++(*k);
10442
w[*k] = z__[jlam];
10443
dlamda[*k] = d__[jlam];
10444
indxp[*k] = jlam;
10445
jlam = j;
10446
}
10447
}
10448
goto L70;
10449
L90:
10450
10451
/* Record the last eigenvalue. */
10452
10453
++(*k);
10454
w[*k] = z__[jlam];
10455
dlamda[*k] = d__[jlam];
10456
indxp[*k] = jlam;
10457
10458
L100:
10459
10460
/*
10461
Sort the eigenvalues and corresponding eigenvectors into DLAMDA
10462
and Q2 respectively. The eigenvalues/vectors which were not
10463
deflated go into the first K slots of DLAMDA and Q2 respectively,
10464
while those which were deflated go into the last N - K slots.
10465
*/
10466
10467
i__1 = *n;
10468
for (j = 1; j <= i__1; ++j) {
10469
jp = indxp[j];
10470
dlamda[j] = d__[jp];
10471
perm[j] = indxq[indx[jp]];
10472
zcopy_(qsiz, &q[perm[j] * q_dim1 + 1], &c__1, &q2[j * q2_dim1 + 1], &
10473
c__1);
10474
/* L110: */
10475
}
10476
10477
/*
10478
The deflated eigenvalues and their corresponding vectors go back
10479
into the last N - K slots of D and Q respectively.
10480
*/
10481
10482
if (*k < *n) {
10483
i__1 = *n - *k;
10484
dcopy_(&i__1, &dlamda[*k + 1], &c__1, &d__[*k + 1], &c__1);
10485
i__1 = *n - *k;
10486
zlacpy_("A", qsiz, &i__1, &q2[(*k + 1) * q2_dim1 + 1], ldq2, &q[(*k +
10487
1) * q_dim1 + 1], ldq);
10488
}
10489
10490
return 0;
10491
10492
/* End of ZLAED8 */
10493
10494
} /* zlaed8_ */
10495
10496
/* Subroutine */ int zlahqr_(logical *wantt, logical *wantz, integer *n,
10497
integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh,
10498
doublecomplex *w, integer *iloz, integer *ihiz, doublecomplex *z__,
10499
integer *ldz, integer *info)
10500
{
10501
/* System generated locals */
10502
integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4;
10503
doublereal d__1, d__2, d__3, d__4, d__5, d__6;
10504
doublecomplex z__1, z__2, z__3, z__4, z__5, z__6, z__7;
10505
10506
/* Local variables */
10507
static integer i__, j, k, l, m;
10508
static doublereal s;
10509
static doublecomplex t, u, v[2], x, y;
10510
static integer i1, i2;
10511
static doublecomplex t1;
10512
static doublereal t2;
10513
static doublecomplex v2;
10514
static doublereal aa, ab, ba, bb, h10;
10515
static doublecomplex h11;
10516
static doublereal h21;
10517
static doublecomplex h22, sc;
10518
static integer nh, nz;
10519
static doublereal sx;
10520
static integer jhi;
10521
static doublecomplex h11s;
10522
static integer jlo, its;
10523
static doublereal ulp;
10524
static doublecomplex sum;
10525
static doublereal tst;
10526
static doublecomplex temp;
10527
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
10528
doublecomplex *, integer *);
10529
static doublereal rtemp;
10530
extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
10531
doublecomplex *, integer *), dlabad_(doublereal *, doublereal *);
10532
10533
static doublereal safmin, safmax;
10534
extern /* Subroutine */ int zlarfg_(integer *, doublecomplex *,
10535
doublecomplex *, integer *, doublecomplex *);
10536
extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
10537
doublecomplex *);
10538
static doublereal smlnum;
10539
10540
10541
/*
10542
-- LAPACK auxiliary routine (version 3.2) --
10543
Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
10544
November 2006
10545
10546
10547
Purpose
10548
=======
10549
10550
ZLAHQR is an auxiliary routine called by CHSEQR to update the
10551
eigenvalues and Schur decomposition already computed by CHSEQR, by
10552
dealing with the Hessenberg submatrix in rows and columns ILO to
10553
IHI.
10554
10555
Arguments
10556
=========
10557
10558
WANTT (input) LOGICAL
10559
= .TRUE. : the full Schur form T is required;
10560
= .FALSE.: only eigenvalues are required.
10561
10562
WANTZ (input) LOGICAL
10563
= .TRUE. : the matrix of Schur vectors Z is required;
10564
= .FALSE.: Schur vectors are not required.
10565
10566
N (input) INTEGER
10567
The order of the matrix H. N >= 0.
10568
10569
ILO (input) INTEGER
10570
IHI (input) INTEGER
10571
It is assumed that H is already upper triangular in rows and
10572
columns IHI+1:N, and that H(ILO,ILO-1) = 0 (unless ILO = 1).
10573
ZLAHQR works primarily with the Hessenberg submatrix in rows
10574
and columns ILO to IHI, but applies transformations to all of
10575
H if WANTT is .TRUE..
10576
1 <= ILO <= max(1,IHI); IHI <= N.
10577
10578
H (input/output) COMPLEX*16 array, dimension (LDH,N)
10579
On entry, the upper Hessenberg matrix H.
10580
On exit, if INFO is zero and if WANTT is .TRUE., then H
10581
is upper triangular in rows and columns ILO:IHI. If INFO
10582
is zero and if WANTT is .FALSE., then the contents of H
10583
are unspecified on exit. The output state of H in case
10584
INF is positive is below under the description of INFO.
10585
10586
LDH (input) INTEGER
10587
The leading dimension of the array H. LDH >= max(1,N).
10588
10589
W (output) COMPLEX*16 array, dimension (N)
10590
The computed eigenvalues ILO to IHI are stored in the
10591
corresponding elements of W. If WANTT is .TRUE., the
10592
eigenvalues are stored in the same order as on the diagonal
10593
of the Schur form returned in H, with W(i) = H(i,i).
10594
10595
ILOZ (input) INTEGER
10596
IHIZ (input) INTEGER
10597
Specify the rows of Z to which transformations must be
10598
applied if WANTZ is .TRUE..
10599
1 <= ILOZ <= ILO; IHI <= IHIZ <= N.
10600
10601
Z (input/output) COMPLEX*16 array, dimension (LDZ,N)
10602
If WANTZ is .TRUE., on entry Z must contain the current
10603
matrix Z of transformations accumulated by CHSEQR, and on
10604
exit Z has been updated; transformations are applied only to
10605
the submatrix Z(ILOZ:IHIZ,ILO:IHI).
10606
If WANTZ is .FALSE., Z is not referenced.
10607
10608
LDZ (input) INTEGER
10609
The leading dimension of the array Z. LDZ >= max(1,N).
10610
10611
INFO (output) INTEGER
10612
= 0: successful exit
10613
.GT. 0: if INFO = i, ZLAHQR failed to compute all the
10614
eigenvalues ILO to IHI in a total of 30 iterations
10615
per eigenvalue; elements i+1:ihi of W contain
10616
those eigenvalues which have been successfully
10617
computed.
10618
10619
If INFO .GT. 0 and WANTT is .FALSE., then on exit,
10620
the remaining unconverged eigenvalues are the
10621
eigenvalues of the upper Hessenberg matrix
10622
rows and columns ILO thorugh INFO of the final,
10623
output value of H.
10624
10625
If INFO .GT. 0 and WANTT is .TRUE., then on exit
10626
(*) (initial value of H)*U = U*(final value of H)
10627
where U is an orthognal matrix. The final
10628
value of H is upper Hessenberg and triangular in
10629
rows and columns INFO+1 through IHI.
10630
10631
If INFO .GT. 0 and WANTZ is .TRUE., then on exit
10632
(final value of Z) = (initial value of Z)*U
10633
where U is the orthogonal matrix in (*)
10634
(regardless of the value of WANTT.)
10635
10636
Further Details
10637
===============
10638
10639
02-96 Based on modifications by
10640
David Day, Sandia National Laboratory, USA
10641
10642
12-04 Further modifications by
10643
Ralph Byers, University of Kansas, USA
10644
This is a modified version of ZLAHQR from LAPACK version 3.0.
10645
It is (1) more robust against overflow and underflow and
10646
(2) adopts the more conservative Ahues & Tisseur stopping
10647
criterion (LAWN 122, 1997).
10648
10649
=========================================================
10650
*/
10651
10652
10653
/* Parameter adjustments */
10654
h_dim1 = *ldh;
10655
h_offset = 1 + h_dim1;
10656
h__ -= h_offset;
10657
--w;
10658
z_dim1 = *ldz;
10659
z_offset = 1 + z_dim1;
10660
z__ -= z_offset;
10661
10662
/* Function Body */
10663
*info = 0;
10664
10665
/* Quick return if possible */
10666
10667
if (*n == 0) {
10668
return 0;
10669
}
10670
if (*ilo == *ihi) {
10671
i__1 = *ilo;
10672
i__2 = *ilo + *ilo * h_dim1;
10673
w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
10674
return 0;
10675
}
10676
10677
/* ==== clear out the trash ==== */
10678
i__1 = *ihi - 3;
10679
for (j = *ilo; j <= i__1; ++j) {
10680
i__2 = j + 2 + j * h_dim1;
10681
h__[i__2].r = 0., h__[i__2].i = 0.;
10682
i__2 = j + 3 + j * h_dim1;
10683
h__[i__2].r = 0., h__[i__2].i = 0.;
10684
/* L10: */
10685
}
10686
if (*ilo <= *ihi - 2) {
10687
i__1 = *ihi + (*ihi - 2) * h_dim1;
10688
h__[i__1].r = 0., h__[i__1].i = 0.;
10689
}
10690
/* ==== ensure that subdiagonal entries are real ==== */
10691
if (*wantt) {
10692
jlo = 1;
10693
jhi = *n;
10694
} else {
10695
jlo = *ilo;
10696
jhi = *ihi;
10697
}
10698
i__1 = *ihi;
10699
for (i__ = *ilo + 1; i__ <= i__1; ++i__) {
10700
if (d_imag(&h__[i__ + (i__ - 1) * h_dim1]) != 0.) {
10701
/*
10702
==== The following redundant normalization
10703
. avoids problems with both gradual and
10704
. sudden underflow in ABS(H(I,I-1)) ====
10705
*/
10706
i__2 = i__ + (i__ - 1) * h_dim1;
10707
i__3 = i__ + (i__ - 1) * h_dim1;
10708
d__3 = (d__1 = h__[i__3].r, abs(d__1)) + (d__2 = d_imag(&h__[i__
10709
+ (i__ - 1) * h_dim1]), abs(d__2));
10710
z__1.r = h__[i__2].r / d__3, z__1.i = h__[i__2].i / d__3;
10711
sc.r = z__1.r, sc.i = z__1.i;
10712
d_cnjg(&z__2, &sc);
10713
d__1 = z_abs(&sc);
10714
z__1.r = z__2.r / d__1, z__1.i = z__2.i / d__1;
10715
sc.r = z__1.r, sc.i = z__1.i;
10716
i__2 = i__ + (i__ - 1) * h_dim1;
10717
d__1 = z_abs(&h__[i__ + (i__ - 1) * h_dim1]);
10718
h__[i__2].r = d__1, h__[i__2].i = 0.;
10719
i__2 = jhi - i__ + 1;
10720
zscal_(&i__2, &sc, &h__[i__ + i__ * h_dim1], ldh);
10721
/* Computing MIN */
10722
i__3 = jhi, i__4 = i__ + 1;
10723
i__2 = min(i__3,i__4) - jlo + 1;
10724
d_cnjg(&z__1, &sc);
10725
zscal_(&i__2, &z__1, &h__[jlo + i__ * h_dim1], &c__1);
10726
if (*wantz) {
10727
i__2 = *ihiz - *iloz + 1;
10728
d_cnjg(&z__1, &sc);
10729
zscal_(&i__2, &z__1, &z__[*iloz + i__ * z_dim1], &c__1);
10730
}
10731
}
10732
/* L20: */
10733
}
10734
10735
nh = *ihi - *ilo + 1;
10736
nz = *ihiz - *iloz + 1;
10737
10738
/* Set machine-dependent constants for the stopping criterion. */
10739
10740
safmin = SAFEMINIMUM;
10741
safmax = 1. / safmin;
10742
dlabad_(&safmin, &safmax);
10743
ulp = PRECISION;
10744
smlnum = safmin * ((doublereal) nh / ulp);
10745
10746
/*
10747
I1 and I2 are the indices of the first row and last column of H
10748
to which transformations must be applied. If eigenvalues only are
10749
being computed, I1 and I2 are set inside the main loop.
10750
*/
10751
10752
if (*wantt) {
10753
i1 = 1;
10754
i2 = *n;
10755
}
10756
10757
/*
10758
The main loop begins here. I is the loop index and decreases from
10759
IHI to ILO in steps of 1. Each iteration of the loop works
10760
with the active submatrix in rows and columns L to I.
10761
Eigenvalues I+1 to IHI have already converged. Either L = ILO, or
10762
H(L,L-1) is negligible so that the matrix splits.
10763
*/
10764
10765
i__ = *ihi;
10766
L30:
10767
if (i__ < *ilo) {
10768
goto L150;
10769
}
10770
10771
/*
10772
Perform QR iterations on rows and columns ILO to I until a
10773
submatrix of order 1 splits off at the bottom because a
10774
subdiagonal element has become negligible.
10775
*/
10776
10777
l = *ilo;
10778
for (its = 0; its <= 30; ++its) {
10779
10780
/* Look for a single small subdiagonal element. */
10781
10782
i__1 = l + 1;
10783
for (k = i__; k >= i__1; --k) {
10784
i__2 = k + (k - 1) * h_dim1;
10785
if ((d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[k + (k
10786
- 1) * h_dim1]), abs(d__2)) <= smlnum) {
10787
goto L50;
10788
}
10789
i__2 = k - 1 + (k - 1) * h_dim1;
10790
i__3 = k + k * h_dim1;
10791
tst = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[k - 1
10792
+ (k - 1) * h_dim1]), abs(d__2)) + ((d__3 = h__[i__3].r,
10793
abs(d__3)) + (d__4 = d_imag(&h__[k + k * h_dim1]), abs(
10794
d__4)));
10795
if (tst == 0.) {
10796
if (k - 2 >= *ilo) {
10797
i__2 = k - 1 + (k - 2) * h_dim1;
10798
tst += (d__1 = h__[i__2].r, abs(d__1));
10799
}
10800
if (k + 1 <= *ihi) {
10801
i__2 = k + 1 + k * h_dim1;
10802
tst += (d__1 = h__[i__2].r, abs(d__1));
10803
}
10804
}
10805
/*
10806
==== The following is a conservative small subdiagonal
10807
. deflation criterion due to Ahues & Tisseur (LAWN 122,
10808
. 1997). It has better mathematical foundation and
10809
. improves accuracy in some examples. ====
10810
*/
10811
i__2 = k + (k - 1) * h_dim1;
10812
if ((d__1 = h__[i__2].r, abs(d__1)) <= ulp * tst) {
10813
/* Computing MAX */
10814
i__2 = k + (k - 1) * h_dim1;
10815
i__3 = k - 1 + k * h_dim1;
10816
d__5 = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[
10817
k + (k - 1) * h_dim1]), abs(d__2)), d__6 = (d__3 =
10818
h__[i__3].r, abs(d__3)) + (d__4 = d_imag(&h__[k - 1 +
10819
k * h_dim1]), abs(d__4));
10820
ab = max(d__5,d__6);
10821
/* Computing MIN */
10822
i__2 = k + (k - 1) * h_dim1;
10823
i__3 = k - 1 + k * h_dim1;
10824
d__5 = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[
10825
k + (k - 1) * h_dim1]), abs(d__2)), d__6 = (d__3 =
10826
h__[i__3].r, abs(d__3)) + (d__4 = d_imag(&h__[k - 1 +
10827
k * h_dim1]), abs(d__4));
10828
ba = min(d__5,d__6);
10829
i__2 = k - 1 + (k - 1) * h_dim1;
10830
i__3 = k + k * h_dim1;
10831
z__2.r = h__[i__2].r - h__[i__3].r, z__2.i = h__[i__2].i -
10832
h__[i__3].i;
10833
z__1.r = z__2.r, z__1.i = z__2.i;
10834
/* Computing MAX */
10835
i__4 = k + k * h_dim1;
10836
d__5 = (d__1 = h__[i__4].r, abs(d__1)) + (d__2 = d_imag(&h__[
10837
k + k * h_dim1]), abs(d__2)), d__6 = (d__3 = z__1.r,
10838
abs(d__3)) + (d__4 = d_imag(&z__1), abs(d__4));
10839
aa = max(d__5,d__6);
10840
i__2 = k - 1 + (k - 1) * h_dim1;
10841
i__3 = k + k * h_dim1;
10842
z__2.r = h__[i__2].r - h__[i__3].r, z__2.i = h__[i__2].i -
10843
h__[i__3].i;
10844
z__1.r = z__2.r, z__1.i = z__2.i;
10845
/* Computing MIN */
10846
i__4 = k + k * h_dim1;
10847
d__5 = (d__1 = h__[i__4].r, abs(d__1)) + (d__2 = d_imag(&h__[
10848
k + k * h_dim1]), abs(d__2)), d__6 = (d__3 = z__1.r,
10849
abs(d__3)) + (d__4 = d_imag(&z__1), abs(d__4));
10850
bb = min(d__5,d__6);
10851
s = aa + ab;
10852
/* Computing MAX */
10853
d__1 = smlnum, d__2 = ulp * (bb * (aa / s));
10854
if (ba * (ab / s) <= max(d__1,d__2)) {
10855
goto L50;
10856
}
10857
}
10858
/* L40: */
10859
}
10860
L50:
10861
l = k;
10862
if (l > *ilo) {
10863
10864
/* H(L,L-1) is negligible */
10865
10866
i__1 = l + (l - 1) * h_dim1;
10867
h__[i__1].r = 0., h__[i__1].i = 0.;
10868
}
10869
10870
/* Exit from loop if a submatrix of order 1 has split off. */
10871
10872
if (l >= i__) {
10873
goto L140;
10874
}
10875
10876
/*
10877
Now the active submatrix is in rows and columns L to I. If
10878
eigenvalues only are being computed, only the active submatrix
10879
need be transformed.
10880
*/
10881
10882
if (! (*wantt)) {
10883
i1 = l;
10884
i2 = i__;
10885
}
10886
10887
if (its == 10) {
10888
10889
/* Exceptional shift. */
10890
10891
i__1 = l + 1 + l * h_dim1;
10892
s = (d__1 = h__[i__1].r, abs(d__1)) * .75;
10893
i__1 = l + l * h_dim1;
10894
z__1.r = s + h__[i__1].r, z__1.i = h__[i__1].i;
10895
t.r = z__1.r, t.i = z__1.i;
10896
} else if (its == 20) {
10897
10898
/* Exceptional shift. */
10899
10900
i__1 = i__ + (i__ - 1) * h_dim1;
10901
s = (d__1 = h__[i__1].r, abs(d__1)) * .75;
10902
i__1 = i__ + i__ * h_dim1;
10903
z__1.r = s + h__[i__1].r, z__1.i = h__[i__1].i;
10904
t.r = z__1.r, t.i = z__1.i;
10905
} else {
10906
10907
/* Wilkinson's shift. */
10908
10909
i__1 = i__ + i__ * h_dim1;
10910
t.r = h__[i__1].r, t.i = h__[i__1].i;
10911
z_sqrt(&z__2, &h__[i__ - 1 + i__ * h_dim1]);
10912
z_sqrt(&z__3, &h__[i__ + (i__ - 1) * h_dim1]);
10913
z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i = z__2.r *
10914
z__3.i + z__2.i * z__3.r;
10915
u.r = z__1.r, u.i = z__1.i;
10916
s = (d__1 = u.r, abs(d__1)) + (d__2 = d_imag(&u), abs(d__2));
10917
if (s != 0.) {
10918
i__1 = i__ - 1 + (i__ - 1) * h_dim1;
10919
z__2.r = h__[i__1].r - t.r, z__2.i = h__[i__1].i - t.i;
10920
z__1.r = z__2.r * .5, z__1.i = z__2.i * .5;
10921
x.r = z__1.r, x.i = z__1.i;
10922
sx = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x), abs(d__2));
10923
/* Computing MAX */
10924
d__3 = s, d__4 = (d__1 = x.r, abs(d__1)) + (d__2 = d_imag(&x),
10925
abs(d__2));
10926
s = max(d__3,d__4);
10927
z__5.r = x.r / s, z__5.i = x.i / s;
10928
pow_zi(&z__4, &z__5, &c__2);
10929
z__7.r = u.r / s, z__7.i = u.i / s;
10930
pow_zi(&z__6, &z__7, &c__2);
10931
z__3.r = z__4.r + z__6.r, z__3.i = z__4.i + z__6.i;
10932
z_sqrt(&z__2, &z__3);
10933
z__1.r = s * z__2.r, z__1.i = s * z__2.i;
10934
y.r = z__1.r, y.i = z__1.i;
10935
if (sx > 0.) {
10936
z__1.r = x.r / sx, z__1.i = x.i / sx;
10937
z__2.r = x.r / sx, z__2.i = x.i / sx;
10938
if (z__1.r * y.r + d_imag(&z__2) * d_imag(&y) < 0.) {
10939
z__3.r = -y.r, z__3.i = -y.i;
10940
y.r = z__3.r, y.i = z__3.i;
10941
}
10942
}
10943
z__4.r = x.r + y.r, z__4.i = x.i + y.i;
10944
zladiv_(&z__3, &u, &z__4);
10945
z__2.r = u.r * z__3.r - u.i * z__3.i, z__2.i = u.r * z__3.i +
10946
u.i * z__3.r;
10947
z__1.r = t.r - z__2.r, z__1.i = t.i - z__2.i;
10948
t.r = z__1.r, t.i = z__1.i;
10949
}
10950
}
10951
10952
/* Look for two consecutive small subdiagonal elements. */
10953
10954
i__1 = l + 1;
10955
for (m = i__ - 1; m >= i__1; --m) {
10956
10957
/*
10958
Determine the effect of starting the single-shift QR
10959
iteration at row M, and see if this would make H(M,M-1)
10960
negligible.
10961
*/
10962
10963
i__2 = m + m * h_dim1;
10964
h11.r = h__[i__2].r, h11.i = h__[i__2].i;
10965
i__2 = m + 1 + (m + 1) * h_dim1;
10966
h22.r = h__[i__2].r, h22.i = h__[i__2].i;
10967
z__1.r = h11.r - t.r, z__1.i = h11.i - t.i;
10968
h11s.r = z__1.r, h11s.i = z__1.i;
10969
i__2 = m + 1 + m * h_dim1;
10970
h21 = h__[i__2].r;
10971
s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2))
10972
+ abs(h21);
10973
z__1.r = h11s.r / s, z__1.i = h11s.i / s;
10974
h11s.r = z__1.r, h11s.i = z__1.i;
10975
h21 /= s;
10976
v[0].r = h11s.r, v[0].i = h11s.i;
10977
v[1].r = h21, v[1].i = 0.;
10978
i__2 = m + (m - 1) * h_dim1;
10979
h10 = h__[i__2].r;
10980
if (abs(h10) * abs(h21) <= ulp * (((d__1 = h11s.r, abs(d__1)) + (
10981
d__2 = d_imag(&h11s), abs(d__2))) * ((d__3 = h11.r, abs(
10982
d__3)) + (d__4 = d_imag(&h11), abs(d__4)) + ((d__5 =
10983
h22.r, abs(d__5)) + (d__6 = d_imag(&h22), abs(d__6)))))) {
10984
goto L70;
10985
}
10986
/* L60: */
10987
}
10988
i__1 = l + l * h_dim1;
10989
h11.r = h__[i__1].r, h11.i = h__[i__1].i;
10990
i__1 = l + 1 + (l + 1) * h_dim1;
10991
h22.r = h__[i__1].r, h22.i = h__[i__1].i;
10992
z__1.r = h11.r - t.r, z__1.i = h11.i - t.i;
10993
h11s.r = z__1.r, h11s.i = z__1.i;
10994
i__1 = l + 1 + l * h_dim1;
10995
h21 = h__[i__1].r;
10996
s = (d__1 = h11s.r, abs(d__1)) + (d__2 = d_imag(&h11s), abs(d__2)) +
10997
abs(h21);
10998
z__1.r = h11s.r / s, z__1.i = h11s.i / s;
10999
h11s.r = z__1.r, h11s.i = z__1.i;
11000
h21 /= s;
11001
v[0].r = h11s.r, v[0].i = h11s.i;
11002
v[1].r = h21, v[1].i = 0.;
11003
L70:
11004
11005
/* Single-shift QR step */
11006
11007
i__1 = i__ - 1;
11008
for (k = m; k <= i__1; ++k) {
11009
11010
/*
11011
The first iteration of this loop determines a reflection G
11012
from the vector V and applies it from left and right to H,
11013
thus creating a nonzero bulge below the subdiagonal.
11014
11015
Each subsequent iteration determines a reflection G to
11016
restore the Hessenberg form in the (K-1)th column, and thus
11017
chases the bulge one step toward the bottom of the active
11018
submatrix.
11019
11020
V(2) is always real before the call to ZLARFG, and hence
11021
after the call T2 ( = T1*V(2) ) is also real.
11022
*/
11023
11024
if (k > m) {
11025
zcopy_(&c__2, &h__[k + (k - 1) * h_dim1], &c__1, v, &c__1);
11026
}
11027
zlarfg_(&c__2, v, &v[1], &c__1, &t1);
11028
if (k > m) {
11029
i__2 = k + (k - 1) * h_dim1;
11030
h__[i__2].r = v[0].r, h__[i__2].i = v[0].i;
11031
i__2 = k + 1 + (k - 1) * h_dim1;
11032
h__[i__2].r = 0., h__[i__2].i = 0.;
11033
}
11034
v2.r = v[1].r, v2.i = v[1].i;
11035
z__1.r = t1.r * v2.r - t1.i * v2.i, z__1.i = t1.r * v2.i + t1.i *
11036
v2.r;
11037
t2 = z__1.r;
11038
11039
/*
11040
Apply G from the left to transform the rows of the matrix
11041
in columns K to I2.
11042
*/
11043
11044
i__2 = i2;
11045
for (j = k; j <= i__2; ++j) {
11046
d_cnjg(&z__3, &t1);
11047
i__3 = k + j * h_dim1;
11048
z__2.r = z__3.r * h__[i__3].r - z__3.i * h__[i__3].i, z__2.i =
11049
z__3.r * h__[i__3].i + z__3.i * h__[i__3].r;
11050
i__4 = k + 1 + j * h_dim1;
11051
z__4.r = t2 * h__[i__4].r, z__4.i = t2 * h__[i__4].i;
11052
z__1.r = z__2.r + z__4.r, z__1.i = z__2.i + z__4.i;
11053
sum.r = z__1.r, sum.i = z__1.i;
11054
i__3 = k + j * h_dim1;
11055
i__4 = k + j * h_dim1;
11056
z__1.r = h__[i__4].r - sum.r, z__1.i = h__[i__4].i - sum.i;
11057
h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
11058
i__3 = k + 1 + j * h_dim1;
11059
i__4 = k + 1 + j * h_dim1;
11060
z__2.r = sum.r * v2.r - sum.i * v2.i, z__2.i = sum.r * v2.i +
11061
sum.i * v2.r;
11062
z__1.r = h__[i__4].r - z__2.r, z__1.i = h__[i__4].i - z__2.i;
11063
h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
11064
/* L80: */
11065
}
11066
11067
/*
11068
Apply G from the right to transform the columns of the
11069
matrix in rows I1 to min(K+2,I).
11070
11071
Computing MIN
11072
*/
11073
i__3 = k + 2;
11074
i__2 = min(i__3,i__);
11075
for (j = i1; j <= i__2; ++j) {
11076
i__3 = j + k * h_dim1;
11077
z__2.r = t1.r * h__[i__3].r - t1.i * h__[i__3].i, z__2.i =
11078
t1.r * h__[i__3].i + t1.i * h__[i__3].r;
11079
i__4 = j + (k + 1) * h_dim1;
11080
z__3.r = t2 * h__[i__4].r, z__3.i = t2 * h__[i__4].i;
11081
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
11082
sum.r = z__1.r, sum.i = z__1.i;
11083
i__3 = j + k * h_dim1;
11084
i__4 = j + k * h_dim1;
11085
z__1.r = h__[i__4].r - sum.r, z__1.i = h__[i__4].i - sum.i;
11086
h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
11087
i__3 = j + (k + 1) * h_dim1;
11088
i__4 = j + (k + 1) * h_dim1;
11089
d_cnjg(&z__3, &v2);
11090
z__2.r = sum.r * z__3.r - sum.i * z__3.i, z__2.i = sum.r *
11091
z__3.i + sum.i * z__3.r;
11092
z__1.r = h__[i__4].r - z__2.r, z__1.i = h__[i__4].i - z__2.i;
11093
h__[i__3].r = z__1.r, h__[i__3].i = z__1.i;
11094
/* L90: */
11095
}
11096
11097
if (*wantz) {
11098
11099
/* Accumulate transformations in the matrix Z */
11100
11101
i__2 = *ihiz;
11102
for (j = *iloz; j <= i__2; ++j) {
11103
i__3 = j + k * z_dim1;
11104
z__2.r = t1.r * z__[i__3].r - t1.i * z__[i__3].i, z__2.i =
11105
t1.r * z__[i__3].i + t1.i * z__[i__3].r;
11106
i__4 = j + (k + 1) * z_dim1;
11107
z__3.r = t2 * z__[i__4].r, z__3.i = t2 * z__[i__4].i;
11108
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
11109
sum.r = z__1.r, sum.i = z__1.i;
11110
i__3 = j + k * z_dim1;
11111
i__4 = j + k * z_dim1;
11112
z__1.r = z__[i__4].r - sum.r, z__1.i = z__[i__4].i -
11113
sum.i;
11114
z__[i__3].r = z__1.r, z__[i__3].i = z__1.i;
11115
i__3 = j + (k + 1) * z_dim1;
11116
i__4 = j + (k + 1) * z_dim1;
11117
d_cnjg(&z__3, &v2);
11118
z__2.r = sum.r * z__3.r - sum.i * z__3.i, z__2.i = sum.r *
11119
z__3.i + sum.i * z__3.r;
11120
z__1.r = z__[i__4].r - z__2.r, z__1.i = z__[i__4].i -
11121
z__2.i;
11122
z__[i__3].r = z__1.r, z__[i__3].i = z__1.i;
11123
/* L100: */
11124
}
11125
}
11126
11127
if (k == m && m > l) {
11128
11129
/*
11130
If the QR step was started at row M > L because two
11131
consecutive small subdiagonals were found, then extra
11132
scaling must be performed to ensure that H(M,M-1) remains
11133
real.
11134
*/
11135
11136
z__1.r = 1. - t1.r, z__1.i = 0. - t1.i;
11137
temp.r = z__1.r, temp.i = z__1.i;
11138
d__1 = z_abs(&temp);
11139
z__1.r = temp.r / d__1, z__1.i = temp.i / d__1;
11140
temp.r = z__1.r, temp.i = z__1.i;
11141
i__2 = m + 1 + m * h_dim1;
11142
i__3 = m + 1 + m * h_dim1;
11143
d_cnjg(&z__2, &temp);
11144
z__1.r = h__[i__3].r * z__2.r - h__[i__3].i * z__2.i, z__1.i =
11145
h__[i__3].r * z__2.i + h__[i__3].i * z__2.r;
11146
h__[i__2].r = z__1.r, h__[i__2].i = z__1.i;
11147
if (m + 2 <= i__) {
11148
i__2 = m + 2 + (m + 1) * h_dim1;
11149
i__3 = m + 2 + (m + 1) * h_dim1;
11150
z__1.r = h__[i__3].r * temp.r - h__[i__3].i * temp.i,
11151
z__1.i = h__[i__3].r * temp.i + h__[i__3].i *
11152
temp.r;
11153
h__[i__2].r = z__1.r, h__[i__2].i = z__1.i;
11154
}
11155
i__2 = i__;
11156
for (j = m; j <= i__2; ++j) {
11157
if (j != m + 1) {
11158
if (i2 > j) {
11159
i__3 = i2 - j;
11160
zscal_(&i__3, &temp, &h__[j + (j + 1) * h_dim1],
11161
ldh);
11162
}
11163
i__3 = j - i1;
11164
d_cnjg(&z__1, &temp);
11165
zscal_(&i__3, &z__1, &h__[i1 + j * h_dim1], &c__1);
11166
if (*wantz) {
11167
d_cnjg(&z__1, &temp);
11168
zscal_(&nz, &z__1, &z__[*iloz + j * z_dim1], &
11169
c__1);
11170
}
11171
}
11172
/* L110: */
11173
}
11174
}
11175
/* L120: */
11176
}
11177
11178
/* Ensure that H(I,I-1) is real. */
11179
11180
i__1 = i__ + (i__ - 1) * h_dim1;
11181
temp.r = h__[i__1].r, temp.i = h__[i__1].i;
11182
if (d_imag(&temp) != 0.) {
11183
rtemp = z_abs(&temp);
11184
i__1 = i__ + (i__ - 1) * h_dim1;
11185
h__[i__1].r = rtemp, h__[i__1].i = 0.;
11186
z__1.r = temp.r / rtemp, z__1.i = temp.i / rtemp;
11187
temp.r = z__1.r, temp.i = z__1.i;
11188
if (i2 > i__) {
11189
i__1 = i2 - i__;
11190
d_cnjg(&z__1, &temp);
11191
zscal_(&i__1, &z__1, &h__[i__ + (i__ + 1) * h_dim1], ldh);
11192
}
11193
i__1 = i__ - i1;
11194
zscal_(&i__1, &temp, &h__[i1 + i__ * h_dim1], &c__1);
11195
if (*wantz) {
11196
zscal_(&nz, &temp, &z__[*iloz + i__ * z_dim1], &c__1);
11197
}
11198
}
11199
11200
/* L130: */
11201
}
11202
11203
/* Failure to converge in remaining number of iterations */
11204
11205
*info = i__;
11206
return 0;
11207
11208
L140:
11209
11210
/* H(I,I-1) is negligible: one eigenvalue has converged. */
11211
11212
i__1 = i__;
11213
i__2 = i__ + i__ * h_dim1;
11214
w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i;
11215
11216
/* return to start of the main loop with new value of I. */
11217
11218
i__ = l - 1;
11219
goto L30;
11220
11221
L150:
11222
return 0;
11223
11224
/* End of ZLAHQR */
11225
11226
} /* zlahqr_ */
11227
11228
/* Subroutine */ int zlahr2_(integer *n, integer *k, integer *nb,
11229
doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *t,
11230
integer *ldt, doublecomplex *y, integer *ldy)
11231
{
11232
/* System generated locals */
11233
integer a_dim1, a_offset, t_dim1, t_offset, y_dim1, y_offset, i__1, i__2,
11234
i__3;
11235
doublecomplex z__1;
11236
11237
/* Local variables */
11238
static integer i__;
11239
static doublecomplex ei;
11240
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
11241
doublecomplex *, integer *), zgemm_(char *, char *, integer *,
11242
integer *, integer *, doublecomplex *, doublecomplex *, integer *,
11243
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
11244
integer *), zgemv_(char *, integer *, integer *,
11245
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
11246
integer *, doublecomplex *, doublecomplex *, integer *),
11247
zcopy_(integer *, doublecomplex *, integer *, doublecomplex *,
11248
integer *), ztrmm_(char *, char *, char *, char *, integer *,
11249
integer *, doublecomplex *, doublecomplex *, integer *,
11250
doublecomplex *, integer *),
11251
zaxpy_(integer *, doublecomplex *, doublecomplex *, integer *,
11252
doublecomplex *, integer *), ztrmv_(char *, char *, char *,
11253
integer *, doublecomplex *, integer *, doublecomplex *, integer *), zlarfg_(integer *, doublecomplex *,
11254
doublecomplex *, integer *, doublecomplex *), zlacgv_(integer *,
11255
doublecomplex *, integer *), zlacpy_(char *, integer *, integer *,
11256
doublecomplex *, integer *, doublecomplex *, integer *);
11257
11258
11259
/*
11260
-- LAPACK auxiliary routine (version 3.2.1) --
11261
-- LAPACK is a software package provided by Univ. of Tennessee, --
11262
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
11263
-- April 2009 --
11264
11265
11266
Purpose
11267
=======
11268
11269
ZLAHR2 reduces the first NB columns of A complex general n-BY-(n-k+1)
11270
matrix A so that elements below the k-th subdiagonal are zero. The
11271
reduction is performed by an unitary similarity transformation
11272
Q' * A * Q. The routine returns the matrices V and T which determine
11273
Q as a block reflector I - V*T*V', and also the matrix Y = A * V * T.
11274
11275
This is an auxiliary routine called by ZGEHRD.
11276
11277
Arguments
11278
=========
11279
11280
N (input) INTEGER
11281
The order of the matrix A.
11282
11283
K (input) INTEGER
11284
The offset for the reduction. Elements below the k-th
11285
subdiagonal in the first NB columns are reduced to zero.
11286
K < N.
11287
11288
NB (input) INTEGER
11289
The number of columns to be reduced.
11290
11291
A (input/output) COMPLEX*16 array, dimension (LDA,N-K+1)
11292
On entry, the n-by-(n-k+1) general matrix A.
11293
On exit, the elements on and above the k-th subdiagonal in
11294
the first NB columns are overwritten with the corresponding
11295
elements of the reduced matrix; the elements below the k-th
11296
subdiagonal, with the array TAU, represent the matrix Q as a
11297
product of elementary reflectors. The other columns of A are
11298
unchanged. See Further Details.
11299
11300
LDA (input) INTEGER
11301
The leading dimension of the array A. LDA >= max(1,N).
11302
11303
TAU (output) COMPLEX*16 array, dimension (NB)
11304
The scalar factors of the elementary reflectors. See Further
11305
Details.
11306
11307
T (output) COMPLEX*16 array, dimension (LDT,NB)
11308
The upper triangular matrix T.
11309
11310
LDT (input) INTEGER
11311
The leading dimension of the array T. LDT >= NB.
11312
11313
Y (output) COMPLEX*16 array, dimension (LDY,NB)
11314
The n-by-nb matrix Y.
11315
11316
LDY (input) INTEGER
11317
The leading dimension of the array Y. LDY >= N.
11318
11319
Further Details
11320
===============
11321
11322
The matrix Q is represented as a product of nb elementary reflectors
11323
11324
Q = H(1) H(2) . . . H(nb).
11325
11326
Each H(i) has the form
11327
11328
H(i) = I - tau * v * v'
11329
11330
where tau is a complex scalar, and v is a complex vector with
11331
v(1:i+k-1) = 0, v(i+k) = 1; v(i+k+1:n) is stored on exit in
11332
A(i+k+1:n,i), and tau in TAU(i).
11333
11334
The elements of the vectors v together form the (n-k+1)-by-nb matrix
11335
V which is needed, with T and Y, to apply the transformation to the
11336
unreduced part of the matrix, using an update of the form:
11337
A := (I - V*T*V') * (A - Y*V').
11338
11339
The contents of A on exit are illustrated by the following example
11340
with n = 7, k = 3 and nb = 2:
11341
11342
( a a a a a )
11343
( a a a a a )
11344
( a a a a a )
11345
( h h a a a )
11346
( v1 h a a a )
11347
( v1 v2 a a a )
11348
( v1 v2 a a a )
11349
11350
where a denotes an element of the original matrix A, h denotes a
11351
modified element of the upper Hessenberg matrix H, and vi denotes an
11352
element of the vector defining H(i).
11353
11354
This subroutine is a slight modification of LAPACK-3.0's DLAHRD
11355
incorporating improvements proposed by Quintana-Orti and Van de
11356
Gejin. Note that the entries of A(1:K,2:NB) differ from those
11357
returned by the original LAPACK-3.0's DLAHRD routine. (This
11358
subroutine is not backward compatible with LAPACK-3.0's DLAHRD.)
11359
11360
References
11361
==========
11362
11363
Gregorio Quintana-Orti and Robert van de Geijn, "Improving the
11364
performance of reduction to Hessenberg form," ACM Transactions on
11365
Mathematical Software, 32(2):180-194, June 2006.
11366
11367
=====================================================================
11368
11369
11370
Quick return if possible
11371
*/
11372
11373
/* Parameter adjustments */
11374
--tau;
11375
a_dim1 = *lda;
11376
a_offset = 1 + a_dim1;
11377
a -= a_offset;
11378
t_dim1 = *ldt;
11379
t_offset = 1 + t_dim1;
11380
t -= t_offset;
11381
y_dim1 = *ldy;
11382
y_offset = 1 + y_dim1;
11383
y -= y_offset;
11384
11385
/* Function Body */
11386
if (*n <= 1) {
11387
return 0;
11388
}
11389
11390
i__1 = *nb;
11391
for (i__ = 1; i__ <= i__1; ++i__) {
11392
if (i__ > 1) {
11393
11394
/*
11395
Update A(K+1:N,I)
11396
11397
Update I-th column of A - Y * V'
11398
*/
11399
11400
i__2 = i__ - 1;
11401
zlacgv_(&i__2, &a[*k + i__ - 1 + a_dim1], lda);
11402
i__2 = *n - *k;
11403
i__3 = i__ - 1;
11404
z__1.r = -1., z__1.i = -0.;
11405
zgemv_("NO TRANSPOSE", &i__2, &i__3, &z__1, &y[*k + 1 + y_dim1],
11406
ldy, &a[*k + i__ - 1 + a_dim1], lda, &c_b57, &a[*k + 1 +
11407
i__ * a_dim1], &c__1);
11408
i__2 = i__ - 1;
11409
zlacgv_(&i__2, &a[*k + i__ - 1 + a_dim1], lda);
11410
11411
/*
11412
Apply I - V * T' * V' to this column (call it b) from the
11413
left, using the last column of T as workspace
11414
11415
Let V = ( V1 ) and b = ( b1 ) (first I-1 rows)
11416
( V2 ) ( b2 )
11417
11418
where V1 is unit lower triangular
11419
11420
w := V1' * b1
11421
*/
11422
11423
i__2 = i__ - 1;
11424
zcopy_(&i__2, &a[*k + 1 + i__ * a_dim1], &c__1, &t[*nb * t_dim1 +
11425
1], &c__1);
11426
i__2 = i__ - 1;
11427
ztrmv_("Lower", "Conjugate transpose", "UNIT", &i__2, &a[*k + 1 +
11428
a_dim1], lda, &t[*nb * t_dim1 + 1], &c__1);
11429
11430
/* w := w + V2'*b2 */
11431
11432
i__2 = *n - *k - i__ + 1;
11433
i__3 = i__ - 1;
11434
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &a[*k + i__ +
11435
a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b57,
11436
&t[*nb * t_dim1 + 1], &c__1);
11437
11438
/* w := T'*w */
11439
11440
i__2 = i__ - 1;
11441
ztrmv_("Upper", "Conjugate transpose", "NON-UNIT", &i__2, &t[
11442
t_offset], ldt, &t[*nb * t_dim1 + 1], &c__1);
11443
11444
/* b2 := b2 - V2*w */
11445
11446
i__2 = *n - *k - i__ + 1;
11447
i__3 = i__ - 1;
11448
z__1.r = -1., z__1.i = -0.;
11449
zgemv_("NO TRANSPOSE", &i__2, &i__3, &z__1, &a[*k + i__ + a_dim1],
11450
lda, &t[*nb * t_dim1 + 1], &c__1, &c_b57, &a[*k + i__ +
11451
i__ * a_dim1], &c__1);
11452
11453
/* b1 := b1 - V1*w */
11454
11455
i__2 = i__ - 1;
11456
ztrmv_("Lower", "NO TRANSPOSE", "UNIT", &i__2, &a[*k + 1 + a_dim1]
11457
, lda, &t[*nb * t_dim1 + 1], &c__1);
11458
i__2 = i__ - 1;
11459
z__1.r = -1., z__1.i = -0.;
11460
zaxpy_(&i__2, &z__1, &t[*nb * t_dim1 + 1], &c__1, &a[*k + 1 + i__
11461
* a_dim1], &c__1);
11462
11463
i__2 = *k + i__ - 1 + (i__ - 1) * a_dim1;
11464
a[i__2].r = ei.r, a[i__2].i = ei.i;
11465
}
11466
11467
/*
11468
Generate the elementary reflector H(I) to annihilate
11469
A(K+I+1:N,I)
11470
*/
11471
11472
i__2 = *n - *k - i__ + 1;
11473
/* Computing MIN */
11474
i__3 = *k + i__ + 1;
11475
zlarfg_(&i__2, &a[*k + i__ + i__ * a_dim1], &a[min(i__3,*n) + i__ *
11476
a_dim1], &c__1, &tau[i__]);
11477
i__2 = *k + i__ + i__ * a_dim1;
11478
ei.r = a[i__2].r, ei.i = a[i__2].i;
11479
i__2 = *k + i__ + i__ * a_dim1;
11480
a[i__2].r = 1., a[i__2].i = 0.;
11481
11482
/* Compute Y(K+1:N,I) */
11483
11484
i__2 = *n - *k;
11485
i__3 = *n - *k - i__ + 1;
11486
zgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b57, &a[*k + 1 + (i__ + 1) *
11487
a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b56, &y[*
11488
k + 1 + i__ * y_dim1], &c__1);
11489
i__2 = *n - *k - i__ + 1;
11490
i__3 = i__ - 1;
11491
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &a[*k + i__ +
11492
a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b56, &t[
11493
i__ * t_dim1 + 1], &c__1);
11494
i__2 = *n - *k;
11495
i__3 = i__ - 1;
11496
z__1.r = -1., z__1.i = -0.;
11497
zgemv_("NO TRANSPOSE", &i__2, &i__3, &z__1, &y[*k + 1 + y_dim1], ldy,
11498
&t[i__ * t_dim1 + 1], &c__1, &c_b57, &y[*k + 1 + i__ * y_dim1]
11499
, &c__1);
11500
i__2 = *n - *k;
11501
zscal_(&i__2, &tau[i__], &y[*k + 1 + i__ * y_dim1], &c__1);
11502
11503
/* Compute T(1:I,I) */
11504
11505
i__2 = i__ - 1;
11506
i__3 = i__;
11507
z__1.r = -tau[i__3].r, z__1.i = -tau[i__3].i;
11508
zscal_(&i__2, &z__1, &t[i__ * t_dim1 + 1], &c__1);
11509
i__2 = i__ - 1;
11510
ztrmv_("Upper", "No Transpose", "NON-UNIT", &i__2, &t[t_offset], ldt,
11511
&t[i__ * t_dim1 + 1], &c__1)
11512
;
11513
i__2 = i__ + i__ * t_dim1;
11514
i__3 = i__;
11515
t[i__2].r = tau[i__3].r, t[i__2].i = tau[i__3].i;
11516
11517
/* L10: */
11518
}
11519
i__1 = *k + *nb + *nb * a_dim1;
11520
a[i__1].r = ei.r, a[i__1].i = ei.i;
11521
11522
/* Compute Y(1:K,1:NB) */
11523
11524
zlacpy_("ALL", k, nb, &a[(a_dim1 << 1) + 1], lda, &y[y_offset], ldy);
11525
ztrmm_("RIGHT", "Lower", "NO TRANSPOSE", "UNIT", k, nb, &c_b57, &a[*k + 1
11526
+ a_dim1], lda, &y[y_offset], ldy);
11527
if (*n > *k + *nb) {
11528
i__1 = *n - *k - *nb;
11529
zgemm_("NO TRANSPOSE", "NO TRANSPOSE", k, nb, &i__1, &c_b57, &a[(*nb
11530
+ 2) * a_dim1 + 1], lda, &a[*k + 1 + *nb + a_dim1], lda, &
11531
c_b57, &y[y_offset], ldy);
11532
}
11533
ztrmm_("RIGHT", "Upper", "NO TRANSPOSE", "NON-UNIT", k, nb, &c_b57, &t[
11534
t_offset], ldt, &y[y_offset], ldy);
11535
11536
return 0;
11537
11538
/* End of ZLAHR2 */
11539
11540
} /* zlahr2_ */
11541
11542
/* Subroutine */ int zlals0_(integer *icompq, integer *nl, integer *nr,
11543
integer *sqre, integer *nrhs, doublecomplex *b, integer *ldb,
11544
doublecomplex *bx, integer *ldbx, integer *perm, integer *givptr,
11545
integer *givcol, integer *ldgcol, doublereal *givnum, integer *ldgnum,
11546
doublereal *poles, doublereal *difl, doublereal *difr, doublereal *
11547
z__, integer *k, doublereal *c__, doublereal *s, doublereal *rwork,
11548
integer *info)
11549
{
11550
/* System generated locals */
11551
integer givcol_dim1, givcol_offset, difr_dim1, difr_offset, givnum_dim1,
11552
givnum_offset, poles_dim1, poles_offset, b_dim1, b_offset,
11553
bx_dim1, bx_offset, i__1, i__2, i__3, i__4, i__5;
11554
doublereal d__1;
11555
doublecomplex z__1;
11556
11557
/* Local variables */
11558
static integer i__, j, m, n;
11559
static doublereal dj;
11560
static integer nlp1, jcol;
11561
static doublereal temp;
11562
static integer jrow;
11563
extern doublereal dnrm2_(integer *, doublereal *, integer *);
11564
static doublereal diflj, difrj, dsigj;
11565
extern /* Subroutine */ int dgemv_(char *, integer *, integer *,
11566
doublereal *, doublereal *, integer *, doublereal *, integer *,
11567
doublereal *, doublereal *, integer *), zdrot_(integer *,
11568
doublecomplex *, integer *, doublecomplex *, integer *,
11569
doublereal *, doublereal *);
11570
extern doublereal dlamc3_(doublereal *, doublereal *);
11571
extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
11572
doublecomplex *, integer *), xerbla_(char *, integer *);
11573
static doublereal dsigjp;
11574
extern /* Subroutine */ int zdscal_(integer *, doublereal *,
11575
doublecomplex *, integer *), zlascl_(char *, integer *, integer *,
11576
doublereal *, doublereal *, integer *, integer *, doublecomplex *
11577
, integer *, integer *), zlacpy_(char *, integer *,
11578
integer *, doublecomplex *, integer *, doublecomplex *, integer *);
11579
11580
11581
/*
11582
-- LAPACK routine (version 3.2) --
11583
-- LAPACK is a software package provided by Univ. of Tennessee, --
11584
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
11585
November 2006
11586
11587
11588
Purpose
11589
=======
11590
11591
ZLALS0 applies back the multiplying factors of either the left or the
11592
right singular vector matrix of a diagonal matrix appended by a row
11593
to the right hand side matrix B in solving the least squares problem
11594
using the divide-and-conquer SVD approach.
11595
11596
For the left singular vector matrix, three types of orthogonal
11597
matrices are involved:
11598
11599
(1L) Givens rotations: the number of such rotations is GIVPTR; the
11600
pairs of columns/rows they were applied to are stored in GIVCOL;
11601
and the C- and S-values of these rotations are stored in GIVNUM.
11602
11603
(2L) Permutation. The (NL+1)-st row of B is to be moved to the first
11604
row, and for J=2:N, PERM(J)-th row of B is to be moved to the
11605
J-th row.
11606
11607
(3L) The left singular vector matrix of the remaining matrix.
11608
11609
For the right singular vector matrix, four types of orthogonal
11610
matrices are involved:
11611
11612
(1R) The right singular vector matrix of the remaining matrix.
11613
11614
(2R) If SQRE = 1, one extra Givens rotation to generate the right
11615
null space.
11616
11617
(3R) The inverse transformation of (2L).
11618
11619
(4R) The inverse transformation of (1L).
11620
11621
Arguments
11622
=========
11623
11624
ICOMPQ (input) INTEGER
11625
Specifies whether singular vectors are to be computed in
11626
factored form:
11627
= 0: Left singular vector matrix.
11628
= 1: Right singular vector matrix.
11629
11630
NL (input) INTEGER
11631
The row dimension of the upper block. NL >= 1.
11632
11633
NR (input) INTEGER
11634
The row dimension of the lower block. NR >= 1.
11635
11636
SQRE (input) INTEGER
11637
= 0: the lower block is an NR-by-NR square matrix.
11638
= 1: the lower block is an NR-by-(NR+1) rectangular matrix.
11639
11640
The bidiagonal matrix has row dimension N = NL + NR + 1,
11641
and column dimension M = N + SQRE.
11642
11643
NRHS (input) INTEGER
11644
The number of columns of B and BX. NRHS must be at least 1.
11645
11646
B (input/output) COMPLEX*16 array, dimension ( LDB, NRHS )
11647
On input, B contains the right hand sides of the least
11648
squares problem in rows 1 through M. On output, B contains
11649
the solution X in rows 1 through N.
11650
11651
LDB (input) INTEGER
11652
The leading dimension of B. LDB must be at least
11653
max(1,MAX( M, N ) ).
11654
11655
BX (workspace) COMPLEX*16 array, dimension ( LDBX, NRHS )
11656
11657
LDBX (input) INTEGER
11658
The leading dimension of BX.
11659
11660
PERM (input) INTEGER array, dimension ( N )
11661
The permutations (from deflation and sorting) applied
11662
to the two blocks.
11663
11664
GIVPTR (input) INTEGER
11665
The number of Givens rotations which took place in this
11666
subproblem.
11667
11668
GIVCOL (input) INTEGER array, dimension ( LDGCOL, 2 )
11669
Each pair of numbers indicates a pair of rows/columns
11670
involved in a Givens rotation.
11671
11672
LDGCOL (input) INTEGER
11673
The leading dimension of GIVCOL, must be at least N.
11674
11675
GIVNUM (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
11676
Each number indicates the C or S value used in the
11677
corresponding Givens rotation.
11678
11679
LDGNUM (input) INTEGER
11680
The leading dimension of arrays DIFR, POLES and
11681
GIVNUM, must be at least K.
11682
11683
POLES (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
11684
On entry, POLES(1:K, 1) contains the new singular
11685
values obtained from solving the secular equation, and
11686
POLES(1:K, 2) is an array containing the poles in the secular
11687
equation.
11688
11689
DIFL (input) DOUBLE PRECISION array, dimension ( K ).
11690
On entry, DIFL(I) is the distance between I-th updated
11691
(undeflated) singular value and the I-th (undeflated) old
11692
singular value.
11693
11694
DIFR (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ).
11695
On entry, DIFR(I, 1) contains the distances between I-th
11696
updated (undeflated) singular value and the I+1-th
11697
(undeflated) old singular value. And DIFR(I, 2) is the
11698
normalizing factor for the I-th right singular vector.
11699
11700
Z (input) DOUBLE PRECISION array, dimension ( K )
11701
Contain the components of the deflation-adjusted updating row
11702
vector.
11703
11704
K (input) INTEGER
11705
Contains the dimension of the non-deflated matrix,
11706
This is the order of the related secular equation. 1 <= K <=N.
11707
11708
C (input) DOUBLE PRECISION
11709
C contains garbage if SQRE =0 and the C-value of a Givens
11710
rotation related to the right null space if SQRE = 1.
11711
11712
S (input) DOUBLE PRECISION
11713
S contains garbage if SQRE =0 and the S-value of a Givens
11714
rotation related to the right null space if SQRE = 1.
11715
11716
RWORK (workspace) DOUBLE PRECISION array, dimension
11717
( K*(1+NRHS) + 2*NRHS )
11718
11719
INFO (output) INTEGER
11720
= 0: successful exit.
11721
< 0: if INFO = -i, the i-th argument had an illegal value.
11722
11723
Further Details
11724
===============
11725
11726
Based on contributions by
11727
Ming Gu and Ren-Cang Li, Computer Science Division, University of
11728
California at Berkeley, USA
11729
Osni Marques, LBNL/NERSC, USA
11730
11731
=====================================================================
11732
11733
11734
Test the input parameters.
11735
*/
11736
11737
/* Parameter adjustments */
11738
b_dim1 = *ldb;
11739
b_offset = 1 + b_dim1;
11740
b -= b_offset;
11741
bx_dim1 = *ldbx;
11742
bx_offset = 1 + bx_dim1;
11743
bx -= bx_offset;
11744
--perm;
11745
givcol_dim1 = *ldgcol;
11746
givcol_offset = 1 + givcol_dim1;
11747
givcol -= givcol_offset;
11748
difr_dim1 = *ldgnum;
11749
difr_offset = 1 + difr_dim1;
11750
difr -= difr_offset;
11751
poles_dim1 = *ldgnum;
11752
poles_offset = 1 + poles_dim1;
11753
poles -= poles_offset;
11754
givnum_dim1 = *ldgnum;
11755
givnum_offset = 1 + givnum_dim1;
11756
givnum -= givnum_offset;
11757
--difl;
11758
--z__;
11759
--rwork;
11760
11761
/* Function Body */
11762
*info = 0;
11763
11764
if (*icompq < 0 || *icompq > 1) {
11765
*info = -1;
11766
} else if (*nl < 1) {
11767
*info = -2;
11768
} else if (*nr < 1) {
11769
*info = -3;
11770
} else if (*sqre < 0 || *sqre > 1) {
11771
*info = -4;
11772
}
11773
11774
n = *nl + *nr + 1;
11775
11776
if (*nrhs < 1) {
11777
*info = -5;
11778
} else if (*ldb < n) {
11779
*info = -7;
11780
} else if (*ldbx < n) {
11781
*info = -9;
11782
} else if (*givptr < 0) {
11783
*info = -11;
11784
} else if (*ldgcol < n) {
11785
*info = -13;
11786
} else if (*ldgnum < n) {
11787
*info = -15;
11788
} else if (*k < 1) {
11789
*info = -20;
11790
}
11791
if (*info != 0) {
11792
i__1 = -(*info);
11793
xerbla_("ZLALS0", &i__1);
11794
return 0;
11795
}
11796
11797
m = n + *sqre;
11798
nlp1 = *nl + 1;
11799
11800
if (*icompq == 0) {
11801
11802
/*
11803
Apply back orthogonal transformations from the left.
11804
11805
Step (1L): apply back the Givens rotations performed.
11806
*/
11807
11808
i__1 = *givptr;
11809
for (i__ = 1; i__ <= i__1; ++i__) {
11810
zdrot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
11811
b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
11812
(givnum_dim1 << 1)], &givnum[i__ + givnum_dim1]);
11813
/* L10: */
11814
}
11815
11816
/* Step (2L): permute rows of B. */
11817
11818
zcopy_(nrhs, &b[nlp1 + b_dim1], ldb, &bx[bx_dim1 + 1], ldbx);
11819
i__1 = n;
11820
for (i__ = 2; i__ <= i__1; ++i__) {
11821
zcopy_(nrhs, &b[perm[i__] + b_dim1], ldb, &bx[i__ + bx_dim1],
11822
ldbx);
11823
/* L20: */
11824
}
11825
11826
/*
11827
Step (3L): apply the inverse of the left singular vector
11828
matrix to BX.
11829
*/
11830
11831
if (*k == 1) {
11832
zcopy_(nrhs, &bx[bx_offset], ldbx, &b[b_offset], ldb);
11833
if (z__[1] < 0.) {
11834
zdscal_(nrhs, &c_b1276, &b[b_offset], ldb);
11835
}
11836
} else {
11837
i__1 = *k;
11838
for (j = 1; j <= i__1; ++j) {
11839
diflj = difl[j];
11840
dj = poles[j + poles_dim1];
11841
dsigj = -poles[j + (poles_dim1 << 1)];
11842
if (j < *k) {
11843
difrj = -difr[j + difr_dim1];
11844
dsigjp = -poles[j + 1 + (poles_dim1 << 1)];
11845
}
11846
if (z__[j] == 0. || poles[j + (poles_dim1 << 1)] == 0.) {
11847
rwork[j] = 0.;
11848
} else {
11849
rwork[j] = -poles[j + (poles_dim1 << 1)] * z__[j] / diflj
11850
/ (poles[j + (poles_dim1 << 1)] + dj);
11851
}
11852
i__2 = j - 1;
11853
for (i__ = 1; i__ <= i__2; ++i__) {
11854
if (z__[i__] == 0. || poles[i__ + (poles_dim1 << 1)] ==
11855
0.) {
11856
rwork[i__] = 0.;
11857
} else {
11858
rwork[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
11859
/ (dlamc3_(&poles[i__ + (poles_dim1 << 1)], &
11860
dsigj) - diflj) / (poles[i__ + (poles_dim1 <<
11861
1)] + dj);
11862
}
11863
/* L30: */
11864
}
11865
i__2 = *k;
11866
for (i__ = j + 1; i__ <= i__2; ++i__) {
11867
if (z__[i__] == 0. || poles[i__ + (poles_dim1 << 1)] ==
11868
0.) {
11869
rwork[i__] = 0.;
11870
} else {
11871
rwork[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
11872
/ (dlamc3_(&poles[i__ + (poles_dim1 << 1)], &
11873
dsigjp) + difrj) / (poles[i__ + (poles_dim1 <<
11874
1)] + dj);
11875
}
11876
/* L40: */
11877
}
11878
rwork[1] = -1.;
11879
temp = dnrm2_(k, &rwork[1], &c__1);
11880
11881
/*
11882
Since B and BX are complex, the following call to DGEMV
11883
is performed in two steps (real and imaginary parts).
11884
11885
CALL DGEMV( 'T', K, NRHS, ONE, BX, LDBX, WORK, 1, ZERO,
11886
$ B( J, 1 ), LDB )
11887
*/
11888
11889
i__ = *k + (*nrhs << 1);
11890
i__2 = *nrhs;
11891
for (jcol = 1; jcol <= i__2; ++jcol) {
11892
i__3 = *k;
11893
for (jrow = 1; jrow <= i__3; ++jrow) {
11894
++i__;
11895
i__4 = jrow + jcol * bx_dim1;
11896
rwork[i__] = bx[i__4].r;
11897
/* L50: */
11898
}
11899
/* L60: */
11900
}
11901
dgemv_("T", k, nrhs, &c_b1034, &rwork[*k + 1 + (*nrhs << 1)],
11902
k, &rwork[1], &c__1, &c_b328, &rwork[*k + 1], &c__1);
11903
i__ = *k + (*nrhs << 1);
11904
i__2 = *nrhs;
11905
for (jcol = 1; jcol <= i__2; ++jcol) {
11906
i__3 = *k;
11907
for (jrow = 1; jrow <= i__3; ++jrow) {
11908
++i__;
11909
rwork[i__] = d_imag(&bx[jrow + jcol * bx_dim1]);
11910
/* L70: */
11911
}
11912
/* L80: */
11913
}
11914
dgemv_("T", k, nrhs, &c_b1034, &rwork[*k + 1 + (*nrhs << 1)],
11915
k, &rwork[1], &c__1, &c_b328, &rwork[*k + 1 + *nrhs],
11916
&c__1);
11917
i__2 = *nrhs;
11918
for (jcol = 1; jcol <= i__2; ++jcol) {
11919
i__3 = j + jcol * b_dim1;
11920
i__4 = jcol + *k;
11921
i__5 = jcol + *k + *nrhs;
11922
z__1.r = rwork[i__4], z__1.i = rwork[i__5];
11923
b[i__3].r = z__1.r, b[i__3].i = z__1.i;
11924
/* L90: */
11925
}
11926
zlascl_("G", &c__0, &c__0, &temp, &c_b1034, &c__1, nrhs, &b[j
11927
+ b_dim1], ldb, info);
11928
/* L100: */
11929
}
11930
}
11931
11932
/* Move the deflated rows of BX to B also. */
11933
11934
if (*k < max(m,n)) {
11935
i__1 = n - *k;
11936
zlacpy_("A", &i__1, nrhs, &bx[*k + 1 + bx_dim1], ldbx, &b[*k + 1
11937
+ b_dim1], ldb);
11938
}
11939
} else {
11940
11941
/*
11942
Apply back the right orthogonal transformations.
11943
11944
Step (1R): apply back the new right singular vector matrix
11945
to B.
11946
*/
11947
11948
if (*k == 1) {
11949
zcopy_(nrhs, &b[b_offset], ldb, &bx[bx_offset], ldbx);
11950
} else {
11951
i__1 = *k;
11952
for (j = 1; j <= i__1; ++j) {
11953
dsigj = poles[j + (poles_dim1 << 1)];
11954
if (z__[j] == 0.) {
11955
rwork[j] = 0.;
11956
} else {
11957
rwork[j] = -z__[j] / difl[j] / (dsigj + poles[j +
11958
poles_dim1]) / difr[j + (difr_dim1 << 1)];
11959
}
11960
i__2 = j - 1;
11961
for (i__ = 1; i__ <= i__2; ++i__) {
11962
if (z__[j] == 0.) {
11963
rwork[i__] = 0.;
11964
} else {
11965
d__1 = -poles[i__ + 1 + (poles_dim1 << 1)];
11966
rwork[i__] = z__[j] / (dlamc3_(&dsigj, &d__1) - difr[
11967
i__ + difr_dim1]) / (dsigj + poles[i__ +
11968
poles_dim1]) / difr[i__ + (difr_dim1 << 1)];
11969
}
11970
/* L110: */
11971
}
11972
i__2 = *k;
11973
for (i__ = j + 1; i__ <= i__2; ++i__) {
11974
if (z__[j] == 0.) {
11975
rwork[i__] = 0.;
11976
} else {
11977
d__1 = -poles[i__ + (poles_dim1 << 1)];
11978
rwork[i__] = z__[j] / (dlamc3_(&dsigj, &d__1) - difl[
11979
i__]) / (dsigj + poles[i__ + poles_dim1]) /
11980
difr[i__ + (difr_dim1 << 1)];
11981
}
11982
/* L120: */
11983
}
11984
11985
/*
11986
Since B and BX are complex, the following call to DGEMV
11987
is performed in two steps (real and imaginary parts).
11988
11989
CALL DGEMV( 'T', K, NRHS, ONE, B, LDB, WORK, 1, ZERO,
11990
$ BX( J, 1 ), LDBX )
11991
*/
11992
11993
i__ = *k + (*nrhs << 1);
11994
i__2 = *nrhs;
11995
for (jcol = 1; jcol <= i__2; ++jcol) {
11996
i__3 = *k;
11997
for (jrow = 1; jrow <= i__3; ++jrow) {
11998
++i__;
11999
i__4 = jrow + jcol * b_dim1;
12000
rwork[i__] = b[i__4].r;
12001
/* L130: */
12002
}
12003
/* L140: */
12004
}
12005
dgemv_("T", k, nrhs, &c_b1034, &rwork[*k + 1 + (*nrhs << 1)],
12006
k, &rwork[1], &c__1, &c_b328, &rwork[*k + 1], &c__1);
12007
i__ = *k + (*nrhs << 1);
12008
i__2 = *nrhs;
12009
for (jcol = 1; jcol <= i__2; ++jcol) {
12010
i__3 = *k;
12011
for (jrow = 1; jrow <= i__3; ++jrow) {
12012
++i__;
12013
rwork[i__] = d_imag(&b[jrow + jcol * b_dim1]);
12014
/* L150: */
12015
}
12016
/* L160: */
12017
}
12018
dgemv_("T", k, nrhs, &c_b1034, &rwork[*k + 1 + (*nrhs << 1)],
12019
k, &rwork[1], &c__1, &c_b328, &rwork[*k + 1 + *nrhs],
12020
&c__1);
12021
i__2 = *nrhs;
12022
for (jcol = 1; jcol <= i__2; ++jcol) {
12023
i__3 = j + jcol * bx_dim1;
12024
i__4 = jcol + *k;
12025
i__5 = jcol + *k + *nrhs;
12026
z__1.r = rwork[i__4], z__1.i = rwork[i__5];
12027
bx[i__3].r = z__1.r, bx[i__3].i = z__1.i;
12028
/* L170: */
12029
}
12030
/* L180: */
12031
}
12032
}
12033
12034
/*
12035
Step (2R): if SQRE = 1, apply back the rotation that is
12036
related to the right null space of the subproblem.
12037
*/
12038
12039
if (*sqre == 1) {
12040
zcopy_(nrhs, &b[m + b_dim1], ldb, &bx[m + bx_dim1], ldbx);
12041
zdrot_(nrhs, &bx[bx_dim1 + 1], ldbx, &bx[m + bx_dim1], ldbx, c__,
12042
s);
12043
}
12044
if (*k < max(m,n)) {
12045
i__1 = n - *k;
12046
zlacpy_("A", &i__1, nrhs, &b[*k + 1 + b_dim1], ldb, &bx[*k + 1 +
12047
bx_dim1], ldbx);
12048
}
12049
12050
/* Step (3R): permute rows of B. */
12051
12052
zcopy_(nrhs, &bx[bx_dim1 + 1], ldbx, &b[nlp1 + b_dim1], ldb);
12053
if (*sqre == 1) {
12054
zcopy_(nrhs, &bx[m + bx_dim1], ldbx, &b[m + b_dim1], ldb);
12055
}
12056
i__1 = n;
12057
for (i__ = 2; i__ <= i__1; ++i__) {
12058
zcopy_(nrhs, &bx[i__ + bx_dim1], ldbx, &b[perm[i__] + b_dim1],
12059
ldb);
12060
/* L190: */
12061
}
12062
12063
/* Step (4R): apply back the Givens rotations performed. */
12064
12065
for (i__ = *givptr; i__ >= 1; --i__) {
12066
d__1 = -givnum[i__ + givnum_dim1];
12067
zdrot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
12068
b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
12069
(givnum_dim1 << 1)], &d__1);
12070
/* L200: */
12071
}
12072
}
12073
12074
return 0;
12075
12076
/* End of ZLALS0 */
12077
12078
} /* zlals0_ */
12079
12080
/* Subroutine */ int zlalsa_(integer *icompq, integer *smlsiz, integer *n,
12081
integer *nrhs, doublecomplex *b, integer *ldb, doublecomplex *bx,
12082
integer *ldbx, doublereal *u, integer *ldu, doublereal *vt, integer *
12083
k, doublereal *difl, doublereal *difr, doublereal *z__, doublereal *
12084
poles, integer *givptr, integer *givcol, integer *ldgcol, integer *
12085
perm, doublereal *givnum, doublereal *c__, doublereal *s, doublereal *
12086
rwork, integer *iwork, integer *info)
12087
{
12088
/* System generated locals */
12089
integer givcol_dim1, givcol_offset, perm_dim1, perm_offset, difl_dim1,
12090
difl_offset, difr_dim1, difr_offset, givnum_dim1, givnum_offset,
12091
poles_dim1, poles_offset, u_dim1, u_offset, vt_dim1, vt_offset,
12092
z_dim1, z_offset, b_dim1, b_offset, bx_dim1, bx_offset, i__1,
12093
i__2, i__3, i__4, i__5, i__6;
12094
doublecomplex z__1;
12095
12096
/* Local variables */
12097
static integer i__, j, i1, ic, lf, nd, ll, nl, nr, im1, nlf, nrf, lvl,
12098
ndb1, nlp1, lvl2, nrp1, jcol, nlvl, sqre, jrow, jimag;
12099
extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
12100
integer *, doublereal *, doublereal *, integer *, doublereal *,
12101
integer *, doublereal *, doublereal *, integer *);
12102
static integer jreal, inode, ndiml, ndimr;
12103
extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
12104
doublecomplex *, integer *), zlals0_(integer *, integer *,
12105
integer *, integer *, integer *, doublecomplex *, integer *,
12106
doublecomplex *, integer *, integer *, integer *, integer *,
12107
integer *, doublereal *, integer *, doublereal *, doublereal *,
12108
doublereal *, doublereal *, integer *, doublereal *, doublereal *,
12109
doublereal *, integer *), dlasdt_(integer *, integer *, integer *
12110
, integer *, integer *, integer *, integer *), xerbla_(char *,
12111
integer *);
12112
12113
12114
/*
12115
-- LAPACK routine (version 3.2) --
12116
-- LAPACK is a software package provided by Univ. of Tennessee, --
12117
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
12118
November 2006
12119
12120
12121
Purpose
12122
=======
12123
12124
ZLALSA is an itermediate step in solving the least squares problem
12125
by computing the SVD of the coefficient matrix in compact form (The
12126
singular vectors are computed as products of simple orthorgonal
12127
matrices.).
12128
12129
If ICOMPQ = 0, ZLALSA applies the inverse of the left singular vector
12130
matrix of an upper bidiagonal matrix to the right hand side; and if
12131
ICOMPQ = 1, ZLALSA applies the right singular vector matrix to the
12132
right hand side. The singular vector matrices were generated in
12133
compact form by ZLALSA.
12134
12135
Arguments
12136
=========
12137
12138
ICOMPQ (input) INTEGER
12139
Specifies whether the left or the right singular vector
12140
matrix is involved.
12141
= 0: Left singular vector matrix
12142
= 1: Right singular vector matrix
12143
12144
SMLSIZ (input) INTEGER
12145
The maximum size of the subproblems at the bottom of the
12146
computation tree.
12147
12148
N (input) INTEGER
12149
The row and column dimensions of the upper bidiagonal matrix.
12150
12151
NRHS (input) INTEGER
12152
The number of columns of B and BX. NRHS must be at least 1.
12153
12154
B (input/output) COMPLEX*16 array, dimension ( LDB, NRHS )
12155
On input, B contains the right hand sides of the least
12156
squares problem in rows 1 through M.
12157
On output, B contains the solution X in rows 1 through N.
12158
12159
LDB (input) INTEGER
12160
The leading dimension of B in the calling subprogram.
12161
LDB must be at least max(1,MAX( M, N ) ).
12162
12163
BX (output) COMPLEX*16 array, dimension ( LDBX, NRHS )
12164
On exit, the result of applying the left or right singular
12165
vector matrix to B.
12166
12167
LDBX (input) INTEGER
12168
The leading dimension of BX.
12169
12170
U (input) DOUBLE PRECISION array, dimension ( LDU, SMLSIZ ).
12171
On entry, U contains the left singular vector matrices of all
12172
subproblems at the bottom level.
12173
12174
LDU (input) INTEGER, LDU = > N.
12175
The leading dimension of arrays U, VT, DIFL, DIFR,
12176
POLES, GIVNUM, and Z.
12177
12178
VT (input) DOUBLE PRECISION array, dimension ( LDU, SMLSIZ+1 ).
12179
On entry, VT' contains the right singular vector matrices of
12180
all subproblems at the bottom level.
12181
12182
K (input) INTEGER array, dimension ( N ).
12183
12184
DIFL (input) DOUBLE PRECISION array, dimension ( LDU, NLVL ).
12185
where NLVL = INT(log_2 (N/(SMLSIZ+1))) + 1.
12186
12187
DIFR (input) DOUBLE PRECISION array, dimension ( LDU, 2 * NLVL ).
12188
On entry, DIFL(*, I) and DIFR(*, 2 * I -1) record
12189
distances between singular values on the I-th level and
12190
singular values on the (I -1)-th level, and DIFR(*, 2 * I)
12191
record the normalizing factors of the right singular vectors
12192
matrices of subproblems on I-th level.
12193
12194
Z (input) DOUBLE PRECISION array, dimension ( LDU, NLVL ).
12195
On entry, Z(1, I) contains the components of the deflation-
12196
adjusted updating row vector for subproblems on the I-th
12197
level.
12198
12199
POLES (input) DOUBLE PRECISION array, dimension ( LDU, 2 * NLVL ).
12200
On entry, POLES(*, 2 * I -1: 2 * I) contains the new and old
12201
singular values involved in the secular equations on the I-th
12202
level.
12203
12204
GIVPTR (input) INTEGER array, dimension ( N ).
12205
On entry, GIVPTR( I ) records the number of Givens
12206
rotations performed on the I-th problem on the computation
12207
tree.
12208
12209
GIVCOL (input) INTEGER array, dimension ( LDGCOL, 2 * NLVL ).
12210
On entry, for each I, GIVCOL(*, 2 * I - 1: 2 * I) records the
12211
locations of Givens rotations performed on the I-th level on
12212
the computation tree.
12213
12214
LDGCOL (input) INTEGER, LDGCOL = > N.
12215
The leading dimension of arrays GIVCOL and PERM.
12216
12217
PERM (input) INTEGER array, dimension ( LDGCOL, NLVL ).
12218
On entry, PERM(*, I) records permutations done on the I-th
12219
level of the computation tree.
12220
12221
GIVNUM (input) DOUBLE PRECISION array, dimension ( LDU, 2 * NLVL ).
12222
On entry, GIVNUM(*, 2 *I -1 : 2 * I) records the C- and S-
12223
values of Givens rotations performed on the I-th level on the
12224
computation tree.
12225
12226
C (input) DOUBLE PRECISION array, dimension ( N ).
12227
On entry, if the I-th subproblem is not square,
12228
C( I ) contains the C-value of a Givens rotation related to
12229
the right null space of the I-th subproblem.
12230
12231
S (input) DOUBLE PRECISION array, dimension ( N ).
12232
On entry, if the I-th subproblem is not square,
12233
S( I ) contains the S-value of a Givens rotation related to
12234
the right null space of the I-th subproblem.
12235
12236
RWORK (workspace) DOUBLE PRECISION array, dimension at least
12237
MAX( (SMLSZ+1)*NRHS*3, N*(1+NRHS) + 2*NRHS ).
12238
12239
IWORK (workspace) INTEGER array.
12240
The dimension must be at least 3 * N
12241
12242
INFO (output) INTEGER
12243
= 0: successful exit.
12244
< 0: if INFO = -i, the i-th argument had an illegal value.
12245
12246
Further Details
12247
===============
12248
12249
Based on contributions by
12250
Ming Gu and Ren-Cang Li, Computer Science Division, University of
12251
California at Berkeley, USA
12252
Osni Marques, LBNL/NERSC, USA
12253
12254
=====================================================================
12255
12256
12257
Test the input parameters.
12258
*/
12259
12260
/* Parameter adjustments */
12261
b_dim1 = *ldb;
12262
b_offset = 1 + b_dim1;
12263
b -= b_offset;
12264
bx_dim1 = *ldbx;
12265
bx_offset = 1 + bx_dim1;
12266
bx -= bx_offset;
12267
givnum_dim1 = *ldu;
12268
givnum_offset = 1 + givnum_dim1;
12269
givnum -= givnum_offset;
12270
poles_dim1 = *ldu;
12271
poles_offset = 1 + poles_dim1;
12272
poles -= poles_offset;
12273
z_dim1 = *ldu;
12274
z_offset = 1 + z_dim1;
12275
z__ -= z_offset;
12276
difr_dim1 = *ldu;
12277
difr_offset = 1 + difr_dim1;
12278
difr -= difr_offset;
12279
difl_dim1 = *ldu;
12280
difl_offset = 1 + difl_dim1;
12281
difl -= difl_offset;
12282
vt_dim1 = *ldu;
12283
vt_offset = 1 + vt_dim1;
12284
vt -= vt_offset;
12285
u_dim1 = *ldu;
12286
u_offset = 1 + u_dim1;
12287
u -= u_offset;
12288
--k;
12289
--givptr;
12290
perm_dim1 = *ldgcol;
12291
perm_offset = 1 + perm_dim1;
12292
perm -= perm_offset;
12293
givcol_dim1 = *ldgcol;
12294
givcol_offset = 1 + givcol_dim1;
12295
givcol -= givcol_offset;
12296
--c__;
12297
--s;
12298
--rwork;
12299
--iwork;
12300
12301
/* Function Body */
12302
*info = 0;
12303
12304
if (*icompq < 0 || *icompq > 1) {
12305
*info = -1;
12306
} else if (*smlsiz < 3) {
12307
*info = -2;
12308
} else if (*n < *smlsiz) {
12309
*info = -3;
12310
} else if (*nrhs < 1) {
12311
*info = -4;
12312
} else if (*ldb < *n) {
12313
*info = -6;
12314
} else if (*ldbx < *n) {
12315
*info = -8;
12316
} else if (*ldu < *n) {
12317
*info = -10;
12318
} else if (*ldgcol < *n) {
12319
*info = -19;
12320
}
12321
if (*info != 0) {
12322
i__1 = -(*info);
12323
xerbla_("ZLALSA", &i__1);
12324
return 0;
12325
}
12326
12327
/* Book-keeping and setting up the computation tree. */
12328
12329
inode = 1;
12330
ndiml = inode + *n;
12331
ndimr = ndiml + *n;
12332
12333
dlasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr],
12334
smlsiz);
12335
12336
/*
12337
The following code applies back the left singular vector factors.
12338
For applying back the right singular vector factors, go to 170.
12339
*/
12340
12341
if (*icompq == 1) {
12342
goto L170;
12343
}
12344
12345
/*
12346
The nodes on the bottom level of the tree were solved
12347
by DLASDQ. The corresponding left and right singular vector
12348
matrices are in explicit form. First apply back the left
12349
singular vector matrices.
12350
*/
12351
12352
ndb1 = (nd + 1) / 2;
12353
i__1 = nd;
12354
for (i__ = ndb1; i__ <= i__1; ++i__) {
12355
12356
/*
12357
IC : center row of each node
12358
NL : number of rows of left subproblem
12359
NR : number of rows of right subproblem
12360
NLF: starting row of the left subproblem
12361
NRF: starting row of the right subproblem
12362
*/
12363
12364
i1 = i__ - 1;
12365
ic = iwork[inode + i1];
12366
nl = iwork[ndiml + i1];
12367
nr = iwork[ndimr + i1];
12368
nlf = ic - nl;
12369
nrf = ic + 1;
12370
12371
/*
12372
Since B and BX are complex, the following call to DGEMM
12373
is performed in two steps (real and imaginary parts).
12374
12375
CALL DGEMM( 'T', 'N', NL, NRHS, NL, ONE, U( NLF, 1 ), LDU,
12376
$ B( NLF, 1 ), LDB, ZERO, BX( NLF, 1 ), LDBX )
12377
*/
12378
12379
j = nl * *nrhs << 1;
12380
i__2 = *nrhs;
12381
for (jcol = 1; jcol <= i__2; ++jcol) {
12382
i__3 = nlf + nl - 1;
12383
for (jrow = nlf; jrow <= i__3; ++jrow) {
12384
++j;
12385
i__4 = jrow + jcol * b_dim1;
12386
rwork[j] = b[i__4].r;
12387
/* L10: */
12388
}
12389
/* L20: */
12390
}
12391
dgemm_("T", "N", &nl, nrhs, &nl, &c_b1034, &u[nlf + u_dim1], ldu, &
12392
rwork[(nl * *nrhs << 1) + 1], &nl, &c_b328, &rwork[1], &nl);
12393
j = nl * *nrhs << 1;
12394
i__2 = *nrhs;
12395
for (jcol = 1; jcol <= i__2; ++jcol) {
12396
i__3 = nlf + nl - 1;
12397
for (jrow = nlf; jrow <= i__3; ++jrow) {
12398
++j;
12399
rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
12400
/* L30: */
12401
}
12402
/* L40: */
12403
}
12404
dgemm_("T", "N", &nl, nrhs, &nl, &c_b1034, &u[nlf + u_dim1], ldu, &
12405
rwork[(nl * *nrhs << 1) + 1], &nl, &c_b328, &rwork[nl * *nrhs
12406
+ 1], &nl);
12407
jreal = 0;
12408
jimag = nl * *nrhs;
12409
i__2 = *nrhs;
12410
for (jcol = 1; jcol <= i__2; ++jcol) {
12411
i__3 = nlf + nl - 1;
12412
for (jrow = nlf; jrow <= i__3; ++jrow) {
12413
++jreal;
12414
++jimag;
12415
i__4 = jrow + jcol * bx_dim1;
12416
i__5 = jreal;
12417
i__6 = jimag;
12418
z__1.r = rwork[i__5], z__1.i = rwork[i__6];
12419
bx[i__4].r = z__1.r, bx[i__4].i = z__1.i;
12420
/* L50: */
12421
}
12422
/* L60: */
12423
}
12424
12425
/*
12426
Since B and BX are complex, the following call to DGEMM
12427
is performed in two steps (real and imaginary parts).
12428
12429
CALL DGEMM( 'T', 'N', NR, NRHS, NR, ONE, U( NRF, 1 ), LDU,
12430
$ B( NRF, 1 ), LDB, ZERO, BX( NRF, 1 ), LDBX )
12431
*/
12432
12433
j = nr * *nrhs << 1;
12434
i__2 = *nrhs;
12435
for (jcol = 1; jcol <= i__2; ++jcol) {
12436
i__3 = nrf + nr - 1;
12437
for (jrow = nrf; jrow <= i__3; ++jrow) {
12438
++j;
12439
i__4 = jrow + jcol * b_dim1;
12440
rwork[j] = b[i__4].r;
12441
/* L70: */
12442
}
12443
/* L80: */
12444
}
12445
dgemm_("T", "N", &nr, nrhs, &nr, &c_b1034, &u[nrf + u_dim1], ldu, &
12446
rwork[(nr * *nrhs << 1) + 1], &nr, &c_b328, &rwork[1], &nr);
12447
j = nr * *nrhs << 1;
12448
i__2 = *nrhs;
12449
for (jcol = 1; jcol <= i__2; ++jcol) {
12450
i__3 = nrf + nr - 1;
12451
for (jrow = nrf; jrow <= i__3; ++jrow) {
12452
++j;
12453
rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
12454
/* L90: */
12455
}
12456
/* L100: */
12457
}
12458
dgemm_("T", "N", &nr, nrhs, &nr, &c_b1034, &u[nrf + u_dim1], ldu, &
12459
rwork[(nr * *nrhs << 1) + 1], &nr, &c_b328, &rwork[nr * *nrhs
12460
+ 1], &nr);
12461
jreal = 0;
12462
jimag = nr * *nrhs;
12463
i__2 = *nrhs;
12464
for (jcol = 1; jcol <= i__2; ++jcol) {
12465
i__3 = nrf + nr - 1;
12466
for (jrow = nrf; jrow <= i__3; ++jrow) {
12467
++jreal;
12468
++jimag;
12469
i__4 = jrow + jcol * bx_dim1;
12470
i__5 = jreal;
12471
i__6 = jimag;
12472
z__1.r = rwork[i__5], z__1.i = rwork[i__6];
12473
bx[i__4].r = z__1.r, bx[i__4].i = z__1.i;
12474
/* L110: */
12475
}
12476
/* L120: */
12477
}
12478
12479
/* L130: */
12480
}
12481
12482
/*
12483
Next copy the rows of B that correspond to unchanged rows
12484
in the bidiagonal matrix to BX.
12485
*/
12486
12487
i__1 = nd;
12488
for (i__ = 1; i__ <= i__1; ++i__) {
12489
ic = iwork[inode + i__ - 1];
12490
zcopy_(nrhs, &b[ic + b_dim1], ldb, &bx[ic + bx_dim1], ldbx);
12491
/* L140: */
12492
}
12493
12494
/*
12495
Finally go through the left singular vector matrices of all
12496
the other subproblems bottom-up on the tree.
12497
*/
12498
12499
j = pow_ii(&c__2, &nlvl);
12500
sqre = 0;
12501
12502
for (lvl = nlvl; lvl >= 1; --lvl) {
12503
lvl2 = (lvl << 1) - 1;
12504
12505
/*
12506
find the first node LF and last node LL on
12507
the current level LVL
12508
*/
12509
12510
if (lvl == 1) {
12511
lf = 1;
12512
ll = 1;
12513
} else {
12514
i__1 = lvl - 1;
12515
lf = pow_ii(&c__2, &i__1);
12516
ll = (lf << 1) - 1;
12517
}
12518
i__1 = ll;
12519
for (i__ = lf; i__ <= i__1; ++i__) {
12520
im1 = i__ - 1;
12521
ic = iwork[inode + im1];
12522
nl = iwork[ndiml + im1];
12523
nr = iwork[ndimr + im1];
12524
nlf = ic - nl;
12525
nrf = ic + 1;
12526
--j;
12527
zlals0_(icompq, &nl, &nr, &sqre, nrhs, &bx[nlf + bx_dim1], ldbx, &
12528
b[nlf + b_dim1], ldb, &perm[nlf + lvl * perm_dim1], &
12529
givptr[j], &givcol[nlf + lvl2 * givcol_dim1], ldgcol, &
12530
givnum[nlf + lvl2 * givnum_dim1], ldu, &poles[nlf + lvl2 *
12531
poles_dim1], &difl[nlf + lvl * difl_dim1], &difr[nlf +
12532
lvl2 * difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[
12533
j], &s[j], &rwork[1], info);
12534
/* L150: */
12535
}
12536
/* L160: */
12537
}
12538
goto L330;
12539
12540
/* ICOMPQ = 1: applying back the right singular vector factors. */
12541
12542
L170:
12543
12544
/*
12545
First now go through the right singular vector matrices of all
12546
the tree nodes top-down.
12547
*/
12548
12549
j = 0;
12550
i__1 = nlvl;
12551
for (lvl = 1; lvl <= i__1; ++lvl) {
12552
lvl2 = (lvl << 1) - 1;
12553
12554
/*
12555
Find the first node LF and last node LL on
12556
the current level LVL.
12557
*/
12558
12559
if (lvl == 1) {
12560
lf = 1;
12561
ll = 1;
12562
} else {
12563
i__2 = lvl - 1;
12564
lf = pow_ii(&c__2, &i__2);
12565
ll = (lf << 1) - 1;
12566
}
12567
i__2 = lf;
12568
for (i__ = ll; i__ >= i__2; --i__) {
12569
im1 = i__ - 1;
12570
ic = iwork[inode + im1];
12571
nl = iwork[ndiml + im1];
12572
nr = iwork[ndimr + im1];
12573
nlf = ic - nl;
12574
nrf = ic + 1;
12575
if (i__ == ll) {
12576
sqre = 0;
12577
} else {
12578
sqre = 1;
12579
}
12580
++j;
12581
zlals0_(icompq, &nl, &nr, &sqre, nrhs, &b[nlf + b_dim1], ldb, &bx[
12582
nlf + bx_dim1], ldbx, &perm[nlf + lvl * perm_dim1], &
12583
givptr[j], &givcol[nlf + lvl2 * givcol_dim1], ldgcol, &
12584
givnum[nlf + lvl2 * givnum_dim1], ldu, &poles[nlf + lvl2 *
12585
poles_dim1], &difl[nlf + lvl * difl_dim1], &difr[nlf +
12586
lvl2 * difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[
12587
j], &s[j], &rwork[1], info);
12588
/* L180: */
12589
}
12590
/* L190: */
12591
}
12592
12593
/*
12594
The nodes on the bottom level of the tree were solved
12595
by DLASDQ. The corresponding right singular vector
12596
matrices are in explicit form. Apply them back.
12597
*/
12598
12599
ndb1 = (nd + 1) / 2;
12600
i__1 = nd;
12601
for (i__ = ndb1; i__ <= i__1; ++i__) {
12602
i1 = i__ - 1;
12603
ic = iwork[inode + i1];
12604
nl = iwork[ndiml + i1];
12605
nr = iwork[ndimr + i1];
12606
nlp1 = nl + 1;
12607
if (i__ == nd) {
12608
nrp1 = nr;
12609
} else {
12610
nrp1 = nr + 1;
12611
}
12612
nlf = ic - nl;
12613
nrf = ic + 1;
12614
12615
/*
12616
Since B and BX are complex, the following call to DGEMM is
12617
performed in two steps (real and imaginary parts).
12618
12619
CALL DGEMM( 'T', 'N', NLP1, NRHS, NLP1, ONE, VT( NLF, 1 ), LDU,
12620
$ B( NLF, 1 ), LDB, ZERO, BX( NLF, 1 ), LDBX )
12621
*/
12622
12623
j = nlp1 * *nrhs << 1;
12624
i__2 = *nrhs;
12625
for (jcol = 1; jcol <= i__2; ++jcol) {
12626
i__3 = nlf + nlp1 - 1;
12627
for (jrow = nlf; jrow <= i__3; ++jrow) {
12628
++j;
12629
i__4 = jrow + jcol * b_dim1;
12630
rwork[j] = b[i__4].r;
12631
/* L200: */
12632
}
12633
/* L210: */
12634
}
12635
dgemm_("T", "N", &nlp1, nrhs, &nlp1, &c_b1034, &vt[nlf + vt_dim1],
12636
ldu, &rwork[(nlp1 * *nrhs << 1) + 1], &nlp1, &c_b328, &rwork[
12637
1], &nlp1);
12638
j = nlp1 * *nrhs << 1;
12639
i__2 = *nrhs;
12640
for (jcol = 1; jcol <= i__2; ++jcol) {
12641
i__3 = nlf + nlp1 - 1;
12642
for (jrow = nlf; jrow <= i__3; ++jrow) {
12643
++j;
12644
rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
12645
/* L220: */
12646
}
12647
/* L230: */
12648
}
12649
dgemm_("T", "N", &nlp1, nrhs, &nlp1, &c_b1034, &vt[nlf + vt_dim1],
12650
ldu, &rwork[(nlp1 * *nrhs << 1) + 1], &nlp1, &c_b328, &rwork[
12651
nlp1 * *nrhs + 1], &nlp1);
12652
jreal = 0;
12653
jimag = nlp1 * *nrhs;
12654
i__2 = *nrhs;
12655
for (jcol = 1; jcol <= i__2; ++jcol) {
12656
i__3 = nlf + nlp1 - 1;
12657
for (jrow = nlf; jrow <= i__3; ++jrow) {
12658
++jreal;
12659
++jimag;
12660
i__4 = jrow + jcol * bx_dim1;
12661
i__5 = jreal;
12662
i__6 = jimag;
12663
z__1.r = rwork[i__5], z__1.i = rwork[i__6];
12664
bx[i__4].r = z__1.r, bx[i__4].i = z__1.i;
12665
/* L240: */
12666
}
12667
/* L250: */
12668
}
12669
12670
/*
12671
Since B and BX are complex, the following call to DGEMM is
12672
performed in two steps (real and imaginary parts).
12673
12674
CALL DGEMM( 'T', 'N', NRP1, NRHS, NRP1, ONE, VT( NRF, 1 ), LDU,
12675
$ B( NRF, 1 ), LDB, ZERO, BX( NRF, 1 ), LDBX )
12676
*/
12677
12678
j = nrp1 * *nrhs << 1;
12679
i__2 = *nrhs;
12680
for (jcol = 1; jcol <= i__2; ++jcol) {
12681
i__3 = nrf + nrp1 - 1;
12682
for (jrow = nrf; jrow <= i__3; ++jrow) {
12683
++j;
12684
i__4 = jrow + jcol * b_dim1;
12685
rwork[j] = b[i__4].r;
12686
/* L260: */
12687
}
12688
/* L270: */
12689
}
12690
dgemm_("T", "N", &nrp1, nrhs, &nrp1, &c_b1034, &vt[nrf + vt_dim1],
12691
ldu, &rwork[(nrp1 * *nrhs << 1) + 1], &nrp1, &c_b328, &rwork[
12692
1], &nrp1);
12693
j = nrp1 * *nrhs << 1;
12694
i__2 = *nrhs;
12695
for (jcol = 1; jcol <= i__2; ++jcol) {
12696
i__3 = nrf + nrp1 - 1;
12697
for (jrow = nrf; jrow <= i__3; ++jrow) {
12698
++j;
12699
rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
12700
/* L280: */
12701
}
12702
/* L290: */
12703
}
12704
dgemm_("T", "N", &nrp1, nrhs, &nrp1, &c_b1034, &vt[nrf + vt_dim1],
12705
ldu, &rwork[(nrp1 * *nrhs << 1) + 1], &nrp1, &c_b328, &rwork[
12706
nrp1 * *nrhs + 1], &nrp1);
12707
jreal = 0;
12708
jimag = nrp1 * *nrhs;
12709
i__2 = *nrhs;
12710
for (jcol = 1; jcol <= i__2; ++jcol) {
12711
i__3 = nrf + nrp1 - 1;
12712
for (jrow = nrf; jrow <= i__3; ++jrow) {
12713
++jreal;
12714
++jimag;
12715
i__4 = jrow + jcol * bx_dim1;
12716
i__5 = jreal;
12717
i__6 = jimag;
12718
z__1.r = rwork[i__5], z__1.i = rwork[i__6];
12719
bx[i__4].r = z__1.r, bx[i__4].i = z__1.i;
12720
/* L300: */
12721
}
12722
/* L310: */
12723
}
12724
12725
/* L320: */
12726
}
12727
12728
L330:
12729
12730
return 0;
12731
12732
/* End of ZLALSA */
12733
12734
} /* zlalsa_ */
12735
12736
/* Subroutine */ int zlalsd_(char *uplo, integer *smlsiz, integer *n, integer
12737
*nrhs, doublereal *d__, doublereal *e, doublecomplex *b, integer *ldb,
12738
doublereal *rcond, integer *rank, doublecomplex *work, doublereal *
12739
rwork, integer *iwork, integer *info)
12740
{
12741
/* System generated locals */
12742
integer b_dim1, b_offset, i__1, i__2, i__3, i__4, i__5, i__6;
12743
doublereal d__1;
12744
doublecomplex z__1;
12745
12746
/* Local variables */
12747
static integer c__, i__, j, k;
12748
static doublereal r__;
12749
static integer s, u, z__;
12750
static doublereal cs;
12751
static integer bx;
12752
static doublereal sn;
12753
static integer st, vt, nm1, st1;
12754
static doublereal eps;
12755
static integer iwk;
12756
static doublereal tol;
12757
static integer difl, difr;
12758
static doublereal rcnd;
12759
static integer jcol, irwb, perm, nsub, nlvl, sqre, bxst, jrow, irwu,
12760
jimag;
12761
extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
12762
integer *, doublereal *, doublereal *, integer *, doublereal *,
12763
integer *, doublereal *, doublereal *, integer *);
12764
static integer jreal, irwib, poles, sizei, irwrb, nsize;
12765
extern /* Subroutine */ int zdrot_(integer *, doublecomplex *, integer *,
12766
doublecomplex *, integer *, doublereal *, doublereal *), zcopy_(
12767
integer *, doublecomplex *, integer *, doublecomplex *, integer *)
12768
;
12769
static integer irwvt, icmpq1, icmpq2;
12770
12771
extern /* Subroutine */ int dlasda_(integer *, integer *, integer *,
12772
integer *, doublereal *, doublereal *, doublereal *, integer *,
12773
doublereal *, integer *, doublereal *, doublereal *, doublereal *,
12774
doublereal *, integer *, integer *, integer *, integer *,
12775
doublereal *, doublereal *, doublereal *, doublereal *, integer *,
12776
integer *), dlascl_(char *, integer *, integer *, doublereal *,
12777
doublereal *, integer *, integer *, doublereal *, integer *,
12778
integer *);
12779
extern integer idamax_(integer *, doublereal *, integer *);
12780
extern /* Subroutine */ int dlasdq_(char *, integer *, integer *, integer
12781
*, integer *, integer *, doublereal *, doublereal *, doublereal *,
12782
integer *, doublereal *, integer *, doublereal *, integer *,
12783
doublereal *, integer *), dlaset_(char *, integer *,
12784
integer *, doublereal *, doublereal *, doublereal *, integer *), dlartg_(doublereal *, doublereal *, doublereal *,
12785
doublereal *, doublereal *), xerbla_(char *, integer *);
12786
static integer givcol;
12787
extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
12788
extern /* Subroutine */ int zlalsa_(integer *, integer *, integer *,
12789
integer *, doublecomplex *, integer *, doublecomplex *, integer *,
12790
doublereal *, integer *, doublereal *, integer *, doublereal *,
12791
doublereal *, doublereal *, doublereal *, integer *, integer *,
12792
integer *, integer *, doublereal *, doublereal *, doublereal *,
12793
doublereal *, integer *, integer *), zlascl_(char *, integer *,
12794
integer *, doublereal *, doublereal *, integer *, integer *,
12795
doublecomplex *, integer *, integer *), dlasrt_(char *,
12796
integer *, doublereal *, integer *), zlacpy_(char *,
12797
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
12798
integer *), zlaset_(char *, integer *, integer *,
12799
doublecomplex *, doublecomplex *, doublecomplex *, integer *);
12800
static doublereal orgnrm;
12801
static integer givnum, givptr, nrwork, irwwrk, smlszp;
12802
12803
12804
/*
12805
-- LAPACK routine (version 3.2.2) --
12806
-- LAPACK is a software package provided by Univ. of Tennessee, --
12807
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
12808
June 2010
12809
12810
12811
Purpose
12812
=======
12813
12814
ZLALSD uses the singular value decomposition of A to solve the least
12815
squares problem of finding X to minimize the Euclidean norm of each
12816
column of A*X-B, where A is N-by-N upper bidiagonal, and X and B
12817
are N-by-NRHS. The solution X overwrites B.
12818
12819
The singular values of A smaller than RCOND times the largest
12820
singular value are treated as zero in solving the least squares
12821
problem; in this case a minimum norm solution is returned.
12822
The actual singular values are returned in D in ascending order.
12823
12824
This code makes very mild assumptions about floating point
12825
arithmetic. It will work on machines with a guard digit in
12826
add/subtract, or on those binary machines without guard digits
12827
which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2.
12828
It could conceivably fail on hexadecimal or decimal machines
12829
without guard digits, but we know of none.
12830
12831
Arguments
12832
=========
12833
12834
UPLO (input) CHARACTER*1
12835
= 'U': D and E define an upper bidiagonal matrix.
12836
= 'L': D and E define a lower bidiagonal matrix.
12837
12838
SMLSIZ (input) INTEGER
12839
The maximum size of the subproblems at the bottom of the
12840
computation tree.
12841
12842
N (input) INTEGER
12843
The dimension of the bidiagonal matrix. N >= 0.
12844
12845
NRHS (input) INTEGER
12846
The number of columns of B. NRHS must be at least 1.
12847
12848
D (input/output) DOUBLE PRECISION array, dimension (N)
12849
On entry D contains the main diagonal of the bidiagonal
12850
matrix. On exit, if INFO = 0, D contains its singular values.
12851
12852
E (input/output) DOUBLE PRECISION array, dimension (N-1)
12853
Contains the super-diagonal entries of the bidiagonal matrix.
12854
On exit, E has been destroyed.
12855
12856
B (input/output) COMPLEX*16 array, dimension (LDB,NRHS)
12857
On input, B contains the right hand sides of the least
12858
squares problem. On output, B contains the solution X.
12859
12860
LDB (input) INTEGER
12861
The leading dimension of B in the calling subprogram.
12862
LDB must be at least max(1,N).
12863
12864
RCOND (input) DOUBLE PRECISION
12865
The singular values of A less than or equal to RCOND times
12866
the largest singular value are treated as zero in solving
12867
the least squares problem. If RCOND is negative,
12868
machine precision is used instead.
12869
For example, if diag(S)*X=B were the least squares problem,
12870
where diag(S) is a diagonal matrix of singular values, the
12871
solution would be X(i) = B(i) / S(i) if S(i) is greater than
12872
RCOND*max(S), and X(i) = 0 if S(i) is less than or equal to
12873
RCOND*max(S).
12874
12875
RANK (output) INTEGER
12876
The number of singular values of A greater than RCOND times
12877
the largest singular value.
12878
12879
WORK (workspace) COMPLEX*16 array, dimension at least
12880
(N * NRHS).
12881
12882
RWORK (workspace) DOUBLE PRECISION array, dimension at least
12883
(9*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS +
12884
MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS ),
12885
where
12886
NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 )
12887
12888
IWORK (workspace) INTEGER array, dimension at least
12889
(3*N*NLVL + 11*N).
12890
12891
INFO (output) INTEGER
12892
= 0: successful exit.
12893
< 0: if INFO = -i, the i-th argument had an illegal value.
12894
> 0: The algorithm failed to compute a singular value while
12895
working on the submatrix lying in rows and columns
12896
INFO/(N+1) through MOD(INFO,N+1).
12897
12898
Further Details
12899
===============
12900
12901
Based on contributions by
12902
Ming Gu and Ren-Cang Li, Computer Science Division, University of
12903
California at Berkeley, USA
12904
Osni Marques, LBNL/NERSC, USA
12905
12906
=====================================================================
12907
12908
12909
Test the input parameters.
12910
*/
12911
12912
/* Parameter adjustments */
12913
--d__;
12914
--e;
12915
b_dim1 = *ldb;
12916
b_offset = 1 + b_dim1;
12917
b -= b_offset;
12918
--work;
12919
--rwork;
12920
--iwork;
12921
12922
/* Function Body */
12923
*info = 0;
12924
12925
if (*n < 0) {
12926
*info = -3;
12927
} else if (*nrhs < 1) {
12928
*info = -4;
12929
} else if (*ldb < 1 || *ldb < *n) {
12930
*info = -8;
12931
}
12932
if (*info != 0) {
12933
i__1 = -(*info);
12934
xerbla_("ZLALSD", &i__1);
12935
return 0;
12936
}
12937
12938
eps = EPSILON;
12939
12940
/* Set up the tolerance. */
12941
12942
if (*rcond <= 0. || *rcond >= 1.) {
12943
rcnd = eps;
12944
} else {
12945
rcnd = *rcond;
12946
}
12947
12948
*rank = 0;
12949
12950
/* Quick return if possible. */
12951
12952
if (*n == 0) {
12953
return 0;
12954
} else if (*n == 1) {
12955
if (d__[1] == 0.) {
12956
zlaset_("A", &c__1, nrhs, &c_b56, &c_b56, &b[b_offset], ldb);
12957
} else {
12958
*rank = 1;
12959
zlascl_("G", &c__0, &c__0, &d__[1], &c_b1034, &c__1, nrhs, &b[
12960
b_offset], ldb, info);
12961
d__[1] = abs(d__[1]);
12962
}
12963
return 0;
12964
}
12965
12966
/* Rotate the matrix if it is lower bidiagonal. */
12967
12968
if (*(unsigned char *)uplo == 'L') {
12969
i__1 = *n - 1;
12970
for (i__ = 1; i__ <= i__1; ++i__) {
12971
dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
12972
d__[i__] = r__;
12973
e[i__] = sn * d__[i__ + 1];
12974
d__[i__ + 1] = cs * d__[i__ + 1];
12975
if (*nrhs == 1) {
12976
zdrot_(&c__1, &b[i__ + b_dim1], &c__1, &b[i__ + 1 + b_dim1], &
12977
c__1, &cs, &sn);
12978
} else {
12979
rwork[(i__ << 1) - 1] = cs;
12980
rwork[i__ * 2] = sn;
12981
}
12982
/* L10: */
12983
}
12984
if (*nrhs > 1) {
12985
i__1 = *nrhs;
12986
for (i__ = 1; i__ <= i__1; ++i__) {
12987
i__2 = *n - 1;
12988
for (j = 1; j <= i__2; ++j) {
12989
cs = rwork[(j << 1) - 1];
12990
sn = rwork[j * 2];
12991
zdrot_(&c__1, &b[j + i__ * b_dim1], &c__1, &b[j + 1 + i__
12992
* b_dim1], &c__1, &cs, &sn);
12993
/* L20: */
12994
}
12995
/* L30: */
12996
}
12997
}
12998
}
12999
13000
/* Scale. */
13001
13002
nm1 = *n - 1;
13003
orgnrm = dlanst_("M", n, &d__[1], &e[1]);
13004
if (orgnrm == 0.) {
13005
zlaset_("A", n, nrhs, &c_b56, &c_b56, &b[b_offset], ldb);
13006
return 0;
13007
}
13008
13009
dlascl_("G", &c__0, &c__0, &orgnrm, &c_b1034, n, &c__1, &d__[1], n, info);
13010
dlascl_("G", &c__0, &c__0, &orgnrm, &c_b1034, &nm1, &c__1, &e[1], &nm1,
13011
info);
13012
13013
/*
13014
If N is smaller than the minimum divide size SMLSIZ, then solve
13015
the problem with another solver.
13016
*/
13017
13018
if (*n <= *smlsiz) {
13019
irwu = 1;
13020
irwvt = irwu + *n * *n;
13021
irwwrk = irwvt + *n * *n;
13022
irwrb = irwwrk;
13023
irwib = irwrb + *n * *nrhs;
13024
irwb = irwib + *n * *nrhs;
13025
dlaset_("A", n, n, &c_b328, &c_b1034, &rwork[irwu], n);
13026
dlaset_("A", n, n, &c_b328, &c_b1034, &rwork[irwvt], n);
13027
dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &rwork[irwvt], n,
13028
&rwork[irwu], n, &rwork[irwwrk], &c__1, &rwork[irwwrk], info);
13029
if (*info != 0) {
13030
return 0;
13031
}
13032
13033
/*
13034
In the real version, B is passed to DLASDQ and multiplied
13035
internally by Q'. Here B is complex and that product is
13036
computed below in two steps (real and imaginary parts).
13037
*/
13038
13039
j = irwb - 1;
13040
i__1 = *nrhs;
13041
for (jcol = 1; jcol <= i__1; ++jcol) {
13042
i__2 = *n;
13043
for (jrow = 1; jrow <= i__2; ++jrow) {
13044
++j;
13045
i__3 = jrow + jcol * b_dim1;
13046
rwork[j] = b[i__3].r;
13047
/* L40: */
13048
}
13049
/* L50: */
13050
}
13051
dgemm_("T", "N", n, nrhs, n, &c_b1034, &rwork[irwu], n, &rwork[irwb],
13052
n, &c_b328, &rwork[irwrb], n);
13053
j = irwb - 1;
13054
i__1 = *nrhs;
13055
for (jcol = 1; jcol <= i__1; ++jcol) {
13056
i__2 = *n;
13057
for (jrow = 1; jrow <= i__2; ++jrow) {
13058
++j;
13059
rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
13060
/* L60: */
13061
}
13062
/* L70: */
13063
}
13064
dgemm_("T", "N", n, nrhs, n, &c_b1034, &rwork[irwu], n, &rwork[irwb],
13065
n, &c_b328, &rwork[irwib], n);
13066
jreal = irwrb - 1;
13067
jimag = irwib - 1;
13068
i__1 = *nrhs;
13069
for (jcol = 1; jcol <= i__1; ++jcol) {
13070
i__2 = *n;
13071
for (jrow = 1; jrow <= i__2; ++jrow) {
13072
++jreal;
13073
++jimag;
13074
i__3 = jrow + jcol * b_dim1;
13075
i__4 = jreal;
13076
i__5 = jimag;
13077
z__1.r = rwork[i__4], z__1.i = rwork[i__5];
13078
b[i__3].r = z__1.r, b[i__3].i = z__1.i;
13079
/* L80: */
13080
}
13081
/* L90: */
13082
}
13083
13084
tol = rcnd * (d__1 = d__[idamax_(n, &d__[1], &c__1)], abs(d__1));
13085
i__1 = *n;
13086
for (i__ = 1; i__ <= i__1; ++i__) {
13087
if (d__[i__] <= tol) {
13088
zlaset_("A", &c__1, nrhs, &c_b56, &c_b56, &b[i__ + b_dim1],
13089
ldb);
13090
} else {
13091
zlascl_("G", &c__0, &c__0, &d__[i__], &c_b1034, &c__1, nrhs, &
13092
b[i__ + b_dim1], ldb, info);
13093
++(*rank);
13094
}
13095
/* L100: */
13096
}
13097
13098
/*
13099
Since B is complex, the following call to DGEMM is performed
13100
in two steps (real and imaginary parts). That is for V * B
13101
(in the real version of the code V' is stored in WORK).
13102
13103
CALL DGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO,
13104
$ WORK( NWORK ), N )
13105
*/
13106
13107
j = irwb - 1;
13108
i__1 = *nrhs;
13109
for (jcol = 1; jcol <= i__1; ++jcol) {
13110
i__2 = *n;
13111
for (jrow = 1; jrow <= i__2; ++jrow) {
13112
++j;
13113
i__3 = jrow + jcol * b_dim1;
13114
rwork[j] = b[i__3].r;
13115
/* L110: */
13116
}
13117
/* L120: */
13118
}
13119
dgemm_("T", "N", n, nrhs, n, &c_b1034, &rwork[irwvt], n, &rwork[irwb],
13120
n, &c_b328, &rwork[irwrb], n);
13121
j = irwb - 1;
13122
i__1 = *nrhs;
13123
for (jcol = 1; jcol <= i__1; ++jcol) {
13124
i__2 = *n;
13125
for (jrow = 1; jrow <= i__2; ++jrow) {
13126
++j;
13127
rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
13128
/* L130: */
13129
}
13130
/* L140: */
13131
}
13132
dgemm_("T", "N", n, nrhs, n, &c_b1034, &rwork[irwvt], n, &rwork[irwb],
13133
n, &c_b328, &rwork[irwib], n);
13134
jreal = irwrb - 1;
13135
jimag = irwib - 1;
13136
i__1 = *nrhs;
13137
for (jcol = 1; jcol <= i__1; ++jcol) {
13138
i__2 = *n;
13139
for (jrow = 1; jrow <= i__2; ++jrow) {
13140
++jreal;
13141
++jimag;
13142
i__3 = jrow + jcol * b_dim1;
13143
i__4 = jreal;
13144
i__5 = jimag;
13145
z__1.r = rwork[i__4], z__1.i = rwork[i__5];
13146
b[i__3].r = z__1.r, b[i__3].i = z__1.i;
13147
/* L150: */
13148
}
13149
/* L160: */
13150
}
13151
13152
/* Unscale. */
13153
13154
dlascl_("G", &c__0, &c__0, &c_b1034, &orgnrm, n, &c__1, &d__[1], n,
13155
info);
13156
dlasrt_("D", n, &d__[1], info);
13157
zlascl_("G", &c__0, &c__0, &orgnrm, &c_b1034, n, nrhs, &b[b_offset],
13158
ldb, info);
13159
13160
return 0;
13161
}
13162
13163
/* Book-keeping and setting up some constants. */
13164
13165
nlvl = (integer) (log((doublereal) (*n) / (doublereal) (*smlsiz + 1)) /
13166
log(2.)) + 1;
13167
13168
smlszp = *smlsiz + 1;
13169
13170
u = 1;
13171
vt = *smlsiz * *n + 1;
13172
difl = vt + smlszp * *n;
13173
difr = difl + nlvl * *n;
13174
z__ = difr + (nlvl * *n << 1);
13175
c__ = z__ + nlvl * *n;
13176
s = c__ + *n;
13177
poles = s + *n;
13178
givnum = poles + (nlvl << 1) * *n;
13179
nrwork = givnum + (nlvl << 1) * *n;
13180
bx = 1;
13181
13182
irwrb = nrwork;
13183
irwib = irwrb + *smlsiz * *nrhs;
13184
irwb = irwib + *smlsiz * *nrhs;
13185
13186
sizei = *n + 1;
13187
k = sizei + *n;
13188
givptr = k + *n;
13189
perm = givptr + *n;
13190
givcol = perm + nlvl * *n;
13191
iwk = givcol + (nlvl * *n << 1);
13192
13193
st = 1;
13194
sqre = 0;
13195
icmpq1 = 1;
13196
icmpq2 = 0;
13197
nsub = 0;
13198
13199
i__1 = *n;
13200
for (i__ = 1; i__ <= i__1; ++i__) {
13201
if ((d__1 = d__[i__], abs(d__1)) < eps) {
13202
d__[i__] = d_sign(&eps, &d__[i__]);
13203
}
13204
/* L170: */
13205
}
13206
13207
i__1 = nm1;
13208
for (i__ = 1; i__ <= i__1; ++i__) {
13209
if ((d__1 = e[i__], abs(d__1)) < eps || i__ == nm1) {
13210
++nsub;
13211
iwork[nsub] = st;
13212
13213
/*
13214
Subproblem found. First determine its size and then
13215
apply divide and conquer on it.
13216
*/
13217
13218
if (i__ < nm1) {
13219
13220
/* A subproblem with E(I) small for I < NM1. */
13221
13222
nsize = i__ - st + 1;
13223
iwork[sizei + nsub - 1] = nsize;
13224
} else if ((d__1 = e[i__], abs(d__1)) >= eps) {
13225
13226
/* A subproblem with E(NM1) not too small but I = NM1. */
13227
13228
nsize = *n - st + 1;
13229
iwork[sizei + nsub - 1] = nsize;
13230
} else {
13231
13232
/*
13233
A subproblem with E(NM1) small. This implies an
13234
1-by-1 subproblem at D(N), which is not solved
13235
explicitly.
13236
*/
13237
13238
nsize = i__ - st + 1;
13239
iwork[sizei + nsub - 1] = nsize;
13240
++nsub;
13241
iwork[nsub] = *n;
13242
iwork[sizei + nsub - 1] = 1;
13243
zcopy_(nrhs, &b[*n + b_dim1], ldb, &work[bx + nm1], n);
13244
}
13245
st1 = st - 1;
13246
if (nsize == 1) {
13247
13248
/*
13249
This is a 1-by-1 subproblem and is not solved
13250
explicitly.
13251
*/
13252
13253
zcopy_(nrhs, &b[st + b_dim1], ldb, &work[bx + st1], n);
13254
} else if (nsize <= *smlsiz) {
13255
13256
/* This is a small subproblem and is solved by DLASDQ. */
13257
13258
dlaset_("A", &nsize, &nsize, &c_b328, &c_b1034, &rwork[vt +
13259
st1], n);
13260
dlaset_("A", &nsize, &nsize, &c_b328, &c_b1034, &rwork[u +
13261
st1], n);
13262
dlasdq_("U", &c__0, &nsize, &nsize, &nsize, &c__0, &d__[st], &
13263
e[st], &rwork[vt + st1], n, &rwork[u + st1], n, &
13264
rwork[nrwork], &c__1, &rwork[nrwork], info)
13265
;
13266
if (*info != 0) {
13267
return 0;
13268
}
13269
13270
/*
13271
In the real version, B is passed to DLASDQ and multiplied
13272
internally by Q'. Here B is complex and that product is
13273
computed below in two steps (real and imaginary parts).
13274
*/
13275
13276
j = irwb - 1;
13277
i__2 = *nrhs;
13278
for (jcol = 1; jcol <= i__2; ++jcol) {
13279
i__3 = st + nsize - 1;
13280
for (jrow = st; jrow <= i__3; ++jrow) {
13281
++j;
13282
i__4 = jrow + jcol * b_dim1;
13283
rwork[j] = b[i__4].r;
13284
/* L180: */
13285
}
13286
/* L190: */
13287
}
13288
dgemm_("T", "N", &nsize, nrhs, &nsize, &c_b1034, &rwork[u +
13289
st1], n, &rwork[irwb], &nsize, &c_b328, &rwork[irwrb],
13290
&nsize);
13291
j = irwb - 1;
13292
i__2 = *nrhs;
13293
for (jcol = 1; jcol <= i__2; ++jcol) {
13294
i__3 = st + nsize - 1;
13295
for (jrow = st; jrow <= i__3; ++jrow) {
13296
++j;
13297
rwork[j] = d_imag(&b[jrow + jcol * b_dim1]);
13298
/* L200: */
13299
}
13300
/* L210: */
13301
}
13302
dgemm_("T", "N", &nsize, nrhs, &nsize, &c_b1034, &rwork[u +
13303
st1], n, &rwork[irwb], &nsize, &c_b328, &rwork[irwib],
13304
&nsize);
13305
jreal = irwrb - 1;
13306
jimag = irwib - 1;
13307
i__2 = *nrhs;
13308
for (jcol = 1; jcol <= i__2; ++jcol) {
13309
i__3 = st + nsize - 1;
13310
for (jrow = st; jrow <= i__3; ++jrow) {
13311
++jreal;
13312
++jimag;
13313
i__4 = jrow + jcol * b_dim1;
13314
i__5 = jreal;
13315
i__6 = jimag;
13316
z__1.r = rwork[i__5], z__1.i = rwork[i__6];
13317
b[i__4].r = z__1.r, b[i__4].i = z__1.i;
13318
/* L220: */
13319
}
13320
/* L230: */
13321
}
13322
13323
zlacpy_("A", &nsize, nrhs, &b[st + b_dim1], ldb, &work[bx +
13324
st1], n);
13325
} else {
13326
13327
/* A large problem. Solve it using divide and conquer. */
13328
13329
dlasda_(&icmpq1, smlsiz, &nsize, &sqre, &d__[st], &e[st], &
13330
rwork[u + st1], n, &rwork[vt + st1], &iwork[k + st1],
13331
&rwork[difl + st1], &rwork[difr + st1], &rwork[z__ +
13332
st1], &rwork[poles + st1], &iwork[givptr + st1], &
13333
iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
13334
givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &
13335
rwork[nrwork], &iwork[iwk], info);
13336
if (*info != 0) {
13337
return 0;
13338
}
13339
bxst = bx + st1;
13340
zlalsa_(&icmpq2, smlsiz, &nsize, nrhs, &b[st + b_dim1], ldb, &
13341
work[bxst], n, &rwork[u + st1], n, &rwork[vt + st1], &
13342
iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1]
13343
, &rwork[z__ + st1], &rwork[poles + st1], &iwork[
13344
givptr + st1], &iwork[givcol + st1], n, &iwork[perm +
13345
st1], &rwork[givnum + st1], &rwork[c__ + st1], &rwork[
13346
s + st1], &rwork[nrwork], &iwork[iwk], info);
13347
if (*info != 0) {
13348
return 0;
13349
}
13350
}
13351
st = i__ + 1;
13352
}
13353
/* L240: */
13354
}
13355
13356
/* Apply the singular values and treat the tiny ones as zero. */
13357
13358
tol = rcnd * (d__1 = d__[idamax_(n, &d__[1], &c__1)], abs(d__1));
13359
13360
i__1 = *n;
13361
for (i__ = 1; i__ <= i__1; ++i__) {
13362
13363
/*
13364
Some of the elements in D can be negative because 1-by-1
13365
subproblems were not solved explicitly.
13366
*/
13367
13368
if ((d__1 = d__[i__], abs(d__1)) <= tol) {
13369
zlaset_("A", &c__1, nrhs, &c_b56, &c_b56, &work[bx + i__ - 1], n);
13370
} else {
13371
++(*rank);
13372
zlascl_("G", &c__0, &c__0, &d__[i__], &c_b1034, &c__1, nrhs, &
13373
work[bx + i__ - 1], n, info);
13374
}
13375
d__[i__] = (d__1 = d__[i__], abs(d__1));
13376
/* L250: */
13377
}
13378
13379
/* Now apply back the right singular vectors. */
13380
13381
icmpq2 = 1;
13382
i__1 = nsub;
13383
for (i__ = 1; i__ <= i__1; ++i__) {
13384
st = iwork[i__];
13385
st1 = st - 1;
13386
nsize = iwork[sizei + i__ - 1];
13387
bxst = bx + st1;
13388
if (nsize == 1) {
13389
zcopy_(nrhs, &work[bxst], n, &b[st + b_dim1], ldb);
13390
} else if (nsize <= *smlsiz) {
13391
13392
/*
13393
Since B and BX are complex, the following call to DGEMM
13394
is performed in two steps (real and imaginary parts).
13395
13396
CALL DGEMM( 'T', 'N', NSIZE, NRHS, NSIZE, ONE,
13397
$ RWORK( VT+ST1 ), N, RWORK( BXST ), N, ZERO,
13398
$ B( ST, 1 ), LDB )
13399
*/
13400
13401
j = bxst - *n - 1;
13402
jreal = irwb - 1;
13403
i__2 = *nrhs;
13404
for (jcol = 1; jcol <= i__2; ++jcol) {
13405
j += *n;
13406
i__3 = nsize;
13407
for (jrow = 1; jrow <= i__3; ++jrow) {
13408
++jreal;
13409
i__4 = j + jrow;
13410
rwork[jreal] = work[i__4].r;
13411
/* L260: */
13412
}
13413
/* L270: */
13414
}
13415
dgemm_("T", "N", &nsize, nrhs, &nsize, &c_b1034, &rwork[vt + st1],
13416
n, &rwork[irwb], &nsize, &c_b328, &rwork[irwrb], &nsize);
13417
j = bxst - *n - 1;
13418
jimag = irwb - 1;
13419
i__2 = *nrhs;
13420
for (jcol = 1; jcol <= i__2; ++jcol) {
13421
j += *n;
13422
i__3 = nsize;
13423
for (jrow = 1; jrow <= i__3; ++jrow) {
13424
++jimag;
13425
rwork[jimag] = d_imag(&work[j + jrow]);
13426
/* L280: */
13427
}
13428
/* L290: */
13429
}
13430
dgemm_("T", "N", &nsize, nrhs, &nsize, &c_b1034, &rwork[vt + st1],
13431
n, &rwork[irwb], &nsize, &c_b328, &rwork[irwib], &nsize);
13432
jreal = irwrb - 1;
13433
jimag = irwib - 1;
13434
i__2 = *nrhs;
13435
for (jcol = 1; jcol <= i__2; ++jcol) {
13436
i__3 = st + nsize - 1;
13437
for (jrow = st; jrow <= i__3; ++jrow) {
13438
++jreal;
13439
++jimag;
13440
i__4 = jrow + jcol * b_dim1;
13441
i__5 = jreal;
13442
i__6 = jimag;
13443
z__1.r = rwork[i__5], z__1.i = rwork[i__6];
13444
b[i__4].r = z__1.r, b[i__4].i = z__1.i;
13445
/* L300: */
13446
}
13447
/* L310: */
13448
}
13449
} else {
13450
zlalsa_(&icmpq2, smlsiz, &nsize, nrhs, &work[bxst], n, &b[st +
13451
b_dim1], ldb, &rwork[u + st1], n, &rwork[vt + st1], &
13452
iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1], &
13453
rwork[z__ + st1], &rwork[poles + st1], &iwork[givptr +
13454
st1], &iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
13455
givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &rwork[
13456
nrwork], &iwork[iwk], info);
13457
if (*info != 0) {
13458
return 0;
13459
}
13460
}
13461
/* L320: */
13462
}
13463
13464
/* Unscale and sort the singular values. */
13465
13466
dlascl_("G", &c__0, &c__0, &c_b1034, &orgnrm, n, &c__1, &d__[1], n, info);
13467
dlasrt_("D", n, &d__[1], info);
13468
zlascl_("G", &c__0, &c__0, &orgnrm, &c_b1034, n, nrhs, &b[b_offset], ldb,
13469
info);
13470
13471
return 0;
13472
13473
/* End of ZLALSD */
13474
13475
} /* zlalsd_ */
13476
13477
doublereal zlange_(char *norm, integer *m, integer *n, doublecomplex *a,
13478
integer *lda, doublereal *work)
13479
{
13480
/* System generated locals */
13481
integer a_dim1, a_offset, i__1, i__2;
13482
doublereal ret_val, d__1, d__2;
13483
13484
/* Local variables */
13485
static integer i__, j;
13486
static doublereal sum, scale;
13487
extern logical lsame_(char *, char *);
13488
static doublereal value;
13489
extern /* Subroutine */ int zlassq_(integer *, doublecomplex *, integer *,
13490
doublereal *, doublereal *);
13491
13492
13493
/*
13494
-- LAPACK auxiliary routine (version 3.2) --
13495
-- LAPACK is a software package provided by Univ. of Tennessee, --
13496
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
13497
November 2006
13498
13499
13500
Purpose
13501
=======
13502
13503
ZLANGE returns the value of the one norm, or the Frobenius norm, or
13504
the infinity norm, or the element of largest absolute value of a
13505
complex matrix A.
13506
13507
Description
13508
===========
13509
13510
ZLANGE returns the value
13511
13512
ZLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
13513
(
13514
( norm1(A), NORM = '1', 'O' or 'o'
13515
(
13516
( normI(A), NORM = 'I' or 'i'
13517
(
13518
( normF(A), NORM = 'F', 'f', 'E' or 'e'
13519
13520
where norm1 denotes the one norm of a matrix (maximum column sum),
13521
normI denotes the infinity norm of a matrix (maximum row sum) and
13522
normF denotes the Frobenius norm of a matrix (square root of sum of
13523
squares). Note that max(abs(A(i,j))) is not a consistent matrix norm.
13524
13525
Arguments
13526
=========
13527
13528
NORM (input) CHARACTER*1
13529
Specifies the value to be returned in ZLANGE as described
13530
above.
13531
13532
M (input) INTEGER
13533
The number of rows of the matrix A. M >= 0. When M = 0,
13534
ZLANGE is set to zero.
13535
13536
N (input) INTEGER
13537
The number of columns of the matrix A. N >= 0. When N = 0,
13538
ZLANGE is set to zero.
13539
13540
A (input) COMPLEX*16 array, dimension (LDA,N)
13541
The m by n matrix A.
13542
13543
LDA (input) INTEGER
13544
The leading dimension of the array A. LDA >= max(M,1).
13545
13546
WORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
13547
where LWORK >= M when NORM = 'I'; otherwise, WORK is not
13548
referenced.
13549
13550
=====================================================================
13551
*/
13552
13553
13554
/* Parameter adjustments */
13555
a_dim1 = *lda;
13556
a_offset = 1 + a_dim1;
13557
a -= a_offset;
13558
--work;
13559
13560
/* Function Body */
13561
if (min(*m,*n) == 0) {
13562
value = 0.;
13563
} else if (lsame_(norm, "M")) {
13564
13565
/* Find max(abs(A(i,j))). */
13566
13567
value = 0.;
13568
i__1 = *n;
13569
for (j = 1; j <= i__1; ++j) {
13570
i__2 = *m;
13571
for (i__ = 1; i__ <= i__2; ++i__) {
13572
/* Computing MAX */
13573
d__1 = value, d__2 = z_abs(&a[i__ + j * a_dim1]);
13574
value = max(d__1,d__2);
13575
/* L10: */
13576
}
13577
/* L20: */
13578
}
13579
} else if (lsame_(norm, "O") || *(unsigned char *)
13580
norm == '1') {
13581
13582
/* Find norm1(A). */
13583
13584
value = 0.;
13585
i__1 = *n;
13586
for (j = 1; j <= i__1; ++j) {
13587
sum = 0.;
13588
i__2 = *m;
13589
for (i__ = 1; i__ <= i__2; ++i__) {
13590
sum += z_abs(&a[i__ + j * a_dim1]);
13591
/* L30: */
13592
}
13593
value = max(value,sum);
13594
/* L40: */
13595
}
13596
} else if (lsame_(norm, "I")) {
13597
13598
/* Find normI(A). */
13599
13600
i__1 = *m;
13601
for (i__ = 1; i__ <= i__1; ++i__) {
13602
work[i__] = 0.;
13603
/* L50: */
13604
}
13605
i__1 = *n;
13606
for (j = 1; j <= i__1; ++j) {
13607
i__2 = *m;
13608
for (i__ = 1; i__ <= i__2; ++i__) {
13609
work[i__] += z_abs(&a[i__ + j * a_dim1]);
13610
/* L60: */
13611
}
13612
/* L70: */
13613
}
13614
value = 0.;
13615
i__1 = *m;
13616
for (i__ = 1; i__ <= i__1; ++i__) {
13617
/* Computing MAX */
13618
d__1 = value, d__2 = work[i__];
13619
value = max(d__1,d__2);
13620
/* L80: */
13621
}
13622
} else if (lsame_(norm, "F") || lsame_(norm, "E")) {
13623
13624
/* Find normF(A). */
13625
13626
scale = 0.;
13627
sum = 1.;
13628
i__1 = *n;
13629
for (j = 1; j <= i__1; ++j) {
13630
zlassq_(m, &a[j * a_dim1 + 1], &c__1, &scale, &sum);
13631
/* L90: */
13632
}
13633
value = scale * sqrt(sum);
13634
}
13635
13636
ret_val = value;
13637
return ret_val;
13638
13639
/* End of ZLANGE */
13640
13641
} /* zlange_ */
13642
13643
doublereal zlanhe_(char *norm, char *uplo, integer *n, doublecomplex *a,
13644
integer *lda, doublereal *work)
13645
{
13646
/* System generated locals */
13647
integer a_dim1, a_offset, i__1, i__2;
13648
doublereal ret_val, d__1, d__2, d__3;
13649
13650
/* Local variables */
13651
static integer i__, j;
13652
static doublereal sum, absa, scale;
13653
extern logical lsame_(char *, char *);
13654
static doublereal value;
13655
extern /* Subroutine */ int zlassq_(integer *, doublecomplex *, integer *,
13656
doublereal *, doublereal *);
13657
13658
13659
/*
13660
-- LAPACK auxiliary routine (version 3.2) --
13661
-- LAPACK is a software package provided by Univ. of Tennessee, --
13662
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
13663
November 2006
13664
13665
13666
Purpose
13667
=======
13668
13669
ZLANHE returns the value of the one norm, or the Frobenius norm, or
13670
the infinity norm, or the element of largest absolute value of a
13671
complex hermitian matrix A.
13672
13673
Description
13674
===========
13675
13676
ZLANHE returns the value
13677
13678
ZLANHE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
13679
(
13680
( norm1(A), NORM = '1', 'O' or 'o'
13681
(
13682
( normI(A), NORM = 'I' or 'i'
13683
(
13684
( normF(A), NORM = 'F', 'f', 'E' or 'e'
13685
13686
where norm1 denotes the one norm of a matrix (maximum column sum),
13687
normI denotes the infinity norm of a matrix (maximum row sum) and
13688
normF denotes the Frobenius norm of a matrix (square root of sum of
13689
squares). Note that max(abs(A(i,j))) is not a consistent matrix norm.
13690
13691
Arguments
13692
=========
13693
13694
NORM (input) CHARACTER*1
13695
Specifies the value to be returned in ZLANHE as described
13696
above.
13697
13698
UPLO (input) CHARACTER*1
13699
Specifies whether the upper or lower triangular part of the
13700
hermitian matrix A is to be referenced.
13701
= 'U': Upper triangular part of A is referenced
13702
= 'L': Lower triangular part of A is referenced
13703
13704
N (input) INTEGER
13705
The order of the matrix A. N >= 0. When N = 0, ZLANHE is
13706
set to zero.
13707
13708
A (input) COMPLEX*16 array, dimension (LDA,N)
13709
The hermitian matrix A. If UPLO = 'U', the leading n by n
13710
upper triangular part of A contains the upper triangular part
13711
of the matrix A, and the strictly lower triangular part of A
13712
is not referenced. If UPLO = 'L', the leading n by n lower
13713
triangular part of A contains the lower triangular part of
13714
the matrix A, and the strictly upper triangular part of A is
13715
not referenced. Note that the imaginary parts of the diagonal
13716
elements need not be set and are assumed to be zero.
13717
13718
LDA (input) INTEGER
13719
The leading dimension of the array A. LDA >= max(N,1).
13720
13721
WORK (workspace) DOUBLE PRECISION array, dimension (MAX(1,LWORK)),
13722
where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
13723
WORK is not referenced.
13724
13725
=====================================================================
13726
*/
13727
13728
13729
/* Parameter adjustments */
13730
a_dim1 = *lda;
13731
a_offset = 1 + a_dim1;
13732
a -= a_offset;
13733
--work;
13734
13735
/* Function Body */
13736
if (*n == 0) {
13737
value = 0.;
13738
} else if (lsame_(norm, "M")) {
13739
13740
/* Find max(abs(A(i,j))). */
13741
13742
value = 0.;
13743
if (lsame_(uplo, "U")) {
13744
i__1 = *n;
13745
for (j = 1; j <= i__1; ++j) {
13746
i__2 = j - 1;
13747
for (i__ = 1; i__ <= i__2; ++i__) {
13748
/* Computing MAX */
13749
d__1 = value, d__2 = z_abs(&a[i__ + j * a_dim1]);
13750
value = max(d__1,d__2);
13751
/* L10: */
13752
}
13753
/* Computing MAX */
13754
i__2 = j + j * a_dim1;
13755
d__2 = value, d__3 = (d__1 = a[i__2].r, abs(d__1));
13756
value = max(d__2,d__3);
13757
/* L20: */
13758
}
13759
} else {
13760
i__1 = *n;
13761
for (j = 1; j <= i__1; ++j) {
13762
/* Computing MAX */
13763
i__2 = j + j * a_dim1;
13764
d__2 = value, d__3 = (d__1 = a[i__2].r, abs(d__1));
13765
value = max(d__2,d__3);
13766
i__2 = *n;
13767
for (i__ = j + 1; i__ <= i__2; ++i__) {
13768
/* Computing MAX */
13769
d__1 = value, d__2 = z_abs(&a[i__ + j * a_dim1]);
13770
value = max(d__1,d__2);
13771
/* L30: */
13772
}
13773
/* L40: */
13774
}
13775
}
13776
} else if (lsame_(norm, "I") || lsame_(norm, "O") || *(unsigned char *)norm == '1') {
13777
13778
/* Find normI(A) ( = norm1(A), since A is hermitian). */
13779
13780
value = 0.;
13781
if (lsame_(uplo, "U")) {
13782
i__1 = *n;
13783
for (j = 1; j <= i__1; ++j) {
13784
sum = 0.;
13785
i__2 = j - 1;
13786
for (i__ = 1; i__ <= i__2; ++i__) {
13787
absa = z_abs(&a[i__ + j * a_dim1]);
13788
sum += absa;
13789
work[i__] += absa;
13790
/* L50: */
13791
}
13792
i__2 = j + j * a_dim1;
13793
work[j] = sum + (d__1 = a[i__2].r, abs(d__1));
13794
/* L60: */
13795
}
13796
i__1 = *n;
13797
for (i__ = 1; i__ <= i__1; ++i__) {
13798
/* Computing MAX */
13799
d__1 = value, d__2 = work[i__];
13800
value = max(d__1,d__2);
13801
/* L70: */
13802
}
13803
} else {
13804
i__1 = *n;
13805
for (i__ = 1; i__ <= i__1; ++i__) {
13806
work[i__] = 0.;
13807
/* L80: */
13808
}
13809
i__1 = *n;
13810
for (j = 1; j <= i__1; ++j) {
13811
i__2 = j + j * a_dim1;
13812
sum = work[j] + (d__1 = a[i__2].r, abs(d__1));
13813
i__2 = *n;
13814
for (i__ = j + 1; i__ <= i__2; ++i__) {
13815
absa = z_abs(&a[i__ + j * a_dim1]);
13816
sum += absa;
13817
work[i__] += absa;
13818
/* L90: */
13819
}
13820
value = max(value,sum);
13821
/* L100: */
13822
}
13823
}
13824
} else if (lsame_(norm, "F") || lsame_(norm, "E")) {
13825
13826
/* Find normF(A). */
13827
13828
scale = 0.;
13829
sum = 1.;
13830
if (lsame_(uplo, "U")) {
13831
i__1 = *n;
13832
for (j = 2; j <= i__1; ++j) {
13833
i__2 = j - 1;
13834
zlassq_(&i__2, &a[j * a_dim1 + 1], &c__1, &scale, &sum);
13835
/* L110: */
13836
}
13837
} else {
13838
i__1 = *n - 1;
13839
for (j = 1; j <= i__1; ++j) {
13840
i__2 = *n - j;
13841
zlassq_(&i__2, &a[j + 1 + j * a_dim1], &c__1, &scale, &sum);
13842
/* L120: */
13843
}
13844
}
13845
sum *= 2;
13846
i__1 = *n;
13847
for (i__ = 1; i__ <= i__1; ++i__) {
13848
i__2 = i__ + i__ * a_dim1;
13849
if (a[i__2].r != 0.) {
13850
i__2 = i__ + i__ * a_dim1;
13851
absa = (d__1 = a[i__2].r, abs(d__1));
13852
if (scale < absa) {
13853
/* Computing 2nd power */
13854
d__1 = scale / absa;
13855
sum = sum * (d__1 * d__1) + 1.;
13856
scale = absa;
13857
} else {
13858
/* Computing 2nd power */
13859
d__1 = absa / scale;
13860
sum += d__1 * d__1;
13861
}
13862
}
13863
/* L130: */
13864
}
13865
value = scale * sqrt(sum);
13866
}
13867
13868
ret_val = value;
13869
return ret_val;
13870
13871
/* End of ZLANHE */
13872
13873
} /* zlanhe_ */
13874
13875
/* Subroutine */ int zlaqr0_(logical *wantt, logical *wantz, integer *n,
13876
integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh,
13877
doublecomplex *w, integer *iloz, integer *ihiz, doublecomplex *z__,
13878
integer *ldz, doublecomplex *work, integer *lwork, integer *info)
13879
{
13880
/* System generated locals */
13881
integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
13882
doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8;
13883
doublecomplex z__1, z__2, z__3, z__4, z__5;
13884
13885
/* Local variables */
13886
static integer i__, k;
13887
static doublereal s;
13888
static doublecomplex aa, bb, cc, dd;
13889
static integer ld, nh, it, ks, kt, ku, kv, ls, ns, nw;
13890
static doublecomplex tr2, det;
13891
static integer inf, kdu, nho, nve, kwh, nsr, nwr, kwv, ndec, ndfl, kbot,
13892
nmin;
13893
static doublecomplex swap;
13894
static integer ktop;
13895
static doublecomplex zdum[1] /* was [1][1] */;
13896
static integer kacc22, itmax, nsmax, nwmax, kwtop;
13897
extern /* Subroutine */ int zlaqr3_(logical *, logical *, integer *,
13898
integer *, integer *, integer *, doublecomplex *, integer *,
13899
integer *, integer *, doublecomplex *, integer *, integer *,
13900
integer *, doublecomplex *, doublecomplex *, integer *, integer *,
13901
doublecomplex *, integer *, integer *, doublecomplex *, integer *
13902
, doublecomplex *, integer *), zlaqr4_(logical *, logical *,
13903
integer *, integer *, integer *, doublecomplex *, integer *,
13904
doublecomplex *, integer *, integer *, doublecomplex *, integer *,
13905
doublecomplex *, integer *, integer *), zlaqr5_(logical *,
13906
logical *, integer *, integer *, integer *, integer *, integer *,
13907
doublecomplex *, doublecomplex *, integer *, integer *, integer *,
13908
doublecomplex *, integer *, doublecomplex *, integer *,
13909
doublecomplex *, integer *, integer *, doublecomplex *, integer *,
13910
integer *, doublecomplex *, integer *);
13911
static integer nibble;
13912
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
13913
integer *, integer *, ftnlen, ftnlen);
13914
static char jbcmpz[2];
13915
static doublecomplex rtdisc;
13916
static integer nwupbd;
13917
static logical sorted;
13918
extern /* Subroutine */ int zlahqr_(logical *, logical *, integer *,
13919
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
13920
integer *, integer *, doublecomplex *, integer *, integer *),
13921
zlacpy_(char *, integer *, integer *, doublecomplex *, integer *,
13922
doublecomplex *, integer *);
13923
static integer lwkopt;
13924
13925
13926
/*
13927
-- LAPACK auxiliary routine (version 3.2) --
13928
Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
13929
November 2006
13930
13931
13932
Purpose
13933
=======
13934
13935
ZLAQR0 computes the eigenvalues of a Hessenberg matrix H
13936
and, optionally, the matrices T and Z from the Schur decomposition
13937
H = Z T Z**H, where T is an upper triangular matrix (the
13938
Schur form), and Z is the unitary matrix of Schur vectors.
13939
13940
Optionally Z may be postmultiplied into an input unitary
13941
matrix Q so that this routine can give the Schur factorization
13942
of a matrix A which has been reduced to the Hessenberg form H
13943
by the unitary matrix Q: A = Q*H*Q**H = (QZ)*H*(QZ)**H.
13944
13945
Arguments
13946
=========
13947
13948
WANTT (input) LOGICAL
13949
= .TRUE. : the full Schur form T is required;
13950
= .FALSE.: only eigenvalues are required.
13951
13952
WANTZ (input) LOGICAL
13953
= .TRUE. : the matrix of Schur vectors Z is required;
13954
= .FALSE.: Schur vectors are not required.
13955
13956
N (input) INTEGER
13957
The order of the matrix H. N .GE. 0.
13958
13959
ILO (input) INTEGER
13960
IHI (input) INTEGER
13961
It is assumed that H is already upper triangular in rows
13962
and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1,
13963
H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
13964
previous call to ZGEBAL, and then passed to ZGEHRD when the
13965
matrix output by ZGEBAL is reduced to Hessenberg form.
13966
Otherwise, ILO and IHI should be set to 1 and N,
13967
respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
13968
If N = 0, then ILO = 1 and IHI = 0.
13969
13970
H (input/output) COMPLEX*16 array, dimension (LDH,N)
13971
On entry, the upper Hessenberg matrix H.
13972
On exit, if INFO = 0 and WANTT is .TRUE., then H
13973
contains the upper triangular matrix T from the Schur
13974
decomposition (the Schur form). If INFO = 0 and WANT is
13975
.FALSE., then the contents of H are unspecified on exit.
13976
(The output value of H when INFO.GT.0 is given under the
13977
description of INFO below.)
13978
13979
This subroutine may explicitly set H(i,j) = 0 for i.GT.j and
13980
j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
13981
13982
LDH (input) INTEGER
13983
The leading dimension of the array H. LDH .GE. max(1,N).
13984
13985
W (output) COMPLEX*16 array, dimension (N)
13986
The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored
13987
in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are
13988
stored in the same order as on the diagonal of the Schur
13989
form returned in H, with W(i) = H(i,i).
13990
13991
Z (input/output) COMPLEX*16 array, dimension (LDZ,IHI)
13992
If WANTZ is .FALSE., then Z is not referenced.
13993
If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
13994
replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
13995
orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
13996
(The output value of Z when INFO.GT.0 is given under
13997
the description of INFO below.)
13998
13999
LDZ (input) INTEGER
14000
The leading dimension of the array Z. if WANTZ is .TRUE.
14001
then LDZ.GE.MAX(1,IHIZ). Otherwize, LDZ.GE.1.
14002
14003
WORK (workspace/output) COMPLEX*16 array, dimension LWORK
14004
On exit, if LWORK = -1, WORK(1) returns an estimate of
14005
the optimal value for LWORK.
14006
14007
LWORK (input) INTEGER
14008
The dimension of the array WORK. LWORK .GE. max(1,N)
14009
is sufficient, but LWORK typically as large as 6*N may
14010
be required for optimal performance. A workspace query
14011
to determine the optimal workspace size is recommended.
14012
14013
If LWORK = -1, then ZLAQR0 does a workspace query.
14014
In this case, ZLAQR0 checks the input parameters and
14015
estimates the optimal workspace size for the given
14016
values of N, ILO and IHI. The estimate is returned
14017
in WORK(1). No error message related to LWORK is
14018
issued by XERBLA. Neither H nor Z are accessed.
14019
14020
14021
INFO (output) INTEGER
14022
= 0: successful exit
14023
.GT. 0: if INFO = i, ZLAQR0 failed to compute all of
14024
the eigenvalues. Elements 1:ilo-1 and i+1:n of WR
14025
and WI contain those eigenvalues which have been
14026
successfully computed. (Failures are rare.)
14027
14028
If INFO .GT. 0 and WANT is .FALSE., then on exit,
14029
the remaining unconverged eigenvalues are the eigen-
14030
values of the upper Hessenberg matrix rows and
14031
columns ILO through INFO of the final, output
14032
value of H.
14033
14034
If INFO .GT. 0 and WANTT is .TRUE., then on exit
14035
14036
(*) (initial value of H)*U = U*(final value of H)
14037
14038
where U is a unitary matrix. The final
14039
value of H is upper Hessenberg and triangular in
14040
rows and columns INFO+1 through IHI.
14041
14042
If INFO .GT. 0 and WANTZ is .TRUE., then on exit
14043
14044
(final value of Z(ILO:IHI,ILOZ:IHIZ)
14045
= (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
14046
14047
where U is the unitary matrix in (*) (regard-
14048
less of the value of WANTT.)
14049
14050
If INFO .GT. 0 and WANTZ is .FALSE., then Z is not
14051
accessed.
14052
14053
================================================================
14054
Based on contributions by
14055
Karen Braman and Ralph Byers, Department of Mathematics,
14056
University of Kansas, USA
14057
14058
================================================================
14059
References:
14060
K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
14061
Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
14062
Performance, SIAM Journal of Matrix Analysis, volume 23, pages
14063
929--947, 2002.
14064
14065
K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
14066
Algorithm Part II: Aggressive Early Deflation, SIAM Journal
14067
of Matrix Analysis, volume 23, pages 948--973, 2002.
14068
14069
================================================================
14070
14071
==== Matrices of order NTINY or smaller must be processed by
14072
. ZLAHQR because of insufficient subdiagonal scratch space.
14073
. (This is a hard limit.) ====
14074
14075
==== Exceptional deflation windows: try to cure rare
14076
. slow convergence by varying the size of the
14077
. deflation window after KEXNW iterations. ====
14078
14079
==== Exceptional shifts: try to cure rare slow convergence
14080
. with ad-hoc exceptional shifts every KEXSH iterations.
14081
. ====
14082
14083
==== The constant WILK1 is used to form the exceptional
14084
. shifts. ====
14085
*/
14086
/* Parameter adjustments */
14087
h_dim1 = *ldh;
14088
h_offset = 1 + h_dim1;
14089
h__ -= h_offset;
14090
--w;
14091
z_dim1 = *ldz;
14092
z_offset = 1 + z_dim1;
14093
z__ -= z_offset;
14094
--work;
14095
14096
/* Function Body */
14097
*info = 0;
14098
14099
/* ==== Quick return for N = 0: nothing to do. ==== */
14100
14101
if (*n == 0) {
14102
work[1].r = 1., work[1].i = 0.;
14103
return 0;
14104
}
14105
14106
if (*n <= 11) {
14107
14108
/* ==== Tiny matrices must use ZLAHQR. ==== */
14109
14110
lwkopt = 1;
14111
if (*lwork != -1) {
14112
zlahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1],
14113
iloz, ihiz, &z__[z_offset], ldz, info);
14114
}
14115
} else {
14116
14117
/*
14118
==== Use small bulge multi-shift QR with aggressive early
14119
. deflation on larger-than-tiny matrices. ====
14120
14121
==== Hope for the best. ====
14122
*/
14123
14124
*info = 0;
14125
14126
/* ==== Set up job flags for ILAENV. ==== */
14127
14128
if (*wantt) {
14129
*(unsigned char *)jbcmpz = 'S';
14130
} else {
14131
*(unsigned char *)jbcmpz = 'E';
14132
}
14133
if (*wantz) {
14134
*(unsigned char *)&jbcmpz[1] = 'V';
14135
} else {
14136
*(unsigned char *)&jbcmpz[1] = 'N';
14137
}
14138
14139
/*
14140
==== NWR = recommended deflation window size. At this
14141
. point, N .GT. NTINY = 11, so there is enough
14142
. subdiagonal workspace for NWR.GE.2 as required.
14143
. (In fact, there is enough subdiagonal space for
14144
. NWR.GE.3.) ====
14145
*/
14146
14147
nwr = ilaenv_(&c__13, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
14148
(ftnlen)2);
14149
nwr = max(2,nwr);
14150
/* Computing MIN */
14151
i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = min(i__1,i__2);
14152
nwr = min(i__1,nwr);
14153
14154
/*
14155
==== NSR = recommended number of simultaneous shifts.
14156
. At this point N .GT. NTINY = 11, so there is at
14157
. enough subdiagonal workspace for NSR to be even
14158
. and greater than or equal to two as required. ====
14159
*/
14160
14161
nsr = ilaenv_(&c__15, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
14162
(ftnlen)2);
14163
/* Computing MIN */
14164
i__1 = nsr, i__2 = (*n + 6) / 9, i__1 = min(i__1,i__2), i__2 = *ihi -
14165
*ilo;
14166
nsr = min(i__1,i__2);
14167
/* Computing MAX */
14168
i__1 = 2, i__2 = nsr - nsr % 2;
14169
nsr = max(i__1,i__2);
14170
14171
/*
14172
==== Estimate optimal workspace ====
14173
14174
==== Workspace query call to ZLAQR3 ====
14175
*/
14176
14177
i__1 = nwr + 1;
14178
zlaqr3_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
14179
ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[h_offset],
14180
ldh, n, &h__[h_offset], ldh, n, &h__[h_offset], ldh, &work[1],
14181
&c_n1);
14182
14183
/*
14184
==== Optimal workspace = MAX(ZLAQR5, ZLAQR3) ====
14185
14186
Computing MAX
14187
*/
14188
i__1 = nsr * 3 / 2, i__2 = (integer) work[1].r;
14189
lwkopt = max(i__1,i__2);
14190
14191
/* ==== Quick return in case of workspace query. ==== */
14192
14193
if (*lwork == -1) {
14194
d__1 = (doublereal) lwkopt;
14195
z__1.r = d__1, z__1.i = 0.;
14196
work[1].r = z__1.r, work[1].i = z__1.i;
14197
return 0;
14198
}
14199
14200
/* ==== ZLAHQR/ZLAQR0 crossover point ==== */
14201
14202
nmin = ilaenv_(&c__12, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork, (ftnlen)
14203
6, (ftnlen)2);
14204
nmin = max(11,nmin);
14205
14206
/* ==== Nibble crossover point ==== */
14207
14208
nibble = ilaenv_(&c__14, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork, (
14209
ftnlen)6, (ftnlen)2);
14210
nibble = max(0,nibble);
14211
14212
/*
14213
==== Accumulate reflections during ttswp? Use block
14214
. 2-by-2 structure during matrix-matrix multiply? ====
14215
*/
14216
14217
kacc22 = ilaenv_(&c__16, "ZLAQR0", jbcmpz, n, ilo, ihi, lwork, (
14218
ftnlen)6, (ftnlen)2);
14219
kacc22 = max(0,kacc22);
14220
kacc22 = min(2,kacc22);
14221
14222
/*
14223
==== NWMAX = the largest possible deflation window for
14224
. which there is sufficient workspace. ====
14225
14226
Computing MIN
14227
*/
14228
i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
14229
nwmax = min(i__1,i__2);
14230
nw = nwmax;
14231
14232
/*
14233
==== NSMAX = the Largest number of simultaneous shifts
14234
. for which there is sufficient workspace. ====
14235
14236
Computing MIN
14237
*/
14238
i__1 = (*n + 6) / 9, i__2 = (*lwork << 1) / 3;
14239
nsmax = min(i__1,i__2);
14240
nsmax -= nsmax % 2;
14241
14242
/* ==== NDFL: an iteration count restarted at deflation. ==== */
14243
14244
ndfl = 1;
14245
14246
/*
14247
==== ITMAX = iteration limit ====
14248
14249
Computing MAX
14250
*/
14251
i__1 = 10, i__2 = *ihi - *ilo + 1;
14252
itmax = max(i__1,i__2) * 30;
14253
14254
/* ==== Last row and column in the active block ==== */
14255
14256
kbot = *ihi;
14257
14258
/* ==== Main Loop ==== */
14259
14260
i__1 = itmax;
14261
for (it = 1; it <= i__1; ++it) {
14262
14263
/* ==== Done when KBOT falls below ILO ==== */
14264
14265
if (kbot < *ilo) {
14266
goto L80;
14267
}
14268
14269
/* ==== Locate active block ==== */
14270
14271
i__2 = *ilo + 1;
14272
for (k = kbot; k >= i__2; --k) {
14273
i__3 = k + (k - 1) * h_dim1;
14274
if (h__[i__3].r == 0. && h__[i__3].i == 0.) {
14275
goto L20;
14276
}
14277
/* L10: */
14278
}
14279
k = *ilo;
14280
L20:
14281
ktop = k;
14282
14283
/*
14284
==== Select deflation window size:
14285
. Typical Case:
14286
. If possible and advisable, nibble the entire
14287
. active block. If not, use size MIN(NWR,NWMAX)
14288
. or MIN(NWR+1,NWMAX) depending upon which has
14289
. the smaller corresponding subdiagonal entry
14290
. (a heuristic).
14291
.
14292
. Exceptional Case:
14293
. If there have been no deflations in KEXNW or
14294
. more iterations, then vary the deflation window
14295
. size. At first, because, larger windows are,
14296
. in general, more powerful than smaller ones,
14297
. rapidly increase the window to the maximum possible.
14298
. Then, gradually reduce the window size. ====
14299
*/
14300
14301
nh = kbot - ktop + 1;
14302
nwupbd = min(nh,nwmax);
14303
if (ndfl < 5) {
14304
nw = min(nwupbd,nwr);
14305
} else {
14306
/* Computing MIN */
14307
i__2 = nwupbd, i__3 = nw << 1;
14308
nw = min(i__2,i__3);
14309
}
14310
if (nw < nwmax) {
14311
if (nw >= nh - 1) {
14312
nw = nh;
14313
} else {
14314
kwtop = kbot - nw + 1;
14315
i__2 = kwtop + (kwtop - 1) * h_dim1;
14316
i__3 = kwtop - 1 + (kwtop - 2) * h_dim1;
14317
if ((d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[
14318
kwtop + (kwtop - 1) * h_dim1]), abs(d__2)) > (
14319
d__3 = h__[i__3].r, abs(d__3)) + (d__4 = d_imag(&
14320
h__[kwtop - 1 + (kwtop - 2) * h_dim1]), abs(d__4))
14321
) {
14322
++nw;
14323
}
14324
}
14325
}
14326
if (ndfl < 5) {
14327
ndec = -1;
14328
} else if (ndec >= 0 || nw >= nwupbd) {
14329
++ndec;
14330
if (nw - ndec < 2) {
14331
ndec = 0;
14332
}
14333
nw -= ndec;
14334
}
14335
14336
/*
14337
==== Aggressive early deflation:
14338
. split workspace under the subdiagonal into
14339
. - an nw-by-nw work array V in the lower
14340
. left-hand-corner,
14341
. - an NW-by-at-least-NW-but-more-is-better
14342
. (NW-by-NHO) horizontal work array along
14343
. the bottom edge,
14344
. - an at-least-NW-but-more-is-better (NHV-by-NW)
14345
. vertical work array along the left-hand-edge.
14346
. ====
14347
*/
14348
14349
kv = *n - nw + 1;
14350
kt = nw + 1;
14351
nho = *n - nw - 1 - kt + 1;
14352
kwv = nw + 2;
14353
nve = *n - nw - kwv + 1;
14354
14355
/* ==== Aggressive early deflation ==== */
14356
14357
zlaqr3_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
14358
iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[kv
14359
+ h_dim1], ldh, &nho, &h__[kv + kt * h_dim1], ldh, &nve, &
14360
h__[kwv + h_dim1], ldh, &work[1], lwork);
14361
14362
/* ==== Adjust KBOT accounting for new deflations. ==== */
14363
14364
kbot -= ld;
14365
14366
/* ==== KS points to the shifts. ==== */
14367
14368
ks = kbot - ls + 1;
14369
14370
/*
14371
==== Skip an expensive QR sweep if there is a (partly
14372
. heuristic) reason to expect that many eigenvalues
14373
. will deflate without it. Here, the QR sweep is
14374
. skipped if many eigenvalues have just been deflated
14375
. or if the remaining active block is small.
14376
*/
14377
14378
if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > min(
14379
nmin,nwmax)) {
14380
14381
/*
14382
==== NS = nominal number of simultaneous shifts.
14383
. This may be lowered (slightly) if ZLAQR3
14384
. did not provide that many shifts. ====
14385
14386
Computing MIN
14387
Computing MAX
14388
*/
14389
i__4 = 2, i__5 = kbot - ktop;
14390
i__2 = min(nsmax,nsr), i__3 = max(i__4,i__5);
14391
ns = min(i__2,i__3);
14392
ns -= ns % 2;
14393
14394
/*
14395
==== If there have been no deflations
14396
. in a multiple of KEXSH iterations,
14397
. then try exceptional shifts.
14398
. Otherwise use shifts provided by
14399
. ZLAQR3 above or from the eigenvalues
14400
. of a trailing principal submatrix. ====
14401
*/
14402
14403
if (ndfl % 6 == 0) {
14404
ks = kbot - ns + 1;
14405
i__2 = ks + 1;
14406
for (i__ = kbot; i__ >= i__2; i__ += -2) {
14407
i__3 = i__;
14408
i__4 = i__ + i__ * h_dim1;
14409
i__5 = i__ + (i__ - 1) * h_dim1;
14410
d__3 = ((d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
14411
d_imag(&h__[i__ + (i__ - 1) * h_dim1]), abs(
14412
d__2))) * .75;
14413
z__1.r = h__[i__4].r + d__3, z__1.i = h__[i__4].i;
14414
w[i__3].r = z__1.r, w[i__3].i = z__1.i;
14415
i__3 = i__ - 1;
14416
i__4 = i__;
14417
w[i__3].r = w[i__4].r, w[i__3].i = w[i__4].i;
14418
/* L30: */
14419
}
14420
} else {
14421
14422
/*
14423
==== Got NS/2 or fewer shifts? Use ZLAQR4 or
14424
. ZLAHQR on a trailing principal submatrix to
14425
. get more. (Since NS.LE.NSMAX.LE.(N+6)/9,
14426
. there is enough space below the subdiagonal
14427
. to fit an NS-by-NS scratch array.) ====
14428
*/
14429
14430
if (kbot - ks + 1 <= ns / 2) {
14431
ks = kbot - ns + 1;
14432
kt = *n - ns + 1;
14433
zlacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
14434
h__[kt + h_dim1], ldh);
14435
if (ns > nmin) {
14436
zlaqr4_(&c_false, &c_false, &ns, &c__1, &ns, &h__[
14437
kt + h_dim1], ldh, &w[ks], &c__1, &c__1,
14438
zdum, &c__1, &work[1], lwork, &inf);
14439
} else {
14440
zlahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[
14441
kt + h_dim1], ldh, &w[ks], &c__1, &c__1,
14442
zdum, &c__1, &inf);
14443
}
14444
ks += inf;
14445
14446
/*
14447
==== In case of a rare QR failure use
14448
. eigenvalues of the trailing 2-by-2
14449
. principal submatrix. Scale to avoid
14450
. overflows, underflows and subnormals.
14451
. (The scale factor S can not be zero,
14452
. because H(KBOT,KBOT-1) is nonzero.) ====
14453
*/
14454
14455
if (ks >= kbot) {
14456
i__2 = kbot - 1 + (kbot - 1) * h_dim1;
14457
i__3 = kbot + (kbot - 1) * h_dim1;
14458
i__4 = kbot - 1 + kbot * h_dim1;
14459
i__5 = kbot + kbot * h_dim1;
14460
s = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 =
14461
d_imag(&h__[kbot - 1 + (kbot - 1) *
14462
h_dim1]), abs(d__2)) + ((d__3 = h__[i__3]
14463
.r, abs(d__3)) + (d__4 = d_imag(&h__[kbot
14464
+ (kbot - 1) * h_dim1]), abs(d__4))) + ((
14465
d__5 = h__[i__4].r, abs(d__5)) + (d__6 =
14466
d_imag(&h__[kbot - 1 + kbot * h_dim1]),
14467
abs(d__6))) + ((d__7 = h__[i__5].r, abs(
14468
d__7)) + (d__8 = d_imag(&h__[kbot + kbot *
14469
h_dim1]), abs(d__8)));
14470
i__2 = kbot - 1 + (kbot - 1) * h_dim1;
14471
z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
14472
s;
14473
aa.r = z__1.r, aa.i = z__1.i;
14474
i__2 = kbot + (kbot - 1) * h_dim1;
14475
z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
14476
s;
14477
cc.r = z__1.r, cc.i = z__1.i;
14478
i__2 = kbot - 1 + kbot * h_dim1;
14479
z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
14480
s;
14481
bb.r = z__1.r, bb.i = z__1.i;
14482
i__2 = kbot + kbot * h_dim1;
14483
z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
14484
s;
14485
dd.r = z__1.r, dd.i = z__1.i;
14486
z__2.r = aa.r + dd.r, z__2.i = aa.i + dd.i;
14487
z__1.r = z__2.r / 2., z__1.i = z__2.i / 2.;
14488
tr2.r = z__1.r, tr2.i = z__1.i;
14489
z__3.r = aa.r - tr2.r, z__3.i = aa.i - tr2.i;
14490
z__4.r = dd.r - tr2.r, z__4.i = dd.i - tr2.i;
14491
z__2.r = z__3.r * z__4.r - z__3.i * z__4.i,
14492
z__2.i = z__3.r * z__4.i + z__3.i *
14493
z__4.r;
14494
z__5.r = bb.r * cc.r - bb.i * cc.i, z__5.i = bb.r
14495
* cc.i + bb.i * cc.r;
14496
z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
14497
z__5.i;
14498
det.r = z__1.r, det.i = z__1.i;
14499
z__2.r = -det.r, z__2.i = -det.i;
14500
z_sqrt(&z__1, &z__2);
14501
rtdisc.r = z__1.r, rtdisc.i = z__1.i;
14502
i__2 = kbot - 1;
14503
z__2.r = tr2.r + rtdisc.r, z__2.i = tr2.i +
14504
rtdisc.i;
14505
z__1.r = s * z__2.r, z__1.i = s * z__2.i;
14506
w[i__2].r = z__1.r, w[i__2].i = z__1.i;
14507
i__2 = kbot;
14508
z__2.r = tr2.r - rtdisc.r, z__2.i = tr2.i -
14509
rtdisc.i;
14510
z__1.r = s * z__2.r, z__1.i = s * z__2.i;
14511
w[i__2].r = z__1.r, w[i__2].i = z__1.i;
14512
14513
ks = kbot - 1;
14514
}
14515
}
14516
14517
if (kbot - ks + 1 > ns) {
14518
14519
/* ==== Sort the shifts (Helps a little) ==== */
14520
14521
sorted = FALSE_;
14522
i__2 = ks + 1;
14523
for (k = kbot; k >= i__2; --k) {
14524
if (sorted) {
14525
goto L60;
14526
}
14527
sorted = TRUE_;
14528
i__3 = k - 1;
14529
for (i__ = ks; i__ <= i__3; ++i__) {
14530
i__4 = i__;
14531
i__5 = i__ + 1;
14532
if ((d__1 = w[i__4].r, abs(d__1)) + (d__2 =
14533
d_imag(&w[i__]), abs(d__2)) < (d__3 =
14534
w[i__5].r, abs(d__3)) + (d__4 =
14535
d_imag(&w[i__ + 1]), abs(d__4))) {
14536
sorted = FALSE_;
14537
i__4 = i__;
14538
swap.r = w[i__4].r, swap.i = w[i__4].i;
14539
i__4 = i__;
14540
i__5 = i__ + 1;
14541
w[i__4].r = w[i__5].r, w[i__4].i = w[i__5]
14542
.i;
14543
i__4 = i__ + 1;
14544
w[i__4].r = swap.r, w[i__4].i = swap.i;
14545
}
14546
/* L40: */
14547
}
14548
/* L50: */
14549
}
14550
L60:
14551
;
14552
}
14553
}
14554
14555
/*
14556
==== If there are only two shifts, then use
14557
. only one. ====
14558
*/
14559
14560
if (kbot - ks + 1 == 2) {
14561
i__2 = kbot;
14562
i__3 = kbot + kbot * h_dim1;
14563
z__2.r = w[i__2].r - h__[i__3].r, z__2.i = w[i__2].i -
14564
h__[i__3].i;
14565
z__1.r = z__2.r, z__1.i = z__2.i;
14566
i__4 = kbot - 1;
14567
i__5 = kbot + kbot * h_dim1;
14568
z__4.r = w[i__4].r - h__[i__5].r, z__4.i = w[i__4].i -
14569
h__[i__5].i;
14570
z__3.r = z__4.r, z__3.i = z__4.i;
14571
if ((d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1),
14572
abs(d__2)) < (d__3 = z__3.r, abs(d__3)) + (d__4 =
14573
d_imag(&z__3), abs(d__4))) {
14574
i__2 = kbot - 1;
14575
i__3 = kbot;
14576
w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
14577
} else {
14578
i__2 = kbot;
14579
i__3 = kbot - 1;
14580
w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
14581
}
14582
}
14583
14584
/*
14585
==== Use up to NS of the smallest magnatiude
14586
. shifts. If there aren't NS shifts available,
14587
. then use them all, possibly dropping one to
14588
. make the number of shifts even. ====
14589
14590
Computing MIN
14591
*/
14592
i__2 = ns, i__3 = kbot - ks + 1;
14593
ns = min(i__2,i__3);
14594
ns -= ns % 2;
14595
ks = kbot - ns + 1;
14596
14597
/*
14598
==== Small-bulge multi-shift QR sweep:
14599
. split workspace under the subdiagonal into
14600
. - a KDU-by-KDU work array U in the lower
14601
. left-hand-corner,
14602
. - a KDU-by-at-least-KDU-but-more-is-better
14603
. (KDU-by-NHo) horizontal work array WH along
14604
. the bottom edge,
14605
. - and an at-least-KDU-but-more-is-better-by-KDU
14606
. (NVE-by-KDU) vertical work WV arrow along
14607
. the left-hand-edge. ====
14608
*/
14609
14610
kdu = ns * 3 - 3;
14611
ku = *n - kdu + 1;
14612
kwh = kdu + 1;
14613
nho = *n - kdu - 3 - (kdu + 1) + 1;
14614
kwv = kdu + 4;
14615
nve = *n - kdu - kwv + 1;
14616
14617
/* ==== Small-bulge multi-shift QR sweep ==== */
14618
14619
zlaqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &w[ks], &
14620
h__[h_offset], ldh, iloz, ihiz, &z__[z_offset], ldz, &
14621
work[1], &c__3, &h__[ku + h_dim1], ldh, &nve, &h__[
14622
kwv + h_dim1], ldh, &nho, &h__[ku + kwh * h_dim1],
14623
ldh);
14624
}
14625
14626
/* ==== Note progress (or the lack of it). ==== */
14627
14628
if (ld > 0) {
14629
ndfl = 1;
14630
} else {
14631
++ndfl;
14632
}
14633
14634
/*
14635
==== End of main loop ====
14636
L70:
14637
*/
14638
}
14639
14640
/*
14641
==== Iteration limit exceeded. Set INFO to show where
14642
. the problem occurred and exit. ====
14643
*/
14644
14645
*info = kbot;
14646
L80:
14647
;
14648
}
14649
14650
/* ==== Return the optimal value of LWORK. ==== */
14651
14652
d__1 = (doublereal) lwkopt;
14653
z__1.r = d__1, z__1.i = 0.;
14654
work[1].r = z__1.r, work[1].i = z__1.i;
14655
14656
/* ==== End of ZLAQR0 ==== */
14657
14658
return 0;
14659
} /* zlaqr0_ */
14660
14661
/* Subroutine */ int zlaqr1_(integer *n, doublecomplex *h__, integer *ldh,
14662
doublecomplex *s1, doublecomplex *s2, doublecomplex *v)
14663
{
14664
/* System generated locals */
14665
integer h_dim1, h_offset, i__1, i__2, i__3, i__4;
14666
doublereal d__1, d__2, d__3, d__4, d__5, d__6;
14667
doublecomplex z__1, z__2, z__3, z__4, z__5, z__6, z__7, z__8;
14668
14669
/* Local variables */
14670
static doublereal s;
14671
static doublecomplex h21s, h31s;
14672
14673
14674
/*
14675
-- LAPACK auxiliary routine (version 3.2) --
14676
Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
14677
November 2006
14678
14679
14680
Given a 2-by-2 or 3-by-3 matrix H, ZLAQR1 sets v to a
14681
scalar multiple of the first column of the product
14682
14683
(*) K = (H - s1*I)*(H - s2*I)
14684
14685
scaling to avoid overflows and most underflows.
14686
14687
This is useful for starting double implicit shift bulges
14688
in the QR algorithm.
14689
14690
14691
N (input) integer
14692
Order of the matrix H. N must be either 2 or 3.
14693
14694
H (input) COMPLEX*16 array of dimension (LDH,N)
14695
The 2-by-2 or 3-by-3 matrix H in (*).
14696
14697
LDH (input) integer
14698
The leading dimension of H as declared in
14699
the calling procedure. LDH.GE.N
14700
14701
S1 (input) COMPLEX*16
14702
S2 S1 and S2 are the shifts defining K in (*) above.
14703
14704
V (output) COMPLEX*16 array of dimension N
14705
A scalar multiple of the first column of the
14706
matrix K in (*).
14707
14708
================================================================
14709
Based on contributions by
14710
Karen Braman and Ralph Byers, Department of Mathematics,
14711
University of Kansas, USA
14712
14713
================================================================
14714
*/
14715
14716
/* Parameter adjustments */
14717
h_dim1 = *ldh;
14718
h_offset = 1 + h_dim1;
14719
h__ -= h_offset;
14720
--v;
14721
14722
/* Function Body */
14723
if (*n == 2) {
14724
i__1 = h_dim1 + 1;
14725
z__2.r = h__[i__1].r - s2->r, z__2.i = h__[i__1].i - s2->i;
14726
z__1.r = z__2.r, z__1.i = z__2.i;
14727
i__2 = h_dim1 + 2;
14728
s = (d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1), abs(d__2)) + (
14729
(d__3 = h__[i__2].r, abs(d__3)) + (d__4 = d_imag(&h__[h_dim1
14730
+ 2]), abs(d__4)));
14731
if (s == 0.) {
14732
v[1].r = 0., v[1].i = 0.;
14733
v[2].r = 0., v[2].i = 0.;
14734
} else {
14735
i__1 = h_dim1 + 2;
14736
z__1.r = h__[i__1].r / s, z__1.i = h__[i__1].i / s;
14737
h21s.r = z__1.r, h21s.i = z__1.i;
14738
i__1 = (h_dim1 << 1) + 1;
14739
z__2.r = h21s.r * h__[i__1].r - h21s.i * h__[i__1].i, z__2.i =
14740
h21s.r * h__[i__1].i + h21s.i * h__[i__1].r;
14741
i__2 = h_dim1 + 1;
14742
z__4.r = h__[i__2].r - s1->r, z__4.i = h__[i__2].i - s1->i;
14743
i__3 = h_dim1 + 1;
14744
z__6.r = h__[i__3].r - s2->r, z__6.i = h__[i__3].i - s2->i;
14745
z__5.r = z__6.r / s, z__5.i = z__6.i / s;
14746
z__3.r = z__4.r * z__5.r - z__4.i * z__5.i, z__3.i = z__4.r *
14747
z__5.i + z__4.i * z__5.r;
14748
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
14749
v[1].r = z__1.r, v[1].i = z__1.i;
14750
i__1 = h_dim1 + 1;
14751
i__2 = (h_dim1 << 1) + 2;
14752
z__4.r = h__[i__1].r + h__[i__2].r, z__4.i = h__[i__1].i + h__[
14753
i__2].i;
14754
z__3.r = z__4.r - s1->r, z__3.i = z__4.i - s1->i;
14755
z__2.r = z__3.r - s2->r, z__2.i = z__3.i - s2->i;
14756
z__1.r = h21s.r * z__2.r - h21s.i * z__2.i, z__1.i = h21s.r *
14757
z__2.i + h21s.i * z__2.r;
14758
v[2].r = z__1.r, v[2].i = z__1.i;
14759
}
14760
} else {
14761
i__1 = h_dim1 + 1;
14762
z__2.r = h__[i__1].r - s2->r, z__2.i = h__[i__1].i - s2->i;
14763
z__1.r = z__2.r, z__1.i = z__2.i;
14764
i__2 = h_dim1 + 2;
14765
i__3 = h_dim1 + 3;
14766
s = (d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1), abs(d__2)) + (
14767
(d__3 = h__[i__2].r, abs(d__3)) + (d__4 = d_imag(&h__[h_dim1
14768
+ 2]), abs(d__4))) + ((d__5 = h__[i__3].r, abs(d__5)) + (d__6
14769
= d_imag(&h__[h_dim1 + 3]), abs(d__6)));
14770
if (s == 0.) {
14771
v[1].r = 0., v[1].i = 0.;
14772
v[2].r = 0., v[2].i = 0.;
14773
v[3].r = 0., v[3].i = 0.;
14774
} else {
14775
i__1 = h_dim1 + 2;
14776
z__1.r = h__[i__1].r / s, z__1.i = h__[i__1].i / s;
14777
h21s.r = z__1.r, h21s.i = z__1.i;
14778
i__1 = h_dim1 + 3;
14779
z__1.r = h__[i__1].r / s, z__1.i = h__[i__1].i / s;
14780
h31s.r = z__1.r, h31s.i = z__1.i;
14781
i__1 = h_dim1 + 1;
14782
z__4.r = h__[i__1].r - s1->r, z__4.i = h__[i__1].i - s1->i;
14783
i__2 = h_dim1 + 1;
14784
z__6.r = h__[i__2].r - s2->r, z__6.i = h__[i__2].i - s2->i;
14785
z__5.r = z__6.r / s, z__5.i = z__6.i / s;
14786
z__3.r = z__4.r * z__5.r - z__4.i * z__5.i, z__3.i = z__4.r *
14787
z__5.i + z__4.i * z__5.r;
14788
i__3 = (h_dim1 << 1) + 1;
14789
z__7.r = h__[i__3].r * h21s.r - h__[i__3].i * h21s.i, z__7.i =
14790
h__[i__3].r * h21s.i + h__[i__3].i * h21s.r;
14791
z__2.r = z__3.r + z__7.r, z__2.i = z__3.i + z__7.i;
14792
i__4 = h_dim1 * 3 + 1;
14793
z__8.r = h__[i__4].r * h31s.r - h__[i__4].i * h31s.i, z__8.i =
14794
h__[i__4].r * h31s.i + h__[i__4].i * h31s.r;
14795
z__1.r = z__2.r + z__8.r, z__1.i = z__2.i + z__8.i;
14796
v[1].r = z__1.r, v[1].i = z__1.i;
14797
i__1 = h_dim1 + 1;
14798
i__2 = (h_dim1 << 1) + 2;
14799
z__5.r = h__[i__1].r + h__[i__2].r, z__5.i = h__[i__1].i + h__[
14800
i__2].i;
14801
z__4.r = z__5.r - s1->r, z__4.i = z__5.i - s1->i;
14802
z__3.r = z__4.r - s2->r, z__3.i = z__4.i - s2->i;
14803
z__2.r = h21s.r * z__3.r - h21s.i * z__3.i, z__2.i = h21s.r *
14804
z__3.i + h21s.i * z__3.r;
14805
i__3 = h_dim1 * 3 + 2;
14806
z__6.r = h__[i__3].r * h31s.r - h__[i__3].i * h31s.i, z__6.i =
14807
h__[i__3].r * h31s.i + h__[i__3].i * h31s.r;
14808
z__1.r = z__2.r + z__6.r, z__1.i = z__2.i + z__6.i;
14809
v[2].r = z__1.r, v[2].i = z__1.i;
14810
i__1 = h_dim1 + 1;
14811
i__2 = h_dim1 * 3 + 3;
14812
z__5.r = h__[i__1].r + h__[i__2].r, z__5.i = h__[i__1].i + h__[
14813
i__2].i;
14814
z__4.r = z__5.r - s1->r, z__4.i = z__5.i - s1->i;
14815
z__3.r = z__4.r - s2->r, z__3.i = z__4.i - s2->i;
14816
z__2.r = h31s.r * z__3.r - h31s.i * z__3.i, z__2.i = h31s.r *
14817
z__3.i + h31s.i * z__3.r;
14818
i__3 = (h_dim1 << 1) + 3;
14819
z__6.r = h21s.r * h__[i__3].r - h21s.i * h__[i__3].i, z__6.i =
14820
h21s.r * h__[i__3].i + h21s.i * h__[i__3].r;
14821
z__1.r = z__2.r + z__6.r, z__1.i = z__2.i + z__6.i;
14822
v[3].r = z__1.r, v[3].i = z__1.i;
14823
}
14824
}
14825
return 0;
14826
} /* zlaqr1_ */
14827
14828
/* Subroutine */ int zlaqr2_(logical *wantt, logical *wantz, integer *n,
14829
integer *ktop, integer *kbot, integer *nw, doublecomplex *h__,
14830
integer *ldh, integer *iloz, integer *ihiz, doublecomplex *z__,
14831
integer *ldz, integer *ns, integer *nd, doublecomplex *sh,
14832
doublecomplex *v, integer *ldv, integer *nh, doublecomplex *t,
14833
integer *ldt, integer *nv, doublecomplex *wv, integer *ldwv,
14834
doublecomplex *work, integer *lwork)
14835
{
14836
/* System generated locals */
14837
integer h_dim1, h_offset, t_dim1, t_offset, v_dim1, v_offset, wv_dim1,
14838
wv_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4;
14839
doublereal d__1, d__2, d__3, d__4, d__5, d__6;
14840
doublecomplex z__1, z__2;
14841
14842
/* Local variables */
14843
static integer i__, j;
14844
static doublecomplex s;
14845
static integer jw;
14846
static doublereal foo;
14847
static integer kln;
14848
static doublecomplex tau;
14849
static integer knt;
14850
static doublereal ulp;
14851
static integer lwk1, lwk2;
14852
static doublecomplex beta;
14853
static integer kcol, info, ifst, ilst, ltop, krow;
14854
extern /* Subroutine */ int zlarf_(char *, integer *, integer *,
14855
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
14856
integer *, doublecomplex *);
14857
static integer infqr;
14858
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
14859
integer *, doublecomplex *, doublecomplex *, integer *,
14860
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
14861
integer *);
14862
static integer kwtop;
14863
extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
14864
doublecomplex *, integer *), dlabad_(doublereal *, doublereal *);
14865
14866
static doublereal safmin, safmax;
14867
extern /* Subroutine */ int zgehrd_(integer *, integer *, integer *,
14868
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
14869
integer *, integer *), zlarfg_(integer *, doublecomplex *,
14870
doublecomplex *, integer *, doublecomplex *), zlahqr_(logical *,
14871
logical *, integer *, integer *, integer *, doublecomplex *,
14872
integer *, doublecomplex *, integer *, integer *, doublecomplex *,
14873
integer *, integer *), zlacpy_(char *, integer *, integer *,
14874
doublecomplex *, integer *, doublecomplex *, integer *),
14875
zlaset_(char *, integer *, integer *, doublecomplex *,
14876
doublecomplex *, doublecomplex *, integer *);
14877
static doublereal smlnum;
14878
extern /* Subroutine */ int ztrexc_(char *, integer *, doublecomplex *,
14879
integer *, doublecomplex *, integer *, integer *, integer *,
14880
integer *);
14881
static integer lwkopt;
14882
extern /* Subroutine */ int zunmhr_(char *, char *, integer *, integer *,
14883
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
14884
doublecomplex *, integer *, doublecomplex *, integer *, integer *
14885
);
14886
14887
14888
/*
14889
-- LAPACK auxiliary routine (version 3.2.1) --
14890
Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
14891
-- April 2009 --
14892
14893
14894
This subroutine is identical to ZLAQR3 except that it avoids
14895
recursion by calling ZLAHQR instead of ZLAQR4.
14896
14897
14898
******************************************************************
14899
Aggressive early deflation:
14900
14901
This subroutine accepts as input an upper Hessenberg matrix
14902
H and performs an unitary similarity transformation
14903
designed to detect and deflate fully converged eigenvalues from
14904
a trailing principal submatrix. On output H has been over-
14905
written by a new Hessenberg matrix that is a perturbation of
14906
an unitary similarity transformation of H. It is to be
14907
hoped that the final version of H has many zero subdiagonal
14908
entries.
14909
14910
******************************************************************
14911
WANTT (input) LOGICAL
14912
If .TRUE., then the Hessenberg matrix H is fully updated
14913
so that the triangular Schur factor may be
14914
computed (in cooperation with the calling subroutine).
14915
If .FALSE., then only enough of H is updated to preserve
14916
the eigenvalues.
14917
14918
WANTZ (input) LOGICAL
14919
If .TRUE., then the unitary matrix Z is updated so
14920
so that the unitary Schur factor may be computed
14921
(in cooperation with the calling subroutine).
14922
If .FALSE., then Z is not referenced.
14923
14924
N (input) INTEGER
14925
The order of the matrix H and (if WANTZ is .TRUE.) the
14926
order of the unitary matrix Z.
14927
14928
KTOP (input) INTEGER
14929
It is assumed that either KTOP = 1 or H(KTOP,KTOP-1)=0.
14930
KBOT and KTOP together determine an isolated block
14931
along the diagonal of the Hessenberg matrix.
14932
14933
KBOT (input) INTEGER
14934
It is assumed without a check that either
14935
KBOT = N or H(KBOT+1,KBOT)=0. KBOT and KTOP together
14936
determine an isolated block along the diagonal of the
14937
Hessenberg matrix.
14938
14939
NW (input) INTEGER
14940
Deflation window size. 1 .LE. NW .LE. (KBOT-KTOP+1).
14941
14942
H (input/output) COMPLEX*16 array, dimension (LDH,N)
14943
On input the initial N-by-N section of H stores the
14944
Hessenberg matrix undergoing aggressive early deflation.
14945
On output H has been transformed by a unitary
14946
similarity transformation, perturbed, and the returned
14947
to Hessenberg form that (it is to be hoped) has some
14948
zero subdiagonal entries.
14949
14950
LDH (input) integer
14951
Leading dimension of H just as declared in the calling
14952
subroutine. N .LE. LDH
14953
14954
ILOZ (input) INTEGER
14955
IHIZ (input) INTEGER
14956
Specify the rows of Z to which transformations must be
14957
applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N.
14958
14959
Z (input/output) COMPLEX*16 array, dimension (LDZ,N)
14960
IF WANTZ is .TRUE., then on output, the unitary
14961
similarity transformation mentioned above has been
14962
accumulated into Z(ILOZ:IHIZ,ILO:IHI) from the right.
14963
If WANTZ is .FALSE., then Z is unreferenced.
14964
14965
LDZ (input) integer
14966
The leading dimension of Z just as declared in the
14967
calling subroutine. 1 .LE. LDZ.
14968
14969
NS (output) integer
14970
The number of unconverged (ie approximate) eigenvalues
14971
returned in SR and SI that may be used as shifts by the
14972
calling subroutine.
14973
14974
ND (output) integer
14975
The number of converged eigenvalues uncovered by this
14976
subroutine.
14977
14978
SH (output) COMPLEX*16 array, dimension KBOT
14979
On output, approximate eigenvalues that may
14980
be used for shifts are stored in SH(KBOT-ND-NS+1)
14981
through SR(KBOT-ND). Converged eigenvalues are
14982
stored in SH(KBOT-ND+1) through SH(KBOT).
14983
14984
V (workspace) COMPLEX*16 array, dimension (LDV,NW)
14985
An NW-by-NW work array.
14986
14987
LDV (input) integer scalar
14988
The leading dimension of V just as declared in the
14989
calling subroutine. NW .LE. LDV
14990
14991
NH (input) integer scalar
14992
The number of columns of T. NH.GE.NW.
14993
14994
T (workspace) COMPLEX*16 array, dimension (LDT,NW)
14995
14996
LDT (input) integer
14997
The leading dimension of T just as declared in the
14998
calling subroutine. NW .LE. LDT
14999
15000
NV (input) integer
15001
The number of rows of work array WV available for
15002
workspace. NV.GE.NW.
15003
15004
WV (workspace) COMPLEX*16 array, dimension (LDWV,NW)
15005
15006
LDWV (input) integer
15007
The leading dimension of W just as declared in the
15008
calling subroutine. NW .LE. LDV
15009
15010
WORK (workspace) COMPLEX*16 array, dimension LWORK.
15011
On exit, WORK(1) is set to an estimate of the optimal value
15012
of LWORK for the given values of N, NW, KTOP and KBOT.
15013
15014
LWORK (input) integer
15015
The dimension of the work array WORK. LWORK = 2*NW
15016
suffices, but greater efficiency may result from larger
15017
values of LWORK.
15018
15019
If LWORK = -1, then a workspace query is assumed; ZLAQR2
15020
only estimates the optimal workspace size for the given
15021
values of N, NW, KTOP and KBOT. The estimate is returned
15022
in WORK(1). No error message related to LWORK is issued
15023
by XERBLA. Neither H nor Z are accessed.
15024
15025
================================================================
15026
Based on contributions by
15027
Karen Braman and Ralph Byers, Department of Mathematics,
15028
University of Kansas, USA
15029
15030
================================================================
15031
15032
==== Estimate optimal workspace. ====
15033
*/
15034
15035
/* Parameter adjustments */
15036
h_dim1 = *ldh;
15037
h_offset = 1 + h_dim1;
15038
h__ -= h_offset;
15039
z_dim1 = *ldz;
15040
z_offset = 1 + z_dim1;
15041
z__ -= z_offset;
15042
--sh;
15043
v_dim1 = *ldv;
15044
v_offset = 1 + v_dim1;
15045
v -= v_offset;
15046
t_dim1 = *ldt;
15047
t_offset = 1 + t_dim1;
15048
t -= t_offset;
15049
wv_dim1 = *ldwv;
15050
wv_offset = 1 + wv_dim1;
15051
wv -= wv_offset;
15052
--work;
15053
15054
/* Function Body */
15055
/* Computing MIN */
15056
i__1 = *nw, i__2 = *kbot - *ktop + 1;
15057
jw = min(i__1,i__2);
15058
if (jw <= 2) {
15059
lwkopt = 1;
15060
} else {
15061
15062
/* ==== Workspace query call to ZGEHRD ==== */
15063
15064
i__1 = jw - 1;
15065
zgehrd_(&jw, &c__1, &i__1, &t[t_offset], ldt, &work[1], &work[1], &
15066
c_n1, &info);
15067
lwk1 = (integer) work[1].r;
15068
15069
/* ==== Workspace query call to ZUNMHR ==== */
15070
15071
i__1 = jw - 1;
15072
zunmhr_("R", "N", &jw, &jw, &c__1, &i__1, &t[t_offset], ldt, &work[1],
15073
&v[v_offset], ldv, &work[1], &c_n1, &info);
15074
lwk2 = (integer) work[1].r;
15075
15076
/* ==== Optimal workspace ==== */
15077
15078
lwkopt = jw + max(lwk1,lwk2);
15079
}
15080
15081
/* ==== Quick return in case of workspace query. ==== */
15082
15083
if (*lwork == -1) {
15084
d__1 = (doublereal) lwkopt;
15085
z__1.r = d__1, z__1.i = 0.;
15086
work[1].r = z__1.r, work[1].i = z__1.i;
15087
return 0;
15088
}
15089
15090
/*
15091
==== Nothing to do ...
15092
... for an empty active block ... ====
15093
*/
15094
*ns = 0;
15095
*nd = 0;
15096
work[1].r = 1., work[1].i = 0.;
15097
if (*ktop > *kbot) {
15098
return 0;
15099
}
15100
/* ... nor for an empty deflation window. ==== */
15101
if (*nw < 1) {
15102
return 0;
15103
}
15104
15105
/* ==== Machine constants ==== */
15106
15107
safmin = SAFEMINIMUM;
15108
safmax = 1. / safmin;
15109
dlabad_(&safmin, &safmax);
15110
ulp = PRECISION;
15111
smlnum = safmin * ((doublereal) (*n) / ulp);
15112
15113
/*
15114
==== Setup deflation window ====
15115
15116
Computing MIN
15117
*/
15118
i__1 = *nw, i__2 = *kbot - *ktop + 1;
15119
jw = min(i__1,i__2);
15120
kwtop = *kbot - jw + 1;
15121
if (kwtop == *ktop) {
15122
s.r = 0., s.i = 0.;
15123
} else {
15124
i__1 = kwtop + (kwtop - 1) * h_dim1;
15125
s.r = h__[i__1].r, s.i = h__[i__1].i;
15126
}
15127
15128
if (*kbot == kwtop) {
15129
15130
/* ==== 1-by-1 deflation window: not much to do ==== */
15131
15132
i__1 = kwtop;
15133
i__2 = kwtop + kwtop * h_dim1;
15134
sh[i__1].r = h__[i__2].r, sh[i__1].i = h__[i__2].i;
15135
*ns = 1;
15136
*nd = 0;
15137
/* Computing MAX */
15138
i__1 = kwtop + kwtop * h_dim1;
15139
d__5 = smlnum, d__6 = ulp * ((d__1 = h__[i__1].r, abs(d__1)) + (d__2 =
15140
d_imag(&h__[kwtop + kwtop * h_dim1]), abs(d__2)));
15141
if ((d__3 = s.r, abs(d__3)) + (d__4 = d_imag(&s), abs(d__4)) <= max(
15142
d__5,d__6)) {
15143
*ns = 0;
15144
*nd = 1;
15145
if (kwtop > *ktop) {
15146
i__1 = kwtop + (kwtop - 1) * h_dim1;
15147
h__[i__1].r = 0., h__[i__1].i = 0.;
15148
}
15149
}
15150
work[1].r = 1., work[1].i = 0.;
15151
return 0;
15152
}
15153
15154
/*
15155
==== Convert to spike-triangular form. (In case of a
15156
. rare QR failure, this routine continues to do
15157
. aggressive early deflation using that part of
15158
. the deflation window that converged using INFQR
15159
. here and there to keep track.) ====
15160
*/
15161
15162
zlacpy_("U", &jw, &jw, &h__[kwtop + kwtop * h_dim1], ldh, &t[t_offset],
15163
ldt);
15164
i__1 = jw - 1;
15165
i__2 = *ldh + 1;
15166
i__3 = *ldt + 1;
15167
zcopy_(&i__1, &h__[kwtop + 1 + kwtop * h_dim1], &i__2, &t[t_dim1 + 2], &
15168
i__3);
15169
15170
zlaset_("A", &jw, &jw, &c_b56, &c_b57, &v[v_offset], ldv);
15171
zlahqr_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sh[kwtop],
15172
&c__1, &jw, &v[v_offset], ldv, &infqr);
15173
15174
/* ==== Deflation detection loop ==== */
15175
15176
*ns = jw;
15177
ilst = infqr + 1;
15178
i__1 = jw;
15179
for (knt = infqr + 1; knt <= i__1; ++knt) {
15180
15181
/* ==== Small spike tip deflation test ==== */
15182
15183
i__2 = *ns + *ns * t_dim1;
15184
foo = (d__1 = t[i__2].r, abs(d__1)) + (d__2 = d_imag(&t[*ns + *ns *
15185
t_dim1]), abs(d__2));
15186
if (foo == 0.) {
15187
foo = (d__1 = s.r, abs(d__1)) + (d__2 = d_imag(&s), abs(d__2));
15188
}
15189
i__2 = *ns * v_dim1 + 1;
15190
/* Computing MAX */
15191
d__5 = smlnum, d__6 = ulp * foo;
15192
if (((d__1 = s.r, abs(d__1)) + (d__2 = d_imag(&s), abs(d__2))) * ((
15193
d__3 = v[i__2].r, abs(d__3)) + (d__4 = d_imag(&v[*ns * v_dim1
15194
+ 1]), abs(d__4))) <= max(d__5,d__6)) {
15195
15196
/* ==== One more converged eigenvalue ==== */
15197
15198
--(*ns);
15199
} else {
15200
15201
/*
15202
==== One undeflatable eigenvalue. Move it up out of the
15203
. way. (ZTREXC can not fail in this case.) ====
15204
*/
15205
15206
ifst = *ns;
15207
ztrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst, &
15208
ilst, &info);
15209
++ilst;
15210
}
15211
/* L10: */
15212
}
15213
15214
/* ==== Return to Hessenberg form ==== */
15215
15216
if (*ns == 0) {
15217
s.r = 0., s.i = 0.;
15218
}
15219
15220
if (*ns < jw) {
15221
15222
/*
15223
==== sorting the diagonal of T improves accuracy for
15224
. graded matrices. ====
15225
*/
15226
15227
i__1 = *ns;
15228
for (i__ = infqr + 1; i__ <= i__1; ++i__) {
15229
ifst = i__;
15230
i__2 = *ns;
15231
for (j = i__ + 1; j <= i__2; ++j) {
15232
i__3 = j + j * t_dim1;
15233
i__4 = ifst + ifst * t_dim1;
15234
if ((d__1 = t[i__3].r, abs(d__1)) + (d__2 = d_imag(&t[j + j *
15235
t_dim1]), abs(d__2)) > (d__3 = t[i__4].r, abs(d__3))
15236
+ (d__4 = d_imag(&t[ifst + ifst * t_dim1]), abs(d__4))
15237
) {
15238
ifst = j;
15239
}
15240
/* L20: */
15241
}
15242
ilst = i__;
15243
if (ifst != ilst) {
15244
ztrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
15245
&ilst, &info);
15246
}
15247
/* L30: */
15248
}
15249
}
15250
15251
/* ==== Restore shift/eigenvalue array from T ==== */
15252
15253
i__1 = jw;
15254
for (i__ = infqr + 1; i__ <= i__1; ++i__) {
15255
i__2 = kwtop + i__ - 1;
15256
i__3 = i__ + i__ * t_dim1;
15257
sh[i__2].r = t[i__3].r, sh[i__2].i = t[i__3].i;
15258
/* L40: */
15259
}
15260
15261
15262
if (*ns < jw || s.r == 0. && s.i == 0.) {
15263
if (*ns > 1 && (s.r != 0. || s.i != 0.)) {
15264
15265
/* ==== Reflect spike back into lower triangle ==== */
15266
15267
zcopy_(ns, &v[v_offset], ldv, &work[1], &c__1);
15268
i__1 = *ns;
15269
for (i__ = 1; i__ <= i__1; ++i__) {
15270
i__2 = i__;
15271
d_cnjg(&z__1, &work[i__]);
15272
work[i__2].r = z__1.r, work[i__2].i = z__1.i;
15273
/* L50: */
15274
}
15275
beta.r = work[1].r, beta.i = work[1].i;
15276
zlarfg_(ns, &beta, &work[2], &c__1, &tau);
15277
work[1].r = 1., work[1].i = 0.;
15278
15279
i__1 = jw - 2;
15280
i__2 = jw - 2;
15281
zlaset_("L", &i__1, &i__2, &c_b56, &c_b56, &t[t_dim1 + 3], ldt);
15282
15283
d_cnjg(&z__1, &tau);
15284
zlarf_("L", ns, &jw, &work[1], &c__1, &z__1, &t[t_offset], ldt, &
15285
work[jw + 1]);
15286
zlarf_("R", ns, ns, &work[1], &c__1, &tau, &t[t_offset], ldt, &
15287
work[jw + 1]);
15288
zlarf_("R", &jw, ns, &work[1], &c__1, &tau, &v[v_offset], ldv, &
15289
work[jw + 1]);
15290
15291
i__1 = *lwork - jw;
15292
zgehrd_(&jw, &c__1, ns, &t[t_offset], ldt, &work[1], &work[jw + 1]
15293
, &i__1, &info);
15294
}
15295
15296
/* ==== Copy updated reduced window into place ==== */
15297
15298
if (kwtop > 1) {
15299
i__1 = kwtop + (kwtop - 1) * h_dim1;
15300
d_cnjg(&z__2, &v[v_dim1 + 1]);
15301
z__1.r = s.r * z__2.r - s.i * z__2.i, z__1.i = s.r * z__2.i + s.i
15302
* z__2.r;
15303
h__[i__1].r = z__1.r, h__[i__1].i = z__1.i;
15304
}
15305
zlacpy_("U", &jw, &jw, &t[t_offset], ldt, &h__[kwtop + kwtop * h_dim1]
15306
, ldh);
15307
i__1 = jw - 1;
15308
i__2 = *ldt + 1;
15309
i__3 = *ldh + 1;
15310
zcopy_(&i__1, &t[t_dim1 + 2], &i__2, &h__[kwtop + 1 + kwtop * h_dim1],
15311
&i__3);
15312
15313
/*
15314
==== Accumulate orthogonal matrix in order update
15315
. H and Z, if requested. ====
15316
*/
15317
15318
if (*ns > 1 && (s.r != 0. || s.i != 0.)) {
15319
i__1 = *lwork - jw;
15320
zunmhr_("R", "N", &jw, ns, &c__1, ns, &t[t_offset], ldt, &work[1],
15321
&v[v_offset], ldv, &work[jw + 1], &i__1, &info);
15322
}
15323
15324
/* ==== Update vertical slab in H ==== */
15325
15326
if (*wantt) {
15327
ltop = 1;
15328
} else {
15329
ltop = *ktop;
15330
}
15331
i__1 = kwtop - 1;
15332
i__2 = *nv;
15333
for (krow = ltop; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
15334
i__2) {
15335
/* Computing MIN */
15336
i__3 = *nv, i__4 = kwtop - krow;
15337
kln = min(i__3,i__4);
15338
zgemm_("N", "N", &kln, &jw, &jw, &c_b57, &h__[krow + kwtop *
15339
h_dim1], ldh, &v[v_offset], ldv, &c_b56, &wv[wv_offset],
15340
ldwv);
15341
zlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &h__[krow + kwtop *
15342
h_dim1], ldh);
15343
/* L60: */
15344
}
15345
15346
/* ==== Update horizontal slab in H ==== */
15347
15348
if (*wantt) {
15349
i__2 = *n;
15350
i__1 = *nh;
15351
for (kcol = *kbot + 1; i__1 < 0 ? kcol >= i__2 : kcol <= i__2;
15352
kcol += i__1) {
15353
/* Computing MIN */
15354
i__3 = *nh, i__4 = *n - kcol + 1;
15355
kln = min(i__3,i__4);
15356
zgemm_("C", "N", &jw, &kln, &jw, &c_b57, &v[v_offset], ldv, &
15357
h__[kwtop + kcol * h_dim1], ldh, &c_b56, &t[t_offset],
15358
ldt);
15359
zlacpy_("A", &jw, &kln, &t[t_offset], ldt, &h__[kwtop + kcol *
15360
h_dim1], ldh);
15361
/* L70: */
15362
}
15363
}
15364
15365
/* ==== Update vertical slab in Z ==== */
15366
15367
if (*wantz) {
15368
i__1 = *ihiz;
15369
i__2 = *nv;
15370
for (krow = *iloz; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
15371
i__2) {
15372
/* Computing MIN */
15373
i__3 = *nv, i__4 = *ihiz - krow + 1;
15374
kln = min(i__3,i__4);
15375
zgemm_("N", "N", &kln, &jw, &jw, &c_b57, &z__[krow + kwtop *
15376
z_dim1], ldz, &v[v_offset], ldv, &c_b56, &wv[
15377
wv_offset], ldwv);
15378
zlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &z__[krow +
15379
kwtop * z_dim1], ldz);
15380
/* L80: */
15381
}
15382
}
15383
}
15384
15385
/* ==== Return the number of deflations ... ==== */
15386
15387
*nd = jw - *ns;
15388
15389
/*
15390
==== ... and the number of shifts. (Subtracting
15391
. INFQR from the spike length takes care
15392
. of the case of a rare QR failure while
15393
. calculating eigenvalues of the deflation
15394
. window.) ====
15395
*/
15396
15397
*ns -= infqr;
15398
15399
/* ==== Return optimal workspace. ==== */
15400
15401
d__1 = (doublereal) lwkopt;
15402
z__1.r = d__1, z__1.i = 0.;
15403
work[1].r = z__1.r, work[1].i = z__1.i;
15404
15405
/* ==== End of ZLAQR2 ==== */
15406
15407
return 0;
15408
} /* zlaqr2_ */
15409
15410
/* Subroutine */ int zlaqr3_(logical *wantt, logical *wantz, integer *n,
15411
integer *ktop, integer *kbot, integer *nw, doublecomplex *h__,
15412
integer *ldh, integer *iloz, integer *ihiz, doublecomplex *z__,
15413
integer *ldz, integer *ns, integer *nd, doublecomplex *sh,
15414
doublecomplex *v, integer *ldv, integer *nh, doublecomplex *t,
15415
integer *ldt, integer *nv, doublecomplex *wv, integer *ldwv,
15416
doublecomplex *work, integer *lwork)
15417
{
15418
/* System generated locals */
15419
integer h_dim1, h_offset, t_dim1, t_offset, v_dim1, v_offset, wv_dim1,
15420
wv_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4;
15421
doublereal d__1, d__2, d__3, d__4, d__5, d__6;
15422
doublecomplex z__1, z__2;
15423
15424
/* Local variables */
15425
static integer i__, j;
15426
static doublecomplex s;
15427
static integer jw;
15428
static doublereal foo;
15429
static integer kln;
15430
static doublecomplex tau;
15431
static integer knt;
15432
static doublereal ulp;
15433
static integer lwk1, lwk2, lwk3;
15434
static doublecomplex beta;
15435
static integer kcol, info, nmin, ifst, ilst, ltop, krow;
15436
extern /* Subroutine */ int zlarf_(char *, integer *, integer *,
15437
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
15438
integer *, doublecomplex *);
15439
static integer infqr;
15440
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
15441
integer *, doublecomplex *, doublecomplex *, integer *,
15442
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
15443
integer *);
15444
static integer kwtop;
15445
extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
15446
doublecomplex *, integer *), dlabad_(doublereal *, doublereal *),
15447
zlaqr4_(logical *, logical *, integer *, integer *, integer *,
15448
doublecomplex *, integer *, doublecomplex *, integer *, integer *,
15449
doublecomplex *, integer *, doublecomplex *, integer *, integer *
15450
);
15451
15452
static doublereal safmin;
15453
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
15454
integer *, integer *, ftnlen, ftnlen);
15455
static doublereal safmax;
15456
extern /* Subroutine */ int zgehrd_(integer *, integer *, integer *,
15457
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
15458
integer *, integer *), zlarfg_(integer *, doublecomplex *,
15459
doublecomplex *, integer *, doublecomplex *), zlahqr_(logical *,
15460
logical *, integer *, integer *, integer *, doublecomplex *,
15461
integer *, doublecomplex *, integer *, integer *, doublecomplex *,
15462
integer *, integer *), zlacpy_(char *, integer *, integer *,
15463
doublecomplex *, integer *, doublecomplex *, integer *),
15464
zlaset_(char *, integer *, integer *, doublecomplex *,
15465
doublecomplex *, doublecomplex *, integer *);
15466
static doublereal smlnum;
15467
extern /* Subroutine */ int ztrexc_(char *, integer *, doublecomplex *,
15468
integer *, doublecomplex *, integer *, integer *, integer *,
15469
integer *);
15470
static integer lwkopt;
15471
extern /* Subroutine */ int zunmhr_(char *, char *, integer *, integer *,
15472
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
15473
doublecomplex *, integer *, doublecomplex *, integer *, integer *
15474
);
15475
15476
15477
/*
15478
-- LAPACK auxiliary routine (version 3.2.1) --
15479
Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
15480
-- April 2009 --
15481
15482
15483
******************************************************************
15484
Aggressive early deflation:
15485
15486
This subroutine accepts as input an upper Hessenberg matrix
15487
H and performs an unitary similarity transformation
15488
designed to detect and deflate fully converged eigenvalues from
15489
a trailing principal submatrix. On output H has been over-
15490
written by a new Hessenberg matrix that is a perturbation of
15491
an unitary similarity transformation of H. It is to be
15492
hoped that the final version of H has many zero subdiagonal
15493
entries.
15494
15495
******************************************************************
15496
WANTT (input) LOGICAL
15497
If .TRUE., then the Hessenberg matrix H is fully updated
15498
so that the triangular Schur factor may be
15499
computed (in cooperation with the calling subroutine).
15500
If .FALSE., then only enough of H is updated to preserve
15501
the eigenvalues.
15502
15503
WANTZ (input) LOGICAL
15504
If .TRUE., then the unitary matrix Z is updated so
15505
so that the unitary Schur factor may be computed
15506
(in cooperation with the calling subroutine).
15507
If .FALSE., then Z is not referenced.
15508
15509
N (input) INTEGER
15510
The order of the matrix H and (if WANTZ is .TRUE.) the
15511
order of the unitary matrix Z.
15512
15513
KTOP (input) INTEGER
15514
It is assumed that either KTOP = 1 or H(KTOP,KTOP-1)=0.
15515
KBOT and KTOP together determine an isolated block
15516
along the diagonal of the Hessenberg matrix.
15517
15518
KBOT (input) INTEGER
15519
It is assumed without a check that either
15520
KBOT = N or H(KBOT+1,KBOT)=0. KBOT and KTOP together
15521
determine an isolated block along the diagonal of the
15522
Hessenberg matrix.
15523
15524
NW (input) INTEGER
15525
Deflation window size. 1 .LE. NW .LE. (KBOT-KTOP+1).
15526
15527
H (input/output) COMPLEX*16 array, dimension (LDH,N)
15528
On input the initial N-by-N section of H stores the
15529
Hessenberg matrix undergoing aggressive early deflation.
15530
On output H has been transformed by a unitary
15531
similarity transformation, perturbed, and the returned
15532
to Hessenberg form that (it is to be hoped) has some
15533
zero subdiagonal entries.
15534
15535
LDH (input) integer
15536
Leading dimension of H just as declared in the calling
15537
subroutine. N .LE. LDH
15538
15539
ILOZ (input) INTEGER
15540
IHIZ (input) INTEGER
15541
Specify the rows of Z to which transformations must be
15542
applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N.
15543
15544
Z (input/output) COMPLEX*16 array, dimension (LDZ,N)
15545
IF WANTZ is .TRUE., then on output, the unitary
15546
similarity transformation mentioned above has been
15547
accumulated into Z(ILOZ:IHIZ,ILO:IHI) from the right.
15548
If WANTZ is .FALSE., then Z is unreferenced.
15549
15550
LDZ (input) integer
15551
The leading dimension of Z just as declared in the
15552
calling subroutine. 1 .LE. LDZ.
15553
15554
NS (output) integer
15555
The number of unconverged (ie approximate) eigenvalues
15556
returned in SR and SI that may be used as shifts by the
15557
calling subroutine.
15558
15559
ND (output) integer
15560
The number of converged eigenvalues uncovered by this
15561
subroutine.
15562
15563
SH (output) COMPLEX*16 array, dimension KBOT
15564
On output, approximate eigenvalues that may
15565
be used for shifts are stored in SH(KBOT-ND-NS+1)
15566
through SR(KBOT-ND). Converged eigenvalues are
15567
stored in SH(KBOT-ND+1) through SH(KBOT).
15568
15569
V (workspace) COMPLEX*16 array, dimension (LDV,NW)
15570
An NW-by-NW work array.
15571
15572
LDV (input) integer scalar
15573
The leading dimension of V just as declared in the
15574
calling subroutine. NW .LE. LDV
15575
15576
NH (input) integer scalar
15577
The number of columns of T. NH.GE.NW.
15578
15579
T (workspace) COMPLEX*16 array, dimension (LDT,NW)
15580
15581
LDT (input) integer
15582
The leading dimension of T just as declared in the
15583
calling subroutine. NW .LE. LDT
15584
15585
NV (input) integer
15586
The number of rows of work array WV available for
15587
workspace. NV.GE.NW.
15588
15589
WV (workspace) COMPLEX*16 array, dimension (LDWV,NW)
15590
15591
LDWV (input) integer
15592
The leading dimension of W just as declared in the
15593
calling subroutine. NW .LE. LDV
15594
15595
WORK (workspace) COMPLEX*16 array, dimension LWORK.
15596
On exit, WORK(1) is set to an estimate of the optimal value
15597
of LWORK for the given values of N, NW, KTOP and KBOT.
15598
15599
LWORK (input) integer
15600
The dimension of the work array WORK. LWORK = 2*NW
15601
suffices, but greater efficiency may result from larger
15602
values of LWORK.
15603
15604
If LWORK = -1, then a workspace query is assumed; ZLAQR3
15605
only estimates the optimal workspace size for the given
15606
values of N, NW, KTOP and KBOT. The estimate is returned
15607
in WORK(1). No error message related to LWORK is issued
15608
by XERBLA. Neither H nor Z are accessed.
15609
15610
================================================================
15611
Based on contributions by
15612
Karen Braman and Ralph Byers, Department of Mathematics,
15613
University of Kansas, USA
15614
15615
================================================================
15616
15617
==== Estimate optimal workspace. ====
15618
*/
15619
15620
/* Parameter adjustments */
15621
h_dim1 = *ldh;
15622
h_offset = 1 + h_dim1;
15623
h__ -= h_offset;
15624
z_dim1 = *ldz;
15625
z_offset = 1 + z_dim1;
15626
z__ -= z_offset;
15627
--sh;
15628
v_dim1 = *ldv;
15629
v_offset = 1 + v_dim1;
15630
v -= v_offset;
15631
t_dim1 = *ldt;
15632
t_offset = 1 + t_dim1;
15633
t -= t_offset;
15634
wv_dim1 = *ldwv;
15635
wv_offset = 1 + wv_dim1;
15636
wv -= wv_offset;
15637
--work;
15638
15639
/* Function Body */
15640
/* Computing MIN */
15641
i__1 = *nw, i__2 = *kbot - *ktop + 1;
15642
jw = min(i__1,i__2);
15643
if (jw <= 2) {
15644
lwkopt = 1;
15645
} else {
15646
15647
/* ==== Workspace query call to ZGEHRD ==== */
15648
15649
i__1 = jw - 1;
15650
zgehrd_(&jw, &c__1, &i__1, &t[t_offset], ldt, &work[1], &work[1], &
15651
c_n1, &info);
15652
lwk1 = (integer) work[1].r;
15653
15654
/* ==== Workspace query call to ZUNMHR ==== */
15655
15656
i__1 = jw - 1;
15657
zunmhr_("R", "N", &jw, &jw, &c__1, &i__1, &t[t_offset], ldt, &work[1],
15658
&v[v_offset], ldv, &work[1], &c_n1, &info);
15659
lwk2 = (integer) work[1].r;
15660
15661
/* ==== Workspace query call to ZLAQR4 ==== */
15662
15663
zlaqr4_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sh[1],
15664
&c__1, &jw, &v[v_offset], ldv, &work[1], &c_n1, &infqr);
15665
lwk3 = (integer) work[1].r;
15666
15667
/*
15668
==== Optimal workspace ====
15669
15670
Computing MAX
15671
*/
15672
i__1 = jw + max(lwk1,lwk2);
15673
lwkopt = max(i__1,lwk3);
15674
}
15675
15676
/* ==== Quick return in case of workspace query. ==== */
15677
15678
if (*lwork == -1) {
15679
d__1 = (doublereal) lwkopt;
15680
z__1.r = d__1, z__1.i = 0.;
15681
work[1].r = z__1.r, work[1].i = z__1.i;
15682
return 0;
15683
}
15684
15685
/*
15686
==== Nothing to do ...
15687
... for an empty active block ... ====
15688
*/
15689
*ns = 0;
15690
*nd = 0;
15691
work[1].r = 1., work[1].i = 0.;
15692
if (*ktop > *kbot) {
15693
return 0;
15694
}
15695
/* ... nor for an empty deflation window. ==== */
15696
if (*nw < 1) {
15697
return 0;
15698
}
15699
15700
/* ==== Machine constants ==== */
15701
15702
safmin = SAFEMINIMUM;
15703
safmax = 1. / safmin;
15704
dlabad_(&safmin, &safmax);
15705
ulp = PRECISION;
15706
smlnum = safmin * ((doublereal) (*n) / ulp);
15707
15708
/*
15709
==== Setup deflation window ====
15710
15711
Computing MIN
15712
*/
15713
i__1 = *nw, i__2 = *kbot - *ktop + 1;
15714
jw = min(i__1,i__2);
15715
kwtop = *kbot - jw + 1;
15716
if (kwtop == *ktop) {
15717
s.r = 0., s.i = 0.;
15718
} else {
15719
i__1 = kwtop + (kwtop - 1) * h_dim1;
15720
s.r = h__[i__1].r, s.i = h__[i__1].i;
15721
}
15722
15723
if (*kbot == kwtop) {
15724
15725
/* ==== 1-by-1 deflation window: not much to do ==== */
15726
15727
i__1 = kwtop;
15728
i__2 = kwtop + kwtop * h_dim1;
15729
sh[i__1].r = h__[i__2].r, sh[i__1].i = h__[i__2].i;
15730
*ns = 1;
15731
*nd = 0;
15732
/* Computing MAX */
15733
i__1 = kwtop + kwtop * h_dim1;
15734
d__5 = smlnum, d__6 = ulp * ((d__1 = h__[i__1].r, abs(d__1)) + (d__2 =
15735
d_imag(&h__[kwtop + kwtop * h_dim1]), abs(d__2)));
15736
if ((d__3 = s.r, abs(d__3)) + (d__4 = d_imag(&s), abs(d__4)) <= max(
15737
d__5,d__6)) {
15738
*ns = 0;
15739
*nd = 1;
15740
if (kwtop > *ktop) {
15741
i__1 = kwtop + (kwtop - 1) * h_dim1;
15742
h__[i__1].r = 0., h__[i__1].i = 0.;
15743
}
15744
}
15745
work[1].r = 1., work[1].i = 0.;
15746
return 0;
15747
}
15748
15749
/*
15750
==== Convert to spike-triangular form. (In case of a
15751
. rare QR failure, this routine continues to do
15752
. aggressive early deflation using that part of
15753
. the deflation window that converged using INFQR
15754
. here and there to keep track.) ====
15755
*/
15756
15757
zlacpy_("U", &jw, &jw, &h__[kwtop + kwtop * h_dim1], ldh, &t[t_offset],
15758
ldt);
15759
i__1 = jw - 1;
15760
i__2 = *ldh + 1;
15761
i__3 = *ldt + 1;
15762
zcopy_(&i__1, &h__[kwtop + 1 + kwtop * h_dim1], &i__2, &t[t_dim1 + 2], &
15763
i__3);
15764
15765
zlaset_("A", &jw, &jw, &c_b56, &c_b57, &v[v_offset], ldv);
15766
nmin = ilaenv_(&c__12, "ZLAQR3", "SV", &jw, &c__1, &jw, lwork, (ftnlen)6,
15767
(ftnlen)2);
15768
if (jw > nmin) {
15769
zlaqr4_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sh[
15770
kwtop], &c__1, &jw, &v[v_offset], ldv, &work[1], lwork, &
15771
infqr);
15772
} else {
15773
zlahqr_(&c_true, &c_true, &jw, &c__1, &jw, &t[t_offset], ldt, &sh[
15774
kwtop], &c__1, &jw, &v[v_offset], ldv, &infqr);
15775
}
15776
15777
/* ==== Deflation detection loop ==== */
15778
15779
*ns = jw;
15780
ilst = infqr + 1;
15781
i__1 = jw;
15782
for (knt = infqr + 1; knt <= i__1; ++knt) {
15783
15784
/* ==== Small spike tip deflation test ==== */
15785
15786
i__2 = *ns + *ns * t_dim1;
15787
foo = (d__1 = t[i__2].r, abs(d__1)) + (d__2 = d_imag(&t[*ns + *ns *
15788
t_dim1]), abs(d__2));
15789
if (foo == 0.) {
15790
foo = (d__1 = s.r, abs(d__1)) + (d__2 = d_imag(&s), abs(d__2));
15791
}
15792
i__2 = *ns * v_dim1 + 1;
15793
/* Computing MAX */
15794
d__5 = smlnum, d__6 = ulp * foo;
15795
if (((d__1 = s.r, abs(d__1)) + (d__2 = d_imag(&s), abs(d__2))) * ((
15796
d__3 = v[i__2].r, abs(d__3)) + (d__4 = d_imag(&v[*ns * v_dim1
15797
+ 1]), abs(d__4))) <= max(d__5,d__6)) {
15798
15799
/* ==== One more converged eigenvalue ==== */
15800
15801
--(*ns);
15802
} else {
15803
15804
/*
15805
==== One undeflatable eigenvalue. Move it up out of the
15806
. way. (ZTREXC can not fail in this case.) ====
15807
*/
15808
15809
ifst = *ns;
15810
ztrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst, &
15811
ilst, &info);
15812
++ilst;
15813
}
15814
/* L10: */
15815
}
15816
15817
/* ==== Return to Hessenberg form ==== */
15818
15819
if (*ns == 0) {
15820
s.r = 0., s.i = 0.;
15821
}
15822
15823
if (*ns < jw) {
15824
15825
/*
15826
==== sorting the diagonal of T improves accuracy for
15827
. graded matrices. ====
15828
*/
15829
15830
i__1 = *ns;
15831
for (i__ = infqr + 1; i__ <= i__1; ++i__) {
15832
ifst = i__;
15833
i__2 = *ns;
15834
for (j = i__ + 1; j <= i__2; ++j) {
15835
i__3 = j + j * t_dim1;
15836
i__4 = ifst + ifst * t_dim1;
15837
if ((d__1 = t[i__3].r, abs(d__1)) + (d__2 = d_imag(&t[j + j *
15838
t_dim1]), abs(d__2)) > (d__3 = t[i__4].r, abs(d__3))
15839
+ (d__4 = d_imag(&t[ifst + ifst * t_dim1]), abs(d__4))
15840
) {
15841
ifst = j;
15842
}
15843
/* L20: */
15844
}
15845
ilst = i__;
15846
if (ifst != ilst) {
15847
ztrexc_("V", &jw, &t[t_offset], ldt, &v[v_offset], ldv, &ifst,
15848
&ilst, &info);
15849
}
15850
/* L30: */
15851
}
15852
}
15853
15854
/* ==== Restore shift/eigenvalue array from T ==== */
15855
15856
i__1 = jw;
15857
for (i__ = infqr + 1; i__ <= i__1; ++i__) {
15858
i__2 = kwtop + i__ - 1;
15859
i__3 = i__ + i__ * t_dim1;
15860
sh[i__2].r = t[i__3].r, sh[i__2].i = t[i__3].i;
15861
/* L40: */
15862
}
15863
15864
15865
if (*ns < jw || s.r == 0. && s.i == 0.) {
15866
if (*ns > 1 && (s.r != 0. || s.i != 0.)) {
15867
15868
/* ==== Reflect spike back into lower triangle ==== */
15869
15870
zcopy_(ns, &v[v_offset], ldv, &work[1], &c__1);
15871
i__1 = *ns;
15872
for (i__ = 1; i__ <= i__1; ++i__) {
15873
i__2 = i__;
15874
d_cnjg(&z__1, &work[i__]);
15875
work[i__2].r = z__1.r, work[i__2].i = z__1.i;
15876
/* L50: */
15877
}
15878
beta.r = work[1].r, beta.i = work[1].i;
15879
zlarfg_(ns, &beta, &work[2], &c__1, &tau);
15880
work[1].r = 1., work[1].i = 0.;
15881
15882
i__1 = jw - 2;
15883
i__2 = jw - 2;
15884
zlaset_("L", &i__1, &i__2, &c_b56, &c_b56, &t[t_dim1 + 3], ldt);
15885
15886
d_cnjg(&z__1, &tau);
15887
zlarf_("L", ns, &jw, &work[1], &c__1, &z__1, &t[t_offset], ldt, &
15888
work[jw + 1]);
15889
zlarf_("R", ns, ns, &work[1], &c__1, &tau, &t[t_offset], ldt, &
15890
work[jw + 1]);
15891
zlarf_("R", &jw, ns, &work[1], &c__1, &tau, &v[v_offset], ldv, &
15892
work[jw + 1]);
15893
15894
i__1 = *lwork - jw;
15895
zgehrd_(&jw, &c__1, ns, &t[t_offset], ldt, &work[1], &work[jw + 1]
15896
, &i__1, &info);
15897
}
15898
15899
/* ==== Copy updated reduced window into place ==== */
15900
15901
if (kwtop > 1) {
15902
i__1 = kwtop + (kwtop - 1) * h_dim1;
15903
d_cnjg(&z__2, &v[v_dim1 + 1]);
15904
z__1.r = s.r * z__2.r - s.i * z__2.i, z__1.i = s.r * z__2.i + s.i
15905
* z__2.r;
15906
h__[i__1].r = z__1.r, h__[i__1].i = z__1.i;
15907
}
15908
zlacpy_("U", &jw, &jw, &t[t_offset], ldt, &h__[kwtop + kwtop * h_dim1]
15909
, ldh);
15910
i__1 = jw - 1;
15911
i__2 = *ldt + 1;
15912
i__3 = *ldh + 1;
15913
zcopy_(&i__1, &t[t_dim1 + 2], &i__2, &h__[kwtop + 1 + kwtop * h_dim1],
15914
&i__3);
15915
15916
/*
15917
==== Accumulate orthogonal matrix in order update
15918
. H and Z, if requested. ====
15919
*/
15920
15921
if (*ns > 1 && (s.r != 0. || s.i != 0.)) {
15922
i__1 = *lwork - jw;
15923
zunmhr_("R", "N", &jw, ns, &c__1, ns, &t[t_offset], ldt, &work[1],
15924
&v[v_offset], ldv, &work[jw + 1], &i__1, &info);
15925
}
15926
15927
/* ==== Update vertical slab in H ==== */
15928
15929
if (*wantt) {
15930
ltop = 1;
15931
} else {
15932
ltop = *ktop;
15933
}
15934
i__1 = kwtop - 1;
15935
i__2 = *nv;
15936
for (krow = ltop; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
15937
i__2) {
15938
/* Computing MIN */
15939
i__3 = *nv, i__4 = kwtop - krow;
15940
kln = min(i__3,i__4);
15941
zgemm_("N", "N", &kln, &jw, &jw, &c_b57, &h__[krow + kwtop *
15942
h_dim1], ldh, &v[v_offset], ldv, &c_b56, &wv[wv_offset],
15943
ldwv);
15944
zlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &h__[krow + kwtop *
15945
h_dim1], ldh);
15946
/* L60: */
15947
}
15948
15949
/* ==== Update horizontal slab in H ==== */
15950
15951
if (*wantt) {
15952
i__2 = *n;
15953
i__1 = *nh;
15954
for (kcol = *kbot + 1; i__1 < 0 ? kcol >= i__2 : kcol <= i__2;
15955
kcol += i__1) {
15956
/* Computing MIN */
15957
i__3 = *nh, i__4 = *n - kcol + 1;
15958
kln = min(i__3,i__4);
15959
zgemm_("C", "N", &jw, &kln, &jw, &c_b57, &v[v_offset], ldv, &
15960
h__[kwtop + kcol * h_dim1], ldh, &c_b56, &t[t_offset],
15961
ldt);
15962
zlacpy_("A", &jw, &kln, &t[t_offset], ldt, &h__[kwtop + kcol *
15963
h_dim1], ldh);
15964
/* L70: */
15965
}
15966
}
15967
15968
/* ==== Update vertical slab in Z ==== */
15969
15970
if (*wantz) {
15971
i__1 = *ihiz;
15972
i__2 = *nv;
15973
for (krow = *iloz; i__2 < 0 ? krow >= i__1 : krow <= i__1; krow +=
15974
i__2) {
15975
/* Computing MIN */
15976
i__3 = *nv, i__4 = *ihiz - krow + 1;
15977
kln = min(i__3,i__4);
15978
zgemm_("N", "N", &kln, &jw, &jw, &c_b57, &z__[krow + kwtop *
15979
z_dim1], ldz, &v[v_offset], ldv, &c_b56, &wv[
15980
wv_offset], ldwv);
15981
zlacpy_("A", &kln, &jw, &wv[wv_offset], ldwv, &z__[krow +
15982
kwtop * z_dim1], ldz);
15983
/* L80: */
15984
}
15985
}
15986
}
15987
15988
/* ==== Return the number of deflations ... ==== */
15989
15990
*nd = jw - *ns;
15991
15992
/*
15993
==== ... and the number of shifts. (Subtracting
15994
. INFQR from the spike length takes care
15995
. of the case of a rare QR failure while
15996
. calculating eigenvalues of the deflation
15997
. window.) ====
15998
*/
15999
16000
*ns -= infqr;
16001
16002
/* ==== Return optimal workspace. ==== */
16003
16004
d__1 = (doublereal) lwkopt;
16005
z__1.r = d__1, z__1.i = 0.;
16006
work[1].r = z__1.r, work[1].i = z__1.i;
16007
16008
/* ==== End of ZLAQR3 ==== */
16009
16010
return 0;
16011
} /* zlaqr3_ */
16012
16013
/* Subroutine */ int zlaqr4_(logical *wantt, logical *wantz, integer *n,
16014
integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh,
16015
doublecomplex *w, integer *iloz, integer *ihiz, doublecomplex *z__,
16016
integer *ldz, doublecomplex *work, integer *lwork, integer *info)
16017
{
16018
/* System generated locals */
16019
integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
16020
doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8;
16021
doublecomplex z__1, z__2, z__3, z__4, z__5;
16022
16023
/* Local variables */
16024
static integer i__, k;
16025
static doublereal s;
16026
static doublecomplex aa, bb, cc, dd;
16027
static integer ld, nh, it, ks, kt, ku, kv, ls, ns, nw;
16028
static doublecomplex tr2, det;
16029
static integer inf, kdu, nho, nve, kwh, nsr, nwr, kwv, ndec, ndfl, kbot,
16030
nmin;
16031
static doublecomplex swap;
16032
static integer ktop;
16033
static doublecomplex zdum[1] /* was [1][1] */;
16034
static integer kacc22, itmax, nsmax, nwmax, kwtop;
16035
extern /* Subroutine */ int zlaqr2_(logical *, logical *, integer *,
16036
integer *, integer *, integer *, doublecomplex *, integer *,
16037
integer *, integer *, doublecomplex *, integer *, integer *,
16038
integer *, doublecomplex *, doublecomplex *, integer *, integer *,
16039
doublecomplex *, integer *, integer *, doublecomplex *, integer *
16040
, doublecomplex *, integer *), zlaqr5_(logical *, logical *,
16041
integer *, integer *, integer *, integer *, integer *,
16042
doublecomplex *, doublecomplex *, integer *, integer *, integer *,
16043
doublecomplex *, integer *, doublecomplex *, integer *,
16044
doublecomplex *, integer *, integer *, doublecomplex *, integer *,
16045
integer *, doublecomplex *, integer *);
16046
static integer nibble;
16047
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
16048
integer *, integer *, ftnlen, ftnlen);
16049
static char jbcmpz[2];
16050
static doublecomplex rtdisc;
16051
static integer nwupbd;
16052
static logical sorted;
16053
extern /* Subroutine */ int zlahqr_(logical *, logical *, integer *,
16054
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
16055
integer *, integer *, doublecomplex *, integer *, integer *),
16056
zlacpy_(char *, integer *, integer *, doublecomplex *, integer *,
16057
doublecomplex *, integer *);
16058
static integer lwkopt;
16059
16060
16061
/*
16062
-- LAPACK auxiliary routine (version 3.2) --
16063
Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
16064
November 2006
16065
16066
16067
This subroutine implements one level of recursion for ZLAQR0.
16068
It is a complete implementation of the small bulge multi-shift
16069
QR algorithm. It may be called by ZLAQR0 and, for large enough
16070
deflation window size, it may be called by ZLAQR3. This
16071
subroutine is identical to ZLAQR0 except that it calls ZLAQR2
16072
instead of ZLAQR3.
16073
16074
Purpose
16075
=======
16076
16077
ZLAQR4 computes the eigenvalues of a Hessenberg matrix H
16078
and, optionally, the matrices T and Z from the Schur decomposition
16079
H = Z T Z**H, where T is an upper triangular matrix (the
16080
Schur form), and Z is the unitary matrix of Schur vectors.
16081
16082
Optionally Z may be postmultiplied into an input unitary
16083
matrix Q so that this routine can give the Schur factorization
16084
of a matrix A which has been reduced to the Hessenberg form H
16085
by the unitary matrix Q: A = Q*H*Q**H = (QZ)*H*(QZ)**H.
16086
16087
Arguments
16088
=========
16089
16090
WANTT (input) LOGICAL
16091
= .TRUE. : the full Schur form T is required;
16092
= .FALSE.: only eigenvalues are required.
16093
16094
WANTZ (input) LOGICAL
16095
= .TRUE. : the matrix of Schur vectors Z is required;
16096
= .FALSE.: Schur vectors are not required.
16097
16098
N (input) INTEGER
16099
The order of the matrix H. N .GE. 0.
16100
16101
ILO (input) INTEGER
16102
IHI (input) INTEGER
16103
It is assumed that H is already upper triangular in rows
16104
and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1,
16105
H(ILO,ILO-1) is zero. ILO and IHI are normally set by a
16106
previous call to ZGEBAL, and then passed to ZGEHRD when the
16107
matrix output by ZGEBAL is reduced to Hessenberg form.
16108
Otherwise, ILO and IHI should be set to 1 and N,
16109
respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N.
16110
If N = 0, then ILO = 1 and IHI = 0.
16111
16112
H (input/output) COMPLEX*16 array, dimension (LDH,N)
16113
On entry, the upper Hessenberg matrix H.
16114
On exit, if INFO = 0 and WANTT is .TRUE., then H
16115
contains the upper triangular matrix T from the Schur
16116
decomposition (the Schur form). If INFO = 0 and WANT is
16117
.FALSE., then the contents of H are unspecified on exit.
16118
(The output value of H when INFO.GT.0 is given under the
16119
description of INFO below.)
16120
16121
This subroutine may explicitly set H(i,j) = 0 for i.GT.j and
16122
j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N.
16123
16124
LDH (input) INTEGER
16125
The leading dimension of the array H. LDH .GE. max(1,N).
16126
16127
W (output) COMPLEX*16 array, dimension (N)
16128
The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored
16129
in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are
16130
stored in the same order as on the diagonal of the Schur
16131
form returned in H, with W(i) = H(i,i).
16132
16133
Z (input/output) COMPLEX*16 array, dimension (LDZ,IHI)
16134
If WANTZ is .FALSE., then Z is not referenced.
16135
If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is
16136
replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the
16137
orthogonal Schur factor of H(ILO:IHI,ILO:IHI).
16138
(The output value of Z when INFO.GT.0 is given under
16139
the description of INFO below.)
16140
16141
LDZ (input) INTEGER
16142
The leading dimension of the array Z. if WANTZ is .TRUE.
16143
then LDZ.GE.MAX(1,IHIZ). Otherwize, LDZ.GE.1.
16144
16145
WORK (workspace/output) COMPLEX*16 array, dimension LWORK
16146
On exit, if LWORK = -1, WORK(1) returns an estimate of
16147
the optimal value for LWORK.
16148
16149
LWORK (input) INTEGER
16150
The dimension of the array WORK. LWORK .GE. max(1,N)
16151
is sufficient, but LWORK typically as large as 6*N may
16152
be required for optimal performance. A workspace query
16153
to determine the optimal workspace size is recommended.
16154
16155
If LWORK = -1, then ZLAQR4 does a workspace query.
16156
In this case, ZLAQR4 checks the input parameters and
16157
estimates the optimal workspace size for the given
16158
values of N, ILO and IHI. The estimate is returned
16159
in WORK(1). No error message related to LWORK is
16160
issued by XERBLA. Neither H nor Z are accessed.
16161
16162
16163
INFO (output) INTEGER
16164
= 0: successful exit
16165
.GT. 0: if INFO = i, ZLAQR4 failed to compute all of
16166
the eigenvalues. Elements 1:ilo-1 and i+1:n of WR
16167
and WI contain those eigenvalues which have been
16168
successfully computed. (Failures are rare.)
16169
16170
If INFO .GT. 0 and WANT is .FALSE., then on exit,
16171
the remaining unconverged eigenvalues are the eigen-
16172
values of the upper Hessenberg matrix rows and
16173
columns ILO through INFO of the final, output
16174
value of H.
16175
16176
If INFO .GT. 0 and WANTT is .TRUE., then on exit
16177
16178
(*) (initial value of H)*U = U*(final value of H)
16179
16180
where U is a unitary matrix. The final
16181
value of H is upper Hessenberg and triangular in
16182
rows and columns INFO+1 through IHI.
16183
16184
If INFO .GT. 0 and WANTZ is .TRUE., then on exit
16185
16186
(final value of Z(ILO:IHI,ILOZ:IHIZ)
16187
= (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U
16188
16189
where U is the unitary matrix in (*) (regard-
16190
less of the value of WANTT.)
16191
16192
If INFO .GT. 0 and WANTZ is .FALSE., then Z is not
16193
accessed.
16194
16195
================================================================
16196
Based on contributions by
16197
Karen Braman and Ralph Byers, Department of Mathematics,
16198
University of Kansas, USA
16199
16200
================================================================
16201
References:
16202
K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
16203
Algorithm Part I: Maintaining Well Focused Shifts, and Level 3
16204
Performance, SIAM Journal of Matrix Analysis, volume 23, pages
16205
929--947, 2002.
16206
16207
K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
16208
Algorithm Part II: Aggressive Early Deflation, SIAM Journal
16209
of Matrix Analysis, volume 23, pages 948--973, 2002.
16210
16211
================================================================
16212
16213
==== Matrices of order NTINY or smaller must be processed by
16214
. ZLAHQR because of insufficient subdiagonal scratch space.
16215
. (This is a hard limit.) ====
16216
16217
==== Exceptional deflation windows: try to cure rare
16218
. slow convergence by varying the size of the
16219
. deflation window after KEXNW iterations. ====
16220
16221
==== Exceptional shifts: try to cure rare slow convergence
16222
. with ad-hoc exceptional shifts every KEXSH iterations.
16223
. ====
16224
16225
==== The constant WILK1 is used to form the exceptional
16226
. shifts. ====
16227
*/
16228
/* Parameter adjustments */
16229
h_dim1 = *ldh;
16230
h_offset = 1 + h_dim1;
16231
h__ -= h_offset;
16232
--w;
16233
z_dim1 = *ldz;
16234
z_offset = 1 + z_dim1;
16235
z__ -= z_offset;
16236
--work;
16237
16238
/* Function Body */
16239
*info = 0;
16240
16241
/* ==== Quick return for N = 0: nothing to do. ==== */
16242
16243
if (*n == 0) {
16244
work[1].r = 1., work[1].i = 0.;
16245
return 0;
16246
}
16247
16248
if (*n <= 11) {
16249
16250
/* ==== Tiny matrices must use ZLAHQR. ==== */
16251
16252
lwkopt = 1;
16253
if (*lwork != -1) {
16254
zlahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1],
16255
iloz, ihiz, &z__[z_offset], ldz, info);
16256
}
16257
} else {
16258
16259
/*
16260
==== Use small bulge multi-shift QR with aggressive early
16261
. deflation on larger-than-tiny matrices. ====
16262
16263
==== Hope for the best. ====
16264
*/
16265
16266
*info = 0;
16267
16268
/* ==== Set up job flags for ILAENV. ==== */
16269
16270
if (*wantt) {
16271
*(unsigned char *)jbcmpz = 'S';
16272
} else {
16273
*(unsigned char *)jbcmpz = 'E';
16274
}
16275
if (*wantz) {
16276
*(unsigned char *)&jbcmpz[1] = 'V';
16277
} else {
16278
*(unsigned char *)&jbcmpz[1] = 'N';
16279
}
16280
16281
/*
16282
==== NWR = recommended deflation window size. At this
16283
. point, N .GT. NTINY = 11, so there is enough
16284
. subdiagonal workspace for NWR.GE.2 as required.
16285
. (In fact, there is enough subdiagonal space for
16286
. NWR.GE.3.) ====
16287
*/
16288
16289
nwr = ilaenv_(&c__13, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
16290
(ftnlen)2);
16291
nwr = max(2,nwr);
16292
/* Computing MIN */
16293
i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = min(i__1,i__2);
16294
nwr = min(i__1,nwr);
16295
16296
/*
16297
==== NSR = recommended number of simultaneous shifts.
16298
. At this point N .GT. NTINY = 11, so there is at
16299
. enough subdiagonal workspace for NSR to be even
16300
. and greater than or equal to two as required. ====
16301
*/
16302
16303
nsr = ilaenv_(&c__15, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)6,
16304
(ftnlen)2);
16305
/* Computing MIN */
16306
i__1 = nsr, i__2 = (*n + 6) / 9, i__1 = min(i__1,i__2), i__2 = *ihi -
16307
*ilo;
16308
nsr = min(i__1,i__2);
16309
/* Computing MAX */
16310
i__1 = 2, i__2 = nsr - nsr % 2;
16311
nsr = max(i__1,i__2);
16312
16313
/*
16314
==== Estimate optimal workspace ====
16315
16316
==== Workspace query call to ZLAQR2 ====
16317
*/
16318
16319
i__1 = nwr + 1;
16320
zlaqr2_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz,
16321
ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[h_offset],
16322
ldh, n, &h__[h_offset], ldh, n, &h__[h_offset], ldh, &work[1],
16323
&c_n1);
16324
16325
/*
16326
==== Optimal workspace = MAX(ZLAQR5, ZLAQR2) ====
16327
16328
Computing MAX
16329
*/
16330
i__1 = nsr * 3 / 2, i__2 = (integer) work[1].r;
16331
lwkopt = max(i__1,i__2);
16332
16333
/* ==== Quick return in case of workspace query. ==== */
16334
16335
if (*lwork == -1) {
16336
d__1 = (doublereal) lwkopt;
16337
z__1.r = d__1, z__1.i = 0.;
16338
work[1].r = z__1.r, work[1].i = z__1.i;
16339
return 0;
16340
}
16341
16342
/* ==== ZLAHQR/ZLAQR0 crossover point ==== */
16343
16344
nmin = ilaenv_(&c__12, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (ftnlen)
16345
6, (ftnlen)2);
16346
nmin = max(11,nmin);
16347
16348
/* ==== Nibble crossover point ==== */
16349
16350
nibble = ilaenv_(&c__14, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (
16351
ftnlen)6, (ftnlen)2);
16352
nibble = max(0,nibble);
16353
16354
/*
16355
==== Accumulate reflections during ttswp? Use block
16356
. 2-by-2 structure during matrix-matrix multiply? ====
16357
*/
16358
16359
kacc22 = ilaenv_(&c__16, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork, (
16360
ftnlen)6, (ftnlen)2);
16361
kacc22 = max(0,kacc22);
16362
kacc22 = min(2,kacc22);
16363
16364
/*
16365
==== NWMAX = the largest possible deflation window for
16366
. which there is sufficient workspace. ====
16367
16368
Computing MIN
16369
*/
16370
i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
16371
nwmax = min(i__1,i__2);
16372
nw = nwmax;
16373
16374
/*
16375
==== NSMAX = the Largest number of simultaneous shifts
16376
. for which there is sufficient workspace. ====
16377
16378
Computing MIN
16379
*/
16380
i__1 = (*n + 6) / 9, i__2 = (*lwork << 1) / 3;
16381
nsmax = min(i__1,i__2);
16382
nsmax -= nsmax % 2;
16383
16384
/* ==== NDFL: an iteration count restarted at deflation. ==== */
16385
16386
ndfl = 1;
16387
16388
/*
16389
==== ITMAX = iteration limit ====
16390
16391
Computing MAX
16392
*/
16393
i__1 = 10, i__2 = *ihi - *ilo + 1;
16394
itmax = max(i__1,i__2) * 30;
16395
16396
/* ==== Last row and column in the active block ==== */
16397
16398
kbot = *ihi;
16399
16400
/* ==== Main Loop ==== */
16401
16402
i__1 = itmax;
16403
for (it = 1; it <= i__1; ++it) {
16404
16405
/* ==== Done when KBOT falls below ILO ==== */
16406
16407
if (kbot < *ilo) {
16408
goto L80;
16409
}
16410
16411
/* ==== Locate active block ==== */
16412
16413
i__2 = *ilo + 1;
16414
for (k = kbot; k >= i__2; --k) {
16415
i__3 = k + (k - 1) * h_dim1;
16416
if (h__[i__3].r == 0. && h__[i__3].i == 0.) {
16417
goto L20;
16418
}
16419
/* L10: */
16420
}
16421
k = *ilo;
16422
L20:
16423
ktop = k;
16424
16425
/*
16426
==== Select deflation window size:
16427
. Typical Case:
16428
. If possible and advisable, nibble the entire
16429
. active block. If not, use size MIN(NWR,NWMAX)
16430
. or MIN(NWR+1,NWMAX) depending upon which has
16431
. the smaller corresponding subdiagonal entry
16432
. (a heuristic).
16433
.
16434
. Exceptional Case:
16435
. If there have been no deflations in KEXNW or
16436
. more iterations, then vary the deflation window
16437
. size. At first, because, larger windows are,
16438
. in general, more powerful than smaller ones,
16439
. rapidly increase the window to the maximum possible.
16440
. Then, gradually reduce the window size. ====
16441
*/
16442
16443
nh = kbot - ktop + 1;
16444
nwupbd = min(nh,nwmax);
16445
if (ndfl < 5) {
16446
nw = min(nwupbd,nwr);
16447
} else {
16448
/* Computing MIN */
16449
i__2 = nwupbd, i__3 = nw << 1;
16450
nw = min(i__2,i__3);
16451
}
16452
if (nw < nwmax) {
16453
if (nw >= nh - 1) {
16454
nw = nh;
16455
} else {
16456
kwtop = kbot - nw + 1;
16457
i__2 = kwtop + (kwtop - 1) * h_dim1;
16458
i__3 = kwtop - 1 + (kwtop - 2) * h_dim1;
16459
if ((d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[
16460
kwtop + (kwtop - 1) * h_dim1]), abs(d__2)) > (
16461
d__3 = h__[i__3].r, abs(d__3)) + (d__4 = d_imag(&
16462
h__[kwtop - 1 + (kwtop - 2) * h_dim1]), abs(d__4))
16463
) {
16464
++nw;
16465
}
16466
}
16467
}
16468
if (ndfl < 5) {
16469
ndec = -1;
16470
} else if (ndec >= 0 || nw >= nwupbd) {
16471
++ndec;
16472
if (nw - ndec < 2) {
16473
ndec = 0;
16474
}
16475
nw -= ndec;
16476
}
16477
16478
/*
16479
==== Aggressive early deflation:
16480
. split workspace under the subdiagonal into
16481
. - an nw-by-nw work array V in the lower
16482
. left-hand-corner,
16483
. - an NW-by-at-least-NW-but-more-is-better
16484
. (NW-by-NHO) horizontal work array along
16485
. the bottom edge,
16486
. - an at-least-NW-but-more-is-better (NHV-by-NW)
16487
. vertical work array along the left-hand-edge.
16488
. ====
16489
*/
16490
16491
kv = *n - nw + 1;
16492
kt = nw + 1;
16493
nho = *n - nw - 1 - kt + 1;
16494
kwv = nw + 2;
16495
nve = *n - nw - kwv + 1;
16496
16497
/* ==== Aggressive early deflation ==== */
16498
16499
zlaqr2_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh,
16500
iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[kv
16501
+ h_dim1], ldh, &nho, &h__[kv + kt * h_dim1], ldh, &nve, &
16502
h__[kwv + h_dim1], ldh, &work[1], lwork);
16503
16504
/* ==== Adjust KBOT accounting for new deflations. ==== */
16505
16506
kbot -= ld;
16507
16508
/* ==== KS points to the shifts. ==== */
16509
16510
ks = kbot - ls + 1;
16511
16512
/*
16513
==== Skip an expensive QR sweep if there is a (partly
16514
. heuristic) reason to expect that many eigenvalues
16515
. will deflate without it. Here, the QR sweep is
16516
. skipped if many eigenvalues have just been deflated
16517
. or if the remaining active block is small.
16518
*/
16519
16520
if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > min(
16521
nmin,nwmax)) {
16522
16523
/*
16524
==== NS = nominal number of simultaneous shifts.
16525
. This may be lowered (slightly) if ZLAQR2
16526
. did not provide that many shifts. ====
16527
16528
Computing MIN
16529
Computing MAX
16530
*/
16531
i__4 = 2, i__5 = kbot - ktop;
16532
i__2 = min(nsmax,nsr), i__3 = max(i__4,i__5);
16533
ns = min(i__2,i__3);
16534
ns -= ns % 2;
16535
16536
/*
16537
==== If there have been no deflations
16538
. in a multiple of KEXSH iterations,
16539
. then try exceptional shifts.
16540
. Otherwise use shifts provided by
16541
. ZLAQR2 above or from the eigenvalues
16542
. of a trailing principal submatrix. ====
16543
*/
16544
16545
if (ndfl % 6 == 0) {
16546
ks = kbot - ns + 1;
16547
i__2 = ks + 1;
16548
for (i__ = kbot; i__ >= i__2; i__ += -2) {
16549
i__3 = i__;
16550
i__4 = i__ + i__ * h_dim1;
16551
i__5 = i__ + (i__ - 1) * h_dim1;
16552
d__3 = ((d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
16553
d_imag(&h__[i__ + (i__ - 1) * h_dim1]), abs(
16554
d__2))) * .75;
16555
z__1.r = h__[i__4].r + d__3, z__1.i = h__[i__4].i;
16556
w[i__3].r = z__1.r, w[i__3].i = z__1.i;
16557
i__3 = i__ - 1;
16558
i__4 = i__;
16559
w[i__3].r = w[i__4].r, w[i__3].i = w[i__4].i;
16560
/* L30: */
16561
}
16562
} else {
16563
16564
/*
16565
==== Got NS/2 or fewer shifts? Use ZLAHQR
16566
. on a trailing principal submatrix to
16567
. get more. (Since NS.LE.NSMAX.LE.(N+6)/9,
16568
. there is enough space below the subdiagonal
16569
. to fit an NS-by-NS scratch array.) ====
16570
*/
16571
16572
if (kbot - ks + 1 <= ns / 2) {
16573
ks = kbot - ns + 1;
16574
kt = *n - ns + 1;
16575
zlacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
16576
h__[kt + h_dim1], ldh);
16577
zlahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[kt
16578
+ h_dim1], ldh, &w[ks], &c__1, &c__1, zdum, &
16579
c__1, &inf);
16580
ks += inf;
16581
16582
/*
16583
==== In case of a rare QR failure use
16584
. eigenvalues of the trailing 2-by-2
16585
. principal submatrix. Scale to avoid
16586
. overflows, underflows and subnormals.
16587
. (The scale factor S can not be zero,
16588
. because H(KBOT,KBOT-1) is nonzero.) ====
16589
*/
16590
16591
if (ks >= kbot) {
16592
i__2 = kbot - 1 + (kbot - 1) * h_dim1;
16593
i__3 = kbot + (kbot - 1) * h_dim1;
16594
i__4 = kbot - 1 + kbot * h_dim1;
16595
i__5 = kbot + kbot * h_dim1;
16596
s = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 =
16597
d_imag(&h__[kbot - 1 + (kbot - 1) *
16598
h_dim1]), abs(d__2)) + ((d__3 = h__[i__3]
16599
.r, abs(d__3)) + (d__4 = d_imag(&h__[kbot
16600
+ (kbot - 1) * h_dim1]), abs(d__4))) + ((
16601
d__5 = h__[i__4].r, abs(d__5)) + (d__6 =
16602
d_imag(&h__[kbot - 1 + kbot * h_dim1]),
16603
abs(d__6))) + ((d__7 = h__[i__5].r, abs(
16604
d__7)) + (d__8 = d_imag(&h__[kbot + kbot *
16605
h_dim1]), abs(d__8)));
16606
i__2 = kbot - 1 + (kbot - 1) * h_dim1;
16607
z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
16608
s;
16609
aa.r = z__1.r, aa.i = z__1.i;
16610
i__2 = kbot + (kbot - 1) * h_dim1;
16611
z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
16612
s;
16613
cc.r = z__1.r, cc.i = z__1.i;
16614
i__2 = kbot - 1 + kbot * h_dim1;
16615
z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
16616
s;
16617
bb.r = z__1.r, bb.i = z__1.i;
16618
i__2 = kbot + kbot * h_dim1;
16619
z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i /
16620
s;
16621
dd.r = z__1.r, dd.i = z__1.i;
16622
z__2.r = aa.r + dd.r, z__2.i = aa.i + dd.i;
16623
z__1.r = z__2.r / 2., z__1.i = z__2.i / 2.;
16624
tr2.r = z__1.r, tr2.i = z__1.i;
16625
z__3.r = aa.r - tr2.r, z__3.i = aa.i - tr2.i;
16626
z__4.r = dd.r - tr2.r, z__4.i = dd.i - tr2.i;
16627
z__2.r = z__3.r * z__4.r - z__3.i * z__4.i,
16628
z__2.i = z__3.r * z__4.i + z__3.i *
16629
z__4.r;
16630
z__5.r = bb.r * cc.r - bb.i * cc.i, z__5.i = bb.r
16631
* cc.i + bb.i * cc.r;
16632
z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
16633
z__5.i;
16634
det.r = z__1.r, det.i = z__1.i;
16635
z__2.r = -det.r, z__2.i = -det.i;
16636
z_sqrt(&z__1, &z__2);
16637
rtdisc.r = z__1.r, rtdisc.i = z__1.i;
16638
i__2 = kbot - 1;
16639
z__2.r = tr2.r + rtdisc.r, z__2.i = tr2.i +
16640
rtdisc.i;
16641
z__1.r = s * z__2.r, z__1.i = s * z__2.i;
16642
w[i__2].r = z__1.r, w[i__2].i = z__1.i;
16643
i__2 = kbot;
16644
z__2.r = tr2.r - rtdisc.r, z__2.i = tr2.i -
16645
rtdisc.i;
16646
z__1.r = s * z__2.r, z__1.i = s * z__2.i;
16647
w[i__2].r = z__1.r, w[i__2].i = z__1.i;
16648
16649
ks = kbot - 1;
16650
}
16651
}
16652
16653
if (kbot - ks + 1 > ns) {
16654
16655
/* ==== Sort the shifts (Helps a little) ==== */
16656
16657
sorted = FALSE_;
16658
i__2 = ks + 1;
16659
for (k = kbot; k >= i__2; --k) {
16660
if (sorted) {
16661
goto L60;
16662
}
16663
sorted = TRUE_;
16664
i__3 = k - 1;
16665
for (i__ = ks; i__ <= i__3; ++i__) {
16666
i__4 = i__;
16667
i__5 = i__ + 1;
16668
if ((d__1 = w[i__4].r, abs(d__1)) + (d__2 =
16669
d_imag(&w[i__]), abs(d__2)) < (d__3 =
16670
w[i__5].r, abs(d__3)) + (d__4 =
16671
d_imag(&w[i__ + 1]), abs(d__4))) {
16672
sorted = FALSE_;
16673
i__4 = i__;
16674
swap.r = w[i__4].r, swap.i = w[i__4].i;
16675
i__4 = i__;
16676
i__5 = i__ + 1;
16677
w[i__4].r = w[i__5].r, w[i__4].i = w[i__5]
16678
.i;
16679
i__4 = i__ + 1;
16680
w[i__4].r = swap.r, w[i__4].i = swap.i;
16681
}
16682
/* L40: */
16683
}
16684
/* L50: */
16685
}
16686
L60:
16687
;
16688
}
16689
}
16690
16691
/*
16692
==== If there are only two shifts, then use
16693
. only one. ====
16694
*/
16695
16696
if (kbot - ks + 1 == 2) {
16697
i__2 = kbot;
16698
i__3 = kbot + kbot * h_dim1;
16699
z__2.r = w[i__2].r - h__[i__3].r, z__2.i = w[i__2].i -
16700
h__[i__3].i;
16701
z__1.r = z__2.r, z__1.i = z__2.i;
16702
i__4 = kbot - 1;
16703
i__5 = kbot + kbot * h_dim1;
16704
z__4.r = w[i__4].r - h__[i__5].r, z__4.i = w[i__4].i -
16705
h__[i__5].i;
16706
z__3.r = z__4.r, z__3.i = z__4.i;
16707
if ((d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1),
16708
abs(d__2)) < (d__3 = z__3.r, abs(d__3)) + (d__4 =
16709
d_imag(&z__3), abs(d__4))) {
16710
i__2 = kbot - 1;
16711
i__3 = kbot;
16712
w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
16713
} else {
16714
i__2 = kbot;
16715
i__3 = kbot - 1;
16716
w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
16717
}
16718
}
16719
16720
/*
16721
==== Use up to NS of the smallest magnatiude
16722
. shifts. If there aren't NS shifts available,
16723
. then use them all, possibly dropping one to
16724
. make the number of shifts even. ====
16725
16726
Computing MIN
16727
*/
16728
i__2 = ns, i__3 = kbot - ks + 1;
16729
ns = min(i__2,i__3);
16730
ns -= ns % 2;
16731
ks = kbot - ns + 1;
16732
16733
/*
16734
==== Small-bulge multi-shift QR sweep:
16735
. split workspace under the subdiagonal into
16736
. - a KDU-by-KDU work array U in the lower
16737
. left-hand-corner,
16738
. - a KDU-by-at-least-KDU-but-more-is-better
16739
. (KDU-by-NHo) horizontal work array WH along
16740
. the bottom edge,
16741
. - and an at-least-KDU-but-more-is-better-by-KDU
16742
. (NVE-by-KDU) vertical work WV arrow along
16743
. the left-hand-edge. ====
16744
*/
16745
16746
kdu = ns * 3 - 3;
16747
ku = *n - kdu + 1;
16748
kwh = kdu + 1;
16749
nho = *n - kdu - 3 - (kdu + 1) + 1;
16750
kwv = kdu + 4;
16751
nve = *n - kdu - kwv + 1;
16752
16753
/* ==== Small-bulge multi-shift QR sweep ==== */
16754
16755
zlaqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &w[ks], &
16756
h__[h_offset], ldh, iloz, ihiz, &z__[z_offset], ldz, &
16757
work[1], &c__3, &h__[ku + h_dim1], ldh, &nve, &h__[
16758
kwv + h_dim1], ldh, &nho, &h__[ku + kwh * h_dim1],
16759
ldh);
16760
}
16761
16762
/* ==== Note progress (or the lack of it). ==== */
16763
16764
if (ld > 0) {
16765
ndfl = 1;
16766
} else {
16767
++ndfl;
16768
}
16769
16770
/*
16771
==== End of main loop ====
16772
L70:
16773
*/
16774
}
16775
16776
/*
16777
==== Iteration limit exceeded. Set INFO to show where
16778
. the problem occurred and exit. ====
16779
*/
16780
16781
*info = kbot;
16782
L80:
16783
;
16784
}
16785
16786
/* ==== Return the optimal value of LWORK. ==== */
16787
16788
d__1 = (doublereal) lwkopt;
16789
z__1.r = d__1, z__1.i = 0.;
16790
work[1].r = z__1.r, work[1].i = z__1.i;
16791
16792
/* ==== End of ZLAQR4 ==== */
16793
16794
return 0;
16795
} /* zlaqr4_ */
16796
16797
/* Subroutine */ int zlaqr5_(logical *wantt, logical *wantz, integer *kacc22,
16798
integer *n, integer *ktop, integer *kbot, integer *nshfts,
16799
doublecomplex *s, doublecomplex *h__, integer *ldh, integer *iloz,
16800
integer *ihiz, doublecomplex *z__, integer *ldz, doublecomplex *v,
16801
integer *ldv, doublecomplex *u, integer *ldu, integer *nv,
16802
doublecomplex *wv, integer *ldwv, integer *nh, doublecomplex *wh,
16803
integer *ldwh)
16804
{
16805
/* System generated locals */
16806
integer h_dim1, h_offset, u_dim1, u_offset, v_dim1, v_offset, wh_dim1,
16807
wh_offset, wv_dim1, wv_offset, z_dim1, z_offset, i__1, i__2, i__3,
16808
i__4, i__5, i__6, i__7, i__8, i__9, i__10, i__11;
16809
doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8, d__9, d__10;
16810
doublecomplex z__1, z__2, z__3, z__4, z__5, z__6, z__7, z__8;
16811
16812
/* Local variables */
16813
static integer j, k, m, i2, j2, i4, j4, k1;
16814
static doublereal h11, h12, h21, h22;
16815
static integer m22, ns, nu;
16816
static doublecomplex vt[3];
16817
static doublereal scl;
16818
static integer kdu, kms;
16819
static doublereal ulp;
16820
static integer knz, kzs;
16821
static doublereal tst1, tst2;
16822
static doublecomplex beta;
16823
static logical blk22, bmp22;
16824
static integer mend, jcol, jlen, jbot, mbot, jtop, jrow, mtop;
16825
static doublecomplex alpha;
16826
static logical accum;
16827
static integer ndcol, incol, krcol, nbmps;
16828
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
16829
integer *, doublecomplex *, doublecomplex *, integer *,
16830
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
16831
integer *), ztrmm_(char *, char *, char *, char *,
16832
integer *, integer *, doublecomplex *, doublecomplex *, integer *
16833
, doublecomplex *, integer *),
16834
dlabad_(doublereal *, doublereal *), zlaqr1_(integer *,
16835
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
16836
doublecomplex *);
16837
16838
static doublereal safmin, safmax;
16839
extern /* Subroutine */ int zlarfg_(integer *, doublecomplex *,
16840
doublecomplex *, integer *, doublecomplex *);
16841
static doublecomplex refsum;
16842
extern /* Subroutine */ int zlacpy_(char *, integer *, integer *,
16843
doublecomplex *, integer *, doublecomplex *, integer *),
16844
zlaset_(char *, integer *, integer *, doublecomplex *,
16845
doublecomplex *, doublecomplex *, integer *);
16846
static integer mstart;
16847
static doublereal smlnum;
16848
16849
16850
/*
16851
-- LAPACK auxiliary routine (version 3.2) --
16852
Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
16853
November 2006
16854
16855
16856
This auxiliary subroutine called by ZLAQR0 performs a
16857
single small-bulge multi-shift QR sweep.
16858
16859
WANTT (input) logical scalar
16860
WANTT = .true. if the triangular Schur factor
16861
is being computed. WANTT is set to .false. otherwise.
16862
16863
WANTZ (input) logical scalar
16864
WANTZ = .true. if the unitary Schur factor is being
16865
computed. WANTZ is set to .false. otherwise.
16866
16867
KACC22 (input) integer with value 0, 1, or 2.
16868
Specifies the computation mode of far-from-diagonal
16869
orthogonal updates.
16870
= 0: ZLAQR5 does not accumulate reflections and does not
16871
use matrix-matrix multiply to update far-from-diagonal
16872
matrix entries.
16873
= 1: ZLAQR5 accumulates reflections and uses matrix-matrix
16874
multiply to update the far-from-diagonal matrix entries.
16875
= 2: ZLAQR5 accumulates reflections, uses matrix-matrix
16876
multiply to update the far-from-diagonal matrix entries,
16877
and takes advantage of 2-by-2 block structure during
16878
matrix multiplies.
16879
16880
N (input) integer scalar
16881
N is the order of the Hessenberg matrix H upon which this
16882
subroutine operates.
16883
16884
KTOP (input) integer scalar
16885
KBOT (input) integer scalar
16886
These are the first and last rows and columns of an
16887
isolated diagonal block upon which the QR sweep is to be
16888
applied. It is assumed without a check that
16889
either KTOP = 1 or H(KTOP,KTOP-1) = 0
16890
and
16891
either KBOT = N or H(KBOT+1,KBOT) = 0.
16892
16893
NSHFTS (input) integer scalar
16894
NSHFTS gives the number of simultaneous shifts. NSHFTS
16895
must be positive and even.
16896
16897
S (input/output) COMPLEX*16 array of size (NSHFTS)
16898
S contains the shifts of origin that define the multi-
16899
shift QR sweep. On output S may be reordered.
16900
16901
H (input/output) COMPLEX*16 array of size (LDH,N)
16902
On input H contains a Hessenberg matrix. On output a
16903
multi-shift QR sweep with shifts SR(J)+i*SI(J) is applied
16904
to the isolated diagonal block in rows and columns KTOP
16905
through KBOT.
16906
16907
LDH (input) integer scalar
16908
LDH is the leading dimension of H just as declared in the
16909
calling procedure. LDH.GE.MAX(1,N).
16910
16911
ILOZ (input) INTEGER
16912
IHIZ (input) INTEGER
16913
Specify the rows of Z to which transformations must be
16914
applied if WANTZ is .TRUE.. 1 .LE. ILOZ .LE. IHIZ .LE. N
16915
16916
Z (input/output) COMPLEX*16 array of size (LDZ,IHI)
16917
If WANTZ = .TRUE., then the QR Sweep unitary
16918
similarity transformation is accumulated into
16919
Z(ILOZ:IHIZ,ILO:IHI) from the right.
16920
If WANTZ = .FALSE., then Z is unreferenced.
16921
16922
LDZ (input) integer scalar
16923
LDA is the leading dimension of Z just as declared in
16924
the calling procedure. LDZ.GE.N.
16925
16926
V (workspace) COMPLEX*16 array of size (LDV,NSHFTS/2)
16927
16928
LDV (input) integer scalar
16929
LDV is the leading dimension of V as declared in the
16930
calling procedure. LDV.GE.3.
16931
16932
U (workspace) COMPLEX*16 array of size
16933
(LDU,3*NSHFTS-3)
16934
16935
LDU (input) integer scalar
16936
LDU is the leading dimension of U just as declared in the
16937
in the calling subroutine. LDU.GE.3*NSHFTS-3.
16938
16939
NH (input) integer scalar
16940
NH is the number of columns in array WH available for
16941
workspace. NH.GE.1.
16942
16943
WH (workspace) COMPLEX*16 array of size (LDWH,NH)
16944
16945
LDWH (input) integer scalar
16946
Leading dimension of WH just as declared in the
16947
calling procedure. LDWH.GE.3*NSHFTS-3.
16948
16949
NV (input) integer scalar
16950
NV is the number of rows in WV agailable for workspace.
16951
NV.GE.1.
16952
16953
WV (workspace) COMPLEX*16 array of size
16954
(LDWV,3*NSHFTS-3)
16955
16956
LDWV (input) integer scalar
16957
LDWV is the leading dimension of WV as declared in the
16958
in the calling subroutine. LDWV.GE.NV.
16959
16960
================================================================
16961
Based on contributions by
16962
Karen Braman and Ralph Byers, Department of Mathematics,
16963
University of Kansas, USA
16964
16965
================================================================
16966
Reference:
16967
16968
K. Braman, R. Byers and R. Mathias, The Multi-Shift QR
16969
Algorithm Part I: Maintaining Well Focused Shifts, and
16970
Level 3 Performance, SIAM Journal of Matrix Analysis,
16971
volume 23, pages 929--947, 2002.
16972
16973
================================================================
16974
16975
16976
==== If there are no shifts, then there is nothing to do. ====
16977
*/
16978
16979
/* Parameter adjustments */
16980
--s;
16981
h_dim1 = *ldh;
16982
h_offset = 1 + h_dim1;
16983
h__ -= h_offset;
16984
z_dim1 = *ldz;
16985
z_offset = 1 + z_dim1;
16986
z__ -= z_offset;
16987
v_dim1 = *ldv;
16988
v_offset = 1 + v_dim1;
16989
v -= v_offset;
16990
u_dim1 = *ldu;
16991
u_offset = 1 + u_dim1;
16992
u -= u_offset;
16993
wv_dim1 = *ldwv;
16994
wv_offset = 1 + wv_dim1;
16995
wv -= wv_offset;
16996
wh_dim1 = *ldwh;
16997
wh_offset = 1 + wh_dim1;
16998
wh -= wh_offset;
16999
17000
/* Function Body */
17001
if (*nshfts < 2) {
17002
return 0;
17003
}
17004
17005
/*
17006
==== If the active block is empty or 1-by-1, then there
17007
. is nothing to do. ====
17008
*/
17009
17010
if (*ktop >= *kbot) {
17011
return 0;
17012
}
17013
17014
/*
17015
==== NSHFTS is supposed to be even, but if it is odd,
17016
. then simply reduce it by one. ====
17017
*/
17018
17019
ns = *nshfts - *nshfts % 2;
17020
17021
/* ==== Machine constants for deflation ==== */
17022
17023
safmin = SAFEMINIMUM;
17024
safmax = 1. / safmin;
17025
dlabad_(&safmin, &safmax);
17026
ulp = PRECISION;
17027
smlnum = safmin * ((doublereal) (*n) / ulp);
17028
17029
/*
17030
==== Use accumulated reflections to update far-from-diagonal
17031
. entries ? ====
17032
*/
17033
17034
accum = *kacc22 == 1 || *kacc22 == 2;
17035
17036
/* ==== If so, exploit the 2-by-2 block structure? ==== */
17037
17038
blk22 = ns > 2 && *kacc22 == 2;
17039
17040
/* ==== clear trash ==== */
17041
17042
if (*ktop + 2 <= *kbot) {
17043
i__1 = *ktop + 2 + *ktop * h_dim1;
17044
h__[i__1].r = 0., h__[i__1].i = 0.;
17045
}
17046
17047
/* ==== NBMPS = number of 2-shift bulges in the chain ==== */
17048
17049
nbmps = ns / 2;
17050
17051
/* ==== KDU = width of slab ==== */
17052
17053
kdu = nbmps * 6 - 3;
17054
17055
/* ==== Create and chase chains of NBMPS bulges ==== */
17056
17057
i__1 = *kbot - 2;
17058
i__2 = nbmps * 3 - 2;
17059
for (incol = (1 - nbmps) * 3 + *ktop - 1; i__2 < 0 ? incol >= i__1 :
17060
incol <= i__1; incol += i__2) {
17061
ndcol = incol + kdu;
17062
if (accum) {
17063
zlaset_("ALL", &kdu, &kdu, &c_b56, &c_b57, &u[u_offset], ldu);
17064
}
17065
17066
/*
17067
==== Near-the-diagonal bulge chase. The following loop
17068
. performs the near-the-diagonal part of a small bulge
17069
. multi-shift QR sweep. Each 6*NBMPS-2 column diagonal
17070
. chunk extends from column INCOL to column NDCOL
17071
. (including both column INCOL and column NDCOL). The
17072
. following loop chases a 3*NBMPS column long chain of
17073
. NBMPS bulges 3*NBMPS-2 columns to the right. (INCOL
17074
. may be less than KTOP and and NDCOL may be greater than
17075
. KBOT indicating phantom columns from which to chase
17076
. bulges before they are actually introduced or to which
17077
. to chase bulges beyond column KBOT.) ====
17078
17079
Computing MIN
17080
*/
17081
i__4 = incol + nbmps * 3 - 3, i__5 = *kbot - 2;
17082
i__3 = min(i__4,i__5);
17083
for (krcol = incol; krcol <= i__3; ++krcol) {
17084
17085
/*
17086
==== Bulges number MTOP to MBOT are active double implicit
17087
. shift bulges. There may or may not also be small
17088
. 2-by-2 bulge, if there is room. The inactive bulges
17089
. (if any) must wait until the active bulges have moved
17090
. down the diagonal to make room. The phantom matrix
17091
. paradigm described above helps keep track. ====
17092
17093
Computing MAX
17094
*/
17095
i__4 = 1, i__5 = (*ktop - 1 - krcol + 2) / 3 + 1;
17096
mtop = max(i__4,i__5);
17097
/* Computing MIN */
17098
i__4 = nbmps, i__5 = (*kbot - krcol) / 3;
17099
mbot = min(i__4,i__5);
17100
m22 = mbot + 1;
17101
bmp22 = mbot < nbmps && krcol + (m22 - 1) * 3 == *kbot - 2;
17102
17103
/*
17104
==== Generate reflections to chase the chain right
17105
. one column. (The minimum value of K is KTOP-1.) ====
17106
*/
17107
17108
i__4 = mbot;
17109
for (m = mtop; m <= i__4; ++m) {
17110
k = krcol + (m - 1) * 3;
17111
if (k == *ktop - 1) {
17112
zlaqr1_(&c__3, &h__[*ktop + *ktop * h_dim1], ldh, &s[(m <<
17113
1) - 1], &s[m * 2], &v[m * v_dim1 + 1]);
17114
i__5 = m * v_dim1 + 1;
17115
alpha.r = v[i__5].r, alpha.i = v[i__5].i;
17116
zlarfg_(&c__3, &alpha, &v[m * v_dim1 + 2], &c__1, &v[m *
17117
v_dim1 + 1]);
17118
} else {
17119
i__5 = k + 1 + k * h_dim1;
17120
beta.r = h__[i__5].r, beta.i = h__[i__5].i;
17121
i__5 = m * v_dim1 + 2;
17122
i__6 = k + 2 + k * h_dim1;
17123
v[i__5].r = h__[i__6].r, v[i__5].i = h__[i__6].i;
17124
i__5 = m * v_dim1 + 3;
17125
i__6 = k + 3 + k * h_dim1;
17126
v[i__5].r = h__[i__6].r, v[i__5].i = h__[i__6].i;
17127
zlarfg_(&c__3, &beta, &v[m * v_dim1 + 2], &c__1, &v[m *
17128
v_dim1 + 1]);
17129
17130
/*
17131
==== A Bulge may collapse because of vigilant
17132
. deflation or destructive underflow. In the
17133
. underflow case, try the two-small-subdiagonals
17134
. trick to try to reinflate the bulge. ====
17135
*/
17136
17137
i__5 = k + 3 + k * h_dim1;
17138
i__6 = k + 3 + (k + 1) * h_dim1;
17139
i__7 = k + 3 + (k + 2) * h_dim1;
17140
if (h__[i__5].r != 0. || h__[i__5].i != 0. || (h__[i__6]
17141
.r != 0. || h__[i__6].i != 0.) || h__[i__7].r ==
17142
0. && h__[i__7].i == 0.) {
17143
17144
/* ==== Typical case: not collapsed (yet). ==== */
17145
17146
i__5 = k + 1 + k * h_dim1;
17147
h__[i__5].r = beta.r, h__[i__5].i = beta.i;
17148
i__5 = k + 2 + k * h_dim1;
17149
h__[i__5].r = 0., h__[i__5].i = 0.;
17150
i__5 = k + 3 + k * h_dim1;
17151
h__[i__5].r = 0., h__[i__5].i = 0.;
17152
} else {
17153
17154
/*
17155
==== Atypical case: collapsed. Attempt to
17156
. reintroduce ignoring H(K+1,K) and H(K+2,K).
17157
. If the fill resulting from the new
17158
. reflector is too large, then abandon it.
17159
. Otherwise, use the new one. ====
17160
*/
17161
17162
zlaqr1_(&c__3, &h__[k + 1 + (k + 1) * h_dim1], ldh, &
17163
s[(m << 1) - 1], &s[m * 2], vt);
17164
alpha.r = vt[0].r, alpha.i = vt[0].i;
17165
zlarfg_(&c__3, &alpha, &vt[1], &c__1, vt);
17166
d_cnjg(&z__2, vt);
17167
i__5 = k + 1 + k * h_dim1;
17168
d_cnjg(&z__5, &vt[1]);
17169
i__6 = k + 2 + k * h_dim1;
17170
z__4.r = z__5.r * h__[i__6].r - z__5.i * h__[i__6].i,
17171
z__4.i = z__5.r * h__[i__6].i + z__5.i * h__[
17172
i__6].r;
17173
z__3.r = h__[i__5].r + z__4.r, z__3.i = h__[i__5].i +
17174
z__4.i;
17175
z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i =
17176
z__2.r * z__3.i + z__2.i * z__3.r;
17177
refsum.r = z__1.r, refsum.i = z__1.i;
17178
17179
i__5 = k + 2 + k * h_dim1;
17180
z__3.r = refsum.r * vt[1].r - refsum.i * vt[1].i,
17181
z__3.i = refsum.r * vt[1].i + refsum.i * vt[1]
17182
.r;
17183
z__2.r = h__[i__5].r - z__3.r, z__2.i = h__[i__5].i -
17184
z__3.i;
17185
z__1.r = z__2.r, z__1.i = z__2.i;
17186
z__5.r = refsum.r * vt[2].r - refsum.i * vt[2].i,
17187
z__5.i = refsum.r * vt[2].i + refsum.i * vt[2]
17188
.r;
17189
z__4.r = z__5.r, z__4.i = z__5.i;
17190
i__6 = k + k * h_dim1;
17191
i__7 = k + 1 + (k + 1) * h_dim1;
17192
i__8 = k + 2 + (k + 2) * h_dim1;
17193
if ((d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1)
17194
, abs(d__2)) + ((d__3 = z__4.r, abs(d__3)) + (
17195
d__4 = d_imag(&z__4), abs(d__4))) > ulp * ((
17196
d__5 = h__[i__6].r, abs(d__5)) + (d__6 =
17197
d_imag(&h__[k + k * h_dim1]), abs(d__6)) + ((
17198
d__7 = h__[i__7].r, abs(d__7)) + (d__8 =
17199
d_imag(&h__[k + 1 + (k + 1) * h_dim1]), abs(
17200
d__8))) + ((d__9 = h__[i__8].r, abs(d__9)) + (
17201
d__10 = d_imag(&h__[k + 2 + (k + 2) * h_dim1])
17202
, abs(d__10))))) {
17203
17204
/*
17205
==== Starting a new bulge here would
17206
. create non-negligible fill. Use
17207
. the old one with trepidation. ====
17208
*/
17209
17210
i__5 = k + 1 + k * h_dim1;
17211
h__[i__5].r = beta.r, h__[i__5].i = beta.i;
17212
i__5 = k + 2 + k * h_dim1;
17213
h__[i__5].r = 0., h__[i__5].i = 0.;
17214
i__5 = k + 3 + k * h_dim1;
17215
h__[i__5].r = 0., h__[i__5].i = 0.;
17216
} else {
17217
17218
/*
17219
==== Stating a new bulge here would
17220
. create only negligible fill.
17221
. Replace the old reflector with
17222
. the new one. ====
17223
*/
17224
17225
i__5 = k + 1 + k * h_dim1;
17226
i__6 = k + 1 + k * h_dim1;
17227
z__1.r = h__[i__6].r - refsum.r, z__1.i = h__[
17228
i__6].i - refsum.i;
17229
h__[i__5].r = z__1.r, h__[i__5].i = z__1.i;
17230
i__5 = k + 2 + k * h_dim1;
17231
h__[i__5].r = 0., h__[i__5].i = 0.;
17232
i__5 = k + 3 + k * h_dim1;
17233
h__[i__5].r = 0., h__[i__5].i = 0.;
17234
i__5 = m * v_dim1 + 1;
17235
v[i__5].r = vt[0].r, v[i__5].i = vt[0].i;
17236
i__5 = m * v_dim1 + 2;
17237
v[i__5].r = vt[1].r, v[i__5].i = vt[1].i;
17238
i__5 = m * v_dim1 + 3;
17239
v[i__5].r = vt[2].r, v[i__5].i = vt[2].i;
17240
}
17241
}
17242
}
17243
/* L10: */
17244
}
17245
17246
/* ==== Generate a 2-by-2 reflection, if needed. ==== */
17247
17248
k = krcol + (m22 - 1) * 3;
17249
if (bmp22) {
17250
if (k == *ktop - 1) {
17251
zlaqr1_(&c__2, &h__[k + 1 + (k + 1) * h_dim1], ldh, &s[(
17252
m22 << 1) - 1], &s[m22 * 2], &v[m22 * v_dim1 + 1])
17253
;
17254
i__4 = m22 * v_dim1 + 1;
17255
beta.r = v[i__4].r, beta.i = v[i__4].i;
17256
zlarfg_(&c__2, &beta, &v[m22 * v_dim1 + 2], &c__1, &v[m22
17257
* v_dim1 + 1]);
17258
} else {
17259
i__4 = k + 1 + k * h_dim1;
17260
beta.r = h__[i__4].r, beta.i = h__[i__4].i;
17261
i__4 = m22 * v_dim1 + 2;
17262
i__5 = k + 2 + k * h_dim1;
17263
v[i__4].r = h__[i__5].r, v[i__4].i = h__[i__5].i;
17264
zlarfg_(&c__2, &beta, &v[m22 * v_dim1 + 2], &c__1, &v[m22
17265
* v_dim1 + 1]);
17266
i__4 = k + 1 + k * h_dim1;
17267
h__[i__4].r = beta.r, h__[i__4].i = beta.i;
17268
i__4 = k + 2 + k * h_dim1;
17269
h__[i__4].r = 0., h__[i__4].i = 0.;
17270
}
17271
}
17272
17273
/* ==== Multiply H by reflections from the left ==== */
17274
17275
if (accum) {
17276
jbot = min(ndcol,*kbot);
17277
} else if (*wantt) {
17278
jbot = *n;
17279
} else {
17280
jbot = *kbot;
17281
}
17282
i__4 = jbot;
17283
for (j = max(*ktop,krcol); j <= i__4; ++j) {
17284
/* Computing MIN */
17285
i__5 = mbot, i__6 = (j - krcol + 2) / 3;
17286
mend = min(i__5,i__6);
17287
i__5 = mend;
17288
for (m = mtop; m <= i__5; ++m) {
17289
k = krcol + (m - 1) * 3;
17290
d_cnjg(&z__2, &v[m * v_dim1 + 1]);
17291
i__6 = k + 1 + j * h_dim1;
17292
d_cnjg(&z__6, &v[m * v_dim1 + 2]);
17293
i__7 = k + 2 + j * h_dim1;
17294
z__5.r = z__6.r * h__[i__7].r - z__6.i * h__[i__7].i,
17295
z__5.i = z__6.r * h__[i__7].i + z__6.i * h__[i__7]
17296
.r;
17297
z__4.r = h__[i__6].r + z__5.r, z__4.i = h__[i__6].i +
17298
z__5.i;
17299
d_cnjg(&z__8, &v[m * v_dim1 + 3]);
17300
i__8 = k + 3 + j * h_dim1;
17301
z__7.r = z__8.r * h__[i__8].r - z__8.i * h__[i__8].i,
17302
z__7.i = z__8.r * h__[i__8].i + z__8.i * h__[i__8]
17303
.r;
17304
z__3.r = z__4.r + z__7.r, z__3.i = z__4.i + z__7.i;
17305
z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i =
17306
z__2.r * z__3.i + z__2.i * z__3.r;
17307
refsum.r = z__1.r, refsum.i = z__1.i;
17308
i__6 = k + 1 + j * h_dim1;
17309
i__7 = k + 1 + j * h_dim1;
17310
z__1.r = h__[i__7].r - refsum.r, z__1.i = h__[i__7].i -
17311
refsum.i;
17312
h__[i__6].r = z__1.r, h__[i__6].i = z__1.i;
17313
i__6 = k + 2 + j * h_dim1;
17314
i__7 = k + 2 + j * h_dim1;
17315
i__8 = m * v_dim1 + 2;
17316
z__2.r = refsum.r * v[i__8].r - refsum.i * v[i__8].i,
17317
z__2.i = refsum.r * v[i__8].i + refsum.i * v[i__8]
17318
.r;
17319
z__1.r = h__[i__7].r - z__2.r, z__1.i = h__[i__7].i -
17320
z__2.i;
17321
h__[i__6].r = z__1.r, h__[i__6].i = z__1.i;
17322
i__6 = k + 3 + j * h_dim1;
17323
i__7 = k + 3 + j * h_dim1;
17324
i__8 = m * v_dim1 + 3;
17325
z__2.r = refsum.r * v[i__8].r - refsum.i * v[i__8].i,
17326
z__2.i = refsum.r * v[i__8].i + refsum.i * v[i__8]
17327
.r;
17328
z__1.r = h__[i__7].r - z__2.r, z__1.i = h__[i__7].i -
17329
z__2.i;
17330
h__[i__6].r = z__1.r, h__[i__6].i = z__1.i;
17331
/* L20: */
17332
}
17333
/* L30: */
17334
}
17335
if (bmp22) {
17336
k = krcol + (m22 - 1) * 3;
17337
/* Computing MAX */
17338
i__4 = k + 1;
17339
i__5 = jbot;
17340
for (j = max(i__4,*ktop); j <= i__5; ++j) {
17341
d_cnjg(&z__2, &v[m22 * v_dim1 + 1]);
17342
i__4 = k + 1 + j * h_dim1;
17343
d_cnjg(&z__5, &v[m22 * v_dim1 + 2]);
17344
i__6 = k + 2 + j * h_dim1;
17345
z__4.r = z__5.r * h__[i__6].r - z__5.i * h__[i__6].i,
17346
z__4.i = z__5.r * h__[i__6].i + z__5.i * h__[i__6]
17347
.r;
17348
z__3.r = h__[i__4].r + z__4.r, z__3.i = h__[i__4].i +
17349
z__4.i;
17350
z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i =
17351
z__2.r * z__3.i + z__2.i * z__3.r;
17352
refsum.r = z__1.r, refsum.i = z__1.i;
17353
i__4 = k + 1 + j * h_dim1;
17354
i__6 = k + 1 + j * h_dim1;
17355
z__1.r = h__[i__6].r - refsum.r, z__1.i = h__[i__6].i -
17356
refsum.i;
17357
h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
17358
i__4 = k + 2 + j * h_dim1;
17359
i__6 = k + 2 + j * h_dim1;
17360
i__7 = m22 * v_dim1 + 2;
17361
z__2.r = refsum.r * v[i__7].r - refsum.i * v[i__7].i,
17362
z__2.i = refsum.r * v[i__7].i + refsum.i * v[i__7]
17363
.r;
17364
z__1.r = h__[i__6].r - z__2.r, z__1.i = h__[i__6].i -
17365
z__2.i;
17366
h__[i__4].r = z__1.r, h__[i__4].i = z__1.i;
17367
/* L40: */
17368
}
17369
}
17370
17371
/*
17372
==== Multiply H by reflections from the right.
17373
. Delay filling in the last row until the
17374
. vigilant deflation check is complete. ====
17375
*/
17376
17377
if (accum) {
17378
jtop = max(*ktop,incol);
17379
} else if (*wantt) {
17380
jtop = 1;
17381
} else {
17382
jtop = *ktop;
17383
}
17384
i__5 = mbot;
17385
for (m = mtop; m <= i__5; ++m) {
17386
i__4 = m * v_dim1 + 1;
17387
if (v[i__4].r != 0. || v[i__4].i != 0.) {
17388
k = krcol + (m - 1) * 3;
17389
/* Computing MIN */
17390
i__6 = *kbot, i__7 = k + 3;
17391
i__4 = min(i__6,i__7);
17392
for (j = jtop; j <= i__4; ++j) {
17393
i__6 = m * v_dim1 + 1;
17394
i__7 = j + (k + 1) * h_dim1;
17395
i__8 = m * v_dim1 + 2;
17396
i__9 = j + (k + 2) * h_dim1;
17397
z__4.r = v[i__8].r * h__[i__9].r - v[i__8].i * h__[
17398
i__9].i, z__4.i = v[i__8].r * h__[i__9].i + v[
17399
i__8].i * h__[i__9].r;
17400
z__3.r = h__[i__7].r + z__4.r, z__3.i = h__[i__7].i +
17401
z__4.i;
17402
i__10 = m * v_dim1 + 3;
17403
i__11 = j + (k + 3) * h_dim1;
17404
z__5.r = v[i__10].r * h__[i__11].r - v[i__10].i * h__[
17405
i__11].i, z__5.i = v[i__10].r * h__[i__11].i
17406
+ v[i__10].i * h__[i__11].r;
17407
z__2.r = z__3.r + z__5.r, z__2.i = z__3.i + z__5.i;
17408
z__1.r = v[i__6].r * z__2.r - v[i__6].i * z__2.i,
17409
z__1.i = v[i__6].r * z__2.i + v[i__6].i *
17410
z__2.r;
17411
refsum.r = z__1.r, refsum.i = z__1.i;
17412
i__6 = j + (k + 1) * h_dim1;
17413
i__7 = j + (k + 1) * h_dim1;
17414
z__1.r = h__[i__7].r - refsum.r, z__1.i = h__[i__7].i
17415
- refsum.i;
17416
h__[i__6].r = z__1.r, h__[i__6].i = z__1.i;
17417
i__6 = j + (k + 2) * h_dim1;
17418
i__7 = j + (k + 2) * h_dim1;
17419
d_cnjg(&z__3, &v[m * v_dim1 + 2]);
17420
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i,
17421
z__2.i = refsum.r * z__3.i + refsum.i *
17422
z__3.r;
17423
z__1.r = h__[i__7].r - z__2.r, z__1.i = h__[i__7].i -
17424
z__2.i;
17425
h__[i__6].r = z__1.r, h__[i__6].i = z__1.i;
17426
i__6 = j + (k + 3) * h_dim1;
17427
i__7 = j + (k + 3) * h_dim1;
17428
d_cnjg(&z__3, &v[m * v_dim1 + 3]);
17429
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i,
17430
z__2.i = refsum.r * z__3.i + refsum.i *
17431
z__3.r;
17432
z__1.r = h__[i__7].r - z__2.r, z__1.i = h__[i__7].i -
17433
z__2.i;
17434
h__[i__6].r = z__1.r, h__[i__6].i = z__1.i;
17435
/* L50: */
17436
}
17437
17438
if (accum) {
17439
17440
/*
17441
==== Accumulate U. (If necessary, update Z later
17442
. with an efficient matrix-matrix
17443
. multiply.) ====
17444
*/
17445
17446
kms = k - incol;
17447
/* Computing MAX */
17448
i__4 = 1, i__6 = *ktop - incol;
17449
i__7 = kdu;
17450
for (j = max(i__4,i__6); j <= i__7; ++j) {
17451
i__4 = m * v_dim1 + 1;
17452
i__6 = j + (kms + 1) * u_dim1;
17453
i__8 = m * v_dim1 + 2;
17454
i__9 = j + (kms + 2) * u_dim1;
17455
z__4.r = v[i__8].r * u[i__9].r - v[i__8].i * u[
17456
i__9].i, z__4.i = v[i__8].r * u[i__9].i +
17457
v[i__8].i * u[i__9].r;
17458
z__3.r = u[i__6].r + z__4.r, z__3.i = u[i__6].i +
17459
z__4.i;
17460
i__10 = m * v_dim1 + 3;
17461
i__11 = j + (kms + 3) * u_dim1;
17462
z__5.r = v[i__10].r * u[i__11].r - v[i__10].i * u[
17463
i__11].i, z__5.i = v[i__10].r * u[i__11]
17464
.i + v[i__10].i * u[i__11].r;
17465
z__2.r = z__3.r + z__5.r, z__2.i = z__3.i +
17466
z__5.i;
17467
z__1.r = v[i__4].r * z__2.r - v[i__4].i * z__2.i,
17468
z__1.i = v[i__4].r * z__2.i + v[i__4].i *
17469
z__2.r;
17470
refsum.r = z__1.r, refsum.i = z__1.i;
17471
i__4 = j + (kms + 1) * u_dim1;
17472
i__6 = j + (kms + 1) * u_dim1;
17473
z__1.r = u[i__6].r - refsum.r, z__1.i = u[i__6].i
17474
- refsum.i;
17475
u[i__4].r = z__1.r, u[i__4].i = z__1.i;
17476
i__4 = j + (kms + 2) * u_dim1;
17477
i__6 = j + (kms + 2) * u_dim1;
17478
d_cnjg(&z__3, &v[m * v_dim1 + 2]);
17479
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i,
17480
z__2.i = refsum.r * z__3.i + refsum.i *
17481
z__3.r;
17482
z__1.r = u[i__6].r - z__2.r, z__1.i = u[i__6].i -
17483
z__2.i;
17484
u[i__4].r = z__1.r, u[i__4].i = z__1.i;
17485
i__4 = j + (kms + 3) * u_dim1;
17486
i__6 = j + (kms + 3) * u_dim1;
17487
d_cnjg(&z__3, &v[m * v_dim1 + 3]);
17488
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i,
17489
z__2.i = refsum.r * z__3.i + refsum.i *
17490
z__3.r;
17491
z__1.r = u[i__6].r - z__2.r, z__1.i = u[i__6].i -
17492
z__2.i;
17493
u[i__4].r = z__1.r, u[i__4].i = z__1.i;
17494
/* L60: */
17495
}
17496
} else if (*wantz) {
17497
17498
/*
17499
==== U is not accumulated, so update Z
17500
. now by multiplying by reflections
17501
. from the right. ====
17502
*/
17503
17504
i__7 = *ihiz;
17505
for (j = *iloz; j <= i__7; ++j) {
17506
i__4 = m * v_dim1 + 1;
17507
i__6 = j + (k + 1) * z_dim1;
17508
i__8 = m * v_dim1 + 2;
17509
i__9 = j + (k + 2) * z_dim1;
17510
z__4.r = v[i__8].r * z__[i__9].r - v[i__8].i *
17511
z__[i__9].i, z__4.i = v[i__8].r * z__[
17512
i__9].i + v[i__8].i * z__[i__9].r;
17513
z__3.r = z__[i__6].r + z__4.r, z__3.i = z__[i__6]
17514
.i + z__4.i;
17515
i__10 = m * v_dim1 + 3;
17516
i__11 = j + (k + 3) * z_dim1;
17517
z__5.r = v[i__10].r * z__[i__11].r - v[i__10].i *
17518
z__[i__11].i, z__5.i = v[i__10].r * z__[
17519
i__11].i + v[i__10].i * z__[i__11].r;
17520
z__2.r = z__3.r + z__5.r, z__2.i = z__3.i +
17521
z__5.i;
17522
z__1.r = v[i__4].r * z__2.r - v[i__4].i * z__2.i,
17523
z__1.i = v[i__4].r * z__2.i + v[i__4].i *
17524
z__2.r;
17525
refsum.r = z__1.r, refsum.i = z__1.i;
17526
i__4 = j + (k + 1) * z_dim1;
17527
i__6 = j + (k + 1) * z_dim1;
17528
z__1.r = z__[i__6].r - refsum.r, z__1.i = z__[
17529
i__6].i - refsum.i;
17530
z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
17531
i__4 = j + (k + 2) * z_dim1;
17532
i__6 = j + (k + 2) * z_dim1;
17533
d_cnjg(&z__3, &v[m * v_dim1 + 2]);
17534
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i,
17535
z__2.i = refsum.r * z__3.i + refsum.i *
17536
z__3.r;
17537
z__1.r = z__[i__6].r - z__2.r, z__1.i = z__[i__6]
17538
.i - z__2.i;
17539
z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
17540
i__4 = j + (k + 3) * z_dim1;
17541
i__6 = j + (k + 3) * z_dim1;
17542
d_cnjg(&z__3, &v[m * v_dim1 + 3]);
17543
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i,
17544
z__2.i = refsum.r * z__3.i + refsum.i *
17545
z__3.r;
17546
z__1.r = z__[i__6].r - z__2.r, z__1.i = z__[i__6]
17547
.i - z__2.i;
17548
z__[i__4].r = z__1.r, z__[i__4].i = z__1.i;
17549
/* L70: */
17550
}
17551
}
17552
}
17553
/* L80: */
17554
}
17555
17556
/* ==== Special case: 2-by-2 reflection (if needed) ==== */
17557
17558
k = krcol + (m22 - 1) * 3;
17559
i__5 = m22 * v_dim1 + 1;
17560
if (bmp22 && (v[i__5].r != 0. || v[i__5].i != 0.)) {
17561
/* Computing MIN */
17562
i__7 = *kbot, i__4 = k + 3;
17563
i__5 = min(i__7,i__4);
17564
for (j = jtop; j <= i__5; ++j) {
17565
i__7 = m22 * v_dim1 + 1;
17566
i__4 = j + (k + 1) * h_dim1;
17567
i__6 = m22 * v_dim1 + 2;
17568
i__8 = j + (k + 2) * h_dim1;
17569
z__3.r = v[i__6].r * h__[i__8].r - v[i__6].i * h__[i__8]
17570
.i, z__3.i = v[i__6].r * h__[i__8].i + v[i__6].i *
17571
h__[i__8].r;
17572
z__2.r = h__[i__4].r + z__3.r, z__2.i = h__[i__4].i +
17573
z__3.i;
17574
z__1.r = v[i__7].r * z__2.r - v[i__7].i * z__2.i, z__1.i =
17575
v[i__7].r * z__2.i + v[i__7].i * z__2.r;
17576
refsum.r = z__1.r, refsum.i = z__1.i;
17577
i__7 = j + (k + 1) * h_dim1;
17578
i__4 = j + (k + 1) * h_dim1;
17579
z__1.r = h__[i__4].r - refsum.r, z__1.i = h__[i__4].i -
17580
refsum.i;
17581
h__[i__7].r = z__1.r, h__[i__7].i = z__1.i;
17582
i__7 = j + (k + 2) * h_dim1;
17583
i__4 = j + (k + 2) * h_dim1;
17584
d_cnjg(&z__3, &v[m22 * v_dim1 + 2]);
17585
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i, z__2.i =
17586
refsum.r * z__3.i + refsum.i * z__3.r;
17587
z__1.r = h__[i__4].r - z__2.r, z__1.i = h__[i__4].i -
17588
z__2.i;
17589
h__[i__7].r = z__1.r, h__[i__7].i = z__1.i;
17590
/* L90: */
17591
}
17592
17593
if (accum) {
17594
kms = k - incol;
17595
/* Computing MAX */
17596
i__5 = 1, i__7 = *ktop - incol;
17597
i__4 = kdu;
17598
for (j = max(i__5,i__7); j <= i__4; ++j) {
17599
i__5 = m22 * v_dim1 + 1;
17600
i__7 = j + (kms + 1) * u_dim1;
17601
i__6 = m22 * v_dim1 + 2;
17602
i__8 = j + (kms + 2) * u_dim1;
17603
z__3.r = v[i__6].r * u[i__8].r - v[i__6].i * u[i__8]
17604
.i, z__3.i = v[i__6].r * u[i__8].i + v[i__6]
17605
.i * u[i__8].r;
17606
z__2.r = u[i__7].r + z__3.r, z__2.i = u[i__7].i +
17607
z__3.i;
17608
z__1.r = v[i__5].r * z__2.r - v[i__5].i * z__2.i,
17609
z__1.i = v[i__5].r * z__2.i + v[i__5].i *
17610
z__2.r;
17611
refsum.r = z__1.r, refsum.i = z__1.i;
17612
i__5 = j + (kms + 1) * u_dim1;
17613
i__7 = j + (kms + 1) * u_dim1;
17614
z__1.r = u[i__7].r - refsum.r, z__1.i = u[i__7].i -
17615
refsum.i;
17616
u[i__5].r = z__1.r, u[i__5].i = z__1.i;
17617
i__5 = j + (kms + 2) * u_dim1;
17618
i__7 = j + (kms + 2) * u_dim1;
17619
d_cnjg(&z__3, &v[m22 * v_dim1 + 2]);
17620
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i,
17621
z__2.i = refsum.r * z__3.i + refsum.i *
17622
z__3.r;
17623
z__1.r = u[i__7].r - z__2.r, z__1.i = u[i__7].i -
17624
z__2.i;
17625
u[i__5].r = z__1.r, u[i__5].i = z__1.i;
17626
/* L100: */
17627
}
17628
} else if (*wantz) {
17629
i__4 = *ihiz;
17630
for (j = *iloz; j <= i__4; ++j) {
17631
i__5 = m22 * v_dim1 + 1;
17632
i__7 = j + (k + 1) * z_dim1;
17633
i__6 = m22 * v_dim1 + 2;
17634
i__8 = j + (k + 2) * z_dim1;
17635
z__3.r = v[i__6].r * z__[i__8].r - v[i__6].i * z__[
17636
i__8].i, z__3.i = v[i__6].r * z__[i__8].i + v[
17637
i__6].i * z__[i__8].r;
17638
z__2.r = z__[i__7].r + z__3.r, z__2.i = z__[i__7].i +
17639
z__3.i;
17640
z__1.r = v[i__5].r * z__2.r - v[i__5].i * z__2.i,
17641
z__1.i = v[i__5].r * z__2.i + v[i__5].i *
17642
z__2.r;
17643
refsum.r = z__1.r, refsum.i = z__1.i;
17644
i__5 = j + (k + 1) * z_dim1;
17645
i__7 = j + (k + 1) * z_dim1;
17646
z__1.r = z__[i__7].r - refsum.r, z__1.i = z__[i__7].i
17647
- refsum.i;
17648
z__[i__5].r = z__1.r, z__[i__5].i = z__1.i;
17649
i__5 = j + (k + 2) * z_dim1;
17650
i__7 = j + (k + 2) * z_dim1;
17651
d_cnjg(&z__3, &v[m22 * v_dim1 + 2]);
17652
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i,
17653
z__2.i = refsum.r * z__3.i + refsum.i *
17654
z__3.r;
17655
z__1.r = z__[i__7].r - z__2.r, z__1.i = z__[i__7].i -
17656
z__2.i;
17657
z__[i__5].r = z__1.r, z__[i__5].i = z__1.i;
17658
/* L110: */
17659
}
17660
}
17661
}
17662
17663
/* ==== Vigilant deflation check ==== */
17664
17665
mstart = mtop;
17666
if (krcol + (mstart - 1) * 3 < *ktop) {
17667
++mstart;
17668
}
17669
mend = mbot;
17670
if (bmp22) {
17671
++mend;
17672
}
17673
if (krcol == *kbot - 2) {
17674
++mend;
17675
}
17676
i__4 = mend;
17677
for (m = mstart; m <= i__4; ++m) {
17678
/* Computing MIN */
17679
i__5 = *kbot - 1, i__7 = krcol + (m - 1) * 3;
17680
k = min(i__5,i__7);
17681
17682
/*
17683
==== The following convergence test requires that
17684
. the tradition small-compared-to-nearby-diagonals
17685
. criterion and the Ahues & Tisseur (LAWN 122, 1997)
17686
. criteria both be satisfied. The latter improves
17687
. accuracy in some examples. Falling back on an
17688
. alternate convergence criterion when TST1 or TST2
17689
. is zero (as done here) is traditional but probably
17690
. unnecessary. ====
17691
*/
17692
17693
i__5 = k + 1 + k * h_dim1;
17694
if (h__[i__5].r != 0. || h__[i__5].i != 0.) {
17695
i__5 = k + k * h_dim1;
17696
i__7 = k + 1 + (k + 1) * h_dim1;
17697
tst1 = (d__1 = h__[i__5].r, abs(d__1)) + (d__2 = d_imag(&
17698
h__[k + k * h_dim1]), abs(d__2)) + ((d__3 = h__[
17699
i__7].r, abs(d__3)) + (d__4 = d_imag(&h__[k + 1 +
17700
(k + 1) * h_dim1]), abs(d__4)));
17701
if (tst1 == 0.) {
17702
if (k >= *ktop + 1) {
17703
i__5 = k + (k - 1) * h_dim1;
17704
tst1 += (d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
17705
d_imag(&h__[k + (k - 1) * h_dim1]), abs(
17706
d__2));
17707
}
17708
if (k >= *ktop + 2) {
17709
i__5 = k + (k - 2) * h_dim1;
17710
tst1 += (d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
17711
d_imag(&h__[k + (k - 2) * h_dim1]), abs(
17712
d__2));
17713
}
17714
if (k >= *ktop + 3) {
17715
i__5 = k + (k - 3) * h_dim1;
17716
tst1 += (d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
17717
d_imag(&h__[k + (k - 3) * h_dim1]), abs(
17718
d__2));
17719
}
17720
if (k <= *kbot - 2) {
17721
i__5 = k + 2 + (k + 1) * h_dim1;
17722
tst1 += (d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
17723
d_imag(&h__[k + 2 + (k + 1) * h_dim1]),
17724
abs(d__2));
17725
}
17726
if (k <= *kbot - 3) {
17727
i__5 = k + 3 + (k + 1) * h_dim1;
17728
tst1 += (d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
17729
d_imag(&h__[k + 3 + (k + 1) * h_dim1]),
17730
abs(d__2));
17731
}
17732
if (k <= *kbot - 4) {
17733
i__5 = k + 4 + (k + 1) * h_dim1;
17734
tst1 += (d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
17735
d_imag(&h__[k + 4 + (k + 1) * h_dim1]),
17736
abs(d__2));
17737
}
17738
}
17739
i__5 = k + 1 + k * h_dim1;
17740
/* Computing MAX */
17741
d__3 = smlnum, d__4 = ulp * tst1;
17742
if ((d__1 = h__[i__5].r, abs(d__1)) + (d__2 = d_imag(&h__[
17743
k + 1 + k * h_dim1]), abs(d__2)) <= max(d__3,d__4)
17744
) {
17745
/* Computing MAX */
17746
i__5 = k + 1 + k * h_dim1;
17747
i__7 = k + (k + 1) * h_dim1;
17748
d__5 = (d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
17749
d_imag(&h__[k + 1 + k * h_dim1]), abs(d__2)),
17750
d__6 = (d__3 = h__[i__7].r, abs(d__3)) + (
17751
d__4 = d_imag(&h__[k + (k + 1) * h_dim1]),
17752
abs(d__4));
17753
h12 = max(d__5,d__6);
17754
/* Computing MIN */
17755
i__5 = k + 1 + k * h_dim1;
17756
i__7 = k + (k + 1) * h_dim1;
17757
d__5 = (d__1 = h__[i__5].r, abs(d__1)) + (d__2 =
17758
d_imag(&h__[k + 1 + k * h_dim1]), abs(d__2)),
17759
d__6 = (d__3 = h__[i__7].r, abs(d__3)) + (
17760
d__4 = d_imag(&h__[k + (k + 1) * h_dim1]),
17761
abs(d__4));
17762
h21 = min(d__5,d__6);
17763
i__5 = k + k * h_dim1;
17764
i__7 = k + 1 + (k + 1) * h_dim1;
17765
z__2.r = h__[i__5].r - h__[i__7].r, z__2.i = h__[i__5]
17766
.i - h__[i__7].i;
17767
z__1.r = z__2.r, z__1.i = z__2.i;
17768
/* Computing MAX */
17769
i__6 = k + 1 + (k + 1) * h_dim1;
17770
d__5 = (d__1 = h__[i__6].r, abs(d__1)) + (d__2 =
17771
d_imag(&h__[k + 1 + (k + 1) * h_dim1]), abs(
17772
d__2)), d__6 = (d__3 = z__1.r, abs(d__3)) + (
17773
d__4 = d_imag(&z__1), abs(d__4));
17774
h11 = max(d__5,d__6);
17775
i__5 = k + k * h_dim1;
17776
i__7 = k + 1 + (k + 1) * h_dim1;
17777
z__2.r = h__[i__5].r - h__[i__7].r, z__2.i = h__[i__5]
17778
.i - h__[i__7].i;
17779
z__1.r = z__2.r, z__1.i = z__2.i;
17780
/* Computing MIN */
17781
i__6 = k + 1 + (k + 1) * h_dim1;
17782
d__5 = (d__1 = h__[i__6].r, abs(d__1)) + (d__2 =
17783
d_imag(&h__[k + 1 + (k + 1) * h_dim1]), abs(
17784
d__2)), d__6 = (d__3 = z__1.r, abs(d__3)) + (
17785
d__4 = d_imag(&z__1), abs(d__4));
17786
h22 = min(d__5,d__6);
17787
scl = h11 + h12;
17788
tst2 = h22 * (h11 / scl);
17789
17790
/* Computing MAX */
17791
d__1 = smlnum, d__2 = ulp * tst2;
17792
if (tst2 == 0. || h21 * (h12 / scl) <= max(d__1,d__2))
17793
{
17794
i__5 = k + 1 + k * h_dim1;
17795
h__[i__5].r = 0., h__[i__5].i = 0.;
17796
}
17797
}
17798
}
17799
/* L120: */
17800
}
17801
17802
/*
17803
==== Fill in the last row of each bulge. ====
17804
17805
Computing MIN
17806
*/
17807
i__4 = nbmps, i__5 = (*kbot - krcol - 1) / 3;
17808
mend = min(i__4,i__5);
17809
i__4 = mend;
17810
for (m = mtop; m <= i__4; ++m) {
17811
k = krcol + (m - 1) * 3;
17812
i__5 = m * v_dim1 + 1;
17813
i__7 = m * v_dim1 + 3;
17814
z__2.r = v[i__5].r * v[i__7].r - v[i__5].i * v[i__7].i,
17815
z__2.i = v[i__5].r * v[i__7].i + v[i__5].i * v[i__7]
17816
.r;
17817
i__6 = k + 4 + (k + 3) * h_dim1;
17818
z__1.r = z__2.r * h__[i__6].r - z__2.i * h__[i__6].i, z__1.i =
17819
z__2.r * h__[i__6].i + z__2.i * h__[i__6].r;
17820
refsum.r = z__1.r, refsum.i = z__1.i;
17821
i__5 = k + 4 + (k + 1) * h_dim1;
17822
z__1.r = -refsum.r, z__1.i = -refsum.i;
17823
h__[i__5].r = z__1.r, h__[i__5].i = z__1.i;
17824
i__5 = k + 4 + (k + 2) * h_dim1;
17825
z__2.r = -refsum.r, z__2.i = -refsum.i;
17826
d_cnjg(&z__3, &v[m * v_dim1 + 2]);
17827
z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i = z__2.r *
17828
z__3.i + z__2.i * z__3.r;
17829
h__[i__5].r = z__1.r, h__[i__5].i = z__1.i;
17830
i__5 = k + 4 + (k + 3) * h_dim1;
17831
i__7 = k + 4 + (k + 3) * h_dim1;
17832
d_cnjg(&z__3, &v[m * v_dim1 + 3]);
17833
z__2.r = refsum.r * z__3.r - refsum.i * z__3.i, z__2.i =
17834
refsum.r * z__3.i + refsum.i * z__3.r;
17835
z__1.r = h__[i__7].r - z__2.r, z__1.i = h__[i__7].i - z__2.i;
17836
h__[i__5].r = z__1.r, h__[i__5].i = z__1.i;
17837
/* L130: */
17838
}
17839
17840
/*
17841
==== End of near-the-diagonal bulge chase. ====
17842
17843
L140:
17844
*/
17845
}
17846
17847
/*
17848
==== Use U (if accumulated) to update far-from-diagonal
17849
. entries in H. If required, use U to update Z as
17850
. well. ====
17851
*/
17852
17853
if (accum) {
17854
if (*wantt) {
17855
jtop = 1;
17856
jbot = *n;
17857
} else {
17858
jtop = *ktop;
17859
jbot = *kbot;
17860
}
17861
if (! blk22 || incol < *ktop || ndcol > *kbot || ns <= 2) {
17862
17863
/*
17864
==== Updates not exploiting the 2-by-2 block
17865
. structure of U. K1 and NU keep track of
17866
. the location and size of U in the special
17867
. cases of introducing bulges and chasing
17868
. bulges off the bottom. In these special
17869
. cases and in case the number of shifts
17870
. is NS = 2, there is no 2-by-2 block
17871
. structure to exploit. ====
17872
17873
Computing MAX
17874
*/
17875
i__3 = 1, i__4 = *ktop - incol;
17876
k1 = max(i__3,i__4);
17877
/* Computing MAX */
17878
i__3 = 0, i__4 = ndcol - *kbot;
17879
nu = kdu - max(i__3,i__4) - k1 + 1;
17880
17881
/* ==== Horizontal Multiply ==== */
17882
17883
i__3 = jbot;
17884
i__4 = *nh;
17885
for (jcol = min(ndcol,*kbot) + 1; i__4 < 0 ? jcol >= i__3 :
17886
jcol <= i__3; jcol += i__4) {
17887
/* Computing MIN */
17888
i__5 = *nh, i__7 = jbot - jcol + 1;
17889
jlen = min(i__5,i__7);
17890
zgemm_("C", "N", &nu, &jlen, &nu, &c_b57, &u[k1 + k1 *
17891
u_dim1], ldu, &h__[incol + k1 + jcol * h_dim1],
17892
ldh, &c_b56, &wh[wh_offset], ldwh);
17893
zlacpy_("ALL", &nu, &jlen, &wh[wh_offset], ldwh, &h__[
17894
incol + k1 + jcol * h_dim1], ldh);
17895
/* L150: */
17896
}
17897
17898
/* ==== Vertical multiply ==== */
17899
17900
i__4 = max(*ktop,incol) - 1;
17901
i__3 = *nv;
17902
for (jrow = jtop; i__3 < 0 ? jrow >= i__4 : jrow <= i__4;
17903
jrow += i__3) {
17904
/* Computing MIN */
17905
i__5 = *nv, i__7 = max(*ktop,incol) - jrow;
17906
jlen = min(i__5,i__7);
17907
zgemm_("N", "N", &jlen, &nu, &nu, &c_b57, &h__[jrow + (
17908
incol + k1) * h_dim1], ldh, &u[k1 + k1 * u_dim1],
17909
ldu, &c_b56, &wv[wv_offset], ldwv);
17910
zlacpy_("ALL", &jlen, &nu, &wv[wv_offset], ldwv, &h__[
17911
jrow + (incol + k1) * h_dim1], ldh);
17912
/* L160: */
17913
}
17914
17915
/* ==== Z multiply (also vertical) ==== */
17916
17917
if (*wantz) {
17918
i__3 = *ihiz;
17919
i__4 = *nv;
17920
for (jrow = *iloz; i__4 < 0 ? jrow >= i__3 : jrow <= i__3;
17921
jrow += i__4) {
17922
/* Computing MIN */
17923
i__5 = *nv, i__7 = *ihiz - jrow + 1;
17924
jlen = min(i__5,i__7);
17925
zgemm_("N", "N", &jlen, &nu, &nu, &c_b57, &z__[jrow +
17926
(incol + k1) * z_dim1], ldz, &u[k1 + k1 *
17927
u_dim1], ldu, &c_b56, &wv[wv_offset], ldwv);
17928
zlacpy_("ALL", &jlen, &nu, &wv[wv_offset], ldwv, &z__[
17929
jrow + (incol + k1) * z_dim1], ldz)
17930
;
17931
/* L170: */
17932
}
17933
}
17934
} else {
17935
17936
/*
17937
==== Updates exploiting U's 2-by-2 block structure.
17938
. (I2, I4, J2, J4 are the last rows and columns
17939
. of the blocks.) ====
17940
*/
17941
17942
i2 = (kdu + 1) / 2;
17943
i4 = kdu;
17944
j2 = i4 - i2;
17945
j4 = kdu;
17946
17947
/*
17948
==== KZS and KNZ deal with the band of zeros
17949
. along the diagonal of one of the triangular
17950
. blocks. ====
17951
*/
17952
17953
kzs = j4 - j2 - (ns + 1);
17954
knz = ns + 1;
17955
17956
/* ==== Horizontal multiply ==== */
17957
17958
i__4 = jbot;
17959
i__3 = *nh;
17960
for (jcol = min(ndcol,*kbot) + 1; i__3 < 0 ? jcol >= i__4 :
17961
jcol <= i__4; jcol += i__3) {
17962
/* Computing MIN */
17963
i__5 = *nh, i__7 = jbot - jcol + 1;
17964
jlen = min(i__5,i__7);
17965
17966
/*
17967
==== Copy bottom of H to top+KZS of scratch ====
17968
(The first KZS rows get multiplied by zero.) ====
17969
*/
17970
17971
zlacpy_("ALL", &knz, &jlen, &h__[incol + 1 + j2 + jcol *
17972
h_dim1], ldh, &wh[kzs + 1 + wh_dim1], ldwh);
17973
17974
/* ==== Multiply by U21' ==== */
17975
17976
zlaset_("ALL", &kzs, &jlen, &c_b56, &c_b56, &wh[wh_offset]
17977
, ldwh);
17978
ztrmm_("L", "U", "C", "N", &knz, &jlen, &c_b57, &u[j2 + 1
17979
+ (kzs + 1) * u_dim1], ldu, &wh[kzs + 1 + wh_dim1]
17980
, ldwh);
17981
17982
/* ==== Multiply top of H by U11' ==== */
17983
17984
zgemm_("C", "N", &i2, &jlen, &j2, &c_b57, &u[u_offset],
17985
ldu, &h__[incol + 1 + jcol * h_dim1], ldh, &c_b57,
17986
&wh[wh_offset], ldwh);
17987
17988
/* ==== Copy top of H to bottom of WH ==== */
17989
17990
zlacpy_("ALL", &j2, &jlen, &h__[incol + 1 + jcol * h_dim1]
17991
, ldh, &wh[i2 + 1 + wh_dim1], ldwh);
17992
17993
/* ==== Multiply by U21' ==== */
17994
17995
ztrmm_("L", "L", "C", "N", &j2, &jlen, &c_b57, &u[(i2 + 1)
17996
* u_dim1 + 1], ldu, &wh[i2 + 1 + wh_dim1], ldwh);
17997
17998
/* ==== Multiply by U22 ==== */
17999
18000
i__5 = i4 - i2;
18001
i__7 = j4 - j2;
18002
zgemm_("C", "N", &i__5, &jlen, &i__7, &c_b57, &u[j2 + 1 +
18003
(i2 + 1) * u_dim1], ldu, &h__[incol + 1 + j2 +
18004
jcol * h_dim1], ldh, &c_b57, &wh[i2 + 1 + wh_dim1]
18005
, ldwh);
18006
18007
/* ==== Copy it back ==== */
18008
18009
zlacpy_("ALL", &kdu, &jlen, &wh[wh_offset], ldwh, &h__[
18010
incol + 1 + jcol * h_dim1], ldh);
18011
/* L180: */
18012
}
18013
18014
/* ==== Vertical multiply ==== */
18015
18016
i__3 = max(incol,*ktop) - 1;
18017
i__4 = *nv;
18018
for (jrow = jtop; i__4 < 0 ? jrow >= i__3 : jrow <= i__3;
18019
jrow += i__4) {
18020
/* Computing MIN */
18021
i__5 = *nv, i__7 = max(incol,*ktop) - jrow;
18022
jlen = min(i__5,i__7);
18023
18024
/*
18025
==== Copy right of H to scratch (the first KZS
18026
. columns get multiplied by zero) ====
18027
*/
18028
18029
zlacpy_("ALL", &jlen, &knz, &h__[jrow + (incol + 1 + j2) *
18030
h_dim1], ldh, &wv[(kzs + 1) * wv_dim1 + 1], ldwv);
18031
18032
/* ==== Multiply by U21 ==== */
18033
18034
zlaset_("ALL", &jlen, &kzs, &c_b56, &c_b56, &wv[wv_offset]
18035
, ldwv);
18036
ztrmm_("R", "U", "N", "N", &jlen, &knz, &c_b57, &u[j2 + 1
18037
+ (kzs + 1) * u_dim1], ldu, &wv[(kzs + 1) *
18038
wv_dim1 + 1], ldwv);
18039
18040
/* ==== Multiply by U11 ==== */
18041
18042
zgemm_("N", "N", &jlen, &i2, &j2, &c_b57, &h__[jrow + (
18043
incol + 1) * h_dim1], ldh, &u[u_offset], ldu, &
18044
c_b57, &wv[wv_offset], ldwv)
18045
;
18046
18047
/* ==== Copy left of H to right of scratch ==== */
18048
18049
zlacpy_("ALL", &jlen, &j2, &h__[jrow + (incol + 1) *
18050
h_dim1], ldh, &wv[(i2 + 1) * wv_dim1 + 1], ldwv);
18051
18052
/* ==== Multiply by U21 ==== */
18053
18054
i__5 = i4 - i2;
18055
ztrmm_("R", "L", "N", "N", &jlen, &i__5, &c_b57, &u[(i2 +
18056
1) * u_dim1 + 1], ldu, &wv[(i2 + 1) * wv_dim1 + 1]
18057
, ldwv);
18058
18059
/* ==== Multiply by U22 ==== */
18060
18061
i__5 = i4 - i2;
18062
i__7 = j4 - j2;
18063
zgemm_("N", "N", &jlen, &i__5, &i__7, &c_b57, &h__[jrow +
18064
(incol + 1 + j2) * h_dim1], ldh, &u[j2 + 1 + (i2
18065
+ 1) * u_dim1], ldu, &c_b57, &wv[(i2 + 1) *
18066
wv_dim1 + 1], ldwv);
18067
18068
/* ==== Copy it back ==== */
18069
18070
zlacpy_("ALL", &jlen, &kdu, &wv[wv_offset], ldwv, &h__[
18071
jrow + (incol + 1) * h_dim1], ldh);
18072
/* L190: */
18073
}
18074
18075
/* ==== Multiply Z (also vertical) ==== */
18076
18077
if (*wantz) {
18078
i__4 = *ihiz;
18079
i__3 = *nv;
18080
for (jrow = *iloz; i__3 < 0 ? jrow >= i__4 : jrow <= i__4;
18081
jrow += i__3) {
18082
/* Computing MIN */
18083
i__5 = *nv, i__7 = *ihiz - jrow + 1;
18084
jlen = min(i__5,i__7);
18085
18086
/*
18087
==== Copy right of Z to left of scratch (first
18088
. KZS columns get multiplied by zero) ====
18089
*/
18090
18091
zlacpy_("ALL", &jlen, &knz, &z__[jrow + (incol + 1 +
18092
j2) * z_dim1], ldz, &wv[(kzs + 1) * wv_dim1 +
18093
1], ldwv);
18094
18095
/* ==== Multiply by U12 ==== */
18096
18097
zlaset_("ALL", &jlen, &kzs, &c_b56, &c_b56, &wv[
18098
wv_offset], ldwv);
18099
ztrmm_("R", "U", "N", "N", &jlen, &knz, &c_b57, &u[j2
18100
+ 1 + (kzs + 1) * u_dim1], ldu, &wv[(kzs + 1)
18101
* wv_dim1 + 1], ldwv);
18102
18103
/* ==== Multiply by U11 ==== */
18104
18105
zgemm_("N", "N", &jlen, &i2, &j2, &c_b57, &z__[jrow +
18106
(incol + 1) * z_dim1], ldz, &u[u_offset], ldu,
18107
&c_b57, &wv[wv_offset], ldwv);
18108
18109
/* ==== Copy left of Z to right of scratch ==== */
18110
18111
zlacpy_("ALL", &jlen, &j2, &z__[jrow + (incol + 1) *
18112
z_dim1], ldz, &wv[(i2 + 1) * wv_dim1 + 1],
18113
ldwv);
18114
18115
/* ==== Multiply by U21 ==== */
18116
18117
i__5 = i4 - i2;
18118
ztrmm_("R", "L", "N", "N", &jlen, &i__5, &c_b57, &u[(
18119
i2 + 1) * u_dim1 + 1], ldu, &wv[(i2 + 1) *
18120
wv_dim1 + 1], ldwv);
18121
18122
/* ==== Multiply by U22 ==== */
18123
18124
i__5 = i4 - i2;
18125
i__7 = j4 - j2;
18126
zgemm_("N", "N", &jlen, &i__5, &i__7, &c_b57, &z__[
18127
jrow + (incol + 1 + j2) * z_dim1], ldz, &u[j2
18128
+ 1 + (i2 + 1) * u_dim1], ldu, &c_b57, &wv[(
18129
i2 + 1) * wv_dim1 + 1], ldwv);
18130
18131
/* ==== Copy the result back to Z ==== */
18132
18133
zlacpy_("ALL", &jlen, &kdu, &wv[wv_offset], ldwv, &
18134
z__[jrow + (incol + 1) * z_dim1], ldz);
18135
/* L200: */
18136
}
18137
}
18138
}
18139
}
18140
/* L210: */
18141
}
18142
18143
/* ==== End of ZLAQR5 ==== */
18144
18145
return 0;
18146
} /* zlaqr5_ */
18147
18148
/* Subroutine */ int zlarcm_(integer *m, integer *n, doublereal *a, integer *
18149
lda, doublecomplex *b, integer *ldb, doublecomplex *c__, integer *ldc,
18150
doublereal *rwork)
18151
{
18152
/* System generated locals */
18153
integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2,
18154
i__3, i__4, i__5;
18155
doublereal d__1;
18156
doublecomplex z__1;
18157
18158
/* Local variables */
18159
static integer i__, j, l;
18160
extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *,
18161
integer *, doublereal *, doublereal *, integer *, doublereal *,
18162
integer *, doublereal *, doublereal *, integer *);
18163
18164
18165
/*
18166
-- LAPACK auxiliary routine (version 3.2) --
18167
-- LAPACK is a software package provided by Univ. of Tennessee, --
18168
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
18169
November 2006
18170
18171
18172
Purpose
18173
=======
18174
18175
ZLARCM performs a very simple matrix-matrix multiplication:
18176
C := A * B,
18177
where A is M by M and real; B is M by N and complex;
18178
C is M by N and complex.
18179
18180
Arguments
18181
=========
18182
18183
M (input) INTEGER
18184
The number of rows of the matrix A and of the matrix C.
18185
M >= 0.
18186
18187
N (input) INTEGER
18188
The number of columns and rows of the matrix B and
18189
the number of columns of the matrix C.
18190
N >= 0.
18191
18192
A (input) DOUBLE PRECISION array, dimension (LDA, M)
18193
A contains the M by M matrix A.
18194
18195
LDA (input) INTEGER
18196
The leading dimension of the array A. LDA >=max(1,M).
18197
18198
B (input) DOUBLE PRECISION array, dimension (LDB, N)
18199
B contains the M by N matrix B.
18200
18201
LDB (input) INTEGER
18202
The leading dimension of the array B. LDB >=max(1,M).
18203
18204
C (input) COMPLEX*16 array, dimension (LDC, N)
18205
C contains the M by N matrix C.
18206
18207
LDC (input) INTEGER
18208
The leading dimension of the array C. LDC >=max(1,M).
18209
18210
RWORK (workspace) DOUBLE PRECISION array, dimension (2*M*N)
18211
18212
=====================================================================
18213
18214
18215
Quick return if possible.
18216
*/
18217
18218
/* Parameter adjustments */
18219
a_dim1 = *lda;
18220
a_offset = 1 + a_dim1;
18221
a -= a_offset;
18222
b_dim1 = *ldb;
18223
b_offset = 1 + b_dim1;
18224
b -= b_offset;
18225
c_dim1 = *ldc;
18226
c_offset = 1 + c_dim1;
18227
c__ -= c_offset;
18228
--rwork;
18229
18230
/* Function Body */
18231
if (*m == 0 || *n == 0) {
18232
return 0;
18233
}
18234
18235
i__1 = *n;
18236
for (j = 1; j <= i__1; ++j) {
18237
i__2 = *m;
18238
for (i__ = 1; i__ <= i__2; ++i__) {
18239
i__3 = i__ + j * b_dim1;
18240
rwork[(j - 1) * *m + i__] = b[i__3].r;
18241
/* L10: */
18242
}
18243
/* L20: */
18244
}
18245
18246
l = *m * *n + 1;
18247
dgemm_("N", "N", m, n, m, &c_b1034, &a[a_offset], lda, &rwork[1], m, &
18248
c_b328, &rwork[l], m);
18249
i__1 = *n;
18250
for (j = 1; j <= i__1; ++j) {
18251
i__2 = *m;
18252
for (i__ = 1; i__ <= i__2; ++i__) {
18253
i__3 = i__ + j * c_dim1;
18254
i__4 = l + (j - 1) * *m + i__ - 1;
18255
c__[i__3].r = rwork[i__4], c__[i__3].i = 0.;
18256
/* L30: */
18257
}
18258
/* L40: */
18259
}
18260
18261
i__1 = *n;
18262
for (j = 1; j <= i__1; ++j) {
18263
i__2 = *m;
18264
for (i__ = 1; i__ <= i__2; ++i__) {
18265
rwork[(j - 1) * *m + i__] = d_imag(&b[i__ + j * b_dim1]);
18266
/* L50: */
18267
}
18268
/* L60: */
18269
}
18270
dgemm_("N", "N", m, n, m, &c_b1034, &a[a_offset], lda, &rwork[1], m, &
18271
c_b328, &rwork[l], m);
18272
i__1 = *n;
18273
for (j = 1; j <= i__1; ++j) {
18274
i__2 = *m;
18275
for (i__ = 1; i__ <= i__2; ++i__) {
18276
i__3 = i__ + j * c_dim1;
18277
i__4 = i__ + j * c_dim1;
18278
d__1 = c__[i__4].r;
18279
i__5 = l + (j - 1) * *m + i__ - 1;
18280
z__1.r = d__1, z__1.i = rwork[i__5];
18281
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
18282
/* L70: */
18283
}
18284
/* L80: */
18285
}
18286
18287
return 0;
18288
18289
/* End of ZLARCM */
18290
18291
} /* zlarcm_ */
18292
18293
/* Subroutine */ int zlarf_(char *side, integer *m, integer *n, doublecomplex
18294
*v, integer *incv, doublecomplex *tau, doublecomplex *c__, integer *
18295
ldc, doublecomplex *work)
18296
{
18297
/* System generated locals */
18298
integer c_dim1, c_offset, i__1;
18299
doublecomplex z__1;
18300
18301
/* Local variables */
18302
static integer i__;
18303
static logical applyleft;
18304
extern logical lsame_(char *, char *);
18305
static integer lastc;
18306
extern /* Subroutine */ int zgerc_(integer *, integer *, doublecomplex *,
18307
doublecomplex *, integer *, doublecomplex *, integer *,
18308
doublecomplex *, integer *), zgemv_(char *, integer *, integer *,
18309
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
18310
integer *, doublecomplex *, doublecomplex *, integer *);
18311
static integer lastv;
18312
extern integer ilazlc_(integer *, integer *, doublecomplex *, integer *),
18313
ilazlr_(integer *, integer *, doublecomplex *, integer *);
18314
18315
18316
/*
18317
-- LAPACK auxiliary routine (version 3.2) --
18318
-- LAPACK is a software package provided by Univ. of Tennessee, --
18319
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
18320
November 2006
18321
18322
18323
Purpose
18324
=======
18325
18326
ZLARF applies a complex elementary reflector H to a complex M-by-N
18327
matrix C, from either the left or the right. H is represented in the
18328
form
18329
18330
H = I - tau * v * v'
18331
18332
where tau is a complex scalar and v is a complex vector.
18333
18334
If tau = 0, then H is taken to be the unit matrix.
18335
18336
To apply H' (the conjugate transpose of H), supply conjg(tau) instead
18337
tau.
18338
18339
Arguments
18340
=========
18341
18342
SIDE (input) CHARACTER*1
18343
= 'L': form H * C
18344
= 'R': form C * H
18345
18346
M (input) INTEGER
18347
The number of rows of the matrix C.
18348
18349
N (input) INTEGER
18350
The number of columns of the matrix C.
18351
18352
V (input) COMPLEX*16 array, dimension
18353
(1 + (M-1)*abs(INCV)) if SIDE = 'L'
18354
or (1 + (N-1)*abs(INCV)) if SIDE = 'R'
18355
The vector v in the representation of H. V is not used if
18356
TAU = 0.
18357
18358
INCV (input) INTEGER
18359
The increment between elements of v. INCV <> 0.
18360
18361
TAU (input) COMPLEX*16
18362
The value tau in the representation of H.
18363
18364
C (input/output) COMPLEX*16 array, dimension (LDC,N)
18365
On entry, the M-by-N matrix C.
18366
On exit, C is overwritten by the matrix H * C if SIDE = 'L',
18367
or C * H if SIDE = 'R'.
18368
18369
LDC (input) INTEGER
18370
The leading dimension of the array C. LDC >= max(1,M).
18371
18372
WORK (workspace) COMPLEX*16 array, dimension
18373
(N) if SIDE = 'L'
18374
or (M) if SIDE = 'R'
18375
18376
=====================================================================
18377
*/
18378
18379
18380
/* Parameter adjustments */
18381
--v;
18382
c_dim1 = *ldc;
18383
c_offset = 1 + c_dim1;
18384
c__ -= c_offset;
18385
--work;
18386
18387
/* Function Body */
18388
applyleft = lsame_(side, "L");
18389
lastv = 0;
18390
lastc = 0;
18391
if (tau->r != 0. || tau->i != 0.) {
18392
/*
18393
Set up variables for scanning V. LASTV begins pointing to the end
18394
of V.
18395
*/
18396
if (applyleft) {
18397
lastv = *m;
18398
} else {
18399
lastv = *n;
18400
}
18401
if (*incv > 0) {
18402
i__ = (lastv - 1) * *incv + 1;
18403
} else {
18404
i__ = 1;
18405
}
18406
/* Look for the last non-zero row in V. */
18407
for(;;) { /* while(complicated condition) */
18408
i__1 = i__;
18409
if (!(lastv > 0 && (v[i__1].r == 0. && v[i__1].i == 0.)))
18410
break;
18411
--lastv;
18412
i__ -= *incv;
18413
}
18414
if (applyleft) {
18415
/* Scan for the last non-zero column in C(1:lastv,:). */
18416
lastc = ilazlc_(&lastv, n, &c__[c_offset], ldc);
18417
} else {
18418
/* Scan for the last non-zero row in C(:,1:lastv). */
18419
lastc = ilazlr_(m, &lastv, &c__[c_offset], ldc);
18420
}
18421
}
18422
/*
18423
Note that lastc.eq.0 renders the BLAS operations null; no special
18424
case is needed at this level.
18425
*/
18426
if (applyleft) {
18427
18428
/* Form H * C */
18429
18430
if (lastv > 0) {
18431
18432
/* w(1:lastc,1) := C(1:lastv,1:lastc)' * v(1:lastv,1) */
18433
18434
zgemv_("Conjugate transpose", &lastv, &lastc, &c_b57, &c__[
18435
c_offset], ldc, &v[1], incv, &c_b56, &work[1], &c__1);
18436
18437
/* C(1:lastv,1:lastc) := C(...) - v(1:lastv,1) * w(1:lastc,1)' */
18438
18439
z__1.r = -tau->r, z__1.i = -tau->i;
18440
zgerc_(&lastv, &lastc, &z__1, &v[1], incv, &work[1], &c__1, &c__[
18441
c_offset], ldc);
18442
}
18443
} else {
18444
18445
/* Form C * H */
18446
18447
if (lastv > 0) {
18448
18449
/* w(1:lastc,1) := C(1:lastc,1:lastv) * v(1:lastv,1) */
18450
18451
zgemv_("No transpose", &lastc, &lastv, &c_b57, &c__[c_offset],
18452
ldc, &v[1], incv, &c_b56, &work[1], &c__1);
18453
18454
/* C(1:lastc,1:lastv) := C(...) - w(1:lastc,1) * v(1:lastv,1)' */
18455
18456
z__1.r = -tau->r, z__1.i = -tau->i;
18457
zgerc_(&lastc, &lastv, &z__1, &work[1], &c__1, &v[1], incv, &c__[
18458
c_offset], ldc);
18459
}
18460
}
18461
return 0;
18462
18463
/* End of ZLARF */
18464
18465
} /* zlarf_ */
18466
18467
/* Subroutine */ int zlarfb_(char *side, char *trans, char *direct, char *
18468
storev, integer *m, integer *n, integer *k, doublecomplex *v, integer
18469
*ldv, doublecomplex *t, integer *ldt, doublecomplex *c__, integer *
18470
ldc, doublecomplex *work, integer *ldwork)
18471
{
18472
/* System generated locals */
18473
integer c_dim1, c_offset, t_dim1, t_offset, v_dim1, v_offset, work_dim1,
18474
work_offset, i__1, i__2, i__3, i__4, i__5;
18475
doublecomplex z__1, z__2;
18476
18477
/* Local variables */
18478
static integer i__, j;
18479
extern logical lsame_(char *, char *);
18480
static integer lastc;
18481
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
18482
integer *, doublecomplex *, doublecomplex *, integer *,
18483
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
18484
integer *);
18485
static integer lastv;
18486
extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
18487
doublecomplex *, integer *), ztrmm_(char *, char *, char *, char *
18488
, integer *, integer *, doublecomplex *, doublecomplex *, integer
18489
*, doublecomplex *, integer *);
18490
extern integer ilazlc_(integer *, integer *, doublecomplex *, integer *);
18491
extern /* Subroutine */ int zlacgv_(integer *, doublecomplex *, integer *)
18492
;
18493
extern integer ilazlr_(integer *, integer *, doublecomplex *, integer *);
18494
static char transt[1];
18495
18496
18497
/*
18498
-- LAPACK auxiliary routine (version 3.2) --
18499
-- LAPACK is a software package provided by Univ. of Tennessee, --
18500
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
18501
November 2006
18502
18503
18504
Purpose
18505
=======
18506
18507
ZLARFB applies a complex block reflector H or its transpose H' to a
18508
complex M-by-N matrix C, from either the left or the right.
18509
18510
Arguments
18511
=========
18512
18513
SIDE (input) CHARACTER*1
18514
= 'L': apply H or H' from the Left
18515
= 'R': apply H or H' from the Right
18516
18517
TRANS (input) CHARACTER*1
18518
= 'N': apply H (No transpose)
18519
= 'C': apply H' (Conjugate transpose)
18520
18521
DIRECT (input) CHARACTER*1
18522
Indicates how H is formed from a product of elementary
18523
reflectors
18524
= 'F': H = H(1) H(2) . . . H(k) (Forward)
18525
= 'B': H = H(k) . . . H(2) H(1) (Backward)
18526
18527
STOREV (input) CHARACTER*1
18528
Indicates how the vectors which define the elementary
18529
reflectors are stored:
18530
= 'C': Columnwise
18531
= 'R': Rowwise
18532
18533
M (input) INTEGER
18534
The number of rows of the matrix C.
18535
18536
N (input) INTEGER
18537
The number of columns of the matrix C.
18538
18539
K (input) INTEGER
18540
The order of the matrix T (= the number of elementary
18541
reflectors whose product defines the block reflector).
18542
18543
V (input) COMPLEX*16 array, dimension
18544
(LDV,K) if STOREV = 'C'
18545
(LDV,M) if STOREV = 'R' and SIDE = 'L'
18546
(LDV,N) if STOREV = 'R' and SIDE = 'R'
18547
The matrix V. See further details.
18548
18549
LDV (input) INTEGER
18550
The leading dimension of the array V.
18551
If STOREV = 'C' and SIDE = 'L', LDV >= max(1,M);
18552
if STOREV = 'C' and SIDE = 'R', LDV >= max(1,N);
18553
if STOREV = 'R', LDV >= K.
18554
18555
T (input) COMPLEX*16 array, dimension (LDT,K)
18556
The triangular K-by-K matrix T in the representation of the
18557
block reflector.
18558
18559
LDT (input) INTEGER
18560
The leading dimension of the array T. LDT >= K.
18561
18562
C (input/output) COMPLEX*16 array, dimension (LDC,N)
18563
On entry, the M-by-N matrix C.
18564
On exit, C is overwritten by H*C or H'*C or C*H or C*H'.
18565
18566
LDC (input) INTEGER
18567
The leading dimension of the array C. LDC >= max(1,M).
18568
18569
WORK (workspace) COMPLEX*16 array, dimension (LDWORK,K)
18570
18571
LDWORK (input) INTEGER
18572
The leading dimension of the array WORK.
18573
If SIDE = 'L', LDWORK >= max(1,N);
18574
if SIDE = 'R', LDWORK >= max(1,M).
18575
18576
=====================================================================
18577
18578
18579
Quick return if possible
18580
*/
18581
18582
/* Parameter adjustments */
18583
v_dim1 = *ldv;
18584
v_offset = 1 + v_dim1;
18585
v -= v_offset;
18586
t_dim1 = *ldt;
18587
t_offset = 1 + t_dim1;
18588
t -= t_offset;
18589
c_dim1 = *ldc;
18590
c_offset = 1 + c_dim1;
18591
c__ -= c_offset;
18592
work_dim1 = *ldwork;
18593
work_offset = 1 + work_dim1;
18594
work -= work_offset;
18595
18596
/* Function Body */
18597
if (*m <= 0 || *n <= 0) {
18598
return 0;
18599
}
18600
18601
if (lsame_(trans, "N")) {
18602
*(unsigned char *)transt = 'C';
18603
} else {
18604
*(unsigned char *)transt = 'N';
18605
}
18606
18607
if (lsame_(storev, "C")) {
18608
18609
if (lsame_(direct, "F")) {
18610
18611
/*
18612
Let V = ( V1 ) (first K rows)
18613
( V2 )
18614
where V1 is unit lower triangular.
18615
*/
18616
18617
if (lsame_(side, "L")) {
18618
18619
/*
18620
Form H * C or H' * C where C = ( C1 )
18621
( C2 )
18622
18623
Computing MAX
18624
*/
18625
i__1 = *k, i__2 = ilazlr_(m, k, &v[v_offset], ldv);
18626
lastv = max(i__1,i__2);
18627
lastc = ilazlc_(&lastv, n, &c__[c_offset], ldc);
18628
18629
/*
18630
W := C' * V = (C1'*V1 + C2'*V2) (stored in WORK)
18631
18632
W := C1'
18633
*/
18634
18635
i__1 = *k;
18636
for (j = 1; j <= i__1; ++j) {
18637
zcopy_(&lastc, &c__[j + c_dim1], ldc, &work[j * work_dim1
18638
+ 1], &c__1);
18639
zlacgv_(&lastc, &work[j * work_dim1 + 1], &c__1);
18640
/* L10: */
18641
}
18642
18643
/* W := W * V1 */
18644
18645
ztrmm_("Right", "Lower", "No transpose", "Unit", &lastc, k, &
18646
c_b57, &v[v_offset], ldv, &work[work_offset], ldwork);
18647
if (lastv > *k) {
18648
18649
/* W := W + C2'*V2 */
18650
18651
i__1 = lastv - *k;
18652
zgemm_("Conjugate transpose", "No transpose", &lastc, k, &
18653
i__1, &c_b57, &c__[*k + 1 + c_dim1], ldc, &v[*k +
18654
1 + v_dim1], ldv, &c_b57, &work[work_offset],
18655
ldwork);
18656
}
18657
18658
/* W := W * T' or W * T */
18659
18660
ztrmm_("Right", "Upper", transt, "Non-unit", &lastc, k, &
18661
c_b57, &t[t_offset], ldt, &work[work_offset], ldwork);
18662
18663
/* C := C - V * W' */
18664
18665
if (*m > *k) {
18666
18667
/* C2 := C2 - V2 * W' */
18668
18669
i__1 = lastv - *k;
18670
z__1.r = -1., z__1.i = -0.;
18671
zgemm_("No transpose", "Conjugate transpose", &i__1, &
18672
lastc, k, &z__1, &v[*k + 1 + v_dim1], ldv, &work[
18673
work_offset], ldwork, &c_b57, &c__[*k + 1 +
18674
c_dim1], ldc);
18675
}
18676
18677
/* W := W * V1' */
18678
18679
ztrmm_("Right", "Lower", "Conjugate transpose", "Unit", &
18680
lastc, k, &c_b57, &v[v_offset], ldv, &work[
18681
work_offset], ldwork);
18682
18683
/* C1 := C1 - W' */
18684
18685
i__1 = *k;
18686
for (j = 1; j <= i__1; ++j) {
18687
i__2 = lastc;
18688
for (i__ = 1; i__ <= i__2; ++i__) {
18689
i__3 = j + i__ * c_dim1;
18690
i__4 = j + i__ * c_dim1;
18691
d_cnjg(&z__2, &work[i__ + j * work_dim1]);
18692
z__1.r = c__[i__4].r - z__2.r, z__1.i = c__[i__4].i -
18693
z__2.i;
18694
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
18695
/* L20: */
18696
}
18697
/* L30: */
18698
}
18699
18700
} else if (lsame_(side, "R")) {
18701
18702
/*
18703
Form C * H or C * H' where C = ( C1 C2 )
18704
18705
Computing MAX
18706
*/
18707
i__1 = *k, i__2 = ilazlr_(n, k, &v[v_offset], ldv);
18708
lastv = max(i__1,i__2);
18709
lastc = ilazlr_(m, &lastv, &c__[c_offset], ldc);
18710
18711
/*
18712
W := C * V = (C1*V1 + C2*V2) (stored in WORK)
18713
18714
W := C1
18715
*/
18716
18717
i__1 = *k;
18718
for (j = 1; j <= i__1; ++j) {
18719
zcopy_(&lastc, &c__[j * c_dim1 + 1], &c__1, &work[j *
18720
work_dim1 + 1], &c__1);
18721
/* L40: */
18722
}
18723
18724
/* W := W * V1 */
18725
18726
ztrmm_("Right", "Lower", "No transpose", "Unit", &lastc, k, &
18727
c_b57, &v[v_offset], ldv, &work[work_offset], ldwork);
18728
if (lastv > *k) {
18729
18730
/* W := W + C2 * V2 */
18731
18732
i__1 = lastv - *k;
18733
zgemm_("No transpose", "No transpose", &lastc, k, &i__1, &
18734
c_b57, &c__[(*k + 1) * c_dim1 + 1], ldc, &v[*k +
18735
1 + v_dim1], ldv, &c_b57, &work[work_offset],
18736
ldwork);
18737
}
18738
18739
/* W := W * T or W * T' */
18740
18741
ztrmm_("Right", "Upper", trans, "Non-unit", &lastc, k, &c_b57,
18742
&t[t_offset], ldt, &work[work_offset], ldwork);
18743
18744
/* C := C - W * V' */
18745
18746
if (lastv > *k) {
18747
18748
/* C2 := C2 - W * V2' */
18749
18750
i__1 = lastv - *k;
18751
z__1.r = -1., z__1.i = -0.;
18752
zgemm_("No transpose", "Conjugate transpose", &lastc, &
18753
i__1, k, &z__1, &work[work_offset], ldwork, &v[*k
18754
+ 1 + v_dim1], ldv, &c_b57, &c__[(*k + 1) *
18755
c_dim1 + 1], ldc);
18756
}
18757
18758
/* W := W * V1' */
18759
18760
ztrmm_("Right", "Lower", "Conjugate transpose", "Unit", &
18761
lastc, k, &c_b57, &v[v_offset], ldv, &work[
18762
work_offset], ldwork);
18763
18764
/* C1 := C1 - W */
18765
18766
i__1 = *k;
18767
for (j = 1; j <= i__1; ++j) {
18768
i__2 = lastc;
18769
for (i__ = 1; i__ <= i__2; ++i__) {
18770
i__3 = i__ + j * c_dim1;
18771
i__4 = i__ + j * c_dim1;
18772
i__5 = i__ + j * work_dim1;
18773
z__1.r = c__[i__4].r - work[i__5].r, z__1.i = c__[
18774
i__4].i - work[i__5].i;
18775
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
18776
/* L50: */
18777
}
18778
/* L60: */
18779
}
18780
}
18781
18782
} else {
18783
18784
/*
18785
Let V = ( V1 )
18786
( V2 ) (last K rows)
18787
where V2 is unit upper triangular.
18788
*/
18789
18790
if (lsame_(side, "L")) {
18791
18792
/*
18793
Form H * C or H' * C where C = ( C1 )
18794
( C2 )
18795
18796
Computing MAX
18797
*/
18798
i__1 = *k, i__2 = ilazlr_(m, k, &v[v_offset], ldv);
18799
lastv = max(i__1,i__2);
18800
lastc = ilazlc_(&lastv, n, &c__[c_offset], ldc);
18801
18802
/*
18803
W := C' * V = (C1'*V1 + C2'*V2) (stored in WORK)
18804
18805
W := C2'
18806
*/
18807
18808
i__1 = *k;
18809
for (j = 1; j <= i__1; ++j) {
18810
zcopy_(&lastc, &c__[lastv - *k + j + c_dim1], ldc, &work[
18811
j * work_dim1 + 1], &c__1);
18812
zlacgv_(&lastc, &work[j * work_dim1 + 1], &c__1);
18813
/* L70: */
18814
}
18815
18816
/* W := W * V2 */
18817
18818
ztrmm_("Right", "Upper", "No transpose", "Unit", &lastc, k, &
18819
c_b57, &v[lastv - *k + 1 + v_dim1], ldv, &work[
18820
work_offset], ldwork);
18821
if (lastv > *k) {
18822
18823
/* W := W + C1'*V1 */
18824
18825
i__1 = lastv - *k;
18826
zgemm_("Conjugate transpose", "No transpose", &lastc, k, &
18827
i__1, &c_b57, &c__[c_offset], ldc, &v[v_offset],
18828
ldv, &c_b57, &work[work_offset], ldwork);
18829
}
18830
18831
/* W := W * T' or W * T */
18832
18833
ztrmm_("Right", "Lower", transt, "Non-unit", &lastc, k, &
18834
c_b57, &t[t_offset], ldt, &work[work_offset], ldwork);
18835
18836
/* C := C - V * W' */
18837
18838
if (lastv > *k) {
18839
18840
/* C1 := C1 - V1 * W' */
18841
18842
i__1 = lastv - *k;
18843
z__1.r = -1., z__1.i = -0.;
18844
zgemm_("No transpose", "Conjugate transpose", &i__1, &
18845
lastc, k, &z__1, &v[v_offset], ldv, &work[
18846
work_offset], ldwork, &c_b57, &c__[c_offset], ldc);
18847
}
18848
18849
/* W := W * V2' */
18850
18851
ztrmm_("Right", "Upper", "Conjugate transpose", "Unit", &
18852
lastc, k, &c_b57, &v[lastv - *k + 1 + v_dim1], ldv, &
18853
work[work_offset], ldwork);
18854
18855
/* C2 := C2 - W' */
18856
18857
i__1 = *k;
18858
for (j = 1; j <= i__1; ++j) {
18859
i__2 = lastc;
18860
for (i__ = 1; i__ <= i__2; ++i__) {
18861
i__3 = lastv - *k + j + i__ * c_dim1;
18862
i__4 = lastv - *k + j + i__ * c_dim1;
18863
d_cnjg(&z__2, &work[i__ + j * work_dim1]);
18864
z__1.r = c__[i__4].r - z__2.r, z__1.i = c__[i__4].i -
18865
z__2.i;
18866
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
18867
/* L80: */
18868
}
18869
/* L90: */
18870
}
18871
18872
} else if (lsame_(side, "R")) {
18873
18874
/*
18875
Form C * H or C * H' where C = ( C1 C2 )
18876
18877
Computing MAX
18878
*/
18879
i__1 = *k, i__2 = ilazlr_(n, k, &v[v_offset], ldv);
18880
lastv = max(i__1,i__2);
18881
lastc = ilazlr_(m, &lastv, &c__[c_offset], ldc);
18882
18883
/*
18884
W := C * V = (C1*V1 + C2*V2) (stored in WORK)
18885
18886
W := C2
18887
*/
18888
18889
i__1 = *k;
18890
for (j = 1; j <= i__1; ++j) {
18891
zcopy_(&lastc, &c__[(lastv - *k + j) * c_dim1 + 1], &c__1,
18892
&work[j * work_dim1 + 1], &c__1);
18893
/* L100: */
18894
}
18895
18896
/* W := W * V2 */
18897
18898
ztrmm_("Right", "Upper", "No transpose", "Unit", &lastc, k, &
18899
c_b57, &v[lastv - *k + 1 + v_dim1], ldv, &work[
18900
work_offset], ldwork);
18901
if (lastv > *k) {
18902
18903
/* W := W + C1 * V1 */
18904
18905
i__1 = lastv - *k;
18906
zgemm_("No transpose", "No transpose", &lastc, k, &i__1, &
18907
c_b57, &c__[c_offset], ldc, &v[v_offset], ldv, &
18908
c_b57, &work[work_offset], ldwork);
18909
}
18910
18911
/* W := W * T or W * T' */
18912
18913
ztrmm_("Right", "Lower", trans, "Non-unit", &lastc, k, &c_b57,
18914
&t[t_offset], ldt, &work[work_offset], ldwork);
18915
18916
/* C := C - W * V' */
18917
18918
if (lastv > *k) {
18919
18920
/* C1 := C1 - W * V1' */
18921
18922
i__1 = lastv - *k;
18923
z__1.r = -1., z__1.i = -0.;
18924
zgemm_("No transpose", "Conjugate transpose", &lastc, &
18925
i__1, k, &z__1, &work[work_offset], ldwork, &v[
18926
v_offset], ldv, &c_b57, &c__[c_offset], ldc);
18927
}
18928
18929
/* W := W * V2' */
18930
18931
ztrmm_("Right", "Upper", "Conjugate transpose", "Unit", &
18932
lastc, k, &c_b57, &v[lastv - *k + 1 + v_dim1], ldv, &
18933
work[work_offset], ldwork);
18934
18935
/* C2 := C2 - W */
18936
18937
i__1 = *k;
18938
for (j = 1; j <= i__1; ++j) {
18939
i__2 = lastc;
18940
for (i__ = 1; i__ <= i__2; ++i__) {
18941
i__3 = i__ + (lastv - *k + j) * c_dim1;
18942
i__4 = i__ + (lastv - *k + j) * c_dim1;
18943
i__5 = i__ + j * work_dim1;
18944
z__1.r = c__[i__4].r - work[i__5].r, z__1.i = c__[
18945
i__4].i - work[i__5].i;
18946
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
18947
/* L110: */
18948
}
18949
/* L120: */
18950
}
18951
}
18952
}
18953
18954
} else if (lsame_(storev, "R")) {
18955
18956
if (lsame_(direct, "F")) {
18957
18958
/*
18959
Let V = ( V1 V2 ) (V1: first K columns)
18960
where V1 is unit upper triangular.
18961
*/
18962
18963
if (lsame_(side, "L")) {
18964
18965
/*
18966
Form H * C or H' * C where C = ( C1 )
18967
( C2 )
18968
18969
Computing MAX
18970
*/
18971
i__1 = *k, i__2 = ilazlc_(k, m, &v[v_offset], ldv);
18972
lastv = max(i__1,i__2);
18973
lastc = ilazlc_(&lastv, n, &c__[c_offset], ldc);
18974
18975
/*
18976
W := C' * V' = (C1'*V1' + C2'*V2') (stored in WORK)
18977
18978
W := C1'
18979
*/
18980
18981
i__1 = *k;
18982
for (j = 1; j <= i__1; ++j) {
18983
zcopy_(&lastc, &c__[j + c_dim1], ldc, &work[j * work_dim1
18984
+ 1], &c__1);
18985
zlacgv_(&lastc, &work[j * work_dim1 + 1], &c__1);
18986
/* L130: */
18987
}
18988
18989
/* W := W * V1' */
18990
18991
ztrmm_("Right", "Upper", "Conjugate transpose", "Unit", &
18992
lastc, k, &c_b57, &v[v_offset], ldv, &work[
18993
work_offset], ldwork);
18994
if (lastv > *k) {
18995
18996
/* W := W + C2'*V2' */
18997
18998
i__1 = lastv - *k;
18999
zgemm_("Conjugate transpose", "Conjugate transpose", &
19000
lastc, k, &i__1, &c_b57, &c__[*k + 1 + c_dim1],
19001
ldc, &v[(*k + 1) * v_dim1 + 1], ldv, &c_b57, &
19002
work[work_offset], ldwork)
19003
;
19004
}
19005
19006
/* W := W * T' or W * T */
19007
19008
ztrmm_("Right", "Upper", transt, "Non-unit", &lastc, k, &
19009
c_b57, &t[t_offset], ldt, &work[work_offset], ldwork);
19010
19011
/* C := C - V' * W' */
19012
19013
if (lastv > *k) {
19014
19015
/* C2 := C2 - V2' * W' */
19016
19017
i__1 = lastv - *k;
19018
z__1.r = -1., z__1.i = -0.;
19019
zgemm_("Conjugate transpose", "Conjugate transpose", &
19020
i__1, &lastc, k, &z__1, &v[(*k + 1) * v_dim1 + 1],
19021
ldv, &work[work_offset], ldwork, &c_b57, &c__[*k
19022
+ 1 + c_dim1], ldc);
19023
}
19024
19025
/* W := W * V1 */
19026
19027
ztrmm_("Right", "Upper", "No transpose", "Unit", &lastc, k, &
19028
c_b57, &v[v_offset], ldv, &work[work_offset], ldwork);
19029
19030
/* C1 := C1 - W' */
19031
19032
i__1 = *k;
19033
for (j = 1; j <= i__1; ++j) {
19034
i__2 = lastc;
19035
for (i__ = 1; i__ <= i__2; ++i__) {
19036
i__3 = j + i__ * c_dim1;
19037
i__4 = j + i__ * c_dim1;
19038
d_cnjg(&z__2, &work[i__ + j * work_dim1]);
19039
z__1.r = c__[i__4].r - z__2.r, z__1.i = c__[i__4].i -
19040
z__2.i;
19041
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
19042
/* L140: */
19043
}
19044
/* L150: */
19045
}
19046
19047
} else if (lsame_(side, "R")) {
19048
19049
/*
19050
Form C * H or C * H' where C = ( C1 C2 )
19051
19052
Computing MAX
19053
*/
19054
i__1 = *k, i__2 = ilazlc_(k, n, &v[v_offset], ldv);
19055
lastv = max(i__1,i__2);
19056
lastc = ilazlr_(m, &lastv, &c__[c_offset], ldc);
19057
19058
/*
19059
W := C * V' = (C1*V1' + C2*V2') (stored in WORK)
19060
19061
W := C1
19062
*/
19063
19064
i__1 = *k;
19065
for (j = 1; j <= i__1; ++j) {
19066
zcopy_(&lastc, &c__[j * c_dim1 + 1], &c__1, &work[j *
19067
work_dim1 + 1], &c__1);
19068
/* L160: */
19069
}
19070
19071
/* W := W * V1' */
19072
19073
ztrmm_("Right", "Upper", "Conjugate transpose", "Unit", &
19074
lastc, k, &c_b57, &v[v_offset], ldv, &work[
19075
work_offset], ldwork);
19076
if (lastv > *k) {
19077
19078
/* W := W + C2 * V2' */
19079
19080
i__1 = lastv - *k;
19081
zgemm_("No transpose", "Conjugate transpose", &lastc, k, &
19082
i__1, &c_b57, &c__[(*k + 1) * c_dim1 + 1], ldc, &
19083
v[(*k + 1) * v_dim1 + 1], ldv, &c_b57, &work[
19084
work_offset], ldwork);
19085
}
19086
19087
/* W := W * T or W * T' */
19088
19089
ztrmm_("Right", "Upper", trans, "Non-unit", &lastc, k, &c_b57,
19090
&t[t_offset], ldt, &work[work_offset], ldwork);
19091
19092
/* C := C - W * V */
19093
19094
if (lastv > *k) {
19095
19096
/* C2 := C2 - W * V2 */
19097
19098
i__1 = lastv - *k;
19099
z__1.r = -1., z__1.i = -0.;
19100
zgemm_("No transpose", "No transpose", &lastc, &i__1, k, &
19101
z__1, &work[work_offset], ldwork, &v[(*k + 1) *
19102
v_dim1 + 1], ldv, &c_b57, &c__[(*k + 1) * c_dim1
19103
+ 1], ldc);
19104
}
19105
19106
/* W := W * V1 */
19107
19108
ztrmm_("Right", "Upper", "No transpose", "Unit", &lastc, k, &
19109
c_b57, &v[v_offset], ldv, &work[work_offset], ldwork);
19110
19111
/* C1 := C1 - W */
19112
19113
i__1 = *k;
19114
for (j = 1; j <= i__1; ++j) {
19115
i__2 = lastc;
19116
for (i__ = 1; i__ <= i__2; ++i__) {
19117
i__3 = i__ + j * c_dim1;
19118
i__4 = i__ + j * c_dim1;
19119
i__5 = i__ + j * work_dim1;
19120
z__1.r = c__[i__4].r - work[i__5].r, z__1.i = c__[
19121
i__4].i - work[i__5].i;
19122
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
19123
/* L170: */
19124
}
19125
/* L180: */
19126
}
19127
19128
}
19129
19130
} else {
19131
19132
/*
19133
Let V = ( V1 V2 ) (V2: last K columns)
19134
where V2 is unit lower triangular.
19135
*/
19136
19137
if (lsame_(side, "L")) {
19138
19139
/*
19140
Form H * C or H' * C where C = ( C1 )
19141
( C2 )
19142
19143
Computing MAX
19144
*/
19145
i__1 = *k, i__2 = ilazlc_(k, m, &v[v_offset], ldv);
19146
lastv = max(i__1,i__2);
19147
lastc = ilazlc_(&lastv, n, &c__[c_offset], ldc);
19148
19149
/*
19150
W := C' * V' = (C1'*V1' + C2'*V2') (stored in WORK)
19151
19152
W := C2'
19153
*/
19154
19155
i__1 = *k;
19156
for (j = 1; j <= i__1; ++j) {
19157
zcopy_(&lastc, &c__[lastv - *k + j + c_dim1], ldc, &work[
19158
j * work_dim1 + 1], &c__1);
19159
zlacgv_(&lastc, &work[j * work_dim1 + 1], &c__1);
19160
/* L190: */
19161
}
19162
19163
/* W := W * V2' */
19164
19165
ztrmm_("Right", "Lower", "Conjugate transpose", "Unit", &
19166
lastc, k, &c_b57, &v[(lastv - *k + 1) * v_dim1 + 1],
19167
ldv, &work[work_offset], ldwork);
19168
if (lastv > *k) {
19169
19170
/* W := W + C1'*V1' */
19171
19172
i__1 = lastv - *k;
19173
zgemm_("Conjugate transpose", "Conjugate transpose", &
19174
lastc, k, &i__1, &c_b57, &c__[c_offset], ldc, &v[
19175
v_offset], ldv, &c_b57, &work[work_offset],
19176
ldwork);
19177
}
19178
19179
/* W := W * T' or W * T */
19180
19181
ztrmm_("Right", "Lower", transt, "Non-unit", &lastc, k, &
19182
c_b57, &t[t_offset], ldt, &work[work_offset], ldwork);
19183
19184
/* C := C - V' * W' */
19185
19186
if (lastv > *k) {
19187
19188
/* C1 := C1 - V1' * W' */
19189
19190
i__1 = lastv - *k;
19191
z__1.r = -1., z__1.i = -0.;
19192
zgemm_("Conjugate transpose", "Conjugate transpose", &
19193
i__1, &lastc, k, &z__1, &v[v_offset], ldv, &work[
19194
work_offset], ldwork, &c_b57, &c__[c_offset], ldc);
19195
}
19196
19197
/* W := W * V2 */
19198
19199
ztrmm_("Right", "Lower", "No transpose", "Unit", &lastc, k, &
19200
c_b57, &v[(lastv - *k + 1) * v_dim1 + 1], ldv, &work[
19201
work_offset], ldwork);
19202
19203
/* C2 := C2 - W' */
19204
19205
i__1 = *k;
19206
for (j = 1; j <= i__1; ++j) {
19207
i__2 = lastc;
19208
for (i__ = 1; i__ <= i__2; ++i__) {
19209
i__3 = lastv - *k + j + i__ * c_dim1;
19210
i__4 = lastv - *k + j + i__ * c_dim1;
19211
d_cnjg(&z__2, &work[i__ + j * work_dim1]);
19212
z__1.r = c__[i__4].r - z__2.r, z__1.i = c__[i__4].i -
19213
z__2.i;
19214
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
19215
/* L200: */
19216
}
19217
/* L210: */
19218
}
19219
19220
} else if (lsame_(side, "R")) {
19221
19222
/*
19223
Form C * H or C * H' where C = ( C1 C2 )
19224
19225
Computing MAX
19226
*/
19227
i__1 = *k, i__2 = ilazlc_(k, n, &v[v_offset], ldv);
19228
lastv = max(i__1,i__2);
19229
lastc = ilazlr_(m, &lastv, &c__[c_offset], ldc);
19230
19231
/*
19232
W := C * V' = (C1*V1' + C2*V2') (stored in WORK)
19233
19234
W := C2
19235
*/
19236
19237
i__1 = *k;
19238
for (j = 1; j <= i__1; ++j) {
19239
zcopy_(&lastc, &c__[(lastv - *k + j) * c_dim1 + 1], &c__1,
19240
&work[j * work_dim1 + 1], &c__1);
19241
/* L220: */
19242
}
19243
19244
/* W := W * V2' */
19245
19246
ztrmm_("Right", "Lower", "Conjugate transpose", "Unit", &
19247
lastc, k, &c_b57, &v[(lastv - *k + 1) * v_dim1 + 1],
19248
ldv, &work[work_offset], ldwork);
19249
if (lastv > *k) {
19250
19251
/* W := W + C1 * V1' */
19252
19253
i__1 = lastv - *k;
19254
zgemm_("No transpose", "Conjugate transpose", &lastc, k, &
19255
i__1, &c_b57, &c__[c_offset], ldc, &v[v_offset],
19256
ldv, &c_b57, &work[work_offset], ldwork);
19257
}
19258
19259
/* W := W * T or W * T' */
19260
19261
ztrmm_("Right", "Lower", trans, "Non-unit", &lastc, k, &c_b57,
19262
&t[t_offset], ldt, &work[work_offset], ldwork);
19263
19264
/* C := C - W * V */
19265
19266
if (lastv > *k) {
19267
19268
/* C1 := C1 - W * V1 */
19269
19270
i__1 = lastv - *k;
19271
z__1.r = -1., z__1.i = -0.;
19272
zgemm_("No transpose", "No transpose", &lastc, &i__1, k, &
19273
z__1, &work[work_offset], ldwork, &v[v_offset],
19274
ldv, &c_b57, &c__[c_offset], ldc);
19275
}
19276
19277
/* W := W * V2 */
19278
19279
ztrmm_("Right", "Lower", "No transpose", "Unit", &lastc, k, &
19280
c_b57, &v[(lastv - *k + 1) * v_dim1 + 1], ldv, &work[
19281
work_offset], ldwork);
19282
19283
/* C1 := C1 - W */
19284
19285
i__1 = *k;
19286
for (j = 1; j <= i__1; ++j) {
19287
i__2 = lastc;
19288
for (i__ = 1; i__ <= i__2; ++i__) {
19289
i__3 = i__ + (lastv - *k + j) * c_dim1;
19290
i__4 = i__ + (lastv - *k + j) * c_dim1;
19291
i__5 = i__ + j * work_dim1;
19292
z__1.r = c__[i__4].r - work[i__5].r, z__1.i = c__[
19293
i__4].i - work[i__5].i;
19294
c__[i__3].r = z__1.r, c__[i__3].i = z__1.i;
19295
/* L230: */
19296
}
19297
/* L240: */
19298
}
19299
19300
}
19301
19302
}
19303
}
19304
19305
return 0;
19306
19307
/* End of ZLARFB */
19308
19309
} /* zlarfb_ */
19310
19311
/* Subroutine */ int zlarfg_(integer *n, doublecomplex *alpha, doublecomplex *
19312
x, integer *incx, doublecomplex *tau)
19313
{
19314
/* System generated locals */
19315
integer i__1;
19316
doublereal d__1, d__2;
19317
doublecomplex z__1, z__2;
19318
19319
/* Local variables */
19320
static integer j, knt;
19321
static doublereal beta, alphi, alphr;
19322
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
19323
doublecomplex *, integer *);
19324
static doublereal xnorm;
19325
extern doublereal dlapy3_(doublereal *, doublereal *, doublereal *),
19326
dznrm2_(integer *, doublecomplex *, integer *), dlamch_(char *);
19327
static doublereal safmin;
19328
extern /* Subroutine */ int zdscal_(integer *, doublereal *,
19329
doublecomplex *, integer *);
19330
static doublereal rsafmn;
19331
extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
19332
doublecomplex *);
19333
19334
19335
/*
19336
-- LAPACK auxiliary routine (version 3.2) --
19337
-- LAPACK is a software package provided by Univ. of Tennessee, --
19338
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
19339
November 2006
19340
19341
19342
Purpose
19343
=======
19344
19345
ZLARFG generates a complex elementary reflector H of order n, such
19346
that
19347
19348
H' * ( alpha ) = ( beta ), H' * H = I.
19349
( x ) ( 0 )
19350
19351
where alpha and beta are scalars, with beta real, and x is an
19352
(n-1)-element complex vector. H is represented in the form
19353
19354
H = I - tau * ( 1 ) * ( 1 v' ) ,
19355
( v )
19356
19357
where tau is a complex scalar and v is a complex (n-1)-element
19358
vector. Note that H is not hermitian.
19359
19360
If the elements of x are all zero and alpha is real, then tau = 0
19361
and H is taken to be the unit matrix.
19362
19363
Otherwise 1 <= real(tau) <= 2 and abs(tau-1) <= 1 .
19364
19365
Arguments
19366
=========
19367
19368
N (input) INTEGER
19369
The order of the elementary reflector.
19370
19371
ALPHA (input/output) COMPLEX*16
19372
On entry, the value alpha.
19373
On exit, it is overwritten with the value beta.
19374
19375
X (input/output) COMPLEX*16 array, dimension
19376
(1+(N-2)*abs(INCX))
19377
On entry, the vector x.
19378
On exit, it is overwritten with the vector v.
19379
19380
INCX (input) INTEGER
19381
The increment between elements of X. INCX > 0.
19382
19383
TAU (output) COMPLEX*16
19384
The value tau.
19385
19386
=====================================================================
19387
*/
19388
19389
19390
/* Parameter adjustments */
19391
--x;
19392
19393
/* Function Body */
19394
if (*n <= 0) {
19395
tau->r = 0., tau->i = 0.;
19396
return 0;
19397
}
19398
19399
i__1 = *n - 1;
19400
xnorm = dznrm2_(&i__1, &x[1], incx);
19401
alphr = alpha->r;
19402
alphi = d_imag(alpha);
19403
19404
if (xnorm == 0. && alphi == 0.) {
19405
19406
/* H = I */
19407
19408
tau->r = 0., tau->i = 0.;
19409
} else {
19410
19411
/* general case */
19412
19413
d__1 = dlapy3_(&alphr, &alphi, &xnorm);
19414
beta = -d_sign(&d__1, &alphr);
19415
safmin = SAFEMINIMUM / EPSILON;
19416
rsafmn = 1. / safmin;
19417
19418
knt = 0;
19419
if (abs(beta) < safmin) {
19420
19421
/* XNORM, BETA may be inaccurate; scale X and recompute them */
19422
19423
L10:
19424
++knt;
19425
i__1 = *n - 1;
19426
zdscal_(&i__1, &rsafmn, &x[1], incx);
19427
beta *= rsafmn;
19428
alphi *= rsafmn;
19429
alphr *= rsafmn;
19430
if (abs(beta) < safmin) {
19431
goto L10;
19432
}
19433
19434
/* New BETA is at most 1, at least SAFMIN */
19435
19436
i__1 = *n - 1;
19437
xnorm = dznrm2_(&i__1, &x[1], incx);
19438
z__1.r = alphr, z__1.i = alphi;
19439
alpha->r = z__1.r, alpha->i = z__1.i;
19440
d__1 = dlapy3_(&alphr, &alphi, &xnorm);
19441
beta = -d_sign(&d__1, &alphr);
19442
}
19443
d__1 = (beta - alphr) / beta;
19444
d__2 = -alphi / beta;
19445
z__1.r = d__1, z__1.i = d__2;
19446
tau->r = z__1.r, tau->i = z__1.i;
19447
z__2.r = alpha->r - beta, z__2.i = alpha->i;
19448
zladiv_(&z__1, &c_b57, &z__2);
19449
alpha->r = z__1.r, alpha->i = z__1.i;
19450
i__1 = *n - 1;
19451
zscal_(&i__1, alpha, &x[1], incx);
19452
19453
/* If ALPHA is subnormal, it may lose relative accuracy */
19454
19455
i__1 = knt;
19456
for (j = 1; j <= i__1; ++j) {
19457
beta *= safmin;
19458
/* L20: */
19459
}
19460
alpha->r = beta, alpha->i = 0.;
19461
}
19462
19463
return 0;
19464
19465
/* End of ZLARFG */
19466
19467
} /* zlarfg_ */
19468
19469
/* Subroutine */ int zlarft_(char *direct, char *storev, integer *n, integer *
19470
k, doublecomplex *v, integer *ldv, doublecomplex *tau, doublecomplex *
19471
t, integer *ldt)
19472
{
19473
/* System generated locals */
19474
integer t_dim1, t_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4;
19475
doublecomplex z__1;
19476
19477
/* Local variables */
19478
static integer i__, j, prevlastv;
19479
static doublecomplex vii;
19480
extern logical lsame_(char *, char *);
19481
extern /* Subroutine */ int zgemv_(char *, integer *, integer *,
19482
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
19483
integer *, doublecomplex *, doublecomplex *, integer *);
19484
static integer lastv;
19485
extern /* Subroutine */ int ztrmv_(char *, char *, char *, integer *,
19486
doublecomplex *, integer *, doublecomplex *, integer *), zlacgv_(integer *, doublecomplex *, integer *);
19487
19488
19489
/*
19490
-- LAPACK auxiliary routine (version 3.2) --
19491
-- LAPACK is a software package provided by Univ. of Tennessee, --
19492
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
19493
November 2006
19494
19495
19496
Purpose
19497
=======
19498
19499
ZLARFT forms the triangular factor T of a complex block reflector H
19500
of order n, which is defined as a product of k elementary reflectors.
19501
19502
If DIRECT = 'F', H = H(1) H(2) . . . H(k) and T is upper triangular;
19503
19504
If DIRECT = 'B', H = H(k) . . . H(2) H(1) and T is lower triangular.
19505
19506
If STOREV = 'C', the vector which defines the elementary reflector
19507
H(i) is stored in the i-th column of the array V, and
19508
19509
H = I - V * T * V'
19510
19511
If STOREV = 'R', the vector which defines the elementary reflector
19512
H(i) is stored in the i-th row of the array V, and
19513
19514
H = I - V' * T * V
19515
19516
Arguments
19517
=========
19518
19519
DIRECT (input) CHARACTER*1
19520
Specifies the order in which the elementary reflectors are
19521
multiplied to form the block reflector:
19522
= 'F': H = H(1) H(2) . . . H(k) (Forward)
19523
= 'B': H = H(k) . . . H(2) H(1) (Backward)
19524
19525
STOREV (input) CHARACTER*1
19526
Specifies how the vectors which define the elementary
19527
reflectors are stored (see also Further Details):
19528
= 'C': columnwise
19529
= 'R': rowwise
19530
19531
N (input) INTEGER
19532
The order of the block reflector H. N >= 0.
19533
19534
K (input) INTEGER
19535
The order of the triangular factor T (= the number of
19536
elementary reflectors). K >= 1.
19537
19538
V (input/output) COMPLEX*16 array, dimension
19539
(LDV,K) if STOREV = 'C'
19540
(LDV,N) if STOREV = 'R'
19541
The matrix V. See further details.
19542
19543
LDV (input) INTEGER
19544
The leading dimension of the array V.
19545
If STOREV = 'C', LDV >= max(1,N); if STOREV = 'R', LDV >= K.
19546
19547
TAU (input) COMPLEX*16 array, dimension (K)
19548
TAU(i) must contain the scalar factor of the elementary
19549
reflector H(i).
19550
19551
T (output) COMPLEX*16 array, dimension (LDT,K)
19552
The k by k triangular factor T of the block reflector.
19553
If DIRECT = 'F', T is upper triangular; if DIRECT = 'B', T is
19554
lower triangular. The rest of the array is not used.
19555
19556
LDT (input) INTEGER
19557
The leading dimension of the array T. LDT >= K.
19558
19559
Further Details
19560
===============
19561
19562
The shape of the matrix V and the storage of the vectors which define
19563
the H(i) is best illustrated by the following example with n = 5 and
19564
k = 3. The elements equal to 1 are not stored; the corresponding
19565
array elements are modified but restored on exit. The rest of the
19566
array is not used.
19567
19568
DIRECT = 'F' and STOREV = 'C': DIRECT = 'F' and STOREV = 'R':
19569
19570
V = ( 1 ) V = ( 1 v1 v1 v1 v1 )
19571
( v1 1 ) ( 1 v2 v2 v2 )
19572
( v1 v2 1 ) ( 1 v3 v3 )
19573
( v1 v2 v3 )
19574
( v1 v2 v3 )
19575
19576
DIRECT = 'B' and STOREV = 'C': DIRECT = 'B' and STOREV = 'R':
19577
19578
V = ( v1 v2 v3 ) V = ( v1 v1 1 )
19579
( v1 v2 v3 ) ( v2 v2 v2 1 )
19580
( 1 v2 v3 ) ( v3 v3 v3 v3 1 )
19581
( 1 v3 )
19582
( 1 )
19583
19584
=====================================================================
19585
19586
19587
Quick return if possible
19588
*/
19589
19590
/* Parameter adjustments */
19591
v_dim1 = *ldv;
19592
v_offset = 1 + v_dim1;
19593
v -= v_offset;
19594
--tau;
19595
t_dim1 = *ldt;
19596
t_offset = 1 + t_dim1;
19597
t -= t_offset;
19598
19599
/* Function Body */
19600
if (*n == 0) {
19601
return 0;
19602
}
19603
19604
if (lsame_(direct, "F")) {
19605
prevlastv = *n;
19606
i__1 = *k;
19607
for (i__ = 1; i__ <= i__1; ++i__) {
19608
prevlastv = max(prevlastv,i__);
19609
i__2 = i__;
19610
if (tau[i__2].r == 0. && tau[i__2].i == 0.) {
19611
19612
/* H(i) = I */
19613
19614
i__2 = i__;
19615
for (j = 1; j <= i__2; ++j) {
19616
i__3 = j + i__ * t_dim1;
19617
t[i__3].r = 0., t[i__3].i = 0.;
19618
/* L10: */
19619
}
19620
} else {
19621
19622
/* general case */
19623
19624
i__2 = i__ + i__ * v_dim1;
19625
vii.r = v[i__2].r, vii.i = v[i__2].i;
19626
i__2 = i__ + i__ * v_dim1;
19627
v[i__2].r = 1., v[i__2].i = 0.;
19628
if (lsame_(storev, "C")) {
19629
/* Skip any trailing zeros. */
19630
i__2 = i__ + 1;
19631
for (lastv = *n; lastv >= i__2; --lastv) {
19632
i__3 = lastv + i__ * v_dim1;
19633
if (v[i__3].r != 0. || v[i__3].i != 0.) {
19634
goto L15;
19635
}
19636
}
19637
L15:
19638
j = min(lastv,prevlastv);
19639
19640
/* T(1:i-1,i) := - tau(i) * V(i:j,1:i-1)' * V(i:j,i) */
19641
19642
i__2 = j - i__ + 1;
19643
i__3 = i__ - 1;
19644
i__4 = i__;
19645
z__1.r = -tau[i__4].r, z__1.i = -tau[i__4].i;
19646
zgemv_("Conjugate transpose", &i__2, &i__3, &z__1, &v[i__
19647
+ v_dim1], ldv, &v[i__ + i__ * v_dim1], &c__1, &
19648
c_b56, &t[i__ * t_dim1 + 1], &c__1);
19649
} else {
19650
/* Skip any trailing zeros. */
19651
i__2 = i__ + 1;
19652
for (lastv = *n; lastv >= i__2; --lastv) {
19653
i__3 = i__ + lastv * v_dim1;
19654
if (v[i__3].r != 0. || v[i__3].i != 0.) {
19655
goto L16;
19656
}
19657
}
19658
L16:
19659
j = min(lastv,prevlastv);
19660
19661
/* T(1:i-1,i) := - tau(i) * V(1:i-1,i:j) * V(i,i:j)' */
19662
19663
if (i__ < j) {
19664
i__2 = j - i__;
19665
zlacgv_(&i__2, &v[i__ + (i__ + 1) * v_dim1], ldv);
19666
}
19667
i__2 = i__ - 1;
19668
i__3 = j - i__ + 1;
19669
i__4 = i__;
19670
z__1.r = -tau[i__4].r, z__1.i = -tau[i__4].i;
19671
zgemv_("No transpose", &i__2, &i__3, &z__1, &v[i__ *
19672
v_dim1 + 1], ldv, &v[i__ + i__ * v_dim1], ldv, &
19673
c_b56, &t[i__ * t_dim1 + 1], &c__1);
19674
if (i__ < j) {
19675
i__2 = j - i__;
19676
zlacgv_(&i__2, &v[i__ + (i__ + 1) * v_dim1], ldv);
19677
}
19678
}
19679
i__2 = i__ + i__ * v_dim1;
19680
v[i__2].r = vii.r, v[i__2].i = vii.i;
19681
19682
/* T(1:i-1,i) := T(1:i-1,1:i-1) * T(1:i-1,i) */
19683
19684
i__2 = i__ - 1;
19685
ztrmv_("Upper", "No transpose", "Non-unit", &i__2, &t[
19686
t_offset], ldt, &t[i__ * t_dim1 + 1], &c__1);
19687
i__2 = i__ + i__ * t_dim1;
19688
i__3 = i__;
19689
t[i__2].r = tau[i__3].r, t[i__2].i = tau[i__3].i;
19690
if (i__ > 1) {
19691
prevlastv = max(prevlastv,lastv);
19692
} else {
19693
prevlastv = lastv;
19694
}
19695
}
19696
/* L20: */
19697
}
19698
} else {
19699
prevlastv = 1;
19700
for (i__ = *k; i__ >= 1; --i__) {
19701
i__1 = i__;
19702
if (tau[i__1].r == 0. && tau[i__1].i == 0.) {
19703
19704
/* H(i) = I */
19705
19706
i__1 = *k;
19707
for (j = i__; j <= i__1; ++j) {
19708
i__2 = j + i__ * t_dim1;
19709
t[i__2].r = 0., t[i__2].i = 0.;
19710
/* L30: */
19711
}
19712
} else {
19713
19714
/* general case */
19715
19716
if (i__ < *k) {
19717
if (lsame_(storev, "C")) {
19718
i__1 = *n - *k + i__ + i__ * v_dim1;
19719
vii.r = v[i__1].r, vii.i = v[i__1].i;
19720
i__1 = *n - *k + i__ + i__ * v_dim1;
19721
v[i__1].r = 1., v[i__1].i = 0.;
19722
/* Skip any leading zeros. */
19723
i__1 = i__ - 1;
19724
for (lastv = 1; lastv <= i__1; ++lastv) {
19725
i__2 = lastv + i__ * v_dim1;
19726
if (v[i__2].r != 0. || v[i__2].i != 0.) {
19727
goto L35;
19728
}
19729
}
19730
L35:
19731
j = max(lastv,prevlastv);
19732
19733
/*
19734
T(i+1:k,i) :=
19735
- tau(i) * V(j:n-k+i,i+1:k)' * V(j:n-k+i,i)
19736
*/
19737
19738
i__1 = *n - *k + i__ - j + 1;
19739
i__2 = *k - i__;
19740
i__3 = i__;
19741
z__1.r = -tau[i__3].r, z__1.i = -tau[i__3].i;
19742
zgemv_("Conjugate transpose", &i__1, &i__2, &z__1, &v[
19743
j + (i__ + 1) * v_dim1], ldv, &v[j + i__ *
19744
v_dim1], &c__1, &c_b56, &t[i__ + 1 + i__ *
19745
t_dim1], &c__1);
19746
i__1 = *n - *k + i__ + i__ * v_dim1;
19747
v[i__1].r = vii.r, v[i__1].i = vii.i;
19748
} else {
19749
i__1 = i__ + (*n - *k + i__) * v_dim1;
19750
vii.r = v[i__1].r, vii.i = v[i__1].i;
19751
i__1 = i__ + (*n - *k + i__) * v_dim1;
19752
v[i__1].r = 1., v[i__1].i = 0.;
19753
/* Skip any leading zeros. */
19754
i__1 = i__ - 1;
19755
for (lastv = 1; lastv <= i__1; ++lastv) {
19756
i__2 = i__ + lastv * v_dim1;
19757
if (v[i__2].r != 0. || v[i__2].i != 0.) {
19758
goto L36;
19759
}
19760
}
19761
L36:
19762
j = max(lastv,prevlastv);
19763
19764
/*
19765
T(i+1:k,i) :=
19766
- tau(i) * V(i+1:k,j:n-k+i) * V(i,j:n-k+i)'
19767
*/
19768
19769
i__1 = *n - *k + i__ - 1 - j + 1;
19770
zlacgv_(&i__1, &v[i__ + j * v_dim1], ldv);
19771
i__1 = *k - i__;
19772
i__2 = *n - *k + i__ - j + 1;
19773
i__3 = i__;
19774
z__1.r = -tau[i__3].r, z__1.i = -tau[i__3].i;
19775
zgemv_("No transpose", &i__1, &i__2, &z__1, &v[i__ +
19776
1 + j * v_dim1], ldv, &v[i__ + j * v_dim1],
19777
ldv, &c_b56, &t[i__ + 1 + i__ * t_dim1], &
19778
c__1);
19779
i__1 = *n - *k + i__ - 1 - j + 1;
19780
zlacgv_(&i__1, &v[i__ + j * v_dim1], ldv);
19781
i__1 = i__ + (*n - *k + i__) * v_dim1;
19782
v[i__1].r = vii.r, v[i__1].i = vii.i;
19783
}
19784
19785
/* T(i+1:k,i) := T(i+1:k,i+1:k) * T(i+1:k,i) */
19786
19787
i__1 = *k - i__;
19788
ztrmv_("Lower", "No transpose", "Non-unit", &i__1, &t[i__
19789
+ 1 + (i__ + 1) * t_dim1], ldt, &t[i__ + 1 + i__ *
19790
t_dim1], &c__1)
19791
;
19792
if (i__ > 1) {
19793
prevlastv = min(prevlastv,lastv);
19794
} else {
19795
prevlastv = lastv;
19796
}
19797
}
19798
i__1 = i__ + i__ * t_dim1;
19799
i__2 = i__;
19800
t[i__1].r = tau[i__2].r, t[i__1].i = tau[i__2].i;
19801
}
19802
/* L40: */
19803
}
19804
}
19805
return 0;
19806
19807
/* End of ZLARFT */
19808
19809
} /* zlarft_ */
19810
19811
/* Subroutine */ int zlartg_(doublecomplex *f, doublecomplex *g, doublereal *
19812
cs, doublecomplex *sn, doublecomplex *r__)
19813
{
19814
/* System generated locals */
19815
integer i__1;
19816
doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8, d__9, d__10;
19817
doublecomplex z__1, z__2, z__3;
19818
19819
/* Local variables */
19820
static doublereal d__;
19821
static integer i__;
19822
static doublereal f2, g2;
19823
static doublecomplex ff;
19824
static doublereal di, dr;
19825
static doublecomplex fs, gs;
19826
static doublereal f2s, g2s, eps, scale;
19827
static integer count;
19828
static doublereal safmn2;
19829
extern doublereal dlapy2_(doublereal *, doublereal *);
19830
static doublereal safmx2;
19831
19832
static doublereal safmin;
19833
19834
19835
/*
19836
-- LAPACK auxiliary routine (version 3.2) --
19837
-- LAPACK is a software package provided by Univ. of Tennessee, --
19838
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
19839
November 2006
19840
19841
19842
Purpose
19843
=======
19844
19845
ZLARTG generates a plane rotation so that
19846
19847
[ CS SN ] [ F ] [ R ]
19848
[ __ ] . [ ] = [ ] where CS**2 + |SN|**2 = 1.
19849
[ -SN CS ] [ G ] [ 0 ]
19850
19851
This is a faster version of the BLAS1 routine ZROTG, except for
19852
the following differences:
19853
F and G are unchanged on return.
19854
If G=0, then CS=1 and SN=0.
19855
If F=0, then CS=0 and SN is chosen so that R is real.
19856
19857
Arguments
19858
=========
19859
19860
F (input) COMPLEX*16
19861
The first component of vector to be rotated.
19862
19863
G (input) COMPLEX*16
19864
The second component of vector to be rotated.
19865
19866
CS (output) DOUBLE PRECISION
19867
The cosine of the rotation.
19868
19869
SN (output) COMPLEX*16
19870
The sine of the rotation.
19871
19872
R (output) COMPLEX*16
19873
The nonzero component of the rotated vector.
19874
19875
Further Details
19876
======= =======
19877
19878
3-5-96 - Modified with a new algorithm by W. Kahan and J. Demmel
19879
19880
This version has a few statements commented out for thread safety
19881
(machine parameters are computed on each entry). 10 feb 03, SJH.
19882
19883
=====================================================================
19884
19885
LOGICAL FIRST
19886
SAVE FIRST, SAFMX2, SAFMIN, SAFMN2
19887
DATA FIRST / .TRUE. /
19888
19889
IF( FIRST ) THEN
19890
*/
19891
safmin = SAFEMINIMUM;
19892
eps = EPSILON;
19893
d__1 = BASE;
19894
i__1 = (integer) (log(safmin / eps) / log(BASE) / 2.);
19895
safmn2 = pow_di(&d__1, &i__1);
19896
safmx2 = 1. / safmn2;
19897
/*
19898
FIRST = .FALSE.
19899
END IF
19900
Computing MAX
19901
Computing MAX
19902
*/
19903
d__7 = (d__1 = f->r, abs(d__1)), d__8 = (d__2 = d_imag(f), abs(d__2));
19904
/* Computing MAX */
19905
d__9 = (d__3 = g->r, abs(d__3)), d__10 = (d__4 = d_imag(g), abs(d__4));
19906
d__5 = max(d__7,d__8), d__6 = max(d__9,d__10);
19907
scale = max(d__5,d__6);
19908
fs.r = f->r, fs.i = f->i;
19909
gs.r = g->r, gs.i = g->i;
19910
count = 0;
19911
if (scale >= safmx2) {
19912
L10:
19913
++count;
19914
z__1.r = safmn2 * fs.r, z__1.i = safmn2 * fs.i;
19915
fs.r = z__1.r, fs.i = z__1.i;
19916
z__1.r = safmn2 * gs.r, z__1.i = safmn2 * gs.i;
19917
gs.r = z__1.r, gs.i = z__1.i;
19918
scale *= safmn2;
19919
if (scale >= safmx2) {
19920
goto L10;
19921
}
19922
} else if (scale <= safmn2) {
19923
if (g->r == 0. && g->i == 0.) {
19924
*cs = 1.;
19925
sn->r = 0., sn->i = 0.;
19926
r__->r = f->r, r__->i = f->i;
19927
return 0;
19928
}
19929
L20:
19930
--count;
19931
z__1.r = safmx2 * fs.r, z__1.i = safmx2 * fs.i;
19932
fs.r = z__1.r, fs.i = z__1.i;
19933
z__1.r = safmx2 * gs.r, z__1.i = safmx2 * gs.i;
19934
gs.r = z__1.r, gs.i = z__1.i;
19935
scale *= safmx2;
19936
if (scale <= safmn2) {
19937
goto L20;
19938
}
19939
}
19940
/* Computing 2nd power */
19941
d__1 = fs.r;
19942
/* Computing 2nd power */
19943
d__2 = d_imag(&fs);
19944
f2 = d__1 * d__1 + d__2 * d__2;
19945
/* Computing 2nd power */
19946
d__1 = gs.r;
19947
/* Computing 2nd power */
19948
d__2 = d_imag(&gs);
19949
g2 = d__1 * d__1 + d__2 * d__2;
19950
if (f2 <= max(g2,1.) * safmin) {
19951
19952
/* This is a rare case: F is very small. */
19953
19954
if (f->r == 0. && f->i == 0.) {
19955
*cs = 0.;
19956
d__2 = g->r;
19957
d__3 = d_imag(g);
19958
d__1 = dlapy2_(&d__2, &d__3);
19959
r__->r = d__1, r__->i = 0.;
19960
/* Do complex/real division explicitly with two real divisions */
19961
d__1 = gs.r;
19962
d__2 = d_imag(&gs);
19963
d__ = dlapy2_(&d__1, &d__2);
19964
d__1 = gs.r / d__;
19965
d__2 = -d_imag(&gs) / d__;
19966
z__1.r = d__1, z__1.i = d__2;
19967
sn->r = z__1.r, sn->i = z__1.i;
19968
return 0;
19969
}
19970
d__1 = fs.r;
19971
d__2 = d_imag(&fs);
19972
f2s = dlapy2_(&d__1, &d__2);
19973
/*
19974
G2 and G2S are accurate
19975
G2 is at least SAFMIN, and G2S is at least SAFMN2
19976
*/
19977
g2s = sqrt(g2);
19978
/*
19979
Error in CS from underflow in F2S is at most
19980
UNFL / SAFMN2 .lt. sqrt(UNFL*EPS) .lt. EPS
19981
If MAX(G2,ONE)=G2, then F2 .lt. G2*SAFMIN,
19982
and so CS .lt. sqrt(SAFMIN)
19983
If MAX(G2,ONE)=ONE, then F2 .lt. SAFMIN
19984
and so CS .lt. sqrt(SAFMIN)/SAFMN2 = sqrt(EPS)
19985
Therefore, CS = F2S/G2S / sqrt( 1 + (F2S/G2S)**2 ) = F2S/G2S
19986
*/
19987
*cs = f2s / g2s;
19988
/*
19989
Make sure abs(FF) = 1
19990
Do complex/real division explicitly with 2 real divisions
19991
Computing MAX
19992
*/
19993
d__3 = (d__1 = f->r, abs(d__1)), d__4 = (d__2 = d_imag(f), abs(d__2));
19994
if (max(d__3,d__4) > 1.) {
19995
d__1 = f->r;
19996
d__2 = d_imag(f);
19997
d__ = dlapy2_(&d__1, &d__2);
19998
d__1 = f->r / d__;
19999
d__2 = d_imag(f) / d__;
20000
z__1.r = d__1, z__1.i = d__2;
20001
ff.r = z__1.r, ff.i = z__1.i;
20002
} else {
20003
dr = safmx2 * f->r;
20004
di = safmx2 * d_imag(f);
20005
d__ = dlapy2_(&dr, &di);
20006
d__1 = dr / d__;
20007
d__2 = di / d__;
20008
z__1.r = d__1, z__1.i = d__2;
20009
ff.r = z__1.r, ff.i = z__1.i;
20010
}
20011
d__1 = gs.r / g2s;
20012
d__2 = -d_imag(&gs) / g2s;
20013
z__2.r = d__1, z__2.i = d__2;
20014
z__1.r = ff.r * z__2.r - ff.i * z__2.i, z__1.i = ff.r * z__2.i + ff.i
20015
* z__2.r;
20016
sn->r = z__1.r, sn->i = z__1.i;
20017
z__2.r = *cs * f->r, z__2.i = *cs * f->i;
20018
z__3.r = sn->r * g->r - sn->i * g->i, z__3.i = sn->r * g->i + sn->i *
20019
g->r;
20020
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
20021
r__->r = z__1.r, r__->i = z__1.i;
20022
} else {
20023
20024
/*
20025
This is the most common case.
20026
Neither F2 nor F2/G2 are less than SAFMIN
20027
F2S cannot overflow, and it is accurate
20028
*/
20029
20030
f2s = sqrt(g2 / f2 + 1.);
20031
/* Do the F2S(real)*FS(complex) multiply with two real multiplies */
20032
d__1 = f2s * fs.r;
20033
d__2 = f2s * d_imag(&fs);
20034
z__1.r = d__1, z__1.i = d__2;
20035
r__->r = z__1.r, r__->i = z__1.i;
20036
*cs = 1. / f2s;
20037
d__ = f2 + g2;
20038
/* Do complex/real division explicitly with two real divisions */
20039
d__1 = r__->r / d__;
20040
d__2 = d_imag(r__) / d__;
20041
z__1.r = d__1, z__1.i = d__2;
20042
sn->r = z__1.r, sn->i = z__1.i;
20043
d_cnjg(&z__2, &gs);
20044
z__1.r = sn->r * z__2.r - sn->i * z__2.i, z__1.i = sn->r * z__2.i +
20045
sn->i * z__2.r;
20046
sn->r = z__1.r, sn->i = z__1.i;
20047
if (count != 0) {
20048
if (count > 0) {
20049
i__1 = count;
20050
for (i__ = 1; i__ <= i__1; ++i__) {
20051
z__1.r = safmx2 * r__->r, z__1.i = safmx2 * r__->i;
20052
r__->r = z__1.r, r__->i = z__1.i;
20053
/* L30: */
20054
}
20055
} else {
20056
i__1 = -count;
20057
for (i__ = 1; i__ <= i__1; ++i__) {
20058
z__1.r = safmn2 * r__->r, z__1.i = safmn2 * r__->i;
20059
r__->r = z__1.r, r__->i = z__1.i;
20060
/* L40: */
20061
}
20062
}
20063
}
20064
}
20065
return 0;
20066
20067
/* End of ZLARTG */
20068
20069
} /* zlartg_ */
20070
20071
/* Subroutine */ int zlascl_(char *type__, integer *kl, integer *ku,
20072
doublereal *cfrom, doublereal *cto, integer *m, integer *n,
20073
doublecomplex *a, integer *lda, integer *info)
20074
{
20075
/* System generated locals */
20076
integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
20077
doublecomplex z__1;
20078
20079
/* Local variables */
20080
static integer i__, j, k1, k2, k3, k4;
20081
static doublereal mul, cto1;
20082
static logical done;
20083
static doublereal ctoc;
20084
extern logical lsame_(char *, char *);
20085
static integer itype;
20086
static doublereal cfrom1;
20087
20088
static doublereal cfromc;
20089
extern logical disnan_(doublereal *);
20090
extern /* Subroutine */ int xerbla_(char *, integer *);
20091
static doublereal bignum, smlnum;
20092
20093
20094
/*
20095
-- LAPACK auxiliary routine (version 3.2) --
20096
-- LAPACK is a software package provided by Univ. of Tennessee, --
20097
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
20098
November 2006
20099
20100
20101
Purpose
20102
=======
20103
20104
ZLASCL multiplies the M by N complex matrix A by the real scalar
20105
CTO/CFROM. This is done without over/underflow as long as the final
20106
result CTO*A(I,J)/CFROM does not over/underflow. TYPE specifies that
20107
A may be full, upper triangular, lower triangular, upper Hessenberg,
20108
or banded.
20109
20110
Arguments
20111
=========
20112
20113
TYPE (input) CHARACTER*1
20114
TYPE indices the storage type of the input matrix.
20115
= 'G': A is a full matrix.
20116
= 'L': A is a lower triangular matrix.
20117
= 'U': A is an upper triangular matrix.
20118
= 'H': A is an upper Hessenberg matrix.
20119
= 'B': A is a symmetric band matrix with lower bandwidth KL
20120
and upper bandwidth KU and with the only the lower
20121
half stored.
20122
= 'Q': A is a symmetric band matrix with lower bandwidth KL
20123
and upper bandwidth KU and with the only the upper
20124
half stored.
20125
= 'Z': A is a band matrix with lower bandwidth KL and upper
20126
bandwidth KU.
20127
20128
KL (input) INTEGER
20129
The lower bandwidth of A. Referenced only if TYPE = 'B',
20130
'Q' or 'Z'.
20131
20132
KU (input) INTEGER
20133
The upper bandwidth of A. Referenced only if TYPE = 'B',
20134
'Q' or 'Z'.
20135
20136
CFROM (input) DOUBLE PRECISION
20137
CTO (input) DOUBLE PRECISION
20138
The matrix A is multiplied by CTO/CFROM. A(I,J) is computed
20139
without over/underflow if the final result CTO*A(I,J)/CFROM
20140
can be represented without over/underflow. CFROM must be
20141
nonzero.
20142
20143
M (input) INTEGER
20144
The number of rows of the matrix A. M >= 0.
20145
20146
N (input) INTEGER
20147
The number of columns of the matrix A. N >= 0.
20148
20149
A (input/output) COMPLEX*16 array, dimension (LDA,N)
20150
The matrix to be multiplied by CTO/CFROM. See TYPE for the
20151
storage type.
20152
20153
LDA (input) INTEGER
20154
The leading dimension of the array A. LDA >= max(1,M).
20155
20156
INFO (output) INTEGER
20157
0 - successful exit
20158
<0 - if INFO = -i, the i-th argument had an illegal value.
20159
20160
=====================================================================
20161
20162
20163
Test the input arguments
20164
*/
20165
20166
/* Parameter adjustments */
20167
a_dim1 = *lda;
20168
a_offset = 1 + a_dim1;
20169
a -= a_offset;
20170
20171
/* Function Body */
20172
*info = 0;
20173
20174
if (lsame_(type__, "G")) {
20175
itype = 0;
20176
} else if (lsame_(type__, "L")) {
20177
itype = 1;
20178
} else if (lsame_(type__, "U")) {
20179
itype = 2;
20180
} else if (lsame_(type__, "H")) {
20181
itype = 3;
20182
} else if (lsame_(type__, "B")) {
20183
itype = 4;
20184
} else if (lsame_(type__, "Q")) {
20185
itype = 5;
20186
} else if (lsame_(type__, "Z")) {
20187
itype = 6;
20188
} else {
20189
itype = -1;
20190
}
20191
20192
if (itype == -1) {
20193
*info = -1;
20194
} else if (*cfrom == 0. || disnan_(cfrom)) {
20195
*info = -4;
20196
} else if (disnan_(cto)) {
20197
*info = -5;
20198
} else if (*m < 0) {
20199
*info = -6;
20200
} else if (*n < 0 || itype == 4 && *n != *m || itype == 5 && *n != *m) {
20201
*info = -7;
20202
} else if (itype <= 3 && *lda < max(1,*m)) {
20203
*info = -9;
20204
} else if (itype >= 4) {
20205
/* Computing MAX */
20206
i__1 = *m - 1;
20207
if (*kl < 0 || *kl > max(i__1,0)) {
20208
*info = -2;
20209
} else /* if(complicated condition) */ {
20210
/* Computing MAX */
20211
i__1 = *n - 1;
20212
if (*ku < 0 || *ku > max(i__1,0) || (itype == 4 || itype == 5) &&
20213
*kl != *ku) {
20214
*info = -3;
20215
} else if (itype == 4 && *lda < *kl + 1 || itype == 5 && *lda < *
20216
ku + 1 || itype == 6 && *lda < (*kl << 1) + *ku + 1) {
20217
*info = -9;
20218
}
20219
}
20220
}
20221
20222
if (*info != 0) {
20223
i__1 = -(*info);
20224
xerbla_("ZLASCL", &i__1);
20225
return 0;
20226
}
20227
20228
/* Quick return if possible */
20229
20230
if (*n == 0 || *m == 0) {
20231
return 0;
20232
}
20233
20234
/* Get machine parameters */
20235
20236
smlnum = SAFEMINIMUM;
20237
bignum = 1. / smlnum;
20238
20239
cfromc = *cfrom;
20240
ctoc = *cto;
20241
20242
L10:
20243
cfrom1 = cfromc * smlnum;
20244
if (cfrom1 == cfromc) {
20245
/*
20246
CFROMC is an inf. Multiply by a correctly signed zero for
20247
finite CTOC, or a NaN if CTOC is infinite.
20248
*/
20249
mul = ctoc / cfromc;
20250
done = TRUE_;
20251
cto1 = ctoc;
20252
} else {
20253
cto1 = ctoc / bignum;
20254
if (cto1 == ctoc) {
20255
/*
20256
CTOC is either 0 or an inf. In both cases, CTOC itself
20257
serves as the correct multiplication factor.
20258
*/
20259
mul = ctoc;
20260
done = TRUE_;
20261
cfromc = 1.;
20262
} else if (abs(cfrom1) > abs(ctoc) && ctoc != 0.) {
20263
mul = smlnum;
20264
done = FALSE_;
20265
cfromc = cfrom1;
20266
} else if (abs(cto1) > abs(cfromc)) {
20267
mul = bignum;
20268
done = FALSE_;
20269
ctoc = cto1;
20270
} else {
20271
mul = ctoc / cfromc;
20272
done = TRUE_;
20273
}
20274
}
20275
20276
if (itype == 0) {
20277
20278
/* Full matrix */
20279
20280
i__1 = *n;
20281
for (j = 1; j <= i__1; ++j) {
20282
i__2 = *m;
20283
for (i__ = 1; i__ <= i__2; ++i__) {
20284
i__3 = i__ + j * a_dim1;
20285
i__4 = i__ + j * a_dim1;
20286
z__1.r = mul * a[i__4].r, z__1.i = mul * a[i__4].i;
20287
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20288
/* L20: */
20289
}
20290
/* L30: */
20291
}
20292
20293
} else if (itype == 1) {
20294
20295
/* Lower triangular matrix */
20296
20297
i__1 = *n;
20298
for (j = 1; j <= i__1; ++j) {
20299
i__2 = *m;
20300
for (i__ = j; i__ <= i__2; ++i__) {
20301
i__3 = i__ + j * a_dim1;
20302
i__4 = i__ + j * a_dim1;
20303
z__1.r = mul * a[i__4].r, z__1.i = mul * a[i__4].i;
20304
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20305
/* L40: */
20306
}
20307
/* L50: */
20308
}
20309
20310
} else if (itype == 2) {
20311
20312
/* Upper triangular matrix */
20313
20314
i__1 = *n;
20315
for (j = 1; j <= i__1; ++j) {
20316
i__2 = min(j,*m);
20317
for (i__ = 1; i__ <= i__2; ++i__) {
20318
i__3 = i__ + j * a_dim1;
20319
i__4 = i__ + j * a_dim1;
20320
z__1.r = mul * a[i__4].r, z__1.i = mul * a[i__4].i;
20321
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20322
/* L60: */
20323
}
20324
/* L70: */
20325
}
20326
20327
} else if (itype == 3) {
20328
20329
/* Upper Hessenberg matrix */
20330
20331
i__1 = *n;
20332
for (j = 1; j <= i__1; ++j) {
20333
/* Computing MIN */
20334
i__3 = j + 1;
20335
i__2 = min(i__3,*m);
20336
for (i__ = 1; i__ <= i__2; ++i__) {
20337
i__3 = i__ + j * a_dim1;
20338
i__4 = i__ + j * a_dim1;
20339
z__1.r = mul * a[i__4].r, z__1.i = mul * a[i__4].i;
20340
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20341
/* L80: */
20342
}
20343
/* L90: */
20344
}
20345
20346
} else if (itype == 4) {
20347
20348
/* Lower half of a symmetric band matrix */
20349
20350
k3 = *kl + 1;
20351
k4 = *n + 1;
20352
i__1 = *n;
20353
for (j = 1; j <= i__1; ++j) {
20354
/* Computing MIN */
20355
i__3 = k3, i__4 = k4 - j;
20356
i__2 = min(i__3,i__4);
20357
for (i__ = 1; i__ <= i__2; ++i__) {
20358
i__3 = i__ + j * a_dim1;
20359
i__4 = i__ + j * a_dim1;
20360
z__1.r = mul * a[i__4].r, z__1.i = mul * a[i__4].i;
20361
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20362
/* L100: */
20363
}
20364
/* L110: */
20365
}
20366
20367
} else if (itype == 5) {
20368
20369
/* Upper half of a symmetric band matrix */
20370
20371
k1 = *ku + 2;
20372
k3 = *ku + 1;
20373
i__1 = *n;
20374
for (j = 1; j <= i__1; ++j) {
20375
/* Computing MAX */
20376
i__2 = k1 - j;
20377
i__3 = k3;
20378
for (i__ = max(i__2,1); i__ <= i__3; ++i__) {
20379
i__2 = i__ + j * a_dim1;
20380
i__4 = i__ + j * a_dim1;
20381
z__1.r = mul * a[i__4].r, z__1.i = mul * a[i__4].i;
20382
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
20383
/* L120: */
20384
}
20385
/* L130: */
20386
}
20387
20388
} else if (itype == 6) {
20389
20390
/* Band matrix */
20391
20392
k1 = *kl + *ku + 2;
20393
k2 = *kl + 1;
20394
k3 = (*kl << 1) + *ku + 1;
20395
k4 = *kl + *ku + 1 + *m;
20396
i__1 = *n;
20397
for (j = 1; j <= i__1; ++j) {
20398
/* Computing MAX */
20399
i__3 = k1 - j;
20400
/* Computing MIN */
20401
i__4 = k3, i__5 = k4 - j;
20402
i__2 = min(i__4,i__5);
20403
for (i__ = max(i__3,k2); i__ <= i__2; ++i__) {
20404
i__3 = i__ + j * a_dim1;
20405
i__4 = i__ + j * a_dim1;
20406
z__1.r = mul * a[i__4].r, z__1.i = mul * a[i__4].i;
20407
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20408
/* L140: */
20409
}
20410
/* L150: */
20411
}
20412
20413
}
20414
20415
if (! done) {
20416
goto L10;
20417
}
20418
20419
return 0;
20420
20421
/* End of ZLASCL */
20422
20423
} /* zlascl_ */
20424
20425
/* Subroutine */ int zlaset_(char *uplo, integer *m, integer *n,
20426
doublecomplex *alpha, doublecomplex *beta, doublecomplex *a, integer *
20427
lda)
20428
{
20429
/* System generated locals */
20430
integer a_dim1, a_offset, i__1, i__2, i__3;
20431
20432
/* Local variables */
20433
static integer i__, j;
20434
extern logical lsame_(char *, char *);
20435
20436
20437
/*
20438
-- LAPACK auxiliary routine (version 3.2) --
20439
-- LAPACK is a software package provided by Univ. of Tennessee, --
20440
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
20441
November 2006
20442
20443
20444
Purpose
20445
=======
20446
20447
ZLASET initializes a 2-D array A to BETA on the diagonal and
20448
ALPHA on the offdiagonals.
20449
20450
Arguments
20451
=========
20452
20453
UPLO (input) CHARACTER*1
20454
Specifies the part of the matrix A to be set.
20455
= 'U': Upper triangular part is set. The lower triangle
20456
is unchanged.
20457
= 'L': Lower triangular part is set. The upper triangle
20458
is unchanged.
20459
Otherwise: All of the matrix A is set.
20460
20461
M (input) INTEGER
20462
On entry, M specifies the number of rows of A.
20463
20464
N (input) INTEGER
20465
On entry, N specifies the number of columns of A.
20466
20467
ALPHA (input) COMPLEX*16
20468
All the offdiagonal array elements are set to ALPHA.
20469
20470
BETA (input) COMPLEX*16
20471
All the diagonal array elements are set to BETA.
20472
20473
A (input/output) COMPLEX*16 array, dimension (LDA,N)
20474
On entry, the m by n matrix A.
20475
On exit, A(i,j) = ALPHA, 1 <= i <= m, 1 <= j <= n, i.ne.j;
20476
A(i,i) = BETA , 1 <= i <= min(m,n)
20477
20478
LDA (input) INTEGER
20479
The leading dimension of the array A. LDA >= max(1,M).
20480
20481
=====================================================================
20482
*/
20483
20484
20485
/* Parameter adjustments */
20486
a_dim1 = *lda;
20487
a_offset = 1 + a_dim1;
20488
a -= a_offset;
20489
20490
/* Function Body */
20491
if (lsame_(uplo, "U")) {
20492
20493
/*
20494
Set the diagonal to BETA and the strictly upper triangular
20495
part of the array to ALPHA.
20496
*/
20497
20498
i__1 = *n;
20499
for (j = 2; j <= i__1; ++j) {
20500
/* Computing MIN */
20501
i__3 = j - 1;
20502
i__2 = min(i__3,*m);
20503
for (i__ = 1; i__ <= i__2; ++i__) {
20504
i__3 = i__ + j * a_dim1;
20505
a[i__3].r = alpha->r, a[i__3].i = alpha->i;
20506
/* L10: */
20507
}
20508
/* L20: */
20509
}
20510
i__1 = min(*n,*m);
20511
for (i__ = 1; i__ <= i__1; ++i__) {
20512
i__2 = i__ + i__ * a_dim1;
20513
a[i__2].r = beta->r, a[i__2].i = beta->i;
20514
/* L30: */
20515
}
20516
20517
} else if (lsame_(uplo, "L")) {
20518
20519
/*
20520
Set the diagonal to BETA and the strictly lower triangular
20521
part of the array to ALPHA.
20522
*/
20523
20524
i__1 = min(*m,*n);
20525
for (j = 1; j <= i__1; ++j) {
20526
i__2 = *m;
20527
for (i__ = j + 1; i__ <= i__2; ++i__) {
20528
i__3 = i__ + j * a_dim1;
20529
a[i__3].r = alpha->r, a[i__3].i = alpha->i;
20530
/* L40: */
20531
}
20532
/* L50: */
20533
}
20534
i__1 = min(*n,*m);
20535
for (i__ = 1; i__ <= i__1; ++i__) {
20536
i__2 = i__ + i__ * a_dim1;
20537
a[i__2].r = beta->r, a[i__2].i = beta->i;
20538
/* L60: */
20539
}
20540
20541
} else {
20542
20543
/*
20544
Set the array to BETA on the diagonal and ALPHA on the
20545
offdiagonal.
20546
*/
20547
20548
i__1 = *n;
20549
for (j = 1; j <= i__1; ++j) {
20550
i__2 = *m;
20551
for (i__ = 1; i__ <= i__2; ++i__) {
20552
i__3 = i__ + j * a_dim1;
20553
a[i__3].r = alpha->r, a[i__3].i = alpha->i;
20554
/* L70: */
20555
}
20556
/* L80: */
20557
}
20558
i__1 = min(*m,*n);
20559
for (i__ = 1; i__ <= i__1; ++i__) {
20560
i__2 = i__ + i__ * a_dim1;
20561
a[i__2].r = beta->r, a[i__2].i = beta->i;
20562
/* L90: */
20563
}
20564
}
20565
20566
return 0;
20567
20568
/* End of ZLASET */
20569
20570
} /* zlaset_ */
20571
20572
/* Subroutine */ int zlasr_(char *side, char *pivot, char *direct, integer *m,
20573
integer *n, doublereal *c__, doublereal *s, doublecomplex *a,
20574
integer *lda)
20575
{
20576
/* System generated locals */
20577
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
20578
doublecomplex z__1, z__2, z__3;
20579
20580
/* Local variables */
20581
static integer i__, j, info;
20582
static doublecomplex temp;
20583
extern logical lsame_(char *, char *);
20584
static doublereal ctemp, stemp;
20585
extern /* Subroutine */ int xerbla_(char *, integer *);
20586
20587
20588
/*
20589
-- LAPACK auxiliary routine (version 3.2) --
20590
-- LAPACK is a software package provided by Univ. of Tennessee, --
20591
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
20592
November 2006
20593
20594
20595
Purpose
20596
=======
20597
20598
ZLASR applies a sequence of real plane rotations to a complex matrix
20599
A, from either the left or the right.
20600
20601
When SIDE = 'L', the transformation takes the form
20602
20603
A := P*A
20604
20605
and when SIDE = 'R', the transformation takes the form
20606
20607
A := A*P**T
20608
20609
where P is an orthogonal matrix consisting of a sequence of z plane
20610
rotations, with z = M when SIDE = 'L' and z = N when SIDE = 'R',
20611
and P**T is the transpose of P.
20612
20613
When DIRECT = 'F' (Forward sequence), then
20614
20615
P = P(z-1) * ... * P(2) * P(1)
20616
20617
and when DIRECT = 'B' (Backward sequence), then
20618
20619
P = P(1) * P(2) * ... * P(z-1)
20620
20621
where P(k) is a plane rotation matrix defined by the 2-by-2 rotation
20622
20623
R(k) = ( c(k) s(k) )
20624
= ( -s(k) c(k) ).
20625
20626
When PIVOT = 'V' (Variable pivot), the rotation is performed
20627
for the plane (k,k+1), i.e., P(k) has the form
20628
20629
P(k) = ( 1 )
20630
( ... )
20631
( 1 )
20632
( c(k) s(k) )
20633
( -s(k) c(k) )
20634
( 1 )
20635
( ... )
20636
( 1 )
20637
20638
where R(k) appears as a rank-2 modification to the identity matrix in
20639
rows and columns k and k+1.
20640
20641
When PIVOT = 'T' (Top pivot), the rotation is performed for the
20642
plane (1,k+1), so P(k) has the form
20643
20644
P(k) = ( c(k) s(k) )
20645
( 1 )
20646
( ... )
20647
( 1 )
20648
( -s(k) c(k) )
20649
( 1 )
20650
( ... )
20651
( 1 )
20652
20653
where R(k) appears in rows and columns 1 and k+1.
20654
20655
Similarly, when PIVOT = 'B' (Bottom pivot), the rotation is
20656
performed for the plane (k,z), giving P(k) the form
20657
20658
P(k) = ( 1 )
20659
( ... )
20660
( 1 )
20661
( c(k) s(k) )
20662
( 1 )
20663
( ... )
20664
( 1 )
20665
( -s(k) c(k) )
20666
20667
where R(k) appears in rows and columns k and z. The rotations are
20668
performed without ever forming P(k) explicitly.
20669
20670
Arguments
20671
=========
20672
20673
SIDE (input) CHARACTER*1
20674
Specifies whether the plane rotation matrix P is applied to
20675
A on the left or the right.
20676
= 'L': Left, compute A := P*A
20677
= 'R': Right, compute A:= A*P**T
20678
20679
PIVOT (input) CHARACTER*1
20680
Specifies the plane for which P(k) is a plane rotation
20681
matrix.
20682
= 'V': Variable pivot, the plane (k,k+1)
20683
= 'T': Top pivot, the plane (1,k+1)
20684
= 'B': Bottom pivot, the plane (k,z)
20685
20686
DIRECT (input) CHARACTER*1
20687
Specifies whether P is a forward or backward sequence of
20688
plane rotations.
20689
= 'F': Forward, P = P(z-1)*...*P(2)*P(1)
20690
= 'B': Backward, P = P(1)*P(2)*...*P(z-1)
20691
20692
M (input) INTEGER
20693
The number of rows of the matrix A. If m <= 1, an immediate
20694
return is effected.
20695
20696
N (input) INTEGER
20697
The number of columns of the matrix A. If n <= 1, an
20698
immediate return is effected.
20699
20700
C (input) DOUBLE PRECISION array, dimension
20701
(M-1) if SIDE = 'L'
20702
(N-1) if SIDE = 'R'
20703
The cosines c(k) of the plane rotations.
20704
20705
S (input) DOUBLE PRECISION array, dimension
20706
(M-1) if SIDE = 'L'
20707
(N-1) if SIDE = 'R'
20708
The sines s(k) of the plane rotations. The 2-by-2 plane
20709
rotation part of the matrix P(k), R(k), has the form
20710
R(k) = ( c(k) s(k) )
20711
( -s(k) c(k) ).
20712
20713
A (input/output) COMPLEX*16 array, dimension (LDA,N)
20714
The M-by-N matrix A. On exit, A is overwritten by P*A if
20715
SIDE = 'R' or by A*P**T if SIDE = 'L'.
20716
20717
LDA (input) INTEGER
20718
The leading dimension of the array A. LDA >= max(1,M).
20719
20720
=====================================================================
20721
20722
20723
Test the input parameters
20724
*/
20725
20726
/* Parameter adjustments */
20727
--c__;
20728
--s;
20729
a_dim1 = *lda;
20730
a_offset = 1 + a_dim1;
20731
a -= a_offset;
20732
20733
/* Function Body */
20734
info = 0;
20735
if (! (lsame_(side, "L") || lsame_(side, "R"))) {
20736
info = 1;
20737
} else if (! (lsame_(pivot, "V") || lsame_(pivot,
20738
"T") || lsame_(pivot, "B"))) {
20739
info = 2;
20740
} else if (! (lsame_(direct, "F") || lsame_(direct,
20741
"B"))) {
20742
info = 3;
20743
} else if (*m < 0) {
20744
info = 4;
20745
} else if (*n < 0) {
20746
info = 5;
20747
} else if (*lda < max(1,*m)) {
20748
info = 9;
20749
}
20750
if (info != 0) {
20751
xerbla_("ZLASR ", &info);
20752
return 0;
20753
}
20754
20755
/* Quick return if possible */
20756
20757
if (*m == 0 || *n == 0) {
20758
return 0;
20759
}
20760
if (lsame_(side, "L")) {
20761
20762
/* Form P * A */
20763
20764
if (lsame_(pivot, "V")) {
20765
if (lsame_(direct, "F")) {
20766
i__1 = *m - 1;
20767
for (j = 1; j <= i__1; ++j) {
20768
ctemp = c__[j];
20769
stemp = s[j];
20770
if (ctemp != 1. || stemp != 0.) {
20771
i__2 = *n;
20772
for (i__ = 1; i__ <= i__2; ++i__) {
20773
i__3 = j + 1 + i__ * a_dim1;
20774
temp.r = a[i__3].r, temp.i = a[i__3].i;
20775
i__3 = j + 1 + i__ * a_dim1;
20776
z__2.r = ctemp * temp.r, z__2.i = ctemp * temp.i;
20777
i__4 = j + i__ * a_dim1;
20778
z__3.r = stemp * a[i__4].r, z__3.i = stemp * a[
20779
i__4].i;
20780
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
20781
z__3.i;
20782
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20783
i__3 = j + i__ * a_dim1;
20784
z__2.r = stemp * temp.r, z__2.i = stemp * temp.i;
20785
i__4 = j + i__ * a_dim1;
20786
z__3.r = ctemp * a[i__4].r, z__3.i = ctemp * a[
20787
i__4].i;
20788
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
20789
z__3.i;
20790
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20791
/* L10: */
20792
}
20793
}
20794
/* L20: */
20795
}
20796
} else if (lsame_(direct, "B")) {
20797
for (j = *m - 1; j >= 1; --j) {
20798
ctemp = c__[j];
20799
stemp = s[j];
20800
if (ctemp != 1. || stemp != 0.) {
20801
i__1 = *n;
20802
for (i__ = 1; i__ <= i__1; ++i__) {
20803
i__2 = j + 1 + i__ * a_dim1;
20804
temp.r = a[i__2].r, temp.i = a[i__2].i;
20805
i__2 = j + 1 + i__ * a_dim1;
20806
z__2.r = ctemp * temp.r, z__2.i = ctemp * temp.i;
20807
i__3 = j + i__ * a_dim1;
20808
z__3.r = stemp * a[i__3].r, z__3.i = stemp * a[
20809
i__3].i;
20810
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
20811
z__3.i;
20812
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
20813
i__2 = j + i__ * a_dim1;
20814
z__2.r = stemp * temp.r, z__2.i = stemp * temp.i;
20815
i__3 = j + i__ * a_dim1;
20816
z__3.r = ctemp * a[i__3].r, z__3.i = ctemp * a[
20817
i__3].i;
20818
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
20819
z__3.i;
20820
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
20821
/* L30: */
20822
}
20823
}
20824
/* L40: */
20825
}
20826
}
20827
} else if (lsame_(pivot, "T")) {
20828
if (lsame_(direct, "F")) {
20829
i__1 = *m;
20830
for (j = 2; j <= i__1; ++j) {
20831
ctemp = c__[j - 1];
20832
stemp = s[j - 1];
20833
if (ctemp != 1. || stemp != 0.) {
20834
i__2 = *n;
20835
for (i__ = 1; i__ <= i__2; ++i__) {
20836
i__3 = j + i__ * a_dim1;
20837
temp.r = a[i__3].r, temp.i = a[i__3].i;
20838
i__3 = j + i__ * a_dim1;
20839
z__2.r = ctemp * temp.r, z__2.i = ctemp * temp.i;
20840
i__4 = i__ * a_dim1 + 1;
20841
z__3.r = stemp * a[i__4].r, z__3.i = stemp * a[
20842
i__4].i;
20843
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
20844
z__3.i;
20845
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20846
i__3 = i__ * a_dim1 + 1;
20847
z__2.r = stemp * temp.r, z__2.i = stemp * temp.i;
20848
i__4 = i__ * a_dim1 + 1;
20849
z__3.r = ctemp * a[i__4].r, z__3.i = ctemp * a[
20850
i__4].i;
20851
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
20852
z__3.i;
20853
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20854
/* L50: */
20855
}
20856
}
20857
/* L60: */
20858
}
20859
} else if (lsame_(direct, "B")) {
20860
for (j = *m; j >= 2; --j) {
20861
ctemp = c__[j - 1];
20862
stemp = s[j - 1];
20863
if (ctemp != 1. || stemp != 0.) {
20864
i__1 = *n;
20865
for (i__ = 1; i__ <= i__1; ++i__) {
20866
i__2 = j + i__ * a_dim1;
20867
temp.r = a[i__2].r, temp.i = a[i__2].i;
20868
i__2 = j + i__ * a_dim1;
20869
z__2.r = ctemp * temp.r, z__2.i = ctemp * temp.i;
20870
i__3 = i__ * a_dim1 + 1;
20871
z__3.r = stemp * a[i__3].r, z__3.i = stemp * a[
20872
i__3].i;
20873
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
20874
z__3.i;
20875
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
20876
i__2 = i__ * a_dim1 + 1;
20877
z__2.r = stemp * temp.r, z__2.i = stemp * temp.i;
20878
i__3 = i__ * a_dim1 + 1;
20879
z__3.r = ctemp * a[i__3].r, z__3.i = ctemp * a[
20880
i__3].i;
20881
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
20882
z__3.i;
20883
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
20884
/* L70: */
20885
}
20886
}
20887
/* L80: */
20888
}
20889
}
20890
} else if (lsame_(pivot, "B")) {
20891
if (lsame_(direct, "F")) {
20892
i__1 = *m - 1;
20893
for (j = 1; j <= i__1; ++j) {
20894
ctemp = c__[j];
20895
stemp = s[j];
20896
if (ctemp != 1. || stemp != 0.) {
20897
i__2 = *n;
20898
for (i__ = 1; i__ <= i__2; ++i__) {
20899
i__3 = j + i__ * a_dim1;
20900
temp.r = a[i__3].r, temp.i = a[i__3].i;
20901
i__3 = j + i__ * a_dim1;
20902
i__4 = *m + i__ * a_dim1;
20903
z__2.r = stemp * a[i__4].r, z__2.i = stemp * a[
20904
i__4].i;
20905
z__3.r = ctemp * temp.r, z__3.i = ctemp * temp.i;
20906
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
20907
z__3.i;
20908
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20909
i__3 = *m + i__ * a_dim1;
20910
i__4 = *m + i__ * a_dim1;
20911
z__2.r = ctemp * a[i__4].r, z__2.i = ctemp * a[
20912
i__4].i;
20913
z__3.r = stemp * temp.r, z__3.i = stemp * temp.i;
20914
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
20915
z__3.i;
20916
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20917
/* L90: */
20918
}
20919
}
20920
/* L100: */
20921
}
20922
} else if (lsame_(direct, "B")) {
20923
for (j = *m - 1; j >= 1; --j) {
20924
ctemp = c__[j];
20925
stemp = s[j];
20926
if (ctemp != 1. || stemp != 0.) {
20927
i__1 = *n;
20928
for (i__ = 1; i__ <= i__1; ++i__) {
20929
i__2 = j + i__ * a_dim1;
20930
temp.r = a[i__2].r, temp.i = a[i__2].i;
20931
i__2 = j + i__ * a_dim1;
20932
i__3 = *m + i__ * a_dim1;
20933
z__2.r = stemp * a[i__3].r, z__2.i = stemp * a[
20934
i__3].i;
20935
z__3.r = ctemp * temp.r, z__3.i = ctemp * temp.i;
20936
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
20937
z__3.i;
20938
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
20939
i__2 = *m + i__ * a_dim1;
20940
i__3 = *m + i__ * a_dim1;
20941
z__2.r = ctemp * a[i__3].r, z__2.i = ctemp * a[
20942
i__3].i;
20943
z__3.r = stemp * temp.r, z__3.i = stemp * temp.i;
20944
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
20945
z__3.i;
20946
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
20947
/* L110: */
20948
}
20949
}
20950
/* L120: */
20951
}
20952
}
20953
}
20954
} else if (lsame_(side, "R")) {
20955
20956
/* Form A * P' */
20957
20958
if (lsame_(pivot, "V")) {
20959
if (lsame_(direct, "F")) {
20960
i__1 = *n - 1;
20961
for (j = 1; j <= i__1; ++j) {
20962
ctemp = c__[j];
20963
stemp = s[j];
20964
if (ctemp != 1. || stemp != 0.) {
20965
i__2 = *m;
20966
for (i__ = 1; i__ <= i__2; ++i__) {
20967
i__3 = i__ + (j + 1) * a_dim1;
20968
temp.r = a[i__3].r, temp.i = a[i__3].i;
20969
i__3 = i__ + (j + 1) * a_dim1;
20970
z__2.r = ctemp * temp.r, z__2.i = ctemp * temp.i;
20971
i__4 = i__ + j * a_dim1;
20972
z__3.r = stemp * a[i__4].r, z__3.i = stemp * a[
20973
i__4].i;
20974
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
20975
z__3.i;
20976
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20977
i__3 = i__ + j * a_dim1;
20978
z__2.r = stemp * temp.r, z__2.i = stemp * temp.i;
20979
i__4 = i__ + j * a_dim1;
20980
z__3.r = ctemp * a[i__4].r, z__3.i = ctemp * a[
20981
i__4].i;
20982
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
20983
z__3.i;
20984
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
20985
/* L130: */
20986
}
20987
}
20988
/* L140: */
20989
}
20990
} else if (lsame_(direct, "B")) {
20991
for (j = *n - 1; j >= 1; --j) {
20992
ctemp = c__[j];
20993
stemp = s[j];
20994
if (ctemp != 1. || stemp != 0.) {
20995
i__1 = *m;
20996
for (i__ = 1; i__ <= i__1; ++i__) {
20997
i__2 = i__ + (j + 1) * a_dim1;
20998
temp.r = a[i__2].r, temp.i = a[i__2].i;
20999
i__2 = i__ + (j + 1) * a_dim1;
21000
z__2.r = ctemp * temp.r, z__2.i = ctemp * temp.i;
21001
i__3 = i__ + j * a_dim1;
21002
z__3.r = stemp * a[i__3].r, z__3.i = stemp * a[
21003
i__3].i;
21004
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
21005
z__3.i;
21006
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
21007
i__2 = i__ + j * a_dim1;
21008
z__2.r = stemp * temp.r, z__2.i = stemp * temp.i;
21009
i__3 = i__ + j * a_dim1;
21010
z__3.r = ctemp * a[i__3].r, z__3.i = ctemp * a[
21011
i__3].i;
21012
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
21013
z__3.i;
21014
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
21015
/* L150: */
21016
}
21017
}
21018
/* L160: */
21019
}
21020
}
21021
} else if (lsame_(pivot, "T")) {
21022
if (lsame_(direct, "F")) {
21023
i__1 = *n;
21024
for (j = 2; j <= i__1; ++j) {
21025
ctemp = c__[j - 1];
21026
stemp = s[j - 1];
21027
if (ctemp != 1. || stemp != 0.) {
21028
i__2 = *m;
21029
for (i__ = 1; i__ <= i__2; ++i__) {
21030
i__3 = i__ + j * a_dim1;
21031
temp.r = a[i__3].r, temp.i = a[i__3].i;
21032
i__3 = i__ + j * a_dim1;
21033
z__2.r = ctemp * temp.r, z__2.i = ctemp * temp.i;
21034
i__4 = i__ + a_dim1;
21035
z__3.r = stemp * a[i__4].r, z__3.i = stemp * a[
21036
i__4].i;
21037
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
21038
z__3.i;
21039
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
21040
i__3 = i__ + a_dim1;
21041
z__2.r = stemp * temp.r, z__2.i = stemp * temp.i;
21042
i__4 = i__ + a_dim1;
21043
z__3.r = ctemp * a[i__4].r, z__3.i = ctemp * a[
21044
i__4].i;
21045
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
21046
z__3.i;
21047
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
21048
/* L170: */
21049
}
21050
}
21051
/* L180: */
21052
}
21053
} else if (lsame_(direct, "B")) {
21054
for (j = *n; j >= 2; --j) {
21055
ctemp = c__[j - 1];
21056
stemp = s[j - 1];
21057
if (ctemp != 1. || stemp != 0.) {
21058
i__1 = *m;
21059
for (i__ = 1; i__ <= i__1; ++i__) {
21060
i__2 = i__ + j * a_dim1;
21061
temp.r = a[i__2].r, temp.i = a[i__2].i;
21062
i__2 = i__ + j * a_dim1;
21063
z__2.r = ctemp * temp.r, z__2.i = ctemp * temp.i;
21064
i__3 = i__ + a_dim1;
21065
z__3.r = stemp * a[i__3].r, z__3.i = stemp * a[
21066
i__3].i;
21067
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
21068
z__3.i;
21069
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
21070
i__2 = i__ + a_dim1;
21071
z__2.r = stemp * temp.r, z__2.i = stemp * temp.i;
21072
i__3 = i__ + a_dim1;
21073
z__3.r = ctemp * a[i__3].r, z__3.i = ctemp * a[
21074
i__3].i;
21075
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
21076
z__3.i;
21077
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
21078
/* L190: */
21079
}
21080
}
21081
/* L200: */
21082
}
21083
}
21084
} else if (lsame_(pivot, "B")) {
21085
if (lsame_(direct, "F")) {
21086
i__1 = *n - 1;
21087
for (j = 1; j <= i__1; ++j) {
21088
ctemp = c__[j];
21089
stemp = s[j];
21090
if (ctemp != 1. || stemp != 0.) {
21091
i__2 = *m;
21092
for (i__ = 1; i__ <= i__2; ++i__) {
21093
i__3 = i__ + j * a_dim1;
21094
temp.r = a[i__3].r, temp.i = a[i__3].i;
21095
i__3 = i__ + j * a_dim1;
21096
i__4 = i__ + *n * a_dim1;
21097
z__2.r = stemp * a[i__4].r, z__2.i = stemp * a[
21098
i__4].i;
21099
z__3.r = ctemp * temp.r, z__3.i = ctemp * temp.i;
21100
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
21101
z__3.i;
21102
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
21103
i__3 = i__ + *n * a_dim1;
21104
i__4 = i__ + *n * a_dim1;
21105
z__2.r = ctemp * a[i__4].r, z__2.i = ctemp * a[
21106
i__4].i;
21107
z__3.r = stemp * temp.r, z__3.i = stemp * temp.i;
21108
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
21109
z__3.i;
21110
a[i__3].r = z__1.r, a[i__3].i = z__1.i;
21111
/* L210: */
21112
}
21113
}
21114
/* L220: */
21115
}
21116
} else if (lsame_(direct, "B")) {
21117
for (j = *n - 1; j >= 1; --j) {
21118
ctemp = c__[j];
21119
stemp = s[j];
21120
if (ctemp != 1. || stemp != 0.) {
21121
i__1 = *m;
21122
for (i__ = 1; i__ <= i__1; ++i__) {
21123
i__2 = i__ + j * a_dim1;
21124
temp.r = a[i__2].r, temp.i = a[i__2].i;
21125
i__2 = i__ + j * a_dim1;
21126
i__3 = i__ + *n * a_dim1;
21127
z__2.r = stemp * a[i__3].r, z__2.i = stemp * a[
21128
i__3].i;
21129
z__3.r = ctemp * temp.r, z__3.i = ctemp * temp.i;
21130
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i +
21131
z__3.i;
21132
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
21133
i__2 = i__ + *n * a_dim1;
21134
i__3 = i__ + *n * a_dim1;
21135
z__2.r = ctemp * a[i__3].r, z__2.i = ctemp * a[
21136
i__3].i;
21137
z__3.r = stemp * temp.r, z__3.i = stemp * temp.i;
21138
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i -
21139
z__3.i;
21140
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
21141
/* L230: */
21142
}
21143
}
21144
/* L240: */
21145
}
21146
}
21147
}
21148
}
21149
21150
return 0;
21151
21152
/* End of ZLASR */
21153
21154
} /* zlasr_ */
21155
21156
/* Subroutine */ int zlassq_(integer *n, doublecomplex *x, integer *incx,
21157
doublereal *scale, doublereal *sumsq)
21158
{
21159
/* System generated locals */
21160
integer i__1, i__2, i__3;
21161
doublereal d__1;
21162
21163
/* Local variables */
21164
static integer ix;
21165
static doublereal temp1;
21166
21167
21168
/*
21169
-- LAPACK auxiliary routine (version 3.2) --
21170
-- LAPACK is a software package provided by Univ. of Tennessee, --
21171
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
21172
November 2006
21173
21174
21175
Purpose
21176
=======
21177
21178
ZLASSQ returns the values scl and ssq such that
21179
21180
( scl**2 )*ssq = x( 1 )**2 +...+ x( n )**2 + ( scale**2 )*sumsq,
21181
21182
where x( i ) = abs( X( 1 + ( i - 1 )*INCX ) ). The value of sumsq is
21183
assumed to be at least unity and the value of ssq will then satisfy
21184
21185
1.0 .le. ssq .le. ( sumsq + 2*n ).
21186
21187
scale is assumed to be non-negative and scl returns the value
21188
21189
scl = max( scale, abs( real( x( i ) ) ), abs( aimag( x( i ) ) ) ),
21190
i
21191
21192
scale and sumsq must be supplied in SCALE and SUMSQ respectively.
21193
SCALE and SUMSQ are overwritten by scl and ssq respectively.
21194
21195
The routine makes only one pass through the vector X.
21196
21197
Arguments
21198
=========
21199
21200
N (input) INTEGER
21201
The number of elements to be used from the vector X.
21202
21203
X (input) COMPLEX*16 array, dimension (N)
21204
The vector x as described above.
21205
x( i ) = X( 1 + ( i - 1 )*INCX ), 1 <= i <= n.
21206
21207
INCX (input) INTEGER
21208
The increment between successive values of the vector X.
21209
INCX > 0.
21210
21211
SCALE (input/output) DOUBLE PRECISION
21212
On entry, the value scale in the equation above.
21213
On exit, SCALE is overwritten with the value scl .
21214
21215
SUMSQ (input/output) DOUBLE PRECISION
21216
On entry, the value sumsq in the equation above.
21217
On exit, SUMSQ is overwritten with the value ssq .
21218
21219
=====================================================================
21220
*/
21221
21222
21223
/* Parameter adjustments */
21224
--x;
21225
21226
/* Function Body */
21227
if (*n > 0) {
21228
i__1 = (*n - 1) * *incx + 1;
21229
i__2 = *incx;
21230
for (ix = 1; i__2 < 0 ? ix >= i__1 : ix <= i__1; ix += i__2) {
21231
i__3 = ix;
21232
if (x[i__3].r != 0.) {
21233
i__3 = ix;
21234
temp1 = (d__1 = x[i__3].r, abs(d__1));
21235
if (*scale < temp1) {
21236
/* Computing 2nd power */
21237
d__1 = *scale / temp1;
21238
*sumsq = *sumsq * (d__1 * d__1) + 1;
21239
*scale = temp1;
21240
} else {
21241
/* Computing 2nd power */
21242
d__1 = temp1 / *scale;
21243
*sumsq += d__1 * d__1;
21244
}
21245
}
21246
if (d_imag(&x[ix]) != 0.) {
21247
temp1 = (d__1 = d_imag(&x[ix]), abs(d__1));
21248
if (*scale < temp1) {
21249
/* Computing 2nd power */
21250
d__1 = *scale / temp1;
21251
*sumsq = *sumsq * (d__1 * d__1) + 1;
21252
*scale = temp1;
21253
} else {
21254
/* Computing 2nd power */
21255
d__1 = temp1 / *scale;
21256
*sumsq += d__1 * d__1;
21257
}
21258
}
21259
/* L10: */
21260
}
21261
}
21262
21263
return 0;
21264
21265
/* End of ZLASSQ */
21266
21267
} /* zlassq_ */
21268
21269
/* Subroutine */ int zlaswp_(integer *n, doublecomplex *a, integer *lda,
21270
integer *k1, integer *k2, integer *ipiv, integer *incx)
21271
{
21272
/* System generated locals */
21273
integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
21274
21275
/* Local variables */
21276
static integer i__, j, k, i1, i2, n32, ip, ix, ix0, inc;
21277
static doublecomplex temp;
21278
21279
21280
/*
21281
-- LAPACK auxiliary routine (version 3.2) --
21282
-- LAPACK is a software package provided by Univ. of Tennessee, --
21283
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
21284
November 2006
21285
21286
21287
Purpose
21288
=======
21289
21290
ZLASWP performs a series of row interchanges on the matrix A.
21291
One row interchange is initiated for each of rows K1 through K2 of A.
21292
21293
Arguments
21294
=========
21295
21296
N (input) INTEGER
21297
The number of columns of the matrix A.
21298
21299
A (input/output) COMPLEX*16 array, dimension (LDA,N)
21300
On entry, the matrix of column dimension N to which the row
21301
interchanges will be applied.
21302
On exit, the permuted matrix.
21303
21304
LDA (input) INTEGER
21305
The leading dimension of the array A.
21306
21307
K1 (input) INTEGER
21308
The first element of IPIV for which a row interchange will
21309
be done.
21310
21311
K2 (input) INTEGER
21312
The last element of IPIV for which a row interchange will
21313
be done.
21314
21315
IPIV (input) INTEGER array, dimension (K2*abs(INCX))
21316
The vector of pivot indices. Only the elements in positions
21317
K1 through K2 of IPIV are accessed.
21318
IPIV(K) = L implies rows K and L are to be interchanged.
21319
21320
INCX (input) INTEGER
21321
The increment between successive values of IPIV. If IPIV
21322
is negative, the pivots are applied in reverse order.
21323
21324
Further Details
21325
===============
21326
21327
Modified by
21328
R. C. Whaley, Computer Science Dept., Univ. of Tenn., Knoxville, USA
21329
21330
=====================================================================
21331
21332
21333
Interchange row I with row IPIV(I) for each of rows K1 through K2.
21334
*/
21335
21336
/* Parameter adjustments */
21337
a_dim1 = *lda;
21338
a_offset = 1 + a_dim1;
21339
a -= a_offset;
21340
--ipiv;
21341
21342
/* Function Body */
21343
if (*incx > 0) {
21344
ix0 = *k1;
21345
i1 = *k1;
21346
i2 = *k2;
21347
inc = 1;
21348
} else if (*incx < 0) {
21349
ix0 = (1 - *k2) * *incx + 1;
21350
i1 = *k2;
21351
i2 = *k1;
21352
inc = -1;
21353
} else {
21354
return 0;
21355
}
21356
21357
n32 = *n / 32 << 5;
21358
if (n32 != 0) {
21359
i__1 = n32;
21360
for (j = 1; j <= i__1; j += 32) {
21361
ix = ix0;
21362
i__2 = i2;
21363
i__3 = inc;
21364
for (i__ = i1; i__3 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__3)
21365
{
21366
ip = ipiv[ix];
21367
if (ip != i__) {
21368
i__4 = j + 31;
21369
for (k = j; k <= i__4; ++k) {
21370
i__5 = i__ + k * a_dim1;
21371
temp.r = a[i__5].r, temp.i = a[i__5].i;
21372
i__5 = i__ + k * a_dim1;
21373
i__6 = ip + k * a_dim1;
21374
a[i__5].r = a[i__6].r, a[i__5].i = a[i__6].i;
21375
i__5 = ip + k * a_dim1;
21376
a[i__5].r = temp.r, a[i__5].i = temp.i;
21377
/* L10: */
21378
}
21379
}
21380
ix += *incx;
21381
/* L20: */
21382
}
21383
/* L30: */
21384
}
21385
}
21386
if (n32 != *n) {
21387
++n32;
21388
ix = ix0;
21389
i__1 = i2;
21390
i__3 = inc;
21391
for (i__ = i1; i__3 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__3) {
21392
ip = ipiv[ix];
21393
if (ip != i__) {
21394
i__2 = *n;
21395
for (k = n32; k <= i__2; ++k) {
21396
i__4 = i__ + k * a_dim1;
21397
temp.r = a[i__4].r, temp.i = a[i__4].i;
21398
i__4 = i__ + k * a_dim1;
21399
i__5 = ip + k * a_dim1;
21400
a[i__4].r = a[i__5].r, a[i__4].i = a[i__5].i;
21401
i__4 = ip + k * a_dim1;
21402
a[i__4].r = temp.r, a[i__4].i = temp.i;
21403
/* L40: */
21404
}
21405
}
21406
ix += *incx;
21407
/* L50: */
21408
}
21409
}
21410
21411
return 0;
21412
21413
/* End of ZLASWP */
21414
21415
} /* zlaswp_ */
21416
21417
/* Subroutine */ int zlatrd_(char *uplo, integer *n, integer *nb,
21418
doublecomplex *a, integer *lda, doublereal *e, doublecomplex *tau,
21419
doublecomplex *w, integer *ldw)
21420
{
21421
/* System generated locals */
21422
integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3;
21423
doublereal d__1;
21424
doublecomplex z__1, z__2, z__3, z__4;
21425
21426
/* Local variables */
21427
static integer i__, iw;
21428
static doublecomplex alpha;
21429
extern logical lsame_(char *, char *);
21430
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
21431
doublecomplex *, integer *);
21432
extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
21433
doublecomplex *, integer *, doublecomplex *, integer *);
21434
extern /* Subroutine */ int zgemv_(char *, integer *, integer *,
21435
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
21436
integer *, doublecomplex *, doublecomplex *, integer *),
21437
zhemv_(char *, integer *, doublecomplex *, doublecomplex *,
21438
integer *, doublecomplex *, integer *, doublecomplex *,
21439
doublecomplex *, integer *), zaxpy_(integer *,
21440
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
21441
integer *), zlarfg_(integer *, doublecomplex *, doublecomplex *,
21442
integer *, doublecomplex *), zlacgv_(integer *, doublecomplex *,
21443
integer *);
21444
21445
21446
/*
21447
-- LAPACK auxiliary routine (version 3.2) --
21448
-- LAPACK is a software package provided by Univ. of Tennessee, --
21449
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
21450
November 2006
21451
21452
21453
Purpose
21454
=======
21455
21456
ZLATRD reduces NB rows and columns of a complex Hermitian matrix A to
21457
Hermitian tridiagonal form by a unitary similarity
21458
transformation Q' * A * Q, and returns the matrices V and W which are
21459
needed to apply the transformation to the unreduced part of A.
21460
21461
If UPLO = 'U', ZLATRD reduces the last NB rows and columns of a
21462
matrix, of which the upper triangle is supplied;
21463
if UPLO = 'L', ZLATRD reduces the first NB rows and columns of a
21464
matrix, of which the lower triangle is supplied.
21465
21466
This is an auxiliary routine called by ZHETRD.
21467
21468
Arguments
21469
=========
21470
21471
UPLO (input) CHARACTER*1
21472
Specifies whether the upper or lower triangular part of the
21473
Hermitian matrix A is stored:
21474
= 'U': Upper triangular
21475
= 'L': Lower triangular
21476
21477
N (input) INTEGER
21478
The order of the matrix A.
21479
21480
NB (input) INTEGER
21481
The number of rows and columns to be reduced.
21482
21483
A (input/output) COMPLEX*16 array, dimension (LDA,N)
21484
On entry, the Hermitian matrix A. If UPLO = 'U', the leading
21485
n-by-n upper triangular part of A contains the upper
21486
triangular part of the matrix A, and the strictly lower
21487
triangular part of A is not referenced. If UPLO = 'L', the
21488
leading n-by-n lower triangular part of A contains the lower
21489
triangular part of the matrix A, and the strictly upper
21490
triangular part of A is not referenced.
21491
On exit:
21492
if UPLO = 'U', the last NB columns have been reduced to
21493
tridiagonal form, with the diagonal elements overwriting
21494
the diagonal elements of A; the elements above the diagonal
21495
with the array TAU, represent the unitary matrix Q as a
21496
product of elementary reflectors;
21497
if UPLO = 'L', the first NB columns have been reduced to
21498
tridiagonal form, with the diagonal elements overwriting
21499
the diagonal elements of A; the elements below the diagonal
21500
with the array TAU, represent the unitary matrix Q as a
21501
product of elementary reflectors.
21502
See Further Details.
21503
21504
LDA (input) INTEGER
21505
The leading dimension of the array A. LDA >= max(1,N).
21506
21507
E (output) DOUBLE PRECISION array, dimension (N-1)
21508
If UPLO = 'U', E(n-nb:n-1) contains the superdiagonal
21509
elements of the last NB columns of the reduced matrix;
21510
if UPLO = 'L', E(1:nb) contains the subdiagonal elements of
21511
the first NB columns of the reduced matrix.
21512
21513
TAU (output) COMPLEX*16 array, dimension (N-1)
21514
The scalar factors of the elementary reflectors, stored in
21515
TAU(n-nb:n-1) if UPLO = 'U', and in TAU(1:nb) if UPLO = 'L'.
21516
See Further Details.
21517
21518
W (output) COMPLEX*16 array, dimension (LDW,NB)
21519
The n-by-nb matrix W required to update the unreduced part
21520
of A.
21521
21522
LDW (input) INTEGER
21523
The leading dimension of the array W. LDW >= max(1,N).
21524
21525
Further Details
21526
===============
21527
21528
If UPLO = 'U', the matrix Q is represented as a product of elementary
21529
reflectors
21530
21531
Q = H(n) H(n-1) . . . H(n-nb+1).
21532
21533
Each H(i) has the form
21534
21535
H(i) = I - tau * v * v'
21536
21537
where tau is a complex scalar, and v is a complex vector with
21538
v(i:n) = 0 and v(i-1) = 1; v(1:i-1) is stored on exit in A(1:i-1,i),
21539
and tau in TAU(i-1).
21540
21541
If UPLO = 'L', the matrix Q is represented as a product of elementary
21542
reflectors
21543
21544
Q = H(1) H(2) . . . H(nb).
21545
21546
Each H(i) has the form
21547
21548
H(i) = I - tau * v * v'
21549
21550
where tau is a complex scalar, and v is a complex vector with
21551
v(1:i) = 0 and v(i+1) = 1; v(i+1:n) is stored on exit in A(i+1:n,i),
21552
and tau in TAU(i).
21553
21554
The elements of the vectors v together form the n-by-nb matrix V
21555
which is needed, with W, to apply the transformation to the unreduced
21556
part of the matrix, using a Hermitian rank-2k update of the form:
21557
A := A - V*W' - W*V'.
21558
21559
The contents of A on exit are illustrated by the following examples
21560
with n = 5 and nb = 2:
21561
21562
if UPLO = 'U': if UPLO = 'L':
21563
21564
( a a a v4 v5 ) ( d )
21565
( a a v4 v5 ) ( 1 d )
21566
( a 1 v5 ) ( v1 1 a )
21567
( d 1 ) ( v1 v2 a a )
21568
( d ) ( v1 v2 a a a )
21569
21570
where d denotes a diagonal element of the reduced matrix, a denotes
21571
an element of the original matrix that is unchanged, and vi denotes
21572
an element of the vector defining H(i).
21573
21574
=====================================================================
21575
21576
21577
Quick return if possible
21578
*/
21579
21580
/* Parameter adjustments */
21581
a_dim1 = *lda;
21582
a_offset = 1 + a_dim1;
21583
a -= a_offset;
21584
--e;
21585
--tau;
21586
w_dim1 = *ldw;
21587
w_offset = 1 + w_dim1;
21588
w -= w_offset;
21589
21590
/* Function Body */
21591
if (*n <= 0) {
21592
return 0;
21593
}
21594
21595
if (lsame_(uplo, "U")) {
21596
21597
/* Reduce last NB columns of upper triangle */
21598
21599
i__1 = *n - *nb + 1;
21600
for (i__ = *n; i__ >= i__1; --i__) {
21601
iw = i__ - *n + *nb;
21602
if (i__ < *n) {
21603
21604
/* Update A(1:i,i) */
21605
21606
i__2 = i__ + i__ * a_dim1;
21607
i__3 = i__ + i__ * a_dim1;
21608
d__1 = a[i__3].r;
21609
a[i__2].r = d__1, a[i__2].i = 0.;
21610
i__2 = *n - i__;
21611
zlacgv_(&i__2, &w[i__ + (iw + 1) * w_dim1], ldw);
21612
i__2 = *n - i__;
21613
z__1.r = -1., z__1.i = -0.;
21614
zgemv_("No transpose", &i__, &i__2, &z__1, &a[(i__ + 1) *
21615
a_dim1 + 1], lda, &w[i__ + (iw + 1) * w_dim1], ldw, &
21616
c_b57, &a[i__ * a_dim1 + 1], &c__1);
21617
i__2 = *n - i__;
21618
zlacgv_(&i__2, &w[i__ + (iw + 1) * w_dim1], ldw);
21619
i__2 = *n - i__;
21620
zlacgv_(&i__2, &a[i__ + (i__ + 1) * a_dim1], lda);
21621
i__2 = *n - i__;
21622
z__1.r = -1., z__1.i = -0.;
21623
zgemv_("No transpose", &i__, &i__2, &z__1, &w[(iw + 1) *
21624
w_dim1 + 1], ldw, &a[i__ + (i__ + 1) * a_dim1], lda, &
21625
c_b57, &a[i__ * a_dim1 + 1], &c__1);
21626
i__2 = *n - i__;
21627
zlacgv_(&i__2, &a[i__ + (i__ + 1) * a_dim1], lda);
21628
i__2 = i__ + i__ * a_dim1;
21629
i__3 = i__ + i__ * a_dim1;
21630
d__1 = a[i__3].r;
21631
a[i__2].r = d__1, a[i__2].i = 0.;
21632
}
21633
if (i__ > 1) {
21634
21635
/*
21636
Generate elementary reflector H(i) to annihilate
21637
A(1:i-2,i)
21638
*/
21639
21640
i__2 = i__ - 1 + i__ * a_dim1;
21641
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
21642
i__2 = i__ - 1;
21643
zlarfg_(&i__2, &alpha, &a[i__ * a_dim1 + 1], &c__1, &tau[i__
21644
- 1]);
21645
i__2 = i__ - 1;
21646
e[i__2] = alpha.r;
21647
i__2 = i__ - 1 + i__ * a_dim1;
21648
a[i__2].r = 1., a[i__2].i = 0.;
21649
21650
/* Compute W(1:i-1,i) */
21651
21652
i__2 = i__ - 1;
21653
zhemv_("Upper", &i__2, &c_b57, &a[a_offset], lda, &a[i__ *
21654
a_dim1 + 1], &c__1, &c_b56, &w[iw * w_dim1 + 1], &
21655
c__1);
21656
if (i__ < *n) {
21657
i__2 = i__ - 1;
21658
i__3 = *n - i__;
21659
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &w[(
21660
iw + 1) * w_dim1 + 1], ldw, &a[i__ * a_dim1 + 1],
21661
&c__1, &c_b56, &w[i__ + 1 + iw * w_dim1], &c__1);
21662
i__2 = i__ - 1;
21663
i__3 = *n - i__;
21664
z__1.r = -1., z__1.i = -0.;
21665
zgemv_("No transpose", &i__2, &i__3, &z__1, &a[(i__ + 1) *
21666
a_dim1 + 1], lda, &w[i__ + 1 + iw * w_dim1], &
21667
c__1, &c_b57, &w[iw * w_dim1 + 1], &c__1);
21668
i__2 = i__ - 1;
21669
i__3 = *n - i__;
21670
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &a[(
21671
i__ + 1) * a_dim1 + 1], lda, &a[i__ * a_dim1 + 1],
21672
&c__1, &c_b56, &w[i__ + 1 + iw * w_dim1], &c__1);
21673
i__2 = i__ - 1;
21674
i__3 = *n - i__;
21675
z__1.r = -1., z__1.i = -0.;
21676
zgemv_("No transpose", &i__2, &i__3, &z__1, &w[(iw + 1) *
21677
w_dim1 + 1], ldw, &w[i__ + 1 + iw * w_dim1], &
21678
c__1, &c_b57, &w[iw * w_dim1 + 1], &c__1);
21679
}
21680
i__2 = i__ - 1;
21681
zscal_(&i__2, &tau[i__ - 1], &w[iw * w_dim1 + 1], &c__1);
21682
z__3.r = -.5, z__3.i = -0.;
21683
i__2 = i__ - 1;
21684
z__2.r = z__3.r * tau[i__2].r - z__3.i * tau[i__2].i, z__2.i =
21685
z__3.r * tau[i__2].i + z__3.i * tau[i__2].r;
21686
i__3 = i__ - 1;
21687
zdotc_(&z__4, &i__3, &w[iw * w_dim1 + 1], &c__1, &a[i__ *
21688
a_dim1 + 1], &c__1);
21689
z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r *
21690
z__4.i + z__2.i * z__4.r;
21691
alpha.r = z__1.r, alpha.i = z__1.i;
21692
i__2 = i__ - 1;
21693
zaxpy_(&i__2, &alpha, &a[i__ * a_dim1 + 1], &c__1, &w[iw *
21694
w_dim1 + 1], &c__1);
21695
}
21696
21697
/* L10: */
21698
}
21699
} else {
21700
21701
/* Reduce first NB columns of lower triangle */
21702
21703
i__1 = *nb;
21704
for (i__ = 1; i__ <= i__1; ++i__) {
21705
21706
/* Update A(i:n,i) */
21707
21708
i__2 = i__ + i__ * a_dim1;
21709
i__3 = i__ + i__ * a_dim1;
21710
d__1 = a[i__3].r;
21711
a[i__2].r = d__1, a[i__2].i = 0.;
21712
i__2 = i__ - 1;
21713
zlacgv_(&i__2, &w[i__ + w_dim1], ldw);
21714
i__2 = *n - i__ + 1;
21715
i__3 = i__ - 1;
21716
z__1.r = -1., z__1.i = -0.;
21717
zgemv_("No transpose", &i__2, &i__3, &z__1, &a[i__ + a_dim1], lda,
21718
&w[i__ + w_dim1], ldw, &c_b57, &a[i__ + i__ * a_dim1], &
21719
c__1);
21720
i__2 = i__ - 1;
21721
zlacgv_(&i__2, &w[i__ + w_dim1], ldw);
21722
i__2 = i__ - 1;
21723
zlacgv_(&i__2, &a[i__ + a_dim1], lda);
21724
i__2 = *n - i__ + 1;
21725
i__3 = i__ - 1;
21726
z__1.r = -1., z__1.i = -0.;
21727
zgemv_("No transpose", &i__2, &i__3, &z__1, &w[i__ + w_dim1], ldw,
21728
&a[i__ + a_dim1], lda, &c_b57, &a[i__ + i__ * a_dim1], &
21729
c__1);
21730
i__2 = i__ - 1;
21731
zlacgv_(&i__2, &a[i__ + a_dim1], lda);
21732
i__2 = i__ + i__ * a_dim1;
21733
i__3 = i__ + i__ * a_dim1;
21734
d__1 = a[i__3].r;
21735
a[i__2].r = d__1, a[i__2].i = 0.;
21736
if (i__ < *n) {
21737
21738
/*
21739
Generate elementary reflector H(i) to annihilate
21740
A(i+2:n,i)
21741
*/
21742
21743
i__2 = i__ + 1 + i__ * a_dim1;
21744
alpha.r = a[i__2].r, alpha.i = a[i__2].i;
21745
i__2 = *n - i__;
21746
/* Computing MIN */
21747
i__3 = i__ + 2;
21748
zlarfg_(&i__2, &alpha, &a[min(i__3,*n) + i__ * a_dim1], &c__1,
21749
&tau[i__]);
21750
i__2 = i__;
21751
e[i__2] = alpha.r;
21752
i__2 = i__ + 1 + i__ * a_dim1;
21753
a[i__2].r = 1., a[i__2].i = 0.;
21754
21755
/* Compute W(i+1:n,i) */
21756
21757
i__2 = *n - i__;
21758
zhemv_("Lower", &i__2, &c_b57, &a[i__ + 1 + (i__ + 1) *
21759
a_dim1], lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &
21760
c_b56, &w[i__ + 1 + i__ * w_dim1], &c__1);
21761
i__2 = *n - i__;
21762
i__3 = i__ - 1;
21763
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &w[i__ +
21764
1 + w_dim1], ldw, &a[i__ + 1 + i__ * a_dim1], &c__1, &
21765
c_b56, &w[i__ * w_dim1 + 1], &c__1);
21766
i__2 = *n - i__;
21767
i__3 = i__ - 1;
21768
z__1.r = -1., z__1.i = -0.;
21769
zgemv_("No transpose", &i__2, &i__3, &z__1, &a[i__ + 1 +
21770
a_dim1], lda, &w[i__ * w_dim1 + 1], &c__1, &c_b57, &w[
21771
i__ + 1 + i__ * w_dim1], &c__1);
21772
i__2 = *n - i__;
21773
i__3 = i__ - 1;
21774
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &a[i__ +
21775
1 + a_dim1], lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &
21776
c_b56, &w[i__ * w_dim1 + 1], &c__1);
21777
i__2 = *n - i__;
21778
i__3 = i__ - 1;
21779
z__1.r = -1., z__1.i = -0.;
21780
zgemv_("No transpose", &i__2, &i__3, &z__1, &w[i__ + 1 +
21781
w_dim1], ldw, &w[i__ * w_dim1 + 1], &c__1, &c_b57, &w[
21782
i__ + 1 + i__ * w_dim1], &c__1);
21783
i__2 = *n - i__;
21784
zscal_(&i__2, &tau[i__], &w[i__ + 1 + i__ * w_dim1], &c__1);
21785
z__3.r = -.5, z__3.i = -0.;
21786
i__2 = i__;
21787
z__2.r = z__3.r * tau[i__2].r - z__3.i * tau[i__2].i, z__2.i =
21788
z__3.r * tau[i__2].i + z__3.i * tau[i__2].r;
21789
i__3 = *n - i__;
21790
zdotc_(&z__4, &i__3, &w[i__ + 1 + i__ * w_dim1], &c__1, &a[
21791
i__ + 1 + i__ * a_dim1], &c__1);
21792
z__1.r = z__2.r * z__4.r - z__2.i * z__4.i, z__1.i = z__2.r *
21793
z__4.i + z__2.i * z__4.r;
21794
alpha.r = z__1.r, alpha.i = z__1.i;
21795
i__2 = *n - i__;
21796
zaxpy_(&i__2, &alpha, &a[i__ + 1 + i__ * a_dim1], &c__1, &w[
21797
i__ + 1 + i__ * w_dim1], &c__1);
21798
}
21799
21800
/* L20: */
21801
}
21802
}
21803
21804
return 0;
21805
21806
/* End of ZLATRD */
21807
21808
} /* zlatrd_ */
21809
21810
/* Subroutine */ int zlatrs_(char *uplo, char *trans, char *diag, char *
21811
normin, integer *n, doublecomplex *a, integer *lda, doublecomplex *x,
21812
doublereal *scale, doublereal *cnorm, integer *info)
21813
{
21814
/* System generated locals */
21815
integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
21816
doublereal d__1, d__2, d__3, d__4;
21817
doublecomplex z__1, z__2, z__3, z__4;
21818
21819
/* Local variables */
21820
static integer i__, j;
21821
static doublereal xj, rec, tjj;
21822
static integer jinc;
21823
static doublereal xbnd;
21824
static integer imax;
21825
static doublereal tmax;
21826
static doublecomplex tjjs;
21827
static doublereal xmax, grow;
21828
extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
21829
integer *);
21830
extern logical lsame_(char *, char *);
21831
static doublereal tscal;
21832
static doublecomplex uscal;
21833
static integer jlast;
21834
static doublecomplex csumj;
21835
extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
21836
doublecomplex *, integer *, doublecomplex *, integer *);
21837
static logical upper;
21838
extern /* Double Complex */ VOID zdotu_(doublecomplex *, integer *,
21839
doublecomplex *, integer *, doublecomplex *, integer *);
21840
extern /* Subroutine */ int zaxpy_(integer *, doublecomplex *,
21841
doublecomplex *, integer *, doublecomplex *, integer *), ztrsv_(
21842
char *, char *, char *, integer *, doublecomplex *, integer *,
21843
doublecomplex *, integer *), dlabad_(
21844
doublereal *, doublereal *);
21845
21846
extern integer idamax_(integer *, doublereal *, integer *);
21847
extern /* Subroutine */ int xerbla_(char *, integer *), zdscal_(
21848
integer *, doublereal *, doublecomplex *, integer *);
21849
static doublereal bignum;
21850
extern integer izamax_(integer *, doublecomplex *, integer *);
21851
extern /* Double Complex */ VOID zladiv_(doublecomplex *, doublecomplex *,
21852
doublecomplex *);
21853
static logical notran;
21854
static integer jfirst;
21855
extern doublereal dzasum_(integer *, doublecomplex *, integer *);
21856
static doublereal smlnum;
21857
static logical nounit;
21858
21859
21860
/*
21861
-- LAPACK auxiliary routine (version 3.2) --
21862
-- LAPACK is a software package provided by Univ. of Tennessee, --
21863
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
21864
November 2006
21865
21866
21867
Purpose
21868
=======
21869
21870
ZLATRS solves one of the triangular systems
21871
21872
A * x = s*b, A**T * x = s*b, or A**H * x = s*b,
21873
21874
with scaling to prevent overflow. Here A is an upper or lower
21875
triangular matrix, A**T denotes the transpose of A, A**H denotes the
21876
conjugate transpose of A, x and b are n-element vectors, and s is a
21877
scaling factor, usually less than or equal to 1, chosen so that the
21878
components of x will be less than the overflow threshold. If the
21879
unscaled problem will not cause overflow, the Level 2 BLAS routine
21880
ZTRSV is called. If the matrix A is singular (A(j,j) = 0 for some j),
21881
then s is set to 0 and a non-trivial solution to A*x = 0 is returned.
21882
21883
Arguments
21884
=========
21885
21886
UPLO (input) CHARACTER*1
21887
Specifies whether the matrix A is upper or lower triangular.
21888
= 'U': Upper triangular
21889
= 'L': Lower triangular
21890
21891
TRANS (input) CHARACTER*1
21892
Specifies the operation applied to A.
21893
= 'N': Solve A * x = s*b (No transpose)
21894
= 'T': Solve A**T * x = s*b (Transpose)
21895
= 'C': Solve A**H * x = s*b (Conjugate transpose)
21896
21897
DIAG (input) CHARACTER*1
21898
Specifies whether or not the matrix A is unit triangular.
21899
= 'N': Non-unit triangular
21900
= 'U': Unit triangular
21901
21902
NORMIN (input) CHARACTER*1
21903
Specifies whether CNORM has been set or not.
21904
= 'Y': CNORM contains the column norms on entry
21905
= 'N': CNORM is not set on entry. On exit, the norms will
21906
be computed and stored in CNORM.
21907
21908
N (input) INTEGER
21909
The order of the matrix A. N >= 0.
21910
21911
A (input) COMPLEX*16 array, dimension (LDA,N)
21912
The triangular matrix A. If UPLO = 'U', the leading n by n
21913
upper triangular part of the array A contains the upper
21914
triangular matrix, and the strictly lower triangular part of
21915
A is not referenced. If UPLO = 'L', the leading n by n lower
21916
triangular part of the array A contains the lower triangular
21917
matrix, and the strictly upper triangular part of A is not
21918
referenced. If DIAG = 'U', the diagonal elements of A are
21919
also not referenced and are assumed to be 1.
21920
21921
LDA (input) INTEGER
21922
The leading dimension of the array A. LDA >= max (1,N).
21923
21924
X (input/output) COMPLEX*16 array, dimension (N)
21925
On entry, the right hand side b of the triangular system.
21926
On exit, X is overwritten by the solution vector x.
21927
21928
SCALE (output) DOUBLE PRECISION
21929
The scaling factor s for the triangular system
21930
A * x = s*b, A**T * x = s*b, or A**H * x = s*b.
21931
If SCALE = 0, the matrix A is singular or badly scaled, and
21932
the vector x is an exact or approximate solution to A*x = 0.
21933
21934
CNORM (input or output) DOUBLE PRECISION array, dimension (N)
21935
21936
If NORMIN = 'Y', CNORM is an input argument and CNORM(j)
21937
contains the norm of the off-diagonal part of the j-th column
21938
of A. If TRANS = 'N', CNORM(j) must be greater than or equal
21939
to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j)
21940
must be greater than or equal to the 1-norm.
21941
21942
If NORMIN = 'N', CNORM is an output argument and CNORM(j)
21943
returns the 1-norm of the offdiagonal part of the j-th column
21944
of A.
21945
21946
INFO (output) INTEGER
21947
= 0: successful exit
21948
< 0: if INFO = -k, the k-th argument had an illegal value
21949
21950
Further Details
21951
======= =======
21952
21953
A rough bound on x is computed; if that is less than overflow, ZTRSV
21954
is called, otherwise, specific code is used which checks for possible
21955
overflow or divide-by-zero at every operation.
21956
21957
A columnwise scheme is used for solving A*x = b. The basic algorithm
21958
if A is lower triangular is
21959
21960
x[1:n] := b[1:n]
21961
for j = 1, ..., n
21962
x(j) := x(j) / A(j,j)
21963
x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j]
21964
end
21965
21966
Define bounds on the components of x after j iterations of the loop:
21967
M(j) = bound on x[1:j]
21968
G(j) = bound on x[j+1:n]
21969
Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}.
21970
21971
Then for iteration j+1 we have
21972
M(j+1) <= G(j) / | A(j+1,j+1) |
21973
G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] |
21974
<= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | )
21975
21976
where CNORM(j+1) is greater than or equal to the infinity-norm of
21977
column j+1 of A, not counting the diagonal. Hence
21978
21979
G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | )
21980
1<=i<=j
21981
and
21982
21983
|x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| )
21984
1<=i< j
21985
21986
Since |x(j)| <= M(j), we use the Level 2 BLAS routine ZTRSV if the
21987
reciprocal of the largest M(j), j=1,..,n, is larger than
21988
max(underflow, 1/overflow).
21989
21990
The bound on x(j) is also used to determine when a step in the
21991
columnwise method can be performed without fear of overflow. If
21992
the computed bound is greater than a large constant, x is scaled to
21993
prevent overflow, but if the bound overflows, x is set to 0, x(j) to
21994
1, and scale to 0, and a non-trivial solution to A*x = 0 is found.
21995
21996
Similarly, a row-wise scheme is used to solve A**T *x = b or
21997
A**H *x = b. The basic algorithm for A upper triangular is
21998
21999
for j = 1, ..., n
22000
x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j)
22001
end
22002
22003
We simultaneously compute two bounds
22004
G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j
22005
M(j) = bound on x(i), 1<=i<=j
22006
22007
The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we
22008
add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1.
22009
Then the bound on x(j) is
22010
22011
M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) |
22012
22013
<= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| )
22014
1<=i<=j
22015
22016
and we can safely call ZTRSV if 1/M(n) and 1/G(n) are both greater
22017
than max(underflow, 1/overflow).
22018
22019
=====================================================================
22020
*/
22021
22022
22023
/* Parameter adjustments */
22024
a_dim1 = *lda;
22025
a_offset = 1 + a_dim1;
22026
a -= a_offset;
22027
--x;
22028
--cnorm;
22029
22030
/* Function Body */
22031
*info = 0;
22032
upper = lsame_(uplo, "U");
22033
notran = lsame_(trans, "N");
22034
nounit = lsame_(diag, "N");
22035
22036
/* Test the input parameters. */
22037
22038
if (! upper && ! lsame_(uplo, "L")) {
22039
*info = -1;
22040
} else if (! notran && ! lsame_(trans, "T") && !
22041
lsame_(trans, "C")) {
22042
*info = -2;
22043
} else if (! nounit && ! lsame_(diag, "U")) {
22044
*info = -3;
22045
} else if (! lsame_(normin, "Y") && ! lsame_(normin,
22046
"N")) {
22047
*info = -4;
22048
} else if (*n < 0) {
22049
*info = -5;
22050
} else if (*lda < max(1,*n)) {
22051
*info = -7;
22052
}
22053
if (*info != 0) {
22054
i__1 = -(*info);
22055
xerbla_("ZLATRS", &i__1);
22056
return 0;
22057
}
22058
22059
/* Quick return if possible */
22060
22061
if (*n == 0) {
22062
return 0;
22063
}
22064
22065
/* Determine machine dependent parameters to control overflow. */
22066
22067
smlnum = SAFEMINIMUM;
22068
bignum = 1. / smlnum;
22069
dlabad_(&smlnum, &bignum);
22070
smlnum /= PRECISION;
22071
bignum = 1. / smlnum;
22072
*scale = 1.;
22073
22074
if (lsame_(normin, "N")) {
22075
22076
/* Compute the 1-norm of each column, not including the diagonal. */
22077
22078
if (upper) {
22079
22080
/* A is upper triangular. */
22081
22082
i__1 = *n;
22083
for (j = 1; j <= i__1; ++j) {
22084
i__2 = j - 1;
22085
cnorm[j] = dzasum_(&i__2, &a[j * a_dim1 + 1], &c__1);
22086
/* L10: */
22087
}
22088
} else {
22089
22090
/* A is lower triangular. */
22091
22092
i__1 = *n - 1;
22093
for (j = 1; j <= i__1; ++j) {
22094
i__2 = *n - j;
22095
cnorm[j] = dzasum_(&i__2, &a[j + 1 + j * a_dim1], &c__1);
22096
/* L20: */
22097
}
22098
cnorm[*n] = 0.;
22099
}
22100
}
22101
22102
/*
22103
Scale the column norms by TSCAL if the maximum element in CNORM is
22104
greater than BIGNUM/2.
22105
*/
22106
22107
imax = idamax_(n, &cnorm[1], &c__1);
22108
tmax = cnorm[imax];
22109
if (tmax <= bignum * .5) {
22110
tscal = 1.;
22111
} else {
22112
tscal = .5 / (smlnum * tmax);
22113
dscal_(n, &tscal, &cnorm[1], &c__1);
22114
}
22115
22116
/*
22117
Compute a bound on the computed solution vector to see if the
22118
Level 2 BLAS routine ZTRSV can be used.
22119
*/
22120
22121
xmax = 0.;
22122
i__1 = *n;
22123
for (j = 1; j <= i__1; ++j) {
22124
/* Computing MAX */
22125
i__2 = j;
22126
d__3 = xmax, d__4 = (d__1 = x[i__2].r / 2., abs(d__1)) + (d__2 =
22127
d_imag(&x[j]) / 2., abs(d__2));
22128
xmax = max(d__3,d__4);
22129
/* L30: */
22130
}
22131
xbnd = xmax;
22132
22133
if (notran) {
22134
22135
/* Compute the growth in A * x = b. */
22136
22137
if (upper) {
22138
jfirst = *n;
22139
jlast = 1;
22140
jinc = -1;
22141
} else {
22142
jfirst = 1;
22143
jlast = *n;
22144
jinc = 1;
22145
}
22146
22147
if (tscal != 1.) {
22148
grow = 0.;
22149
goto L60;
22150
}
22151
22152
if (nounit) {
22153
22154
/*
22155
A is non-unit triangular.
22156
22157
Compute GROW = 1/G(j) and XBND = 1/M(j).
22158
Initially, G(0) = max{x(i), i=1,...,n}.
22159
*/
22160
22161
grow = .5 / max(xbnd,smlnum);
22162
xbnd = grow;
22163
i__1 = jlast;
22164
i__2 = jinc;
22165
for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
22166
22167
/* Exit the loop if the growth factor is too small. */
22168
22169
if (grow <= smlnum) {
22170
goto L60;
22171
}
22172
22173
i__3 = j + j * a_dim1;
22174
tjjs.r = a[i__3].r, tjjs.i = a[i__3].i;
22175
tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
22176
d__2));
22177
22178
if (tjj >= smlnum) {
22179
22180
/*
22181
M(j) = G(j-1) / abs(A(j,j))
22182
22183
Computing MIN
22184
*/
22185
d__1 = xbnd, d__2 = min(1.,tjj) * grow;
22186
xbnd = min(d__1,d__2);
22187
} else {
22188
22189
/* M(j) could overflow, set XBND to 0. */
22190
22191
xbnd = 0.;
22192
}
22193
22194
if (tjj + cnorm[j] >= smlnum) {
22195
22196
/* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
22197
22198
grow *= tjj / (tjj + cnorm[j]);
22199
} else {
22200
22201
/* G(j) could overflow, set GROW to 0. */
22202
22203
grow = 0.;
22204
}
22205
/* L40: */
22206
}
22207
grow = xbnd;
22208
} else {
22209
22210
/*
22211
A is unit triangular.
22212
22213
Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}.
22214
22215
Computing MIN
22216
*/
22217
d__1 = 1., d__2 = .5 / max(xbnd,smlnum);
22218
grow = min(d__1,d__2);
22219
i__2 = jlast;
22220
i__1 = jinc;
22221
for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
22222
22223
/* Exit the loop if the growth factor is too small. */
22224
22225
if (grow <= smlnum) {
22226
goto L60;
22227
}
22228
22229
/* G(j) = G(j-1)*( 1 + CNORM(j) ) */
22230
22231
grow *= 1. / (cnorm[j] + 1.);
22232
/* L50: */
22233
}
22234
}
22235
L60:
22236
22237
;
22238
} else {
22239
22240
/* Compute the growth in A**T * x = b or A**H * x = b. */
22241
22242
if (upper) {
22243
jfirst = 1;
22244
jlast = *n;
22245
jinc = 1;
22246
} else {
22247
jfirst = *n;
22248
jlast = 1;
22249
jinc = -1;
22250
}
22251
22252
if (tscal != 1.) {
22253
grow = 0.;
22254
goto L90;
22255
}
22256
22257
if (nounit) {
22258
22259
/*
22260
A is non-unit triangular.
22261
22262
Compute GROW = 1/G(j) and XBND = 1/M(j).
22263
Initially, M(0) = max{x(i), i=1,...,n}.
22264
*/
22265
22266
grow = .5 / max(xbnd,smlnum);
22267
xbnd = grow;
22268
i__1 = jlast;
22269
i__2 = jinc;
22270
for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
22271
22272
/* Exit the loop if the growth factor is too small. */
22273
22274
if (grow <= smlnum) {
22275
goto L90;
22276
}
22277
22278
/* G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
22279
22280
xj = cnorm[j] + 1.;
22281
/* Computing MIN */
22282
d__1 = grow, d__2 = xbnd / xj;
22283
grow = min(d__1,d__2);
22284
22285
i__3 = j + j * a_dim1;
22286
tjjs.r = a[i__3].r, tjjs.i = a[i__3].i;
22287
tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
22288
d__2));
22289
22290
if (tjj >= smlnum) {
22291
22292
/* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
22293
22294
if (xj > tjj) {
22295
xbnd *= tjj / xj;
22296
}
22297
} else {
22298
22299
/* M(j) could overflow, set XBND to 0. */
22300
22301
xbnd = 0.;
22302
}
22303
/* L70: */
22304
}
22305
grow = min(grow,xbnd);
22306
} else {
22307
22308
/*
22309
A is unit triangular.
22310
22311
Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}.
22312
22313
Computing MIN
22314
*/
22315
d__1 = 1., d__2 = .5 / max(xbnd,smlnum);
22316
grow = min(d__1,d__2);
22317
i__2 = jlast;
22318
i__1 = jinc;
22319
for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
22320
22321
/* Exit the loop if the growth factor is too small. */
22322
22323
if (grow <= smlnum) {
22324
goto L90;
22325
}
22326
22327
/* G(j) = ( 1 + CNORM(j) )*G(j-1) */
22328
22329
xj = cnorm[j] + 1.;
22330
grow /= xj;
22331
/* L80: */
22332
}
22333
}
22334
L90:
22335
;
22336
}
22337
22338
if (grow * tscal > smlnum) {
22339
22340
/*
22341
Use the Level 2 BLAS solve if the reciprocal of the bound on
22342
elements of X is not too small.
22343
*/
22344
22345
ztrsv_(uplo, trans, diag, n, &a[a_offset], lda, &x[1], &c__1);
22346
} else {
22347
22348
/* Use a Level 1 BLAS solve, scaling intermediate results. */
22349
22350
if (xmax > bignum * .5) {
22351
22352
/*
22353
Scale X so that its components are less than or equal to
22354
BIGNUM in absolute value.
22355
*/
22356
22357
*scale = bignum * .5 / xmax;
22358
zdscal_(n, scale, &x[1], &c__1);
22359
xmax = bignum;
22360
} else {
22361
xmax *= 2.;
22362
}
22363
22364
if (notran) {
22365
22366
/* Solve A * x = b */
22367
22368
i__1 = jlast;
22369
i__2 = jinc;
22370
for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
22371
22372
/* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
22373
22374
i__3 = j;
22375
xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]),
22376
abs(d__2));
22377
if (nounit) {
22378
i__3 = j + j * a_dim1;
22379
z__1.r = tscal * a[i__3].r, z__1.i = tscal * a[i__3].i;
22380
tjjs.r = z__1.r, tjjs.i = z__1.i;
22381
} else {
22382
tjjs.r = tscal, tjjs.i = 0.;
22383
if (tscal == 1.) {
22384
goto L110;
22385
}
22386
}
22387
tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs), abs(
22388
d__2));
22389
if (tjj > smlnum) {
22390
22391
/* abs(A(j,j)) > SMLNUM: */
22392
22393
if (tjj < 1.) {
22394
if (xj > tjj * bignum) {
22395
22396
/* Scale x by 1/b(j). */
22397
22398
rec = 1. / xj;
22399
zdscal_(n, &rec, &x[1], &c__1);
22400
*scale *= rec;
22401
xmax *= rec;
22402
}
22403
}
22404
i__3 = j;
22405
zladiv_(&z__1, &x[j], &tjjs);
22406
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22407
i__3 = j;
22408
xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
22409
, abs(d__2));
22410
} else if (tjj > 0.) {
22411
22412
/* 0 < abs(A(j,j)) <= SMLNUM: */
22413
22414
if (xj > tjj * bignum) {
22415
22416
/*
22417
Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM
22418
to avoid overflow when dividing by A(j,j).
22419
*/
22420
22421
rec = tjj * bignum / xj;
22422
if (cnorm[j] > 1.) {
22423
22424
/*
22425
Scale by 1/CNORM(j) to avoid overflow when
22426
multiplying x(j) times column j.
22427
*/
22428
22429
rec /= cnorm[j];
22430
}
22431
zdscal_(n, &rec, &x[1], &c__1);
22432
*scale *= rec;
22433
xmax *= rec;
22434
}
22435
i__3 = j;
22436
zladiv_(&z__1, &x[j], &tjjs);
22437
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22438
i__3 = j;
22439
xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
22440
, abs(d__2));
22441
} else {
22442
22443
/*
22444
A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and
22445
scale = 0, and compute a solution to A*x = 0.
22446
*/
22447
22448
i__3 = *n;
22449
for (i__ = 1; i__ <= i__3; ++i__) {
22450
i__4 = i__;
22451
x[i__4].r = 0., x[i__4].i = 0.;
22452
/* L100: */
22453
}
22454
i__3 = j;
22455
x[i__3].r = 1., x[i__3].i = 0.;
22456
xj = 1.;
22457
*scale = 0.;
22458
xmax = 0.;
22459
}
22460
L110:
22461
22462
/*
22463
Scale x if necessary to avoid overflow when adding a
22464
multiple of column j of A.
22465
*/
22466
22467
if (xj > 1.) {
22468
rec = 1. / xj;
22469
if (cnorm[j] > (bignum - xmax) * rec) {
22470
22471
/* Scale x by 1/(2*abs(x(j))). */
22472
22473
rec *= .5;
22474
zdscal_(n, &rec, &x[1], &c__1);
22475
*scale *= rec;
22476
}
22477
} else if (xj * cnorm[j] > bignum - xmax) {
22478
22479
/* Scale x by 1/2. */
22480
22481
zdscal_(n, &c_b2435, &x[1], &c__1);
22482
*scale *= .5;
22483
}
22484
22485
if (upper) {
22486
if (j > 1) {
22487
22488
/*
22489
Compute the update
22490
x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j)
22491
*/
22492
22493
i__3 = j - 1;
22494
i__4 = j;
22495
z__2.r = -x[i__4].r, z__2.i = -x[i__4].i;
22496
z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
22497
zaxpy_(&i__3, &z__1, &a[j * a_dim1 + 1], &c__1, &x[1],
22498
&c__1);
22499
i__3 = j - 1;
22500
i__ = izamax_(&i__3, &x[1], &c__1);
22501
i__3 = i__;
22502
xmax = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
22503
&x[i__]), abs(d__2));
22504
}
22505
} else {
22506
if (j < *n) {
22507
22508
/*
22509
Compute the update
22510
x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j)
22511
*/
22512
22513
i__3 = *n - j;
22514
i__4 = j;
22515
z__2.r = -x[i__4].r, z__2.i = -x[i__4].i;
22516
z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
22517
zaxpy_(&i__3, &z__1, &a[j + 1 + j * a_dim1], &c__1, &
22518
x[j + 1], &c__1);
22519
i__3 = *n - j;
22520
i__ = j + izamax_(&i__3, &x[j + 1], &c__1);
22521
i__3 = i__;
22522
xmax = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
22523
&x[i__]), abs(d__2));
22524
}
22525
}
22526
/* L120: */
22527
}
22528
22529
} else if (lsame_(trans, "T")) {
22530
22531
/* Solve A**T * x = b */
22532
22533
i__2 = jlast;
22534
i__1 = jinc;
22535
for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
22536
22537
/*
22538
Compute x(j) = b(j) - sum A(k,j)*x(k).
22539
k<>j
22540
*/
22541
22542
i__3 = j;
22543
xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]),
22544
abs(d__2));
22545
uscal.r = tscal, uscal.i = 0.;
22546
rec = 1. / max(xmax,1.);
22547
if (cnorm[j] > (bignum - xj) * rec) {
22548
22549
/* If x(j) could overflow, scale x by 1/(2*XMAX). */
22550
22551
rec *= .5;
22552
if (nounit) {
22553
i__3 = j + j * a_dim1;
22554
z__1.r = tscal * a[i__3].r, z__1.i = tscal * a[i__3]
22555
.i;
22556
tjjs.r = z__1.r, tjjs.i = z__1.i;
22557
} else {
22558
tjjs.r = tscal, tjjs.i = 0.;
22559
}
22560
tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
22561
abs(d__2));
22562
if (tjj > 1.) {
22563
22564
/*
22565
Divide by A(j,j) when scaling x if A(j,j) > 1.
22566
22567
Computing MIN
22568
*/
22569
d__1 = 1., d__2 = rec * tjj;
22570
rec = min(d__1,d__2);
22571
zladiv_(&z__1, &uscal, &tjjs);
22572
uscal.r = z__1.r, uscal.i = z__1.i;
22573
}
22574
if (rec < 1.) {
22575
zdscal_(n, &rec, &x[1], &c__1);
22576
*scale *= rec;
22577
xmax *= rec;
22578
}
22579
}
22580
22581
csumj.r = 0., csumj.i = 0.;
22582
if (uscal.r == 1. && uscal.i == 0.) {
22583
22584
/*
22585
If the scaling needed for A in the dot product is 1,
22586
call ZDOTU to perform the dot product.
22587
*/
22588
22589
if (upper) {
22590
i__3 = j - 1;
22591
zdotu_(&z__1, &i__3, &a[j * a_dim1 + 1], &c__1, &x[1],
22592
&c__1);
22593
csumj.r = z__1.r, csumj.i = z__1.i;
22594
} else if (j < *n) {
22595
i__3 = *n - j;
22596
zdotu_(&z__1, &i__3, &a[j + 1 + j * a_dim1], &c__1, &
22597
x[j + 1], &c__1);
22598
csumj.r = z__1.r, csumj.i = z__1.i;
22599
}
22600
} else {
22601
22602
/* Otherwise, use in-line code for the dot product. */
22603
22604
if (upper) {
22605
i__3 = j - 1;
22606
for (i__ = 1; i__ <= i__3; ++i__) {
22607
i__4 = i__ + j * a_dim1;
22608
z__3.r = a[i__4].r * uscal.r - a[i__4].i *
22609
uscal.i, z__3.i = a[i__4].r * uscal.i + a[
22610
i__4].i * uscal.r;
22611
i__5 = i__;
22612
z__2.r = z__3.r * x[i__5].r - z__3.i * x[i__5].i,
22613
z__2.i = z__3.r * x[i__5].i + z__3.i * x[
22614
i__5].r;
22615
z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
22616
z__2.i;
22617
csumj.r = z__1.r, csumj.i = z__1.i;
22618
/* L130: */
22619
}
22620
} else if (j < *n) {
22621
i__3 = *n;
22622
for (i__ = j + 1; i__ <= i__3; ++i__) {
22623
i__4 = i__ + j * a_dim1;
22624
z__3.r = a[i__4].r * uscal.r - a[i__4].i *
22625
uscal.i, z__3.i = a[i__4].r * uscal.i + a[
22626
i__4].i * uscal.r;
22627
i__5 = i__;
22628
z__2.r = z__3.r * x[i__5].r - z__3.i * x[i__5].i,
22629
z__2.i = z__3.r * x[i__5].i + z__3.i * x[
22630
i__5].r;
22631
z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
22632
z__2.i;
22633
csumj.r = z__1.r, csumj.i = z__1.i;
22634
/* L140: */
22635
}
22636
}
22637
}
22638
22639
z__1.r = tscal, z__1.i = 0.;
22640
if (uscal.r == z__1.r && uscal.i == z__1.i) {
22641
22642
/*
22643
Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j)
22644
was not used to scale the dotproduct.
22645
*/
22646
22647
i__3 = j;
22648
i__4 = j;
22649
z__1.r = x[i__4].r - csumj.r, z__1.i = x[i__4].i -
22650
csumj.i;
22651
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22652
i__3 = j;
22653
xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
22654
, abs(d__2));
22655
if (nounit) {
22656
i__3 = j + j * a_dim1;
22657
z__1.r = tscal * a[i__3].r, z__1.i = tscal * a[i__3]
22658
.i;
22659
tjjs.r = z__1.r, tjjs.i = z__1.i;
22660
} else {
22661
tjjs.r = tscal, tjjs.i = 0.;
22662
if (tscal == 1.) {
22663
goto L160;
22664
}
22665
}
22666
22667
/* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
22668
22669
tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
22670
abs(d__2));
22671
if (tjj > smlnum) {
22672
22673
/* abs(A(j,j)) > SMLNUM: */
22674
22675
if (tjj < 1.) {
22676
if (xj > tjj * bignum) {
22677
22678
/* Scale X by 1/abs(x(j)). */
22679
22680
rec = 1. / xj;
22681
zdscal_(n, &rec, &x[1], &c__1);
22682
*scale *= rec;
22683
xmax *= rec;
22684
}
22685
}
22686
i__3 = j;
22687
zladiv_(&z__1, &x[j], &tjjs);
22688
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22689
} else if (tjj > 0.) {
22690
22691
/* 0 < abs(A(j,j)) <= SMLNUM: */
22692
22693
if (xj > tjj * bignum) {
22694
22695
/* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
22696
22697
rec = tjj * bignum / xj;
22698
zdscal_(n, &rec, &x[1], &c__1);
22699
*scale *= rec;
22700
xmax *= rec;
22701
}
22702
i__3 = j;
22703
zladiv_(&z__1, &x[j], &tjjs);
22704
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22705
} else {
22706
22707
/*
22708
A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and
22709
scale = 0 and compute a solution to A**T *x = 0.
22710
*/
22711
22712
i__3 = *n;
22713
for (i__ = 1; i__ <= i__3; ++i__) {
22714
i__4 = i__;
22715
x[i__4].r = 0., x[i__4].i = 0.;
22716
/* L150: */
22717
}
22718
i__3 = j;
22719
x[i__3].r = 1., x[i__3].i = 0.;
22720
*scale = 0.;
22721
xmax = 0.;
22722
}
22723
L160:
22724
;
22725
} else {
22726
22727
/*
22728
Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot
22729
product has already been divided by 1/A(j,j).
22730
*/
22731
22732
i__3 = j;
22733
zladiv_(&z__2, &x[j], &tjjs);
22734
z__1.r = z__2.r - csumj.r, z__1.i = z__2.i - csumj.i;
22735
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22736
}
22737
/* Computing MAX */
22738
i__3 = j;
22739
d__3 = xmax, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 =
22740
d_imag(&x[j]), abs(d__2));
22741
xmax = max(d__3,d__4);
22742
/* L170: */
22743
}
22744
22745
} else {
22746
22747
/* Solve A**H * x = b */
22748
22749
i__1 = jlast;
22750
i__2 = jinc;
22751
for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
22752
22753
/*
22754
Compute x(j) = b(j) - sum A(k,j)*x(k).
22755
k<>j
22756
*/
22757
22758
i__3 = j;
22759
xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j]),
22760
abs(d__2));
22761
uscal.r = tscal, uscal.i = 0.;
22762
rec = 1. / max(xmax,1.);
22763
if (cnorm[j] > (bignum - xj) * rec) {
22764
22765
/* If x(j) could overflow, scale x by 1/(2*XMAX). */
22766
22767
rec *= .5;
22768
if (nounit) {
22769
d_cnjg(&z__2, &a[j + j * a_dim1]);
22770
z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
22771
tjjs.r = z__1.r, tjjs.i = z__1.i;
22772
} else {
22773
tjjs.r = tscal, tjjs.i = 0.;
22774
}
22775
tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
22776
abs(d__2));
22777
if (tjj > 1.) {
22778
22779
/*
22780
Divide by A(j,j) when scaling x if A(j,j) > 1.
22781
22782
Computing MIN
22783
*/
22784
d__1 = 1., d__2 = rec * tjj;
22785
rec = min(d__1,d__2);
22786
zladiv_(&z__1, &uscal, &tjjs);
22787
uscal.r = z__1.r, uscal.i = z__1.i;
22788
}
22789
if (rec < 1.) {
22790
zdscal_(n, &rec, &x[1], &c__1);
22791
*scale *= rec;
22792
xmax *= rec;
22793
}
22794
}
22795
22796
csumj.r = 0., csumj.i = 0.;
22797
if (uscal.r == 1. && uscal.i == 0.) {
22798
22799
/*
22800
If the scaling needed for A in the dot product is 1,
22801
call ZDOTC to perform the dot product.
22802
*/
22803
22804
if (upper) {
22805
i__3 = j - 1;
22806
zdotc_(&z__1, &i__3, &a[j * a_dim1 + 1], &c__1, &x[1],
22807
&c__1);
22808
csumj.r = z__1.r, csumj.i = z__1.i;
22809
} else if (j < *n) {
22810
i__3 = *n - j;
22811
zdotc_(&z__1, &i__3, &a[j + 1 + j * a_dim1], &c__1, &
22812
x[j + 1], &c__1);
22813
csumj.r = z__1.r, csumj.i = z__1.i;
22814
}
22815
} else {
22816
22817
/* Otherwise, use in-line code for the dot product. */
22818
22819
if (upper) {
22820
i__3 = j - 1;
22821
for (i__ = 1; i__ <= i__3; ++i__) {
22822
d_cnjg(&z__4, &a[i__ + j * a_dim1]);
22823
z__3.r = z__4.r * uscal.r - z__4.i * uscal.i,
22824
z__3.i = z__4.r * uscal.i + z__4.i *
22825
uscal.r;
22826
i__4 = i__;
22827
z__2.r = z__3.r * x[i__4].r - z__3.i * x[i__4].i,
22828
z__2.i = z__3.r * x[i__4].i + z__3.i * x[
22829
i__4].r;
22830
z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
22831
z__2.i;
22832
csumj.r = z__1.r, csumj.i = z__1.i;
22833
/* L180: */
22834
}
22835
} else if (j < *n) {
22836
i__3 = *n;
22837
for (i__ = j + 1; i__ <= i__3; ++i__) {
22838
d_cnjg(&z__4, &a[i__ + j * a_dim1]);
22839
z__3.r = z__4.r * uscal.r - z__4.i * uscal.i,
22840
z__3.i = z__4.r * uscal.i + z__4.i *
22841
uscal.r;
22842
i__4 = i__;
22843
z__2.r = z__3.r * x[i__4].r - z__3.i * x[i__4].i,
22844
z__2.i = z__3.r * x[i__4].i + z__3.i * x[
22845
i__4].r;
22846
z__1.r = csumj.r + z__2.r, z__1.i = csumj.i +
22847
z__2.i;
22848
csumj.r = z__1.r, csumj.i = z__1.i;
22849
/* L190: */
22850
}
22851
}
22852
}
22853
22854
z__1.r = tscal, z__1.i = 0.;
22855
if (uscal.r == z__1.r && uscal.i == z__1.i) {
22856
22857
/*
22858
Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j)
22859
was not used to scale the dotproduct.
22860
*/
22861
22862
i__3 = j;
22863
i__4 = j;
22864
z__1.r = x[i__4].r - csumj.r, z__1.i = x[i__4].i -
22865
csumj.i;
22866
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22867
i__3 = j;
22868
xj = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[j])
22869
, abs(d__2));
22870
if (nounit) {
22871
d_cnjg(&z__2, &a[j + j * a_dim1]);
22872
z__1.r = tscal * z__2.r, z__1.i = tscal * z__2.i;
22873
tjjs.r = z__1.r, tjjs.i = z__1.i;
22874
} else {
22875
tjjs.r = tscal, tjjs.i = 0.;
22876
if (tscal == 1.) {
22877
goto L210;
22878
}
22879
}
22880
22881
/* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
22882
22883
tjj = (d__1 = tjjs.r, abs(d__1)) + (d__2 = d_imag(&tjjs),
22884
abs(d__2));
22885
if (tjj > smlnum) {
22886
22887
/* abs(A(j,j)) > SMLNUM: */
22888
22889
if (tjj < 1.) {
22890
if (xj > tjj * bignum) {
22891
22892
/* Scale X by 1/abs(x(j)). */
22893
22894
rec = 1. / xj;
22895
zdscal_(n, &rec, &x[1], &c__1);
22896
*scale *= rec;
22897
xmax *= rec;
22898
}
22899
}
22900
i__3 = j;
22901
zladiv_(&z__1, &x[j], &tjjs);
22902
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22903
} else if (tjj > 0.) {
22904
22905
/* 0 < abs(A(j,j)) <= SMLNUM: */
22906
22907
if (xj > tjj * bignum) {
22908
22909
/* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
22910
22911
rec = tjj * bignum / xj;
22912
zdscal_(n, &rec, &x[1], &c__1);
22913
*scale *= rec;
22914
xmax *= rec;
22915
}
22916
i__3 = j;
22917
zladiv_(&z__1, &x[j], &tjjs);
22918
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22919
} else {
22920
22921
/*
22922
A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and
22923
scale = 0 and compute a solution to A**H *x = 0.
22924
*/
22925
22926
i__3 = *n;
22927
for (i__ = 1; i__ <= i__3; ++i__) {
22928
i__4 = i__;
22929
x[i__4].r = 0., x[i__4].i = 0.;
22930
/* L200: */
22931
}
22932
i__3 = j;
22933
x[i__3].r = 1., x[i__3].i = 0.;
22934
*scale = 0.;
22935
xmax = 0.;
22936
}
22937
L210:
22938
;
22939
} else {
22940
22941
/*
22942
Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot
22943
product has already been divided by 1/A(j,j).
22944
*/
22945
22946
i__3 = j;
22947
zladiv_(&z__2, &x[j], &tjjs);
22948
z__1.r = z__2.r - csumj.r, z__1.i = z__2.i - csumj.i;
22949
x[i__3].r = z__1.r, x[i__3].i = z__1.i;
22950
}
22951
/* Computing MAX */
22952
i__3 = j;
22953
d__3 = xmax, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 =
22954
d_imag(&x[j]), abs(d__2));
22955
xmax = max(d__3,d__4);
22956
/* L220: */
22957
}
22958
}
22959
*scale /= tscal;
22960
}
22961
22962
/* Scale the column norms by 1/TSCAL for return. */
22963
22964
if (tscal != 1.) {
22965
d__1 = 1. / tscal;
22966
dscal_(n, &d__1, &cnorm[1], &c__1);
22967
}
22968
22969
return 0;
22970
22971
/* End of ZLATRS */
22972
22973
} /* zlatrs_ */
22974
22975
/* Subroutine */ int zlauu2_(char *uplo, integer *n, doublecomplex *a,
22976
integer *lda, integer *info)
22977
{
22978
/* System generated locals */
22979
integer a_dim1, a_offset, i__1, i__2, i__3;
22980
doublereal d__1;
22981
doublecomplex z__1;
22982
22983
/* Local variables */
22984
static integer i__;
22985
static doublereal aii;
22986
extern logical lsame_(char *, char *);
22987
extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
22988
doublecomplex *, integer *, doublecomplex *, integer *);
22989
extern /* Subroutine */ int zgemv_(char *, integer *, integer *,
22990
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
22991
integer *, doublecomplex *, doublecomplex *, integer *);
22992
static logical upper;
22993
extern /* Subroutine */ int xerbla_(char *, integer *), zdscal_(
22994
integer *, doublereal *, doublecomplex *, integer *), zlacgv_(
22995
integer *, doublecomplex *, integer *);
22996
22997
22998
/*
22999
-- LAPACK auxiliary routine (version 3.2) --
23000
-- LAPACK is a software package provided by Univ. of Tennessee, --
23001
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23002
November 2006
23003
23004
23005
Purpose
23006
=======
23007
23008
ZLAUU2 computes the product U * U' or L' * L, where the triangular
23009
factor U or L is stored in the upper or lower triangular part of
23010
the array A.
23011
23012
If UPLO = 'U' or 'u' then the upper triangle of the result is stored,
23013
overwriting the factor U in A.
23014
If UPLO = 'L' or 'l' then the lower triangle of the result is stored,
23015
overwriting the factor L in A.
23016
23017
This is the unblocked form of the algorithm, calling Level 2 BLAS.
23018
23019
Arguments
23020
=========
23021
23022
UPLO (input) CHARACTER*1
23023
Specifies whether the triangular factor stored in the array A
23024
is upper or lower triangular:
23025
= 'U': Upper triangular
23026
= 'L': Lower triangular
23027
23028
N (input) INTEGER
23029
The order of the triangular factor U or L. N >= 0.
23030
23031
A (input/output) COMPLEX*16 array, dimension (LDA,N)
23032
On entry, the triangular factor U or L.
23033
On exit, if UPLO = 'U', the upper triangle of A is
23034
overwritten with the upper triangle of the product U * U';
23035
if UPLO = 'L', the lower triangle of A is overwritten with
23036
the lower triangle of the product L' * L.
23037
23038
LDA (input) INTEGER
23039
The leading dimension of the array A. LDA >= max(1,N).
23040
23041
INFO (output) INTEGER
23042
= 0: successful exit
23043
< 0: if INFO = -k, the k-th argument had an illegal value
23044
23045
=====================================================================
23046
23047
23048
Test the input parameters.
23049
*/
23050
23051
/* Parameter adjustments */
23052
a_dim1 = *lda;
23053
a_offset = 1 + a_dim1;
23054
a -= a_offset;
23055
23056
/* Function Body */
23057
*info = 0;
23058
upper = lsame_(uplo, "U");
23059
if (! upper && ! lsame_(uplo, "L")) {
23060
*info = -1;
23061
} else if (*n < 0) {
23062
*info = -2;
23063
} else if (*lda < max(1,*n)) {
23064
*info = -4;
23065
}
23066
if (*info != 0) {
23067
i__1 = -(*info);
23068
xerbla_("ZLAUU2", &i__1);
23069
return 0;
23070
}
23071
23072
/* Quick return if possible */
23073
23074
if (*n == 0) {
23075
return 0;
23076
}
23077
23078
if (upper) {
23079
23080
/* Compute the product U * U'. */
23081
23082
i__1 = *n;
23083
for (i__ = 1; i__ <= i__1; ++i__) {
23084
i__2 = i__ + i__ * a_dim1;
23085
aii = a[i__2].r;
23086
if (i__ < *n) {
23087
i__2 = i__ + i__ * a_dim1;
23088
i__3 = *n - i__;
23089
zdotc_(&z__1, &i__3, &a[i__ + (i__ + 1) * a_dim1], lda, &a[
23090
i__ + (i__ + 1) * a_dim1], lda);
23091
d__1 = aii * aii + z__1.r;
23092
a[i__2].r = d__1, a[i__2].i = 0.;
23093
i__2 = *n - i__;
23094
zlacgv_(&i__2, &a[i__ + (i__ + 1) * a_dim1], lda);
23095
i__2 = i__ - 1;
23096
i__3 = *n - i__;
23097
z__1.r = aii, z__1.i = 0.;
23098
zgemv_("No transpose", &i__2, &i__3, &c_b57, &a[(i__ + 1) *
23099
a_dim1 + 1], lda, &a[i__ + (i__ + 1) * a_dim1], lda, &
23100
z__1, &a[i__ * a_dim1 + 1], &c__1);
23101
i__2 = *n - i__;
23102
zlacgv_(&i__2, &a[i__ + (i__ + 1) * a_dim1], lda);
23103
} else {
23104
zdscal_(&i__, &aii, &a[i__ * a_dim1 + 1], &c__1);
23105
}
23106
/* L10: */
23107
}
23108
23109
} else {
23110
23111
/* Compute the product L' * L. */
23112
23113
i__1 = *n;
23114
for (i__ = 1; i__ <= i__1; ++i__) {
23115
i__2 = i__ + i__ * a_dim1;
23116
aii = a[i__2].r;
23117
if (i__ < *n) {
23118
i__2 = i__ + i__ * a_dim1;
23119
i__3 = *n - i__;
23120
zdotc_(&z__1, &i__3, &a[i__ + 1 + i__ * a_dim1], &c__1, &a[
23121
i__ + 1 + i__ * a_dim1], &c__1);
23122
d__1 = aii * aii + z__1.r;
23123
a[i__2].r = d__1, a[i__2].i = 0.;
23124
i__2 = i__ - 1;
23125
zlacgv_(&i__2, &a[i__ + a_dim1], lda);
23126
i__2 = *n - i__;
23127
i__3 = i__ - 1;
23128
z__1.r = aii, z__1.i = 0.;
23129
zgemv_("Conjugate transpose", &i__2, &i__3, &c_b57, &a[i__ +
23130
1 + a_dim1], lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &
23131
z__1, &a[i__ + a_dim1], lda);
23132
i__2 = i__ - 1;
23133
zlacgv_(&i__2, &a[i__ + a_dim1], lda);
23134
} else {
23135
zdscal_(&i__, &aii, &a[i__ + a_dim1], lda);
23136
}
23137
/* L20: */
23138
}
23139
}
23140
23141
return 0;
23142
23143
/* End of ZLAUU2 */
23144
23145
} /* zlauu2_ */
23146
23147
/* Subroutine */ int zlauum_(char *uplo, integer *n, doublecomplex *a,
23148
integer *lda, integer *info)
23149
{
23150
/* System generated locals */
23151
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
23152
23153
/* Local variables */
23154
static integer i__, ib, nb;
23155
extern logical lsame_(char *, char *);
23156
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
23157
integer *, doublecomplex *, doublecomplex *, integer *,
23158
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
23159
integer *), zherk_(char *, char *, integer *,
23160
integer *, doublereal *, doublecomplex *, integer *, doublereal *,
23161
doublecomplex *, integer *);
23162
static logical upper;
23163
extern /* Subroutine */ int ztrmm_(char *, char *, char *, char *,
23164
integer *, integer *, doublecomplex *, doublecomplex *, integer *,
23165
doublecomplex *, integer *),
23166
zlauu2_(char *, integer *, doublecomplex *, integer *, integer *), xerbla_(char *, integer *);
23167
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
23168
integer *, integer *, ftnlen, ftnlen);
23169
23170
23171
/*
23172
-- LAPACK auxiliary routine (version 3.2) --
23173
-- LAPACK is a software package provided by Univ. of Tennessee, --
23174
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23175
November 2006
23176
23177
23178
Purpose
23179
=======
23180
23181
ZLAUUM computes the product U * U' or L' * L, where the triangular
23182
factor U or L is stored in the upper or lower triangular part of
23183
the array A.
23184
23185
If UPLO = 'U' or 'u' then the upper triangle of the result is stored,
23186
overwriting the factor U in A.
23187
If UPLO = 'L' or 'l' then the lower triangle of the result is stored,
23188
overwriting the factor L in A.
23189
23190
This is the blocked form of the algorithm, calling Level 3 BLAS.
23191
23192
Arguments
23193
=========
23194
23195
UPLO (input) CHARACTER*1
23196
Specifies whether the triangular factor stored in the array A
23197
is upper or lower triangular:
23198
= 'U': Upper triangular
23199
= 'L': Lower triangular
23200
23201
N (input) INTEGER
23202
The order of the triangular factor U or L. N >= 0.
23203
23204
A (input/output) COMPLEX*16 array, dimension (LDA,N)
23205
On entry, the triangular factor U or L.
23206
On exit, if UPLO = 'U', the upper triangle of A is
23207
overwritten with the upper triangle of the product U * U';
23208
if UPLO = 'L', the lower triangle of A is overwritten with
23209
the lower triangle of the product L' * L.
23210
23211
LDA (input) INTEGER
23212
The leading dimension of the array A. LDA >= max(1,N).
23213
23214
INFO (output) INTEGER
23215
= 0: successful exit
23216
< 0: if INFO = -k, the k-th argument had an illegal value
23217
23218
=====================================================================
23219
23220
23221
Test the input parameters.
23222
*/
23223
23224
/* Parameter adjustments */
23225
a_dim1 = *lda;
23226
a_offset = 1 + a_dim1;
23227
a -= a_offset;
23228
23229
/* Function Body */
23230
*info = 0;
23231
upper = lsame_(uplo, "U");
23232
if (! upper && ! lsame_(uplo, "L")) {
23233
*info = -1;
23234
} else if (*n < 0) {
23235
*info = -2;
23236
} else if (*lda < max(1,*n)) {
23237
*info = -4;
23238
}
23239
if (*info != 0) {
23240
i__1 = -(*info);
23241
xerbla_("ZLAUUM", &i__1);
23242
return 0;
23243
}
23244
23245
/* Quick return if possible */
23246
23247
if (*n == 0) {
23248
return 0;
23249
}
23250
23251
/* Determine the block size for this environment. */
23252
23253
nb = ilaenv_(&c__1, "ZLAUUM", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
23254
ftnlen)1);
23255
23256
if (nb <= 1 || nb >= *n) {
23257
23258
/* Use unblocked code */
23259
23260
zlauu2_(uplo, n, &a[a_offset], lda, info);
23261
} else {
23262
23263
/* Use blocked code */
23264
23265
if (upper) {
23266
23267
/* Compute the product U * U'. */
23268
23269
i__1 = *n;
23270
i__2 = nb;
23271
for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
23272
/* Computing MIN */
23273
i__3 = nb, i__4 = *n - i__ + 1;
23274
ib = min(i__3,i__4);
23275
i__3 = i__ - 1;
23276
ztrmm_("Right", "Upper", "Conjugate transpose", "Non-unit", &
23277
i__3, &ib, &c_b57, &a[i__ + i__ * a_dim1], lda, &a[
23278
i__ * a_dim1 + 1], lda);
23279
zlauu2_("Upper", &ib, &a[i__ + i__ * a_dim1], lda, info);
23280
if (i__ + ib <= *n) {
23281
i__3 = i__ - 1;
23282
i__4 = *n - i__ - ib + 1;
23283
zgemm_("No transpose", "Conjugate transpose", &i__3, &ib,
23284
&i__4, &c_b57, &a[(i__ + ib) * a_dim1 + 1], lda, &
23285
a[i__ + (i__ + ib) * a_dim1], lda, &c_b57, &a[i__
23286
* a_dim1 + 1], lda);
23287
i__3 = *n - i__ - ib + 1;
23288
zherk_("Upper", "No transpose", &ib, &i__3, &c_b1034, &a[
23289
i__ + (i__ + ib) * a_dim1], lda, &c_b1034, &a[i__
23290
+ i__ * a_dim1], lda);
23291
}
23292
/* L10: */
23293
}
23294
} else {
23295
23296
/* Compute the product L' * L. */
23297
23298
i__2 = *n;
23299
i__1 = nb;
23300
for (i__ = 1; i__1 < 0 ? i__ >= i__2 : i__ <= i__2; i__ += i__1) {
23301
/* Computing MIN */
23302
i__3 = nb, i__4 = *n - i__ + 1;
23303
ib = min(i__3,i__4);
23304
i__3 = i__ - 1;
23305
ztrmm_("Left", "Lower", "Conjugate transpose", "Non-unit", &
23306
ib, &i__3, &c_b57, &a[i__ + i__ * a_dim1], lda, &a[
23307
i__ + a_dim1], lda);
23308
zlauu2_("Lower", &ib, &a[i__ + i__ * a_dim1], lda, info);
23309
if (i__ + ib <= *n) {
23310
i__3 = i__ - 1;
23311
i__4 = *n - i__ - ib + 1;
23312
zgemm_("Conjugate transpose", "No transpose", &ib, &i__3,
23313
&i__4, &c_b57, &a[i__ + ib + i__ * a_dim1], lda, &
23314
a[i__ + ib + a_dim1], lda, &c_b57, &a[i__ +
23315
a_dim1], lda);
23316
i__3 = *n - i__ - ib + 1;
23317
zherk_("Lower", "Conjugate transpose", &ib, &i__3, &
23318
c_b1034, &a[i__ + ib + i__ * a_dim1], lda, &
23319
c_b1034, &a[i__ + i__ * a_dim1], lda);
23320
}
23321
/* L20: */
23322
}
23323
}
23324
}
23325
23326
return 0;
23327
23328
/* End of ZLAUUM */
23329
23330
} /* zlauum_ */
23331
23332
/* Subroutine */ int zpotf2_(char *uplo, integer *n, doublecomplex *a,
23333
integer *lda, integer *info)
23334
{
23335
/* System generated locals */
23336
integer a_dim1, a_offset, i__1, i__2, i__3;
23337
doublereal d__1;
23338
doublecomplex z__1, z__2;
23339
23340
/* Local variables */
23341
static integer j;
23342
static doublereal ajj;
23343
extern logical lsame_(char *, char *);
23344
extern /* Double Complex */ VOID zdotc_(doublecomplex *, integer *,
23345
doublecomplex *, integer *, doublecomplex *, integer *);
23346
extern /* Subroutine */ int zgemv_(char *, integer *, integer *,
23347
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
23348
integer *, doublecomplex *, doublecomplex *, integer *);
23349
static logical upper;
23350
extern logical disnan_(doublereal *);
23351
extern /* Subroutine */ int xerbla_(char *, integer *), zdscal_(
23352
integer *, doublereal *, doublecomplex *, integer *), zlacgv_(
23353
integer *, doublecomplex *, integer *);
23354
23355
23356
/*
23357
-- LAPACK routine (version 3.2) --
23358
-- LAPACK is a software package provided by Univ. of Tennessee, --
23359
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23360
November 2006
23361
23362
23363
Purpose
23364
=======
23365
23366
ZPOTF2 computes the Cholesky factorization of a complex Hermitian
23367
positive definite matrix A.
23368
23369
The factorization has the form
23370
A = U' * U , if UPLO = 'U', or
23371
A = L * L', if UPLO = 'L',
23372
where U is an upper triangular matrix and L is lower triangular.
23373
23374
This is the unblocked version of the algorithm, calling Level 2 BLAS.
23375
23376
Arguments
23377
=========
23378
23379
UPLO (input) CHARACTER*1
23380
Specifies whether the upper or lower triangular part of the
23381
Hermitian matrix A is stored.
23382
= 'U': Upper triangular
23383
= 'L': Lower triangular
23384
23385
N (input) INTEGER
23386
The order of the matrix A. N >= 0.
23387
23388
A (input/output) COMPLEX*16 array, dimension (LDA,N)
23389
On entry, the Hermitian matrix A. If UPLO = 'U', the leading
23390
n by n upper triangular part of A contains the upper
23391
triangular part of the matrix A, and the strictly lower
23392
triangular part of A is not referenced. If UPLO = 'L', the
23393
leading n by n lower triangular part of A contains the lower
23394
triangular part of the matrix A, and the strictly upper
23395
triangular part of A is not referenced.
23396
23397
On exit, if INFO = 0, the factor U or L from the Cholesky
23398
factorization A = U'*U or A = L*L'.
23399
23400
LDA (input) INTEGER
23401
The leading dimension of the array A. LDA >= max(1,N).
23402
23403
INFO (output) INTEGER
23404
= 0: successful exit
23405
< 0: if INFO = -k, the k-th argument had an illegal value
23406
> 0: if INFO = k, the leading minor of order k is not
23407
positive definite, and the factorization could not be
23408
completed.
23409
23410
=====================================================================
23411
23412
23413
Test the input parameters.
23414
*/
23415
23416
/* Parameter adjustments */
23417
a_dim1 = *lda;
23418
a_offset = 1 + a_dim1;
23419
a -= a_offset;
23420
23421
/* Function Body */
23422
*info = 0;
23423
upper = lsame_(uplo, "U");
23424
if (! upper && ! lsame_(uplo, "L")) {
23425
*info = -1;
23426
} else if (*n < 0) {
23427
*info = -2;
23428
} else if (*lda < max(1,*n)) {
23429
*info = -4;
23430
}
23431
if (*info != 0) {
23432
i__1 = -(*info);
23433
xerbla_("ZPOTF2", &i__1);
23434
return 0;
23435
}
23436
23437
/* Quick return if possible */
23438
23439
if (*n == 0) {
23440
return 0;
23441
}
23442
23443
if (upper) {
23444
23445
/* Compute the Cholesky factorization A = U'*U. */
23446
23447
i__1 = *n;
23448
for (j = 1; j <= i__1; ++j) {
23449
23450
/* Compute U(J,J) and test for non-positive-definiteness. */
23451
23452
i__2 = j + j * a_dim1;
23453
d__1 = a[i__2].r;
23454
i__3 = j - 1;
23455
zdotc_(&z__2, &i__3, &a[j * a_dim1 + 1], &c__1, &a[j * a_dim1 + 1]
23456
, &c__1);
23457
z__1.r = d__1 - z__2.r, z__1.i = -z__2.i;
23458
ajj = z__1.r;
23459
if (ajj <= 0. || disnan_(&ajj)) {
23460
i__2 = j + j * a_dim1;
23461
a[i__2].r = ajj, a[i__2].i = 0.;
23462
goto L30;
23463
}
23464
ajj = sqrt(ajj);
23465
i__2 = j + j * a_dim1;
23466
a[i__2].r = ajj, a[i__2].i = 0.;
23467
23468
/* Compute elements J+1:N of row J. */
23469
23470
if (j < *n) {
23471
i__2 = j - 1;
23472
zlacgv_(&i__2, &a[j * a_dim1 + 1], &c__1);
23473
i__2 = j - 1;
23474
i__3 = *n - j;
23475
z__1.r = -1., z__1.i = -0.;
23476
zgemv_("Transpose", &i__2, &i__3, &z__1, &a[(j + 1) * a_dim1
23477
+ 1], lda, &a[j * a_dim1 + 1], &c__1, &c_b57, &a[j + (
23478
j + 1) * a_dim1], lda);
23479
i__2 = j - 1;
23480
zlacgv_(&i__2, &a[j * a_dim1 + 1], &c__1);
23481
i__2 = *n - j;
23482
d__1 = 1. / ajj;
23483
zdscal_(&i__2, &d__1, &a[j + (j + 1) * a_dim1], lda);
23484
}
23485
/* L10: */
23486
}
23487
} else {
23488
23489
/* Compute the Cholesky factorization A = L*L'. */
23490
23491
i__1 = *n;
23492
for (j = 1; j <= i__1; ++j) {
23493
23494
/* Compute L(J,J) and test for non-positive-definiteness. */
23495
23496
i__2 = j + j * a_dim1;
23497
d__1 = a[i__2].r;
23498
i__3 = j - 1;
23499
zdotc_(&z__2, &i__3, &a[j + a_dim1], lda, &a[j + a_dim1], lda);
23500
z__1.r = d__1 - z__2.r, z__1.i = -z__2.i;
23501
ajj = z__1.r;
23502
if (ajj <= 0. || disnan_(&ajj)) {
23503
i__2 = j + j * a_dim1;
23504
a[i__2].r = ajj, a[i__2].i = 0.;
23505
goto L30;
23506
}
23507
ajj = sqrt(ajj);
23508
i__2 = j + j * a_dim1;
23509
a[i__2].r = ajj, a[i__2].i = 0.;
23510
23511
/* Compute elements J+1:N of column J. */
23512
23513
if (j < *n) {
23514
i__2 = j - 1;
23515
zlacgv_(&i__2, &a[j + a_dim1], lda);
23516
i__2 = *n - j;
23517
i__3 = j - 1;
23518
z__1.r = -1., z__1.i = -0.;
23519
zgemv_("No transpose", &i__2, &i__3, &z__1, &a[j + 1 + a_dim1]
23520
, lda, &a[j + a_dim1], lda, &c_b57, &a[j + 1 + j *
23521
a_dim1], &c__1);
23522
i__2 = j - 1;
23523
zlacgv_(&i__2, &a[j + a_dim1], lda);
23524
i__2 = *n - j;
23525
d__1 = 1. / ajj;
23526
zdscal_(&i__2, &d__1, &a[j + 1 + j * a_dim1], &c__1);
23527
}
23528
/* L20: */
23529
}
23530
}
23531
goto L40;
23532
23533
L30:
23534
*info = j;
23535
23536
L40:
23537
return 0;
23538
23539
/* End of ZPOTF2 */
23540
23541
} /* zpotf2_ */
23542
23543
/* Subroutine */ int zpotrf_(char *uplo, integer *n, doublecomplex *a,
23544
integer *lda, integer *info)
23545
{
23546
/* System generated locals */
23547
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
23548
doublecomplex z__1;
23549
23550
/* Local variables */
23551
static integer j, jb, nb;
23552
extern logical lsame_(char *, char *);
23553
extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
23554
integer *, doublecomplex *, doublecomplex *, integer *,
23555
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
23556
integer *), zherk_(char *, char *, integer *,
23557
integer *, doublereal *, doublecomplex *, integer *, doublereal *,
23558
doublecomplex *, integer *);
23559
static logical upper;
23560
extern /* Subroutine */ int ztrsm_(char *, char *, char *, char *,
23561
integer *, integer *, doublecomplex *, doublecomplex *, integer *,
23562
doublecomplex *, integer *),
23563
zpotf2_(char *, integer *, doublecomplex *, integer *, integer *), xerbla_(char *, integer *);
23564
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
23565
integer *, integer *, ftnlen, ftnlen);
23566
23567
23568
/*
23569
-- LAPACK routine (version 3.2) --
23570
-- LAPACK is a software package provided by Univ. of Tennessee, --
23571
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23572
November 2006
23573
23574
23575
Purpose
23576
=======
23577
23578
ZPOTRF computes the Cholesky factorization of a complex Hermitian
23579
positive definite matrix A.
23580
23581
The factorization has the form
23582
A = U**H * U, if UPLO = 'U', or
23583
A = L * L**H, if UPLO = 'L',
23584
where U is an upper triangular matrix and L is lower triangular.
23585
23586
This is the block version of the algorithm, calling Level 3 BLAS.
23587
23588
Arguments
23589
=========
23590
23591
UPLO (input) CHARACTER*1
23592
= 'U': Upper triangle of A is stored;
23593
= 'L': Lower triangle of A is stored.
23594
23595
N (input) INTEGER
23596
The order of the matrix A. N >= 0.
23597
23598
A (input/output) COMPLEX*16 array, dimension (LDA,N)
23599
On entry, the Hermitian matrix A. If UPLO = 'U', the leading
23600
N-by-N upper triangular part of A contains the upper
23601
triangular part of the matrix A, and the strictly lower
23602
triangular part of A is not referenced. If UPLO = 'L', the
23603
leading N-by-N lower triangular part of A contains the lower
23604
triangular part of the matrix A, and the strictly upper
23605
triangular part of A is not referenced.
23606
23607
On exit, if INFO = 0, the factor U or L from the Cholesky
23608
factorization A = U**H*U or A = L*L**H.
23609
23610
LDA (input) INTEGER
23611
The leading dimension of the array A. LDA >= max(1,N).
23612
23613
INFO (output) INTEGER
23614
= 0: successful exit
23615
< 0: if INFO = -i, the i-th argument had an illegal value
23616
> 0: if INFO = i, the leading minor of order i is not
23617
positive definite, and the factorization could not be
23618
completed.
23619
23620
=====================================================================
23621
23622
23623
Test the input parameters.
23624
*/
23625
23626
/* Parameter adjustments */
23627
a_dim1 = *lda;
23628
a_offset = 1 + a_dim1;
23629
a -= a_offset;
23630
23631
/* Function Body */
23632
*info = 0;
23633
upper = lsame_(uplo, "U");
23634
if (! upper && ! lsame_(uplo, "L")) {
23635
*info = -1;
23636
} else if (*n < 0) {
23637
*info = -2;
23638
} else if (*lda < max(1,*n)) {
23639
*info = -4;
23640
}
23641
if (*info != 0) {
23642
i__1 = -(*info);
23643
xerbla_("ZPOTRF", &i__1);
23644
return 0;
23645
}
23646
23647
/* Quick return if possible */
23648
23649
if (*n == 0) {
23650
return 0;
23651
}
23652
23653
/* Determine the block size for this environment. */
23654
23655
nb = ilaenv_(&c__1, "ZPOTRF", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
23656
ftnlen)1);
23657
if (nb <= 1 || nb >= *n) {
23658
23659
/* Use unblocked code. */
23660
23661
zpotf2_(uplo, n, &a[a_offset], lda, info);
23662
} else {
23663
23664
/* Use blocked code. */
23665
23666
if (upper) {
23667
23668
/* Compute the Cholesky factorization A = U'*U. */
23669
23670
i__1 = *n;
23671
i__2 = nb;
23672
for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
23673
23674
/*
23675
Update and factorize the current diagonal block and test
23676
for non-positive-definiteness.
23677
23678
Computing MIN
23679
*/
23680
i__3 = nb, i__4 = *n - j + 1;
23681
jb = min(i__3,i__4);
23682
i__3 = j - 1;
23683
zherk_("Upper", "Conjugate transpose", &jb, &i__3, &c_b1276, &
23684
a[j * a_dim1 + 1], lda, &c_b1034, &a[j + j * a_dim1],
23685
lda);
23686
zpotf2_("Upper", &jb, &a[j + j * a_dim1], lda, info);
23687
if (*info != 0) {
23688
goto L30;
23689
}
23690
if (j + jb <= *n) {
23691
23692
/* Compute the current block row. */
23693
23694
i__3 = *n - j - jb + 1;
23695
i__4 = j - 1;
23696
z__1.r = -1., z__1.i = -0.;
23697
zgemm_("Conjugate transpose", "No transpose", &jb, &i__3,
23698
&i__4, &z__1, &a[j * a_dim1 + 1], lda, &a[(j + jb)
23699
* a_dim1 + 1], lda, &c_b57, &a[j + (j + jb) *
23700
a_dim1], lda);
23701
i__3 = *n - j - jb + 1;
23702
ztrsm_("Left", "Upper", "Conjugate transpose", "Non-unit",
23703
&jb, &i__3, &c_b57, &a[j + j * a_dim1], lda, &a[
23704
j + (j + jb) * a_dim1], lda);
23705
}
23706
/* L10: */
23707
}
23708
23709
} else {
23710
23711
/* Compute the Cholesky factorization A = L*L'. */
23712
23713
i__2 = *n;
23714
i__1 = nb;
23715
for (j = 1; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
23716
23717
/*
23718
Update and factorize the current diagonal block and test
23719
for non-positive-definiteness.
23720
23721
Computing MIN
23722
*/
23723
i__3 = nb, i__4 = *n - j + 1;
23724
jb = min(i__3,i__4);
23725
i__3 = j - 1;
23726
zherk_("Lower", "No transpose", &jb, &i__3, &c_b1276, &a[j +
23727
a_dim1], lda, &c_b1034, &a[j + j * a_dim1], lda);
23728
zpotf2_("Lower", &jb, &a[j + j * a_dim1], lda, info);
23729
if (*info != 0) {
23730
goto L30;
23731
}
23732
if (j + jb <= *n) {
23733
23734
/* Compute the current block column. */
23735
23736
i__3 = *n - j - jb + 1;
23737
i__4 = j - 1;
23738
z__1.r = -1., z__1.i = -0.;
23739
zgemm_("No transpose", "Conjugate transpose", &i__3, &jb,
23740
&i__4, &z__1, &a[j + jb + a_dim1], lda, &a[j +
23741
a_dim1], lda, &c_b57, &a[j + jb + j * a_dim1],
23742
lda);
23743
i__3 = *n - j - jb + 1;
23744
ztrsm_("Right", "Lower", "Conjugate transpose", "Non-unit"
23745
, &i__3, &jb, &c_b57, &a[j + j * a_dim1], lda, &a[
23746
j + jb + j * a_dim1], lda);
23747
}
23748
/* L20: */
23749
}
23750
}
23751
}
23752
goto L40;
23753
23754
L30:
23755
*info = *info + j - 1;
23756
23757
L40:
23758
return 0;
23759
23760
/* End of ZPOTRF */
23761
23762
} /* zpotrf_ */
23763
23764
/* Subroutine */ int zpotri_(char *uplo, integer *n, doublecomplex *a,
23765
integer *lda, integer *info)
23766
{
23767
/* System generated locals */
23768
integer a_dim1, a_offset, i__1;
23769
23770
/* Local variables */
23771
extern logical lsame_(char *, char *);
23772
extern /* Subroutine */ int xerbla_(char *, integer *), zlauum_(
23773
char *, integer *, doublecomplex *, integer *, integer *),
23774
ztrtri_(char *, char *, integer *, doublecomplex *, integer *,
23775
integer *);
23776
23777
23778
/*
23779
-- LAPACK routine (version 3.2) --
23780
-- LAPACK is a software package provided by Univ. of Tennessee, --
23781
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23782
November 2006
23783
23784
23785
Purpose
23786
=======
23787
23788
ZPOTRI computes the inverse of a complex Hermitian positive definite
23789
matrix A using the Cholesky factorization A = U**H*U or A = L*L**H
23790
computed by ZPOTRF.
23791
23792
Arguments
23793
=========
23794
23795
UPLO (input) CHARACTER*1
23796
= 'U': Upper triangle of A is stored;
23797
= 'L': Lower triangle of A is stored.
23798
23799
N (input) INTEGER
23800
The order of the matrix A. N >= 0.
23801
23802
A (input/output) COMPLEX*16 array, dimension (LDA,N)
23803
On entry, the triangular factor U or L from the Cholesky
23804
factorization A = U**H*U or A = L*L**H, as computed by
23805
ZPOTRF.
23806
On exit, the upper or lower triangle of the (Hermitian)
23807
inverse of A, overwriting the input factor U or L.
23808
23809
LDA (input) INTEGER
23810
The leading dimension of the array A. LDA >= max(1,N).
23811
23812
INFO (output) INTEGER
23813
= 0: successful exit
23814
< 0: if INFO = -i, the i-th argument had an illegal value
23815
> 0: if INFO = i, the (i,i) element of the factor U or L is
23816
zero, and the inverse could not be computed.
23817
23818
=====================================================================
23819
23820
23821
Test the input parameters.
23822
*/
23823
23824
/* Parameter adjustments */
23825
a_dim1 = *lda;
23826
a_offset = 1 + a_dim1;
23827
a -= a_offset;
23828
23829
/* Function Body */
23830
*info = 0;
23831
if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
23832
*info = -1;
23833
} else if (*n < 0) {
23834
*info = -2;
23835
} else if (*lda < max(1,*n)) {
23836
*info = -4;
23837
}
23838
if (*info != 0) {
23839
i__1 = -(*info);
23840
xerbla_("ZPOTRI", &i__1);
23841
return 0;
23842
}
23843
23844
/* Quick return if possible */
23845
23846
if (*n == 0) {
23847
return 0;
23848
}
23849
23850
/* Invert the triangular Cholesky factor U or L. */
23851
23852
ztrtri_(uplo, "Non-unit", n, &a[a_offset], lda, info);
23853
if (*info > 0) {
23854
return 0;
23855
}
23856
23857
/* Form inv(U)*inv(U)' or inv(L)'*inv(L). */
23858
23859
zlauum_(uplo, n, &a[a_offset], lda, info);
23860
23861
return 0;
23862
23863
/* End of ZPOTRI */
23864
23865
} /* zpotri_ */
23866
23867
/* Subroutine */ int zpotrs_(char *uplo, integer *n, integer *nrhs,
23868
doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb,
23869
integer *info)
23870
{
23871
/* System generated locals */
23872
integer a_dim1, a_offset, b_dim1, b_offset, i__1;
23873
23874
/* Local variables */
23875
extern logical lsame_(char *, char *);
23876
static logical upper;
23877
extern /* Subroutine */ int ztrsm_(char *, char *, char *, char *,
23878
integer *, integer *, doublecomplex *, doublecomplex *, integer *,
23879
doublecomplex *, integer *),
23880
xerbla_(char *, integer *);
23881
23882
23883
/*
23884
-- LAPACK routine (version 3.2) --
23885
-- LAPACK is a software package provided by Univ. of Tennessee, --
23886
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
23887
November 2006
23888
23889
23890
Purpose
23891
=======
23892
23893
ZPOTRS solves a system of linear equations A*X = B with a Hermitian
23894
positive definite matrix A using the Cholesky factorization
23895
A = U**H*U or A = L*L**H computed by ZPOTRF.
23896
23897
Arguments
23898
=========
23899
23900
UPLO (input) CHARACTER*1
23901
= 'U': Upper triangle of A is stored;
23902
= 'L': Lower triangle of A is stored.
23903
23904
N (input) INTEGER
23905
The order of the matrix A. N >= 0.
23906
23907
NRHS (input) INTEGER
23908
The number of right hand sides, i.e., the number of columns
23909
of the matrix B. NRHS >= 0.
23910
23911
A (input) COMPLEX*16 array, dimension (LDA,N)
23912
The triangular factor U or L from the Cholesky factorization
23913
A = U**H*U or A = L*L**H, as computed by ZPOTRF.
23914
23915
LDA (input) INTEGER
23916
The leading dimension of the array A. LDA >= max(1,N).
23917
23918
B (input/output) COMPLEX*16 array, dimension (LDB,NRHS)
23919
On entry, the right hand side matrix B.
23920
On exit, the solution matrix X.
23921
23922
LDB (input) INTEGER
23923
The leading dimension of the array B. LDB >= max(1,N).
23924
23925
INFO (output) INTEGER
23926
= 0: successful exit
23927
< 0: if INFO = -i, the i-th argument had an illegal value
23928
23929
=====================================================================
23930
23931
23932
Test the input parameters.
23933
*/
23934
23935
/* Parameter adjustments */
23936
a_dim1 = *lda;
23937
a_offset = 1 + a_dim1;
23938
a -= a_offset;
23939
b_dim1 = *ldb;
23940
b_offset = 1 + b_dim1;
23941
b -= b_offset;
23942
23943
/* Function Body */
23944
*info = 0;
23945
upper = lsame_(uplo, "U");
23946
if (! upper && ! lsame_(uplo, "L")) {
23947
*info = -1;
23948
} else if (*n < 0) {
23949
*info = -2;
23950
} else if (*nrhs < 0) {
23951
*info = -3;
23952
} else if (*lda < max(1,*n)) {
23953
*info = -5;
23954
} else if (*ldb < max(1,*n)) {
23955
*info = -7;
23956
}
23957
if (*info != 0) {
23958
i__1 = -(*info);
23959
xerbla_("ZPOTRS", &i__1);
23960
return 0;
23961
}
23962
23963
/* Quick return if possible */
23964
23965
if (*n == 0 || *nrhs == 0) {
23966
return 0;
23967
}
23968
23969
if (upper) {
23970
23971
/*
23972
Solve A*X = B where A = U'*U.
23973
23974
Solve U'*X = B, overwriting B with X.
23975
*/
23976
23977
ztrsm_("Left", "Upper", "Conjugate transpose", "Non-unit", n, nrhs, &
23978
c_b57, &a[a_offset], lda, &b[b_offset], ldb);
23979
23980
/* Solve U*X = B, overwriting B with X. */
23981
23982
ztrsm_("Left", "Upper", "No transpose", "Non-unit", n, nrhs, &c_b57, &
23983
a[a_offset], lda, &b[b_offset], ldb);
23984
} else {
23985
23986
/*
23987
Solve A*X = B where A = L*L'.
23988
23989
Solve L*X = B, overwriting B with X.
23990
*/
23991
23992
ztrsm_("Left", "Lower", "No transpose", "Non-unit", n, nrhs, &c_b57, &
23993
a[a_offset], lda, &b[b_offset], ldb);
23994
23995
/* Solve L'*X = B, overwriting B with X. */
23996
23997
ztrsm_("Left", "Lower", "Conjugate transpose", "Non-unit", n, nrhs, &
23998
c_b57, &a[a_offset], lda, &b[b_offset], ldb);
23999
}
24000
24001
return 0;
24002
24003
/* End of ZPOTRS */
24004
24005
} /* zpotrs_ */
24006
24007
/* Subroutine */ int zrot_(integer *n, doublecomplex *cx, integer *incx,
24008
doublecomplex *cy, integer *incy, doublereal *c__, doublecomplex *s)
24009
{
24010
/* System generated locals */
24011
integer i__1, i__2, i__3, i__4;
24012
doublecomplex z__1, z__2, z__3, z__4;
24013
24014
/* Local variables */
24015
static integer i__, ix, iy;
24016
static doublecomplex stemp;
24017
24018
24019
/*
24020
-- LAPACK auxiliary routine (version 3.2) --
24021
-- LAPACK is a software package provided by Univ. of Tennessee, --
24022
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
24023
November 2006
24024
24025
24026
Purpose
24027
=======
24028
24029
ZROT applies a plane rotation, where the cos (C) is real and the
24030
sin (S) is complex, and the vectors CX and CY are complex.
24031
24032
Arguments
24033
=========
24034
24035
N (input) INTEGER
24036
The number of elements in the vectors CX and CY.
24037
24038
CX (input/output) COMPLEX*16 array, dimension (N)
24039
On input, the vector X.
24040
On output, CX is overwritten with C*X + S*Y.
24041
24042
INCX (input) INTEGER
24043
The increment between successive values of CY. INCX <> 0.
24044
24045
CY (input/output) COMPLEX*16 array, dimension (N)
24046
On input, the vector Y.
24047
On output, CY is overwritten with -CONJG(S)*X + C*Y.
24048
24049
INCY (input) INTEGER
24050
The increment between successive values of CY. INCX <> 0.
24051
24052
C (input) DOUBLE PRECISION
24053
S (input) COMPLEX*16
24054
C and S define a rotation
24055
[ C S ]
24056
[ -conjg(S) C ]
24057
where C*C + S*CONJG(S) = 1.0.
24058
24059
=====================================================================
24060
*/
24061
24062
24063
/* Parameter adjustments */
24064
--cy;
24065
--cx;
24066
24067
/* Function Body */
24068
if (*n <= 0) {
24069
return 0;
24070
}
24071
if (*incx == 1 && *incy == 1) {
24072
goto L20;
24073
}
24074
24075
/* Code for unequal increments or equal increments not equal to 1 */
24076
24077
ix = 1;
24078
iy = 1;
24079
if (*incx < 0) {
24080
ix = (-(*n) + 1) * *incx + 1;
24081
}
24082
if (*incy < 0) {
24083
iy = (-(*n) + 1) * *incy + 1;
24084
}
24085
i__1 = *n;
24086
for (i__ = 1; i__ <= i__1; ++i__) {
24087
i__2 = ix;
24088
z__2.r = *c__ * cx[i__2].r, z__2.i = *c__ * cx[i__2].i;
24089
i__3 = iy;
24090
z__3.r = s->r * cy[i__3].r - s->i * cy[i__3].i, z__3.i = s->r * cy[
24091
i__3].i + s->i * cy[i__3].r;
24092
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
24093
stemp.r = z__1.r, stemp.i = z__1.i;
24094
i__2 = iy;
24095
i__3 = iy;
24096
z__2.r = *c__ * cy[i__3].r, z__2.i = *c__ * cy[i__3].i;
24097
d_cnjg(&z__4, s);
24098
i__4 = ix;
24099
z__3.r = z__4.r * cx[i__4].r - z__4.i * cx[i__4].i, z__3.i = z__4.r *
24100
cx[i__4].i + z__4.i * cx[i__4].r;
24101
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
24102
cy[i__2].r = z__1.r, cy[i__2].i = z__1.i;
24103
i__2 = ix;
24104
cx[i__2].r = stemp.r, cx[i__2].i = stemp.i;
24105
ix += *incx;
24106
iy += *incy;
24107
/* L10: */
24108
}
24109
return 0;
24110
24111
/* Code for both increments equal to 1 */
24112
24113
L20:
24114
i__1 = *n;
24115
for (i__ = 1; i__ <= i__1; ++i__) {
24116
i__2 = i__;
24117
z__2.r = *c__ * cx[i__2].r, z__2.i = *c__ * cx[i__2].i;
24118
i__3 = i__;
24119
z__3.r = s->r * cy[i__3].r - s->i * cy[i__3].i, z__3.i = s->r * cy[
24120
i__3].i + s->i * cy[i__3].r;
24121
z__1.r = z__2.r + z__3.r, z__1.i = z__2.i + z__3.i;
24122
stemp.r = z__1.r, stemp.i = z__1.i;
24123
i__2 = i__;
24124
i__3 = i__;
24125
z__2.r = *c__ * cy[i__3].r, z__2.i = *c__ * cy[i__3].i;
24126
d_cnjg(&z__4, s);
24127
i__4 = i__;
24128
z__3.r = z__4.r * cx[i__4].r - z__4.i * cx[i__4].i, z__3.i = z__4.r *
24129
cx[i__4].i + z__4.i * cx[i__4].r;
24130
z__1.r = z__2.r - z__3.r, z__1.i = z__2.i - z__3.i;
24131
cy[i__2].r = z__1.r, cy[i__2].i = z__1.i;
24132
i__2 = i__;
24133
cx[i__2].r = stemp.r, cx[i__2].i = stemp.i;
24134
/* L30: */
24135
}
24136
return 0;
24137
} /* zrot_ */
24138
24139
/* Subroutine */ int zstedc_(char *compz, integer *n, doublereal *d__,
24140
doublereal *e, doublecomplex *z__, integer *ldz, doublecomplex *work,
24141
integer *lwork, doublereal *rwork, integer *lrwork, integer *iwork,
24142
integer *liwork, integer *info)
24143
{
24144
/* System generated locals */
24145
integer z_dim1, z_offset, i__1, i__2, i__3, i__4;
24146
doublereal d__1, d__2;
24147
24148
/* Local variables */
24149
static integer i__, j, k, m;
24150
static doublereal p;
24151
static integer ii, ll, lgn;
24152
static doublereal eps, tiny;
24153
extern logical lsame_(char *, char *);
24154
static integer lwmin, start;
24155
extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *,
24156
doublecomplex *, integer *), zlaed0_(integer *, integer *,
24157
doublereal *, doublereal *, doublecomplex *, integer *,
24158
doublecomplex *, integer *, doublereal *, integer *, integer *);
24159
24160
extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
24161
doublereal *, doublereal *, integer *, integer *, doublereal *,
24162
integer *, integer *), dstedc_(char *, integer *,
24163
doublereal *, doublereal *, doublereal *, integer *, doublereal *,
24164
integer *, integer *, integer *, integer *), dlaset_(
24165
char *, integer *, integer *, doublereal *, doublereal *,
24166
doublereal *, integer *), xerbla_(char *, integer *);
24167
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
24168
integer *, integer *, ftnlen, ftnlen);
24169
static integer finish;
24170
extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
24171
extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *,
24172
integer *), zlacrm_(integer *, integer *, doublecomplex *,
24173
integer *, doublereal *, integer *, doublecomplex *, integer *,
24174
doublereal *);
24175
static integer liwmin, icompz;
24176
extern /* Subroutine */ int dsteqr_(char *, integer *, doublereal *,
24177
doublereal *, doublereal *, integer *, doublereal *, integer *), zlacpy_(char *, integer *, integer *, doublecomplex *,
24178
integer *, doublecomplex *, integer *);
24179
static doublereal orgnrm;
24180
static integer lrwmin;
24181
static logical lquery;
24182
static integer smlsiz;
24183
extern /* Subroutine */ int zsteqr_(char *, integer *, doublereal *,
24184
doublereal *, doublecomplex *, integer *, doublereal *, integer *);
24185
24186
24187
/*
24188
-- LAPACK routine (version 3.2) --
24189
-- LAPACK is a software package provided by Univ. of Tennessee, --
24190
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
24191
November 2006
24192
24193
24194
Purpose
24195
=======
24196
24197
ZSTEDC computes all eigenvalues and, optionally, eigenvectors of a
24198
symmetric tridiagonal matrix using the divide and conquer method.
24199
The eigenvectors of a full or band complex Hermitian matrix can also
24200
be found if ZHETRD or ZHPTRD or ZHBTRD has been used to reduce this
24201
matrix to tridiagonal form.
24202
24203
This code makes very mild assumptions about floating point
24204
arithmetic. It will work on machines with a guard digit in
24205
add/subtract, or on those binary machines without guard digits
24206
which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2.
24207
It could conceivably fail on hexadecimal or decimal machines
24208
without guard digits, but we know of none. See DLAED3 for details.
24209
24210
Arguments
24211
=========
24212
24213
COMPZ (input) CHARACTER*1
24214
= 'N': Compute eigenvalues only.
24215
= 'I': Compute eigenvectors of tridiagonal matrix also.
24216
= 'V': Compute eigenvectors of original Hermitian matrix
24217
also. On entry, Z contains the unitary matrix used
24218
to reduce the original matrix to tridiagonal form.
24219
24220
N (input) INTEGER
24221
The dimension of the symmetric tridiagonal matrix. N >= 0.
24222
24223
D (input/output) DOUBLE PRECISION array, dimension (N)
24224
On entry, the diagonal elements of the tridiagonal matrix.
24225
On exit, if INFO = 0, the eigenvalues in ascending order.
24226
24227
E (input/output) DOUBLE PRECISION array, dimension (N-1)
24228
On entry, the subdiagonal elements of the tridiagonal matrix.
24229
On exit, E has been destroyed.
24230
24231
Z (input/output) COMPLEX*16 array, dimension (LDZ,N)
24232
On entry, if COMPZ = 'V', then Z contains the unitary
24233
matrix used in the reduction to tridiagonal form.
24234
On exit, if INFO = 0, then if COMPZ = 'V', Z contains the
24235
orthonormal eigenvectors of the original Hermitian matrix,
24236
and if COMPZ = 'I', Z contains the orthonormal eigenvectors
24237
of the symmetric tridiagonal matrix.
24238
If COMPZ = 'N', then Z is not referenced.
24239
24240
LDZ (input) INTEGER
24241
The leading dimension of the array Z. LDZ >= 1.
24242
If eigenvectors are desired, then LDZ >= max(1,N).
24243
24244
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
24245
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
24246
24247
LWORK (input) INTEGER
24248
The dimension of the array WORK.
24249
If COMPZ = 'N' or 'I', or N <= 1, LWORK must be at least 1.
24250
If COMPZ = 'V' and N > 1, LWORK must be at least N*N.
24251
Note that for COMPZ = 'V', then if N is less than or
24252
equal to the minimum divide size, usually 25, then LWORK need
24253
only be 1.
24254
24255
If LWORK = -1, then a workspace query is assumed; the routine
24256
only calculates the optimal sizes of the WORK, RWORK and
24257
IWORK arrays, returns these values as the first entries of
24258
the WORK, RWORK and IWORK arrays, and no error message
24259
related to LWORK or LRWORK or LIWORK is issued by XERBLA.
24260
24261
RWORK (workspace/output) DOUBLE PRECISION array,
24262
dimension (LRWORK)
24263
On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK.
24264
24265
LRWORK (input) INTEGER
24266
The dimension of the array RWORK.
24267
If COMPZ = 'N' or N <= 1, LRWORK must be at least 1.
24268
If COMPZ = 'V' and N > 1, LRWORK must be at least
24269
1 + 3*N + 2*N*lg N + 3*N**2 ,
24270
where lg( N ) = smallest integer k such
24271
that 2**k >= N.
24272
If COMPZ = 'I' and N > 1, LRWORK must be at least
24273
1 + 4*N + 2*N**2 .
24274
Note that for COMPZ = 'I' or 'V', then if N is less than or
24275
equal to the minimum divide size, usually 25, then LRWORK
24276
need only be max(1,2*(N-1)).
24277
24278
If LRWORK = -1, then a workspace query is assumed; the
24279
routine only calculates the optimal sizes of the WORK, RWORK
24280
and IWORK arrays, returns these values as the first entries
24281
of the WORK, RWORK and IWORK arrays, and no error message
24282
related to LWORK or LRWORK or LIWORK is issued by XERBLA.
24283
24284
IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK))
24285
On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
24286
24287
LIWORK (input) INTEGER
24288
The dimension of the array IWORK.
24289
If COMPZ = 'N' or N <= 1, LIWORK must be at least 1.
24290
If COMPZ = 'V' or N > 1, LIWORK must be at least
24291
6 + 6*N + 5*N*lg N.
24292
If COMPZ = 'I' or N > 1, LIWORK must be at least
24293
3 + 5*N .
24294
Note that for COMPZ = 'I' or 'V', then if N is less than or
24295
equal to the minimum divide size, usually 25, then LIWORK
24296
need only be 1.
24297
24298
If LIWORK = -1, then a workspace query is assumed; the
24299
routine only calculates the optimal sizes of the WORK, RWORK
24300
and IWORK arrays, returns these values as the first entries
24301
of the WORK, RWORK and IWORK arrays, and no error message
24302
related to LWORK or LRWORK or LIWORK is issued by XERBLA.
24303
24304
INFO (output) INTEGER
24305
= 0: successful exit.
24306
< 0: if INFO = -i, the i-th argument had an illegal value.
24307
> 0: The algorithm failed to compute an eigenvalue while
24308
working on the submatrix lying in rows and columns
24309
INFO/(N+1) through mod(INFO,N+1).
24310
24311
Further Details
24312
===============
24313
24314
Based on contributions by
24315
Jeff Rutter, Computer Science Division, University of California
24316
at Berkeley, USA
24317
24318
=====================================================================
24319
24320
24321
Test the input parameters.
24322
*/
24323
24324
/* Parameter adjustments */
24325
--d__;
24326
--e;
24327
z_dim1 = *ldz;
24328
z_offset = 1 + z_dim1;
24329
z__ -= z_offset;
24330
--work;
24331
--rwork;
24332
--iwork;
24333
24334
/* Function Body */
24335
*info = 0;
24336
lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
24337
24338
if (lsame_(compz, "N")) {
24339
icompz = 0;
24340
} else if (lsame_(compz, "V")) {
24341
icompz = 1;
24342
} else if (lsame_(compz, "I")) {
24343
icompz = 2;
24344
} else {
24345
icompz = -1;
24346
}
24347
if (icompz < 0) {
24348
*info = -1;
24349
} else if (*n < 0) {
24350
*info = -2;
24351
} else if (*ldz < 1 || icompz > 0 && *ldz < max(1,*n)) {
24352
*info = -6;
24353
}
24354
24355
if (*info == 0) {
24356
24357
/* Compute the workspace requirements */
24358
24359
smlsiz = ilaenv_(&c__9, "ZSTEDC", " ", &c__0, &c__0, &c__0, &c__0, (
24360
ftnlen)6, (ftnlen)1);
24361
if (*n <= 1 || icompz == 0) {
24362
lwmin = 1;
24363
liwmin = 1;
24364
lrwmin = 1;
24365
} else if (*n <= smlsiz) {
24366
lwmin = 1;
24367
liwmin = 1;
24368
lrwmin = *n - 1 << 1;
24369
} else if (icompz == 1) {
24370
lgn = (integer) (log((doublereal) (*n)) / log(2.));
24371
if (pow_ii(&c__2, &lgn) < *n) {
24372
++lgn;
24373
}
24374
if (pow_ii(&c__2, &lgn) < *n) {
24375
++lgn;
24376
}
24377
lwmin = *n * *n;
24378
/* Computing 2nd power */
24379
i__1 = *n;
24380
lrwmin = *n * 3 + 1 + (*n << 1) * lgn + i__1 * i__1 * 3;
24381
liwmin = *n * 6 + 6 + *n * 5 * lgn;
24382
} else if (icompz == 2) {
24383
lwmin = 1;
24384
/* Computing 2nd power */
24385
i__1 = *n;
24386
lrwmin = (*n << 2) + 1 + (i__1 * i__1 << 1);
24387
liwmin = *n * 5 + 3;
24388
}
24389
work[1].r = (doublereal) lwmin, work[1].i = 0.;
24390
rwork[1] = (doublereal) lrwmin;
24391
iwork[1] = liwmin;
24392
24393
if (*lwork < lwmin && ! lquery) {
24394
*info = -8;
24395
} else if (*lrwork < lrwmin && ! lquery) {
24396
*info = -10;
24397
} else if (*liwork < liwmin && ! lquery) {
24398
*info = -12;
24399
}
24400
}
24401
24402
if (*info != 0) {
24403
i__1 = -(*info);
24404
xerbla_("ZSTEDC", &i__1);
24405
return 0;
24406
} else if (lquery) {
24407
return 0;
24408
}
24409
24410
/* Quick return if possible */
24411
24412
if (*n == 0) {
24413
return 0;
24414
}
24415
if (*n == 1) {
24416
if (icompz != 0) {
24417
i__1 = z_dim1 + 1;
24418
z__[i__1].r = 1., z__[i__1].i = 0.;
24419
}
24420
return 0;
24421
}
24422
24423
/*
24424
If the following conditional clause is removed, then the routine
24425
will use the Divide and Conquer routine to compute only the
24426
eigenvalues, which requires (3N + 3N**2) real workspace and
24427
(2 + 5N + 2N lg(N)) integer workspace.
24428
Since on many architectures DSTERF is much faster than any other
24429
algorithm for finding eigenvalues only, it is used here
24430
as the default. If the conditional clause is removed, then
24431
information on the size of workspace needs to be changed.
24432
24433
If COMPZ = 'N', use DSTERF to compute the eigenvalues.
24434
*/
24435
24436
if (icompz == 0) {
24437
dsterf_(n, &d__[1], &e[1], info);
24438
goto L70;
24439
}
24440
24441
/*
24442
If N is smaller than the minimum divide size (SMLSIZ+1), then
24443
solve the problem with another solver.
24444
*/
24445
24446
if (*n <= smlsiz) {
24447
24448
zsteqr_(compz, n, &d__[1], &e[1], &z__[z_offset], ldz, &rwork[1],
24449
info);
24450
24451
} else {
24452
24453
/* If COMPZ = 'I', we simply call DSTEDC instead. */
24454
24455
if (icompz == 2) {
24456
dlaset_("Full", n, n, &c_b328, &c_b1034, &rwork[1], n);
24457
ll = *n * *n + 1;
24458
i__1 = *lrwork - ll + 1;
24459
dstedc_("I", n, &d__[1], &e[1], &rwork[1], n, &rwork[ll], &i__1, &
24460
iwork[1], liwork, info);
24461
i__1 = *n;
24462
for (j = 1; j <= i__1; ++j) {
24463
i__2 = *n;
24464
for (i__ = 1; i__ <= i__2; ++i__) {
24465
i__3 = i__ + j * z_dim1;
24466
i__4 = (j - 1) * *n + i__;
24467
z__[i__3].r = rwork[i__4], z__[i__3].i = 0.;
24468
/* L10: */
24469
}
24470
/* L20: */
24471
}
24472
goto L70;
24473
}
24474
24475
/*
24476
From now on, only option left to be handled is COMPZ = 'V',
24477
i.e. ICOMPZ = 1.
24478
24479
Scale.
24480
*/
24481
24482
orgnrm = dlanst_("M", n, &d__[1], &e[1]);
24483
if (orgnrm == 0.) {
24484
goto L70;
24485
}
24486
24487
eps = EPSILON;
24488
24489
start = 1;
24490
24491
/* while ( START <= N ) */
24492
24493
L30:
24494
if (start <= *n) {
24495
24496
/*
24497
Let FINISH be the position of the next subdiagonal entry
24498
such that E( FINISH ) <= TINY or FINISH = N if no such
24499
subdiagonal exists. The matrix identified by the elements
24500
between START and FINISH constitutes an independent
24501
sub-problem.
24502
*/
24503
24504
finish = start;
24505
L40:
24506
if (finish < *n) {
24507
tiny = eps * sqrt((d__1 = d__[finish], abs(d__1))) * sqrt((
24508
d__2 = d__[finish + 1], abs(d__2)));
24509
if ((d__1 = e[finish], abs(d__1)) > tiny) {
24510
++finish;
24511
goto L40;
24512
}
24513
}
24514
24515
/* (Sub) Problem determined. Compute its size and solve it. */
24516
24517
m = finish - start + 1;
24518
if (m > smlsiz) {
24519
24520
/* Scale. */
24521
24522
orgnrm = dlanst_("M", &m, &d__[start], &e[start]);
24523
dlascl_("G", &c__0, &c__0, &orgnrm, &c_b1034, &m, &c__1, &d__[
24524
start], &m, info);
24525
i__1 = m - 1;
24526
i__2 = m - 1;
24527
dlascl_("G", &c__0, &c__0, &orgnrm, &c_b1034, &i__1, &c__1, &
24528
e[start], &i__2, info);
24529
24530
zlaed0_(n, &m, &d__[start], &e[start], &z__[start * z_dim1 +
24531
1], ldz, &work[1], n, &rwork[1], &iwork[1], info);
24532
if (*info > 0) {
24533
*info = (*info / (m + 1) + start - 1) * (*n + 1) + *info %
24534
(m + 1) + start - 1;
24535
goto L70;
24536
}
24537
24538
/* Scale back. */
24539
24540
dlascl_("G", &c__0, &c__0, &c_b1034, &orgnrm, &m, &c__1, &d__[
24541
start], &m, info);
24542
24543
} else {
24544
dsteqr_("I", &m, &d__[start], &e[start], &rwork[1], &m, &
24545
rwork[m * m + 1], info);
24546
zlacrm_(n, &m, &z__[start * z_dim1 + 1], ldz, &rwork[1], &m, &
24547
work[1], n, &rwork[m * m + 1]);
24548
zlacpy_("A", n, &m, &work[1], n, &z__[start * z_dim1 + 1],
24549
ldz);
24550
if (*info > 0) {
24551
*info = start * (*n + 1) + finish;
24552
goto L70;
24553
}
24554
}
24555
24556
start = finish + 1;
24557
goto L30;
24558
}
24559
24560
/*
24561
endwhile
24562
24563
If the problem split any number of times, then the eigenvalues
24564
will not be properly ordered. Here we permute the eigenvalues
24565
(and the associated eigenvectors) into ascending order.
24566
*/
24567
24568
if (m != *n) {
24569
24570
/* Use Selection Sort to minimize swaps of eigenvectors */
24571
24572
i__1 = *n;
24573
for (ii = 2; ii <= i__1; ++ii) {
24574
i__ = ii - 1;
24575
k = i__;
24576
p = d__[i__];
24577
i__2 = *n;
24578
for (j = ii; j <= i__2; ++j) {
24579
if (d__[j] < p) {
24580
k = j;
24581
p = d__[j];
24582
}
24583
/* L50: */
24584
}
24585
if (k != i__) {
24586
d__[k] = d__[i__];
24587
d__[i__] = p;
24588
zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[k * z_dim1
24589
+ 1], &c__1);
24590
}
24591
/* L60: */
24592
}
24593
}
24594
}
24595
24596
L70:
24597
work[1].r = (doublereal) lwmin, work[1].i = 0.;
24598
rwork[1] = (doublereal) lrwmin;
24599
iwork[1] = liwmin;
24600
24601
return 0;
24602
24603
/* End of ZSTEDC */
24604
24605
} /* zstedc_ */
24606
24607
/* Subroutine */ int zsteqr_(char *compz, integer *n, doublereal *d__,
24608
doublereal *e, doublecomplex *z__, integer *ldz, doublereal *work,
24609
integer *info)
24610
{
24611
/* System generated locals */
24612
integer z_dim1, z_offset, i__1, i__2;
24613
doublereal d__1, d__2;
24614
24615
/* Local variables */
24616
static doublereal b, c__, f, g;
24617
static integer i__, j, k, l, m;
24618
static doublereal p, r__, s;
24619
static integer l1, ii, mm, lm1, mm1, nm1;
24620
static doublereal rt1, rt2, eps;
24621
static integer lsv;
24622
static doublereal tst, eps2;
24623
static integer lend, jtot;
24624
extern /* Subroutine */ int dlae2_(doublereal *, doublereal *, doublereal
24625
*, doublereal *, doublereal *);
24626
extern logical lsame_(char *, char *);
24627
static doublereal anorm;
24628
extern /* Subroutine */ int zlasr_(char *, char *, char *, integer *,
24629
integer *, doublereal *, doublereal *, doublecomplex *, integer *), zswap_(integer *, doublecomplex *,
24630
integer *, doublecomplex *, integer *), dlaev2_(doublereal *,
24631
doublereal *, doublereal *, doublereal *, doublereal *,
24632
doublereal *, doublereal *);
24633
static integer lendm1, lendp1;
24634
24635
static integer iscale;
24636
extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
24637
doublereal *, doublereal *, integer *, integer *, doublereal *,
24638
integer *, integer *);
24639
static doublereal safmin;
24640
extern /* Subroutine */ int dlartg_(doublereal *, doublereal *,
24641
doublereal *, doublereal *, doublereal *);
24642
static doublereal safmax;
24643
extern /* Subroutine */ int xerbla_(char *, integer *);
24644
extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
24645
extern /* Subroutine */ int dlasrt_(char *, integer *, doublereal *,
24646
integer *);
24647
static integer lendsv;
24648
static doublereal ssfmin;
24649
static integer nmaxit, icompz;
24650
static doublereal ssfmax;
24651
extern /* Subroutine */ int zlaset_(char *, integer *, integer *,
24652
doublecomplex *, doublecomplex *, doublecomplex *, integer *);
24653
24654
24655
/*
24656
-- LAPACK routine (version 3.2) --
24657
-- LAPACK is a software package provided by Univ. of Tennessee, --
24658
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
24659
November 2006
24660
24661
24662
Purpose
24663
=======
24664
24665
ZSTEQR computes all eigenvalues and, optionally, eigenvectors of a
24666
symmetric tridiagonal matrix using the implicit QL or QR method.
24667
The eigenvectors of a full or band complex Hermitian matrix can also
24668
be found if ZHETRD or ZHPTRD or ZHBTRD has been used to reduce this
24669
matrix to tridiagonal form.
24670
24671
Arguments
24672
=========
24673
24674
COMPZ (input) CHARACTER*1
24675
= 'N': Compute eigenvalues only.
24676
= 'V': Compute eigenvalues and eigenvectors of the original
24677
Hermitian matrix. On entry, Z must contain the
24678
unitary matrix used to reduce the original matrix
24679
to tridiagonal form.
24680
= 'I': Compute eigenvalues and eigenvectors of the
24681
tridiagonal matrix. Z is initialized to the identity
24682
matrix.
24683
24684
N (input) INTEGER
24685
The order of the matrix. N >= 0.
24686
24687
D (input/output) DOUBLE PRECISION array, dimension (N)
24688
On entry, the diagonal elements of the tridiagonal matrix.
24689
On exit, if INFO = 0, the eigenvalues in ascending order.
24690
24691
E (input/output) DOUBLE PRECISION array, dimension (N-1)
24692
On entry, the (n-1) subdiagonal elements of the tridiagonal
24693
matrix.
24694
On exit, E has been destroyed.
24695
24696
Z (input/output) COMPLEX*16 array, dimension (LDZ, N)
24697
On entry, if COMPZ = 'V', then Z contains the unitary
24698
matrix used in the reduction to tridiagonal form.
24699
On exit, if INFO = 0, then if COMPZ = 'V', Z contains the
24700
orthonormal eigenvectors of the original Hermitian matrix,
24701
and if COMPZ = 'I', Z contains the orthonormal eigenvectors
24702
of the symmetric tridiagonal matrix.
24703
If COMPZ = 'N', then Z is not referenced.
24704
24705
LDZ (input) INTEGER
24706
The leading dimension of the array Z. LDZ >= 1, and if
24707
eigenvectors are desired, then LDZ >= max(1,N).
24708
24709
WORK (workspace) DOUBLE PRECISION array, dimension (max(1,2*N-2))
24710
If COMPZ = 'N', then WORK is not referenced.
24711
24712
INFO (output) INTEGER
24713
= 0: successful exit
24714
< 0: if INFO = -i, the i-th argument had an illegal value
24715
> 0: the algorithm has failed to find all the eigenvalues in
24716
a total of 30*N iterations; if INFO = i, then i
24717
elements of E have not converged to zero; on exit, D
24718
and E contain the elements of a symmetric tridiagonal
24719
matrix which is unitarily similar to the original
24720
matrix.
24721
24722
=====================================================================
24723
24724
24725
Test the input parameters.
24726
*/
24727
24728
/* Parameter adjustments */
24729
--d__;
24730
--e;
24731
z_dim1 = *ldz;
24732
z_offset = 1 + z_dim1;
24733
z__ -= z_offset;
24734
--work;
24735
24736
/* Function Body */
24737
*info = 0;
24738
24739
if (lsame_(compz, "N")) {
24740
icompz = 0;
24741
} else if (lsame_(compz, "V")) {
24742
icompz = 1;
24743
} else if (lsame_(compz, "I")) {
24744
icompz = 2;
24745
} else {
24746
icompz = -1;
24747
}
24748
if (icompz < 0) {
24749
*info = -1;
24750
} else if (*n < 0) {
24751
*info = -2;
24752
} else if (*ldz < 1 || icompz > 0 && *ldz < max(1,*n)) {
24753
*info = -6;
24754
}
24755
if (*info != 0) {
24756
i__1 = -(*info);
24757
xerbla_("ZSTEQR", &i__1);
24758
return 0;
24759
}
24760
24761
/* Quick return if possible */
24762
24763
if (*n == 0) {
24764
return 0;
24765
}
24766
24767
if (*n == 1) {
24768
if (icompz == 2) {
24769
i__1 = z_dim1 + 1;
24770
z__[i__1].r = 1., z__[i__1].i = 0.;
24771
}
24772
return 0;
24773
}
24774
24775
/* Determine the unit roundoff and over/underflow thresholds. */
24776
24777
eps = EPSILON;
24778
/* Computing 2nd power */
24779
d__1 = eps;
24780
eps2 = d__1 * d__1;
24781
safmin = SAFEMINIMUM;
24782
safmax = 1. / safmin;
24783
ssfmax = sqrt(safmax) / 3.;
24784
ssfmin = sqrt(safmin) / eps2;
24785
24786
/*
24787
Compute the eigenvalues and eigenvectors of the tridiagonal
24788
matrix.
24789
*/
24790
24791
if (icompz == 2) {
24792
zlaset_("Full", n, n, &c_b56, &c_b57, &z__[z_offset], ldz);
24793
}
24794
24795
nmaxit = *n * 30;
24796
jtot = 0;
24797
24798
/*
24799
Determine where the matrix splits and choose QL or QR iteration
24800
for each block, according to whether top or bottom diagonal
24801
element is smaller.
24802
*/
24803
24804
l1 = 1;
24805
nm1 = *n - 1;
24806
24807
L10:
24808
if (l1 > *n) {
24809
goto L160;
24810
}
24811
if (l1 > 1) {
24812
e[l1 - 1] = 0.;
24813
}
24814
if (l1 <= nm1) {
24815
i__1 = nm1;
24816
for (m = l1; m <= i__1; ++m) {
24817
tst = (d__1 = e[m], abs(d__1));
24818
if (tst == 0.) {
24819
goto L30;
24820
}
24821
if (tst <= sqrt((d__1 = d__[m], abs(d__1))) * sqrt((d__2 = d__[m
24822
+ 1], abs(d__2))) * eps) {
24823
e[m] = 0.;
24824
goto L30;
24825
}
24826
/* L20: */
24827
}
24828
}
24829
m = *n;
24830
24831
L30:
24832
l = l1;
24833
lsv = l;
24834
lend = m;
24835
lendsv = lend;
24836
l1 = m + 1;
24837
if (lend == l) {
24838
goto L10;
24839
}
24840
24841
/* Scale submatrix in rows and columns L to LEND */
24842
24843
i__1 = lend - l + 1;
24844
anorm = dlanst_("I", &i__1, &d__[l], &e[l]);
24845
iscale = 0;
24846
if (anorm == 0.) {
24847
goto L10;
24848
}
24849
if (anorm > ssfmax) {
24850
iscale = 1;
24851
i__1 = lend - l + 1;
24852
dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &d__[l], n,
24853
info);
24854
i__1 = lend - l;
24855
dlascl_("G", &c__0, &c__0, &anorm, &ssfmax, &i__1, &c__1, &e[l], n,
24856
info);
24857
} else if (anorm < ssfmin) {
24858
iscale = 2;
24859
i__1 = lend - l + 1;
24860
dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &d__[l], n,
24861
info);
24862
i__1 = lend - l;
24863
dlascl_("G", &c__0, &c__0, &anorm, &ssfmin, &i__1, &c__1, &e[l], n,
24864
info);
24865
}
24866
24867
/* Choose between QL and QR iteration */
24868
24869
if ((d__1 = d__[lend], abs(d__1)) < (d__2 = d__[l], abs(d__2))) {
24870
lend = lsv;
24871
l = lendsv;
24872
}
24873
24874
if (lend > l) {
24875
24876
/*
24877
QL Iteration
24878
24879
Look for small subdiagonal element.
24880
*/
24881
24882
L40:
24883
if (l != lend) {
24884
lendm1 = lend - 1;
24885
i__1 = lendm1;
24886
for (m = l; m <= i__1; ++m) {
24887
/* Computing 2nd power */
24888
d__2 = (d__1 = e[m], abs(d__1));
24889
tst = d__2 * d__2;
24890
if (tst <= eps2 * (d__1 = d__[m], abs(d__1)) * (d__2 = d__[m
24891
+ 1], abs(d__2)) + safmin) {
24892
goto L60;
24893
}
24894
/* L50: */
24895
}
24896
}
24897
24898
m = lend;
24899
24900
L60:
24901
if (m < lend) {
24902
e[m] = 0.;
24903
}
24904
p = d__[l];
24905
if (m == l) {
24906
goto L80;
24907
}
24908
24909
/*
24910
If remaining matrix is 2-by-2, use DLAE2 or SLAEV2
24911
to compute its eigensystem.
24912
*/
24913
24914
if (m == l + 1) {
24915
if (icompz > 0) {
24916
dlaev2_(&d__[l], &e[l], &d__[l + 1], &rt1, &rt2, &c__, &s);
24917
work[l] = c__;
24918
work[*n - 1 + l] = s;
24919
zlasr_("R", "V", "B", n, &c__2, &work[l], &work[*n - 1 + l], &
24920
z__[l * z_dim1 + 1], ldz);
24921
} else {
24922
dlae2_(&d__[l], &e[l], &d__[l + 1], &rt1, &rt2);
24923
}
24924
d__[l] = rt1;
24925
d__[l + 1] = rt2;
24926
e[l] = 0.;
24927
l += 2;
24928
if (l <= lend) {
24929
goto L40;
24930
}
24931
goto L140;
24932
}
24933
24934
if (jtot == nmaxit) {
24935
goto L140;
24936
}
24937
++jtot;
24938
24939
/* Form shift. */
24940
24941
g = (d__[l + 1] - p) / (e[l] * 2.);
24942
r__ = dlapy2_(&g, &c_b1034);
24943
g = d__[m] - p + e[l] / (g + d_sign(&r__, &g));
24944
24945
s = 1.;
24946
c__ = 1.;
24947
p = 0.;
24948
24949
/* Inner loop */
24950
24951
mm1 = m - 1;
24952
i__1 = l;
24953
for (i__ = mm1; i__ >= i__1; --i__) {
24954
f = s * e[i__];
24955
b = c__ * e[i__];
24956
dlartg_(&g, &f, &c__, &s, &r__);
24957
if (i__ != m - 1) {
24958
e[i__ + 1] = r__;
24959
}
24960
g = d__[i__ + 1] - p;
24961
r__ = (d__[i__] - g) * s + c__ * 2. * b;
24962
p = s * r__;
24963
d__[i__ + 1] = g + p;
24964
g = c__ * r__ - b;
24965
24966
/* If eigenvectors are desired, then save rotations. */
24967
24968
if (icompz > 0) {
24969
work[i__] = c__;
24970
work[*n - 1 + i__] = -s;
24971
}
24972
24973
/* L70: */
24974
}
24975
24976
/* If eigenvectors are desired, then apply saved rotations. */
24977
24978
if (icompz > 0) {
24979
mm = m - l + 1;
24980
zlasr_("R", "V", "B", n, &mm, &work[l], &work[*n - 1 + l], &z__[l
24981
* z_dim1 + 1], ldz);
24982
}
24983
24984
d__[l] -= p;
24985
e[l] = g;
24986
goto L40;
24987
24988
/* Eigenvalue found. */
24989
24990
L80:
24991
d__[l] = p;
24992
24993
++l;
24994
if (l <= lend) {
24995
goto L40;
24996
}
24997
goto L140;
24998
24999
} else {
25000
25001
/*
25002
QR Iteration
25003
25004
Look for small superdiagonal element.
25005
*/
25006
25007
L90:
25008
if (l != lend) {
25009
lendp1 = lend + 1;
25010
i__1 = lendp1;
25011
for (m = l; m >= i__1; --m) {
25012
/* Computing 2nd power */
25013
d__2 = (d__1 = e[m - 1], abs(d__1));
25014
tst = d__2 * d__2;
25015
if (tst <= eps2 * (d__1 = d__[m], abs(d__1)) * (d__2 = d__[m
25016
- 1], abs(d__2)) + safmin) {
25017
goto L110;
25018
}
25019
/* L100: */
25020
}
25021
}
25022
25023
m = lend;
25024
25025
L110:
25026
if (m > lend) {
25027
e[m - 1] = 0.;
25028
}
25029
p = d__[l];
25030
if (m == l) {
25031
goto L130;
25032
}
25033
25034
/*
25035
If remaining matrix is 2-by-2, use DLAE2 or SLAEV2
25036
to compute its eigensystem.
25037
*/
25038
25039
if (m == l - 1) {
25040
if (icompz > 0) {
25041
dlaev2_(&d__[l - 1], &e[l - 1], &d__[l], &rt1, &rt2, &c__, &s)
25042
;
25043
work[m] = c__;
25044
work[*n - 1 + m] = s;
25045
zlasr_("R", "V", "F", n, &c__2, &work[m], &work[*n - 1 + m], &
25046
z__[(l - 1) * z_dim1 + 1], ldz);
25047
} else {
25048
dlae2_(&d__[l - 1], &e[l - 1], &d__[l], &rt1, &rt2);
25049
}
25050
d__[l - 1] = rt1;
25051
d__[l] = rt2;
25052
e[l - 1] = 0.;
25053
l += -2;
25054
if (l >= lend) {
25055
goto L90;
25056
}
25057
goto L140;
25058
}
25059
25060
if (jtot == nmaxit) {
25061
goto L140;
25062
}
25063
++jtot;
25064
25065
/* Form shift. */
25066
25067
g = (d__[l - 1] - p) / (e[l - 1] * 2.);
25068
r__ = dlapy2_(&g, &c_b1034);
25069
g = d__[m] - p + e[l - 1] / (g + d_sign(&r__, &g));
25070
25071
s = 1.;
25072
c__ = 1.;
25073
p = 0.;
25074
25075
/* Inner loop */
25076
25077
lm1 = l - 1;
25078
i__1 = lm1;
25079
for (i__ = m; i__ <= i__1; ++i__) {
25080
f = s * e[i__];
25081
b = c__ * e[i__];
25082
dlartg_(&g, &f, &c__, &s, &r__);
25083
if (i__ != m) {
25084
e[i__ - 1] = r__;
25085
}
25086
g = d__[i__] - p;
25087
r__ = (d__[i__ + 1] - g) * s + c__ * 2. * b;
25088
p = s * r__;
25089
d__[i__] = g + p;
25090
g = c__ * r__ - b;
25091
25092
/* If eigenvectors are desired, then save rotations. */
25093
25094
if (icompz > 0) {
25095
work[i__] = c__;
25096
work[*n - 1 + i__] = s;
25097
}
25098
25099
/* L120: */
25100
}
25101
25102
/* If eigenvectors are desired, then apply saved rotations. */
25103
25104
if (icompz > 0) {
25105
mm = l - m + 1;
25106
zlasr_("R", "V", "F", n, &mm, &work[m], &work[*n - 1 + m], &z__[m
25107
* z_dim1 + 1], ldz);
25108
}
25109
25110
d__[l] -= p;
25111
e[lm1] = g;
25112
goto L90;
25113
25114
/* Eigenvalue found. */
25115
25116
L130:
25117
d__[l] = p;
25118
25119
--l;
25120
if (l >= lend) {
25121
goto L90;
25122
}
25123
goto L140;
25124
25125
}
25126
25127
/* Undo scaling if necessary */
25128
25129
L140:
25130
if (iscale == 1) {
25131
i__1 = lendsv - lsv + 1;
25132
dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &d__[lsv],
25133
n, info);
25134
i__1 = lendsv - lsv;
25135
dlascl_("G", &c__0, &c__0, &ssfmax, &anorm, &i__1, &c__1, &e[lsv], n,
25136
info);
25137
} else if (iscale == 2) {
25138
i__1 = lendsv - lsv + 1;
25139
dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &d__[lsv],
25140
n, info);
25141
i__1 = lendsv - lsv;
25142
dlascl_("G", &c__0, &c__0, &ssfmin, &anorm, &i__1, &c__1, &e[lsv], n,
25143
info);
25144
}
25145
25146
/*
25147
Check for no convergence to an eigenvalue after a total
25148
of N*MAXIT iterations.
25149
*/
25150
25151
if (jtot == nmaxit) {
25152
i__1 = *n - 1;
25153
for (i__ = 1; i__ <= i__1; ++i__) {
25154
if (e[i__] != 0.) {
25155
++(*info);
25156
}
25157
/* L150: */
25158
}
25159
return 0;
25160
}
25161
goto L10;
25162
25163
/* Order eigenvalues and eigenvectors. */
25164
25165
L160:
25166
if (icompz == 0) {
25167
25168
/* Use Quick Sort */
25169
25170
dlasrt_("I", n, &d__[1], info);
25171
25172
} else {
25173
25174
/* Use Selection Sort to minimize swaps of eigenvectors */
25175
25176
i__1 = *n;
25177
for (ii = 2; ii <= i__1; ++ii) {
25178
i__ = ii - 1;
25179
k = i__;
25180
p = d__[i__];
25181
i__2 = *n;
25182
for (j = ii; j <= i__2; ++j) {
25183
if (d__[j] < p) {
25184
k = j;
25185
p = d__[j];
25186
}
25187
/* L170: */
25188
}
25189
if (k != i__) {
25190
d__[k] = d__[i__];
25191
d__[i__] = p;
25192
zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[k * z_dim1 + 1],
25193
&c__1);
25194
}
25195
/* L180: */
25196
}
25197
}
25198
return 0;
25199
25200
/* End of ZSTEQR */
25201
25202
} /* zsteqr_ */
25203
25204
/* Subroutine */ int ztrevc_(char *side, char *howmny, logical *select,
25205
integer *n, doublecomplex *t, integer *ldt, doublecomplex *vl,
25206
integer *ldvl, doublecomplex *vr, integer *ldvr, integer *mm, integer
25207
*m, doublecomplex *work, doublereal *rwork, integer *info)
25208
{
25209
/* System generated locals */
25210
integer t_dim1, t_offset, vl_dim1, vl_offset, vr_dim1, vr_offset, i__1,
25211
i__2, i__3, i__4, i__5;
25212
doublereal d__1, d__2, d__3;
25213
doublecomplex z__1, z__2;
25214
25215
/* Local variables */
25216
static integer i__, j, k, ii, ki, is;
25217
static doublereal ulp;
25218
static logical allv;
25219
static doublereal unfl, ovfl, smin;
25220
static logical over;
25221
static doublereal scale;
25222
extern logical lsame_(char *, char *);
25223
static doublereal remax;
25224
static logical leftv, bothv;
25225
extern /* Subroutine */ int zgemv_(char *, integer *, integer *,
25226
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
25227
integer *, doublecomplex *, doublecomplex *, integer *);
25228
static logical somev;
25229
extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
25230
doublecomplex *, integer *), dlabad_(doublereal *, doublereal *);
25231
25232
extern /* Subroutine */ int xerbla_(char *, integer *), zdscal_(
25233
integer *, doublereal *, doublecomplex *, integer *);
25234
extern integer izamax_(integer *, doublecomplex *, integer *);
25235
static logical rightv;
25236
extern doublereal dzasum_(integer *, doublecomplex *, integer *);
25237
static doublereal smlnum;
25238
extern /* Subroutine */ int zlatrs_(char *, char *, char *, char *,
25239
integer *, doublecomplex *, integer *, doublecomplex *,
25240
doublereal *, doublereal *, integer *);
25241
25242
25243
/*
25244
-- LAPACK routine (version 3.2) --
25245
-- LAPACK is a software package provided by Univ. of Tennessee, --
25246
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
25247
November 2006
25248
25249
25250
Purpose
25251
=======
25252
25253
ZTREVC computes some or all of the right and/or left eigenvectors of
25254
a complex upper triangular matrix T.
25255
Matrices of this type are produced by the Schur factorization of
25256
a complex general matrix: A = Q*T*Q**H, as computed by ZHSEQR.
25257
25258
The right eigenvector x and the left eigenvector y of T corresponding
25259
to an eigenvalue w are defined by:
25260
25261
T*x = w*x, (y**H)*T = w*(y**H)
25262
25263
where y**H denotes the conjugate transpose of the vector y.
25264
The eigenvalues are not input to this routine, but are read directly
25265
from the diagonal of T.
25266
25267
This routine returns the matrices X and/or Y of right and left
25268
eigenvectors of T, or the products Q*X and/or Q*Y, where Q is an
25269
input matrix. If Q is the unitary factor that reduces a matrix A to
25270
Schur form T, then Q*X and Q*Y are the matrices of right and left
25271
eigenvectors of A.
25272
25273
Arguments
25274
=========
25275
25276
SIDE (input) CHARACTER*1
25277
= 'R': compute right eigenvectors only;
25278
= 'L': compute left eigenvectors only;
25279
= 'B': compute both right and left eigenvectors.
25280
25281
HOWMNY (input) CHARACTER*1
25282
= 'A': compute all right and/or left eigenvectors;
25283
= 'B': compute all right and/or left eigenvectors,
25284
backtransformed using the matrices supplied in
25285
VR and/or VL;
25286
= 'S': compute selected right and/or left eigenvectors,
25287
as indicated by the logical array SELECT.
25288
25289
SELECT (input) LOGICAL array, dimension (N)
25290
If HOWMNY = 'S', SELECT specifies the eigenvectors to be
25291
computed.
25292
The eigenvector corresponding to the j-th eigenvalue is
25293
computed if SELECT(j) = .TRUE..
25294
Not referenced if HOWMNY = 'A' or 'B'.
25295
25296
N (input) INTEGER
25297
The order of the matrix T. N >= 0.
25298
25299
T (input/output) COMPLEX*16 array, dimension (LDT,N)
25300
The upper triangular matrix T. T is modified, but restored
25301
on exit.
25302
25303
LDT (input) INTEGER
25304
The leading dimension of the array T. LDT >= max(1,N).
25305
25306
VL (input/output) COMPLEX*16 array, dimension (LDVL,MM)
25307
On entry, if SIDE = 'L' or 'B' and HOWMNY = 'B', VL must
25308
contain an N-by-N matrix Q (usually the unitary matrix Q of
25309
Schur vectors returned by ZHSEQR).
25310
On exit, if SIDE = 'L' or 'B', VL contains:
25311
if HOWMNY = 'A', the matrix Y of left eigenvectors of T;
25312
if HOWMNY = 'B', the matrix Q*Y;
25313
if HOWMNY = 'S', the left eigenvectors of T specified by
25314
SELECT, stored consecutively in the columns
25315
of VL, in the same order as their
25316
eigenvalues.
25317
Not referenced if SIDE = 'R'.
25318
25319
LDVL (input) INTEGER
25320
The leading dimension of the array VL. LDVL >= 1, and if
25321
SIDE = 'L' or 'B', LDVL >= N.
25322
25323
VR (input/output) COMPLEX*16 array, dimension (LDVR,MM)
25324
On entry, if SIDE = 'R' or 'B' and HOWMNY = 'B', VR must
25325
contain an N-by-N matrix Q (usually the unitary matrix Q of
25326
Schur vectors returned by ZHSEQR).
25327
On exit, if SIDE = 'R' or 'B', VR contains:
25328
if HOWMNY = 'A', the matrix X of right eigenvectors of T;
25329
if HOWMNY = 'B', the matrix Q*X;
25330
if HOWMNY = 'S', the right eigenvectors of T specified by
25331
SELECT, stored consecutively in the columns
25332
of VR, in the same order as their
25333
eigenvalues.
25334
Not referenced if SIDE = 'L'.
25335
25336
LDVR (input) INTEGER
25337
The leading dimension of the array VR. LDVR >= 1, and if
25338
SIDE = 'R' or 'B'; LDVR >= N.
25339
25340
MM (input) INTEGER
25341
The number of columns in the arrays VL and/or VR. MM >= M.
25342
25343
M (output) INTEGER
25344
The number of columns in the arrays VL and/or VR actually
25345
used to store the eigenvectors. If HOWMNY = 'A' or 'B', M
25346
is set to N. Each selected eigenvector occupies one
25347
column.
25348
25349
WORK (workspace) COMPLEX*16 array, dimension (2*N)
25350
25351
RWORK (workspace) DOUBLE PRECISION array, dimension (N)
25352
25353
INFO (output) INTEGER
25354
= 0: successful exit
25355
< 0: if INFO = -i, the i-th argument had an illegal value
25356
25357
Further Details
25358
===============
25359
25360
The algorithm used in this program is basically backward (forward)
25361
substitution, with scaling to make the code robust against
25362
possible overflow.
25363
25364
Each eigenvector is normalized so that the element of largest
25365
magnitude has magnitude 1; here the magnitude of a complex number
25366
(x,y) is taken to be |x| + |y|.
25367
25368
=====================================================================
25369
25370
25371
Decode and test the input parameters
25372
*/
25373
25374
/* Parameter adjustments */
25375
--select;
25376
t_dim1 = *ldt;
25377
t_offset = 1 + t_dim1;
25378
t -= t_offset;
25379
vl_dim1 = *ldvl;
25380
vl_offset = 1 + vl_dim1;
25381
vl -= vl_offset;
25382
vr_dim1 = *ldvr;
25383
vr_offset = 1 + vr_dim1;
25384
vr -= vr_offset;
25385
--work;
25386
--rwork;
25387
25388
/* Function Body */
25389
bothv = lsame_(side, "B");
25390
rightv = lsame_(side, "R") || bothv;
25391
leftv = lsame_(side, "L") || bothv;
25392
25393
allv = lsame_(howmny, "A");
25394
over = lsame_(howmny, "B");
25395
somev = lsame_(howmny, "S");
25396
25397
/*
25398
Set M to the number of columns required to store the selected
25399
eigenvectors.
25400
*/
25401
25402
if (somev) {
25403
*m = 0;
25404
i__1 = *n;
25405
for (j = 1; j <= i__1; ++j) {
25406
if (select[j]) {
25407
++(*m);
25408
}
25409
/* L10: */
25410
}
25411
} else {
25412
*m = *n;
25413
}
25414
25415
*info = 0;
25416
if (! rightv && ! leftv) {
25417
*info = -1;
25418
} else if (! allv && ! over && ! somev) {
25419
*info = -2;
25420
} else if (*n < 0) {
25421
*info = -4;
25422
} else if (*ldt < max(1,*n)) {
25423
*info = -6;
25424
} else if (*ldvl < 1 || leftv && *ldvl < *n) {
25425
*info = -8;
25426
} else if (*ldvr < 1 || rightv && *ldvr < *n) {
25427
*info = -10;
25428
} else if (*mm < *m) {
25429
*info = -11;
25430
}
25431
if (*info != 0) {
25432
i__1 = -(*info);
25433
xerbla_("ZTREVC", &i__1);
25434
return 0;
25435
}
25436
25437
/* Quick return if possible. */
25438
25439
if (*n == 0) {
25440
return 0;
25441
}
25442
25443
/* Set the constants to control overflow. */
25444
25445
unfl = SAFEMINIMUM;
25446
ovfl = 1. / unfl;
25447
dlabad_(&unfl, &ovfl);
25448
ulp = PRECISION;
25449
smlnum = unfl * (*n / ulp);
25450
25451
/* Store the diagonal elements of T in working array WORK. */
25452
25453
i__1 = *n;
25454
for (i__ = 1; i__ <= i__1; ++i__) {
25455
i__2 = i__ + *n;
25456
i__3 = i__ + i__ * t_dim1;
25457
work[i__2].r = t[i__3].r, work[i__2].i = t[i__3].i;
25458
/* L20: */
25459
}
25460
25461
/*
25462
Compute 1-norm of each column of strictly upper triangular
25463
part of T to control overflow in triangular solver.
25464
*/
25465
25466
rwork[1] = 0.;
25467
i__1 = *n;
25468
for (j = 2; j <= i__1; ++j) {
25469
i__2 = j - 1;
25470
rwork[j] = dzasum_(&i__2, &t[j * t_dim1 + 1], &c__1);
25471
/* L30: */
25472
}
25473
25474
if (rightv) {
25475
25476
/* Compute right eigenvectors. */
25477
25478
is = *m;
25479
for (ki = *n; ki >= 1; --ki) {
25480
25481
if (somev) {
25482
if (! select[ki]) {
25483
goto L80;
25484
}
25485
}
25486
/* Computing MAX */
25487
i__1 = ki + ki * t_dim1;
25488
d__3 = ulp * ((d__1 = t[i__1].r, abs(d__1)) + (d__2 = d_imag(&t[
25489
ki + ki * t_dim1]), abs(d__2)));
25490
smin = max(d__3,smlnum);
25491
25492
work[1].r = 1., work[1].i = 0.;
25493
25494
/* Form right-hand side. */
25495
25496
i__1 = ki - 1;
25497
for (k = 1; k <= i__1; ++k) {
25498
i__2 = k;
25499
i__3 = k + ki * t_dim1;
25500
z__1.r = -t[i__3].r, z__1.i = -t[i__3].i;
25501
work[i__2].r = z__1.r, work[i__2].i = z__1.i;
25502
/* L40: */
25503
}
25504
25505
/*
25506
Solve the triangular system:
25507
(T(1:KI-1,1:KI-1) - T(KI,KI))*X = SCALE*WORK.
25508
*/
25509
25510
i__1 = ki - 1;
25511
for (k = 1; k <= i__1; ++k) {
25512
i__2 = k + k * t_dim1;
25513
i__3 = k + k * t_dim1;
25514
i__4 = ki + ki * t_dim1;
25515
z__1.r = t[i__3].r - t[i__4].r, z__1.i = t[i__3].i - t[i__4]
25516
.i;
25517
t[i__2].r = z__1.r, t[i__2].i = z__1.i;
25518
i__2 = k + k * t_dim1;
25519
if ((d__1 = t[i__2].r, abs(d__1)) + (d__2 = d_imag(&t[k + k *
25520
t_dim1]), abs(d__2)) < smin) {
25521
i__3 = k + k * t_dim1;
25522
t[i__3].r = smin, t[i__3].i = 0.;
25523
}
25524
/* L50: */
25525
}
25526
25527
if (ki > 1) {
25528
i__1 = ki - 1;
25529
zlatrs_("Upper", "No transpose", "Non-unit", "Y", &i__1, &t[
25530
t_offset], ldt, &work[1], &scale, &rwork[1], info);
25531
i__1 = ki;
25532
work[i__1].r = scale, work[i__1].i = 0.;
25533
}
25534
25535
/* Copy the vector x or Q*x to VR and normalize. */
25536
25537
if (! over) {
25538
zcopy_(&ki, &work[1], &c__1, &vr[is * vr_dim1 + 1], &c__1);
25539
25540
ii = izamax_(&ki, &vr[is * vr_dim1 + 1], &c__1);
25541
i__1 = ii + is * vr_dim1;
25542
remax = 1. / ((d__1 = vr[i__1].r, abs(d__1)) + (d__2 = d_imag(
25543
&vr[ii + is * vr_dim1]), abs(d__2)));
25544
zdscal_(&ki, &remax, &vr[is * vr_dim1 + 1], &c__1);
25545
25546
i__1 = *n;
25547
for (k = ki + 1; k <= i__1; ++k) {
25548
i__2 = k + is * vr_dim1;
25549
vr[i__2].r = 0., vr[i__2].i = 0.;
25550
/* L60: */
25551
}
25552
} else {
25553
if (ki > 1) {
25554
i__1 = ki - 1;
25555
z__1.r = scale, z__1.i = 0.;
25556
zgemv_("N", n, &i__1, &c_b57, &vr[vr_offset], ldvr, &work[
25557
1], &c__1, &z__1, &vr[ki * vr_dim1 + 1], &c__1);
25558
}
25559
25560
ii = izamax_(n, &vr[ki * vr_dim1 + 1], &c__1);
25561
i__1 = ii + ki * vr_dim1;
25562
remax = 1. / ((d__1 = vr[i__1].r, abs(d__1)) + (d__2 = d_imag(
25563
&vr[ii + ki * vr_dim1]), abs(d__2)));
25564
zdscal_(n, &remax, &vr[ki * vr_dim1 + 1], &c__1);
25565
}
25566
25567
/* Set back the original diagonal elements of T. */
25568
25569
i__1 = ki - 1;
25570
for (k = 1; k <= i__1; ++k) {
25571
i__2 = k + k * t_dim1;
25572
i__3 = k + *n;
25573
t[i__2].r = work[i__3].r, t[i__2].i = work[i__3].i;
25574
/* L70: */
25575
}
25576
25577
--is;
25578
L80:
25579
;
25580
}
25581
}
25582
25583
if (leftv) {
25584
25585
/* Compute left eigenvectors. */
25586
25587
is = 1;
25588
i__1 = *n;
25589
for (ki = 1; ki <= i__1; ++ki) {
25590
25591
if (somev) {
25592
if (! select[ki]) {
25593
goto L130;
25594
}
25595
}
25596
/* Computing MAX */
25597
i__2 = ki + ki * t_dim1;
25598
d__3 = ulp * ((d__1 = t[i__2].r, abs(d__1)) + (d__2 = d_imag(&t[
25599
ki + ki * t_dim1]), abs(d__2)));
25600
smin = max(d__3,smlnum);
25601
25602
i__2 = *n;
25603
work[i__2].r = 1., work[i__2].i = 0.;
25604
25605
/* Form right-hand side. */
25606
25607
i__2 = *n;
25608
for (k = ki + 1; k <= i__2; ++k) {
25609
i__3 = k;
25610
d_cnjg(&z__2, &t[ki + k * t_dim1]);
25611
z__1.r = -z__2.r, z__1.i = -z__2.i;
25612
work[i__3].r = z__1.r, work[i__3].i = z__1.i;
25613
/* L90: */
25614
}
25615
25616
/*
25617
Solve the triangular system:
25618
(T(KI+1:N,KI+1:N) - T(KI,KI))'*X = SCALE*WORK.
25619
*/
25620
25621
i__2 = *n;
25622
for (k = ki + 1; k <= i__2; ++k) {
25623
i__3 = k + k * t_dim1;
25624
i__4 = k + k * t_dim1;
25625
i__5 = ki + ki * t_dim1;
25626
z__1.r = t[i__4].r - t[i__5].r, z__1.i = t[i__4].i - t[i__5]
25627
.i;
25628
t[i__3].r = z__1.r, t[i__3].i = z__1.i;
25629
i__3 = k + k * t_dim1;
25630
if ((d__1 = t[i__3].r, abs(d__1)) + (d__2 = d_imag(&t[k + k *
25631
t_dim1]), abs(d__2)) < smin) {
25632
i__4 = k + k * t_dim1;
25633
t[i__4].r = smin, t[i__4].i = 0.;
25634
}
25635
/* L100: */
25636
}
25637
25638
if (ki < *n) {
25639
i__2 = *n - ki;
25640
zlatrs_("Upper", "Conjugate transpose", "Non-unit", "Y", &
25641
i__2, &t[ki + 1 + (ki + 1) * t_dim1], ldt, &work[ki +
25642
1], &scale, &rwork[1], info);
25643
i__2 = ki;
25644
work[i__2].r = scale, work[i__2].i = 0.;
25645
}
25646
25647
/* Copy the vector x or Q*x to VL and normalize. */
25648
25649
if (! over) {
25650
i__2 = *n - ki + 1;
25651
zcopy_(&i__2, &work[ki], &c__1, &vl[ki + is * vl_dim1], &c__1)
25652
;
25653
25654
i__2 = *n - ki + 1;
25655
ii = izamax_(&i__2, &vl[ki + is * vl_dim1], &c__1) + ki - 1;
25656
i__2 = ii + is * vl_dim1;
25657
remax = 1. / ((d__1 = vl[i__2].r, abs(d__1)) + (d__2 = d_imag(
25658
&vl[ii + is * vl_dim1]), abs(d__2)));
25659
i__2 = *n - ki + 1;
25660
zdscal_(&i__2, &remax, &vl[ki + is * vl_dim1], &c__1);
25661
25662
i__2 = ki - 1;
25663
for (k = 1; k <= i__2; ++k) {
25664
i__3 = k + is * vl_dim1;
25665
vl[i__3].r = 0., vl[i__3].i = 0.;
25666
/* L110: */
25667
}
25668
} else {
25669
if (ki < *n) {
25670
i__2 = *n - ki;
25671
z__1.r = scale, z__1.i = 0.;
25672
zgemv_("N", n, &i__2, &c_b57, &vl[(ki + 1) * vl_dim1 + 1],
25673
ldvl, &work[ki + 1], &c__1, &z__1, &vl[ki *
25674
vl_dim1 + 1], &c__1);
25675
}
25676
25677
ii = izamax_(n, &vl[ki * vl_dim1 + 1], &c__1);
25678
i__2 = ii + ki * vl_dim1;
25679
remax = 1. / ((d__1 = vl[i__2].r, abs(d__1)) + (d__2 = d_imag(
25680
&vl[ii + ki * vl_dim1]), abs(d__2)));
25681
zdscal_(n, &remax, &vl[ki * vl_dim1 + 1], &c__1);
25682
}
25683
25684
/* Set back the original diagonal elements of T. */
25685
25686
i__2 = *n;
25687
for (k = ki + 1; k <= i__2; ++k) {
25688
i__3 = k + k * t_dim1;
25689
i__4 = k + *n;
25690
t[i__3].r = work[i__4].r, t[i__3].i = work[i__4].i;
25691
/* L120: */
25692
}
25693
25694
++is;
25695
L130:
25696
;
25697
}
25698
}
25699
25700
return 0;
25701
25702
/* End of ZTREVC */
25703
25704
} /* ztrevc_ */
25705
25706
/* Subroutine */ int ztrexc_(char *compq, integer *n, doublecomplex *t,
25707
integer *ldt, doublecomplex *q, integer *ldq, integer *ifst, integer *
25708
ilst, integer *info)
25709
{
25710
/* System generated locals */
25711
integer q_dim1, q_offset, t_dim1, t_offset, i__1, i__2, i__3;
25712
doublecomplex z__1;
25713
25714
/* Local variables */
25715
static integer k, m1, m2, m3;
25716
static doublereal cs;
25717
static doublecomplex t11, t22, sn, temp;
25718
extern /* Subroutine */ int zrot_(integer *, doublecomplex *, integer *,
25719
doublecomplex *, integer *, doublereal *, doublecomplex *);
25720
extern logical lsame_(char *, char *);
25721
static logical wantq;
25722
extern /* Subroutine */ int xerbla_(char *, integer *), zlartg_(
25723
doublecomplex *, doublecomplex *, doublereal *, doublecomplex *,
25724
doublecomplex *);
25725
25726
25727
/*
25728
-- LAPACK routine (version 3.2) --
25729
-- LAPACK is a software package provided by Univ. of Tennessee, --
25730
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
25731
November 2006
25732
25733
25734
Purpose
25735
=======
25736
25737
ZTREXC reorders the Schur factorization of a complex matrix
25738
A = Q*T*Q**H, so that the diagonal element of T with row index IFST
25739
is moved to row ILST.
25740
25741
The Schur form T is reordered by a unitary similarity transformation
25742
Z**H*T*Z, and optionally the matrix Q of Schur vectors is updated by
25743
postmultplying it with Z.
25744
25745
Arguments
25746
=========
25747
25748
COMPQ (input) CHARACTER*1
25749
= 'V': update the matrix Q of Schur vectors;
25750
= 'N': do not update Q.
25751
25752
N (input) INTEGER
25753
The order of the matrix T. N >= 0.
25754
25755
T (input/output) COMPLEX*16 array, dimension (LDT,N)
25756
On entry, the upper triangular matrix T.
25757
On exit, the reordered upper triangular matrix.
25758
25759
LDT (input) INTEGER
25760
The leading dimension of the array T. LDT >= max(1,N).
25761
25762
Q (input/output) COMPLEX*16 array, dimension (LDQ,N)
25763
On entry, if COMPQ = 'V', the matrix Q of Schur vectors.
25764
On exit, if COMPQ = 'V', Q has been postmultiplied by the
25765
unitary transformation matrix Z which reorders T.
25766
If COMPQ = 'N', Q is not referenced.
25767
25768
LDQ (input) INTEGER
25769
The leading dimension of the array Q. LDQ >= max(1,N).
25770
25771
IFST (input) INTEGER
25772
ILST (input) INTEGER
25773
Specify the reordering of the diagonal elements of T:
25774
The element with row index IFST is moved to row ILST by a
25775
sequence of transpositions between adjacent elements.
25776
1 <= IFST <= N; 1 <= ILST <= N.
25777
25778
INFO (output) INTEGER
25779
= 0: successful exit
25780
< 0: if INFO = -i, the i-th argument had an illegal value
25781
25782
=====================================================================
25783
25784
25785
Decode and test the input parameters.
25786
*/
25787
25788
/* Parameter adjustments */
25789
t_dim1 = *ldt;
25790
t_offset = 1 + t_dim1;
25791
t -= t_offset;
25792
q_dim1 = *ldq;
25793
q_offset = 1 + q_dim1;
25794
q -= q_offset;
25795
25796
/* Function Body */
25797
*info = 0;
25798
wantq = lsame_(compq, "V");
25799
if (! lsame_(compq, "N") && ! wantq) {
25800
*info = -1;
25801
} else if (*n < 0) {
25802
*info = -2;
25803
} else if (*ldt < max(1,*n)) {
25804
*info = -4;
25805
} else if (*ldq < 1 || wantq && *ldq < max(1,*n)) {
25806
*info = -6;
25807
} else if (*ifst < 1 || *ifst > *n) {
25808
*info = -7;
25809
} else if (*ilst < 1 || *ilst > *n) {
25810
*info = -8;
25811
}
25812
if (*info != 0) {
25813
i__1 = -(*info);
25814
xerbla_("ZTREXC", &i__1);
25815
return 0;
25816
}
25817
25818
/* Quick return if possible */
25819
25820
if (*n == 1 || *ifst == *ilst) {
25821
return 0;
25822
}
25823
25824
if (*ifst < *ilst) {
25825
25826
/* Move the IFST-th diagonal element forward down the diagonal. */
25827
25828
m1 = 0;
25829
m2 = -1;
25830
m3 = 1;
25831
} else {
25832
25833
/* Move the IFST-th diagonal element backward up the diagonal. */
25834
25835
m1 = -1;
25836
m2 = 0;
25837
m3 = -1;
25838
}
25839
25840
i__1 = *ilst + m2;
25841
i__2 = m3;
25842
for (k = *ifst + m1; i__2 < 0 ? k >= i__1 : k <= i__1; k += i__2) {
25843
25844
/* Interchange the k-th and (k+1)-th diagonal elements. */
25845
25846
i__3 = k + k * t_dim1;
25847
t11.r = t[i__3].r, t11.i = t[i__3].i;
25848
i__3 = k + 1 + (k + 1) * t_dim1;
25849
t22.r = t[i__3].r, t22.i = t[i__3].i;
25850
25851
/* Determine the transformation to perform the interchange. */
25852
25853
z__1.r = t22.r - t11.r, z__1.i = t22.i - t11.i;
25854
zlartg_(&t[k + (k + 1) * t_dim1], &z__1, &cs, &sn, &temp);
25855
25856
/* Apply transformation to the matrix T. */
25857
25858
if (k + 2 <= *n) {
25859
i__3 = *n - k - 1;
25860
zrot_(&i__3, &t[k + (k + 2) * t_dim1], ldt, &t[k + 1 + (k + 2) *
25861
t_dim1], ldt, &cs, &sn);
25862
}
25863
i__3 = k - 1;
25864
d_cnjg(&z__1, &sn);
25865
zrot_(&i__3, &t[k * t_dim1 + 1], &c__1, &t[(k + 1) * t_dim1 + 1], &
25866
c__1, &cs, &z__1);
25867
25868
i__3 = k + k * t_dim1;
25869
t[i__3].r = t22.r, t[i__3].i = t22.i;
25870
i__3 = k + 1 + (k + 1) * t_dim1;
25871
t[i__3].r = t11.r, t[i__3].i = t11.i;
25872
25873
if (wantq) {
25874
25875
/* Accumulate transformation in the matrix Q. */
25876
25877
d_cnjg(&z__1, &sn);
25878
zrot_(n, &q[k * q_dim1 + 1], &c__1, &q[(k + 1) * q_dim1 + 1], &
25879
c__1, &cs, &z__1);
25880
}
25881
25882
/* L10: */
25883
}
25884
25885
return 0;
25886
25887
/* End of ZTREXC */
25888
25889
} /* ztrexc_ */
25890
25891
/* Subroutine */ int ztrti2_(char *uplo, char *diag, integer *n,
25892
doublecomplex *a, integer *lda, integer *info)
25893
{
25894
/* System generated locals */
25895
integer a_dim1, a_offset, i__1, i__2;
25896
doublecomplex z__1;
25897
25898
/* Local variables */
25899
static integer j;
25900
static doublecomplex ajj;
25901
extern logical lsame_(char *, char *);
25902
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
25903
doublecomplex *, integer *);
25904
static logical upper;
25905
extern /* Subroutine */ int ztrmv_(char *, char *, char *, integer *,
25906
doublecomplex *, integer *, doublecomplex *, integer *), xerbla_(char *, integer *);
25907
static logical nounit;
25908
25909
25910
/*
25911
-- LAPACK routine (version 3.2) --
25912
-- LAPACK is a software package provided by Univ. of Tennessee, --
25913
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
25914
November 2006
25915
25916
25917
Purpose
25918
=======
25919
25920
ZTRTI2 computes the inverse of a complex upper or lower triangular
25921
matrix.
25922
25923
This is the Level 2 BLAS version of the algorithm.
25924
25925
Arguments
25926
=========
25927
25928
UPLO (input) CHARACTER*1
25929
Specifies whether the matrix A is upper or lower triangular.
25930
= 'U': Upper triangular
25931
= 'L': Lower triangular
25932
25933
DIAG (input) CHARACTER*1
25934
Specifies whether or not the matrix A is unit triangular.
25935
= 'N': Non-unit triangular
25936
= 'U': Unit triangular
25937
25938
N (input) INTEGER
25939
The order of the matrix A. N >= 0.
25940
25941
A (input/output) COMPLEX*16 array, dimension (LDA,N)
25942
On entry, the triangular matrix A. If UPLO = 'U', the
25943
leading n by n upper triangular part of the array A contains
25944
the upper triangular matrix, and the strictly lower
25945
triangular part of A is not referenced. If UPLO = 'L', the
25946
leading n by n lower triangular part of the array A contains
25947
the lower triangular matrix, and the strictly upper
25948
triangular part of A is not referenced. If DIAG = 'U', the
25949
diagonal elements of A are also not referenced and are
25950
assumed to be 1.
25951
25952
On exit, the (triangular) inverse of the original matrix, in
25953
the same storage format.
25954
25955
LDA (input) INTEGER
25956
The leading dimension of the array A. LDA >= max(1,N).
25957
25958
INFO (output) INTEGER
25959
= 0: successful exit
25960
< 0: if INFO = -k, the k-th argument had an illegal value
25961
25962
=====================================================================
25963
25964
25965
Test the input parameters.
25966
*/
25967
25968
/* Parameter adjustments */
25969
a_dim1 = *lda;
25970
a_offset = 1 + a_dim1;
25971
a -= a_offset;
25972
25973
/* Function Body */
25974
*info = 0;
25975
upper = lsame_(uplo, "U");
25976
nounit = lsame_(diag, "N");
25977
if (! upper && ! lsame_(uplo, "L")) {
25978
*info = -1;
25979
} else if (! nounit && ! lsame_(diag, "U")) {
25980
*info = -2;
25981
} else if (*n < 0) {
25982
*info = -3;
25983
} else if (*lda < max(1,*n)) {
25984
*info = -5;
25985
}
25986
if (*info != 0) {
25987
i__1 = -(*info);
25988
xerbla_("ZTRTI2", &i__1);
25989
return 0;
25990
}
25991
25992
if (upper) {
25993
25994
/* Compute inverse of upper triangular matrix. */
25995
25996
i__1 = *n;
25997
for (j = 1; j <= i__1; ++j) {
25998
if (nounit) {
25999
i__2 = j + j * a_dim1;
26000
z_div(&z__1, &c_b57, &a[j + j * a_dim1]);
26001
a[i__2].r = z__1.r, a[i__2].i = z__1.i;
26002
i__2 = j + j * a_dim1;
26003
z__1.r = -a[i__2].r, z__1.i = -a[i__2].i;
26004
ajj.r = z__1.r, ajj.i = z__1.i;
26005
} else {
26006
z__1.r = -1., z__1.i = -0.;
26007
ajj.r = z__1.r, ajj.i = z__1.i;
26008
}
26009
26010
/* Compute elements 1:j-1 of j-th column. */
26011
26012
i__2 = j - 1;
26013
ztrmv_("Upper", "No transpose", diag, &i__2, &a[a_offset], lda, &
26014
a[j * a_dim1 + 1], &c__1);
26015
i__2 = j - 1;
26016
zscal_(&i__2, &ajj, &a[j * a_dim1 + 1], &c__1);
26017
/* L10: */
26018
}
26019
} else {
26020
26021
/* Compute inverse of lower triangular matrix. */
26022
26023
for (j = *n; j >= 1; --j) {
26024
if (nounit) {
26025
i__1 = j + j * a_dim1;
26026
z_div(&z__1, &c_b57, &a[j + j * a_dim1]);
26027
a[i__1].r = z__1.r, a[i__1].i = z__1.i;
26028
i__1 = j + j * a_dim1;
26029
z__1.r = -a[i__1].r, z__1.i = -a[i__1].i;
26030
ajj.r = z__1.r, ajj.i = z__1.i;
26031
} else {
26032
z__1.r = -1., z__1.i = -0.;
26033
ajj.r = z__1.r, ajj.i = z__1.i;
26034
}
26035
if (j < *n) {
26036
26037
/* Compute elements j+1:n of j-th column. */
26038
26039
i__1 = *n - j;
26040
ztrmv_("Lower", "No transpose", diag, &i__1, &a[j + 1 + (j +
26041
1) * a_dim1], lda, &a[j + 1 + j * a_dim1], &c__1);
26042
i__1 = *n - j;
26043
zscal_(&i__1, &ajj, &a[j + 1 + j * a_dim1], &c__1);
26044
}
26045
/* L20: */
26046
}
26047
}
26048
26049
return 0;
26050
26051
/* End of ZTRTI2 */
26052
26053
} /* ztrti2_ */
26054
26055
/* Subroutine */ int ztrtri_(char *uplo, char *diag, integer *n,
26056
doublecomplex *a, integer *lda, integer *info)
26057
{
26058
/* System generated locals */
26059
address a__1[2];
26060
integer a_dim1, a_offset, i__1, i__2, i__3[2], i__4, i__5;
26061
doublecomplex z__1;
26062
char ch__1[2];
26063
26064
/* Local variables */
26065
static integer j, jb, nb, nn;
26066
extern logical lsame_(char *, char *);
26067
static logical upper;
26068
extern /* Subroutine */ int ztrmm_(char *, char *, char *, char *,
26069
integer *, integer *, doublecomplex *, doublecomplex *, integer *,
26070
doublecomplex *, integer *),
26071
ztrsm_(char *, char *, char *, char *, integer *, integer *,
26072
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
26073
integer *), ztrti2_(char *, char *
26074
, integer *, doublecomplex *, integer *, integer *), xerbla_(char *, integer *);
26075
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
26076
integer *, integer *, ftnlen, ftnlen);
26077
static logical nounit;
26078
26079
26080
/*
26081
-- LAPACK routine (version 3.2) --
26082
-- LAPACK is a software package provided by Univ. of Tennessee, --
26083
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
26084
November 2006
26085
26086
26087
Purpose
26088
=======
26089
26090
ZTRTRI computes the inverse of a complex upper or lower triangular
26091
matrix A.
26092
26093
This is the Level 3 BLAS version of the algorithm.
26094
26095
Arguments
26096
=========
26097
26098
UPLO (input) CHARACTER*1
26099
= 'U': A is upper triangular;
26100
= 'L': A is lower triangular.
26101
26102
DIAG (input) CHARACTER*1
26103
= 'N': A is non-unit triangular;
26104
= 'U': A is unit triangular.
26105
26106
N (input) INTEGER
26107
The order of the matrix A. N >= 0.
26108
26109
A (input/output) COMPLEX*16 array, dimension (LDA,N)
26110
On entry, the triangular matrix A. If UPLO = 'U', the
26111
leading N-by-N upper triangular part of the array A contains
26112
the upper triangular matrix, and the strictly lower
26113
triangular part of A is not referenced. If UPLO = 'L', the
26114
leading N-by-N lower triangular part of the array A contains
26115
the lower triangular matrix, and the strictly upper
26116
triangular part of A is not referenced. If DIAG = 'U', the
26117
diagonal elements of A are also not referenced and are
26118
assumed to be 1.
26119
On exit, the (triangular) inverse of the original matrix, in
26120
the same storage format.
26121
26122
LDA (input) INTEGER
26123
The leading dimension of the array A. LDA >= max(1,N).
26124
26125
INFO (output) INTEGER
26126
= 0: successful exit
26127
< 0: if INFO = -i, the i-th argument had an illegal value
26128
> 0: if INFO = i, A(i,i) is exactly zero. The triangular
26129
matrix is singular and its inverse can not be computed.
26130
26131
=====================================================================
26132
26133
26134
Test the input parameters.
26135
*/
26136
26137
/* Parameter adjustments */
26138
a_dim1 = *lda;
26139
a_offset = 1 + a_dim1;
26140
a -= a_offset;
26141
26142
/* Function Body */
26143
*info = 0;
26144
upper = lsame_(uplo, "U");
26145
nounit = lsame_(diag, "N");
26146
if (! upper && ! lsame_(uplo, "L")) {
26147
*info = -1;
26148
} else if (! nounit && ! lsame_(diag, "U")) {
26149
*info = -2;
26150
} else if (*n < 0) {
26151
*info = -3;
26152
} else if (*lda < max(1,*n)) {
26153
*info = -5;
26154
}
26155
if (*info != 0) {
26156
i__1 = -(*info);
26157
xerbla_("ZTRTRI", &i__1);
26158
return 0;
26159
}
26160
26161
/* Quick return if possible */
26162
26163
if (*n == 0) {
26164
return 0;
26165
}
26166
26167
/* Check for singularity if non-unit. */
26168
26169
if (nounit) {
26170
i__1 = *n;
26171
for (*info = 1; *info <= i__1; ++(*info)) {
26172
i__2 = *info + *info * a_dim1;
26173
if (a[i__2].r == 0. && a[i__2].i == 0.) {
26174
return 0;
26175
}
26176
/* L10: */
26177
}
26178
*info = 0;
26179
}
26180
26181
/*
26182
Determine the block size for this environment.
26183
26184
Writing concatenation
26185
*/
26186
i__3[0] = 1, a__1[0] = uplo;
26187
i__3[1] = 1, a__1[1] = diag;
26188
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
26189
nb = ilaenv_(&c__1, "ZTRTRI", ch__1, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (
26190
ftnlen)2);
26191
if (nb <= 1 || nb >= *n) {
26192
26193
/* Use unblocked code */
26194
26195
ztrti2_(uplo, diag, n, &a[a_offset], lda, info);
26196
} else {
26197
26198
/* Use blocked code */
26199
26200
if (upper) {
26201
26202
/* Compute inverse of upper triangular matrix */
26203
26204
i__1 = *n;
26205
i__2 = nb;
26206
for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
26207
/* Computing MIN */
26208
i__4 = nb, i__5 = *n - j + 1;
26209
jb = min(i__4,i__5);
26210
26211
/* Compute rows 1:j-1 of current block column */
26212
26213
i__4 = j - 1;
26214
ztrmm_("Left", "Upper", "No transpose", diag, &i__4, &jb, &
26215
c_b57, &a[a_offset], lda, &a[j * a_dim1 + 1], lda);
26216
i__4 = j - 1;
26217
z__1.r = -1., z__1.i = -0.;
26218
ztrsm_("Right", "Upper", "No transpose", diag, &i__4, &jb, &
26219
z__1, &a[j + j * a_dim1], lda, &a[j * a_dim1 + 1],
26220
lda);
26221
26222
/* Compute inverse of current diagonal block */
26223
26224
ztrti2_("Upper", diag, &jb, &a[j + j * a_dim1], lda, info);
26225
/* L20: */
26226
}
26227
} else {
26228
26229
/* Compute inverse of lower triangular matrix */
26230
26231
nn = (*n - 1) / nb * nb + 1;
26232
i__2 = -nb;
26233
for (j = nn; i__2 < 0 ? j >= 1 : j <= 1; j += i__2) {
26234
/* Computing MIN */
26235
i__1 = nb, i__4 = *n - j + 1;
26236
jb = min(i__1,i__4);
26237
if (j + jb <= *n) {
26238
26239
/* Compute rows j+jb:n of current block column */
26240
26241
i__1 = *n - j - jb + 1;
26242
ztrmm_("Left", "Lower", "No transpose", diag, &i__1, &jb,
26243
&c_b57, &a[j + jb + (j + jb) * a_dim1], lda, &a[j
26244
+ jb + j * a_dim1], lda);
26245
i__1 = *n - j - jb + 1;
26246
z__1.r = -1., z__1.i = -0.;
26247
ztrsm_("Right", "Lower", "No transpose", diag, &i__1, &jb,
26248
&z__1, &a[j + j * a_dim1], lda, &a[j + jb + j *
26249
a_dim1], lda);
26250
}
26251
26252
/* Compute inverse of current diagonal block */
26253
26254
ztrti2_("Lower", diag, &jb, &a[j + j * a_dim1], lda, info);
26255
/* L30: */
26256
}
26257
}
26258
}
26259
26260
return 0;
26261
26262
/* End of ZTRTRI */
26263
26264
} /* ztrtri_ */
26265
26266
/* Subroutine */ int zung2r_(integer *m, integer *n, integer *k,
26267
doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
26268
work, integer *info)
26269
{
26270
/* System generated locals */
26271
integer a_dim1, a_offset, i__1, i__2, i__3;
26272
doublecomplex z__1;
26273
26274
/* Local variables */
26275
static integer i__, j, l;
26276
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
26277
doublecomplex *, integer *), zlarf_(char *, integer *, integer *,
26278
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
26279
integer *, doublecomplex *), xerbla_(char *, integer *);
26280
26281
26282
/*
26283
-- LAPACK routine (version 3.2) --
26284
-- LAPACK is a software package provided by Univ. of Tennessee, --
26285
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
26286
November 2006
26287
26288
26289
Purpose
26290
=======
26291
26292
ZUNG2R generates an m by n complex matrix Q with orthonormal columns,
26293
which is defined as the first n columns of a product of k elementary
26294
reflectors of order m
26295
26296
Q = H(1) H(2) . . . H(k)
26297
26298
as returned by ZGEQRF.
26299
26300
Arguments
26301
=========
26302
26303
M (input) INTEGER
26304
The number of rows of the matrix Q. M >= 0.
26305
26306
N (input) INTEGER
26307
The number of columns of the matrix Q. M >= N >= 0.
26308
26309
K (input) INTEGER
26310
The number of elementary reflectors whose product defines the
26311
matrix Q. N >= K >= 0.
26312
26313
A (input/output) COMPLEX*16 array, dimension (LDA,N)
26314
On entry, the i-th column must contain the vector which
26315
defines the elementary reflector H(i), for i = 1,2,...,k, as
26316
returned by ZGEQRF in the first k columns of its array
26317
argument A.
26318
On exit, the m by n matrix Q.
26319
26320
LDA (input) INTEGER
26321
The first dimension of the array A. LDA >= max(1,M).
26322
26323
TAU (input) COMPLEX*16 array, dimension (K)
26324
TAU(i) must contain the scalar factor of the elementary
26325
reflector H(i), as returned by ZGEQRF.
26326
26327
WORK (workspace) COMPLEX*16 array, dimension (N)
26328
26329
INFO (output) INTEGER
26330
= 0: successful exit
26331
< 0: if INFO = -i, the i-th argument has an illegal value
26332
26333
=====================================================================
26334
26335
26336
Test the input arguments
26337
*/
26338
26339
/* Parameter adjustments */
26340
a_dim1 = *lda;
26341
a_offset = 1 + a_dim1;
26342
a -= a_offset;
26343
--tau;
26344
--work;
26345
26346
/* Function Body */
26347
*info = 0;
26348
if (*m < 0) {
26349
*info = -1;
26350
} else if (*n < 0 || *n > *m) {
26351
*info = -2;
26352
} else if (*k < 0 || *k > *n) {
26353
*info = -3;
26354
} else if (*lda < max(1,*m)) {
26355
*info = -5;
26356
}
26357
if (*info != 0) {
26358
i__1 = -(*info);
26359
xerbla_("ZUNG2R", &i__1);
26360
return 0;
26361
}
26362
26363
/* Quick return if possible */
26364
26365
if (*n <= 0) {
26366
return 0;
26367
}
26368
26369
/* Initialise columns k+1:n to columns of the unit matrix */
26370
26371
i__1 = *n;
26372
for (j = *k + 1; j <= i__1; ++j) {
26373
i__2 = *m;
26374
for (l = 1; l <= i__2; ++l) {
26375
i__3 = l + j * a_dim1;
26376
a[i__3].r = 0., a[i__3].i = 0.;
26377
/* L10: */
26378
}
26379
i__2 = j + j * a_dim1;
26380
a[i__2].r = 1., a[i__2].i = 0.;
26381
/* L20: */
26382
}
26383
26384
for (i__ = *k; i__ >= 1; --i__) {
26385
26386
/* Apply H(i) to A(i:m,i:n) from the left */
26387
26388
if (i__ < *n) {
26389
i__1 = i__ + i__ * a_dim1;
26390
a[i__1].r = 1., a[i__1].i = 0.;
26391
i__1 = *m - i__ + 1;
26392
i__2 = *n - i__;
26393
zlarf_("Left", &i__1, &i__2, &a[i__ + i__ * a_dim1], &c__1, &tau[
26394
i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]);
26395
}
26396
if (i__ < *m) {
26397
i__1 = *m - i__;
26398
i__2 = i__;
26399
z__1.r = -tau[i__2].r, z__1.i = -tau[i__2].i;
26400
zscal_(&i__1, &z__1, &a[i__ + 1 + i__ * a_dim1], &c__1);
26401
}
26402
i__1 = i__ + i__ * a_dim1;
26403
i__2 = i__;
26404
z__1.r = 1. - tau[i__2].r, z__1.i = 0. - tau[i__2].i;
26405
a[i__1].r = z__1.r, a[i__1].i = z__1.i;
26406
26407
/* Set A(1:i-1,i) to zero */
26408
26409
i__1 = i__ - 1;
26410
for (l = 1; l <= i__1; ++l) {
26411
i__2 = l + i__ * a_dim1;
26412
a[i__2].r = 0., a[i__2].i = 0.;
26413
/* L30: */
26414
}
26415
/* L40: */
26416
}
26417
return 0;
26418
26419
/* End of ZUNG2R */
26420
26421
} /* zung2r_ */
26422
26423
/* Subroutine */ int zungbr_(char *vect, integer *m, integer *n, integer *k,
26424
doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
26425
work, integer *lwork, integer *info)
26426
{
26427
/* System generated locals */
26428
integer a_dim1, a_offset, i__1, i__2, i__3;
26429
26430
/* Local variables */
26431
static integer i__, j, nb, mn;
26432
extern logical lsame_(char *, char *);
26433
static integer iinfo;
26434
static logical wantq;
26435
extern /* Subroutine */ int xerbla_(char *, integer *);
26436
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
26437
integer *, integer *, ftnlen, ftnlen);
26438
static integer lwkopt;
26439
static logical lquery;
26440
extern /* Subroutine */ int zunglq_(integer *, integer *, integer *,
26441
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
26442
integer *, integer *), zungqr_(integer *, integer *, integer *,
26443
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
26444
integer *, integer *);
26445
26446
26447
/*
26448
-- LAPACK routine (version 3.2) --
26449
-- LAPACK is a software package provided by Univ. of Tennessee, --
26450
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
26451
November 2006
26452
26453
26454
Purpose
26455
=======
26456
26457
ZUNGBR generates one of the complex unitary matrices Q or P**H
26458
determined by ZGEBRD when reducing a complex matrix A to bidiagonal
26459
form: A = Q * B * P**H. Q and P**H are defined as products of
26460
elementary reflectors H(i) or G(i) respectively.
26461
26462
If VECT = 'Q', A is assumed to have been an M-by-K matrix, and Q
26463
is of order M:
26464
if m >= k, Q = H(1) H(2) . . . H(k) and ZUNGBR returns the first n
26465
columns of Q, where m >= n >= k;
26466
if m < k, Q = H(1) H(2) . . . H(m-1) and ZUNGBR returns Q as an
26467
M-by-M matrix.
26468
26469
If VECT = 'P', A is assumed to have been a K-by-N matrix, and P**H
26470
is of order N:
26471
if k < n, P**H = G(k) . . . G(2) G(1) and ZUNGBR returns the first m
26472
rows of P**H, where n >= m >= k;
26473
if k >= n, P**H = G(n-1) . . . G(2) G(1) and ZUNGBR returns P**H as
26474
an N-by-N matrix.
26475
26476
Arguments
26477
=========
26478
26479
VECT (input) CHARACTER*1
26480
Specifies whether the matrix Q or the matrix P**H is
26481
required, as defined in the transformation applied by ZGEBRD:
26482
= 'Q': generate Q;
26483
= 'P': generate P**H.
26484
26485
M (input) INTEGER
26486
The number of rows of the matrix Q or P**H to be returned.
26487
M >= 0.
26488
26489
N (input) INTEGER
26490
The number of columns of the matrix Q or P**H to be returned.
26491
N >= 0.
26492
If VECT = 'Q', M >= N >= min(M,K);
26493
if VECT = 'P', N >= M >= min(N,K).
26494
26495
K (input) INTEGER
26496
If VECT = 'Q', the number of columns in the original M-by-K
26497
matrix reduced by ZGEBRD.
26498
If VECT = 'P', the number of rows in the original K-by-N
26499
matrix reduced by ZGEBRD.
26500
K >= 0.
26501
26502
A (input/output) COMPLEX*16 array, dimension (LDA,N)
26503
On entry, the vectors which define the elementary reflectors,
26504
as returned by ZGEBRD.
26505
On exit, the M-by-N matrix Q or P**H.
26506
26507
LDA (input) INTEGER
26508
The leading dimension of the array A. LDA >= M.
26509
26510
TAU (input) COMPLEX*16 array, dimension
26511
(min(M,K)) if VECT = 'Q'
26512
(min(N,K)) if VECT = 'P'
26513
TAU(i) must contain the scalar factor of the elementary
26514
reflector H(i) or G(i), which determines Q or P**H, as
26515
returned by ZGEBRD in its array argument TAUQ or TAUP.
26516
26517
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
26518
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
26519
26520
LWORK (input) INTEGER
26521
The dimension of the array WORK. LWORK >= max(1,min(M,N)).
26522
For optimum performance LWORK >= min(M,N)*NB, where NB
26523
is the optimal blocksize.
26524
26525
If LWORK = -1, then a workspace query is assumed; the routine
26526
only calculates the optimal size of the WORK array, returns
26527
this value as the first entry of the WORK array, and no error
26528
message related to LWORK is issued by XERBLA.
26529
26530
INFO (output) INTEGER
26531
= 0: successful exit
26532
< 0: if INFO = -i, the i-th argument had an illegal value
26533
26534
=====================================================================
26535
26536
26537
Test the input arguments
26538
*/
26539
26540
/* Parameter adjustments */
26541
a_dim1 = *lda;
26542
a_offset = 1 + a_dim1;
26543
a -= a_offset;
26544
--tau;
26545
--work;
26546
26547
/* Function Body */
26548
*info = 0;
26549
wantq = lsame_(vect, "Q");
26550
mn = min(*m,*n);
26551
lquery = *lwork == -1;
26552
if (! wantq && ! lsame_(vect, "P")) {
26553
*info = -1;
26554
} else if (*m < 0) {
26555
*info = -2;
26556
} else if (*n < 0 || wantq && (*n > *m || *n < min(*m,*k)) || ! wantq && (
26557
*m > *n || *m < min(*n,*k))) {
26558
*info = -3;
26559
} else if (*k < 0) {
26560
*info = -4;
26561
} else if (*lda < max(1,*m)) {
26562
*info = -6;
26563
} else if (*lwork < max(1,mn) && ! lquery) {
26564
*info = -9;
26565
}
26566
26567
if (*info == 0) {
26568
if (wantq) {
26569
nb = ilaenv_(&c__1, "ZUNGQR", " ", m, n, k, &c_n1, (ftnlen)6, (
26570
ftnlen)1);
26571
} else {
26572
nb = ilaenv_(&c__1, "ZUNGLQ", " ", m, n, k, &c_n1, (ftnlen)6, (
26573
ftnlen)1);
26574
}
26575
lwkopt = max(1,mn) * nb;
26576
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
26577
}
26578
26579
if (*info != 0) {
26580
i__1 = -(*info);
26581
xerbla_("ZUNGBR", &i__1);
26582
return 0;
26583
} else if (lquery) {
26584
return 0;
26585
}
26586
26587
/* Quick return if possible */
26588
26589
if (*m == 0 || *n == 0) {
26590
work[1].r = 1., work[1].i = 0.;
26591
return 0;
26592
}
26593
26594
if (wantq) {
26595
26596
/*
26597
Form Q, determined by a call to ZGEBRD to reduce an m-by-k
26598
matrix
26599
*/
26600
26601
if (*m >= *k) {
26602
26603
/* If m >= k, assume m >= n >= k */
26604
26605
zungqr_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, &
26606
iinfo);
26607
26608
} else {
26609
26610
/*
26611
If m < k, assume m = n
26612
26613
Shift the vectors which define the elementary reflectors one
26614
column to the right, and set the first row and column of Q
26615
to those of the unit matrix
26616
*/
26617
26618
for (j = *m; j >= 2; --j) {
26619
i__1 = j * a_dim1 + 1;
26620
a[i__1].r = 0., a[i__1].i = 0.;
26621
i__1 = *m;
26622
for (i__ = j + 1; i__ <= i__1; ++i__) {
26623
i__2 = i__ + j * a_dim1;
26624
i__3 = i__ + (j - 1) * a_dim1;
26625
a[i__2].r = a[i__3].r, a[i__2].i = a[i__3].i;
26626
/* L10: */
26627
}
26628
/* L20: */
26629
}
26630
i__1 = a_dim1 + 1;
26631
a[i__1].r = 1., a[i__1].i = 0.;
26632
i__1 = *m;
26633
for (i__ = 2; i__ <= i__1; ++i__) {
26634
i__2 = i__ + a_dim1;
26635
a[i__2].r = 0., a[i__2].i = 0.;
26636
/* L30: */
26637
}
26638
if (*m > 1) {
26639
26640
/* Form Q(2:m,2:m) */
26641
26642
i__1 = *m - 1;
26643
i__2 = *m - 1;
26644
i__3 = *m - 1;
26645
zungqr_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[
26646
1], &work[1], lwork, &iinfo);
26647
}
26648
}
26649
} else {
26650
26651
/*
26652
Form P', determined by a call to ZGEBRD to reduce a k-by-n
26653
matrix
26654
*/
26655
26656
if (*k < *n) {
26657
26658
/* If k < n, assume k <= m <= n */
26659
26660
zunglq_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, &
26661
iinfo);
26662
26663
} else {
26664
26665
/*
26666
If k >= n, assume m = n
26667
26668
Shift the vectors which define the elementary reflectors one
26669
row downward, and set the first row and column of P' to
26670
those of the unit matrix
26671
*/
26672
26673
i__1 = a_dim1 + 1;
26674
a[i__1].r = 1., a[i__1].i = 0.;
26675
i__1 = *n;
26676
for (i__ = 2; i__ <= i__1; ++i__) {
26677
i__2 = i__ + a_dim1;
26678
a[i__2].r = 0., a[i__2].i = 0.;
26679
/* L40: */
26680
}
26681
i__1 = *n;
26682
for (j = 2; j <= i__1; ++j) {
26683
for (i__ = j - 1; i__ >= 2; --i__) {
26684
i__2 = i__ + j * a_dim1;
26685
i__3 = i__ - 1 + j * a_dim1;
26686
a[i__2].r = a[i__3].r, a[i__2].i = a[i__3].i;
26687
/* L50: */
26688
}
26689
i__2 = j * a_dim1 + 1;
26690
a[i__2].r = 0., a[i__2].i = 0.;
26691
/* L60: */
26692
}
26693
if (*n > 1) {
26694
26695
/* Form P'(2:n,2:n) */
26696
26697
i__1 = *n - 1;
26698
i__2 = *n - 1;
26699
i__3 = *n - 1;
26700
zunglq_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[
26701
1], &work[1], lwork, &iinfo);
26702
}
26703
}
26704
}
26705
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
26706
return 0;
26707
26708
/* End of ZUNGBR */
26709
26710
} /* zungbr_ */
26711
26712
/* Subroutine */ int zunghr_(integer *n, integer *ilo, integer *ihi,
26713
doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
26714
work, integer *lwork, integer *info)
26715
{
26716
/* System generated locals */
26717
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
26718
26719
/* Local variables */
26720
static integer i__, j, nb, nh, iinfo;
26721
extern /* Subroutine */ int xerbla_(char *, integer *);
26722
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
26723
integer *, integer *, ftnlen, ftnlen);
26724
static integer lwkopt;
26725
static logical lquery;
26726
extern /* Subroutine */ int zungqr_(integer *, integer *, integer *,
26727
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
26728
integer *, integer *);
26729
26730
26731
/*
26732
-- LAPACK routine (version 3.2) --
26733
-- LAPACK is a software package provided by Univ. of Tennessee, --
26734
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
26735
November 2006
26736
26737
26738
Purpose
26739
=======
26740
26741
ZUNGHR generates a complex unitary matrix Q which is defined as the
26742
product of IHI-ILO elementary reflectors of order N, as returned by
26743
ZGEHRD:
26744
26745
Q = H(ilo) H(ilo+1) . . . H(ihi-1).
26746
26747
Arguments
26748
=========
26749
26750
N (input) INTEGER
26751
The order of the matrix Q. N >= 0.
26752
26753
ILO (input) INTEGER
26754
IHI (input) INTEGER
26755
ILO and IHI must have the same values as in the previous call
26756
of ZGEHRD. Q is equal to the unit matrix except in the
26757
submatrix Q(ilo+1:ihi,ilo+1:ihi).
26758
1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0.
26759
26760
A (input/output) COMPLEX*16 array, dimension (LDA,N)
26761
On entry, the vectors which define the elementary reflectors,
26762
as returned by ZGEHRD.
26763
On exit, the N-by-N unitary matrix Q.
26764
26765
LDA (input) INTEGER
26766
The leading dimension of the array A. LDA >= max(1,N).
26767
26768
TAU (input) COMPLEX*16 array, dimension (N-1)
26769
TAU(i) must contain the scalar factor of the elementary
26770
reflector H(i), as returned by ZGEHRD.
26771
26772
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
26773
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
26774
26775
LWORK (input) INTEGER
26776
The dimension of the array WORK. LWORK >= IHI-ILO.
26777
For optimum performance LWORK >= (IHI-ILO)*NB, where NB is
26778
the optimal blocksize.
26779
26780
If LWORK = -1, then a workspace query is assumed; the routine
26781
only calculates the optimal size of the WORK array, returns
26782
this value as the first entry of the WORK array, and no error
26783
message related to LWORK is issued by XERBLA.
26784
26785
INFO (output) INTEGER
26786
= 0: successful exit
26787
< 0: if INFO = -i, the i-th argument had an illegal value
26788
26789
=====================================================================
26790
26791
26792
Test the input arguments
26793
*/
26794
26795
/* Parameter adjustments */
26796
a_dim1 = *lda;
26797
a_offset = 1 + a_dim1;
26798
a -= a_offset;
26799
--tau;
26800
--work;
26801
26802
/* Function Body */
26803
*info = 0;
26804
nh = *ihi - *ilo;
26805
lquery = *lwork == -1;
26806
if (*n < 0) {
26807
*info = -1;
26808
} else if (*ilo < 1 || *ilo > max(1,*n)) {
26809
*info = -2;
26810
} else if (*ihi < min(*ilo,*n) || *ihi > *n) {
26811
*info = -3;
26812
} else if (*lda < max(1,*n)) {
26813
*info = -5;
26814
} else if (*lwork < max(1,nh) && ! lquery) {
26815
*info = -8;
26816
}
26817
26818
if (*info == 0) {
26819
nb = ilaenv_(&c__1, "ZUNGQR", " ", &nh, &nh, &nh, &c_n1, (ftnlen)6, (
26820
ftnlen)1);
26821
lwkopt = max(1,nh) * nb;
26822
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
26823
}
26824
26825
if (*info != 0) {
26826
i__1 = -(*info);
26827
xerbla_("ZUNGHR", &i__1);
26828
return 0;
26829
} else if (lquery) {
26830
return 0;
26831
}
26832
26833
/* Quick return if possible */
26834
26835
if (*n == 0) {
26836
work[1].r = 1., work[1].i = 0.;
26837
return 0;
26838
}
26839
26840
/*
26841
Shift the vectors which define the elementary reflectors one
26842
column to the right, and set the first ilo and the last n-ihi
26843
rows and columns to those of the unit matrix
26844
*/
26845
26846
i__1 = *ilo + 1;
26847
for (j = *ihi; j >= i__1; --j) {
26848
i__2 = j - 1;
26849
for (i__ = 1; i__ <= i__2; ++i__) {
26850
i__3 = i__ + j * a_dim1;
26851
a[i__3].r = 0., a[i__3].i = 0.;
26852
/* L10: */
26853
}
26854
i__2 = *ihi;
26855
for (i__ = j + 1; i__ <= i__2; ++i__) {
26856
i__3 = i__ + j * a_dim1;
26857
i__4 = i__ + (j - 1) * a_dim1;
26858
a[i__3].r = a[i__4].r, a[i__3].i = a[i__4].i;
26859
/* L20: */
26860
}
26861
i__2 = *n;
26862
for (i__ = *ihi + 1; i__ <= i__2; ++i__) {
26863
i__3 = i__ + j * a_dim1;
26864
a[i__3].r = 0., a[i__3].i = 0.;
26865
/* L30: */
26866
}
26867
/* L40: */
26868
}
26869
i__1 = *ilo;
26870
for (j = 1; j <= i__1; ++j) {
26871
i__2 = *n;
26872
for (i__ = 1; i__ <= i__2; ++i__) {
26873
i__3 = i__ + j * a_dim1;
26874
a[i__3].r = 0., a[i__3].i = 0.;
26875
/* L50: */
26876
}
26877
i__2 = j + j * a_dim1;
26878
a[i__2].r = 1., a[i__2].i = 0.;
26879
/* L60: */
26880
}
26881
i__1 = *n;
26882
for (j = *ihi + 1; j <= i__1; ++j) {
26883
i__2 = *n;
26884
for (i__ = 1; i__ <= i__2; ++i__) {
26885
i__3 = i__ + j * a_dim1;
26886
a[i__3].r = 0., a[i__3].i = 0.;
26887
/* L70: */
26888
}
26889
i__2 = j + j * a_dim1;
26890
a[i__2].r = 1., a[i__2].i = 0.;
26891
/* L80: */
26892
}
26893
26894
if (nh > 0) {
26895
26896
/* Generate Q(ilo+1:ihi,ilo+1:ihi) */
26897
26898
zungqr_(&nh, &nh, &nh, &a[*ilo + 1 + (*ilo + 1) * a_dim1], lda, &tau[*
26899
ilo], &work[1], lwork, &iinfo);
26900
}
26901
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
26902
return 0;
26903
26904
/* End of ZUNGHR */
26905
26906
} /* zunghr_ */
26907
26908
/* Subroutine */ int zungl2_(integer *m, integer *n, integer *k,
26909
doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
26910
work, integer *info)
26911
{
26912
/* System generated locals */
26913
integer a_dim1, a_offset, i__1, i__2, i__3;
26914
doublecomplex z__1, z__2;
26915
26916
/* Local variables */
26917
static integer i__, j, l;
26918
extern /* Subroutine */ int zscal_(integer *, doublecomplex *,
26919
doublecomplex *, integer *), zlarf_(char *, integer *, integer *,
26920
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
26921
integer *, doublecomplex *), xerbla_(char *, integer *), zlacgv_(integer *, doublecomplex *, integer *);
26922
26923
26924
/*
26925
-- LAPACK routine (version 3.2) --
26926
-- LAPACK is a software package provided by Univ. of Tennessee, --
26927
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
26928
November 2006
26929
26930
26931
Purpose
26932
=======
26933
26934
ZUNGL2 generates an m-by-n complex matrix Q with orthonormal rows,
26935
which is defined as the first m rows of a product of k elementary
26936
reflectors of order n
26937
26938
Q = H(k)' . . . H(2)' H(1)'
26939
26940
as returned by ZGELQF.
26941
26942
Arguments
26943
=========
26944
26945
M (input) INTEGER
26946
The number of rows of the matrix Q. M >= 0.
26947
26948
N (input) INTEGER
26949
The number of columns of the matrix Q. N >= M.
26950
26951
K (input) INTEGER
26952
The number of elementary reflectors whose product defines the
26953
matrix Q. M >= K >= 0.
26954
26955
A (input/output) COMPLEX*16 array, dimension (LDA,N)
26956
On entry, the i-th row must contain the vector which defines
26957
the elementary reflector H(i), for i = 1,2,...,k, as returned
26958
by ZGELQF in the first k rows of its array argument A.
26959
On exit, the m by n matrix Q.
26960
26961
LDA (input) INTEGER
26962
The first dimension of the array A. LDA >= max(1,M).
26963
26964
TAU (input) COMPLEX*16 array, dimension (K)
26965
TAU(i) must contain the scalar factor of the elementary
26966
reflector H(i), as returned by ZGELQF.
26967
26968
WORK (workspace) COMPLEX*16 array, dimension (M)
26969
26970
INFO (output) INTEGER
26971
= 0: successful exit
26972
< 0: if INFO = -i, the i-th argument has an illegal value
26973
26974
=====================================================================
26975
26976
26977
Test the input arguments
26978
*/
26979
26980
/* Parameter adjustments */
26981
a_dim1 = *lda;
26982
a_offset = 1 + a_dim1;
26983
a -= a_offset;
26984
--tau;
26985
--work;
26986
26987
/* Function Body */
26988
*info = 0;
26989
if (*m < 0) {
26990
*info = -1;
26991
} else if (*n < *m) {
26992
*info = -2;
26993
} else if (*k < 0 || *k > *m) {
26994
*info = -3;
26995
} else if (*lda < max(1,*m)) {
26996
*info = -5;
26997
}
26998
if (*info != 0) {
26999
i__1 = -(*info);
27000
xerbla_("ZUNGL2", &i__1);
27001
return 0;
27002
}
27003
27004
/* Quick return if possible */
27005
27006
if (*m <= 0) {
27007
return 0;
27008
}
27009
27010
if (*k < *m) {
27011
27012
/* Initialise rows k+1:m to rows of the unit matrix */
27013
27014
i__1 = *n;
27015
for (j = 1; j <= i__1; ++j) {
27016
i__2 = *m;
27017
for (l = *k + 1; l <= i__2; ++l) {
27018
i__3 = l + j * a_dim1;
27019
a[i__3].r = 0., a[i__3].i = 0.;
27020
/* L10: */
27021
}
27022
if (j > *k && j <= *m) {
27023
i__2 = j + j * a_dim1;
27024
a[i__2].r = 1., a[i__2].i = 0.;
27025
}
27026
/* L20: */
27027
}
27028
}
27029
27030
for (i__ = *k; i__ >= 1; --i__) {
27031
27032
/* Apply H(i)' to A(i:m,i:n) from the right */
27033
27034
if (i__ < *n) {
27035
i__1 = *n - i__;
27036
zlacgv_(&i__1, &a[i__ + (i__ + 1) * a_dim1], lda);
27037
if (i__ < *m) {
27038
i__1 = i__ + i__ * a_dim1;
27039
a[i__1].r = 1., a[i__1].i = 0.;
27040
i__1 = *m - i__;
27041
i__2 = *n - i__ + 1;
27042
d_cnjg(&z__1, &tau[i__]);
27043
zlarf_("Right", &i__1, &i__2, &a[i__ + i__ * a_dim1], lda, &
27044
z__1, &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
27045
}
27046
i__1 = *n - i__;
27047
i__2 = i__;
27048
z__1.r = -tau[i__2].r, z__1.i = -tau[i__2].i;
27049
zscal_(&i__1, &z__1, &a[i__ + (i__ + 1) * a_dim1], lda);
27050
i__1 = *n - i__;
27051
zlacgv_(&i__1, &a[i__ + (i__ + 1) * a_dim1], lda);
27052
}
27053
i__1 = i__ + i__ * a_dim1;
27054
d_cnjg(&z__2, &tau[i__]);
27055
z__1.r = 1. - z__2.r, z__1.i = 0. - z__2.i;
27056
a[i__1].r = z__1.r, a[i__1].i = z__1.i;
27057
27058
/* Set A(i,1:i-1) to zero */
27059
27060
i__1 = i__ - 1;
27061
for (l = 1; l <= i__1; ++l) {
27062
i__2 = i__ + l * a_dim1;
27063
a[i__2].r = 0., a[i__2].i = 0.;
27064
/* L30: */
27065
}
27066
/* L40: */
27067
}
27068
return 0;
27069
27070
/* End of ZUNGL2 */
27071
27072
} /* zungl2_ */
27073
27074
/* Subroutine */ int zunglq_(integer *m, integer *n, integer *k,
27075
doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
27076
work, integer *lwork, integer *info)
27077
{
27078
/* System generated locals */
27079
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
27080
27081
/* Local variables */
27082
static integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
27083
extern /* Subroutine */ int zungl2_(integer *, integer *, integer *,
27084
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
27085
integer *), xerbla_(char *, integer *);
27086
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
27087
integer *, integer *, ftnlen, ftnlen);
27088
extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *,
27089
integer *, integer *, integer *, doublecomplex *, integer *,
27090
doublecomplex *, integer *, doublecomplex *, integer *,
27091
doublecomplex *, integer *);
27092
static integer ldwork;
27093
extern /* Subroutine */ int zlarft_(char *, char *, integer *, integer *,
27094
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
27095
integer *);
27096
static logical lquery;
27097
static integer lwkopt;
27098
27099
27100
/*
27101
-- LAPACK routine (version 3.2) --
27102
-- LAPACK is a software package provided by Univ. of Tennessee, --
27103
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
27104
November 2006
27105
27106
27107
Purpose
27108
=======
27109
27110
ZUNGLQ generates an M-by-N complex matrix Q with orthonormal rows,
27111
which is defined as the first M rows of a product of K elementary
27112
reflectors of order N
27113
27114
Q = H(k)' . . . H(2)' H(1)'
27115
27116
as returned by ZGELQF.
27117
27118
Arguments
27119
=========
27120
27121
M (input) INTEGER
27122
The number of rows of the matrix Q. M >= 0.
27123
27124
N (input) INTEGER
27125
The number of columns of the matrix Q. N >= M.
27126
27127
K (input) INTEGER
27128
The number of elementary reflectors whose product defines the
27129
matrix Q. M >= K >= 0.
27130
27131
A (input/output) COMPLEX*16 array, dimension (LDA,N)
27132
On entry, the i-th row must contain the vector which defines
27133
the elementary reflector H(i), for i = 1,2,...,k, as returned
27134
by ZGELQF in the first k rows of its array argument A.
27135
On exit, the M-by-N matrix Q.
27136
27137
LDA (input) INTEGER
27138
The first dimension of the array A. LDA >= max(1,M).
27139
27140
TAU (input) COMPLEX*16 array, dimension (K)
27141
TAU(i) must contain the scalar factor of the elementary
27142
reflector H(i), as returned by ZGELQF.
27143
27144
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
27145
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
27146
27147
LWORK (input) INTEGER
27148
The dimension of the array WORK. LWORK >= max(1,M).
27149
For optimum performance LWORK >= M*NB, where NB is
27150
the optimal blocksize.
27151
27152
If LWORK = -1, then a workspace query is assumed; the routine
27153
only calculates the optimal size of the WORK array, returns
27154
this value as the first entry of the WORK array, and no error
27155
message related to LWORK is issued by XERBLA.
27156
27157
INFO (output) INTEGER
27158
= 0: successful exit;
27159
< 0: if INFO = -i, the i-th argument has an illegal value
27160
27161
=====================================================================
27162
27163
27164
Test the input arguments
27165
*/
27166
27167
/* Parameter adjustments */
27168
a_dim1 = *lda;
27169
a_offset = 1 + a_dim1;
27170
a -= a_offset;
27171
--tau;
27172
--work;
27173
27174
/* Function Body */
27175
*info = 0;
27176
nb = ilaenv_(&c__1, "ZUNGLQ", " ", m, n, k, &c_n1, (ftnlen)6, (ftnlen)1);
27177
lwkopt = max(1,*m) * nb;
27178
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
27179
lquery = *lwork == -1;
27180
if (*m < 0) {
27181
*info = -1;
27182
} else if (*n < *m) {
27183
*info = -2;
27184
} else if (*k < 0 || *k > *m) {
27185
*info = -3;
27186
} else if (*lda < max(1,*m)) {
27187
*info = -5;
27188
} else if (*lwork < max(1,*m) && ! lquery) {
27189
*info = -8;
27190
}
27191
if (*info != 0) {
27192
i__1 = -(*info);
27193
xerbla_("ZUNGLQ", &i__1);
27194
return 0;
27195
} else if (lquery) {
27196
return 0;
27197
}
27198
27199
/* Quick return if possible */
27200
27201
if (*m <= 0) {
27202
work[1].r = 1., work[1].i = 0.;
27203
return 0;
27204
}
27205
27206
nbmin = 2;
27207
nx = 0;
27208
iws = *m;
27209
if (nb > 1 && nb < *k) {
27210
27211
/*
27212
Determine when to cross over from blocked to unblocked code.
27213
27214
Computing MAX
27215
*/
27216
i__1 = 0, i__2 = ilaenv_(&c__3, "ZUNGLQ", " ", m, n, k, &c_n1, (
27217
ftnlen)6, (ftnlen)1);
27218
nx = max(i__1,i__2);
27219
if (nx < *k) {
27220
27221
/* Determine if workspace is large enough for blocked code. */
27222
27223
ldwork = *m;
27224
iws = ldwork * nb;
27225
if (*lwork < iws) {
27226
27227
/*
27228
Not enough workspace to use optimal NB: reduce NB and
27229
determine the minimum value of NB.
27230
*/
27231
27232
nb = *lwork / ldwork;
27233
/* Computing MAX */
27234
i__1 = 2, i__2 = ilaenv_(&c__2, "ZUNGLQ", " ", m, n, k, &c_n1,
27235
(ftnlen)6, (ftnlen)1);
27236
nbmin = max(i__1,i__2);
27237
}
27238
}
27239
}
27240
27241
if (nb >= nbmin && nb < *k && nx < *k) {
27242
27243
/*
27244
Use blocked code after the last block.
27245
The first kk rows are handled by the block method.
27246
*/
27247
27248
ki = (*k - nx - 1) / nb * nb;
27249
/* Computing MIN */
27250
i__1 = *k, i__2 = ki + nb;
27251
kk = min(i__1,i__2);
27252
27253
/* Set A(kk+1:m,1:kk) to zero. */
27254
27255
i__1 = kk;
27256
for (j = 1; j <= i__1; ++j) {
27257
i__2 = *m;
27258
for (i__ = kk + 1; i__ <= i__2; ++i__) {
27259
i__3 = i__ + j * a_dim1;
27260
a[i__3].r = 0., a[i__3].i = 0.;
27261
/* L10: */
27262
}
27263
/* L20: */
27264
}
27265
} else {
27266
kk = 0;
27267
}
27268
27269
/* Use unblocked code for the last or only block. */
27270
27271
if (kk < *m) {
27272
i__1 = *m - kk;
27273
i__2 = *n - kk;
27274
i__3 = *k - kk;
27275
zungl2_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
27276
tau[kk + 1], &work[1], &iinfo);
27277
}
27278
27279
if (kk > 0) {
27280
27281
/* Use blocked code */
27282
27283
i__1 = -nb;
27284
for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
27285
/* Computing MIN */
27286
i__2 = nb, i__3 = *k - i__ + 1;
27287
ib = min(i__2,i__3);
27288
if (i__ + ib <= *m) {
27289
27290
/*
27291
Form the triangular factor of the block reflector
27292
H = H(i) H(i+1) . . . H(i+ib-1)
27293
*/
27294
27295
i__2 = *n - i__ + 1;
27296
zlarft_("Forward", "Rowwise", &i__2, &ib, &a[i__ + i__ *
27297
a_dim1], lda, &tau[i__], &work[1], &ldwork);
27298
27299
/* Apply H' to A(i+ib:m,i:n) from the right */
27300
27301
i__2 = *m - i__ - ib + 1;
27302
i__3 = *n - i__ + 1;
27303
zlarfb_("Right", "Conjugate transpose", "Forward", "Rowwise",
27304
&i__2, &i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[
27305
1], &ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[
27306
ib + 1], &ldwork);
27307
}
27308
27309
/* Apply H' to columns i:n of current block */
27310
27311
i__2 = *n - i__ + 1;
27312
zungl2_(&ib, &i__2, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
27313
work[1], &iinfo);
27314
27315
/* Set columns 1:i-1 of current block to zero */
27316
27317
i__2 = i__ - 1;
27318
for (j = 1; j <= i__2; ++j) {
27319
i__3 = i__ + ib - 1;
27320
for (l = i__; l <= i__3; ++l) {
27321
i__4 = l + j * a_dim1;
27322
a[i__4].r = 0., a[i__4].i = 0.;
27323
/* L30: */
27324
}
27325
/* L40: */
27326
}
27327
/* L50: */
27328
}
27329
}
27330
27331
work[1].r = (doublereal) iws, work[1].i = 0.;
27332
return 0;
27333
27334
/* End of ZUNGLQ */
27335
27336
} /* zunglq_ */
27337
27338
/* Subroutine */ int zungqr_(integer *m, integer *n, integer *k,
27339
doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
27340
work, integer *lwork, integer *info)
27341
{
27342
/* System generated locals */
27343
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
27344
27345
/* Local variables */
27346
static integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
27347
extern /* Subroutine */ int zung2r_(integer *, integer *, integer *,
27348
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
27349
integer *), xerbla_(char *, integer *);
27350
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
27351
integer *, integer *, ftnlen, ftnlen);
27352
extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *,
27353
integer *, integer *, integer *, doublecomplex *, integer *,
27354
doublecomplex *, integer *, doublecomplex *, integer *,
27355
doublecomplex *, integer *);
27356
static integer ldwork;
27357
extern /* Subroutine */ int zlarft_(char *, char *, integer *, integer *,
27358
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
27359
integer *);
27360
static integer lwkopt;
27361
static logical lquery;
27362
27363
27364
/*
27365
-- LAPACK routine (version 3.2) --
27366
-- LAPACK is a software package provided by Univ. of Tennessee, --
27367
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
27368
November 2006
27369
27370
27371
Purpose
27372
=======
27373
27374
ZUNGQR generates an M-by-N complex matrix Q with orthonormal columns,
27375
which is defined as the first N columns of a product of K elementary
27376
reflectors of order M
27377
27378
Q = H(1) H(2) . . . H(k)
27379
27380
as returned by ZGEQRF.
27381
27382
Arguments
27383
=========
27384
27385
M (input) INTEGER
27386
The number of rows of the matrix Q. M >= 0.
27387
27388
N (input) INTEGER
27389
The number of columns of the matrix Q. M >= N >= 0.
27390
27391
K (input) INTEGER
27392
The number of elementary reflectors whose product defines the
27393
matrix Q. N >= K >= 0.
27394
27395
A (input/output) COMPLEX*16 array, dimension (LDA,N)
27396
On entry, the i-th column must contain the vector which
27397
defines the elementary reflector H(i), for i = 1,2,...,k, as
27398
returned by ZGEQRF in the first k columns of its array
27399
argument A.
27400
On exit, the M-by-N matrix Q.
27401
27402
LDA (input) INTEGER
27403
The first dimension of the array A. LDA >= max(1,M).
27404
27405
TAU (input) COMPLEX*16 array, dimension (K)
27406
TAU(i) must contain the scalar factor of the elementary
27407
reflector H(i), as returned by ZGEQRF.
27408
27409
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
27410
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
27411
27412
LWORK (input) INTEGER
27413
The dimension of the array WORK. LWORK >= max(1,N).
27414
For optimum performance LWORK >= N*NB, where NB is the
27415
optimal blocksize.
27416
27417
If LWORK = -1, then a workspace query is assumed; the routine
27418
only calculates the optimal size of the WORK array, returns
27419
this value as the first entry of the WORK array, and no error
27420
message related to LWORK is issued by XERBLA.
27421
27422
INFO (output) INTEGER
27423
= 0: successful exit
27424
< 0: if INFO = -i, the i-th argument has an illegal value
27425
27426
=====================================================================
27427
27428
27429
Test the input arguments
27430
*/
27431
27432
/* Parameter adjustments */
27433
a_dim1 = *lda;
27434
a_offset = 1 + a_dim1;
27435
a -= a_offset;
27436
--tau;
27437
--work;
27438
27439
/* Function Body */
27440
*info = 0;
27441
nb = ilaenv_(&c__1, "ZUNGQR", " ", m, n, k, &c_n1, (ftnlen)6, (ftnlen)1);
27442
lwkopt = max(1,*n) * nb;
27443
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
27444
lquery = *lwork == -1;
27445
if (*m < 0) {
27446
*info = -1;
27447
} else if (*n < 0 || *n > *m) {
27448
*info = -2;
27449
} else if (*k < 0 || *k > *n) {
27450
*info = -3;
27451
} else if (*lda < max(1,*m)) {
27452
*info = -5;
27453
} else if (*lwork < max(1,*n) && ! lquery) {
27454
*info = -8;
27455
}
27456
if (*info != 0) {
27457
i__1 = -(*info);
27458
xerbla_("ZUNGQR", &i__1);
27459
return 0;
27460
} else if (lquery) {
27461
return 0;
27462
}
27463
27464
/* Quick return if possible */
27465
27466
if (*n <= 0) {
27467
work[1].r = 1., work[1].i = 0.;
27468
return 0;
27469
}
27470
27471
nbmin = 2;
27472
nx = 0;
27473
iws = *n;
27474
if (nb > 1 && nb < *k) {
27475
27476
/*
27477
Determine when to cross over from blocked to unblocked code.
27478
27479
Computing MAX
27480
*/
27481
i__1 = 0, i__2 = ilaenv_(&c__3, "ZUNGQR", " ", m, n, k, &c_n1, (
27482
ftnlen)6, (ftnlen)1);
27483
nx = max(i__1,i__2);
27484
if (nx < *k) {
27485
27486
/* Determine if workspace is large enough for blocked code. */
27487
27488
ldwork = *n;
27489
iws = ldwork * nb;
27490
if (*lwork < iws) {
27491
27492
/*
27493
Not enough workspace to use optimal NB: reduce NB and
27494
determine the minimum value of NB.
27495
*/
27496
27497
nb = *lwork / ldwork;
27498
/* Computing MAX */
27499
i__1 = 2, i__2 = ilaenv_(&c__2, "ZUNGQR", " ", m, n, k, &c_n1,
27500
(ftnlen)6, (ftnlen)1);
27501
nbmin = max(i__1,i__2);
27502
}
27503
}
27504
}
27505
27506
if (nb >= nbmin && nb < *k && nx < *k) {
27507
27508
/*
27509
Use blocked code after the last block.
27510
The first kk columns are handled by the block method.
27511
*/
27512
27513
ki = (*k - nx - 1) / nb * nb;
27514
/* Computing MIN */
27515
i__1 = *k, i__2 = ki + nb;
27516
kk = min(i__1,i__2);
27517
27518
/* Set A(1:kk,kk+1:n) to zero. */
27519
27520
i__1 = *n;
27521
for (j = kk + 1; j <= i__1; ++j) {
27522
i__2 = kk;
27523
for (i__ = 1; i__ <= i__2; ++i__) {
27524
i__3 = i__ + j * a_dim1;
27525
a[i__3].r = 0., a[i__3].i = 0.;
27526
/* L10: */
27527
}
27528
/* L20: */
27529
}
27530
} else {
27531
kk = 0;
27532
}
27533
27534
/* Use unblocked code for the last or only block. */
27535
27536
if (kk < *n) {
27537
i__1 = *m - kk;
27538
i__2 = *n - kk;
27539
i__3 = *k - kk;
27540
zung2r_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
27541
tau[kk + 1], &work[1], &iinfo);
27542
}
27543
27544
if (kk > 0) {
27545
27546
/* Use blocked code */
27547
27548
i__1 = -nb;
27549
for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
27550
/* Computing MIN */
27551
i__2 = nb, i__3 = *k - i__ + 1;
27552
ib = min(i__2,i__3);
27553
if (i__ + ib <= *n) {
27554
27555
/*
27556
Form the triangular factor of the block reflector
27557
H = H(i) H(i+1) . . . H(i+ib-1)
27558
*/
27559
27560
i__2 = *m - i__ + 1;
27561
zlarft_("Forward", "Columnwise", &i__2, &ib, &a[i__ + i__ *
27562
a_dim1], lda, &tau[i__], &work[1], &ldwork);
27563
27564
/* Apply H to A(i:m,i+ib:n) from the left */
27565
27566
i__2 = *m - i__ + 1;
27567
i__3 = *n - i__ - ib + 1;
27568
zlarfb_("Left", "No transpose", "Forward", "Columnwise", &
27569
i__2, &i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[
27570
1], &ldwork, &a[i__ + (i__ + ib) * a_dim1], lda, &
27571
work[ib + 1], &ldwork);
27572
}
27573
27574
/* Apply H to rows i:m of current block */
27575
27576
i__2 = *m - i__ + 1;
27577
zung2r_(&i__2, &ib, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
27578
work[1], &iinfo);
27579
27580
/* Set rows 1:i-1 of current block to zero */
27581
27582
i__2 = i__ + ib - 1;
27583
for (j = i__; j <= i__2; ++j) {
27584
i__3 = i__ - 1;
27585
for (l = 1; l <= i__3; ++l) {
27586
i__4 = l + j * a_dim1;
27587
a[i__4].r = 0., a[i__4].i = 0.;
27588
/* L30: */
27589
}
27590
/* L40: */
27591
}
27592
/* L50: */
27593
}
27594
}
27595
27596
work[1].r = (doublereal) iws, work[1].i = 0.;
27597
return 0;
27598
27599
/* End of ZUNGQR */
27600
27601
} /* zungqr_ */
27602
27603
/* Subroutine */ int zunm2l_(char *side, char *trans, integer *m, integer *n,
27604
integer *k, doublecomplex *a, integer *lda, doublecomplex *tau,
27605
doublecomplex *c__, integer *ldc, doublecomplex *work, integer *info)
27606
{
27607
/* System generated locals */
27608
integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3;
27609
doublecomplex z__1;
27610
27611
/* Local variables */
27612
static integer i__, i1, i2, i3, mi, ni, nq;
27613
static doublecomplex aii;
27614
static logical left;
27615
static doublecomplex taui;
27616
extern logical lsame_(char *, char *);
27617
extern /* Subroutine */ int zlarf_(char *, integer *, integer *,
27618
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
27619
integer *, doublecomplex *), xerbla_(char *, integer *);
27620
static logical notran;
27621
27622
27623
/*
27624
-- LAPACK routine (version 3.2) --
27625
-- LAPACK is a software package provided by Univ. of Tennessee, --
27626
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
27627
November 2006
27628
27629
27630
Purpose
27631
=======
27632
27633
ZUNM2L overwrites the general complex m-by-n matrix C with
27634
27635
Q * C if SIDE = 'L' and TRANS = 'N', or
27636
27637
Q'* C if SIDE = 'L' and TRANS = 'C', or
27638
27639
C * Q if SIDE = 'R' and TRANS = 'N', or
27640
27641
C * Q' if SIDE = 'R' and TRANS = 'C',
27642
27643
where Q is a complex unitary matrix defined as the product of k
27644
elementary reflectors
27645
27646
Q = H(k) . . . H(2) H(1)
27647
27648
as returned by ZGEQLF. Q is of order m if SIDE = 'L' and of order n
27649
if SIDE = 'R'.
27650
27651
Arguments
27652
=========
27653
27654
SIDE (input) CHARACTER*1
27655
= 'L': apply Q or Q' from the Left
27656
= 'R': apply Q or Q' from the Right
27657
27658
TRANS (input) CHARACTER*1
27659
= 'N': apply Q (No transpose)
27660
= 'C': apply Q' (Conjugate transpose)
27661
27662
M (input) INTEGER
27663
The number of rows of the matrix C. M >= 0.
27664
27665
N (input) INTEGER
27666
The number of columns of the matrix C. N >= 0.
27667
27668
K (input) INTEGER
27669
The number of elementary reflectors whose product defines
27670
the matrix Q.
27671
If SIDE = 'L', M >= K >= 0;
27672
if SIDE = 'R', N >= K >= 0.
27673
27674
A (input) COMPLEX*16 array, dimension (LDA,K)
27675
The i-th column must contain the vector which defines the
27676
elementary reflector H(i), for i = 1,2,...,k, as returned by
27677
ZGEQLF in the last k columns of its array argument A.
27678
A is modified by the routine but restored on exit.
27679
27680
LDA (input) INTEGER
27681
The leading dimension of the array A.
27682
If SIDE = 'L', LDA >= max(1,M);
27683
if SIDE = 'R', LDA >= max(1,N).
27684
27685
TAU (input) COMPLEX*16 array, dimension (K)
27686
TAU(i) must contain the scalar factor of the elementary
27687
reflector H(i), as returned by ZGEQLF.
27688
27689
C (input/output) COMPLEX*16 array, dimension (LDC,N)
27690
On entry, the m-by-n matrix C.
27691
On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q.
27692
27693
LDC (input) INTEGER
27694
The leading dimension of the array C. LDC >= max(1,M).
27695
27696
WORK (workspace) COMPLEX*16 array, dimension
27697
(N) if SIDE = 'L',
27698
(M) if SIDE = 'R'
27699
27700
INFO (output) INTEGER
27701
= 0: successful exit
27702
< 0: if INFO = -i, the i-th argument had an illegal value
27703
27704
=====================================================================
27705
27706
27707
Test the input arguments
27708
*/
27709
27710
/* Parameter adjustments */
27711
a_dim1 = *lda;
27712
a_offset = 1 + a_dim1;
27713
a -= a_offset;
27714
--tau;
27715
c_dim1 = *ldc;
27716
c_offset = 1 + c_dim1;
27717
c__ -= c_offset;
27718
--work;
27719
27720
/* Function Body */
27721
*info = 0;
27722
left = lsame_(side, "L");
27723
notran = lsame_(trans, "N");
27724
27725
/* NQ is the order of Q */
27726
27727
if (left) {
27728
nq = *m;
27729
} else {
27730
nq = *n;
27731
}
27732
if (! left && ! lsame_(side, "R")) {
27733
*info = -1;
27734
} else if (! notran && ! lsame_(trans, "C")) {
27735
*info = -2;
27736
} else if (*m < 0) {
27737
*info = -3;
27738
} else if (*n < 0) {
27739
*info = -4;
27740
} else if (*k < 0 || *k > nq) {
27741
*info = -5;
27742
} else if (*lda < max(1,nq)) {
27743
*info = -7;
27744
} else if (*ldc < max(1,*m)) {
27745
*info = -10;
27746
}
27747
if (*info != 0) {
27748
i__1 = -(*info);
27749
xerbla_("ZUNM2L", &i__1);
27750
return 0;
27751
}
27752
27753
/* Quick return if possible */
27754
27755
if (*m == 0 || *n == 0 || *k == 0) {
27756
return 0;
27757
}
27758
27759
if (left && notran || ! left && ! notran) {
27760
i1 = 1;
27761
i2 = *k;
27762
i3 = 1;
27763
} else {
27764
i1 = *k;
27765
i2 = 1;
27766
i3 = -1;
27767
}
27768
27769
if (left) {
27770
ni = *n;
27771
} else {
27772
mi = *m;
27773
}
27774
27775
i__1 = i2;
27776
i__2 = i3;
27777
for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
27778
if (left) {
27779
27780
/* H(i) or H(i)' is applied to C(1:m-k+i,1:n) */
27781
27782
mi = *m - *k + i__;
27783
} else {
27784
27785
/* H(i) or H(i)' is applied to C(1:m,1:n-k+i) */
27786
27787
ni = *n - *k + i__;
27788
}
27789
27790
/* Apply H(i) or H(i)' */
27791
27792
if (notran) {
27793
i__3 = i__;
27794
taui.r = tau[i__3].r, taui.i = tau[i__3].i;
27795
} else {
27796
d_cnjg(&z__1, &tau[i__]);
27797
taui.r = z__1.r, taui.i = z__1.i;
27798
}
27799
i__3 = nq - *k + i__ + i__ * a_dim1;
27800
aii.r = a[i__3].r, aii.i = a[i__3].i;
27801
i__3 = nq - *k + i__ + i__ * a_dim1;
27802
a[i__3].r = 1., a[i__3].i = 0.;
27803
zlarf_(side, &mi, &ni, &a[i__ * a_dim1 + 1], &c__1, &taui, &c__[
27804
c_offset], ldc, &work[1]);
27805
i__3 = nq - *k + i__ + i__ * a_dim1;
27806
a[i__3].r = aii.r, a[i__3].i = aii.i;
27807
/* L10: */
27808
}
27809
return 0;
27810
27811
/* End of ZUNM2L */
27812
27813
} /* zunm2l_ */
27814
27815
/* Subroutine */ int zunm2r_(char *side, char *trans, integer *m, integer *n,
27816
integer *k, doublecomplex *a, integer *lda, doublecomplex *tau,
27817
doublecomplex *c__, integer *ldc, doublecomplex *work, integer *info)
27818
{
27819
/* System generated locals */
27820
integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3;
27821
doublecomplex z__1;
27822
27823
/* Local variables */
27824
static integer i__, i1, i2, i3, ic, jc, mi, ni, nq;
27825
static doublecomplex aii;
27826
static logical left;
27827
static doublecomplex taui;
27828
extern logical lsame_(char *, char *);
27829
extern /* Subroutine */ int zlarf_(char *, integer *, integer *,
27830
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
27831
integer *, doublecomplex *), xerbla_(char *, integer *);
27832
static logical notran;
27833
27834
27835
/*
27836
-- LAPACK routine (version 3.2) --
27837
-- LAPACK is a software package provided by Univ. of Tennessee, --
27838
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
27839
November 2006
27840
27841
27842
Purpose
27843
=======
27844
27845
ZUNM2R overwrites the general complex m-by-n matrix C with
27846
27847
Q * C if SIDE = 'L' and TRANS = 'N', or
27848
27849
Q'* C if SIDE = 'L' and TRANS = 'C', or
27850
27851
C * Q if SIDE = 'R' and TRANS = 'N', or
27852
27853
C * Q' if SIDE = 'R' and TRANS = 'C',
27854
27855
where Q is a complex unitary matrix defined as the product of k
27856
elementary reflectors
27857
27858
Q = H(1) H(2) . . . H(k)
27859
27860
as returned by ZGEQRF. Q is of order m if SIDE = 'L' and of order n
27861
if SIDE = 'R'.
27862
27863
Arguments
27864
=========
27865
27866
SIDE (input) CHARACTER*1
27867
= 'L': apply Q or Q' from the Left
27868
= 'R': apply Q or Q' from the Right
27869
27870
TRANS (input) CHARACTER*1
27871
= 'N': apply Q (No transpose)
27872
= 'C': apply Q' (Conjugate transpose)
27873
27874
M (input) INTEGER
27875
The number of rows of the matrix C. M >= 0.
27876
27877
N (input) INTEGER
27878
The number of columns of the matrix C. N >= 0.
27879
27880
K (input) INTEGER
27881
The number of elementary reflectors whose product defines
27882
the matrix Q.
27883
If SIDE = 'L', M >= K >= 0;
27884
if SIDE = 'R', N >= K >= 0.
27885
27886
A (input) COMPLEX*16 array, dimension (LDA,K)
27887
The i-th column must contain the vector which defines the
27888
elementary reflector H(i), for i = 1,2,...,k, as returned by
27889
ZGEQRF in the first k columns of its array argument A.
27890
A is modified by the routine but restored on exit.
27891
27892
LDA (input) INTEGER
27893
The leading dimension of the array A.
27894
If SIDE = 'L', LDA >= max(1,M);
27895
if SIDE = 'R', LDA >= max(1,N).
27896
27897
TAU (input) COMPLEX*16 array, dimension (K)
27898
TAU(i) must contain the scalar factor of the elementary
27899
reflector H(i), as returned by ZGEQRF.
27900
27901
C (input/output) COMPLEX*16 array, dimension (LDC,N)
27902
On entry, the m-by-n matrix C.
27903
On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q.
27904
27905
LDC (input) INTEGER
27906
The leading dimension of the array C. LDC >= max(1,M).
27907
27908
WORK (workspace) COMPLEX*16 array, dimension
27909
(N) if SIDE = 'L',
27910
(M) if SIDE = 'R'
27911
27912
INFO (output) INTEGER
27913
= 0: successful exit
27914
< 0: if INFO = -i, the i-th argument had an illegal value
27915
27916
=====================================================================
27917
27918
27919
Test the input arguments
27920
*/
27921
27922
/* Parameter adjustments */
27923
a_dim1 = *lda;
27924
a_offset = 1 + a_dim1;
27925
a -= a_offset;
27926
--tau;
27927
c_dim1 = *ldc;
27928
c_offset = 1 + c_dim1;
27929
c__ -= c_offset;
27930
--work;
27931
27932
/* Function Body */
27933
*info = 0;
27934
left = lsame_(side, "L");
27935
notran = lsame_(trans, "N");
27936
27937
/* NQ is the order of Q */
27938
27939
if (left) {
27940
nq = *m;
27941
} else {
27942
nq = *n;
27943
}
27944
if (! left && ! lsame_(side, "R")) {
27945
*info = -1;
27946
} else if (! notran && ! lsame_(trans, "C")) {
27947
*info = -2;
27948
} else if (*m < 0) {
27949
*info = -3;
27950
} else if (*n < 0) {
27951
*info = -4;
27952
} else if (*k < 0 || *k > nq) {
27953
*info = -5;
27954
} else if (*lda < max(1,nq)) {
27955
*info = -7;
27956
} else if (*ldc < max(1,*m)) {
27957
*info = -10;
27958
}
27959
if (*info != 0) {
27960
i__1 = -(*info);
27961
xerbla_("ZUNM2R", &i__1);
27962
return 0;
27963
}
27964
27965
/* Quick return if possible */
27966
27967
if (*m == 0 || *n == 0 || *k == 0) {
27968
return 0;
27969
}
27970
27971
if (left && ! notran || ! left && notran) {
27972
i1 = 1;
27973
i2 = *k;
27974
i3 = 1;
27975
} else {
27976
i1 = *k;
27977
i2 = 1;
27978
i3 = -1;
27979
}
27980
27981
if (left) {
27982
ni = *n;
27983
jc = 1;
27984
} else {
27985
mi = *m;
27986
ic = 1;
27987
}
27988
27989
i__1 = i2;
27990
i__2 = i3;
27991
for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
27992
if (left) {
27993
27994
/* H(i) or H(i)' is applied to C(i:m,1:n) */
27995
27996
mi = *m - i__ + 1;
27997
ic = i__;
27998
} else {
27999
28000
/* H(i) or H(i)' is applied to C(1:m,i:n) */
28001
28002
ni = *n - i__ + 1;
28003
jc = i__;
28004
}
28005
28006
/* Apply H(i) or H(i)' */
28007
28008
if (notran) {
28009
i__3 = i__;
28010
taui.r = tau[i__3].r, taui.i = tau[i__3].i;
28011
} else {
28012
d_cnjg(&z__1, &tau[i__]);
28013
taui.r = z__1.r, taui.i = z__1.i;
28014
}
28015
i__3 = i__ + i__ * a_dim1;
28016
aii.r = a[i__3].r, aii.i = a[i__3].i;
28017
i__3 = i__ + i__ * a_dim1;
28018
a[i__3].r = 1., a[i__3].i = 0.;
28019
zlarf_(side, &mi, &ni, &a[i__ + i__ * a_dim1], &c__1, &taui, &c__[ic
28020
+ jc * c_dim1], ldc, &work[1]);
28021
i__3 = i__ + i__ * a_dim1;
28022
a[i__3].r = aii.r, a[i__3].i = aii.i;
28023
/* L10: */
28024
}
28025
return 0;
28026
28027
/* End of ZUNM2R */
28028
28029
} /* zunm2r_ */
28030
28031
/* Subroutine */ int zunmbr_(char *vect, char *side, char *trans, integer *m,
28032
integer *n, integer *k, doublecomplex *a, integer *lda, doublecomplex
28033
*tau, doublecomplex *c__, integer *ldc, doublecomplex *work, integer *
28034
lwork, integer *info)
28035
{
28036
/* System generated locals */
28037
address a__1[2];
28038
integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2];
28039
char ch__1[2];
28040
28041
/* Local variables */
28042
static integer i1, i2, nb, mi, ni, nq, nw;
28043
static logical left;
28044
extern logical lsame_(char *, char *);
28045
static integer iinfo;
28046
extern /* Subroutine */ int xerbla_(char *, integer *);
28047
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
28048
integer *, integer *, ftnlen, ftnlen);
28049
static logical notran, applyq;
28050
static char transt[1];
28051
static integer lwkopt;
28052
static logical lquery;
28053
extern /* Subroutine */ int zunmlq_(char *, char *, integer *, integer *,
28054
integer *, doublecomplex *, integer *, doublecomplex *,
28055
doublecomplex *, integer *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *,
28056
integer *, doublecomplex *, integer *, doublecomplex *,
28057
doublecomplex *, integer *, doublecomplex *, integer *, integer *);
28058
28059
28060
/*
28061
-- LAPACK routine (version 3.2) --
28062
-- LAPACK is a software package provided by Univ. of Tennessee, --
28063
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
28064
November 2006
28065
28066
28067
Purpose
28068
=======
28069
28070
If VECT = 'Q', ZUNMBR overwrites the general complex M-by-N matrix C
28071
with
28072
SIDE = 'L' SIDE = 'R'
28073
TRANS = 'N': Q * C C * Q
28074
TRANS = 'C': Q**H * C C * Q**H
28075
28076
If VECT = 'P', ZUNMBR overwrites the general complex M-by-N matrix C
28077
with
28078
SIDE = 'L' SIDE = 'R'
28079
TRANS = 'N': P * C C * P
28080
TRANS = 'C': P**H * C C * P**H
28081
28082
Here Q and P**H are the unitary matrices determined by ZGEBRD when
28083
reducing a complex matrix A to bidiagonal form: A = Q * B * P**H. Q
28084
and P**H are defined as products of elementary reflectors H(i) and
28085
G(i) respectively.
28086
28087
Let nq = m if SIDE = 'L' and nq = n if SIDE = 'R'. Thus nq is the
28088
order of the unitary matrix Q or P**H that is applied.
28089
28090
If VECT = 'Q', A is assumed to have been an NQ-by-K matrix:
28091
if nq >= k, Q = H(1) H(2) . . . H(k);
28092
if nq < k, Q = H(1) H(2) . . . H(nq-1).
28093
28094
If VECT = 'P', A is assumed to have been a K-by-NQ matrix:
28095
if k < nq, P = G(1) G(2) . . . G(k);
28096
if k >= nq, P = G(1) G(2) . . . G(nq-1).
28097
28098
Arguments
28099
=========
28100
28101
VECT (input) CHARACTER*1
28102
= 'Q': apply Q or Q**H;
28103
= 'P': apply P or P**H.
28104
28105
SIDE (input) CHARACTER*1
28106
= 'L': apply Q, Q**H, P or P**H from the Left;
28107
= 'R': apply Q, Q**H, P or P**H from the Right.
28108
28109
TRANS (input) CHARACTER*1
28110
= 'N': No transpose, apply Q or P;
28111
= 'C': Conjugate transpose, apply Q**H or P**H.
28112
28113
M (input) INTEGER
28114
The number of rows of the matrix C. M >= 0.
28115
28116
N (input) INTEGER
28117
The number of columns of the matrix C. N >= 0.
28118
28119
K (input) INTEGER
28120
If VECT = 'Q', the number of columns in the original
28121
matrix reduced by ZGEBRD.
28122
If VECT = 'P', the number of rows in the original
28123
matrix reduced by ZGEBRD.
28124
K >= 0.
28125
28126
A (input) COMPLEX*16 array, dimension
28127
(LDA,min(nq,K)) if VECT = 'Q'
28128
(LDA,nq) if VECT = 'P'
28129
The vectors which define the elementary reflectors H(i) and
28130
G(i), whose products determine the matrices Q and P, as
28131
returned by ZGEBRD.
28132
28133
LDA (input) INTEGER
28134
The leading dimension of the array A.
28135
If VECT = 'Q', LDA >= max(1,nq);
28136
if VECT = 'P', LDA >= max(1,min(nq,K)).
28137
28138
TAU (input) COMPLEX*16 array, dimension (min(nq,K))
28139
TAU(i) must contain the scalar factor of the elementary
28140
reflector H(i) or G(i) which determines Q or P, as returned
28141
by ZGEBRD in the array argument TAUQ or TAUP.
28142
28143
C (input/output) COMPLEX*16 array, dimension (LDC,N)
28144
On entry, the M-by-N matrix C.
28145
On exit, C is overwritten by Q*C or Q**H*C or C*Q**H or C*Q
28146
or P*C or P**H*C or C*P or C*P**H.
28147
28148
LDC (input) INTEGER
28149
The leading dimension of the array C. LDC >= max(1,M).
28150
28151
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
28152
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
28153
28154
LWORK (input) INTEGER
28155
The dimension of the array WORK.
28156
If SIDE = 'L', LWORK >= max(1,N);
28157
if SIDE = 'R', LWORK >= max(1,M);
28158
if N = 0 or M = 0, LWORK >= 1.
28159
For optimum performance LWORK >= max(1,N*NB) if SIDE = 'L',
28160
and LWORK >= max(1,M*NB) if SIDE = 'R', where NB is the
28161
optimal blocksize. (NB = 0 if M = 0 or N = 0.)
28162
28163
If LWORK = -1, then a workspace query is assumed; the routine
28164
only calculates the optimal size of the WORK array, returns
28165
this value as the first entry of the WORK array, and no error
28166
message related to LWORK is issued by XERBLA.
28167
28168
INFO (output) INTEGER
28169
= 0: successful exit
28170
< 0: if INFO = -i, the i-th argument had an illegal value
28171
28172
=====================================================================
28173
28174
28175
Test the input arguments
28176
*/
28177
28178
/* Parameter adjustments */
28179
a_dim1 = *lda;
28180
a_offset = 1 + a_dim1;
28181
a -= a_offset;
28182
--tau;
28183
c_dim1 = *ldc;
28184
c_offset = 1 + c_dim1;
28185
c__ -= c_offset;
28186
--work;
28187
28188
/* Function Body */
28189
*info = 0;
28190
applyq = lsame_(vect, "Q");
28191
left = lsame_(side, "L");
28192
notran = lsame_(trans, "N");
28193
lquery = *lwork == -1;
28194
28195
/* NQ is the order of Q or P and NW is the minimum dimension of WORK */
28196
28197
if (left) {
28198
nq = *m;
28199
nw = *n;
28200
} else {
28201
nq = *n;
28202
nw = *m;
28203
}
28204
if (*m == 0 || *n == 0) {
28205
nw = 0;
28206
}
28207
if (! applyq && ! lsame_(vect, "P")) {
28208
*info = -1;
28209
} else if (! left && ! lsame_(side, "R")) {
28210
*info = -2;
28211
} else if (! notran && ! lsame_(trans, "C")) {
28212
*info = -3;
28213
} else if (*m < 0) {
28214
*info = -4;
28215
} else if (*n < 0) {
28216
*info = -5;
28217
} else if (*k < 0) {
28218
*info = -6;
28219
} else /* if(complicated condition) */ {
28220
/* Computing MAX */
28221
i__1 = 1, i__2 = min(nq,*k);
28222
if (applyq && *lda < max(1,nq) || ! applyq && *lda < max(i__1,i__2)) {
28223
*info = -8;
28224
} else if (*ldc < max(1,*m)) {
28225
*info = -11;
28226
} else if (*lwork < max(1,nw) && ! lquery) {
28227
*info = -13;
28228
}
28229
}
28230
28231
if (*info == 0) {
28232
if (nw > 0) {
28233
if (applyq) {
28234
if (left) {
28235
/* Writing concatenation */
28236
i__3[0] = 1, a__1[0] = side;
28237
i__3[1] = 1, a__1[1] = trans;
28238
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
28239
i__1 = *m - 1;
28240
i__2 = *m - 1;
28241
nb = ilaenv_(&c__1, "ZUNMQR", ch__1, &i__1, n, &i__2, &
28242
c_n1, (ftnlen)6, (ftnlen)2);
28243
} else {
28244
/* Writing concatenation */
28245
i__3[0] = 1, a__1[0] = side;
28246
i__3[1] = 1, a__1[1] = trans;
28247
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
28248
i__1 = *n - 1;
28249
i__2 = *n - 1;
28250
nb = ilaenv_(&c__1, "ZUNMQR", ch__1, m, &i__1, &i__2, &
28251
c_n1, (ftnlen)6, (ftnlen)2);
28252
}
28253
} else {
28254
if (left) {
28255
/* Writing concatenation */
28256
i__3[0] = 1, a__1[0] = side;
28257
i__3[1] = 1, a__1[1] = trans;
28258
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
28259
i__1 = *m - 1;
28260
i__2 = *m - 1;
28261
nb = ilaenv_(&c__1, "ZUNMLQ", ch__1, &i__1, n, &i__2, &
28262
c_n1, (ftnlen)6, (ftnlen)2);
28263
} else {
28264
/* Writing concatenation */
28265
i__3[0] = 1, a__1[0] = side;
28266
i__3[1] = 1, a__1[1] = trans;
28267
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
28268
i__1 = *n - 1;
28269
i__2 = *n - 1;
28270
nb = ilaenv_(&c__1, "ZUNMLQ", ch__1, m, &i__1, &i__2, &
28271
c_n1, (ftnlen)6, (ftnlen)2);
28272
}
28273
}
28274
/* Computing MAX */
28275
i__1 = 1, i__2 = nw * nb;
28276
lwkopt = max(i__1,i__2);
28277
} else {
28278
lwkopt = 1;
28279
}
28280
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
28281
}
28282
28283
if (*info != 0) {
28284
i__1 = -(*info);
28285
xerbla_("ZUNMBR", &i__1);
28286
return 0;
28287
} else if (lquery) {
28288
return 0;
28289
}
28290
28291
/* Quick return if possible */
28292
28293
if (*m == 0 || *n == 0) {
28294
return 0;
28295
}
28296
28297
if (applyq) {
28298
28299
/* Apply Q */
28300
28301
if (nq >= *k) {
28302
28303
/* Q was determined by a call to ZGEBRD with nq >= k */
28304
28305
zunmqr_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
28306
c_offset], ldc, &work[1], lwork, &iinfo);
28307
} else if (nq > 1) {
28308
28309
/* Q was determined by a call to ZGEBRD with nq < k */
28310
28311
if (left) {
28312
mi = *m - 1;
28313
ni = *n;
28314
i1 = 2;
28315
i2 = 1;
28316
} else {
28317
mi = *m;
28318
ni = *n - 1;
28319
i1 = 1;
28320
i2 = 2;
28321
}
28322
i__1 = nq - 1;
28323
zunmqr_(side, trans, &mi, &ni, &i__1, &a[a_dim1 + 2], lda, &tau[1]
28324
, &c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &iinfo);
28325
}
28326
} else {
28327
28328
/* Apply P */
28329
28330
if (notran) {
28331
*(unsigned char *)transt = 'C';
28332
} else {
28333
*(unsigned char *)transt = 'N';
28334
}
28335
if (nq > *k) {
28336
28337
/* P was determined by a call to ZGEBRD with nq > k */
28338
28339
zunmlq_(side, transt, m, n, k, &a[a_offset], lda, &tau[1], &c__[
28340
c_offset], ldc, &work[1], lwork, &iinfo);
28341
} else if (nq > 1) {
28342
28343
/* P was determined by a call to ZGEBRD with nq <= k */
28344
28345
if (left) {
28346
mi = *m - 1;
28347
ni = *n;
28348
i1 = 2;
28349
i2 = 1;
28350
} else {
28351
mi = *m;
28352
ni = *n - 1;
28353
i1 = 1;
28354
i2 = 2;
28355
}
28356
i__1 = nq - 1;
28357
zunmlq_(side, transt, &mi, &ni, &i__1, &a[(a_dim1 << 1) + 1], lda,
28358
&tau[1], &c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &
28359
iinfo);
28360
}
28361
}
28362
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
28363
return 0;
28364
28365
/* End of ZUNMBR */
28366
28367
} /* zunmbr_ */
28368
28369
/* Subroutine */ int zunmhr_(char *side, char *trans, integer *m, integer *n,
28370
integer *ilo, integer *ihi, doublecomplex *a, integer *lda,
28371
doublecomplex *tau, doublecomplex *c__, integer *ldc, doublecomplex *
28372
work, integer *lwork, integer *info)
28373
{
28374
/* System generated locals */
28375
address a__1[2];
28376
integer a_dim1, a_offset, c_dim1, c_offset, i__1[2], i__2;
28377
char ch__1[2];
28378
28379
/* Local variables */
28380
static integer i1, i2, nb, mi, nh, ni, nq, nw;
28381
static logical left;
28382
extern logical lsame_(char *, char *);
28383
static integer iinfo;
28384
extern /* Subroutine */ int xerbla_(char *, integer *);
28385
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
28386
integer *, integer *, ftnlen, ftnlen);
28387
static integer lwkopt;
28388
static logical lquery;
28389
extern /* Subroutine */ int zunmqr_(char *, char *, integer *, integer *,
28390
integer *, doublecomplex *, integer *, doublecomplex *,
28391
doublecomplex *, integer *, doublecomplex *, integer *, integer *);
28392
28393
28394
/*
28395
-- LAPACK routine (version 3.2) --
28396
-- LAPACK is a software package provided by Univ. of Tennessee, --
28397
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
28398
November 2006
28399
28400
28401
Purpose
28402
=======
28403
28404
ZUNMHR overwrites the general complex M-by-N matrix C with
28405
28406
SIDE = 'L' SIDE = 'R'
28407
TRANS = 'N': Q * C C * Q
28408
TRANS = 'C': Q**H * C C * Q**H
28409
28410
where Q is a complex unitary matrix of order nq, with nq = m if
28411
SIDE = 'L' and nq = n if SIDE = 'R'. Q is defined as the product of
28412
IHI-ILO elementary reflectors, as returned by ZGEHRD:
28413
28414
Q = H(ilo) H(ilo+1) . . . H(ihi-1).
28415
28416
Arguments
28417
=========
28418
28419
SIDE (input) CHARACTER*1
28420
= 'L': apply Q or Q**H from the Left;
28421
= 'R': apply Q or Q**H from the Right.
28422
28423
TRANS (input) CHARACTER*1
28424
= 'N': apply Q (No transpose)
28425
= 'C': apply Q**H (Conjugate transpose)
28426
28427
M (input) INTEGER
28428
The number of rows of the matrix C. M >= 0.
28429
28430
N (input) INTEGER
28431
The number of columns of the matrix C. N >= 0.
28432
28433
ILO (input) INTEGER
28434
IHI (input) INTEGER
28435
ILO and IHI must have the same values as in the previous call
28436
of ZGEHRD. Q is equal to the unit matrix except in the
28437
submatrix Q(ilo+1:ihi,ilo+1:ihi).
28438
If SIDE = 'L', then 1 <= ILO <= IHI <= M, if M > 0, and
28439
ILO = 1 and IHI = 0, if M = 0;
28440
if SIDE = 'R', then 1 <= ILO <= IHI <= N, if N > 0, and
28441
ILO = 1 and IHI = 0, if N = 0.
28442
28443
A (input) COMPLEX*16 array, dimension
28444
(LDA,M) if SIDE = 'L'
28445
(LDA,N) if SIDE = 'R'
28446
The vectors which define the elementary reflectors, as
28447
returned by ZGEHRD.
28448
28449
LDA (input) INTEGER
28450
The leading dimension of the array A.
28451
LDA >= max(1,M) if SIDE = 'L'; LDA >= max(1,N) if SIDE = 'R'.
28452
28453
TAU (input) COMPLEX*16 array, dimension
28454
(M-1) if SIDE = 'L'
28455
(N-1) if SIDE = 'R'
28456
TAU(i) must contain the scalar factor of the elementary
28457
reflector H(i), as returned by ZGEHRD.
28458
28459
C (input/output) COMPLEX*16 array, dimension (LDC,N)
28460
On entry, the M-by-N matrix C.
28461
On exit, C is overwritten by Q*C or Q**H*C or C*Q**H or C*Q.
28462
28463
LDC (input) INTEGER
28464
The leading dimension of the array C. LDC >= max(1,M).
28465
28466
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
28467
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
28468
28469
LWORK (input) INTEGER
28470
The dimension of the array WORK.
28471
If SIDE = 'L', LWORK >= max(1,N);
28472
if SIDE = 'R', LWORK >= max(1,M).
28473
For optimum performance LWORK >= N*NB if SIDE = 'L', and
28474
LWORK >= M*NB if SIDE = 'R', where NB is the optimal
28475
blocksize.
28476
28477
If LWORK = -1, then a workspace query is assumed; the routine
28478
only calculates the optimal size of the WORK array, returns
28479
this value as the first entry of the WORK array, and no error
28480
message related to LWORK is issued by XERBLA.
28481
28482
INFO (output) INTEGER
28483
= 0: successful exit
28484
< 0: if INFO = -i, the i-th argument had an illegal value
28485
28486
=====================================================================
28487
28488
28489
Test the input arguments
28490
*/
28491
28492
/* Parameter adjustments */
28493
a_dim1 = *lda;
28494
a_offset = 1 + a_dim1;
28495
a -= a_offset;
28496
--tau;
28497
c_dim1 = *ldc;
28498
c_offset = 1 + c_dim1;
28499
c__ -= c_offset;
28500
--work;
28501
28502
/* Function Body */
28503
*info = 0;
28504
nh = *ihi - *ilo;
28505
left = lsame_(side, "L");
28506
lquery = *lwork == -1;
28507
28508
/* NQ is the order of Q and NW is the minimum dimension of WORK */
28509
28510
if (left) {
28511
nq = *m;
28512
nw = *n;
28513
} else {
28514
nq = *n;
28515
nw = *m;
28516
}
28517
if (! left && ! lsame_(side, "R")) {
28518
*info = -1;
28519
} else if (! lsame_(trans, "N") && ! lsame_(trans,
28520
"C")) {
28521
*info = -2;
28522
} else if (*m < 0) {
28523
*info = -3;
28524
} else if (*n < 0) {
28525
*info = -4;
28526
} else if (*ilo < 1 || *ilo > max(1,nq)) {
28527
*info = -5;
28528
} else if (*ihi < min(*ilo,nq) || *ihi > nq) {
28529
*info = -6;
28530
} else if (*lda < max(1,nq)) {
28531
*info = -8;
28532
} else if (*ldc < max(1,*m)) {
28533
*info = -11;
28534
} else if (*lwork < max(1,nw) && ! lquery) {
28535
*info = -13;
28536
}
28537
28538
if (*info == 0) {
28539
if (left) {
28540
/* Writing concatenation */
28541
i__1[0] = 1, a__1[0] = side;
28542
i__1[1] = 1, a__1[1] = trans;
28543
s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
28544
nb = ilaenv_(&c__1, "ZUNMQR", ch__1, &nh, n, &nh, &c_n1, (ftnlen)
28545
6, (ftnlen)2);
28546
} else {
28547
/* Writing concatenation */
28548
i__1[0] = 1, a__1[0] = side;
28549
i__1[1] = 1, a__1[1] = trans;
28550
s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
28551
nb = ilaenv_(&c__1, "ZUNMQR", ch__1, m, &nh, &nh, &c_n1, (ftnlen)
28552
6, (ftnlen)2);
28553
}
28554
lwkopt = max(1,nw) * nb;
28555
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
28556
}
28557
28558
if (*info != 0) {
28559
i__2 = -(*info);
28560
xerbla_("ZUNMHR", &i__2);
28561
return 0;
28562
} else if (lquery) {
28563
return 0;
28564
}
28565
28566
/* Quick return if possible */
28567
28568
if (*m == 0 || *n == 0 || nh == 0) {
28569
work[1].r = 1., work[1].i = 0.;
28570
return 0;
28571
}
28572
28573
if (left) {
28574
mi = nh;
28575
ni = *n;
28576
i1 = *ilo + 1;
28577
i2 = 1;
28578
} else {
28579
mi = *m;
28580
ni = nh;
28581
i1 = 1;
28582
i2 = *ilo + 1;
28583
}
28584
28585
zunmqr_(side, trans, &mi, &ni, &nh, &a[*ilo + 1 + *ilo * a_dim1], lda, &
28586
tau[*ilo], &c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &iinfo);
28587
28588
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
28589
return 0;
28590
28591
/* End of ZUNMHR */
28592
28593
} /* zunmhr_ */
28594
28595
/* Subroutine */ int zunml2_(char *side, char *trans, integer *m, integer *n,
28596
integer *k, doublecomplex *a, integer *lda, doublecomplex *tau,
28597
doublecomplex *c__, integer *ldc, doublecomplex *work, integer *info)
28598
{
28599
/* System generated locals */
28600
integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3;
28601
doublecomplex z__1;
28602
28603
/* Local variables */
28604
static integer i__, i1, i2, i3, ic, jc, mi, ni, nq;
28605
static doublecomplex aii;
28606
static logical left;
28607
static doublecomplex taui;
28608
extern logical lsame_(char *, char *);
28609
extern /* Subroutine */ int zlarf_(char *, integer *, integer *,
28610
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
28611
integer *, doublecomplex *), xerbla_(char *, integer *), zlacgv_(integer *, doublecomplex *, integer *);
28612
static logical notran;
28613
28614
28615
/*
28616
-- LAPACK routine (version 3.2) --
28617
-- LAPACK is a software package provided by Univ. of Tennessee, --
28618
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
28619
November 2006
28620
28621
28622
Purpose
28623
=======
28624
28625
ZUNML2 overwrites the general complex m-by-n matrix C with
28626
28627
Q * C if SIDE = 'L' and TRANS = 'N', or
28628
28629
Q'* C if SIDE = 'L' and TRANS = 'C', or
28630
28631
C * Q if SIDE = 'R' and TRANS = 'N', or
28632
28633
C * Q' if SIDE = 'R' and TRANS = 'C',
28634
28635
where Q is a complex unitary matrix defined as the product of k
28636
elementary reflectors
28637
28638
Q = H(k)' . . . H(2)' H(1)'
28639
28640
as returned by ZGELQF. Q is of order m if SIDE = 'L' and of order n
28641
if SIDE = 'R'.
28642
28643
Arguments
28644
=========
28645
28646
SIDE (input) CHARACTER*1
28647
= 'L': apply Q or Q' from the Left
28648
= 'R': apply Q or Q' from the Right
28649
28650
TRANS (input) CHARACTER*1
28651
= 'N': apply Q (No transpose)
28652
= 'C': apply Q' (Conjugate transpose)
28653
28654
M (input) INTEGER
28655
The number of rows of the matrix C. M >= 0.
28656
28657
N (input) INTEGER
28658
The number of columns of the matrix C. N >= 0.
28659
28660
K (input) INTEGER
28661
The number of elementary reflectors whose product defines
28662
the matrix Q.
28663
If SIDE = 'L', M >= K >= 0;
28664
if SIDE = 'R', N >= K >= 0.
28665
28666
A (input) COMPLEX*16 array, dimension
28667
(LDA,M) if SIDE = 'L',
28668
(LDA,N) if SIDE = 'R'
28669
The i-th row must contain the vector which defines the
28670
elementary reflector H(i), for i = 1,2,...,k, as returned by
28671
ZGELQF in the first k rows of its array argument A.
28672
A is modified by the routine but restored on exit.
28673
28674
LDA (input) INTEGER
28675
The leading dimension of the array A. LDA >= max(1,K).
28676
28677
TAU (input) COMPLEX*16 array, dimension (K)
28678
TAU(i) must contain the scalar factor of the elementary
28679
reflector H(i), as returned by ZGELQF.
28680
28681
C (input/output) COMPLEX*16 array, dimension (LDC,N)
28682
On entry, the m-by-n matrix C.
28683
On exit, C is overwritten by Q*C or Q'*C or C*Q' or C*Q.
28684
28685
LDC (input) INTEGER
28686
The leading dimension of the array C. LDC >= max(1,M).
28687
28688
WORK (workspace) COMPLEX*16 array, dimension
28689
(N) if SIDE = 'L',
28690
(M) if SIDE = 'R'
28691
28692
INFO (output) INTEGER
28693
= 0: successful exit
28694
< 0: if INFO = -i, the i-th argument had an illegal value
28695
28696
=====================================================================
28697
28698
28699
Test the input arguments
28700
*/
28701
28702
/* Parameter adjustments */
28703
a_dim1 = *lda;
28704
a_offset = 1 + a_dim1;
28705
a -= a_offset;
28706
--tau;
28707
c_dim1 = *ldc;
28708
c_offset = 1 + c_dim1;
28709
c__ -= c_offset;
28710
--work;
28711
28712
/* Function Body */
28713
*info = 0;
28714
left = lsame_(side, "L");
28715
notran = lsame_(trans, "N");
28716
28717
/* NQ is the order of Q */
28718
28719
if (left) {
28720
nq = *m;
28721
} else {
28722
nq = *n;
28723
}
28724
if (! left && ! lsame_(side, "R")) {
28725
*info = -1;
28726
} else if (! notran && ! lsame_(trans, "C")) {
28727
*info = -2;
28728
} else if (*m < 0) {
28729
*info = -3;
28730
} else if (*n < 0) {
28731
*info = -4;
28732
} else if (*k < 0 || *k > nq) {
28733
*info = -5;
28734
} else if (*lda < max(1,*k)) {
28735
*info = -7;
28736
} else if (*ldc < max(1,*m)) {
28737
*info = -10;
28738
}
28739
if (*info != 0) {
28740
i__1 = -(*info);
28741
xerbla_("ZUNML2", &i__1);
28742
return 0;
28743
}
28744
28745
/* Quick return if possible */
28746
28747
if (*m == 0 || *n == 0 || *k == 0) {
28748
return 0;
28749
}
28750
28751
if (left && notran || ! left && ! notran) {
28752
i1 = 1;
28753
i2 = *k;
28754
i3 = 1;
28755
} else {
28756
i1 = *k;
28757
i2 = 1;
28758
i3 = -1;
28759
}
28760
28761
if (left) {
28762
ni = *n;
28763
jc = 1;
28764
} else {
28765
mi = *m;
28766
ic = 1;
28767
}
28768
28769
i__1 = i2;
28770
i__2 = i3;
28771
for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
28772
if (left) {
28773
28774
/* H(i) or H(i)' is applied to C(i:m,1:n) */
28775
28776
mi = *m - i__ + 1;
28777
ic = i__;
28778
} else {
28779
28780
/* H(i) or H(i)' is applied to C(1:m,i:n) */
28781
28782
ni = *n - i__ + 1;
28783
jc = i__;
28784
}
28785
28786
/* Apply H(i) or H(i)' */
28787
28788
if (notran) {
28789
d_cnjg(&z__1, &tau[i__]);
28790
taui.r = z__1.r, taui.i = z__1.i;
28791
} else {
28792
i__3 = i__;
28793
taui.r = tau[i__3].r, taui.i = tau[i__3].i;
28794
}
28795
if (i__ < nq) {
28796
i__3 = nq - i__;
28797
zlacgv_(&i__3, &a[i__ + (i__ + 1) * a_dim1], lda);
28798
}
28799
i__3 = i__ + i__ * a_dim1;
28800
aii.r = a[i__3].r, aii.i = a[i__3].i;
28801
i__3 = i__ + i__ * a_dim1;
28802
a[i__3].r = 1., a[i__3].i = 0.;
28803
zlarf_(side, &mi, &ni, &a[i__ + i__ * a_dim1], lda, &taui, &c__[ic +
28804
jc * c_dim1], ldc, &work[1]);
28805
i__3 = i__ + i__ * a_dim1;
28806
a[i__3].r = aii.r, a[i__3].i = aii.i;
28807
if (i__ < nq) {
28808
i__3 = nq - i__;
28809
zlacgv_(&i__3, &a[i__ + (i__ + 1) * a_dim1], lda);
28810
}
28811
/* L10: */
28812
}
28813
return 0;
28814
28815
/* End of ZUNML2 */
28816
28817
} /* zunml2_ */
28818
28819
/* Subroutine */ int zunmlq_(char *side, char *trans, integer *m, integer *n,
28820
integer *k, doublecomplex *a, integer *lda, doublecomplex *tau,
28821
doublecomplex *c__, integer *ldc, doublecomplex *work, integer *lwork,
28822
integer *info)
28823
{
28824
/* System generated locals */
28825
address a__1[2];
28826
integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
28827
i__5;
28828
char ch__1[2];
28829
28830
/* Local variables */
28831
static integer i__;
28832
static doublecomplex t[4160] /* was [65][64] */;
28833
static integer i1, i2, i3, ib, ic, jc, nb, mi, ni, nq, nw, iws;
28834
static logical left;
28835
extern logical lsame_(char *, char *);
28836
static integer nbmin, iinfo;
28837
extern /* Subroutine */ int zunml2_(char *, char *, integer *, integer *,
28838
integer *, doublecomplex *, integer *, doublecomplex *,
28839
doublecomplex *, integer *, doublecomplex *, integer *), xerbla_(char *, integer *);
28840
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
28841
integer *, integer *, ftnlen, ftnlen);
28842
extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *,
28843
integer *, integer *, integer *, doublecomplex *, integer *,
28844
doublecomplex *, integer *, doublecomplex *, integer *,
28845
doublecomplex *, integer *);
28846
static logical notran;
28847
static integer ldwork;
28848
extern /* Subroutine */ int zlarft_(char *, char *, integer *, integer *,
28849
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
28850
integer *);
28851
static char transt[1];
28852
static integer lwkopt;
28853
static logical lquery;
28854
28855
28856
/*
28857
-- LAPACK routine (version 3.2) --
28858
-- LAPACK is a software package provided by Univ. of Tennessee, --
28859
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
28860
November 2006
28861
28862
28863
Purpose
28864
=======
28865
28866
ZUNMLQ overwrites the general complex M-by-N matrix C with
28867
28868
SIDE = 'L' SIDE = 'R'
28869
TRANS = 'N': Q * C C * Q
28870
TRANS = 'C': Q**H * C C * Q**H
28871
28872
where Q is a complex unitary matrix defined as the product of k
28873
elementary reflectors
28874
28875
Q = H(k)' . . . H(2)' H(1)'
28876
28877
as returned by ZGELQF. Q is of order M if SIDE = 'L' and of order N
28878
if SIDE = 'R'.
28879
28880
Arguments
28881
=========
28882
28883
SIDE (input) CHARACTER*1
28884
= 'L': apply Q or Q**H from the Left;
28885
= 'R': apply Q or Q**H from the Right.
28886
28887
TRANS (input) CHARACTER*1
28888
= 'N': No transpose, apply Q;
28889
= 'C': Conjugate transpose, apply Q**H.
28890
28891
M (input) INTEGER
28892
The number of rows of the matrix C. M >= 0.
28893
28894
N (input) INTEGER
28895
The number of columns of the matrix C. N >= 0.
28896
28897
K (input) INTEGER
28898
The number of elementary reflectors whose product defines
28899
the matrix Q.
28900
If SIDE = 'L', M >= K >= 0;
28901
if SIDE = 'R', N >= K >= 0.
28902
28903
A (input) COMPLEX*16 array, dimension
28904
(LDA,M) if SIDE = 'L',
28905
(LDA,N) if SIDE = 'R'
28906
The i-th row must contain the vector which defines the
28907
elementary reflector H(i), for i = 1,2,...,k, as returned by
28908
ZGELQF in the first k rows of its array argument A.
28909
A is modified by the routine but restored on exit.
28910
28911
LDA (input) INTEGER
28912
The leading dimension of the array A. LDA >= max(1,K).
28913
28914
TAU (input) COMPLEX*16 array, dimension (K)
28915
TAU(i) must contain the scalar factor of the elementary
28916
reflector H(i), as returned by ZGELQF.
28917
28918
C (input/output) COMPLEX*16 array, dimension (LDC,N)
28919
On entry, the M-by-N matrix C.
28920
On exit, C is overwritten by Q*C or Q**H*C or C*Q**H or C*Q.
28921
28922
LDC (input) INTEGER
28923
The leading dimension of the array C. LDC >= max(1,M).
28924
28925
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
28926
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
28927
28928
LWORK (input) INTEGER
28929
The dimension of the array WORK.
28930
If SIDE = 'L', LWORK >= max(1,N);
28931
if SIDE = 'R', LWORK >= max(1,M).
28932
For optimum performance LWORK >= N*NB if SIDE 'L', and
28933
LWORK >= M*NB if SIDE = 'R', where NB is the optimal
28934
blocksize.
28935
28936
If LWORK = -1, then a workspace query is assumed; the routine
28937
only calculates the optimal size of the WORK array, returns
28938
this value as the first entry of the WORK array, and no error
28939
message related to LWORK is issued by XERBLA.
28940
28941
INFO (output) INTEGER
28942
= 0: successful exit
28943
< 0: if INFO = -i, the i-th argument had an illegal value
28944
28945
=====================================================================
28946
28947
28948
Test the input arguments
28949
*/
28950
28951
/* Parameter adjustments */
28952
a_dim1 = *lda;
28953
a_offset = 1 + a_dim1;
28954
a -= a_offset;
28955
--tau;
28956
c_dim1 = *ldc;
28957
c_offset = 1 + c_dim1;
28958
c__ -= c_offset;
28959
--work;
28960
28961
/* Function Body */
28962
*info = 0;
28963
left = lsame_(side, "L");
28964
notran = lsame_(trans, "N");
28965
lquery = *lwork == -1;
28966
28967
/* NQ is the order of Q and NW is the minimum dimension of WORK */
28968
28969
if (left) {
28970
nq = *m;
28971
nw = *n;
28972
} else {
28973
nq = *n;
28974
nw = *m;
28975
}
28976
if (! left && ! lsame_(side, "R")) {
28977
*info = -1;
28978
} else if (! notran && ! lsame_(trans, "C")) {
28979
*info = -2;
28980
} else if (*m < 0) {
28981
*info = -3;
28982
} else if (*n < 0) {
28983
*info = -4;
28984
} else if (*k < 0 || *k > nq) {
28985
*info = -5;
28986
} else if (*lda < max(1,*k)) {
28987
*info = -7;
28988
} else if (*ldc < max(1,*m)) {
28989
*info = -10;
28990
} else if (*lwork < max(1,nw) && ! lquery) {
28991
*info = -12;
28992
}
28993
28994
if (*info == 0) {
28995
28996
/*
28997
Determine the block size. NB may be at most NBMAX, where NBMAX
28998
is used to define the local array T.
28999
29000
Computing MIN
29001
Writing concatenation
29002
*/
29003
i__3[0] = 1, a__1[0] = side;
29004
i__3[1] = 1, a__1[1] = trans;
29005
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
29006
i__1 = 64, i__2 = ilaenv_(&c__1, "ZUNMLQ", ch__1, m, n, k, &c_n1, (
29007
ftnlen)6, (ftnlen)2);
29008
nb = min(i__1,i__2);
29009
lwkopt = max(1,nw) * nb;
29010
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
29011
}
29012
29013
if (*info != 0) {
29014
i__1 = -(*info);
29015
xerbla_("ZUNMLQ", &i__1);
29016
return 0;
29017
} else if (lquery) {
29018
return 0;
29019
}
29020
29021
/* Quick return if possible */
29022
29023
if (*m == 0 || *n == 0 || *k == 0) {
29024
work[1].r = 1., work[1].i = 0.;
29025
return 0;
29026
}
29027
29028
nbmin = 2;
29029
ldwork = nw;
29030
if (nb > 1 && nb < *k) {
29031
iws = nw * nb;
29032
if (*lwork < iws) {
29033
nb = *lwork / ldwork;
29034
/*
29035
Computing MAX
29036
Writing concatenation
29037
*/
29038
i__3[0] = 1, a__1[0] = side;
29039
i__3[1] = 1, a__1[1] = trans;
29040
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
29041
i__1 = 2, i__2 = ilaenv_(&c__2, "ZUNMLQ", ch__1, m, n, k, &c_n1, (
29042
ftnlen)6, (ftnlen)2);
29043
nbmin = max(i__1,i__2);
29044
}
29045
} else {
29046
iws = nw;
29047
}
29048
29049
if (nb < nbmin || nb >= *k) {
29050
29051
/* Use unblocked code */
29052
29053
zunml2_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
29054
c_offset], ldc, &work[1], &iinfo);
29055
} else {
29056
29057
/* Use blocked code */
29058
29059
if (left && notran || ! left && ! notran) {
29060
i1 = 1;
29061
i2 = *k;
29062
i3 = nb;
29063
} else {
29064
i1 = (*k - 1) / nb * nb + 1;
29065
i2 = 1;
29066
i3 = -nb;
29067
}
29068
29069
if (left) {
29070
ni = *n;
29071
jc = 1;
29072
} else {
29073
mi = *m;
29074
ic = 1;
29075
}
29076
29077
if (notran) {
29078
*(unsigned char *)transt = 'C';
29079
} else {
29080
*(unsigned char *)transt = 'N';
29081
}
29082
29083
i__1 = i2;
29084
i__2 = i3;
29085
for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
29086
/* Computing MIN */
29087
i__4 = nb, i__5 = *k - i__ + 1;
29088
ib = min(i__4,i__5);
29089
29090
/*
29091
Form the triangular factor of the block reflector
29092
H = H(i) H(i+1) . . . H(i+ib-1)
29093
*/
29094
29095
i__4 = nq - i__ + 1;
29096
zlarft_("Forward", "Rowwise", &i__4, &ib, &a[i__ + i__ * a_dim1],
29097
lda, &tau[i__], t, &c__65);
29098
if (left) {
29099
29100
/* H or H' is applied to C(i:m,1:n) */
29101
29102
mi = *m - i__ + 1;
29103
ic = i__;
29104
} else {
29105
29106
/* H or H' is applied to C(1:m,i:n) */
29107
29108
ni = *n - i__ + 1;
29109
jc = i__;
29110
}
29111
29112
/* Apply H or H' */
29113
29114
zlarfb_(side, transt, "Forward", "Rowwise", &mi, &ni, &ib, &a[i__
29115
+ i__ * a_dim1], lda, t, &c__65, &c__[ic + jc * c_dim1],
29116
ldc, &work[1], &ldwork);
29117
/* L10: */
29118
}
29119
}
29120
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
29121
return 0;
29122
29123
/* End of ZUNMLQ */
29124
29125
} /* zunmlq_ */
29126
29127
/* Subroutine */ int zunmql_(char *side, char *trans, integer *m, integer *n,
29128
integer *k, doublecomplex *a, integer *lda, doublecomplex *tau,
29129
doublecomplex *c__, integer *ldc, doublecomplex *work, integer *lwork,
29130
integer *info)
29131
{
29132
/* System generated locals */
29133
address a__1[2];
29134
integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
29135
i__5;
29136
char ch__1[2];
29137
29138
/* Local variables */
29139
static integer i__;
29140
static doublecomplex t[4160] /* was [65][64] */;
29141
static integer i1, i2, i3, ib, nb, mi, ni, nq, nw, iws;
29142
static logical left;
29143
extern logical lsame_(char *, char *);
29144
static integer nbmin, iinfo;
29145
extern /* Subroutine */ int zunm2l_(char *, char *, integer *, integer *,
29146
integer *, doublecomplex *, integer *, doublecomplex *,
29147
doublecomplex *, integer *, doublecomplex *, integer *), xerbla_(char *, integer *);
29148
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
29149
integer *, integer *, ftnlen, ftnlen);
29150
extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *,
29151
integer *, integer *, integer *, doublecomplex *, integer *,
29152
doublecomplex *, integer *, doublecomplex *, integer *,
29153
doublecomplex *, integer *);
29154
static logical notran;
29155
static integer ldwork;
29156
extern /* Subroutine */ int zlarft_(char *, char *, integer *, integer *,
29157
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
29158
integer *);
29159
static integer lwkopt;
29160
static logical lquery;
29161
29162
29163
/*
29164
-- LAPACK routine (version 3.2) --
29165
-- LAPACK is a software package provided by Univ. of Tennessee, --
29166
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
29167
November 2006
29168
29169
29170
Purpose
29171
=======
29172
29173
ZUNMQL overwrites the general complex M-by-N matrix C with
29174
29175
SIDE = 'L' SIDE = 'R'
29176
TRANS = 'N': Q * C C * Q
29177
TRANS = 'C': Q**H * C C * Q**H
29178
29179
where Q is a complex unitary matrix defined as the product of k
29180
elementary reflectors
29181
29182
Q = H(k) . . . H(2) H(1)
29183
29184
as returned by ZGEQLF. Q is of order M if SIDE = 'L' and of order N
29185
if SIDE = 'R'.
29186
29187
Arguments
29188
=========
29189
29190
SIDE (input) CHARACTER*1
29191
= 'L': apply Q or Q**H from the Left;
29192
= 'R': apply Q or Q**H from the Right.
29193
29194
TRANS (input) CHARACTER*1
29195
= 'N': No transpose, apply Q;
29196
= 'C': Transpose, apply Q**H.
29197
29198
M (input) INTEGER
29199
The number of rows of the matrix C. M >= 0.
29200
29201
N (input) INTEGER
29202
The number of columns of the matrix C. N >= 0.
29203
29204
K (input) INTEGER
29205
The number of elementary reflectors whose product defines
29206
the matrix Q.
29207
If SIDE = 'L', M >= K >= 0;
29208
if SIDE = 'R', N >= K >= 0.
29209
29210
A (input) COMPLEX*16 array, dimension (LDA,K)
29211
The i-th column must contain the vector which defines the
29212
elementary reflector H(i), for i = 1,2,...,k, as returned by
29213
ZGEQLF in the last k columns of its array argument A.
29214
A is modified by the routine but restored on exit.
29215
29216
LDA (input) INTEGER
29217
The leading dimension of the array A.
29218
If SIDE = 'L', LDA >= max(1,M);
29219
if SIDE = 'R', LDA >= max(1,N).
29220
29221
TAU (input) COMPLEX*16 array, dimension (K)
29222
TAU(i) must contain the scalar factor of the elementary
29223
reflector H(i), as returned by ZGEQLF.
29224
29225
C (input/output) COMPLEX*16 array, dimension (LDC,N)
29226
On entry, the M-by-N matrix C.
29227
On exit, C is overwritten by Q*C or Q**H*C or C*Q**H or C*Q.
29228
29229
LDC (input) INTEGER
29230
The leading dimension of the array C. LDC >= max(1,M).
29231
29232
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
29233
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
29234
29235
LWORK (input) INTEGER
29236
The dimension of the array WORK.
29237
If SIDE = 'L', LWORK >= max(1,N);
29238
if SIDE = 'R', LWORK >= max(1,M).
29239
For optimum performance LWORK >= N*NB if SIDE = 'L', and
29240
LWORK >= M*NB if SIDE = 'R', where NB is the optimal
29241
blocksize.
29242
29243
If LWORK = -1, then a workspace query is assumed; the routine
29244
only calculates the optimal size of the WORK array, returns
29245
this value as the first entry of the WORK array, and no error
29246
message related to LWORK is issued by XERBLA.
29247
29248
INFO (output) INTEGER
29249
= 0: successful exit
29250
< 0: if INFO = -i, the i-th argument had an illegal value
29251
29252
=====================================================================
29253
29254
29255
Test the input arguments
29256
*/
29257
29258
/* Parameter adjustments */
29259
a_dim1 = *lda;
29260
a_offset = 1 + a_dim1;
29261
a -= a_offset;
29262
--tau;
29263
c_dim1 = *ldc;
29264
c_offset = 1 + c_dim1;
29265
c__ -= c_offset;
29266
--work;
29267
29268
/* Function Body */
29269
*info = 0;
29270
left = lsame_(side, "L");
29271
notran = lsame_(trans, "N");
29272
lquery = *lwork == -1;
29273
29274
/* NQ is the order of Q and NW is the minimum dimension of WORK */
29275
29276
if (left) {
29277
nq = *m;
29278
nw = max(1,*n);
29279
} else {
29280
nq = *n;
29281
nw = max(1,*m);
29282
}
29283
if (! left && ! lsame_(side, "R")) {
29284
*info = -1;
29285
} else if (! notran && ! lsame_(trans, "C")) {
29286
*info = -2;
29287
} else if (*m < 0) {
29288
*info = -3;
29289
} else if (*n < 0) {
29290
*info = -4;
29291
} else if (*k < 0 || *k > nq) {
29292
*info = -5;
29293
} else if (*lda < max(1,nq)) {
29294
*info = -7;
29295
} else if (*ldc < max(1,*m)) {
29296
*info = -10;
29297
}
29298
29299
if (*info == 0) {
29300
if (*m == 0 || *n == 0) {
29301
lwkopt = 1;
29302
} else {
29303
29304
/*
29305
Determine the block size. NB may be at most NBMAX, where
29306
NBMAX is used to define the local array T.
29307
29308
Computing MIN
29309
Writing concatenation
29310
*/
29311
i__3[0] = 1, a__1[0] = side;
29312
i__3[1] = 1, a__1[1] = trans;
29313
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
29314
i__1 = 64, i__2 = ilaenv_(&c__1, "ZUNMQL", ch__1, m, n, k, &c_n1,
29315
(ftnlen)6, (ftnlen)2);
29316
nb = min(i__1,i__2);
29317
lwkopt = nw * nb;
29318
}
29319
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
29320
29321
if (*lwork < nw && ! lquery) {
29322
*info = -12;
29323
}
29324
}
29325
29326
if (*info != 0) {
29327
i__1 = -(*info);
29328
xerbla_("ZUNMQL", &i__1);
29329
return 0;
29330
} else if (lquery) {
29331
return 0;
29332
}
29333
29334
/* Quick return if possible */
29335
29336
if (*m == 0 || *n == 0) {
29337
return 0;
29338
}
29339
29340
nbmin = 2;
29341
ldwork = nw;
29342
if (nb > 1 && nb < *k) {
29343
iws = nw * nb;
29344
if (*lwork < iws) {
29345
nb = *lwork / ldwork;
29346
/*
29347
Computing MAX
29348
Writing concatenation
29349
*/
29350
i__3[0] = 1, a__1[0] = side;
29351
i__3[1] = 1, a__1[1] = trans;
29352
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
29353
i__1 = 2, i__2 = ilaenv_(&c__2, "ZUNMQL", ch__1, m, n, k, &c_n1, (
29354
ftnlen)6, (ftnlen)2);
29355
nbmin = max(i__1,i__2);
29356
}
29357
} else {
29358
iws = nw;
29359
}
29360
29361
if (nb < nbmin || nb >= *k) {
29362
29363
/* Use unblocked code */
29364
29365
zunm2l_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
29366
c_offset], ldc, &work[1], &iinfo);
29367
} else {
29368
29369
/* Use blocked code */
29370
29371
if (left && notran || ! left && ! notran) {
29372
i1 = 1;
29373
i2 = *k;
29374
i3 = nb;
29375
} else {
29376
i1 = (*k - 1) / nb * nb + 1;
29377
i2 = 1;
29378
i3 = -nb;
29379
}
29380
29381
if (left) {
29382
ni = *n;
29383
} else {
29384
mi = *m;
29385
}
29386
29387
i__1 = i2;
29388
i__2 = i3;
29389
for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
29390
/* Computing MIN */
29391
i__4 = nb, i__5 = *k - i__ + 1;
29392
ib = min(i__4,i__5);
29393
29394
/*
29395
Form the triangular factor of the block reflector
29396
H = H(i+ib-1) . . . H(i+1) H(i)
29397
*/
29398
29399
i__4 = nq - *k + i__ + ib - 1;
29400
zlarft_("Backward", "Columnwise", &i__4, &ib, &a[i__ * a_dim1 + 1]
29401
, lda, &tau[i__], t, &c__65);
29402
if (left) {
29403
29404
/* H or H' is applied to C(1:m-k+i+ib-1,1:n) */
29405
29406
mi = *m - *k + i__ + ib - 1;
29407
} else {
29408
29409
/* H or H' is applied to C(1:m,1:n-k+i+ib-1) */
29410
29411
ni = *n - *k + i__ + ib - 1;
29412
}
29413
29414
/* Apply H or H' */
29415
29416
zlarfb_(side, trans, "Backward", "Columnwise", &mi, &ni, &ib, &a[
29417
i__ * a_dim1 + 1], lda, t, &c__65, &c__[c_offset], ldc, &
29418
work[1], &ldwork);
29419
/* L10: */
29420
}
29421
}
29422
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
29423
return 0;
29424
29425
/* End of ZUNMQL */
29426
29427
} /* zunmql_ */
29428
29429
/* Subroutine */ int zunmqr_(char *side, char *trans, integer *m, integer *n,
29430
integer *k, doublecomplex *a, integer *lda, doublecomplex *tau,
29431
doublecomplex *c__, integer *ldc, doublecomplex *work, integer *lwork,
29432
integer *info)
29433
{
29434
/* System generated locals */
29435
address a__1[2];
29436
integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3[2], i__4,
29437
i__5;
29438
char ch__1[2];
29439
29440
/* Local variables */
29441
static integer i__;
29442
static doublecomplex t[4160] /* was [65][64] */;
29443
static integer i1, i2, i3, ib, ic, jc, nb, mi, ni, nq, nw, iws;
29444
static logical left;
29445
extern logical lsame_(char *, char *);
29446
static integer nbmin, iinfo;
29447
extern /* Subroutine */ int zunm2r_(char *, char *, integer *, integer *,
29448
integer *, doublecomplex *, integer *, doublecomplex *,
29449
doublecomplex *, integer *, doublecomplex *, integer *), xerbla_(char *, integer *);
29450
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
29451
integer *, integer *, ftnlen, ftnlen);
29452
extern /* Subroutine */ int zlarfb_(char *, char *, char *, char *,
29453
integer *, integer *, integer *, doublecomplex *, integer *,
29454
doublecomplex *, integer *, doublecomplex *, integer *,
29455
doublecomplex *, integer *);
29456
static logical notran;
29457
static integer ldwork;
29458
extern /* Subroutine */ int zlarft_(char *, char *, integer *, integer *,
29459
doublecomplex *, integer *, doublecomplex *, doublecomplex *,
29460
integer *);
29461
static integer lwkopt;
29462
static logical lquery;
29463
29464
29465
/*
29466
-- LAPACK routine (version 3.2) --
29467
-- LAPACK is a software package provided by Univ. of Tennessee, --
29468
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
29469
November 2006
29470
29471
29472
Purpose
29473
=======
29474
29475
ZUNMQR overwrites the general complex M-by-N matrix C with
29476
29477
SIDE = 'L' SIDE = 'R'
29478
TRANS = 'N': Q * C C * Q
29479
TRANS = 'C': Q**H * C C * Q**H
29480
29481
where Q is a complex unitary matrix defined as the product of k
29482
elementary reflectors
29483
29484
Q = H(1) H(2) . . . H(k)
29485
29486
as returned by ZGEQRF. Q is of order M if SIDE = 'L' and of order N
29487
if SIDE = 'R'.
29488
29489
Arguments
29490
=========
29491
29492
SIDE (input) CHARACTER*1
29493
= 'L': apply Q or Q**H from the Left;
29494
= 'R': apply Q or Q**H from the Right.
29495
29496
TRANS (input) CHARACTER*1
29497
= 'N': No transpose, apply Q;
29498
= 'C': Conjugate transpose, apply Q**H.
29499
29500
M (input) INTEGER
29501
The number of rows of the matrix C. M >= 0.
29502
29503
N (input) INTEGER
29504
The number of columns of the matrix C. N >= 0.
29505
29506
K (input) INTEGER
29507
The number of elementary reflectors whose product defines
29508
the matrix Q.
29509
If SIDE = 'L', M >= K >= 0;
29510
if SIDE = 'R', N >= K >= 0.
29511
29512
A (input) COMPLEX*16 array, dimension (LDA,K)
29513
The i-th column must contain the vector which defines the
29514
elementary reflector H(i), for i = 1,2,...,k, as returned by
29515
ZGEQRF in the first k columns of its array argument A.
29516
A is modified by the routine but restored on exit.
29517
29518
LDA (input) INTEGER
29519
The leading dimension of the array A.
29520
If SIDE = 'L', LDA >= max(1,M);
29521
if SIDE = 'R', LDA >= max(1,N).
29522
29523
TAU (input) COMPLEX*16 array, dimension (K)
29524
TAU(i) must contain the scalar factor of the elementary
29525
reflector H(i), as returned by ZGEQRF.
29526
29527
C (input/output) COMPLEX*16 array, dimension (LDC,N)
29528
On entry, the M-by-N matrix C.
29529
On exit, C is overwritten by Q*C or Q**H*C or C*Q**H or C*Q.
29530
29531
LDC (input) INTEGER
29532
The leading dimension of the array C. LDC >= max(1,M).
29533
29534
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
29535
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
29536
29537
LWORK (input) INTEGER
29538
The dimension of the array WORK.
29539
If SIDE = 'L', LWORK >= max(1,N);
29540
if SIDE = 'R', LWORK >= max(1,M).
29541
For optimum performance LWORK >= N*NB if SIDE = 'L', and
29542
LWORK >= M*NB if SIDE = 'R', where NB is the optimal
29543
blocksize.
29544
29545
If LWORK = -1, then a workspace query is assumed; the routine
29546
only calculates the optimal size of the WORK array, returns
29547
this value as the first entry of the WORK array, and no error
29548
message related to LWORK is issued by XERBLA.
29549
29550
INFO (output) INTEGER
29551
= 0: successful exit
29552
< 0: if INFO = -i, the i-th argument had an illegal value
29553
29554
=====================================================================
29555
29556
29557
Test the input arguments
29558
*/
29559
29560
/* Parameter adjustments */
29561
a_dim1 = *lda;
29562
a_offset = 1 + a_dim1;
29563
a -= a_offset;
29564
--tau;
29565
c_dim1 = *ldc;
29566
c_offset = 1 + c_dim1;
29567
c__ -= c_offset;
29568
--work;
29569
29570
/* Function Body */
29571
*info = 0;
29572
left = lsame_(side, "L");
29573
notran = lsame_(trans, "N");
29574
lquery = *lwork == -1;
29575
29576
/* NQ is the order of Q and NW is the minimum dimension of WORK */
29577
29578
if (left) {
29579
nq = *m;
29580
nw = *n;
29581
} else {
29582
nq = *n;
29583
nw = *m;
29584
}
29585
if (! left && ! lsame_(side, "R")) {
29586
*info = -1;
29587
} else if (! notran && ! lsame_(trans, "C")) {
29588
*info = -2;
29589
} else if (*m < 0) {
29590
*info = -3;
29591
} else if (*n < 0) {
29592
*info = -4;
29593
} else if (*k < 0 || *k > nq) {
29594
*info = -5;
29595
} else if (*lda < max(1,nq)) {
29596
*info = -7;
29597
} else if (*ldc < max(1,*m)) {
29598
*info = -10;
29599
} else if (*lwork < max(1,nw) && ! lquery) {
29600
*info = -12;
29601
}
29602
29603
if (*info == 0) {
29604
29605
/*
29606
Determine the block size. NB may be at most NBMAX, where NBMAX
29607
is used to define the local array T.
29608
29609
Computing MIN
29610
Writing concatenation
29611
*/
29612
i__3[0] = 1, a__1[0] = side;
29613
i__3[1] = 1, a__1[1] = trans;
29614
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
29615
i__1 = 64, i__2 = ilaenv_(&c__1, "ZUNMQR", ch__1, m, n, k, &c_n1, (
29616
ftnlen)6, (ftnlen)2);
29617
nb = min(i__1,i__2);
29618
lwkopt = max(1,nw) * nb;
29619
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
29620
}
29621
29622
if (*info != 0) {
29623
i__1 = -(*info);
29624
xerbla_("ZUNMQR", &i__1);
29625
return 0;
29626
} else if (lquery) {
29627
return 0;
29628
}
29629
29630
/* Quick return if possible */
29631
29632
if (*m == 0 || *n == 0 || *k == 0) {
29633
work[1].r = 1., work[1].i = 0.;
29634
return 0;
29635
}
29636
29637
nbmin = 2;
29638
ldwork = nw;
29639
if (nb > 1 && nb < *k) {
29640
iws = nw * nb;
29641
if (*lwork < iws) {
29642
nb = *lwork / ldwork;
29643
/*
29644
Computing MAX
29645
Writing concatenation
29646
*/
29647
i__3[0] = 1, a__1[0] = side;
29648
i__3[1] = 1, a__1[1] = trans;
29649
s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2);
29650
i__1 = 2, i__2 = ilaenv_(&c__2, "ZUNMQR", ch__1, m, n, k, &c_n1, (
29651
ftnlen)6, (ftnlen)2);
29652
nbmin = max(i__1,i__2);
29653
}
29654
} else {
29655
iws = nw;
29656
}
29657
29658
if (nb < nbmin || nb >= *k) {
29659
29660
/* Use unblocked code */
29661
29662
zunm2r_(side, trans, m, n, k, &a[a_offset], lda, &tau[1], &c__[
29663
c_offset], ldc, &work[1], &iinfo);
29664
} else {
29665
29666
/* Use blocked code */
29667
29668
if (left && ! notran || ! left && notran) {
29669
i1 = 1;
29670
i2 = *k;
29671
i3 = nb;
29672
} else {
29673
i1 = (*k - 1) / nb * nb + 1;
29674
i2 = 1;
29675
i3 = -nb;
29676
}
29677
29678
if (left) {
29679
ni = *n;
29680
jc = 1;
29681
} else {
29682
mi = *m;
29683
ic = 1;
29684
}
29685
29686
i__1 = i2;
29687
i__2 = i3;
29688
for (i__ = i1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
29689
/* Computing MIN */
29690
i__4 = nb, i__5 = *k - i__ + 1;
29691
ib = min(i__4,i__5);
29692
29693
/*
29694
Form the triangular factor of the block reflector
29695
H = H(i) H(i+1) . . . H(i+ib-1)
29696
*/
29697
29698
i__4 = nq - i__ + 1;
29699
zlarft_("Forward", "Columnwise", &i__4, &ib, &a[i__ + i__ *
29700
a_dim1], lda, &tau[i__], t, &c__65)
29701
;
29702
if (left) {
29703
29704
/* H or H' is applied to C(i:m,1:n) */
29705
29706
mi = *m - i__ + 1;
29707
ic = i__;
29708
} else {
29709
29710
/* H or H' is applied to C(1:m,i:n) */
29711
29712
ni = *n - i__ + 1;
29713
jc = i__;
29714
}
29715
29716
/* Apply H or H' */
29717
29718
zlarfb_(side, trans, "Forward", "Columnwise", &mi, &ni, &ib, &a[
29719
i__ + i__ * a_dim1], lda, t, &c__65, &c__[ic + jc *
29720
c_dim1], ldc, &work[1], &ldwork);
29721
/* L10: */
29722
}
29723
}
29724
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
29725
return 0;
29726
29727
/* End of ZUNMQR */
29728
29729
} /* zunmqr_ */
29730
29731
/* Subroutine */ int zunmtr_(char *side, char *uplo, char *trans, integer *m,
29732
integer *n, doublecomplex *a, integer *lda, doublecomplex *tau,
29733
doublecomplex *c__, integer *ldc, doublecomplex *work, integer *lwork,
29734
integer *info)
29735
{
29736
/* System generated locals */
29737
address a__1[2];
29738
integer a_dim1, a_offset, c_dim1, c_offset, i__1[2], i__2, i__3;
29739
char ch__1[2];
29740
29741
/* Local variables */
29742
static integer i1, i2, nb, mi, ni, nq, nw;
29743
static logical left;
29744
extern logical lsame_(char *, char *);
29745
static integer iinfo;
29746
static logical upper;
29747
extern /* Subroutine */ int xerbla_(char *, integer *);
29748
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
29749
integer *, integer *, ftnlen, ftnlen);
29750
static integer lwkopt;
29751
static logical lquery;
29752
extern /* Subroutine */ int zunmql_(char *, char *, integer *, integer *,
29753
integer *, doublecomplex *, integer *, doublecomplex *,
29754
doublecomplex *, integer *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *,
29755
integer *, doublecomplex *, integer *, doublecomplex *,
29756
doublecomplex *, integer *, doublecomplex *, integer *, integer *);
29757
29758
29759
/*
29760
-- LAPACK routine (version 3.2) --
29761
-- LAPACK is a software package provided by Univ. of Tennessee, --
29762
-- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
29763
November 2006
29764
29765
29766
Purpose
29767
=======
29768
29769
ZUNMTR overwrites the general complex M-by-N matrix C with
29770
29771
SIDE = 'L' SIDE = 'R'
29772
TRANS = 'N': Q * C C * Q
29773
TRANS = 'C': Q**H * C C * Q**H
29774
29775
where Q is a complex unitary matrix of order nq, with nq = m if
29776
SIDE = 'L' and nq = n if SIDE = 'R'. Q is defined as the product of
29777
nq-1 elementary reflectors, as returned by ZHETRD:
29778
29779
if UPLO = 'U', Q = H(nq-1) . . . H(2) H(1);
29780
29781
if UPLO = 'L', Q = H(1) H(2) . . . H(nq-1).
29782
29783
Arguments
29784
=========
29785
29786
SIDE (input) CHARACTER*1
29787
= 'L': apply Q or Q**H from the Left;
29788
= 'R': apply Q or Q**H from the Right.
29789
29790
UPLO (input) CHARACTER*1
29791
= 'U': Upper triangle of A contains elementary reflectors
29792
from ZHETRD;
29793
= 'L': Lower triangle of A contains elementary reflectors
29794
from ZHETRD.
29795
29796
TRANS (input) CHARACTER*1
29797
= 'N': No transpose, apply Q;
29798
= 'C': Conjugate transpose, apply Q**H.
29799
29800
M (input) INTEGER
29801
The number of rows of the matrix C. M >= 0.
29802
29803
N (input) INTEGER
29804
The number of columns of the matrix C. N >= 0.
29805
29806
A (input) COMPLEX*16 array, dimension
29807
(LDA,M) if SIDE = 'L'
29808
(LDA,N) if SIDE = 'R'
29809
The vectors which define the elementary reflectors, as
29810
returned by ZHETRD.
29811
29812
LDA (input) INTEGER
29813
The leading dimension of the array A.
29814
LDA >= max(1,M) if SIDE = 'L'; LDA >= max(1,N) if SIDE = 'R'.
29815
29816
TAU (input) COMPLEX*16 array, dimension
29817
(M-1) if SIDE = 'L'
29818
(N-1) if SIDE = 'R'
29819
TAU(i) must contain the scalar factor of the elementary
29820
reflector H(i), as returned by ZHETRD.
29821
29822
C (input/output) COMPLEX*16 array, dimension (LDC,N)
29823
On entry, the M-by-N matrix C.
29824
On exit, C is overwritten by Q*C or Q**H*C or C*Q**H or C*Q.
29825
29826
LDC (input) INTEGER
29827
The leading dimension of the array C. LDC >= max(1,M).
29828
29829
WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK))
29830
On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
29831
29832
LWORK (input) INTEGER
29833
The dimension of the array WORK.
29834
If SIDE = 'L', LWORK >= max(1,N);
29835
if SIDE = 'R', LWORK >= max(1,M).
29836
For optimum performance LWORK >= N*NB if SIDE = 'L', and
29837
LWORK >=M*NB if SIDE = 'R', where NB is the optimal
29838
blocksize.
29839
29840
If LWORK = -1, then a workspace query is assumed; the routine
29841
only calculates the optimal size of the WORK array, returns
29842
this value as the first entry of the WORK array, and no error
29843
message related to LWORK is issued by XERBLA.
29844
29845
INFO (output) INTEGER
29846
= 0: successful exit
29847
< 0: if INFO = -i, the i-th argument had an illegal value
29848
29849
=====================================================================
29850
29851
29852
Test the input arguments
29853
*/
29854
29855
/* Parameter adjustments */
29856
a_dim1 = *lda;
29857
a_offset = 1 + a_dim1;
29858
a -= a_offset;
29859
--tau;
29860
c_dim1 = *ldc;
29861
c_offset = 1 + c_dim1;
29862
c__ -= c_offset;
29863
--work;
29864
29865
/* Function Body */
29866
*info = 0;
29867
left = lsame_(side, "L");
29868
upper = lsame_(uplo, "U");
29869
lquery = *lwork == -1;
29870
29871
/* NQ is the order of Q and NW is the minimum dimension of WORK */
29872
29873
if (left) {
29874
nq = *m;
29875
nw = *n;
29876
} else {
29877
nq = *n;
29878
nw = *m;
29879
}
29880
if (! left && ! lsame_(side, "R")) {
29881
*info = -1;
29882
} else if (! upper && ! lsame_(uplo, "L")) {
29883
*info = -2;
29884
} else if (! lsame_(trans, "N") && ! lsame_(trans,
29885
"C")) {
29886
*info = -3;
29887
} else if (*m < 0) {
29888
*info = -4;
29889
} else if (*n < 0) {
29890
*info = -5;
29891
} else if (*lda < max(1,nq)) {
29892
*info = -7;
29893
} else if (*ldc < max(1,*m)) {
29894
*info = -10;
29895
} else if (*lwork < max(1,nw) && ! lquery) {
29896
*info = -12;
29897
}
29898
29899
if (*info == 0) {
29900
if (upper) {
29901
if (left) {
29902
/* Writing concatenation */
29903
i__1[0] = 1, a__1[0] = side;
29904
i__1[1] = 1, a__1[1] = trans;
29905
s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
29906
i__2 = *m - 1;
29907
i__3 = *m - 1;
29908
nb = ilaenv_(&c__1, "ZUNMQL", ch__1, &i__2, n, &i__3, &c_n1, (
29909
ftnlen)6, (ftnlen)2);
29910
} else {
29911
/* Writing concatenation */
29912
i__1[0] = 1, a__1[0] = side;
29913
i__1[1] = 1, a__1[1] = trans;
29914
s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
29915
i__2 = *n - 1;
29916
i__3 = *n - 1;
29917
nb = ilaenv_(&c__1, "ZUNMQL", ch__1, m, &i__2, &i__3, &c_n1, (
29918
ftnlen)6, (ftnlen)2);
29919
}
29920
} else {
29921
if (left) {
29922
/* Writing concatenation */
29923
i__1[0] = 1, a__1[0] = side;
29924
i__1[1] = 1, a__1[1] = trans;
29925
s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
29926
i__2 = *m - 1;
29927
i__3 = *m - 1;
29928
nb = ilaenv_(&c__1, "ZUNMQR", ch__1, &i__2, n, &i__3, &c_n1, (
29929
ftnlen)6, (ftnlen)2);
29930
} else {
29931
/* Writing concatenation */
29932
i__1[0] = 1, a__1[0] = side;
29933
i__1[1] = 1, a__1[1] = trans;
29934
s_cat(ch__1, a__1, i__1, &c__2, (ftnlen)2);
29935
i__2 = *n - 1;
29936
i__3 = *n - 1;
29937
nb = ilaenv_(&c__1, "ZUNMQR", ch__1, m, &i__2, &i__3, &c_n1, (
29938
ftnlen)6, (ftnlen)2);
29939
}
29940
}
29941
lwkopt = max(1,nw) * nb;
29942
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
29943
}
29944
29945
if (*info != 0) {
29946
i__2 = -(*info);
29947
xerbla_("ZUNMTR", &i__2);
29948
return 0;
29949
} else if (lquery) {
29950
return 0;
29951
}
29952
29953
/* Quick return if possible */
29954
29955
if (*m == 0 || *n == 0 || nq == 1) {
29956
work[1].r = 1., work[1].i = 0.;
29957
return 0;
29958
}
29959
29960
if (left) {
29961
mi = *m - 1;
29962
ni = *n;
29963
} else {
29964
mi = *m;
29965
ni = *n - 1;
29966
}
29967
29968
if (upper) {
29969
29970
/* Q was determined by a call to ZHETRD with UPLO = 'U' */
29971
29972
i__2 = nq - 1;
29973
zunmql_(side, trans, &mi, &ni, &i__2, &a[(a_dim1 << 1) + 1], lda, &
29974
tau[1], &c__[c_offset], ldc, &work[1], lwork, &iinfo);
29975
} else {
29976
29977
/* Q was determined by a call to ZHETRD with UPLO = 'L' */
29978
29979
if (left) {
29980
i1 = 2;
29981
i2 = 1;
29982
} else {
29983
i1 = 1;
29984
i2 = 2;
29985
}
29986
i__2 = nq - 1;
29987
zunmqr_(side, trans, &mi, &ni, &i__2, &a[a_dim1 + 2], lda, &tau[1], &
29988
c__[i1 + i2 * c_dim1], ldc, &work[1], lwork, &iinfo);
29989
}
29990
work[1].r = (doublereal) lwkopt, work[1].i = 0.;
29991
return 0;
29992
29993
/* End of ZUNMTR */
29994
29995
} /* zunmtr_ */
29996
29997
29998