ivl 679
array_nd< T, OPTS > Class Template Reference

Multi-dimensional array of type T. More...

#include <array_nd_class.hpp>

Inherits array_common_base< array_nd< T, OPTS > >.

List of all members.

Public Types

typedef types::t_true has_1d_parenthesis
 types that specify the defined parenthesis operators for this class
typedef const array< size_t,
tiny > & 
size_nd_ref_type
 return type of size_nd in that data-specific class
typedef array< size_t, tiny > size_type
 parameter of resize, in each class of the hierarchy
typedef const array< size_t,
tiny > & 
stride_ref_type
 return type of size_nd in that data-specific class

Public Member Functions

base_class & base ()
 get base class
Element access (multidimensional)

Elements can be accessed by specifying the

best_reference operator() (size_t s1)
best_reference operator() (size_t s1, size_t s2)
best_reference operator() (size_t s1, size_t s2, size_t s3)
best_reference operator() (size_t s1, size_t s2, size_t s3, size_t s4)
best_reference operator() (size_t s1, size_t s2, size_t s3, size_t s4, size_t s5)
best_reference operator() (size_t s1, size_t s2, size_t s3, size_t s4, size_t s5, size_t s6)
template<class S >
best_reference operator() (const array< size_t, S > &indx)
const_reference operator() (size_t s1) const
const_reference operator() (size_t s1, size_t s2) const
const_reference operator() (size_t s1, size_t s2, size_t s3) const
const_reference operator() (size_t s1, size_t s2, size_t s3, size_t s4) const
const_reference operator() (size_t s1, size_t s2, size_t s3, size_t s4, size_t s5) const
const_reference operator() (size_t s1, size_t s2, size_t s3, size_t s4, size_t s5, size_t s6) const
template<class S >
const_reference operator() (const array< size_t, S > &indx) const
Single-dimensional constructors
 array_nd ()
 Default constructor.
 array_nd (size_t count)
 Construct by defining an element count.
 array_nd (size_t count, const T &s)
 Construct by defining an element count and a sigle default value for all elements.
template<class J , class D >
 array_nd (size_t count, const array< J, D > &s)
 Construct by defining an element count and a sigle default value for all elements or an ivl::array to copy the elements from.
 array_nd (size_t count, const T *data)
 Construct by defining an element count and a pointer to data.
template<class S >
 array_nd (size_t count, const data_init_arg &y)
 Construct from a size_t and a data_init_arg used for arrays of special types only.
Multi-dimensional constructors
template<class S >
 array_nd (const array< size_t, S > &sz)
 Construct from a size_array containing the dimension sizes.
template<class S >
 array_nd (const array< size_t, S > &sz, const T &s)
 Construct from a size_array containing the dimension sizes and assign scalar.
template<class S >
 array_nd (const array< size_t, S > &sz, const T *ptr)
 Construct from a size_array containing the dimension sizes and assign values from an one-dimensional C array.
template<class S >
 array_nd (const array< size_t, S > &sz, const data_init_arg &y)
 Construct from a size_array and a data_init_arg used for arrays of special types only.
template<class S , class J , class D >
 array_nd (const array< size_t, S > &sz, const array< J, D > &a)
 Construct from a size_array containing the dimension sizes and an array with the values.
template<class S , class J , class D >
 array_nd (const array< size_t, S > &sz, array< J, D > &a)
 Construct from a size_array containing the dimension sizes and an array with the values.
 array_nd (const this_type &a)
 Copy constructor.
template<class J , class S >
 array_nd (const array_nd< J, S > &a)
 Constructor using another form of array_nd.
template<class J , class S >
 array_nd (array_nd< J, S > &a)
 (special for ref_iterator) Constructor using another form of array_nd
Size functions (multidimensional)
size_nd_ref_type size_nd () const
 Get the size for each dimension.
size_t size_nd (size_t d) const
 Get the size for a specific dimension.
stride_ref_type stride () const
 Get the stride for each dimension.
size_t stride (size_t dim) const
 Get the stride for a particular dimension.
size_type size () const
 Get the size for each dimension.
size_t size (size_t d) const
 Get the size for a specific dimension.
size_t ndims () const
 Get the number of dimensions.
Resize Functions
void init (const size_t newsize, const T &s)
void init (const size_t newsize)
 init (1-dim) without padding
template<class S >
void init (const array< size_t, S > &newsize, const T &s)
 init (n-dim)
template<class S >
void init (const array< size_t, S > &newsize)
 init (n-dim) without padding
void resize (const size_t newsize, const T &s)
void resize (const size_t newsize)
 resize (1-dim) without padding
template<class S >
void resize (const array< size_t, S > &newsize, const T &s)
 resize (n-dim)
template<class S >
void resize (const array< size_t, S > &newsize)
 resize (n-dim) without padding
void reshape (const size_t newsize, const T &s)
void reshape (const size_t newsize)
 reshape (1-dim) without padding
template<class S >
void reshape (const array< size_t, S > &newsize, const T &s)
 reshape (n-dim)
template<class S >
void reshape (const array< size_t, S > &newsize)
 reshape (n-dim) without padding
Assignment Operators
template<class K >
derived_type & operator= (const K &k)
this_typeoperator= (const this_type &in)
 C++ copy-constructor.

Related Functions

(Note that these are not member functions.)

template<class T , class S >
array_nd< T, S >::create_similar flipdim (const array_nd< T, S > &a, size_t dim)
 flips array along dimth dimension
Array_nd non-member functions
template<class T , class S >
array< size_t, stack< 3 > > ind2sub (const array_nd< T, S > &a, size_t s)
 returns index vector from single-dimension index
template<class T , class S , class D >
array_nd< T, S >::create_new permute (const array_nd< T, S > &a, const array< size_t, D > &sz)
 Permute array dimensions.
template<class T , class S , class D >
array_nd< T, S >::create_new reshape (const array_nd< T, S > &src, const array< size_t, D > &sz)
 Reshape a matrix.
template<class T , class S >
array< typename array_nd< T, S >
::create_new > 
split (const array_nd< T, S > &a, size_t spoint, size_t dim)
 Split matrix at single point along dimension dim.
template<class T , class S , class D >
array< typename array_nd< T, S >
::create_new > 
split (const array_nd< T, S > &a, const array< size_t, D > &spoint, size_t dim)
 Split matrix at specific points along dimension dim.
template<class T , class S , class D >
size_t sub2ind (const array_nd< T, S > &a, const array< size_t, D > &b)
 converts index vector to single-dim index
template<class T , class D >
array_nd< T > ones (const array< size_t, D > &sz)
 Create an array_nd of all Ones.
template<class T , class D >
array_nd< T > zeros (const array< size_t, D > &sz)
 Create an array_nd of all zeros.
template<class T , class D >
array_nd< T > inf (const array< size_t, D > &sz)
 Create array_nd of all inf.

Detailed Description

template<class T, class OPTS = mem>
class array_nd< T, OPTS >

Multi-dimensional array of type T.

This structure is used to define a multidimensional array of type T. The number of dimensions can be specified when constructing an object and can be altered anytime by using methods like resize(const size_array &, const T).

The simpliest way to access an array_nd element is by using operator() and specifying the offset on each dimension, like this:

 int i = a(2, 3, 2) 

An array_nd inherites all the functionality the array class provides, which means that it can also be indexed as an one-dimensional array using the array subscript operator: []. Keep in mind that in array_nd the elements are stored in column-major order like Fortran and Matlab and not like C. So, the offset is computed like this:

offset = row + column*NUMROWS 

This is the normal specialization. It also applies to unspecialized data_class_sets, however they have to be resizable, creatable and writable.


Constructor & Destructor Documentation

template<class T, class OPTS = mem>
array_nd< T, OPTS >::array_nd ( size_t  count,
const T *  data 
) [inline]

Construct by defining an element count and a pointer to data.

Warning:
The constructor will try to read count*size_of(T) bytes from the memory pointed by data, without performing any kind of check. The user is responsible of making sure the memory is accessible and properly initialized.

Member Function Documentation

template<class T , class D >
void array_nd< T, D >::init ( const size_t  newsize,
const T &  s 
)

init (1-dim) The array is resized according to the new shape and new length. The old data that fits into the new shape is kept from the portion of the same shape that was common to the new and the old shape. In other words, the array-level data is moved, so that the rectangle, cube, or n-dim shape of data remains intact, and it is optionally padded with new values if it grows.

template<class T, class OPTS = mem>
template<class S >
const_reference array_nd< T, OPTS >::operator() ( const array< size_t, S > &  indx) const [inline]

Selects a single, const element of the array, using a size_array for the coordinates.

template<class T, class OPTS = mem>
template<class S >
best_reference array_nd< T, OPTS >::operator() ( const array< size_t, S > &  indx) [inline]

Selects a single, mutable element of the array, using a size_array for the coordinates.

template<class T , class D >
void array_nd< T, D >::reshape ( const size_t  newsize,
const T &  s 
)

reshape (1-dim). resizes and keeps the underlying array contents. changes shape, and discards the old data shape. faster than resize. The array is resized. The data that fits in the new length is not affected. It will be the same as the old if viewed as an array, and it will be folded into the dimensions of the array_nd according to the new shape. Padding is applied at the end of the data.

template<class T , class D >
void array_nd< T, D >::resize ( const size_t  newsize,
const T &  s 
)

resize (1-dim) The array is resized according to the new shape and new length. The old data that fits into the new shape is kept from the portion of the same shape that was common to the new and the old shape. In other words, the array-level data is moved, so that the rectangle, cube, or n-dim shape of data remains intact, and it is optionally padded with new values if it grows.


Friends And Related Function Documentation

template<class T , class D >
array_nd< T > inf ( const array< size_t, D > &  sz) [related]

Create array_nd of all inf.

Parameters:
szContains the dimensions of the array_nd that will be created.
Warning:
Be Infinity is only defined for float, double, long double
template<class T , class D >
array_nd< T > ones ( const array< size_t, D > &  sz) [related]

Create an array_nd of all Ones.

Parameters:
szContains the dimensions of the array_nd that will be created.
template<class T , class S , class D >
array_nd< T, S >::create_new permute ( const array_nd< T, S > &  a,
const array< size_t, D > &  sz 
) [related]

Permute array dimensions.

This function rearranges the dimensions of array_nd so that they are in the order specified by sz.

template<class T , class S , class D >
array_nd< T, S >::create_new reshape ( const array_nd< T, S > &  src,
const array< size_t, D > &  sz 
) [related]

Reshape a matrix.

Create a new array_nd whith dimensions appointed by size_array sz and whose elements are taken columnwise from src

Parameters:
srcInput array
szDimensions of output array
template<class T , class D >
array_nd< T > zeros ( const array< size_t, D > &  sz) [related]

Create an array_nd of all zeros.

Parameters:
szContains the dimensions of the array_nd that will be created.

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations