Template Class NDArray
Defined in File ndarray.h
Nested Relationships
Nested Types
Class Documentation
-
template<typename T, int D>
class NDArray Public Functions
-
inline NDArray() noexcept
Creates an empty array.
This constructor creates an empty array and initializes the reference count to one.
- Throws:
std::bad_alloc – if memory allocation fails.
-
inline explicit NDArray(const std::array<int, D> &dims)
Creates an array with the specified number of elements in each dimension, from an array.
This constructor creates an array with the specified size.
- Parameters:
dims –
std::array
list of the number of elements in each dimension.- Throws:
std::bad_alloc – if memory allocation fails.
-
inline explicit NDArray(const std::array<int, D> &dims, T value)
Creates an array with the specified number of elements in each dimension, from an array and initializes the array.
This constructor creates an array with the specified size.
- Parameters:
dims –
std::array
list of the number of elements in each dimension.value – Initial element value.
- Throws:
std::bad_alloc – if memory allocation fails.
-
template<typename U>
inline NDArray(const std::initializer_list<U> &dims) Creates an array with the specified number of elements in each dimension, from an initializer-list.
This constructor creates an array with the specified size.
- Parameters:
dims –
std::vector
list of the number of elements in each dimension.- Throws:
std::bad_alloc – if memory allocation fails.
-
template<typename U>
inline explicit NDArray(const std::array<U, D> &dims, T value) Creates an array with the specified number of elements in each dimension, from an array. Each entry in the array is assigned the designated value.
This constructor creates an array with the specified size.
- Parameters:
dims –
std::array
list of the number of elements in each dimension.value – The value to assing to each element.
- Throws:
std::bad_alloc – if memory allocation fails.
-
template<typename U>
inline explicit NDArray(const std::array<U, D> &dims) Creates an array with the specified number of elements in each dimension, from an array. Each entry in the array is assigned the designated value.
This constructor creates an array with the specified size.
- Parameters:
dims –
std::array
list of the number of elements in each dimension.value – The value to assing to each element.
- Throws:
std::bad_alloc – if memory allocation fails.
-
template<typename U>
inline NDArray(const std::initializer_list<U> &dims, T value) Creates an array with the specified number of elements in each dimension, from an initializer-list. Each entry in the array is assigned the designated value.
- Parameters:
dims –
std::initializer
list of the number of elements in each dimension.value – The value to assing to each element.
-
inline NDArray<T, D> &operator=(NDArray<T, D> const &other)
Assign from another array.
- Parameters:
other – The array to copy.
-
template<typename U>
inline void resize(const std::array<U, D> &dims) Resizes the array with a vector.
This method resizes the array to the specified number of elements. If the current size is equal to the new size, no memory allocation occurs.
- Parameters:
dims – std::vector of the number of elements in each dimension.
- Throws:
std::bad_alloc – if memory allocation fails.
-
template<typename U, size_t N>
inline void resize(const std::array<U, N> &dims) Resizes the array with an array.
This method resizes the array to the specified number of elements. If the current size is equal to the new size, no memory allocation occurs.
- Parameters:
dims – std::array of the number of elements in each dimension.
- Throws:
std::bad_alloc – if memory allocation fails.
-
template<typename U>
inline void resize(const std::initializer_list<U> &dims) Resizes the array with an initializer_list.
This method resizes the array to the specified number of elements. If the current size is equal to the new size, no memory allocation occurs.
- Parameters:
dims – std::initializer_list of the number of elements in each dimension.
- Throws:
std::bad_alloc – if memory allocation fails.
- template<typename... Args> inline __attribute__ ((always_inline)) const expr T &operator()(Args... args) noexcept
Accesses the specified element for an array with N dimensions.
- Parameters:
args – Indices for each dimension.
- Returns:
Read/write reference to the element.
- inline __attribute__ ((always_inline)) const expr T &operator()(size_t idx) noexcept
- __attribute__ ((always_inline)) const expr T &operator()(size_t i
-
template<typename ...Args>
inline T &at(Args... args) Accesses the specified element for an array with N dimensions with bounds checking.
- Parameters:
args – Indices for each dimension.
- Returns:
Read/write reference to the element.
- template<typename... Args> inline __attribute__ ((always_inline)) const expr const T &operator()(Args... args) const noexcept
Accesses the specified element for an array with N dimensions.
- Parameters:
args – Indices for each dimension.
- Returns:
Read reference to the element.
- inline __attribute__ ((always_inline)) const expr T const &operator()(size_t idx) const noexcept
- __attribute__ ((always_inline)) const expr T const &operator()(size_t i
-
template<typename ...Args>
inline const T &at(Args... args) const Accesses the specified element for an array with N dimensions with bounds checking.
- Parameters:
args – Indices for each dimension.
- Returns:
Read reference to the element.
-
inline const T *cbegin() const noexcept
Returns a constant iterator pointing to the beginning of the array.
-
inline const T *cend() const noexcept
Returns a constant iterator pointing to the end of the array.
-
inline size_t size() const noexcept
Returns the number of elements in the array.
-
inline bool empty() const noexcept
Returns true if the array has no elements.
-
inline size_t rank() const noexcept
Returns the rank of the array.
-
inline std::vector<size_t> dimension() const
Returns the dimension of the array.
-
template<typename ...Args>
inline size_t MapNDtoLin(Args... args) const Returns a linear index to the specified element with safety checks.
- Parameters:
args – The indices of the desired element.
- Throws:
std::invalid_argument – if the number of arguments are incorrect and std::out_of_range if one of the dimension-indices are out of range.
- Returns:
Linear index to the specified element.
Public Members
- size_t j noexcept {static_assert(D == 2, "Can be only used on 2-dimensional arrays")
- return storage_ [i *strides_[0]+j]
- size_t j const noexcept {static_assert(D == 2, "Can be only used on 2-dimensional arrays")
-
inline NDArray() noexcept