A dense representation stores every position in a graph’s adjacency matrix, including zero entries, and keeps node features in a complete two-dimensional tensor. It is most useful when many vertices connect to one another and faster computation justifies higher memory use. section 7.5
In PyTorch Geometric, dense graph storage typically means:
- An N × N tensor stores the entire adjacency matrix for N nodes, including zero and nonzero elements. section 7.5
- An N × F tensor stores features for N nodes and F features per node. section 7.5
- Memory usage grows with the full matrix, but computation can be faster when the graph has a high percentage of nonzero adjacency entries. section 7.5
- Sparse representation provides the contrasting strategy by storing only nonzero adjacency entries, such as COO coordinates and values. section 7.5
Choosing a graph storage format
For a densely connected graph, retaining the complete N × N adjacency tensor can favor computation speed. For a graph with few connections, storing only nonzero entries can reduce memory requirements, although some operations may run more slowly. section 7.5 section 7.11
torch_geometric.transforms import ToSparseTensor dataset = YourDataset(transform=ToSparseTensor())
Inspect the PyG transform pattern for converting a dense dataset to sparse storage when memory becomes the limiting constraint. section 7.5
