From b312d95896ab35a1b1f2b6c3d3d3ae5d436e18eb Mon Sep 17 00:00:00 2001 From: Reed Johns <115313701+vertumnal@users.noreply.github.com> Date: Mon, 8 Dec 2025 18:22:38 -0700 Subject: [PATCH 1/3] Validate edge weights in Graclus clustering Added validation to check for negative edge weights in Graclus clustering. --- torch_cluster/graclus.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/torch_cluster/graclus.py b/torch_cluster/graclus.py index 7fa834d6..5f6aeb86 100644 --- a/torch_cluster/graclus.py +++ b/torch_cluster/graclus.py @@ -51,6 +51,9 @@ def graclus_cluster( row, col = row[perm], col[perm] if weight is not None: + if (weight < 0).any().item(): + raise ValueError(f"PyG's implementation of Graclus clustering " + f"does not support negative edge weights.") weight = weight[perm] deg = row.new_zeros(num_nodes) From d5e4fef163457f4423616acfbc705c1315209085 Mon Sep 17 00:00:00 2001 From: Reed Johns <115313701+vertumnal@users.noreply.github.com> Date: Mon, 8 Dec 2025 18:35:09 -0700 Subject: [PATCH 2/3] Prevent negative edge weights in Graclus Change to flake8 standards and move to first weight is not None call --- torch_cluster/graclus.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/torch_cluster/graclus.py b/torch_cluster/graclus.py index 5f6aeb86..7ed75aee 100644 --- a/torch_cluster/graclus.py +++ b/torch_cluster/graclus.py @@ -39,6 +39,9 @@ def graclus_cluster( row, col = row[mask], col[mask] if weight is not None: + if (weight < 0).any().item(): + raise ValueError(f"PyG's implementation of Graclus clustering " + f"does not support negative edge weights.") weight = weight[mask] # Randomly shuffle nodes. @@ -51,9 +54,6 @@ def graclus_cluster( row, col = row[perm], col[perm] if weight is not None: - if (weight < 0).any().item(): - raise ValueError(f"PyG's implementation of Graclus clustering " - f"does not support negative edge weights.") weight = weight[perm] deg = row.new_zeros(num_nodes) From 2c104c7a995829f6b189069810f81449db1ea70f Mon Sep 17 00:00:00 2001 From: Reed Johns <115313701+vertumnal@users.noreply.github.com> Date: Mon, 8 Dec 2025 19:23:58 -0700 Subject: [PATCH 3/3] Implement error check for negative edge weights Fix flake8 formatting --- torch_cluster/graclus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/torch_cluster/graclus.py b/torch_cluster/graclus.py index 7ed75aee..ef73df6f 100644 --- a/torch_cluster/graclus.py +++ b/torch_cluster/graclus.py @@ -40,8 +40,8 @@ def graclus_cluster( if weight is not None: if (weight < 0).any().item(): - raise ValueError(f"PyG's implementation of Graclus clustering " - f"does not support negative edge weights.") + raise ValueError("PyG's implementation of Graclus clustering " + "does not support negative edge weights.") weight = weight[mask] # Randomly shuffle nodes.