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