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[ImmStaticOrigin]](data: TileTensor[data_type, Storage=data.Storage, address_space=data.address_space, linear_idx_type=data.linear_idx_type], indices: TileTensor[index_type, Storage=indices.Storage, address_space=indices.address_space, linear_idx_type=indices.linear_idx_type], 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]]

Parameters:

  • ​data_type (DType): Element type of data and fill_value.
  • ​index_type (DType): Integral element type of the indices tensor.
  • ​target (StringSlice[ImmStaticOrigin]): Target backend to execute on, such as "cpu" or "cuda".

Args:

Was this page helpful?