<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
her2k.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_HER2K_HH
12#define TLAPACK_LEGACY_HER2K_HH
13
17
18namespace tlapack {
19namespace legacy {
20
99 template <typename TA, typename TB, typename TC>
100 void her2k(Layout layout,
101 Uplo uplo,
102 Op trans,
103 idx_t n,
104 idx_t k,
105 scalar_type<TA, TB, TC> alpha, // note: complex
106 TA const* A,
107 idx_t lda,
108 TB const* B,
109 idx_t ldb,
110 real_type<TA, TB, TC> beta, // note: real
111 TC* C,
112 idx_t ldc)
113 {
114 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);
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 || ((alpha == scalar_t(0) || k == 0) && (beta == real_t(1))))
138 return;
139
140 // This algorithm only works with Op::NoTrans or Op::ConjTrans
141 if (trans == Op::Trans) trans = Op::ConjTrans;
142
143 // adapt if row major
144 if (layout == Layout::RowMajor) {
145 if (uplo == Uplo::Lower)
146 uplo = Uplo::Upper;
147 else if (uplo == Uplo::Upper)
148 uplo = Uplo::Lower;
149 trans = (trans == Op::NoTrans) ? Op::ConjTrans : Op::NoTrans;
150 alpha = conj(alpha);
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 == real_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 == real_t(0))
176 her2k(uplo, trans, alpha, A_, B_, C_);
177 else
178 her2k(uplo, trans, alpha, A_, B_, beta, C_);
179 }
180 }
181
182} // namespace legacy
183} // namespace tlapack
184
185#endif // #ifndef TLAPACK_LEGACY_HER2K_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
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
void her2k(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, real_type< TA, TB, TC > beta, TC *C, idx_t ldc)
Hermitian rank-k update:
Definition her2k.hpp:100
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