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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:14