Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
Morpheus::DynamicMatrix< ValueType, Properties > Class Template Reference

Implementation of the Dynamic Sparse Matrix Format Representation. More...

#include <Morpheus_DynamicMatrix.hpp>

Inheritance diagram for Morpheus::DynamicMatrix< ValueType, Properties >:
Inheritance graph
[legend]
Collaboration diagram for Morpheus::DynamicMatrix< ValueType, Properties >:
Collaboration graph
[legend]

Public Types

using traits = ContainerTraits< DynamicMatrix, ValueType, Properties... >
 
using type = typename traits::type
 
using base = MatrixBase< DynamicMatrix, ValueType, Properties... >
 
using tag = typename MatrixFormatTag< Morpheus::DynamicMatrixFormatTag >::tag
 
using value_type = typename traits::value_type
 
using non_const_value_type = typename traits::non_const_value_type
 
using size_type = typename traits::size_type
 
using index_type = typename traits::index_type
 
using non_const_index_type = typename traits::non_const_index_type
 
using array_layout = typename traits::array_layout
 
using backend = typename traits::backend
 
using memory_space = typename traits::memory_space
 
using execution_space = typename traits::execution_space
 
using device_type = typename traits::device_type
 
using memory_traits = typename traits::memory_traits
 
using HostMirror = typename traits::HostMirror
 
using pointer = typename traits::pointer
 
using const_pointer = typename traits::const_pointer
 
using reference = typename traits::reference
 
using const_reference = typename traits::const_reference
 
using variant_type = typename MatrixFormats< ValueType, Properties... >::variant
 
- Public Types inherited from Morpheus::MatrixBase< DynamicMatrix, ValueType, Properties... >
using type = MatrixBase< DynamicMatrix, ValueType, Properties... >
 The traits associated with the particular container.
 
using traits = ContainerTraits< DynamicMatrix, ValueType, Properties... >
 The type of the indices held by the container.
 
using size_type = typename traits::size_type
 
- Public Types inherited from Morpheus::ContainerTraits< Container, ValueType, Properties >
enum  { is_hostspace = std::is_same<MemorySpace, Kokkos::HostSpace>::value }
 
enum  { is_managed = MemoryTraits::is_unmanaged == 0 }
 
using value_type = ValueType
 The type of values held by the container.
 
using const_value_type = typename std::add_const< ValueType >::type
 The const type of values held by the container.
 
using non_const_value_type = typename std::remove_const< ValueType >::type
 The non-const type of values held by the container.
 
using index_type = IndexType
 The type of indices held by the container.
 
using size_type = size_t
 The size type of the container.
 
using non_const_index_type = typename std::remove_const< IndexType >::type
 The non-const type of indices held by the container.
 
using array_layout = ArrayLayout
 The storage layout of data held by the container.
 
using backend = Backend
 The backend out of which algorithms will be dispatched from.
 
using execution_space = ExecutionSpace
 The space in which member functions will be executed in.
 
using memory_space = MemorySpace
 The space in which data will be stored in.
 
using device_type = Morpheus::Device< execution_space, memory_space, backend >
 A device aware of the execution, memory spaces and backend.
 
using memory_traits = MemoryTraits
 Represents the user's intended access behaviour.
 
using host_mirror_backend = typename Morpheus::HostMirror< backend >::backend
 The host equivalent backend.
 
using type = Container< value_type, index_type, array_layout, backend, memory_traits >
 The complete type of the container.
 
using HostMirror = Container< 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 >
 The host mirror equivalent for the container. More...
 
using pointer = typename std::add_pointer< type >::type
 The pointer type of the container.
 
using const_pointer = typename std::add_pointer< typename std::add_const< type >::type >::type
 The const pointer type of the container.
 
using reference = typename std::add_lvalue_reference< type >::type
 The reference type of the container.
 
using const_reference = typename std::add_lvalue_reference< typename std::add_const< type >::type >::type
 The const reference type of the container.
 

Public Member Functions

 ~DynamicMatrix ()=default
 The default destructor.
 
 DynamicMatrix (const DynamicMatrix &)=default
 The default copy contructor (shallow copy) of a DynamicMatrix container from another DynamicMatrix container with the same properties.
 
 DynamicMatrix (DynamicMatrix &&)=default
 The default move contructor (shallow copy) of a DynamicMatrix container from another DynamicMatrix container with the same properties.
 
DynamicMatrixoperator= (const DynamicMatrix &)=default
 The default copy assignment (shallow copy) of a DynamicMatrix container from another DynamicMatrix container with the same properties.
 
DynamicMatrixoperator= (DynamicMatrix &&)=default
 The default move assignment (shallow copy) of a DynamicMatrix container from another DynamicMatrix container with the same properties.
 
 DynamicMatrix ()
 Constructs an empty DynamicMatrix object.
 
template<typename Matrix >
 DynamicMatrix (const Matrix &src, typename std::enable_if< is_variant_member_v< Matrix, variant_type > >::type *=nullptr)
 Constructs a DynamicMatrix from another concrete format. More...
 
template<typename Matrix >
std::enable_if< is_variant_member_v< Matrix, variant_type >, DynamicMatrix & >::type operator= (const Matrix &matrix)
 Assigns a DynamicMatrix from another concrete format. More...
 
template<class VR , class... PR>
 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. More...
 
template<class VR , class... PR>
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. More...
 
template<class VR , class... PR>
void resize (const DynamicMatrix< VR, PR... > &src)
 Resizes DynamicMatrix with the shape and number of non-zero entries of the active type of another DynamicMatrix with different parameters. More...
 
template<typename Matrix >
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 different storage format. More...
 
template<class VR , class... PR>
DynamicMatrixallocate (const DynamicMatrix< VR, PR... > &src)
 Allocates DynamicMatrix with the shape and number of non-zero entries of the active type of another DynamicMatrix with different parameters. More...
 
int active_index () const
 Returns the format index assigned to the active type of the DynamicMatrix container. More...
 
int format_index () const
 Returns the format index assigned to the active type of the DynamicMatrix container. More...
 
formats_e active_enum () const
 Returns the format enum assigned to the active type of the DynamicMatrix container. More...
 
formats_e format_enum () const
 Returns the format enum assigned to the active type of the DynamicMatrix container. More...
 
void activate (const formats_e index)
 Changes the active type of the DynamicMatrix container to the one given by the enum index parameter. More...
 
void activate (const int index)
 Changes the active type of the DynamicMatrix container to the one given by the index parameter. More...
 
const variant_typeconst_formats () const
 Returns a const-reference to the variant container that holds the supported formats in the DynamicMatrix. More...
 
variant_typeformats ()
 Returns a reference to the variant container that holds the supported formats in the DynamicMatrix. More...
 
- Public Member Functions inherited from Morpheus::MatrixBase< DynamicMatrix, ValueType, Properties... >
 MatrixBase ()
 Default constructor. More...
 
 MatrixBase (size_type rows, size_type cols, size_type entries=0)
 Construct a MatrixBase object with shape (num_rows, num_cols) and number of non-zeros equal to num_entries. More...
 
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_entries. More...
 
size_type nrows () const
 Number of rows of the matrix. More...
 
size_type ncols () const
 Number of columns of the matrix. More...
 
size_type nnnz () const
 Number of non-zeros of the matrix. More...
 
void set_nrows (const size_type rows)
 Set the number of rows of the matrix. More...
 
void set_ncols (const size_type cols)
 Set the number of columns of the matrix. More...
 
void set_nnnz (const size_type nnz)
 Set the number of non-zeros of the matrix. More...
 
MatrixStructure structure () const
 The specialized structure of the matrix e.g Symmetric. More...
 
MatrixOptions options () const
 Information about specific characteristics of the matrix e.g has short rows. More...
 
void set_structure (MatrixStructure op)
 Set the structure of the matrix. More...
 
void set_options (MatrixOptions op)
 Set the characteristics of the matrix. More...
 

Detailed Description

template<class ValueType, class... Properties>
class Morpheus::DynamicMatrix< ValueType, Properties >

Implementation of the Dynamic Sparse Matrix Format Representation.

Template Parameters
ValueTypeType of values to store
PropertiesOptional properties to modify the behaviour of the container. Sensible defaults are selected based on the configuration. Please refer to impl/Morpheus_ContainerTraits.hpp to find out more about the valid properties.
Overview
The DynamicMatrix container is a two-dimensional container that acts as a superset of all the available matrix storage formats supported in Morpheus. The purpose of such a container is to enable run-time switching across the different formats under a single unified interface such that we can take advantage of the format that is best suited for the given computation and target hardware. It is a polymorphic container in the sense that it can store scalar or integer type values, on host or device depending how the template parameters are selected.
Example
#include <Morpheus_Core.hpp>
// Matrix to Build
// [1 * 2]
// [* * 3]
// [* 4 *]
int main(){
using index_array_type = typename Matrix::index_array_type;
using value_array_type = typename Matrix::value_array_type;
DynamicMatrix A; // A acts as COO format by default
A.activate(Morpheus::DIA_FORMAT); // Now acts as a DIA format
index_array_type off(4, 0), j(4, 0);
value_array_type v(4,0);
off[0] = 0; off[1] = 2; off[2] = 3; off[3] = 4;
j[0] = 0; v[0] = 1;
j[1] = 2; v[1] = 2;
j[2] = 2; v[2] = 3;
j[3] = 1; v[3] = 4;
// Construct the matrix from off,j,v
Matrix Acsr(3, 3, 4, off, j, v);
A = Acsr; // Now acts as CSR and holds the same data
Morpheus::print(A); // prints A
}
Implementation of the Compressed-Sparse Row (CSR) Sparse Matrix Format Representation.
Definition: Morpheus_CsrMatrix.hpp:91
Implementation of the Dynamic Sparse Matrix Format Representation.
Definition: Morpheus_DynamicMatrix.hpp:104
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

Member Typedef Documentation

◆ index_type

template<class ValueType , class... Properties>
using Morpheus::DynamicMatrix< ValueType, Properties >::index_type = typename traits::index_type

The type of the indices held by the container - can be const

◆ non_const_index_type

template<class ValueType , class... Properties>
using Morpheus::DynamicMatrix< ValueType, Properties >::non_const_index_type = typename traits::non_const_index_type

The non-constant type of the indices held by the container

◆ non_const_value_type

template<class ValueType , class... Properties>
using Morpheus::DynamicMatrix< ValueType, Properties >::non_const_value_type = typename traits::non_const_value_type

The non-constant type of the values held by the container

◆ tag

template<class ValueType , class... Properties>
using Morpheus::DynamicMatrix< ValueType, Properties >::tag = typename MatrixFormatTag<Morpheus::DynamicMatrixFormatTag>::tag

The tag associated specificaly to the particular container

◆ traits

template<class ValueType , class... Properties>
using Morpheus::DynamicMatrix< ValueType, Properties >::traits = ContainerTraits<DynamicMatrix, ValueType, Properties...>

The traits associated with the particular container

◆ type

template<class ValueType , class... Properties>
using Morpheus::DynamicMatrix< ValueType, Properties >::type = typename traits::type

The complete type of the container

◆ value_type

template<class ValueType , class... Properties>
using Morpheus::DynamicMatrix< ValueType, Properties >::value_type = typename traits::value_type

The type of the values held by the container - can be const

◆ variant_type

template<class ValueType , class... Properties>
using Morpheus::DynamicMatrix< ValueType, Properties >::variant_type = typename MatrixFormats<ValueType, Properties...>::variant

The variant container that holds the various supported containers

Constructor & Destructor Documentation

◆ DynamicMatrix() [1/2]

template<class ValueType , class... Properties>
template<typename Matrix >
Morpheus::DynamicMatrix< ValueType, Properties >::DynamicMatrix ( const Matrix &  src,
typename std::enable_if< is_variant_member_v< Matrix, variant_type > >::type = nullptr 
)
inline

Constructs a DynamicMatrix from another concrete format.

Overview
Constructs a DynamicMatrix from another concrete format supported in Morpheus. For the construction to be valid the is_variant_member check needs to be satisfied. In other words, we can only construct from one of the member types in the variant held by the DynamicMatrix. Note that the DynamicMatrix will change it's active type to the format type of the source Matrix.
Template Parameters
MatrixThe type of the concrete matrix format.
Parameters
srcThe source container we are constructing from.

◆ DynamicMatrix() [2/2]

template<class ValueType , class... Properties>
template<class VR , class... PR>
Morpheus::DynamicMatrix< ValueType, Properties >::DynamicMatrix ( const DynamicMatrix< VR, PR... > &  src,
typename std::enable_if< is_format_compatible< DynamicMatrix< ValueType, Properties >, DynamicMatrix< VR, PR... > >::value >::type = nullptr 
)
inline

Constructs a DynamicMatrix from another compatible DynamicMatrix.

Overview
Constructs a DynamicMatrix from another compatible DynamicMatrix i.e a matrix that satisfies the is_format_compatible check. Note that upon construction the new DynamicMatrix will set to have the same active type as the source Matrix.
Template Parameters
VRType of Values the Other Matrix holds.
PRProperties of the Other Matrix.
Parameters
srcThe matrix we are constructing from.

Member Function Documentation

◆ activate() [1/2]

template<class ValueType , class... Properties>
void Morpheus::DynamicMatrix< ValueType, Properties >::activate ( const formats_e  index)
inline

Changes the active type of the DynamicMatrix container to the one given by the enum index parameter.

Parameters
indexThe enum state representing the active type to change to.

◆ activate() [2/2]

template<class ValueType , class... Properties>
void Morpheus::DynamicMatrix< ValueType, Properties >::activate ( const int  index)
inline

Changes the active type of the DynamicMatrix container to the one given by the index parameter.

Parameters
indexThe index representing the active type to change to.

◆ active_enum()

template<class ValueType , class... Properties>
formats_e Morpheus::DynamicMatrix< ValueType, Properties >::active_enum ( ) const
inline

Returns the format enum assigned to the active type of the DynamicMatrix container.

Returns
formats_e The format enum

◆ active_index()

template<class ValueType , class... Properties>
int Morpheus::DynamicMatrix< ValueType, Properties >::active_index ( ) const
inline

Returns the format index assigned to the active type of the DynamicMatrix container.

Returns
formats_e The format enum

◆ allocate()

template<class ValueType , class... Properties>
template<class VR , class... PR>
DynamicMatrix & Morpheus::DynamicMatrix< ValueType, Properties >::allocate ( const DynamicMatrix< VR, PR... > &  src)
inline

Allocates DynamicMatrix with the shape and number of non-zero entries of the active type of another DynamicMatrix with different parameters.

Note
Upon allocation the new DynamicMatrix will set to have the same active type as the source Matrix.
Template Parameters
VRType of values the source matrix stores.
PROther properties of source matrix.
Parameters
srcThe source DynamicMatrix we are resizing from.

◆ const_formats()

template<class ValueType , class... Properties>
const variant_type & Morpheus::DynamicMatrix< ValueType, Properties >::const_formats ( ) const
inline

Returns a const-reference to the variant container that holds the supported formats in the DynamicMatrix.

Returns
const variant_type& A const-reference to the variant container.

◆ format_enum()

template<class ValueType , class... Properties>
formats_e Morpheus::DynamicMatrix< ValueType, Properties >::format_enum ( ) const
inline

Returns the format enum assigned to the active type of the DynamicMatrix container.

Returns
formats_e The format enum

◆ format_index()

template<class ValueType , class... Properties>
int Morpheus::DynamicMatrix< ValueType, Properties >::format_index ( ) const
inline

Returns the format index assigned to the active type of the DynamicMatrix container.

Returns
formats_e The format enum

◆ formats()

template<class ValueType , class... Properties>
variant_type & Morpheus::DynamicMatrix< ValueType, Properties >::formats ( )
inline

Returns a reference to the variant container that holds the supported formats in the DynamicMatrix.

Returns
variant_type& A reference to the variant container.

◆ operator=() [1/2]

template<class ValueType , class... Properties>
template<class VR , class... PR>
std::enable_if< is_format_compatible< DynamicMatrix, DynamicMatrix< VR, PR... > >::value, DynamicMatrix & >::type Morpheus::DynamicMatrix< ValueType, Properties >::operator= ( const DynamicMatrix< VR, PR... > &  src)
inline

Assigns a DynamicMatrix from another compatible DynamicMatrix.

Overview
Assigns a DynamicMatrix from another compatible DynamicMatrix i.e a matrix that satisfies the is_format_compatible check. Note that upon assignment the new DynamicMatrix will set to have the same active type as the source Matrix.
Template Parameters
VRType of Values the Other Matrix holds.
PRProperties of the Other Matrix.
Parameters
srcThe matrix we are assigning from.

◆ operator=() [2/2]

template<class ValueType , class... Properties>
template<typename Matrix >
std::enable_if< is_variant_member_v< Matrix, variant_type >, DynamicMatrix & >::type Morpheus::DynamicMatrix< ValueType, Properties >::operator= ( const Matrix &  matrix)
inline

Assigns a DynamicMatrix from another concrete format.

Overview
Assigns a DynamicMatrix from another concrete format supported in Morpheus. For the assignment to be valid the is_variant_member check needs to be satisfied. In other words, we can only assign from one of the member types in the variant held by the DynamicMatrix. Note that the DynamicMatrix will change it's active type to the format type of the source Matrix.
Template Parameters
MatrixThe type of the concrete matrix format.
Parameters
srcThe source container we are assigning from.

◆ resize() [1/2]

template<class ValueType , class... Properties>
template<class VR , class... PR>
void Morpheus::DynamicMatrix< ValueType, Properties >::resize ( const DynamicMatrix< VR, PR... > &  src)
inline

Resizes DynamicMatrix with the shape and number of non-zero entries of the active type of another DynamicMatrix with different parameters.

Template Parameters
VRType of values the source matrix stores.
PROther properties of source matrix.
Parameters
srcThe source DynamicMatrix we are resizing from.

◆ resize() [2/2]

template<class ValueType , class... Properties>
template<typename Matrix >
void Morpheus::DynamicMatrix< ValueType, Properties >::resize ( const Matrix &  src,
typename std::enable_if< is_variant_member_v< Matrix, variant_type > >::type = nullptr 
)
inline

Resizes DynamicMatrix with the shape and number of non-zero entries of another Matrix with possibly a different storage format.

Note
Upon resizing the new DynamicMatrix will set to have the same active type as the source Matrix.
Template Parameters
VRType of values the source matrix stores.
PROther properties of source matrix.
Parameters
srcThe source Matrix we are resizing from.

The documentation for this class was generated from the following files: