Skip to main content

tsdistances

Introduction

tsdistances is a Python library (with Rust backend) for computing various pairwise distances between sets of time series data.

It provides efficient implementation of elastic distance measures such as Dynamic Time Warping (DTW), Longest Common Subsequence (LCSS), Time Warping Edit (TWE), and many others.

The library is designed to be fast and scalable, leveraging parallel computation and GPU support via Vulkan for improved performance.

Features

  1. Multiple Distance Measures: Supports a wide range of time series distance measures:

    • Euclidean

    • CATCH22 Euclidean

    • Edit Distance with Real Penalty (ERP) optionally with GPU support

    • Longest Common Subsequence (LCSS) optionally with GPU support

    • Dynamic Time Warping (DTW) optionally with GPU support

    • Derivative Dynamic Time Warping (DDTW) optionally with GPU support

    • Weighted Dynamic Time Warping (WDTW) optionally with GPU support

    • Weighted Derivative Dynamic Time Warping (WDDTW) optionally with GPU support

    • Amerced Dynamic Time Warping (ADTW) optionally with GPU support

    • Move-Split-Merge (MSM) optionally with GPU support

    • Time Warp Edit Distance (TWE) optionally with GPU support

    • Shape-Based Distance (SBD)

    • MPDist

  2. Parallel Computation: Utilizes multiple CPU cores to speed up computations.

  3. GPU Acceleration: Optional GPU support based on Vulkan for even faster computations with Rust-GPU.

Benchmark

To evaluate the performance of our time series distance computation library, we conducted a comparative analysis with existing libraries.

We selected AEON as the primary competitor due to its comprehensive implementation of distance metrics, making it the most suitable for direct comparison. Several other libraries were considered, and while we did not conduct a full benchmark on all datasets, we reported their execution times on a subset of the UCR Archive datasets.

sthread par gpu
ACSF1 31.60 5.74 1.41
Adiac 5.27 0.84 1.02
Beef 0.47 0.08 0.09
CBF 1.51 0.25 0.28
ChlorineConcentration 131.53 22.73 7.36
CinCECGTorso 524.77 86.92 7.85
CricketX 47.93 8.35 1.82
DiatomSizeReduction 0.59 0.09 0.24
DistalPhalanxOutlineCorrect 2.45 0.37 0.57
ECG200 0.28 0.04 0.05
EthanolLevel 925.06 169.63 38.18
FreezerRegularTrain 100.48 16.94 4.69
FreezerSmallTrain 18.54 3.18 1.11
Ham 5.43 0.93 0.45
Haptics 149.35 27.49 3.82
HouseTwenty 65.37 11.64 1.20
ItalyPowerDemand 0.16 0.03 0.12
MixedShapesSmallTrain 804.75 150.01 16.66
NonInvasiveFetalECGThorax1 3398.64 724.58 107.42
ShapesAll 312.02 54.83 6.90
Strawberry 19.38 3.42 2.35
UWaveGestureLibraryX 1016.30 196.54 21.05
Wafer 462.68 81.98 16.08

Computation times (in seconds) of our method across 23 datasets, comparing single-threaded, parallelized, and GPU implementations.

Installation

PIP

If you use pip, you can install tsdistances with:

    $ pip install tsdistances

From Source

This can be done by going through the following steps in sequence:

  1. Install the latest Rust compiler
  2. Install maturin: pip install maturin
  3. Build the library:
    maturin develop --release
    

GPU Support

To build with GPU acceleration:

  1. Install LunarG Vulkan SDK
  2. Either:
    • Install SPIRV-Tools, or
    • Use pre-compiled tools with --features use-compiled-tools
maturin develop --release --features use-compiled-tools

Feature Flags

The library uses Cargo feature flags to control what gets compiled:

Feature Description Default
python Python bindings via PyO3
gpu Enable Vulkan/Rust-GPU support
matlab MATLAB/C FFI bindings
use-compiled-tools Use pre-compiled SPIRV tools for GPU
use-installed-tools Use system-installed SPIRV tools

For Python development (default):

maturin develop --release
# or explicitly:
cargo build --release --features python,use-compiled-tools

For MATLAB bindings only (no Python dependency):

cargo build --release --no-default-features --features matlab

See matlab/README.md for detailed MATLAB installation instructions.

Usage

Example 1: Compute DTW Distance on CPU and GPU

        
    import numpy as np
    import tsdistances

    # Generate two random time series (1-D arrays of length 100)
    np.random.seed(0)
    x1 = np.random.rand(100)
    x2 = np.random.rand(100)

    # Compute DTW distance on CPU
    cpu_distance = tsdistances.dtw_distance(x1, x2, device='cpu')
    print(f"DTW distance (CPU): {cpu_distance}")

    gpu_distance = tsdistances.dtw_distance(x1, x2, device='gpu')

    print(f"DTW distance (GPU): {gpu_distance}")

Example 2: Pairwise Distances with Multiple Time Series and Parallel Computation

    import numpy as np
    import tsdistances

    # Generate a batch of 10 random time series (each of length 50)
    np.random.seed(42)
    X = np.random.rand(10, 50)

    # Pairwise DTW distances within the set X (on CPU, single thread)
    pairwise_distances = tsdistances.dtw_distance(X, par=False, device='cpu')
    print("Pairwise DTW distance matrix (CPU, single thread):")
    print(pairwise_distances)

    # Compare two batches: compute distances between each element of X and each element of Y
    Y = np.random.rand(8, 50)
    batch_distances = tsdistances.dtw_distance(X, Y, par=True, device='cpu')
    print("Batch DTW distance matrix (X vs Y):")
    print(batch_distances)

Notes

  1. device='gpu' enables GPU acceleration.

  2. par controls parallelism. Set it to True to use all available CPU cores.

  3. If v is not provided, the function computes pairwise distances within u.

Important: Results will differ between CPU and GPU due to floating-point precision:

CPU computations use f64 (double precision) for higher numerical accuracy.

GPU computations use f32 (single precision) for better performance.
For instance, on an RTX 4090:

    FP32 performance: 82.58 TFLOPS

    FP64 performance: 1.29 TFLOPS (1:64 rate)
    Using f32 on GPU drastically improves speed but introduces small numerical differences compared to CPU results.

Testing and Validation

All distance implementations in tsdistances are tested against AEON, a widely-used Python library for time series analysis and distances. This ensures that the results are correct and consistent with established benchmarks in the field.

To run the correctness tests, simply use pytest:

pytest -v tests/test_correctness_cpu.py

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tsdistances-0.1.9.tar.gz (983.4 kB view details)

Uploaded Source

Built Distributions

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

tsdistances-0.1.9-cp314-cp314-win_amd64.whl (668.9 kB view details)

Uploaded CPython 3.14Windows x86-64

tsdistances-0.1.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

tsdistances-0.1.9-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (588.9 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

tsdistances-0.1.9-cp314-cp314-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

tsdistances-0.1.9-cp313-cp313-win_amd64.whl (669.9 kB view details)

Uploaded CPython 3.13Windows x86-64

tsdistances-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

tsdistances-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (590.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

tsdistances-0.1.9-cp313-cp313-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

tsdistances-0.1.9-cp312-cp312-win_amd64.whl (670.4 kB view details)

Uploaded CPython 3.12Windows x86-64

tsdistances-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

tsdistances-0.1.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (590.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

tsdistances-0.1.9-cp312-cp312-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file tsdistances-0.1.9.tar.gz.

File metadata

  • Download URL: tsdistances-0.1.9.tar.gz
  • Upload date:
  • Size: 983.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for tsdistances-0.1.9.tar.gz
Algorithm Hash digest
SHA256 d119f11899612c45bd9fb9a1ed847c6ecd3501a600778f5884fe36580f733ccb
MD5 a04c87fe81ea8d39784caf26f7d9eb37
BLAKE2b-256 fa781a616809d17982c955983f96e910d32b6505f14f24484685a1a5c7a1e652

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 bd56b426b7f406fe4e0d6f7b48a5978fdd532c81c0f209156f57808c017b502f
MD5 025bb5eda2175e3b202dc596ca93c8ff
BLAKE2b-256 13b5313a19965d571fc841caf35e4489b19cac3a837bb01bcc37c13757d1fdd7

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d26d0d882f6c43f095d1f211e36f1de8c09f55557ce9a6f0625c0fca04a2084
MD5 7c4bb92a1261b9f48fcc95398cf1bdfb
BLAKE2b-256 580ae35b811013d0d29e81f67cafa81c330d58b097e8f5fb053c9416d4bfa8b9

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 03b4d13aaef59d63e018e688bc680cacb559fdb3d70213a6b9cc51ce0eb6aa61
MD5 9057bfcfec56971e4be65507f71fccce
BLAKE2b-256 8446781108e6842c9a1de2aa0723ec69079587de468806c348951dabf8089e2e

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e441c12b94ebc9e90cadf93963b38720e43a5c7197af9ba0aaecf51e083de734
MD5 26f4b94cb980b913b1f37064b8d7abd6
BLAKE2b-256 a54145d049db44ee298c338d2c8f16b294b19594e89954a4806af6c8e57d4cde

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d5d46386b84a3008fddc4f3019a49cbbfca9d33b82e9ffe0080cfc74b5b287a9
MD5 bb5d605348430a00a50a69de242d732c
BLAKE2b-256 abfeae5ca18a1c2e9c1d0d15b347f36121f5aa09660267fb4cdaf929ce45b4ba

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 145aa06942a9e97c8ad51c5385c3592183a9033b8268fbba31a6f7f8dfaf5f20
MD5 caacc5c9c40a27f2ef23a07ba44062e5
BLAKE2b-256 b61d30ffe938deaa21b6e7726ddaf12e7c45d42c3150820fb2a7221b6ed98c0f

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d3e67fec90c8c9fd7846e9485d2301de18a54ff8e60b12e8f2b446883c5bc456
MD5 d9cecce5ed3010d0218378e1a6e5bc89
BLAKE2b-256 05def2d1ee89853268e9a29a8ff85ae9f8239bb7fffe96c776770e585cdbb62e

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 513155c7cc08f1cf0d00d7485fa9f0aa38ebe95d3028663f623477dd2703a779
MD5 e7f124ebccd98fdb8df4663bf08782d2
BLAKE2b-256 23127656d0a6b5ffa7c5f1939c65af4bbe317116718679bde98d99f534e830eb

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 85d8f3d758772e1a48d797a207cdc58e3438857a1958e5ce718c490706668d19
MD5 61050b9e3ed83ab3f07a9bf581dae3af
BLAKE2b-256 9a4a036b2bb5be92aa6ab5cb9b8ea6d494d3e1b450d96d1efc42fbd206238fc9

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f3dab4ca4b803f59f9fe65912c57afc14b2a0159327753a14f72d88fa25a027c
MD5 bc2416cc1e9544100141383bd5af955a
BLAKE2b-256 c89c9b5e0cef2d1eb45e917bf6785826cd187515a406b5f7b62e2e0176f5c99b

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3ebfb9ff93333a0a0db5bb546a60a1269f35b3f727239289c76b20abfed401a5
MD5 0fa56b41c670fe3fa163571ed2a0bb49
BLAKE2b-256 82bff6a96efd5b7f1d17f4585f8c35978ce5a7b69abf5cbcd2e5b22df160543b

See more details on using hashes here.

File details

Details for the file tsdistances-0.1.9-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tsdistances-0.1.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 387db0cdb1095f01add2be93fff30e09d31f770d2ea8213e1d50a6e3636c71bd
MD5 64c25272940bf1ae9b960efcfe91cbb8
BLAKE2b-256 57243faa6b6ab84ee65a7fa8d5386415207665d48d211dfd14e237d2d9ead9b9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.9 This release

13 files

0.1.7

7 files

0.1.5

7 files

0.1.1

28 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page