gammagl.utils.to_dense_batch¶
- class to_dense_batch(x, batch=None, fill_value=0, max_num_nodes=None)[source]¶
Given a sparse batch of node features \(\mathbf{X} \in \mathbb{R}^{(N_1 + \ldots + N_B) \times F}\) (with \(N_i\) indicating the number of nodes in graph \(i\)), creates a dense node feature tensor \(\mathbf{X} \in \mathbb{R}^{B \times N_{\max} \times F}\) (with \(N_{\max} = \max_i^B N_i\)). In addition, a mask of shape \(\mathbf{M} \in \{ 0, 1 \}^{B \times N_{\max}}\) is returned, holding information about the existence of fake-nodes in the dense representation.
- Parameters:
x (tensor) – Node feature matrix \(\mathbf{X} \in \mathbb{R}^{(N_1 + \ldots + N_B) \times F}\).
batch (tensor) – \(\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N\), which assigns each node to a specific example. Must be ordered. (default:
None
)fill_value (float, optional) – The value for invalid entries in the resulting dense output tensor. (default:
0
)max_num_nodes (int, optional) – The size of the output node dimension. (default:
None
)batch_size (int, optional) – The batch size. (default:
None
)
- Return type:
(
Tensor
,BoolTensor
)