### Verifying PyTorch Version (Older Example) Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This command demonstrates checking the PyTorch version, showing an example of an older version (1.1.0). While the current requirement for source installation is 1.4.0+, this snippet illustrates the general method for version verification. ```bash python -c "import torch; print(torch.__version__)" ``` -------------------------------- ### Installing PyTorch Cluster Binaries for PyTorch 2.5 Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This command installs the `torch-cluster` library binaries for PyTorch versions 2.5.0 or 2.5.1. Users need to substitute `${CUDA}` with their specific CUDA version (e.g., `cpu`, `cu118`, `cu121`, `cu124`) to ensure compatibility with their PyTorch setup. This approach leverages pre-built packages for ease of installation. ```bash pip install torch-cluster -f https://data.pyg.org/whl/torch-2.5.0+${CUDA}.html ``` -------------------------------- ### Building and Installing torch-cluster C++ API Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This shell script provides the steps to build and install the `torch-cluster` C++ API. It involves setting the `Torch_DIR` environment variable, creating a build directory, running CMake for configuration (with an option for CUDA support), and then compiling and installing the library. ```Shell export Torch_DIR=`python -c 'import torch;print(torch.utils.cmake_prefix_path)'` mkdir build cd build # Add -DWITH_CUDA=on support for the CUDA if needed cmake .. make make install ``` -------------------------------- ### Installing PyTorch Cluster from Source Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This command initiates the installation of `torch-cluster` directly from its source code. This method is used when pre-built binaries are not available or when specific compilation options are required. It assumes all necessary build tools and CUDA environment variables are correctly configured. ```bash pip install torch-cluster ``` -------------------------------- ### Installing PyTorch Cluster Binaries for PyTorch 2.6 Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This command installs the `torch-cluster` library binaries for PyTorch version 2.6.0. Users must replace `${CUDA}` with their specific CUDA version (e.g., `cpu`, `cu118`, `cu124`, `cu126`) to match their PyTorch installation. This method provides pre-compiled packages for various OS and CUDA combinations. ```bash pip install torch-cluster -f https://data.pyg.org/whl/torch-2.6.0+${CUDA}.html ``` -------------------------------- ### Verifying PyTorch Version for Source Installation Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This Python command checks the installed PyTorch version, which is a prerequisite for compiling `torch-cluster` from source. A version of at least 1.4.0 is required. This helps ensure compatibility before proceeding with the source installation. ```bash python -c "import torch; print(torch.__version__)" ``` -------------------------------- ### Sampling Random Walks - PyTorch Cluster - Python Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This snippet demonstrates how to sample random walks on a graph using `random_walk`. It takes graph edges (`row`, `col`), starting nodes (`start`), and a `walk_length` to generate paths. The output `walk` tensor contains the sequences of nodes visited during each walk, starting from the corresponding node in `start`. ```Python import torch from torch_cluster import random_walk row = torch.tensor([0, 1, 1, 1, 2, 2, 3, 3, 4, 4]) col = torch.tensor([1, 0, 2, 3, 1, 4, 1, 4, 2, 3]) start = torch.tensor([0, 1, 2, 3, 4]) walk = random_walk(row, col, start, walk_length=3) print(walk) # Expected output: tensor([[0, 1, 2, 4], # [1, 3, 4, 2], # [2, 4, 2, 1], # [3, 4, 2, 4], # [4, 3, 1, 0]]) ``` -------------------------------- ### Verifying CUDA Binaries in PATH for Source Installation Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This shell command displays the current `$PATH` environment variable. For successful source compilation of `torch-cluster`, it's crucial to ensure that the `cuda/bin` directory is included in the `$PATH`, allowing the system to locate necessary CUDA executables. ```bash echo $PATH ``` -------------------------------- ### Performing VoxelGrid Clustering - PyTorch Cluster - Python Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This example illustrates the `VoxelGrid` clustering algorithm, which partitions a point cloud into voxels of a specified `size`. Points within the same voxel are assigned to the same cluster. The `pos` tensor represents the 2D coordinates of points, and `size` defines the dimensions of each voxel. ```Python import torch from torch_cluster import grid_cluster pos = torch.tensor([[0., 0.], [11., 9.], [2., 8.], [2., 2.], [8., 3.]]) size = torch.Tensor([5, 5]) cluster = grid_cluster(pos, size) print(cluster) # Expected output: tensor([0, 5, 3, 0, 1]) ``` -------------------------------- ### Running PyTorch Cluster Tests - Command Line - Shell Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This command executes the test suite for the `torch_cluster` library using `pytest`. It is typically run from the project's root directory to verify the correctness and functionality of the installed library components. ```Shell pytest ``` -------------------------------- ### Verifying CUDA Includes in CPATH for Source Installation Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This shell command outputs the current `$CPATH` environment variable. For compiling `torch-cluster` from source, the `cuda/include` directory must be present in `$CPATH` to enable the compiler to find CUDA header files, which are essential for building CUDA-enabled components. ```bash echo $CPATH ``` -------------------------------- ### Setting CUDA Architecture List for Docker Environments Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This command sets the `TORCH_CUDA_ARCH_LIST` environment variable, which is crucial when installing PyTorch-related libraries in a Docker container without an NVIDIA driver. It explicitly defines the compute capabilities for which PyTorch should compile, preventing failures during installation by bypassing automatic detection. ```bash export TORCH_CUDA_ARCH_LIST = "6.0 6.1 7.2+PTX 7.5+PTX" ``` -------------------------------- ### Constructing k-Nearest Neighbors Graph - PyTorch Cluster - Python Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This example shows how to build a k-Nearest Neighbors graph using `knn_graph`. It connects each node to its `k` nearest neighbors based on Euclidean distance (or Cosine if specified). The function requires a node feature matrix `x` and returns `edge_index`, representing the graph's connectivity in COO format. Optional `batch`ing and `loop` parameters are supported. ```Python import torch from torch_cluster import knn_graph x = torch.tensor([[-1., -1.], [-1., 1.], [1., -1.], [1., 1.]]) batch = torch.tensor([0, 0, 0, 0]) edge_index = knn_graph(x, k=2, batch=batch, loop=False) print(edge_index) # Expected output: tensor([[1, 2, 0, 3, 0, 3, 1, 2], # [0, 0, 1, 1, 2, 2, 3, 3]]) ``` -------------------------------- ### Finding Nearest Clusters - PyTorch Cluster - Python Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This example shows how to find the nearest cluster for points in `x` relative to query points in `y` using the `nearest` function. It assigns each point in `x` to the cluster of its closest point in `y`. Both `x` and `y` can be batched using `batch_x` and `batch_y` respectively, which must be sorted. ```Python import torch from torch_cluster import nearest x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]]) batch_x = torch.tensor([0, 0, 0, 0]) y = torch.Tensor([[-1, 0], [1, 0]]) batch_y = torch.tensor([0, 0]) cluster = nearest(x, y, batch_x, batch_y) print(cluster) # Expected output: tensor([0, 0, 1, 1]) ``` -------------------------------- ### Constructing Radius Graph - PyTorch Cluster - Python Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This snippet demonstrates how to create a radius graph using `radius_graph`, connecting all points within a specified `r` (radius) of each other. It takes a node feature matrix `x` and returns `edge_index` in COO format. The function supports optional `batch`ing, self-`loop`s, and a `max_num_neighbors` limit for dense point clouds. ```Python import torch from torch_cluster import radius_graph x = torch.tensor([[-1., -1.], [-1., 1.], [1., -1.], [1., 1.]]) batch = torch.tensor([0, 0, 0, 0]) edge_index = radius_graph(x, r=2.5, batch=batch, loop=False) print(edge_index) # Expected output: tensor([[1, 2, 0, 3, 0, 3, 1, 2], # [0, 0, 1, 1, 2, 2, 3, 3]]) ``` -------------------------------- ### Applying Graclus Clustering - PyTorch Cluster - Python Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This snippet demonstrates how to apply the Graclus greedy clustering algorithm using `torch_cluster`. It takes edge `row` and `col` indices, along with optional `weight`s, to group connected components. The output `cluster` tensor indicates the cluster ID for each original node. ```Python import torch from torch_cluster import graclus_cluster row = torch.tensor([0, 1, 1, 2]) col = torch.tensor([1, 0, 2, 1]) weight = torch.tensor([1., 1., 1., 1.]) # Optional edge weights. cluster = graclus_cluster(row, col, weight) print(cluster) # Expected output: tensor([0, 0, 1]) ``` -------------------------------- ### Executing Farthest Point Sampling - PyTorch Cluster - Python Source: https://github.com/rusty1s/pytorch_cluster/blob/master/README.md This snippet demonstrates Farthest Point Sampling (FPS), an iterative algorithm that selects points most distant from previously sampled points. It takes a feature matrix `x`, an optional `batch` tensor for batching, and a `ratio` to determine the number of points to sample. The output `index` tensor contains the indices of the sampled points. ```Python import torch from torch_cluster import fps x = torch.tensor([[-1., -1.], [-1., 1.], [1., -1.], [1., 1.]]) batch = torch.tensor([0, 0, 0, 0]) index = fps(x, batch, ratio=0.5, random_start=False) print(index) # Expected output: tensor([0, 3]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.