MultidimArray

Implements multidimensional rectangular arrays.

Something like FORTRAN's one.

Constructors

this
this(size_t[n] lengths)
Undocumented in source.
this
this(T[] data, size_t[n] lengths)
Undocumented in source.

Members

Aliases

dimensions
alias dimensions = n

Dimensions of this array.

Functions

opApply
int opApply(int delegate(RepeatTuple!(n, size_t), ref T) dg)

Implements by-element iteration with inidces starting from the top dimension.

opDollar
size_t opDollar()
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
ref opIndex(size_t[n] indices)
auto opIndex(A args)
opIndexAssign
auto opIndexAssign(U value, A args)

Inexing/slicing.

opSlice
R opSlice(size_t from, size_t to)
Undocumented in source. Be warned that the author may not have intended to support it.
opSliceAssign
MultidimArray opSliceAssign(T value)
MultidimArray opSliceAssign(Range value)
MultidimArray opSliceAssign(MultidimArray!(U, n) value)

Implements elements initialisation with a value, where value can be of type T or an input range which front can be assigned to an element. The range should contain exectly elements elements, otherwise an Exception will be thrown.

reorderIndices
auto reorderIndices(size_t[n] newOrder)

Creates a slice of this entire array with reordered indices. newOrder[i] = n means that i-th index of a resulting array will behave like n-th index of the original array. Every index sould be used once, otherwise an Exception will be thrown.

toString
string toString()

Conversion to string function for debugging purposes.

Properties

byElementForward
byElementForward [@property getter]

Returns a forward range which has mutable elements and a length for iteration by an element.

byElementRandomAccess
byElementRandomAccess [@property getter]

Returns a finite random-access range which has mutable elements and a length for iteration by an element.

byFunction
auto byFunction [@property getter]

Returns a forward range which has mutable elements for iteration using indices defined by pred starting from a = 0 and incrementing it while indices are in valid range.

byTopDimension
byTopDimension [@property getter]

Returns a finite random-access range for iteration over the top dimension. It has mutable elements iff dimensions is 1.

dup
dup [@property getter]

Support for dup and idup properties for MultidimArray.

elements
size_t elements [@property getter]

Returns the elements count of the array.

idup
idup [@property getter]

Support for dup and idup properties for MultidimArray.

lengths
const(size_t)[n] lengths [@property getter]

Returns the read only view at its lengths array.

packedDimensions
size_t packedDimensions [@property getter]

Returns the maximum number of tail dimensions without pading. Note, that there can be no such dimensions.

Examples

t
{
	// Let's creates an GC allocated three-dimensional rectangular array from 2 matrices 3x4
	auto matrices = multidimArray!int(2, 3, 4); // matrices has a type MultidimArray!(int, 3)

	// Setting an element at intersection of the first column and
	// the third row of the secon matrix to seven:
	matrices[1, 0, 2] = 7;

	// Filling the whole first column of the secon matrix with sixes:
	matrices[1, 0, 0..$][] = 6;

	// Filling the whole array with fives:
	matrices[] = 5;

	// Iterating the array
	foreach(z, y, x, ref el; matrices) // using opApply
		el = cast(int) (z * 100 + y * 10 + x);

	int c = 0;
	foreach(ref el; matrices.byElementForward)
		el = c++;

	c = 0;
	foreach(i; 0 .. matrices.elements)
		matrices.byElementRandomAccess[i] = c++;

	c = 0;
	foreach(matrix; matrices.byTopDimension)       // for each of two matrices
		foreach(row; matrix.byTopDimension)        // for each row
			foreach(ref el; row.byTopDimension) // for each element
				el = c++;

	c = 0;
	foreach_reverse(ref el; matrices.byElementRandomAccess)
		el = c++;

	c = 0;
	foreach_reverse(i; 0 .. matrices.elements)
		matrices.byElementRandomAccess[i] = c++;

	// Inexing/slicing
	// * use <integer> to select a position
	// * use <integer> .. <integer> to select a range
	// E.g. use 0..$  to select the whole range
	matrices = matrices[0..$, 0..$, 0..$];  // the entire array, same as [0..2, 0..3, 0..4]
	auto array2d = matrices[0, 0..$, 0..$]; // the first matrix
	auto array1d = matrices[0, 1, 0..$];  // the second row of the first matrix
	array1d = matrices[0, 0..$, 1];       // the second column of the first matrix
	matrices[0, 1, 1] = 9;                // setting an element at a crossing of the row an the column

	// first two rows and three columns of the secon matrix
	array2d = matrices[1, 0 .. 2, 0 .. 3

Meta