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> {
209 template <
template <
class...>
class Container =
std::vector>
226 template <
template <
class...>
class Container =
std::vector>
247 template <
template <
class...>
class Container =
std::vector>
262 template <
typename Iterator>
275 template <
typename... Args>
361 template <
typename... D>
414 template <
typename... D>
415 T&
at(
size_t i, D... rest);
427 template <
typename... D>
428 const T&
at(
size_t i, D... rest)
const;
517 T
get(
size_t offset)
const {
518 return *
reinterpret_cast<T*
>(
m_data_ptr + offset);
523 return *
reinterpret_cast<T*
>(
m_data_ptr + offset);
527 virtual size_t size()
const = 0;
531 return size() *
sizeof(T);
541 template <
template <
class...>
class Container>
553 template <typename... Args>
562 template <
typename T2>
568 template <
typename T2>
570 ->
decltype((void)
std::declval<Container<T2>>().resize(
size_t{}),
void()) {
583 resizeImpl<T>(
shape);
588 return Euclid::make_unique<ContainerWrapper>(
m_container);
627 template <
typename... D>
628 T&
at_helper(
size_t offset_acc,
size_t axis,
size_t i, D... rest);
643 template <
typename... D>
644 const T&
at_helper(
size_t offset_acc,
size_t axis,
size_t i, D... rest)
const;
649 const T&
at_helper(
size_t offset_acc,
size_t axis)
const;
656 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
std::vector< std::string > m_attr_names
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)
Iterator< true > const_iterator
bool operator!=(const self_type &b) const
self_type rslice(size_t i)
std::shared_ptr< ContainerInterface > m_container
std::vector< size_t > m_shape
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)
std::vector< size_t > m_stride_size
NdArray(const self_type &)=default
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)
Iterator< false > iterator
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_)
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)
virtual ~NdArray()=default
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)
std::ostream & operator<<(std::ostream &out, const NdArray< T > &ndarray)
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
size_t nbytes() const
Get the size in bytes.
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
auto resizeImpl(const std::vector< size_t > &shape) -> decltype((void) std::declval< Container< T2 > >().resize(std::vector< size_t >{}), void())
ContainerWrapper(ContainerWrapper &&) noexcept=default
Container< T > m_container
ContainerWrapper(const ContainerWrapper &)=delete
~ContainerWrapper()=default
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())
size_t size() const final