Update to 2.0.0 tree from current Fremantle build
[opencv] / 3rdparty / lapack / sger.c
1 #include "clapack.h"
2
3 /* Subroutine */ int sger_(integer *m, integer *n, real *alpha, real *x, 
4         integer *incx, real *y, integer *incy, real *a, integer *lda)
5 {
6     /* System generated locals */
7     integer a_dim1, a_offset, i__1, i__2;
8
9     /* Local variables */
10     integer i__, j, ix, jy, kx, info;
11     real temp;
12     extern /* Subroutine */ int xerbla_(char *, integer *);
13
14 /*     .. Scalar Arguments .. */
15 /*     .. */
16 /*     .. Array Arguments .. */
17 /*     .. */
18
19 /*  Purpose */
20 /*  ======= */
21
22 /*  SGER   performs the rank 1 operation */
23
24 /*     A := alpha*x*y' + A, */
25
26 /*  where alpha is a scalar, x is an m element vector, y is an n element */
27 /*  vector and A is an m by n matrix. */
28
29 /*  Arguments */
30 /*  ========== */
31
32 /*  M      - INTEGER. */
33 /*           On entry, M specifies the number of rows of the matrix A. */
34 /*           M must be at least zero. */
35 /*           Unchanged on exit. */
36
37 /*  N      - INTEGER. */
38 /*           On entry, N specifies the number of columns of the matrix A. */
39 /*           N must be at least zero. */
40 /*           Unchanged on exit. */
41
42 /*  ALPHA  - REAL            . */
43 /*           On entry, ALPHA specifies the scalar alpha. */
44 /*           Unchanged on exit. */
45
46 /*  X      - REAL             array of dimension at least */
47 /*           ( 1 + ( m - 1 )*abs( INCX ) ). */
48 /*           Before entry, the incremented array X must contain the m */
49 /*           element vector x. */
50 /*           Unchanged on exit. */
51
52 /*  INCX   - INTEGER. */
53 /*           On entry, INCX specifies the increment for the elements of */
54 /*           X. INCX must not be zero. */
55 /*           Unchanged on exit. */
56
57 /*  Y      - REAL             array of dimension at least */
58 /*           ( 1 + ( n - 1 )*abs( INCY ) ). */
59 /*           Before entry, the incremented array Y must contain the n */
60 /*           element vector y. */
61 /*           Unchanged on exit. */
62
63 /*  INCY   - INTEGER. */
64 /*           On entry, INCY specifies the increment for the elements of */
65 /*           Y. INCY must not be zero. */
66 /*           Unchanged on exit. */
67
68 /*  A      - REAL             array of DIMENSION ( LDA, n ). */
69 /*           Before entry, the leading m by n part of the array A must */
70 /*           contain the matrix of coefficients. On exit, A is */
71 /*           overwritten by the updated matrix. */
72
73 /*  LDA    - INTEGER. */
74 /*           On entry, LDA specifies the first dimension of A as declared */
75 /*           in the calling (sub) program. LDA must be at least */
76 /*           max( 1, m ). */
77 /*           Unchanged on exit. */
78
79
80 /*  Level 2 Blas routine. */
81
82 /*  -- Written on 22-October-1986. */
83 /*     Jack Dongarra, Argonne National Lab. */
84 /*     Jeremy Du Croz, Nag Central Office. */
85 /*     Sven Hammarling, Nag Central Office. */
86 /*     Richard Hanson, Sandia National Labs. */
87
88
89 /*     .. Parameters .. */
90 /*     .. */
91 /*     .. Local Scalars .. */
92 /*     .. */
93 /*     .. External Subroutines .. */
94 /*     .. */
95 /*     .. Intrinsic Functions .. */
96 /*     .. */
97
98 /*     Test the input parameters. */
99
100     /* Parameter adjustments */
101     --x;
102     --y;
103     a_dim1 = *lda;
104     a_offset = 1 + a_dim1;
105     a -= a_offset;
106
107     /* Function Body */
108     info = 0;
109     if (*m < 0) {
110         info = 1;
111     } else if (*n < 0) {
112         info = 2;
113     } else if (*incx == 0) {
114         info = 5;
115     } else if (*incy == 0) {
116         info = 7;
117     } else if (*lda < max(1,*m)) {
118         info = 9;
119     }
120     if (info != 0) {
121         xerbla_("SGER  ", &info);
122         return 0;
123     }
124
125 /*     Quick return if possible. */
126
127     if (*m == 0 || *n == 0 || *alpha == 0.f) {
128         return 0;
129     }
130
131 /*     Start the operations. In this version the elements of A are */
132 /*     accessed sequentially with one pass through A. */
133
134     if (*incy > 0) {
135         jy = 1;
136     } else {
137         jy = 1 - (*n - 1) * *incy;
138     }
139     if (*incx == 1) {
140         i__1 = *n;
141         for (j = 1; j <= i__1; ++j) {
142             if (y[jy] != 0.f) {
143                 temp = *alpha * y[jy];
144                 i__2 = *m;
145                 for (i__ = 1; i__ <= i__2; ++i__) {
146                     a[i__ + j * a_dim1] += x[i__] * temp;
147 /* L10: */
148                 }
149             }
150             jy += *incy;
151 /* L20: */
152         }
153     } else {
154         if (*incx > 0) {
155             kx = 1;
156         } else {
157             kx = 1 - (*m - 1) * *incx;
158         }
159         i__1 = *n;
160         for (j = 1; j <= i__1; ++j) {
161             if (y[jy] != 0.f) {
162                 temp = *alpha * y[jy];
163                 ix = kx;
164                 i__2 = *m;
165                 for (i__ = 1; i__ <= i__2; ++i__) {
166                     a[i__ + j * a_dim1] += x[ix] * temp;
167                     ix += *incx;
168 /* L30: */
169                 }
170             }
171             jy += *incy;
172 /* L40: */
173         }
174     }
175
176     return 0;
177
178 /*     End of SGER  . */
179
180 } /* sger_ */