<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
axpy.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_AXPY_HH
12#define TLAPACK_BLAS_AXPY_HH
13
15
16namespace tlapack {
17
27template <TLAPACK_VECTOR vectorX_t,
28 TLAPACK_VECTOR vectorY_t,
29 TLAPACK_SCALAR alpha_t,
30 class T = type_t<vectorY_t>,
31 disable_if_allow_optblas_t<pair<alpha_t, T>,
32 pair<vectorX_t, T>,
33 pair<vectorY_t, T> > = 0>
34void axpy(const alpha_t& alpha, const vectorX_t& x, vectorY_t& y)
35{
36 using idx_t = size_type<vectorX_t>;
37
38 // constants
39 const idx_t n = size(x);
40
41 // check arguments
42 tlapack_check_false((idx_t)size(y) < n);
43
44 for (idx_t i = 0; i < n; ++i)
45 y[i] += alpha * x[i];
46}
47
48#ifdef TLAPACK_USE_LAPACKPP
49
50template <TLAPACK_LEGACY_VECTOR vectorX_t,
51 TLAPACK_LEGACY_VECTOR vectorY_t,
52 TLAPACK_SCALAR alpha_t,
53 class T = type_t<vectorY_t>,
54 enable_if_allow_optblas_t<pair<alpha_t, T>,
55 pair<vectorX_t, T>,
56 pair<vectorY_t, T> > = 0>
57void axpy(const alpha_t alpha, const vectorX_t& x, vectorY_t& y)
58{
59 // Legacy objects
60 auto x_ = legacy_vector(x);
61 auto y_ = legacy_vector(y);
62
63 // Constants to forward
64 const auto& n = x_.n;
65
66 // Warnings for NaNs and Infs
67 if (alpha == alpha_t(0))
69 "Infs and NaNs in x will not propagate to y on output");
70
71 return ::blas::axpy(n, alpha, x_.ptr, x_.inc, y_.ptr, y_.inc);
72}
73
74#endif
75
76} // namespace tlapack
77
78#endif // #ifndef TLAPACK_BLAS_AXPY_HH
#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_VECTOR
Macro for tlapack::concepts::Vector compatible with C++17.
Definition concepts.hpp:906
void axpy(const alpha_t &alpha, const vectorX_t &x, vectorY_t &y)
Add scaled vector, .
Definition axpy.hpp:34
#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
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