Domi
Multi-dimensional, distributed data structures
 All Classes Files Functions Variables Typedefs Friends
Related Functions | List of all members
Domi::MDArrayView< T > Class Template Reference

Memory-safe templated multi-dimensional array view class. More...

#include <Domi_MDArrayView.hpp>

Public Types

Public types
typedef T value_type
 Value type.
 
typedef T * pointer
 Pointer type.
 
typedef const T * const_pointer
 Const pointer type.
 
typedef T & reference
 Reference type.
 
typedef const T & const_reference
 Const reference type.
 

Public Member Functions

Constructors and Destructor
 MDArrayView (Teuchos::ENull null_arg=Teuchos::null)
 Default constructor. More...
 
 MDArrayView (const Teuchos::ArrayView< T > &array, const Teuchos::ArrayView< dim_type > &dims, const Layout layout=DEFAULT_ORDER)
 Constructor with a source Teuchos::ArrayView, dimensions, and optional storage order. More...
 
 MDArrayView (const Teuchos::ArrayView< T > &array, const Teuchos::Array< dim_type > &dims, const Teuchos::Array< size_type > &strides, const Layout layout=DEFAULT_ORDER)
 Constructor with a source Teuchos::ArrayView, dimensions, strides, and optional storage order. More...
 
 MDArrayView (const MDArrayView< T > &array)
 Copy constructor. More...
 
 MDArrayView (const MDArrayView< T > &parent, int axis, dim_type index)
 
 MDArrayView (const MDArrayView< T > &parent, int axis, Slice slice)
 
MDArrayView< T > & operator= (const MDArrayView< T > &array)
 Assignment operator. More...
 
 ~MDArrayView ()
 Destructor.
 
Attribute accesor methods
int numDims () const
 Return the number of dimensions.
 
const Teuchos::Array< dim_type > & dimensions () const
 Return the array of dimensions.
 
dim_type dimension (int axis) const
 Return the dimension of the given axis. More...
 
size_type size () const
 Return the total size of the MDArrayView
 
const Teuchos::Array< size_type > & strides () const
 Return the indexing strides.
 
const Teuchos::ArrayView< T > & arrayView () const
 Return the underlying Teuchos::ArrayView
 
const Teuchos::ArrayView
< const T > & 
arrayViewConst () const
 Return const version of the underlying Teuchos::ArrayView
 
Layout layout () const
 Return the storage order.
 
bool contiguous () const
 Return whether the MDArrayView is contiguous in memory.
 
Indexing operators that return MDArrayViews
MDArrayView< const T > getConst () const
 Return an MDArrayView< const T > of an MDArrayView< T > object. More...
 
MDArrayView< T > operator[] (dim_type i)
 Sub-array access operator. The returned MDArrayView object will have one fewer dimensions than the calling MDArrayView. More...
 
const MDArrayView< T > operator[] (dim_type i) const
 Sub-array const access operator. The returned MDArrayView object will have one fewer dimensions than the calling MDArrayView. More...
 
MDArrayView< T > operator[] (Slice s)
 Sub-array access operator. The returned MDArrayView object will have the same number of dimensions as the calling MDArrayView. More...
 
const MDArrayView< T > operator[] (Slice s) const
 Sub-array const access operator. The returned MDArrayView object will have the same number of dimensions as the calling MDArrayView. More...
 
Indexing operators that return a reference to a single array element
T & operator() (dim_type i)
 Non-const 1D element access operator. More...
 
T & operator() (dim_type i, dim_type j)
 Non-const 2D element access operator. More...
 
T & operator() (dim_type i, dim_type j, dim_type k)
 Non-const 3D element access operator. More...
 
T & operator() (dim_type i, dim_type j, dim_type k, dim_type m)
 Non-const 4D element access operator. More...
 
T & operator() (dim_type i, dim_type j, dim_type k, dim_type m, dim_type n)
 Non-const 5D element access operator. More...
 
T & operator() (dim_type i, dim_type j, dim_type k, dim_type m, dim_type n, dim_type p,...)
 Non-const 6D and higher element access operator. More...
 
const T & operator() (dim_type i) const
 Const 1D element access operator. More...
 
const T & operator() (dim_type i, dim_type j) const
 Const 2D element access operator. More...
 
const T & operator() (dim_type i, dim_type j, dim_type k) const
 Const 3D element access operator. More...
 
const T & operator() (dim_type i, dim_type j, dim_type k, dim_type m) const
 Const 4D element access operator. More...
 
const T & operator() (dim_type i, dim_type j, dim_type k, dim_type m, dim_type n) const
 Const 5D element access operator. More...
 
const T & operator() (dim_type i, dim_type j, dim_type k, dim_type m, dim_type n, dim_type p,...) const
 Const 6D and higher element access operator. More...
 

Friends

Non-member operators and functions
template<typename T2 >
bool operator== (const MDArrayView< T2 > &a1, const MDArrayView< T2 > &a2)
 Equality operator.
 
template<typename T2 >
bool operator!= (const MDArrayView< T2 > &a1, const MDArrayView< T2 > &a2)
 Inequality operator.
 
template<typename T2 >
void swap (MDArrayView< T2 > &a1, MDArrayView< T2 > &a2)
 Swap function.
 
template<typename T2 >
std::ostream & operator<< (std::ostream &os, const MDArrayView< T2 > &a)
 Stream output operator. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
bool operator== (const MDArray< T > &a1, const MDArrayView< T > &a2)
 MDArray/MDArrayView equality operator.
 
template<typename T >
bool operator== (const MDArrayView< T > &a1, const MDArray< T > &a2)
 MDArrayView/MDArray equality operator.
 
template<typename T >
bool operator!= (const MDArrayView< T > &a1, const MDArray< T > &a2)
 MDArrayView/MDArray inequality operator.
 
template<typename T >
bool operator== (const MDArrayView< T > &a1, const MDArrayView< T > &a2)
 Equality operator.
 
template<typename T >
bool operator!= (const MDArrayView< T > &a1, const MDArrayView< T > &a2)
 Inequality operator.
 

Iterator classes and methods

typedef MDIterator
< MDArrayView< T > > 
iterator
 
typedef MDIterator
< MDArrayView< const T > > 
const_iterator
 
typedef MDRevIterator
< MDArrayView< T > > 
reverse_iterator
 
typedef MDRevIterator
< MDArrayView< const T > > 
const_reverse_iterator
 
class MDIterator< MDArrayView< T > >
 
class MDIterator< MDArrayView< const T > >
 
class MDRevIterator< MDArrayView< T > >
 
class MDRevIterator< MDArrayView< const T > >
 
iterator begin ()
 Return the beginning iterator.
 
iterator end ()
 Return the ending iterator.
 
const_iterator begin () const
 Return the beginning const_iterator.
 
const_iterator end () const
 Return the ending const_iterator.
 
const_iterator cbegin () const
 Return the beginning const_iterator.
 
const_iterator cend () const
 Return the ending const_iterator.
 
reverse_iterator rbegin ()
 Return the beginning reverse_iterator.
 
reverse_iterator rend ()
 Return the ending reverse_iterator.
 
const_reverse_iterator crbegin () const
 Return the beginning const_reverse_iterator.
 
const_reverse_iterator crend () const
 Return the ending const_reverse_iterator.
 

Teuchos::Array-like and std::vector-like methods

void assign (const T &value)
 Assign a value to all elements of the MDArrayView More...
 
T & at (dim_type i,...)
 Non-const single element access method with bounds checking. More...
 
const T & at (dim_type i,...) const
 Const single element access method with bounds checking. More...
 
std::string toString () const
 Convert the MDArrayView to a string representation.
 
const T * getRawPtr () const
 Return a const raw pointer to the beginning of the MDArrayView or NULL if unsized.
 
T * getRawPtr ()
 Return a raw pointer to the beginning of the MDArrayView or NULL if unsized.
 
static bool hasBoundsChecking ()
 Return true if MDArrayView has been compiled with bounds checking on.
 

Detailed Description

template<typename T>
class Domi::MDArrayView< T >

Memory-safe templated multi-dimensional array view class.

The MDArrayView class is to the MDArray class as the Teuchos::ArrayView class is to the Teuchos::Array class. Its primary function is to provide sub-views into both MDArray objects and other MDArrayView objects.

MDArrayView objects have a similar interface to the MDArray class and much of the behavior is the same as is described in the MDArray documentation. The big difference is that MDArrayView objects are constructed with pre-existing data buffers.

Constructor & Destructor Documentation

template<typename T >
Domi::MDArrayView< T >::MDArrayView ( Teuchos::ENull  null_arg = Teuchos::null)

Default constructor.

Parameters
null_arg[in] Enumerated constant denoting null construction

Returns a view into an array of 1 dimension of length zero with NULL pointer.

template<typename T>
Domi::MDArrayView< T >::MDArrayView ( const Teuchos::ArrayView< T > &  array,
const Teuchos::ArrayView< dim_type > &  dims,
const Layout  layout = DEFAULT_ORDER 
)

Constructor with a source Teuchos::ArrayView, dimensions, and optional storage order.

Parameters
array[in] Teuchos::ArrayView of the data buffer
dims[in] An array that defines the lengths of each dimension. The most convenient way to specify dimensions is with a Tuple returned by the non-member Teuchos::tuple<T>() function.
layout[in] An enumerated value specifying the internal storage order of the MDArrayView
template<typename T>
Domi::MDArrayView< T >::MDArrayView ( const Teuchos::ArrayView< T > &  array,
const Teuchos::Array< dim_type > &  dims,
const Teuchos::Array< size_type > &  strides,
const Layout  layout = DEFAULT_ORDER 
)

Constructor with a source Teuchos::ArrayView, dimensions, strides, and optional storage order.

Parameters
array[in] Teuchos::ArrayView of the data buffer
dims[in] An array that defines the lengths of each dimension.
strides[in] An array that defines the strides between elements along each axis.
layout[in] An enumerated value specifying the internal storage order of the MDArrayView

Note that this constructor was introduced specifically to implement the getConst() method, which converts an MDArrayView< T > to an MDArrayView< const T >. The presence of both strides and layout in the input arguments makes this an easy constructor to call incorrectly, and is not advised for general use.

template<typename T>
Domi::MDArrayView< T >::MDArrayView ( const MDArrayView< T > &  array)

Copy constructor.

Parameters
array[in] The source MDArrayView to be copied

Member Function Documentation

template<typename T>
void Domi::MDArrayView< T >::assign ( const T &  value)

Assign a value to all elements of the MDArrayView

Parameters
value[in] The value to be assigned
template<typename T >
T & Domi::MDArrayView< T >::at ( dim_type  i,
  ... 
)

Non-const single element access method with bounds checking.

Parameters
i,...[in] Indexes representing the location of the single element of the MDArrayView to be accessed. Note that this method assumes that the user will provide the same number of arguments as the number of dimensions of the MDArrayView.
template<typename T >
const T & Domi::MDArrayView< T >::at ( dim_type  i,
  ... 
) const

Const single element access method with bounds checking.

Parameters
i,...[in] Indexes representing the location of the single element of the MDArrayView to be accessed. Note that this method assumes that the user will provide the same number of arguments as the number of dimensions of the MDArrayView.
template<typename T >
dim_type Domi::MDArrayView< T >::dimension ( int  axis) const
inline

Return the dimension of the given axis.

Parameters
axis[in] The axis being queried (0 for the first axis, 1 for the second axis, and so forth)
template<typename T >
MDArrayView< const T > Domi::MDArrayView< T >::getConst ( ) const

Return an MDArrayView< const T > of an MDArrayView< T > object.

WARNING! If T is already const (e.g. const double) then do not try to instantiate this function since it will not compile!

template<typename T >
T & Domi::MDArrayView< T >::operator() ( dim_type  i)
inline

Non-const 1D element access operator.

Parameters
i[in] 1D index.

This operator should only be used with a 1D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 1D, an exception will be thrown.

template<typename T >
T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j 
)
inline

Non-const 2D element access operator.

Parameters
i[in] first 2D index.
j[in] second 2D index.

This operator should only be used with a 2D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 2D, an exception will be thrown.

template<typename T >
T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j,
dim_type  k 
)
inline

Non-const 3D element access operator.

Parameters
i[in] first 3D index.
j[in] second 3D index.
k[in] third 3D index.

This operator should only be used with a 3D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 3D, an exception will be thrown.

template<typename T >
T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j,
dim_type  k,
dim_type  m 
)
inline

Non-const 4D element access operator.

Parameters
i[in] first 4D index.
j[in] second 4D index.
k[in] third 4D index.
m[in] fourth 4D index.

This operator should only be used with a 4D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 4D, an exception will be thrown.

template<typename T >
T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j,
dim_type  k,
dim_type  m,
dim_type  n 
)
inline

Non-const 5D element access operator.

Parameters
i[in] first 5D index.
j[in] second 5D index.
k[in] third 5D index.
m[in] fourth 5D index.
n[in] fifth 5D index.

This operator should only be used with a 5D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 5D, an exception will be thrown.

template<typename T >
T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j,
dim_type  k,
dim_type  m,
dim_type  n,
dim_type  p,
  ... 
)
inline

Non-const 6D and higher element access operator.

Parameters
i[in] first index.
j[in] second index.
k[in] third index.
m[in] fourth index.
n[in] fifth index.
p[in] sixth index.
...[in] seventh and higher indexes.

This operator should only be used with a 6D and higher MDArrayViews. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is less than 6D, an exception will be thrown.

template<typename T >
const T & Domi::MDArrayView< T >::operator() ( dim_type  i) const
inline

Const 1D element access operator.

Parameters
i[in] 1D index.

This operator should only be used with a 1D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 1D, an exception will be thrown.

template<typename T >
const T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j 
) const
inline

Const 2D element access operator.

Parameters
i[in] first 2D index.
j[in] second 2D index.

This operator should only be used with a 2D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 2D, an exception will be thrown.

template<typename T >
const T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j,
dim_type  k 
) const
inline

Const 3D element access operator.

Parameters
i[in] first 3D index.
j[in] second 3D index.
k[in] third 3D index.

This operator should only be used with a 3D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 3D, an exception will be thrown.

template<typename T >
const T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j,
dim_type  k,
dim_type  m 
) const
inline

Const 4D element access operator.

Parameters
i[in] first 4D index.
j[in] second 4D index.
k[in] third 4D index.
m[in] fourth 4D index.

This operator should only be used with a 4D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 4D, an exception will be thrown.

template<typename T >
const T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j,
dim_type  k,
dim_type  m,
dim_type  n 
) const
inline

Const 5D element access operator.

Parameters
i[in] first 5D index.
j[in] second 5D index.
k[in] third 5D index.
m[in] fourth 5D index.
n[in] fifth 5D index.

This operator should only be used with a 5D MDArrayView. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is not 5D, an exception will be thrown.

template<typename T >
const T & Domi::MDArrayView< T >::operator() ( dim_type  i,
dim_type  j,
dim_type  k,
dim_type  m,
dim_type  n,
dim_type  p,
  ... 
) const
inline

Const 6D and higher element access operator.

Parameters
i[in] first index.
j[in] second index.
k[in] third index.
m[in] fourth index.
n[in] fifth index.
p[in] sixth index.
...[in] seventh and higher indexes.

This operator should only be used with a 6D and higher MDArrayViews. If HAVE_DOMI_ARRAY_BOUNDSCHECK is true and the MDArrayView is less than 6D, an exception will be thrown.

template<typename T>
MDArrayView< T > & Domi::MDArrayView< T >::operator= ( const MDArrayView< T > &  array)

Assignment operator.

Parameters
array[in] The source MDArrayView to be copied
template<typename T >
MDArrayView< T > Domi::MDArrayView< T >::operator[] ( dim_type  i)

Sub-array access operator. The returned MDArrayView object will have one fewer dimensions than the calling MDArrayView.

Parameters
i[in] Index of the desired sub-array. Note that to obtain expected behavior, you should always chain together n square bracket operators when referencing an n-dimensional MDArrayView.
template<typename T >
const MDArrayView< T > Domi::MDArrayView< T >::operator[] ( dim_type  i) const

Sub-array const access operator. The returned MDArrayView object will have one fewer dimensions than the calling MDArrayView.

Parameters
i[in] Index of the desired sub-array. Note that to obtain expected behavior, you should always chain together n square bracket operators when referencing an n-dimensional MDArrayView.
template<typename T >
MDArrayView< T > Domi::MDArrayView< T >::operator[] ( Slice  s)

Sub-array access operator. The returned MDArrayView object will have the same number of dimensions as the calling MDArrayView.

Parameters
s[in] Slice representing the bounds of the desired sub-array. Note that to obtain expected behavior, you should always chain together n square bracket operators when referencing an n-dimensional MDArrayView.
template<typename T >
const MDArrayView< T > Domi::MDArrayView< T >::operator[] ( Slice  s) const

Sub-array const access operator. The returned MDArrayView object will have the same number of dimensions as the calling MDArrayView.

Parameters
s[in] Slice representing the bounds of the desired sub-array. Note that to obtain expected behavior, you should always chain together n square bracket operators when referencing an n-dimensional MDArrayView.

Friends And Related Function Documentation

template<typename T>
template<typename T2 >
std::ostream& operator<< ( std::ostream &  os,
const MDArrayView< T2 > &  a 
)
friend

Stream output operator.

This operator calls the MDArrayView toString() method.


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

Generated on Fri Sep 1 2023 07:56:17 for Domi by doxygen 1.8.5