安装torch-scatter

## Installation

### Binaries

We provide pip wheels for all major OS/PyTorch/CUDA combinations, see [here](https://pytorch-geometric.com/whl).

#### PyTorch 1.5.0

To install the binaries for PyTorch 1.5.0, simply run

```
pip install torch-scatter==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-1.5.0.html
```

where `${CUDA}` should be replaced by either `cpu`, `cu92`, `cu101` or `cu102` depending on your PyTorch installation.

|             | `cpu` | `cu92` | `cu101` | `cu102` |
|-------------|-------|--------|---------|---------|
| **Linux**   | ✅    | ✅     | ✅      | ✅      |
| **Windows** | ✅    | ❌     | ✅      | ✅      |
| **macOS**   | ✅    |        |         |         |

#### PyTorch 1.4.0

To install the binaries for PyTorch 1.4.0, simply run

```
pip install torch-scatter==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-1.4.0.html
```

where `${CUDA}` should be replaced by either `cpu`, `cu92`, `cu100` or `cu101` depending on your PyTorch installation.

|             | `cpu` | `cu92` | `cu100` | `cu101` |
|-------------|-------|--------|---------|---------|
| **Linux**   | ✅    | ✅     | ✅      | ✅      |
| **Windows** | ✅    | ❌     | ❌      | ✅      |
| **macOS**   | ✅    |        |         |         |

### From source

Ensure that at least PyTorch 1.4.0 is installed and verify that `cuda/bin` and `cuda/include` are in your `$PATH` and `$CPATH` respectively, *e.g.*:

```
$ python -c "import torch; print(torch.__version__)"
>>> 1.4.0

$ echo $PATH
>>> /usr/local/cuda/bin:...

$ echo $CPATH
>>> /usr/local/cuda/include:...
```

Then run:

```
pip install torch-scatter
```

When running in a docker container without nvidia driver, PyTorch needs to evaluate the compute capabilities and may fail.
In this case, ensure that the compute capabilities are set via `TORCH_CUDA_ARCH_LIST`, *e.g.*:

```
export TORCH_CUDA_ARCH_LIST = "6.0 6.1 7.2+PTX 7.5+PTX"
```

## Example

```py
import torch
from torch_scatter import scatter_max

src = torch.tensor([[2, 0, 1, 4, 3], [0, 2, 1, 3, 4]])
index = torch.tensor([[4, 5, 4, 2, 3], [0, 0, 2, 2, 1]])

out, argmax = scatter_max(src, index, dim=-1)
```

```
print(out)
tensor([[0, 0, 4, 3, 2, 0],
        [2, 4, 3, 0, 0, 0]])

print(argmax)
tensor([[5, 5, 3, 4, 0, 1]
        [1, 4, 3, 5, 5, 5]])
```

## Running tests

```
python setup.py test
```

## C++ API

`torch-scatter` also offers a C++ API that contains C++ equivalent of python models.

```
mkdir build
cd build
# Add -DWITH_CUDA=on support for the CUDA if needed
cmake ..
make
make install
```

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 很高兴能回答您的问题,torch-scatter库是一个PyTorch库,它提供了一系列函数来处理数据中的索引和深度学习中的稀疏数据。它可以用于计算距离,更新索引,扩展索引,处理数据块,处理稀疏数据,进行数据平衡,调整大小,等等。 ### 回答2: torch-scatter库是一个用于在PyTorch中进行稀疏张量的聚合操作的库。在深度学习中,稀疏张量是一种特殊的数据结构,其中大部分元素都是零。与普通的密集张量相比,稀疏张量在存储和计算上更加高效。而torch-scatter库提供了一些方便的函数,可以针对稀疏张量进行聚合操作。 具体来说,torch-scatter库提供了一些常用的聚合函数,如求和、均值、最大值等。这些函数能够对稀疏张量进行聚合计算,并返回聚合结果。与传统的dense tensor相比,对于稀疏张量的聚合计算,torch-scatter库能够更高效地处理,节省内存和计算资源。 该库还提供了一些高级功能,如自定义聚合函数和处理多个输入张量的聚合等。这些功能使得用户可以根据自己的需求,定义并执行复杂的稀疏张量聚合计算。 总的来说,torch-scatter库为PyTorch用户提供了一种便捷而高效的处理稀疏张量的方式,使得稀疏张量的聚合计算更加方便和灵活。同时,该库也为深度学习领域中以稀疏张量为基础的算法研究提供了很好的支持。 ### 回答3: torch-scatter库是PyTorch中的一个扩展库,主要用于执行图数据的分散(scatter)操作。图数据是指由节点和边构成的复杂数据结构,通常用于表示非结构化数据,如社交网络、知识图谱等。 torch-scatter库通过提供一系列高效的图聚合操作,使得在图数据上进行计算更加方便和高效。其中最常用的操作是scatter_add函数,它允许在图节点上对特征进行聚合,生成全局的节点特征表示。 具体来说,torch-scatter库可以执行以下操作: 1. scatter_add: 将每个节点的特征按照图边的连接关系进行聚合,并返回聚合结果。这对于实现图卷积网络(GCN)等图神经网络模型非常关键。 2. scatter_mean: 类似于scatter_add,但是将节点的特征聚合为均值。 3. scatter_max: 类似于scatter_add,但是将节点的特征聚合为最大值。 4. scatter_min: 类似于scatter_add,但是将节点的特征聚合为最小值。 5. scatter_mul: 类似于scatter_add,但是将节点的特征进行乘法聚合。 除了上述操作外,torch-scatter还提供了一些其他的辅助函数,如index_select、index_add等,用于快速和灵活地处理图数据。 总之,torch-scatter库是PyTorch中一个强大的图聚合操作库,提供了高效的图数据处理方法,方便用户在图神经网络模型中进行计算和研究。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值