Mapping between coordinates, indices, and addresses of multi-dimensional data.
More...
|
| bool | has_default_strides (std::size_t minimal_dimension=0) const noexcept |
| | Check if view has default strides. More...
|
| |
| std::size_t | default_strides_padding (std::size_t minimal_dimension=0) const |
| | Returns padding of the view which has default strides. More...
|
| |
| | ndarray_view () |
| | Create null view. More...
|
| |
| | ndarray_view (pointer start, const shape_type &, const strides_type &) |
| | Create view with explicitly specified start, shape and strides. More...
|
| |
| | ndarray_view (pointer start, const shape_type &shape) |
| | Create view with explicitly specified start and shape, with default strides (without padding). More...
|
| |
| | ndarray_view (const ndarray_view< Dim, std::remove_const_t< T >> &arr) |
| | Copy-construct view. More...
|
| |
| bool | is_null () const noexcept |
| |
| | operator bool () const noexcept |
| |
| void | reset (const ndarray_view &other) noexcept |
| |
| void | reset () noexcept |
| |
| void | reset (pointer start, const shape_type &shape, const strides_type &strides) |
| |
| void | reset (pointer start, const shape_type &shape) |
| |
| template<typename Arg > |
| const ndarray_view & | operator= (Arg &&arg) const |
| |
| const ndarray_view & | operator= (const ndarray_view &other) const |
| |
| coordinates_type | index_to_coordinates (const index_type &) const |
| |
| index_type | coordinates_to_index (const coordinates_type &) const |
| |
| pointer | coordinates_to_pointer (const coordinates_type &) const |
| |
| ndarray_view | section (const coordinates_type &start, const coordinates_type &end, const strides_type &steps=strides_type(1)) const |
| | Cuboid section of view, with interval in each axis. More...
|
| |
| ndarray_view | section (const span_type &span, const strides_type &steps=strides_type(1)) const |
| | Cuboid section of view, defined using ndspan object. More...
|
| |
| ndarray_view< Dim-1, T > | slice (std::ptrdiff_t c, std::ptrdiff_t dimension) const |
| | Create ndarray_view with one less dimension, by fixing coordinate of axis dimension to c. More...
|
| |
| decltype(auto) | operator[] (std::ptrdiff_t c) const |
| | Subscript operator, creates slice on first dimension. More...
|
| |
| fcall_result | operator() (std::ptrdiff_t start, std::ptrdiff_t end, std::ptrdiff_t step=1) const |
| |
| fcall_result | operator() (std::ptrdiff_t c) const |
| |
| fcall_result | operator() () const |
| |
| reference | at (const coordinates_type &) const |
| |
| iterator | begin () const |
| |
| iterator | end () const |
| |
| template<typename T2 > |
| void | assign (const ndarray_view< Dim, T2 > &) const |
| |
| void | assign (const ndarray_view< Dim, const T > &other) const |
| |
| template<typename T2 > |
| bool | compare (const ndarray_view< Dim, T2 > &) const |
| |
| bool | compare (const ndarray_view< Dim, const T > &other) const |
| |
| template<typename Arg > |
| bool | operator== (Arg &&arg) const |
| |
| template<typename Arg > |
| bool | operator!= (Arg &&arg) const |
| |
| std::size_t | size () const |
| |
| pointer | start () const noexcept |
| |
| const shape_type & | shape () const noexcept |
| |
| const strides_type & | strides () const noexcept |
| |
| std::ptrdiff_t | contiguous_length () const noexcept |
| |
| span_type | full_span () const noexcept |
| |
| template<std::size_t New_dim> |
| ndarray_view< New_dim, T > | reshape (const ndsize< New_dim > &) const |
| |
| ndarray_view< 1+Dim, T > | add_front_axis () const |
| |
| ndarray_view | swapaxis (std::size_t axis1, std::size_t axis2) const |
| |
template<std::size_t Dim, typename T>
class mf::ndarray_view< Dim, T >
Mapping between coordinates, indices, and addresses of multi-dimensional data.
Templated for dimension and element type. T must be elem type, i.e. elem_traits<T> must be defined. The ndarray_view is defined by the three values (start, shape, strides).
start is the pointer to the array element at indices (0, 0, ..., 0).
shape is the vector of size Dim which defined length of array in each axis.
strides defined memory layout of elements: strides[i] defined distance in bytes between arr[][k][] and arr[][k+1][] (the i-th coordinate changes). ndarray_view is non-owning view to data. T can be a const type. Always gives full access to elements, no matter if this const. Subscript operator operator[] and functions section(), etc., return another ndarray_view to given region.
Stride values may be negative to form reverse-order view on that axis (then start is no longer the element with lowest absolute address.) If strides are in non-descending order, coordinates to address mapping is no longer row-major. Strides need to be set to at least sizeof(T) and multiple of alignof(T). Default strides produce row-major mapping, optionally with padding between elements. The term default strides is still used here if there is inter-element padding. Coordinates map to address, but not the other way.
Coordinates map one-to-one to index, and index to coordinates. Index always advances in row-major order with coordinates, independently of strides. Index of coordinates (0, 0, ..., 0) is 0. Random-access iterator ndarray_iterator always traverses ndarray in index order. As an optimization, iterator incrementation and decrementation is more efficient when all strides, or tail of strides, is default.
Important: Assignment and comparison operators perform deep assignment/comparison in the elements that the view points to, and not of the ndarray_view itself. Shallow assignment and comparison is done with same() and reset(). This simplifies interface: assigning a single element arr[0][2] = 3 works the same as assigning an entire region arr[0] = make_frame(...). (Because operator[] returns an ndarray_view.) Copy-constructing a view does not copy data. Semantics are similar to C++ references.
Default constructor, or null() returns null view. All null views compare equal (with same()), and is_null() or explicit bool conversion operator test for null view. Zero-length views (where shape().product() == 0) are possible, and are not equal to null views.