16#ifndef dealii_array_view_h
17#define dealii_array_view_h
36template <
int N,
typename T>
39template <
typename number>
84template <
typename ElementType,
typename MemorySpaceType = MemorySpace::Host>
140 MemorySpaceType> &view);
163 const std::vector<
typename std::remove_cv<value_type>::type> &vector);
179 ArrayView(std::vector<
typename std::remove_cv<value_type>::type> &vector);
195 template <std::
size_t N>
206 template <std::
size_t N>
208 const std::array<
typename std::remove_cv<value_type>::type, N> &vector);
218 template <std::
size_t N>
219 ArrayView(std::array<
typename std::remove_cv<value_type>::type, N> &vector);
275 MemorySpaceType> &other_view)
const;
312 MemorySpaceType> &other_view)
const;
371 operator[](const
std::
size_t i) const;
385 friend class
ArrayView<const ElementType, MemorySpaceType>;
393template <typename ElementType, typename MemorySpaceType>
401template <
typename ElementType,
typename MemorySpaceType>
411template <
typename ElementType,
typename MemorySpaceType>
414 const std::size_t n_elements)
416 this->starting_element = starting_element;
417 this->n_elements = n_elements;
422template <
typename ElementType,
typename MemorySpaceType>
424 : starting_element(&element)
430template <
typename ElementType,
typename MemorySpaceType>
432 const ArrayView<
typename std::remove_cv<value_type>::type, MemorySpaceType>
434 : starting_element(view.starting_element)
435 , n_elements(view.n_elements)
440template <
typename ElementType,
typename MemorySpaceType>
442 const std::vector<
typename std::remove_cv<value_type>::type> &vector)
455 static_assert(std::is_const<value_type>::value ==
true,
456 "This constructor may only be called if the ArrayView "
457 "object has a const value_type. In other words, you can "
458 "only create an ArrayView to const values from a const "
464template <
typename ElementType,
typename MemorySpaceType>
466 std::vector<
typename std::remove_cv<value_type>::type> &vector)
473template <
typename ElementType,
typename MemorySpaceType>
474template <std::
size_t N>
476 const std::array<
typename std::remove_cv<value_type>::type, N> &vector)
489 static_assert(std::is_const<value_type>::value ==
true,
490 "This constructor may only be called if the ArrayView "
491 "object has a const value_type. In other words, you can "
492 "only create an ArrayView to const values from a const "
498template <
typename ElementType,
typename MemorySpaceType>
499template <std::
size_t N>
501 ElementType (&array)[N])
507template <
typename ElementType,
typename MemorySpaceType>
508template <std::
size_t N>
510 std::array<
typename std::remove_cv<value_type>::type, N> &vector)
517template <
typename ElementType,
typename MemorySpaceType>
522 return (other_view.
data() == starting_element) &&
523 (other_view.
size() == n_elements);
528template <
typename ElementType,
typename MemorySpaceType>
531 const ArrayView<
typename std::remove_cv<value_type>::type, MemorySpaceType>
534 return (other_view.data() == starting_element) &&
535 (other_view.size() == n_elements);
540template <
typename ElementType,
typename MemorySpaceType>
545 return !(*
this == other_view);
550template <
typename ElementType,
typename MemorySpaceType>
558 return starting_element;
563template <
typename ElementType,
typename MemorySpaceType>
566 const ArrayView<
typename std::remove_cv<value_type>::type, MemorySpaceType>
569 return !(*
this == other_view);
574template <
typename ElementType,
typename MemorySpaceType>
583template <
typename ElementType,
typename MemorySpaceType>
587 return n_elements == 0;
592template <
typename ElementType,
typename MemorySpaceType>
596 return starting_element;
601template <
typename ElementType,
typename MemorySpaceType>
605 return starting_element + n_elements;
610template <
typename ElementType,
typename MemorySpaceType>
614 return starting_element;
619template <
typename ElementType,
typename MemorySpaceType>
623 return starting_element + n_elements;
628template <
typename ElementType,
typename MemorySpaceType>
634 return *(starting_element + i);
642 namespace ArrayViewHelper
649 template <
class Iterator>
651 is_contiguous(
const Iterator &
first,
const Iterator &last)
653 const auto n = std::distance(
first, last);
654 for (
typename std::decay<
decltype(n)>::type i = 0; i < n; ++i)
655 if (std::addressof(*(std::next(
first, i))) !=
656 std::next(std::addressof(*
first), i))
674 is_contiguous(T *, T *)
700template <
typename Iterator,
typename MemorySpaceType = MemorySpace::Host>
702 typename std::iterator_traits<Iterator>::reference>::type,
707 std::is_same<typename std::iterator_traits<Iterator>::iterator_category,
708 typename std::random_access_iterator_tag>::value
709#ifdef DEAL_II_HAVE_CXX20
711 std::is_same<typename std::iterator_traits<Iterator>::iterator_category,
712 typename std::contiguous_iterator_tag>::value
715 "The provided iterator needs to be a random access iterator.");
718 "The beginning of the array view needs to be before the end."));
719 Assert(internal::ArrayViewHelper::is_contiguous(begin, end),
720 ExcMessage(
"The provided range isn't contiguous in memory!"));
722 return ArrayView<
typename std::remove_reference<
723 typename std::iterator_traits<Iterator>::reference>::type,
724 MemorySpaceType>(std::addressof(*begin), end - begin);
738template <
typename ElementType,
typename MemorySpaceType = MemorySpace::Host>
744 "The beginning of the array view needs to be before the end."));
760template <
typename Number,
typename MemorySpaceType>
779template <
typename Number,
typename MemorySpaceType>
809template <
int rank,
int dim,
typename Number>
839template <
int rank,
int dim,
typename Number>
869template <
int rank,
int dim,
typename Number>
900template <
int rank,
int dim,
typename Number>
922template <
typename ElementType,
int N>
944template <
typename ElementType>
967template <
typename ElementType>
990template <
typename ElementType>
1013template <
typename ElementType>
1041template <
typename ElementType>
1044 const std::size_t starting_index,
1045 const std::size_t size_of_view)
1047 Assert(starting_index + size_of_view <= vector.size(),
1048 ExcMessage(
"The starting index and size of the view you want to "
1049 "create would lead to a view that extends beyond the end "
1050 "of the given vector."));
1075template <
typename ElementType>
1078 const std::size_t starting_index,
1079 const std::size_t size_of_view)
1081 Assert(starting_index + size_of_view <= vector.size(),
1082 ExcMessage(
"The starting index and size of the view you want to "
1083 "create would lead to a view that extends beyond the end "
1084 "of the given vector."));
1097template <
typename ElementType>
1113template <
typename ElementType>
1129template <
typename ElementType>
1132 const std::size_t starting_index,
1133 const std::size_t size_of_view)
1135 Assert(starting_index + size_of_view <= vector.
size(),
1136 ExcMessage(
"The starting index and size of the view you want to "
1137 "create would lead to a view that extends beyond the end "
1138 "of the given vector."));
1151template <
typename ElementType>
1154 const std::size_t starting_index,
1155 const std::size_t size_of_view)
1157 Assert(starting_index + size_of_view <= vector.
size(),
1158 ExcMessage(
"The starting index and size of the view you want to "
1159 "create would lead to a view that extends beyond the end "
1160 "of the given vector."));
1180template <
typename ElementType, std::
size_t N>
1203template <
typename ElementType, std::
size_t N>
1228template <
typename ElementType>
1255template <
typename ElementType>
1280template <
typename ElementType>
1305template <
typename ElementType>
1330template <
typename ElementType>
1355template <
typename ElementType>
1385template <
typename ElementType>
1390 const std::size_t size_of_view)
1394 Assert(starting_column + size_of_view <= table.size()[1],
1395 ExcMessage(
"The starting index and size of the view you want to "
1396 "create would lead to a view that extends beyond the end "
1397 "of a column of the given table."));
1422template <
typename ElementType>
1427 const std::size_t size_of_view)
1431 Assert(starting_column + size_of_view <= table.size()[1],
1432 ExcMessage(
"The starting index and size of the view you want to "
1433 "create would lead to a view that extends beyond the end "
1434 "of a column of the given table."));
1451template <
typename Container>
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
auto make_const_array_view(const Container &container) -> decltype(make_array_view(container))
ArrayView< const ElementType > make_array_view(const Vector< ElementType > &vector)
ArrayView(value_type &element)
ArrayView(const ArrayView< typename std::remove_cv< value_type >::type, MemorySpaceType > &view)
ArrayView< Number, MemorySpaceType > make_array_view(ArrayView< Number, MemorySpaceType > &array_view)
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
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)
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)
bool operator!=(const ArrayView< typename std::remove_cv< value_type >::type, MemorySpaceType > &other_view) const
const_iterator cend() const
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(const std::array< typename std::remove_cv< value_type >::type, N > &vector)
ArrayView< ElementType > make_array_view(std::vector< ElementType > &vector)
ArrayView(std::vector< typename std::remove_cv< value_type >::type > &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(const std::vector< typename std::remove_cv< value_type >::type > &vector)
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
bool operator==(const ArrayView< typename std::remove_cv< value_type >::type, MemorySpaceType > &other_view) const
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< ElementType > make_array_view(AlignedVector< ElementType > &vector)
ArrayView(std::array< typename std::remove_cv< value_type >::type, N > &vector)
#define DEAL_II_DEPRECATED
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define DEAL_II_HOST_DEVICE