Skip to content

Instantly share code, notes, and snippets.

@t-vi
Created November 21, 2017 19:05
Show Gist options
  • Save t-vi/b1e455fc93120548be83191f2bd6b45c to your computer and use it in GitHub Desktop.
Save t-vi/b1e455fc93120548be83191f2bd6b45c to your computer and use it in GitHub Desktop.
add.at-like addition using sparse matrices
import torch
indices = torch.LongTensor([[1,1,1],
[2,1,1]]) # must be two dimensional with one row per dimension
values = torch.arange(1,4)
size = torch.Size((3,3))
a = torch.sparse.FloatTensor(indices, values, size)
b = torch.eye(3)
b += a
print (b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment