Skip to main content

pycatch22-rs

A Rust implementation of the catch22 time-series feature set, with Python bindings.

25 features: the 22 catch22 features, the two catch24 additions (mean and standard deviation), and the slope of a linear fit.

  • Verified against the original C over the entire UCR archive — 128 datasets, 191,158 series, 4.78 million feature values. See docs/parity.md for exactly what was compared, at what tolerance, and where the two still differ.
  • ~6x faster than the original C, single-threaded, on the same machine and data, with C built at -O3 -march=native. See BENCHMARKS.md.
  • Zero-copy numpy interface, with a batch entry point that releases the GIL and processes series in parallel.

Installation

Requires Python 3.11 or later.

pip install pycatch22-rs

From source:

git clone https://github.com/irazza/pycatch22-rs
cd pycatch22-rs
python -m venv .venv && source .venv/bin/activate
pip install maturin numpy
maturin develop --release

Usage

import numpy as np
import pycatch22_rs

x = np.random.default_rng(0).standard_normal(500)

# All 25 features at once.
values = pycatch22_rs.compute_all(x)            # -> ndarray, shape (25,)
dict(zip(pycatch22_rs.FEATURE_NAMES, values))

# Any single feature, by name.
pycatch22_rs.SP_Summaries_welch_rect_centroid(x)
pycatch22_rs.CO_f1ecac(x)

# ...or by index, in FEATURE_NAMES order.
pycatch22_rs.compute(x, 19)

# A batch of series: GIL released, rows processed in parallel.
batch = np.random.default_rng(0).standard_normal((1000, 500))
pycatch22_rs.compute_batch(batch)               # -> ndarray, shape (1000, 25)

Normalisation

By default, compute_all and compute_batch reproduce the reference pipeline: features 0–21 are computed on the z-scored series, and 22–24 (mean, standard deviation, slope) on the raw series, which is the catch24 convention. Pass normalize=False to compute everything on the series exactly as given.

The z-score uses the sample standard deviation (ddof=1), matching the reference implementation's zscore_norm2. This is not cosmetic: several features are not scale-invariant, so normalising with the population standard deviation shifts their values.

The individually named functions take the series as given and do no normalisation, so z-score first if you want the reference values:

z = pycatch22_rs.zscore(x)
pycatch22_rs.DN_HistogramMode_5(z)

Input handling

Lists, non-float64 dtypes, and non-contiguous views are all accepted and converted once. Input is never modified.

Series shorter than 4 samples, and series containing NaN or infinity, raise ValueError. This is a deliberate departure from C, which propagates NaN through its feature functions. Note that a constant series z-scores to NaN (its standard deviation is zero), so compute_all(constant, normalize=True) raises as well.

Rust

The kernel is a standalone crate with no Python dependency:

[dependencies]
catch22 = { path = "crates/catch22" }
let values = catch22::compute_all_normalized(&series)?;   // [f64; 25]
let centroid = catch22::sp_summaries_welch_rect_centroid(&z);

FEATURES and FEATURE_NAMES are parallel arrays over the same 25 indices.

Development

cargo test --workspace          # Rust: parity, consistency, edge cases
maturin develop --release
pytest tests/                   # Python: API surface and parity

Checking against the C reference

Parity is enforced at two levels. The committed fixture in tests/data/ holds C's expected output for a sample of series plus hand-picked edge cases, and is checked by both test suites on every run. The full archive sweep is opt-in and needs a local copy of the UCR archive:

bash tools/c_reference/fetch.sh          # clone catch22 C at the pinned commit
make -C tools/c_reference                # build the reference driver
cargo run --release -p ucr_check -- --ucr-root ~/DATA/ucr --report docs/parity-report.md

The same tool produces the benchmark table:

cargo run --release -p ucr_check -- --ucr-root <subset> \
    --driver tools/c_reference/driver_native --bench BENCHMARKS.md

License

GPL-3.0-or-later. See LICENSE.

Download files

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

Source Distribution

pycatch22_rs-0.1.0.tar.gz (192.5 kB view details)

Uploaded Source

Built Distributions

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

pycatch22_rs-0.1.0-cp311-abi3-win_amd64.whl (289.7 kB view details)

Uploaded CPython 3.11+Windows x86-64

pycatch22_rs-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (411.1 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

pycatch22_rs-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (399.5 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

pycatch22_rs-0.1.0-cp311-abi3-macosx_11_0_arm64.whl (365.0 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

pycatch22_rs-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl (379.0 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pycatch22_rs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fadb0ed6b19e6549e98ec44de48d7186343501a40c06ed56e6060690f23da20e
MD5 5307c174c8f5bd6ee26bdb55dfe20df9
BLAKE2b-256 5b6af910730bbda888e39eba99bb19723a433b1d50e6721e63c23c8bd25debfd

See more details on using hashes here.

File details

Details for the file pycatch22_rs-0.1.0-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pycatch22_rs-0.1.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6ecd15ef75fffe0784a6bf6cdd4c5a91b69d2d1127d218f28ee5f8ec381e84f2
MD5 a58d7e961bef726540ad1976f3dede53
BLAKE2b-256 7aeeb444a6ef2250b8c7c54f0c49e5c6b1f560285c91d0c0c672811f847b60a4

See more details on using hashes here.

File details

Details for the file pycatch22_rs-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pycatch22_rs-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7fb0840f7001cb1277f0892570cfb8117640ddb47539eced64fb72c4c6ce2248
MD5 65ef28d132483026406cbbf2a0933e3a
BLAKE2b-256 a19a67a7a84cb22cf08226f7e7ef63860b4b09d2ae063070554e2b2ea2c3f349

See more details on using hashes here.

File details

Details for the file pycatch22_rs-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pycatch22_rs-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 470eab6ccd29b1d6b764d4d716bcf51aa0968b244b473c847a49708bb2123352
MD5 3053627f6cd6ac81f301104bb43d2004
BLAKE2b-256 5cb99351317a0f0e34f0494be27a4fe26554d8ecd304047a0e4ba42530001d46

See more details on using hashes here.

File details

Details for the file pycatch22_rs-0.1.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pycatch22_rs-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f767fe63970aec72956b83cb6c7a0ecd9af9a22ccbee756f52492e4a90b7081d
MD5 f61a71e6db8ea4f87edb350d3c2006eb
BLAKE2b-256 fbe3442ec298680c0cadf5e1eb6805340309ab2b005875d76ce2b8d8be415a9f

See more details on using hashes here.

File details

Details for the file pycatch22_rs-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pycatch22_rs-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b20e1ef0f49c0e517201a04ecbc1a9b8284dae47a1784a366aef99893b1be068
MD5 5cb4b5f96a9ab832f71663291a399ca4
BLAKE2b-256 8dd30a26bc7529b191c1a05fdd23780379894b8cb663bbcd063a09761a5d2e60

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

6 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