Skip to content

perf(delta): O(n) cumulative sum instead of O(n w) per-element np.mean - #48

Merged
cbueth merged 2 commits into
mainfrom
perf/delta-convolution
Jul 30, 2026
Merged

perf(delta): O(n) cumulative sum instead of O(n w) per-element np.mean#48
cbueth merged 2 commits into
mainfrom
perf/delta-convolution

Conversation

@cbueth

@cbueth cbueth commented Jul 30, 2026

Copy link
Copy Markdown
Owner

This PR replaces the O(n w) per-element np.mean loop in delta detrending with a single np.cumsum pass. Local tests show it is 37 to40 times faster (38µs -> 1µs). I added more tests with hardcoded expected values, a naive reference implementation, and constant-series symmetry tests. Through this we can assure the functionality is not breaking.

Signed-off-by: Carlson Büth <commit@cbueth.de>
@cbueth cbueth self-assigned this Jul 30, 2026
@cbueth cbueth added the enhancement New feature or request label Jul 30, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.5

⚡ 4 improved benchmarks
✅ 24 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
test_detrend_method[delta-w100] 17.6 ms 3.5 ms ×5.1
test_detrend_method[delta-w10] 17.4 ms 3.5 ms ×5
test_detrend_method[z_score-p10] 2.1 ms 1.7 ms +22.45%
test_ordinal_patterns 15.9 ms 13.4 ms +18.17%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing perf/delta-convolution (6af1d81) with main (875adcd)

Open in CodSpeed

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@cbueth
cbueth merged commit 8119494 into main Jul 30, 2026
14 checks passed
@cbueth
cbueth deleted the perf/delta-convolution branch July 30, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant