25 #ifndef ALEXANDRIA_NDARRAY_H 26 #define ALEXANDRIA_NDARRAY_H 44 template<
typename T,
template<
class...>
class Container =
std::vector>
47 typedef typename Container<T>::iterator
iterator;
117 template <
typename Iterator>
171 throw std::range_error(
"New shape does not match the number of contained elements");
188 template <
typename ...D>
228 template <
typename ...D>
229 T &
at(
size_t i, D... rest) {
244 template <
typename ...D>
245 const T &
at(
size_t i, D... rest)
const {
285 const Container<T>&
data()
const {
327 for (
size_t i = 0; i < coords.
size(); ++i) {
356 template <
typename ...D>
372 template <
typename ...D>
385 template <
typename ...D>
399 template<
typename T,
template<
class...>
class Container>
402 auto shape = ndarray.shape();
404 if (ndarray.size()) {
406 for (i = 0; i < shape.size() - 1; ++i) {
407 out << shape[i] <<
",";
409 out << shape[i] <<
">";
410 for (i = 0; i < ndarray.size() - 1; ++i) {
411 out << ndarray.data()[i] <<
",";
413 out << ndarray.data()[i];
421 #endif // ALEXANDRIA_NDARRAY_H T & at_helper(std::vector< size_t > &acc)
bool operator!=(const self_type &b) const
const T & at(size_t i, D... rest) const
self_type & reshape_helper(std::vector< size_t > &acc)
Container< T > m_container
const T & at_helper(std::vector< size_t > &acc) const
NdArray(const std::vector< size_t > &shape, Iterator begin, Iterator end)
self_type & reshape_helper(std::vector< size_t > &acc, size_t i, D... rest)
T & at(const std::vector< size_t > &coords)
T & at_helper(std::vector< size_t > &acc, size_t i, D... rest)
NdArray & operator=(const NdArray &)=default
std::vector< size_t > m_stride_size
T & at(size_t i, D... rest)
const Container< T > & data() const
NdArray(const std::vector< size_t > &shape)
const std::vector< size_t > shape() const
std::vector< size_t > m_shape
NdArray(const std::vector< size_t > &shape, Container< T > &&data)
const T & at(const std::vector< size_t > &coords) const
std::ostream & operator<<(std::ostream &out, const NdArray< T, Container > &ndarray)
NdArray(const std::vector< size_t > &shape, const Container< T > &data)
const T & at_helper(std::vector< size_t > &acc, size_t i, D... rest) const
size_t get_offset(const std::vector< size_t > &coords) const
virtual ~NdArray()=default
bool operator==(const self_type &b) const
const_iterator end() const
NdArray< T, Container > self_type
self_type & reshape(const std::vector< size_t > new_shape)
Container< T >::iterator iterator
Container< T >::const_iterator const_iterator
const_iterator begin() const
NdArray(const std::initializer_list< size_t > &shape)
self_type & reshape(size_t i, D... rest)