Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
DenseVector/Serial/Morpheus_WAXPBY_Impl.hpp
1
24#ifndef MORPHEUS_DENSEVECTOR_SERIAL_WAXPBY_IMPL_HPP
25#define MORPHEUS_DENSEVECTOR_SERIAL_WAXPBY_IMPL_HPP
26
27#include <Morpheus_Macros.hpp>
28#if defined(MORPHEUS_ENABLE_SERIAL)
29
30#include <Morpheus_SpaceTraits.hpp>
31#include <Morpheus_FormatTraits.hpp>
32#include <Morpheus_FormatTags.hpp>
33#include <Morpheus_Spaces.hpp>
34
35#include <cassert>
36
37namespace Morpheus {
38namespace Impl {
39template <typename ExecSpace, typename Vector1, typename Vector2,
40 typename Vector3>
41inline void waxpby(
42 const typename Vector1::size_type n,
43 const typename Vector1::value_type alpha, const Vector1& x,
44 const typename Vector2::value_type beta, const Vector2& y, Vector3& w,
45 typename std::enable_if_t<
46 Morpheus::is_dense_vector_format_container_v<Vector1> &&
47 Morpheus::is_dense_vector_format_container_v<Vector2> &&
48 Morpheus::is_dense_vector_format_container_v<Vector3> &&
49 Morpheus::has_custom_backend_v<ExecSpace> &&
50 Morpheus::has_serial_execution_space_v<ExecSpace> &&
51 Morpheus::has_access_v<ExecSpace, Vector1, Vector2, Vector3>>* =
52 nullptr) {
53 using size_type = typename Vector1::size_type;
54
55 assert(x.size() >= n);
56 assert(y.size() >= n);
57 assert(w.size() >= n);
58
59 if (alpha == 1.0) {
60 for (size_type i = 0; i < n; i++) w[i] = x[i] + beta * y[i];
61 } else if (beta == 1.0) {
62 for (size_type i = 0; i < n; i++) w[i] = alpha * x[i] + y[i];
63 } else {
64 for (size_type i = 0; i < n; i++) w[i] = alpha * x[i] + beta * y[i];
65 }
66}
67
68} // namespace Impl
69} // namespace Morpheus
70
71#endif // MORPHEUS_ENABLE_SERIAL
72#endif // MORPHEUS_DENSEVECTOR_SERIAL_WAXPBY_IMPL_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24