Skip to content

scatter_max

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

Scatters values at index within src. If duplicate indices are present, the maximum value is kept at these indices.

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 max operations on the values at

duplicate indices

Source code in mlx_graphs/utils/scatter.py
def scatter_max(src: mx.array, index: mx.array, values: mx.array):
    """Scatters `values` at `index` within `src`. If duplicate indices are present,
    the maximum value is kept at these indices.

    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 max operations on the values at
        duplicate indices
    """
    out = _scatter_extremum(src.shape, index, values, "max")
    count = broadcast(degree(index, src.shape[0]), out, 0)
    return mx.where(count > 0, out, src)

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