IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

scatter_set_constant

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

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.