24#ifndef MORPHEUS_DIAMATRIX_HPP
25#define MORPHEUS_DIAMATRIX_HPP
27#include <Morpheus_Exceptions.hpp>
28#include <Morpheus_FormatTags.hpp>
29#include <Morpheus_DenseVector.hpp>
30#include <Morpheus_DenseMatrix.hpp>
31#include <Morpheus_DynamicMatrix.hpp>
32#include <Morpheus_MatrixBase.hpp>
34#include <impl/Dia/Morpheus_Utils_Impl.hpp>
96template <
class ValueType,
class... Properties>
135 using index_array_pointer =
typename index_array_type::value_array_pointer;
136 using index_array_reference =
137 typename index_array_type::value_array_reference;
138 using const_index_array_reference =
const index_array_reference;
145 using value_array_pointer =
typename value_array_type::value_array_pointer;
146 using value_array_reference =
147 typename value_array_type::value_array_reference;
148 using const_value_array_reference =
const value_array_reference;
179 :
base(), _ndiags(0), _alignment(0), _diagonal_offsets(), _values() {}
192 inline DiaMatrix(
const size_type num_rows,
const size_type num_cols,
193 const size_type num_entries,
const size_type num_diagonals,
195 :
base(num_rows, num_cols, num_entries),
196 _ndiags(num_diagonals),
198 _diagonal_offsets(num_diagonals) {
218 template <
typename ValueArray,
typename IndexArray>
220 const size_type num_rows,
const size_type num_cols,
221 const size_type num_entries,
const IndexArray &diag_offsets,
222 const ValueArray &vals,
223 typename std::enable_if<
227 ValueArray>::value &&
229 IndexArray>::value &&
230 !ValueArray::memory_traits::is_unmanaged &&
231 !IndexArray::memory_traits::is_unmanaged>
::type * =
nullptr)
232 :
base(num_rows, num_cols, num_entries),
233 _diagonal_offsets(diag_offsets),
235 _ndiags = _diagonal_offsets.
size();
236 _alignment = _values.
nrows();
240 template <
typename ValuePtr,
typename IndexPtr>
242 const size_type num_rows,
const size_type num_cols,
243 const size_type num_entries, IndexPtr diag_offsets_ptr, ValuePtr vals_ptr,
244 const size_type num_diagonals,
const size_type
alignment = 32,
245 typename std::enable_if<
246 (std::is_pointer<ValuePtr>::value &&
248 memory_traits::is_unmanaged) &&
249 (std::is_pointer<IndexPtr>::value &&
251 memory_traits::is_unmanaged)>
::type * =
nullptr)
252 : base(num_rows, num_cols, num_entries),
253 _diagonal_offsets(num_diagonals, diag_offsets_ptr),
254 _values(Impl::get_pad_size<size_type>(num_rows,
alignment),
255 num_diagonals, vals_ptr) {}
267 template <
class VR,
class... PR>
288 template <
class VR,
class... PR>
289 typename std::enable_if<
318 template <
class VR,
class... PR>
342 template <
class VR,
class... PR>
343 typename std::enable_if<
363 template <
typename MatrixType>
374 template <
typename MatrixType>
388 inline void resize(
const size_type num_rows,
const size_type num_cols,
389 const size_type num_entries,
const size_type num_diagonals,
392 _ndiags = num_diagonals;
395 if (Impl::exceeds_tolerance(num_rows, num_entries, _ndiags)) {
397 "DiaMatrix fill-in would exceed maximum tolerance");
400 _diagonal_offsets.
resize(num_diagonals);
413 template <
class VR,
class... PR>
426 template <
class VR,
class... PR>
454 MORPHEUS_FORCEINLINE_FUNCTION index_array_reference
456 return _diagonal_offsets(n);
466 MORPHEUS_FORCEINLINE_FUNCTION value_array_reference
values(size_type i,
468 return _values(i, j);
478 MORPHEUS_FORCEINLINE_FUNCTION const_index_array_reference
480 return _diagonal_offsets(n);
491 MORPHEUS_FORCEINLINE_FUNCTION const_value_array_reference
493 return _values(i, j);
502 return _diagonal_offsets;
519 return _diagonal_offsets;
536 MORPHEUS_FORCEINLINE_FUNCTION size_type
ndiags()
const {
return _ndiags; }
543 MORPHEUS_FORCEINLINE_FUNCTION size_type
alignment()
const {
552 MORPHEUS_FORCEINLINE_FUNCTION
void set_ndiags(
const size_type num_diagonals) {
553 _ndiags = num_diagonals;
566 size_type _ndiags, _alignment;
569 static constexpr formats_e _id = Morpheus::DIA_FORMAT;
void resize(size_type num_rows, size_type num_cols)
Resizes DenseMatrix with shape (num_rows * num_cols). Overlapping subextents will preserve their cont...
Definition: Morpheus_DenseMatrix.hpp:265
void resize(const size_type n)
Resizes DenseVector with size of n and sets values to zero.
Definition: Morpheus_DenseVector.hpp:334
size_type size() const
Returns the size of the container.
Definition: Morpheus_DenseVector.hpp:305
Implementation of the Diagonal (DIA) Sparse Matrix Format Representation.
Definition: Morpheus_DiaMatrix.hpp:97
void resize(const DiaMatrix< VR, PR... > &src)
Resizes DiaMatrix with the shape and number of non-zero entries of another DiaMatrix with different p...
Definition: Morpheus_DiaMatrix.hpp:414
~DiaMatrix()=default
The default destructor.
reference operator=(const MatrixType &src)=delete
Assigns to DiaMatrix object from another storage format. This functionality is disabled to avoid impl...
DiaMatrix & allocate(const DiaMatrix< VR, PR... > &src)
Allocates memory from another DiaMatrix container with different properties.
Definition: Morpheus_DiaMatrix.hpp:427
DiaMatrix(DiaMatrix &&)=default
The default move contructor (shallow copy) of a DiaMatrix container from another DiaMatrix container ...
MORPHEUS_FORCEINLINE_FUNCTION const_index_array_reference cdiagonal_offsets(size_type n) const
Returns a const-reference to the diagonal offsets of the matrix with index n.
Definition: Morpheus_DiaMatrix.hpp:479
MORPHEUS_FORCEINLINE_FUNCTION size_type ndiags() const
Returns the number of occupied diagonals of the matrix.
Definition: Morpheus_DiaMatrix.hpp:536
Morpheus::DenseVector< index_type, size_type, array_layout, backend, memory_traits > index_array_type
Definition: Morpheus_DiaMatrix.hpp:133
MORPHEUS_FORCEINLINE_FUNCTION value_array_type & values()
Returns a reference to the values of the matrix.
Definition: Morpheus_DiaMatrix.hpp:510
MORPHEUS_FORCEINLINE_FUNCTION const_value_array_reference cvalues(size_type i, size_type j) const
Returns a const-reference to the value of the matrix with indexes (i, j)
Definition: Morpheus_DiaMatrix.hpp:492
void resize(const size_type num_rows, const size_type num_cols, const size_type num_entries, const size_type num_diagonals, const size_type alignment=32)
Resizes DiaMatrix with shape of (num_rows, num_cols) and sets number of non-zero entries to num_entri...
Definition: Morpheus_DiaMatrix.hpp:388
DiaMatrix(const DiaMatrix< VR, PR... > &src, typename std::enable_if< is_format_compatible< DiaMatrix, DiaMatrix< VR, PR... > >::value >::type *=nullptr)
Constructs a DiaMatrix from another compatible DiaMatrix.
Definition: Morpheus_DiaMatrix.hpp:268
MORPHEUS_FORCEINLINE_FUNCTION index_array_type & diagonal_offsets()
Returns a reference to the diagonal offsets of the matrix.
Definition: Morpheus_DiaMatrix.hpp:501
DiaMatrix(const size_type num_rows, const size_type num_cols, const size_type num_entries, const size_type num_diagonals, const size_type alignment=32)
Construct a DiaMatrix object with shape (num_rows, num_cols) and number of non-zeros equal to num_ent...
Definition: Morpheus_DiaMatrix.hpp:192
MORPHEUS_FORCEINLINE_FUNCTION void set_ndiags(const size_type num_diagonals)
Sets the number of occupied diagonals of the matrix.
Definition: Morpheus_DiaMatrix.hpp:552
int format_index() const
Returns the equivalent index to the format enum assigned to the DiaMatrix container.
Definition: Morpheus_DiaMatrix.hpp:445
DiaMatrix(const size_type num_rows, const size_type num_cols, const size_type num_entries, const IndexArray &diag_offsets, const ValueArray &vals, typename std::enable_if< is_dense_matrix_format_container< ValueArray >::value &&is_dense_vector_format_container< IndexArray >::value &&is_compatible< typename DiaMatrix::value_array_type, ValueArray >::value &&is_compatible< typename DiaMatrix::index_array_type, IndexArray >::value &&!ValueArray::memory_traits::is_unmanaged &&!IndexArray::memory_traits::is_unmanaged >::type *=nullptr)
Construct a DiaMatrix object with shape (num_rows, num_cols) and number of non-zeros equal to num_ent...
Definition: Morpheus_DiaMatrix.hpp:219
typename traits::type type
Definition: Morpheus_DiaMatrix.hpp:102
DiaMatrix(const DiaMatrix &)=default
The default copy contructor (shallow copy) of a DiaMatrix container from another DiaMatrix container ...
std::enable_if< is_dynamically_compatible< DiaMatrix, DynamicMatrix< VR, PR... > >::value, DiaMatrix & >::type operator=(const DynamicMatrix< VR, PR... > &src)
Assigns a DiarMatrix from a compatible DynamicMatrix.
Definition: Morpheus_DiaMatrix.hpp:346
MORPHEUS_FORCEINLINE_FUNCTION size_type alignment() const
Returns the amount of padding used to align the data.
Definition: Morpheus_DiaMatrix.hpp:543
std::enable_if< is_format_compatible< DiaMatrix, DiaMatrix< VR, PR... > >::value, DiaMatrix & >::type operator=(const DiaMatrix< VR, PR... > &src)
Assigns a DiaMatrix from another compatible DiaMatrix.
Definition: Morpheus_DiaMatrix.hpp:292
typename traits::value_type value_type
Definition: Morpheus_DiaMatrix.hpp:108
DiaMatrix(const DynamicMatrix< VR, PR... > &src, typename std::enable_if< is_dynamically_compatible< DiaMatrix, DynamicMatrix< VR, PR... > >::value >::type *=nullptr)
Constructs a DiaMatrix from a compatible DynamicMatrix.
Definition: Morpheus_DiaMatrix.hpp:319
formats_e format_enum() const
Returns the format enum assigned to the DiaMatrix container.
Definition: Morpheus_DiaMatrix.hpp:437
typename MatrixFormatTag< DiaFormatTag >::tag tag
Definition: Morpheus_DiaMatrix.hpp:105
typename traits::non_const_index_type non_const_index_type
Definition: Morpheus_DiaMatrix.hpp:115
typename traits::non_const_value_type non_const_value_type
Definition: Morpheus_DiaMatrix.hpp:110
DiaMatrix(const MatrixType &src)=delete
Construct a DiaMatrix object from another storage format. This functionality is disabled to avoid imp...
DiaMatrix & operator=(DiaMatrix &&)=default
The default move assignment (shallow copy) of a DiaMatrix container from another DiaMatrix container ...
DiaMatrix()
Construct an empty DiaMatrix object.
Definition: Morpheus_DiaMatrix.hpp:178
MORPHEUS_FORCEINLINE_FUNCTION index_array_reference diagonal_offsets(size_type n)
Returns a reference to the diagonal offsets of the matrix with index n.
Definition: Morpheus_DiaMatrix.hpp:455
MORPHEUS_FORCEINLINE_FUNCTION value_array_reference values(size_type i, size_type j)
Returns a reference to the value of the matrix with indexes (i, j)
Definition: Morpheus_DiaMatrix.hpp:466
MORPHEUS_FORCEINLINE_FUNCTION const_index_array_type & cdiagonal_offsets() const
Returns a const-reference to the diagonal offsets of the matrix.
Definition: Morpheus_DiaMatrix.hpp:517
MORPHEUS_FORCEINLINE_FUNCTION const_value_array_type & cvalues() const
Returns a const-reference to the values of the matrix.
Definition: Morpheus_DiaMatrix.hpp:527
MORPHEUS_FORCEINLINE_FUNCTION void set_alignment(const size_type alignment)
Sets amount of padding with which to align the data.
Definition: Morpheus_DiaMatrix.hpp:561
DiaMatrix & operator=(const DiaMatrix &)=default
The default copy assignment (shallow copy) of a DiaMatrix container from another DiaMatrix container ...
typename traits::index_type index_type
Definition: Morpheus_DiaMatrix.hpp:113
Morpheus::DenseMatrix< value_type, size_type, array_layout, backend, memory_traits > value_array_type
Definition: Morpheus_DiaMatrix.hpp:143
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
DiaMatrix< 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
DiaMatrix< 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