Skip to main content

Mojo function

scatter_set_constant

scatter_set_constant[data_type: DType, index_type: DType, //, target: StringSlice[StaticConstantOrigin]](data: TileTensor[data_type, data.LayoutType, data.origin, address_space=data.address_space, linear_idx_type=data.linear_idx_type, element_size=data.element_size], indices: TileTensor[index_type, indices.LayoutType, indices.origin, address_space=indices.address_space, linear_idx_type=indices.linear_idx_type, element_size=indices.element_size], fill_value: Scalar[data_type], ctx: DeviceContextPtr)

Scatter the fill_value into the data at the specified indices.

Example: Suppose we have a 3x3 matrix data initialized to zeros:

data = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

And indices is a 2D tensor with shape [2, 2]:

indices = [[0, 1], [2, 0]]

If fill_value is 5, after calling scatter_set_constant, data will be:

data = [[0, 5, 0], [0, 0, 0], [5, 0, 0]]

Arguments: data: The data to scatter the updates into. indices: The indices to scatter the updates into. fill_value: The value to fill the data with. ctx: The device context.

Was this page helpful?