/root/doris/contrib/openblas/lapack-netlib/SRC/sgeqr2.c
Line | Count | Source |
1 | | #include <math.h> |
2 | | #include <stdlib.h> |
3 | | #include <string.h> |
4 | | #include <stdio.h> |
5 | | #include <complex.h> |
6 | | #ifdef complex |
7 | | #undef complex |
8 | | #endif |
9 | | #ifdef I |
10 | | #undef I |
11 | | #endif |
12 | | |
13 | | #if defined(_WIN64) |
14 | | typedef long long BLASLONG; |
15 | | typedef unsigned long long BLASULONG; |
16 | | #else |
17 | | typedef long BLASLONG; |
18 | | typedef unsigned long BLASULONG; |
19 | | #endif |
20 | | |
21 | | #ifdef LAPACK_ILP64 |
22 | | typedef BLASLONG blasint; |
23 | | #if defined(_WIN64) |
24 | | #define blasabs(x) llabs(x) |
25 | | #else |
26 | | #define blasabs(x) labs(x) |
27 | | #endif |
28 | | #else |
29 | | typedef int blasint; |
30 | | #define blasabs(x) abs(x) |
31 | | #endif |
32 | | |
33 | | typedef blasint integer; |
34 | | |
35 | | typedef unsigned int uinteger; |
36 | | typedef char *address; |
37 | | typedef short int shortint; |
38 | | typedef float real; |
39 | | typedef double doublereal; |
40 | | typedef struct { real r, i; } complex; |
41 | | typedef struct { doublereal r, i; } doublecomplex; |
42 | | #ifdef _MSC_VER |
43 | | static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;} |
44 | | static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;} |
45 | | static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;} |
46 | | static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;} |
47 | | #else |
48 | 0 | static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} |
49 | 0 | static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} |
50 | 0 | static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} |
51 | 0 | static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} |
52 | | #endif |
53 | | #define pCf(z) (*_pCf(z)) |
54 | | #define pCd(z) (*_pCd(z)) |
55 | | typedef char integer1; |
56 | | |
57 | | #define TRUE_ (1) |
58 | | #define FALSE_ (0) |
59 | | |
60 | | /* Extern is for use with -E */ |
61 | | #ifndef Extern |
62 | | #define Extern extern |
63 | | #endif |
64 | | |
65 | | /* I/O stuff */ |
66 | | |
67 | | typedef int flag; |
68 | | typedef int ftnlen; |
69 | | typedef int ftnint; |
70 | | |
71 | | /*external read, write*/ |
72 | | typedef struct |
73 | | { flag cierr; |
74 | | ftnint ciunit; |
75 | | flag ciend; |
76 | | char *cifmt; |
77 | | ftnint cirec; |
78 | | } cilist; |
79 | | |
80 | | /*internal read, write*/ |
81 | | typedef struct |
82 | | { flag icierr; |
83 | | char *iciunit; |
84 | | flag iciend; |
85 | | char *icifmt; |
86 | | ftnint icirlen; |
87 | | ftnint icirnum; |
88 | | } icilist; |
89 | | |
90 | | /*open*/ |
91 | | typedef struct |
92 | | { flag oerr; |
93 | | ftnint ounit; |
94 | | char *ofnm; |
95 | | ftnlen ofnmlen; |
96 | | char *osta; |
97 | | char *oacc; |
98 | | char *ofm; |
99 | | ftnint orl; |
100 | | char *oblnk; |
101 | | } olist; |
102 | | |
103 | | /*close*/ |
104 | | typedef struct |
105 | | { flag cerr; |
106 | | ftnint cunit; |
107 | | char *csta; |
108 | | } cllist; |
109 | | |
110 | | /*rewind, backspace, endfile*/ |
111 | | typedef struct |
112 | | { flag aerr; |
113 | | ftnint aunit; |
114 | | } alist; |
115 | | |
116 | | /* inquire */ |
117 | | typedef struct |
118 | | { flag inerr; |
119 | | ftnint inunit; |
120 | | char *infile; |
121 | | ftnlen infilen; |
122 | | ftnint *inex; /*parameters in standard's order*/ |
123 | | ftnint *inopen; |
124 | | ftnint *innum; |
125 | | ftnint *innamed; |
126 | | char *inname; |
127 | | ftnlen innamlen; |
128 | | char *inacc; |
129 | | ftnlen inacclen; |
130 | | char *inseq; |
131 | | ftnlen inseqlen; |
132 | | char *indir; |
133 | | ftnlen indirlen; |
134 | | char *infmt; |
135 | | ftnlen infmtlen; |
136 | | char *inform; |
137 | | ftnint informlen; |
138 | | char *inunf; |
139 | | ftnlen inunflen; |
140 | | ftnint *inrecl; |
141 | | ftnint *innrec; |
142 | | char *inblank; |
143 | | ftnlen inblanklen; |
144 | | } inlist; |
145 | | |
146 | | #define VOID void |
147 | | |
148 | | union Multitype { /* for multiple entry points */ |
149 | | integer1 g; |
150 | | shortint h; |
151 | | integer i; |
152 | | /* longint j; */ |
153 | | real r; |
154 | | doublereal d; |
155 | | complex c; |
156 | | doublecomplex z; |
157 | | }; |
158 | | |
159 | | typedef union Multitype Multitype; |
160 | | |
161 | | struct Vardesc { /* for Namelist */ |
162 | | char *name; |
163 | | char *addr; |
164 | | ftnlen *dims; |
165 | | int type; |
166 | | }; |
167 | | typedef struct Vardesc Vardesc; |
168 | | |
169 | | struct Namelist { |
170 | | char *name; |
171 | | Vardesc **vars; |
172 | | int nvars; |
173 | | }; |
174 | | typedef struct Namelist Namelist; |
175 | | |
176 | | #define abs(x) ((x) >= 0 ? (x) : -(x)) |
177 | | #define dabs(x) (fabs(x)) |
178 | 0 | #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) |
179 | 0 | #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) |
180 | | #define dmin(a,b) (f2cmin(a,b)) |
181 | | #define dmax(a,b) (f2cmax(a,b)) |
182 | | #define bit_test(a,b) ((a) >> (b) & 1) |
183 | | #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) |
184 | | #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) |
185 | | |
186 | | #define abort_() { sig_die("Fortran abort routine called", 1); } |
187 | | #define c_abs(z) (cabsf(Cf(z))) |
188 | | #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } |
189 | | #ifdef _MSC_VER |
190 | | #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);} |
191 | | #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);} |
192 | | #else |
193 | | #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} |
194 | | #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} |
195 | | #endif |
196 | | #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} |
197 | | #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} |
198 | | #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} |
199 | | //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} |
200 | | #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} |
201 | | #define d_abs(x) (fabs(*(x))) |
202 | | #define d_acos(x) (acos(*(x))) |
203 | | #define d_asin(x) (asin(*(x))) |
204 | | #define d_atan(x) (atan(*(x))) |
205 | | #define d_atn2(x, y) (atan2(*(x),*(y))) |
206 | | #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } |
207 | | #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); } |
208 | | #define d_cos(x) (cos(*(x))) |
209 | | #define d_cosh(x) (cosh(*(x))) |
210 | | #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) |
211 | | #define d_exp(x) (exp(*(x))) |
212 | | #define d_imag(z) (cimag(Cd(z))) |
213 | | #define r_imag(z) (cimagf(Cf(z))) |
214 | | #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) |
215 | | #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) |
216 | | #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) |
217 | | #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) |
218 | | #define d_log(x) (log(*(x))) |
219 | | #define d_mod(x, y) (fmod(*(x), *(y))) |
220 | | #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) |
221 | | #define d_nint(x) u_nint(*(x)) |
222 | | #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) |
223 | | #define d_sign(a,b) u_sign(*(a),*(b)) |
224 | | #define r_sign(a,b) u_sign(*(a),*(b)) |
225 | | #define d_sin(x) (sin(*(x))) |
226 | | #define d_sinh(x) (sinh(*(x))) |
227 | | #define d_sqrt(x) (sqrt(*(x))) |
228 | | #define d_tan(x) (tan(*(x))) |
229 | | #define d_tanh(x) (tanh(*(x))) |
230 | | #define i_abs(x) abs(*(x)) |
231 | | #define i_dnnt(x) ((integer)u_nint(*(x))) |
232 | | #define i_len(s, n) (n) |
233 | | #define i_nint(x) ((integer)u_nint(*(x))) |
234 | | #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) |
235 | | #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } |
236 | | #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) |
237 | | #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } |
238 | | #define sig_die(s, kill) { exit(1); } |
239 | | #define s_stop(s, n) {exit(0);} |
240 | | #define z_abs(z) (cabs(Cd(z))) |
241 | | #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} |
242 | | #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} |
243 | | #define myexit_() break; |
244 | | #define mycycle() continue; |
245 | | #define myceiling(w) {ceil(w)} |
246 | | #define myhuge(w) {HUGE_VAL} |
247 | | //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} |
248 | | #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} |
249 | | |
250 | | /* -- translated by f2c (version 20000121). |
251 | | You must link the resulting object file with the libraries: |
252 | | -lf2c -lm (in that order) |
253 | | */ |
254 | | |
255 | | |
256 | | |
257 | | |
258 | | /* Table of constant values */ |
259 | | |
260 | | static integer c__1 = 1; |
261 | | |
262 | | /* > \brief \b SGEQR2 computes the QR factorization of a general rectangular matrix using an unblocked algorit |
263 | | hm. */ |
264 | | |
265 | | /* =========== DOCUMENTATION =========== */ |
266 | | |
267 | | /* Online html documentation available at */ |
268 | | /* http://www.netlib.org/lapack/explore-html/ */ |
269 | | |
270 | | /* > \htmlonly */ |
271 | | /* > Download SGEQR2 + dependencies */ |
272 | | /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgeqr2. |
273 | | f"> */ |
274 | | /* > [TGZ]</a> */ |
275 | | /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgeqr2. |
276 | | f"> */ |
277 | | /* > [ZIP]</a> */ |
278 | | /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgeqr2. |
279 | | f"> */ |
280 | | /* > [TXT]</a> */ |
281 | | /* > \endhtmlonly */ |
282 | | |
283 | | /* Definition: */ |
284 | | /* =========== */ |
285 | | |
286 | | /* SUBROUTINE SGEQR2( M, N, A, LDA, TAU, WORK, INFO ) */ |
287 | | |
288 | | /* INTEGER INFO, LDA, M, N */ |
289 | | /* REAL A( LDA, * ), TAU( * ), WORK( * ) */ |
290 | | |
291 | | |
292 | | /* > \par Purpose: */ |
293 | | /* ============= */ |
294 | | /* > */ |
295 | | /* > \verbatim */ |
296 | | /* > */ |
297 | | /* > SGEQR2 computes a QR factorization of a real m-by-n matrix A: */ |
298 | | /* > */ |
299 | | /* > A = Q * ( R ), */ |
300 | | /* > ( 0 ) */ |
301 | | /* > */ |
302 | | /* > where: */ |
303 | | /* > */ |
304 | | /* > Q is a m-by-m orthogonal matrix; */ |
305 | | /* > R is an upper-triangular n-by-n matrix; */ |
306 | | /* > 0 is a (m-n)-by-n zero matrix, if m > n. */ |
307 | | /* > */ |
308 | | /* > \endverbatim */ |
309 | | |
310 | | /* Arguments: */ |
311 | | /* ========== */ |
312 | | |
313 | | /* > \param[in] M */ |
314 | | /* > \verbatim */ |
315 | | /* > M is INTEGER */ |
316 | | /* > The number of rows of the matrix A. M >= 0. */ |
317 | | /* > \endverbatim */ |
318 | | /* > */ |
319 | | /* > \param[in] N */ |
320 | | /* > \verbatim */ |
321 | | /* > N is INTEGER */ |
322 | | /* > The number of columns of the matrix A. N >= 0. */ |
323 | | /* > \endverbatim */ |
324 | | /* > */ |
325 | | /* > \param[in,out] A */ |
326 | | /* > \verbatim */ |
327 | | /* > A is REAL array, dimension (LDA,N) */ |
328 | | /* > On entry, the m by n matrix A. */ |
329 | | /* > On exit, the elements on and above the diagonal of the array */ |
330 | | /* > contain the f2cmin(m,n) by n upper trapezoidal matrix R (R is */ |
331 | | /* > upper triangular if m >= n); the elements below the diagonal, */ |
332 | | /* > with the array TAU, represent the orthogonal matrix Q as a */ |
333 | | /* > product of elementary reflectors (see Further Details). */ |
334 | | /* > \endverbatim */ |
335 | | /* > */ |
336 | | /* > \param[in] LDA */ |
337 | | /* > \verbatim */ |
338 | | /* > LDA is INTEGER */ |
339 | | /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */ |
340 | | /* > \endverbatim */ |
341 | | /* > */ |
342 | | /* > \param[out] TAU */ |
343 | | /* > \verbatim */ |
344 | | /* > TAU is REAL array, dimension (f2cmin(M,N)) */ |
345 | | /* > The scalar factors of the elementary reflectors (see Further */ |
346 | | /* > Details). */ |
347 | | /* > \endverbatim */ |
348 | | /* > */ |
349 | | /* > \param[out] WORK */ |
350 | | /* > \verbatim */ |
351 | | /* > WORK is REAL array, dimension (N) */ |
352 | | /* > \endverbatim */ |
353 | | /* > */ |
354 | | /* > \param[out] INFO */ |
355 | | /* > \verbatim */ |
356 | | /* > INFO is INTEGER */ |
357 | | /* > = 0: successful exit */ |
358 | | /* > < 0: if INFO = -i, the i-th argument had an illegal value */ |
359 | | /* > \endverbatim */ |
360 | | |
361 | | /* Authors: */ |
362 | | /* ======== */ |
363 | | |
364 | | /* > \author Univ. of Tennessee */ |
365 | | /* > \author Univ. of California Berkeley */ |
366 | | /* > \author Univ. of Colorado Denver */ |
367 | | /* > \author NAG Ltd. */ |
368 | | |
369 | | /* > \date November 2019 */ |
370 | | |
371 | | /* > \ingroup realGEcomputational */ |
372 | | |
373 | | /* > \par Further Details: */ |
374 | | /* ===================== */ |
375 | | /* > */ |
376 | | /* > \verbatim */ |
377 | | /* > */ |
378 | | /* > The matrix Q is represented as a product of elementary reflectors */ |
379 | | /* > */ |
380 | | /* > Q = H(1) H(2) . . . H(k), where k = f2cmin(m,n). */ |
381 | | /* > */ |
382 | | /* > Each H(i) has the form */ |
383 | | /* > */ |
384 | | /* > H(i) = I - tau * v * v**T */ |
385 | | /* > */ |
386 | | /* > where tau is a real scalar, and v is a real vector with */ |
387 | | /* > v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i), */ |
388 | | /* > and tau in TAU(i). */ |
389 | | /* > \endverbatim */ |
390 | | /* > */ |
391 | | /* ===================================================================== */ |
392 | | /* Subroutine */ void sgeqr2_(integer *m, integer *n, real *a, integer *lda, |
393 | | real *tau, real *work, integer *info) |
394 | 0 | { |
395 | | /* System generated locals */ |
396 | 0 | integer a_dim1, a_offset, i__1, i__2, i__3; |
397 | | |
398 | | /* Local variables */ |
399 | 0 | integer i__, k; |
400 | 0 | extern /* Subroutine */ void slarf_(char *, integer *, integer *, real *, |
401 | 0 | integer *, real *, real *, integer *, real *); |
402 | 0 | extern int xerbla_(char *, integer *, ftnlen); |
403 | 0 | extern void slarfg_(integer *, real *, real *, integer *, real *); |
404 | 0 | real aii; |
405 | | |
406 | | |
407 | | /* -- LAPACK computational routine (version 3.9.0) -- */ |
408 | | /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ |
409 | | /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ |
410 | | /* November 2019 */ |
411 | | |
412 | | |
413 | | /* ===================================================================== */ |
414 | | |
415 | | |
416 | | /* Test the input arguments */ |
417 | | |
418 | | /* Parameter adjustments */ |
419 | 0 | a_dim1 = *lda; |
420 | 0 | a_offset = 1 + a_dim1 * 1; |
421 | 0 | a -= a_offset; |
422 | 0 | --tau; |
423 | 0 | --work; |
424 | | |
425 | | /* Function Body */ |
426 | 0 | *info = 0; |
427 | 0 | if (*m < 0) { |
428 | 0 | *info = -1; |
429 | 0 | } else if (*n < 0) { |
430 | 0 | *info = -2; |
431 | 0 | } else if (*lda < f2cmax(1,*m)) { |
432 | 0 | *info = -4; |
433 | 0 | } |
434 | 0 | if (*info != 0) { |
435 | 0 | i__1 = -(*info); |
436 | 0 | xerbla_("SGEQR2", &i__1, (ftnlen)6); |
437 | 0 | return; |
438 | 0 | } |
439 | | |
440 | 0 | k = f2cmin(*m,*n); |
441 | |
|
442 | 0 | i__1 = k; |
443 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
444 | | |
445 | | /* Generate elementary reflector H(i) to annihilate A(i+1:m,i) */ |
446 | |
|
447 | 0 | i__2 = *m - i__ + 1; |
448 | | /* Computing MIN */ |
449 | 0 | i__3 = i__ + 1; |
450 | 0 | slarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[f2cmin(i__3,*m) + i__ * a_dim1] |
451 | 0 | , &c__1, &tau[i__]); |
452 | 0 | if (i__ < *n) { |
453 | | |
454 | | /* Apply H(i) to A(i:m,i+1:n) from the left */ |
455 | |
|
456 | 0 | aii = a[i__ + i__ * a_dim1]; |
457 | 0 | a[i__ + i__ * a_dim1] = 1.f; |
458 | 0 | i__2 = *m - i__ + 1; |
459 | 0 | i__3 = *n - i__; |
460 | 0 | slarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &tau[ |
461 | 0 | i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]); |
462 | 0 | a[i__ + i__ * a_dim1] = aii; |
463 | 0 | } |
464 | | /* L10: */ |
465 | 0 | } |
466 | 0 | return; |
467 | | |
468 | | /* End of SGEQR2 */ |
469 | |
|
470 | 0 | } /* sgeqr2_ */ |
471 | | |