normalized_cut broadcasts degree scales over feature channels instead of edges
Describe the bug
normalized_cut documents multi-dimensional edge features, but multiplies an (E, ...) feature tensor by a raw (E,) degree scale. PyTorch aligns that scale with the last feature axis, rather than the edge axis.
(E, F)raises whenF != E(except singleton broadcasting cases).(E, E)silently scales columns rather than rows, producing incorrect values.- Higher-rank features and empty
(0, F)features are affected too.
import torch
from torch_geometric.utils import normalized_cut
edge_index = torch.tensor([[1, 1, 2, 3], [3, 3, 1, 2]])
edge_attr = torch.arange(1., 17.).view(4, 4)
expected = edge_attr * torch.tensor([1.5, 1.5, 2., 1.5]).view(4, 1)
actual = normalized_cut(edge_index, edge_attr)
print(torch.allclose(actual, expected)) # False
normalized_cut(edge_index, torch.ones(4, 2)) # RuntimeErrorThe coefficient follows the documented endpoint-degree formula: destination degrees at nodes 1, 2, 3 are 1, 1, 2, giving edge scales [1.5, 1.5, 2.0, 1.5].
Versions and proposed fix
Current master 79d3396, PyG 2.9.0, torch 2.13.0+cpu, Python 3.14.6, Windows 11. Six new shape/dtype regression cases failed before the patch. Reshape the scale to (E, 1, ...) before multiplication, preserving scalar-edge behavior. A focused patch includes float32/float64, gradients, empty edges, and TorchScript tests.
Codex assisted with reproduction, implementation, tests, and this report. The reported checks were executed locally.
Source: pyg-team/pytorch_geometric