Skip to content

scatter_add

scatter_add(src: array, index: array, values: array)

Scatters values at index within src. If duplicate indices are present, the sum of the values will be assigned to these index.

Parameters:

Name Type Description Default
src array

Source array where the values will be scattered (often an empty array)

required
index array

Array containing indices that determine the scatter of the 'values'.

required
values array

Input array containing values to be scattered.

required

Returns:

Type Description

The resulting array after applying scatter and sum operations on the values at

duplicate indices

Source code in mlx_graphs/utils/scatter.py
def scatter_add(src: mx.array, index: mx.array, values: mx.array):
    """Scatters `values` at `index` within `src`. If duplicate indices are present,
    the sum of the values will be assigned to these index.

    Args:
        src: Source array where the values will be scattered (often an empty array)
        index: Array containing indices that determine the scatter of the 'values'.
        values: Input array containing values to be scattered.

    Returns:
        The resulting array after applying scatter and sum operations on the values at
        duplicate indices
    """
    return src.at[index].add(values)

from mlx_graphs.utils.scatter import scatter_add · mlx_graphs/utils/scatter.py