Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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: 3 additions & 3 deletions torch_geometric/utils/_subgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def subgraph(
else:
num_nodes = subset.size(0)
node_mask = subset
subset = node_mask.nonzero().view(-1)
subset = node_mask.nonzero_static(size=num_nodes).view(-1)

edge_mask = node_mask[edge_index[0]] & node_mask[edge_index[1]]
edge_index = edge_index[:, edge_mask]
Expand Down Expand Up @@ -219,15 +219,15 @@ def bipartite_subgraph(
else:
src_size = src_subset.size(0)
src_node_mask = src_subset
src_subset = src_subset.nonzero().view(-1)
src_subset = src_subset.nonzero_static(size=src_size).view(-1)

if dst_subset.dtype != torch.bool:
dst_size = int(edge_index[1].max()) + 1 if size is None else size[1]
dst_node_mask = index_to_mask(dst_subset, size=dst_size)
else:
dst_size = dst_subset.size(0)
dst_node_mask = dst_subset
dst_subset = dst_subset.nonzero().view(-1)
dst_subset = dst_subset.nonzero_static(size=dst_size).view(-1)

edge_mask = src_node_mask[edge_index[0]] & dst_node_mask[edge_index[1]]
edge_index = edge_index[:, edge_mask]
Expand Down
2 changes: 1 addition & 1 deletion torch_geometric/utils/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def index_to_mask(index: Tensor, size: Optional[int] = None) -> Tensor:
index = index.view(-1)
size = int(index.max()) + 1 if size is None else size
mask = index.new_zeros(size, dtype=torch.bool)
mask[index] = True
mask.scatter_(0, index, True)
return mask


Expand Down