|
16 | 16 | This package consists of a small extension library of optimized sparse matrix operations for the use in [PyTorch](http://pytorch.org/), which are missing and or lack autograd support in the main package.
|
17 | 17 | This package currently consists of the following methods:
|
18 | 18 |
|
19 |
| -* **[Autograd Sparse Tensor Creation](#Autograd Sparse Tensor Creation)** |
20 |
| -* **[Autograd Sparse Tensor Value Extraction](#Autograd Sparse Tensor Value Extraction)** |
21 |
| -* **[Sparse Sparse Matrix Multiplication](#Sparse Sparse Matrix Multiplication)** |
| 19 | +* **[Autograd Sparse Tensor Creation](#autograd-sparse-tensor-creation)** |
| 20 | +* **[Autograd Sparse Tensor Value Extraction](#autograd-sparse-tensor-value-extraction)** |
| 21 | +* **[Sparse Sparse Matrix Multiplication](#sparse-sparse-matrix-multiplication)** |
22 | 22 |
|
23 | 23 | All included operations work on varying data types and are implemented both for CPU and GPU.
|
24 | 24 |
|
@@ -47,10 +47,60 @@ If you are running into any installation problems, please follow these [instruct
|
47 | 47 |
|
48 | 48 | ## Autograd Sparse Tensor Creation
|
49 | 49 |
|
| 50 | +``` |
| 51 | +torch_sparse.sparse_coo_tensor(torch.LongTensor, torch.Tensor, torch.Size) -> torch.SparseTensor |
| 52 | +``` |
| 53 | + |
| 54 | +Constructs a [`torch.SparseTensor`](https://pytorch.org/docs/stable/sparse.html) with autograd capabilities w.r.t. `value`. |
| 55 | + |
| 56 | +```python |
| 57 | +from torch_sparse import sparse_coo_tensor |
| 58 | + |
| 59 | +i = torch.tensor([[0, 1, 1], |
| 60 | + [2, 0, 2]]) |
| 61 | +v = torch.Tensor([3, 4, 5], requires_grad=True) |
| 62 | +A = sparse_coo_tensor(i, v, torch.Size([2,3])) |
| 63 | +``` |
| 64 | + |
| 65 | +This method may become obsolete in future PyTorch releases (>= 0.4.1) as reported by this [issue](https://github.com/pytorch/pytorch/issues/9674). |
| 66 | + |
50 | 67 | ## Autograd Sparse Tensor Value Extraction
|
51 | 68 |
|
| 69 | +``` |
| 70 | +torch_sparse.to_value(SparseTensor) --> Tensor |
| 71 | +``` |
| 72 | + |
| 73 | +Wrapper method to support autograd on values of sparse tensors. |
| 74 | + |
| 75 | +```python |
| 76 | +from torch_sparse import to_value |
| 77 | + |
| 78 | +i = torch.tensor([[0, 1, 1], |
| 79 | + [2, 0, 2]]) |
| 80 | +v = torch.Tensor([3, 4, 5], requires_grad=True) |
| 81 | +A = torch.sparse_coo_tensor(i, v, torch.Size([2,3]), requires_grad=True) |
| 82 | +v = to_value(A) |
| 83 | +``` |
| 84 | + |
| 85 | +This method may become obsolete in future PyTorch releases (>= 0.4.1) as reported by this [issue](https://github.com/pytorch/pytorch/issues/9674). |
| 86 | + |
52 | 87 | ## Sparse Sparse Matrix Multiplication
|
53 | 88 |
|
| 89 | +``` |
| 90 | +torch_sparse.spspmm(SparseTensor, SparseTensor) --> SparseTensor |
| 91 | +``` |
| 92 | + |
| 93 | +Sparse matrix product of two sparse tensors with autograd support. |
| 94 | + |
| 95 | +``` |
| 96 | +from torch_sparse import spspmm |
| 97 | +
|
| 98 | +A = torch.sparse_coo_tensor(..., requries_grad=True) |
| 99 | +B = torch.sparse_coo_tensor(..., requries_grad=True) |
| 100 | +
|
| 101 | +C = spspmm(A, B) |
| 102 | +``` |
| 103 | + |
54 | 104 | ## Running tests
|
55 | 105 |
|
56 | 106 | ```
|
|
0 commit comments