TNT::Array2D< T > Class Template Reference
#include <tnt_array2d.h>
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
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 < class ArrayTwoD >
void foo(ArrayTwoD &A)
{
A::value_type first_entry = A[0][0];
...
}
Constructor & Destructor Documentation
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:
-
| m | the first (row) dimension of the new matrix. |
| n | the second (column) dimension of the new matrix. |
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:
-
| m | the first (row) dimension of the new matrix. |
| n | the second (column) dimension of the new matrix. |
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:
-
| m | the first (row) dimension of the new matrix. |
| n | the second (column) dimension of the new matrix. |
| a | the one dimensional C array to use as data storage for the array. |
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:
-
| m | the first (row) dimension of the new matrix. |
| n | the second (column) dimension of the new matrix. |
| val | the constant value to set all elements of the new array to. |
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
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>&".
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>.
Assign one Array2D to another. (This is a shallow-assignement operation, and it is the identical semantics to ref(A).
- Parameters:
-
| A | the array to assign this one to. |
Assign all elements of array the same value.
- Parameters:
-
| val | the value to assign each element. |
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: