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