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