23#ifndef MORPHEUS_DENSEVECTOR_HPP
24#define MORPHEUS_DENSEVECTOR_HPP
26#include <Morpheus_FormatTraits.hpp>
27#include <Morpheus_FormatTags.hpp>
28#include <Morpheus_ContainerTraits.hpp>
30#include <impl/Morpheus_Functors.hpp>
32#include <Kokkos_Core.hpp>
33#include <Kokkos_Random.hpp>
81template <
class ValueType,
class... Properties>
117 Kokkos::View<value_type*, array_layout, execution_space, memory_traits>;
118 using value_array_pointer =
typename value_array_type::pointer_type;
119 using value_array_reference =
typename value_array_type::reference_type;
159 : _size(n), _values(
"vector", n) {
171 template <
typename ValuePtr>
173 typename std::enable_if<std::is_pointer<ValuePtr>::value>
::type* =
175 : _size(n), _values(ptr, n) {
176 static_assert(std::is_same<value_array_pointer, ValuePtr>::value,
177 "Constructing DenseVector to wrap user memory must supply "
178 "matching pointer type");
191 template <
typename Generator>
194 : _size(n), _values(
"vector", n) {
195 Kokkos::fill_random(_values, rand_pool, range_low, range_high);
207 template <
class VR,
class... PR>
210 typename std::enable_if_t<
223 template <
class VR,
class... PR>
224 typename std::enable_if_t<
240 template <
class VR,
class... PR>
254 using range_policy = Kokkos::RangePolicy<size_type, execution_space>;
256 range_policy policy(0, n);
258 Kokkos::parallel_for(
"Morpheus::DenseVector::assign", policy, f);
271 template <
typename Generator>
272 inline void assign(
const size_type n, Generator rand_pool,
274 auto vals = Kokkos::subview(_values, std::make_pair(size_type(0), n));
275 Kokkos::fill_random(vals, rand_pool, range_low, range_high);
284 MORPHEUS_FORCEINLINE_FUNCTION value_array_reference
295 MORPHEUS_FORCEINLINE_FUNCTION value_array_reference
305 inline size_type
size()
const {
return _size; }
312 inline value_array_pointer
data()
const {
return _values.data(); }
335 Kokkos::resize(_values, n);
359 template <
class VR,
class... PR>
The DenseVector container is a one-dimensional container that contains contiguous elements....
Definition: Morpheus_DenseVector.hpp:83
value_array_type & view()
Returns a reference to the beginning of the view that holds the data.
Definition: Morpheus_DenseVector.hpp:319
void assign(const size_type n, Generator rand_pool, const value_type range_low, const value_type range_high)
Assigns n elements of values between range_low and range_high to the DenseVector.
Definition: Morpheus_DenseVector.hpp:272
DenseVector(const DenseVector &)=default
The default copy contructor (shallow copy) of a DenseVector container from another DenseVector contai...
typename traits::index_type index_type
Definition: Morpheus_DenseVector.hpp:98
typename traits::type type
Definition: Morpheus_DenseVector.hpp:88
DenseVector(DenseVector &&)=default
The default move contructor (shallow copy) of a DenseVector container from another DenseVector contai...
void assign(const size_type n, const value_type val)
Assigns n elements of value val to the DenseVector.
Definition: Morpheus_DenseVector.hpp:253
void resize(const size_type n)
Resizes DenseVector with size of n and sets values to zero.
Definition: Morpheus_DenseVector.hpp:334
DenseVector(const size_type n, Generator rand_pool, const value_type range_low, const value_type range_high)
Construct a DenseVector object with values from range_low to range_high.
Definition: Morpheus_DenseVector.hpp:192
Kokkos::View< value_type *, array_layout, execution_space, memory_traits > value_array_type
Definition: Morpheus_DenseVector.hpp:117
void resize(const size_type n, const value_type val)
Resizes DenseVector with size of n and sets values to val. Note that compared to assign() member func...
Definition: Morpheus_DenseVector.hpp:346
DenseVector(const size_type n, value_type val=0)
Construct a DenseVector object with size n and values set to val.
Definition: Morpheus_DenseVector.hpp:158
typename traits::non_const_index_type non_const_index_type
Definition: Morpheus_DenseVector.hpp:100
const value_array_type & const_view() const
Returns a constant reference to the beginning of the view that holds the data.
Definition: Morpheus_DenseVector.hpp:327
size_type size() const
Returns the size of the container.
Definition: Morpheus_DenseVector.hpp:305
typename traits::non_const_value_type non_const_value_type
Definition: Morpheus_DenseVector.hpp:95
DenseVector & operator=(const DenseVector &)=default
The default copy assignment (shallow copy) of a DenseVector container from another DenseVector contai...
DenseVector & operator=(DenseVector &&)=default
The default move assignment (shallow copy) of a DenseVector container from another DenseVector contai...
std::enable_if_t< is_compatible< DenseVector, DenseVector< VR, PR... > >::value, DenseVector & > operator=(const DenseVector< VR, PR... > &src)
Shallow Copy Assignment from another DenseVector container with different properties....
Definition: Morpheus_DenseVector.hpp:226
typename VectorFormatTag< Morpheus::DenseVectorFormatTag >::tag tag
Definition: Morpheus_DenseVector.hpp:90
typename traits::value_type value_type
Definition: Morpheus_DenseVector.hpp:93
MORPHEUS_FORCEINLINE_FUNCTION value_array_reference operator[](const size_type i) const
Returns a reference to the element with index i.
Definition: Morpheus_DenseVector.hpp:296
DenseVector(const size_type n, ValuePtr ptr, typename std::enable_if< std::is_pointer< ValuePtr >::value >::type *=nullptr)
Construct a DenseVector object from a raw pointer. This is only enabled if the DenseVector is an unma...
Definition: Morpheus_DenseVector.hpp:172
~DenseVector()=default
The default destructor.
void resize(const DenseVector< VR, PR... > &src)
Resizes DenseVector with the shape another DenseVector with different parameters.
Definition: Morpheus_DenseVector.hpp:360
DenseVector()
Construct an empty DenseVector object.
Definition: Morpheus_DenseVector.hpp:149
DenseVector(const DenseVector< VR, PR... > &src, typename std::enable_if_t< is_compatible< DenseVector, DenseVector< VR, PR... > >::value > *=nullptr)
Shallow Copy contrustor from another DenseVector container with different properties....
Definition: Morpheus_DenseVector.hpp:208
MORPHEUS_FORCEINLINE_FUNCTION value_array_reference operator()(const size_type i) const
Returns a reference to the element with index i.
Definition: Morpheus_DenseVector.hpp:285
value_array_pointer data() const
Returns a pointer to the data at the beginning of the container.
Definition: Morpheus_DenseVector.hpp:312
DenseVector & allocate(const DenseVector< VR, PR... > &src)
Allocates memory from another DenseVector container with different properties.
Definition: Morpheus_DenseVector.hpp:241
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
Generic Morpheus interfaces.
Definition: dummy.cpp:24
Traits class for accessing attributes of a Container (Matrix or Vector)
Definition: Morpheus_ContainerTraits.hpp:54
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
DenseVector< 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
DenseVector< 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