Metadata-Version: 2.3
Name: torchpsort
Version: 0.1.8
Summary: Fast, differentiable sorting and ranking without custom C++ or CUDA extensions
Author: RektPunk
Author-email: RektPunk <rektpunk@gmail.com>
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: torch>=2.4.0
Requires-Dist: numba>=0.60
Requires-Python: >=3.12
Project-URL: repository, https://github.com/RektPunk/torchpsort
Description-Content-Type: text/markdown

<div style="text-align: center;">
  <img src="https://capsule-render.vercel.app/api?type=transparent&fontColor=0047AB&text=torchpsort&height=120&fontSize=80">
</div>

Fast, differentiable sorting and ranking **without custom C++ or CUDA extensions**. This is a lightweight implementation of [Fast Differentiable Sorting and Ranking (Blondel et al.)](https://arxiv.org/abs/2002.08871) based on [fast-soft-sort](https://github.com/google-research/fast-soft-sort) and inspired by [torchsort](https://github.com/teddykoker/torchsort). Unlike [torchsort](https://github.com/teddykoker/torchsort), this version requires no custom C++ or CUDA extensions, making it easy to install and portable across platforms. While optimized C++/CUDA implementations may have a performance advantage for extremely large sequence lengths, this version is optimized for typical deep learning workflows. Try it here:
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/RektPunk/torchpsort/blob/main/examples/notebook.ipynb)

## Installation

```bash
pip install torchpsort
```

> [!NOTE]
> The CPU forward implementation uses [Numba](https://numba.pydata.org/) for JIT compilation like [fast-soft-sort](https://github.com/google-research/fast-soft-sort). Numba is installed automatically as a dependency of `torchpsort`. On CUDA tensors, the forward pass uses a separate chunked GPU implementation instead.
