ArrayTools
Fill
fill portion of Matrix, Vector, or Array with specified value
Calling Sequence
Parameters
Description
Thread Safety
Examples
Fill(num, val, A, offset, skip)
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
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 multidimensional 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 10⁢i−1+3−1 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 i−1+6⁢3−1 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](..).
The Fill command is thread safe as of Maple 2023, provided that the rtable A is not shared between threads.
For more information on thread safety, see index/threadsafe.
with⁡ArrayTools:
Vector
A≔Vectorrow⁡10
A≔0000000000
Set all entries to 1.
Fill⁡1,A
1111111111
Set every second entry to 2.
Fill⁡5,2,A,0,2
2121212121
Set every second entry to 3 starting at an offset of 1.
Fill⁡3,A,1,2
2323232323
C_order Matrix
M≔Matrix⁡6,10,order=C_order
M≔000000000000000000000000000000000000000000000000000000000000
Set all entries to 2.
Fill⁡2,M
M
222222222222222222222222222222222222222222222222222222222222
Set first 20 entries to 3.
Fill⁡20,3,M
333333333333333333332222222222222222222222222222222222222222
Set second-last row to zero.
Fill⁡10,0,M,40
333333333333333333332222222222222222222200000000002222222222
Set third column to 5.
Fill⁡6,5,M,2,10
335333333333533333332252222222225222222200500000002252222222
Fortran_order Matrix
M≔Matrix⁡6,10,order=Fortran_order
Set first 12 entries to 3.
Fill⁡12,3,M
332222222233222222223322222222332222222233222222223322222222
Fill⁡10,0,M,4,6
332222222233222222223322222222332222222200000000003322222222
Fill⁡6,5,M,12
335222222233522222223352222222335222222200500000003352222222
See Also
C_order
Fortran_order
Matrix
Download Help Document