ergo
template_lapack_larf.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_LARF_HEADER
38#define TEMPLATE_LAPACK_LARF_HEADER
39
40
41template<class Treal>
42int template_lapack_larf(const char *side, const integer *m, const integer *n, const Treal *v,
43 const integer *incv, const Treal *tau, Treal *c__, const integer *ldc,
44 Treal *work)
45{
46/* -- LAPACK auxiliary routine (version 3.0) --
47 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
48 Courant Institute, Argonne National Lab, and Rice University
49 February 29, 1992
50
51
52 Purpose
53 =======
54
55 DLARF applies a real elementary reflector H to a real m by n matrix
56 C, from either the left or the right. H is represented in the form
57
58 H = I - tau * v * v'
59
60 where tau is a real scalar and v is a real vector.
61
62 If tau = 0, then H is taken to be the unit matrix.
63
64 Arguments
65 =========
66
67 SIDE (input) CHARACTER*1
68 = 'L': form H * C
69 = 'R': form C * H
70
71 M (input) INTEGER
72 The number of rows of the matrix C.
73
74 N (input) INTEGER
75 The number of columns of the matrix C.
76
77 V (input) DOUBLE PRECISION array, dimension
78 (1 + (M-1)*abs(INCV)) if SIDE = 'L'
79 or (1 + (N-1)*abs(INCV)) if SIDE = 'R'
80 The vector v in the representation of H. V is not used if
81 TAU = 0.
82
83 INCV (input) INTEGER
84 The increment between elements of v. INCV <> 0.
85
86 TAU (input) DOUBLE PRECISION
87 The value tau in the representation of H.
88
89 C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
90 On entry, the m by n matrix C.
91 On exit, C is overwritten by the matrix H * C if SIDE = 'L',
92 or C * H if SIDE = 'R'.
93
94 LDC (input) INTEGER
95 The leading dimension of the array C. LDC >= max(1,M).
96
97 WORK (workspace) DOUBLE PRECISION array, dimension
98 (N) if SIDE = 'L'
99 or (M) if SIDE = 'R'
100
101 =====================================================================
102
103
104 Parameter adjustments */
105 /* Table of constant values */
106 Treal c_b4 = 1.;
107 Treal c_b5 = 0.;
108 integer c__1 = 1;
109
110 /* System generated locals */
111 integer c_dim1, c_offset;
112 Treal d__1;
113
114
115 --v;
116 c_dim1 = *ldc;
117 c_offset = 1 + c_dim1 * 1;
118 c__ -= c_offset;
119 --work;
120
121 /* Function Body */
122 if (template_blas_lsame(side, "L")) {
123
124/* Form H * C */
125
126 if (*tau != 0.) {
127
128/* w := C' * v */
129
130 template_blas_gemv("Transpose", m, n, &c_b4, &c__[c_offset], ldc, &v[1], incv,
131 &c_b5, &work[1], &c__1);
132
133/* C := C - v * w' */
134
135 d__1 = -(*tau);
136 template_blas_ger(m, n, &d__1, &v[1], incv, &work[1], &c__1, &c__[c_offset],
137 ldc);
138 }
139 } else {
140
141/* Form C * H */
142
143 if (*tau != 0.) {
144
145/* w := C * v */
146
147 template_blas_gemv("No transpose", m, n, &c_b4, &c__[c_offset], ldc, &v[1],
148 incv, &c_b5, &work[1], &c__1);
149
150/* C := C - w * v' */
151
152 d__1 = -(*tau);
153 template_blas_ger(m, n, &d__1, &work[1], &c__1, &v[1], incv, &c__[c_offset],
154 ldc);
155 }
156 }
157 return 0;
158
159/* End of DLARF */
160
161} /* dlarf_ */
162
163#endif
side
Definition: Matrix.h:75
logical template_blas_lsame(const char *ca, const char *cb)
Definition: template_blas_common.cc:46
int integer
Definition: template_blas_common.h:40
int template_blas_gemv(const char *trans, const integer *m, const integer *n, const Treal *alpha, const Treal *a, const integer *lda, const Treal *x, const integer *incx, const Treal *beta, Treal *y, const integer *incy)
Definition: template_blas_gemv.h:43
int template_blas_ger(const integer *m, const integer *n, const Treal *alpha, const Treal *x, const integer *incx, const Treal *y, const integer *incy, Treal *a, const integer *lda)
Definition: template_blas_ger.h:42
int template_lapack_larf(const char *side, const integer *m, const integer *n, const Treal *v, const integer *incv, const Treal *tau, Treal *c__, const integer *ldc, Treal *work)
Definition: template_lapack_larf.h:42