SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sydevs::arraynd_base< T, ndims > Class Template Reference

A base class template for a multidimensional array with elements of type T arranged in a lattice of ndim dimensions. More...

#include <arraynd_base.h>

Inherited by sydevs::arraynd< T, ndims >.

Public Member Functions

 ~arraynd_base ()=default
 Destructor. More...
 
std::array< int64, ndims > dims () const
 Returns the lengths of each dimension. More...
 
std::array< int64, ndims > strides () const
 Returns the number of element-size steps in memory between successive elements for each dimension. More...
 
bool empty () const
 Returns true if there is at least one element. More...
 
int64 size () const
 Returns the total number of elements. More...
 
int64 offset () const
 Returns the number of element-size steps in memory before the first element. More...
 
const T * data () const
 Returns a pointer to the element data (const). More...
 
T * data ()
 Returns a pointer to the element data. More...
 
bool is_contiguous () const
 Returns true if a row-major traversal of the multidimensional array accesses each element of data in sequence. More...
 
bool is_view () const
 Returns true if this multidimensional array is a view of another, meaning that data is shared. More...
 
bool is_readonly () const
 Returns true if the data is readonly, in which case attempts to modify it raise a std::logic_error. More...
 
const T & operator() (const std::array< int64, ndims > &indices) const
 Returns a reference to an element (const). More...
 
T & operator() (const std::array< int64, ndims > &indices)
 Returns a reference to an element. More...
 
const T & operator() (const arraynd_base< int64, 1 > &indices) const
 Returns a reference to an element (const). More...
 
T & operator() (const arraynd_base< int64, 1 > &indices)
 Returns a reference to an element. More...
 
template<typename... Indices>
const T & operator() (Indices...indices) const
 Returns a reference to an element (const). More...
 
template<typename... Indices>
T & operator() (Indices...indices)
 Returns a reference to an element. More...
 
void fill (const T &value)
 Replaces every element with value. More...
 
void assign (const arraynd_base< T, ndims > &rhs)
 Replaces every element with the corresponding value in rhs. More...
 
void assign_from_function (std::function< T(const std::array< int64, ndims > &indices)> func)
 Replaces every element with the result of func evaluated at the cooresponding indices. More...
 
bool traverse (std::function< bool(const std::array< int64, ndims > &indices, const T &value)> func) const
 Traverses the multidimensional array in row-major order, calling func at every element. More...
 

Protected Member Functions

 arraynd_base ()
 
 arraynd_base (const std::array< int64, ndims > &dims, const T &value)
 
 arraynd_base (const std::array< int64, ndims > &dims, const std::vector< T > &data)
 
 arraynd_base (const std::array< int64, ndims > &dims, std::function< T(const std::array< int64, ndims > &indices)> func)
 
 arraynd_base (const arraynd_base< T, ndims+1 > &rhs, int64 index, bool is_readonly)
 
 arraynd_base (const arraynd_base< T, ndims > &rhs, range r, bool is_readonly)
 
 arraynd_base (const arraynd_base< T, ndims > &rhs, bool is_view, bool is_readonly)
 
 arraynd_base (const arraynd_base< T, ndims > &rhs)
 
arraynd_base< T, ndims > & operator= (const arraynd_base< T, ndims > &rhs)
 
 arraynd_base (arraynd_base< T, ndims > &&)=default
 
arraynd_base< T, ndims > & operator= (arraynd_base< T, ndims > &&)=default
 

Static Protected Member Functions

static void transpose (arraynd_base< T, ndims > &arr)
 
static void swap_axes (arraynd_base< T, ndims > &arr, int64 idim0, int64 idim1)
 
static void subdivide_axis (const arraynd_base< T, ndims > &arr0, arraynd_base< T, ndims+1 > &arr, int64 idim, const std::array< int64, 2 > &dims)
 
static void absorb_axis (const arraynd_base< T, ndims > &arr0, arraynd_base< T, ndims-1 > &arr, int64 idim)
 

Friends

class arraynd_base< T, ndims-1 >
 
class arraynd_base< T, ndims+1 >
 

Detailed Description

template<typename T, int64 ndims>
class sydevs::arraynd_base< T, ndims >

A base class template for a multidimensional array with elements of type T arranged in a lattice of ndim dimensions.

arraynd_base contains all member variables, all member functions that behave the same for ndims == 1 and ndims > 1, and all member functions that do not return a multidimensional array.

Constructor & Destructor Documentation

template<typename T, int64 ndims>
sydevs::arraynd_base< T, ndims >::~arraynd_base ( )
default

Destructor.

template<typename T , int64 ndims>
sydevs::arraynd_base< T, ndims >::arraynd_base ( )
protected
template<typename T, int64 ndims>
sydevs::arraynd_base< T, ndims >::arraynd_base ( const std::array< int64, ndims > &  dims,
const T &  value 
)
protected
template<typename T, int64 ndims>
sydevs::arraynd_base< T, ndims >::arraynd_base ( const std::array< int64, ndims > &  dims,
const std::vector< T > &  data 
)
protected
template<typename T, int64 ndims>
sydevs::arraynd_base< T, ndims >::arraynd_base ( const std::array< int64, ndims > &  dims,
std::function< T(const std::array< int64, ndims > &indices)>  func 
)
protected
template<typename T, int64 ndims>
sydevs::arraynd_base< T, ndims >::arraynd_base ( const arraynd_base< T, ndims+1 > &  rhs,
int64  index,
bool  is_readonly 
)
protected
template<typename T, int64 ndims>
sydevs::arraynd_base< T, ndims >::arraynd_base ( const arraynd_base< T, ndims > &  rhs,
range  r,
bool  is_readonly 
)
protected
template<typename T, int64 ndims>
sydevs::arraynd_base< T, ndims >::arraynd_base ( const arraynd_base< T, ndims > &  rhs,
bool  is_view,
bool  is_readonly 
)
protected
template<typename T, int64 ndims>
sydevs::arraynd_base< T, ndims >::arraynd_base ( const arraynd_base< T, ndims > &  rhs)
protected
template<typename T, int64 ndims>
sydevs::arraynd_base< T, ndims >::arraynd_base ( arraynd_base< T, ndims > &&  )
protecteddefault

Member Function Documentation

template<typename T, int64 ndims>
void sydevs::arraynd_base< T, ndims >::absorb_axis ( const arraynd_base< T, ndims > &  arr0,
arraynd_base< T, ndims-1 > &  arr,
int64  idim 
)
staticprotected
template<typename T, int64 ndims>
void sydevs::arraynd_base< T, ndims >::assign ( const arraynd_base< T, ndims > &  rhs)

Replaces every element with the corresponding value in rhs.

template<typename T, int64 ndims>
void sydevs::arraynd_base< T, ndims >::assign_from_function ( std::function< T(const std::array< int64, ndims > &indices)>  func)

Replaces every element with the result of func evaluated at the cooresponding indices.

template<typename T , int64 ndims>
const T * sydevs::arraynd_base< T, ndims >::data ( ) const

Returns a pointer to the element data (const).

template<typename T , int64 ndims>
T * sydevs::arraynd_base< T, ndims >::data ( )

Returns a pointer to the element data.

template<typename T , int64 ndims>
std::array< int64, ndims > sydevs::arraynd_base< T, ndims >::dims ( ) const

Returns the lengths of each dimension.

template<typename T , int64 ndims>
bool sydevs::arraynd_base< T, ndims >::empty ( ) const

Returns true if there is at least one element.

template<typename T, int64 ndims>
void sydevs::arraynd_base< T, ndims >::fill ( const T &  value)

Replaces every element with value.

template<typename T , int64 ndims>
bool sydevs::arraynd_base< T, ndims >::is_contiguous ( ) const

Returns true if a row-major traversal of the multidimensional array accesses each element of data in sequence.

template<typename T , int64 ndims>
bool sydevs::arraynd_base< T, ndims >::is_readonly ( ) const

Returns true if the data is readonly, in which case attempts to modify it raise a std::logic_error.

template<typename T , int64 ndims>
bool sydevs::arraynd_base< T, ndims >::is_view ( ) const

Returns true if this multidimensional array is a view of another, meaning that data is shared.

template<typename T , int64 ndims>
int64 sydevs::arraynd_base< T, ndims >::offset ( ) const

Returns the number of element-size steps in memory before the first element.

template<typename T , int64 ndims>
const T & sydevs::arraynd_base< T, ndims >::operator() ( const std::array< int64, ndims > &  indices) const

Returns a reference to an element (const).

template<typename T , int64 ndims>
T & sydevs::arraynd_base< T, ndims >::operator() ( const std::array< int64, ndims > &  indices)

Returns a reference to an element.

template<typename T , int64 ndims>
const T & sydevs::arraynd_base< T, ndims >::operator() ( const arraynd_base< int64, 1 > &  indices) const

Returns a reference to an element (const).

template<typename T , int64 ndims>
T & sydevs::arraynd_base< T, ndims >::operator() ( const arraynd_base< int64, 1 > &  indices)

Returns a reference to an element.

template<typename T , int64 ndims>
template<typename... Indices>
const T & sydevs::arraynd_base< T, ndims >::operator() ( Indices...  indices) const

Returns a reference to an element (const).

template<typename T , int64 ndims>
template<typename... Indices>
T & sydevs::arraynd_base< T, ndims >::operator() ( Indices...  indices)

Returns a reference to an element.

template<typename T, int64 ndims>
arraynd_base< T, ndims > & sydevs::arraynd_base< T, ndims >::operator= ( const arraynd_base< T, ndims > &  rhs)
protected
template<typename T, int64 ndims>
arraynd_base<T, ndims>& sydevs::arraynd_base< T, ndims >::operator= ( arraynd_base< T, ndims > &&  )
protecteddefault
template<typename T , int64 ndims>
int64 sydevs::arraynd_base< T, ndims >::size ( ) const

Returns the total number of elements.

template<typename T , int64 ndims>
std::array< int64, ndims > sydevs::arraynd_base< T, ndims >::strides ( ) const

Returns the number of element-size steps in memory between successive elements for each dimension.

template<typename T, int64 ndims>
void sydevs::arraynd_base< T, ndims >::subdivide_axis ( const arraynd_base< T, ndims > &  arr0,
arraynd_base< T, ndims+1 > &  arr,
int64  idim,
const std::array< int64, 2 > &  dims 
)
staticprotected
template<typename T, int64 ndims>
void sydevs::arraynd_base< T, ndims >::swap_axes ( arraynd_base< T, ndims > &  arr,
int64  idim0,
int64  idim1 
)
staticprotected
template<typename T, int64 ndims>
void sydevs::arraynd_base< T, ndims >::transpose ( arraynd_base< T, ndims > &  arr)
staticprotected
template<typename T, int64 ndims>
bool sydevs::arraynd_base< T, ndims >::traverse ( std::function< bool(const std::array< int64, ndims > &indices, const T &value)>  func) const

Traverses the multidimensional array in row-major order, calling func at every element.

For each element traversed in row-major order, func is called with the indices of the element and the element's value. If func returns true, the traversal continues. If func returns false, the traversal is terminated.

Parameters
funcThe function to be called at every element.
Returns
true if the entire multidimensional array is traversed and func returns true at every element; false otherwise.

Friends And Related Function Documentation

template<typename T, int64 ndims>
friend class arraynd_base< T, ndims+1 >
friend
template<typename T, int64 ndims>
friend class arraynd_base< T, ndims-1 >
friend

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