24#ifndef MORPHEUS_DYNAMICMATRIX_HPP
25#define MORPHEUS_DYNAMICMATRIX_HPP
27#include <Morpheus_FormatTags.hpp>
28#include <Morpheus_MatrixBase.hpp>
30#include <impl/Morpheus_Variant.hpp>
31#include <impl/Dynamic/Morpheus_DynamicMatrix_Impl.hpp>
102template <
class ValueType,
class... Properties>
104 :
public MatrixBase<DynamicMatrix, ValueType, Properties...> {
185 template <
typename Matrix>
188 typename std::enable_if<is_variant_member_v<Matrix, variant_type>>
::type
194 std::placeholders::_1);
195 Morpheus::Impl::Variant::visit(f, _formats);
212 template <
typename Matrix>
213 typename std::enable_if<is_variant_member_v<Matrix, variant_type>,
216 this->
activate(matrix.format_enum());
217 base::resize(matrix.nrows(), matrix.ncols(), matrix.nnnz());
220 std::placeholders::_1);
221 Morpheus::Impl::Variant::visit(f, _formats);
238 template <
class VR,
class... PR>
263 template <
class VR,
class... PR>
264 typename std::enable_if<
295 template <
class VR,
class... PR>
314 template <
typename Matrix>
317 typename std::enable_if<is_variant_member_v<Matrix, variant_type>>
::type
323 std::placeholders::_1);
324 Morpheus::Impl::Variant::visit(f, _formats);
338 template <
class VR,
class... PR>
371 return static_cast<formats_e
>(_formats.index());
389 constexpr int size = Morpheus::Impl::Variant::variant_size_v<
391 const int idx =
static_cast<int>(index);
395 }
else if (idx > size) {
396 std::cout <<
"Warning: There are " << size
397 <<
" available formats to switch to. "
398 <<
"Selecting to switch to format with index " << idx
399 <<
" will default to no change." << std::endl;
417 activate(
static_cast<formats_e
>(index));
Implementation of the Dynamic Sparse Matrix Format Representation.
Definition: Morpheus_DynamicMatrix.hpp:104
int format_index() const
Returns the format index assigned to the active type of the DynamicMatrix container.
Definition: Morpheus_DynamicMatrix.hpp:362
formats_e active_enum() const
Returns the format enum assigned to the active type of the DynamicMatrix container.
Definition: Morpheus_DynamicMatrix.hpp:370
void activate(const int index)
Changes the active type of the DynamicMatrix container to the one given by the index parameter.
Definition: Morpheus_DynamicMatrix.hpp:416
void resize(const Matrix &src, typename std::enable_if< is_variant_member_v< Matrix, variant_type > >::type *=nullptr)
Resizes DynamicMatrix with the shape and number of non-zero entries of another Matrix with possibly a...
Definition: Morpheus_DynamicMatrix.hpp:315
typename traits::type type
Definition: Morpheus_DynamicMatrix.hpp:109
int active_index() const
Returns the format index assigned to the active type of the DynamicMatrix container.
Definition: Morpheus_DynamicMatrix.hpp:354
DynamicMatrix(const DynamicMatrix &)=default
The default copy contructor (shallow copy) of a DynamicMatrix container from another DynamicMatrix co...
typename traits::value_type value_type
Definition: Morpheus_DynamicMatrix.hpp:115
~DynamicMatrix()=default
The default destructor.
std::enable_if< is_format_compatible< DynamicMatrix, DynamicMatrix< VR, PR... > >::value, DynamicMatrix & >::type operator=(const DynamicMatrix< VR, PR... > &src)
Assigns a DynamicMatrix from another compatible DynamicMatrix.
Definition: Morpheus_DynamicMatrix.hpp:267
DynamicMatrix & allocate(const DynamicMatrix< VR, PR... > &src)
Allocates DynamicMatrix with the shape and number of non-zero entries of the active type of another D...
Definition: Morpheus_DynamicMatrix.hpp:339
variant_type & formats()
Returns a reference to the variant container that holds the supported formats in the DynamicMatrix.
Definition: Morpheus_DynamicMatrix.hpp:434
DynamicMatrix(const Matrix &src, typename std::enable_if< is_variant_member_v< Matrix, variant_type > >::type *=nullptr)
Constructs a DynamicMatrix from another concrete format.
Definition: Morpheus_DynamicMatrix.hpp:186
DynamicMatrix()
Constructs an empty DynamicMatrix object.
Definition: Morpheus_DynamicMatrix.hpp:169
formats_e format_enum() const
Returns the format enum assigned to the active type of the DynamicMatrix container.
Definition: Morpheus_DynamicMatrix.hpp:380
const variant_type & const_formats() const
Returns a const-reference to the variant container that holds the supported formats in the DynamicMat...
Definition: Morpheus_DynamicMatrix.hpp:426
typename MatrixFormats< ValueType, Properties... >::variant variant_type
Definition: Morpheus_DynamicMatrix.hpp:139
typename traits::non_const_value_type non_const_value_type
Definition: Morpheus_DynamicMatrix.hpp:117
typename traits::index_type index_type
Definition: Morpheus_DynamicMatrix.hpp:120
DynamicMatrix & operator=(const DynamicMatrix &)=default
The default copy assignment (shallow copy) of a DynamicMatrix container from another DynamicMatrix co...
DynamicMatrix(DynamicMatrix &&)=default
The default move contructor (shallow copy) of a DynamicMatrix container from another DynamicMatrix co...
DynamicMatrix(const DynamicMatrix< VR, PR... > &src, typename std::enable_if< is_format_compatible< DynamicMatrix, DynamicMatrix< VR, PR... > >::value >::type *=nullptr)
Constructs a DynamicMatrix from another compatible DynamicMatrix.
Definition: Morpheus_DynamicMatrix.hpp:239
typename traits::non_const_index_type non_const_index_type
Definition: Morpheus_DynamicMatrix.hpp:122
std::enable_if< is_variant_member_v< Matrix, variant_type >, DynamicMatrix & >::type operator=(const Matrix &matrix)
Assigns a DynamicMatrix from another concrete format.
Definition: Morpheus_DynamicMatrix.hpp:215
typename MatrixFormatTag< Morpheus::DynamicMatrixFormatTag >::tag tag
Definition: Morpheus_DynamicMatrix.hpp:112
void activate(const formats_e index)
Changes the active type of the DynamicMatrix container to the one given by the enum index parameter.
Definition: Morpheus_DynamicMatrix.hpp:388
DynamicMatrix & operator=(DynamicMatrix &&)=default
The default move assignment (shallow copy) of a DynamicMatrix container from another DynamicMatrix co...
void resize(const DynamicMatrix< VR, PR... > &src)
Resizes DynamicMatrix with the shape and number of non-zero entries of the active type of another Dyn...
Definition: Morpheus_DynamicMatrix.hpp:296
Base class used to derive new matrices.
Definition: Morpheus_MatrixBase.hpp:70
void resize(size_type rows, size_type cols, size_type entries)
Resizes MatrixBase with shape of (num_rows, num_cols) and sets number of non-zero entries to num_entr...
Definition: Morpheus_MatrixBase.hpp:108
size_type nnnz() const
Number of non-zeros of the matrix.
Definition: Morpheus_MatrixBase.hpp:133
size_type nrows() const
Number of rows of the matrix.
Definition: Morpheus_MatrixBase.hpp:119
size_type ncols() const
Number of columns of the matrix.
Definition: Morpheus_MatrixBase.hpp:126
Generic Morpheus interfaces.
Definition: dummy.cpp:24
typename std::add_lvalue_reference< typename std::add_const< type >::type >::type const_reference
The const reference type of the container.
Definition: Morpheus_ContainerTraits.hpp:158
MemorySpace memory_space
The space in which data will be stored in.
Definition: Morpheus_ContainerTraits.hpp:119
MemoryTraits memory_traits
Represents the user's intended access behaviour.
Definition: Morpheus_ContainerTraits.hpp:125
ArrayLayout array_layout
The storage layout of data held by the container.
Definition: Morpheus_ContainerTraits.hpp:110
size_t size_type
The size type of the container.
Definition: Morpheus_ContainerTraits.hpp:103
IndexType index_type
The type of indices held by the container.
Definition: Morpheus_ContainerTraits.hpp:100
typename std::remove_const< ValueType >::type non_const_value_type
The non-const type of values held by the container.
Definition: Morpheus_ContainerTraits.hpp:97
typename std::add_pointer< typename std::add_const< type >::type >::type const_pointer
The const pointer type of the container.
Definition: Morpheus_ContainerTraits.hpp:151
ValueType value_type
The type of values held by the container.
Definition: Morpheus_ContainerTraits.hpp:91
typename std::add_pointer< type >::type pointer
The pointer type of the container.
Definition: Morpheus_ContainerTraits.hpp:147
Backend backend
The backend out of which algorithms will be dispatched from.
Definition: Morpheus_ContainerTraits.hpp:113
DynamicMatrix< value_type, index_type, array_layout, backend, memory_traits > type
The complete type of the container.
Definition: Morpheus_ContainerTraits.hpp:133
ExecutionSpace execution_space
The space in which member functions will be executed in.
Definition: Morpheus_ContainerTraits.hpp:116
typename std::add_lvalue_reference< type >::type reference
The reference type of the container.
Definition: Morpheus_ContainerTraits.hpp:154
DynamicMatrix< non_const_value_type, non_const_index_type, array_layout, Morpheus::Device< typename host_mirror_backend::execution_space, typename host_mirror_backend::memory_space, typename host_mirror_backend::backend >, typename Kokkos::MemoryManaged > HostMirror
The host mirror equivalent for the container.
Definition: Morpheus_ContainerTraits.hpp:143
typename std::remove_const< IndexType >::type non_const_index_type
The non-const type of indices held by the container.
Definition: Morpheus_ContainerTraits.hpp:106
Morpheus::Device< execution_space, memory_space, backend > device_type
A device aware of the execution, memory spaces and backend.
Definition: Morpheus_ContainerTraits.hpp:122
Definition: Morpheus_DynamicMatrix_Impl.hpp:172
Definition: Morpheus_DynamicMatrix_Impl.hpp:123
Definition: Morpheus_DynamicMatrix_Impl.hpp:147
Definition: Morpheus_DynamicMatrix_Impl.hpp:99
A wrapper that checks if the provided type is a scalar type.
Definition: Morpheus_TypeTraits.hpp:85