slansp.c
Go to the documentation of this file.
00001 /* slansp.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 
00020 doublereal slansp_(char *norm, char *uplo, integer *n, real *ap, real *work)
00021 {
00022     /* System generated locals */
00023     integer i__1, i__2;
00024     real ret_val, r__1, r__2, r__3;
00025 
00026     /* Builtin functions */
00027     double sqrt(doublereal);
00028 
00029     /* Local variables */
00030     integer i__, j, k;
00031     real sum, absa, scale;
00032     extern logical lsame_(char *, char *);
00033     real value;
00034     extern /* Subroutine */ int slassq_(integer *, real *, integer *, real *, 
00035             real *);
00036 
00037 
00038 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00039 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00040 /*     November 2006 */
00041 
00042 /*     .. Scalar Arguments .. */
00043 /*     .. */
00044 /*     .. Array Arguments .. */
00045 /*     .. */
00046 
00047 /*  Purpose */
00048 /*  ======= */
00049 
00050 /*  SLANSP  returns the value of the one norm,  or the Frobenius norm, or */
00051 /*  the  infinity norm,  or the  element of  largest absolute value  of a */
00052 /*  real symmetric matrix A,  supplied in packed form. */
00053 
00054 /*  Description */
00055 /*  =========== */
00056 
00057 /*  SLANSP returns the value */
00058 
00059 /*     SLANSP = ( max(abs(A(i,j))), NORM = 'M' or 'm' */
00060 /*              ( */
00061 /*              ( norm1(A),         NORM = '1', 'O' or 'o' */
00062 /*              ( */
00063 /*              ( normI(A),         NORM = 'I' or 'i' */
00064 /*              ( */
00065 /*              ( normF(A),         NORM = 'F', 'f', 'E' or 'e' */
00066 
00067 /*  where  norm1  denotes the  one norm of a matrix (maximum column sum), */
00068 /*  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and */
00069 /*  normF  denotes the  Frobenius norm of a matrix (square root of sum of */
00070 /*  squares).  Note that  max(abs(A(i,j)))  is not a consistent matrix norm. */
00071 
00072 /*  Arguments */
00073 /*  ========= */
00074 
00075 /*  NORM    (input) CHARACTER*1 */
00076 /*          Specifies the value to be returned in SLANSP as described */
00077 /*          above. */
00078 
00079 /*  UPLO    (input) CHARACTER*1 */
00080 /*          Specifies whether the upper or lower triangular part of the */
00081 /*          symmetric matrix A is supplied. */
00082 /*          = 'U':  Upper triangular part of A is supplied */
00083 /*          = 'L':  Lower triangular part of A is supplied */
00084 
00085 /*  N       (input) INTEGER */
00086 /*          The order of the matrix A.  N >= 0.  When N = 0, SLANSP is */
00087 /*          set to zero. */
00088 
00089 /*  AP      (input) REAL array, dimension (N*(N+1)/2) */
00090 /*          The upper or lower triangle of the symmetric matrix A, packed */
00091 /*          columnwise in a linear array.  The j-th column of A is stored */
00092 /*          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 /*  WORK    (workspace) REAL array, dimension (MAX(1,LWORK)), */
00097 /*          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise, */
00098 /*          WORK is not referenced. */
00099 
00100 /* ===================================================================== */
00101 
00102 /*     .. Parameters .. */
00103 /*     .. */
00104 /*     .. Local Scalars .. */
00105 /*     .. */
00106 /*     .. External Subroutines .. */
00107 /*     .. */
00108 /*     .. External Functions .. */
00109 /*     .. */
00110 /*     .. Intrinsic Functions .. */
00111 /*     .. */
00112 /*     .. Executable Statements .. */
00113 
00114     /* Parameter adjustments */
00115     --work;
00116     --ap;
00117 
00118     /* Function Body */
00119     if (*n == 0) {
00120         value = 0.f;
00121     } else if (lsame_(norm, "M")) {
00122 
00123 /*        Find max(abs(A(i,j))). */
00124 
00125         value = 0.f;
00126         if (lsame_(uplo, "U")) {
00127             k = 1;
00128             i__1 = *n;
00129             for (j = 1; j <= i__1; ++j) {
00130                 i__2 = k + j - 1;
00131                 for (i__ = k; i__ <= i__2; ++i__) {
00132 /* Computing MAX */
00133                     r__2 = value, r__3 = (r__1 = ap[i__], dabs(r__1));
00134                     value = dmax(r__2,r__3);
00135 /* L10: */
00136                 }
00137                 k += j;
00138 /* L20: */
00139             }
00140         } else {
00141             k = 1;
00142             i__1 = *n;
00143             for (j = 1; j <= i__1; ++j) {
00144                 i__2 = k + *n - j;
00145                 for (i__ = k; i__ <= i__2; ++i__) {
00146 /* Computing MAX */
00147                     r__2 = value, r__3 = (r__1 = ap[i__], dabs(r__1));
00148                     value = dmax(r__2,r__3);
00149 /* L30: */
00150                 }
00151                 k = k + *n - j + 1;
00152 /* L40: */
00153             }
00154         }
00155     } else if (lsame_(norm, "I") || lsame_(norm, "O") || *(unsigned char *)norm == '1') {
00156 
00157 /*        Find normI(A) ( = norm1(A), since A is symmetric). */
00158 
00159         value = 0.f;
00160         k = 1;
00161         if (lsame_(uplo, "U")) {
00162             i__1 = *n;
00163             for (j = 1; j <= i__1; ++j) {
00164                 sum = 0.f;
00165                 i__2 = j - 1;
00166                 for (i__ = 1; i__ <= i__2; ++i__) {
00167                     absa = (r__1 = ap[k], dabs(r__1));
00168                     sum += absa;
00169                     work[i__] += absa;
00170                     ++k;
00171 /* L50: */
00172                 }
00173                 work[j] = sum + (r__1 = ap[k], dabs(r__1));
00174                 ++k;
00175 /* L60: */
00176             }
00177             i__1 = *n;
00178             for (i__ = 1; i__ <= i__1; ++i__) {
00179 /* Computing MAX */
00180                 r__1 = value, r__2 = work[i__];
00181                 value = dmax(r__1,r__2);
00182 /* L70: */
00183             }
00184         } else {
00185             i__1 = *n;
00186             for (i__ = 1; i__ <= i__1; ++i__) {
00187                 work[i__] = 0.f;
00188 /* L80: */
00189             }
00190             i__1 = *n;
00191             for (j = 1; j <= i__1; ++j) {
00192                 sum = work[j] + (r__1 = ap[k], dabs(r__1));
00193                 ++k;
00194                 i__2 = *n;
00195                 for (i__ = j + 1; i__ <= i__2; ++i__) {
00196                     absa = (r__1 = ap[k], dabs(r__1));
00197                     sum += absa;
00198                     work[i__] += absa;
00199                     ++k;
00200 /* L90: */
00201                 }
00202                 value = dmax(value,sum);
00203 /* L100: */
00204             }
00205         }
00206     } else if (lsame_(norm, "F") || lsame_(norm, "E")) {
00207 
00208 /*        Find normF(A). */
00209 
00210         scale = 0.f;
00211         sum = 1.f;
00212         k = 2;
00213         if (lsame_(uplo, "U")) {
00214             i__1 = *n;
00215             for (j = 2; j <= i__1; ++j) {
00216                 i__2 = j - 1;
00217                 slassq_(&i__2, &ap[k], &c__1, &scale, &sum);
00218                 k += j;
00219 /* L110: */
00220             }
00221         } else {
00222             i__1 = *n - 1;
00223             for (j = 1; j <= i__1; ++j) {
00224                 i__2 = *n - j;
00225                 slassq_(&i__2, &ap[k], &c__1, &scale, &sum);
00226                 k = k + *n - j + 1;
00227 /* L120: */
00228             }
00229         }
00230         sum *= 2;
00231         k = 1;
00232         i__1 = *n;
00233         for (i__ = 1; i__ <= i__1; ++i__) {
00234             if (ap[k] != 0.f) {
00235                 absa = (r__1 = ap[k], dabs(r__1));
00236                 if (scale < absa) {
00237 /* Computing 2nd power */
00238                     r__1 = scale / absa;
00239                     sum = sum * (r__1 * r__1) + 1.f;
00240                     scale = absa;
00241                 } else {
00242 /* Computing 2nd power */
00243                     r__1 = absa / scale;
00244                     sum += r__1 * r__1;
00245                 }
00246             }
00247             if (lsame_(uplo, "U")) {
00248                 k = k + i__ + 1;
00249             } else {
00250                 k = k + *n - i__ + 1;
00251             }
00252 /* L130: */
00253         }
00254         value = scale * sqrt(sum);
00255     }
00256 
00257     ret_val = value;
00258     return ret_val;
00259 
00260 /*     End of SLANSP */
00261 
00262 } /* slansp_ */


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