Skip to content

Normalize negative axes before iterating signal vectors - #238

Open
antonsoo wants to merge 1 commit into
florisvb:masterfrom
antonsoo:fix/negative-signal-axes
Open

antonsoo wants to merge 1 commit into
florisvb:masterfrom
antonsoo:fix/negative-signal-axes

Conversation

@antonsoo

Copy link
Copy Markdown

The per-vector loops slice x.shape with the raw axis. With a negative axis this can include the time dimension among the vector indices, leading to an indexing error or results along the wrong dimension. For example:

import numpy as np
from pynumdiff import splinediff

x = np.arange(18.0).reshape(2, 9)
x_hat, dxdt_hat = splinediff(x, .1, axis=-1)
print(x_hat.shape, dxdt_hat.shape)

Before, this raises IndexError: too many indices for array. After, both shapes are (2, 9), with the same values as axis=1.

Normalize the axis before building vector index tuples in splinediff, polydiff, rtsdiff, robustdiff and tvrdiff. Indexing range(x.ndim) resolves valid negative axes and rejects out-of-range axes. The numerical algorithms and positive-axis paths stay the same.

Validation: all 225 tests pass, including equivalent-axis and input-preservation regressions. Pylint was run against both sources; existing diagnostics remain. In 108 recorded KITTI velocity/gyro workflows with scalar and irregular timing, 30 exceptions and six incorrect results become zero. All 54 positive-axis control hashes remain exact. Separate cubic-spline and dense Gaussian trajectory references agree within 3.4e-9. The existing convex-solver accuracy warning is also present on the unmodified base.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant