<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
syrk.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_SYRK_HH
12#define TLAPACK_LEGACY_SYRK_HH
13
14#include "tlapack/blas/syrk.hpp"
17
18namespace tlapack {
19namespace legacy {
20
88 template <typename TA, typename TC>
89 void syrk(Layout layout,
90 Uplo uplo,
91 Op trans,
92 idx_t n,
93 idx_t k,
95 TA const* A,
96 idx_t lda,
98 TC* C,
99 idx_t ldc)
100 {
101 using internal::create_matrix;
103
104 // check arguments
105 tlapack_check_false(layout != Layout::ColMajor &&
106 layout != Layout::RowMajor);
107 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper &&
108 uplo != Uplo::General);
109 tlapack_check_false(trans != Op::NoTrans && trans != Op::Trans &&
110 trans != Op::ConjTrans);
111 tlapack_check_false(is_complex<TA> && trans == Op::ConjTrans);
112 tlapack_check_false(n < 0);
114 tlapack_check_false(lda < ((layout == Layout::RowMajor)
115 ? ((trans == Op::NoTrans) ? k : n)
116 : ((trans == Op::NoTrans) ? n : k)));
118
119 // quick return
120 if (n == 0 ||
121 ((alpha == scalar_t(0) || k == 0) && (beta == scalar_t(1))))
122 return;
123
124 // This algorithm only works with Op::NoTrans or Op::Trans
125 if (trans == Op::ConjTrans) trans = Op::Trans;
126
127 // adapt if row major
128 if (layout == Layout::RowMajor) {
129 if (uplo == Uplo::Lower)
130 uplo = Uplo::Upper;
131 else if (uplo == Uplo::Upper)
132 uplo = Uplo::Lower;
133 trans = (trans == Op::NoTrans) ? Op::Trans : Op::NoTrans;
134 }
135
136 // Matrix views
137 const auto A_ = (trans == Op::NoTrans)
138 ? create_matrix<TA>((TA*)A, n, k, lda)
139 : create_matrix<TA>((TA*)A, k, n, lda);
140 auto C_ = create_matrix<TC>(C, n, n, ldc);
141
142 if (alpha == scalar_t(0)) {
143 if (beta == scalar_t(0)) {
144 for (idx_t j = 0; j < n; ++j)
145 for (idx_t i = 0; i < n; ++i)
146 C_(i, j) = TC(0);
147 }
148 else {
149 for (idx_t j = 0; j < n; ++j)
150 for (idx_t i = 0; i < n; ++i)
151 C_(i, j) *= beta;
152 }
153 }
154 else {
155 if (beta == scalar_t(0))
156 syrk(uplo, trans, alpha, A_, C_);
157 else
158 syrk(uplo, trans, alpha, A_, beta, C_);
159 }
160 }
161
162} // namespace legacy
163} // namespace tlapack
164
165#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 syrk(Layout layout, Uplo uplo, Op trans, idx_t n, idx_t k, scalar_type< TA, TC > alpha, TA const *A, idx_t lda, scalar_type< TA, TC > beta, TC *C, idx_t ldc)
Symmetric rank-k update:
Definition syrk.hpp:89
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