6 #ifndef ECHELON_MULTI_ARRAY_HPP 7 #define ECHELON_MULTI_ARRAY_HPP 9 #include <echelon/range.hpp> 11 #include <echelon/detail/map_indices.hpp> 12 #include <echelon/detail/all_integral.hpp> 18 #include <type_traits> 44 explicit multi_array(
const std::vector<std::size_t>& shape_,
const T& value_ = T())
45 : data_(std::accumulate(std::
begin(shape_), std::
end(shape_), std::size_t(1),
46 std::multiplies<std::size_t>()),
65 template <
typename... Indices,
typename Enabler =
typename std::enable_if<
66 detail::all_integral<Indices...>::value>
::type>
69 return data_[detail::map_indices(shape_, indices...)];
86 template <
typename... Indices,
typename Enabler =
typename std::enable_if<
87 detail::all_integral<Indices...>::value>
::type>
90 return data_[detail::map_indices(shape_, indices...)];
101 template <
typename... Args,
typename Enabler =
typename std::enable_if<
102 !detail::all_integral<Args...>::value>
::type>
105 return echelon::make_slice(*
this, std::forward<Args>(args)...);
132 typename std::vector<T>::iterator
begin()
134 return data_.begin();
143 typename std::vector<T>::iterator
end()
154 typename std::vector<T>::const_iterator
begin()
const 156 return data_.begin();
165 typename std::vector<T>::const_iterator
end()
const 172 const std::vector<std::size_t>&
shape()
const 181 void reshape(
const std::vector<std::size_t>& new_shape)
183 data_.resize(std::accumulate(std::begin(new_shape), std::end(new_shape), std::size_t(1),
184 std::multiplies<std::size_t>()));
186 this->shape_ = new_shape;
190 std::vector<T> data_;
191 std::vector<std::size_t> shape_;
echelon's core namespace
Definition: attribute.cpp:10
T & operator()(Indices...indices)
Accesses a specified element.
Definition: multi_array.hpp:88
std::vector< T >::iterator end()
Returns an iterator, which points to the last element of the flattened array.
Definition: multi_array.hpp:143
A handle to an HDF5 type.
Definition: type.hpp:21
T * data()
Direct access to the underlying array.
Definition: multi_array.hpp:121
T value_type
value type of the array
Definition: multi_array.hpp:32
echelon::hdf5::array_slice< T > operator()(Args...args)
Slice the array.
Definition: multi_array.hpp:103
multi_array()=default
Creates an empty array.
const std::vector< std::size_t > & shape() const
The shape of the array.
Definition: multi_array.hpp:172
void reshape(const std::vector< std::size_t > &new_shape)
Reshapes the array.
Definition: multi_array.hpp:181
const T & operator()(Indices...indices) const
Accesses a specified element.
Definition: multi_array.hpp:67
std::vector< T >::const_iterator begin() const
Returns an iterator, which points to the first element of the flattened array.
Definition: multi_array.hpp:154
Multidimensional array with runtime rank and shape.
Definition: multi_array.hpp:28
multi_array(const std::vector< std::size_t > &shape_, const T &value_=T())
Creates an array with a given shape.
Definition: multi_array.hpp:44
const T * data() const
Direct access to the underlying array.
Definition: multi_array.hpp:112
std::vector< T >::iterator begin()
Returns an iterator, which points to the first element of the flattened array.
Definition: multi_array.hpp:132
std::vector< T >::const_iterator end() const
Returns an iterator, which points to the last element of the flattened array.
Definition: multi_array.hpp:165