00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__1 = 1;
00019 static real c_b12 = 1.f;
00020 static real c_b15 = -1.f;
00021
00022 int sgetrf_(integer *m, integer *n, real *a, integer *lda,
00023 integer *ipiv, integer *info)
00024 {
00025
00026 integer a_dim1, a_offset, i__1, i__2, i__3;
00027 real r__1;
00028
00029
00030 integer i__, j, ipivstart, jpivstart, jp;
00031 real tmp;
00032 extern int sscal_(integer *, real *, real *, integer *),
00033 sgemm_(char *, char *, integer *, integer *, integer *, real *,
00034 real *, integer *, real *, integer *, real *, real *, integer *);
00035 integer kcols;
00036 real sfmin;
00037 integer nstep;
00038 extern int strsm_(char *, char *, char *, char *,
00039 integer *, integer *, real *, real *, integer *, real *, integer *
00040 );
00041 integer kahead;
00042 extern doublereal slamch_(char *);
00043 extern int xerbla_(char *, integer *);
00044 extern integer isamax_(integer *, real *, integer *);
00045 integer npived;
00046 extern logical sisnan_(real *);
00047 integer kstart;
00048 extern int slaswp_(integer *, real *, integer *, integer
00049 *, integer *, integer *, integer *);
00050 integer ntopiv;
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 a_dim1 = *lda;
00157 a_offset = 1 + a_dim1;
00158 a -= a_offset;
00159 --ipiv;
00160
00161
00162 *info = 0;
00163 if (*m < 0) {
00164 *info = -1;
00165 } else if (*n < 0) {
00166 *info = -2;
00167 } else if (*lda < max(1,*m)) {
00168 *info = -4;
00169 }
00170 if (*info != 0) {
00171 i__1 = -(*info);
00172 xerbla_("SGETRF", &i__1);
00173 return 0;
00174 }
00175
00176
00177
00178 if (*m == 0 || *n == 0) {
00179 return 0;
00180 }
00181
00182
00183
00184 sfmin = slamch_("S");
00185
00186 nstep = min(*m,*n);
00187 i__1 = nstep;
00188 for (j = 1; j <= i__1; ++j) {
00189 kahead = j & -j;
00190 kstart = j + 1 - kahead;
00191
00192 i__2 = kahead, i__3 = *m - j;
00193 kcols = min(i__2,i__3);
00194
00195
00196
00197 i__2 = *m - j + 1;
00198 jp = j - 1 + isamax_(&i__2, &a[j + j * a_dim1], &c__1);
00199 ipiv[j] = jp;
00200
00201 if (jp != j) {
00202 tmp = a[j + j * a_dim1];
00203 a[j + j * a_dim1] = a[jp + j * a_dim1];
00204 a[jp + j * a_dim1] = tmp;
00205 }
00206
00207 ntopiv = 1;
00208 ipivstart = j;
00209 jpivstart = j - ntopiv;
00210 while(ntopiv < kahead) {
00211 slaswp_(&ntopiv, &a[jpivstart * a_dim1 + 1], lda, &ipivstart, &j,
00212 &ipiv[1], &c__1);
00213 ipivstart -= ntopiv;
00214 ntopiv <<= 1;
00215 jpivstart -= ntopiv;
00216 }
00217
00218 slaswp_(&kcols, &a[(j + 1) * a_dim1 + 1], lda, &kstart, &j, &ipiv[1],
00219 &c__1);
00220
00221 if (a[j + j * a_dim1] != 0.f && ! sisnan_(&a[j + j * a_dim1])) {
00222 if ((r__1 = a[j + j * a_dim1], dabs(r__1)) >= sfmin) {
00223 i__2 = *m - j;
00224 r__1 = 1.f / a[j + j * a_dim1];
00225 sscal_(&i__2, &r__1, &a[j + 1 + j * a_dim1], &c__1);
00226 } else {
00227 i__2 = *m - j;
00228 for (i__ = 1; i__ <= i__2; ++i__) {
00229 a[j + i__ + j * a_dim1] /= a[j + j * a_dim1];
00230 }
00231 }
00232 } else if (a[j + j * a_dim1] == 0.f && *info == 0) {
00233 *info = j;
00234 }
00235
00236 strsm_("Left", "Lower", "No transpose", "Unit", &kahead, &kcols, &
00237 c_b12, &a[kstart + kstart * a_dim1], lda, &a[kstart + (j + 1)
00238 * a_dim1], lda);
00239
00240 i__2 = *m - j;
00241 sgemm_("No transpose", "No transpose", &i__2, &kcols, &kahead, &c_b15,
00242 &a[j + 1 + kstart * a_dim1], lda, &a[kstart + (j + 1) *
00243 a_dim1], lda, &c_b12, &a[j + 1 + (j + 1) * a_dim1], lda);
00244 }
00245
00246 npived = nstep & -nstep;
00247 j = nstep - npived;
00248 while(j > 0) {
00249 ntopiv = j & -j;
00250 i__1 = j + 1;
00251 slaswp_(&ntopiv, &a[(j - ntopiv + 1) * a_dim1 + 1], lda, &i__1, &
00252 nstep, &ipiv[1], &c__1);
00253 j -= ntopiv;
00254 }
00255
00256 if (*m < *n) {
00257 i__1 = *n - *m;
00258 slaswp_(&i__1, &a[(*m + kcols + 1) * a_dim1 + 1], lda, &c__1, m, &
00259 ipiv[1], &c__1);
00260 i__1 = *n - *m;
00261 strsm_("Left", "Lower", "No transpose", "Unit", m, &i__1, &c_b12, &a[
00262 a_offset], lda, &a[(*m + kcols + 1) * a_dim1 + 1], lda);
00263 }
00264 return 0;
00265
00266
00267
00268 }