fill portion of Matrix, Vector, or Array with specified value
Fill(num, val, A, offset, skip)
(optional) number of elements to fill
fill value; must correspond to data type of input Matrix, Vector, or Array
rectangular storage Matrix, Vector, or Array of any data type and ordering
(optional) offset for start of fill
(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.
A ≔ Vectorrow⁡10
Set all entries to 1.
Set every second entry to 2.
Set every second entry to 3 starting at an offset of 1.
M ≔ Matrix⁡6,10,order=C_order
Set all entries to 2.
Set first 20 entries to 3.
Set second-last row to zero.
Set third column to 5.
M ≔ Matrix⁡6,10,order=Fortran_order
Set first 12 entries to 3.
Download Help Document