<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
syr2k.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_LEGACY_SYR2K_HH
12#define TLAPACK_LEGACY_SYR2K_HH
13
17
18namespace tlapack {
19namespace legacy {
20
100 template <typename TA, typename TB, typename TC>
101 void syr2k(Layout layout,
102 Uplo uplo,
103 Op trans,
104 idx_t n,
105 idx_t k,
107 TA const* A,
108 idx_t lda,
109 TB const* B,
110 idx_t ldb,
112 TC* C,
113 idx_t ldc)
114 {
115 using internal::create_matrix;
117
118 // check arguments
119 tlapack_check_false(layout != Layout::ColMajor &&
120 layout != Layout::RowMajor);
121 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper &&
122 uplo != Uplo::General);
123 tlapack_check_false(trans != Op::NoTrans && trans != Op::Trans &&
124 trans != Op::ConjTrans);
125 tlapack_check_false(is_complex<TA> && trans == Op::ConjTrans);
126 tlapack_check_false(n < 0);
128 tlapack_check_false(lda < ((layout == Layout::RowMajor)
129 ? ((trans == Op::NoTrans) ? k : n)
130 : ((trans == Op::NoTrans) ? n : k)));
131 tlapack_check_false(ldb < ((layout == Layout::RowMajor)
132 ? ((trans == Op::NoTrans) ? k : n)
133 : ((trans == Op::NoTrans) ? n : k)));
135
136 // quick return
137 if (n == 0 ||
138 ((alpha == scalar_t(0) || k == 0) && (beta == scalar_t(1))))
139 return;
140
141 // This algorithm only works with Op::NoTrans or Op::Trans
142 if (trans == Op::ConjTrans) trans = Op::Trans;
143
144 // adapt if row major
145 if (layout == Layout::RowMajor) {
146 if (uplo == Uplo::Lower)
147 uplo = Uplo::Upper;
148 else if (uplo == Uplo::Upper)
149 uplo = Uplo::Lower;
150 trans = (trans == Op::NoTrans) ? Op::Trans : Op::NoTrans;
151 }
152
153 // Matrix views
154 const auto A_ = (trans == Op::NoTrans)
155 ? create_matrix<TA>((TA*)A, n, k, lda)
156 : create_matrix<TA>((TA*)A, k, n, lda);
157 const auto B_ = (trans == Op::NoTrans)
158 ? create_matrix<TB>((TB*)B, n, k, ldb)
159 : create_matrix<TB>((TB*)B, k, n, ldb);
160 auto C_ = create_matrix<TC>(C, n, n, ldc);
161
162 if (alpha == scalar_t(0)) {
163 if (beta == scalar_t(0)) {
164 for (idx_t j = 0; j < n; ++j)
165 for (idx_t i = 0; i < n; ++i)
166 C_(i, j) = TC(0);
167 }
168 else {
169 for (idx_t j = 0; j < n; ++j)
170 for (idx_t i = 0; i < n; ++i)
171 C_(i, j) *= beta;
172 }
173 }
174 else {
175 if (beta == scalar_t(0))
176 syr2k(uplo, trans, alpha, A_, B_, C_);
177 else
178 syr2k(uplo, trans, alpha, A_, B_, beta, C_);
179 }
180 }
181
182} // namespace legacy
183} // namespace tlapack
184
185#endif // #ifndef TLAPACK_LEGACY_SYMM_HH
constexpr Layout layout
Layout of a matrix or vector.
Definition arrayTraits.hpp:232
Op
Definition types.hpp:222
Uplo
Definition types.hpp:45
Layout
Definition types.hpp:24
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
void syr2k(Layout layout, Uplo uplo, Op trans, idx_t n, idx_t k, scalar_type< TA, TB, TC > alpha, TA const *A, idx_t lda, TB const *B, idx_t ldb, scalar_type< TA, TB, TC > beta, TC *C, idx_t ldc)
Symmetric rank-k update:
Definition syr2k.hpp:101
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