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> &&
565 ArrayView(container.data(), container.size())
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)
590 ArrayView(container.data(), container.size())
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)
620 ArrayView(initializer.begin(), initializer.size())
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>
1054template <
int rank,
int dim,
typename Number>
1058 static_assert(rank == 1,
1059 "This function is only available for rank-1 tensors "
1060 "because higher-rank tensors may not store their elements "
1061 "in a contiguous array.");
1089template <
int rank,
int dim,
typename Number>
1093 static_assert(rank == 1,
1094 "This function is only available for rank-1 tensors "
1095 "because higher-rank tensors may not store their elements "
1096 "in a contiguous array.");
1124template <
int rank,
int dim,
typename Number>
1155template <
int rank,
int dim,
typename Number>
1177template <
typename ElementType,
int N>
1200template <
typename ElementType>
1223template <
typename ElementType>
1246template <
typename ElementType>
1269template <
typename ElementType>
1297template <
typename ElementType>
1300 const std::size_t starting_index,
1301 const std::size_t size_of_view)
1303 Assert(starting_index + size_of_view <= vector.size(),
1304 ExcMessage(
"The starting index and size of the view you want to "
1305 "create would lead to a view that extends beyond the end "
1306 "of the given vector."));
1331template <
typename ElementType>
1334 const std::size_t starting_index,
1335 const std::size_t size_of_view)
1337 Assert(starting_index + size_of_view <= vector.size(),
1338 ExcMessage(
"The starting index and size of the view you want to "
1339 "create would lead to a view that extends beyond the end "
1340 "of the given vector."));
1353template <
typename ElementType>
1369template <
typename ElementType>
1385template <
typename ElementType>
1388 const std::size_t starting_index,
1389 const std::size_t size_of_view)
1391 Assert(starting_index + size_of_view <= vector.
size(),
1392 ExcMessage(
"The starting index and size of the view you want to "
1393 "create would lead to a view that extends beyond the end "
1394 "of the given vector."));
1407template <
typename ElementType>
1410 const std::size_t starting_index,
1411 const std::size_t size_of_view)
1413 Assert(starting_index + size_of_view <= vector.
size(),
1414 ExcMessage(
"The starting index and size of the view you want to "
1415 "create would lead to a view that extends beyond the end "
1416 "of the given vector."));
1436template <
typename ElementType, std::
size_t N>
1459template <
typename ElementType, std::
size_t N>
1484template <
typename ElementType>
1511template <
typename ElementType>
1536template <
typename ElementType>
1561template <
typename ElementType>
1586template <
typename ElementType>
1611template <
typename ElementType>
1641template <
typename ElementType>
1646 const std::size_t size_of_view)
1650 Assert(starting_column + size_of_view <= table.size()[1],
1651 ExcMessage(
"The starting index and size of the view you want to "
1652 "create would lead to a view that extends beyond the end "
1653 "of a column of the given table."));
1678template <
typename ElementType>
1683 const std::size_t size_of_view)
1687 Assert(starting_column + size_of_view <= table.size()[1],
1688 ExcMessage(
"The starting index and size of the view you want to "
1689 "create would lead to a view that extends beyond the end "
1690 "of a column of the given table."));
1707template <
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)
ArrayView< Number > make_array_view(SymmetricTensor< rank, dim, Number > &tensor)
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)
ArrayView< const Number > make_array_view(const Tensor< rank, dim, Number > &tensor)
bool operator==(const ArrayView< std::remove_cv_t< value_type >, MemorySpaceType > &other_view) const
ArrayView< const Number > make_array_view(const SymmetricTensor< rank, dim, Number > &tensor)
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])
ArrayView< Number > make_array_view(Tensor< rank, dim, Number > &tensor)
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_DEPRECATED
#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)
#define DEAL_II_HOST_DEVICE