scatter
¶
scatter(
values: array,
index: array,
out_size: Optional[int] = None,
aggr: ScatterAggregations = "add",
axis: int = 0,
) -> array
Default function for performing all scattering operations.
Scatters values at index in an empty array of out_size elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
array
|
array with all the values to scatter in the output tensor |
required |
index
|
array
|
array with index to which scatter the values |
required |
out_size
|
Optional[int]
|
number of elements in the output array (size of the first dimension).
If not provided, uses the number of elements in |
None
|
aggr
|
ScatterAggregations
|
scattering method employed for reduction at index:
|
'add'
|
axis
|
int
|
axis on which applying the scattering |
0
|
Returns:
| Type | Description |
|---|---|
array
|
Array with |
array
|
following the given |
Example:
src = mx.array([1., 1., 1., 1.])
index = mx.array([0, 0, 1, 2])
num_nodes = src.shape[0]
scatter(src, index, num_nodes, "softmax")
>>> mx.array([0.5, 0.5, 1, 1])
num_nodes = index.max().item() + 1
scatter(src, index, num_nodes, "add")
>>> mx.array([2, 1, 1])
Source code in mlx_graphs/utils/scatter.py
from mlx_graphs.utils.scatter import scatter · mlx_graphs/utils/scatter.py