liveBook · Manning

Dense representation

As explained in Graph Neural Networks in Action

A dense representation explicitly stores entries for all possible relationships or attribute positions, including zeros or absent values.

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

How Graph Neural Networks in Action covers it

How deep it goes
Defines adjacency and feature tensor shapes, contrasts sparse storage, and stops short of algorithm internals or benchmark results.
Examples
Uses N × N adjacency tensors, N × F feature tensors, and COO storage as contrasting representation examples.
What you can do after
Evaluate dense versus sparse PyG storage using graph connectivity, memory requirements, and computation speed.
How it connects
Connects adjacency matrices, node features, sparse representation, PyTorch Geometric, and graph-scale optimization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.