Cell access
Accessing elements of ILCells is usually done by indexer access.
In general the same rules apply here as for ILArray<> subarray access. One may access, query elements
or derive 'subcells' from an ILCell by specifying the range by strings, by integer values or by numerical arrays.
In the following examples we suppose A to be a cell of size A is therefore done by specifying...
- distinct strings for each dimension
A[":","1"]; // gives the elements from the second column from A - one string for all dimensions
A[":;1"]; // gives the elements from the second column from A - single integer numbers
A[2,3]; // gives the element from the 3rd row, last column from A - numerical index arrays (ILArray<[numeric]>/ System.Array, null, etc)
A[I,new int[]{1,2}]; // rows specified by I, 2nd and 3rd column from A
Some considerations are to be made for handling values returned from ILCell index access:
Type of returned elements
In general, if using an index access capable of addressing more than one element - i.e. a range of the ILCell -
the return value will be of type ILCell itself. If the access method is able to address only one element,
the return type is ILBaseArray. The real type - of course - will be the actual type of the cell addressed, which mostly
will be a ILArray<>.
| Access method | return type |
|---|---|
| A[":","3"] | ILCell |
| A[":,3"] | ILCell |
| A[null,new int[]{4,3,2,3,4}] | ILCell |
| A[2,1] | ILBaseArray |
Value or reference?
Values returned from ILCells will be a deep copy of the contents of addressed elements. What does 'deep copy' mean?
The need arises, having taken values from the ILCell, modifying them must preserve the source value inside the ILCell.
Therefore the value(s) returned from an ILCell must be detached from the ILCell elements. Since ILNumerics.Net
implements a comprehensive referencing model, why not use it for this purpose?
Since all objects of type ILBaseArray support the CreateReference() member and therefore are able to built references, that
capability is used. The values taken out of the ILCell will be a reference array of the source inside the ILCell elements.
What happens for elements of ILCells which itself store ILCells? In this case the values addressed are recursively be walked
down into the inner elements of the ILCell, creating a so called 'deep reference'. The result will then be returned.
All this mechanism is completely hidden from the user. You dont want to worry about copying any data. Just imagine the values returned beeing returned 'by value' and lay back trusting them to consume as little memory as possible.
Sequential addressing / deep index addressing
In order to access elements of elements of ILCell one may use one of the following ways:
- address the needed element from the top layer. From the return value address the element needed and so forth....
// C is a ILCell of size 3 x 2 // the element at position 0,0 is itself a cell of size 5 x 5 C[0,0][1,2] -> walk inside the element - the use of multiple index accesses sequentially can be abbreviated by specifying the indices of the inner elements all together:
// let's take the same cell as in the previous example C[0,0,1,2] -> will give the same result as the sample above.
ILCell. More about cell manipulation is found in the next section.