to_dense_batch
¶
to_dense_batch(
node_features: array,
batch_indices: Optional[array] = None,
fill_value: float = 0.0,
max_num_nodes: Optional[int] = None,
) -> tuple[array, array]
Converts the node features of a batch of graphs to a dense array of shape
[batch_size, max_num_nodes, num_features], padded with fill_value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features
|
array
|
Array of shape |
required |
batch_indices
|
Optional[array]
|
Array of shape |
None
|
fill_value
|
float
|
Value of the padded entries. Default: |
0.0
|
max_num_nodes
|
Optional[int]
|
Number of nodes per graph in the output. Graphs with
more nodes are truncated. Default: |
None
|
Returns:
| Type | Description |
|---|---|
array
|
A tuple |
array
|
|
tuple[array, array]
|
|
tuple[array, array]
|
|
Example:
node_features = mx.array([[1.0], [2.0], [3.0]])
batch_indices = mx.array([0, 0, 1])
dense, mask = to_dense_batch(node_features, batch_indices)
# dense: mx.array([[[1.0], [2.0]], [[3.0], [0.0]]])
# mask: mx.array([[True, True], [True, False]])
Source code in mlx_graphs/utils/dense.py
from mlx_graphs.utils import to_dense_batch · mlx_graphs/utils/dense.py