Skip to content
Snippets Groups Projects

Add SubArray class

Merged Stéphane Del Pino requested to merge feature/item-array into develop
1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
@@ -41,6 +41,12 @@ class SubItemValuePerItem
// Allow const std:weak_ptr version to access our data
friend SubItemValuePerItem<std::add_const_t<DataType>, ItemOfItem, ConnectivityWeakPtr>;
// Allow const std:shared_ptr version to access our data
friend SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivitySharedPtr>;
// Allow const std:weak_ptr version to access our data
friend SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityWeakPtr>;
public:
using ToShared = SubItemValuePerItem<DataType, ItemOfItem, ConnectivitySharedPtr>;
@@ -55,7 +61,8 @@ class SubItemValuePerItem
public:
template <typename IndexType>
PUGS_INLINE const DataType& operator[](IndexType i) const noexcept(NO_ASSERT)
PUGS_FORCEINLINE DataType&
operator[](IndexType i) const noexcept(NO_ASSERT)
{
static_assert(std::is_integral_v<IndexType>, "SubView is indexed by integral values");
Assert(i < m_size);
@@ -63,7 +70,8 @@ class SubItemValuePerItem
}
template <typename IndexType>
PUGS_FORCEINLINE DataType& operator[](IndexType i) noexcept(NO_ASSERT)
PUGS_FORCEINLINE DataType&
operator[](IndexType i) noexcept(NO_ASSERT)
{
static_assert(std::is_integral_v<IndexType>, "SubView is indexed by integral values");
Assert(i < m_size);
@@ -78,9 +86,7 @@ class SubItemValuePerItem
}
SubView(const SubView&) = delete;
PUGS_INLINE
SubView(SubView&&) noexcept = default;
SubView(SubView&&) noexcept = delete;
PUGS_INLINE
SubView(const Array<DataType>& values, size_t begin, size_t end) noexcept(NO_ASSERT)
@@ -89,8 +95,21 @@ class SubItemValuePerItem
Assert(begin <= end);
Assert(end <= values.size());
}
~SubView() = default;
};
friend PUGS_INLINE SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr>
copy(SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& source)
{
SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr> image;
image.m_connectivity_ptr = source.m_connectivity_ptr;
image.m_host_row_map = source.m_host_row_map;
image.m_values = copy(source.m_values);
return image;
}
PUGS_INLINE
bool
isBuilt() const noexcept
@@ -98,6 +117,17 @@ class SubItemValuePerItem
return m_connectivity_ptr.use_count() != 0;
}
PUGS_INLINE
std::shared_ptr<const IConnectivity>
connectivity_ptr() const noexcept
{
if constexpr (std::is_same_v<ConnectivityPtr, ConnectivitySharedPtr>) {
return m_connectivity_ptr;
} else {
return m_connectivity_ptr.lock();
}
}
template <typename IndexType, typename SubIndexType>
PUGS_FORCEINLINE DataType&
operator()(IndexType item_id, SubIndexType i) const noexcept(NO_ASSERT)
@@ -109,32 +139,33 @@ class SubItemValuePerItem
return m_values[m_host_row_map(size_t{item_id}) + i];
}
PUGS_INLINE
size_t
numberOfValues() const noexcept(NO_ASSERT)
{
Assert(this->isBuilt());
return m_values.size();
}
// Following Kokkos logic, these classes are view and const view does allow
// changes in data
template <typename ArrayIndexType>
DataType& operator[](const ArrayIndexType& i) const noexcept(NO_ASSERT)
DataType&
operator[](const ArrayIndexType& i) const noexcept(NO_ASSERT)
{
static_assert(std::is_integral_v<ArrayIndexType>, "index must be an integral type");
Assert(this->isBuilt());
Assert(i < m_values.size());
Assert(static_cast<size_t>(i) < m_values.size());
return m_values[i];
}
PUGS_INLINE
size_t
numberOfValues() const noexcept(NO_ASSERT)
{
Assert(this->isBuilt());
return m_values.size();
}
PUGS_INLINE
size_t
numberOfItems() const noexcept(NO_ASSERT)
{
Assert(this->isBuilt());
Assert(m_host_row_map.extent(0) != 0);
return m_host_row_map.extent(0);
Assert(m_host_row_map.extent(0) > 0);
return m_host_row_map.extent(0) - 1;
}
template <typename IndexType>
@@ -143,7 +174,7 @@ class SubItemValuePerItem
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < m_host_row_map.extent(0));
Assert(item_id < this->numberOfItems());
return m_host_row_map(size_t{item_id} + 1) - m_host_row_map(size_t{item_id});
}
@@ -153,7 +184,7 @@ class SubItemValuePerItem
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < m_host_row_map.extent(0));
Assert(item_id < this->numberOfItems());
const auto& item_begin = m_host_row_map(size_t{item_id});
const auto& item_end = m_host_row_map(size_t{item_id} + 1);
return SubView(m_values, item_begin, item_end);
@@ -167,7 +198,7 @@ class SubItemValuePerItem
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < m_host_row_map.extent(0));
Assert(item_id < this->numberOfItems());
const auto& item_begin = m_host_row_map(size_t{item_id});
const auto& item_end = m_host_row_map(size_t{item_id} + 1);
return SubView(m_values, item_begin, item_end);
@@ -211,7 +242,6 @@ class SubItemValuePerItem
{
static_assert(not std::is_const_v<DataType>, "Cannot allocate SubItemValuePerItem of const data: only "
"view is supported");
;
ConnectivityMatrix connectivity_matrix = connectivity._getMatrix(item_type, sub_item_type);
Loading