ctptri.c
Go to the documentation of this file.
00001 /* ctptri.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 complex c_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020 
00021 /* Subroutine */ int ctptri_(char *uplo, char *diag, integer *n, complex *ap, 
00022         integer *info)
00023 {
00024     /* System generated locals */
00025     integer i__1, i__2;
00026     complex q__1;
00027 
00028     /* Builtin functions */
00029     void c_div(complex *, complex *, complex *);
00030 
00031     /* Local variables */
00032     integer j, jc, jj;
00033     complex ajj;
00034     extern /* Subroutine */ int cscal_(integer *, complex *, complex *, 
00035             integer *);
00036     extern logical lsame_(char *, char *);
00037     extern /* Subroutine */ int ctpmv_(char *, char *, char *, integer *, 
00038             complex *, complex *, integer *);
00039     logical upper;
00040     extern /* Subroutine */ int xerbla_(char *, integer *);
00041     integer jclast;
00042     logical nounit;
00043 
00044 
00045 /*  -- LAPACK routine (version 3.2) -- */
00046 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00047 /*     November 2006 */
00048 
00049 /*     .. Scalar Arguments .. */
00050 /*     .. */
00051 /*     .. Array Arguments .. */
00052 /*     .. */
00053 
00054 /*  Purpose */
00055 /*  ======= */
00056 
00057 /*  CTPTRI computes the inverse of a complex upper or lower triangular */
00058 /*  matrix A stored in packed format. */
00059 
00060 /*  Arguments */
00061 /*  ========= */
00062 
00063 /*  UPLO    (input) CHARACTER*1 */
00064 /*          = 'U':  A is upper triangular; */
00065 /*          = 'L':  A is lower triangular. */
00066 
00067 /*  DIAG    (input) CHARACTER*1 */
00068 /*          = 'N':  A is non-unit triangular; */
00069 /*          = 'U':  A is unit triangular. */
00070 
00071 /*  N       (input) INTEGER */
00072 /*          The order of the matrix A.  N >= 0. */
00073 
00074 /*  AP      (input/output) COMPLEX array, dimension (N*(N+1)/2) */
00075 /*          On entry, the upper or lower triangular matrix A, stored */
00076 /*          columnwise in a linear array.  The j-th column of A is stored */
00077 /*          in the array AP as follows: */
00078 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00079 /*          if UPLO = 'L', AP(i + (j-1)*((2*n-j)/2) = A(i,j) for j<=i<=n. */
00080 /*          See below for further details. */
00081 /*          On exit, the (triangular) inverse of the original matrix, in */
00082 /*          the same packed storage format. */
00083 
00084 /*  INFO    (output) INTEGER */
00085 /*          = 0:  successful exit */
00086 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00087 /*          > 0:  if INFO = i, A(i,i) is exactly zero.  The triangular */
00088 /*                matrix is singular and its inverse can not be computed. */
00089 
00090 /*  Further Details */
00091 /*  =============== */
00092 
00093 /*  A triangular matrix A can be transferred to packed storage using one */
00094 /*  of the following program segments: */
00095 
00096 /*  UPLO = 'U':                      UPLO = 'L': */
00097 
00098 /*        JC = 1                           JC = 1 */
00099 /*        DO 2 J = 1, N                    DO 2 J = 1, N */
00100 /*           DO 1 I = 1, J                    DO 1 I = J, N */
00101 /*              AP(JC+I-1) = A(I,J)              AP(JC+I-J) = A(I,J) */
00102 /*      1    CONTINUE                    1    CONTINUE */
00103 /*           JC = JC + J                      JC = JC + N - J + 1 */
00104 /*      2 CONTINUE                       2 CONTINUE */
00105 
00106 /*  ===================================================================== */
00107 
00108 /*     .. Parameters .. */
00109 /*     .. */
00110 /*     .. Local Scalars .. */
00111 /*     .. */
00112 /*     .. External Functions .. */
00113 /*     .. */
00114 /*     .. External Subroutines .. */
00115 /*     .. */
00116 /*     .. Executable Statements .. */
00117 
00118 /*     Test the input parameters. */
00119 
00120     /* Parameter adjustments */
00121     --ap;
00122 
00123     /* Function Body */
00124     *info = 0;
00125     upper = lsame_(uplo, "U");
00126     nounit = lsame_(diag, "N");
00127     if (! upper && ! lsame_(uplo, "L")) {
00128         *info = -1;
00129     } else if (! nounit && ! lsame_(diag, "U")) {
00130         *info = -2;
00131     } else if (*n < 0) {
00132         *info = -3;
00133     }
00134     if (*info != 0) {
00135         i__1 = -(*info);
00136         xerbla_("CTPTRI", &i__1);
00137         return 0;
00138     }
00139 
00140 /*     Check for singularity if non-unit. */
00141 
00142     if (nounit) {
00143         if (upper) {
00144             jj = 0;
00145             i__1 = *n;
00146             for (*info = 1; *info <= i__1; ++(*info)) {
00147                 jj += *info;
00148                 i__2 = jj;
00149                 if (ap[i__2].r == 0.f && ap[i__2].i == 0.f) {
00150                     return 0;
00151                 }
00152 /* L10: */
00153             }
00154         } else {
00155             jj = 1;
00156             i__1 = *n;
00157             for (*info = 1; *info <= i__1; ++(*info)) {
00158                 i__2 = jj;
00159                 if (ap[i__2].r == 0.f && ap[i__2].i == 0.f) {
00160                     return 0;
00161                 }
00162                 jj = jj + *n - *info + 1;
00163 /* L20: */
00164             }
00165         }
00166         *info = 0;
00167     }
00168 
00169     if (upper) {
00170 
00171 /*        Compute inverse of upper triangular matrix. */
00172 
00173         jc = 1;
00174         i__1 = *n;
00175         for (j = 1; j <= i__1; ++j) {
00176             if (nounit) {
00177                 i__2 = jc + j - 1;
00178                 c_div(&q__1, &c_b1, &ap[jc + j - 1]);
00179                 ap[i__2].r = q__1.r, ap[i__2].i = q__1.i;
00180                 i__2 = jc + j - 1;
00181                 q__1.r = -ap[i__2].r, q__1.i = -ap[i__2].i;
00182                 ajj.r = q__1.r, ajj.i = q__1.i;
00183             } else {
00184                 q__1.r = -1.f, q__1.i = -0.f;
00185                 ajj.r = q__1.r, ajj.i = q__1.i;
00186             }
00187 
00188 /*           Compute elements 1:j-1 of j-th column. */
00189 
00190             i__2 = j - 1;
00191             ctpmv_("Upper", "No transpose", diag, &i__2, &ap[1], &ap[jc], &
00192                     c__1);
00193             i__2 = j - 1;
00194             cscal_(&i__2, &ajj, &ap[jc], &c__1);
00195             jc += j;
00196 /* L30: */
00197         }
00198 
00199     } else {
00200 
00201 /*        Compute inverse of lower triangular matrix. */
00202 
00203         jc = *n * (*n + 1) / 2;
00204         for (j = *n; j >= 1; --j) {
00205             if (nounit) {
00206                 i__1 = jc;
00207                 c_div(&q__1, &c_b1, &ap[jc]);
00208                 ap[i__1].r = q__1.r, ap[i__1].i = q__1.i;
00209                 i__1 = jc;
00210                 q__1.r = -ap[i__1].r, q__1.i = -ap[i__1].i;
00211                 ajj.r = q__1.r, ajj.i = q__1.i;
00212             } else {
00213                 q__1.r = -1.f, q__1.i = -0.f;
00214                 ajj.r = q__1.r, ajj.i = q__1.i;
00215             }
00216             if (j < *n) {
00217 
00218 /*              Compute elements j+1:n of j-th column. */
00219 
00220                 i__1 = *n - j;
00221                 ctpmv_("Lower", "No transpose", diag, &i__1, &ap[jclast], &ap[
00222                         jc + 1], &c__1);
00223                 i__1 = *n - j;
00224                 cscal_(&i__1, &ajj, &ap[jc + 1], &c__1);
00225             }
00226             jclast = jc;
00227             jc = jc - *n + j - 2;
00228 /* L40: */
00229         }
00230     }
00231 
00232     return 0;
00233 
00234 /*     End of CTPTRI */
00235 
00236 } /* ctptri_ */


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