DOLFINx
0.1.0
DOLFINx C++ interface
|
12 #include <xtl/xspan.hpp>
19 template <
typename T,
class Allocator = std::allocator<T>>
25 using allocator_type = Allocator;
26 using size_type =
typename std::vector<T, Allocator>::size_type;
27 using reference =
typename std::vector<T, Allocator>::reference;
28 using const_reference =
typename std::vector<T, Allocator>::const_reference;
29 using pointer =
typename std::vector<T, Allocator>::pointer;
30 using iterator =
typename std::vector<T, Allocator>::iterator;
31 using const_iterator =
typename std::vector<T, Allocator>::const_iterator;
39 const Allocator& alloc = Allocator())
42 _storage = std::vector<T, Allocator>(
shape[0] *
shape[1], value, alloc);
50 array2d(size_type rows, size_type cols, value_type value = T(),
51 const Allocator& alloc = Allocator())
54 _storage = std::vector<T, Allocator>(
shape[0] *
shape[1], value, alloc);
59 template <
typename Vector>
61 :
shape(
shape), _storage(std::forward<Vector>(x))
68 constexpr
array2d(std::initializer_list<std::initializer_list<T>> list)
69 :
shape({list.size(), (*list.begin()).
size()})
72 for (std::initializer_list<T> l : list)
74 _storage.push_back(val);
99 return _storage[i *
shape[1] + j];
108 constexpr const_reference
operator()(size_type i, size_type j)
const
110 return _storage[i *
shape[1] + j];
116 constexpr xtl::span<value_type>
row(size_type i)
118 return xtl::span<value_type>(std::next(_storage.data(), i *
shape[1]),
125 constexpr xtl::span<const value_type>
row(size_type i)
const
127 return xtl::span<const value_type>(std::next(_storage.data(), i *
shape[1]),
133 constexpr value_type*
data() noexcept {
return _storage.data(); }
138 constexpr
const value_type*
data() const noexcept {
return _storage.data(); };
144 constexpr size_type
size() const noexcept {
return _storage.size(); }
147 constexpr std::array<size_type, 2>
strides() const noexcept
149 return {
shape[1] *
sizeof(T),
sizeof(T)};
154 constexpr
bool empty() const noexcept {
return _storage.empty(); }
160 std::vector<T, Allocator> _storage;
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition: array2d.h:154
constexpr xtl::span< const value_type > row(size_type i) const
Access a row in the array (const version)
Definition: array2d.h:125
array2d(size_type rows, size_type cols, value_type value=T(), const Allocator &alloc=Allocator())
Construct a two dimensional array.
Definition: array2d.h:50
~array2d()=default
Destructor.
constexpr size_type size() const noexcept
Returns the number of elements in the array.
Definition: array2d.h:144
constexpr const value_type * data() const noexcept
Get pointer to the first element of the underlying storage (const version)
Definition: array2d.h:138
array2d(std::array< size_type, 2 > shape, Vector &&x)
Definition: array2d.h:60
array2d & operator=(const array2d &x)=default
Copy assignment.
constexpr array2d(std::initializer_list< std::initializer_list< T >> list)
Construct a two dimensional array using nested initializer lists.
Definition: array2d.h:68
constexpr reference operator()(size_type i, size_type j)
Return a reference to the element at specified location (i, j)
Definition: array2d.h:97
array2d(std::array< size_type, 2 > shape, value_type value=T(), const Allocator &alloc=Allocator())
Construct a two dimensional array.
Definition: array2d.h:38
This class provides a dynamic 2-dimensional row-wise array data structure.
Definition: array2d.h:20
constexpr const_reference operator()(size_type i, size_type j) const
Return a reference to the element at specified location (i, j) (const version)
Definition: array2d.h:108
std::array< size_type, 2 > shape
The shape of the array.
Definition: array2d.h:157
constexpr xtl::span< value_type > row(size_type i)
Access a row in the array.
Definition: array2d.h:116
constexpr std::array< size_type, 2 > strides() const noexcept
Returns the strides of the array.
Definition: array2d.h:147
constexpr value_type * data() noexcept
Get pointer to the first element of the underlying storage.
Definition: array2d.h:133