24#ifndef MORPHEUS_COOMATRIX_HPP
25#define MORPHEUS_COOMATRIX_HPP
27#include <Morpheus_Exceptions.hpp>
28#include <Morpheus_FormatTags.hpp>
29#include <Morpheus_DenseVector.hpp>
30#include <Morpheus_DynamicMatrix.hpp>
31#include <Morpheus_Sort.hpp>
32#include <Morpheus_MatrixBase.hpp>
90template <
class ValueType,
class... Properties>
128 using index_array_pointer =
typename index_array_type::value_array_pointer;
129 using index_array_reference =
130 typename index_array_type::value_array_reference;
136 using value_array_pointer =
typename value_array_type::value_array_pointer;
137 using value_array_reference =
138 typename value_array_type::value_array_reference;
168 inline CooMatrix() :
base(), _row_indices(), _column_indices(), _values() {}
180 :
base(num_rows, num_cols, num_entries),
181 _row_indices(num_entries),
182 _column_indices(num_entries),
183 _values(num_entries) {}
186 template <
typename ValuePtr,
typename IndexPtr>
189 const size_type num_entries, IndexPtr rind_ptr, IndexPtr cind_ptr,
191 typename std::enable_if<
192 (std::is_pointer<ValuePtr>::value &&
194 memory_traits::is_unmanaged) &&
195 (std::is_pointer<IndexPtr>::value &&
197 memory_traits::is_unmanaged)>::type * =
nullptr)
198 :
base(num_rows, num_cols, num_entries),
199 _row_indices(size_t(num_entries), rind_ptr),
200 _column_indices(size_t(num_entries), cind_ptr),
201 _values(size_t(num_entries), vals_ptr) {}
218 template <
typename ValueArray,
typename IndexArray>
221 const size_type num_entries, IndexArray rind, IndexArray cind,
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),
234 _column_indices(cind),
247 template <
class VR,
class... PR>
267 template <
class VR,
class... PR>
268 typename std::enable_if<
296 template <
class VR,
class... PR>
320 template <
class VR,
class... PR>
321 typename std::enable_if<
341 template <
typename MatrixType>
352 template <
typename MatrixType>
366 _row_indices.
resize(num_entries);
367 _column_indices.
resize(num_entries);
368 _values.
resize(num_entries);
379 template <
class VR,
class... PR>
392 template <
class VR,
class... PR>
410 void sort(
void) { Morpheus::sort_by_row_and_column<backend>(*
this); }
426 bool is_sorted(
void) {
return Morpheus::is_sorted<backend>(*
this); }
450 return _row_indices(n);
460 MORPHEUS_FORCEINLINE_FUNCTION index_array_reference
462 return _column_indices(n);
482 MORPHEUS_FORCEINLINE_FUNCTION
const index_array_reference
484 return _row_indices(n);
494 MORPHEUS_FORCEINLINE_FUNCTION
const index_array_reference
496 return _column_indices(n);
505 MORPHEUS_FORCEINLINE_FUNCTION
const value_array_reference
525 return _column_indices;
551 return _column_indices;
566 static constexpr formats_e _id = Morpheus::COO_FORMAT;
Implementation of the Coordinate (COO) Sparse Matrix Format Representation.
Definition: Morpheus_CooMatrix.hpp:91
MORPHEUS_FORCEINLINE_FUNCTION index_array_type & column_indices()
Returns a reference to the column indices of the matrix.
Definition: Morpheus_CooMatrix.hpp:524
CooMatrix(const DynamicMatrix< VR, PR... > &src, typename std::enable_if< is_dynamically_compatible< CooMatrix, DynamicMatrix< VR, PR... > >::value >::type *=nullptr)
Constructs a CooMatrix from a compatible DynamicMatrix.
Definition: Morpheus_CooMatrix.hpp:297
std::enable_if< is_format_compatible< CooMatrix, CooMatrix< VR, PR... > >::value, CooMatrix & >::type operator=(const CooMatrix< VR, PR... > &src)
Assigns a CooMatrix from another compatible CooMatrix.
Definition: Morpheus_CooMatrix.hpp:271
typename traits::value_type value_type
Definition: Morpheus_CooMatrix.hpp:102
CooMatrix & operator=(const CooMatrix &)=default
The default copy assignment (shallow copy) of a CooMatrix container from another CooMatrix container ...
CooMatrix(const MatrixType &src)=delete
Construct a CooMatrix object from another storage format. This functionality is disabled to avoid imp...
formats_e format_enum() const
Returns the format enum assigned to the CooMatrix container.
Definition: Morpheus_CooMatrix.hpp:433
MORPHEUS_FORCEINLINE_FUNCTION const value_array_type & cvalues() const
Returns a reference to the values of the matrix.
Definition: Morpheus_CooMatrix.hpp:559
~CooMatrix()=default
The default destructor.
CooMatrix(const size_type num_rows, const size_type num_cols, const size_type num_entries)
Construct a CooMatrix object with shape (num_rows, num_cols) and number of non-zeros equal to num_ent...
Definition: Morpheus_CooMatrix.hpp:178
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_CooMatrix.hpp:495
void resize(const CooMatrix< VR, PR... > &src)
Resizes CooMatrix with the shape and number of non-zero entries of another CooMatrix with different p...
Definition: Morpheus_CooMatrix.hpp:380
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_CooMatrix.hpp:461
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_CooMatrix.hpp:506
reference operator=(const MatrixType &src)=delete
Assign to CooMatrix object from another storage format. This functionality is disabled to avoid impli...
CooMatrix & operator=(CooMatrix &&)=default
The default move assignment (shallow copy) of a CooMatrix container from another CooMatrix container ...
MORPHEUS_FORCEINLINE_FUNCTION value_array_type & values()
Returns a reference to the values of the matrix.
Definition: Morpheus_CooMatrix.hpp:533
std::enable_if< is_dynamically_compatible< CooMatrix, DynamicMatrix< VR, PR... > >::value, CooMatrix & >::type operator=(const DynamicMatrix< VR, PR... > &src)
Assigns a CooMatrix from a compatible DynamicMatrix.
Definition: Morpheus_CooMatrix.hpp:324
CooMatrix(const CooMatrix< VR, PR... > &src, typename std::enable_if< is_format_compatible< CooMatrix, CooMatrix< VR, PR... > >::value >::type *=nullptr)
Constructs a CooMatrix from another compatible CooMatrix.
Definition: Morpheus_CooMatrix.hpp:248
typename traits::non_const_index_type non_const_index_type
Definition: Morpheus_CooMatrix.hpp:109
void sort_by_row(void)
Sorts matrix elements by row index.
Definition: Morpheus_CooMatrix.hpp:402
MatrixBase< CooMatrix, ValueType, Properties... > base
The tag associated specificaly to the particular container*/.
Definition: Morpheus_CooMatrix.hpp:98
MORPHEUS_FORCEINLINE_FUNCTION const index_array_reference crow_indices(size_type n) const
Returns a const-reference to the row index of the matrix with index n.
Definition: Morpheus_CooMatrix.hpp:483
MORPHEUS_FORCEINLINE_FUNCTION const index_array_type & ccolumn_indices() const
Returns a const-reference to the column indices of the matrix.
Definition: Morpheus_CooMatrix.hpp:549
CooMatrix(const size_type num_rows, const size_type num_cols, const size_type num_entries, IndexArray rind, 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 CooMatrix::value_array_type, ValueArray >::value &&is_compatible< typename CooMatrix::index_array_type, IndexArray >::value &&!ValueArray::memory_traits::is_unmanaged &&!IndexArray::memory_traits::is_unmanaged >::type *=nullptr)
Construct a CooMatrix object with shape (num_rows, num_cols) and number of non-zeros equal to num_ent...
Definition: Morpheus_CooMatrix.hpp:219
typename traits::non_const_value_type non_const_value_type
Definition: Morpheus_CooMatrix.hpp:104
CooMatrix(const CooMatrix &)=default
The default copy contructor (shallow copy) of a CooMatrix container from another CooMatrix container ...
Morpheus::DenseVector< value_type, size_type, array_layout, backend, memory_traits > value_array_type
Definition: Morpheus_CooMatrix.hpp:135
void resize(const size_type num_rows, const size_type num_cols, const size_type num_entries)
Resizes CooMatrix with shape of (num_rows, num_cols) and sets number of non-zero entries to num_entri...
Definition: Morpheus_CooMatrix.hpp:363
MORPHEUS_FORCEINLINE_FUNCTION value_array_reference values(size_type n)
Returns a reference to the value of the matrix with index n.
Definition: Morpheus_CooMatrix.hpp:471
bool is_sorted(void)
Determines whether matrix elements are sorted by row and column index.
Definition: Morpheus_CooMatrix.hpp:426
void sort(void)
Sorts matrix elements by row index first and then by column index.
Definition: Morpheus_CooMatrix.hpp:410
int format_index() const
Returns the equivalent index to the format enum assigned to the CooMatrix container.
Definition: Morpheus_CooMatrix.hpp:441
MORPHEUS_FORCEINLINE_FUNCTION index_array_type & row_indices()
Returns a reference to the row indices of the matrix.
Definition: Morpheus_CooMatrix.hpp:515
bool is_sorted_by_row(void)
Determines whether matrix elements are sorted by row index.
Definition: Morpheus_CooMatrix.hpp:416
CooMatrix & allocate(const CooMatrix< VR, PR... > &src)
Allocates memory from another CooMatrix container with different properties.
Definition: Morpheus_CooMatrix.hpp:393
CooMatrix()
Construct an empty CooMatrix object.
Definition: Morpheus_CooMatrix.hpp:168
MORPHEUS_FORCEINLINE_FUNCTION const index_array_type & crow_indices() const
Returns a const-reference to the row indices of the matrix.
Definition: Morpheus_CooMatrix.hpp:540
Morpheus::DenseVector< index_type, size_type, array_layout, backend, memory_traits > index_array_type
Definition: Morpheus_CooMatrix.hpp:127
CooMatrix(CooMatrix &&)=default
The default move contructor (shallow copy) of a CooMatrix container from another CooMatrix container ...
typename traits::size_type size_type
The type of the indices held by the container - can be const.
Definition: Morpheus_CooMatrix.hpp:106
MORPHEUS_FORCEINLINE_FUNCTION index_array_reference row_indices(size_type n)
Returns a reference to the row index of the matrix with index n.
Definition: Morpheus_CooMatrix.hpp:449
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
Definition: Morpheus_Exceptions.hpp:43
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
CooMatrix< 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
CooMatrix< 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