Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
DenseVector/Serial/Morpheus_Dot_Impl.hpp
1
24#ifndef MORPHEUS_DENSEVECTOR_SERIAL_DOT_IMPL_HPP
25#define MORPHEUS_DENSEVECTOR_SERIAL_DOT_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
35namespace Morpheus {
36namespace Impl {
37
38template <typename ExecSpace, typename Vector1, typename Vector2>
39inline typename Vector2::value_type dot(
40 typename Vector1::size_type n, const Vector1& x, const Vector2& y,
41 typename std::enable_if_t<
42 Morpheus::is_dense_vector_format_container_v<Vector1> &&
43 Morpheus::is_dense_vector_format_container_v<Vector2> &&
44 Morpheus::has_custom_backend_v<ExecSpace> &&
45 Morpheus::has_serial_execution_space_v<ExecSpace> &&
46 Morpheus::has_access_v<ExecSpace, Vector1, Vector2>>* = nullptr) {
47 using size_type = typename Vector1::size_type;
48 using value_type = typename Vector1::non_const_value_type;
49
50 value_type result = value_type(0);
51
52 if (y.data() == x.data()) {
53 for (size_type i = 0; i < n; i++) result += x[i] * x[i];
54 } else {
55 for (size_type i = 0; i < n; i++) result += x[i] * y[i];
56 }
57
58 return result;
59}
60
61} // namespace Impl
62} // namespace Morpheus
63
64#endif // MORPHEUS_ENABLE_SERIAL
65#endif // MORPHEUS_DENSEVECTOR_SERIAL_DOT_IMPL_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24