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