ergo
template_lapack_lange.h
Go to the documentation of this file.
1 /* Ergo, version 3.4, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2014 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 
28  /* This file belongs to the template_lapack part of the Ergo source
29  * code. The source files in the template_lapack directory are modified
30  * versions of files originally distributed as CLAPACK, see the
31  * Copyright/license notice in the file template_lapack/COPYING.
32  */
33 
34 
35 #ifndef TEMPLATE_LAPACK_LANGE_HEADER
36 #define TEMPLATE_LAPACK_LANGE_HEADER
37 
38 
39 template<class Treal>
40 Treal template_lapack_lange(const char *norm, const integer *m, const integer *n, const Treal *a, const integer
41  *lda, Treal *work)
42 {
43 /* -- LAPACK auxiliary routine (version 3.0) --
44  Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
45  Courant Institute, Argonne National Lab, and Rice University
46  October 31, 1992
47 
48 
49  Purpose
50  =======
51 
52  DLANGE returns the value of the one norm, or the Frobenius norm, or
53  the infinity norm, or the element of largest absolute value of a
54  real matrix A.
55 
56  Description
57  ===========
58 
59  DLANGE returns the value
60 
61  DLANGE = ( maxMACRO(abs(A(i,j))), NORM = 'M' or 'm'
62  (
63  ( norm1(A), NORM = '1', 'O' or 'o'
64  (
65  ( normI(A), NORM = 'I' or 'i'
66  (
67  ( normF(A), NORM = 'F', 'f', 'E' or 'e'
68 
69  where norm1 denotes the one norm of a matrix (maximum column sum),
70  normI denotes the infinity norm of a matrix (maximum row sum) and
71  normF denotes the Frobenius norm of a matrix (square root of sum of
72  squares). Note that maxMACRO(abs(A(i,j))) is not a matrix norm.
73 
74  Arguments
75  =========
76 
77  NORM (input) CHARACTER*1
78  Specifies the value to be returned in DLANGE as described
79  above.
80 
81  M (input) INTEGER
82  The number of rows of the matrix A. M >= 0. When M = 0,
83  DLANGE is set to zero.
84 
85  N (input) INTEGER
86  The number of columns of the matrix A. N >= 0. When N = 0,
87  DLANGE is set to zero.
88 
89  A (input) DOUBLE PRECISION array, dimension (LDA,N)
90  The m by n matrix A.
91 
92  LDA (input) INTEGER
93  The leading dimension of the array A. LDA >= maxMACRO(M,1).
94 
95  WORK (workspace) DOUBLE PRECISION array, dimension (LWORK),
96  where LWORK >= M when NORM = 'I'; otherwise, WORK is not
97  referenced.
98 
99  =====================================================================
100 
101 
102  Parameter adjustments */
103  /* Table of constant values */
104  integer c__1 = 1;
105 
106  /* System generated locals */
107  integer a_dim1, a_offset, i__1, i__2;
108  Treal ret_val, d__1, d__2, d__3;
109  /* Local variables */
110  integer i__, j;
111  Treal scale;
112  Treal value;
113  Treal sum;
114 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
115 
116 
117  a_dim1 = *lda;
118  a_offset = 1 + a_dim1 * 1;
119  a -= a_offset;
120  --work;
121 
122  /* Initialization added by Elias to get rid of compiler warnings. */
123  value = 0;
124  /* Function Body */
125  if (minMACRO(*m,*n) == 0) {
126  value = 0.;
127  } else if (template_blas_lsame(norm, "M")) {
128 
129 /* Find maxMACRO(abs(A(i,j))). */
130 
131  value = 0.;
132  i__1 = *n;
133  for (j = 1; j <= i__1; ++j) {
134  i__2 = *m;
135  for (i__ = 1; i__ <= i__2; ++i__) {
136 /* Computing MAX */
137  d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1));
138  value = maxMACRO(d__2,d__3);
139 /* L10: */
140  }
141 /* L20: */
142  }
143  } else if (template_blas_lsame(norm, "O") || *(unsigned char *)
144  norm == '1') {
145 
146 /* Find norm1(A). */
147 
148  value = 0.;
149  i__1 = *n;
150  for (j = 1; j <= i__1; ++j) {
151  sum = 0.;
152  i__2 = *m;
153  for (i__ = 1; i__ <= i__2; ++i__) {
154  sum += (d__1 = a_ref(i__, j), absMACRO(d__1));
155 /* L30: */
156  }
157  value = maxMACRO(value,sum);
158 /* L40: */
159  }
160  } else if (template_blas_lsame(norm, "I")) {
161 
162 /* Find normI(A). */
163 
164  i__1 = *m;
165  for (i__ = 1; i__ <= i__1; ++i__) {
166  work[i__] = 0.;
167 /* L50: */
168  }
169  i__1 = *n;
170  for (j = 1; j <= i__1; ++j) {
171  i__2 = *m;
172  for (i__ = 1; i__ <= i__2; ++i__) {
173  work[i__] += (d__1 = a_ref(i__, j), absMACRO(d__1));
174 /* L60: */
175  }
176 /* L70: */
177  }
178  value = 0.;
179  i__1 = *m;
180  for (i__ = 1; i__ <= i__1; ++i__) {
181 /* Computing MAX */
182  d__1 = value, d__2 = work[i__];
183  value = maxMACRO(d__1,d__2);
184 /* L80: */
185  }
186  } else if (template_blas_lsame(norm, "F") || template_blas_lsame(norm, "E")) {
187 
188 /* Find normF(A). */
189 
190  scale = 0.;
191  sum = 1.;
192  i__1 = *n;
193  for (j = 1; j <= i__1; ++j) {
194  template_lapack_lassq(m, &a_ref(1, j), &c__1, &scale, &sum);
195 /* L90: */
196  }
197  value = scale * template_blas_sqrt(sum);
198  }
199 
200  ret_val = value;
201  return ret_val;
202 
203 /* End of DLANGE */
204 
205 } /* dlange_ */
206 
207 #undef a_ref
208 
209 
210 #endif
Treal template_lapack_lange(const char *norm, const integer *m, const integer *n, const Treal *a, const integer *lda, Treal *work)
Definition: template_lapack_lange.h:40
#define absMACRO(x)
Definition: template_blas_common.h:45
int integer
Definition: template_blas_common.h:38
#define maxMACRO(a, b)
Definition: template_blas_common.h:43
#define minMACRO(a, b)
Definition: template_blas_common.h:44
#define a_ref(a_1, a_2)
int template_lapack_lassq(const integer *n, const Treal *x, const integer *incx, Treal *scale, Treal *sumsq)
Definition: template_lapack_lamch.h:70
Treal template_blas_sqrt(Treal x)
logical template_blas_lsame(const char *ca, const char *cb)
Definition: template_blas_common.cc:44