15#ifndef dealii_array_view_h
16#define dealii_array_view_h
26#include <boost/container/small_vector.hpp>
38template <
int N,
typename T>
41template <
typename number>
86template <
typename ElementType,
typename MemorySpaceType = MemorySpace::Host>
145 const ArrayView<std::remove_cv_t<value_type>, MemorySpaceType> &view);
153#ifdef DEAL_II_HAVE_CXX20
171 template <
typename ContiguousContainer>
172 ArrayView(
const ContiguousContainer &container)
173 requires(std::is_same_v<
174 std::remove_cv_t<ElementType>,
175 std::remove_cv_t<typename ContiguousContainer::value_type>> &&
176 std::is_const_v<ElementType> &&
196 template <
typename ContiguousContainer>
197 ArrayView(ContiguousContainer &container)
198 requires(std::is_same_v<
199 std::remove_cv_t<ElementType>,
200 std::remove_cv_t<typename ContiguousContainer::value_type>> &&
223 template <
typename ContiguousContainer,
224 typename =
decltype(std::data(std::declval<ContiguousContainer>())),
225 typename =
decltype(std::size(std::declval<ContiguousContainer>())),
226 typename = std::enable_if_t<
228 std::remove_cv_t<ElementType>,
229 std::remove_cv_t<typename ContiguousContainer::value_type>> &&
230 std::is_const_v<ElementType>>>
250 template <
typename ContiguousContainer,
251 typename =
decltype(std::data(std::declval<ContiguousContainer>())),
252 typename =
decltype(std::size(std::declval<ContiguousContainer>())),
253 typename = std::enable_if_t<std::is_same_v<
254 std::remove_cv_t<ElementType>,
255 std::remove_cv_t<typename ContiguousContainer::value_type>>>>
274 template <std::
size_t N>
321 const std::initializer_list<std::remove_cv_t<value_type>> &initializer_list)
474 operator[](const
std::
size_t i) const;
488 friend class
ArrayView<const ElementType, MemorySpaceType>;
496template <typename ElementType, typename MemorySpaceType>
504template <
typename ElementType,
typename MemorySpaceType>
519template <
typename ElementType,
typename MemorySpaceType>
522 const std::size_t n_elements)
526 this->starting_element = starting_element;
528 this->starting_element =
nullptr;
530 this->starting_element = starting_element;
532 this->n_elements = n_elements;
537template <
typename ElementType,
typename MemorySpaceType>
539 : starting_element(&element)
545template <
typename ElementType,
typename MemorySpaceType>
547 const ArrayView<std::remove_cv_t<value_type>, MemorySpaceType> &view)
548 : starting_element(view.starting_element)
549 , n_elements(view.n_elements)
553#ifdef DEAL_II_HAVE_CXX20
555template <
typename ElementType,
typename MemorySpaceType>
556template <
typename ContiguousContainer>
558 const ContiguousContainer &container)
559 requires(std::is_same_v<
560 std::remove_cv_t<ElementType>,
561 std::remove_cv_t<typename ContiguousContainer::value_type>> &&
562 std::is_const_v<ElementType> &&
570template <
typename ElementType,
typename MemorySpaceType>
571template <
typename ContiguousContainer>
573 ContiguousContainer &container)
574 requires(std::is_same_v<
575 std::remove_cv_t<ElementType>,
576 std::remove_cv_t<typename ContiguousContainer::value_type>> &&
585template <
typename ElementType,
typename MemorySpaceType>
586template <
typename ContiguousContainer,
typename,
typename,
typename>
588 const ContiguousContainer &container)
595template <
typename ElementType,
typename MemorySpaceType>
596template <
typename ContiguousContainer,
typename,
typename,
typename>
598 ContiguousContainer &container)
607template <
typename ElementType,
typename MemorySpaceType>
608template <std::
size_t N>
610 ElementType (&array)[N])
615template <
typename ElementType,
typename MemorySpaceType>
617 const std::initializer_list<std::remove_cv_t<value_type>> &initializer)
625template <
typename ElementType,
typename MemorySpaceType>
630 return (other_view.
data() == starting_element) &&
631 (other_view.
size() == n_elements);
636template <
typename ElementType,
typename MemorySpaceType>
639 const ArrayView<std::remove_cv_t<value_type>, MemorySpaceType> &other_view)
642 return (other_view.data() == starting_element) &&
643 (other_view.size() == n_elements);
648template <
typename ElementType,
typename MemorySpaceType>
653 return !(*
this == other_view);
658template <
typename ElementType,
typename MemorySpaceType>
666 return starting_element;
671template <
typename ElementType,
typename MemorySpaceType>
674 const ArrayView<std::remove_cv_t<value_type>, MemorySpaceType> &other_view)
677 return !(*
this == other_view);
682template <
typename ElementType,
typename MemorySpaceType>
691template <
typename ElementType,
typename MemorySpaceType>
695 return n_elements == 0;
700template <
typename ElementType,
typename MemorySpaceType>
704 return starting_element;
709template <
typename ElementType,
typename MemorySpaceType>
713 return starting_element + n_elements;
718template <
typename ElementType,
typename MemorySpaceType>
722 return starting_element;
727template <
typename ElementType,
typename MemorySpaceType>
731 return starting_element + n_elements;
736template <
typename ElementType,
typename MemorySpaceType>
742 return *(starting_element + i);
752template <
typename ElementType, std::
size_t str
ide = 1>
801 data() const noexcept;
816 operator[](const
std::
size_t i) const;
833template <typename ElementType,
std::
size_t stride>
839 return *(this->starting_element + stride * i);
844template <
typename ElementType, std::
size_t str
ide>
856template <
typename ElementType, std::
size_t str
ide>
865template <
typename ElementType, std::
size_t str
ide>
874template <
typename ElementType, std::
size_t str
ide>
887 namespace ArrayViewHelper
894 template <
class Iterator>
896 is_contiguous(
const Iterator &
first,
const Iterator &last)
898 const auto n = std::distance(
first, last);
899 for (std::decay_t<
decltype(n)> i = 0; i < n; ++i)
900 if (std::addressof(*(std::next(
first, i))) !=
901 std::next(std::addressof(*
first), i))
919 is_contiguous(T *, T *)
945template <
typename Iterator,
typename MemorySpaceType = MemorySpace::Host>
947 std::remove_reference_t<typename std::iterator_traits<Iterator>::reference>,
952 std::is_same_v<typename std::iterator_traits<Iterator>::iterator_category,
953 typename std::random_access_iterator_tag>
954#ifdef DEAL_II_HAVE_CXX20
956 std::is_same_v<typename std::iterator_traits<Iterator>::iterator_category,
957 typename std::contiguous_iterator_tag>
960 "The provided iterator needs to be a random access iterator.");
963 "The beginning of the array view needs to be before the end."));
964 Assert(internal::ArrayViewHelper::is_contiguous(begin, end),
965 ExcMessage(
"The provided range isn't contiguous in memory!"));
968 std::remove_reference_t<typename std::iterator_traits<Iterator>::reference>,
969 MemorySpaceType>(std::addressof(*begin), end - begin);
983template <
typename ElementType,
typename MemorySpaceType = MemorySpace::Host>
989 "The beginning of the array view needs to be before the end."));
1005template <
typename Number,
typename MemorySpaceType>
1024template <
typename Number,
typename MemorySpaceType>
1046template <
typename ElementType,
int N>
1069template <
typename ElementType>
1092template <
typename ElementType>
1115template <
typename ElementType>
1138template <
typename ElementType>
1166template <
typename ElementType>
1169 const std::size_t starting_index,
1170 const std::size_t size_of_view)
1172 Assert(starting_index + size_of_view <= vector.size(),
1173 ExcMessage(
"The starting index and size of the view you want to "
1174 "create would lead to a view that extends beyond the end "
1175 "of the given vector."));
1200template <
typename ElementType>
1203 const std::size_t starting_index,
1204 const std::size_t size_of_view)
1206 Assert(starting_index + size_of_view <= vector.size(),
1207 ExcMessage(
"The starting index and size of the view you want to "
1208 "create would lead to a view that extends beyond the end "
1209 "of the given vector."));
1222template <
typename ElementType>
1238template <
typename ElementType>
1254template <
typename ElementType>
1257 const std::size_t starting_index,
1258 const std::size_t size_of_view)
1260 Assert(starting_index + size_of_view <= vector.
size(),
1261 ExcMessage(
"The starting index and size of the view you want to "
1262 "create would lead to a view that extends beyond the end "
1263 "of the given vector."));
1276template <
typename ElementType>
1279 const std::size_t starting_index,
1280 const std::size_t size_of_view)
1282 Assert(starting_index + size_of_view <= vector.
size(),
1283 ExcMessage(
"The starting index and size of the view you want to "
1284 "create would lead to a view that extends beyond the end "
1285 "of the given vector."));
1305template <
typename ElementType, std::
size_t N>
1328template <
typename ElementType, std::
size_t N>
1353template <
typename ElementType>
1380template <
typename ElementType>
1405template <
typename ElementType>
1430template <
typename ElementType>
1455template <
typename ElementType>
1480template <
typename ElementType>
1510template <
typename ElementType>
1515 const std::size_t size_of_view)
1519 Assert(starting_column + size_of_view <= table.size()[1],
1520 ExcMessage(
"The starting index and size of the view you want to "
1521 "create would lead to a view that extends beyond the end "
1522 "of a column of the given table."));
1547template <
typename ElementType>
1552 const std::size_t size_of_view)
1556 Assert(starting_column + size_of_view <= table.size()[1],
1557 ExcMessage(
"The starting index and size of the view you want to "
1558 "create would lead to a view that extends beyond the end "
1559 "of a column of the given table."));
1576template <
typename Container>
auto make_const_array_view(const Container &container) -> decltype(make_array_view(container))
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
ArrayView(ContiguousContainer &container)
ArrayView< const ElementType > make_array_view(const Vector< ElementType > &vector)
ArrayView(value_type &element)
bool operator!=(const ArrayView< std::remove_cv_t< value_type >, MemorySpaceType > &other_view) const
ArrayView< Number, MemorySpaceType > make_array_view(ArrayView< Number, MemorySpaceType > &array_view)
ArrayView(const ArrayView< std::remove_cv_t< value_type >, MemorySpaceType > &view)
value_type & operator[](const std::size_t i) const
ArrayView< const ElementType > make_array_view(const LAPACKFullMatrix< ElementType > &matrix)
ArrayView< ElementType > make_array_view(std::array< ElementType, N > &array)
bool operator==(const ArrayView< std::remove_cv_t< value_type >, MemorySpaceType > &other_view) const
ArrayView< ElementType > make_array_view(LAPACKFullMatrix< ElementType > &matrix)
ArrayView< ElementType > make_array_view(ElementType(&array)[N])
ArrayView< ElementType, MemorySpaceType > make_array_view(ElementType *const begin, ElementType *const end)
const_iterator cend() const
ArrayView(const ContiguousContainer &container)
ArrayView< const ElementType > make_array_view(const std::vector< ElementType > &vector, const std::size_t starting_index, const std::size_t size_of_view)
ArrayView< const ElementType > make_array_view(const Table< 2, ElementType > &table)
ArrayView< const ElementType > make_array_view(const Table< 2, ElementType > &table, const typename Table< 2, ElementType >::size_type row, const typename Table< 2, ElementType >::size_type starting_column, const std::size_t size_of_view)
ArrayView< ElementType > make_array_view(std::vector< ElementType > &vector)
bool operator==(const ArrayView< const value_type, MemorySpaceType > &other_view) const
ArrayView< ElementType > make_array_view(std::vector< ElementType > &vector, const std::size_t starting_index, const std::size_t size_of_view)
bool operator!=(const ArrayView< const value_type, MemorySpaceType > &other_view) const
const_iterator cbegin() const
ArrayView(value_type(&array)[N])
value_type * data() const noexcept
ArrayView< ElementType > make_array_view(Table< 2, ElementType > &table, const typename Table< 2, ElementType >::size_type row, const typename Table< 2, ElementType >::size_type starting_column, const std::size_t size_of_view)
void reinit(value_type *starting_element, const std::size_t n_elements)
ArrayView< ElementType > make_array_view(Table< 2, ElementType > &table)
value_type * starting_element
ArrayView(const std::initializer_list< std::remove_cv_t< value_type > > &initializer_list)
ArrayView(value_type *starting_element, const std::size_t n_elements)
ArrayView< const Number, MemorySpaceType > make_array_view(const ArrayView< Number, MemorySpaceType > &array_view)
ArrayView< const ElementType > make_array_view(const Table< 2, ElementType > &table, const typename Table< 2, ElementType >::size_type row)
ArrayView< const ElementType > make_array_view(const AlignedVector< ElementType > &vector, const std::size_t starting_index, const std::size_t size_of_view)
ArrayView< const ElementType > make_array_view(const AlignedVector< ElementType > &vector)
const ElementType * const_iterator
ArrayView< ElementType > make_array_view(Vector< ElementType > &vector)
ArrayView< ElementType > make_array_view(Table< 2, ElementType > &table, const typename Table< 2, ElementType >::size_type row)
ArrayView< const ElementType > make_array_view(const std::vector< ElementType > &vector)
ArrayView< ElementType > make_array_view(AlignedVector< ElementType > &vector, const std::size_t starting_index, const std::size_t size_of_view)
ArrayView< const ElementType > make_array_view(const std::array< ElementType, N > &array)
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
ArrayView< ElementType > make_array_view(AlignedVector< ElementType > &vector)
StridedArrayView(value_type *starting_element, const std::size_t n_elements)
value_type * starting_element
value_type * data() const noexcept
virtual size_type size() const override
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< index_type > data
#define DEAL_II_HOST_DEVICE