Skip to content

Benchmarking Lfilter#83

Merged
trueb2 merged 75 commits intoqsib-cbie:mainfrom
SpookyYomo:lfilter_bench
Feb 16, 2026
Merged

Benchmarking Lfilter#83
trueb2 merged 75 commits intoqsib-cbie:mainfrom
SpookyYomo:lfilter_bench

Conversation

@SpookyYomo
Copy link
Copy Markdown
Contributor

@SpookyYomo SpookyYomo commented Nov 17, 2025

Adds a benchmark for lfilter with 50 element wide FIR window.

Blockers:


Note

Introduces sci-rs-core with ndarray-based convolution and errors, adds FIR design (firwin/kaiser) and comprehensive window utilities, implements ndarray lfilter/lfilter_zi, integrates across sci-rs, and adds an lfilter benchmark.

  • Core (sci-rs-core):
    • New crate with Error type and ndarray-based num_rs::convolve (Full/Same/Valid) using ndarray_conv.
  • Signal Filtering/Design:
    • Implement firwin_dyn with validation, scaling, and window selection; add Kaiser helpers (kaiser_beta, kaiser_atten, kaiserord).
    • New windows module: get_window API and window types (e.g., Boxcar, Triangle, Blackman, Hamming, Nuttall, Kaiser, General*).
    • Add ndarray-based lfilter trait/function (with optional zi) and lfilter_zi.
  • Convolution:
    • Export ConvolveMode from core; update FFT-based convolve/correlate tests and rand usage.
  • Benchmarks:
    • Add benches/lfilter.rs Criterion benchmark generating synthetic signals and applying FIR lfilter.
  • Project Integration/Deps:
    • Integrate sci-rs-core as dependency and feature-gated (alloc/std); update rand to 0.9; extend signal module docs/exports.

Written by Cursor Bugbot for commit 5b112b3. This will update automatically on new commits. Configure here.

To implement firwin, there is a need to get_windows on all window types
defined in the Scipy signal.windows namespace, most of which are
implemented in a _windows.py file. This commit keeps all the window
variants that needs to be implemented as comments in an Enum for future
implementation, along with some functions that are used across the
implementation of all window types.

The intended strategy to combat the variadic function type associated to
the Scipy's get_windows function is to enclose all function arguments in
a struct that represents the given function type, while ensuring all
structs representing the Windows type implement a common trait.
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.
We also introduce the convenience enum to go along with the function.
There still is a need for double specification of window size across
both firwin and the Window struct that uses it, unless we have a string
to enum converter I suppose...; Either way, its suboptimal currently.
Older commits didn't utilise some properities afforded by Real and
RealField.

Also added a useless(?) cfg(attr = "alloc") compiler attribute for
consistency.
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
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.
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.
It appears that regardless for sizes 50 and 500, scipy takes 95-101ms
whilst our implementation scales with decimation factor, with decimation
factor of 50 taking 31ms and 500 taking 340ms?
`feature = "test"` was unintentionally left out in the previous commit.
@SpookyYomo SpookyYomo requested a review from trueb2 as a code owner November 17, 2025 06:03
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 14

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Wrong argument was being signalled in the message.
This is needed for generating Finite Impulse Response windows that will
be used by lfilter in benching.
@SpookyYomo SpookyYomo force-pushed the lfilter_bench branch 7 times, most recently from 726c36e to 4cb6cf9 Compare November 24, 2025 18:56
@trueb2 trueb2 merged commit ba0f286 into qsib-cbie:main Feb 16, 2026
2 checks 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