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


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