MultiArray< T > Class Template Reference

The multidimensional variabled size array class. More...

#include <MultiArray.hpp>

Inheritance diagram for MultiArray< T >:

Inheritance graph
[legend]
Collaboration diagram for MultiArray< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

long Dimension () const
 Returns the dimensionality of the array.
int Length (int i) const
 Returns the size for a given dimension.
const Array< int > & Lengths () const
 Returns all the lengths.
long TotalNOfElements () const
 Returns the total number of elem. in the array.
long SubArrayTotalLen (int n) const
 Raw length of subarrays reference by first n indices.
T * Entries ()
 Returns the pointer to the 'raw' array of the entries.
const T * Entries () const
 Returns a const-pointer to the 'raw' array of the entries.
const T & operator[] (long offset) const
 An element by an absolute position.
T & operator[] (long offset)
 An element by an absolute position.
const T & operator[] (const MultiIndex &index) const
 References an element by a multiindex.
T & operator[] (const MultiIndex &index)
 References an element by a multiindex.
const T * operator() (const MultiIndex &index) const
 A subarray by a multiindex.
T * operator() (const MultiIndex &index)
 A subarray by a multiindex.
long Offset (const MultiIndex &index, long d) const
 The offset of an entry referenced by 'd' elems of 'index'.
long Offset (const MultiIndex &index) const
 Returns the offset of an entry for a given multiindex.
void Position (long offset, MultiIndex &index) const
 Computes the multiindex for an offset.
MultiArray< T > & operator= (const MultiArray< T > &src)
 Standard assignment.
MultiArray< T > & operator= (const T &value)
 Sets constant values to all the elements.
void SetZero ()
 Sets all the entries to zero.
void Reset ()
 Releases the memory, make the sizes undefined.
void Reset (const Array< int > &new_length, T *mem=NULL)
 Sets the new sizes, reallocates memory.
void Reset (const Array< int > &new_length, int block_sz, T *mem=NULL)
 Sets the new sizes with the block size, reallocates memory.
void Reset (int len, T *mem=NULL)
 Sets new sizes and reallocates memory:.
bool NextPos (MultiIndex &index) const
 Go lexicographically to the next position.
bool NextPos (MultiIndex &index, int range) const
 Go to the next position in the subarray.
bool NextPos (MultiIndex &index, SelectedDim &subgrid) const
 Go to the next position in the selected dimensions.
void SaveAsciiAs (char *file_name)
 The ASCII output into a file (cf. 'operator <<' below):.
void ReadAsciiFrom (char *file_name)
 The ASCII input into a file (cf. 'operator >>' below):.
 MultiArray ()
 Zero sizes, no memory.
 MultiArray (const MultiArray< T > &ma)
 MultiArray (const Array< int > &len)
 MultiArray by given sizes.
 MultiArray (const Array< int > &len, int block_sz)
 MultiArray by given grid sizes and the additional block size.
 MultiArray (int len, T *mem=NULL)
 1d MultiArray

Protected Attributes

Array< T > elements
Array< int > length

Friends

std::ostream & operator (std::ostream &, MultiArray< T > &)
std::istream & operator>> (std::istream &, MultiArray< T > &)
 The C++-style input operator.

Detailed Description

template<typename T>
class MultiArray< T >

The multidimensional variabled size array class.

MultiArray<T> is a multidimensional variable size array of elements of type <T>. Not only the sizes but also the dimensionality is variable. This template is used to represent grid functions (cf. MultiVector<T>) and other grid objects like sparse matrices (cf. SparseMatrix<T>). For MultiArray<T>, T may be any type.

Note:
Define CHECK_ARRAY_RANGE to switch on the range checking at the indexation. While that helps at debugging it takes a lot of computation time.

There are two types of the indexation operators: [] and (). The first one references the entries of the array and has the return type T & so that you can you it for reading and writing the entries. If the argument of this operation is a multiindex, it must have the same length as 'length'. The second operator references subarrays. Its argument is a multiindex whose length may be less that that of 'length'. The operation returns the pointer to the subarray containing all the entries whose first indices coincide with the given ones.


Constructor & Destructor Documentation

template<typename T>
MultiArray< T >::MultiArray (  )  [inline]

Zero sizes, no memory.

template<typename T>
MultiArray< T >::MultiArray ( const MultiArray< T > &  ma  )  [inline]

Duplication

template<typename T>
MultiArray< T >::MultiArray ( const Array< int > &  len  )  [inline]

MultiArray by given sizes.

Parameters:
[in] len The sizes.

template<typename T>
MultiArray< T >::MultiArray ( const Array< int > &  len,
int  block_sz 
) [inline]

MultiArray by given grid sizes and the additional block size.

Parameters:
[in] len The sizes
[in] block_sz The additional dimension (the block size)

template<typename T>
MultiArray< T >::MultiArray ( int  len,
T *  mem = NULL 
) [inline]

1d MultiArray

Parameters:
[in] len The length of the 1d array.
[in] mem The memory to place the 'T'-objects (optional).


Member Function Documentation

template<typename T>
long MultiArray< T >::Dimension (  )  const [inline]

Returns the dimensionality of the array.

template<typename T>
int MultiArray< T >::Length ( int  i  )  const [inline]

Returns the size for a given dimension.

Parameters:
[in] i The dimension
Returns:
Const-reference to size of dimension i

template<typename T>
const Array<int>& MultiArray< T >::Lengths (  )  const [inline]

Returns all the lengths.

Returns:
Reference to length array.

template<typename T>
long MultiArray< T >::TotalNOfElements (  )  const [inline]

Returns the total number of elem. in the array.

template<typename T>
long MultiArray< T >::SubArrayTotalLen ( int  n  )  const [inline]

Raw length of subarrays reference by first n indices.

Parameters:
[in] n Number of the first indices
Returns:
Raw length of subarrays reference by first n indices.

template<typename T>
T* MultiArray< T >::Entries (  )  [inline]

Returns the pointer to the 'raw' array of the entries.

Returns:
Pointer to the 'raw' array of the entries.

template<typename T>
const T* MultiArray< T >::Entries (  )  const [inline]

Returns a const-pointer to the 'raw' array of the entries.

Returns:
Const-pointer to the 'raw' array of the entries.

template<typename T>
const T& MultiArray< T >::operator[] ( long  offset  )  const [inline]

An element by an absolute position.

Parameters:
[in] offset the position
Returns:
Const-reference of element at position.

template<typename T>
T& MultiArray< T >::operator[] ( long  offset  )  [inline]

An element by an absolute position.

Parameters:
[in] offset the position
Returns:
reference of element at position.

template<typename T>
const T & MultiArray< T >::operator[] ( const MultiIndex index  )  const [inline]

References an element by a multiindex.

The multiindex must have the same length as the dimensionality of the MultiArray

Parameters:
[in] index The multiindex.
Returns:
Const-reference to the corresponding element.

template<typename T>
T & MultiArray< T >::operator[] ( const MultiIndex index  )  [inline]

References an element by a multiindex.

The multiindex must have the same length as the dimensionality of the MultiArray

Parameters:
[in] index The multiindex.
Returns:
Reference to the corresponding element.

template<typename T>
const T* MultiArray< T >::operator() ( const MultiIndex index  )  const [inline]

A subarray by a multiindex.

template<typename T>
T* MultiArray< T >::operator() ( const MultiIndex index  )  [inline]

A subarray by a multiindex.

template<typename T>
long MultiArray< T >::Offset ( const MultiIndex index,
long  d 
) const [inline]

The offset of an entry referenced by 'd' elems of 'index'.

template<typename T>
long MultiArray< T >::Offset ( const MultiIndex index  )  const [inline]

Returns the offset of an entry for a given multiindex.

template<typename T>
void MultiArray< T >::Position ( long  offset,
MultiIndex index 
) const [inline]

Computes the multiindex for an offset.

The size of the 'index' argument ist set automatically.

Parameters:
[in] offset The offset
[out] index To save the multiindex.

template<typename T>
MultiArray<T>& MultiArray< T >::operator= ( const MultiArray< T > &  src  )  [inline]

Standard assignment.

'this' and 'src' may have different sizes.

Parameters:
[in] src Source-array

Reimplemented in MultiVector< T >.

template<typename T>
MultiArray<T>& MultiArray< T >::operator= ( const T &  value  )  [inline]

Sets constant values to all the elements.

template<typename T>
void MultiArray< T >::SetZero (  )  [inline]

Sets all the entries to zero.

template<typename T>
void MultiArray< T >::Reset (  )  [inline]

Releases the memory, make the sizes undefined.

template<typename T>
void MultiArray< T >::Reset ( const Array< int > &  new_length,
T *  mem = NULL 
) [inline]

Sets the new sizes, reallocates memory.

Parameters:
[in] new_length The new sizes
[in] mem (optionally) the memory where to place the 'T'-objects.

template<typename T>
void MultiArray< T >::Reset ( const Array< int > &  new_length,
int  block_sz,
T *  mem = NULL 
) [inline]

Sets the new sizes with the block size, reallocates memory.

Parameters:
[in] new_length The new sizes
[in] block_sz Additional dimension (the block size) IFF != 1
[in] mem The memory where to place the 'T'-objects (optional)
Note:
If the given block size is 1 no new dimension is created to index the block entries. Then the function is equivalent to Reset(const Array<int>, T * mem). Otherwise, a new dimension is added to the block sizes.

template<typename T>
void MultiArray< T >::Reset ( int  len,
T *  mem = NULL 
) [inline]

Sets new sizes and reallocates memory:.

The 1d version (creates a 1d array)

Parameters:
[in] len The size of the 1d array.
[in] mem The memory where to place the 'T'-objects (optional).

template<typename T>
bool MultiArray< T >::NextPos ( MultiIndex index  )  const [inline]

Go lexicographically to the next position.

Parameters:
[in] index The index to update

template<typename T>
bool MultiArray< T >::NextPos ( MultiIndex index,
int  range 
) const [inline]

Go to the next position in the subarray.

Parameters:
[in] index The index to update.
[in] range Only the first 'range' indices are considered and changed.

template<typename T>
bool MultiArray< T >::NextPos ( MultiIndex index,
SelectedDim subgrid 
) const [inline]

Go to the next position in the selected dimensions.

Parameters:
[in] index The index to update.
[in] subgrid The selected subgrid.

template<typename T>
void MultiArray< T >::SaveAsciiAs ( char *  file_name  )  [inline]

The ASCII output into a file (cf. 'operator <<' below):.

Parameters:
[in] file_name The name of the file where to save

template<typename T>
void MultiArray< T >::ReadAsciiFrom ( char *  file_name  )  [inline]

The ASCII input into a file (cf. 'operator >>' below):.

Parameters:
[in] file_name The name of the file from where to load


Friends And Related Function Documentation

template<typename T>
std::ostream& operator ( std::ostream &  ,
MultiArray< T > &   
) [friend]

template<typename T>
std::istream& operator>> ( std::istream &  ,
MultiArray< T > &   
) [friend]

The C++-style input operator.

Reads values of the array from a stream in the format of operator << . On errors like memory lack the function throws an exception.


Member Data Documentation

template<typename T>
Array<T> MultiArray< T >::elements [protected]

Keeps the entries, length! elements.

template<typename T>
Array<int> MultiArray< T >::length [protected]

Keeps the sizes for every dimension.


The documentation for this class was generated from the following file:
Generated on Fri Sep 21 12:34:21 2007 for SG2 by  doxygen 1.5.2