<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
symm.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2017-2021, University of Tennessee. All rights reserved.
5// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
6//
7// This file is part of <T>LAPACK.
8// <T>LAPACK is free software: you can redistribute it and/or modify it under
9// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
10
11#ifndef TLAPACK_BLAS_SYMM_HH
12#define TLAPACK_BLAS_SYMM_HH
13
15
16namespace tlapack {
17
50template <TLAPACK_MATRIX matrixA_t,
51 TLAPACK_MATRIX matrixB_t,
52 TLAPACK_MATRIX matrixC_t,
53 TLAPACK_SCALAR alpha_t,
54 TLAPACK_SCALAR beta_t,
55 class T = type_t<matrixC_t>,
56 disable_if_allow_optblas_t<pair<matrixA_t, T>,
57 pair<matrixB_t, T>,
58 pair<matrixC_t, T>,
59 pair<alpha_t, T>,
60 pair<beta_t, T> > = 0>
62 Uplo uplo,
63 const alpha_t& alpha,
64 const matrixA_t& A,
65 const matrixB_t& B,
66 const beta_t& beta,
67 matrixC_t& C)
68{
69 // data traits
70 using TA = type_t<matrixA_t>;
71 using TB = type_t<matrixB_t>;
72 using idx_t = size_type<matrixC_t>;
73
74 // constants
75 const idx_t m = nrows(B);
76 const idx_t n = ncols(B);
77
78 // check arguments
79 tlapack_check_false(side != Side::Left && side != Side::Right);
80 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper &&
81 uplo != Uplo::General);
82 tlapack_check_false(nrows(A) != ncols(A));
83 tlapack_check_false(nrows(A) != ((side == Side::Left) ? m : n));
84 tlapack_check_false(nrows(C) != m);
85 tlapack_check_false(ncols(C) != n);
86
87 if (side == Side::Left) {
88 if (uplo != Uplo::Lower) {
89 // uplo == Uplo::Upper or uplo == Uplo::General
90 for (idx_t j = 0; j < n; ++j) {
91 for (idx_t i = 0; i < m; ++i) {
93 alpha * B(i, j);
95
96 for (idx_t k = 0; k < i; ++k) {
97 C(k, j) += A(k, i) * alphaTimesBij;
98 sum += A(k, i) * B(k, j);
99 }
100 C(i, j) =
101 beta * C(i, j) + A(i, i) * alphaTimesBij + alpha * sum;
102 }
103 }
104 }
105 else {
106 // uplo == Uplo::Lower
107 for (idx_t j = 0; j < n; ++j) {
108 for (idx_t i = m - 1; i != idx_t(-1); --i) {
110 alpha * B(i, j);
112
113 for (idx_t k = i + 1; k < m; ++k) {
114 C(k, j) += A(k, i) * alphaTimesBij;
115 sum += A(k, i) * B(k, j);
116 }
117 C(i, j) =
118 beta * C(i, j) + A(i, i) * alphaTimesBij + alpha * sum;
119 }
120 }
121 }
122 }
123 else { // side == Side::Right
124
126
127 if (uplo != Uplo::Lower) {
128 // uplo == Uplo::Upper or uplo == Uplo::General
129 for (idx_t j = 0; j < n; ++j) {
130 {
131 const scalar_t alphaTimesAjj = alpha * A(j, j);
132 for (idx_t i = 0; i < m; ++i)
133 C(i, j) = beta * C(i, j) + B(i, j) * alphaTimesAjj;
134 }
135
136 for (idx_t k = 0; k < j; ++k) {
137 const scalar_t alphaTimesAkj = alpha * A(k, j);
138 for (idx_t i = 0; i < m; ++i)
139 C(i, j) += B(i, k) * alphaTimesAkj;
140 }
141
142 for (idx_t k = j + 1; k < n; ++k) {
143 const scalar_t alphaTimesAjk = alpha * A(j, k);
144 for (idx_t i = 0; i < m; ++i)
145 C(i, j) += B(i, k) * alphaTimesAjk;
146 }
147 }
148 }
149 else {
150 // uplo == Uplo::Lower
151 for (idx_t j = 0; j < n; ++j) {
152 {
153 const scalar_t alphaTimesAjj = alpha * A(j, j);
154 for (idx_t i = 0; i < m; ++i)
155 C(i, j) = beta * C(i, j) + B(i, j) * alphaTimesAjj;
156 }
157
158 for (idx_t k = 0; k < j; ++k) {
159 const scalar_t alphaTimesAjk = alpha * A(j, k);
160 for (idx_t i = 0; i < m; ++i)
161 C(i, j) += B(i, k) * alphaTimesAjk;
162 }
163
164 for (idx_t k = j + 1; k < n; ++k) {
165 const scalar_t alphaTimesAkj = alpha * A(k, j);
166 for (idx_t i = 0; i < m; ++i)
167 C(i, j) += B(i, k) * alphaTimesAkj;
168 }
169 }
170 }
171 }
172}
173
174#ifdef TLAPACK_USE_LAPACKPP
175
189template <TLAPACK_LEGACY_MATRIX matrixA_t,
190 TLAPACK_LEGACY_MATRIX matrixB_t,
191 TLAPACK_LEGACY_MATRIX matrixC_t,
192 TLAPACK_SCALAR alpha_t,
193 TLAPACK_SCALAR beta_t,
194 class T = type_t<matrixC_t>,
195 enable_if_allow_optblas_t<pair<matrixA_t, T>,
196 pair<matrixB_t, T>,
197 pair<matrixC_t, T>,
198 pair<alpha_t, T>,
199 pair<beta_t, T> > = 0>
200void symm(Side side,
201 Uplo uplo,
202 const alpha_t alpha,
203 const matrixA_t& A,
204 const matrixB_t& B,
205 const beta_t beta,
206 matrixC_t& C)
207{
208 // Legacy objects
209 auto A_ = legacy_matrix(A);
210 auto B_ = legacy_matrix(B);
211 auto C_ = legacy_matrix(C);
212
213 // Constants to forward
214 constexpr Layout L = layout<matrixC_t>;
215 const auto& m = C_.m;
216 const auto& n = C_.n;
217
218 // Warnings for NaNs and Infs
219 if (alpha == alpha_t(0))
221 -3, "Infs and NaNs in A or B will not propagate to C on output");
222 if (beta == beta_t(0) && !is_same_v<beta_t, StrongZero>)
224 -6,
225 "Infs and NaNs in C on input will not propagate to C on output");
226
227 return ::blas::symm((::blas::Layout)L, (::blas::Side)side,
228 (::blas::Uplo)uplo, m, n, alpha, A_.ptr, A_.ldim,
229 B_.ptr, B_.ldim, (T)beta, C_.ptr, C_.ldim);
230}
231
232#endif
233
265template <TLAPACK_MATRIX matrixA_t,
266 TLAPACK_MATRIX matrixB_t,
267 TLAPACK_MATRIX matrixC_t,
268 TLAPACK_SCALAR alpha_t>
270 Uplo uplo,
271 const alpha_t& alpha,
272 const matrixA_t& A,
273 const matrixB_t& B,
274 matrixC_t& C)
275{
276 return symm(side, uplo, alpha, A, B, StrongZero(), C);
277}
278
279} // namespace tlapack
280
281#endif // #ifndef TLAPACK_BLAS_SYMM_HH
Side
Definition types.hpp:266
Uplo
Definition types.hpp:45
#define TLAPACK_SCALAR
Macro for tlapack::concepts::Scalar compatible with C++17.
Definition concepts.hpp:915
#define TLAPACK_LEGACY_MATRIX
Macro for tlapack::concepts::LegacyMatrix compatible with C++17.
Definition concepts.hpp:951
#define TLAPACK_MATRIX
Macro for tlapack::concepts::Matrix compatible with C++17.
Definition concepts.hpp:896
void symm(Side side, Uplo uplo, const alpha_t &alpha, const matrixA_t &A, const matrixB_t &B, const beta_t &beta, matrixC_t &C)
Symmetric matrix-matrix multiply:
Definition symm.hpp:61
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
#define tlapack_warning(info, detailedInfo)
Warning handler.
Definition exceptionHandling.hpp:156
Concept for types that represent tlapack::Side.
Concept for types that represent tlapack::Uplo.
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113
Strong zero type.
Definition StrongZero.hpp:43