FillOperation
Applicable Products
Hardware Model |
Supported or Not |
|---|---|
Atlas 350 accelerator card |
x |
√ |
|
√ |
|
√ |
|
√ |
|
√ |
Description
Sets a specified position to value or generates a tensor with a specified shape and fills it to value.

- MaskedFill (withMask = true):
For an element in x, if the value of the element in the same location in mask is true or 1, the value of the element in the same location in output is set to value; the values of the elements in other locations in output are the same as those of x. The broadcast function is supported.
Figure 2 Implementation principle of the Fill operator
Figure 3 Implementation principle of the Fill operator (broadcast scenario)
- Fill (withMask = false)
Generates a tensor with the shape specified by outDim. The values of all elements are value.
Definition
1 2 3 4 5 6 | struct FillParam { bool withMask = true; SVector<float> value; SVector<int64_t> outDim; uint8_t rsv[8] = {0}; } |
Parameters
Member |
Type |
Default Value |
Description |
|---|---|---|---|
withMask |
bool |
true |
Masked filing. |
value |
SVector<float> |
[] |
Padded element. value is a SVector containing only one element. |
outDim |
SVector<float> |
[] |
Shape of the output tensor when withMask = false |
rsv[8] |
uint8_t |
{0} |
Reserved |
- withMask = true
Sets the element in the location specified by mask to value.
If the number of input tensors is 2, outDim does not need to be specified.
- withMask = false
Generates a tensor with the shape specified by outDim and fills each element of the tensor with value.
If the number of input tensors is 0, outDim must be specified.
Input
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
x |
[dx_0, ..., dx_n] |
float16/int32/bf16 |
ND |
This parameter is valid only when withMask is set to true. |
mask |
[dmask_0, ..., dmask_m] |
int8/bool |
ND |
This parameter is valid only when withMask is set to true. You can set the values in certain locations to true or 1 to set the value in the same location as x to value. |
Output
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
output |
|
|
ND |
Output tensor. |
Restrictions
- Restrictions on the parameters:
a. value.size() == 1.
- Input and output constraints
- Input x cannot be broadcast.
- Each element of the input mask can only be 0 or 1.
- When withMask is true, the shape of mask must be the same as that of x or can be broadcast to the shape of x.
API Calling Example
- Example 1: MaskedFill non-broadcast scenario
- Input
param.withMask = true param.value = [-1] x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] mask = [[ true, false, true], [false, true, true], [ true, true, false]] - Output
output = [[-1, 2, -1], [ 4, -1, -1], [-1, -1, 9]]
- Input
- Example 2: MaskedFill broadcast scenario
- Input
param.withMask = true param.value = [-1] x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] mask = [true, false, true] - Output
output = [[-1, 2, -1], [-1, 5, -1], [-1, 8, -1]]
- Input
- Example 3: Fill scenario
- Input
param.withMask = false param.value = [1] param.outDim = [2, 3]
- Output
output = [[1, 1, 1], [1, 1, 1]]
- Input