ergo
template_lapack_lanst.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_LANST_HEADER
38#define TEMPLATE_LAPACK_LANST_HEADER
39
40
41template<class Treal>
42Treal template_lapack_lanst(const char *norm, const integer *n, const Treal *d__, const Treal *e)
43{
44/* -- LAPACK auxiliary routine (version 3.0) --
45 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
46 Courant Institute, Argonne National Lab, and Rice University
47 February 29, 1992
48
49
50 Purpose
51 =======
52
53 DLANST returns the value of the one norm, or the Frobenius norm, or
54 the infinity norm, or the element of largest absolute value of a
55 real symmetric tridiagonal matrix A.
56
57 Description
58 ===========
59
60 DLANST returns the value
61
62 DLANST = ( max(abs(A(i,j))), NORM = 'M' or 'm'
63 (
64 ( norm1(A), NORM = '1', 'O' or 'o'
65 (
66 ( normI(A), NORM = 'I' or 'i'
67 (
68 ( normF(A), NORM = 'F', 'f', 'E' or 'e'
69
70 where norm1 denotes the one norm of a matrix (maximum column sum),
71 normI denotes the infinity norm of a matrix (maximum row sum) and
72 normF denotes the Frobenius norm of a matrix (square root of sum of
73 squares). Note that max(abs(A(i,j))) is not a matrix norm.
74
75 Arguments
76 =========
77
78 NORM (input) CHARACTER*1
79 Specifies the value to be returned in DLANST as described
80 above.
81
82 N (input) INTEGER
83 The order of the matrix A. N >= 0. When N = 0, DLANST is
84 set to zero.
85
86 D (input) DOUBLE PRECISION array, dimension (N)
87 The diagonal elements of A.
88
89 E (input) DOUBLE PRECISION array, dimension (N-1)
90 The (n-1) sub-diagonal or super-diagonal elements of A.
91
92 =====================================================================
93
94
95 Parameter adjustments */
96 /* Table of constant values */
97 integer c__1 = 1;
98
99 /* System generated locals */
100 integer i__1;
101 Treal ret_val, d__1, d__2, d__3, d__4, d__5;
102 /* Local variables */
103 integer i__;
104 Treal scale;
105 Treal anorm;
106 Treal sum;
107
108
109 --e;
110 --d__;
111
112 /* Initialization added by Elias to get rid of compiler warnings. */
113 anorm = 0;
114 /* Function Body */
115 if (*n <= 0) {
116 anorm = 0.;
117 } else if (template_blas_lsame(norm, "M")) {
118
119/* Find max(abs(A(i,j))). */
120
121 anorm = (d__1 = d__[*n], absMACRO(d__1));
122 i__1 = *n - 1;
123 for (i__ = 1; i__ <= i__1; ++i__) {
124/* Computing MAX */
125 d__2 = anorm, d__3 = (d__1 = d__[i__], absMACRO(d__1));
126 anorm = maxMACRO(d__2,d__3);
127/* Computing MAX */
128 d__2 = anorm, d__3 = (d__1 = e[i__], absMACRO(d__1));
129 anorm = maxMACRO(d__2,d__3);
130/* L10: */
131 }
132 } else if (template_blas_lsame(norm, "O") || *(unsigned char *)
133 norm == '1' || template_blas_lsame(norm, "I")) {
134
135/* Find norm1(A). */
136
137 if (*n == 1) {
138 anorm = absMACRO(d__[1]);
139 } else {
140/* Computing MAX */
141 d__3 = absMACRO(d__[1]) + absMACRO(e[1]), d__4 = (d__1 = e[*n - 1], absMACRO(
142 d__1)) + (d__2 = d__[*n], absMACRO(d__2));
143 anorm = maxMACRO(d__3,d__4);
144 i__1 = *n - 1;
145 for (i__ = 2; i__ <= i__1; ++i__) {
146/* Computing MAX */
147 d__4 = anorm, d__5 = (d__1 = d__[i__], absMACRO(d__1)) + (d__2 = e[
148 i__], absMACRO(d__2)) + (d__3 = e[i__ - 1], absMACRO(d__3));
149 anorm = maxMACRO(d__4,d__5);
150/* L20: */
151 }
152 }
153 } else if (template_blas_lsame(norm, "F") || template_blas_lsame(norm, "E")) {
154
155/* Find normF(A). */
156
157 scale = 0.;
158 sum = 1.;
159 if (*n > 1) {
160 i__1 = *n - 1;
161 template_lapack_lassq(&i__1, &e[1], &c__1, &scale, &sum);
162 sum *= 2;
163 }
164 template_lapack_lassq(n, &d__[1], &c__1, &scale, &sum);
165 anorm = scale * template_blas_sqrt(sum);
166 }
167
168 ret_val = anorm;
169 return ret_val;
170
171/* End of DLANST */
172
173} /* dlanst_ */
174
175#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 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
Treal template_lapack_lanst(const char *norm, const integer *n, const Treal *d__, const Treal *e)
Definition template_lapack_lanst.h:42