ergo
template_blas_nrm2.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_BLAS_NRM2_HEADER
38
#define TEMPLATE_BLAS_NRM2_HEADER
39
40
41
template
<
class
Treal>
42
Treal
template_blas_nrm2
(
const
integer
*n,
const
Treal *x,
const
integer
*incx)
43
{
44
/* The following loop is equivalent to this call to the LAPACK
45
auxiliary routine:
46
CALL DLASSQ( N, X, INCX, SCALE, SSQ ) */
47
/* System generated locals */
48
integer
i__1, i__2;
49
Treal ret_val, d__1;
50
/* Local variables */
51
Treal norm, scale, absxi;
52
integer
ix;
53
Treal ssq;
54
/* DNRM2 returns the euclidean norm of a vector via the function
55
name, so that
56
DNRM2 := sqrt( x'*x )
57
-- This version written on 25-October-1982.
58
Modified on 14-October-1993 to inline the call to DLASSQ.
59
Sven Hammarling, Nag Ltd.
60
Parameter adjustments */
61
--x;
62
/* Function Body */
63
if
(*n < 1 || *incx < 1) {
64
norm = 0.;
65
}
else
if
(*n == 1) {
66
norm =
absMACRO
(x[1]);
67
}
else
{
68
scale = 0.;
69
ssq = 1.;
70
71
72
i__1 = (*n - 1) * *incx + 1;
73
i__2 = *incx;
74
for
(ix = 1; i__2 < 0 ? ix >= i__1 : ix <= i__1; ix += i__2) {
75
if
(x[ix] != 0.) {
76
absxi = (d__1 = x[ix],
absMACRO
(d__1));
77
if
(scale < absxi) {
78
/* Computing 2nd power */
79
d__1 = scale / absxi;
80
ssq = ssq * (d__1 * d__1) + 1.;
81
scale = absxi;
82
}
else
{
83
/* Computing 2nd power */
84
d__1 = absxi / scale;
85
ssq += d__1 * d__1;
86
}
87
}
88
/* L10: */
89
}
90
norm = scale *
template_blas_sqrt
(ssq);
91
}
92
93
ret_val = norm;
94
return
ret_val;
95
96
/* End of DNRM2. */
97
98
}
/* dnrm2_ */
99
100
#endif
template_blas_sqrt
Treal template_blas_sqrt(Treal x)
absMACRO
#define absMACRO(x)
Definition:
template_blas_common.h:47
template_blas_nrm2
Treal template_blas_nrm2(const integer *n, const Treal *x, const integer *incx)
Definition:
template_blas_nrm2.h:42
integer
int integer
Definition:
template_blas_common.h:40
source
matrix
template_lapack
blas
template_blas_nrm2.h
Generated on Sun Aug 16 2020 00:00:00 for ergo by
1.8.18