sgbtrs.c
Go to the documentation of this file.
00001 /* sgbtrs.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_b7 = -1.f;
00019 static integer c__1 = 1;
00020 static real c_b23 = 1.f;
00021 
00022 /* Subroutine */ int sgbtrs_(char *trans, integer *n, integer *kl, integer *
00023         ku, integer *nrhs, real *ab, integer *ldab, integer *ipiv, real *b, 
00024         integer *ldb, integer *info)
00025 {
00026     /* System generated locals */
00027     integer ab_dim1, ab_offset, b_dim1, b_offset, i__1, i__2, i__3;
00028 
00029     /* Local variables */
00030     integer i__, j, l, kd, lm;
00031     extern /* Subroutine */ int sger_(integer *, integer *, real *, real *, 
00032             integer *, real *, integer *, real *, integer *);
00033     extern logical lsame_(char *, char *);
00034     extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *, 
00035             real *, integer *, real *, integer *, real *, real *, integer *);
00036     logical lnoti;
00037     extern /* Subroutine */ int sswap_(integer *, real *, integer *, real *, 
00038             integer *), stbsv_(char *, char *, char *, integer *, integer *, 
00039             real *, integer *, real *, integer *), 
00040             xerbla_(char *, integer *);
00041     logical notran;
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 /*  SGBTRS solves a system of linear equations */
00057 /*     A * X = B  or  A' * X = B */
00058 /*  with a general band matrix A using the LU factorization computed */
00059 /*  by SGBTRF. */
00060 
00061 /*  Arguments */
00062 /*  ========= */
00063 
00064 /*  TRANS   (input) CHARACTER*1 */
00065 /*          Specifies the form of the system of equations. */
00066 /*          = 'N':  A * X = B  (No transpose) */
00067 /*          = 'T':  A'* X = B  (Transpose) */
00068 /*          = 'C':  A'* X = B  (Conjugate transpose = Transpose) */
00069 
00070 /*  N       (input) INTEGER */
00071 /*          The order of the matrix A.  N >= 0. */
00072 
00073 /*  KL      (input) INTEGER */
00074 /*          The number of subdiagonals within the band of A.  KL >= 0. */
00075 
00076 /*  KU      (input) INTEGER */
00077 /*          The number of superdiagonals within the band of A.  KU >= 0. */
00078 
00079 /*  NRHS    (input) INTEGER */
00080 /*          The number of right hand sides, i.e., the number of columns */
00081 /*          of the matrix B.  NRHS >= 0. */
00082 
00083 /*  AB      (input) REAL array, dimension (LDAB,N) */
00084 /*          Details of the LU factorization of the band matrix A, as */
00085 /*          computed by SGBTRF.  U is stored as an upper triangular band */
00086 /*          matrix with KL+KU superdiagonals in rows 1 to KL+KU+1, and */
00087 /*          the multipliers used during the factorization are stored in */
00088 /*          rows KL+KU+2 to 2*KL+KU+1. */
00089 
00090 /*  LDAB    (input) INTEGER */
00091 /*          The leading dimension of the array AB.  LDAB >= 2*KL+KU+1. */
00092 
00093 /*  IPIV    (input) INTEGER array, dimension (N) */
00094 /*          The pivot indices; for 1 <= i <= N, row i of the matrix was */
00095 /*          interchanged with row IPIV(i). */
00096 
00097 /*  B       (input/output) REAL array, dimension (LDB,NRHS) */
00098 /*          On entry, the right hand side matrix B. */
00099 /*          On exit, the solution matrix X. */
00100 
00101 /*  LDB     (input) INTEGER */
00102 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00103 
00104 /*  INFO    (output) INTEGER */
00105 /*          = 0:  successful exit */
00106 /*          < 0: if INFO = -i, the i-th argument had an illegal value */
00107 
00108 /*  ===================================================================== */
00109 
00110 /*     .. Parameters .. */
00111 /*     .. */
00112 /*     .. Local Scalars .. */
00113 /*     .. */
00114 /*     .. External Functions .. */
00115 /*     .. */
00116 /*     .. External Subroutines .. */
00117 /*     .. */
00118 /*     .. Intrinsic Functions .. */
00119 /*     .. */
00120 /*     .. Executable Statements .. */
00121 
00122 /*     Test the input parameters. */
00123 
00124     /* Parameter adjustments */
00125     ab_dim1 = *ldab;
00126     ab_offset = 1 + ab_dim1;
00127     ab -= ab_offset;
00128     --ipiv;
00129     b_dim1 = *ldb;
00130     b_offset = 1 + b_dim1;
00131     b -= b_offset;
00132 
00133     /* Function Body */
00134     *info = 0;
00135     notran = lsame_(trans, "N");
00136     if (! notran && ! lsame_(trans, "T") && ! lsame_(
00137             trans, "C")) {
00138         *info = -1;
00139     } else if (*n < 0) {
00140         *info = -2;
00141     } else if (*kl < 0) {
00142         *info = -3;
00143     } else if (*ku < 0) {
00144         *info = -4;
00145     } else if (*nrhs < 0) {
00146         *info = -5;
00147     } else if (*ldab < (*kl << 1) + *ku + 1) {
00148         *info = -7;
00149     } else if (*ldb < max(1,*n)) {
00150         *info = -10;
00151     }
00152     if (*info != 0) {
00153         i__1 = -(*info);
00154         xerbla_("SGBTRS", &i__1);
00155         return 0;
00156     }
00157 
00158 /*     Quick return if possible */
00159 
00160     if (*n == 0 || *nrhs == 0) {
00161         return 0;
00162     }
00163 
00164     kd = *ku + *kl + 1;
00165     lnoti = *kl > 0;
00166 
00167     if (notran) {
00168 
00169 /*        Solve  A*X = B. */
00170 
00171 /*        Solve L*X = B, overwriting B with X. */
00172 
00173 /*        L is represented as a product of permutations and unit lower */
00174 /*        triangular matrices L = P(1) * L(1) * ... * P(n-1) * L(n-1), */
00175 /*        where each transformation L(i) is a rank-one modification of */
00176 /*        the identity matrix. */
00177 
00178         if (lnoti) {
00179             i__1 = *n - 1;
00180             for (j = 1; j <= i__1; ++j) {
00181 /* Computing MIN */
00182                 i__2 = *kl, i__3 = *n - j;
00183                 lm = min(i__2,i__3);
00184                 l = ipiv[j];
00185                 if (l != j) {
00186                     sswap_(nrhs, &b[l + b_dim1], ldb, &b[j + b_dim1], ldb);
00187                 }
00188                 sger_(&lm, nrhs, &c_b7, &ab[kd + 1 + j * ab_dim1], &c__1, &b[
00189                         j + b_dim1], ldb, &b[j + 1 + b_dim1], ldb);
00190 /* L10: */
00191             }
00192         }
00193 
00194         i__1 = *nrhs;
00195         for (i__ = 1; i__ <= i__1; ++i__) {
00196 
00197 /*           Solve U*X = B, overwriting B with X. */
00198 
00199             i__2 = *kl + *ku;
00200             stbsv_("Upper", "No transpose", "Non-unit", n, &i__2, &ab[
00201                     ab_offset], ldab, &b[i__ * b_dim1 + 1], &c__1);
00202 /* L20: */
00203         }
00204 
00205     } else {
00206 
00207 /*        Solve A'*X = B. */
00208 
00209         i__1 = *nrhs;
00210         for (i__ = 1; i__ <= i__1; ++i__) {
00211 
00212 /*           Solve U'*X = B, overwriting B with X. */
00213 
00214             i__2 = *kl + *ku;
00215             stbsv_("Upper", "Transpose", "Non-unit", n, &i__2, &ab[ab_offset], 
00216                      ldab, &b[i__ * b_dim1 + 1], &c__1);
00217 /* L30: */
00218         }
00219 
00220 /*        Solve L'*X = B, overwriting B with X. */
00221 
00222         if (lnoti) {
00223             for (j = *n - 1; j >= 1; --j) {
00224 /* Computing MIN */
00225                 i__1 = *kl, i__2 = *n - j;
00226                 lm = min(i__1,i__2);
00227                 sgemv_("Transpose", &lm, nrhs, &c_b7, &b[j + 1 + b_dim1], ldb, 
00228                          &ab[kd + 1 + j * ab_dim1], &c__1, &c_b23, &b[j + 
00229                         b_dim1], ldb);
00230                 l = ipiv[j];
00231                 if (l != j) {
00232                     sswap_(nrhs, &b[l + b_dim1], ldb, &b[j + b_dim1], ldb);
00233                 }
00234 /* L40: */
00235             }
00236         }
00237     }
00238     return 0;
00239 
00240 /*     End of SGBTRS */
00241 
00242 } /* sgbtrs_ */


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