Skip to main content

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

torchdtw-0.1.0.tar.gz (57.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

torchdtw-0.1.0-cp312-abi3-win_amd64.whl (30.8 kB view details)

Uploaded CPython 3.12+Windows x86-64

torchdtw-0.1.0-cp312-abi3-manylinux_2_34_x86_64.whl (252.6 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.34+ x86-64

torchdtw-0.1.0-cp312-abi3-macosx_14_0_arm64.whl (25.6 kB view details)

Uploaded CPython 3.12+macOS 14.0+ ARM64

File details

Details for the file torchdtw-0.1.0.tar.gz.

File metadata

  • Download URL: torchdtw-0.1.0.tar.gz
  • Upload date:
  • Size: 57.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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

Hashes for torchdtw-0.1.0.tar.gz
Algorithm Hash digest
SHA256 63d0a782a49fe121d6694302d8778591b6ed323f726960ef07ae9093c09b8197
MD5 fa85ee62db70f364951b9dc0fb8ca5c9
BLAKE2b-256 bf406cf3362190a853b243cf7d8bd32ddaae3431f3792ca7b4393cf11499c028

See more details on using hashes here.

File details

Details for the file torchdtw-0.1.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: torchdtw-0.1.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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

Hashes for torchdtw-0.1.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4acce003055e97c97a662bf27ac159a4024c8ad77e123661733adb7277cf04e3
MD5 f8679e319c88c85a55322745b87f81fc
BLAKE2b-256 9e2346a67ec05cb178aaaa85f783adeb1d69177c954dd7e37a7d5dea4dd67b3d

See more details on using hashes here.

File details

Details for the file torchdtw-0.1.0-cp312-abi3-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: torchdtw-0.1.0-cp312-abi3-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 252.6 kB
  • Tags: CPython 3.12+, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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

Hashes for torchdtw-0.1.0-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0828cc4454efee702ac89933f7cd76f82e841ec5dea2c1b034a3e2e899a53175
MD5 7662c4a084b34b88d3cc9dd06a33f3ef
BLAKE2b-256 8abc72318a9e62aaa351de1e3b959597baf28661e25186648ae631324b2adb0f

See more details on using hashes here.

File details

Details for the file torchdtw-0.1.0-cp312-abi3-macosx_14_0_arm64.whl.

File metadata

  • Download URL: torchdtw-0.1.0-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.26 {"installer":{"name":"uv","version":"0.9.26","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

Hashes for torchdtw-0.1.0-cp312-abi3-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bb544f61750bde26b2c256d7e4a555fc52d552a6280d3e280a4c2ab9c508cc8f
MD5 4832f7bc53adfe3b3a7c8f5ed75e817f
BLAKE2b-256 dce72ad2ef9814028c0c17e5e1e0feadeb4dbc70cbc2e56a770e3257f3332637

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page