<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
syr2.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_SYR2_HH
12#define TLAPACK_BLAS_SYR2_HH
13
15
16namespace tlapack {
17
39template <TLAPACK_MATRIX matrixA_t,
40 TLAPACK_VECTOR vectorX_t,
41 TLAPACK_VECTOR vectorY_t,
42 TLAPACK_SCALAR alpha_t,
43 class T = type_t<matrixA_t>,
44 disable_if_allow_optblas_t<pair<alpha_t, T>,
45 pair<matrixA_t, T>,
46 pair<vectorX_t, T>,
47 pair<vectorY_t, T> > = 0>
49 const alpha_t& alpha,
50 const vectorX_t& x,
51 const vectorY_t& y,
52 matrixA_t& A)
53{
54 // data traits
55 using idx_t = size_type<matrixA_t>;
56 using TX = type_t<vectorX_t>;
57 using TY = type_t<vectorY_t>;
58
59 // constants
60 const idx_t n = nrows(A);
61
62 // check arguments
63 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper);
64 tlapack_check_false(size(x) != n);
65 tlapack_check_false(size(y) != n);
66 tlapack_check_false(ncols(A) != n);
67
68 if (uplo == Uplo::Upper) {
69 for (idx_t j = 0; j < n; ++j) {
72 for (idx_t i = 0; i <= j; ++i)
73 A(i, j) += x[i] * tmp1 + y[i] * tmp2;
74 }
75 }
76 else {
77 for (idx_t j = 0; j < n; ++j) {
80 for (idx_t i = j; i < n; ++i)
81 A(i, j) += x[i] * tmp1 + y[i] * tmp2;
82 }
83 }
84}
85
86#ifdef TLAPACK_USE_LAPACKPP
87
88template <TLAPACK_LEGACY_MATRIX matrixA_t,
89 TLAPACK_LEGACY_VECTOR vectorX_t,
90 TLAPACK_LEGACY_VECTOR vectorY_t,
91 TLAPACK_SCALAR alpha_t,
92 class T = type_t<matrixA_t>,
93 enable_if_allow_optblas_t<pair<alpha_t, T>,
94 pair<matrixA_t, T>,
95 pair<vectorX_t, T>,
96 pair<vectorY_t, T> > = 0>
97void syr2(Uplo uplo,
98 const alpha_t alpha,
99 const vectorX_t& x,
100 const vectorY_t& y,
101 matrixA_t& A)
102{
103 // Legacy objects
104 auto A_ = legacy_matrix(A);
105 auto x_ = legacy_vector(x);
106 auto y_ = legacy_vector(y);
107
108 // Constants to forward
109 constexpr Layout L = layout<matrixA_t>;
110 const auto& n = A_.n;
111
112 return ::blas::syr2((::blas::Layout)L, (::blas::Uplo)uplo, n, alpha, x_.ptr,
113 x_.inc, y_.ptr, y_.inc, A_.ptr, A_.ldim);
114}
115
116#endif
117
118} // namespace tlapack
119
120#endif // #ifndef TLAPACK_BLAS_SYR2_HH
Uplo
Definition types.hpp:45
#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 syr2(Uplo uplo, const alpha_t &alpha, const vectorX_t &x, const vectorY_t &y, matrixA_t &A)
Symmetric matrix rank-2 update:
Definition syr2.hpp:48
#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