My Project
Loading...
Searching...
No Matches
TNT::Array2D< T > Class Template Reference

#include <tnt_array2d.h>

Public Types

typedef T value_type
 

Public Member Functions

 Array2D ()
 
 Array2D (int m, int n)
 
 Array2D (int m, int n, T *a)
 
 Array2D (int m, int n, const T &val)
 
 Array2D (const Array2D &A)
 
 operator T** ()
 
 operator const T ** () const
 
Array2Doperator= (const T &val)
 
Array2Doperator= (const Array2D &A)
 
Array2Dref (const Array2D &A)
 
Array2D copy () const
 
Array2Dinject (const Array2D &A)
 
T * operator[] (int i)
 
const T * operator[] (int i) const
 
int dim1 () const
 
int dim2 () const
 
int ref_count ()
 
int ref_count_data ()
 
int ref_count_dim1 ()
 
Array2D subarray (int i0, int i1, int j0, int j1)
 

Detailed Description

template<class T>
class TNT::Array2D< T >

Ttwo-dimensional numerical array which looks like a conventional C multiarray. Storage corresponds to C (row-major) ordering. Elements are accessed via A[i][j] notation for 0-based indexing, and A(i,j) for 1-based indexing..

Array assignment is by reference (i.e. shallow assignment). That is, B=A implies that the A and B point to the same array, so modifications to the elements of A will be reflected in B. If an independent copy is required, then B = A.copy() can be used. Note that this facilitates returning arrays from functions without relying on compiler optimizations to eliminate extensive data copying.

The indexing and layout of this array object makes it compatible with C and C++ algorithms that utilize the familiar C[i][j] notation. This includes numerous

textbooks, such as Numercial Recipes, and various public domain codes.

Member Typedef Documentation

◆ value_type

template<class T >
T TNT::Array2D< T >::value_type

Used to determined the data type of array entries. This is most commonly used when requiring scalar temporaries in templated algorithms that have TNT arrays as input. For example,

template &lt class ArrayTwoD &gt
void foo(ArrayTwoD &A)
{
  A::value_type first_entry = A[0][0];
  ...
}

Constructor & Destructor Documentation

◆ Array2D() [1/5]

template<class T >
TNT::Array2D< T >::Array2D ( )

Create a null array. This is not the same as Array2D(0,0), which consumes some memory overhead.

Create a new (m x n) array, WIHOUT initializing array elements. To create an initialized array of constants, see Array2D(m,n,value).

This version avoids the O(m*n) initialization overhead and is used just before manual assignment.

Parameters
mthe first (row) dimension of the new matrix.
nthe second (column) dimension of the new matrix.

◆ Array2D() [2/5]

template<class T >
TNT::Array2D< T >::Array2D ( int m,
int n )

Create a new (m x n) array, without initalizing elements. (This encurs an O(1) operation cost, rather than a O(m*n) cost.)

Parameters
mthe first (row) dimension of the new matrix.
nthe second (column) dimension of the new matrix.

◆ Array2D() [3/5]

template<class T >
TNT::Array2D< T >::Array2D ( int m,
int n,
T * a )

Create a new (m x n) array, as a view of an existing one-dimensional array stored in row-major order, i.e. right-most dimension varying fastest. Note that the storage for this pre-existing array will never be destroyed by TNT.

Parameters
mthe first (row) dimension of the new matrix.
nthe second (column) dimension of the new matrix.
athe one dimensional C array to use as data storage for the array.

◆ Array2D() [4/5]

template<class T >
TNT::Array2D< T >::Array2D ( int m,
int n,
const T & val )

Create a new (m x n) array, initializing array elements to constant specified by argument. Most often used to create an array of zeros, as in A(m, n, 0.0).

Parameters
mthe first (row) dimension of the new matrix.
nthe second (column) dimension of the new matrix.
valthe constant value to set all elements of the new array to.

◆ Array2D() [5/5]

template<class T >
TNT::Array2D< T >::Array2D ( const Array2D< T > & A)
inline

Copy constructor. Array data is NOT copied, but shared. Thus, in Array2D B(A), subsequent changes to A will be reflected in B. For an indepent copy of A, use Array2D B(A.copy()), or B = A.copy(), instead.

Member Function Documentation

◆ operator const T **()

template<class T >
TNT::Array2D< T >::operator const T ** ( ) const
inline

Convert a const 2D array into a const multidimensional C pointer.
Most often called automatically when calling C interfaces that expect things like "const double**" rather than "const Array2D<dobule>&".

◆ operator T**()

template<class T >
TNT::Array2D< T >::operator T** ( )
inline

Convert 2D array into a regular multidimensional C pointer. Most often called automatically when calling C interfaces that expect things like double** rather than Array2D<dobule>.

◆ operator=() [1/2]

template<class T >
Array2D< T > & TNT::Array2D< T >::operator= ( const Array2D< T > & A)
inline

Assign one Array2D to another. (This is a shallow-assignement operation, and it is the identical semantics to ref(A).

Parameters
Athe array to assign this one to.

◆ operator=() [2/2]

template<class T >
Array2D< T > & TNT::Array2D< T >::operator= ( const T & val)
inline

Assign all elements of array the same value.

Parameters
valthe value to assign each element.

◆ subarray()

template<class T >
Array2D< T > TNT::Array2D< T >::subarray ( int i0,
int i1,
int j0,
int j1 )

Create a new view to a subarray defined by the boundaries [i0][i0] and [i1][j1]. The size of the subarray is (i1-i0) by (j1-j0). If either of these lengths are zero or negative, the subarray view is null.


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