PyTorch DTW C++ extension
Project description
PyTorch DTW C++ extension
Dynamic time warping in native PyTorch, with CPU and CUDA backends.
pip install torchdtw
This package requires PyTorch 2.10 or later. It is developed using the PyTorch 2.10 Stable ABI, and compiled with instructions for CUDA cards from Volta to Blackwell. This was originally made for fastabx, but it can be used in other projects. Only the exact DTW is implemented, there is no plan to add variants.
Usage
This package provides three functions:
DTW
def dtw(distances: torch.Tensor) -> torch.Tensor
Compute the DTW cost of the given distances 2D tensor.
Arguments:
distances: A 2D tensor of shape (n, m) representing the pairwise distances between two sequences.
Returns:
A scalar tensor with the cost.
DTW path
def dtw_path(distances: torch.Tensor) -> torch.Tensor
Compute the DTW path of the given distances 2D tensor.
No CUDA variant or batched implementation are provided for now.
Arguments:
distances: A 2D tensor of shape (n, m) representing the pairwise distances between two sequences.
Returns:
A 2D tensor of shape (*, 2) with the path indices.
Batched DTW
def dtw_batch(distances: torch.Tensor, sx: torch.Tensor, sy: torch.Tensor, *,
symmetric: bool) -> torch.Tensor
Compute the batched DTW cost on the distances 4D tensor.
Arguments:
distances: A 4D tensor of shape (n1, n2, s1, s2) representing the pairwise distances between two batches of sequences.sx: A 1D tensor of shape (n1,) representing the lengths of the sequences in the first batch.sy: A 1D tensor of shape (n2,) representing the lengths of the sequences in the second batch.symmetric: Whether or not the DTW is symmetric (i.e., the two batches are the same).
Returns:
A 2D tensor of shape (n1, n2) with the costs.
Benchmark
Check this folder for comparisons against reference implementations.
Citation
Please cite the fastabx paper if you use this package in your work:
@misc{fastabx,
title={fastabx: A library for efficient computation of ABX discriminability},
author={Maxime Poli and Emmanuel Chemla and Emmanuel Dupoux},
year={2025},
eprint={2505.02692},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2505.02692},
}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchdtw-0.1.1.tar.gz.
File metadata
- Download URL: torchdtw-0.1.1.tar.gz
- Upload date:
- Size: 58.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e26438b34d7bb13bd027434977e5d3851b69513ba43025bae1c49d355d3eeee7
|
|
| MD5 |
c601fec4a261a40755fe1d5d02375cd4
|
|
| BLAKE2b-256 |
c2fd40787717c777062d8e626bcdb47159e48dd6d9c82a6c6cff09ae6805b626
|
File details
Details for the file torchdtw-0.1.1-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: torchdtw-0.1.1-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 63.3 kB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b66884cd7c0807c32d6500e022addb654fbbd682e724470998611c6e99e364e9
|
|
| MD5 |
4b6c626e316feb501b4b706695ce21b6
|
|
| BLAKE2b-256 |
081a9eae59d5710a3d1afda8952e22007de45192a68688bc24948dcac4638704
|
File details
Details for the file torchdtw-0.1.1-cp312-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: torchdtw-0.1.1-cp312-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 252.5 kB
- Tags: CPython 3.12+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffd676521b9349ef12c83fd1c430228f1c643c5a568d225060b490ac6acebe57
|
|
| MD5 |
dbbd97b10a28c7a56e4bcebce456467d
|
|
| BLAKE2b-256 |
3984d9a73f23d083a38d5d184ee154634cbe9d2e78ddb610caae25a71f9573f1
|
File details
Details for the file torchdtw-0.1.1-cp312-abi3-macosx_14_0_arm64.whl.
File metadata
- Download URL: torchdtw-0.1.1-cp312-abi3-macosx_14_0_arm64.whl
- Upload date:
- Size: 25.6 kB
- Tags: CPython 3.12+, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
690a06d1e8cd4af1653846549ea74ca4c9be65b9cff54bb85e63b05b75021884
|
|
| MD5 |
152f8b74915460415d27413d13f8ac0d
|
|
| BLAKE2b-256 |
42705f097bb05e3d788b896194bbf6d90fc47694342a0726685ca716a41770c9
|