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