Reshaping ILArrays
The shape of ILArray objects can be changed without recreating the whole array. This is done by use of the
member function Reshape(params int[] dimensions) of ILArray instances.
The number of elements in the array must not change during that operation.
In the next example we change the size of an array from [4 x 3] to [3 x 4]. Notice that this is not the same as a simple transpose. The example will make this clear:
ILArray<double> A = ILMath.counter(4,3);
// A is now:
// (:,:) 1e+001 *
// 0,10000 0,50000 0,90000
// 0,20000 0,60000 1,00000
// 0,30000 0,70000 1,10000
// 0,40000 0,80000 1,20000
// reshape the size of A -> [3 x 4]
A.Reshape(new ILDimension(4,3));
// A is now:
//(:,:) 1e+001 *
// 0,10000 0,40000 0,70000 1,00000
// 0,20000 0,50000 0,80000 1,10000
// 0,30000 0,60000 0,90000 1,20000
The function Reshape works implace on the instance it belongs to. No assignment is nesseccary! Arrays of arbitrary shape can get reshaped this way. The cost for such an operation is relatively small. No element values will be copied.
This operation is smoothly integrated into the referencing model of ILNumerics.Net. If references to the array to be reshaped exist, they will not be bothered from this operation.