Cell manipulation

ILCell objects can be altered in different ways:

  • setting elements
  • setting ranges of elements
  • setting elements of internal elements
  • removing dimensions
  • concatenation

Setting elements of ILCell

One may use all the indexing methods known from ILArray<> and from element access in order to set elements into ILCell cells.

example
ILCell C = new ILCell(5,4);
ILCell Ci = new ILCell(20,3); 
ILArray<double> A = new ILArray<double>(100,100);
single index access
// place Ci in first cell element
C[0,0] = Ci; 
string access
// place Ci in first cell element
C["0","1"] = A; // or: 
C["0;1"] = A;  
array index access
ILArray<int> I = new int[0,2,3,4]; 
C[I,null] = A;

Note: here A is an array of size [4 x 3 x 2]. However assigning A to the left side as in the example above will assign it to all elements addressed. Therefore C will now look like this:

ILCell [5,4]

(:,:) [4,3,2] [4,3,2] [4,3,2] [4,3,2] (null) (null) (null) (null) [4,3,2] [4,3,2] [4,3,2] [4,3,2] [4,3,2] [4,3,2] [4,3,2] [4,3,2] [4,3,2] [4,3,2] [4,3,2] [4,3,2]

Notice that from the ILCell array point of view, A will be a "scalar value" since the right side of the expression contains only one array and not a ILCell of arrays. Therefore subsequent copies of A will be stored into all corresponding elements of the cell.

Setting ranges of elements

array range access
// copy the first column to the last
C[I,3] = C[I,0];
string range access
// copy the first column to the last 
C["0,2,3,4;3"] = C["0,2,3,4;0"]

The access method (string/array's) may be mixed for both sides. You can use string access on the left side and array access on the right side and vice versa.

alter internal elements

To alter an element stored as a cell element you may

  • query the element from the ILCell, alter it outside the ILCell and store it back to the cell, or simply
  • alter the element directly inside its cell position. Therefore 'deep referencing' is used. The indices leading to the element in question are given to the indexer of the outer ILCell all together. The index access will crawl down into the ILCell hirarchy directly setting the new value to the element.

The following example explains the syntax in detail.

Example: alter inner cell elements

First we prepare a cell which holds a cell which holds an ILArray<double>.
ILCell C = new ILCell(2,3); 
// than create another cell holding an ILArray<double>,
Ci = new ILCell(2,4); 
Ci[0] = ILMath.rand(4,5);
// store this as inner cell of C
C[0] = Ci; 

Now let's alter a value from the double array! We first demonstrate it "the long way": we get the array, alter it and store it back into the cells.

// query the inner cell
ILCell innerCellR = (ILCell) C[0]; 
ILArray<double> innerArrR = (ILArray<double>)(innerCellR)[0]; 
// do something with the array 
innerArrR["end"] = 999.0; 
// store the array back
innerCellR[0] = innerArrR; 
C[0] = innerCellR; 
Note, all values returned from a ILCell have to be casted into their actual type, since ILCell will always return objects of type ILBaseArray.

Now, we demonstrate the same action with 'deep indexing' access.

C[0,0,0,0,3,4] = 999.0;
You must explicitely specify all dimensions for each cell involved. Only for the most inner element the last dimension(s) may be ommited.

Deep indexing also works for right sides:

ILArray<double> fromCell = (ILArray<double>)C[0,0,0,0,3,4];  
// now returns: 
// (:,:) 1e+002 * 
//  9,99000 

Removal of cell elements

ILCells use the removal functionality of their base type ILArray<> for removal of dimensions. Therefore the syntax is the same here. Removal is done by assigning null to a ranged index access. Use the string index access or the array index access:

ILCell C = new ILCell(4,3,2); 
// remove the first & second columns
C[":;0,1;:"] = null; 
// C is now of size [4,2,2]; 
// remove the 1st rows
C[0,null,null] = null;

value or reference?

Just like querying cell elements gives only copies (or ILNumerics.Net references) of the source elements, setting values into a cell will also create array elements independent of their original arrays. The independence is maintained by the same referencing mechanism responsible for creating references for ILArray<> and for querying elements from ILCell.

For practical situations this means, you never have to worry about altering any arrays which exist inside and outside of an ILCell. The other array respectively will stay the same. However the referencing mechanism will ensure the 'copy' done will be made with the least storage really needed.

Therefore you may think of using ILCells as storing elements 'by value' - even for arrays actually beeing reference types.


Valid CSS! Valid XHTML 1.0 Transitional