[v0.2.2] perm_entropy improvements; better doc/doctest#51
Merged
raphaelvallat merged 12 commits intomasterfrom Apr 1, 2026
Merged
[v0.2.2] perm_entropy improvements; better doc/doctest#51raphaelvallat merged 12 commits intomasterfrom
raphaelvallat merged 12 commits intomasterfrom
Conversation
perm_entropy now uses a lookup-table fast path for order=3/4 (2–6× faster for 1D, 3–7× for 2D) and accepts 2D arrays (n_epochs, n_times) for those orders, removing the need for apply_along_axis. The general path (order > 4) gains a zero-copy as_strided window view and a BLAS @ hash product (~1.4× faster). Integer-dtype signals get positional epsilon jitter to match argsort tie-breaking. Includes new tests (fast_path, 2d, ties), updated docstring with 2D examples, and a three-way benchmark script.
- Added deterministic results as a third bullet in "What's new", explaining that the previous unstable sort gave platform-dependent results on tied signals. - Updated the benchmark table descriptions to label the original as "unstable sort, no 2D support" and the new paths as "stable". - The [!NOTE] on ties now mentions "all inputs and all orders" to cover the general path change. - Updated test_perm_entropy_ties description to reflect it now covers float arrays and both dtypes. - Refreshed all benchmark numbers.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #51 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 312 370 +58
Branches 52 62 +10
=========================================
+ Hits 312 370 +58 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's new
perm_entropynow accepts arrays of shape(n_epochs, n_times)fororder=3andorder=4, computing entropy for all epochs in one call instead of looping withnp.apply_along_axis.How it works
For
order=3andorder=4(the two most common settings),argsortis replaced by a small lookup table indexed by pairwise comparisons between delayed columns. Pattern counts are accumulated in a single vectorisednp.bincountcall across all epochs simultaneously.For
order > 4, the existingargsort-based path is retained (1D only) with two minor improvements: a zero-copy window view (as_strided) and a BLAS@product for hashing.Note
Ties (exact duplicate values within a window) are broken by position across all inputs and all orders — earlier position ranks lower, matching stable
argsort. This covers integer arrays, quantized float signals, zero-padded epochs, and any other signal with duplicate values.Benchmarks
Three implementations are compared:
antropyimplementation (unstable sort, no 2D support)order > 4(stable sort, 1D only)order=3/4(stable, 1D and 2D)1D — single time series
2D — multi-epoch data (
n_epochs × n_times)Compared against
np.apply_along_axiswith the original implementation.Tests
test_perm_entropy_fast_path— fast path matches the reference withinatol=1e-12fororder=3/4, across multiple delays and normalize settings.test_perm_entropy_2d— 2D output matchesapply_along_axisof the reference row-by-row.test_perm_entropy_ties— signals with ties (integer arrays, float arrays, zero-padded, quantized) agree with a stable-sort reference for all orders and both dtypes.