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_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020
00021 int chegs2_(integer *itype, char *uplo, integer *n, complex *
00022 a, integer *lda, complex *b, integer *ldb, integer *info)
00023 {
00024
00025 integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
00026 real r__1, r__2;
00027 complex q__1;
00028
00029
00030 integer k;
00031 complex ct;
00032 real akk, bkk;
00033 extern int cher2_(char *, integer *, complex *, complex *
00034 , integer *, complex *, integer *, complex *, integer *);
00035 extern logical lsame_(char *, char *);
00036 extern int caxpy_(integer *, complex *, complex *,
00037 integer *, complex *, integer *);
00038 logical upper;
00039 extern int ctrmv_(char *, char *, char *, integer *,
00040 complex *, integer *, complex *, integer *), ctrsv_(char *, char *, char *, integer *, complex *,
00041 integer *, complex *, integer *), clacgv_(
00042 integer *, complex *, integer *), csscal_(integer *, real *,
00043 complex *, integer *), xerbla_(char *, integer *);
00044
00045
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
00121
00122
00123
00124
00125
00126
00127
00128 a_dim1 = *lda;
00129 a_offset = 1 + a_dim1;
00130 a -= a_offset;
00131 b_dim1 = *ldb;
00132 b_offset = 1 + b_dim1;
00133 b -= b_offset;
00134
00135
00136 *info = 0;
00137 upper = lsame_(uplo, "U");
00138 if (*itype < 1 || *itype > 3) {
00139 *info = -1;
00140 } else if (! upper && ! lsame_(uplo, "L")) {
00141 *info = -2;
00142 } else if (*n < 0) {
00143 *info = -3;
00144 } else if (*lda < max(1,*n)) {
00145 *info = -5;
00146 } else if (*ldb < max(1,*n)) {
00147 *info = -7;
00148 }
00149 if (*info != 0) {
00150 i__1 = -(*info);
00151 xerbla_("CHEGS2", &i__1);
00152 return 0;
00153 }
00154
00155 if (*itype == 1) {
00156 if (upper) {
00157
00158
00159
00160 i__1 = *n;
00161 for (k = 1; k <= i__1; ++k) {
00162
00163
00164
00165 i__2 = k + k * a_dim1;
00166 akk = a[i__2].r;
00167 i__2 = k + k * b_dim1;
00168 bkk = b[i__2].r;
00169
00170 r__1 = bkk;
00171 akk /= r__1 * r__1;
00172 i__2 = k + k * a_dim1;
00173 a[i__2].r = akk, a[i__2].i = 0.f;
00174 if (k < *n) {
00175 i__2 = *n - k;
00176 r__1 = 1.f / bkk;
00177 csscal_(&i__2, &r__1, &a[k + (k + 1) * a_dim1], lda);
00178 r__1 = akk * -.5f;
00179 ct.r = r__1, ct.i = 0.f;
00180 i__2 = *n - k;
00181 clacgv_(&i__2, &a[k + (k + 1) * a_dim1], lda);
00182 i__2 = *n - k;
00183 clacgv_(&i__2, &b[k + (k + 1) * b_dim1], ldb);
00184 i__2 = *n - k;
00185 caxpy_(&i__2, &ct, &b[k + (k + 1) * b_dim1], ldb, &a[k + (
00186 k + 1) * a_dim1], lda);
00187 i__2 = *n - k;
00188 q__1.r = -1.f, q__1.i = -0.f;
00189 cher2_(uplo, &i__2, &q__1, &a[k + (k + 1) * a_dim1], lda,
00190 &b[k + (k + 1) * b_dim1], ldb, &a[k + 1 + (k + 1)
00191 * a_dim1], lda);
00192 i__2 = *n - k;
00193 caxpy_(&i__2, &ct, &b[k + (k + 1) * b_dim1], ldb, &a[k + (
00194 k + 1) * a_dim1], lda);
00195 i__2 = *n - k;
00196 clacgv_(&i__2, &b[k + (k + 1) * b_dim1], ldb);
00197 i__2 = *n - k;
00198 ctrsv_(uplo, "Conjugate transpose", "Non-unit", &i__2, &b[
00199 k + 1 + (k + 1) * b_dim1], ldb, &a[k + (k + 1) *
00200 a_dim1], lda);
00201 i__2 = *n - k;
00202 clacgv_(&i__2, &a[k + (k + 1) * a_dim1], lda);
00203 }
00204
00205 }
00206 } else {
00207
00208
00209
00210 i__1 = *n;
00211 for (k = 1; k <= i__1; ++k) {
00212
00213
00214
00215 i__2 = k + k * a_dim1;
00216 akk = a[i__2].r;
00217 i__2 = k + k * b_dim1;
00218 bkk = b[i__2].r;
00219
00220 r__1 = bkk;
00221 akk /= r__1 * r__1;
00222 i__2 = k + k * a_dim1;
00223 a[i__2].r = akk, a[i__2].i = 0.f;
00224 if (k < *n) {
00225 i__2 = *n - k;
00226 r__1 = 1.f / bkk;
00227 csscal_(&i__2, &r__1, &a[k + 1 + k * a_dim1], &c__1);
00228 r__1 = akk * -.5f;
00229 ct.r = r__1, ct.i = 0.f;
00230 i__2 = *n - k;
00231 caxpy_(&i__2, &ct, &b[k + 1 + k * b_dim1], &c__1, &a[k +
00232 1 + k * a_dim1], &c__1);
00233 i__2 = *n - k;
00234 q__1.r = -1.f, q__1.i = -0.f;
00235 cher2_(uplo, &i__2, &q__1, &a[k + 1 + k * a_dim1], &c__1,
00236 &b[k + 1 + k * b_dim1], &c__1, &a[k + 1 + (k + 1)
00237 * a_dim1], lda);
00238 i__2 = *n - k;
00239 caxpy_(&i__2, &ct, &b[k + 1 + k * b_dim1], &c__1, &a[k +
00240 1 + k * a_dim1], &c__1);
00241 i__2 = *n - k;
00242 ctrsv_(uplo, "No transpose", "Non-unit", &i__2, &b[k + 1
00243 + (k + 1) * b_dim1], ldb, &a[k + 1 + k * a_dim1],
00244 &c__1);
00245 }
00246
00247 }
00248 }
00249 } else {
00250 if (upper) {
00251
00252
00253
00254 i__1 = *n;
00255 for (k = 1; k <= i__1; ++k) {
00256
00257
00258
00259 i__2 = k + k * a_dim1;
00260 akk = a[i__2].r;
00261 i__2 = k + k * b_dim1;
00262 bkk = b[i__2].r;
00263 i__2 = k - 1;
00264 ctrmv_(uplo, "No transpose", "Non-unit", &i__2, &b[b_offset],
00265 ldb, &a[k * a_dim1 + 1], &c__1);
00266 r__1 = akk * .5f;
00267 ct.r = r__1, ct.i = 0.f;
00268 i__2 = k - 1;
00269 caxpy_(&i__2, &ct, &b[k * b_dim1 + 1], &c__1, &a[k * a_dim1 +
00270 1], &c__1);
00271 i__2 = k - 1;
00272 cher2_(uplo, &i__2, &c_b1, &a[k * a_dim1 + 1], &c__1, &b[k *
00273 b_dim1 + 1], &c__1, &a[a_offset], lda);
00274 i__2 = k - 1;
00275 caxpy_(&i__2, &ct, &b[k * b_dim1 + 1], &c__1, &a[k * a_dim1 +
00276 1], &c__1);
00277 i__2 = k - 1;
00278 csscal_(&i__2, &bkk, &a[k * a_dim1 + 1], &c__1);
00279 i__2 = k + k * a_dim1;
00280
00281 r__2 = bkk;
00282 r__1 = akk * (r__2 * r__2);
00283 a[i__2].r = r__1, a[i__2].i = 0.f;
00284
00285 }
00286 } else {
00287
00288
00289
00290 i__1 = *n;
00291 for (k = 1; k <= i__1; ++k) {
00292
00293
00294
00295 i__2 = k + k * a_dim1;
00296 akk = a[i__2].r;
00297 i__2 = k + k * b_dim1;
00298 bkk = b[i__2].r;
00299 i__2 = k - 1;
00300 clacgv_(&i__2, &a[k + a_dim1], lda);
00301 i__2 = k - 1;
00302 ctrmv_(uplo, "Conjugate transpose", "Non-unit", &i__2, &b[
00303 b_offset], ldb, &a[k + a_dim1], lda);
00304 r__1 = akk * .5f;
00305 ct.r = r__1, ct.i = 0.f;
00306 i__2 = k - 1;
00307 clacgv_(&i__2, &b[k + b_dim1], ldb);
00308 i__2 = k - 1;
00309 caxpy_(&i__2, &ct, &b[k + b_dim1], ldb, &a[k + a_dim1], lda);
00310 i__2 = k - 1;
00311 cher2_(uplo, &i__2, &c_b1, &a[k + a_dim1], lda, &b[k + b_dim1]
00312 , ldb, &a[a_offset], lda);
00313 i__2 = k - 1;
00314 caxpy_(&i__2, &ct, &b[k + b_dim1], ldb, &a[k + a_dim1], lda);
00315 i__2 = k - 1;
00316 clacgv_(&i__2, &b[k + b_dim1], ldb);
00317 i__2 = k - 1;
00318 csscal_(&i__2, &bkk, &a[k + a_dim1], lda);
00319 i__2 = k - 1;
00320 clacgv_(&i__2, &a[k + a_dim1], lda);
00321 i__2 = k + k * a_dim1;
00322
00323 r__2 = bkk;
00324 r__1 = akk * (r__2 * r__2);
00325 a[i__2].r = r__1, a[i__2].i = 0.f;
00326
00327 }
00328 }
00329 }
00330 return 0;
00331
00332
00333
00334 }