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