<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
symv.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_SYMV_HH
12#define TLAPACK_BLAS_SYMV_HH
13
15
16namespace tlapack {
17
40template <TLAPACK_MATRIX matrixA_t,
41 TLAPACK_VECTOR vectorX_t,
42 TLAPACK_VECTOR vectorY_t,
43 TLAPACK_SCALAR alpha_t,
44 TLAPACK_SCALAR beta_t,
45 class T = type_t<vectorY_t>,
46 disable_if_allow_optblas_t<pair<matrixA_t, T>,
47 pair<vectorX_t, T>,
48 pair<vectorY_t, T>,
49 pair<beta_t, T> > = 0>
51 const alpha_t& alpha,
52 const matrixA_t& A,
53 const vectorX_t& x,
54 const beta_t& beta,
55 vectorY_t& y)
56{
57 // data traits
58 using TA = type_t<matrixA_t>;
59 using TX = type_t<vectorX_t>;
60 using idx_t = size_type<matrixA_t>;
61
62 // constants
63 const idx_t n = nrows(A);
64
65 // check arguments
66 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper);
67 tlapack_check_false(ncols(A) != n);
68 tlapack_check_false(size(x) != n);
69 tlapack_check_false(size(y) != n);
70
71 // form y = beta*y
72 for (idx_t i = 0; i < n; ++i)
73 y[i] *= beta;
74
75 if (uplo == Uplo::Upper) {
76 // A is stored in upper triangle
77 // form y += alpha * A * x
78 for (idx_t j = 0; j < n; ++j) {
81 for (idx_t i = 0; i < j; ++i) {
82 y[i] += tmp1 * A(i, j);
83 sum += A(i, j) * x[i];
84 }
85 y[j] += tmp1 * A(j, j) + alpha * sum;
86 }
87 }
88 else {
89 // A is stored in lower triangle
90 // form y += alpha * A * x
91 for (idx_t j = 0; j < n; ++j) {
94 for (idx_t i = j + 1; i < n; ++i) {
95 y[i] += tmp1 * A(i, j);
96 sum += A(i, j) * x[i];
97 }
98 y[j] += tmp1 * A(j, j) + alpha * sum;
99 }
100 }
101}
102
103#ifdef TLAPACK_USE_LAPACKPP
104
105template <TLAPACK_LEGACY_MATRIX matrixA_t,
106 TLAPACK_LEGACY_VECTOR vectorX_t,
107 TLAPACK_LEGACY_VECTOR vectorY_t,
108 TLAPACK_SCALAR alpha_t,
109 TLAPACK_SCALAR beta_t,
110 class T = type_t<vectorY_t>,
111 enable_if_allow_optblas_t<pair<matrixA_t, T>,
112 pair<vectorX_t, T>,
113 pair<vectorY_t, T>,
114 pair<beta_t, T> > = 0>
115void symv(Uplo uplo,
116 const alpha_t alpha,
117 const matrixA_t& A,
118 const vectorX_t& x,
119 const beta_t beta,
120 vectorY_t& y)
121{
122 // Legacy objects
123 auto A_ = legacy_matrix(A);
124 auto x_ = legacy_vector(x);
125 auto y_ = legacy_vector(y);
126
127 // Constants to forward
128 constexpr Layout L = layout<matrixA_t>;
129 const auto& n = A_.n;
130
131 // Warnings for NaNs and Infs
132 if (alpha == alpha_t(0))
134 -2, "Infs and NaNs in A or x will not propagate to y on output");
135 if (beta == beta_t(0) && !is_same_v<beta_t, StrongZero>)
137 -5,
138 "Infs and NaNs in y on input will not propagate to y on output");
139
140 return ::blas::symv((::blas::Layout)L, (::blas::Uplo)uplo, n, alpha, A_.ptr,
141 A_.ldim, x_.ptr, x_.inc, (T)beta, y_.ptr, y_.inc);
142}
143
144#endif
145
167template <TLAPACK_MATRIX matrixA_t,
168 TLAPACK_VECTOR vectorX_t,
169 TLAPACK_VECTOR vectorY_t,
170 TLAPACK_SCALAR alpha_t>
172 const alpha_t& alpha,
173 const matrixA_t& A,
174 const vectorX_t& x,
175 vectorY_t& y)
176{
177 return symv(uplo, alpha, A, x, StrongZero(), y);
178}
179
180} // namespace tlapack
181
182#endif // #ifndef TLAPACK_BLAS_SYMV_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 symv(Uplo uplo, const alpha_t &alpha, const matrixA_t &A, const vectorX_t &x, const beta_t &beta, vectorY_t &y)
Symmetric matrix-vector multiply:
Definition symv.hpp:50
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
#define tlapack_warning(info, detailedInfo)
Warning handler.
Definition exceptionHandling.hpp:156
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
Strong zero type.
Definition StrongZero.hpp:43