Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Coo/Serial/Morpheus_Convert_Impl.hpp
1
24#ifndef MORPHEUS_COO_SERIAL_CONVERT_IMPL_HPP
25#define MORPHEUS_COO_SERIAL_CONVERT_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 SourceType, typename DestinationType>
39void convert(
40 const SourceType& src, DestinationType& dst,
41 typename std::enable_if<
42 Morpheus::is_coo_matrix_format_container_v<SourceType> &&
43 Morpheus::is_coo_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* =
47 nullptr) {
48 using size_type = typename SourceType::size_type;
49
50 dst.resize(src.nrows(), src.ncols(), src.nnnz());
51
52 // element-wise copy of indices and values
53 for (size_type n = 0; n < src.nnnz(); n++) {
54 dst.row_indices(n) = src.crow_indices(n);
55 }
56
57 for (size_type n = 0; n < src.nnnz(); n++) {
58 dst.column_indices(n) = src.ccolumn_indices(n);
59 }
60
61 for (size_type n = 0; n < src.nnnz(); n++) {
62 dst.values(n) = src.cvalues(n);
63 }
64}
65
66} // namespace Impl
67} // namespace Morpheus
68
69#endif // MORPHEUS_ENABLE_SERIAL
70#endif // MORPHEUS_COO_SERIAL_CONVERT_IMPL_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24