Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Morpheus_Convert.hpp
1
24#ifndef MORPHEUS_CONVERT_HPP
25#define MORPHEUS_CONVERT_HPP
26
27#include <Morpheus_Print.hpp>
28#include <Morpheus_FormatTags.hpp>
29#include <fwd/Morpheus_Fwd_CooMatrix.hpp>
30
31#include <impl/Morpheus_Convert_Impl.hpp>
32#include <impl/Dynamic/Morpheus_Convert_Impl.hpp>
33
34namespace Morpheus {
53template <typename ExecSpace, typename SourceType, typename DestinationType>
54void convert(const SourceType& src, DestinationType& dst) {
55 Impl::convert<ExecSpace>(src, dst);
56}
57
66};
67
87template <typename ExecSpace, typename SourceType>
88conversion_error_e convert(SourceType& src, const formats_e index) {
90 "Container must be a DynamicMatrix.");
92 typename SourceType::value_type, typename SourceType::index_type,
93 typename SourceType::array_layout, typename SourceType::memory_space>
94 temp;
95
96 // No conversion needed
97 if (src.active_index() == index) {
98 return CONV_SUCCESS;
99 }
100
101 if (src.active_index() != Morpheus::COO_FORMAT) {
102 try {
103 Impl::convert<ExecSpace>(src, temp);
104 } catch (...) {
105 std::cout << "Warning: Conversion failed! Active state set to: "
106 << src.active_index() << std::endl;
107
108 return DYNAMIC_TO_PROXY;
109 }
110 } else {
111 temp = src;
112 }
113
114 // TODO: If index==COO, shallow copy instead of convert
115 SourceType dynamic_temp;
116 dynamic_temp.activate(index);
117
118 try {
119 Impl::convert<ExecSpace>(temp, dynamic_temp);
120 } catch (...) {
121 std::cout << "Warning: Conversion failed! Active state set to: "
122 << src.active_index() << std::endl;
123
124 return PROXY_TO_DYNAMIC;
125 }
126 src = dynamic_temp;
127 return CONV_SUCCESS;
128}
129
141template <typename ExecSpace, typename SourceType>
142conversion_error_e convert(SourceType& src, const int index) {
143 return Morpheus::convert<ExecSpace>(src, static_cast<formats_e>(index));
144}
147} // namespace Morpheus
148
149#endif // MORPHEUS_CONVERT_HPP
Implementation of the Coordinate (COO) Sparse Matrix Format Representation.
Definition: Morpheus_CooMatrix.hpp:91
Checks if the given type T is a valid Dynamic Matrix Format Container i.e is valid matrix container a...
Definition: Morpheus_FormatTags.hpp:201
conversion_error_e
Enum values for in-place conversion status.
Definition: Morpheus_Convert.hpp:62
void convert(const SourceType &src, DestinationType &dst)
Performs a conversion operation between two containers.
Definition: Morpheus_Convert.hpp:54
@ CONV_SUCCESS
In-place conversion successful.
Definition: Morpheus_Convert.hpp:65
@ PROXY_TO_DYNAMIC
Proxy to Dynamic conversion failed.
Definition: Morpheus_Convert.hpp:64
@ DYNAMIC_TO_PROXY
Dynamic to Proxy conversion failed.
Definition: Morpheus_Convert.hpp:63
Generic Morpheus interfaces.
Definition: dummy.cpp:24