Expanding ILArrays

ILArray objects are capable of expanding its size during its lifetime. This is automatically done on attempts to assign values to elements addressed outside the bounds of the array.

In the next example we expand an array from [4 x 3] to [4 x 6].

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
 
// expand A by assigning a value 
A["2;5"] = 10.0;  

// A is now:
//  (:,:) 1e+001 * 
//  0,10000   0,50000   0,90000   0,00000   0,00000   0,00000 
//  0,20000   0,60000   1,00000   0,00000   0,00000   0,00000 
//  0,30000   0,70000   1,10000   0,00000   0,00000   1,00000 
//  0,40000   0,80000   1,20000   0,00000   0,00000   0,00000 

In the example the array is expanded along the second dimension. New elements not addressed are set to zero.

Expanding can be done on multiple dimensions the same time.

It is recommended to specify all dimensions explicitly for expanding ILArrays. Trailing (singleton) dimensions should not be ommited!

Performance considerations

Expanding ILArrays the way described above is a relatively expensive operation! It involves copying existing elements to a new array of the (expanded) destination size. Therefore it is always recommended, to avoid expanding if possible. You'd better create the working arrays neccessary of the maximum size expected and use this large array for assignment operations. However, if the size of the problem is not known in advance, expanding arrays this way might be a solution. Another solution could be to use collection classes, inherently capable of dynamically changing their size.
The expanding functionality is mainly implemented for compatibility reasons.

Valid CSS! Valid XHTML 1.0 Transitional