ergo
template_lapack_lanhs.h
Go to the documentation of this file.
1 /* Ergo, version 3.3, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2013 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_LANHS_HEADER
36 #define TEMPLATE_LAPACK_LANHS_HEADER
37 
38 
39 template<class Treal>
40 Treal dlanhs_(const char *norm, const integer *n, const Treal *a, const integer *lda,
41  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  DLANHS 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  Hessenberg matrix A.
55 
56  Description
57  ===========
58 
59  DLANHS returns the value
60 
61  DLANHS = ( max(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 max(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 DLANHS as described
79  above.
80 
81  N (input) INTEGER
82  The order of the matrix A. N >= 0. When N = 0, DLANHS is
83  set to zero.
84 
85  A (input) DOUBLE PRECISION array, dimension (LDA,N)
86  The n by n upper Hessenberg matrix A; the part of A below the
87  first sub-diagonal is not referenced.
88 
89  LDA (input) INTEGER
90  The leading dimension of the array A. LDA >= max(N,1).
91 
92  WORK (workspace) DOUBLE PRECISION array, dimension (LWORK),
93  where LWORK >= N when NORM = 'I'; otherwise, WORK is not
94  referenced.
95 
96  =====================================================================
97 
98 
99  Parameter adjustments */
100  /* Table of constant values */
101  integer c__1 = 1;
102 
103  /* System generated locals */
104  integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
105  Treal ret_val, d__1, d__2, d__3;
106  /* Local variables */
107  integer i__, j;
108  Treal scale;
109  Treal value;
110  Treal sum;
111 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
112 
113 
114  a_dim1 = *lda;
115  a_offset = 1 + a_dim1 * 1;
116  a -= a_offset;
117  --work;
118 
119  /* Initialization added by Elias to get rid of compiler warnings. */
120  value = 0;
121  /* Function Body */
122  if (*n == 0) {
123  value = 0.;
124  } else if (template_blas_lsame(norm, "M")) {
125 
126 /* Find max(abs(A(i,j))). */
127 
128  value = 0.;
129  i__1 = *n;
130  for (j = 1; j <= i__1; ++j) {
131 /* Computing MIN */
132  i__3 = *n, i__4 = j + 1;
133  i__2 = minMACRO(i__3,i__4);
134  for (i__ = 1; i__ <= i__2; ++i__) {
135 /* Computing MAX */
136  d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1));
137  value = maxMACRO(d__2,d__3);
138 /* L10: */
139  }
140 /* L20: */
141  }
142  } else if (template_blas_lsame(norm, "O") || *(unsigned char *)
143  norm == '1') {
144 
145 /* Find norm1(A). */
146 
147  value = 0.;
148  i__1 = *n;
149  for (j = 1; j <= i__1; ++j) {
150  sum = 0.;
151 /* Computing MIN */
152  i__3 = *n, i__4 = j + 1;
153  i__2 = minMACRO(i__3,i__4);
154  for (i__ = 1; i__ <= i__2; ++i__) {
155  sum += (d__1 = a_ref(i__, j), absMACRO(d__1));
156 /* L30: */
157  }
158  value = maxMACRO(value,sum);
159 /* L40: */
160  }
161  } else if (template_blas_lsame(norm, "I")) {
162 
163 /* Find normI(A). */
164 
165  i__1 = *n;
166  for (i__ = 1; i__ <= i__1; ++i__) {
167  work[i__] = 0.;
168 /* L50: */
169  }
170  i__1 = *n;
171  for (j = 1; j <= i__1; ++j) {
172 /* Computing MIN */
173  i__3 = *n, i__4 = j + 1;
174  i__2 = minMACRO(i__3,i__4);
175  for (i__ = 1; i__ <= i__2; ++i__) {
176  work[i__] += (d__1 = a_ref(i__, j), absMACRO(d__1));
177 /* L60: */
178  }
179 /* L70: */
180  }
181  value = 0.;
182  i__1 = *n;
183  for (i__ = 1; i__ <= i__1; ++i__) {
184 /* Computing MAX */
185  d__1 = value, d__2 = work[i__];
186  value = maxMACRO(d__1,d__2);
187 /* L80: */
188  }
189  } else if (template_blas_lsame(norm, "F") || template_blas_lsame(norm, "E")) {
190 
191 /* Find normF(A). */
192 
193  scale = 0.;
194  sum = 1.;
195  i__1 = *n;
196  for (j = 1; j <= i__1; ++j) {
197 /* Computing MIN */
198  i__3 = *n, i__4 = j + 1;
199  i__2 = minMACRO(i__3,i__4);
200  template_lapack_lassq(&i__2, &a_ref(1, j), &c__1, &scale, &sum);
201 /* L90: */
202  }
203  value = scale * template_blas_sqrt(sum);
204  }
205 
206  ret_val = value;
207  return ret_val;
208 
209 /* End of DLANHS */
210 
211 } /* dlanhs_ */
212 
213 #undef a_ref
214 
215 
216 #endif
#define absMACRO(x)
Definition: template_blas_common.h:45
#define a_ref(a_1, a_2)
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
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
Treal dlanhs_(const char *norm, const integer *n, const Treal *a, const integer *lda, Treal *work)
Definition: template_lapack_lanhs.h:40