00001 /* Ergo, version 3.7, a program for linear scaling electronic structure 00002 * calculations. 00003 * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, 00004 * and Anastasia Kruchinina. 00005 * 00006 * This program is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 * 00019 * Primary academic reference: 00020 * Ergo: An open-source program for linear-scaling electronic structure 00021 * calculations, 00022 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia 00023 * Kruchinina, 00024 * SoftwareX 7, 107 (2018), 00025 * <http://dx.doi.org/10.1016/j.softx.2018.03.005> 00026 * 00027 * For further information about Ergo, see <http://www.ergoscf.org>. 00028 */ 00029 00030 /* This file belongs to the template_lapack part of the Ergo source 00031 * code. The source files in the template_lapack directory are modified 00032 * versions of files originally distributed as CLAPACK, see the 00033 * Copyright/license notice in the file template_lapack/COPYING. 00034 */ 00035 00036 00037 #ifndef TEMPLATE_LAPACK_LANSY_HEADER 00038 #define TEMPLATE_LAPACK_LANSY_HEADER 00039 00040 00041 template<class Treal> 00042 Treal template_lapack_lansy(const char *norm, const char *uplo, const integer *n, const Treal *a, const integer 00043 *lda, Treal *work) 00044 { 00045 /* -- LAPACK auxiliary routine (version 3.0) -- 00046 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., 00047 Courant Institute, Argonne National Lab, and Rice University 00048 October 31, 1992 00049 00050 00051 Purpose 00052 ======= 00053 00054 DLANSY returns the value of the one norm, or the Frobenius norm, or 00055 the infinity norm, or the element of largest absolute value of a 00056 real symmetric matrix A. 00057 00058 Description 00059 =========== 00060 00061 DLANSY returns the value 00062 00063 DLANSY = ( max(abs(A(i,j))), NORM = 'M' or 'm' 00064 ( 00065 ( norm1(A), NORM = '1', 'O' or 'o' 00066 ( 00067 ( normI(A), NORM = 'I' or 'i' 00068 ( 00069 ( normF(A), NORM = 'F', 'f', 'E' or 'e' 00070 00071 where norm1 denotes the one norm of a matrix (maximum column sum), 00072 normI denotes the infinity norm of a matrix (maximum row sum) and 00073 normF denotes the Frobenius norm of a matrix (square root of sum of 00074 squares). Note that max(abs(A(i,j))) is not a matrix norm. 00075 00076 Arguments 00077 ========= 00078 00079 NORM (input) CHARACTER*1 00080 Specifies the value to be returned in DLANSY as described 00081 above. 00082 00083 UPLO (input) CHARACTER*1 00084 Specifies whether the upper or lower triangular part of the 00085 symmetric matrix A is to be referenced. 00086 = 'U': Upper triangular part of A is referenced 00087 = 'L': Lower triangular part of A is referenced 00088 00089 N (input) INTEGER 00090 The order of the matrix A. N >= 0. When N = 0, DLANSY is 00091 set to zero. 00092 00093 A (input) DOUBLE PRECISION array, dimension (LDA,N) 00094 The symmetric matrix A. If UPLO = 'U', the leading n by n 00095 upper triangular part of A contains the upper triangular part 00096 of the matrix A, and the strictly lower triangular part of A 00097 is not referenced. If UPLO = 'L', the leading n by n lower 00098 triangular part of A contains the lower triangular part of 00099 the matrix A, and the strictly upper triangular part of A is 00100 not referenced. 00101 00102 LDA (input) INTEGER 00103 The leading dimension of the array A. LDA >= max(N,1). 00104 00105 WORK (workspace) DOUBLE PRECISION array, dimension (LWORK), 00106 where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise, 00107 WORK is not referenced. 00108 00109 ===================================================================== 00110 00111 00112 Parameter adjustments */ 00113 /* Table of constant values */ 00114 integer c__1 = 1; 00115 00116 /* System generated locals */ 00117 integer a_dim1, a_offset, i__1, i__2; 00118 Treal ret_val, d__1, d__2, d__3; 00119 /* Local variables */ 00120 Treal absa; 00121 integer i__, j; 00122 Treal scale; 00123 Treal value; 00124 Treal sum; 00125 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1] 00126 00127 00128 a_dim1 = *lda; 00129 a_offset = 1 + a_dim1 * 1; 00130 a -= a_offset; 00131 --work; 00132 00133 /* Initialization added by Elias to get rid of compiler warnings. */ 00134 value = 0; 00135 /* Function Body */ 00136 if (*n == 0) { 00137 value = 0.; 00138 } else if (template_blas_lsame(norm, "M")) { 00139 00140 /* Find max(abs(A(i,j))). */ 00141 00142 value = 0.; 00143 if (template_blas_lsame(uplo, "U")) { 00144 i__1 = *n; 00145 for (j = 1; j <= i__1; ++j) { 00146 i__2 = j; 00147 for (i__ = 1; i__ <= i__2; ++i__) { 00148 /* Computing MAX */ 00149 d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1)); 00150 value = maxMACRO(d__2,d__3); 00151 /* L10: */ 00152 } 00153 /* L20: */ 00154 } 00155 } else { 00156 i__1 = *n; 00157 for (j = 1; j <= i__1; ++j) { 00158 i__2 = *n; 00159 for (i__ = j; i__ <= i__2; ++i__) { 00160 /* Computing MAX */ 00161 d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1)); 00162 value = maxMACRO(d__2,d__3); 00163 /* L30: */ 00164 } 00165 /* L40: */ 00166 } 00167 } 00168 } else if (template_blas_lsame(norm, "I") || template_blas_lsame(norm, "O") || *(unsigned char *)norm == '1') { 00169 00170 /* Find normI(A) ( = norm1(A), since A is symmetric). */ 00171 00172 value = 0.; 00173 if (template_blas_lsame(uplo, "U")) { 00174 i__1 = *n; 00175 for (j = 1; j <= i__1; ++j) { 00176 sum = 0.; 00177 i__2 = j - 1; 00178 for (i__ = 1; i__ <= i__2; ++i__) { 00179 absa = (d__1 = a_ref(i__, j), absMACRO(d__1)); 00180 sum += absa; 00181 work[i__] += absa; 00182 /* L50: */ 00183 } 00184 work[j] = sum + (d__1 = a_ref(j, j), absMACRO(d__1)); 00185 /* L60: */ 00186 } 00187 i__1 = *n; 00188 for (i__ = 1; i__ <= i__1; ++i__) { 00189 /* Computing MAX */ 00190 d__1 = value, d__2 = work[i__]; 00191 value = maxMACRO(d__1,d__2); 00192 /* L70: */ 00193 } 00194 } else { 00195 i__1 = *n; 00196 for (i__ = 1; i__ <= i__1; ++i__) { 00197 work[i__] = 0.; 00198 /* L80: */ 00199 } 00200 i__1 = *n; 00201 for (j = 1; j <= i__1; ++j) { 00202 sum = work[j] + (d__1 = a_ref(j, j), absMACRO(d__1)); 00203 i__2 = *n; 00204 for (i__ = j + 1; i__ <= i__2; ++i__) { 00205 absa = (d__1 = a_ref(i__, j), absMACRO(d__1)); 00206 sum += absa; 00207 work[i__] += absa; 00208 /* L90: */ 00209 } 00210 value = maxMACRO(value,sum); 00211 /* L100: */ 00212 } 00213 } 00214 } else if (template_blas_lsame(norm, "F") || template_blas_lsame(norm, "E")) { 00215 00216 /* Find normF(A). */ 00217 00218 scale = 0.; 00219 sum = 1.; 00220 if (template_blas_lsame(uplo, "U")) { 00221 i__1 = *n; 00222 for (j = 2; j <= i__1; ++j) { 00223 i__2 = j - 1; 00224 template_lapack_lassq(&i__2, &a_ref(1, j), &c__1, &scale, &sum); 00225 /* L110: */ 00226 } 00227 } else { 00228 i__1 = *n - 1; 00229 for (j = 1; j <= i__1; ++j) { 00230 i__2 = *n - j; 00231 template_lapack_lassq(&i__2, &a_ref(j + 1, j), &c__1, &scale, &sum); 00232 /* L120: */ 00233 } 00234 } 00235 sum *= 2; 00236 i__1 = *lda + 1; 00237 template_lapack_lassq(n, &a[a_offset], &i__1, &scale, &sum); 00238 value = scale * template_blas_sqrt(sum); 00239 } 00240 00241 ret_val = value; 00242 return ret_val; 00243 00244 /* End of DLANSY */ 00245 00246 } /* dlansy_ */ 00247 00248 #undef a_ref 00249 00250 00251 #endif
1.6.1