Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / slagtf.c
1 #include "clapack.h"
2
3 /* Subroutine */ int slagtf_(integer *n, real *a, real *lambda, real *b, real 
4         *c__, real *tol, real *d__, integer *in, integer *info)
5 {
6     /* System generated locals */
7     integer i__1;
8     real r__1, r__2;
9
10     /* Local variables */
11     integer k;
12     real tl, eps, piv1, piv2, temp, mult, scale1, scale2;
13     extern doublereal slamch_(char *);
14     extern /* Subroutine */ int xerbla_(char *, integer *);
15
16
17 /*  -- LAPACK routine (version 3.1) -- */
18 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
19 /*     November 2006 */
20
21 /*     .. Scalar Arguments .. */
22 /*     .. */
23 /*     .. Array Arguments .. */
24 /*     .. */
25
26 /*  Purpose */
27 /*  ======= */
28
29 /*  SLAGTF factorizes the matrix (T - lambda*I), where T is an n by n */
30 /*  tridiagonal matrix and lambda is a scalar, as */
31
32 /*     T - lambda*I = PLU, */
33
34 /*  where P is a permutation matrix, L is a unit lower tridiagonal matrix */
35 /*  with at most one non-zero sub-diagonal elements per column and U is */
36 /*  an upper triangular matrix with at most two non-zero super-diagonal */
37 /*  elements per column. */
38
39 /*  The factorization is obtained by Gaussian elimination with partial */
40 /*  pivoting and implicit row scaling. */
41
42 /*  The parameter LAMBDA is included in the routine so that SLAGTF may */
43 /*  be used, in conjunction with SLAGTS, to obtain eigenvectors of T by */
44 /*  inverse iteration. */
45
46 /*  Arguments */
47 /*  ========= */
48
49 /*  N       (input) INTEGER */
50 /*          The order of the matrix T. */
51
52 /*  A       (input/output) REAL array, dimension (N) */
53 /*          On entry, A must contain the diagonal elements of T. */
54
55 /*          On exit, A is overwritten by the n diagonal elements of the */
56 /*          upper triangular matrix U of the factorization of T. */
57
58 /*  LAMBDA  (input) REAL */
59 /*          On entry, the scalar lambda. */
60
61 /*  B       (input/output) REAL array, dimension (N-1) */
62 /*          On entry, B must contain the (n-1) super-diagonal elements of */
63 /*          T. */
64
65 /*          On exit, B is overwritten by the (n-1) super-diagonal */
66 /*          elements of the matrix U of the factorization of T. */
67
68 /*  C       (input/output) REAL array, dimension (N-1) */
69 /*          On entry, C must contain the (n-1) sub-diagonal elements of */
70 /*          T. */
71
72 /*          On exit, C is overwritten by the (n-1) sub-diagonal elements */
73 /*          of the matrix L of the factorization of T. */
74
75 /*  TOL     (input) REAL */
76 /*          On entry, a relative tolerance used to indicate whether or */
77 /*          not the matrix (T - lambda*I) is nearly singular. TOL should */
78 /*          normally be chose as approximately the largest relative error */
79 /*          in the elements of T. For example, if the elements of T are */
80 /*          correct to about 4 significant figures, then TOL should be */
81 /*          set to about 5*10**(-4). If TOL is supplied as less than eps, */
82 /*          where eps is the relative machine precision, then the value */
83 /*          eps is used in place of TOL. */
84
85 /*  D       (output) REAL array, dimension (N-2) */
86 /*          On exit, D is overwritten by the (n-2) second super-diagonal */
87 /*          elements of the matrix U of the factorization of T. */
88
89 /*  IN      (output) INTEGER array, dimension (N) */
90 /*          On exit, IN contains details of the permutation matrix P. If */
91 /*          an interchange occurred at the kth step of the elimination, */
92 /*          then IN(k) = 1, otherwise IN(k) = 0. The element IN(n) */
93 /*          returns the smallest positive integer j such that */
94
95 /*             abs( u(j,j) ).le. norm( (T - lambda*I)(j) )*TOL, */
96
97 /*          where norm( A(j) ) denotes the sum of the absolute values of */
98 /*          the jth row of the matrix A. If no such j exists then IN(n) */
99 /*          is returned as zero. If IN(n) is returned as positive, then a */
100 /*          diagonal element of U is small, indicating that */
101 /*          (T - lambda*I) is singular or nearly singular, */
102
103 /*  INFO    (output) INTEGER */
104 /*          = 0   : successful exit */
105 /*          .lt. 0: if INFO = -k, the kth argument had an illegal value */
106
107 /* ===================================================================== */
108
109 /*     .. Parameters .. */
110 /*     .. */
111 /*     .. Local Scalars .. */
112 /*     .. */
113 /*     .. Intrinsic Functions .. */
114 /*     .. */
115 /*     .. External Functions .. */
116 /*     .. */
117 /*     .. External Subroutines .. */
118 /*     .. */
119 /*     .. Executable Statements .. */
120
121     /* Parameter adjustments */
122     --in;
123     --d__;
124     --c__;
125     --b;
126     --a;
127
128     /* Function Body */
129     *info = 0;
130     if (*n < 0) {
131         *info = -1;
132         i__1 = -(*info);
133         xerbla_("SLAGTF", &i__1);
134         return 0;
135     }
136
137     if (*n == 0) {
138         return 0;
139     }
140
141     a[1] -= *lambda;
142     in[*n] = 0;
143     if (*n == 1) {
144         if (a[1] == 0.f) {
145             in[1] = 1;
146         }
147         return 0;
148     }
149
150     eps = slamch_("Epsilon");
151
152     tl = dmax(*tol,eps);
153     scale1 = dabs(a[1]) + dabs(b[1]);
154     i__1 = *n - 1;
155     for (k = 1; k <= i__1; ++k) {
156         a[k + 1] -= *lambda;
157         scale2 = (r__1 = c__[k], dabs(r__1)) + (r__2 = a[k + 1], dabs(r__2));
158         if (k < *n - 1) {
159             scale2 += (r__1 = b[k + 1], dabs(r__1));
160         }
161         if (a[k] == 0.f) {
162             piv1 = 0.f;
163         } else {
164             piv1 = (r__1 = a[k], dabs(r__1)) / scale1;
165         }
166         if (c__[k] == 0.f) {
167             in[k] = 0;
168             piv2 = 0.f;
169             scale1 = scale2;
170             if (k < *n - 1) {
171                 d__[k] = 0.f;
172             }
173         } else {
174             piv2 = (r__1 = c__[k], dabs(r__1)) / scale2;
175             if (piv2 <= piv1) {
176                 in[k] = 0;
177                 scale1 = scale2;
178                 c__[k] /= a[k];
179                 a[k + 1] -= c__[k] * b[k];
180                 if (k < *n - 1) {
181                     d__[k] = 0.f;
182                 }
183             } else {
184                 in[k] = 1;
185                 mult = a[k] / c__[k];
186                 a[k] = c__[k];
187                 temp = a[k + 1];
188                 a[k + 1] = b[k] - mult * temp;
189                 if (k < *n - 1) {
190                     d__[k] = b[k + 1];
191                     b[k + 1] = -mult * d__[k];
192                 }
193                 b[k] = temp;
194                 c__[k] = mult;
195             }
196         }
197         if (dmax(piv1,piv2) <= tl && in[*n] == 0) {
198             in[*n] = k;
199         }
200 /* L10: */
201     }
202     if ((r__1 = a[*n], dabs(r__1)) <= scale1 * tl && in[*n] == 0) {
203         in[*n] = *n;
204     }
205
206     return 0;
207
208 /*     End of SLAGTF */
209
210 } /* slagtf_ */