array
C++ library for multi-dimensional arrays
Public Types | Public Member Functions | Static Public Member Functions | List of all members
array_ref< T, Shape > Class Template Reference

#include <array.h>

Public Types

using value_type = T
 
using reference = value_type &
 
using const_reference = const value_type &
 
using pointer = value_type *
 
using shape_type = Shape
 
using index_type = typename Shape::index_type
 
using shape_traits_type = shape_traits< Shape >
 
using size_type = size_t
 

Public Member Functions

NDARRAY_HOST_DEVICE array_ref (pointer base=nullptr, const Shape &shape=Shape())
 
NDARRAY_HOST_DEVICE array_ref (pointer base, const Shape &shape, internal::no_resolve)
 
NDARRAY_HOST_DEVICE array_ref (const array_ref &other)=default
 
NDARRAY_HOST_DEVICE array_ref (array_ref &&other)=default
 
NDARRAY_HOST_DEVICE array_refoperator= (const array_ref &other)=default
 
NDARRAY_HOST_DEVICE array_refoperator= (array_ref &&other)=default
 
template<class OtherShape , class = enable_if_shape_compatible<OtherShape>>
NDARRAY_HOST_DEVICE array_ref (const array_ref< T, OtherShape > &other)
 
template<class OtherShape , class = enable_if_shape_compatible<OtherShape>>
NDARRAY_HOST_DEVICE array_refoperator= (const array_ref< T, OtherShape > &other)
 
NDARRAY_HOST_DEVICE reference operator[] (const index_type &indices) const
 
template<class... Args, class = enable_if_all_indices<Args...>>
NDARRAY_HOST_DEVICE reference operator() (Args...indices) const
 
template<class... Args, class = enable_if_any_slices<Args...>>
NDARRAY_HOST_DEVICE auto operator[] (const std::tuple< Args... > &args) const
 
template<class... Args, class = enable_if_any_slices<Args...>>
NDARRAY_HOST_DEVICE auto operator() (Args...args) const
 
template<class Fn , class = internal::enable_if_callable<Fn, reference>>
NDARRAY_HOST_DEVICE void for_each_value (Fn &&fn) const
 
NDARRAY_HOST_DEVICE pointer base () const
 
NDARRAY_HOST_DEVICE pointer data () const
 
NDARRAY_HOST_DEVICE Shape & shape ()
 
NDARRAY_HOST_DEVICE const Shape & shape () const
 
template<size_t D, class = enable_if_dim<D>>
NDARRAY_HOST_DEVICE auto & dim ()
 
template<size_t D, class = enable_if_dim<D>>
NDARRAY_HOST_DEVICE const auto & dim () const
 
const nda::dim dim (size_t d) const
 
NDARRAY_HOST_DEVICE size_type size () const
 
NDARRAY_HOST_DEVICE bool empty () const
 
NDARRAY_HOST_DEVICE bool is_compact () const
 
NDARRAY_HOST_DEVICE auto & i ()
 
NDARRAY_HOST_DEVICE const auto & i () const
 
NDARRAY_HOST_DEVICE auto & j ()
 
NDARRAY_HOST_DEVICE const auto & j () const
 
NDARRAY_HOST_DEVICE auto & k ()
 
NDARRAY_HOST_DEVICE const auto & k () const
 
NDARRAY_HOST_DEVICE auto & x ()
 
NDARRAY_HOST_DEVICE const auto & x () const
 
NDARRAY_HOST_DEVICE auto & y ()
 
NDARRAY_HOST_DEVICE const auto & y () const
 
NDARRAY_HOST_DEVICE auto & z ()
 
NDARRAY_HOST_DEVICE const auto & z () const
 
NDARRAY_HOST_DEVICE auto & c ()
 
NDARRAY_HOST_DEVICE const auto & c () const
 
NDARRAY_HOST_DEVICE auto & w ()
 
NDARRAY_HOST_DEVICE const auto & w () const
 
NDARRAY_HOST_DEVICE index_t width () const
 
NDARRAY_HOST_DEVICE index_t height () const
 
NDARRAY_HOST_DEVICE index_t channels () const
 
NDARRAY_HOST_DEVICE index_t rows () const
 
NDARRAY_HOST_DEVICE index_t columns () const
 
NDARRAY_HOST_DEVICE bool operator!= (const array_ref &other) const
 
NDARRAY_HOST_DEVICE bool operator== (const array_ref &other) const
 
NDARRAY_HOST_DEVICE const array_ref< T, Shape > & ref () const
 
NDARRAY_HOST_DEVICE const const_array_ref< T, Shape > cref () const
 
NDARRAY_HOST_DEVICE operator const_array_ref< T, Shape > () const
 
template<std::size_t R = rank(), typename = std::enable_if_t<R == 0>>
NDARRAY_HOST_DEVICE operator reference () const
 
NDARRAY_HOST_DEVICE void set_shape (const Shape &new_shape, index_t offset=0)
 

Static Public Member Functions

static constexpr size_t rank ()
 
static constexpr bool is_scalar ()
 

Detailed Description

template<class T, class Shape>
class nda::array_ref< T, Shape >

A reference to an array is an object with a shape mapping indices to flat offsets, which are used to dereference a pointer. This object does not own any memory, and it is cheap to copy.

Member Typedef Documentation

using value_type = T

Type of elements referenced in this array_ref.

using shape_type = Shape

Type of the shape of this array_ref.

Constructor & Destructor Documentation

NDARRAY_HOST_DEVICE array_ref ( pointer  base = nullptr,
const Shape &  shape = Shape() 
)
inline

Make an array_ref to the given base pointer, interpreting it as having the shape shape.

NDARRAY_HOST_DEVICE array_ref ( const array_ref< T, Shape > &  other)
default

Shallow copy or assign an array_ref.

NDARRAY_HOST_DEVICE array_ref ( const array_ref< T, OtherShape > &  other)
inline

Shallow copy or assign an array_ref with a different shape type.

Member Function Documentation

static constexpr size_t rank ( )
inlinestatic

The number of dims in the shape of this array.

static constexpr bool is_scalar ( )
inlinestatic

True if the rank of this array is 0.

NDARRAY_HOST_DEVICE reference operator[] ( const index_type &  indices) const
inline

Get a reference to the element at indices.

NDARRAY_HOST_DEVICE auto operator[] ( const std::tuple< Args... > &  args) const
inline

Create an array_ref from this array_ref using indices or intervals args. Dimensions corresponding to indices in args are sliced, i.e. the result will not have this dimension. The rest of the dimensions are cropped.

NDARRAY_HOST_DEVICE void for_each_value ( Fn &&  fn) const
inline

Call a function with a reference to each value in this array_ref. The order in which fn is called is undefined, to enable optimized memory access patterns.

NDARRAY_HOST_DEVICE pointer base ( ) const
inline

Pointer to the element at the min index of the shape.

NDARRAY_HOST_DEVICE pointer data ( ) const
inline

Pointer to the element at the beginning of the flat array. This is equivalent to base() if all of the strides of the shape are positive.

NDARRAY_HOST_DEVICE Shape& shape ( )
inline

Shape of this array_ref.

NDARRAY_HOST_DEVICE auto& i ( )
inline

Provide some aliases for common interpretations of dimensions i, j, k as dimensions 0, 1, 2, respectively.

NDARRAY_HOST_DEVICE auto& x ( )
inline

Provide some aliases for common interpretations of dimensions x, y, z or c, w as dimensions 0, 1, 2, 3 respectively.

NDARRAY_HOST_DEVICE index_t width ( ) const
inline

Assuming this array represents an image with dimensions width, height, channels, get the extent of those dimensions.

NDARRAY_HOST_DEVICE index_t rows ( ) const
inline

Assuming this array represents a matrix with dimensions {rows, cols}, get the extent of those dimensions.

NDARRAY_HOST_DEVICE bool operator!= ( const array_ref< T, Shape > &  other) const
inline

Compare the contents of this array_ref to other. For two array_refs to be considered equal, they must have the same shape, and all elements addressable by the shape must also be equal.

NDARRAY_HOST_DEVICE const const_array_ref<T, Shape> cref ( ) const
inline

Allow conversion from array_ref<T> to const_array_ref<T>.

NDARRAY_HOST_DEVICE operator reference ( ) const
inline

Implicit conversion to T for scalar shaped array_refs.

NDARRAY_HOST_DEVICE void set_shape ( const Shape &  new_shape,
index_t  offset = 0 
)
inline

Change the shape of the array to new_shape, and move the base pointer by offset. The new shape must be a subset of the old shape.


The documentation for this class was generated from the following file: