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

Minor improvement to FakeDataset #4065

Merged
merged 2 commits into from
Feb 11, 2022
Merged
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
17 changes: 10 additions & 7 deletions torch_geometric/datasets/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ def generate_data(self) -> Data:

data = Data()

if self._num_classes > 0 and self.task == 'node':
data.y = torch.randint(self._num_classes, (num_nodes, ))
elif self._num_classes > 0 and self.task == 'graph':
data.y = torch.tensor([random.randint(0, self._num_classes - 1)])

data.edge_index = get_edge_index(num_nodes, num_nodes, self.avg_degree,
self.is_undirected, remove_loops=True)

if self.num_channels > 0:
data.x = torch.randn(num_nodes, self.num_channels)
if self.num_channels > 0 and self.task == 'graph':
data.x = torch.randn(num_nodes, self.num_channels) + data.y
elif self.num_channels > 0 and self.task == 'node':
data.x = torch.randn(num_nodes,
self.num_channels) + data.y.unsqueeze(1)
else:
data.num_nodes = num_nodes

Expand All @@ -85,11 +93,6 @@ def generate_data(self) -> Data:
elif self.edge_dim == 1:
data.edge_weight = torch.rand(data.num_edges)

if self._num_classes > 0 and self.task == 'node':
data.y = torch.randint(self._num_classes, (num_nodes, ))
elif self._num_classes > 0 and self.task == 'graph':
data.y = torch.tensor([random.randint(0, self._num_classes - 1)])

return data


Expand Down