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