TemplateTNT::Array2D class Reference
Main Page Namespace List Compound List File List Namespace Members Compound Members File Members
Copyright By PowCoder代写 加微信 powcoder
TNT::Array2D Class Template Reference
#include
List of all members.
Public Types
typedef T value_type
Public Methods
Array2D ()
Array2D (int m, int n)
Array2D (int m, int n, T *a)
Array2D (int m, int n, const T &a)
Array2D (const Array2D &A)
operator T ** ()
operator const T ** ()
Array2D& operator= (const T &a)
Array2D& operator= (const Array2D &A)
Array2D& ref (const Array2D &A)
Array2D copy () const
Array2D& inject (const Array2D &A)
T* operator[] (int i)
const T* operator[] (int i) const
int dim1 () const
int dim2 () const
~Array2D ()
Detailed Description
template
Templated two-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.
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
template
typedef T TNT::Array2D
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
void foo(ArrayTwoD &A)
A::value_type first_entry = A[0][0];
Constructor & Destructor Documentation
template
TNT::Array2D
Create a null array. This is not the same as Array2D(0,0), which consumes some memory overhead.
template
TNT::Array2D
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.
template
TNT::Array2D
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:
the first (row) dimension of the new matrix.
the second (column) dimension of the new matrix.
template
TNT::Array2D
const T & a )
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:
the first (row) dimension of the new matrix.
the second (column) dimension of the new matrix.
the constant value to set all elements of the new array to.
template
TNT::Array2D
const Array2D
Create a new (m x n) array, as a view of an existing one-dimensional array stored in C order, i.e. right-most dimension varying fastest. (Often referred to as “row-major” ordering.) Note that the storage for this pre-existing array will never be garbage collected by the Array2D class.
Parameters:
the first (row) dimension of the new matrix.
the second (column) dimension of the new matrix.
the one dimensional C array to use as data storage for the array.
template
TNT::Array2D
Destructor. Reclaim resouces associated with this view of the array data. Note that elements are still intact if other array views of this data exist.
Member Function Documentation
template
Array2D
Create a new copy of existing matrix. Used in B = A.copy() or in the construction of B, e.g. Array2D B(A.copy()), to create a new array that does not share data.
template
int TNT::Array2D
) const [inline]
the size of the first dimension of the array, i.e. the number of rows.
template
int TNT::Array2D
) const [inline]
the size of the second dimension of the array, i.e. the number of columns.
template
Array2D
const Array2D
Copy the elements to from one array to another, in place. That is B.inject(A), both A and B must conform (i.e. have identical row and column dimensions).
This differs from B = A.copy() in that references to B before this assignment are also affected. That is, if we have
Array2D A(m,n);
Array2D C(m,n);
Array2D B(C); // elements of B and C are shared.
then B.inject(A) affects both and C, while B=A.copy() creates a new array B which shares no data with C or A.
Parameters:
the array from elements will be copied
an instance of the modifed array. That is, in B.inject(A), it returns B. If A and B are not conformat, no modifications to B are made.
template
TNT::Array2D
) [inline]
Automatic conversion to a two-dimensional C array. Useful for integrating with numerical codes that utilize the A[i][j] interface. Thus, if a function declared as
void row_max(double **D);
is called with an Array2D
Array2D
then A is automatically converted. Likewise,
double **d = A;
also converts A into a regular C pointer.
template
TNT::Array2D
) [inline]
Automatic conversion to a const two-dimensional C array. Useful for integrating with numerical codes that utilize the A[i][j] interface. Thus, if a function declared as
void row_max(const double **D);
is called with an Array2D
Array2D
then A is automatically converted. Likewise,
const double **d = A;
also converts A into a regular C pointer.
template
Array2D
const Array2D
B = A is shorthand notation for B.ref(A).
template
Array2D
const T & a ) [inline]
Assign all elemnts of A to a constant scalar.
template
const T * TNT::Array2D
int i ) const [inline]
template
T * TNT::Array2D
int i ) [inline]
Used for A[i][j] indexing. The first [] operator returns a conventional pointer which can be dereferenced using the same [] notation.
If TNT_BOUNDS_CHECK macro is define, the left-most index (row index) is checked that it falls within the array bounds (via the assert() macro.) Note that bounds checking can occur in the row dimension, but the not column, since this is just a C pointer.
template
Array2D
const Array2D
Create a reference (shallow assignment) to another existing array. In B.ref(A), B and A shared the same data and subsequent changes to the array elements of one will be reflected in the other.
This is what operator= calls, and B=A and B.ref(A) are equivalent operations.
The new referenced array: in B.ref(A), it returns B.
The documentation for this class was generated from the following file: tnt_array2d.h
Generated at Thu Jun 26 17:26:22 2003 for Template Numerical Toolkit (TNT) by
1.2.5 written by Dimitri van Heesch,
© 1997-2001
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com