Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Dia/Kokkos/Morpheus_MatrixOperations_Impl.hpp
1
24#ifndef MORPHEUS_DIA_KOKKOS_MATRIXOPERATIONS_IMPL_HPP
25#define MORPHEUS_DIA_KOKKOS_MATRIXOPERATIONS_IMPL_HPP
26
27#include <Morpheus_Exceptions.hpp>
28#include <Morpheus_SpaceTraits.hpp>
29#include <Morpheus_FormatTraits.hpp>
30#include <Morpheus_FormatTags.hpp>
31#include <Morpheus_Spaces.hpp>
32
33namespace Morpheus {
34namespace Impl {
35
36template <typename ExecSpace, typename Matrix, typename Vector>
37void update_diagonal(
38 Matrix& A, const Vector& diagonal,
39 typename std::enable_if_t<
40 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
41 Morpheus::is_dense_vector_format_container_v<Vector> &&
42 Morpheus::has_generic_backend_v<ExecSpace> &&
43 Morpheus::has_access_v<ExecSpace, Matrix, Vector>>* = nullptr) {
44 using execution_space = typename ExecSpace::execution_space;
45 using value_array_type = typename Matrix::value_array_type::value_array_type;
46 using index_array_type = typename Matrix::index_array_type::value_array_type;
47 using array_type = typename Vector::value_array_type;
48 using size_type = typename Matrix::size_type;
49 using index_type = typename Matrix::index_type;
50 using value_type = typename Matrix::value_type;
51 using range_policy =
52 Kokkos::RangePolicy<Kokkos::IndexType<size_type>, execution_space>;
53
54 value_array_type values = A.values().view();
55 index_array_type diagonal_offsets = A.diagonal_offsets().view();
56 const array_type diagonal_view = diagonal.const_view();
57
58 size_type ndiag = A.values().ncols(), ncols = A.ncols();
59
60 range_policy policy(0, A.nrows());
61
62 Kokkos::parallel_for(
63 policy, KOKKOS_LAMBDA(const size_type row) {
64 for (size_type n = 0; n < ndiag; n++) {
65 const index_type col = row + diagonal_offsets[n];
66
67 if ((col >= 0 && col < (index_type)ncols) &&
68 (col == (index_type)row)) {
69 values(row, n) =
70 (values(row, n) == value_type(0)) ? 0 : diagonal_view[col];
71 }
72 }
73 });
74}
75
76template <typename ExecSpace, typename Matrix, typename Vector>
77void get_diagonal(
78 Matrix&, const Vector&,
79 typename std::enable_if_t<
80 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
81 Morpheus::is_dense_vector_format_container_v<Vector> &&
82 Morpheus::has_generic_backend_v<ExecSpace> &&
83 Morpheus::has_access_v<ExecSpace, Matrix, Vector>>* = nullptr) {
84 throw Morpheus::NotImplementedException("get_diagonal not implemented yet");
85}
86
87template <typename ExecSpace, typename Matrix, typename SizeType,
88 typename ValueType>
89void set_value(Matrix&, SizeType, SizeType, ValueType,
90 typename std::enable_if_t<
91 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
92 Morpheus::has_generic_backend_v<ExecSpace> &&
93 Morpheus::has_access_v<ExecSpace, Matrix>>* = nullptr) {
94 throw Morpheus::NotImplementedException("set_value not implemented yet");
95}
96
97template <typename ExecSpace, typename Matrix, typename IndexVector,
98 typename ValueVector>
99void set_values(
100 Matrix&, typename IndexVector::value_type, const IndexVector,
101 typename IndexVector::value_type, const IndexVector, const ValueVector,
102 typename std::enable_if_t<
103 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
104 Morpheus::is_dense_vector_format_container_v<IndexVector> &&
105 Morpheus::is_dense_vector_format_container_v<ValueVector> &&
106 Morpheus::has_generic_backend_v<ExecSpace> &&
107 Morpheus::has_access_v<ExecSpace, Matrix, IndexVector, ValueVector>>* =
108 nullptr) {
109 throw Morpheus::NotImplementedException("set_values not implemented yet");
110}
111
112template <typename ExecSpace, typename Matrix, typename TransposeMatrix>
113void transpose(
114 const Matrix&, TransposeMatrix&,
115 typename std::enable_if_t<
116 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
117 Morpheus::is_dia_matrix_format_container_v<TransposeMatrix> &&
118 Morpheus::has_generic_backend_v<ExecSpace> &&
119 Morpheus::has_access_v<ExecSpace, Matrix, TransposeMatrix>>* =
120 nullptr) {
121 throw Morpheus::NotImplementedException("transpose not implemented yet");
122}
123
124} // namespace Impl
125} // namespace Morpheus
126
127#endif // MORPHEUS_DIA_KOKKOS_MATRIXOPERATIONS_IMPL_HPP
Definition: Morpheus_Exceptions.hpp:43
Generic Morpheus interfaces.
Definition: dummy.cpp:24