Class for defining arrays, comparable to Array, but more efficient by using additional pointers as in class Array2D, but not only for 2-dimensional arrays, but also for 3-dimensional arrays. More...
#include <ArrayTable.h>
Public Member Functions | |
| void | resize (unsigned d0, unsigned d1, unsigned d2, int dummy=0) |
| Modifies the size of a 3-dimensional array. | |
| void | resize (unsigned d0, unsigned d1, int dummy=0) |
| Modifies the size of a 2-dimensional array. | |
| void | resize (unsigned d0, int dummy=0) |
| Modifies the size of a 1-dimensional array. | |
| operator T * () | |
| Casts current 1-dimensional ArrayTable object to C-style array. | |
| operator T ** () | |
| Casts current 2-dimensional ArrayTable object to C-style array. | |
| operator T *** () | |
| Casts current 3-dimensional ArrayTable object to C-style array. | |
| T & | operator() (unsigned i) |
| Allows access to single entries of a 1-dimensional array. | |
| T & | operator() (unsigned i, unsigned j) |
| Allows access to single entries of a 2-dimensional array. | |
| T & | operator() (unsigned i, unsigned j, unsigned k) |
| Allows access to single entries of a 3-dimensional array. | |
| ArrayTable< T > & | operator= (const ArrayTable< T > &a) |
| Assigns the values of one ArrayTable to another. | |
| ArrayTable< T > & | operator= (const T &d) |
| Assigns one value to all elements of an ArrayTable. | |
| ArrayTable () | |
| Creates a new empty ArrayTable. | |
| ArrayTable (unsigned i) | |
| Creates a new empty one-dimensional ArrayTable. | |
| ArrayTable (unsigned i, unsigned j) | |
| Creates a new empty 2-dimensional ArrayTable. | |
| ArrayTable (unsigned i, unsigned j, unsigned k) | |
| Creates a new empty 3-dimensional ArrayTable. | |
| ArrayTable (const ArrayTable< T > &a) | |
| Creates a new ArrayTable as a copy of the parameter (copy constructor). | |
Public Attributes | |
| Array< T > | A |
| Used to store all elements of a 1- to 3-dimensional array (as the element vector Array::e). | |
| Array< T * > | P1 |
| Used for faster access, when working with 2-dimensional arrays. | |
| Array< T ** > | P2 |
| Used for faster access, when working with 3-dimensional arrays. | |
Class for defining arrays, comparable to Array, but more efficient by using additional pointers as in class Array2D, but not only for 2-dimensional arrays, but also for 3-dimensional arrays.
This class enhances the Array class to allow for a faster reference on the elements. In case of 1D arrays nothing changes. In case of 2D arrays it stores additional pointers which reference to a block of elements belonging to a fixed first index - thus avoiding the use of multiplication during reference in trade of consuming more memory (comparable to the Array2D class).
The same principle is recursively applied in the 3D case: additional pointers reference to a block of 2D pointers belonging to a fixed first index. It'd be easy to enhance the principle to 4D, etc.
The speed up is noticeable at least for 3D arrays.
This class is used for the implementation of the recurrent neural networks "MSERNNet" in package "ReClaM".
Definition at line 86 of file ArrayTable.h.
| ArrayTable< T >::operator T * | ( | ) | [inline] |
Casts current 1-dimensional ArrayTable object to C-style array.
When you want to use C-style arrays of type
to store the content of an ArrayTable object, then this operator is used for the correct casting.
// 1-dimensional ArrayTable, allocate memory: ArrayTable< double > a; a.resize( 2 ); // 1-dimensional C-style array, allocate memory: double *b; b = (double *) malloc(2 * sizeof(double)); // Fill ArrayTable "a" with content: ... b = a;
In this example two arrays are used. The first one is of type ArrayTable, the second one is an array as used in C. Later in the program the ArrayTable object is assigned to the C-style array. This assignment needs a casting, where the operator is used.
Definition at line 296 of file ArrayTable.h.
References ArrayTable< T >::A.
| ArrayTable< T >::operator T ** | ( | ) | [inline] |
Casts current 2-dimensional ArrayTable object to C-style array.
When you want to use C-style arrays of type
to store the content of an ArrayTable object, then this operator is used for the correct casting.
// 2-dimensional ArrayTable, allocate memory: ArrayTable< double > a; a.resize( 2, 3 ); // 2-dimensional C-style array: double **b; // Allocate memory for first dimension (C-style): b = (double **) malloc(2 * sizeof(double *)); // Auxiliary variable: double *c; // Allocate memory for second dimension (C-style): for (unsigned i = 0; i < 2; i = i + 1) { c = (double *) malloc(3 * sizeof(double)); b[i] = c; } // Fill ArrayTable "a" with content: ... b = a;
In this example two arrays are used. The first one is of type ArrayTable, the second one is an array as used in C. Later in the program the ArrayTable object is assigned to the C-style array. This assignment needs a casting, where the operator is used.
Definition at line 347 of file ArrayTable.h.
References Array< T >::elemvec(), and ArrayTable< T >::P1.
| ArrayTable< T >::operator T *** | ( | ) | [inline] |
Casts current 3-dimensional ArrayTable object to C-style array.
When you want to use C-style arrays of type
to store the content of an ArrayTable object, then this operator is used for the correct casting.
// 3-dimensional ArrayTable, allocate memory: ArrayTable< double > a; a.resize( 2, 3, 4 ); // 3-dimensional C-style array: double ***b; // Allocate memory for first dimension (C-style): b = (double ***) malloc(2 * sizeof(double **)); // Auxiliary variables: double **c; double *d; // Allocate memory for second dimension (C-style): for (unsigned i = 0; i < 2; i = i + 1) { c = (double **) malloc(3 * sizeof(double *)); // Allocate memory for third dimension (C-style): for (unsigned j = 0; i < 3; j = j + 1) { d = (double *) malloc(4 * sizeof(double)); c[ j ] = d; } b[i] = c; } // Fill ArrayTable "a" with content: ... b = a;
In this example two arrays are used. The first one is of type ArrayTable, the second one is an array as used in C. Later in the program the ArrayTable object is assigned to the C-style array. This assignment needs a casting, where the operator is used.
Definition at line 403 of file ArrayTable.h.
References Array< T >::elemvec(), and ArrayTable< T >::P2.
| Array<T> ArrayTable< T >::A |
Used to store all elements of a 1- to 3-dimensional array (as the element vector Array::e).
When working with 1-dimensional arrays, there is no difference to class Array.
Definition at line 109 of file ArrayTable.h.
Referenced by ArrayTable< T >::operator T *(), ArrayTable< T >::operator()(), ArrayTable< T >::operator=(), and ArrayTable< T >::resize().
| Array<T*> ArrayTable< T >::P1 |
Used for faster access, when working with 2-dimensional arrays.
When working with 2-dimensional arrays, this array of pointers (comparable to Array2D::ptrArrM) to the 1-dimensional arrays in A allows a direct access to rows, faster than achieved by class Array.
Definition at line 130 of file ArrayTable.h.
Referenced by ArrayTable< T >::operator T **(), ArrayTable< T >::operator()(), and ArrayTable< T >::resize().
| Array<T**> ArrayTable< T >::P2 |
Used for faster access, when working with 3-dimensional arrays.
When working with 3-dimensional arrays, this array of pointers to the 2-dimensional arrays in A allows a direct access, faster than achieved by class Array.
Definition at line 150 of file ArrayTable.h.
Referenced by ArrayTable< T >::operator T ***(), ArrayTable< T >::operator()(), and ArrayTable< T >::resize().