<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
her2.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_HER2_HH
12#define TLAPACK_BLAS_HER2_HH
13
15
16namespace tlapack {
17
41template <TLAPACK_MATRIX matrixA_t,
42 TLAPACK_VECTOR vectorX_t,
43 TLAPACK_VECTOR vectorY_t,
44 TLAPACK_SCALAR alpha_t,
45 class T = type_t<matrixA_t>,
46 disable_if_allow_optblas_t<pair<alpha_t, T>,
47 pair<matrixA_t, T>,
48 pair<vectorX_t, T>,
49 pair<vectorY_t, T> > = 0>
51 const alpha_t& alpha,
52 const vectorX_t& x,
53 const vectorY_t& y,
54 matrixA_t& A)
55{
56 // data traits
57 using idx_t = size_type<matrixA_t>;
58 using TX = type_t<vectorX_t>;
59 using TY = type_t<vectorY_t>;
60
61 // constants
62 const idx_t n = nrows(A);
63
64 // check arguments
65 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper);
66 tlapack_check_false(size(x) != n);
67 tlapack_check_false(size(y) != n);
68 tlapack_check_false(ncols(A) != n);
69
70 if (uplo == Uplo::Upper) {
71 for (idx_t j = 0; j < n; ++j) {
74 for (idx_t i = 0; i < j; ++i)
75 A(i, j) += x[i] * tmp1 + y[i] * tmp2;
76 A(j, j) = real(A(j, j)) + real(x[j]) * real(tmp1) -
77 imag(x[j]) * imag(tmp1) + real(y[j]) * real(tmp2) -
78 imag(y[j]) * imag(tmp2);
79 }
80 }
81 else {
82 for (idx_t j = 0; j < n; ++j) {
85 A(j, j) = real(A(j, j)) + real(x[j]) * real(tmp1) -
86 imag(x[j]) * imag(tmp1) + real(y[j]) * real(tmp2) -
87 imag(y[j]) * imag(tmp2);
88 for (idx_t i = j + 1; i < n; ++i)
89 A(i, j) += x[i] * tmp1 + y[i] * tmp2;
90 }
91 }
92}
93
94#ifdef TLAPACK_USE_LAPACKPP
95
96template <TLAPACK_LEGACY_MATRIX matrixA_t,
97 TLAPACK_LEGACY_VECTOR vectorX_t,
98 TLAPACK_LEGACY_VECTOR vectorY_t,
99 TLAPACK_SCALAR alpha_t,
100 class T = type_t<matrixA_t>,
101 enable_if_allow_optblas_t<pair<alpha_t, T>,
102 pair<matrixA_t, T>,
103 pair<vectorX_t, T>,
104 pair<vectorY_t, T> > = 0>
105void her2(Uplo uplo,
106 const alpha_t alpha,
107 const vectorX_t& x,
108 const vectorY_t& y,
109 matrixA_t& A)
110{
111 // Legacy objects
112 auto A_ = legacy_matrix(A);
113 auto x_ = legacy_vector(x);
114 auto y_ = legacy_vector(y);
115
116 // Constants to forward
117 constexpr Layout L = layout<matrixA_t>;
118 const auto& n = A_.n;
119
120 return ::blas::her2((::blas::Layout)L, (::blas::Uplo)uplo, n, alpha, x_.ptr,
121 x_.inc, y_.ptr, y_.inc, A_.ptr, A_.ldim);
122}
123
124#endif
125
126} // namespace tlapack
127
128#endif // #ifndef TLAPACK_BLAS_HER2_HH
Uplo
Definition types.hpp:45
constexpr real_type< T > real(const T &x) noexcept
Extends std::real() to real datatypes.
Definition utils.hpp:71
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
constexpr real_type< T > imag(const T &x) noexcept
Extends std::imag() to real datatypes.
Definition utils.hpp:86
#define TLAPACK_SCALAR
Macro for tlapack::concepts::Scalar compatible with C++17.
Definition concepts.hpp:915
#define TLAPACK_LEGACY_VECTOR
Macro for tlapack::concepts::LegacyVector compatible with C++17.
Definition concepts.hpp:954
#define TLAPACK_LEGACY_MATRIX
Macro for tlapack::concepts::LegacyMatrix compatible with C++17.
Definition concepts.hpp:951
#define TLAPACK_VECTOR
Macro for tlapack::concepts::Vector compatible with C++17.
Definition concepts.hpp:906
#define TLAPACK_MATRIX
Macro for tlapack::concepts::Matrix compatible with C++17.
Definition concepts.hpp:896
void her2(Uplo uplo, const alpha_t &alpha, const vectorX_t &x, const vectorY_t &y, matrixA_t &A)
Hermitian matrix rank-2 update:
Definition her2.hpp:50
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
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