24#ifndef MORPHEUS_DENSEMATRIX_SERIAL_CONVERT_IMPL_HPP
25#define MORPHEUS_DENSEMATRIX_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_dense_matrix_format_container_v<SourceType> &&
43 Morpheus::is_dense_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 MORPHEUS_ASSERT((dst.nrows() >= src.nrows()) && (dst.ncols() >= src.ncols()),
51 "Destination matrix must have equal or larger shape to the "
54 for (size_type i = 0; i < src.nrows(); i++) {
55 for (size_type j = 0; j < src.ncols(); j++) {
56 dst(i, j) = src(i, j);
61template <
typename ExecSpace,
typename SourceType,
typename DestinationType>
63 const SourceType& src, DestinationType& dst,
64 typename std::enable_if<
65 Morpheus::is_dense_matrix_format_container_v<SourceType> &&
66 Morpheus::is_dense_vector_format_container_v<DestinationType> &&
67 Morpheus::has_custom_backend_v<ExecSpace> &&
68 Morpheus::has_serial_execution_space_v<ExecSpace> &&
69 Morpheus::has_access_v<ExecSpace, SourceType, DestinationType>>::type* =
71 using size_type =
typename SourceType::size_type;
73 dst.resize(src.nrows() * src.ncols());
75 for (size_type i = 0; i < src.nrows(); i++) {
76 for (size_type j = 0; j < src.ncols(); j++) {
77 size_type idx = i * src.ncols() + j;
83template <
typename ExecSpace,
typename SourceType,
typename DestinationType>
85 const SourceType& src, DestinationType& dst,
86 typename std::enable_if<
87 Morpheus::is_dense_matrix_format_container_v<SourceType> &&
88 Morpheus::is_coo_matrix_format_container_v<DestinationType> &&
89 Morpheus::has_custom_backend_v<ExecSpace> &&
90 Morpheus::has_serial_execution_space_v<ExecSpace> &&
91 Morpheus::has_access_v<ExecSpace, SourceType, DestinationType>>::type* =
93 using size_type =
typename SourceType::size_type;
94 using value_type =
typename SourceType::value_type;
98 for (size_type i = 0; i < src.nrows(); i++) {
99 for (size_type j = 0; j < src.ncols(); j++) {
100 if (src(i, j) != value_type(0)) nnz = nnz + 1;
104 dst.resize(src.nrows(), src.ncols(), nnz);
106 for (size_type i = 0, n = 0; i < src.nrows(); i++) {
107 for (size_type j = 0; j < src.ncols(); j++) {
108 if (src(i, j) != value_type(0)) {
109 dst.row_indices(n) = i;
110 dst.column_indices(n) = j;
111 dst.values(n) = src(i, j);
118template <
typename ExecSpace,
typename SourceType,
typename DestinationType>
120 const SourceType& src, DestinationType& dst,
121 typename std::enable_if<
122 Morpheus::is_coo_matrix_format_container_v<SourceType> &&
123 Morpheus::is_dense_matrix_format_container_v<DestinationType> &&
124 Morpheus::has_custom_backend_v<ExecSpace> &&
125 Morpheus::has_serial_execution_space_v<ExecSpace> &&
126 Morpheus::has_access_v<ExecSpace, SourceType, DestinationType>>::type* =
128 using size_type =
typename SourceType::size_type;
130 dst.resize(src.nrows(), src.ncols());
132 for (size_type n = 0; n < src.nnnz(); n++) {
133 size_type i = src.crow_indices(n);
134 size_type j = src.ccolumn_indices(n);
135 dst(i, j) = src.cvalues(n);
Generic Morpheus interfaces.
Definition: dummy.cpp:24