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

#include <array.h>

Public Types

using dims_type = std::tuple< Dims... >
 
using index_type = index_of_rank< rank()>
 
using size_type = size_t
 
using dim_indices = decltype(internal::make_index_sequence< std::tuple_size< dims_type >::value >())
 

Public Member Functions

template<size_t N = sizeof...(Dims), class = std::enable_if_t<(N > 0>
NDARRAY_HOST_DEVICE shape (const Dims &...dims)
 
NDARRAY_HOST_DEVICE shape (const shape &)=default
 
NDARRAY_HOST_DEVICE shape (shape &&)=default
 
NDARRAY_HOST_DEVICE shapeoperator= (const shape &)=default
 
NDARRAY_HOST_DEVICE shapeoperator= (shape &&)=default
 
template<class... OtherDims, class = enable_if_dims_compatible<OtherDims...>>
NDARRAY_HOST_DEVICE shape (const std::tuple< OtherDims... > &other)
 
template<class... OtherDims, class = enable_if_dims_compatible<OtherDims...>>
NDARRAY_HOST_DEVICE shape (OtherDims...other_dims)
 
template<class... OtherDims, class = enable_if_dims_compatible<OtherDims...>>
NDARRAY_HOST_DEVICE shape (const shape< OtherDims... > &other)
 
template<class... OtherDims, class = enable_if_dims_compatible<OtherDims...>>
NDARRAY_HOST_DEVICE shapeoperator= (const shape< OtherDims... > &other)
 
NDARRAY_HOST_DEVICE void resolve ()
 
NDARRAY_HOST_DEVICE bool is_resolved () const
 
template<class... Args, class = enable_if_any_slices_or_indices<Args...>>
NDARRAY_HOST_DEVICE bool is_in_range (const std::tuple< Args... > &args) const
 
template<class... Args, class = enable_if_any_slices_or_indices<Args...>>
NDARRAY_HOST_DEVICE bool is_in_range (Args...args) const
 
NDARRAY_HOST_DEVICE index_t operator[] (const index_type &indices) const
 
template<class... Args, class = enable_if_all_indices<Args...>>
NDARRAY_HOST_DEVICE index_t 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<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
 
NDARRAY_HOST_DEVICE const nda::dim dim (size_t d) const
 
NDARRAY_HOST_DEVICE dims_typedims ()
 
NDARRAY_HOST_DEVICE const dims_typedims () const
 
NDARRAY_HOST_DEVICE index_type min () const
 
NDARRAY_HOST_DEVICE index_type max () const
 
NDARRAY_HOST_DEVICE index_type extent () const
 
NDARRAY_HOST_DEVICE index_type stride () const
 
NDARRAY_HOST_DEVICE index_t flat_min () const
 
NDARRAY_HOST_DEVICE index_t flat_max () const
 
NDARRAY_HOST_DEVICE size_type flat_extent () const
 
NDARRAY_HOST_DEVICE size_type size () const
 
NDARRAY_HOST_DEVICE bool empty () const
 
NDARRAY_HOST_DEVICE bool is_compact () const
 
NDARRAY_HOST_DEVICE bool is_one_to_one () const
 
template<typename OtherShape >
NDARRAY_HOST_DEVICE bool is_subset_of (const OtherShape &other, index_t offset) 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
 
template<class... OtherDims, class = enable_if_same_rank<OtherDims...>>
NDARRAY_HOST_DEVICE bool operator== (const shape< OtherDims... > &other) const
 
template<class... OtherDims, class = enable_if_same_rank<OtherDims...>>
NDARRAY_HOST_DEVICE bool operator!= (const shape< OtherDims... > &other) const
 

Static Public Member Functions

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

Detailed Description

template<class... Dims>
class nda::shape< Dims >

A list of Dim objects describing a multi-dimensional space of indices. The rank of a shape refers to the number of dimensions in the shape. The first dimension is known as the 'innermost' dimension, and dimensions then increase until the 'outermost' dimension.

Shapes map a multi-dimensional index x to a flat offset by sum(dim<i>().flat_offset(std::get<i>(x))) for i in [0, Rank).

Member Typedef Documentation

using dims_type = std::tuple<Dims...>

The type of the dims tuple of this shape.

The type of an index for this shape.

Constructor & Destructor Documentation

NDARRAY_HOST_DEVICE shape ( const std::tuple< OtherDims... > &  other)
inline

Construct or assign a shape from another set of dims of a possibly different type. Each dim must be compatible with the corresponding dim of this shape.

Member Function Documentation

static constexpr size_t rank ( )
inlinestatic

Number of dims in this shape.

static constexpr bool is_scalar ( )
inlinestatic

A shape is scalar if its rank is 0.

NDARRAY_HOST_DEVICE void resolve ( )
inline

Replace strides with automatically determined values.

An automatic stride for a dimension is determined by taking the minimum of all possible candidate strides, which are the product of the stride and extent of all dimensions with a known stride. This is repeated for each dimension, starting with the innermost dimension.

Examples:

  • {{0, 5}, {0, 10}} -> {{0, 5, 1}, {0, 10, 5}}
  • {{0, 5}, {0, 10}, {0, 3, 1}} -> {{0, 5, 3}, {0, 10, 15}, {0, 3, 1}}
NDARRAY_HOST_DEVICE bool is_resolved ( ) const
inline

Check if all strides of the shape are known.

NDARRAY_HOST_DEVICE bool is_in_range ( const std::tuple< Args... > &  args) const
inline

Returns true if the indices or intervals args are in interval of this shape.

NDARRAY_HOST_DEVICE index_t operator[] ( const index_type indices) const
inline

Compute the flat offset of the index indices.

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

Create a new shape from this shape using a 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 auto& dim ( )
inline

Get a specific dim D of this shape.

NDARRAY_HOST_DEVICE const nda::dim dim ( size_t  d) const
inline

Get a specific dim of this shape with a runtime dimension index d. This will lose knowledge of any compile-time constant dimension attributes, and it is not a reference to the original dimension.

NDARRAY_HOST_DEVICE dims_type& dims ( )
inline

Get a tuple of all of the dims of this shape.

NDARRAY_HOST_DEVICE index_t flat_min ( ) const
inline

Compute the min, max, or extent of the flat offsets of this shape. This is the min, max, or extent of the valid interval of values returned by operator() or operator[].

NDARRAY_HOST_DEVICE size_type size ( ) const
inline

Compute the total number of indices in this shape.

NDARRAY_HOST_DEVICE bool empty ( ) const
inline

A shape is empty if its size is 0.

NDARRAY_HOST_DEVICE bool is_compact ( ) const
inline

Returns true if this shape is 'compact' in memory. A shape is compact if there are no unaddressable flat indices between the first and last addressable flat elements.

NDARRAY_HOST_DEVICE bool is_one_to_one ( ) const
inline

Returns true if this shape is an injective function mapping indices to flat indices. If the dims overlap, or a dim has stride zero, multiple indices will map to the same flat index; in this case, this function will return false.

NDARRAY_HOST_DEVICE bool is_subset_of ( const OtherShape &  other,
index_t  offset 
) const
inline

Returns true if this shape projects to a set of flat indices that is a subset of the other shape's projection to flat indices, with an offset offset.

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 shape< OtherDims... > &  other) const
inline

A shape is equal to another shape if the dim objects of each dimension from both shapes are equal.


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