Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Type Hints] utils.normalized_cut #5665

Merged
merged 6 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/utils/test_normalized_cut.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import torch

from torch_geometric.testing import is_full_test
from torch_geometric.utils import normalized_cut


Expand All @@ -11,3 +12,8 @@ def test_normalized_cut():

output = normalized_cut(torch.stack([row, col], dim=0), edge_attr)
assert output.tolist() == expected_output

if is_full_test():
jit = torch.jit.script(normalized_cut)
output = jit(torch.stack([row, col], dim=0), edge_attr)
assert output.tolist() == expected_output
5 changes: 4 additions & 1 deletion torch_geometric/utils/normalized_cut.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from typing import Optional

from torch import Tensor

from torch_geometric.utils import degree


def normalized_cut(edge_index, edge_attr, num_nodes: Optional[int] = None):
def normalized_cut(edge_index: Tensor, edge_attr: Tensor,
num_nodes: Optional[int] = None) -> Tensor:
rusty1s marked this conversation as resolved.
Show resolved Hide resolved
r"""Computes the normalized cut :math:`\mathbf{e}_{i,j} \cdot
\left( \frac{1}{\deg(i)} + \frac{1}{\deg(j)} \right)` of a weighted graph
given by edge indices and edge attributes.
Expand Down