25#ifndef ALEXANDRIA_NDARRAY_H
26#define ALEXANDRIA_NDARRAY_H
50 template <
template <
class...>
class Container =
std::vector>
63 :
public std::iterator<std::random_access_iterator_tag, typename std::conditional<Const, const T, T>::type> {
211 template <
template <
class...>
class Container =
std::vector>
228 template <
template <
class...>
class Container =
std::vector>
249 template <
template <
class...>
class Container =
std::vector>
264 template <
typename Iterator>
277 template <
typename... Args>
363 template <
typename... D>
421 template <
typename... D>
422 T&
at(
size_t i, D... rest);
434 template <
typename... D>
435 const T&
at(
size_t i, D... rest)
const;
519 T
get(
size_t offset)
const {
520 return *
reinterpret_cast<T*
>(
m_data_ptr + offset);
525 return *
reinterpret_cast<T*
>(
m_data_ptr + offset);
529 virtual size_t size()
const = 0;
541 template <
template <
class...>
class Container>
553 template <
typename... Args>
562 template <
typename T2>
567 template <
typename T2>
573 return nbytesImpl<T>(0);
576 template <
typename T2>
582 template <
typename T2>
584 ->
decltype((void)
std::declval<Container<T2>>().resize(
size_t{}),
void()) {
597 resizeImpl<T>(
shape);
602 return Euclid::make_unique<ContainerWrapper>(
m_container);
654 template <
typename... D>
655 T&
at_helper(
size_t offset_acc,
size_t axis,
size_t i, D... rest);
670 template <
typename... D>
671 const T&
at_helper(
size_t offset_acc,
size_t axis,
size_t i, D... rest)
const;
676 const T&
at_helper(
size_t offset_acc,
size_t axis)
const;
683 template <
typename... D>
Iterator & operator-=(size_t n)
Iterator(ContainerInterface *container_ptr, size_t offset, size_t row_size, size_t stride, size_t start)
const Iterator operator++(int)
Iterator operator+(size_t n) const
Iterator & operator+=(size_t n)
bool operator!=(const Iterator &other) const
typename std::conditional< Const, const T, T >::type value_t
bool operator>(const Iterator &other)
bool operator<(const Iterator &other)
Iterator(ContainerInterface *container_ptr, size_t offset, const std::vector< size_t > &shape, const std::vector< size_t > &strides, size_t start)
ContainerInterface * m_container_ptr
Iterator operator-(size_t n) const
bool operator==(const Iterator &other) const
value_t operator*() const
Iterator(const Iterator< false > &other)
value_t & operator[](size_t i)
value_t operator[](size_t i) const
difference_type operator-(const Iterator &other)
const T & at_helper(size_t offset_acc, size_t axis, size_t i, D... rest) const
const T & at(const std::vector< size_t > &coords) const
const T & at_helper(size_t offset_acc, size_t axis) const
size_t get_offset(const std::vector< size_t > &coords) const
size_t shape(std::size_t i) const
const T & at(const std::vector< size_t > &coords, const std::string &attr) const
T & at(const std::vector< size_t > &coords, const std::string &attr)
self_type & reshape(const std::vector< size_t > &new_shape)
self_type & reshape_helper(std::vector< size_t > &acc)
NdArray(const std::vector< size_t > &shape_, const std::vector< std::string > &attr_names, Args &&... args)
const std::vector< size_t > & shape() const
NdArray(const self_type *other)
self_type slice(size_t i)
NdArray(std::vector< size_t > shape_, std::vector< size_t > strides_, Container< T > &&data)
bool operator!=(const self_type &b) const
self_type rslice(size_t i)
T & at_helper(size_t offset_acc, size_t axis, const std::string &attr)
NdArray(std::vector< size_t > shape_, const Container< T > &data)
std::size_t strides(std::size_t i) const
NdArray(const std::initializer_list< size_t > &shape_)
const_iterator begin() const
T & at_helper(size_t offset_acc, size_t axis, size_t i, D... rest)
const std::vector< std::string > & attributes() const
const self_type rslice(size_t i) const
NdArray(self_type &&) noexcept=default
NdArray(std::vector< size_t > shape_, Container< T > &&data)
self_type & reshape(size_t i, D... rest)
const T & at(size_t i, D... rest) const
self_type & concatenate(const self_type &other)
size_t get_attr_offset(const std::string &attr) const
T & at_helper(size_t offset_acc, size_t axis)
bool operator==(const self_type &b) const
const std::vector< std::size_t > & strides() const
self_type & reshape_helper(std::vector< size_t > &acc, size_t i, D... rest)
NdArray(std::vector< size_t > shape_)
std::unique_ptr< Details > m_details_ptr
NdArray(std::vector< size_t > shape_, Iterator begin, Iterator end)
T & at(const std::vector< size_t > &coords)
const T & at_helper(size_t offset_acc, size_t axis, const std::string &attr) const
const_iterator end() const
T & at(size_t i, D... rest)
NdArray(const self_type &)
const self_type slice(size_t i) const
NdArray(std::shared_ptr< ContainerInterface > container, size_t offset, std::vector< size_t > shape, std::vector< size_t > stride, std::vector< std::string > attr_names)
T & get(size_t offset)
Get a reference to the element at the given absolute offset (in bytes)
virtual std::unique_ptr< ContainerInterface > copy() const =0
Expected to generate a deep copy of the underlying data.
virtual ~ContainerInterface()=default
T get(size_t offset) const
Get the element at the given absolute offset (in bytes)
virtual void resize(const std::vector< size_t > &shape)=0
Resize container.
virtual size_t size() const =0
virtual size_t nbytes() const =0
Get the size in bytes.
auto resizeImpl(const std::vector< size_t > &shape) -> decltype((void) std::declval< Container< T2 > >().resize(std::vector< size_t >{}), void())
size_t nbytesImpl(...) const
Container< T > m_container
ContainerWrapper(const ContainerWrapper &)=delete
~ContainerWrapper()=default
auto nbytesImpl(int) const -> decltype(std::declval< Container< T2 > >().nbytes())
void resize(const std::vector< size_t > &shape) final
std::unique_ptr< ContainerInterface > copy() const final
Expected to generate a deep copy of the underlying data.
auto resizeImpl(const std::vector< size_t > &shape) -> decltype((void) std::declval< Container< T2 > >().resize(size_t{}), void())
ContainerWrapper(ContainerWrapper &&)=default
size_t size() const final
size_t nbytes() const final
Get the size in bytes.
ContainerWrapper(Args &&... args)
std::vector< std::string > m_attr_names
std::shared_ptr< ContainerInterface > m_container
std::vector< size_t > m_shape
std::vector< size_t > m_stride_size