Line data Source code
1 :
2 : /* -- translated by f2c (version 19940927).
3 : You must link the resulting object file with the libraries:
4 : -lf2c -lm (in that order)
5 : */
6 : #include <string.h>
7 : #include "f2c.h"
8 :
9 0 : /* Subroutine */ void dtrsv_(char *uplo, char *trans, char *diag, integer *n,
10 : doublereal *a, integer *lda, doublereal *x, integer *incx)
11 : {
12 :
13 :
14 : /* System generated locals */
15 :
16 : /* Local variables */
17 : integer info;
18 : doublereal temp;
19 : integer i, j;
20 : integer ix, jx, kx;
21 : logical nounit;
22 :
23 : extern int input_error(char *, int *);
24 :
25 : /* Purpose
26 : =======
27 :
28 : DTRSV solves one of the systems of equations
29 :
30 : A*x = b, or A'*x = b,
31 :
32 : where b and x are n element vectors and A is an n by n unit, or
33 : non-unit, upper or lower triangular matrix.
34 :
35 : No test for singularity or near-singularity is included in this
36 : routine. Such tests must be performed before calling this routine.
37 :
38 : Parameters
39 : ==========
40 :
41 : UPLO - CHARACTER*1.
42 : On entry, UPLO specifies whether the matrix is an upper or
43 : lower triangular matrix as follows:
44 :
45 : UPLO = 'U' or 'u' A is an upper triangular matrix.
46 :
47 : UPLO = 'L' or 'l' A is a lower triangular matrix.
48 :
49 : Unchanged on exit.
50 :
51 : TRANS - CHARACTER*1.
52 : On entry, TRANS specifies the equations to be solved as
53 : follows:
54 :
55 : TRANS = 'N' or 'n' A*x = b.
56 :
57 : TRANS = 'T' or 't' A'*x = b.
58 :
59 : TRANS = 'C' or 'c' A'*x = b.
60 :
61 : Unchanged on exit.
62 :
63 : DIAG - CHARACTER*1.
64 : On entry, DIAG specifies whether or not A is unit
65 : triangular as follows:
66 :
67 : DIAG = 'U' or 'u' A is assumed to be unit triangular.
68 :
69 : DIAG = 'N' or 'n' A is not assumed to be unit
70 : triangular.
71 :
72 : Unchanged on exit.
73 :
74 : N - INTEGER.
75 : On entry, N specifies the order of the matrix A.
76 : N must be at least zero.
77 : Unchanged on exit.
78 :
79 : A - DOUBLE PRECISION array of DIMENSION ( LDA, n ).
80 : Before entry with UPLO = 'U' or 'u', the leading n by n
81 : upper triangular part of the array A must contain the upper
82 :
83 : triangular matrix and the strictly lower triangular part of
84 :
85 : A is not referenced.
86 : Before entry with UPLO = 'L' or 'l', the leading n by n
87 : lower triangular part of the array A must contain the lower
88 :
89 : triangular matrix and the strictly upper triangular part of
90 :
91 : A is not referenced.
92 : Note that when DIAG = 'U' or 'u', the diagonal elements of
93 :
94 : A are not referenced either, but are assumed to be unity.
95 : Unchanged on exit.
96 :
97 : LDA - INTEGER.
98 : On entry, LDA specifies the first dimension of A as declared
99 :
100 : in the calling (sub) program. LDA must be at least
101 : max( 1, n ).
102 : Unchanged on exit.
103 :
104 : X - DOUBLE PRECISION array of dimension at least
105 : ( 1 + ( n - 1 )*abs( INCX ) ).
106 : Before entry, the incremented array X must contain the n
107 : element right-hand side vector b. On exit, X is overwritten
108 :
109 : with the solution vector x.
110 :
111 : INCX - INTEGER.
112 : On entry, INCX specifies the increment for the elements of
113 : X. INCX must not be zero.
114 : Unchanged on exit.
115 :
116 :
117 : Level 2 Blas routine.
118 :
119 : -- Written on 22-October-1986.
120 : Jack Dongarra, Argonne National Lab.
121 : Jeremy Du Croz, Nag Central Office.
122 : Sven Hammarling, Nag Central Office.
123 : Richard Hanson, Sandia National Labs.
124 :
125 :
126 :
127 : Test the input parameters.
128 :
129 :
130 : Parameter adjustments
131 : Function Body */
132 : #define X(I) x[(I)-1]
133 :
134 : #define A(I,J) a[(I)-1 + ((J)-1)* ( *lda)]
135 :
136 0 : info = 0;
137 0 : if ( strncmp(uplo, "U", 1)!=0 && strncmp(uplo, "L", 1)!=0 ) {
138 0 : info = 1;
139 0 : } else if ( strncmp(trans, "N", 1)!=0 && strncmp(trans, "T", 1)!=0 &&
140 : strncmp(trans, "C", 1)!=0 ) {
141 0 : info = 2;
142 0 : } else if ( strncmp(diag, "U", 1)!=0 && strncmp(diag, "N", 1)!=0 ) {
143 0 : info = 3;
144 0 : } else if (*n < 0) {
145 0 : info = 4;
146 0 : } else if (*lda < max(1,*n)) {
147 0 : info = 6;
148 0 : } else if (*incx == 0) {
149 0 : info = 8;
150 : }
151 0 : if (info != 0) {
152 0 : input_error("DTRSV ", &info);
153 0 : return;
154 : }
155 :
156 : /* Quick return if possible. */
157 :
158 0 : if (*n == 0) {
159 : return;
160 : }
161 :
162 0 : nounit = (strncmp(diag, "N", 1)==0);
163 :
164 : /* Set up the start point in X if the increment is not unity. This
165 : will be ( N - 1 )*INCX too small for descending loops. */
166 :
167 0 : if (*incx <= 0) {
168 0 : kx = 1 - (*n - 1) * *incx;
169 0 : } else if (*incx != 1) {
170 : kx = 1;
171 : }
172 :
173 : /* Start the operations. In this version the elements of A are
174 : accessed sequentially with one pass through A. */
175 :
176 0 : if (strncmp(trans, "N", 1)==0) {
177 :
178 : /* Form x := inv( A )*x. */
179 :
180 0 : if (strncmp(uplo, "U", 1)==0) {
181 0 : if (*incx == 1) {
182 0 : for (j = *n; j >= 1; --j) {
183 0 : if (X(j) != 0.) {
184 0 : if (nounit) {
185 0 : X(j) /= A(j,j);
186 : }
187 0 : temp = X(j);
188 0 : for (i = j - 1; i >= 1; --i) {
189 0 : X(i) -= temp * A(i,j);
190 : /* L10: */
191 : }
192 : }
193 : /* L20: */
194 : }
195 : } else {
196 0 : jx = kx + (*n - 1) * *incx;
197 0 : for (j = *n; j >= 1; --j) {
198 0 : if (X(jx) != 0.) {
199 0 : if (nounit) {
200 0 : X(jx) /= A(j,j);
201 : }
202 0 : temp = X(jx);
203 : ix = jx;
204 0 : for (i = j - 1; i >= 1; --i) {
205 0 : ix -= *incx;
206 0 : X(ix) -= temp * A(i,j);
207 : /* L30: */
208 : }
209 : }
210 0 : jx -= *incx;
211 : /* L40: */
212 : }
213 : }
214 : } else {
215 0 : if (*incx == 1) {
216 0 : for (j = 1; j <= *n; ++j) {
217 0 : if (X(j) != 0.) {
218 0 : if (nounit) {
219 0 : X(j) /= A(j,j);
220 : }
221 0 : temp = X(j);
222 0 : for (i = j + 1; i <= *n; ++i) {
223 0 : X(i) -= temp * A(i,j);
224 : /* L50: */
225 : }
226 : }
227 : /* L60: */
228 : }
229 : } else {
230 : jx = kx;
231 0 : for (j = 1; j <= *n; ++j) {
232 0 : if (X(jx) != 0.) {
233 0 : if (nounit) {
234 0 : X(jx) /= A(j,j);
235 : }
236 0 : temp = X(jx);
237 : ix = jx;
238 0 : for (i = j + 1; i <= *n; ++i) {
239 0 : ix += *incx;
240 0 : X(ix) -= temp * A(i,j);
241 : /* L70: */
242 : }
243 : }
244 0 : jx += *incx;
245 : /* L80: */
246 : }
247 : }
248 : }
249 : } else {
250 :
251 : /* Form x := inv( A' )*x. */
252 :
253 0 : if (strncmp(uplo, "U", 1)==0) {
254 0 : if (*incx == 1) {
255 0 : for (j = 1; j <= *n; ++j) {
256 0 : temp = X(j);
257 0 : for (i = 1; i <= j-1; ++i) {
258 0 : temp -= A(i,j) * X(i);
259 : /* L90: */
260 : }
261 0 : if (nounit) {
262 0 : temp /= A(j,j);
263 : }
264 0 : X(j) = temp;
265 : /* L100: */
266 : }
267 : } else {
268 : jx = kx;
269 0 : for (j = 1; j <= *n; ++j) {
270 0 : temp = X(jx);
271 : ix = kx;
272 0 : for (i = 1; i <= j-1; ++i) {
273 0 : temp -= A(i,j) * X(ix);
274 0 : ix += *incx;
275 : /* L110: */
276 : }
277 0 : if (nounit) {
278 0 : temp /= A(j,j);
279 : }
280 0 : X(jx) = temp;
281 0 : jx += *incx;
282 : /* L120: */
283 : }
284 : }
285 : } else {
286 0 : if (*incx == 1) {
287 0 : for (j = *n; j >= 1; --j) {
288 0 : temp = X(j);
289 0 : for (i = *n; i >= j+1; --i) {
290 0 : temp -= A(i,j) * X(i);
291 : /* L130: */
292 : }
293 0 : if (nounit) {
294 0 : temp /= A(j,j);
295 : }
296 0 : X(j) = temp;
297 : /* L140: */
298 : }
299 : } else {
300 0 : kx += (*n - 1) * *incx;
301 : jx = kx;
302 0 : for (j = *n; j >= 1; --j) {
303 0 : temp = X(jx);
304 : ix = kx;
305 0 : for (i = *n; i >= j+1; --i) {
306 0 : temp -= A(i,j) * X(ix);
307 0 : ix -= *incx;
308 : /* L150: */
309 : }
310 0 : if (nounit) {
311 0 : temp /= A(j,j);
312 : }
313 0 : X(jx) = temp;
314 0 : jx -= *incx;
315 : /* L160: */
316 : }
317 : }
318 : }
319 : }
320 :
321 : return;
322 :
323 : /* End of DTRSV . */
324 :
325 : } /* dtrsv_ */
326 :
|