ergo
template_lapack_lansy.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_LANSY_HEADER
38 #define TEMPLATE_LAPACK_LANSY_HEADER
39 
40 
41 template<class Treal>
42 Treal template_lapack_lansy(const char *norm, const char *uplo, 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  DLANSY 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 symmetric matrix A.
57 
58  Description
59  ===========
60 
61  DLANSY returns the value
62 
63  DLANSY = ( 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 DLANSY as described
81  above.
82 
83  UPLO (input) CHARACTER*1
84  Specifies whether the upper or lower triangular part of the
85  symmetric matrix A is to be referenced.
86  = 'U': Upper triangular part of A is referenced
87  = 'L': Lower triangular part of A is referenced
88 
89  N (input) INTEGER
90  The order of the matrix A. N >= 0. When N = 0, DLANSY is
91  set to zero.
92 
93  A (input) DOUBLE PRECISION array, dimension (LDA,N)
94  The symmetric matrix A. If UPLO = 'U', the leading n by n
95  upper triangular part of A contains the upper triangular part
96  of the matrix A, and the strictly lower triangular part of A
97  is not referenced. If UPLO = 'L', the leading n by n lower
98  triangular part of A contains the lower triangular part of
99  the matrix A, and the strictly upper triangular part of A is
100  not referenced.
101 
102  LDA (input) INTEGER
103  The leading dimension of the array A. LDA >= max(N,1).
104 
105  WORK (workspace) DOUBLE PRECISION array, dimension (LWORK),
106  where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
107  WORK is not referenced.
108 
109  =====================================================================
110 
111 
112  Parameter adjustments */
113  /* Table of constant values */
114  integer c__1 = 1;
115 
116  /* System generated locals */
117  integer a_dim1, a_offset, i__1, i__2;
118  Treal ret_val, d__1, d__2, d__3;
119  /* Local variables */
120  Treal absa;
121  integer i__, j;
122  Treal scale;
123  Treal value;
124  Treal sum;
125 #define a_ref(a_1,a_2) a[(a_2)*a_dim1 + a_1]
126 
127 
128  a_dim1 = *lda;
129  a_offset = 1 + a_dim1 * 1;
130  a -= a_offset;
131  --work;
132 
133  /* Initialization added by Elias to get rid of compiler warnings. */
134  value = 0;
135  /* Function Body */
136  if (*n == 0) {
137  value = 0.;
138  } else if (template_blas_lsame(norm, "M")) {
139 
140 /* Find max(abs(A(i,j))). */
141 
142  value = 0.;
143  if (template_blas_lsame(uplo, "U")) {
144  i__1 = *n;
145  for (j = 1; j <= i__1; ++j) {
146  i__2 = j;
147  for (i__ = 1; i__ <= i__2; ++i__) {
148 /* Computing MAX */
149  d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1));
150  value = maxMACRO(d__2,d__3);
151 /* L10: */
152  }
153 /* L20: */
154  }
155  } else {
156  i__1 = *n;
157  for (j = 1; j <= i__1; ++j) {
158  i__2 = *n;
159  for (i__ = j; i__ <= i__2; ++i__) {
160 /* Computing MAX */
161  d__2 = value, d__3 = (d__1 = a_ref(i__, j), absMACRO(d__1));
162  value = maxMACRO(d__2,d__3);
163 /* L30: */
164  }
165 /* L40: */
166  }
167  }
168  } else if (template_blas_lsame(norm, "I") || template_blas_lsame(norm, "O") || *(unsigned char *)norm == '1') {
169 
170 /* Find normI(A) ( = norm1(A), since A is symmetric). */
171 
172  value = 0.;
173  if (template_blas_lsame(uplo, "U")) {
174  i__1 = *n;
175  for (j = 1; j <= i__1; ++j) {
176  sum = 0.;
177  i__2 = j - 1;
178  for (i__ = 1; i__ <= i__2; ++i__) {
179  absa = (d__1 = a_ref(i__, j), absMACRO(d__1));
180  sum += absa;
181  work[i__] += absa;
182 /* L50: */
183  }
184  work[j] = sum + (d__1 = a_ref(j, j), absMACRO(d__1));
185 /* L60: */
186  }
187  i__1 = *n;
188  for (i__ = 1; i__ <= i__1; ++i__) {
189 /* Computing MAX */
190  d__1 = value, d__2 = work[i__];
191  value = maxMACRO(d__1,d__2);
192 /* L70: */
193  }
194  } else {
195  i__1 = *n;
196  for (i__ = 1; i__ <= i__1; ++i__) {
197  work[i__] = 0.;
198 /* L80: */
199  }
200  i__1 = *n;
201  for (j = 1; j <= i__1; ++j) {
202  sum = work[j] + (d__1 = a_ref(j, j), absMACRO(d__1));
203  i__2 = *n;
204  for (i__ = j + 1; i__ <= i__2; ++i__) {
205  absa = (d__1 = a_ref(i__, j), absMACRO(d__1));
206  sum += absa;
207  work[i__] += absa;
208 /* L90: */
209  }
210  value = maxMACRO(value,sum);
211 /* L100: */
212  }
213  }
214  } else if (template_blas_lsame(norm, "F") || template_blas_lsame(norm, "E")) {
215 
216 /* Find normF(A). */
217 
218  scale = 0.;
219  sum = 1.;
220  if (template_blas_lsame(uplo, "U")) {
221  i__1 = *n;
222  for (j = 2; j <= i__1; ++j) {
223  i__2 = j - 1;
224  template_lapack_lassq(&i__2, &a_ref(1, j), &c__1, &scale, &sum);
225 /* L110: */
226  }
227  } else {
228  i__1 = *n - 1;
229  for (j = 1; j <= i__1; ++j) {
230  i__2 = *n - j;
231  template_lapack_lassq(&i__2, &a_ref(j + 1, j), &c__1, &scale, &sum);
232 /* L120: */
233  }
234  }
235  sum *= 2;
236  i__1 = *lda + 1;
237  template_lapack_lassq(n, &a[a_offset], &i__1, &scale, &sum);
238  value = scale * template_blas_sqrt(sum);
239  }
240 
241  ret_val = value;
242  return ret_val;
243 
244 /* End of DLANSY */
245 
246 } /* dlansy_ */
247 
248 #undef a_ref
249 
250 
251 #endif
template_blas_sqrt
Treal template_blas_sqrt(Treal x)
template_lapack_lansy
Treal template_lapack_lansy(const char *norm, const char *uplo, const integer *n, const Treal *a, const integer *lda, Treal *work)
Definition: template_lapack_lansy.h:42
absMACRO
#define absMACRO(x)
Definition: template_blas_common.h:47
a_ref
#define a_ref(a_1, a_2)
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
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