3D arrays

Definition

3D arrays are instances of the class Array3D. Class Array3D is a template class: Array3D<T, Allocator>. As for vectors, T is the type of the elements to be stored (e.g. double). Allocator defines the way memory is managed. It is close to STL allocators. See the section "Allocators" for further details.

Declaration

There is a default Allocator (see the section "Allocators"). It means that the last template parameter may be omitted. Then a 3D array of integers may be declared thanks to the line:

Array3D<int> A;

This defines an array of size 0 x 0 x 0, that is to say an empty array. To define a 3D array of size 5 x 3 x 6, one may write:

Array3D<int> A(5, 3, 6);

Use of 3D arrays

Only a few methods are available for 3D arrays because they are not the main concern of Seldon. Mainly, the access to elements is achieved through the operator(int, int, int), and indices start at 0:

Array3D<double> A(5, 6, 3);
A(0, 1, 3) = -3.1;
A(0, 0, 5) = 1.2 * A(0, 1, 3);

One may point out some methods:

  • GetLength1(), GetLength2() and GetLength3() return lengths in dimensions #1, #2 and #3.
  • Fill fills with 0, 1, 2, 3, etc. or fills the array with a given value.
  • Reallocate resizes the array (warning, data may be lost, depending on the allocator).
  • Copy enables to duplicate an array.
A comprehensive test of this class is done in file test/program/array3d_test.cpp.