24#ifndef MORPHEUS_DENSEMATRIX_HPP
25#define MORPHEUS_DENSEMATRIX_HPP
27#include <Morpheus_Exceptions.hpp>
28#include <Morpheus_FormatTags.hpp>
29#include <Morpheus_MatrixBase.hpp>
31#include <impl/Morpheus_Functors.hpp>
33#include <Kokkos_Core.hpp>
73template <
class ValueType,
class... Properties>
109 Kokkos::View<value_type **, array_layout, execution_space, memory_traits>;
110 using value_array_pointer =
typename value_array_type::pointer_type;
111 using value_array_reference =
typename value_array_type::reference_type;
151 inline DenseMatrix(
const size_type num_rows,
const size_type num_cols,
153 :
base(num_rows, num_cols, num_rows * num_cols),
154 _values(
"matrix", size_t(num_rows), size_t(num_cols)) {
155 assign(num_rows, num_cols, val);
167 template <
typename ValuePtr>
169 const size_type num_rows,
const size_type num_cols, ValuePtr ptr,
170 typename std::enable_if<std::is_pointer<ValuePtr>::value &&
172 memory_traits::is_unmanaged>
::type * =
nullptr)
173 :
base(num_rows, num_cols, num_rows * num_cols),
174 _values(ptr, size_t(num_rows), size_t(num_cols)) {
175 static_assert(std::is_same<value_array_pointer, ValuePtr>::value,
176 "Constructing DenseMatrix to wrap user memory must supply "
177 "matching pointer type");
189 template <
class VR,
class... PR>
206 template <
class VR,
class... PR>
207 typename std::enable_if<
226 template <
class MatrixType>
237 template <
class MatrixType>
248 inline void assign(size_type num_rows, size_type num_cols,
250 using range_policy = Kokkos::RangePolicy<size_type, execution_space>;
252 range_policy policy(0, num_rows);
255 Kokkos::parallel_for(
"Morpheus::DenseMatrix::assign", policy, f);
265 inline void resize(size_type num_rows, size_type num_cols) {
267 Kokkos::resize(_values,
size_t(num_rows),
size_t(num_cols));
278 template <
class VR,
class... PR>
291 template <
class VR,
class... PR>
304 MORPHEUS_FORCEINLINE_FUNCTION value_array_reference
306 return _values(i, j);
314 inline value_array_pointer
data()
const {
return _values.data(); }
The DenseMatrix container is a two-dimensional dense container that contains contiguous elements....
Definition: Morpheus_DenseMatrix.hpp:74
void assign(size_type num_rows, size_type num_cols, const value_type val)
Assigns (num_rows * num_cols) elements of value val to the DenseMatrix. The container will always res...
Definition: Morpheus_DenseMatrix.hpp:248
void resize(const DenseMatrix< VR, PR... > &src)
Resizes DenseVector with the shape another DenseMatrix with different parameters.
Definition: Morpheus_DenseMatrix.hpp:279
value_array_pointer data() const
Returns a pointer to the data at the beginning of the container.
Definition: Morpheus_DenseMatrix.hpp:314
typename MatrixFormatTag< Morpheus::DenseMatrixFormatTag >::tag tag
Definition: Morpheus_DenseMatrix.hpp:82
DenseMatrix(const DenseMatrix &)=default
The default copy contructor (shallow copy) of a DenseMatrix container from another DenseMatrix contai...
DenseMatrix & operator=(DenseMatrix &&)=default
The default move assignment (shallow copy) of a DenseMatrix container from another DenseMatrix contai...
MORPHEUS_FORCEINLINE_FUNCTION value_array_reference operator()(size_type i, size_type j) const
Returns a reference to the element with index (i,j)
Definition: Morpheus_DenseMatrix.hpp:305
typename traits::type type
Definition: Morpheus_DenseMatrix.hpp:79
value_array_type & view()
Returns a reference to the beginning of the view that holds the data.
Definition: Morpheus_DenseMatrix.hpp:321
Kokkos::View< value_type **, array_layout, execution_space, memory_traits > value_array_type
Definition: Morpheus_DenseMatrix.hpp:109
DenseMatrix()
Construct an empty DenseVector object.
Definition: Morpheus_DenseMatrix.hpp:141
typename traits::index_type index_type
Definition: Morpheus_DenseMatrix.hpp:90
typename traits::non_const_index_type non_const_index_type
Definition: Morpheus_DenseMatrix.hpp:92
DenseMatrix(const size_type num_rows, const size_type num_cols, ValuePtr ptr, typename std::enable_if< std::is_pointer< ValuePtr >::value &&is_same_value_type< value_type, ValuePtr >::value &&memory_traits::is_unmanaged >::type *=nullptr)
Construct a DenseMatrix object from a raw pointer. This is only enabled if the DenseMatrix is an unma...
Definition: Morpheus_DenseMatrix.hpp:168
typename traits::value_type value_type
Definition: Morpheus_DenseMatrix.hpp:85
const value_array_type & const_view() const
Returns a constant reference to the beginning of the view that holds the data.
Definition: Morpheus_DenseMatrix.hpp:329
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
reference operator=(const MatrixType &src)=delete
Assign to DenseMatrix object from another storage format. This functionality is disabled to avoid imp...
DenseMatrix(DenseMatrix &&)=default
The default move contructor (shallow copy) of a DenseMatrix container from another DenseMatrix contai...
DenseMatrix(const MatrixType &src)=delete
Construct a DenserMatrix object from another storage format. This functionality is disabled to avoid ...
typename traits::non_const_value_type non_const_value_type
Definition: Morpheus_DenseMatrix.hpp:87
~DenseMatrix()=default
Default destructor.
DenseMatrix & operator=(const DenseMatrix &)=default
The default copy assignment (shallow copy) of a DenseMatrix container from another DenseMatrix contai...
DenseMatrix(const DenseMatrix< VR, PR... > &src, typename std::enable_if< is_format_compatible< DenseMatrix, DenseMatrix< VR, PR... > >::value >::type *=nullptr)
Shallow Copy contrustor from another DenseMatrix container with different properties....
Definition: Morpheus_DenseMatrix.hpp:190
DenseMatrix(const size_type num_rows, const size_type num_cols, const value_type val=0)
Construct a DenseMatrix object with shape (num_rows, num_cols) and values set to val.
Definition: Morpheus_DenseMatrix.hpp:151
DenseMatrix & allocate(const DenseMatrix< VR, PR... > &src)
Allocates memory from another DenseMatrix container with different properties.
Definition: Morpheus_DenseMatrix.hpp:292
std::enable_if< is_format_compatible< DenseMatrix, DenseMatrix< VR, PR... > >::value, DenseMatrix & >::type operator=(const DenseMatrix< VR, PR... > &src)
Shallow Copy Assignment from another DenseMatrix container with different properties....
Definition: Morpheus_DenseMatrix.hpp:210
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 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
DenseMatrix< 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
DenseMatrix< 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_Functors.hpp:32
A wrapper that checks if the provided type is a scalar type.
Definition: Morpheus_TypeTraits.hpp:85