Skip to content
Snippets Groups Projects
Commit 1a0c91f6 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Get ride of SubItemValuePerItem::SubView

Now returns a subArray. This simplifies the code, makes it safer and
more consistent without any performances loss.
parent e69fb289
No related branches found
No related tags found
1 merge request!85Add Table class and use it in ItemArray
...@@ -50,55 +50,6 @@ class SubItemValuePerItem ...@@ -50,55 +50,6 @@ class SubItemValuePerItem
public: public:
using ToShared = SubItemValuePerItem<DataType, ItemOfItem, ConnectivitySharedPtr>; using ToShared = SubItemValuePerItem<DataType, ItemOfItem, ConnectivitySharedPtr>;
class SubView
{
public:
using data_type = DataType;
private:
PUGS_RESTRICT DataType* const m_sub_values;
const size_t m_size;
public:
template <typename IndexType>
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);
return m_sub_values[i];
}
template <typename IndexType>
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);
return m_sub_values[i];
}
PUGS_INLINE
size_t
size() const noexcept
{
return m_size;
}
SubView(const SubView&) = delete;
SubView(SubView&&) noexcept = delete;
PUGS_INLINE
SubView(const Array<DataType>& values, size_t begin, size_t end) noexcept(NO_ASSERT)
: m_sub_values(&(values[begin])), m_size(end - begin)
{
Assert(begin <= end);
Assert(end <= values.size());
}
~SubView() = default;
};
friend PUGS_INLINE SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr> friend PUGS_INLINE SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr>
copy(SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& source) copy(SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& source)
{ {
...@@ -178,8 +129,16 @@ class SubItemValuePerItem ...@@ -178,8 +129,16 @@ class SubItemValuePerItem
return m_host_row_map(size_t{item_id} + 1) - m_host_row_map(size_t{item_id}); return m_host_row_map(size_t{item_id} + 1) - m_host_row_map(size_t{item_id});
} }
PUGS_INLINE
void
fill(const DataType& data) const noexcept
{
static_assert(not std::is_const_v<DataType>, "Cannot modify ItemValue of const");
m_values.fill(data);
}
template <typename IndexType> template <typename IndexType>
PUGS_INLINE SubView PUGS_INLINE Array<DataType>
itemValues(IndexType item_id) noexcept(NO_ASSERT) itemValues(IndexType item_id) noexcept(NO_ASSERT)
{ {
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId"); static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
...@@ -187,13 +146,13 @@ class SubItemValuePerItem ...@@ -187,13 +146,13 @@ class SubItemValuePerItem
Assert(item_id < this->numberOfItems()); Assert(item_id < this->numberOfItems());
const auto& item_begin = m_host_row_map(size_t{item_id}); 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); const auto& item_end = m_host_row_map(size_t{item_id} + 1);
return SubView(m_values, item_begin, item_end); return subArray(m_values, item_begin, item_end - item_begin);
} }
// Following Kokkos logic, these classes are view and const view does allow // Following Kokkos logic, these classes are view and const view does allow
// changes in data // changes in data
template <typename IndexType> template <typename IndexType>
PUGS_INLINE SubView PUGS_INLINE Array<DataType>
itemValues(IndexType item_id) const noexcept(NO_ASSERT) itemValues(IndexType item_id) const noexcept(NO_ASSERT)
{ {
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId"); static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
...@@ -201,7 +160,7 @@ class SubItemValuePerItem ...@@ -201,7 +160,7 @@ class SubItemValuePerItem
Assert(item_id < this->numberOfItems()); Assert(item_id < this->numberOfItems());
const auto& item_begin = m_host_row_map(size_t{item_id}); 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); const auto& item_end = m_host_row_map(size_t{item_id} + 1);
return SubView(m_values, item_begin, item_end); return subArray(m_values, item_begin, item_end - item_begin);
} }
template <typename DataType2, typename ConnectivityPtr2> template <typename DataType2, typename ConnectivityPtr2>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment