Skip to content

Lfilter zi dyn sig#84

Merged
trueb2 merged 48 commits into
qsib-cbie:mainfrom
SpookyYomo:lfilter_zi_dyn_sig
Feb 16, 2026
Merged

Lfilter zi dyn sig#84
trueb2 merged 48 commits into
qsib-cbie:mainfrom
SpookyYomo:lfilter_zi_dyn_sig

Conversation

@SpookyYomo
Copy link
Copy Markdown
Contributor

@SpookyYomo SpookyYomo commented Nov 18, 2025

Updates lfilter_zi_dyn's signature to use NDArrays instead of Vec. This aligns the return type
with the input of lfilter.
Removes incorrect assumptions associated with lfilter_zi in the body of the function.

Blockers:

The error variants here should guide the user as to the wrong use of
functions, instead of taking down the entire program with a panic, which
is especially necessary in an embedded environment.
This however does not specify to the end user which arguments are
raising the error.

Fix "Conflict" typo in Error enum variant
ndarray_conv provides linear and FFT convolution for N-dimensional
tensors.
This commit thus introduces into core under a "num_rs" namespace, since
there are many scipy functions that use numpy functions.
The ConvolveMode enum is thus moved, and the relevant enum variants of
ndarray_conv is also provisioned by means of `.into()`.
Display trait is for when `main` ends and an error message is shown to
the end user.
There will be other functions in sci-rs::signal space that uses the
linear convolution.
One can use into the Make and ArrayView from Array but not the other way
round, this makes the function signature abit more friendly without
needing to use `.to_owned()` needlessly.
There is nothing distinguishing between kernel and signal with both
arguments now being identical in type.
This is to ensure both branches are tracking Cargo.toml in sci-rs-core
Unfortunately, it's not quite possible to specify at compile time that
`axis: isize` sastisifes the bounds wrt `N`.

Also check that a[0] exists and is non-zero.
Variable lifetime capture through reborrow only for subsequent
`assign_to` is unnecessary.
This is later checked in `_validate_x()` function. We instead frontload
it into the body.
This version of ndarray-conv accounts for both cross-correlation and
convolution.
This updates ndarray-conv to 0.5.0.
Behavior of convolve in ndarray-conv was changed with 0.5.0.
This is a squash of 3 commits:
1. Failing unit test with a panic atm, more work needs to be done.
2. Further lfilter fix
3. Fix lfilter for 1D signal
Had to step into python to actually see what the slicing was doing...
`alloc` feature flag for lfilter is already specified in the parent
module.
Progressively make the test cases more complex so that its easier to
identify. We also clarify the filter as being FIR as the `a` polynomial
has been set to 1.
This helps reduce from the flow of lfilter code.
Found within .cc file.
Only provide the function signature first. This function is called when
`a.len() > 1`.

Function signature of lfilter is also changed to reflect what zi is
expected to be from both lfilter and linear_filter.
Made it clear that it was taking the shape instead of the ndim of a
NDArray and making into a array `[T; N]`.
Instead of refactoring the non-zi code to follow the structure of zi
code, which results in an additional heap allocation, we instead branch
the code so that the scenario where zi is None does not need to undergo
the additional heap allocation step.
If any error occurs in numpy-esque convolve, we can propagate it out
instead of unwrapping it and panicking.
ndarray::SliceInfo::try_from only works for [SliceInfoElem; N], where N
is up to and including 8. As such, whiltout resorting to Nightly
compiler for `generic_const_exprs` feature, we will eventually implement
lfilter for Array<_, Dim<[Ix; N]>> instead.
Due to some other requirements, lfilter will instead be implemented up
to 6 dimensions.

See rust-lang:rust#76560.
Correspondingly update all test cases.
See previous commit for rationale.
Currently, the as_strided trick is still not quite working.
This commit also adds a corresponding unit test.
ShapeBuilder trait along with Array::as_slice allows as to replicate the
stride_tricks method to create a different array view. It is not yet
presently clear if as_slice_memory_order should be used instead, but the
tests that are included are passing.

It might be possible to remove the reallocation of zi at the start of
the scope now that this is settled.
Update to show when lfilter is not yet implemented for.
Reborrow is all you need.
Some warning that came up in `cargo doc`.
Change the function signature to linear_filter first to be more
permissive.
Also add tests for lfilter.

Note that `lanes_mut` etc are parrallelizeable with Rayon, and may need
more work in the future.
Suggested by clippy on the website. It is yet to be apparent if this
provisioned type necessarily eases the reasoning of the return of the
functions.
This avoids the use of RawData and makes return type T more explicit
with container S.
The shape as `[usize; N]` function is not used by just lfilter.
Also changed the name and documentation to reflect the `const N`
requirement.
There is no requirement that the arguments passed into lfilter has to be
IIR in the way where the denominator length is identical to the
numerator length. FIR can be treated as a special case of IIR as a
matter of fact.
Assume init for uninit arrays instead of specifying zeros with required
shape gives an improved speed in lfilter.
Tried to see in Cargo-asm if this is inlined but `cargo-show-asm` isn't
picking up `lfilter` as a function. This will have to be tested in the
benching function.
This centralizes areas of concern.
Callee should have the responsibility of constructing the `Axis` object.
These are fairly generic functions that parse user input into valid
values of usizes (in their respective context being the arrays they act
on), and thus are more suited to be in array tools.
Some of the trait requirements bound to lfilter as a function can be
removed.
This is necessary for the return type to be consistent with lfilter.
@SpookyYomo SpookyYomo requested a review from trueb2 as a code owner November 18, 2025 07:26
@SpookyYomo SpookyYomo force-pushed the lfilter_zi_dyn_sig branch 5 times, most recently from d9a9e4e to f0882bd Compare November 22, 2025 23:03
@SpookyYomo SpookyYomo mentioned this pull request Nov 23, 2025
1 task
@SpookyYomo SpookyYomo force-pushed the lfilter_zi_dyn_sig branch 2 times, most recently from 349f36f to 7d5b796 Compare November 26, 2025 14:14
@trueb2 trueb2 merged commit 7d5b796 into qsib-cbie:main Feb 16, 2026
1 check passed
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.

2 participants