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_LANHS_HEADER 00038 #define TEMPLATE_LAPACK_LANHS_HEADER 00039 00040 00041 template<class Treal> 00042 Treal dlanhs_(const char *norm, const integer *n, const Treal *a, const integer *lda, 00043 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 DLANHS 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 Hessenberg matrix A. 00057 00058 Description 00059 =========== 00060 00061 DLANHS returns the value 00062 00063 DLANHS = ( 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 DLANHS as described 00081 above. 00082 00083 N (input) INTEGER 00084 The order of the matrix A. N >= 0. When N = 0, DLANHS is 00085 set to zero. 00086 00087 A (input) DOUBLE PRECISION array, dimension (LDA,N) 00088 The n by n upper Hessenberg matrix A; the part of A below the 00089 first sub-diagonal is not referenced. 00090 00091 LDA (input) INTEGER 00092 The leading dimension of the array A. LDA >= max(N,1). 00093 00094 WORK (workspace) DOUBLE PRECISION array, dimension (LWORK), 00095 where LWORK >= N when NORM = 'I'; otherwise, WORK is not 00096 referenced. 00097 00098 ===================================================================== 00099 00100 00101 Parameter adjustments */ 00102 /* Table of constant values */ 00103 integer c__1 = 1; 00104 00105 /* System generated locals */ 00106 integer a_dim1, a_offset, i__1, i__2, i__3, i__4; 00107 Treal ret_val, d__1, d__2, d__3; 00108 /* Local variables */ 00109 integer i__, j; 00110 Treal scale; 00111 Treal value; 00112 Treal sum; 00113 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1] 00114 00115 00116 a_dim1 = *lda; 00117 a_offset = 1 + a_dim1 * 1; 00118 a -= a_offset; 00119 --work; 00120 00121 /* Initialization added by Elias to get rid of compiler warnings. */ 00122 value = 0; 00123 /* Function Body */ 00124 if (*n == 0) { 00125 value = 0.; 00126 } else if (template_blas_lsame(norm, "M")) { 00127 00128 /* Find max(abs(A(i,j))). */ 00129 00130 value = 0.; 00131 i__1 = *n; 00132 for (j = 1; j <= i__1; ++j) { 00133 /* Computing MIN */ 00134 i__3 = *n, i__4 = j + 1; 00135 i__2 = minMACRO(i__3,i__4); 00136 for (i__ = 1; i__ <= i__2; ++i__) { 00137 /* Computing MAX */ 00138 d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1)); 00139 value = maxMACRO(d__2,d__3); 00140 /* L10: */ 00141 } 00142 /* L20: */ 00143 } 00144 } else if (template_blas_lsame(norm, "O") || *(unsigned char *) 00145 norm == '1') { 00146 00147 /* Find norm1(A). */ 00148 00149 value = 0.; 00150 i__1 = *n; 00151 for (j = 1; j <= i__1; ++j) { 00152 sum = 0.; 00153 /* Computing MIN */ 00154 i__3 = *n, i__4 = j + 1; 00155 i__2 = minMACRO(i__3,i__4); 00156 for (i__ = 1; i__ <= i__2; ++i__) { 00157 sum += (d__1 = a_ref(i__, j), absMACRO(d__1)); 00158 /* L30: */ 00159 } 00160 value = maxMACRO(value,sum); 00161 /* L40: */ 00162 } 00163 } else if (template_blas_lsame(norm, "I")) { 00164 00165 /* Find normI(A). */ 00166 00167 i__1 = *n; 00168 for (i__ = 1; i__ <= i__1; ++i__) { 00169 work[i__] = 0.; 00170 /* L50: */ 00171 } 00172 i__1 = *n; 00173 for (j = 1; j <= i__1; ++j) { 00174 /* Computing MIN */ 00175 i__3 = *n, i__4 = j + 1; 00176 i__2 = minMACRO(i__3,i__4); 00177 for (i__ = 1; i__ <= i__2; ++i__) { 00178 work[i__] += (d__1 = a_ref(i__, j), absMACRO(d__1)); 00179 /* L60: */ 00180 } 00181 /* L70: */ 00182 } 00183 value = 0.; 00184 i__1 = *n; 00185 for (i__ = 1; i__ <= i__1; ++i__) { 00186 /* Computing MAX */ 00187 d__1 = value, d__2 = work[i__]; 00188 value = maxMACRO(d__1,d__2); 00189 /* L80: */ 00190 } 00191 } else if (template_blas_lsame(norm, "F") || template_blas_lsame(norm, "E")) { 00192 00193 /* Find normF(A). */ 00194 00195 scale = 0.; 00196 sum = 1.; 00197 i__1 = *n; 00198 for (j = 1; j <= i__1; ++j) { 00199 /* Computing MIN */ 00200 i__3 = *n, i__4 = j + 1; 00201 i__2 = minMACRO(i__3,i__4); 00202 template_lapack_lassq(&i__2, &a_ref(1, j), &c__1, &scale, &sum); 00203 /* L90: */ 00204 } 00205 value = scale * template_blas_sqrt(sum); 00206 } 00207 00208 ret_val = value; 00209 return ret_val; 00210 00211 /* End of DLANHS */ 00212 00213 } /* dlanhs_ */ 00214 00215 #undef a_ref 00216 00217 00218 #endif