dsygs2.c
Go to the documentation of this file.
00001 /* dsygs2.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static doublereal c_b6 = -1.;
00019 static integer c__1 = 1;
00020 static doublereal c_b27 = 1.;
00021 
00022 /* Subroutine */ int dsygs2_(integer *itype, char *uplo, integer *n, 
00023         doublereal *a, integer *lda, doublereal *b, integer *ldb, integer *
00024         info)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
00028     doublereal d__1;
00029 
00030     /* Local variables */
00031     integer k;
00032     doublereal ct, akk, bkk;
00033     extern /* Subroutine */ int dsyr2_(char *, integer *, doublereal *, 
00034             doublereal *, integer *, doublereal *, integer *, doublereal *, 
00035             integer *), dscal_(integer *, doublereal *, doublereal *, 
00036             integer *);
00037     extern logical lsame_(char *, char *);
00038     extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *, 
00039             integer *, doublereal *, integer *);
00040     logical upper;
00041     extern /* Subroutine */ int dtrmv_(char *, char *, char *, integer *, 
00042             doublereal *, integer *, doublereal *, integer *), dtrsv_(char *, char *, char *, integer *, doublereal *, 
00043             integer *, doublereal *, integer *), 
00044             xerbla_(char *, integer *);
00045 
00046 
00047 /*  -- LAPACK routine (version 3.2) -- */
00048 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00049 /*     November 2006 */
00050 
00051 /*     .. Scalar Arguments .. */
00052 /*     .. */
00053 /*     .. Array Arguments .. */
00054 /*     .. */
00055 
00056 /*  Purpose */
00057 /*  ======= */
00058 
00059 /*  DSYGS2 reduces a real symmetric-definite generalized eigenproblem */
00060 /*  to standard form. */
00061 
00062 /*  If ITYPE = 1, the problem is A*x = lambda*B*x, */
00063 /*  and A is overwritten by inv(U')*A*inv(U) or inv(L)*A*inv(L') */
00064 
00065 /*  If ITYPE = 2 or 3, the problem is A*B*x = lambda*x or */
00066 /*  B*A*x = lambda*x, and A is overwritten by U*A*U` or L'*A*L. */
00067 
00068 /*  B must have been previously factorized as U'*U or L*L' by DPOTRF. */
00069 
00070 /*  Arguments */
00071 /*  ========= */
00072 
00073 /*  ITYPE   (input) INTEGER */
00074 /*          = 1: compute inv(U')*A*inv(U) or inv(L)*A*inv(L'); */
00075 /*          = 2 or 3: compute U*A*U' or L'*A*L. */
00076 
00077 /*  UPLO    (input) CHARACTER*1 */
00078 /*          Specifies whether the upper or lower triangular part of the */
00079 /*          symmetric matrix A is stored, and how B has been factorized. */
00080 /*          = 'U':  Upper triangular */
00081 /*          = 'L':  Lower triangular */
00082 
00083 /*  N       (input) INTEGER */
00084 /*          The order of the matrices A and B.  N >= 0. */
00085 
00086 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
00087 /*          On entry, the symmetric matrix A.  If UPLO = 'U', the leading */
00088 /*          n by n upper triangular part of A contains the upper */
00089 /*          triangular part of the matrix A, and the strictly lower */
00090 /*          triangular part of A is not referenced.  If UPLO = 'L', the */
00091 /*          leading n by n lower triangular part of A contains the lower */
00092 /*          triangular part of the matrix A, and the strictly upper */
00093 /*          triangular part of A is not referenced. */
00094 
00095 /*          On exit, if INFO = 0, the transformed matrix, stored in the */
00096 /*          same format as A. */
00097 
00098 /*  LDA     (input) INTEGER */
00099 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00100 
00101 /*  B       (input) DOUBLE PRECISION array, dimension (LDB,N) */
00102 /*          The triangular factor from the Cholesky factorization of B, */
00103 /*          as returned by DPOTRF. */
00104 
00105 /*  LDB     (input) INTEGER */
00106 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00107 
00108 /*  INFO    (output) INTEGER */
00109 /*          = 0:  successful exit. */
00110 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00111 
00112 /*  ===================================================================== */
00113 
00114 /*     .. Parameters .. */
00115 /*     .. */
00116 /*     .. Local Scalars .. */
00117 /*     .. */
00118 /*     .. External Subroutines .. */
00119 /*     .. */
00120 /*     .. Intrinsic Functions .. */
00121 /*     .. */
00122 /*     .. External Functions .. */
00123 /*     .. */
00124 /*     .. Executable Statements .. */
00125 
00126 /*     Test the input parameters. */
00127 
00128     /* Parameter adjustments */
00129     a_dim1 = *lda;
00130     a_offset = 1 + a_dim1;
00131     a -= a_offset;
00132     b_dim1 = *ldb;
00133     b_offset = 1 + b_dim1;
00134     b -= b_offset;
00135 
00136     /* Function Body */
00137     *info = 0;
00138     upper = lsame_(uplo, "U");
00139     if (*itype < 1 || *itype > 3) {
00140         *info = -1;
00141     } else if (! upper && ! lsame_(uplo, "L")) {
00142         *info = -2;
00143     } else if (*n < 0) {
00144         *info = -3;
00145     } else if (*lda < max(1,*n)) {
00146         *info = -5;
00147     } else if (*ldb < max(1,*n)) {
00148         *info = -7;
00149     }
00150     if (*info != 0) {
00151         i__1 = -(*info);
00152         xerbla_("DSYGS2", &i__1);
00153         return 0;
00154     }
00155 
00156     if (*itype == 1) {
00157         if (upper) {
00158 
00159 /*           Compute inv(U')*A*inv(U) */
00160 
00161             i__1 = *n;
00162             for (k = 1; k <= i__1; ++k) {
00163 
00164 /*              Update the upper triangle of A(k:n,k:n) */
00165 
00166                 akk = a[k + k * a_dim1];
00167                 bkk = b[k + k * b_dim1];
00168 /* Computing 2nd power */
00169                 d__1 = bkk;
00170                 akk /= d__1 * d__1;
00171                 a[k + k * a_dim1] = akk;
00172                 if (k < *n) {
00173                     i__2 = *n - k;
00174                     d__1 = 1. / bkk;
00175                     dscal_(&i__2, &d__1, &a[k + (k + 1) * a_dim1], lda);
00176                     ct = akk * -.5;
00177                     i__2 = *n - k;
00178                     daxpy_(&i__2, &ct, &b[k + (k + 1) * b_dim1], ldb, &a[k + (
00179                             k + 1) * a_dim1], lda);
00180                     i__2 = *n - k;
00181                     dsyr2_(uplo, &i__2, &c_b6, &a[k + (k + 1) * a_dim1], lda, 
00182                             &b[k + (k + 1) * b_dim1], ldb, &a[k + 1 + (k + 1) 
00183                             * a_dim1], lda);
00184                     i__2 = *n - k;
00185                     daxpy_(&i__2, &ct, &b[k + (k + 1) * b_dim1], ldb, &a[k + (
00186                             k + 1) * a_dim1], lda);
00187                     i__2 = *n - k;
00188                     dtrsv_(uplo, "Transpose", "Non-unit", &i__2, &b[k + 1 + (
00189                             k + 1) * b_dim1], ldb, &a[k + (k + 1) * a_dim1], 
00190                             lda);
00191                 }
00192 /* L10: */
00193             }
00194         } else {
00195 
00196 /*           Compute inv(L)*A*inv(L') */
00197 
00198             i__1 = *n;
00199             for (k = 1; k <= i__1; ++k) {
00200 
00201 /*              Update the lower triangle of A(k:n,k:n) */
00202 
00203                 akk = a[k + k * a_dim1];
00204                 bkk = b[k + k * b_dim1];
00205 /* Computing 2nd power */
00206                 d__1 = bkk;
00207                 akk /= d__1 * d__1;
00208                 a[k + k * a_dim1] = akk;
00209                 if (k < *n) {
00210                     i__2 = *n - k;
00211                     d__1 = 1. / bkk;
00212                     dscal_(&i__2, &d__1, &a[k + 1 + k * a_dim1], &c__1);
00213                     ct = akk * -.5;
00214                     i__2 = *n - k;
00215                     daxpy_(&i__2, &ct, &b[k + 1 + k * b_dim1], &c__1, &a[k + 
00216                             1 + k * a_dim1], &c__1);
00217                     i__2 = *n - k;
00218                     dsyr2_(uplo, &i__2, &c_b6, &a[k + 1 + k * a_dim1], &c__1, 
00219                             &b[k + 1 + k * b_dim1], &c__1, &a[k + 1 + (k + 1) 
00220                             * a_dim1], lda);
00221                     i__2 = *n - k;
00222                     daxpy_(&i__2, &ct, &b[k + 1 + k * b_dim1], &c__1, &a[k + 
00223                             1 + k * a_dim1], &c__1);
00224                     i__2 = *n - k;
00225                     dtrsv_(uplo, "No transpose", "Non-unit", &i__2, &b[k + 1 
00226                             + (k + 1) * b_dim1], ldb, &a[k + 1 + k * a_dim1], 
00227                             &c__1);
00228                 }
00229 /* L20: */
00230             }
00231         }
00232     } else {
00233         if (upper) {
00234 
00235 /*           Compute U*A*U' */
00236 
00237             i__1 = *n;
00238             for (k = 1; k <= i__1; ++k) {
00239 
00240 /*              Update the upper triangle of A(1:k,1:k) */
00241 
00242                 akk = a[k + k * a_dim1];
00243                 bkk = b[k + k * b_dim1];
00244                 i__2 = k - 1;
00245                 dtrmv_(uplo, "No transpose", "Non-unit", &i__2, &b[b_offset], 
00246                         ldb, &a[k * a_dim1 + 1], &c__1);
00247                 ct = akk * .5;
00248                 i__2 = k - 1;
00249                 daxpy_(&i__2, &ct, &b[k * b_dim1 + 1], &c__1, &a[k * a_dim1 + 
00250                         1], &c__1);
00251                 i__2 = k - 1;
00252                 dsyr2_(uplo, &i__2, &c_b27, &a[k * a_dim1 + 1], &c__1, &b[k * 
00253                         b_dim1 + 1], &c__1, &a[a_offset], lda);
00254                 i__2 = k - 1;
00255                 daxpy_(&i__2, &ct, &b[k * b_dim1 + 1], &c__1, &a[k * a_dim1 + 
00256                         1], &c__1);
00257                 i__2 = k - 1;
00258                 dscal_(&i__2, &bkk, &a[k * a_dim1 + 1], &c__1);
00259 /* Computing 2nd power */
00260                 d__1 = bkk;
00261                 a[k + k * a_dim1] = akk * (d__1 * d__1);
00262 /* L30: */
00263             }
00264         } else {
00265 
00266 /*           Compute L'*A*L */
00267 
00268             i__1 = *n;
00269             for (k = 1; k <= i__1; ++k) {
00270 
00271 /*              Update the lower triangle of A(1:k,1:k) */
00272 
00273                 akk = a[k + k * a_dim1];
00274                 bkk = b[k + k * b_dim1];
00275                 i__2 = k - 1;
00276                 dtrmv_(uplo, "Transpose", "Non-unit", &i__2, &b[b_offset], 
00277                         ldb, &a[k + a_dim1], lda);
00278                 ct = akk * .5;
00279                 i__2 = k - 1;
00280                 daxpy_(&i__2, &ct, &b[k + b_dim1], ldb, &a[k + a_dim1], lda);
00281                 i__2 = k - 1;
00282                 dsyr2_(uplo, &i__2, &c_b27, &a[k + a_dim1], lda, &b[k + 
00283                         b_dim1], ldb, &a[a_offset], lda);
00284                 i__2 = k - 1;
00285                 daxpy_(&i__2, &ct, &b[k + b_dim1], ldb, &a[k + a_dim1], lda);
00286                 i__2 = k - 1;
00287                 dscal_(&i__2, &bkk, &a[k + a_dim1], lda);
00288 /* Computing 2nd power */
00289                 d__1 = bkk;
00290                 a[k + k * a_dim1] = akk * (d__1 * d__1);
00291 /* L40: */
00292             }
00293         }
00294     }
00295     return 0;
00296 
00297 /*     End of DSYGS2 */
00298 
00299 } /* dsygs2_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:49