Reshaping subarray creation

One special case we still left out here. If the number of dimension specifier is less then the actual number of dimensions in the array, the subarray returned will reshape and extend the last dimension by trailing dimensions - joint together. In that special case the algorithm of subarray creation can be seen as follows:
  • reshape the original array by reducing its dimension to the number of given dimension specifications.
  • In order to fit all elements inside the new shape, the last dimension will pick up all elements from trailing dimensions and therefore expand accordingly.
  • indices into that last dimension will refer to the new dimension length.

Lets take an example again.
Example 7 (C#)
ILArray<double> A = ILMath.counter(4,3,2);
/* this recreates the 3-d array from the last example:
A
{<double> 44148697 [4x3x2] Phys.
(:,:,0)
1,00000 5,00000 9,00000
2,00000 6,00000 10,00000
3,00000 7,00000 11,00000
4,00000 8,00000 12,00000

(:,:,1)
13,00000 17,00000 21,00000
14,00000 18,00000 22,00000
15,00000 19,00000 23,00000
16,00000 20,00000 24,00000
}

A now has 3 dimensions. We only specify 2 of them:
A[":;:"]
{<Double> 10972427 [4x6] Ref(3) 
(:,:) 
 1,00000  5,00000   9,00000  13,00000  17,00000  21,00000 
 2,00000  6,00000  10,00000  14,00000  18,00000  22,00000 
 3,00000  7,00000  11,00000  15,00000  19,00000  23,00000 
 4,00000  8,00000  12,00000  16,00000  20,00000  24,00000 
}
Notice, the last dimension has joined with the second dimension which is now twice as long.
A["end;1:end"] -> evaluates to:
{<Double> 6130944 [1x5] Phys. 
(:,:)
8,00000  12,00000  16,00000  20,00000  24,00000
}
Now lets only specify one single dimension:

A[1,"end:-5:0"]
{<Double> 23469 [5x1] Phys. (:,:) 24,00000 19,00000 14,00000 9,00000 4,00000 }
Internally the array is first reshaped from a [4 x 3 x 2] array to a [24 x 1] vector. The indices given will then get evaluated. A counter is created starting from end (23) stepping backwards with stepwidth 5 until 0 is exceeded. Those numbers are than used to create the subarray as a column in the first dimension. That column vector is than shifted by 1 dimension before returned. For a column vector such a dimension shift turns the vector into a row vector.

Valid CSS! Valid XHTML 1.0 Transitional