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 integer c_n1 = -1;
00020 static integer c__2 = 2;
00021 static real c_b20 = -1.f;
00022 static real c_b22 = 1.f;
00023
00024 int sgetri_(integer *n, real *a, integer *lda, integer *ipiv,
00025 real *work, integer *lwork, integer *info)
00026 {
00027
00028 integer a_dim1, a_offset, i__1, i__2, i__3;
00029
00030
00031 integer i__, j, jb, nb, jj, jp, nn, iws, nbmin;
00032 extern int sgemm_(char *, char *, integer *, integer *,
00033 integer *, real *, real *, integer *, real *, integer *, real *,
00034 real *, integer *), sgemv_(char *, integer *,
00035 integer *, real *, real *, integer *, real *, integer *, real *,
00036 real *, integer *), sswap_(integer *, real *, integer *,
00037 real *, integer *), strsm_(char *, char *, char *, char *,
00038 integer *, integer *, real *, real *, integer *, real *, integer *
00039 ), xerbla_(char *, integer *);
00040 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
00041 integer *, integer *);
00042 integer ldwork, lwkopt;
00043 logical lquery;
00044 extern int strtri_(char *, char *, integer *, real *,
00045 integer *, integer *);
00046
00047
00048
00049
00050
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 a_dim1 = *lda;
00121 a_offset = 1 + a_dim1;
00122 a -= a_offset;
00123 --ipiv;
00124 --work;
00125
00126
00127 *info = 0;
00128 nb = ilaenv_(&c__1, "SGETRI", " ", n, &c_n1, &c_n1, &c_n1);
00129 lwkopt = *n * nb;
00130 work[1] = (real) lwkopt;
00131 lquery = *lwork == -1;
00132 if (*n < 0) {
00133 *info = -1;
00134 } else if (*lda < max(1,*n)) {
00135 *info = -3;
00136 } else if (*lwork < max(1,*n) && ! lquery) {
00137 *info = -6;
00138 }
00139 if (*info != 0) {
00140 i__1 = -(*info);
00141 xerbla_("SGETRI", &i__1);
00142 return 0;
00143 } else if (lquery) {
00144 return 0;
00145 }
00146
00147
00148
00149 if (*n == 0) {
00150 return 0;
00151 }
00152
00153
00154
00155
00156 strtri_("Upper", "Non-unit", n, &a[a_offset], lda, info);
00157 if (*info > 0) {
00158 return 0;
00159 }
00160
00161 nbmin = 2;
00162 ldwork = *n;
00163 if (nb > 1 && nb < *n) {
00164
00165 i__1 = ldwork * nb;
00166 iws = max(i__1,1);
00167 if (*lwork < iws) {
00168 nb = *lwork / ldwork;
00169
00170 i__1 = 2, i__2 = ilaenv_(&c__2, "SGETRI", " ", n, &c_n1, &c_n1, &
00171 c_n1);
00172 nbmin = max(i__1,i__2);
00173 }
00174 } else {
00175 iws = *n;
00176 }
00177
00178
00179
00180 if (nb < nbmin || nb >= *n) {
00181
00182
00183
00184 for (j = *n; j >= 1; --j) {
00185
00186
00187
00188 i__1 = *n;
00189 for (i__ = j + 1; i__ <= i__1; ++i__) {
00190 work[i__] = a[i__ + j * a_dim1];
00191 a[i__ + j * a_dim1] = 0.f;
00192
00193 }
00194
00195
00196
00197 if (j < *n) {
00198 i__1 = *n - j;
00199 sgemv_("No transpose", n, &i__1, &c_b20, &a[(j + 1) * a_dim1
00200 + 1], lda, &work[j + 1], &c__1, &c_b22, &a[j * a_dim1
00201 + 1], &c__1);
00202 }
00203
00204 }
00205 } else {
00206
00207
00208
00209 nn = (*n - 1) / nb * nb + 1;
00210 i__1 = -nb;
00211 for (j = nn; i__1 < 0 ? j >= 1 : j <= 1; j += i__1) {
00212
00213 i__2 = nb, i__3 = *n - j + 1;
00214 jb = min(i__2,i__3);
00215
00216
00217
00218
00219 i__2 = j + jb - 1;
00220 for (jj = j; jj <= i__2; ++jj) {
00221 i__3 = *n;
00222 for (i__ = jj + 1; i__ <= i__3; ++i__) {
00223 work[i__ + (jj - j) * ldwork] = a[i__ + jj * a_dim1];
00224 a[i__ + jj * a_dim1] = 0.f;
00225
00226 }
00227
00228 }
00229
00230
00231
00232 if (j + jb <= *n) {
00233 i__2 = *n - j - jb + 1;
00234 sgemm_("No transpose", "No transpose", n, &jb, &i__2, &c_b20,
00235 &a[(j + jb) * a_dim1 + 1], lda, &work[j + jb], &
00236 ldwork, &c_b22, &a[j * a_dim1 + 1], lda);
00237 }
00238 strsm_("Right", "Lower", "No transpose", "Unit", n, &jb, &c_b22, &
00239 work[j], &ldwork, &a[j * a_dim1 + 1], lda);
00240
00241 }
00242 }
00243
00244
00245
00246 for (j = *n - 1; j >= 1; --j) {
00247 jp = ipiv[j];
00248 if (jp != j) {
00249 sswap_(n, &a[j * a_dim1 + 1], &c__1, &a[jp * a_dim1 + 1], &c__1);
00250 }
00251
00252 }
00253
00254 work[1] = (real) iws;
00255 return 0;
00256
00257
00258
00259 }