plotsimplify 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plotsimplify-0.1.0/.github/workflows/ci.yml +53 -0
- plotsimplify-0.1.0/.github/workflows/release.yml +121 -0
- plotsimplify-0.1.0/.gitignore +13 -0
- plotsimplify-0.1.0/CLAUDE.md +53 -0
- plotsimplify-0.1.0/Cargo.lock +228 -0
- plotsimplify-0.1.0/Cargo.toml +30 -0
- plotsimplify-0.1.0/LICENSE +21 -0
- plotsimplify-0.1.0/PKG-INFO +175 -0
- plotsimplify-0.1.0/README.md +148 -0
- plotsimplify-0.1.0/benchmarks/bench.py +108 -0
- plotsimplify-0.1.0/benchmarks/results.txt +11 -0
- plotsimplify-0.1.0/docs/downsampling-report.md +200 -0
- plotsimplify-0.1.0/pyproject.toml +42 -0
- plotsimplify-0.1.0/python/plotsimplify/__init__.py +130 -0
- plotsimplify-0.1.0/python/plotsimplify/_plotsimplify.pyi +18 -0
- plotsimplify-0.1.0/python/plotsimplify/py.typed +0 -0
- plotsimplify-0.1.0/src/core.rs +656 -0
- plotsimplify-0.1.0/src/lib.rs +64 -0
- plotsimplify-0.1.0/tests/__init__.py +0 -0
- plotsimplify-0.1.0/tests/reference_kernel.py +110 -0
- plotsimplify-0.1.0/tests/test_simplify.py +272 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
env:
|
|
9
|
+
CARGO_TERM_COLOR: always
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
rust:
|
|
13
|
+
name: rust fmt / clippy / test
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
18
|
+
with:
|
|
19
|
+
components: rustfmt, clippy
|
|
20
|
+
- uses: Swatinem/rust-cache@v2
|
|
21
|
+
- run: cargo fmt --check
|
|
22
|
+
- run: cargo clippy --no-default-features --all-targets -- -D warnings
|
|
23
|
+
- run: cargo test --no-default-features
|
|
24
|
+
|
|
25
|
+
python:
|
|
26
|
+
name: python ${{ matrix.python-version }} tests
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
strategy:
|
|
29
|
+
fail-fast: false
|
|
30
|
+
matrix:
|
|
31
|
+
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v4
|
|
34
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
35
|
+
- uses: Swatinem/rust-cache@v2
|
|
36
|
+
- uses: actions/setup-python@v5
|
|
37
|
+
with:
|
|
38
|
+
python-version: ${{ matrix.python-version }}
|
|
39
|
+
cache: pip
|
|
40
|
+
cache-dependency-path: pyproject.toml
|
|
41
|
+
- run: pip install -e '.[dev]'
|
|
42
|
+
- run: pytest -v
|
|
43
|
+
|
|
44
|
+
lint-python:
|
|
45
|
+
name: ruff
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
steps:
|
|
48
|
+
- uses: actions/checkout@v4
|
|
49
|
+
- uses: astral-sh/ruff-action@v3
|
|
50
|
+
with:
|
|
51
|
+
version: "0.15.21"
|
|
52
|
+
- run: ruff check .
|
|
53
|
+
- run: ruff format --check .
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
linux:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
target: [x86_64, aarch64]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: PyO3/maturin-action@v1
|
|
21
|
+
with:
|
|
22
|
+
target: ${{ matrix.target }}
|
|
23
|
+
args: --release --out dist
|
|
24
|
+
sccache: "true"
|
|
25
|
+
manylinux: auto
|
|
26
|
+
- uses: actions/upload-artifact@v4
|
|
27
|
+
with:
|
|
28
|
+
name: wheels-linux-${{ matrix.target }}
|
|
29
|
+
path: dist
|
|
30
|
+
|
|
31
|
+
windows:
|
|
32
|
+
runs-on: windows-latest
|
|
33
|
+
strategy:
|
|
34
|
+
matrix:
|
|
35
|
+
target: [x64]
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
- uses: actions/setup-python@v5
|
|
39
|
+
with:
|
|
40
|
+
python-version: "3.13"
|
|
41
|
+
architecture: ${{ matrix.target }}
|
|
42
|
+
- uses: PyO3/maturin-action@v1
|
|
43
|
+
with:
|
|
44
|
+
target: ${{ matrix.target }}
|
|
45
|
+
args: --release --out dist
|
|
46
|
+
sccache: "true"
|
|
47
|
+
- uses: actions/upload-artifact@v4
|
|
48
|
+
with:
|
|
49
|
+
name: wheels-windows-${{ matrix.target }}
|
|
50
|
+
path: dist
|
|
51
|
+
|
|
52
|
+
macos:
|
|
53
|
+
runs-on: macos-latest
|
|
54
|
+
strategy:
|
|
55
|
+
matrix:
|
|
56
|
+
target: [x86_64, aarch64]
|
|
57
|
+
steps:
|
|
58
|
+
- uses: actions/checkout@v4
|
|
59
|
+
- uses: PyO3/maturin-action@v1
|
|
60
|
+
with:
|
|
61
|
+
target: ${{ matrix.target }}
|
|
62
|
+
args: --release --out dist
|
|
63
|
+
sccache: "true"
|
|
64
|
+
- uses: actions/upload-artifact@v4
|
|
65
|
+
with:
|
|
66
|
+
name: wheels-macos-${{ matrix.target }}
|
|
67
|
+
path: dist
|
|
68
|
+
|
|
69
|
+
sdist:
|
|
70
|
+
runs-on: ubuntu-latest
|
|
71
|
+
steps:
|
|
72
|
+
- uses: actions/checkout@v4
|
|
73
|
+
- uses: PyO3/maturin-action@v1
|
|
74
|
+
with:
|
|
75
|
+
command: sdist
|
|
76
|
+
args: --out dist
|
|
77
|
+
- uses: actions/upload-artifact@v4
|
|
78
|
+
with:
|
|
79
|
+
name: wheels-sdist
|
|
80
|
+
path: dist
|
|
81
|
+
|
|
82
|
+
# Manual runs (workflow_dispatch) publish to TestPyPI as a dry run.
|
|
83
|
+
# Requires a "testpypi" trusted publisher configured on the TestPyPI
|
|
84
|
+
# project settings for this repo/workflow before it will work.
|
|
85
|
+
publish-testpypi:
|
|
86
|
+
name: Publish to TestPyPI
|
|
87
|
+
if: github.event_name == 'workflow_dispatch'
|
|
88
|
+
needs: [linux, windows, macos, sdist]
|
|
89
|
+
runs-on: ubuntu-latest
|
|
90
|
+
environment: testpypi
|
|
91
|
+
permissions:
|
|
92
|
+
id-token: write
|
|
93
|
+
steps:
|
|
94
|
+
- uses: actions/download-artifact@v4
|
|
95
|
+
with:
|
|
96
|
+
pattern: wheels-*
|
|
97
|
+
path: dist
|
|
98
|
+
merge-multiple: true
|
|
99
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
100
|
+
with:
|
|
101
|
+
repository-url: https://test.pypi.org/legacy/
|
|
102
|
+
skip-existing: true
|
|
103
|
+
|
|
104
|
+
# Tag pushes (v*) publish to real PyPI. Requires a "pypi" trusted
|
|
105
|
+
# publisher configured on the PyPI project settings for this
|
|
106
|
+
# repo/workflow before it will work.
|
|
107
|
+
publish-pypi:
|
|
108
|
+
name: Publish to PyPI
|
|
109
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
110
|
+
needs: [linux, windows, macos, sdist]
|
|
111
|
+
runs-on: ubuntu-latest
|
|
112
|
+
environment: pypi
|
|
113
|
+
permissions:
|
|
114
|
+
id-token: write
|
|
115
|
+
steps:
|
|
116
|
+
- uses: actions/download-artifact@v4
|
|
117
|
+
with:
|
|
118
|
+
pattern: wheels-*
|
|
119
|
+
path: dist
|
|
120
|
+
merge-multiple: true
|
|
121
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`plotsimplify` does error-bounded Ramer–Douglas–Peucker simplification of time
|
|
6
|
+
series for plotting. The Rust kernel is exposed via PyO3/maturin (+ the `numpy`
|
|
7
|
+
crate); input handling lives in Python.
|
|
8
|
+
|
|
9
|
+
- `src/core.rs`: PyO3-free kernels.
|
|
10
|
+
- `scan`: one fused pass that ANDs finiteness into `valid` and returns
|
|
11
|
+
sortedness, the first/last valid index and the y range.
|
|
12
|
+
- `rdp_keep`: max-heap, largest-error-first RDP over each valid run.
|
|
13
|
+
- The 8-lane distance loops (`argmax_cross_*`, `argmax_seg_*`) are compiled
|
|
14
|
+
again with AVX-512/AVX2 `target_feature` and picked at runtime
|
|
15
|
+
(`PLOTSIMPLIFY_BASELINE=1` / `PLOTSIMPLIFY_NO_AVX512=1` force fallbacks).
|
|
16
|
+
- Rust tests compare against textbook recursive RDP.
|
|
17
|
+
- `src/lib.rs`: thin numpy-array bindings (`scan`, `rdp_keep`, `simd_level`),
|
|
18
|
+
GIL released.
|
|
19
|
+
- `python/plotsimplify/__init__.py`: the `simplify()` API. It converts
|
|
20
|
+
datetime64/int x to float offsets from the first valid point (exact in
|
|
21
|
+
int64 first), handles pixel scaling and gap markers, and calls the kernel
|
|
22
|
+
via the module global `_rs`.
|
|
23
|
+
- `tests/reference_kernel.py`: pure-NumPy implementation of `scan`/`rdp_keep`.
|
|
24
|
+
Tests monkeypatch `plotsimplify._rs` with it and require **bit-identical**
|
|
25
|
+
results. A subprocess test does the same for the non-SIMD path.
|
|
26
|
+
- `docs/downsampling-report.md`: the research that motivated the package
|
|
27
|
+
(mentions Numba/NumPy backends that were dropped when packaging).
|
|
28
|
+
|
|
29
|
+
## Commands
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
cargo test --no-default-features
|
|
33
|
+
cargo fmt --check && cargo clippy --no-default-features --all-targets -- -D warnings
|
|
34
|
+
pip install -e '.[dev]' && maturin develop --release && pytest
|
|
35
|
+
ruff check . && ruff format --check .
|
|
36
|
+
pip install simplification && python benchmarks/bench.py
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Invariants
|
|
40
|
+
|
|
41
|
+
- Never enable FMA or reorder floating-point ops in the distance loops: every
|
|
42
|
+
SIMD path and the NumPy reference must round identically. Ties go to the
|
|
43
|
+
lowest index.
|
|
44
|
+
- If kernel semantics change, change `tests/reference_kernel.py` the same way.
|
|
45
|
+
- Keep `version` in sync between `Cargo.toml` and `pyproject.toml`;
|
|
46
|
+
`abi3-py311` must match `requires-python`.
|
|
47
|
+
|
|
48
|
+
## Releasing
|
|
49
|
+
|
|
50
|
+
`release.yml`: `workflow_dispatch` publishes to TestPyPI, and a `v*` tag
|
|
51
|
+
publishes to PyPI, both via Trusted Publishing (OIDC). A trusted publisher
|
|
52
|
+
must be configured first on pypi.org/test.pypi.org (owner `f4hy`, repo
|
|
53
|
+
`plotsimplify`, workflow `release.yml`, environment `pypi`/`testpypi`).
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "autocfg"
|
|
7
|
+
version = "1.5.1"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "heck"
|
|
13
|
+
version = "0.5.0"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "libc"
|
|
19
|
+
version = "0.2.191"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "matrixmultiply"
|
|
25
|
+
version = "0.3.11"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "3f607c237553f086e7043417a51df26b2eb899d3caff94e6a67592ff992fedc7"
|
|
28
|
+
dependencies = [
|
|
29
|
+
"autocfg",
|
|
30
|
+
"rawpointer",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[[package]]
|
|
34
|
+
name = "ndarray"
|
|
35
|
+
version = "0.17.2"
|
|
36
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
37
|
+
checksum = "520080814a7a6b4a6e9070823bb24b4531daac8c4627e08ba5de8c5ef2f2752d"
|
|
38
|
+
dependencies = [
|
|
39
|
+
"matrixmultiply",
|
|
40
|
+
"num-complex",
|
|
41
|
+
"num-integer",
|
|
42
|
+
"num-traits",
|
|
43
|
+
"portable-atomic",
|
|
44
|
+
"portable-atomic-util",
|
|
45
|
+
"rawpointer",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[[package]]
|
|
49
|
+
name = "num-complex"
|
|
50
|
+
version = "0.4.6"
|
|
51
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
52
|
+
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
|
53
|
+
dependencies = [
|
|
54
|
+
"num-traits",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[[package]]
|
|
58
|
+
name = "num-integer"
|
|
59
|
+
version = "0.1.47"
|
|
60
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
61
|
+
checksum = "7ce2d95d4b3734dc35aa2f45e1aa22cd416814592a4f9d9205e11affd5b8e10b"
|
|
62
|
+
dependencies = [
|
|
63
|
+
"num-traits",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[[package]]
|
|
67
|
+
name = "num-traits"
|
|
68
|
+
version = "0.2.19"
|
|
69
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
70
|
+
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
|
71
|
+
dependencies = [
|
|
72
|
+
"autocfg",
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
[[package]]
|
|
76
|
+
name = "numpy"
|
|
77
|
+
version = "0.30.0"
|
|
78
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
79
|
+
checksum = "aa0b9111761885449e894981fa8051dcf69e0bd114aecbd4bcdd830b6be4ed92"
|
|
80
|
+
dependencies = [
|
|
81
|
+
"libc",
|
|
82
|
+
"ndarray",
|
|
83
|
+
"num-complex",
|
|
84
|
+
"num-integer",
|
|
85
|
+
"num-traits",
|
|
86
|
+
"pyo3",
|
|
87
|
+
"pyo3-build-config",
|
|
88
|
+
"rustc-hash",
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
[[package]]
|
|
92
|
+
name = "once_cell"
|
|
93
|
+
version = "1.21.4"
|
|
94
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
95
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
96
|
+
|
|
97
|
+
[[package]]
|
|
98
|
+
name = "plotsimplify"
|
|
99
|
+
version = "0.1.0"
|
|
100
|
+
dependencies = [
|
|
101
|
+
"numpy",
|
|
102
|
+
"pyo3",
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
[[package]]
|
|
106
|
+
name = "portable-atomic"
|
|
107
|
+
version = "1.15.0"
|
|
108
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
109
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
110
|
+
|
|
111
|
+
[[package]]
|
|
112
|
+
name = "portable-atomic-util"
|
|
113
|
+
version = "0.2.8"
|
|
114
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
115
|
+
checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715"
|
|
116
|
+
dependencies = [
|
|
117
|
+
"portable-atomic",
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
[[package]]
|
|
121
|
+
name = "proc-macro2"
|
|
122
|
+
version = "1.0.107"
|
|
123
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
124
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
125
|
+
dependencies = [
|
|
126
|
+
"unicode-ident",
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
[[package]]
|
|
130
|
+
name = "pyo3"
|
|
131
|
+
version = "0.30.1"
|
|
132
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
133
|
+
checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4"
|
|
134
|
+
dependencies = [
|
|
135
|
+
"libc",
|
|
136
|
+
"once_cell",
|
|
137
|
+
"portable-atomic",
|
|
138
|
+
"pyo3-build-config",
|
|
139
|
+
"pyo3-ffi",
|
|
140
|
+
"pyo3-macros",
|
|
141
|
+
]
|
|
142
|
+
|
|
143
|
+
[[package]]
|
|
144
|
+
name = "pyo3-build-config"
|
|
145
|
+
version = "0.30.1"
|
|
146
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
147
|
+
checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700"
|
|
148
|
+
dependencies = [
|
|
149
|
+
"target-lexicon",
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
[[package]]
|
|
153
|
+
name = "pyo3-ffi"
|
|
154
|
+
version = "0.30.1"
|
|
155
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
156
|
+
checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4"
|
|
157
|
+
dependencies = [
|
|
158
|
+
"libc",
|
|
159
|
+
"pyo3-build-config",
|
|
160
|
+
]
|
|
161
|
+
|
|
162
|
+
[[package]]
|
|
163
|
+
name = "pyo3-macros"
|
|
164
|
+
version = "0.30.1"
|
|
165
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
166
|
+
checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60"
|
|
167
|
+
dependencies = [
|
|
168
|
+
"proc-macro2",
|
|
169
|
+
"pyo3-macros-backend",
|
|
170
|
+
"quote",
|
|
171
|
+
"syn",
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
[[package]]
|
|
175
|
+
name = "pyo3-macros-backend"
|
|
176
|
+
version = "0.30.1"
|
|
177
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
178
|
+
checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b"
|
|
179
|
+
dependencies = [
|
|
180
|
+
"heck",
|
|
181
|
+
"proc-macro2",
|
|
182
|
+
"quote",
|
|
183
|
+
"syn",
|
|
184
|
+
]
|
|
185
|
+
|
|
186
|
+
[[package]]
|
|
187
|
+
name = "quote"
|
|
188
|
+
version = "1.0.47"
|
|
189
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
190
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
191
|
+
dependencies = [
|
|
192
|
+
"proc-macro2",
|
|
193
|
+
]
|
|
194
|
+
|
|
195
|
+
[[package]]
|
|
196
|
+
name = "rawpointer"
|
|
197
|
+
version = "0.2.1"
|
|
198
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
199
|
+
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
|
|
200
|
+
|
|
201
|
+
[[package]]
|
|
202
|
+
name = "rustc-hash"
|
|
203
|
+
version = "2.1.3"
|
|
204
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
205
|
+
checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
|
|
206
|
+
|
|
207
|
+
[[package]]
|
|
208
|
+
name = "syn"
|
|
209
|
+
version = "3.0.10"
|
|
210
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
211
|
+
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
212
|
+
dependencies = [
|
|
213
|
+
"proc-macro2",
|
|
214
|
+
"quote",
|
|
215
|
+
"unicode-ident",
|
|
216
|
+
]
|
|
217
|
+
|
|
218
|
+
[[package]]
|
|
219
|
+
name = "target-lexicon"
|
|
220
|
+
version = "0.13.6"
|
|
221
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
222
|
+
checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
|
|
223
|
+
|
|
224
|
+
[[package]]
|
|
225
|
+
name = "unicode-ident"
|
|
226
|
+
version = "1.0.27"
|
|
227
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
228
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "plotsimplify"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
description = "Error-bounded time series simplification (Ramer-Douglas-Peucker) for plotting, for Python (PyO3)"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
repository = "https://github.com/f4hy/plotsimplify"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
|
|
10
|
+
[lib]
|
|
11
|
+
name = "_plotsimplify"
|
|
12
|
+
crate-type = ["cdylib", "rlib"]
|
|
13
|
+
|
|
14
|
+
# `extension-module` links against libpython and breaks `cargo test` (no
|
|
15
|
+
# libpython to link against outside a Python process). Gate it behind a
|
|
16
|
+
# feature that's on by default (so `maturin develop`/`maturin build` just
|
|
17
|
+
# work) but can be turned off for plain `cargo test --no-default-features`.
|
|
18
|
+
[features]
|
|
19
|
+
default = ["extension-module"]
|
|
20
|
+
extension-module = ["pyo3/extension-module"]
|
|
21
|
+
|
|
22
|
+
[dependencies]
|
|
23
|
+
# abi3-py311 builds against the stable ABI (matches requires-python in
|
|
24
|
+
# pyproject.toml): one wheel per platform covers every Python >= 3.11.
|
|
25
|
+
pyo3 = { version = "0.30", features = ["abi3-py311"] }
|
|
26
|
+
numpy = "0.30"
|
|
27
|
+
|
|
28
|
+
[profile.release]
|
|
29
|
+
lto = true
|
|
30
|
+
codegen-units = 1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brendan Fahy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: plotsimplify
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Development Status :: 3 - Alpha
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: Intended Audience :: Science/Research
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Programming Language :: Rust
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Requires-Dist: numpy>=1.26
|
|
14
|
+
Requires-Dist: pytest ; extra == 'dev'
|
|
15
|
+
Requires-Dist: ruff==0.15.21 ; extra == 'dev'
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Summary: Rust-powered error-bounded time series simplification (Ramer-Douglas-Peucker) for plotting: keep only the points you can see
|
|
19
|
+
Keywords: ramer-douglas-peucker,rdp,downsampling,time series,plotting,line simplification,decimation
|
|
20
|
+
License: MIT
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
23
|
+
Project-URL: Homepage, https://github.com/f4hy/plotsimplify
|
|
24
|
+
Project-URL: Issues, https://github.com/f4hy/plotsimplify/issues
|
|
25
|
+
Project-URL: Repository, https://github.com/f4hy/plotsimplify
|
|
26
|
+
|
|
27
|
+
# plotsimplify
|
|
28
|
+
|
|
29
|
+
Shrinks a time series to only the points needed to draw it, using
|
|
30
|
+
Ramer–Douglas–Peucker (RDP) with an error bound you set **in pixels**. The
|
|
31
|
+
kernel is Rust (SIMD, with runtime CPU dispatch and the GIL released),
|
|
32
|
+
exposed to Python via [PyO3](https://pyo3.rs).
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import numpy as np
|
|
36
|
+
from plotsimplify import simplify
|
|
37
|
+
|
|
38
|
+
t = np.datetime64("2026-01-01", "ns") + np.arange(n) * np.timedelta64(1, "s")
|
|
39
|
+
y = ... # float values; NaN = gap
|
|
40
|
+
|
|
41
|
+
r = simplify(t, y, width_px=1200, height_px=400) # eps=0.5 px by default
|
|
42
|
+
t_small, y_small = t[r.indices], y[r.indices]
|
|
43
|
+
r.max_error # worst error of the result, in pixels (<= eps unless max_points cut it short)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
On a 1M-point sensor series plotted at 1200×400 px, this keeps about 2,400
|
|
47
|
+
points in 20 ms, and every dropped point is within half a pixel of the line
|
|
48
|
+
that's drawn.
|
|
49
|
+
|
|
50
|
+
## Why
|
|
51
|
+
|
|
52
|
+
Sending or plotting millions of points is slow, and most of them are
|
|
53
|
+
invisible. Python already has two kinds of tools for this, and neither fits:
|
|
54
|
+
|
|
55
|
+
- **RDP libraries aren't built for time series.**
|
|
56
|
+
- The [`rdp`](https://pypi.org/project/rdp/) package is pure Python,
|
|
57
|
+
about 70x slower than a plain loop, and fails on NumPy 2.
|
|
58
|
+
- [`simplification`](https://pypi.org/project/simplification/) (Rust
|
|
59
|
+
`geo`) and shapely are compiled, but they're written for general
|
|
60
|
+
geometry. They have no notion of pixels, datetimes or NaN gaps, and
|
|
61
|
+
`simplification` is 7–9x slower than this package (see below).
|
|
62
|
+
- **Fixed-budget downsamplers** such as
|
|
63
|
+
[`tsdownsample`](https://github.com/predict-idlab/tsdownsample) (LTTB,
|
|
64
|
+
MinMax, M4) are very fast and give you exactly `n_out` points, but they
|
|
65
|
+
don't bound the error. They aim to look right at pixel resolution, not to
|
|
66
|
+
stay close to the line. With the same number of points on plateau-and-ramp
|
|
67
|
+
test data, their worst error was 12–16x larger than RDP's.
|
|
68
|
+
|
|
69
|
+
[`docs/downsampling-report.md`](docs/downsampling-report.md) has the full
|
|
70
|
+
comparison of methods and libraries.
|
|
71
|
+
|
|
72
|
+
## Install
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
pip install plotsimplify
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Prebuilt `abi3` wheels (Linux/macOS/Windows, x86-64 and arm64, Python
|
|
79
|
+
3.11+). The only dependency is NumPy.
|
|
80
|
+
|
|
81
|
+
## Features
|
|
82
|
+
|
|
83
|
+
- **Error in pixels.** Pass the plot's `width_px`/`height_px` and `eps` is
|
|
84
|
+
in pixels. Without them, `eps` is in data units.
|
|
85
|
+
- **Two distance metrics.**
|
|
86
|
+
- `metric="vertical"` (default) measures distance straight up/down from
|
|
87
|
+
the drawn line. It guarantees `max |y - drawn line| <= eps` and is the
|
|
88
|
+
fastest.
|
|
89
|
+
- `metric="perpendicular"` measures Euclidean distance to the drawn
|
|
90
|
+
*segment*. It's clamped to the segment's endpoints, so a spike just
|
|
91
|
+
past the end of a steep ramp isn't dropped. RDP using the infinite line
|
|
92
|
+
would drop it.
|
|
93
|
+
- **`max_points`.** Segments are split largest-error-first, so a budget
|
|
94
|
+
gives you the most important points in one pass, and `max_error` reports
|
|
95
|
+
the error you actually got.
|
|
96
|
+
- **Gaps.** Points with NaN `y` or NaT `x` are dropped, except the first
|
|
97
|
+
point of each gap. It's kept so the plot breaks the line instead of
|
|
98
|
+
joining across the gap.
|
|
99
|
+
- **Timestamps.** `datetime64` and integer `x` are handled without losing
|
|
100
|
+
precision. `x` must be sorted.
|
|
101
|
+
- **Returns indices,** so you can pick timestamps, other columns or metadata
|
|
102
|
+
from your original arrays.
|
|
103
|
+
- `y_range=(lo, hi)` if the plot has a fixed y-axis rather than one that
|
|
104
|
+
auto-scales to the data.
|
|
105
|
+
|
|
106
|
+
## Benchmarks
|
|
107
|
+
|
|
108
|
+
Intel Xeon W-2123 (AVX-512), one thread, synthetic sensor data at 1 sample/s
|
|
109
|
+
with one outage, plotted at 1200×400 px, `eps=0.5` px. Source:
|
|
110
|
+
[`benchmarks/bench.py`](./benchmarks/bench.py), raw output in
|
|
111
|
+
[`benchmarks/results.txt`](./benchmarks/results.txt).
|
|
112
|
+
|
|
113
|
+
| N | case | plotsimplify | pure NumPy RDP | `simplification` (Rust geo) | points kept |
|
|
114
|
+
|---|---|---:|---:|---:|---:|
|
|
115
|
+
| 100k | vertical | **3.8 ms** | 126 ms | – | 7,334 |
|
|
116
|
+
| 100k | perpendicular | **4.0 ms** | 115 ms | 38 ms | 1,871 |
|
|
117
|
+
| 1M | vertical | **21 ms** | 107 ms | – | 2,386 |
|
|
118
|
+
| 1M | perpendicular | **32 ms** | 327 ms | 216 ms | 1,072 |
|
|
119
|
+
| 1M | vertical, `max_points=1000` | **19 ms** | 93 ms | – | 1,000 |
|
|
120
|
+
| 10M | vertical | **255 ms** | 1,664 ms | – | 14,117 |
|
|
121
|
+
| 10M | perpendicular | **345 ms** | 6,560 ms | 3,125 ms | 3,377 |
|
|
122
|
+
|
|
123
|
+
- `simplification` only has perpendicular distance, so it appears only in
|
|
124
|
+
those rows. It's given the same pixel-scaled coordinates. Its time
|
|
125
|
+
includes that scaling and dropping NaNs, since it can't handle gaps.
|
|
126
|
+
- The "pure NumPy RDP" column is the test suite's reference implementation
|
|
127
|
+
(`tests/reference_kernel.py`): the same algorithm with the inner search
|
|
128
|
+
vectorized. It's a good stand-in for what you'd get writing RDP in NumPy
|
|
129
|
+
yourself.
|
|
130
|
+
|
|
131
|
+
## How it's fast
|
|
132
|
+
|
|
133
|
+
- **The farthest-point search uses 8 independent lanes,** so the compiler
|
|
134
|
+
can turn it into SIMD. Ties go to the lowest index.
|
|
135
|
+
- **Runtime CPU dispatch.** Wheels are built for baseline x86-64, so the hot
|
|
136
|
+
loops are also compiled for AVX-512 and AVX2 and chosen at startup.
|
|
137
|
+
`plotsimplify.simd_level()` reports which path is in use. Without dispatch,
|
|
138
|
+
a portable wheel lost about a third of its speed. arm64 builds use the
|
|
139
|
+
generic loops with NEON; that path isn't benchmarked yet.
|
|
140
|
+
- **FMA stays off.** Fused multiply-add would round differently, so every
|
|
141
|
+
SIMD path gives bit-identical output, and the output matches a plain NumPy
|
|
142
|
+
implementation. The tests check both.
|
|
143
|
+
- **Perpendicular distance is computed branch-free:** all three cases are
|
|
144
|
+
computed and one is selected, so it vectorizes too.
|
|
145
|
+
- **The input scan is one fused pass,** because it's memory-bound: the
|
|
146
|
+
number of passes over the data is what costs.
|
|
147
|
+
- **Pixel scaling is free for `vertical`.** Vertical pixel distance is just
|
|
148
|
+
data distance times a constant, so `eps` is converted instead of the
|
|
149
|
+
arrays.
|
|
150
|
+
|
|
151
|
+
## Using it in a web service
|
|
152
|
+
|
|
153
|
+
- **Simplify only the visible range.** Slice to the zoom window with
|
|
154
|
+
`np.searchsorted` first, then simplify. Zooming in brings back detail.
|
|
155
|
+
- **Cap the payload.** Zoomed in, sensor noise can be several pixels tall,
|
|
156
|
+
and RDP keeps noise. `max_points=4 * width_px` is a reasonable cap.
|
|
157
|
+
- **Use a sync endpoint.** In FastAPI, a plain `def` endpoint runs in the
|
|
158
|
+
thread pool, and `simplify` releases the GIL, so concurrent requests run
|
|
159
|
+
in parallel.
|
|
160
|
+
- **Gaps in JSON.** Send `y[r.indices]` with NaN gap markers as `null`;
|
|
161
|
+
plotting libraries draw a break there.
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
```sh
|
|
166
|
+
cargo test --no-default-features
|
|
167
|
+
pip install -e '.[dev]' && maturin develop --release
|
|
168
|
+
pytest # includes bit-identical checks vs the NumPy reference and the non-SIMD path
|
|
169
|
+
pip install simplification && python benchmarks/bench.py
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT
|
|
175
|
+
|