README.md 2.38 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
[pypi-image]: https://badge.fury.io/py/torch-scatter.svg
[pypi-url]: https://pypi.python.org/pypi/torch-scatter
rusty1s's avatar
rusty1s committed
3
4
[build-image]: https://travis-ci.org/rusty1s/pytorch_scatter.svg?branch=master
[build-url]: https://travis-ci.org/rusty1s/pytorch_scatter
rusty1s's avatar
rusty1s committed
5
6
[coverage-image]: https://codecov.io/gh/rusty1s/pytorch_scatter/branch/master/graph/badge.svg
[coverage-url]: https://codecov.io/github/rusty1s/pytorch_scatter?branch=master
rusty1s's avatar
rusty1s committed
7

rusty1s's avatar
rusty1s committed
8
9
10
11
12
# PyTorch Scatter

[![PyPI Version][pypi-image]][pypi-url]
[![Build Status][build-image]][build-url]
[![Code Coverage][coverage-image]][coverage-url]
rusty1s's avatar
rusty1s committed
13

rusty1s's avatar
rusty1s committed
14
<p align="center">
rusty1s's avatar
smaller  
rusty1s committed
15
  <img width="50%" src="https://raw.githubusercontent.com/rusty1s/pytorch_scatter/master/docs/source/_figures/add.svg?sanitize=true" />
rusty1s's avatar
rusty1s committed
16
17
18
19
</p>

--------------------------------------------------------------------------------

rusty1s's avatar
rusty1s committed
20
21
**[Documentation](http://rusty1s.github.io/pytorch_scatter)**

rusty1s's avatar
rusty1s committed
22
23
24
This package consists of a small extension library of highly optimised sparse update (scatter) operations for the use in [PyTorch](http://pytorch.org/), which are missing in the main package.
Scatter-operations can be roughly described as reduce-operations based on a given "group-index" tensor.
The package consists of the following operations:
rusty1s's avatar
rusty1s committed
25

rusty1s's avatar
typo  
rusty1s committed
26
* [**Scatter Add**](https://rusty1s.github.io/pytorch_scatter/functions/add.html)
rusty1s's avatar
typo  
rusty1s committed
27
28
29
30
31
32
* [**Scatter Sub**](https://rusty1s.github.io/pytorch_scatter/functions/sub.html)
* [**Scatter Mul**](https://rusty1s.github.io/pytorch_scatter/functions/mul.html)
* [**Scatter Div**](https://rusty1s.github.io/pytorch_scatter/functions/div.html)
* [**Scatter Mean**](https://rusty1s.github.io/pytorch_scatter/functions/mean.html)
* [**Scatter Min**](https://rusty1s.github.io/pytorch_scatter/functions/min.html)
* [**Scatter Max**](https://rusty1s.github.io/pytorch_scatter/functions/max.html)
rusty1s's avatar
rusty1s committed
33

rusty1s's avatar
rusty1s committed
34
All included operations work on varying data types, are implemented both for CPU and GPU and include a backwards implementation.
rusty1s's avatar
rusty1s committed
35

rusty1s's avatar
rusty1s committed
36
37
## Installation

rusty1s's avatar
typo  
rusty1s committed
38
```
rusty1s's avatar
rusty1s committed
39
pip install cffi torch-scatter
rusty1s's avatar
rusty1s committed
40
41
```

rusty1s's avatar
rusty1s committed
42
## Example
rusty1s's avatar
rusty1s committed
43

rusty1s's avatar
rusty1s committed
44
45
46
```py
from torch_scatter import scatter_max

rusty1s's avatar
typos  
rusty1s committed
47
48
input = torch.Tensor([[2, 0, 1, 4, 3], [0, 2, 1, 3, 4]])
index = torch.LongTensor([[4, 5, 4, 2, 3], [0, 0, 2, 2, 1]])
rusty1s's avatar
rusty1s committed
49

Matthias Fey's avatar
Typo  
Matthias Fey committed
50
max, argmax = scatter_max(index, input, dim=1)
rusty1s's avatar
typo  
rusty1s committed
51
```
rusty1s's avatar
rusty1s committed
52

rusty1s's avatar
typo  
rusty1s committed
53
```
rusty1s's avatar
typos  
rusty1s committed
54
55
56
57
print(max)
 0  0  4  3  2  0
 2  4  3  0  0  0
[torch.FloatTensor of size 2x6]
rusty1s's avatar
rusty1s committed
58

rusty1s's avatar
typos  
rusty1s committed
59
60
61
62
63
print(argmax)
-1 -1  3  4  0  1
 1  4  3 -1 -1 -1
[torch.LongTensor of size 2x6]
```
rusty1s's avatar
rusty1s committed
64
65
66

## Running tests

rusty1s's avatar
typo  
rusty1s committed
67
```
rusty1s's avatar
rusty1s committed
68
69
python setup.py test
```