24#ifndef MORPHEUS_CSR_SERIAL_CONVERT_IMPL_HPP
25#define MORPHEUS_CSR_SERIAL_CONVERT_IMPL_HPP
27#include <Morpheus_Macros.hpp>
28#if defined(MORPHEUS_ENABLE_SERIAL)
30#include <Morpheus_SpaceTraits.hpp>
31#include <Morpheus_FormatTraits.hpp>
32#include <Morpheus_FormatTags.hpp>
33#include <Morpheus_Spaces.hpp>
38template <
typename ExecSpace,
typename SourceType,
typename DestinationType>
40 const SourceType& src, DestinationType& dst,
41 typename std::enable_if<
42 Morpheus::is_csr_matrix_format_container_v<SourceType> &&
43 Morpheus::is_csr_matrix_format_container_v<DestinationType> &&
44 Morpheus::has_custom_backend_v<ExecSpace> &&
45 Morpheus::has_serial_execution_space_v<ExecSpace> &&
46 Morpheus::has_access_v<ExecSpace, SourceType, DestinationType>>::type* =
48 using size_type =
typename SourceType::size_type;
50 dst.resize(src.nrows(), src.ncols(), src.nnnz());
53 for (size_type n = 0; n < src.nrows() + 1; n++) {
54 dst.row_offsets(n) = src.crow_offsets(n);
57 for (size_type n = 0; n < src.nnnz(); n++) {
58 dst.column_indices(n) = src.ccolumn_indices(n);
61 for (size_type n = 0; n < src.nnnz(); n++) {
62 dst.values(n) = src.cvalues(n);
66template <
typename ExecSpace,
typename SourceType,
typename DestinationType>
68 const SourceType& src, DestinationType& dst,
69 typename std::enable_if<
70 Morpheus::is_csr_matrix_format_container_v<SourceType> &&
71 Morpheus::is_coo_matrix_format_container_v<DestinationType> &&
72 Morpheus::has_custom_backend_v<ExecSpace> &&
73 Morpheus::has_serial_execution_space_v<ExecSpace> &&
74 Morpheus::has_access_v<ExecSpace, SourceType, DestinationType>>::type* =
77 using size_type =
typename SourceType::size_type;
78 using index_type =
typename SourceType::index_type;
80 dst.resize(src.nrows(), src.ncols(), src.nnnz());
83 for (size_type i = 0; i < src.nrows(); i++) {
84 for (index_type jj = src.crow_offsets(i); jj < src.crow_offsets(i + 1);
86 dst.row_indices(jj) = i;
90 for (size_type n = 0; n < src.nnnz(); n++) {
91 dst.column_indices(n) = src.ccolumn_indices(n);
94 for (size_type n = 0; n < src.nnnz(); n++) {
95 dst.values(n) = src.cvalues(n);
99template <
typename ExecSpace,
typename SourceType,
typename DestinationType>
101 const SourceType& src, DestinationType& dst,
102 typename std::enable_if<
103 Morpheus::is_coo_matrix_format_container_v<SourceType> &&
104 Morpheus::is_csr_matrix_format_container_v<DestinationType> &&
105 Morpheus::has_custom_backend_v<ExecSpace> &&
106 Morpheus::has_serial_execution_space_v<ExecSpace> &&
107 Morpheus::has_access_v<ExecSpace, SourceType, DestinationType>>::type* =
110 using size_type =
typename SourceType::size_type;
111 using index_type =
typename SourceType::index_type;
113 dst.resize(src.nrows(), src.ncols(), src.nnnz());
115 dst.row_offsets().assign(src.nrows() + 1, 0);
118 for (size_type n = 0; n < src.nnnz(); n++) {
119 dst.row_offsets(src.crow_indices(n))++;
123 index_type cumsum = 0;
124 for (size_type i = 0; i < src.nrows(); i++) {
125 index_type temp = dst.row_offsets(i);
126 dst.row_offsets(i) = cumsum;
130 dst.row_offsets(src.nrows()) = src.nnnz();
133 for (size_type n = 0; n < src.nnnz(); n++) {
134 size_type row = src.crow_indices(n);
135 size_type dest = dst.row_offsets(row);
137 dst.column_indices(dest) = src.ccolumn_indices(n);
138 dst.values(dest) = src.cvalues(n);
140 dst.row_offsets(row)++;
144 for (size_type i = 0; i <= src.nrows(); i++) {
145 index_type temp = dst.row_offsets(i);
146 dst.row_offsets(i) = last;
Generic Morpheus interfaces.
Definition: dummy.cpp:24