You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Part of #3261 (memory optimization for elastic distances). Applies the two-row dynamic-programming optimization established for DTW in #3258 (and MSM in #3562) to TWE.
Public API and outputs are unchanged. Signatures, defaults (nu=0.001, lmbda=1.0), docstrings, and return values of twe_distance, twe_pairwise_distance, twe_cost_matrix, and twe_alignment_path are all the same.
The full cost matrix is intentionally retained. _twe_cost_matrix is untouched and still backs twe_cost_matrix (which by definition returns the whole matrix) and twe_alignment_path (which needs the full matrix to backtrack the alignment via
compute_min_return_path).
_pad_arrs, the pointwise Euclidean cost, the pairwise / multiple-to-multiple drivers, and the bounding-matrix / windowing / Itakura logic are untouched. All callers of _twe_distance (the pairwise functions) already pass padded arrays and are
unaffected.
Validation
Equivalence: matches the previous full-matrix result to floating-point tolerance — max absolute difference ~3.5e-14 over 400 randomized cases (univariate/multivariate, varying nu/lmbda, windows, and unequal lengths), growing to ~1e-9 at n=8000
(≈1e-13 relative).
Benchmark (univariate, n = m, no window)
n
Runtime baseline → opt
Peak mem baseline → opt
Mem reduction
1,000
15.6 ms → 13.6 ms (1.1×)
9.0 MB → 1.0 MB
9.0×
2,000
67.9 ms → 60.1 ms (1.1×)
36.0 MB → 4.0 MB
9.0×
4,000
0.26 s → 0.21 s (1.3×)
144.1 MB → 16.1 MB
9.0×
8,000
1.89 s → 0.85 s (2.2×)
576.3 MB → 64.3 MB
9.0×
The optimization eliminates the float64 cost matrix (n²·8 bytes); the ~9× reduction reflects that the remaining memory of the public call is the O(n²) boolean bounding matrix (n²·1 byte, window=None).
I have added the following labels to this PR based on the title: [ enhancement ].
I have added the following labels to this PR based on the changes made: [ distances ]. Feel free to change these if they do not properly represent the PR.
The Checks tab will show the status of our automated tests. You can click on individual test runs in the tab or "Details" in the panel below to see more information if there is a failure.
If our pre-commit code quality check fails, please run pre-commit locally and push the fixes to your PR branch.
Don't hesitate to ask questions on the aeonDiscord channel if you have any.
PR CI actions
These checkboxes will add labels to enable or disable CI functionality for this PR. This may not take effect immediately, and a new commit may be required to run the new configuration.
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
distancesDistances packageenhancementNew feature, improvement request or other non-bug code enhancement
1 participant
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.
Part of #3261 (memory optimization for elastic distances). Applies the two-row dynamic-programming optimization established for DTW in #3258 (and MSM in #3562) to TWE.
closes #3269
compute_min_return_path).
unaffected.
Validation
(≈1e-13 relative).
Benchmark (univariate, n = m, no window)
The optimization eliminates the float64 cost matrix (n²·8 bytes); the ~9× reduction reflects that the remaining memory of the public call is the O(n²) boolean bounding matrix (n²·1 byte, window=None).