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