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

Add fill and copy mechanisms

parent 64443540
Branches
Tags
1 merge request!11Feature/mpi
...@@ -31,6 +31,16 @@ class ItemValue ...@@ -31,6 +31,16 @@ class ItemValue
friend ItemValue<std::add_const_t<DataType>, friend ItemValue<std::add_const_t<DataType>,
item_type>; item_type>;
friend PASTIS_INLINE
ItemValue<std::remove_const_t<DataType>,item_type>
copy(const ItemValue<DataType, item_type>& source)
{
ItemValue<std::remove_const_t<DataType>, item_type> image(source);
image.m_values = copy(source.m_values);
return image;
}
public: public:
PASTIS_FORCEINLINE PASTIS_FORCEINLINE
const bool& isBuilt() const const bool& isBuilt() const
...@@ -45,6 +55,14 @@ class ItemValue ...@@ -45,6 +55,14 @@ class ItemValue
return m_values.size(); return m_values.size();
} }
PASTIS_INLINE
void fill(const DataType& data) const
{
static_assert(not std::is_const<DataType>(),
"Cannot modify ItemValue of const");
m_values.fill(data);
}
// 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
PASTIS_FORCEINLINE PASTIS_FORCEINLINE
...@@ -59,6 +77,8 @@ class ItemValue ...@@ -59,6 +77,8 @@ class ItemValue
{ {
static_assert(std::is_same<IndexType,ItemId>(), static_assert(std::is_same<IndexType,ItemId>(),
"ItemValue must be indexed by ItemId"); "ItemValue must be indexed by ItemId");
static_assert(not std::is_const<DataType>(),
"Cannot modify ItemValue of const");
return m_values[i]; return m_values[i];
} }
......
...@@ -33,6 +33,17 @@ class Array ...@@ -33,6 +33,17 @@ class Array
return m_values[i]; return m_values[i];
} }
PASTIS_INLINE
void fill(const DataType& data) const
{
static_assert(not std::is_const<DataType>(),
"Cannot modify Array of const");
parallel_for(this->size(), PASTIS_LAMBDA(const index_type& i){
m_values[i] = data;
});
}
template <typename DataType2> template <typename DataType2>
PASTIS_INLINE PASTIS_INLINE
Array& operator=(const Array<DataType2>& array) Array& operator=(const Array<DataType2>& array)
...@@ -82,4 +93,17 @@ class Array ...@@ -82,4 +93,17 @@ class Array
~Array() = default; ~Array() = default;
}; };
template <typename DataType>
PASTIS_INLINE
Array<std::remove_const_t<DataType>> copy(const Array<DataType>& array)
{
Array<std::remove_const_t<DataType>> image(array.size());
using index_type = typename Array<DataType>::index_type;
parallel_for(array.size(), PASTIS_LAMBDA(const index_type& i){
image[i] = array[i];
});
return image;
}
#endif // ARRAY_HPP #endif // ARRAY_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment