Altering ranges of elements

Ranged element addressing is used to address elements of ILArray beeing ordered in a regular way. Here the same rules applies as for subarray creation. You may specify any ranges for each dimension of the array. The specification of indices for each dimension is done by strings or by ILBaseArrays.

For altering ranged elements one may use one of the following functions. They are basically the same as for sequential addressing, but more than one specifier is supplied to the variable argument list for each dimension.

  • ILArrays member function SetRange(ILRange range, ILArray<BaseT> values),
  • the indexer this[params ILBaseArray[] range] = values
  • the indexer this[params string[] range] = values

The SetRange function expects a range definition of type ILRange. Ranges can be created by variable arguments of type string[] or ILBaseArray. See the online class documentation for details on the ILRange constructors.

The most convenient way to alter ranges of elements is to use one of the indexer available. The same rules applies here as for subarray creation. The syntax is the same, except it is supplied to the indexer argument on the left side.

ILArray<double> A = ILMath.ones(4,3);
ILArray<int> ind = new int[]{0,1,2};
// A is now:
//(:,:)
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000

// set elements of the second row to 5,4,3
A["1","0,1,2"] = new double[]{5,4,3}; 
// - or - 
A["1;:"] = new double[]{5,4,3}; 
// - or - 
A[1,null] = new double[]{5,4,3}; 
// - or - 
A[1,ind] = new double[]{5,4,3}; 

// A is now:
//(:,:)
// 1,00000   1,00000   1,00000
// 5,00000   4,00000   3,00000 
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000

In the code above both indexers are shown: string and ILBaseArray specification. Notice the use of placeholders like null and ":" to address a full dimension. See the subarray creation tutorial for a complete specification of valid syntax elements.

Simultaneously using range and sequential addressing

For the operations above the range index specifiers for each dimension must lay inside the bounds of the corresponding dimension. There is one exception to this rule: if the number of dimensions specified is less then the actual number of dimensions, the last dimension specifier may address indices outside the bounds of the corresponding dimension. The last dimension specifier will than be interpreted as sequential indices. This behaviour is the same as described in reshaping subarray creation. It can be imagined as having the trailing dimensions of the array joint together, and after having accessed the elements, changed the array back to its original shape.
ILArray<double> A = ILMath.ones(4,3,2);
ILArray<int> ind = new int[]{0,1,2};
// A is now:
//(:,:,0)
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
//
//(:,:,1)
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000
// 1,00000   1,00000   1,00000

// access one element by sequential index for dimension 2: 
A["1;4"] = 10.0;

// A is now: 
//(:,:,0) 1e+001 * 
//  0,10000   0,10000   0,10000 
//  0,10000   0,10000   0,10000 
//  0,10000   0,10000   0,10000 
//  0,10000   0,10000   0,10000 
//
//(:,:,1) 1e+001 * 
//  0,10000   0,10000   0,10000 
//  0,10000   1,00000   0,10000 
//  0,10000   0,10000   0,10000 
//  0,10000   0,10000   0,10000 

Notice the index specification for dimension 2 actually lays outside the length of the dimension (which has length 3). However, since this is the last dimension specified, the index is interpreted as sequential address into the joint dimensions 2 + 3. The destination element addressed by indices [1,4] inside array A is therefore found at index [1,1,1].

This kind of mixed sequential indexing is valid for both: string and ILBaseArray arguments. It can also be used for arrays of arbitrary shape and with arbitrary number of dimensions.

Further readings: subarray creation tutorial


Valid CSS! Valid XHTML 1.0 Transitional