Skip to content

Conversation

@SpookyYomo
Copy link
Contributor

@SpookyYomo SpookyYomo commented May 1, 2025

There are scipy functions such as lfilter that use numpy's linear convolve
over scipy's fft convolve explicitly. While it is possible for us to implement
ourselves, the hope is that the shared dependency from sci-rs-signal can be
shared with sci-rs-core. Also, hopefully another library can instead be the
one to provide SIMD/etc performance.

For now, this PR merely scopes the function to be feature parallel with
numpy's by utilising ndarray-conv crate.

The dependency brought into sci-rs-core naturally uses ndarray/rayon, which might
mean that this entire feature has to be gated behind std(or perhaps even a rayon
which automatically enables std) feature flag.

Blockers:


Note

Introduces a new core crate with numpy-like 1D convolution and shared error types, and updates sci-rs to depend on it and reuse its ConvolveMode via feature-propagated flags.

  • Core (sci-rs-core):
    • Add new crate with no_std/alloc features and shared Error type.
    • Implement num_rs::convolve and ConvolveMode (Full/Same/Valid) via ndarray-conv, with unit tests.
  • sci-rs integration:
    • Add dependency on sci-rs-core and propagate alloc/std features in Cargo.toml.
    • Replace local ConvolveMode with re-export from sci_rs_core::num_rs in signal/convolve.rs.

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

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
@SpookyYomo SpookyYomo requested a review from trueb2 as a code owner May 1, 2025 22:14
@SpookyYomo SpookyYomo mentioned this pull request May 2, 2025
1 task
@SpookyYomo
Copy link
Contributor Author

SpookyYomo commented Jun 29, 2025

I will open a relevant PR in due time to utilise ndarray-conv 0.5, which should so implement the remaining convolution patterns required in #76.
edit: Just commit straight into core branch and merged into relevant branches.

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.
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