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

How to Scatter the sparse output to a dense tensor? #7

Closed
poodarchu opened this issue May 24, 2019 · 2 comments
Closed

How to Scatter the sparse output to a dense tensor? #7

poodarchu opened this issue May 24, 2019 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@poodarchu
Copy link

No description provided.

@chrischoy chrischoy added enhancement New feature or request question Further information is requested labels May 24, 2019
@chrischoy
Copy link
Contributor

chrischoy commented May 24, 2019

Currently, it does not support the function, but I'll add more efficient version soon.

For now, you can do the following. Make sure that the coordinates are non-negative when you create the sparse_input.

sparse_output = Network(sparse_input)
coordinates = sparse_output.C
out_size = coordinates.max(0)[0] + 1  # get the max indices
out_size = out_size.tolist() + [sparse_output.F.shape[1],]
dense_output = torch.zeros(out_size)
for i, coord in enumerate(coordinates):
    dense_output[tuple(coord)] = sparse_output.F[i]
return dense_output

@poodarchu
Copy link
Author

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants