Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / dsyrk.c
1 #include "clapack.h"
2
3 /* Subroutine */ int dsyrk_(char *uplo, char *trans, integer *n, integer *k, 
4         doublereal *alpha, doublereal *a, integer *lda, doublereal *beta, 
5         doublereal *c__, integer *ldc)
6 {
7     /* System generated locals */
8     integer a_dim1, a_offset, c_dim1, c_offset, i__1, i__2, i__3;
9
10     /* Local variables */
11     integer i__, j, l, info;
12     doublereal temp;
13     extern logical lsame_(char *, char *);
14     integer nrowa;
15     logical upper;
16     extern /* Subroutine */ int xerbla_(char *, integer *);
17
18 /*     .. Scalar Arguments .. */
19 /*     .. */
20 /*     .. Array Arguments .. */
21 /*     .. */
22
23 /*  Purpose */
24 /*  ======= */
25
26 /*  DSYRK  performs one of the symmetric rank k operations */
27
28 /*     C := alpha*A*A' + beta*C, */
29
30 /*  or */
31
32 /*     C := alpha*A'*A + beta*C, */
33
34 /*  where  alpha and beta  are scalars, C is an  n by n  symmetric matrix */
35 /*  and  A  is an  n by k  matrix in the first case and a  k by n  matrix */
36 /*  in the second case. */
37
38 /*  Arguments */
39 /*  ========== */
40
41 /*  UPLO   - CHARACTER*1. */
42 /*           On  entry,   UPLO  specifies  whether  the  upper  or  lower */
43 /*           triangular  part  of the  array  C  is to be  referenced  as */
44 /*           follows: */
45
46 /*              UPLO = 'U' or 'u'   Only the  upper triangular part of  C */
47 /*                                  is to be referenced. */
48
49 /*              UPLO = 'L' or 'l'   Only the  lower triangular part of  C */
50 /*                                  is to be referenced. */
51
52 /*           Unchanged on exit. */
53
54 /*  TRANS  - CHARACTER*1. */
55 /*           On entry,  TRANS  specifies the operation to be performed as */
56 /*           follows: */
57
58 /*              TRANS = 'N' or 'n'   C := alpha*A*A' + beta*C. */
59
60 /*              TRANS = 'T' or 't'   C := alpha*A'*A + beta*C. */
61
62 /*              TRANS = 'C' or 'c'   C := alpha*A'*A + beta*C. */
63
64 /*           Unchanged on exit. */
65
66 /*  N      - INTEGER. */
67 /*           On entry,  N specifies the order of the matrix C.  N must be */
68 /*           at least zero. */
69 /*           Unchanged on exit. */
70
71 /*  K      - INTEGER. */
72 /*           On entry with  TRANS = 'N' or 'n',  K  specifies  the number */
73 /*           of  columns   of  the   matrix   A,   and  on   entry   with */
74 /*           TRANS = 'T' or 't' or 'C' or 'c',  K  specifies  the  number */
75 /*           of rows of the matrix  A.  K must be at least zero. */
76 /*           Unchanged on exit. */
77
78 /*  ALPHA  - DOUBLE PRECISION. */
79 /*           On entry, ALPHA specifies the scalar alpha. */
80 /*           Unchanged on exit. */
81
82 /*  A      - DOUBLE PRECISION array of DIMENSION ( LDA, ka ), where ka is */
83 /*           k  when  TRANS = 'N' or 'n',  and is  n  otherwise. */
84 /*           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k */
85 /*           part of the array  A  must contain the matrix  A,  otherwise */
86 /*           the leading  k by n  part of the array  A  must contain  the */
87 /*           matrix A. */
88 /*           Unchanged on exit. */
89
90 /*  LDA    - INTEGER. */
91 /*           On entry, LDA specifies the first dimension of A as declared */
92 /*           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n' */
93 /*           then  LDA must be at least  max( 1, n ), otherwise  LDA must */
94 /*           be at least  max( 1, k ). */
95 /*           Unchanged on exit. */
96
97 /*  BETA   - DOUBLE PRECISION. */
98 /*           On entry, BETA specifies the scalar beta. */
99 /*           Unchanged on exit. */
100
101 /*  C      - DOUBLE PRECISION array of DIMENSION ( LDC, n ). */
102 /*           Before entry  with  UPLO = 'U' or 'u',  the leading  n by n */
103 /*           upper triangular part of the array C must contain the upper */
104 /*           triangular part  of the  symmetric matrix  and the strictly */
105 /*           lower triangular part of C is not referenced.  On exit, the */
106 /*           upper triangular part of the array  C is overwritten by the */
107 /*           upper triangular part of the updated matrix. */
108 /*           Before entry  with  UPLO = 'L' or 'l',  the leading  n by n */
109 /*           lower triangular part of the array C must contain the lower */
110 /*           triangular part  of the  symmetric matrix  and the strictly */
111 /*           upper triangular part of C is not referenced.  On exit, the */
112 /*           lower triangular part of the array  C is overwritten by the */
113 /*           lower triangular part of the updated matrix. */
114
115 /*  LDC    - INTEGER. */
116 /*           On entry, LDC specifies the first dimension of C as declared */
117 /*           in  the  calling  (sub)  program.   LDC  must  be  at  least */
118 /*           max( 1, n ). */
119 /*           Unchanged on exit. */
120
121
122 /*  Level 3 Blas routine. */
123
124 /*  -- Written on 8-February-1989. */
125 /*     Jack Dongarra, Argonne National Laboratory. */
126 /*     Iain Duff, AERE Harwell. */
127 /*     Jeremy Du Croz, Numerical Algorithms Group Ltd. */
128 /*     Sven Hammarling, Numerical Algorithms Group Ltd. */
129
130
131 /*     .. External Functions .. */
132 /*     .. */
133 /*     .. External Subroutines .. */
134 /*     .. */
135 /*     .. Intrinsic Functions .. */
136 /*     .. */
137 /*     .. Local Scalars .. */
138 /*     .. */
139 /*     .. Parameters .. */
140 /*     .. */
141
142 /*     Test the input parameters. */
143
144     /* Parameter adjustments */
145     a_dim1 = *lda;
146     a_offset = 1 + a_dim1;
147     a -= a_offset;
148     c_dim1 = *ldc;
149     c_offset = 1 + c_dim1;
150     c__ -= c_offset;
151
152     /* Function Body */
153     if (lsame_(trans, "N")) {
154         nrowa = *n;
155     } else {
156         nrowa = *k;
157     }
158     upper = lsame_(uplo, "U");
159
160     info = 0;
161     if (! upper && ! lsame_(uplo, "L")) {
162         info = 1;
163     } else if (! lsame_(trans, "N") && ! lsame_(trans, 
164             "T") && ! lsame_(trans, "C")) {
165         info = 2;
166     } else if (*n < 0) {
167         info = 3;
168     } else if (*k < 0) {
169         info = 4;
170     } else if (*lda < max(1,nrowa)) {
171         info = 7;
172     } else if (*ldc < max(1,*n)) {
173         info = 10;
174     }
175     if (info != 0) {
176         xerbla_("DSYRK ", &info);
177         return 0;
178     }
179
180 /*     Quick return if possible. */
181
182     if (*n == 0 || (*alpha == 0. || *k == 0) && *beta == 1.) {
183         return 0;
184     }
185
186 /*     And when  alpha.eq.zero. */
187
188     if (*alpha == 0.) {
189         if (upper) {
190             if (*beta == 0.) {
191                 i__1 = *n;
192                 for (j = 1; j <= i__1; ++j) {
193                     i__2 = j;
194                     for (i__ = 1; i__ <= i__2; ++i__) {
195                         c__[i__ + j * c_dim1] = 0.;
196 /* L10: */
197                     }
198 /* L20: */
199                 }
200             } else {
201                 i__1 = *n;
202                 for (j = 1; j <= i__1; ++j) {
203                     i__2 = j;
204                     for (i__ = 1; i__ <= i__2; ++i__) {
205                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
206 /* L30: */
207                     }
208 /* L40: */
209                 }
210             }
211         } else {
212             if (*beta == 0.) {
213                 i__1 = *n;
214                 for (j = 1; j <= i__1; ++j) {
215                     i__2 = *n;
216                     for (i__ = j; i__ <= i__2; ++i__) {
217                         c__[i__ + j * c_dim1] = 0.;
218 /* L50: */
219                     }
220 /* L60: */
221                 }
222             } else {
223                 i__1 = *n;
224                 for (j = 1; j <= i__1; ++j) {
225                     i__2 = *n;
226                     for (i__ = j; i__ <= i__2; ++i__) {
227                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
228 /* L70: */
229                     }
230 /* L80: */
231                 }
232             }
233         }
234         return 0;
235     }
236
237 /*     Start the operations. */
238
239     if (lsame_(trans, "N")) {
240
241 /*        Form  C := alpha*A*A' + beta*C. */
242
243         if (upper) {
244             i__1 = *n;
245             for (j = 1; j <= i__1; ++j) {
246                 if (*beta == 0.) {
247                     i__2 = j;
248                     for (i__ = 1; i__ <= i__2; ++i__) {
249                         c__[i__ + j * c_dim1] = 0.;
250 /* L90: */
251                     }
252                 } else if (*beta != 1.) {
253                     i__2 = j;
254                     for (i__ = 1; i__ <= i__2; ++i__) {
255                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
256 /* L100: */
257                     }
258                 }
259                 i__2 = *k;
260                 for (l = 1; l <= i__2; ++l) {
261                     if (a[j + l * a_dim1] != 0.) {
262                         temp = *alpha * a[j + l * a_dim1];
263                         i__3 = j;
264                         for (i__ = 1; i__ <= i__3; ++i__) {
265                             c__[i__ + j * c_dim1] += temp * a[i__ + l * 
266                                     a_dim1];
267 /* L110: */
268                         }
269                     }
270 /* L120: */
271                 }
272 /* L130: */
273             }
274         } else {
275             i__1 = *n;
276             for (j = 1; j <= i__1; ++j) {
277                 if (*beta == 0.) {
278                     i__2 = *n;
279                     for (i__ = j; i__ <= i__2; ++i__) {
280                         c__[i__ + j * c_dim1] = 0.;
281 /* L140: */
282                     }
283                 } else if (*beta != 1.) {
284                     i__2 = *n;
285                     for (i__ = j; i__ <= i__2; ++i__) {
286                         c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1];
287 /* L150: */
288                     }
289                 }
290                 i__2 = *k;
291                 for (l = 1; l <= i__2; ++l) {
292                     if (a[j + l * a_dim1] != 0.) {
293                         temp = *alpha * a[j + l * a_dim1];
294                         i__3 = *n;
295                         for (i__ = j; i__ <= i__3; ++i__) {
296                             c__[i__ + j * c_dim1] += temp * a[i__ + l * 
297                                     a_dim1];
298 /* L160: */
299                         }
300                     }
301 /* L170: */
302                 }
303 /* L180: */
304             }
305         }
306     } else {
307
308 /*        Form  C := alpha*A'*A + beta*C. */
309
310         if (upper) {
311             i__1 = *n;
312             for (j = 1; j <= i__1; ++j) {
313                 i__2 = j;
314                 for (i__ = 1; i__ <= i__2; ++i__) {
315                     temp = 0.;
316                     i__3 = *k;
317                     for (l = 1; l <= i__3; ++l) {
318                         temp += a[l + i__ * a_dim1] * a[l + j * a_dim1];
319 /* L190: */
320                     }
321                     if (*beta == 0.) {
322                         c__[i__ + j * c_dim1] = *alpha * temp;
323                     } else {
324                         c__[i__ + j * c_dim1] = *alpha * temp + *beta * c__[
325                                 i__ + j * c_dim1];
326                     }
327 /* L200: */
328                 }
329 /* L210: */
330             }
331         } else {
332             i__1 = *n;
333             for (j = 1; j <= i__1; ++j) {
334                 i__2 = *n;
335                 for (i__ = j; i__ <= i__2; ++i__) {
336                     temp = 0.;
337                     i__3 = *k;
338                     for (l = 1; l <= i__3; ++l) {
339                         temp += a[l + i__ * a_dim1] * a[l + j * a_dim1];
340 /* L220: */
341                     }
342                     if (*beta == 0.) {
343                         c__[i__ + j * c_dim1] = *alpha * temp;
344                     } else {
345                         c__[i__ + j * c_dim1] = *alpha * temp + *beta * c__[
346                                 i__ + j * c_dim1];
347                     }
348 /* L230: */
349                 }
350 /* L240: */
351             }
352         }
353     }
354
355     return 0;
356
357 /*     End of DSYRK . */
358
359 } /* dsyrk_ */