ArrayTools[Fill] - fill portion of Matrix, Vector, or Array with specified value
|
Calling Sequence
|
|
Fill(num, val, A, offset, skip)
|
|
Parameters
|
|
num
|
-
|
(optional); number of elements to fill
|
val
|
-
|
fill value; must correspond to data type of input Matrix, Vector, or Array
|
A
|
-
|
rectangular storage Matrix, Vector, or Array of any data type and ordering
|
offset
|
-
|
(optional); offset for start of fill
|
skip
|
-
|
(optional); fill every 'skip'th element. Can be specified only if offset specified
|
|
|
|
|
Description
|
|
•
|
The Fill command sets entries of the input Matrix, Vector, or Array A to the specified value val. The value must be of the same type as the input Matrix, Vector, or Array, or an error results. In addition, the input Matrix, Vector, or Array must have rectangular (dense) storage.
|
•
|
The additional parameters, num, offset, and skip, extend Fill command usage. For example, you can set every second element in a Vector, a specific row or column in a Matrix, all entries [4,*,*] in a C_order Array.
|
|
The use of these additional parameters is a programmer level feature, and requires detailed knowledge of the storage structure of multi-dimensional rtables under different data orderings (C_order and Fortran_order). For a description of storage under these orderings, see Fortran_order.
|
•
|
Knowledge of these storage schemes becomes required when you want to compute the num, offset, and skip values to fill a row or column of a Matrix using the Fill command.
|
|
Filling the third column of a 6 x 10 C_order Matrix corresponds to acting on the elements for i from 1 to 6.
|
|
- num is the number of elements to fill, which is 6
|
|
- offset is the offset of the first element to be filled, which is (3-1)=2
|
|
- skip is the distance between consecutive elements (the multiplier of the 'i' above), which is 10.
|
|
The resulting command is Fill(6,val,A,2,10).
|
|
In contrast, the same operation for a 6 x 10 Fortran_order Matrix corresponds to acting on the elements for i from 1 to 6. In this case the command is Fill(6,val,A,12,1), which can be abbreviated to Fill(6,val,A,12). This is shown in the following examples.
|
•
|
The default values of the optional parameters are described as follows.
|
|
- offset is 0 (start at the very beginning)
|
|
- skip is 1 (fill all consecutive elements)
|
|
- num is chosen so that the operation does not exceed the storage of the rtable
|
•
|
This function is part of the ArrayTools package, so it can be used in the short form Fill(..) only after executing the command with(ArrayTools). However, it can always be accessed through the long form of the command by using ArrayTools[Fill](..).
|
|
|
Examples
|
|
>
|
|
Vector
>
|
|
| (1) |
Set all entries to 1.
>
|
|
>
|
|
| (2) |
Set every second entry to 2.
>
|
|
>
|
|
| (3) |
Set every second entry to 3 starting at an offset of 1.
>
|
|
>
|
|
| (4) |
C_order Matrix
>
|
|
| (5) |
Set all entries to 2.
>
|
|
>
|
|
| (6) |
Set first 20 entries to 3.
>
|
|
>
|
|
| (7) |
Set second-last row to zero.
>
|
|
>
|
|
| (8) |
Set third column to 5.
>
|
|
>
|
|
| (9) |
Fortran_order Matrix
>
|
|
| (10) |
Set all entries to 2.
>
|
|
>
|
|
| (11) |
Set first 12 entries to 3.
>
|
|
>
|
|
| (12) |
Set second-last row to zero.
>
|
|
>
|
|
| (13) |
Set third column to 5.
>
|
|
>
|
|
| (14) |
|
|