24#ifndef MORPHEUS_CSRMATRIX_HPP
25#define MORPHEUS_CSRMATRIX_HPP
27#include <Morpheus_Exceptions.hpp>
28#include <Morpheus_FormatTags.hpp>
29#include <Morpheus_DenseVector.hpp>
30#include <Morpheus_DynamicMatrix.hpp>
31#include <Morpheus_MatrixBase.hpp>
90template <
class ValueType,
class... Properties>
129 using index_array_pointer =
typename index_array_type::value_array_pointer;
130 using index_array_reference =
131 typename index_array_type::value_array_reference;
132 using const_index_array_reference =
const index_array_reference;
139 using value_array_pointer =
typename value_array_type::value_array_pointer;
140 using value_array_reference =
141 typename value_array_type::value_array_reference;
142 using const_value_array_reference =
const value_array_reference;
172 inline CsrMatrix() :
base(), _row_offsets(), _column_indices(), _values() {}
182 inline CsrMatrix(
const size_type num_rows,
const size_type num_cols,
183 const size_type num_entries)
184 :
base(num_rows, num_cols, num_entries),
185 _row_offsets(num_rows + 1),
186 _column_indices(num_entries),
187 _values(num_entries) {}
190 template <
typename ValuePtr,
typename IndexPtr>
192 const size_type num_rows,
const size_type num_cols,
193 const size_type num_entries, IndexPtr roff_ptr, IndexPtr cind_ptr,
195 typename std::enable_if<
196 (std::is_pointer<ValuePtr>::value &&
198 memory_traits::is_unmanaged) &&
199 (std::is_pointer<IndexPtr>::value &&
201 memory_traits::is_unmanaged)>
::type * =
nullptr)
202 : base(num_rows, num_cols, num_entries),
203 _row_offsets(num_rows + 1, roff_ptr),
204 _column_indices(num_entries, cind_ptr),
205 _values(num_entries, vals_ptr) {}
222 template <
typename ValueArray,
typename IndexArray>
224 const size_type num_rows,
const size_type num_cols,
225 const size_type num_entries, IndexArray roff, IndexArray cind,
227 typename std::enable_if<
231 ValueArray>::value &&
233 IndexArray>::value &&
234 !ValueArray::memory_traits::is_unmanaged &&
235 !IndexArray::memory_traits::is_unmanaged>
::type * =
nullptr)
236 :
base(num_rows, num_cols, num_entries),
238 _column_indices(cind),
251 template <
class VR,
class... PR>
271 template <
class VR,
class... PR>
272 typename std::enable_if<
300 template <
class VR,
class... PR>
324 template <
class VR,
class... PR>
325 typename std::enable_if<
345 template <
typename MatrixType>
356 template <
typename MatrixType>
367 inline void resize(
const size_type num_rows,
const size_type num_cols,
368 const size_type num_entries) {
370 _row_offsets.
resize(num_rows + 1);
371 _column_indices.
resize(num_entries);
372 _values.
resize(num_entries);
383 template <
class VR,
class... PR>
396 template <
class VR,
class... PR>
423 MORPHEUS_FORCEINLINE_FUNCTION index_array_reference
row_offsets(size_type n) {
424 return _row_offsets(n);
434 MORPHEUS_FORCEINLINE_FUNCTION index_array_reference
436 return _column_indices(n);
445 MORPHEUS_FORCEINLINE_FUNCTION value_array_reference
values(size_type n) {
456 MORPHEUS_FORCEINLINE_FUNCTION const_index_array_reference
458 return _row_offsets(n);
468 MORPHEUS_FORCEINLINE_FUNCTION const_index_array_reference
470 return _column_indices(n);
479 MORPHEUS_FORCEINLINE_FUNCTION const_value_array_reference
499 return _column_indices;
525 return _column_indices;
540 static constexpr formats_e _id = Morpheus::CSR_FORMAT;
Implementation of the Compressed-Sparse Row (CSR) Sparse Matrix Format Representation.
Definition: Morpheus_CsrMatrix.hpp:91
MORPHEUS_FORCEINLINE_FUNCTION const_index_array_type & ccolumn_indices() const
Returns a const-reference to the column indices of the matrix.
Definition: Morpheus_CsrMatrix.hpp:523
MORPHEUS_FORCEINLINE_FUNCTION index_array_type & column_indices()
Returns a reference to the column indices of the matrix.
Definition: Morpheus_CsrMatrix.hpp:498
MORPHEUS_FORCEINLINE_FUNCTION const_index_array_reference ccolumn_indices(size_type n) const
Returns a const-reference to the column index of the matrix with index n.
Definition: Morpheus_CsrMatrix.hpp:469
CsrMatrix()
Construct an empty CsrMatrix object.
Definition: Morpheus_CsrMatrix.hpp:172
MORPHEUS_FORCEINLINE_FUNCTION const_value_array_type & cvalues() const
Returns a reference to the values of the matrix.
Definition: Morpheus_CsrMatrix.hpp:533
std::enable_if< is_format_compatible< CsrMatrix, CsrMatrix< VR, PR... > >::value, CsrMatrix & >::type operator=(const CsrMatrix< VR, PR... > &src)
Assigns a CsrMatrix from another compatible CsrMatrix.
Definition: Morpheus_CsrMatrix.hpp:275
CsrMatrix(const CsrMatrix< VR, PR... > &src, typename std::enable_if< is_format_compatible< CsrMatrix, CsrMatrix< VR, PR... > >::value >::type *=nullptr)
Constructs a CsrMatrix from another compatible CsrMatrix.
Definition: Morpheus_CsrMatrix.hpp:252
MORPHEUS_FORCEINLINE_FUNCTION const_index_array_type & crow_offsets() const
Returns a const-reference to the row offsets of the matrix.
Definition: Morpheus_CsrMatrix.hpp:514
typename traits::type type
Definition: Morpheus_CsrMatrix.hpp:96
~CsrMatrix()=default
The default destructor.
typename traits::value_type value_type
Definition: Morpheus_CsrMatrix.hpp:102
MORPHEUS_FORCEINLINE_FUNCTION value_array_type & values()
Returns a reference to the values of the matrix.
Definition: Morpheus_CsrMatrix.hpp:507
typename traits::index_type index_type
Definition: Morpheus_CsrMatrix.hpp:107
CsrMatrix & operator=(CsrMatrix &&)=default
The default move assignment (shallow copy) of a CsrMatrix container from another CsrMatrix container ...
CsrMatrix & operator=(const CsrMatrix &)=default
The default copy assignment (shallow copy) of a CsrMatrix container from another CsrMatrix container ...
int format_index() const
Returns the equivalent index to the format enum assigned to the CsrMatrix container.
Definition: Morpheus_CsrMatrix.hpp:415
MORPHEUS_FORCEINLINE_FUNCTION const_value_array_reference cvalues(size_type n) const
Returns a const-reference to the value of the matrix with index n.
Definition: Morpheus_CsrMatrix.hpp:480
CsrMatrix(const MatrixType &src)=delete
Construct a CsrMatrix object from another storage format. This functionality is disabled to avoid imp...
MORPHEUS_FORCEINLINE_FUNCTION const_index_array_reference crow_offsets(size_type n) const
Returns a const-reference to the row offset of the matrix with index n.
Definition: Morpheus_CsrMatrix.hpp:457
typename traits::non_const_value_type non_const_value_type
Definition: Morpheus_CsrMatrix.hpp:104
MORPHEUS_FORCEINLINE_FUNCTION value_array_reference values(size_type n)
Returns a reference to the value of the matrix with index n.
Definition: Morpheus_CsrMatrix.hpp:445
CsrMatrix(const size_type num_rows, const size_type num_cols, const size_type num_entries)
Construct a CsrMatrix object with shape (num_rows, num_cols) and number of non-zeros equal to num_ent...
Definition: Morpheus_CsrMatrix.hpp:182
CsrMatrix(const CsrMatrix &)=default
The default copy contructor (shallow copy) of a CsrMatrix container from another CsrMatrix container ...
MORPHEUS_FORCEINLINE_FUNCTION index_array_reference row_offsets(size_type n)
Returns a reference to the row offset of the matrix with index n.
Definition: Morpheus_CsrMatrix.hpp:423
std::enable_if< is_dynamically_compatible< CsrMatrix, DynamicMatrix< VR, PR... > >::value, CsrMatrix & >::type operator=(const DynamicMatrix< VR, PR... > &src)
Assigns a CsrMatrix from a compatible DynamicMatrix.
Definition: Morpheus_CsrMatrix.hpp:328
typename traits::non_const_index_type non_const_index_type
Definition: Morpheus_CsrMatrix.hpp:109
formats_e format_enum() const
Returns the format enum assigned to the CsrMatrix container.
Definition: Morpheus_CsrMatrix.hpp:407
MORPHEUS_FORCEINLINE_FUNCTION index_array_reference column_indices(size_type n)
Returns a reference to the column index of the matrix with index n.
Definition: Morpheus_CsrMatrix.hpp:435
Morpheus::DenseVector< index_type, size_type, array_layout, backend, memory_traits > index_array_type
Definition: Morpheus_CsrMatrix.hpp:127
typename MatrixFormatTag< Morpheus::CsrFormatTag >::tag tag
Definition: Morpheus_CsrMatrix.hpp:99
MORPHEUS_FORCEINLINE_FUNCTION index_array_type & row_offsets()
Returns a reference to the row offsets of the matrix.
Definition: Morpheus_CsrMatrix.hpp:489
CsrMatrix & allocate(const CsrMatrix< VR, PR... > &src)
Allocates memory from another CsrMatrix container with different properties.
Definition: Morpheus_CsrMatrix.hpp:397
reference operator=(const MatrixType &src)=delete
Assigns to CsrMatrix object from another storage format. This functionality is disabled to avoid impl...
CsrMatrix(const size_type num_rows, const size_type num_cols, const size_type num_entries, IndexArray roff, IndexArray cind, ValueArray vals, typename std::enable_if< is_dense_vector_format_container< ValueArray >::value &&is_dense_vector_format_container< IndexArray >::value &&is_compatible< typename CsrMatrix::value_array_type, ValueArray >::value &&is_compatible< typename CsrMatrix::index_array_type, IndexArray >::value &&!ValueArray::memory_traits::is_unmanaged &&!IndexArray::memory_traits::is_unmanaged >::type *=nullptr)
Construct a CsrMatrix object with shape (num_rows, num_cols) and number of non-zeros equal to num_ent...
Definition: Morpheus_CsrMatrix.hpp:223
Morpheus::DenseVector< value_type, size_type, array_layout, backend, memory_traits > value_array_type
Definition: Morpheus_CsrMatrix.hpp:137
void resize(const CsrMatrix< VR, PR... > &src)
Resizes CsrMatrix with the shape and number of non-zero entries of another CsrMatrix with different p...
Definition: Morpheus_CsrMatrix.hpp:384
CsrMatrix(const DynamicMatrix< VR, PR... > &src, typename std::enable_if< is_dynamically_compatible< CsrMatrix, DynamicMatrix< VR, PR... > >::value >::type *=nullptr)
Constructs a CsrMatrix from a compatible DynamicMatrix.
Definition: Morpheus_CsrMatrix.hpp:301
void resize(const size_type num_rows, const size_type num_cols, const size_type num_entries)
Resizes CsrMatrix with shape of (num_rows, num_cols) and sets number of non-zero entries to num_entri...
Definition: Morpheus_CsrMatrix.hpp:367
CsrMatrix(CsrMatrix &&)=default
The default move contructor (shallow copy) of a CsrMatrix container from another CsrMatrix container ...
void resize(const size_type n)
Resizes DenseVector with size of n and sets values to zero.
Definition: Morpheus_DenseVector.hpp:334
Implementation of the Dynamic Sparse Matrix Format Representation.
Definition: Morpheus_DynamicMatrix.hpp:104
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
Base class used to derive new matrices.
Definition: Morpheus_MatrixBase.hpp:70
void set_ncols(const size_type cols)
Set the number of columns of the matrix.
Definition: Morpheus_MatrixBase.hpp:147
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
void set_nrows(const size_type rows)
Set the number of rows of the matrix.
Definition: Morpheus_MatrixBase.hpp:140
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
void set_nnnz(const size_type nnz)
Set the number of non-zeros of the matrix.
Definition: Morpheus_MatrixBase.hpp:154
Checks if the two types are compatible containers i.e are in the same memory space and have the same ...
Definition: Morpheus_FormatTraits.hpp:286
Checks if the two types are dynamically compatible containers i.e are compatible containers and at le...
Definition: Morpheus_FormatTraits.hpp:323
Checks if the two types is of type index_type and are the same.
Definition: Morpheus_TypeTraits.hpp:514
Checks if the two types are of type value_type and the same.
Definition: Morpheus_TypeTraits.hpp:385
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
CsrMatrix< 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
CsrMatrix< 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:147
A wrapper that checks if the provided type is a scalar type.
Definition: Morpheus_TypeTraits.hpp:85