topobench.nn.backbones.graph.nsd_utils.laplace module#
Utilities for computing Laplacian indices and operations.
This module provides efficient functions for computing indices required for sheaf Laplacian construction and sparse matrix operations.
- compute_learnable_diag_laplacian_indices(size, edge_index, learned_d, total_d)#
Compute sparse indices for a learnable Laplacian with diagonal matrices.
Generates indices for both diagonal and non-diagonal blocks of a block-structured Laplacian matrix where each block is diagonal (learned_d x learned_d).
- Parameters:
- sizeint
Number of nodes in the graph.
- edge_indextorch.Tensor
Edge indices of shape [2, num_edges] where edge_index[0] < edge_index[1].
- learned_dint
Dimension of each learned diagonal block.
- total_dint
Total dimension per node (typically equal to learned_d).
- Returns:
- diag_indicestorch.Tensor
Sparse indices for diagonal blocks, shape [2, size * learned_d].
- non_diag_indicestorch.Tensor
Sparse indices for non-diagonal blocks, shape [2, num_edges * learned_d].
- compute_learnable_laplacian_indices(size, edge_index, learned_d, total_d)#
Compute sparse indices for a learnable Laplacian with full matrices.
Generates indices for both diagonal and non-diagonal blocks of a block-structured Laplacian matrix where each block is learned_d x learned_d.
- Parameters:
- sizeint
Number of nodes in the graph.
- edge_indextorch.Tensor
Edge indices of shape [2, num_edges] where edge_index[0] < edge_index[1].
- learned_dint
Dimension of each learned block matrix.
- total_dint
Total dimension per node (typically equal to learned_d).
- Returns:
- diag_indicestorch.Tensor
Sparse indices for diagonal blocks, shape [2, size * learned_d * learned_d].
- non_diag_indicestorch.Tensor
Sparse indices for non-diagonal blocks, shape [2, num_edges * learned_d * learned_d].
- compute_left_right_map_index(edge_index, full_matrix=False)#
Compute indices for mapping edges to their reverse edges.
For each edge in the lower triangular part (source < target) or all edges, find the index of its corresponding reverse edge in the original edge list.
- Parameters:
- edge_indextorch.Tensor
Edge indices of shape [2, num_edges] representing directed edges.
- full_matrixbool, optional
If True, use all edges. If False, only use edges where source < target. Default is False.
- Returns:
- left_right_indextorch.Tensor
Indices of shape [2, num_selected_edges] where first row contains indices of selected edges and second row contains indices of their reverse edges.
- new_edge_indextorch.Tensor
Edge indices of selected edges, shape [2, num_selected_edges].
- mergesp(index1, value1, index2, value2)#
Merge two sparse matrices with disjoint indices into one.
Concatenates two sets of sparse matrix indices and values, assuming the indices are disjoint (no overlapping entries).
- Parameters:
- index1torch.Tensor
First set of sparse indices, shape [2, num_entries1].
- value1torch.Tensor
First set of values, shape [num_entries1].
- index2torch.Tensor
Second set of sparse indices, shape [2, num_entries2].
- value2torch.Tensor
Second set of values, shape [num_entries2].
- Returns:
- indextorch.Tensor
Merged sparse indices, shape [2, num_entries1 + num_entries2].
- valtorch.Tensor
Merged values, shape [num_entries1 + num_entries2].