1 /* stpmv.f -- translated by f2c (version 20061008).
2    You must link the resulting object file with libf2c:
3 	on Microsoft Windows system, link with libf2c.lib;
4 	on Linux or Unix systems, link with .../path/to/libf2c.a -lm
5 	or, if you install libf2c.a in a standard place, with -lf2c -lm
6 	-- in that order, at the end of the command line, as in
7 		cc *.o -lf2c -lm
8 	Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
9 
10 		http://www.netlib.org/f2c/libf2c.zip
11 */
12 
13 #include "f2c.h"
14 #include "blaswrap.h"
15 
stpmv_(char * uplo,char * trans,char * diag,integer * n,real * ap,real * x,integer * incx)16 /* Subroutine */ int stpmv_(char *uplo, char *trans, char *diag, integer *n,
17 	real *ap, real *x, integer *incx)
18 {
19     /* System generated locals */
20     integer i__1, i__2;
21 
22     /* Local variables */
23     integer i__, j, k, kk, ix, jx, kx, info;
24     real temp;
25     extern logical lsame_(char *, char *);
26     extern /* Subroutine */ int xerbla_(char *, integer *);
27     logical nounit;
28 
29 /*     .. Scalar Arguments .. */
30 /*     .. */
31 /*     .. Array Arguments .. */
32 /*     .. */
33 
34 /*  Purpose */
35 /*  ======= */
36 
37 /*  STPMV  performs one of the matrix-vector operations */
38 
39 /*     x := A*x,   or   x := A'*x, */
40 
41 /*  where x is an n element vector and  A is an n by n unit, or non-unit, */
42 /*  upper or lower triangular matrix, supplied in packed form. */
43 
44 /*  Arguments */
45 /*  ========== */
46 
47 /*  UPLO   - CHARACTER*1. */
48 /*           On entry, UPLO specifies whether the matrix is an upper or */
49 /*           lower triangular matrix as follows: */
50 
51 /*              UPLO = 'U' or 'u'   A is an upper triangular matrix. */
52 
53 /*              UPLO = 'L' or 'l'   A is a lower triangular matrix. */
54 
55 /*           Unchanged on exit. */
56 
57 /*  TRANS  - CHARACTER*1. */
58 /*           On entry, TRANS specifies the operation to be performed as */
59 /*           follows: */
60 
61 /*              TRANS = 'N' or 'n'   x := A*x. */
62 
63 /*              TRANS = 'T' or 't'   x := A'*x. */
64 
65 /*              TRANS = 'C' or 'c'   x := A'*x. */
66 
67 /*           Unchanged on exit. */
68 
69 /*  DIAG   - CHARACTER*1. */
70 /*           On entry, DIAG specifies whether or not A is unit */
71 /*           triangular as follows: */
72 
73 /*              DIAG = 'U' or 'u'   A is assumed to be unit triangular. */
74 
75 /*              DIAG = 'N' or 'n'   A is not assumed to be unit */
76 /*                                  triangular. */
77 
78 /*           Unchanged on exit. */
79 
80 /*  N      - INTEGER. */
81 /*           On entry, N specifies the order of the matrix A. */
82 /*           N must be at least zero. */
83 /*           Unchanged on exit. */
84 
85 /*  AP     - REAL             array of DIMENSION at least */
86 /*           ( ( n*( n + 1 ) )/2 ). */
87 /*           Before entry with  UPLO = 'U' or 'u', the array AP must */
88 /*           contain the upper triangular matrix packed sequentially, */
89 /*           column by column, so that AP( 1 ) contains a( 1, 1 ), */
90 /*           AP( 2 ) and AP( 3 ) contain a( 1, 2 ) and a( 2, 2 ) */
91 /*           respectively, and so on. */
92 /*           Before entry with UPLO = 'L' or 'l', the array AP must */
93 /*           contain the lower triangular matrix packed sequentially, */
94 /*           column by column, so that AP( 1 ) contains a( 1, 1 ), */
95 /*           AP( 2 ) and AP( 3 ) contain a( 2, 1 ) and a( 3, 1 ) */
96 /*           respectively, and so on. */
97 /*           Note that when  DIAG = 'U' or 'u', the diagonal elements of */
98 /*           A are not referenced, but are assumed to be unity. */
99 /*           Unchanged on exit. */
100 
101 /*  X      - REAL             array of dimension at least */
102 /*           ( 1 + ( n - 1 )*abs( INCX ) ). */
103 /*           Before entry, the incremented array X must contain the n */
104 /*           element vector x. On exit, X is overwritten with the */
105 /*           tranformed vector x. */
106 
107 /*  INCX   - INTEGER. */
108 /*           On entry, INCX specifies the increment for the elements of */
109 /*           X. INCX must not be zero. */
110 /*           Unchanged on exit. */
111 
112 
113 /*  Level 2 Blas routine. */
114 
115 /*  -- Written on 22-October-1986. */
116 /*     Jack Dongarra, Argonne National Lab. */
117 /*     Jeremy Du Croz, Nag Central Office. */
118 /*     Sven Hammarling, Nag Central Office. */
119 /*     Richard Hanson, Sandia National Labs. */
120 
121 
122 /*     .. Parameters .. */
123 /*     .. */
124 /*     .. Local Scalars .. */
125 /*     .. */
126 /*     .. External Functions .. */
127 /*     .. */
128 /*     .. External Subroutines .. */
129 /*     .. */
130 
131 /*     Test the input parameters. */
132 
133     /* Parameter adjustments */
134     --x;
135     --ap;
136 
137     /* Function Body */
138     info = 0;
139     if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) {
140 	info = 1;
141     } else if (! lsame_(trans, "N") && ! lsame_(trans,
142 	    "T") && ! lsame_(trans, "C")) {
143 	info = 2;
144     } else if (! lsame_(diag, "U") && ! lsame_(diag,
145 	    "N")) {
146 	info = 3;
147     } else if (*n < 0) {
148 	info = 4;
149     } else if (*incx == 0) {
150 	info = 7;
151     }
152     if (info != 0) {
153 	xerbla_("STPMV ", &info);
154 	return 0;
155     }
156 
157 /*     Quick return if possible. */
158 
159     if (*n == 0) {
160 	return 0;
161     }
162 
163     nounit = lsame_(diag, "N");
164 
165 /*     Set up the start point in X if the increment is not unity. This */
166 /*     will be  ( N - 1 )*INCX  too small for descending loops. */
167 
168     if (*incx <= 0) {
169 	kx = 1 - (*n - 1) * *incx;
170     } else if (*incx != 1) {
171 	kx = 1;
172     }
173 
174 /*     Start the operations. In this version the elements of AP are */
175 /*     accessed sequentially with one pass through AP. */
176 
177     if (lsame_(trans, "N")) {
178 
179 /*        Form  x:= A*x. */
180 
181 	if (lsame_(uplo, "U")) {
182 	    kk = 1;
183 	    if (*incx == 1) {
184 		i__1 = *n;
185 		for (j = 1; j <= i__1; ++j) {
186 		    if (x[j] != 0.f) {
187 			temp = x[j];
188 			k = kk;
189 			i__2 = j - 1;
190 			for (i__ = 1; i__ <= i__2; ++i__) {
191 			    x[i__] += temp * ap[k];
192 			    ++k;
193 /* L10: */
194 			}
195 			if (nounit) {
196 			    x[j] *= ap[kk + j - 1];
197 			}
198 		    }
199 		    kk += j;
200 /* L20: */
201 		}
202 	    } else {
203 		jx = kx;
204 		i__1 = *n;
205 		for (j = 1; j <= i__1; ++j) {
206 		    if (x[jx] != 0.f) {
207 			temp = x[jx];
208 			ix = kx;
209 			i__2 = kk + j - 2;
210 			for (k = kk; k <= i__2; ++k) {
211 			    x[ix] += temp * ap[k];
212 			    ix += *incx;
213 /* L30: */
214 			}
215 			if (nounit) {
216 			    x[jx] *= ap[kk + j - 1];
217 			}
218 		    }
219 		    jx += *incx;
220 		    kk += j;
221 /* L40: */
222 		}
223 	    }
224 	} else {
225 	    kk = *n * (*n + 1) / 2;
226 	    if (*incx == 1) {
227 		for (j = *n; j >= 1; --j) {
228 		    if (x[j] != 0.f) {
229 			temp = x[j];
230 			k = kk;
231 			i__1 = j + 1;
232 			for (i__ = *n; i__ >= i__1; --i__) {
233 			    x[i__] += temp * ap[k];
234 			    --k;
235 /* L50: */
236 			}
237 			if (nounit) {
238 			    x[j] *= ap[kk - *n + j];
239 			}
240 		    }
241 		    kk -= *n - j + 1;
242 /* L60: */
243 		}
244 	    } else {
245 		kx += (*n - 1) * *incx;
246 		jx = kx;
247 		for (j = *n; j >= 1; --j) {
248 		    if (x[jx] != 0.f) {
249 			temp = x[jx];
250 			ix = kx;
251 			i__1 = kk - (*n - (j + 1));
252 			for (k = kk; k >= i__1; --k) {
253 			    x[ix] += temp * ap[k];
254 			    ix -= *incx;
255 /* L70: */
256 			}
257 			if (nounit) {
258 			    x[jx] *= ap[kk - *n + j];
259 			}
260 		    }
261 		    jx -= *incx;
262 		    kk -= *n - j + 1;
263 /* L80: */
264 		}
265 	    }
266 	}
267     } else {
268 
269 /*        Form  x := A'*x. */
270 
271 	if (lsame_(uplo, "U")) {
272 	    kk = *n * (*n + 1) / 2;
273 	    if (*incx == 1) {
274 		for (j = *n; j >= 1; --j) {
275 		    temp = x[j];
276 		    if (nounit) {
277 			temp *= ap[kk];
278 		    }
279 		    k = kk - 1;
280 		    for (i__ = j - 1; i__ >= 1; --i__) {
281 			temp += ap[k] * x[i__];
282 			--k;
283 /* L90: */
284 		    }
285 		    x[j] = temp;
286 		    kk -= j;
287 /* L100: */
288 		}
289 	    } else {
290 		jx = kx + (*n - 1) * *incx;
291 		for (j = *n; j >= 1; --j) {
292 		    temp = x[jx];
293 		    ix = jx;
294 		    if (nounit) {
295 			temp *= ap[kk];
296 		    }
297 		    i__1 = kk - j + 1;
298 		    for (k = kk - 1; k >= i__1; --k) {
299 			ix -= *incx;
300 			temp += ap[k] * x[ix];
301 /* L110: */
302 		    }
303 		    x[jx] = temp;
304 		    jx -= *incx;
305 		    kk -= j;
306 /* L120: */
307 		}
308 	    }
309 	} else {
310 	    kk = 1;
311 	    if (*incx == 1) {
312 		i__1 = *n;
313 		for (j = 1; j <= i__1; ++j) {
314 		    temp = x[j];
315 		    if (nounit) {
316 			temp *= ap[kk];
317 		    }
318 		    k = kk + 1;
319 		    i__2 = *n;
320 		    for (i__ = j + 1; i__ <= i__2; ++i__) {
321 			temp += ap[k] * x[i__];
322 			++k;
323 /* L130: */
324 		    }
325 		    x[j] = temp;
326 		    kk += *n - j + 1;
327 /* L140: */
328 		}
329 	    } else {
330 		jx = kx;
331 		i__1 = *n;
332 		for (j = 1; j <= i__1; ++j) {
333 		    temp = x[jx];
334 		    ix = jx;
335 		    if (nounit) {
336 			temp *= ap[kk];
337 		    }
338 		    i__2 = kk + *n - j;
339 		    for (k = kk + 1; k <= i__2; ++k) {
340 			ix += *incx;
341 			temp += ap[k] * x[ix];
342 /* L150: */
343 		    }
344 		    x[jx] = temp;
345 		    jx += *incx;
346 		    kk += *n - j + 1;
347 /* L160: */
348 		}
349 	    }
350 	}
351     }
352 
353     return 0;
354 
355 /*     End of STPMV . */
356 
357 } /* stpmv_ */
358